aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/ParseAST.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-20 00:43:19 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-20 00:43:19 +0000
commit27f8a28bee33bb0e857cfe1a61c281bbc234b338 (patch)
tree5e0cc27d9b0948a8cd6bc99306411a03d35d49fe /lib/Sema/ParseAST.cpp
parent017cbdfd5417d4d31ae6406421276f90269f75e2 (diff)
Try to plug some memory leaks...
1) Sema::ParseAST now constructs a TranslationUnit object to own the top-level Decls, which releases the top-level Decls upon exiting ParseAST. 2) Bug fix: TranslationUnit::~TranslationUnit handles the case where a Decl is added more than once as a top-level Decl. 3) Decl::Destroy is now a virtual method, obviating the need for a special dispatch based on DeclKind. 3) FunctionDecl::Destroy now releases its Body using its Destroy method. 4) Added Stmt::Destroy and Stmt::DestroyChildren, which recursively delete the child ASTs of a Stmt and call their dstors. We may need to special case dstor/Destroy methods for particular Stmt subclasses that own other dynamically allocated objects besides AST nodes. 5) REGRESSION: We temporarily are not deallocating attributes; a FIXME is provided. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/ParseAST.cpp')
-rw-r--r--lib/Sema/ParseAST.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index 364b072910..fcdc27b10a 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -14,6 +14,7 @@
#include "clang/Sema/ParseAST.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/TranslationUnit.h"
#include "Sema.h"
#include "clang/Parse/Action.h"
#include "clang/Parse/Parser.h"
@@ -36,6 +37,8 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
PP.getIdentifierTable(), PP.getSelectorTable());
+ TranslationUnit TU(Context, PP.getLangOptions());
+
Parser P(PP, *new Sema(PP, Context, *Consumer));
PP.EnterMainSourceFile();
@@ -45,12 +48,16 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
Consumer->Initialize(Context);
Parser::DeclTy *ADecl;
+
while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file.
// If we got a null return and something *was* parsed, ignore it. This
// is due to a top-level semicolon, an action override, or a parse error
// skipping something.
- if (ADecl)
- Consumer->HandleTopLevelDecl(static_cast<Decl*>(ADecl));
+ if (ADecl) {
+ Decl* D = static_cast<Decl*>(ADecl);
+ TU.AddTopLevelDecl(D); // TranslationUnit now owns the Decl.
+ Consumer->HandleTopLevelDecl(D);
+ }
};
if (PrintStats) {