[cfe-commits] r47420 - in /cfe/trunk: Parse/ParseDecl.cpp Sema/SemaDecl.cpp Sema/SemaType.cpp include/clang/Parse/DeclSpec.h

Chris Lattner sabre at nondot.org
Wed Feb 20 17:32:26 PST 2008


Author: lattner
Date: Wed Feb 20 19:32:26 2008
New Revision: 47420

URL: http://llvm.org/viewvc/llvm-project?rev=47420&view=rev
Log:
Collect and build and process type attributes on pointers.  For 
example, we can now correctly build the type for things like:
    _AS1 float * _AS2 *B;


Modified:
    cfe/trunk/Parse/ParseDecl.cpp
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/Parse/DeclSpec.h

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=47420&r1=47419&r2=47420&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Wed Feb 20 19:32:26 2008
@@ -1064,14 +1064,14 @@
   tok::TokenKind Kind = Tok.getKind();
 
   // Not a pointer or C++ reference.
-  if (Kind != tok::star && !(Kind == tok::amp && getLang().CPlusPlus))
+  if (Kind != tok::star && (Kind != tok::amp || !getLang().CPlusPlus))
     return ParseDirectDeclarator(D);
   
   // Otherwise, '*' -> pointer or '&' -> reference.
   SourceLocation Loc = ConsumeToken();  // Eat the * or &.
 
   if (Kind == tok::star) {
-    // Is a pointer
+    // Is a pointer.
     DeclSpec DS;
     
     ParseTypeQualifierListOpt(DS);
@@ -1080,7 +1080,8 @@
     ParseDeclaratorInternal(D);
 
     // Remember that we parsed a pointer type, and remember the type-quals.
-    D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc));
+    D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,
+                                              DS.TakeAttributes()));
   } else {
     // Is a reference
     DeclSpec DS;
@@ -1108,7 +1109,8 @@
     ParseDeclaratorInternal(D);
 
     // Remember that we parsed a reference type. It doesn't have type-quals.
-    D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc));
+    D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc,
+                                                DS.TakeAttributes()));
   }
 }
 
@@ -1385,11 +1387,8 @@
         
       ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, 
         ParmDecl.getIdentifierLoc(), ParamTy.Val, ParmDecl.getInvalidType(),
-        ParmDecl.getDeclSpec().getAttributes()));
+        ParmDecl.getDeclSpec().TakeAttributes()));
 
-      // Ownership of DeclSpec has been handed off to ParamInfo.
-      DS.clearAttributes();
-      
       // If the next token is a comma, consume it and keep reading arguments.
       if (Tok.isNot(tok::comma)) break;
       

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=47420&r1=47419&r2=47420&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Feb 20 19:32:26 2008
@@ -732,8 +732,8 @@
     FunctionDecl *NewFD = new FunctionDecl(D.getIdentifierLoc(), II, R, SC,
                                            D.getDeclSpec().isInlineSpecified(),
                                            LastDeclarator);
-    // FIXME: Handle attributes.
-    D.getDeclSpec().clearAttributes();
+    // FIXME: Handle attributes: should delete anything left.
+    D.getDeclSpec().SetAttributes(0);
     
     // Merge the decl with the existing one if appropriate. Since C functions
     // are in a flat namespace, make sure we consider decls in outer scopes.

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

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Wed Feb 20 19:32:26 2008
@@ -100,7 +100,7 @@
       Action::DeclTy **PPDecl = &(*DS.getProtocolQualifiers())[0];
       Result = Context.getObjCQualifiedInterfaceType(ObjCIntDecl,
                                    reinterpret_cast<ObjCProtocolDecl**>(PPDecl),
-                                                    DS.NumProtocolQualifiers());
+                                                 DS.getNumProtocolQualifiers());
       break;
     }
     else if (TypedefDecl *typeDecl = dyn_cast<TypedefDecl>(D)) {
@@ -110,7 +110,7 @@
         Action::DeclTy **PPDecl = &(*DS.getProtocolQualifiers())[0];
         Result = Context.getObjCQualifiedIdType(typeDecl->getUnderlyingType(),
                                  reinterpret_cast<ObjCProtocolDecl**>(PPDecl),
-                                            DS.NumProtocolQualifiers());
+                                            DS.getNumProtocolQualifiers());
         break;
       }
     }
@@ -164,7 +164,7 @@
   // Walk the DeclTypeInfo, building the recursive type as we go.  DeclTypeInfos
   // are ordered from the identifier out, which is opposite of what we want :).
   for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
-    const DeclaratorChunk &DeclType = D.getTypeObject(e-i-1);
+    DeclaratorChunk &DeclType = D.getTypeObject(e-i-1);
     switch (DeclType.Kind) {
     default: assert(0 && "Unknown decltype!");
     case DeclaratorChunk::Pointer:
@@ -178,6 +178,11 @@
 
       // 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 (AttributeList *AL = DeclType.Ptr.AttrList)
+        DeclType.Ptr.AttrList = ProcessTypeAttributes(T, AL);
+        
       break;
     case DeclaratorChunk::Reference:
       if (const ReferenceType *RT = T->getAsReferenceType()) {
@@ -190,6 +195,10 @@
       }
 
       T = Context.getReferenceType(T);
+        
+      // See if there are any attributes on the pointer that apply to it.
+      if (AttributeList *AL = DeclType.Ref.AttrList)
+        DeclType.Ref.AttrList = ProcessTypeAttributes(T, AL);
       break;
     case DeclaratorChunk::Array: {
       const DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;

Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=47420&r1=47419&r2=47420&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Wed Feb 20 19:32:26 2008
@@ -260,7 +260,14 @@
   }
   void SetAttributes(AttributeList *AL) { AttrList = AL; }
   AttributeList *getAttributes() const { return AttrList; }
-  void clearAttributes() { AttrList = 0; }
+  
+  /// TakeAttributes - Return the current attribute list and remove them from
+  /// the DeclSpec so that it doesn't own them.
+  AttributeList *TakeAttributes() {
+    AttributeList *AL = AttrList;
+    AttrList = 0;
+    return AL;
+  }
   
   llvm::SmallVector<Action::DeclTy *, 8> *getProtocolQualifiers() const {
     return ProtocolQualifiers;
@@ -268,7 +275,7 @@
   void setProtocolQualifiers(llvm::SmallVector<Action::DeclTy *, 8> *protos) {
     ProtocolQualifiers = protos;
   }
-  unsigned NumProtocolQualifiers() const {
+  unsigned getNumProtocolQualifiers() const {
     return ProtocolQualifiers ?  ProtocolQualifiers->size() : 0;
   }
   /// Finish - This does final analysis of the declspec, issuing diagnostics for
@@ -362,13 +369,19 @@
   struct PointerTypeInfo {
     /// The type qualifiers: const/volatile/restrict.
     unsigned TypeQuals : 3;
-    void destroy() {}
+    AttributeList *AttrList;
+    void destroy() {
+      delete AttrList;
+    }
   };
 
   struct ReferenceTypeInfo {
     /// The type qualifier: restrict. [GNU] C++ extension
     bool HasRestrict;
-    void destroy() {}
+    AttributeList *AttrList;
+    void destroy() {
+      delete AttrList;
+    }
   };
 
   struct ArrayTypeInfo {
@@ -441,21 +454,25 @@
   
   /// getPointer - Return a DeclaratorChunk for a pointer.
   ///
-  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc) {
+  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
+                                    AttributeList *AL) {
     DeclaratorChunk I;
     I.Kind          = Pointer;
     I.Loc           = Loc;
     I.Ptr.TypeQuals = TypeQuals;
+    I.Ptr.AttrList  = AL;
     return I;
   }
   
   /// getReference - Return a DeclaratorChunk for a reference.
   ///
-  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc) {
+  static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
+                                      AttributeList *AL) {
     DeclaratorChunk I;
     I.Kind            = Reference;
     I.Loc             = Loc;
     I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
+    I.Ref.AttrList  = AL;
     return I;
   }
   





More information about the cfe-commits mailing list