diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-09-05 01:34:33 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-09-05 01:34:33 +0000 |
| commit | 47923c7e594c9539d5369f293152b93dd0521956 (patch) | |
| tree | bbe8ee4fa74b91e65255d2d5c14e1c9ba573f7fd | |
| parent | 09faf81b6c6507af95ffc134908dc560577cb027 (diff) | |
| download | bcm5719-llvm-47923c7e594c9539d5369f293152b93dd0521956.tar.gz bcm5719-llvm-47923c7e594c9539d5369f293152b93dd0521956.zip | |
Remove "NextDecl" from RecordDecl. This change touches many files that where RecordDecl or CXXRecordDecl was constructed, always with an argument of 'NULL' for the previous declaration.
The motivation behind this change is that chaining the RecordDecls is simply unnecessary. Once we create multiple RecordDecls for the same struct/union/class, clients that care about all the declarations of the same struct can build a back map by seeing which Decls refer to the same RecordType.
llvm-svn: 55821
| -rw-r--r-- | clang/Driver/RewriteObjC.cpp | 12 | ||||
| -rw-r--r-- | clang/include/clang/AST/Decl.h | 23 | ||||
| -rw-r--r-- | clang/include/clang/AST/DeclCXX.h | 8 | ||||
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 43 | ||||
| -rw-r--r-- | clang/lib/AST/DeclCXX.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/AST/DeclSerialization.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/Sema.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 6 |
10 files changed, 28 insertions, 83 deletions
diff --git a/clang/Driver/RewriteObjC.cpp b/clang/Driver/RewriteObjC.cpp index 2f91ea9741b..b078db31844 100644 --- a/clang/Driver/RewriteObjC.cpp +++ b/clang/Driver/RewriteObjC.cpp @@ -880,7 +880,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, RecName += "_IMPL"; IdentifierInfo *II = &Context->Idents.get(RecName.c_str()); RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl, - SourceLocation(), II, 0); + SourceLocation(), II); assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); CastExpr *castExpr = new ExplicitCastExpr(castT, IV->getBase(), @@ -922,7 +922,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, RecName += "_IMPL"; IdentifierInfo *II = &Context->Idents.get(RecName.c_str()); RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl, - SourceLocation(), II, 0); + SourceLocation(), II); assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); CastExpr *castExpr = new ExplicitCastExpr(castT, IV->getBase(), @@ -1795,7 +1795,7 @@ void RewriteObjC::SynthMsgSendSuperFunctionDecl() { llvm::SmallVector<QualType, 16> ArgTys; RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl, SourceLocation(), - &Context->Idents.get("objc_super"), 0); + &Context->Idents.get("objc_super")); QualType argT = Context->getPointerType(Context->getTagDeclType(RD)); assert(!argT.isNull() && "Can't build 'struct objc_super *' type"); ArgTys.push_back(argT); @@ -1838,7 +1838,7 @@ void RewriteObjC::SynthMsgSendSuperStretFunctionDecl() { llvm::SmallVector<QualType, 16> ArgTys; RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl, SourceLocation(), - &Context->Idents.get("objc_super"), 0); + &Context->Idents.get("objc_super")); QualType argT = Context->getPointerType(Context->getTagDeclType(RD)); assert(!argT.isNull() && "Can't build 'struct objc_super *' type"); ArgTys.push_back(argT); @@ -1964,7 +1964,7 @@ QualType RewriteObjC::getSuperStructType() { if (!SuperStructDecl) { SuperStructDecl = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl, SourceLocation(), - &Context->Idents.get("objc_super"), 0); + &Context->Idents.get("objc_super")); QualType FieldTypes[2]; // struct objc_object *receiver; @@ -1987,7 +1987,7 @@ QualType RewriteObjC::getConstantStringStructType() { if (!ConstantStringDecl) { ConstantStringDecl = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl, SourceLocation(), - &Context->Idents.get("__NSConstantStringImpl"), 0); + &Context->Idents.get("__NSConstantStringImpl")); QualType FieldTypes[4]; // struct objc_object *receiver; diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 9688ea3e8cf..0e2db965f99 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -795,38 +795,21 @@ class RecordDecl : public TagDecl { /// array member (e.g. int X[]) or if this union contains a struct that does. /// 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. - /// NOTE: This is *not* an owning reference. - 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, - RecordDecl *PrevDecl); - + RecordDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id); virtual ~RecordDecl(); public: static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, - SourceLocation L, IdentifierInfo *Id, - RecordDecl *PrevDecl); + SourceLocation L, IdentifierInfo *Id); virtual void Destroy(ASTContext& C); - - /// 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; } diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index a4f522eaf5e..614e8ef93c5 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -43,15 +43,13 @@ public: /// The only difference with RecordDecl is that CXXRecordDecl is a DeclContext. class CXXRecordDecl : public RecordDecl, public DeclContext { protected: - CXXRecordDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, - CXXRecordDecl *PrevDecl) : RecordDecl(DK, DC, L, Id, PrevDecl), - DeclContext(DK) { + CXXRecordDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id) + : RecordDecl(DK, DC, L, Id), DeclContext(DK) { assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); } public: static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC, - SourceLocation L, IdentifierInfo *Id, - CXXRecordDecl *PrevDecl); + SourceLocation L, IdentifierInfo *Id); const CXXFieldDecl *getMember(unsigned i) const { return cast<const CXXFieldDecl>(RecordDecl::getMember(i)); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2264bca0f9c..5a6aa1ae312 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1348,7 +1348,7 @@ QualType ASTContext::getCFConstantStringType() { if (!CFConstantStringTypeDecl) { CFConstantStringTypeDecl = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), - &Idents.get("NSConstantString"), 0); + &Idents.get("NSConstantString")); QualType FieldTypes[4]; // const int *isa; @@ -1390,7 +1390,7 @@ QualType ASTContext::getObjCFastEnumerationStateType() ObjCFastEnumerationStateTypeDecl = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), - &Idents.get("__objcFastEnumerationState"), 0); + &Idents.get("__objcFastEnumerationState")); ObjCFastEnumerationStateTypeDecl->defineBody(FieldDecls, 4); } diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 04cec6f66bb..eb9d0efdb48 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -204,36 +204,18 @@ unsigned FunctionDecl::getMinRequiredArguments() const { //===----------------------------------------------------------------------===// RecordDecl::RecordDecl(Kind DK, DeclContext *DC, SourceLocation L, - IdentifierInfo *Id, RecordDecl *PrevDecl) -: TagDecl(DK, DC, L, Id, 0), NextDecl(0) { + IdentifierInfo *Id) +: TagDecl(DK, DC, L, Id, 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->isDefinition() - && "Previous RecordDecl has a NextDecl that is " - "not the 'defining' RecordDecl"); - - NextDecl = Tmp; - } - - PrevDecl->NextDecl = this; - } + NumMembers = -1; } RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, - SourceLocation L, IdentifierInfo *Id, - RecordDecl *PrevDecl) { + SourceLocation L, IdentifierInfo *Id) { + void *Mem = C.getAllocator().Allocate<RecordDecl>(); Kind DK; switch (TK) { @@ -243,7 +225,7 @@ RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, case TK_union: DK = Union; break; case TK_class: DK = Class; break; } - return new (Mem) RecordDecl(DK, DC, L, Id, PrevDecl); + return new (Mem) RecordDecl(DK, DC, L, Id); } RecordDecl::~RecordDecl() { @@ -281,16 +263,3 @@ FieldDecl *RecordDecl::getMember(IdentifierInfo *II) { return Members[i]; return 0; } - -/// 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; -} - diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 2fe69fced52..0cce7db1d68 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -27,8 +27,7 @@ CXXFieldDecl *CXXFieldDecl::Create(ASTContext &C, CXXRecordDecl *RD, }
CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
- SourceLocation L, IdentifierInfo *Id,
- CXXRecordDecl *PrevDecl) {
+ SourceLocation L, IdentifierInfo *Id) {
Kind DK;
switch (TK) {
default: assert(0 && "Invalid TagKind!");
@@ -38,7 +37,7 @@ CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, case TK_class: DK = CXXClass; break;
}
void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
- return new (Mem) CXXRecordDecl(DK, DC, L, Id, PrevDecl);
+ return new (Mem) CXXRecordDecl(DK, DC, L, Id);
}
CXXMethodDecl *
diff --git a/clang/lib/AST/DeclSerialization.cpp b/clang/lib/AST/DeclSerialization.cpp index 82a8fcd0f62..3f36e3ac89d 100644 --- a/clang/lib/AST/DeclSerialization.cpp +++ b/clang/lib/AST/DeclSerialization.cpp @@ -449,7 +449,6 @@ void RecordDecl::EmitImpl(Serializer& S) const { ScopedDecl::EmitInRec(S); S.EmitBool(isDefinition()); S.EmitBool(hasFlexibleArrayMember()); - S.EmitPtr(NextDecl); S.EmitSInt(getNumMembers()); if (getNumMembers() > 0) { assert (Members); @@ -463,12 +462,11 @@ RecordDecl* RecordDecl::CreateImpl(Decl::Kind DK, Deserializer& D, ASTContext& C) { void *Mem = C.getAllocator().Allocate<RecordDecl>(); - RecordDecl* decl = new (Mem) RecordDecl(DK, 0, SourceLocation(), NULL, NULL); + RecordDecl* decl = new (Mem) RecordDecl(DK, 0, SourceLocation(), NULL); decl->ScopedDecl::ReadInRec(D, C); decl->setDefinition(D.ReadBool()); decl->setHasFlexibleArrayMember(D.ReadBool()); - D.ReadPtr(decl->NextDecl); // Allow backpatching. decl->NumMembers = D.ReadSInt(); if (decl->getNumMembers() > 0) { diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 9638bc14308..a535ea254ee 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -1866,7 +1866,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm) // FIXME: Merge with rewriter code? RecordDecl *RD = RecordDecl::Create(Ctx, TagDecl::TK_struct, 0, SourceLocation(), - &Ctx.Idents.get("_objc_super"), 0); + &Ctx.Idents.get("_objc_super")); FieldDecl *FieldDecls[2]; FieldDecls[0] = FieldDecl::Create(Ctx, SourceLocation(), 0, Ctx.getObjCIdType()); diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index b288c627872..9092f83f0a4 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -32,11 +32,11 @@ static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) if (C.getLangOptions().CPlusPlus) return CXXRecordDecl::Create(C, TagDecl::TK_struct, C.getTranslationUnitDecl(), - SourceLocation(), &C.Idents.get(Name), 0); + SourceLocation(), &C.Idents.get(Name)); else return RecordDecl::Create(C, TagDecl::TK_struct, C.getTranslationUnitDecl(), - SourceLocation(), &C.Idents.get(Name), 0); + SourceLocation(), &C.Idents.get(Name)); } void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b45611ca59b..53327e497e5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1765,14 +1765,12 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, // We use 'dyn_cast' instead of 'cast' because PrevDecl might not // be a CXXRecordDecl* if we had a redefinition error. In this case, // the dyn_cast will return a NULL pointer. - New = CXXRecordDecl::Create(Context, Kind, CurContext, Loc, Name, - dyn_cast_or_null<CXXRecordDecl>(PrevDecl)); + New = CXXRecordDecl::Create(Context, Kind, CurContext, Loc, Name); else // We use 'dyn_cast' instead of 'cast' because PrevDecl might not // be a RecordDecl* if we had a redefinition error. In this case, // the dyn_cast will return a NULL pointer. - New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name, - dyn_cast_or_null<RecordDecl>(PrevDecl)); + New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name); } // If this has an identifier, add it to the scope stack. |

