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

Douglas Gregor dgregor at apple.com
Wed May 2 08:56:52 PDT 2012


Author: dgregor
Date: Wed May  2 10:56:52 2012
New Revision: 155995

URL: http://llvm.org/viewvc/llvm-project?rev=155995&view=rev
Log:
Introduce the notion of an attribute that has no direct representation
as an AST node, and fold a number of such attributes into Attr.td.

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/include/clang/Sema/AttributeList.h
    cfe/trunk/lib/Sema/AttributeList.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=155995&r1=155994&r2=155995&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed May  2 10:56:52 2012
@@ -95,6 +95,8 @@
   bit LateParsed = 0;  
   // Set to true for attributes which must be instantiated within templates
   bit TemplateDependent = 0;
+  // Set to true for attributes that have a corresponding AST node.
+  bit ASTNode = 1;
   // Set to true for attributes which have handler in Sema.
   bit SemaHandler = 1;
   // Any additional text that should be included verbatim in the class.  
@@ -112,6 +114,12 @@
 // Attributes begin here
 //
 
+def AddressSpace : Attr {
+  let Spellings = ["address_space"];
+  let Args = [IntArgument<"AddressSpace">];
+  let ASTNode = 0;  
+}
+
 def Alias : InheritableAttr {
   let Spellings = ["alias"];
   let Args = [StringArgument<"Aliasee">];
@@ -162,6 +170,11 @@
 } }];
 }
 
+def BaseCheck : Attr {
+  let Spellings = ["base_check"];
+  let ASTNode = 0;
+}
+
 def Blocks : InheritableAttr {
   let Spellings = ["blocks"];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
@@ -194,6 +207,11 @@
   let Subjects = [Function];
 }
 
+def CFReturnsAutoreleased : Attr {
+  let Spellings = ["cf_returns_autoreleased"];
+  let ASTNode = 0;
+}
+
 def CFReturnsRetained : InheritableAttr {
   let Spellings = ["cf_returns_retained"];
   let Subjects = [ObjCMethod, Function];
@@ -256,6 +274,12 @@
   let Spellings = ["opencl_kernel_function"];
 }
 
+def OpenCLImageAccess : Attr {
+  let Spellings = ["opencl_image_access"];
+  let Args = [IntArgument<"Access">];
+  let ASTNode = 0;
+}
+
 def Deprecated : InheritableAttr {
   let Spellings = ["deprecated"];
   let Args = [StringArgument<"Message">];
@@ -274,6 +298,12 @@
   let Spellings = ["dllimport"];
 }
 
+def ExtVectorType : Attr {
+  let Spellings = ["ext_vector_type"];
+  let Args = [ExprArgument<"NumElements">];
+  let ASTNode = 0;
+}
+
 def FastCall : InheritableAttr {
   let Spellings = ["fastcall", "__fastcall"];
 }
@@ -345,10 +375,28 @@
   let SemaHandler = 0;
 }
 
+def Mode : Attr {
+  let Spellings = ["mode"];
+  let Args = [IdentifierArgument<"Mode">];
+  let ASTNode = 0;
+}
+
 def Naked : InheritableAttr {
   let Spellings = ["naked"];
 }
 
+def NeonPolyVectorType : Attr {
+  let Spellings = ["neon_polyvector_type"];
+  let Args = [IntArgument<"NumElements">];
+  let ASTNode = 0;
+}
+
+def NeonVectorType : Attr {
+  let Spellings = ["neon_vector_type"];
+  let Args = [IntArgument<"NumElements">];
+  let ASTNode = 0;
+}
+
 def ReturnsTwice : InheritableAttr {
   let Spellings = ["returns_twice"];
 }
@@ -542,6 +590,18 @@
   let Subjects = [ObjCInterface];
 }
 
+def ObjCGC : Attr {
+  let Spellings = ["objc_gc"];
+  let Args = [IdentifierArgument<"Kind">];
+  let ASTNode = 0;
+}
+
+def ObjCOwnership : Attr {
+  let Spellings = ["objc_ownership"];
+  let Args = [IdentifierArgument<"Kind">];
+  let ASTNode = 0;
+}
+
 def ObjCRequiresPropertyDefs : InheritableAttr {
   let Spellings = ["objc_requires_property_definitions"];
   let Subjects = [ObjCInterface];
@@ -561,6 +621,12 @@
   let Subjects = [CXXRecord];
 }
 
+def VectorSize : Attr {
+  let Spellings = ["vector_size"];
+  let Args = [ExprArgument<"NumBytes">];
+  let ASTNode = 0;
+}
+
 def Visibility : InheritableAttr {
   let Spellings = ["visibility"];
   let Args = [EnumArgument<"Visibility", "VisibilityType",

Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=155995&r1=155994&r2=155995&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Wed May  2 10:56:52 2012
@@ -162,17 +162,6 @@
   enum Kind {           
     #define PARSED_ATTR(NAME) AT_##NAME,
     #include "clang/Sema/AttrParsedAttrList.inc"
-    PARSED_ATTR(address_space)
-    PARSED_ATTR(base_check)
-    PARSED_ATTR(cf_returns_autoreleased)
-    PARSED_ATTR(ext_vector_type)
-    PARSED_ATTR(mode)
-    PARSED_ATTR(neon_polyvector_type)
-    PARSED_ATTR(neon_vector_type)
-    PARSED_ATTR(objc_gc)
-    PARSED_ATTR(objc_ownership)
-    PARSED_ATTR(opencl_image_access)
-    PARSED_ATTR(vector_size)
     #undef PARSED_ATTR
     IgnoredAttribute,
     UnknownAttribute

Modified: cfe/trunk/lib/Sema/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=155995&r1=155994&r2=155995&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AttributeList.cpp (original)
+++ cfe/trunk/lib/Sema/AttributeList.cpp Wed May  2 10:56:52 2012
@@ -107,18 +107,7 @@
 
   return llvm::StringSwitch<AttributeList::Kind>(AttrName)
     #include "clang/Sema/AttrParsedAttrKinds.inc"
-    .Case("address_space", AT_address_space)
-    .Case("base_check", AT_base_check)
     .Case("bounded", IgnoredAttribute)       // OpenBSD
-    .Case("cf_returns_autoreleased", AT_cf_returns_autoreleased)
-    .Case("mode", AT_mode)
     .Case("vec_type_hint", IgnoredAttribute)
-    .Case("ext_vector_type", AT_ext_vector_type)
-    .Case("neon_vector_type", AT_neon_vector_type)
-    .Case("neon_polyvector_type", AT_neon_polyvector_type)
-    .Case("opencl_image_access", AT_opencl_image_access)
-    .Case("objc_gc", AT_objc_gc)
-    .Case("objc_ownership", AT_objc_ownership)
-    .Case("vector_size", AT_vector_size)
     .Default(UnknownAttribute);
 }

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=155995&r1=155994&r2=155995&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed May  2 10:56:52 2012
@@ -670,6 +670,10 @@
   for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
        i != e; ++i) {
     Record &R = **i;
+    
+    if (!R.getValueAsBit("ASTNode"))
+      continue;
+    
     const std::string &SuperName = R.getSuperClasses().back()->getName();
 
     OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n";
@@ -754,6 +758,10 @@
 
   for (; i != e; ++i) {
     Record &R = **i;
+    
+    if (!R.getValueAsBit("ASTNode"))
+      continue;
+    
     std::vector<Record*> ArgRecords = R.getValueAsListOfDefs("Args");
     std::vector<StringRef> Spellings = getValueAsListOfStrings(R, "Spellings");
     std::vector<Argument*> Args;
@@ -798,8 +806,12 @@
 
   if (i != e) {
     // Move the end iterator back to emit the last attribute.
-    for(--e; i != e; ++i)
+    for(--e; i != e; ++i) {
+      if (!(*i)->getValueAsBit("ASTNode"))
+        continue;
+      
       OS << Class << "(" << (*i)->getName() << ")\n";
+    }
     
     OS << "LAST_" << Class << "(" << (*i)->getName() << ")\n\n";
   }
@@ -835,6 +847,9 @@
                        NonInhAttrs, InhAttrs, InhParamAttrs;
   for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
        i != e; ++i) {
+    if (!(*i)->getValueAsBit("ASTNode"))
+      continue;
+    
     if ((*i)->isSubClassOf(InhParamClass))
       InhParamAttrs.push_back(*i);
     else if ((*i)->isSubClassOf(InhClass))
@@ -870,6 +885,9 @@
   OS << "    break;\n";
   for (; i != e; ++i) {
     Record &R = **i;
+    if (!R.getValueAsBit("ASTNode"))
+      continue;
+    
     OS << "  case attr::" << R.getName() << ": {\n";
     if (R.isSubClassOf(InhClass))
       OS << "    bool isInherited = Record[Idx++];\n";
@@ -905,6 +923,8 @@
   OS << "    break;\n";
   for (; i != e; ++i) {
     Record &R = **i;
+    if (!R.getValueAsBit("ASTNode"))
+      continue;
     OS << "  case attr::" << R.getName() << ": {\n";
     Args = R.getValueAsListOfDefs("Args");
     if (R.isSubClassOf(InhClass) || !Args.empty())
@@ -979,6 +999,8 @@
   for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end();
        I != E; ++I) {
     Record &R = **I;
+    if (!R.getValueAsBit("ASTNode"))
+      continue;
 
     OS << "    case attr::" << R.getName() << ": {\n";
     OS << "      const " << R.getName() << "Attr *A = cast<"





More information about the cfe-commits mailing list