]> granicus.if.org Git - clang/commitdiff
Add getTypeSpecStartLoc() to VarDecls and FunctionDecls.
authorSteve Naroff <snaroff@apple.com>
Fri, 3 Oct 2008 00:02:03 +0000 (00:02 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 3 Oct 2008 00:02:03 +0000 (00:02 +0000)
This is a temporary solution to help with the block rewriter (though it certainly has general utility).
Once DeclGroup's are implemented, this SourceLocation should be stored with it (since it applies to all the decls).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56985 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp

index 29ec40b6e213dda41e485c3bef2416adbdab1e8f..fe5e1400cafc649a033ad866e89b73b488cd5d39 100644 (file)
@@ -230,19 +230,25 @@ private:
   unsigned SClass : 3;
   bool ThreadSpecified : 1;
   
+  // Move to DeclGroup when it is implemented.
+  SourceLocation TypeSpecStartLoc;
   friend class StmtIteratorBase;
 protected:
   VarDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
-          QualType T, StorageClass SC, ScopedDecl *PrevDecl)
+          QualType T, StorageClass SC, ScopedDecl *PrevDecl, 
+          SourceLocation TSSL = SourceLocation())
     : ValueDecl(DK, DC, L, Id, T, PrevDecl), Init(0),
-          ThreadSpecified(false) { SClass = SC; }
+          ThreadSpecified(false), TypeSpecStartLoc(TSSL) { SClass = SC; }
 public:
   static VarDecl *Create(ASTContext &C, DeclContext *DC,
                          SourceLocation L, IdentifierInfo *Id,
-                         QualType T, StorageClass S, ScopedDecl *PrevDecl);
+                         QualType T, StorageClass S, ScopedDecl *PrevDecl,
+                         SourceLocation TypeSpecStartLoc = SourceLocation());
   
   StorageClass getStorageClass() const { return (StorageClass)SClass; }
 
+  SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
+  
   const Expr *getInit() const { return (const Expr*) Init; }
   Expr *getInit() { return (Expr*) Init; }
   void setInit(Expr *I) { Init = (Stmt*) I; }
@@ -416,14 +422,17 @@ private:
   bool IsInline : 1;
   bool IsImplicit : 1;
 
+  // Move to DeclGroup when it is implemented.
+  SourceLocation TypeSpecStartLoc;
 protected:
   FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
                IdentifierInfo *Id, QualType T,
-               StorageClass S, bool isInline, ScopedDecl *PrevDecl)
+               StorageClass S, bool isInline, ScopedDecl *PrevDecl,
+               SourceLocation TSSL = SourceLocation())
     : ValueDecl(DK, DC, L, Id, T, PrevDecl), 
       DeclContext(DK),
       ParamInfo(0), Body(0), PreviousDeclaration(0),
-      SClass(S), IsInline(isInline), IsImplicit(0) {}
+      SClass(S), IsInline(isInline), IsImplicit(0), TypeSpecStartLoc(TSSL) {}
 
   virtual ~FunctionDecl();
   virtual void Destroy(ASTContext& C);
@@ -432,8 +441,11 @@ public:
   static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                               IdentifierInfo *Id, QualType T, 
                               StorageClass S = None, bool isInline = false, 
-                              ScopedDecl *PrevDecl = 0);  
+                              ScopedDecl *PrevDecl = 0,
+                              SourceLocation TSStartLoc = SourceLocation());  
   
+  SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
+
   /// getBody - Retrieve the body (definition) of the function. The
   /// function body might be in any of the (re-)declarations of this
   /// function. The variant that accepts a FunctionDecl pointer will
index 8bc212d302d341db26d0fc9298c010443c2f978f..3ddf81974b682ed9b7bc422e2c9d0d254eb45ae0 100644 (file)
@@ -51,9 +51,10 @@ ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
 VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
                          SourceLocation L,
                          IdentifierInfo *Id, QualType T,
-                         StorageClass S, ScopedDecl *PrevDecl) {
+                         StorageClass S, ScopedDecl *PrevDecl,
+                         SourceLocation TypeSpecStartLoc) {
   void *Mem = C.getAllocator().Allocate<VarDecl>();
-  return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl);
+  return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc);
 }
 
 ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
@@ -68,9 +69,11 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
                                    SourceLocation L, 
                                    IdentifierInfo *Id, QualType T, 
                                    StorageClass S, bool isInline, 
-                                   ScopedDecl *PrevDecl) {
+                                   ScopedDecl *PrevDecl,
+                                   SourceLocation TypeSpecStartLoc) {
   void *Mem = C.getAllocator().Allocate<FunctionDecl>();
-  return new (Mem) FunctionDecl(Function, DC, L, Id, T, S, isInline, PrevDecl);
+  return new (Mem) FunctionDecl(Function, DC, L, Id, T, S, isInline, PrevDecl,
+                                TypeSpecStartLoc);
 }
 
 FieldDecl *FieldDecl::Create(ASTContext &C, SourceLocation L,
index 8214fe4c631683951fbbfa6582ab7916d7953104..1d755efd1213ca054ca8f3e79ee8ed7bcc2f244c 100644 (file)
@@ -661,8 +661,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
     } else {
       NewFD = FunctionDecl::Create(Context, CurContext,
                                    D.getIdentifierLoc(),
-                                   II, R, SC, isInline,
-                                   LastDeclarator);
+                                   II, R, SC, isInline, LastDeclarator,
+                                   // FIXME: Move to DeclGroup...
+                                   D.getDeclSpec().getSourceRange().getBegin());
     }
     // Handle attributes.
     ProcessDeclAttributes(NewFD, D);
@@ -766,7 +767,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
         }
       }
         NewVD = VarDecl::Create(Context, CurContext, D.getIdentifierLoc(), 
-                                II, R, SC, LastDeclarator);
+                                II, R, SC, LastDeclarator,
+                                // FIXME: Move to DeclGroup...
+                                D.getDeclSpec().getSourceRange().getBegin());
         NewVD->setThreadSpecified(ThreadSpecified);
     }
     // Handle attributes prior to checking for duplicates in MergeVarDecl