[llvm-commits] [llvm] r116899 - in /llvm/trunk/utils/TableGen: ClangAttrEmitter.cpp ClangAttrEmitter.h TableGen.cpp

Anders Carlsson andersca at mac.com
Tue Oct 19 18:21:53 PDT 2010


Author: andersca
Date: Tue Oct 19 20:21:53 2010
New Revision: 116899

URL: http://llvm.org/viewvc/llvm-project?rev=116899&view=rev
Log:
Add a way to emit StringSwitch of clang attribute spellings.

Modified:
    llvm/trunk/utils/TableGen/ClangAttrEmitter.cpp
    llvm/trunk/utils/TableGen/ClangAttrEmitter.h
    llvm/trunk/utils/TableGen/TableGen.cpp

Modified: llvm/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=116899&r1=116898&r2=116899&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/ClangAttrEmitter.cpp Tue Oct 19 20:21:53 2010
@@ -637,3 +637,21 @@
   }
   OS << "  }\n";
 }
+
+void ClangAttrSpellingListEmitter::run(raw_ostream &OS) {
+  OS << "// This file is generated by TableGen. Do not edit.\n\n";
+
+  std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
+  
+  for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); I != E; ++I) {
+    Record &Attr = **I;
+
+    std::vector<StringRef> Spellings = getValueAsListOfStrings(Attr, "Spellings");
+
+    for (std::vector<StringRef>::const_iterator I = Spellings.begin(), E = Spellings.end(); I != E; ++I) {
+      StringRef Spelling = *I;
+      OS << ".Case(\"" << Spelling << "\", true)\n";
+    }
+  }
+
+}

Modified: llvm/trunk/utils/TableGen/ClangAttrEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/ClangAttrEmitter.h?rev=116899&r1=116898&r2=116899&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/ClangAttrEmitter.h (original)
+++ llvm/trunk/utils/TableGen/ClangAttrEmitter.h Tue Oct 19 20:21:53 2010
@@ -83,6 +83,19 @@
   void run(raw_ostream &OS);
 };
 
+/// ClangAttrSpellingListEmitter - class emits the list of spellings for attributes for
+///   clang.
+class ClangAttrSpellingListEmitter : public TableGenBackend {
+  RecordKeeper &Records;
+
+ public:
+  explicit ClangAttrSpellingListEmitter(RecordKeeper &R)
+    : Records(R)
+    {}
+
+  void run(raw_ostream &OS);
+};
+
 }
 
 #endif

Modified: llvm/trunk/utils/TableGen/TableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TableGen.cpp?rev=116899&r1=116898&r2=116899&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TableGen.cpp (original)
+++ llvm/trunk/utils/TableGen/TableGen.cpp Tue Oct 19 20:21:53 2010
@@ -59,6 +59,7 @@
   GenClangAttrList,
   GenClangAttrPCHRead,
   GenClangAttrPCHWrite,
+  GenClangAttrSpellingList,
   GenClangDiagsDefs,
   GenClangDiagGroups,
   GenClangDeclNodes,
@@ -127,6 +128,8 @@
                                "Generate clang PCH attribute reader"),
                     clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
                                "Generate clang PCH attribute writer"),
+                    clEnumValN(GenClangAttrSpellingList, "gen-clang-attr-spelling-list",
+                               "Generate a clang attribute spelling list"),
                     clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
                                "Generate Clang diagnostics definitions"),
                     clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
@@ -274,6 +277,9 @@
     case GenClangAttrPCHWrite:
       ClangAttrPCHWriteEmitter(Records).run(Out.os());
       break;
+    case GenClangAttrSpellingList:
+      ClangAttrSpellingListEmitter(Records).run(Out.os());
+      break;
     case GenClangDiagsDefs:
       ClangDiagsDefsEmitter(Records, ClangComponent).run(Out.os());
       break;





More information about the llvm-commits mailing list