From: Ted Kremenek Date: Fri, 8 Aug 2008 02:46:37 +0000 (+0000) Subject: ParseAST now never releases the passed ASTConsumer. This is the responsibility of... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e7e6253d45eb2ca4a4ad9cafcb8b80693f0670a;p=clang ParseAST now never releases the passed ASTConsumer. This is the responsibility of the client. 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 --- diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 28ec5ffbb7..8bafbd5078 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -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 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) { diff --git a/include/clang/Sema/ParseAST.h b/include/clang/Sema/ParseAST.h index 4d77a58abd..907372ddef 100644 --- a/include/clang/Sema/ParseAST.h +++ b/include/clang/Sema/ParseAST.h @@ -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 diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp index 6b9b8d5804..43736e32ac 100644 --- a/lib/Sema/ParseAST.cpp +++ b/lib/Sema/ParseAST.cpp @@ -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; }