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/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index a9c129b..ee242c5 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -25,16 +25,14 @@
TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
bool Typename) {
- void *Mem = C.getAllocator().Allocate<TemplateTypeParmDecl>();
- 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<NonTypeTemplateParmDecl>();
- 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::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<TemplateParameterList>::Alignment;
void *Mem = C.getAllocator().Allocate(Size, Align);
@@ -63,8 +62,7 @@
CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
CXXRecordDecl* PrevDecl) {
- void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
- 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::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
QualType T, bool isStatic, bool isInline) {
- void *Mem = C.getAllocator().Allocate<CXXMethodDecl>();
- 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 @@
bool isInline, bool isImplicitlyDeclared) {
assert(N.getNameKind() == DeclarationName::CXXConstructorName &&
"Name must refer to a constructor");
- void *Mem = C.getAllocator().Allocate<CXXConstructorDecl>();
- 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 @@
bool isImplicitlyDeclared) {
assert(N.getNameKind() == DeclarationName::CXXDestructorName &&
"Name must refer to a destructor");
- void *Mem = C.getAllocator().Allocate<CXXDestructorDecl>();
- 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 @@
QualType T, bool isInline, bool isExplicit) {
assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName &&
"Name must refer to a conversion function");
- void *Mem = C.getAllocator().Allocate<CXXConversionDecl>();
- 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<CXXClassVarDecl>();
- 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<OverloadedFunctionDecl>();
- 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<LinkageSpecDecl>();
- return new (Mem) LinkageSpecDecl(DC, L, Lang, Braces);
+ return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
}