summaryrefslogtreecommitdiffstats
path: root/lib/AST/Stmt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/AST/Stmt.cpp')
-rw-r--r--lib/AST/Stmt.cpp128
1 files changed, 89 insertions, 39 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index fad80ec..7c7aeb8 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -47,17 +47,6 @@ const char *Stmt::getStmtClassName() const {
return getStmtInfoTableEntry((StmtClass)sClass).Name;
}
-void Stmt::DestroyChildren(ASTContext &C) {
- for (child_iterator I = child_begin(), E = child_end(); I !=E; )
- if (Stmt* Child = *I++) Child->Destroy(C);
-}
-
-void Stmt::DoDestroy(ASTContext &C) {
- DestroyChildren(C);
- this->~Stmt();
- C.Deallocate((void *)this);
-}
-
void Stmt::PrintStats() {
// Ensure the table is primed.
getStmtInfoTableEntry(Stmt::NullStmtClass);
@@ -93,20 +82,6 @@ bool Stmt::CollectingStats(bool Enable) {
return StatSwitch;
}
-void SwitchStmt::DoDestroy(ASTContext &Ctx) {
- // Destroy the SwitchCase statements in this switch. In the normal
- // case, this loop will merely decrement the reference counts from
- // the Retain() calls in addSwitchCase();
- SwitchCase *SC = FirstCase;
- while (SC) {
- SwitchCase *Next = SC->getNextSwitchCase();
- SC->Destroy(Ctx);
- SC = Next;
- }
-
- Stmt::DoDestroy(Ctx);
-}
-
void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
if (this->Body)
C.Deallocate(Body);
@@ -412,6 +387,71 @@ ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc,
RParenLoc = rparenloc;
}
+//===----------------------------------------------------------------------===//
+// AST Destruction.
+//===----------------------------------------------------------------------===//
+
+void Stmt::DestroyChildren(ASTContext &C) {
+ for (child_iterator I = child_begin(), E = child_end(); I !=E; )
+ if (Stmt* Child = *I++) Child->Destroy(C);
+}
+
+static void BranchDestroy(ASTContext &C, Stmt *S, Stmt **SubExprs,
+ unsigned NumExprs) {
+ // We do not use child_iterator here because that will include
+ // the expressions referenced by the condition variable.
+ for (Stmt **I = SubExprs, **E = SubExprs + NumExprs; I != E; ++I)
+ if (Stmt *Child = *I) Child->Destroy(C);
+
+ S->~Stmt();
+ C.Deallocate((void *) S);
+}
+
+void Stmt::DoDestroy(ASTContext &C) {
+ DestroyChildren(C);
+ this->~Stmt();
+ C.Deallocate((void *)this);
+}
+
+void CXXCatchStmt::DoDestroy(ASTContext& C) {
+ if (ExceptionDecl)
+ ExceptionDecl->Destroy(C);
+ Stmt::DoDestroy(C);
+}
+
+void DeclStmt::DoDestroy(ASTContext &C) {
+ // Don't use StmtIterator to iterate over the Decls, as that can recurse
+ // into VLA size expressions (which are owned by the VLA). Further, Decls
+ // are owned by the DeclContext, and will be destroyed with them.
+ if (DG.isDeclGroup())
+ DG.getDeclGroup().Destroy(C);
+}
+
+void IfStmt::DoDestroy(ASTContext &C) {
+ BranchDestroy(C, this, SubExprs, END_EXPR);
+}
+
+void ForStmt::DoDestroy(ASTContext &C) {
+ BranchDestroy(C, this, SubExprs, END_EXPR);
+}
+
+void SwitchStmt::DoDestroy(ASTContext &C) {
+ // Destroy the SwitchCase statements in this switch. In the normal
+ // case, this loop will merely decrement the reference counts from
+ // the Retain() calls in addSwitchCase();
+ SwitchCase *SC = FirstCase;
+ while (SC) {
+ SwitchCase *Next = SC->getNextSwitchCase();
+ SC->Destroy(C);
+ SC = Next;
+ }
+
+ BranchDestroy(C, this, SubExprs, END_EXPR);
+}
+
+void WhileStmt::DoDestroy(ASTContext &C) {
+ BranchDestroy(C, this, SubExprs, END_EXPR);
+}
//===----------------------------------------------------------------------===//
// Child Iterators for iterating over subexpressions/substatements
@@ -447,24 +487,40 @@ Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; }
Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
// IfStmt
-Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; }
-Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; }
+Stmt::child_iterator IfStmt::child_begin() {
+ return child_iterator(Var, &SubExprs[0]);
+}
+Stmt::child_iterator IfStmt::child_end() {
+ return child_iterator(0, &SubExprs[0]+END_EXPR);
+}
// SwitchStmt
-Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; }
-Stmt::child_iterator SwitchStmt::child_end() { return &SubExprs[0]+END_EXPR; }
+Stmt::child_iterator SwitchStmt::child_begin() {
+ return child_iterator(Var, &SubExprs[0]);
+}
+Stmt::child_iterator SwitchStmt::child_end() {
+ return child_iterator(0, &SubExprs[0]+END_EXPR);
+}
// WhileStmt
-Stmt::child_iterator WhileStmt::child_begin() { return &SubExprs[0]; }
-Stmt::child_iterator WhileStmt::child_end() { return &SubExprs[0]+END_EXPR; }
+Stmt::child_iterator WhileStmt::child_begin() {
+ return child_iterator(Var, &SubExprs[0]);
+}
+Stmt::child_iterator WhileStmt::child_end() {
+ return child_iterator(0, &SubExprs[0]+END_EXPR);
+}
// DoStmt
Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; }
Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; }
// ForStmt
-Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; }
-Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; }
+Stmt::child_iterator ForStmt::child_begin() {
+ return child_iterator(CondVar, &SubExprs[0]);
+}
+Stmt::child_iterator ForStmt::child_end() {
+ return child_iterator(0, &SubExprs[0]+END_EXPR);
+}
// ObjCForCollectionStmt
Stmt::child_iterator ObjCForCollectionStmt::child_begin() {
@@ -565,12 +621,6 @@ QualType CXXCatchStmt::getCaughtType() const {
return QualType();
}
-void CXXCatchStmt::DoDestroy(ASTContext& C) {
- if (ExceptionDecl)
- ExceptionDecl->Destroy(C);
- Stmt::DoDestroy(C);
-}
-
// CXXTryStmt
Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; }
Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); }
OpenPOWER on IntegriCloud