[cfe-commits] r55640 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclCXX.h lib/AST/Decl.cpp lib/AST/DeclCXX.cpp

Ted Kremenek kremenek at apple.com
Tue Sep 2 13:13:33 PDT 2008


Author: kremenek
Date: Tue Sep  2 15:13:32 2008
New Revision: 55640

URL: http://llvm.org/viewvc/llvm-project?rev=55640&view=rev
Log:
CXXRecordDecl and RecordDecl:
- Change constructor and create methods to accept a CXXRecordDecl* (RecordDecl*)
  instead of a ScopedDecl* for PrevDecl.  This causes the type checking
  to be more tight and doesn't break any code.
  
RecordDecl:

- Don't use the NextDeclarator field in ScopedDecl to represent the previous
  declaration. This is a conflated use of the NextDeclarator field, which will
  be removed anyway when DeclGroups are fully implemented.

- Instead, represent (a soon to be implemented) chain of RecordDecls using a
  NextDecl field.  The last RecordDecl in the chain is always the 'defining'
  RecordDecl that owns the FieldDecls.  The other RecordDecls in the chain
  are forward declarations.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Sep  2 15:13:32 2008
@@ -796,25 +796,28 @@
   /// If so, this cannot be contained in arrays or other structs as a member.
   bool HasFlexibleArrayMember : 1;
 
+  /// NextDecl - A pointer to the next RecordDecl in a chain of RecordDecls
+  ///  for the same struct/union.  By construction, the last RecordDecl in
+  ///  the chain is the one that provides the definition of the struct/union
+  ///  (i.e., all forward declarations appear first in the chain).  Note that
+  ///  one should make no other assumption about the order of the RecordDecl's
+  ///  within this chain with respect to the original source.
+  RecordDecl* NextDecl;
+  
   /// Members/NumMembers - This is a new[]'d array of pointers to Decls.
   FieldDecl **Members;   // Null if not defined.
   int NumMembers;   // -1 if not defined.
 
 protected:
   RecordDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 
-             ScopedDecl *PrevDecl) : TagDecl(DK, DC, L, Id, PrevDecl) {
-    HasFlexibleArrayMember = false;
-    assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
-    Members = 0;
-    NumMembers = -1;
-  }
+             RecordDecl *PrevDecl);
 
   virtual ~RecordDecl();
 
 public:
   static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
                             SourceLocation L, IdentifierInfo *Id,
-                            ScopedDecl *PrevDecl);
+                            RecordDecl *PrevDecl);
 
   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=55640&r1=55639&r2=55640&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Sep  2 15:13:32 2008
@@ -44,14 +44,14 @@
 class CXXRecordDecl : public RecordDecl, public DeclContext {
 protected:
   CXXRecordDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
-             ScopedDecl *PrevDecl) : RecordDecl(DK, DC, L, Id, PrevDecl),
+             CXXRecordDecl *PrevDecl) : RecordDecl(DK, DC, L, Id, PrevDecl),
                                      DeclContext(DK) {
     assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
   }
 public:
   static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
-                            SourceLocation L, IdentifierInfo *Id,
-                            ScopedDecl *PrevDecl);
+                               SourceLocation L, IdentifierInfo *Id,
+                               CXXRecordDecl *PrevDecl);
   
   const CXXFieldDecl *getMember(unsigned i) const {
     return cast<const CXXFieldDecl>(RecordDecl::getMember(i));

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

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Sep  2 15:13:32 2008
@@ -109,9 +109,45 @@
   return new (Mem) EnumDecl(DC, L, Id, PrevDecl);
 }
 
+void EnumDecl::Destroy(ASTContext& C) {
+  if (getEnumConstantList()) getEnumConstantList()->Destroy(C);
+  Decl::Destroy(C);
+}
+
+//==------------------------------------------------------------------------==//
+// RecordDecl methods.
+//==------------------------------------------------------------------------==//
+
+RecordDecl::RecordDecl(Kind DK, DeclContext *DC, SourceLocation L,
+                       IdentifierInfo *Id, RecordDecl *PrevDecl)
+  : TagDecl(DK, DC, L, Id, 0), NextDecl(0) {
+    
+  HasFlexibleArrayMember = false;
+  assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
+  Members = 0;
+  NumMembers = -1;
+    
+  // Hook up the RecordDecl chain.
+  if (PrevDecl) {
+    RecordDecl* Tmp = PrevDecl->NextDecl;    
+    // 'Tmp' might be non-NULL if it is the RecordDecl that provides the
+    // definition of the struct/union. By construction, the last RecordDecl
+    // in the chain is the 'defining' RecordDecl.
+    if (Tmp) { 
+      assert (Tmp->NextDecl == 0);
+      assert (Tmp->Members && "Previous RecordDecl has a NextDecl that is "
+                              "not the 'defining' RecordDecl");
+      
+      NextDecl = Tmp;
+    }
+
+    PrevDecl->NextDecl = this;
+  }
+}
+
 RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
                                SourceLocation L, IdentifierInfo *Id,
-                               ScopedDecl *PrevDecl) {
+                               RecordDecl *PrevDecl) {
   void *Mem = C.getAllocator().Allocate<RecordDecl>();
   Kind DK;
   switch (TK) {
@@ -124,11 +160,6 @@
   return new (Mem) RecordDecl(DK, DC, L, Id, PrevDecl);
 }
 
-void EnumDecl::Destroy(ASTContext& C) {
-  if (getEnumConstantList()) getEnumConstantList()->Destroy(C);
-  Decl::Destroy(C);
-}
-
 
 FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C,
                                            SourceLocation L,

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

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Tue Sep  2 15:13:32 2008
@@ -28,7 +28,7 @@
 
 CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
                                      SourceLocation L, IdentifierInfo *Id,
-                                     ScopedDecl *PrevDecl) {
+                                     CXXRecordDecl *PrevDecl) {
   Kind DK;
   switch (TK) {
     default: assert(0 && "Invalid TagKind!");





More information about the cfe-commits mailing list