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

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:41:36 PDT 2007


Author: sabre
Date: Wed Jul 11 11:41:36 2007
New Revision: 39230

URL: http://llvm.org/viewvc/llvm-project?rev=39230&view=rev
Log:
Next step of retaining information about function prototypes: actually retain
the info.  Also, call Actions.ParseParamDeclaratorType instead of
Actions.ParseDeclarator for parameter type lists: we don't want declaration
objects created when parsing a function declarator, we just want type info.

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

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39230&r1=39229&r2=39230&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:41:36 2007
@@ -140,7 +140,7 @@
   bool Error = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, Dummy);
   assert(!Error && "Error setting up implicit decl!");
   Declarator D(DS, Declarator::BlockContext);
-  D.AddTypeInfo(DeclaratorTypeInfo::getFunction(false, false, 0, 0, Loc));
+  D.AddTypeInfo(DeclaratorChunk::getFunction(false, false, 0, 0, Loc));
   D.SetIdentifier(&II, Loc);
   
   Decl *Result = static_cast<Decl*>(ParseDeclarator(S, D, 0, 0));

Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39230&r1=39229&r2=39230&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:41:36 2007
@@ -103,17 +103,17 @@
   // 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 DeclaratorTypeInfo &DeclType = D.getTypeObject(e-i-1);
+    const DeclaratorChunk &DeclType = D.getTypeObject(e-i-1);
     switch (DeclType.Kind) {
     default: assert(0 && "Unknown decltype!");
-    case DeclaratorTypeInfo::Pointer:
+    case DeclaratorChunk::Pointer:
       T = Context.getPointerType(T);
 
       // Apply the pointer typequals to the pointer object.
       T = T.getQualifiedType(DeclType.Ptr.TypeQuals);
       break;
-    case DeclaratorTypeInfo::Array: {
-      const DeclaratorTypeInfo::ArrayTypeInfo &ATI = DeclType.Arr;
+    case DeclaratorChunk::Array: {
+      const DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
       ArrayType::ArraySizeModifier ASM;
       if (ATI.isStar)
         ASM = ArrayType::Star;
@@ -125,7 +125,7 @@
       T = Context.getArrayType(T, ASM, ATI.TypeQuals, ATI.NumElts);
       break;
     }
-    case DeclaratorTypeInfo::Function:
+    case DeclaratorChunk::Function:
       return TypeRef();   // FIXME: implement these!
     }
   }

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

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:41:36 2007
@@ -784,7 +784,7 @@
   ParseDeclaratorInternal(D);
 
   // Remember that we parsed a pointer type, and remember the type-quals.
-  D.AddTypeInfo(DeclaratorTypeInfo::getPointer(DS.getTypeQualifiers(), Loc));
+  D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc));
 }
 
 
@@ -862,7 +862,6 @@
 ///         identifier
 ///         identifier-list ',' identifier
 ///
-#include <iostream>
 void Parser::ParseParenDeclarator(Declarator &D) {
   SourceLocation StartLoc = ConsumeParen();
   
@@ -916,7 +915,7 @@
   bool ErrorEmitted = false;
 
   // Build up an array of information about the parsed arguments.
-  SmallVector<DeclaratorTypeInfo::ParamInfo, 16> ParamInfo;
+  SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
   
   if (Tok.getKind() == tok::r_paren) {
     // int() -> no prototype, no '...'.
@@ -936,23 +935,28 @@
     // diagnose this.
     if (!D.getIdentifier())
       Diag(Tok, diag::ext_ident_list_in_param);
-    
-    // FIXME: pass stuff.
-    ParamInfo.push_back(DeclaratorTypeInfo::ParamInfo());
 
-    // TODO: Remember token.
+    // Remember this identifier in ParamInfo.
+    ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(),
+                                                   Tok.getLocation(), 0));
+
     ConsumeToken();
     while (Tok.getKind() == tok::comma) {
       // Eat the comma.
       ConsumeToken();
       
-      if (ExpectAndConsume(tok::identifier, diag::err_expected_ident)) {
+      if (Tok.getKind() != tok::identifier) {
+        Diag(Tok, diag::err_expected_ident);
         ErrorEmitted = true;
         break;
       }
-
-      // FIXME: pass stuff.
-      ParamInfo.push_back(DeclaratorTypeInfo::ParamInfo());
+      
+      // Remember this identifier in ParamInfo.
+      ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(),
+                                                     Tok.getLocation(), 0));
+      
+      // Eat the identifier.
+      ConsumeToken();
     }
     
     // K&R 'prototype'.
@@ -961,18 +965,18 @@
   } else {
     // Finally, a normal, non-empty parameter type list.
     
-    // Enter function-declaration scope, limiting any declarators for arguments
-    // to the function scope.
+    // Enter function-declaration scope, limiting any declarators for struct
+    // tags to the function prototype scope.
+    // FIXME: is this needed?
     EnterScope(0);
     
     IsVariadic = false;
-    bool ReadArg = false;
     while (1) {
       if (Tok.getKind() == tok::ellipsis) {
         IsVariadic = true;
 
         // Check to see if this is "void(...)" which is not allowed.
-        if (!ReadArg) {
+        if (ParamInfo.empty()) {
           // Otherwise, parse parameter type list.  If it starts with an
           // ellipsis,  diagnose the malformed function.
           Diag(Tok, diag::err_ellipsis_first_arg);
@@ -984,16 +988,14 @@
         break;
       }
       
-      ReadArg = true;
-
       // Parse the declaration-specifiers.
       DeclSpec DS;
       ParseDeclarationSpecifiers(DS);
 
       // Parse the declarator.  This is "PrototypeContext", because we must
       // accept either 'declarator' or 'abstract-declarator' here.
-      Declarator DeclaratorInfo(DS, Declarator::PrototypeContext);
-      ParseDeclarator(DeclaratorInfo);
+      Declarator ParmDecl(DS, Declarator::PrototypeContext);
+      ParseDeclarator(ParmDecl);
 
       // Parse GNU attributes, if present.
       if (Tok.getKind() == tok::kw___attribute)
@@ -1018,13 +1020,14 @@
         DS.ClearStorageClassSpecs();
       }
       
-      
-      // FIXME: pass stuff.
-      ParamInfo.push_back(DeclaratorTypeInfo::ParamInfo());
-      
       // Inform the actions module about the parameter declarator, so it gets
       // added to the current scope.
-      Actions.ParseDeclarator(CurScope, DeclaratorInfo, 0, 0);
+      Action::TypeResult ParamTy = Actions.ParseParamDeclaratorType(ParmDecl);
+        
+      // Remember this parsed parameter in ParamInfo.
+      ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmDecl.getIdentifier(),
+                                                    ParmDecl.getIdentifierLoc(),
+                                                     ParamTy.Val));
       
       // If the next token is a comma, consume it and keep reading arguments.
       if (Tok.getKind() != tok::comma) break;
@@ -1039,16 +1042,16 @@
     ExitScope();
   }
   
-  DeclaratorTypeInfo::ParamInfo *ParamArray = 0;
+  DeclaratorChunk::ParamInfo *ParamArray = 0;
   if (!ParamInfo.empty()) {
-    ParamArray = new DeclaratorTypeInfo::ParamInfo[ParamInfo.size()];
+    ParamArray = new DeclaratorChunk::ParamInfo[ParamInfo.size()];
     memcpy(ParamArray, &ParamInfo[0], sizeof(ParamInfo[0])*ParamInfo.size());
   }
   
   // Remember that we parsed a function type, and remember the attributes.
-  D.AddTypeInfo(DeclaratorTypeInfo::getFunction(HasPrototype, IsVariadic,
-                                                ParamInfo.size(), ParamArray,
-                                                StartLoc));
+  D.AddTypeInfo(DeclaratorChunk::getFunction(HasPrototype, IsVariadic,
+                                             ParamInfo.size(), ParamArray,
+                                             StartLoc));
   
   
   // If we have the closing ')', eat it and we're done.
@@ -1131,8 +1134,8 @@
   }
   
   // Remember that we parsed a pointer type, and remember the type-quals.
-  D.AddTypeInfo(DeclaratorTypeInfo::getArray(DS.getTypeQualifiers(),
-                                             StaticLoc.isValid(), isStar,
-                                             NumElements.Val, StartLoc));
+  D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(),
+                                          StaticLoc.isValid(), isStar,
+                                          NumElements.Val, StartLoc));
 }
 

Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=39230&r1=39229&r2=39230&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:41:36 2007
@@ -399,8 +399,8 @@
 ///                 compound-statement                           [TODO]
 ///
 Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) {
-  const DeclaratorTypeInfo &FnTypeInfo = D.getTypeObject(0);
-  assert(FnTypeInfo.Kind == DeclaratorTypeInfo::Function &&
+  const DeclaratorChunk &FnTypeInfo = D.getTypeObject(0);
+  assert(FnTypeInfo.Kind == DeclaratorChunk::Function &&
          "This isn't a function declarator!");
 
   DeclTy *Res = Actions.ParseStartOfFunctionDef(CurScope, D);

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:41:36 2007
@@ -140,7 +140,7 @@
   bool Error = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, Dummy);
   assert(!Error && "Error setting up implicit decl!");
   Declarator D(DS, Declarator::BlockContext);
-  D.AddTypeInfo(DeclaratorTypeInfo::getFunction(false, false, 0, 0, Loc));
+  D.AddTypeInfo(DeclaratorChunk::getFunction(false, false, 0, 0, Loc));
   D.SetIdentifier(&II, Loc);
   
   Decl *Result = static_cast<Decl*>(ParseDeclarator(S, D, 0, 0));

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:41:36 2007
@@ -103,17 +103,17 @@
   // 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 DeclaratorTypeInfo &DeclType = D.getTypeObject(e-i-1);
+    const DeclaratorChunk &DeclType = D.getTypeObject(e-i-1);
     switch (DeclType.Kind) {
     default: assert(0 && "Unknown decltype!");
-    case DeclaratorTypeInfo::Pointer:
+    case DeclaratorChunk::Pointer:
       T = Context.getPointerType(T);
 
       // Apply the pointer typequals to the pointer object.
       T = T.getQualifiedType(DeclType.Ptr.TypeQuals);
       break;
-    case DeclaratorTypeInfo::Array: {
-      const DeclaratorTypeInfo::ArrayTypeInfo &ATI = DeclType.Arr;
+    case DeclaratorChunk::Array: {
+      const DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
       ArrayType::ArraySizeModifier ASM;
       if (ATI.isStar)
         ASM = ArrayType::Star;
@@ -125,7 +125,7 @@
       T = Context.getArrayType(T, ASM, ATI.TypeQuals, ATI.NumElts);
       break;
     }
-    case DeclaratorTypeInfo::Function:
+    case DeclaratorChunk::Function:
       return TypeRef();   // FIXME: implement these!
     }
   }

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:41:36 2007
@@ -136,6 +136,10 @@
     return 0;
   }
   
+  virtual TypeResult ParseParamDeclaratorType(Declarator &D) {
+    return 0;
+  }
+  
   //===--------------------------------------------------------------------===//
   // Statement Parsing Callbacks.
   //===--------------------------------------------------------------------===//

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:41:36 2007
@@ -15,7 +15,7 @@
 #define LLVM_CLANG_PARSE_SEMADECLSPEC_H
 
 #include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/SourceLocation.h"
+#include "clang/Parse/Action.h"
 #include "llvm/ADT/SmallVector.h"
 
 namespace llvm {
@@ -219,11 +219,11 @@
 };
 
 
-/// DeclaratorTypeInfo - One instance of this struct is used for each type in a
+/// DeclaratorChunk - One instance of this struct is used for each type in a
 /// declarator that is parsed.
 ///
 /// This is intended to be a small value object.
-struct DeclaratorTypeInfo {
+struct DeclaratorChunk {
   enum {
     Pointer, Array, Function
   } Kind;
@@ -260,7 +260,12 @@
     /// Ident - In a K&R 
     IdentifierInfo *Ident;
     SourceLocation IdentLoc;
-    void *TypeInfo;
+    Action::TypeTy *TypeInfo;
+    
+    ParamInfo() {}
+    ParamInfo(IdentifierInfo *ident, SourceLocation iloc, Action::TypeTy *typ)
+      : Ident(ident), IdentLoc(iloc), TypeInfo(typ) {
+    }
   };
   
   struct FunctionTypeInfo {
@@ -290,22 +295,22 @@
   };
   
   
-  /// getPointer - Return a DeclaratorTypeInfo for a pointer.
+  /// getPointer - Return a DeclaratorChunk for a pointer.
   ///
-  static DeclaratorTypeInfo getPointer(unsigned TypeQuals, SourceLocation Loc) {
-    DeclaratorTypeInfo I;
+  static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc) {
+    DeclaratorChunk I;
     I.Kind          = Pointer;
     I.Loc           = Loc;
     I.Ptr.TypeQuals = TypeQuals;
     return I;
   }
   
-  /// getArray - Return a DeclaratorTypeInfo for an array.
+  /// getArray - Return a DeclaratorChunk for an array.
   ///
-  static DeclaratorTypeInfo getArray(unsigned TypeQuals, bool isStatic,
+  static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic,
                                      bool isStar, void *NumElts,
                                      SourceLocation Loc) {
-    DeclaratorTypeInfo I;
+    DeclaratorChunk I;
     I.Kind          = Array;
     I.Loc           = Loc;
     I.Arr.TypeQuals = TypeQuals;
@@ -315,12 +320,12 @@
     return I;
   }
   
-  /// getFunction - Return a DeclaratorTypeInfo for a function.  ArgInfo should
+  /// getFunction - Return a DeclaratorChunk for a function.  ArgInfo should
   /// be a new[]'d array with NumArgs elements in it, or null if NumArgs is 0.
-  static DeclaratorTypeInfo getFunction(bool hasProto, bool isVariadic,
+  static DeclaratorChunk getFunction(bool hasProto, bool isVariadic,
                                         unsigned NumArgs, ParamInfo *ArgInfo,
                                         SourceLocation Loc) {
-    DeclaratorTypeInfo I;
+    DeclaratorChunk I;
     I.Kind             = Function;
     I.Loc              = Loc;
     I.Fun.hasPrototype = hasProto;
@@ -366,7 +371,7 @@
   /// parsed.  This is pushed from the identifier out, which means that element
   /// #0 will be the most closely bound to the identifier, and
   /// DeclTypeInfo.back() will be the least closely bound.
-  SmallVector<DeclaratorTypeInfo, 8> DeclTypeInfo;
+  SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
   
 public:
   Declarator(const DeclSpec &ds, TheContext C)
@@ -389,7 +394,7 @@
     IdentifierLoc = SourceLocation();
     
     for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
-      if (DeclTypeInfo[i].Kind == DeclaratorTypeInfo::Function)
+      if (DeclTypeInfo[i].Kind == DeclaratorChunk::Function)
         delete [] DeclTypeInfo[i].Fun.ArgInfo;
         
     DeclTypeInfo.clear();
@@ -420,7 +425,7 @@
     IdentifierLoc = Loc;
   }
   
-  void AddTypeInfo(const DeclaratorTypeInfo &TI) {
+  void AddTypeInfo(const DeclaratorChunk &TI) {
     DeclTypeInfo.push_back(TI);
   }
   
@@ -430,7 +435,7 @@
   
   /// Return the specified TypeInfo from this declarator.  TypeInfo #0 is
   /// closest to the identifier.
-  const DeclaratorTypeInfo &getTypeObject(unsigned i) const {
+  const DeclaratorChunk &getTypeObject(unsigned i) const {
     return DeclTypeInfo[i];
   }
   
@@ -438,7 +443,7 @@
   /// this method returns true if the identifier is a function declarator.
   bool isFunctionDeclarator() const {
     return !DeclTypeInfo.empty() &&
-           DeclTypeInfo[0].Kind == DeclaratorTypeInfo::Function;
+           DeclTypeInfo[0].Kind == DeclaratorChunk::Function;
   }
 };
 





More information about the cfe-commits mailing list