]> granicus.if.org Git - clang/commitdiff
Improve representation of tag declarations first declared or defined
authorDouglas Gregor <dgregor@apple.com>
Fri, 12 Feb 2010 17:40:34 +0000 (17:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 12 Feb 2010 17:40:34 +0000 (17:40 +0000)
within the declarator of another declaration, from Enea Zaffanella!

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

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

index b9c9d9eb2c7c5ee7f883beb692316724bc6d0186..07442896dc4bc466ed7f7dd5dc8a0096553bd707 100644 (file)
@@ -1511,9 +1511,10 @@ private:
   /// it is a declaration ("struct foo;").
   bool IsDefinition : 1;
 
-  /// IsDefinedInDeclarator - True if this tag declaration is
-  /// syntactically defined in a declarator.
-  bool IsDefinedInDeclarator : 1;
+  /// IsEmbeddedInDeclarator - True if this tag declaration is
+  /// "embedded" (i.e., defined or declared for the very first time)
+  /// in the syntax of a declarator,
+  bool IsEmbeddedInDeclarator : 1;
 
   /// TypedefForAnonDecl - If a TagDecl is anonymous and part of a typedef,
   /// this points to the TypedefDecl. Used for mangling.
@@ -1531,7 +1532,7 @@ protected:
     assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
     TagDeclKind = TK;
     IsDefinition = false;
-    IsDefinedInDeclarator = false;
+    IsEmbeddedInDeclarator = false;
     setPreviousDeclaration(PrevDecl);
   }
 
@@ -1565,11 +1566,11 @@ public:
     return IsDefinition;
   }
 
-  bool isDefinedInDeclarator() const {
-    return IsDefinedInDeclarator;
+  bool isEmbeddedInDeclarator() const {
+    return IsEmbeddedInDeclarator;
   }
-  void setDefinedInDeclarator(bool isInDeclarator) {
-    IsDefinedInDeclarator = isInDeclarator;
+  void setEmbeddedInDeclarator(bool isInDeclarator) {
+    IsEmbeddedInDeclarator = isInDeclarator;
   }
 
   /// \brief Whether this declaration declares a type that is
index 6a93e6c265d7d52168f2641ab5cd125e0c5a00c9..625997cac23239a2ea7f80f514b9fedac8b76929 100644 (file)
@@ -117,7 +117,7 @@ void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
                         cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
   TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
   TD->setDefinition(Record[Idx++]);
-  TD->setDefinedInDeclarator(Record[Idx++]);
+  TD->setEmbeddedInDeclarator(Record[Idx++]);
   TD->setTypedefForAnonDecl(
                     cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
   TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
index 1901b2fad6856e0582e7071ed60d8bce172f833e..d105382b4354b3c84fde0a72b7e0c3eba4048521 100644 (file)
@@ -115,7 +115,7 @@ void PCHDeclWriter::VisitTagDecl(TagDecl *D) {
   Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
   Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
   Record.push_back(D->isDefinition());
-  Record.push_back(D->isDefinedInDeclarator());
+  Record.push_back(D->isEmbeddedInDeclarator());
   Writer.AddDeclRef(D->getTypedefForAnonDecl(), Record);
   Writer.AddSourceLocation(D->getRBraceLoc(), Record);
   Writer.AddSourceLocation(D->getTagKeywordLoc(), Record);
index ceec5f226ff32452414a5fd4727a73cb93548b1e..7911e76d446a2d9b0101db275f458362ec54cf7d 100644 (file)
@@ -930,7 +930,10 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
     
     if (!D.isInvalidType() && D.getDeclSpec().isTypeSpecOwned()) {
       TagDecl* Owned = cast<TagDecl>((Decl *)D.getDeclSpec().getTypeRep());
-      Owned->setDefinedInDeclarator(Owned->isDefinition());
+      // Owned is embedded if it was defined here, or if it is the
+      // very first (i.e., canonical) declaration of this tag type.
+      Owned->setEmbeddedInDeclarator(Owned->isDefinition() ||
+                                     Owned->isCanonicalDecl());
       if (OwnedDecl) *OwnedDecl = Owned;
     }
     break;