diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-02-07 01:47:29 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-02-07 01:47:29 +0000 |
commit | 8189cde56b4f6f938cd65f53c932fe1860d0204c (patch) | |
tree | 071221f15cf949ffcf6023f72528dd8c4ea487cb /lib/AST/StmtSerialization.cpp | |
parent | cad2996edf303978932c621ab02729dc11debb81 (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/StmtSerialization.cpp')
-rw-r--r-- | lib/AST/StmtSerialization.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index 8d6636d6a6..92713cc633 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -483,7 +483,8 @@ void CompoundLiteralExpr::EmitImpl(Serializer& S) const { S.EmitOwnedPtr(Init); } -CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D, ASTContext& C) { +CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D, + ASTContext& C) { QualType Q = QualType::ReadVal(D); SourceLocation L = SourceLocation::ReadVal(D); bool fileScope = D.ReadBool(); @@ -495,10 +496,8 @@ CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D, ASTContext void CompoundStmt::EmitImpl(Serializer& S) const { S.Emit(LBracLoc); S.Emit(RBracLoc); - S.Emit(Body.size()); - - for (const_body_iterator I=body_begin(), E=body_end(); I!=E; ++I) - S.EmitOwnedPtr(*I); + S.Emit(NumStmts); + if (NumStmts) S.BatchEmitOwnedPtrs(NumStmts, &Body[0]); } CompoundStmt* CompoundStmt::CreateImpl(Deserializer& D, ASTContext& C) { @@ -507,13 +506,15 @@ CompoundStmt* CompoundStmt::CreateImpl(Deserializer& D, ASTContext& C) { unsigned size = D.ReadInt(); CompoundStmt* stmt = new (C, llvm::alignof<CompoundStmt>()) - CompoundStmt(NULL, 0, LB, RB); - - stmt->Body.reserve(size); - - for (unsigned i = 0; i < size; ++i) - stmt->Body.push_back(D.ReadOwnedPtr<Stmt>(C)); + CompoundStmt(C, NULL, 0, LB, RB); + + stmt->NumStmts = size; + if (size) { + stmt->Body = new (C) Stmt*[size]; + D.BatchReadOwnedPtrs(size, &stmt->Body[0], C); + } + return stmt; } @@ -1306,7 +1307,7 @@ ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C) { Expr *B = D.ReadOwnedPtr<Expr>(C); IdentifierInfo *A = D.ReadPtr<IdentifierInfo>(); SourceLocation AL = SourceLocation::ReadVal(D); - return new ExtVectorElementExpr(T, B, *A, AL); + return new (C) ExtVectorElementExpr(T, B, *A, AL); } void BlockExpr::EmitImpl(Serializer& S) const { |