From 112fd083fafabcda3e9ead58d2359fd9e3f987c3 Mon Sep 17 00:00:00 2001 From: John McCall Date: Thu, 12 Aug 2010 21:39:05 +0000 Subject: Fixing the build isn't good enough; back out r110956 and r110953. llvm-svn: 110958 --- clang/lib/Sema/ParseAST.cpp | 64 +++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'clang/lib/Sema/ParseAST.cpp') diff --git a/clang/lib/Sema/ParseAST.cpp b/clang/lib/Sema/ParseAST.cpp index c0208c7bbd1..4286b3f7c4d 100644 --- a/clang/lib/Sema/ParseAST.cpp +++ b/clang/lib/Sema/ParseAST.cpp @@ -56,54 +56,68 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, ASTContext &Ctx, bool PrintStats, bool CompleteTranslationUnit, CodeCompleteConsumer *CompletionConsumer) { - Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer); - ParseAST(S, PrintStats); -} - -void clang::ParseAST(Sema &S, bool PrintStats) { // Collect global stats on Decls/Stmts (until we have a module streamer). if (PrintStats) { Decl::CollectingStats(true); Stmt::CollectingStats(true); } - ASTConsumer *Consumer = &S.getASTConsumer(); + Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer); + Parser P(PP, S); + PP.EnterMainSourceFile(); + + // Initialize the parser. + P.Initialize(); + + Consumer->Initialize(Ctx); + + if (SemaConsumer *SC = dyn_cast(Consumer)) + SC->InitializeSema(S); + + if (ExternalASTSource *External = Ctx.getExternalSource()) { + if (ExternalSemaSource *ExternalSema = + dyn_cast(External)) + ExternalSema->InitializeSema(S); - Parser P(S.getPreprocessor(), S); - S.getPreprocessor().EnterMainSourceFile(); - - if (ExternalASTSource *External = S.getASTContext().getExternalSource()) External->StartTranslationUnit(Consumer); - + } + 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 - // skipping something. + // 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 + // skipping something. if (ADecl) Consumer->HandleTopLevelDecl(ADecl.getAsVal()); }; // Check for any pending objective-c implementation decl. while ((ADecl = P.FinishPendingObjCActions())) Consumer->HandleTopLevelDecl(ADecl.getAsVal()); - + // Process any TopLevelDecls generated by #pragma weak. for (llvm::SmallVector::iterator - I = S.WeakTopLevelDecls().begin(), - E = S.WeakTopLevelDecls().end(); I != E; ++I) + I = S.WeakTopLevelDecls().begin(), + E = S.WeakTopLevelDecls().end(); I != E; ++I) Consumer->HandleTopLevelDecl(DeclGroupRef(*I)); - + // Dump record layouts, if requested. - if (S.getLangOptions().DumpRecordLayouts) - DumpRecordLayouts(S.getASTContext()); - - Consumer->HandleTranslationUnit(S.getASTContext()); - + if (PP.getLangOptions().DumpRecordLayouts) + DumpRecordLayouts(Ctx); + + Consumer->HandleTranslationUnit(Ctx); + + if (ExternalSemaSource *ESS = + dyn_cast_or_null(Ctx.getExternalSource())) + ESS->ForgetSema(); + + if (SemaConsumer *SC = dyn_cast(Consumer)) + SC->ForgetSema(); + if (PrintStats) { fprintf(stderr, "\nSTATISTICS:\n"); P.getActions().PrintStats(); - S.getASTContext().PrintStats(); + Ctx.PrintStats(); Decl::PrintStats(); Stmt::PrintStats(); Consumer->PrintStats(); -- cgit v1.2.3