aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-08-08 02:46:37 +0000
committerTed Kremenek <kremenek@apple.com>2008-08-08 02:46:37 +0000
commit7e7e6253d45eb2ca4a4ad9cafcb8b80693f0670a (patch)
tree3f099d92aeca2397c818d5651b18e261704cc9af
parent909cd267dd8f66867c0aaef3bef052dc27bde47c (diff)
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
-rw-r--r--Driver/clang.cpp15
-rw-r--r--include/clang/Sema/ParseAST.h3
-rw-r--r--lib/Sema/ParseAST.cpp5
3 files changed, 9 insertions, 14 deletions
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<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) {
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;
}