]> granicus.if.org Git - clang/commitdiff
ParseAST now conditionally deletes the passed ASTConsumer.
authorTed Kremenek <kremenek@apple.com>
Thu, 7 Aug 2008 19:47:41 +0000 (19:47 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 7 Aug 2008 19:47:41 +0000 (19:47 +0000)
ModuleBuilder now performs llvmgen in HandleTranslationUnit.

This patch follows from the discussion on the following thread on cfe-commits:

http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080804/006849.html

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54486 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/ParseAST.h
lib/CodeGen/ModuleBuilder.cpp
lib/Sema/ParseAST.cpp

index 61ce30d9f4ee0413ac84136751ac7b6f45a73526..9f6690a0bdc70decbb1f4f3ffccc0b3a8b8f5887 100644 (file)
@@ -21,7 +21,7 @@ namespace clang {
   /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
   /// the file is parsed.  This takes ownership of the ASTConsumer and
   /// ultimately deletes it.
-  void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false);
+  void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false, bool DeleteConsumer = true);
 }  // end namespace clang
 
 #endif
index 7329ed1d90d067a69bda1c7f4a8d0eafd56d48ec..6ce4e6894d946f02749541fcdc5843e32b95bc88 100644 (file)
@@ -49,13 +49,7 @@ namespace {
     
     virtual ~CodeGeneratorImpl() {}
     
-    virtual llvm::Module* ReleaseModule() {      
-      if (Diags.hasErrorOccurred())
-        return 0;
-      
-      if (Builder)
-        Builder->Release();
-      
+    virtual llvm::Module* ReleaseModule() {
       return M.take();
     }
     
@@ -134,7 +128,16 @@ namespace {
     virtual void HandleTagDeclDefinition(TagDecl *D) {
       Builder->UpdateCompletedType(D);
     }
-    
+
+    virtual void HandleTranslationUnit(TranslationUnit& TU) {
+      if (Diags.hasErrorOccurred()) {
+        M.reset();
+        return;
+      }
+
+      if (Builder)
+        Builder->Release();
+    };
   };
 }
 
index 94e0185f03f92c8bc42057ec321fb8efd0043721..6b9b8d5804dd336ba4cc766f77c86088013dc2f0 100644 (file)
@@ -27,7 +27,7 @@ using namespace clang;
 /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
 /// the file is parsed.  This takes ownership of the ASTConsumer and
 /// ultimately deletes it.
-void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
+void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats, bool DeleteConsumer) {
   // Collect global stats on Decls/Stmts (until we have a module streamer).
   if (PrintStats) {
     Decl::CollectingStats(true);
@@ -78,5 +78,6 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
     Stmt::CollectingStats(false);
   }
   
-  delete Consumer;
+  if (DeleteConsumer)
+    delete Consumer;
 }