]> granicus.if.org Git - clang/commitdiff
RecordDecl:
authorTed Kremenek <kremenek@apple.com>
Tue, 2 Sep 2008 20:25:22 +0000 (20:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 2 Sep 2008 20:25:22 +0000 (20:25 +0000)
- 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.

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

include/clang/AST/Decl.h
lib/AST/Decl.cpp

index eda74f399f21da134c534c1853e077cf077d3ec4..28d7a57366b0745401e19b7dda1de1c4cdff97a2 100644 (file)
@@ -802,6 +802,7 @@ class RecordDecl : public TagDecl {
   ///  (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 @@ public:
 
   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; }
   
index c2ae5d91ab69b4f4fd4ee33788011bd69245ceff..4b4aa65f90313e233e8d01ea81ba12b428afdbe7 100644 (file)
@@ -160,6 +160,18 @@ RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
   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,