[llvm-commits] [llvm] r104018 - /llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp

Sean Hunt rideau3 at gmail.com
Mon May 17 23:22:50 PDT 2010


Author: coppro
Date: Tue May 18 01:22:50 2010
New Revision: 104018

URL: http://llvm.org/viewvc/llvm-project?rev=104018&view=rev
Log:
Replace FIRST_* and LAST_* macros with a generic STMT_RANGE macro
Also rename ABSTRACT to ABSTRACT_STMT

Modified:
    llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp

Modified: llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp?rev=104018&r1=104017&r2=104018&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/ClangASTNodesEmitter.cpp Tue May 18 01:22:50 2010
@@ -37,7 +37,8 @@
 // Called recursively to ensure that nodes remain contiguous
 static std::pair<Record *, Record *> EmitStmtNode(const ChildMap &Tree,
                                                   raw_ostream &OS,
-                                                  Record *Base) {
+                                                  Record *Base,
+						  bool Root = true) {
   std::string BaseName = macroName(Base->getName());
 
   ChildIterator i = Tree.lower_bound(Base), e = Tree.upper_bound(Base);
@@ -59,14 +60,15 @@
     OS << "#endif\n";
 
     if (Abstract)
-      OS << "ABSTRACT(" << NodeName << "(" << R->getName() << ", "
+      OS << "ABSTRACT_STMT(" << 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);
+      const std::pair<Record *, Record *> &Result
+        = EmitStmtNode(Tree, OS, R, false);
       if (!First && Result.first)
         First = Result.first;
       if (Result.second)
@@ -83,32 +85,35 @@
     OS << "#undef " << NodeName << "\n\n";
   }
 
-  assert(!First == !Last && "Got a first or last node, but not the other");
-
   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 << "FIRST_" << BaseName << "(" << First->getName() << ")\n";
-    OS << "LAST_" << BaseName << "(" << Last->getName() << ")\n\n";
+    assert (Last && "Got a first node but not a last node for a range!");
+    if (Root)
+      OS << "LAST_STMT_RANGE(";
+    else
+      OS << "STMT_RANGE(";
+ 
+    OS << Base->getName() << ", " << First->getName() << ", "
+       << 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) {
   // Write the preamble
-  OS << "#ifndef ABSTRACT\n";
-  OS << "#  define ABSTRACT(Stmt) Stmt\n";
+  OS << "#ifndef ABSTRACT_STMT\n";
+  OS << "#  define ABSTRACT_STMT(Stmt) Stmt\n";
+  OS << "#endif\n";
+
+  OS << "#ifndef STMT_RANGE\n";
+  OS << "#  define STMT_RANGE(Base, First, Last)\n";
   OS << "#endif\n\n";
 
+  OS << "#ifndef LAST_STMT_RANGE\n";
+  OS << "#  define LAST_STMT_RANGE(Base, First, Last) "
+          "STMT_RANGE(Base, First, Last)\n";
+  OS << "#endif\n\n";
+ 
   // Emit statements
   const std::vector<Record*> Stmts = Records.getAllDerivedDefinitions("Stmt");
 
@@ -130,5 +135,7 @@
   EmitStmtNode(Tree, OS, &Stmt);
 
   OS << "#undef STMT\n";
-  OS << "#undef ABSTRACT\n";
+  OS << "#undef STMT_RANGE\n";
+  OS << "#undef LAST_STMT_RANGE\n";
+  OS << "#undef ABSTRACT_STMT\n";
 }





More information about the llvm-commits mailing list