[cfe-commits] r52881 - in /cfe/trunk/lib/Sema: Sema.h SemaType.cpp

Chris Lattner sabre at nondot.org
Sat Jun 28 17:50:09 PDT 2008


Author: lattner
Date: Sat Jun 28 19:50:08 2008
New Revision: 52881

URL: http://llvm.org/viewvc/llvm-project?rev=52881&view=rev
Log:
make type attribute processing static instead of methods on Sema.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=52881&r1=52880&r2=52881&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Jun 28 19:50:08 2008
@@ -193,7 +193,7 @@
   // Type Analysis / Processing: SemaType.cpp.
   //
   QualType ConvertDeclSpecToType(const DeclSpec &DS);
-  void ProcessTypeAttributes(QualType &Result, const AttributeList *AL);
+  void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
   QualType GetTypeForDeclarator(Declarator &D, Scope *S);
 
   
@@ -305,13 +305,6 @@
   void ProcessDeclAttributes(Decl *D, const Declarator &PD);
   void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
 
-  /// HandleAddressSpaceTypeAttribute - this attribute is only applicable to 
-  /// objects without automatic storage duration. 
-  /// The raw attribute contains 1 argument, the id of the address space 
-  /// for the type.
-  QualType HandleAddressSpaceTypeAttribute(QualType curType, 
-                                           const AttributeList &Attr);
-  
   void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
                            bool &IncompleteImpl);
                            

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=52881&r1=52880&r2=52881&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Jun 28 19:50:08 2008
@@ -169,7 +169,7 @@
   // See if there are any attributes on the declspec that apply to the type (as
   // opposed to the decl).
   if (const AttributeList *AL = DS.getAttributes())
-    ProcessTypeAttributes(Result, AL);
+    ProcessTypeAttributeList(Result, AL);
     
   // Apply const/volatile/restrict qualifiers to T.
   if (unsigned TypeQuals = DS.getTypeQualifiers()) {
@@ -256,11 +256,6 @@
         
       // Apply the pointer typequals to the pointer object.
       T = Context.getPointerType(T).getQualifiedType(DeclType.Ptr.TypeQuals);
-        
-      // See if there are any attributes on the pointer that apply to it.
-      if (const AttributeList *AL = DeclType.Ptr.AttrList)
-        ProcessTypeAttributes(T, AL);
-        
       break;
     case DeclaratorChunk::Reference:
       if (const ReferenceType *RT = T->getAsReferenceType()) {
@@ -286,10 +281,6 @@
       // Handle restrict on references.
       if (DeclType.Ref.HasRestrict)
         T.addRestrict();
-        
-      // See if there are any attributes on the pointer that apply to it.
-      if (const AttributeList *AL = DeclType.Ref.AttrList)
-        ProcessTypeAttributes(T, AL);
       break;
     case DeclaratorChunk::Array: {
       DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
@@ -454,12 +445,16 @@
       }
       break;
     }
+    
+    // See if there are any attributes on this declarator chunk.
+    if (const AttributeList *AL = DeclType.getAttrs())
+      ProcessTypeAttributeList(T, AL);
   }
   
   // If there were any type attributes applied to the decl itself (not the
   // type, apply the type attribute to the type!)
   if (const AttributeList *Attrs = D.getAttributes())
-    ProcessTypeAttributes(T, Attrs);
+    ProcessTypeAttributeList(T, Attrs);
   
   return T;
 }
@@ -518,51 +513,58 @@
   return T.getAsOpaquePtr();
 }
 
-void Sema::ProcessTypeAttributes(QualType &Result, const AttributeList *AL) {
-  // Scan through and apply attributes to this type where it makes sense.  Some
-  // attributes (such as __address_space__, __vector_size__, etc) apply to the
-  // type, but others can be present in the type specifiers even though they
-  // apply to the decl.  Here we apply type attributes and ignore the rest.
-  for (; AL; AL = AL->getNext()) {
-    // If this is an attribute we can handle, do so now, otherwise, add it to
-    // the LeftOverAttrs list for rechaining.
-    switch (AL->getKind()) {
-    default: break;
-    case AttributeList::AT_address_space:
-      Result = HandleAddressSpaceTypeAttribute(Result, *AL);
-      continue;
-    }
-  }
-}
+
+
+//===----------------------------------------------------------------------===//
+// Type Attribute Processing
+//===----------------------------------------------------------------------===//
 
 /// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
-/// specified type.
-QualType Sema::HandleAddressSpaceTypeAttribute(QualType Type, 
-                                               const AttributeList &Attr) {
+/// specified type.  The attribute contains 1 argument, the id of the address
+/// space for the type.
+static void HandleAddressSpaceTypeAttribute(QualType &Type, 
+                                            const AttributeList &Attr, Sema &S){
   // If this type is already address space qualified, reject it.
   // Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers
   // for two or more different address spaces."
   if (Type.getAddressSpace()) {
-    Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
-    return Type;
+    S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
+    return;
   }
   
   // Check the attribute arguments.
   if (Attr.getNumArgs() != 1) {
-    Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments,
-         std::string("1"));
-    return Type;
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments,
+           std::string("1"));
+    return;
   }
   Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0));
   llvm::APSInt addrSpace(32);
-  if (!ASArgExpr->isIntegerConstantExpr(addrSpace, Context)) {
-    Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int,
-         ASArgExpr->getSourceRange());
-    return Type;
+  if (!ASArgExpr->isIntegerConstantExpr(addrSpace, S.Context)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int,
+           ASArgExpr->getSourceRange());
+    return;
   }
 
   unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue()); 
-  return Context.getASQualType(Type, ASIdx);
+  Type = S.Context.getASQualType(Type, ASIdx);
+}
+
+void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) {
+  // Scan through and apply attributes to this type where it makes sense.  Some
+  // attributes (such as __address_space__, __vector_size__, etc) apply to the
+  // type, but others can be present in the type specifiers even though they
+  // apply to the decl.  Here we apply type attributes and ignore the rest.
+  for (; AL; AL = AL->getNext()) {
+    // If this is an attribute we can handle, do so now, otherwise, add it to
+    // the LeftOverAttrs list for rechaining.
+    switch (AL->getKind()) {
+    default: break;
+    case AttributeList::AT_address_space:
+      HandleAddressSpaceTypeAttribute(Result, *AL, *this);
+      break;
+    }
+  }
 }
 
 





More information about the cfe-commits mailing list