summaryrefslogtreecommitdiffstats
path: root/clang/Sema/ASTStreamer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-09-15 22:56:56 +0000
committerChris Lattner <sabre@nondot.org>2007-09-15 22:56:56 +0000
commit75e0c8cf4c25014d591d5ffe0b88807c61e27c5f (patch)
tree774f20844c7277de9a47aec7c1f43c0cd4abdf9f /clang/Sema/ASTStreamer.cpp
parente27d865e366fe9731129c7e77f01623acb8172fe (diff)
downloadbcm5719-llvm-75e0c8cf4c25014d591d5ffe0b88807c61e27c5f.tar.gz
bcm5719-llvm-75e0c8cf4c25014d591d5ffe0b88807c61e27c5f.zip
add a new ASTConsumer consumer to simplify stuff in the driver.
Switch -parse-ast over to it. llvm-svn: 41991
Diffstat (limited to 'clang/Sema/ASTStreamer.cpp')
-rw-r--r--clang/Sema/ASTStreamer.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/Sema/ASTStreamer.cpp b/clang/Sema/ASTStreamer.cpp
index c0f4cae7354..f96621da2cd 100644
--- a/clang/Sema/ASTStreamer.cpp
+++ b/clang/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 @@ void ASTStreamer::PrintStats() const {
// 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,
OpenPOWER on IntegriCloud