aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-03 06:24:16 +0000
committerChris Lattner <sabre@nondot.org>2007-11-03 06:24:16 +0000
commit31e6c7ddfeeefe05b67220bc87fa23d4338d1056 (patch)
treef445f70ad9a9bb949af7c23aa2f92a873ca51060
parent8aab17e82aab6b3f266ef1884253226d2cb8b8d8 (diff)
Fix ownership model of ParseAST to allow the dtor of
ASTConsumer to process the AST before it is destroyed. This allows elimination of HandleObjcMetaDataEmission. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43659 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/DiagChecker.cpp4
-rw-r--r--Driver/RewriteTest.cpp17
-rw-r--r--Driver/clang.cpp9
-rw-r--r--Sema/ASTStreamer.cpp15
-rw-r--r--include/clang/AST/ASTConsumer.h5
-rw-r--r--include/clang/Sema/ASTStreamer.h5
6 files changed, 23 insertions, 32 deletions
diff --git a/Driver/DiagChecker.cpp b/Driver/DiagChecker.cpp
index 4b457290e3..8daaa6cce2 100644
--- a/Driver/DiagChecker.cpp
+++ b/Driver/DiagChecker.cpp
@@ -227,8 +227,8 @@ static bool CheckResults(Preprocessor &PP,
/// CheckASTConsumer - Implement diagnostic checking for AST consumers.
bool clang::CheckASTConsumer(Preprocessor &PP, unsigned MainFileID,
ASTConsumer* C) {
-
- ParseAST(PP, MainFileID, *C);
+ // Parse the AST and run the consumer, ultimately deleting C.
+ ParseAST(PP, MainFileID, C);
// Gather the set of expected diagnostics.
DiagList ExpectedErrors, ExpectedWarnings;
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index ca9b1153f0..7bbd7afdb5 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -79,7 +79,6 @@ namespace {
void SynthGetClassFunctionDecl();
// Metadata emission.
- void HandleObjcMetaDataEmission();
void RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl,
std::string &Result);
@@ -162,6 +161,12 @@ RewriteTest::~RewriteTest() {
// Get the top-level buffer that this corresponds to.
RewriteTabs();
+ // Rewrite Objective-c meta data*
+ std::string ResultStr;
+ WriteObjcMetaData(ResultStr);
+ // For now just print the string out.
+ printf("%s", ResultStr.c_str());
+
// Get the buffer corresponding to MainFileID. If we haven't changed it, then
// we are done.
if (const RewriteBuffer *RewriteBuf =
@@ -175,16 +180,6 @@ RewriteTest::~RewriteTest() {
}
-/// HandleObjcMetaDataEmission - main routine to generate objective-c's
-/// metadata.
-void RewriteTest::HandleObjcMetaDataEmission() {
- // Rewrite Objective-c meta data*
- std::string ResultStr;
- WriteObjcMetaData(ResultStr);
- // For now just print the string out.
- printf("%s", ResultStr.c_str());
-}
-
//===----------------------------------------------------------------------===//
// Syntactic (non-AST) Rewriting Code
//===----------------------------------------------------------------------===//
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 77779f7e80..f568302444 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -821,11 +821,10 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
if (Consumer) {
if (VerifyDiagnostics)
- exit (CheckASTConsumer(PP, MainFileID, Consumer));
- else
- ParseAST(PP, MainFileID, *Consumer, Stats);
-
- delete Consumer;
+ exit(CheckASTConsumer(PP, MainFileID, Consumer));
+
+ // This deletes Consumer.
+ ParseAST(PP, MainFileID, Consumer, Stats);
}
if (Stats) {
diff --git a/Sema/ASTStreamer.cpp b/Sema/ASTStreamer.cpp
index d7f59af04b..be43289be5 100644
--- a/Sema/ASTStreamer.cpp
+++ b/Sema/ASTStreamer.cpp
@@ -89,9 +89,10 @@ void ASTStreamer::PrintStats() const {
//===----------------------------------------------------------------------===//
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
-/// the file is parsed.
+/// the file is parsed. This takes ownership of the ASTConsumer and
+/// ultimately deletes it.
void clang::ParseAST(Preprocessor &PP, unsigned MainFileID,
- ASTConsumer &Consumer, bool PrintStats) {
+ ASTConsumer *Consumer, bool PrintStats) {
// Collect global stats on Decls/Stmts (until we have a module streamer).
if (PrintStats) {
Decl::CollectingStats(true);
@@ -103,22 +104,22 @@ void clang::ParseAST(Preprocessor &PP, unsigned MainFileID,
ASTStreamer Streamer(PP, Context, MainFileID);
- Consumer.Initialize(Context, MainFileID);
+ Consumer->Initialize(Context, MainFileID);
while (Decl *D = Streamer.ReadTopLevelDecl())
- Consumer.HandleTopLevelDecl(D);
+ Consumer->HandleTopLevelDecl(D);
- Consumer.HandleObjcMetaDataEmission();
-
if (PrintStats) {
fprintf(stderr, "\nSTATISTICS:\n");
Streamer.PrintStats();
Context.PrintStats();
Decl::PrintStats();
Stmt::PrintStats();
- Consumer.PrintStats();
+ Consumer->PrintStats();
Decl::CollectingStats(false);
Stmt::CollectingStats(false);
}
+
+ delete Consumer;
}
diff --git a/include/clang/AST/ASTConsumer.h b/include/clang/AST/ASTConsumer.h
index 48b6f0cea4..160260f030 100644
--- a/include/clang/AST/ASTConsumer.h
+++ b/include/clang/AST/ASTConsumer.h
@@ -34,11 +34,6 @@ public:
virtual void HandleTopLevelDecl(Decl *D) {
}
- /// HandleObjcMetaDataEmission - top level routine for objective-c
- /// metadata emission.
- virtual void HandleObjcMetaDataEmission() {
- }
-
/// PrintStats - If desired, print any statistics.
virtual void PrintStats() {
}
diff --git a/include/clang/Sema/ASTStreamer.h b/include/clang/Sema/ASTStreamer.h
index 3130613e7a..bffc4db993 100644
--- a/include/clang/Sema/ASTStreamer.h
+++ b/include/clang/Sema/ASTStreamer.h
@@ -21,9 +21,10 @@ namespace clang {
class ASTConsumer;
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
- /// the file is parsed. This does not take ownership of the ASTConsumer.
+ /// the file is parsed. This takes ownership of the ASTConsumer and
+ /// ultimately deletes it.
void ParseAST(Preprocessor &pp, unsigned MainFileID,
- ASTConsumer &C, bool PrintStats = false);
+ ASTConsumer *C, bool PrintStats = false);
} // end namespace clang
#endif