r199414 - When generating Spelling enumeration values, do not generate identifiers in the reserved namespace. Strip underscores as appropriate, taking care to not create duplicate identifiers.

Aaron Ballman aaron at aaronballman.com
Thu Jan 16 11:44:01 PST 2014


Author: aaronballman
Date: Thu Jan 16 13:44:01 2014
New Revision: 199414

URL: http://llvm.org/viewvc/llvm-project?rev=199414&view=rev
Log:
When generating Spelling enumeration values, do not generate identifiers in the reserved namespace. Strip underscores as appropriate, taking care to not create duplicate identifiers.

Modified:
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=199414&r1=199413&r2=199414&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Thu Jan 16 13:44:01 2014
@@ -1200,7 +1200,12 @@ void EmitClangAttrClass(RecordKeeper &Re
                          SpellingNamesAreCommon(Spellings);
 
     if (!ElideSpelling) {
+      // The enumerants are automatically generated based on the variety,
+      // namespace (if present) and name for each attribute spelling. However,
+      // care is taken to avoid trampling on the reserved namespace due to
+      // underscores.
       OS << "  enum Spelling {\n";
+      std::set<std::string> Uniques;
       for (std::vector<Record *>::const_iterator I = Spellings.begin(),
            E = Spellings.end(); I != E; ++I) {
         if (I != Spellings.begin())
@@ -1209,14 +1214,25 @@ void EmitClangAttrClass(RecordKeeper &Re
         std::string Variety = S.getValueAsString("Variety");
         std::string Spelling = S.getValueAsString("Name");
         std::string Namespace = "";
+        std::string EnumName = "";
 
         if (Variety == "CXX11")
           Namespace = S.getValueAsString("Namespace");
 
-        OS << "    " << Variety << "_";
+        EnumName += (Variety + "_");
         if (!Namespace.empty())
-          OS << Namespace << "_";
-        OS << Spelling;
+          EnumName += (NormalizeNameForSpellingComparison(Namespace).str() +
+                      "_");
+        EnumName += NormalizeNameForSpellingComparison(Spelling);
+
+        // Since we have been stripping underscores to avoid trampling on the
+        // reserved namespace, we may have inadvertantly created duplicate
+        // enumerant names. Unique the name if required.
+        while (Uniques.find(EnumName) != Uniques.end())
+          EnumName += "_alternate";
+        Uniques.insert(EnumName);
+
+        OS << "    " << EnumName;
       }
       OS << "\n  };\n\n";
     }





More information about the cfe-commits mailing list