diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-01-20 01:17:11 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-01-20 01:17:11 +0000 |
commit | 4afa39deaa245592977136d367251ee2c173dd8d (patch) | |
tree | b147c76b69b1dc48d42e3cc3080554515db96d94 /lib | |
parent | f4f6f219423a67a969de7b3e0c28bcefdb3c0a10 (diff) |
Remove ScopedDecl, collapsing all of its functionality into Decl, so
that every declaration lives inside a DeclContext.
Moved several things that don't have names but were ScopedDecls (and,
therefore, NamedDecls) to inherit from Decl rather than NamedDecl,
including ObjCImplementationDecl and LinkageSpecDecl. Now, we don't
store empty DeclarationNames for these things, nor do we try to insert
them into DeclContext's lookup structure.
The serialization tests are temporarily disabled. We'll re-enable them
once we've sorted out the remaining ownership/serialiazation issues
between DeclContexts and TranslationUnion, DeclGroups, etc.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/ASTContext.cpp | 6 | ||||
-rw-r--r-- | lib/AST/CFG.cpp | 10 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 77 | ||||
-rw-r--r-- | lib/AST/DeclBase.cpp | 94 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 10 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 7 | ||||
-rw-r--r-- | lib/AST/DeclSerialization.cpp | 256 | ||||
-rw-r--r-- | lib/AST/StmtDumper.cpp | 2 | ||||
-rw-r--r-- | lib/AST/StmtIterator.cpp | 2 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 10 | ||||
-rw-r--r-- | lib/AST/StmtSerialization.cpp | 38 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CGObjC.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/ModuleBuilder.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/IdentifierResolver.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/IdentifierResolver.h | 6 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 27 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 95 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 15 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 12 |
27 files changed, 305 insertions, 450 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 192c06868d..057dfb7bcf 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -537,7 +537,7 @@ const RecordDecl *ASTContext::addRecordToClass(const ObjCInterfaceDecl *D) RecFields[i]->getLocation(), RecFields[i]->getIdentifier(), RecFields[i]->getType(), - RecFields[i]->getBitWidth(), false, 0); + RecFields[i]->getBitWidth(), false); NewRD->addDecl(Field); } NewRD->completeDefinition(*this); @@ -1586,7 +1586,7 @@ QualType ASTContext::getCFConstantStringType() { FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, SourceLocation(), 0, FieldTypes[i], /*BitWidth=*/0, - /*Mutable=*/false, /*PrevDecl=*/0); + /*Mutable=*/false); CFConstantStringTypeDecl->addDecl(Field); } @@ -1616,7 +1616,7 @@ QualType ASTContext::getObjCFastEnumerationStateType() ObjCFastEnumerationStateTypeDecl, SourceLocation(), 0, FieldTypes[i], /*BitWidth=*/0, - /*Mutable=*/false, /*PrevDecl=*/0); + /*Mutable=*/false); ObjCFastEnumerationStateTypeDecl->addDecl(Field); } diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp index b84ead763f..2ea8388287 100644 --- a/lib/AST/CFG.cpp +++ b/lib/AST/CFG.cpp @@ -42,7 +42,7 @@ struct VISIBILITY_HIDDEN SaveAndRestore { T old_value; }; -static SourceLocation GetEndLoc(ScopedDecl* D) { +static SourceLocation GetEndLoc(Decl* D) { if (VarDecl* VD = dyn_cast<VarDecl>(D)) if (Expr* Ex = VD->getInit()) return Ex->getSourceRange().getEnd(); @@ -150,7 +150,7 @@ private: CFGBlock* addStmt(Stmt* Terminator); CFGBlock* WalkAST(Stmt* Terminator, bool AlwaysAddStmt); CFGBlock* WalkAST_VisitChildren(Stmt* Terminator); - CFGBlock* WalkAST_VisitDeclSubExpr(ScopedDecl* D); + CFGBlock* WalkAST_VisitDeclSubExpr(Decl* D); CFGBlock* WalkAST_VisitStmtExpr(StmtExpr* Terminator); void FinishBlock(CFGBlock* B); @@ -363,7 +363,7 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) { return WalkAST_VisitDeclSubExpr(DS->getSolitaryDecl()); } else { - typedef llvm::SmallVector<ScopedDecl*,10> BufTy; + typedef llvm::SmallVector<Decl*,10> BufTy; BufTy Buf; CFGBlock* B = 0; @@ -384,7 +384,7 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) { // that Decl* will not get deallocated because the destroy method // of DG is never called. DeclGroupOwningRef DG(*I); - ScopedDecl* D = *I; + Decl* D = *I; void* Mem = cfg->getAllocator().Allocate(sizeof(DeclStmt), A); DeclStmt* DS = new (Mem) DeclStmt(DG, D->getLocation(), @@ -486,7 +486,7 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) { /// WalkAST_VisitDeclSubExpr - Utility method to add block-level expressions /// for initializers in Decls. -CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(ScopedDecl* D) { +CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(Decl* D) { VarDecl* VD = dyn_cast<VarDecl>(D); if (!VD) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 5ec6aff4f5..9ddc62a51e 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -44,17 +44,17 @@ void NamespaceDecl::Destroy(ASTContext& C) { ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, - SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl) { + SourceLocation L, IdentifierInfo *Id, QualType T) { void *Mem = C.getAllocator().Allocate<ImplicitParamDecl>(); - return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T, PrevDecl); + return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T); } ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, - Expr *DefArg, ScopedDecl *PrevDecl) { + Expr *DefArg) { void *Mem = C.getAllocator().Allocate<ParmVarDecl>(); - return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg, PrevDecl); + return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg); } QualType ParmVarDecl::getOriginalType() const { @@ -68,20 +68,18 @@ ParmVarWithOriginalTypeDecl *ParmVarWithOriginalTypeDecl::Create( ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, QualType OT, StorageClass S, - Expr *DefArg, ScopedDecl *PrevDecl) { + Expr *DefArg) { void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>(); - return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, - DefArg, PrevDecl); + return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, DefArg); } FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, StorageClass S, bool isInline, - ScopedDecl *PrevDecl, SourceLocation TypeSpecStartLoc) { void *Mem = C.getAllocator().Allocate<FunctionDecl>(); - return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, PrevDecl, + return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, TypeSpecStartLoc); } @@ -92,9 +90,9 @@ BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW, - bool Mutable, ScopedDecl *PrevDecl) { + bool Mutable) { void *Mem = C.getAllocator().Allocate<FieldDecl>(); - return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable, PrevDecl); + return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable); } bool FieldDecl::isAnonymousStructOrUnion() const { @@ -110,10 +108,9 @@ bool FieldDecl::isAnonymousStructOrUnion() const { EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, SourceLocation L, IdentifierInfo *Id, QualType T, - Expr *E, const llvm::APSInt &V, - ScopedDecl *PrevDecl){ + Expr *E, const llvm::APSInt &V) { void *Mem = C.getAllocator().Allocate<EnumConstantDecl>(); - return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V, PrevDecl); + return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V); } void EnumConstantDecl::Destroy(ASTContext& C) { @@ -123,17 +120,16 @@ void EnumConstantDecl::Destroy(ASTContext& C) { TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, - IdentifierInfo *Id, QualType T, - ScopedDecl *PD) { + IdentifierInfo *Id, QualType T) { void *Mem = C.getAllocator().Allocate<TypedefDecl>(); - return new (Mem) TypedefDecl(DC, L, Id, T, PD); + return new (Mem) TypedefDecl(DC, L, Id, T); } EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, EnumDecl *PrevDecl) { void *Mem = C.getAllocator().Allocate<EnumDecl>(); - EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id, 0); + EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id); C.getTypeDeclType(Enum, PrevDecl); return Enum; } @@ -148,44 +144,18 @@ void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) { TagDecl::completeDefinition(); } -FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, +FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, StringLiteral *Str) { void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>(); - return new (Mem) FileScopeAsmDecl(L, Str); + return new (Mem) FileScopeAsmDecl(DC, L, Str); } //===----------------------------------------------------------------------===// -// ScopedDecl Implementation +// NamedDecl Implementation //===----------------------------------------------------------------------===// -void ScopedDecl::setDeclContext(DeclContext *DC) { - if (isOutOfSemaDC()) - delete getMultipleDC(); - - DeclCtx = reinterpret_cast<uintptr_t>(DC); -} - -void ScopedDecl::setLexicalDeclContext(DeclContext *DC) { - if (DC == getLexicalDeclContext()) - return; - - if (isInSemaDC()) { - MultipleDC *MDC = new MultipleDC(); - MDC->SemanticDC = getDeclContext(); - MDC->LexicalDC = DC; - DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1; - } else { - getMultipleDC()->LexicalDC = DC; - } -} - -ScopedDecl::~ScopedDecl() { - if (isOutOfSemaDC()) - delete getMultipleDC(); -} - -bool ScopedDecl::declarationReplaces(NamedDecl *OldD) const { +bool NamedDecl::declarationReplaces(NamedDecl *OldD) const { assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) @@ -198,17 +168,16 @@ bool ScopedDecl::declarationReplaces(NamedDecl *OldD) const { return this->getKind() == OldD->getKind(); } + //===----------------------------------------------------------------------===// // VarDecl Implementation //===----------------------------------------------------------------------===// -VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, - SourceLocation L, - IdentifierInfo *Id, QualType T, - StorageClass S, ScopedDecl *PrevDecl, +VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, + IdentifierInfo *Id, QualType T, StorageClass S, SourceLocation TypeSpecStartLoc) { void *Mem = C.getAllocator().Allocate<VarDecl>(); - return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc); + return new (Mem) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc); } void VarDecl::Destroy(ASTContext& C) { @@ -330,7 +299,7 @@ TagDecl* TagDecl::getDefinition(ASTContext& C) const { RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id) - : TagDecl(DK, TK, DC, L, Id, 0) { + : TagDecl(DK, TK, DC, L, Id) { HasFlexibleArrayMember = false; AnonymousStructOrUnion = false; assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 28656873ab..70792c4efd 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -262,8 +262,32 @@ void Decl::addDeclKind(Kind k) { // Decl Implementation //===----------------------------------------------------------------------===// +void Decl::setDeclContext(DeclContext *DC) { + if (isOutOfSemaDC()) + delete getMultipleDC(); + + DeclCtx = reinterpret_cast<uintptr_t>(DC); +} + +void Decl::setLexicalDeclContext(DeclContext *DC) { + if (DC == getLexicalDeclContext()) + return; + + if (isInSemaDC()) { + MultipleDC *MDC = new MultipleDC(); + MDC->SemanticDC = getDeclContext(); + MDC->LexicalDC = DC; + DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1; + } else { + getMultipleDC()->LexicalDC = DC; + } +} + // Out-of-line virtual method providing a home for Decl. Decl::~Decl() { + if (isOutOfSemaDC()) + delete getMultipleDC(); + if (!HasAttrs) return; @@ -336,20 +360,18 @@ void Decl::Destroy(ASTContext& C) { #if 0 // FIXME: This causes double-destroys in some cases, so it is // disabled at the moment. - if (ScopedDecl* SD = dyn_cast<ScopedDecl>(this)) { - // Observe the unrolled recursion. By setting N->NextDeclarator = 0x0 - // within the loop, only the Destroy method for the first ScopedDecl - // will deallocate all of the ScopedDecls in a chain. - - ScopedDecl* N = SD->getNextDeclarator(); - - while (N) { - ScopedDecl* Tmp = N->getNextDeclarator(); - N->NextDeclarator = 0x0; - N->Destroy(C); - N = Tmp; - } + // Observe the unrolled recursion. By setting N->NextDeclarator = 0x0 + // within the loop, only the Destroy method for the first Decl + // will deallocate all of the Decls in a chain. + + Decl* N = SD->getNextDeclarator(); + + while (N) { + Decl* Tmp = N->getNextDeclarator(); + N->NextDeclarator = 0x0; + N->Destroy(C); + N = Tmp; } #endif @@ -370,17 +392,16 @@ DeclContext *Decl::castToDeclContext(const Decl *D) { //===----------------------------------------------------------------------===// const DeclContext *DeclContext::getParent() const { - if (const ScopedDecl *SD = dyn_cast<ScopedDecl>(this)) - return SD->getDeclContext(); - else if (const BlockDecl *BD = dyn_cast<BlockDecl>(this)) - return BD->getParentContext(); - else - return NULL; + if (const Decl *D = dyn_cast<Decl>(this)) + return D->getDeclContext(); + + return NULL; } const DeclContext *DeclContext::getLexicalParent() const { - if (const ScopedDecl *SD = dyn_cast<ScopedDecl>(this)) - return SD->getLexicalDeclContext(); + if (const Decl *D = dyn_cast<Decl>(this)) + return D->getLexicalDeclContext(); + return getParent(); } @@ -391,7 +412,7 @@ const DeclContext *DeclContext::getLexicalParent() const { // implemented in terms of DenseMap anyway. However, this data // structure is really space-inefficient, so we'll have to do // something. -typedef llvm::DenseMap<DeclarationName, std::vector<ScopedDecl*> > +typedef llvm::DenseMap<DeclarationName, std::vector<NamedDecl*> > StoredDeclsMap; DeclContext::~DeclContext() { @@ -400,7 +421,7 @@ DeclContext::~DeclContext() { StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(LookupPtr.getPointer()); delete Map; } else { - ScopedDecl **Array = static_cast<ScopedDecl**>(LookupPtr.getPointer()); + NamedDecl **Array = static_cast<NamedDecl**>(LookupPtr.getPointer()); delete [] Array; } } @@ -500,7 +521,7 @@ DeclContext *DeclContext::getNextContext() { } } -void DeclContext::addDecl(ScopedDecl *D) { +void DeclContext::addDecl(Decl *D) { assert(D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"); assert(!D->NextDeclInScope && D != LastDecl && "Decl already inserted into a DeclContext"); @@ -511,7 +532,9 @@ void DeclContext::addDecl(ScopedDecl *D) { } else { FirstDecl = LastDecl = D; } - D->getDeclContext()->insert(D); + + if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) + ND->getDeclContext()->insert(ND); } /// buildLookup - Build the lookup data structure with all of the @@ -522,7 +545,8 @@ void DeclContext::buildLookup(DeclContext *DCtx) { for (decl_iterator D = DCtx->decls_begin(), DEnd = DCtx->decls_end(); D != DEnd; ++D) { // Insert this declaration into the lookup structure - insertImpl(*D); + if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) + insertImpl(ND); // If this declaration is itself a transparent declaration context, // add its members (recursively). @@ -556,7 +580,7 @@ DeclContext::lookup(DeclarationName Name) { // We have a small array. Look into it. unsigned Size = LookupPtr.getInt(); - ScopedDecl **Array = static_cast<ScopedDecl**>(LookupPtr.getPointer()); + NamedDecl **Array = static_cast<NamedDecl**>(LookupPtr.getPointer()); for (unsigned Idx = 0; Idx != Size; ++Idx) if (Array[Idx]->getDeclName() == Name) { unsigned Last = Idx + 1; @@ -581,7 +605,7 @@ const DeclContext *DeclContext::getLookupContext() const { return Ctx; } -void DeclContext::insert(ScopedDecl *D) { +void DeclContext::insert(NamedDecl *D) { DeclContext *PrimaryContext = getPrimaryContext(); if (PrimaryContext != this) { PrimaryContext->insert(D); @@ -600,7 +624,7 @@ void DeclContext::insert(ScopedDecl *D) { getParent()->insert(D); } -void DeclContext::insertImpl(ScopedDecl *D) { +void DeclContext::insertImpl(NamedDecl *D) { // Skip unnamed declarations. if (!D->getDeclName()) return; @@ -612,12 +636,12 @@ void DeclContext::insertImpl(ScopedDecl *D) { // The lookup data is stored as an array. Search through the array // to find the insertion location. - ScopedDecl **Array; + NamedDecl **Array; if (Size == 0) { - Array = new ScopedDecl*[LookupIsMap - 1]; + Array = new NamedDecl*[LookupIsMap - 1]; LookupPtr.setPointer(Array); } else { - Array = static_cast<ScopedDecl **>(LookupPtr.getPointer()); + Array = static_cast<NamedDecl **>(LookupPtr.getPointer()); } // We always keep declarations of the same name next to each other @@ -688,9 +712,9 @@ void DeclContext::insertImpl(ScopedDecl *D) { if (Pos != Map->end()) { if (MayBeRedeclaration) { // Determine if this declaration is actually a redeclaration. - std::vector<ScopedDecl *>::iterator Redecl + std::vector<NamedDecl *>::iterator Redecl = std::find_if(Pos->second.begin(), Pos->second.end(), - std::bind1st(std::mem_fun(&ScopedDecl::declarationReplaces), + std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces), D)); if (Redecl != Pos->second.end()) { *Redecl = D; @@ -702,7 +726,7 @@ void DeclContext::insertImpl(ScopedDecl *D) { if (D->getIdentifierNamespace() == Decl::IDNS_Tag || Pos->second.empty()) Pos->second.push_back(D); else if (Pos->second.back()->getIdentifierNamespace() == Decl::IDNS_Tag) { - ScopedDecl *TagD = Pos->second.back(); + NamedDecl *TagD = Pos->second.back(); Pos->second.back() = D; Pos->second.push_back(TagD); } else diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index e3d753490a..a9c129ba22 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -210,11 +210,9 @@ void CXXRecordDecl::addConversionFunction(ASTContext &Context, CXXMethodDecl * CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, DeclarationName N, - QualType T, bool isStatic, bool isInline, - ScopedDecl *PrevDecl) { + QualType T, bool isStatic, bool isInline) { void *Mem = C.getAllocator().Allocate<CXXMethodDecl>(); - return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline, - PrevDecl); + return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline); } QualType CXXMethodDecl::getThisType(ASTContext &C) const { @@ -355,9 +353,9 @@ CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, IdentifierInfo *Id, - QualType T, ScopedDecl *PrevDecl) { + QualType T) { void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>(); - return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl); + return new (Mem) CXXClassVarDecl(RD, L, Id, T); } OverloadedFunctionDecl * diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 90962e69bd..bbbcc5f671 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -166,11 +166,10 @@ ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, ObjCImplementationDecl * ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, - IdentifierInfo *Id, ObjCInterfaceDecl *ClassInterface, ObjCInterfaceDecl *SuperDecl) { void *Mem = C.getAllocator().Allocate<ObjCImplementationDecl>(); - return new (Mem) ObjCImplementationDecl(DC, L, Id, ClassInterface, SuperDecl); + return new (Mem) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); } ObjCCompatibleAliasDecl * @@ -213,12 +212,12 @@ void ObjCMethodDecl::createImplicitParams(ASTContext &Context, SelfDecl = ImplicitParamDecl::Create(Context, this, SourceLocation(), &Context.Idents.get("self"), - selfTy, 0); + selfTy); CmdDecl = ImplicitParamDecl::Create(Context, this, SourceLocation(), &Context.Idents.get("_cmd"), - Context.getObjCSelType(), 0); + Context.getObjCSelType()); } void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp index 11577cd6dc..b37e7b4cfe 100644 --- a/lib/AST/DeclSerialization.cpp +++ b/lib/AST/DeclSerialization.cpp @@ -31,8 +31,25 @@ using namespace clang; void Decl::Emit(Serializer& S) const { S.EmitInt(getKind()); EmitImpl(S); + S.Emit(getLocation()); + S.EmitBool(InvalidDecl); + // FIXME: HasAttrs? + S.EmitBool(Implicit); + S.EmitInt(Access); + S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From Decl. + S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From Decl. + S.EmitPtr(NextDeclarator); if (const DeclContext *DC = dyn_cast<const DeclContext>(this)) DC->EmitOutRec(S); + + if (getDeclContext() && + !getDeclContext()->isFunctionOrMethod()) { + S.EmitBool(true); + S.EmitOwnedPtr(NextDeclInScope); + } else { + S.EmitBool(false); + S.EmitPtr(NextDeclInScope); + } } Decl* Decl::Create(Deserializer& D, ASTContext& C) { @@ -101,22 +118,39 @@ Decl* Decl::Create(Deserializer& D, ASTContext& C) { break; } - if (DeclContext *DC = dyn_cast<DeclContext>(Dcl)) - DC->ReadOutRec(D, C); + Dcl->Loc = SourceLocation::ReadVal(D); // From Decl. + Dcl->InvalidDecl = D.ReadBool(); + // FIXME: HasAttrs? + Dcl->Implicit = D.ReadBool(); + Dcl->Access = D.ReadInt(); - return Dcl; -} - -//===----------------------------------------------------------------------===// -// Common serialization logic for subclasses of Decl. -//===----------------------------------------------------------------------===// + assert(Dcl->DeclCtx == 0); -void Decl::EmitInRec(Serializer& S) const { - S.Emit(getLocation()); // From Decl. -} + const SerializedPtrID &SemaDCPtrID = D.ReadPtrID(); + const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID(); -void Decl::ReadInRec(Deserializer& D, ASTContext& C) { - Loc = SourceLocation::ReadVal(D); // From Decl. + if (SemaDCPtrID == LexicalDCPtrID) { + // Allow back-patching. Observe that we register the variable of the + // *object* for back-patching. Its actual value will get filled in later. + D.ReadUIntPtr(Dcl->DeclCtx, SemaDCPtrID); + } + else { + MultipleDC *MDC = new MultipleDC(); + Dcl->DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1; + // Allow back-patching. Observe that we register the variable of the + // *object* for back-patching. Its actual value will get filled in later. + D.ReadPtr(MDC->SemanticDC, SemaDCPtrID); + D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID); + } + D.ReadPtr(Dcl->NextDeclarator); + if (DeclContext *DC = dyn_cast<DeclContext>(Dcl)) + DC->ReadOutRec(D, C); + bool OwnsNext = D.ReadBool(); + if (OwnsNext) + Dcl->NextDeclInScope = D.ReadOwnedPtr<Decl>(C); + else + D.ReadPtr(Dcl->NextDeclInScope); + return Dcl; } //===----------------------------------------------------------------------===// @@ -124,36 +158,22 @@ void Decl::ReadInRec(Deserializer& D, ASTContext& C) { //===----------------------------------------------------------------------===// void DeclContext::EmitOutRec(Serializer& S) const { -#if 0 - // FIXME: it would be far easier to just serialize FirstDecl and let - // ScopedDecl do the work of serializing NextDeclInScope. - S.EmitInt(Decls.size()); - for (decl_iterator D = decls_begin(); D != decls_end(); ++D) { - bool Owned = ((*D)->getLexicalDeclContext() == this && - DeclKind != Decl::TranslationUnit && - !isFunctionOrMethod()); - S.EmitBool(Owned); - if (Owned) - S.EmitOwnedPtr(*D); - else - S.EmitPtr(*D); - } -#endif + bool Owned = !isFunctionOrMethod(); + S.EmitBool(Owned); + if (Owned) + S.EmitOwnedPtr(FirstDecl); + else + S.EmitPtr(FirstDecl); + S.EmitPtr(LastDecl); } void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) { -#if 0 - // FIXME: See comment in DeclContext::EmitOutRec - unsigned NumDecls = D.ReadInt(); - Decls.resize(NumDecls); - for (unsigned Idx = 0; Idx < NumDecls; ++Idx) { - bool Owned = D.ReadBool(); - if (Owned) - Decls[Idx] = cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C)); - else - D.ReadPtr<ScopedDecl>(Decls[Idx]); - } -#endif + bool Owned = D.ReadBool(); + if (Owned) + FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C)); + else + D.ReadPtr(FirstDecl); + D.ReadPtr(LastDecl); } //===----------------------------------------------------------------------===// @@ -161,7 +181,6 @@ void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) { //===----------------------------------------------------------------------===// void NamedDecl::EmitInRec(Serializer& S) const { - Decl::EmitInRec(S); S.EmitInt(Name.getNameKind()); switch (Name.getNameKind()) { @@ -188,8 +207,6 @@ void NamedDecl::EmitInRec(Serializer& S) const { } void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) { - Decl::ReadInRec(D, C); - DeclarationName::NameKind Kind = static_cast<DeclarationName::NameKind>(D.ReadInt()); switch (Kind) { @@ -229,64 +246,16 @@ void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) { } //===----------------------------------------------------------------------===// -// Common serialization logic for subclasses of ScopedDecl. -//===----------------------------------------------------------------------===// - -void ScopedDecl::EmitInRec(Serializer& S) const { - NamedDecl::EmitInRec(S); - S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From ScopedDecl. - S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From ScopedDecl. -} - -void ScopedDecl::ReadInRec(Deserializer& D, ASTContext& C) { - NamedDecl::ReadInRec(D, C); - - assert(DeclCtx == 0); - - const SerializedPtrID &SemaDCPtrID = D.ReadPtrID(); - const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID(); - - if (SemaDCPtrID == LexicalDCPtrID) { - // Allow back-patching. Observe that we register the variable of the - // *object* for back-patching. Its actual value will get filled in later. - D.ReadUIntPtr(DeclCtx, SemaDCPtrID); - } - else { - MultipleDC *MDC = new MultipleDC(); - DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1; - // Allow back-patching. Observe that we register the variable of the - // *object* for back-patching. Its actual value will get filled in later. - D.ReadPtr(MDC->SemanticDC, SemaDCPtrID); - D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID); - } -} - - //===------------------------------------------------------------===// - // NOTE: Not all subclasses of ScopedDecl will use the "OutRec" // - // methods. This is because owned pointers are usually "batched" // - // together for efficiency. // - //===------------------------------------------------------------===// - -void ScopedDecl::EmitOutRec(Serializer& S) const { - S.EmitOwnedPtr(getNextDeclarator()); // From Sc |