diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-05 21:55:30 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-05 21:55:30 +0000 |
commit | 1e68ecc4fcce12f683c4fd38acfd1a004001b04f (patch) | |
tree | fd87a549e1751f907c6ae4355553f2c51bdce0cb /lib | |
parent | b8c879a5363f36bdae8831112b563333e3c05acb (diff) |
When creating declarations that are deserialized from an module file,
go through a central allocation routine
Decl::AllocateDeserializedDecl(). No actual functionality change (yet).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Decl.cpp | 102 | ||||
-rw-r--r-- | lib/AST/DeclBase.cpp | 6 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 120 | ||||
-rw-r--r-- | lib/AST/DeclFriend.cpp | 5 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 76 | ||||
-rw-r--r-- | lib/AST/DeclTemplate.cpp | 89 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 154 |
7 files changed, 390 insertions, 162 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 468baae205..e6b3a74342 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1152,6 +1152,12 @@ VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, return new (C) VarDecl(Var, DC, StartL, IdL, Id, T, TInfo, S, SCAsWritten); } +VarDecl *VarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(VarDecl)); + return new (Mem) VarDecl(Var, 0, SourceLocation(), SourceLocation(), 0, + QualType(), 0, SC_None, SC_None); +} + void VarDecl::setStorageClass(StorageClass SC) { assert(isLegalForVariable(SC)); if (getStorageClass() != SC) @@ -1513,6 +1519,12 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, S, SCAsWritten, DefArg); } +ParmVarDecl *ParmVarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ParmVarDecl)); + return new (Mem) ParmVarDecl(ParmVar, 0, SourceLocation(), SourceLocation(), + 0, QualType(), 0, SC_None, SC_None, 0); +} + SourceRange ParmVarDecl::getSourceRange() const { if (!hasInheritedDefaultArg()) { SourceRange ArgRange = getDefaultArgRange(); @@ -2303,6 +2315,12 @@ FieldDecl *FieldDecl::Create(const ASTContext &C, DeclContext *DC, BW, Mutable, HasInit); } +FieldDecl *FieldDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FieldDecl)); + return new (Mem) FieldDecl(Field, 0, SourceLocation(), SourceLocation(), + 0, QualType(), 0, 0, false, false); +} + bool FieldDecl::isAnonymousStructOrUnion() const { if (!isImplicit() || getDeclName()) return false; @@ -2469,9 +2487,10 @@ EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, return Enum; } -EnumDecl *EnumDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) EnumDecl(0, SourceLocation(), SourceLocation(), 0, 0, - false, false, false); +EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(EnumDecl)); + return new (Mem) EnumDecl(0, SourceLocation(), SourceLocation(), 0, 0, + false, false, false); } void EnumDecl::completeDefinition(QualType NewType, @@ -2511,9 +2530,10 @@ RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC, return R; } -RecordDecl *RecordDecl::Create(const ASTContext &C, EmptyShell Empty) { - return new (C) RecordDecl(Record, TTK_Struct, 0, SourceLocation(), - SourceLocation(), 0, 0); +RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(RecordDecl)); + return new (Mem) RecordDecl(Record, TTK_Struct, 0, SourceLocation(), + SourceLocation(), 0, 0); } bool RecordDecl::isInjectedClassName() const { @@ -2641,17 +2661,9 @@ LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC, return new (C) LabelDecl(DC, IdentL, II, 0, GnuLabelL); } -void NamespaceDecl::anchor() { } - -NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, - SourceLocation StartLoc, - SourceLocation IdLoc, IdentifierInfo *Id) { - return new (C) NamespaceDecl(DC, StartLoc, IdLoc, Id); -} - -NamespaceDecl *NamespaceDecl::getNextNamespace() { - return dyn_cast_or_null<NamespaceDecl>( - NextNamespace.get(getASTContext().getExternalSource())); +LabelDecl *LabelDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(LabelDecl)); + return new (Mem) LabelDecl(0, SourceLocation(), 0, 0, SourceLocation()); } void ValueDecl::anchor() { } @@ -2665,6 +2677,12 @@ ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, return new (C) ImplicitParamDecl(DC, IdLoc, Id, Type); } +ImplicitParamDecl *ImplicitParamDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ImplicitParamDecl)); + return new (Mem) ImplicitParamDecl(0, SourceLocation(), 0, QualType()); +} + FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, @@ -2681,10 +2699,22 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, return New; } +FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionDecl)); + return new (Mem) FunctionDecl(Function, 0, SourceLocation(), + DeclarationNameInfo(), QualType(), 0, + SC_None, SC_None, false, false); +} + BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { return new (C) BlockDecl(DC, L); } +BlockDecl *BlockDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(BlockDecl)); + return new (Mem) BlockDecl(0, SourceLocation()); +} + EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, SourceLocation L, IdentifierInfo *Id, QualType T, @@ -2692,6 +2722,13 @@ EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, return new (C) EnumConstantDecl(CD, L, Id, T, E, V); } +EnumConstantDecl * +EnumConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(EnumConstantDecl)); + return new (Mem) EnumConstantDecl(0, SourceLocation(), 0, QualType(), 0, + llvm::APSInt()); +} + void IndirectFieldDecl::anchor() { } IndirectFieldDecl * @@ -2701,6 +2738,13 @@ IndirectFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, return new (C) IndirectFieldDecl(DC, L, Id, T, CH, CHS); } +IndirectFieldDecl *IndirectFieldDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(IndirectFieldDecl)); + return new (Mem) IndirectFieldDecl(0, SourceLocation(), DeclarationName(), + QualType(), 0, 0); +} + SourceRange EnumConstantDecl::getSourceRange() const { SourceLocation End = getLocation(); if (Init) @@ -2718,6 +2762,11 @@ TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, void TypedefNameDecl::anchor() { } +TypedefDecl *TypedefDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypedefDecl)); + return new (Mem) TypedefDecl(0, SourceLocation(), SourceLocation(), 0, 0); +} + TypeAliasDecl *TypeAliasDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, @@ -2725,6 +2774,11 @@ TypeAliasDecl *TypeAliasDecl::Create(ASTContext &C, DeclContext *DC, return new (C) TypeAliasDecl(DC, StartLoc, IdLoc, Id, TInfo); } +TypeAliasDecl *TypeAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasDecl)); + return new (Mem) TypeAliasDecl(0, SourceLocation(), SourceLocation(), 0, 0); +} + SourceRange TypedefDecl::getSourceRange() const { SourceLocation RangeEnd = getLocation(); if (TypeSourceInfo *TInfo = getTypeSourceInfo()) { @@ -2750,6 +2804,12 @@ FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, return new (C) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc); } +FileScopeAsmDecl *FileScopeAsmDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FileScopeAsmDecl)); + return new (Mem) FileScopeAsmDecl(0, 0, SourceLocation(), SourceLocation()); +} + //===----------------------------------------------------------------------===// // ImportDecl Implementation //===----------------------------------------------------------------------===// @@ -2803,9 +2863,11 @@ ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC, return Import; } -ImportDecl *ImportDecl::CreateEmpty(ASTContext &C, unsigned NumLocations) { - void *Mem = C.Allocate(sizeof(ImportDecl) + - NumLocations * sizeof(SourceLocation)); +ImportDecl *ImportDecl::CreateDeserialized(ASTContext &C, unsigned ID, + unsigned NumLocations) { + void *Mem = AllocateDeserializedDecl(C, ID, + (sizeof(ImportDecl) + + NumLocations * sizeof(SourceLocation))); return new (Mem) ImportDecl(EmptyShell()); } diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index d60edd06e9..55484188c8 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -41,6 +41,12 @@ using namespace clang; static bool StatSwitch = false; +void *Decl::AllocateDeserializedDecl(const ASTContext &Context, + unsigned ID, + unsigned Size) { + return Context.Allocate(Size); +} + const char *Decl::getDeclKindName() const { switch (DeclKind) { default: llvm_unreachable("Declaration not in DeclNodes.inc!"); diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index c1aa35f305..0f83c560b0 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -30,6 +30,12 @@ using namespace clang; void AccessSpecDecl::anchor() { } +AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(AccessSpecDecl)); + return new (Mem) AccessSpecDecl(EmptyShell()); +} + + CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), UserDeclaredMoveConstructor(false), UserDeclaredCopyAssignment(false), @@ -76,9 +82,11 @@ CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, return R; } -CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, EmptyShell Empty) { - return new (C) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), - SourceLocation(), 0, 0); +CXXRecordDecl * +CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXRecordDecl)); + return new (Mem) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), + SourceLocation(), 0, 0); } void @@ -1271,6 +1279,14 @@ CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, EndLocation); } +CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXMethodDecl)); + return new (Mem) CXXMethodDecl(CXXMethod, 0, SourceLocation(), + DeclarationNameInfo(), QualType(), + 0, false, SC_None, false, false, + SourceLocation()); +} + bool CXXMethodDecl::isUsualDeallocationFunction() const { if (getOverloadedOperator() != OO_Delete && getOverloadedOperator() != OO_Array_Delete) @@ -1511,9 +1527,10 @@ SourceRange CXXCtorInitializer::getSourceRange() const { void CXXConstructorDecl::anchor() { } CXXConstructorDecl * -CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) CXXConstructorDecl(0, SourceLocation(), DeclarationNameInfo(), - QualType(), 0, false, false, false, false); +CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConstructorDecl)); + return new (Mem) CXXConstructorDecl(0, SourceLocation(),DeclarationNameInfo(), + QualType(), 0, false, false, false,false); } CXXConstructorDecl * @@ -1657,8 +1674,9 @@ CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ void CXXDestructorDecl::anchor() { } CXXDestructorDecl * -CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(), +CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXDestructorDecl)); + return new (Mem) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(), QualType(), 0, false, false); } @@ -1678,10 +1696,11 @@ CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, void CXXConversionDecl::anchor() { } CXXConversionDecl * -CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(), - QualType(), 0, false, false, false, - SourceLocation()); +CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConversionDecl)); + return new (Mem) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(), + QualType(), 0, false, false, false, + SourceLocation()); } CXXConversionDecl * @@ -1710,6 +1729,12 @@ LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, RBraceLoc); } +LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(LinkageSpecDecl)); + return new (Mem) LinkageSpecDecl(0, SourceLocation(), SourceLocation(), + lang_c, SourceLocation()); +} + void UsingDirectiveDecl::anchor() { } UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, @@ -1725,6 +1750,14 @@ UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, IdentLoc, Used, CommonAncestor); } +UsingDirectiveDecl * +UsingDirectiveDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDirectiveDecl)); + return new (Mem) UsingDirectiveDecl(0, SourceLocation(), SourceLocation(), + NestedNameSpecifierLoc(), + SourceLocation(), 0, 0); +} + NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { if (NamespaceAliasDecl *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) @@ -1732,6 +1765,24 @@ NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { return cast_or_null<NamespaceDecl>(NominatedNamespace); } +void NamespaceDecl::anchor() { } + +NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, + SourceLocation StartLoc, + SourceLocation IdLoc, IdentifierInfo *Id) { + return new (C) NamespaceDecl(DC, StartLoc, IdLoc, Id); +} + +NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceDecl)); + return new (Mem) NamespaceDecl(0, SourceLocation(), SourceLocation(), 0); +} + +NamespaceDecl *NamespaceDecl::getNextNamespace() { + return dyn_cast_or_null<NamespaceDecl>( + NextNamespace.get(getASTContext().getExternalSource())); +} + void NamespaceAliasDecl::anchor() { } NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, @@ -1747,8 +1798,22 @@ NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, QualifierLoc, IdentLoc, Namespace); } +NamespaceAliasDecl * +NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceAliasDecl)); + return new (Mem) NamespaceAliasDecl(0, SourceLocation(), SourceLocation(), 0, + NestedNameSpecifierLoc(), + SourceLocation(), 0); +} + void UsingShadowDecl::anchor() { } +UsingShadowDecl * +UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingShadowDecl)); + return new (Mem) UsingShadowDecl(0, SourceLocation(), 0, 0); +} + UsingDecl *UsingShadowDecl::getUsingDecl() const { const UsingShadowDecl *Shadow = this; while (const UsingShadowDecl *NextShadow = @@ -1796,6 +1861,12 @@ UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, IsTypeNameArg); } +UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDecl)); + return new (Mem) UsingDecl(0, SourceLocation(), NestedNameSpecifierLoc(), + DeclarationNameInfo(), false); +} + void UnresolvedUsingValueDecl::anchor() { } UnresolvedUsingValueDecl * @@ -1807,6 +1878,14 @@ UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, QualifierLoc, NameInfo); } +UnresolvedUsingValueDecl * +UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UnresolvedUsingValueDecl)); + return new (Mem) UnresolvedUsingValueDecl(0, QualType(), SourceLocation(), + NestedNameSpecifierLoc(), + DeclarationNameInfo()); +} + void UnresolvedUsingTypenameDecl::anchor() { } UnresolvedUsingTypenameDecl * @@ -1821,6 +1900,17 @@ UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, TargetName.getAsIdentifierInfo()); } +UnresolvedUsingTypenameDecl * +UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, + sizeof(UnresolvedUsingTypenameDecl)); + return new (Mem) UnresolvedUsingTypenameDecl(0, SourceLocation(), + SourceLocation(), + NestedNameSpecifierLoc(), + SourceLocation(), + 0); +} + void StaticAssertDecl::anchor() { } StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, @@ -1832,6 +1922,12 @@ StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, RParenLoc); } +StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(StaticAssertDecl)); + return new (Mem) StaticAssertDecl(0, SourceLocation(), 0, 0,SourceLocation()); +} + static const char *getAccessName(AccessSpecifier AS) { switch (AS) { default: diff --git a/lib/AST/DeclFriend.cpp b/lib/AST/DeclFriend.cpp index e44333effa..6e3bd8d422 100644 --- a/lib/AST/DeclFriend.cpp +++ b/lib/AST/DeclFriend.cpp @@ -42,6 +42,7 @@ FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, return FD; } -FriendDecl *FriendDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) FriendDecl(Empty); +FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendDecl)); + return new (Mem) FriendDecl(EmptyShell()); } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 59bfdc6b6e..b0aeabf68f 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -409,6 +409,12 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, HasRelatedResultType); } +ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCMethodDecl)); + return new (Mem) ObjCMethodDecl(SourceLocation(), SourceLocation(), + Selector(), QualType(), 0, 0); +} + void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { assert(PrevMethod); getASTContext().setObjCMethodRedeclaration(PrevMethod, this); @@ -692,9 +698,11 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, return Result; } -ObjCInterfaceDecl *ObjCInterfaceDecl::CreateEmpty(ASTContext &C) { - return new (C) ObjCInterfaceDecl(0, SourceLocation(), 0, SourceLocation(), - 0, false); +ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCInterfaceDecl)); + return new (Mem) ObjCInterfaceDecl(0, SourceLocation(), 0, SourceLocation(), + 0, false); } ObjCInterfaceDecl:: @@ -924,6 +932,12 @@ ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, ac, BW, synthesized); } +ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCIvarDecl)); + return new (Mem) ObjCIvarDecl(0, SourceLocation(), SourceLocation(), 0, + QualType(), 0, ObjCIvarDecl::None, 0, false); +} + const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); @@ -961,6 +975,13 @@ ObjCAtDefsFieldDecl return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); } +ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCAtDefsFieldDecl)); + return new (Mem) ObjCAtDefsFieldDecl(0, SourceLocation(), SourceLocation(), + 0, QualType(), 0); +} + //===----------------------------------------------------------------------===// // ObjCProtocolDecl //===----------------------------------------------------------------------===// @@ -989,6 +1010,13 @@ ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, return Result; } +ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCProtocolDecl)); + return new (Mem) ObjCProtocolDecl(0, 0, SourceLocation(), SourceLocation(), + 0); +} + ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { ObjCProtocolDecl *PDecl = this; @@ -1063,9 +1091,11 @@ ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, return CatDecl; } -ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(), - SourceLocation(), 0, 0); +ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryDecl)); + return new (Mem) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(), + SourceLocation(), 0, 0); } ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { @@ -1097,6 +1127,13 @@ ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, nameLoc, atStartLoc, CategoryNameLoc); } +ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryImplDecl)); + return new (Mem) ObjCCategoryImplDecl(0, 0, 0, SourceLocation(), + SourceLocation(), SourceLocation()); +} + ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { // The class interface might be NULL if we are working with invalid code. if (const ObjCInterfaceDecl *ID = getClassInterface()) @@ -1183,6 +1220,13 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, nameLoc, atStartLoc); } +ObjCImplementationDecl * +ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCImplementationDecl)); + return new (Mem) ObjCImplementationDecl(0, 0, 0, SourceLocation(), + SourceLocation()); +} + void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, CXXCtorInitializer ** initializers, unsigned numInitializers) { @@ -1216,6 +1260,12 @@ ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); } +ObjCCompatibleAliasDecl * +ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCompatibleAliasDecl)); + return new (Mem) ObjCCompatibleAliasDecl(0, SourceLocation(), 0, 0); +} + //===----------------------------------------------------------------------===// // ObjCPropertyDecl //===----------------------------------------------------------------------===// @@ -1231,6 +1281,13 @@ ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T); } +ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void * Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyDecl)); + return new (Mem) ObjCPropertyDecl(0, SourceLocation(), 0, SourceLocation(), + 0); +} + //===----------------------------------------------------------------------===// // ObjCPropertyImplDecl //===----------------------------------------------------------------------===// @@ -1247,6 +1304,13 @@ ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, ivarLoc); } +ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyImplDecl)); + return new (Mem) ObjCPropertyImplDecl(0, SourceLocation(), SourceLocation(), + 0, Dynamic, 0, SourceLocation()); +} + SourceRange ObjCPropertyImplDecl::getSourceRange() const { SourceLocation EndLoc = getLocation(); if (IvarLoc.isValid()) diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index a2d5a2d70d..f505321f03 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -224,9 +224,11 @@ FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); } -FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, EmptyShell) { - return new (C) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(), - 0, 0); +FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionTemplateDecl)); + return new (Mem) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(), + 0, 0); } RedeclarableTemplateDecl::CommonBase * @@ -284,8 +286,10 @@ ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, return New; } -ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, EmptyShell Empty) { - return new (C) ClassTemplateDecl(Empty); +ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl)); + return new (Mem) ClassTemplateDecl(EmptyShell()); } void ClassTemplateDecl::LoadLazySpecializations() { @@ -433,9 +437,10 @@ TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, } TemplateTypeParmDecl * -TemplateTypeParmDecl::Create(const ASTContext &C, EmptyShell Empty) { - return new (C) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(), - 0, false); +TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl)); + return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(), + 0, false); } SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { @@ -520,6 +525,27 @@ NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, ExpandedTInfos); } +NonTypeTemplateParmDecl * +NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl)); + return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), + SourceLocation(), 0, 0, 0, + QualType(), false, 0); +} + +NonTypeTemplateParmDecl * +NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, + unsigned NumExpandedTypes) { + unsigned Size = sizeof(NonTypeTemplateParmDecl) + + NumExpandedTypes * 2 * sizeof(void*); + + void *Mem = AllocateDeserializedDecl(C, ID, Size); + return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), + SourceLocation(), 0, 0, 0, + QualType(), 0, 0, NumExpandedTypes, + 0); +} + SourceRange NonTypeTemplateParmDecl::getSourceRange() const { if (hasDefaultArgument() && !defaultArgumentWasInherited()) return SourceRange(getOuterLocStart(), @@ -548,6 +574,13 @@ TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, Params); } +TemplateTemplateParmDecl * +TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl)); + return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false, + 0, 0); +} + //===----------------------------------------------------------------------===// // TemplateArgumentList Implementation //===----------------------------------------------------------------------===// @@ -636,9 +669,11 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, } ClassTemplateSpecializationDecl * -ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) { - return - new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization); +ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, + sizeof(ClassTemplateSpecializationDecl)); + return new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization); } void @@ -750,9 +785,11 @@ Create(ASTContext &Context, TagKind TK,DeclContext *DC, } ClassTemplatePartialSpecializationDecl * -ClassTemplatePartialSpecializationDecl::Create(ASTContext &Context, - EmptyShell Empty) { - return new (Context)ClassTemplatePartialSpecializationDecl(); +ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, + sizeof(ClassTemplatePartialSpecializationDecl)); + return new (Mem) ClassTemplatePartialSpecializationDecl(); } //===----------------------------------------------------------------------===// @@ -773,9 +810,10 @@ FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, return Result; } -FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, - EmptyShell Empty) { - return new (Context) FriendTemplateDecl(Empty); +FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl)); + return new (Mem) FriendTemplateDecl(EmptyShell()); } //===----------------------------------------------------------------------===// @@ -792,10 +830,11 @@ TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl); } -TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, - EmptyShell) { - return new (C) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(), - 0, 0); +TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl)); + return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(), + 0, 0); } void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) { @@ -813,3 +852,11 @@ TypeAliasTemplateDecl::newCommon(ASTContext &C) { //===----------------------------------------------------------------------===// void ClassScopeFunctionSpecializationDecl::anchor() { } + +ClassScopeFunctionSpecializationDecl * +ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C, + unsigned ID) { + void *Mem = AllocateDeserializedDecl(C, ID, + sizeof(ClassScopeFunctionSpecializationDecl)); + return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0); +} diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 84f7545e6a..cff8667f4b 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1877,208 +1877,160 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { case DECL_CONTEXT_VISIBLE: llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); case DECL_TYPEDEF: - D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(), - 0, 0); + D = TypedefDecl::CreateDeserialized(Context, ID); break; case DECL_TYPEALIAS: - D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(), - 0, 0); + D = TypeAliasDecl::CreateDeserialized(Context, ID); break; case DECL_ENUM: - D = EnumDecl::Create(Context, Decl::EmptyShell()); + D = EnumDecl::CreateDeserialized(Context, ID); break; case DECL_RECORD: - D = RecordDecl::Create(Context, Decl::EmptyShell()); + D = RecordDecl::CreateDeserialized(Context, ID); break; case DECL_ENUM_CONSTANT: - D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(), - 0, llvm::APSInt()); + D = EnumConstantDecl::CreateDeserialized(Context, ID); break; case DECL_FUNCTION: - D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(), - |