aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-02-07 01:47:29 +0000
committerTed Kremenek <kremenek@apple.com>2009-02-07 01:47:29 +0000
commit8189cde56b4f6f938cd65f53c932fe1860d0204c (patch)
tree071221f15cf949ffcf6023f72528dd8c4ea487cb /lib/AST/Expr.cpp
parentcad2996edf303978932c621ab02729dc11debb81 (diff)
Overhaul of Stmt allocation:
- Made allocation of Stmt objects using vanilla new/delete a *compiler error* by making this new/delete "protected" within class Stmt. - Now the only way to allocate Stmt objects is by using the new operator that takes ASTContext& as an argument. This ensures that all Stmt nodes are allocated from the same (pool) allocator. - Naturally, these two changes required that *all* creation sites for AST nodes use new (ASTContext&). This is a large patch, but the majority of the changes are just this mechanical adjustment. - The above changes also mean that AST nodes can no longer be deallocated using 'delete'. Instead, one most do StmtObject->Destroy(ASTContext&) or do ASTContextObject.Deallocate(StmtObject) (the latter not running the 'Destroy' method). Along the way I also... - Made CompoundStmt allocate its array of Stmt* using the allocator in ASTContext (previously it used std::vector). There are a whole bunch of other Stmt classes that need to be similarly changed to ensure that all memory allocated for ASTs comes from the allocator in ASTContext. - Added a new smart pointer ExprOwningPtr to Sema.h. This replaces the uses of llvm::OwningPtr within Sema, as llvm::OwningPtr used 'delete' to free memory instead of a Stmt's 'Destroy' method. Big thanks to Doug Gregor for helping with the acrobatics of making 'new/delete' private and the new smart pointer ExprOwningPtr! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63997 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r--lib/AST/Expr.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 89fdbe31f3..d686167cd0 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -54,8 +54,8 @@ StringLiteral::StringLiteral(ASTContext& C, const char *strData,
}
void StringLiteral::Destroy(ASTContext &C) {
- C.Deallocate(const_cast<char*>(StrData));
this->~StringLiteral();
+ C.Deallocate(const_cast<char*>(StrData));
}
bool UnaryOperator::isPostfix(Opcode Op) {
@@ -104,8 +104,8 @@ const char *UnaryOperator::getOpcodeStr(Opcode Op) {
// Postfix Operators.
//===----------------------------------------------------------------------===//
-CallExpr::CallExpr(StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
- QualType t, SourceLocation rparenloc)
+CallExpr::CallExpr(StmtClass SC, Expr *fn, Expr **args,
+ unsigned numargs, QualType t, SourceLocation rparenloc)
: Expr(SC, t,
fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
fn->isValueDependent() || hasAnyValueDependentArguments(args, numargs)),
@@ -133,14 +133,14 @@ CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
/// setNumArgs - This changes the number of arguments present in this call.
/// Any orphaned expressions are deleted by this, and any new operands are set
/// to null.
-void CallExpr::setNumArgs(unsigned NumArgs) {
+void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
// No change, just return.
if (NumArgs == getNumArgs()) return;
// If shrinking # arguments, just delete the extras and forgot them.
if (NumArgs < getNumArgs()) {
for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
- delete getArg(i);
+ getArg(i)->Destroy(C);
this->NumArgs = NumArgs;
return;
}
@@ -154,7 +154,7 @@ void CallExpr::setNumArgs(unsigned NumArgs) {
for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
NewSubExprs[i] = 0;
- delete[] SubExprs;
+ delete [] SubExprs;
SubExprs = NewSubExprs;
this->NumArgs = NumArgs;
}
@@ -1391,10 +1391,10 @@ void SizeOfAlignOfExpr::Destroy(ASTContext& C) {
// will iterate over the size expression. However, this expression belongs
// to the type, not to this, so we don't want to delete it.
// We still want to delete this expression.
- // FIXME: Same as in Stmt::Destroy - will be eventually in ASTContext's
- // pool allocator.
- if (isArgumentType())
- delete this;
+ if (isArgumentType()) {
+ this->~SizeOfAlignOfExpr();
+ C.Deallocate(this);
+ }
else
Expr::Destroy(C);
}