From: Ted Kremenek Date: Mon, 19 May 2008 22:02:12 +0000 (+0000) Subject: Added Stmt::DestroyChildren, which will be used by the dstors of the subclasses of... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c1863ef36a74e8203f00289d19856ad956f48b9;p=clang Added Stmt::DestroyChildren, which will be used by the dstors of the subclasses of Stmt to recursively delete their child AST nodes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51278 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 5875d008b3..dac69a1610 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -50,6 +50,12 @@ public: }; private: const StmtClass sClass; + +protected: + /// DestroyChildren - Invoked by destructors of subclasses of Stmt to + /// recursively release child AST nodes. + void DestroyChildren(); + public: Stmt(StmtClass SC) : sClass(SC) { if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 572280bc05..ffc6c2e62a 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -42,6 +42,11 @@ const char *Stmt::getStmtClassName() const { return getStmtInfoTableEntry(sClass).Name; } +void Stmt::DestroyChildren() { + for (child_iterator I = child_begin(), E = child_end(); I !=E; ++I) + delete *I; // Handles the case when *I == NULL. +} + void Stmt::PrintStats() { // Ensure the table is primed. getStmtInfoTableEntry(Stmt::NullStmtClass);