]> granicus.if.org Git - clang/commitdiff
ParseAST now never releases the passed ASTConsumer. This is the responsibility of...
authorTed Kremenek <kremenek@apple.com>
Fri, 8 Aug 2008 02:46:37 +0000 (02:46 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 8 Aug 2008 02:46:37 +0000 (02:46 +0000)
The motivation is that clients may either:

(a) query the ASTConsumer object after AST parsing to collect data/etc.
(b) reuse the ASTConsumer.

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

Driver/clang.cpp
include/clang/Sema/ParseAST.h
lib/Sema/ParseAST.cpp

index 28ec5ffbb78d36823c3b9201fc82ab2cdfa79cdf..8bafbd50789812d154ea9d290df6ec5e58ff7c00 100644 (file)
@@ -1228,14 +1228,14 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
 static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
                              const std::string &InFile) {
 
-  ASTConsumer* Consumer = NULL;
+  llvm::OwningPtr<ASTConsumer> Consumer;
   bool ClearSourceMgr = false;
   
   switch (ProgAction) {
   default:
-    Consumer = CreateASTConsumer(InFile, PP.getDiagnostics(),
-                                 PP.getFileManager(), PP.getLangOptions(), &PP,
-                                 &PPF);
+    Consumer.reset(CreateASTConsumer(InFile, PP.getDiagnostics(),
+                                     PP.getFileManager(), PP.getLangOptions(),
+                                     &PP, &PPF));
     
     if (!Consumer) {      
       fprintf(stderr, "Unexpected program action!\n");
@@ -1283,7 +1283,7 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
     break;
       
   case ParseSyntaxOnly:              // -fsyntax-only
-    Consumer = new ASTConsumer();
+    Consumer.reset(new ASTConsumer());
     break;
       
   case RewriteMacros:
@@ -1294,10 +1294,9 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
   
   if (Consumer) {
     if (VerifyDiagnostics)
-      exit(CheckASTConsumer(PP, Consumer));
+      exit(CheckASTConsumer(PP, Consumer.get()));
     
-    // This deletes Consumer.
-    ParseAST(PP, Consumer, Stats);
+    ParseAST(PP, Consumer.get(), Stats);
   }
 
   if (Stats) {
index 4d77a58abd8ec04b0608d5901604a4b4436a02ba..907372ddef4d15bb2681e570408930190f4eb768 100644 (file)
@@ -21,8 +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,
-                bool DeleteConsumer = true);
+  void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false);
 
 }  // end namespace clang
 
index 6b9b8d5804dd336ba4cc766f77c86088013dc2f0..43736e32ac55888df5f8a8057d0d40e8541c97ad 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, bool DeleteConsumer) {
+void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
   // Collect global stats on Decls/Stmts (until we have a module streamer).
   if (PrintStats) {
     Decl::CollectingStats(true);
@@ -77,7 +77,4 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats, b
     Decl::CollectingStats(false);
     Stmt::CollectingStats(false);
   }
-  
-  if (DeleteConsumer)
-    delete Consumer;
 }