[cfe-commits] r92112 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp

Ted Kremenek kremenek at apple.com
Wed Dec 23 17:48:39 PST 2009


Author: kremenek
Date: Wed Dec 23 19:48:39 2009
New Revision: 92112

URL: http://llvm.org/viewvc/llvm-project?rev=92112&view=rev
Log:
Coelesce 'DoDestroy()' methods in Stmt.cpp, and modify the child_iterator returned by ForStmt to include the initializer of the condition variable.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=92112&r1=92111&r2=92112&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Dec 23 19:48:39 2009
@@ -938,6 +938,9 @@
   // Iterators
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
+  
+protected:
+  virtual void DoDestroy(ASTContext &Ctx);
 };
 
 /// GotoStmt - This represents a direct goto.

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=92112&r1=92111&r2=92112&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Wed Dec 23 19:48:39 2009
@@ -47,17 +47,6 @@
   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,26 +82,6 @@
   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;
-  }
-  
-  // We do not use child_iterator here because that will include
-  // the expressions referenced by the condition variable.
-  for (Stmt **I = &SubExprs[0], **E = &SubExprs[END_EXPR]; I != E; ++I)
-    if (Stmt *Child = *I) Child->Destroy(Ctx);
-  
-  this->~Stmt();
-  Ctx.Deallocate((void *)this);
-}
-
 void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
   if (this->Body)
     C.Deallocate(Body);
@@ -418,18 +387,36 @@
   RParenLoc = rparenloc;
 }
 
-
 //===----------------------------------------------------------------------===//
-//  Child Iterators for iterating over subexpressions/substatements
+// AST Destruction.
 //===----------------------------------------------------------------------===//
 
-// DeclStmt
-Stmt::child_iterator DeclStmt::child_begin() {
-  return StmtIterator(DG.begin(), DG.end());
+void Stmt::DestroyChildren(ASTContext &C) {
+  for (child_iterator I = child_begin(), E = child_end(); I !=E; )
+    if (Stmt* Child = *I++) Child->Destroy(C);
 }
 
-Stmt::child_iterator DeclStmt::child_end() {
-  return StmtIterator(DG.end(), DG.end());
+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) {
@@ -440,6 +427,45 @@
     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
+//===----------------------------------------------------------------------===//
+
+// DeclStmt
+Stmt::child_iterator DeclStmt::child_begin() {
+  return StmtIterator(DG.begin(), DG.end());
+}
+
+Stmt::child_iterator DeclStmt::child_end() {
+  return StmtIterator(DG.end(), DG.end());
+}
+
 // NullStmt
 Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
 Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
@@ -467,15 +493,6 @@
 Stmt::child_iterator IfStmt::child_end() {
   return child_iterator(0, &SubExprs[0]+END_EXPR);
 }
-void IfStmt::DoDestroy(ASTContext &C) {
-  // We do not use child_iterator here because that will include
-  // the expressions referenced by the condition variable.
-  for (Stmt **I = &SubExprs[0], **E = &SubExprs[END_EXPR]; I != E; ++I)
-    if (Stmt *Child = *I) Child->Destroy(C);
-
-  this->~Stmt();
-  C.Deallocate((void *)this);
-}
 
 // SwitchStmt
 Stmt::child_iterator SwitchStmt::child_begin() {
@@ -492,24 +509,18 @@
 Stmt::child_iterator WhileStmt::child_end() {
   return child_iterator(0, &SubExprs[0]+END_EXPR);
 }
-void WhileStmt::DoDestroy(ASTContext &C) {
-  // We do not use child_iterator here because that will include
-  // the expressions referenced by the condition variable.
-  for (Stmt **I = &SubExprs[0], **E = &SubExprs[END_EXPR]; I != E; ++I)
-    if (Stmt *Child = *I) Child->Destroy(C);
-  
-  this->~Stmt();
-  C.Deallocate((void *)this);
-}
-
 
 // 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(CondVar, &SubExprs[0]+END_EXPR);
+}
 
 // ObjCForCollectionStmt
 Stmt::child_iterator ObjCForCollectionStmt::child_begin() {
@@ -610,12 +621,6 @@
   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(); }





More information about the cfe-commits mailing list