]> granicus.if.org Git - clang/commitdiff
Add a "TypeSpecStartLoc" to FieldDecl. Patch contributed by Enea Zaffanella.
authorSteve Naroff <snaroff@apple.com>
Tue, 14 Jul 2009 14:58:18 +0000 (14:58 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 14 Jul 2009 14:58:18 +0000 (14:58 +0000)
Note: One day, it might be useful to consider adding this info to DeclGroup (as the comments in FunctionDecl/VarDecl suggest). For now, I think this works fine. I considered moving this to ValueDecl (a common ancestor of FunctionDecl/VarDecl/FieldDecl), however this would add overhead to EnumConstantDecl (which would burn memory and isn't necessary).

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

include/clang/AST/Decl.h
lib/AST/Decl.cpp
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHWriterDecl.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp

index 66099217b06840d241f2a2e7bc5163a94e16757a..a5c3ea0680e75f3374511e06d9aea5abaf67ba42 100644 (file)
@@ -1137,16 +1137,19 @@ class FieldDecl : public ValueDecl {
   // FIXME: This can be packed into the bitfields in Decl.
   bool Mutable : 1;
   Expr *BitWidth;
+  SourceLocation TypeSpecStartLoc;
 protected:
   FieldDecl(Kind DK, DeclContext *DC, SourceLocation L, 
-            IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable)
-    : ValueDecl(DK, DC, L, Id, T), Mutable(Mutable), BitWidth(BW)
-      { }
+            IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable,
+            SourceLocation TSSL = SourceLocation())
+    : ValueDecl(DK, DC, L, Id, T), Mutable(Mutable), BitWidth(BW),
+      TypeSpecStartLoc(TSSL) { }
 
 public:
   static FieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 
                            IdentifierInfo *Id, QualType T, Expr *BW, 
-                           bool Mutable);
+                           bool Mutable,
+                           SourceLocation TypeSpecStartLoc = SourceLocation());
 
   /// isMutable - Determines whether this field is mutable (C++ only).
   bool isMutable() const { return Mutable; }
@@ -1154,6 +1157,9 @@ public:
   /// \brief Set whether this field is mutable (C++ only).
   void setMutable(bool M) { Mutable = M; }
 
+  SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
+  void setTypeSpecStartLoc(SourceLocation TSSL) { TypeSpecStartLoc = TSSL; }
+
   /// isBitfield - Determines whether this field is a bitfield.
   bool isBitField() const { return BitWidth != NULL; }
 
index 19f17184185352bc448c7d929390e67c78145ef0..728724f1b3d4da30863c9d9eb9747b45be5e3641 100644 (file)
@@ -149,8 +149,8 @@ BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
 
 FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                              IdentifierInfo *Id, QualType T, Expr *BW,
-                             bool Mutable) {
-  return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable);
+                             bool Mutable, SourceLocation TSSL) {
+  return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable, TSSL);
 }
 
 bool FieldDecl::isAnonymousStructOrUnion() const {
index e11729b6628079d65e68acbed590f864257bd8a9..5fbf2d746208f463ae8dfa89d8f0b0fda5e24097 100644 (file)
@@ -333,6 +333,7 @@ void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
 void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
   VisitValueDecl(FD);
   FD->setMutable(Record[Idx++]);
+  FD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   if (Record[Idx++])
     FD->setBitWidth(Reader.ReadDeclExpr());
 }
@@ -667,7 +668,7 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
     break;
   case pch::DECL_FIELD:
     D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 
-                          false);
+                          false, SourceLocation());
     break;
   case pch::DECL_VAR:
     D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
index 6aed0e900950f3181c2dca9b1ee50375a63689b7..ff5c5761592ca81ff0cbe55acc91ac81d3be0685 100644 (file)
@@ -325,6 +325,7 @@ void PCHDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
 void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) {
   VisitValueDecl(D);
   Record.push_back(D->isMutable());
+  Writer.AddSourceLocation(D->getTypeSpecStartLoc(), Record);
   Record.push_back(D->getBitWidth()? 1 : 0);
   if (D->getBitWidth())
     Writer.AddStmt(D->getBitWidth());
index 844566081629729b088665817bca332998ac45df..4344fde67652a49c2c81bc66cc422b6b1b267e3a 100644 (file)
@@ -541,6 +541,7 @@ public:
   FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, 
                             RecordDecl *Record, SourceLocation Loc,
                             bool Mutable, Expr *BitfieldWidth,
+                            SourceLocation TSSL,
                             AccessSpecifier AS, NamedDecl *PrevDecl,
                             Declarator *D = 0);
   
index c1dcdd6ec030555ba85b9267853c78f4605b77da..d069fb06b9872e86b835fafc9828656a37be3055 100644 (file)
@@ -1268,7 +1268,8 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
     Anon = FieldDecl::Create(Context, OwningClass, Record->getLocation(),
                              /*IdentifierInfo=*/0, 
                              Context.getTypeDeclType(Record),
-                             /*BitWidth=*/0, /*Mutable=*/false);
+                             /*BitWidth=*/0, /*Mutable=*/false,
+                             DS.getSourceRange().getBegin());
     Anon->setAccess(AS_public);
     if (getLangOptions().CPlusPlus)
       FieldCollector->Add(cast<FieldDecl>(Anon));
@@ -3947,10 +3948,12 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
   if (PrevDecl && !isDeclInScope(PrevDecl, Record, S))
     PrevDecl = 0;
 
-  FieldDecl *NewFD 
-    = CheckFieldDecl(II, T, Record, Loc,
-               D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_mutable,
-                     BitWidth, AS, PrevDecl, &D);
+  bool Mutable
+    = (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_mutable);
+  SourceLocation TSSL = D.getSourceRange().getBegin();
+  FieldDecl *NewFD
+    = CheckFieldDecl(II, T, Record, Loc, Mutable, BitWidth, TSSL,
+                     AS, PrevDecl, &D);
   if (NewFD->isInvalidDecl() && PrevDecl) {
     // Don't introduce NewFD into scope; there's already something
     // with the same name in the same scope.
@@ -3975,6 +3978,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
 FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, 
                                 RecordDecl *Record, SourceLocation Loc,
                                 bool Mutable, Expr *BitWidth, 
+                                SourceLocation TSSL,
                                 AccessSpecifier AS, NamedDecl *PrevDecl,
                                 Declarator *D) {
   IdentifierInfo *II = Name.getAsIdentifierInfo();
@@ -4020,7 +4024,7 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
   }
   
   FieldDecl *NewFD = FieldDecl::Create(Context, Record, Loc, II, T, BitWidth,
-                                       Mutable);
+                                       Mutable, TSSL);
   if (InvalidDecl)
     NewFD->setInvalidDecl();
 
index f59719992066606b8ee0e416f779712e6e4fc317..1f5856858042a57a34620a59cecc280a4b8e0970 100644 (file)
@@ -182,6 +182,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
                                             D->getLocation(),
                                             D->isMutable(),
                                             BitWidth,
+                                            D->getTypeSpecStartLoc(),
                                             D->getAccess(),
                                             0);
   if (Field) {