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

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


Author: kremenek
Date: Tue Sep  2 15:25:22 2008
New Revision: 55642

URL: http://llvm.org/viewvc/llvm-project?rev=55642&view=rev
Log:
RecordDecl:
- Added method 'isForwardDeclaration', a predicate method that returns true
  if a RecordDecl represents a forward declaration.
- Added method 'getDefinitionDecl', a query method that returns a pointer to
  the RecordDecl that provides the actual definition of a struct/union.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Sep  2 15:25:22 2008
@@ -802,6 +802,7 @@
   ///  (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.
+  ///  NOTE: This is *not* an owning reference.
   RecordDecl* NextDecl;
   
   /// Members/NumMembers - This is a new[]'d array of pointers to Decls.
@@ -821,6 +822,18 @@
 
   virtual void Destroy(ASTContext& C);
   
+  /// isForwardDeclaration - Returns true if this RecordDecl represents a
+  ///  forward declaration.
+  bool isForwardDeclaration() const {
+    assert ((!Members || NextDecl == 0) && "(Members != 0) => (NextDecl == 0)");
+    return !Members;
+  }
+  
+  /// getDefinitionDecl - Returns the RecordDecl for the struct/union that
+  ///  represents the actual definition (i.e., not a forward declaration).
+  ///  This method returns NULL if no such RecordDecl exists.
+  const RecordDecl* getDefinitionDecl() const;  
+  
   bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
   void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
   

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

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Sep  2 15:25:22 2008
@@ -160,6 +160,18 @@
   return new (Mem) RecordDecl(DK, DC, L, Id, PrevDecl);
 }
 
+/// getDefinitionDecl - Returns the RecordDecl for the struct/union that
+///  represents the actual definition (i.e., not a forward declaration).
+///  This method returns NULL if no such RecordDecl exists.
+const RecordDecl* RecordDecl::getDefinitionDecl() const {
+  const RecordDecl* R = this;
+  
+  for (RecordDecl* N = R->NextDecl; N; N = R->NextDecl)
+    R = N;
+  
+  return R->Members ? R : 0;
+}
+
 
 FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C,
                                            SourceLocation L,





More information about the cfe-commits mailing list