diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-09-02 20:13:32 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-09-02 20:13:32 +0000 |
commit | df91eca19bd9738abd9a3b84791f39750e27ad36 (patch) | |
tree | 85318f27df0ad31bdcba99303cfabbb3a9a66089 /lib/AST/Decl.cpp | |
parent | b4eaf9cf5f79c86a3f7564f4dfdea57f165ca45c (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55640 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 3cc12c9a86..c2ae5d91ab 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -109,9 +109,45 @@ EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, 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 @@ RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, 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, |