From: Steve Naroff Date: Tue, 27 Jan 2009 21:25:57 +0000 (+0000) Subject: Remove many references to ASTContext::getAllocator(), replacing them with calls to... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e9704981d7691fdd44913bf1786e8d760d8a627;p=clang Remove many references to ASTContext::getAllocator(), replacing them with calls to the recently added placement new (which uses ASTContext's allocator for memory). Also added ASTContext::Deallocate(). This will simplify runtime replacement of ASTContext's allocator. Keeping the allocator private (and removing getAllocator() entirely) is also goodness. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63135 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index a01199d4b2..9cf11b8578 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -129,6 +129,8 @@ public: SourceManager& getSourceManager() { return SourceMgr; } llvm::MallocAllocator &getAllocator() { return Allocator; } + void Deallocate(void *Ptr) { Allocator.Deallocate(Ptr); } + const LangOptions& getLangOptions() const { return LangOpts; } FullSourceLoc getFullLoc(SourceLocation Loc) const { @@ -567,7 +569,7 @@ private: FieldDecl *Field, bool OutermostType = false, bool EncodingProperty = false) const; - + }; } // end namespace clang diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 165a6c0948..c8b7fc2dcf 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -24,14 +24,12 @@ using namespace clang; //===----------------------------------------------------------------------===// TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) TranslationUnitDecl(); + return new (C) TranslationUnitDecl(); } NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) NamespaceDecl(DC, L, Id); + return new (C) NamespaceDecl(DC, L, Id); } void NamespaceDecl::Destroy(ASTContext& C) { @@ -39,22 +37,20 @@ void NamespaceDecl::Destroy(ASTContext& C) { // together. They are all top-level Decls. this->~NamespaceDecl(); - C.getAllocator().Deallocate((void *)this); + C.Deallocate((void *)this); } ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T); + return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T); } ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, Expr *DefArg) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg); + return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg); } QualType ParmVarDecl::getOriginalType() const { @@ -69,8 +65,7 @@ ParmVarWithOriginalTypeDecl *ParmVarWithOriginalTypeDecl::Create( SourceLocation L, IdentifierInfo *Id, QualType T, QualType OT, StorageClass S, Expr *DefArg) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, DefArg); + return new (C) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, DefArg); } FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, @@ -78,21 +73,18 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, DeclarationName N, QualType T, StorageClass S, bool isInline, SourceLocation TypeSpecStartLoc) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, + return new (C) FunctionDecl(Function, DC, L, N, T, S, isInline, TypeSpecStartLoc); } BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) BlockDecl(DC, L); + return new (C) BlockDecl(DC, L); } FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable); + return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable); } bool FieldDecl::isAnonymousStructOrUnion() const { @@ -109,8 +101,7 @@ EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V); + return new (C) EnumConstantDecl(CD, L, Id, T, E, V); } void EnumConstantDecl::Destroy(ASTContext& C) { @@ -121,8 +112,7 @@ void EnumConstantDecl::Destroy(ASTContext& C) { TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) TypedefDecl(DC, L, Id, T); + return new (C) TypedefDecl(DC, L, Id, T); } EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, @@ -147,8 +137,7 @@ void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) { FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, StringLiteral *Str) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) FileScopeAsmDecl(DC, L, Str); + return new (C) FileScopeAsmDecl(DC, L, Str); } //===----------------------------------------------------------------------===// @@ -176,13 +165,12 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD) const { VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S, SourceLocation TypeSpecStartLoc) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc); + return new (C) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc); } void VarDecl::Destroy(ASTContext& C) { this->~VarDecl(); - C.getAllocator().Deallocate((void *)this); + C.Deallocate((void *)this); } VarDecl::~VarDecl() { @@ -200,7 +188,7 @@ void FunctionDecl::Destroy(ASTContext& C) { for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) (*I)->Destroy(C); - C.getAllocator().Deallocate(ParamInfo); + C.Deallocate(ParamInfo); Decl::Destroy(C); } @@ -309,8 +297,7 @@ RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, RecordDecl* PrevDecl) { - void *Mem = C.getAllocator().Allocate(); - RecordDecl* R = new (Mem) RecordDecl(Record, TK, DC, L, Id); + RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id); C.getTypeDeclType(R, PrevDecl); return R; } diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 016f7b1e04..983c726c22 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -405,7 +405,7 @@ void Decl::Destroy(ASTContext& C) { } this->~Decl(); - C.getAllocator().Deallocate((void *)this); + C.Deallocate((void *)this); #endif } diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index a9c129ba22..ee242c5dff 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -25,16 +25,14 @@ TemplateTypeParmDecl * TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, bool Typename) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) TemplateTypeParmDecl(DC, L, Id, Typename); + return new (C) TemplateTypeParmDecl(DC, L, Id, Typename); } NonTypeTemplateParmDecl * NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, SourceLocation TypeSpecStartLoc) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) NonTypeTemplateParmDecl(DC, L, Id, T, TypeSpecStartLoc); + return new (C) NonTypeTemplateParmDecl(DC, L, Id, T, TypeSpecStartLoc); } TemplateParameterList::TemplateParameterList(Decl **Params, unsigned NumParams) @@ -46,6 +44,7 @@ TemplateParameterList::TemplateParameterList(Decl **Params, unsigned NumParams) TemplateParameterList * TemplateParameterList::Create(ASTContext &C, Decl **Params, unsigned NumParams) { + // FIXME: how do I pass in Size to ASTContext::new? unsigned Size = sizeof(TemplateParameterList) + sizeof(Decl *) * NumParams; unsigned Align = llvm::AlignOf::Alignment; void *Mem = C.getAllocator().Allocate(Size, Align); @@ -63,8 +62,7 @@ CXXRecordDecl::CXXRecordDecl(TagKind TK, DeclContext *DC, CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, CXXRecordDecl* PrevDecl) { - void *Mem = C.getAllocator().Allocate(); - CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id); + CXXRecordDecl* R = new (C) CXXRecordDecl(TK, DC, L, Id); C.getTypeDeclType(R, PrevDecl); return R; } @@ -211,8 +209,7 @@ CXXMethodDecl * CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, DeclarationName N, QualType T, bool isStatic, bool isInline) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline); + return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline); } QualType CXXMethodDecl::getThisType(ASTContext &C) const { @@ -268,8 +265,7 @@ CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, bool isInline, bool isImplicitlyDeclared) { assert(N.getNameKind() == DeclarationName::CXXConstructorName && "Name must refer to a constructor"); - void *Mem = C.getAllocator().Allocate(); - return new (Mem) CXXConstructorDecl(RD, L, N, T, isExplicit, isInline, + return new (C) CXXConstructorDecl(RD, L, N, T, isExplicit, isInline, isImplicitlyDeclared); } @@ -336,9 +332,8 @@ CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, bool isImplicitlyDeclared) { assert(N.getNameKind() == DeclarationName::CXXDestructorName && "Name must refer to a destructor"); - void *Mem = C.getAllocator().Allocate(); - return new (Mem) CXXDestructorDecl(RD, L, N, T, isInline, - isImplicitlyDeclared); + return new (C) CXXDestructorDecl(RD, L, N, T, isInline, + isImplicitlyDeclared); } CXXConversionDecl * @@ -347,28 +342,24 @@ CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, QualType T, bool isInline, bool isExplicit) { assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && "Name must refer to a conversion function"); - void *Mem = C.getAllocator().Allocate(); - return new (Mem) CXXConversionDecl(RD, L, N, T, isInline, isExplicit); + return new (C) CXXConversionDecl(RD, L, N, T, isInline, isExplicit); } CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, IdentifierInfo *Id, QualType T) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) CXXClassVarDecl(RD, L, Id, T); + return new (C) CXXClassVarDecl(RD, L, Id, T); } OverloadedFunctionDecl * OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, DeclarationName N) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) OverloadedFunctionDecl(DC, N); + return new (C) OverloadedFunctionDecl(DC, N); } LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, LanguageIDs Lang, bool Braces) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) LinkageSpecDecl(DC, L, Lang, Braces); + return new (C) LinkageSpecDecl(DC, L, Lang, Braces); } diff --git a/lib/AST/DeclGroup.cpp b/lib/AST/DeclGroup.cpp index 62b4077a3f..c7af7cd89e 100644 --- a/lib/AST/DeclGroup.cpp +++ b/lib/AST/DeclGroup.cpp @@ -60,7 +60,7 @@ void DeclGroup::Destroy(ASTContext& C) { Decls[i]->Destroy(C); this->~DeclGroup(); - C.getAllocator().Deallocate((void*) this); + C.Deallocate((void*) this); } DeclGroupOwningRef::~DeclGroupOwningRef() { diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index bbbcc5f671..b36da643ec 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -29,8 +29,7 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, bool isVariadic, bool isSynthesized, ImplementationControl impControl) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCMethodDecl(beginLoc, endLoc, + return new (C) ObjCMethodDecl(beginLoc, endLoc, SelInfo, T, contextDecl, isInstance, isVariadic, isSynthesized, impControl); @@ -56,8 +55,7 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, IdentifierInfo *Id, SourceLocation ClassLoc, bool ForwardDecl, bool isInternal){ - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, + return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, isInternal); } @@ -83,28 +81,25 @@ void ObjCInterfaceDecl::Destroy(ASTContext& C) { ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id, QualType T, AccessControl ac, Expr *BW) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW); + return new (C) ObjCIvarDecl(L, Id, T, ac, BW); } ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); + return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); } void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { this->~ObjCAtDefsFieldDecl(); - C.getAllocator().Deallocate((void *)this); + C.Deallocate((void *)this); } ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCProtocolDecl(DC, L, Id); + return new (C) ObjCProtocolDecl(DC, L, Id); } ObjCProtocolDecl::~ObjCProtocolDecl() { @@ -115,8 +110,7 @@ ObjCProtocolDecl::~ObjCProtocolDecl() { ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, ObjCInterfaceDecl **Elts, unsigned nElts) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCClassDecl(DC, L, Elts, nElts); + return new (C) ObjCClassDecl(DC, L, Elts, nElts); } ObjCClassDecl::~ObjCClassDecl() { @@ -140,8 +134,7 @@ ObjCForwardProtocolDecl * ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, ObjCProtocolDecl **Elts, unsigned NumElts) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCForwardProtocolDecl(DC, L, Elts, NumElts); + return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts); } ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() { @@ -151,16 +144,14 @@ ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() { ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCCategoryDecl(DC, L, Id); + return new (C) ObjCCategoryDecl(DC, L, Id); } ObjCCategoryImplDecl * ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,IdentifierInfo *Id, ObjCInterfaceDecl *ClassInterface) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); + return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); } ObjCImplementationDecl * @@ -168,8 +159,7 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, ObjCInterfaceDecl *ClassInterface, ObjCInterfaceDecl *SuperDecl) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); + return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); } ObjCCompatibleAliasDecl * @@ -177,8 +167,7 @@ ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, ObjCInterfaceDecl* AliasedClass) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); + return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); } ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, @@ -186,8 +175,7 @@ ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, QualType T, PropertyControl propControl) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCPropertyDecl(DC, L, Id, T); + return new (C) ObjCPropertyDecl(DC, L, Id, T); } //===----------------------------------------------------------------------===// @@ -638,8 +626,7 @@ ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, ObjCPropertyDecl *property, Kind PK, ObjCIvarDecl *ivar) { - void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); + return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); } diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp index 7d848ff2f2..662de369a7 100644 --- a/lib/AST/DeclSerialization.cpp +++ b/lib/AST/DeclSerialization.cpp @@ -303,10 +303,7 @@ void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - TranslationUnitDecl* decl = new (Mem) TranslationUnitDecl(); - - return decl; + return new (C) TranslationUnitDecl(); } //===----------------------------------------------------------------------===// @@ -321,8 +318,7 @@ void NamespaceDecl::EmitImpl(llvm::Serializer& S) const } NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - NamespaceDecl* decl = new (Mem) NamespaceDecl(0, SourceLocation(), 0); + NamespaceDecl* decl = new (C) NamespaceDecl(0, SourceLocation(), 0); decl->NamedDecl::ReadInRec(D, C); decl->LBracLoc = SourceLocation::ReadVal(D); @@ -336,9 +332,8 @@ NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) { //===----------------------------------------------------------------------===// VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); VarDecl* decl = - new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None); + new (C) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None); decl->VarDecl::ReadImpl(D, C); return decl; @@ -355,8 +350,7 @@ void ParmVarDecl::EmitImpl(llvm::Serializer& S) const { } ParmVarDecl* ParmVarDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - ParmVarDecl* decl = new (Mem) + ParmVarDecl* decl = new (C) ParmVarDecl(ParmVar, 0, SourceLocation(), NULL, QualType(), None, NULL); @@ -377,8 +371,7 @@ void ParmVarWithOriginalTypeDecl::EmitImpl(llvm::Serializer& S) const { ParmVarWithOriginalTypeDecl* ParmVarWithOriginalTypeDecl::CreateImpl( Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - ParmVarWithOriginalTypeDecl* decl = new (Mem) + ParmVarWithOriginalTypeDecl* decl = new (C) ParmVarWithOriginalTypeDecl(0, SourceLocation(), NULL, QualType(), QualType(), None, NULL); @@ -397,8 +390,7 @@ void EnumDecl::EmitImpl(Serializer& S) const { } EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - EnumDecl* decl = new (Mem) EnumDecl(0, SourceLocation(), NULL); + EnumDecl* decl = new (C) EnumDecl(0, SourceLocation(), NULL); decl->NamedDecl::ReadInRec(D, C); decl->setDefinition(D.ReadBool()); @@ -421,8 +413,7 @@ EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) { llvm::APSInt val(1); D.Read(val); - void *Mem = C.getAllocator().Allocate(); - EnumConstantDecl* decl = new (Mem) + EnumConstantDecl* decl = new (C) EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val); decl->ValueDecl::ReadInRec(D, C); @@ -442,8 +433,7 @@ void FieldDecl::EmitImpl(Serializer& S) const { } FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - FieldDecl* decl = new (Mem) FieldDecl(Field, 0, SourceLocation(), NULL, + FieldDecl* decl = new (C) FieldDecl(Field, 0, SourceLocation(), NULL, QualType(), 0, false); decl->Mutable = D.ReadBool(); decl->DeclType.ReadBackpatch(D); @@ -480,8 +470,7 @@ FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) { StorageClass SClass = static_cast(D.ReadInt()); bool IsInline = D.ReadBool(); - void *Mem = C.getAllocator().Allocate(); - FunctionDecl* decl = new (Mem) + FunctionDecl* decl = new (C) FunctionDecl(Function, 0, SourceLocation(), DeclarationName(), QualType(), SClass, IsInline); @@ -537,8 +526,7 @@ void OverloadedFunctionDecl::EmitImpl(Serializer& S) const { OverloadedFunctionDecl * OverloadedFunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - OverloadedFunctionDecl* decl = new (Mem) + OverloadedFunctionDecl* decl = new (C) OverloadedFunctionDecl(0, DeclarationName()); decl->NamedDecl::ReadInRec(D, C); @@ -567,8 +555,7 @@ void RecordDecl::EmitImpl(Serializer& S) const { RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) { TagKind TK = TagKind(D.ReadInt()); - void *Mem = C.getAllocator().Allocate(); - RecordDecl* decl = new (Mem) RecordDecl(Record, TK, 0, SourceLocation(), NULL); + RecordDecl* decl = new (C) RecordDecl(Record, TK, 0, SourceLocation(), NULL); decl->NamedDecl::ReadInRec(D, C); decl->setDefinition(D.ReadBool()); @@ -590,8 +577,7 @@ void TypedefDecl::EmitImpl(Serializer& S) const { TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) { QualType T = QualType::ReadVal(D); - void *Mem = C.getAllocator().Allocate(); - TypedefDecl* decl = new (Mem) TypedefDecl(0, SourceLocation(), NULL, T); + TypedefDecl* decl = new (C) TypedefDecl(0, SourceLocation(), NULL, T); decl->NamedDecl::ReadInRec(D, C); @@ -610,9 +596,8 @@ void TemplateTypeParmDecl::EmitImpl(Serializer& S) const { TemplateTypeParmDecl * TemplateTypeParmDecl::CreateImpl(Deserializer& D, ASTContext& C) { bool Typename = D.ReadBool(); - void *Mem = C.getAllocator().Allocate(); TemplateTypeParmDecl *decl - = new (Mem) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename); + = new (C) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename); decl->NamedDecl::ReadInRec(D, C); return decl; } @@ -641,8 +626,7 @@ void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const } FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) { - void *Mem = C.getAllocator().Allocate(); - FileScopeAsmDecl* decl = new (Mem) FileScopeAsmDecl(0, SourceLocation(), 0); + FileScopeAsmDecl* decl = new (C) FileScopeAsmDecl(0, SourceLocation(), 0); decl->AsmString = cast(D.ReadOwnedPtr(C)); // D.ReadOwnedPtr(D.ReadOwnedPtr())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 7d9be2d72c..65fd3b4040 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -32,19 +32,19 @@ bool QualType::isConstant(ASTContext &Ctx) const { void Type::Destroy(ASTContext& C) { this->~Type(); - C.getAllocator().Deallocate(this); + C.Deallocate(this); } void VariableArrayType::Destroy(ASTContext& C) { SizeExpr->Destroy(C); this->~VariableArrayType(); - C.getAllocator().Deallocate(this); + C.Deallocate(this); } void DependentSizedArrayType::Destroy(ASTContext& C) { SizeExpr->Destroy(C); this->~DependentSizedArrayType(); - C.getAllocator().Deallocate(this); + C.Deallocate(this); } /// getArrayElementTypeNoTypeQual - If this is an array type, return the