summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Stmt.cpp
diff options
context:
space:
mode:
authorSam Weinig <sam.weinig@gmail.com>2010-02-03 03:56:39 +0000
committerSam Weinig <sam.weinig@gmail.com>2010-02-03 03:56:39 +0000
commita16b0dd1aef297b66df1ee2b0d0374949a25ac67 (patch)
treee265f01c4f33eccde2d03289c435782540030e04 /clang/lib/AST/Stmt.cpp
parent27a41d5473041c2b6d9459ddd2299381dad9678d (diff)
downloadbcm5719-llvm-a16b0dd1aef297b66df1ee2b0d0374949a25ac67.tar.gz
bcm5719-llvm-a16b0dd1aef297b66df1ee2b0d0374949a25ac67.zip
Implement Doug's suggestion. Eliminate the Stmts pointer from CXXTryStmt and instead allocate the statements after the object.
llvm-svn: 95199
Diffstat (limited to 'clang/lib/AST/Stmt.cpp')
-rw-r--r--clang/lib/AST/Stmt.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp
index e90eceec1b3..8347249a466 100644
--- a/clang/lib/AST/Stmt.cpp
+++ b/clang/lib/AST/Stmt.cpp
@@ -407,10 +407,20 @@ ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc,
RParenLoc = rparenloc;
}
-CXXTryStmt::CXXTryStmt(ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock,
+CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc,
+ Stmt *tryBlock, Stmt **handlers,
+ unsigned numHandlers) {
+ std::size_t Size = sizeof(CXXTryStmt);
+ Size += ((numHandlers + 1) * sizeof(Stmt));
+
+ void *Mem = C.Allocate(Size, llvm::alignof<CXXTryStmt>());
+ return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers, numHandlers);
+}
+
+CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
Stmt **handlers, unsigned numHandlers)
: Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
- Stmts = new (C) Stmt*[NumHandlers + 1];
+ Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
Stmts[0] = tryBlock;
std::copy(handlers, handlers + NumHandlers, Stmts + 1);
}
@@ -493,14 +503,6 @@ void AsmStmt::DoDestroy(ASTContext &C) {
C.Deallocate((void *)this);
}
-void CXXTryStmt::DoDestroy(ASTContext& C) {
- DestroyChildren(C);
- C.Deallocate(Stmts);
-
- this->~CXXTryStmt();
- C.Deallocate((void *)this);
-}
-
//===----------------------------------------------------------------------===//
// Child Iterators for iterating over subexpressions/substatements
//===----------------------------------------------------------------------===//
@@ -664,5 +666,10 @@ Stmt::child_iterator CXXCatchStmt::child_end() {
}
// CXXTryStmt
-Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; }
-Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+NumHandlers+1; }
+Stmt::child_iterator CXXTryStmt::child_begin() {
+ return reinterpret_cast<Stmt **>(this + 1);
+}
+
+Stmt::child_iterator CXXTryStmt::child_end() {
+ return reinterpret_cast<Stmt **>(this + 1) + NumHandlers + 1;
+}
OpenPOWER on IntegriCloud