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/Driver/ASTStreamers.cpp b/Driver/ASTStreamers.cpp
index b60a994..b3517df 100644
--- a/Driver/ASTStreamers.cpp
+++ b/Driver/ASTStreamers.cpp
@@ -20,32 +20,6 @@
#include "clang/Sema/ASTStreamer.h"
using namespace clang;
-void clang::BuildASTs(Preprocessor &PP, unsigned MainFileID, bool Stats) {
- // collect global stats on Decls/Stmts (until we have a module streamer)
- if (Stats) {
- Decl::CollectingStats(true);
- Stmt::CollectingStats(true);
- }
-
- ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
- PP.getIdentifierTable());
- ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
-
- while (ASTStreamer_ReadTopLevelDecl(Streamer))
- /* keep reading */;
-
- if (Stats) {
- fprintf(stderr, "\nSTATISTICS:\n");
- ASTStreamer_PrintStats(Streamer);
- Context.PrintStats();
- Decl::PrintStats();
- Stmt::PrintStats();
- }
-
- ASTStreamer_Terminate(Streamer);
-}
-
-
static void PrintFunctionDeclStart(FunctionDecl *FD) {
bool HasBody = FD->getBody();
diff --git a/Driver/ASTStreamers.h b/Driver/ASTStreamers.h
index f568e8e..e21c1c9 100644
--- a/Driver/ASTStreamers.h
+++ b/Driver/ASTStreamers.h
@@ -19,8 +19,8 @@
class Preprocessor;
class FunctionDecl;
class TypedefDecl;
+class ASTConsumer;
-void BuildASTs(Preprocessor &PP, unsigned MainFileID, bool Stats);
void PrintASTs(Preprocessor &PP, unsigned MainFileID, bool Stats);
void DumpASTs(Preprocessor &PP, unsigned MainFileID, bool Stats);
diff --git a/Driver/DiagChecker.cpp b/Driver/DiagChecker.cpp
index e2efd96..3b08924 100644
--- a/Driver/DiagChecker.cpp
+++ b/Driver/DiagChecker.cpp
@@ -14,6 +14,8 @@
#include "clang.h"
#include "ASTStreamers.h"
#include "TextDiagnosticBuffer.h"
+#include "clang/Sema/ASTStreamer.h"
+#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Preprocessor.h"
using namespace clang;
@@ -223,8 +225,12 @@
/// CheckDiagnostics - Implement the -parse-ast-check diagnostic verifier.
bool clang::CheckDiagnostics(Preprocessor &PP, unsigned MainFileID) {
- // Parse the specified input file.
- BuildASTs(PP, MainFileID, false);
+ // Parse the specified input file, building ASTs and performing sema, but
+ // doing nothing else.
+{
+ ASTConsumer NullConsumer;
+ ParseAST(PP, MainFileID, NullConsumer);
+}
// Gather the set of expected diagnostics.
DiagList ExpectedErrors, ExpectedWarnings;
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 79a09f1..d6f4da8 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -26,6 +26,8 @@
#include "ASTStreamers.h"
#include "TextDiagnosticBuffer.h"
#include "TextDiagnosticPrinter.h"
+#include "clang/Sema/ASTStreamer.h"
+#include "clang/AST/ASTConsumer.h"
#include "clang/Parse/Parser.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Basic/FileManager.h"
@@ -51,7 +53,7 @@
ParseASTPrint, // Parse ASTs and print them.
ParseASTDump, // Parse ASTs and dump them.
ParseASTCheck, // Parse ASTs and check diagnostics.
- ParseAST, // Parse ASTs.
+ BuildAST, // Parse ASTs.
ParseCFGDump, // Parse ASTS. Build CFGs. Print CFGs.
ParseCFGView, // Parse ASTS. Build CFGs. View CFGs.
AnalysisLiveVariables, // Print results of live-variable analysis.
@@ -80,7 +82,7 @@
"Run parser and perform semantic analysis"),
clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
"Run parser and print each callback invoked"),
- clEnumValN(ParseAST, "parse-ast",
+ clEnumValN(BuildAST, "parse-ast",
"Run parser and build ASTs"),
clEnumValN(ParseASTPrint, "parse-ast-print",
"Run parser, build ASTs, then print ASTs"),
@@ -837,9 +839,11 @@
ClearSourceMgr = true;
break;
case ParseSyntaxOnly: // -fsyntax-only
- case ParseAST:
- BuildASTs(PP, MainFileID, Stats);
+ case BuildAST: {
+ ASTConsumer NullConsumer;
+ ParseAST(PP, MainFileID, NullConsumer, Stats);
break;
+ }
case ParseASTPrint:
PrintASTs(PP, MainFileID, Stats);
break;