]> granicus.if.org Git - clang/commitdiff
Teach the parser to deal with multiple spellings for the same
authorDouglas Gregor <dgregor@apple.com>
Fri, 11 May 2012 23:37:49 +0000 (23:37 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 11 May 2012 23:37:49 +0000 (23:37 +0000)
attribute, rather than requiring multiple cases in consumers of this
information.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156666 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
lib/Sema/SemaDeclAttr.cpp
utils/TableGen/ClangAttrEmitter.cpp

index 3d2bebb6f6d839ebb616a73b66bf4d8a59204e50..fc886faab14cfaf6c5a191ef155971fd055142de 100644 (file)
@@ -101,6 +101,8 @@ class Attr {
   bit SemaHandler = 1;
   // Set to true for attributes that are completely ignored.
   bit Ignored = 0;
+  // Set to true if each of the spellings is a distinct attribute.
+  bit DistinctSpellings = 0;
   // Any additional text that should be included verbatim in the class.  
   code AdditionalMembers = [{}];
 }
@@ -530,6 +532,7 @@ def Override : InheritableAttr {
 
 def Ownership : InheritableAttr {
   let Spellings = ["ownership_holds", "ownership_returns", "ownership_takes"];
+  let DistinctSpellings = 1;
   let Args = [EnumArgument<"OwnKind", "OwnershipKind",
                     ["ownership_holds", "ownership_returns", "ownership_takes"],
                     ["Holds", "Returns", "Takes"]>,
index 284a72e3399ba9971f770b1e560dab69c4ac9f4e..93516501aacef6e3db4b36b228e2c917f8f81c6e 100644 (file)
@@ -3792,7 +3792,6 @@ static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D,
     // by ProcessNonInheritableDeclAttr.
     break;
   case AttributeList::AT_alias:       handleAliasAttr       (S, D, Attr); break;
-  case AttributeList::AT_align:
   case AttributeList::AT_aligned:     handleAlignedAttr     (S, D, Attr); break;
   case AttributeList::AT_always_inline:
     handleAlwaysInlineAttr  (S, D, Attr); break;
index 4177660e26b9c8f3cae116827b82820a90145ce0..772fc2f526f4f1809b0f9ba103e44ebf742bb57d 100644 (file)
@@ -1062,7 +1062,8 @@ void ClangAttrParsedAttrListEmitter::run(raw_ostream &OS) {
     Record &Attr = **I;
     
     bool SemaHandler = Attr.getValueAsBit("SemaHandler");
-    
+    bool DistinctSpellings = Attr.getValueAsBit("DistinctSpellings");
+
     if (SemaHandler) {
       std::vector<StringRef> Spellings =
         getValueAsListOfStrings(Attr, "Spellings");
@@ -1079,6 +1080,9 @@ void ClangAttrParsedAttrListEmitter::run(raw_ostream &OS) {
           ProcessedAttrs.insert(AttrName);
 
         OS << "PARSED_ATTR(" << AttrName << ")\n";
+        
+        if (!DistinctSpellings)
+          break;
       }
     }
   }
@@ -1097,23 +1101,23 @@ void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) {
     
     bool SemaHandler = Attr.getValueAsBit("SemaHandler");
     bool Ignored = Attr.getValueAsBit("Ignored");
-    
+    bool DistinctSpellings = Attr.getValueAsBit("DistinctSpellings");
     if (SemaHandler || Ignored) {
       std::vector<StringRef> Spellings =
         getValueAsListOfStrings(Attr, "Spellings");
 
       for (std::vector<StringRef>::const_iterator I = Spellings.begin(),
            E = Spellings.end(); I != E; ++I) {
-        StringRef AttrName = *I, Spelling = *I;
-       
-        AttrName = NormalizeAttrName(AttrName);
-        Spelling = NormalizeAttrSpelling(Spelling);
+        StringRef AttrName = NormalizeAttrName(DistinctSpellings
+                                                 ? *I
+                                                 : Spellings.front());
+        StringRef Spelling = NormalizeAttrSpelling(*I);
 
         if (SemaHandler)
           Matches.push_back(
-            StringMatcher::StringPair(Spelling,
-                                      std::string("return AttributeList::AT_") +
-                                      AttrName.str() + ";"));
+            StringMatcher::StringPair(
+              Spelling,
+              std::string("return AttributeList::AT_")+AttrName.str() + ";"));
         else
           Matches.push_back(
             StringMatcher::StringPair(