///
class CXXTryStmt : public Stmt {
SourceLocation TryLoc;
+
// First place is the guarded CompoundStatement. Subsequent are the handlers.
- // More than three handlers should be rare.
- llvm::SmallVector<Stmt*, 4> Stmts;
+ Stmt **Stmts;
+ unsigned NumHandlers;
+
+protected:
+ virtual void DoDestroy(ASTContext &Ctx);
public:
- CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
+ CXXTryStmt(ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock,
Stmt **handlers, unsigned numHandlers);
virtual SourceRange getSourceRange() const {
}
SourceLocation getTryLoc() const { return TryLoc; }
- SourceLocation getEndLoc() const { return Stmts.back()->getLocEnd(); }
+ SourceLocation getEndLoc() const { return Stmts[NumHandlers]->getLocEnd(); }
CompoundStmt *getTryBlock() { return llvm::cast<CompoundStmt>(Stmts[0]); }
const CompoundStmt *getTryBlock() const {
return llvm::cast<CompoundStmt>(Stmts[0]);
}
- unsigned getNumHandlers() const { return Stmts.size() - 1; }
+ unsigned getNumHandlers() const { return NumHandlers; }
CXXCatchStmt *getHandler(unsigned i) {
return llvm::cast<CXXCatchStmt>(Stmts[i + 1]);
}
}
}
+QualType CXXCatchStmt::getCaughtType() const {
+ if (ExceptionDecl)
+ return ExceptionDecl->getType();
+ return QualType();
+}
+
//===----------------------------------------------------------------------===//
// Constructors
//===----------------------------------------------------------------------===//
RParenLoc = rparenloc;
}
+CXXTryStmt::CXXTryStmt(ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock,
+ Stmt **handlers, unsigned numHandlers)
+ : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
+ Stmts = new (C) Stmt*[NumHandlers + 1];
+ Stmts[0] = tryBlock;
+ std::copy(handlers, handlers + NumHandlers, Stmts + 1);
+}
+
//===----------------------------------------------------------------------===//
// AST Destruction.
//===----------------------------------------------------------------------===//
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
//===----------------------------------------------------------------------===//
return &HandlerBlock + 1;
}
-QualType CXXCatchStmt::getCaughtType() const {
- if (ExceptionDecl)
- return ExceptionDecl->getType();
- return QualType();
-}
-
// CXXTryStmt
Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; }
-Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); }
-
-CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
- Stmt **handlers, unsigned numHandlers)
- : Stmt(CXXTryStmtClass), TryLoc(tryLoc) {
- Stmts.push_back(tryBlock);
- Stmts.insert(Stmts.end(), handlers, handlers + numHandlers);
-}
+Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+NumHandlers+1; }