aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/ParseAST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/ParseAST.cpp')
-rw-r--r--lib/Sema/ParseAST.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index e2ee88ac86bc..d3f26d875cc4 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -13,13 +13,15 @@
#include "clang/Sema/ParseAST.h"
#include "Sema.h"
+#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/SemaConsumer.h"
#include "clang/Sema/ExternalSemaSource.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/Stmt.h"
#include "clang/Parse/Parser.h"
-#include "llvm/ADT/OwningPtr.h"
+#include <cstdio>
+
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -32,7 +34,9 @@ using namespace clang;
///
void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
ASTContext &Ctx, bool PrintStats,
- bool CompleteTranslationUnit) {
+ bool CompleteTranslationUnit,
+ CodeCompleteConsumer *(*CreateCodeCompleter)(Sema &, void *Data),
+ void *CreateCodeCompleterData) {
// Collect global stats on Decls/Stmts (until we have a module streamer).
if (PrintStats) {
Decl::CollectingStats(true);
@@ -42,25 +46,31 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit);
Parser P(PP, S);
PP.EnterMainSourceFile();
-
+
// Initialize the parser.
P.Initialize();
-
+
Consumer->Initialize(Ctx);
-
+
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer))
SC->InitializeSema(S);
if (ExternalASTSource *External = Ctx.getExternalSource()) {
- if (ExternalSemaSource *ExternalSema =
+ if (ExternalSemaSource *ExternalSema =
dyn_cast<ExternalSemaSource>(External))
ExternalSema->InitializeSema(S);
External->StartTranslationUnit(Consumer);
}
- Parser::DeclGroupPtrTy ADecl;
+ CodeCompleteConsumer *CodeCompleter = 0;
+ if (CreateCodeCompleter) {
+ CodeCompleter = CreateCodeCompleter(S, CreateCodeCompleterData);
+ S.setCodeCompleteConsumer(CodeCompleter);
+ }
+ Parser::DeclGroupPtrTy ADecl;
+
while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file.
// If we got a null return and something *was* parsed, ignore it. This
// is due to a top-level semicolon, an action override, or a parse error
@@ -68,9 +78,18 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
if (ADecl)
Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
};
-
+
+ // process any TopLevelDecls generated by #pragma weak
+ for (llvm::SmallVector<Decl*,2>::iterator
+ I = S.WeakTopLevelDecls().begin(),
+ E = S.WeakTopLevelDecls().end(); I != E; ++I)
+ Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
+
Consumer->HandleTranslationUnit(Ctx);
+ if (CreateCodeCompleter)
+ delete CodeCompleter;
+
if (PrintStats) {
fprintf(stderr, "\nSTATISTICS:\n");
P.getActions().PrintStats();
@@ -78,7 +97,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
Decl::PrintStats();
Stmt::PrintStats();
Consumer->PrintStats();
-
+
Decl::CollectingStats(false);
Stmt::CollectingStats(false);
}