[cfe-commits] r156666 - in /cfe/trunk: include/clang/Basic/Attr.td lib/Sema/SemaDeclAttr.cpp utils/TableGen/ClangAttrEmitter.cpp

Douglas Gregor dgregor at apple.com
Fri May 11 16:37:49 PDT 2012


Author: dgregor
Date: Fri May 11 18:37:49 2012
New Revision: 156666

URL: http://llvm.org/viewvc/llvm-project?rev=156666&view=rev
Log:
Teach the parser to deal with multiple spellings for the same
attribute, rather than requiring multiple cases in consumers of this
information.

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=156666&r1=156665&r2=156666&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri May 11 18:37:49 2012
@@ -101,6 +101,8 @@
   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 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"]>,

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=156666&r1=156665&r2=156666&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri May 11 18:37:49 2012
@@ -3792,7 +3792,6 @@
     // 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;

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=156666&r1=156665&r2=156666&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Fri May 11 18:37:49 2012
@@ -1062,7 +1062,8 @@
     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 @@
           ProcessedAttrs.insert(AttrName);
 
         OS << "PARSED_ATTR(" << AttrName << ")\n";
+        
+        if (!DistinctSpellings)
+          break;
       }
     }
   }
@@ -1097,23 +1101,23 @@
     
     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(





More information about the cfe-commits mailing list