[llvm-commits] [llvm] r103164 - in /llvm/trunk/utils/TableGen: ClangASTNodesEmitter.cpp ClangASTNodesEmitter.h
Sean Hunt
rideau3 at gmail.com
Wed May 5 22:24:38 PDT 2010
Author: coppro
Date: Thu May 6 00:24:38 2010
New Revision: 103164
URL: http://llvm.org/viewvc/llvm-project?rev=103164&view=rev
Log:
Fix some stylistic issues with my last commit.
Modified:
llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp
llvm/trunk/utils/TableGen/ClangASTNodesEmitter.h
Modified: llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp?rev=103164&r1=103163&r2=103164&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp Thu May 6 00:24:38 2010
@@ -1,10 +1,19 @@
+//=== ClangASTNodesEmitter.cpp - Generate Clang AST node tables -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// These tablegen backends emit Clang AST node tables
+//
+//===----------------------------------------------------------------------===//
+
#include "ClangASTNodesEmitter.h"
#include "Record.h"
-#include <vector>
-#include <stack>
-#include <string>
#include <map>
-#include <utility>
#include <cctype>
using namespace llvm;
@@ -12,87 +21,86 @@
// Statement Node Tables (.inc file) generation.
//===----------------------------------------------------------------------===//
-// Sort to create a tree-like structure based on the 'Base' field.
-namespace {
- // Create a macro-ized version of a name
- std::string macroName(std::string S) {
- for (unsigned i = 0; i < S.size(); ++i)
- S[i] = std::toupper(S[i]);
+// Create a macro-ized version of a name
+static std::string macroName(std::string S) {
+ for (unsigned i = 0; i < S.size(); ++i)
+ S[i] = std::toupper(S[i]);
- return S;
- }
+ return S;
+}
- // A map from a node to each of its derived nodes.
- typedef std::multimap<Record*, Record*> ChildMap;
- typedef ChildMap::const_iterator ChildIterator;
-
- // Returns the first and last non-abstract subrecords
- std::pair<Record *, Record *> EmitStmtNode(const ChildMap &Tree,
- raw_ostream &OS, Record *Base) {
- std::string BaseName = macroName(Base->getName());
-
- ChildIterator i = Tree.lower_bound(Base), e = Tree.upper_bound(Base);
-
- Record *First = 0, *Last = 0;
- // This might be the pseudo-node for Stmt; don't assume it has an Abstract
- // bit
- if (Base->getValue("Abstract") && !Base->getValueAsBit("Abstract"))
- First = Last = Base;
-
- for (; i != e; ++i) {
- Record *R = i->second;
- bool Abstract = R->getValueAsBit("Abstract");
- std::string NodeName = macroName(R->getName());
-
- OS << "#ifndef " << NodeName << "\n";
- OS << "# define " << NodeName << "(Type, Base) "
- << BaseName << "(Type, Base)\n";
- OS << "#endif\n";
-
- if (Abstract)
- OS << "ABSTRACT(" << NodeName << "(" << R->getName() << ", "
- << Base->getName() << "))\n";
- else
- OS << NodeName << "(" << R->getName() << ", "
- << Base->getName() << ")\n";
-
- if (Tree.find(R) != Tree.end()) {
- const std::pair<Record *, Record *> &Result = EmitStmtNode(Tree, OS, R);
- if (!First && Result.first)
- First = Result.first;
- if (Result.second)
- Last = Result.second;
- } else {
- if (!Abstract) {
- Last = R;
-
- if (!First)
- First = R;
- }
- }
+// A map from a node to each of its derived nodes.
+typedef std::multimap<Record*, Record*> ChildMap;
+typedef ChildMap::const_iterator ChildIterator;
+
+// Returns the first and last non-abstract subrecords
+// Called recursively to ensure that nodes remain contiguous
+static std::pair<Record *, Record *> EmitStmtNode(const ChildMap &Tree,
+ raw_ostream &OS,
+ Record *Base) {
+ std::string BaseName = macroName(Base->getName());
+
+ ChildIterator i = Tree.lower_bound(Base), e = Tree.upper_bound(Base);
+
+ Record *First = 0, *Last = 0;
+ // This might be the pseudo-node for Stmt; don't assume it has an Abstract
+ // bit
+ if (Base->getValue("Abstract") && !Base->getValueAsBit("Abstract"))
+ First = Last = Base;
+
+ for (; i != e; ++i) {
+ Record *R = i->second;
+ bool Abstract = R->getValueAsBit("Abstract");
+ std::string NodeName = macroName(R->getName());
+
+ OS << "#ifndef " << NodeName << "\n";
+ OS << "# define " << NodeName << "(Type, Base) "
+ << BaseName << "(Type, Base)\n";
+ OS << "#endif\n";
+
+ if (Abstract)
+ OS << "ABSTRACT(" << NodeName << "(" << R->getName() << ", "
+ << Base->getName() << "))\n";
+ else
+ OS << NodeName << "(" << R->getName() << ", "
+ << Base->getName() << ")\n";
- OS << "#undef " << NodeName << "\n\n";
+ if (Tree.find(R) != Tree.end()) {
+ const std::pair<Record *, Record *> &Result = EmitStmtNode(Tree, OS, R);
+ if (!First && Result.first)
+ First = Result.first;
+ if (Result.second)
+ Last = Result.second;
+ } else {
+ if (!Abstract) {
+ Last = R;
+
+ if (!First)
+ First = R;
+ }
}
- assert(!First == !Last && "Got a first or last node, but not the other");
+ OS << "#undef " << NodeName << "\n\n";
+ }
- if (First) {
- OS << "#ifndef FIRST_" << BaseName << "\n";
- OS << "# define FIRST_" << BaseName << "(CLASS)\n";
- OS << "#endif\n";
- OS << "#ifndef LAST_" << BaseName << "\n";
- OS << "# define LAST_" << BaseName << "(CLASS)\n";
- OS << "#endif\n\n";
+ assert(!First == !Last && "Got a first or last node, but not the other");
- OS << "FIRST_" << BaseName << "(" << First->getName() << ")\n";
- OS << "LAST_" << BaseName << "(" << Last->getName() << ")\n\n";
- }
+ if (First) {
+ OS << "#ifndef FIRST_" << BaseName << "\n";
+ OS << "# define FIRST_" << BaseName << "(CLASS)\n";
+ OS << "#endif\n";
+ OS << "#ifndef LAST_" << BaseName << "\n";
+ OS << "# define LAST_" << BaseName << "(CLASS)\n";
+ OS << "#endif\n\n";
- OS << "#undef FIRST_" << BaseName << "\n";
- OS << "#undef LAST_" << BaseName << "\n\n";
-
- return std::make_pair(First, Last);
+ OS << "FIRST_" << BaseName << "(" << First->getName() << ")\n";
+ OS << "LAST_" << BaseName << "(" << Last->getName() << ")\n\n";
}
+
+ OS << "#undef FIRST_" << BaseName << "\n";
+ OS << "#undef LAST_" << BaseName << "\n\n";
+
+ return std::make_pair(First, Last);
}
void ClangStmtNodesEmitter::run(raw_ostream &OS) {
Modified: llvm/trunk/utils/TableGen/ClangASTNodesEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/ClangASTNodesEmitter.h?rev=103164&r1=103163&r2=103164&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/ClangASTNodesEmitter.h (original)
+++ llvm/trunk/utils/TableGen/ClangASTNodesEmitter.h Thu May 6 00:24:38 2010
@@ -1,4 +1,4 @@
-//===- ClangDiagnosticsEmitter.h - Generate Clang diagnostics tables -*- C++ -*-
+//===- ClangASTNodesEmitter.h - Generate Clang AST node tables -*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
-// These tablegen backends emit Clang diagnostics tables.
+// These tablegen backends emit Clang AST node tables
//
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list