diff options
Diffstat (limited to 'lib/Parse/ParseAST.cpp')
-rw-r--r-- | lib/Parse/ParseAST.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp index d018d4c08ed96..696506099e589 100644 --- a/lib/Parse/ParseAST.cpp +++ b/lib/Parse/ParseAST.cpp @@ -21,6 +21,7 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/Sema.h" #include "clang/Sema/SemaConsumer.h" +#include "clang/Sema/TemplateInstCallback.h" #include "llvm/Support/CrashRecoveryContext.h" #include <cstdio> #include <memory> @@ -121,6 +122,10 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) { bool OldCollectStats = PrintStats; std::swap(OldCollectStats, S.CollectStats); + // Initialize the template instantiation observer chain. + // FIXME: See note on "finalize" below. + initialize(S.TemplateInstCallbacks, S); + ASTConsumer *Consumer = &S.getASTConsumer(); std::unique_ptr<Parser> ParseOP( @@ -136,6 +141,12 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) { CleanupParser(ParseOP.get()); S.getPreprocessor().EnterMainSourceFile(); + if (!S.getPreprocessor().getCurrentLexer()) { + // If a PCH through header is specified that does not have an include in + // the source, there won't be any tokens or a Lexer. + return; + } + P.Initialize(); Parser::DeclGroupPtrTy ADecl; @@ -158,6 +169,13 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) { Consumer->HandleTranslationUnit(S.getASTContext()); + // Finalize the template instantiation observer chain. + // FIXME: This (and init.) should be done in the Sema class, but because + // Sema does not have a reliable "Finalize" function (it has a + // destructor, but it is not guaranteed to be called ("-disable-free")). + // So, do the initialization above and do the finalization here: + finalize(S.TemplateInstCallbacks, S); + std::swap(OldCollectStats, S.CollectStats); if (PrintStats) { llvm::errs() << "\nSTATISTICS:\n"; |