add a new ASTConsumer consumer to simplify stuff in the driver.
Switch -parse-ast over to it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41991 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/ASTStreamer.cpp b/Sema/ASTStreamer.cpp
index c0f4cae..f96621d 100644
--- a/Sema/ASTStreamer.cpp
+++ b/Sema/ASTStreamer.cpp
@@ -13,11 +13,14 @@
#include "clang/Sema/ASTStreamer.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTConsumer.h"
#include "Sema.h"
#include "clang/Parse/Action.h"
#include "clang/Parse/Parser.h"
using namespace clang;
+ASTConsumer::~ASTConsumer() {}
+
namespace {
class ASTStreamer {
Parser P;
@@ -84,6 +87,39 @@
// Public interface to the file
//===----------------------------------------------------------------------===//
+/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
+/// the file is parsed.
+void clang::ParseAST(Preprocessor &PP, unsigned MainFileID,
+ ASTConsumer &Consumer, bool PrintStats) {
+ // Collect global stats on Decls/Stmts (until we have a module streamer).
+ if (PrintStats) {
+ Decl::CollectingStats(true);
+ Stmt::CollectingStats(true);
+ }
+
+ ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
+ PP.getIdentifierTable());
+
+ ASTStreamer Streamer(PP, Context, MainFileID);
+
+ Consumer.Initialize(Context, MainFileID);
+
+ while (Decl *D = Streamer.ReadTopLevelDecl())
+ Consumer.HandleTopLevelDecl(D);
+
+ if (PrintStats) {
+ fprintf(stderr, "\nSTATISTICS:\n");
+ Streamer.PrintStats();
+ Context.PrintStats();
+ Decl::PrintStats();
+ Stmt::PrintStats();
+ Consumer.PrintStats();
+
+ Decl::CollectingStats(false);
+ Stmt::CollectingStats(false);
+ }
+}
+
/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor
/// and FileID.
ASTStreamerTy *clang::ASTStreamer_Init(Preprocessor &pp, ASTContext &ctxt,