[cfe-commits] r76576 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclCXX.h lib/AST/Decl.cpp lib/AST/DeclCXX.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp

Douglas Gregor dgregor at apple.com
Tue Jul 21 07:46:34 PDT 2009


Author: dgregor
Date: Tue Jul 21 09:46:17 2009
New Revision: 76576

URL: http://llvm.org/viewvc/llvm-project?rev=76576&view=rev
Log:
Add the location of the tag keyword into TagDecl. From Enea
Zaffanella, with tweaks from Abramo Bagnara.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=76576&r1=76575&r2=76576&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Jul 21 09:46:17 2009
@@ -1176,12 +1176,14 @@
   /// this points to the TypedefDecl. Used for mangling.
   TypedefDecl *TypedefForAnonDecl;
 
+  SourceLocation TagKeywordLoc;
   SourceLocation RBraceLoc;
 
 protected:
   TagDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
-          IdentifierInfo *Id)
-    : TypeDecl(DK, DC, L, Id), DeclContext(DK), TypedefForAnonDecl(0) {
+          IdentifierInfo *Id, SourceLocation TKL = SourceLocation())
+    : TypeDecl(DK, DC, L, Id), DeclContext(DK), TypedefForAnonDecl(0),
+      TagKeywordLoc(TKL) {
     assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
     TagDeclKind = TK;
     IsDefinition = false;
@@ -1191,6 +1193,9 @@
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
 
+  SourceLocation getTagKeywordLoc() const { return TagKeywordLoc; }
+  void setTagKeywordLoc(SourceLocation TKL) { TagKeywordLoc = TKL; }
+
   virtual SourceRange getSourceRange() const;
   
   virtual TagDecl* getCanonicalDecl();
@@ -1278,14 +1283,14 @@
   EnumDecl *InstantiatedFrom;
 
   EnumDecl(DeclContext *DC, SourceLocation L,
-           IdentifierInfo *Id)
-    : TagDecl(Enum, TK_enum, DC, L, Id), InstantiatedFrom(0) {
+           IdentifierInfo *Id, SourceLocation TKL)
+    : TagDecl(Enum, TK_enum, DC, L, Id, TKL), InstantiatedFrom(0) {
       IntegerType = QualType();
     }
 public:
   static EnumDecl *Create(ASTContext &C, DeclContext *DC,
                           SourceLocation L, IdentifierInfo *Id,
-                          EnumDecl *PrevDecl);
+                          SourceLocation TKL, EnumDecl *PrevDecl);
   
   virtual void Destroy(ASTContext& C);
 
@@ -1351,12 +1356,13 @@
 
 protected:
   RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
-             SourceLocation L, IdentifierInfo *Id);
+             SourceLocation L, IdentifierInfo *Id, SourceLocation TKL);
   virtual ~RecordDecl();
 
 public:
   static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
                             SourceLocation L, IdentifierInfo *Id,
+                            SourceLocation TKL = SourceLocation(),
                             RecordDecl* PrevDecl = 0);
 
   virtual void Destroy(ASTContext& C);

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=76576&r1=76575&r2=76576&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Jul 21 09:46:17 2009
@@ -335,7 +335,8 @@
 
 protected:
   CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
-                SourceLocation L, IdentifierInfo *Id);
+                SourceLocation L, IdentifierInfo *Id,
+                SourceLocation TKL = SourceLocation());
 
   ~CXXRecordDecl();
 
@@ -350,6 +351,7 @@
 
   static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
                                SourceLocation L, IdentifierInfo *Id,
+                               SourceLocation TKL = SourceLocation(),
                                CXXRecordDecl* PrevDecl=0,
                                bool DelayTypeCreation = false);
   

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=76576&r1=76575&r2=76576&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Jul 21 09:46:17 2009
@@ -182,9 +182,9 @@
 }
 
 EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
-                           IdentifierInfo *Id,
+                           IdentifierInfo *Id, SourceLocation TKL,
                            EnumDecl *PrevDecl) {
-  EnumDecl *Enum = new (C) EnumDecl(DC, L, Id);
+  EnumDecl *Enum = new (C) EnumDecl(DC, L, Id, TKL);
   C.getTypeDeclType(Enum, PrevDecl);
   return Enum;
 }
@@ -654,7 +654,7 @@
 
 SourceRange TagDecl::getSourceRange() const {
   SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation();
-  return SourceRange(getLocation(), E);
+  return SourceRange(TagKeywordLoc, E);
 }
 
 TagDecl* TagDecl::getCanonicalDecl() {
@@ -692,8 +692,8 @@
 //===----------------------------------------------------------------------===//
 
 RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
-                       IdentifierInfo *Id)
-  : TagDecl(DK, TK, DC, L, Id) {
+                       IdentifierInfo *Id, SourceLocation TKL)
+  : TagDecl(DK, TK, DC, L, Id, TKL) {
   HasFlexibleArrayMember = false;
   AnonymousStructOrUnion = false;
   HasObjectMember = false;
@@ -702,9 +702,9 @@
 
 RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
                                SourceLocation L, IdentifierInfo *Id,
-                               RecordDecl* PrevDecl) {
+                               SourceLocation TKL, RecordDecl* PrevDecl) {
   
-  RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id);
+  RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id, TKL);
   C.getTypeDeclType(R, PrevDecl);
   return R;
 }

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=76576&r1=76575&r2=76576&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Tue Jul 21 09:46:17 2009
@@ -24,8 +24,9 @@
 //===----------------------------------------------------------------------===//
 
 CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
-                             SourceLocation L, IdentifierInfo *Id) 
-  : RecordDecl(K, TK, DC, L, Id),
+                             SourceLocation L, IdentifierInfo *Id,
+                             SourceLocation TKL) 
+  : RecordDecl(K, TK, DC, L, Id, TKL),
     UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
     UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false),
     Aggregate(true), PlainOldData(true), Polymorphic(false), Abstract(false),
@@ -36,9 +37,10 @@
 
 CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
                                      SourceLocation L, IdentifierInfo *Id,
+                                     SourceLocation TKL,
                                      CXXRecordDecl* PrevDecl,
                                      bool DelayTypeCreation) {
-  CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id);
+  CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id, TKL);
   if (!DelayTypeCreation)
     C.getTypeDeclType(R, PrevDecl);  
   return R;

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=76576&r1=76575&r2=76576&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Tue Jul 21 09:46:17 2009
@@ -117,6 +117,7 @@
   TD->setTypedefForAnonDecl(
                     cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
   TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
 
 void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
@@ -607,11 +608,11 @@
     D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
     break;
   case pch::DECL_ENUM:
-    D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, 0);
+    D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
     break;
   case pch::DECL_RECORD:
     D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
-                           0, 0);
+                           0, SourceLocation(), 0);
     break;
   case pch::DECL_ENUM_CONSTANT:
     D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=76576&r1=76575&r2=76576&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Tue Jul 21 09:46:17 2009
@@ -113,6 +113,7 @@
   Record.push_back(D->isDefinition());
   Writer.AddDeclRef(D->getTypedefForAnonDecl(), Record);
   Writer.AddSourceLocation(D->getRBraceLoc(), Record);
+  Writer.AddSourceLocation(D->getTagKeywordLoc(), Record);
 }
 
 void PCHDeclWriter::VisitEnumDecl(EnumDecl *D) {

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jul 21 09:46:17 2009
@@ -3711,7 +3711,7 @@
   if (Kind == TagDecl::TK_enum) {
     // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
     // enum X { A, B, C } D;    D should chain to X.
-    New = EnumDecl::Create(Context, SearchDC, Loc, Name, 
+    New = EnumDecl::Create(Context, SearchDC, Loc, Name, KWLoc,
                            cast_or_null<EnumDecl>(PrevDecl));
     // If this is an undefined enum, warn.
     if (TK != TK_Definition && !Invalid)  {
@@ -3726,10 +3726,10 @@
     // struct X { int A; } D;    D should chain to X.
     if (getLangOptions().CPlusPlus)
       // FIXME: Look for a way to use RecordDecl for simple structs.
-      New = CXXRecordDecl::Create(Context, Kind, SearchDC, Loc, Name,
+      New = CXXRecordDecl::Create(Context, Kind, SearchDC, Loc, Name, KWLoc,
                                   cast_or_null<CXXRecordDecl>(PrevDecl));
     else
-      New = RecordDecl::Create(Context, Kind, SearchDC, Loc, Name,
+      New = RecordDecl::Create(Context, Kind, SearchDC, Loc, Name, KWLoc,
                                cast_or_null<RecordDecl>(PrevDecl));
   }
 
@@ -3831,7 +3831,9 @@
       CXXRecordDecl *InjectedClassName
         = CXXRecordDecl::Create(Context, Record->getTagKind(),
                                 CurContext, Record->getLocation(),
-                                Record->getIdentifier(), Record);
+                                Record->getIdentifier(),
+                                Record->getTagKeywordLoc(),
+                                Record);
       InjectedClassName->setImplicit();
       InjectedClassName->setAccess(AS_public);
       if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate())

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Jul 21 09:46:17 2009
@@ -522,7 +522,7 @@
   // declaration!
 
   CXXRecordDecl *NewClass = 
-    CXXRecordDecl::Create(Context, Kind, SemanticContext, NameLoc, Name,
+    CXXRecordDecl::Create(Context, Kind, SemanticContext, NameLoc, Name, KWLoc,
                           PrevClassTemplate? 
                             PrevClassTemplate->getTemplatedDecl() : 0,
                           /*DelayTypeCreation=*/true);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Jul 21 09:46:17 2009
@@ -217,6 +217,7 @@
 Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
   EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, 
                                     D->getLocation(), D->getIdentifier(),
+                                    D->getTagKeywordLoc(),
                                     /*PrevDecl=*/0);
   Enum->setInstantiationOfMemberEnum(D);
   Enum->setAccess(D->getAccess());
@@ -284,7 +285,8 @@
 
   CXXRecordDecl *Record
     = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner, 
-                            D->getLocation(), D->getIdentifier(), PrevDecl);
+                            D->getLocation(), D->getIdentifier(),
+                            D->getTagKeywordLoc(), PrevDecl);
   Record->setImplicit(D->isImplicit());
   Record->setAccess(D->getAccess());
   if (!D->isInjectedClassName())





More information about the cfe-commits mailing list