diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-03 08:14:03 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-03 08:14:03 +0000 |
commit | 48c8cd3fd06dfa1eeda3972c8a8887c00ca8c675 (patch) | |
tree | 7f2f01566310d1204c09c9a5f4ac04a747f857ad /clang/lib/Frontend/ASTUnit.cpp | |
parent | 5696d6d316ed7a66aa405450b7991a8eee8937b8 (diff) | |
download | bcm5719-llvm-48c8cd3fd06dfa1eeda3972c8a8887c00ca8c675.tar.gz bcm5719-llvm-48c8cd3fd06dfa1eeda3972c8a8887c00ca8c675.zip |
Reshuffle the PCH generator action and consumer, so that we can re-use
it while generating precompiled preambles. No functionality change.
llvm-svn: 110108
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index b36a338c196..bd60296ca80 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Frontend/ASTUnit.h" -#include "clang/Frontend/PCHReader.h" +#include "clang/Frontend/PCHWriter.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/DeclVisitor.h" @@ -25,6 +25,7 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h" +#include "clang/Frontend/PCHReader.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/TargetOptions.h" @@ -328,6 +329,54 @@ public: virtual bool hasCodeCompletionSupport() const { return false; } }; +class PrecompilePreambleConsumer : public PCHGenerator { + ASTUnit &Unit; + +public: + PrecompilePreambleConsumer(ASTUnit &Unit, + const Preprocessor &PP, bool Chaining, + const char *isysroot, llvm::raw_ostream *Out) + : PCHGenerator(PP, Chaining, isysroot, Out), Unit(Unit) { } + + void HandleTopLevelDecl(DeclGroupRef D) { + for (DeclGroupRef::iterator it = D.begin(), ie = D.end(); it != ie; ++it) { + Decl *D = *it; + // FIXME: Currently ObjC method declarations are incorrectly being + // reported as top-level declarations, even though their DeclContext + // is the containing ObjC @interface/@implementation. This is a + // fundamental problem in the parser right now. + if (isa<ObjCMethodDecl>(D)) + continue; + Unit.getTopLevelDecls().push_back(D); + } + } +}; + +class PrecompilePreambleAction : public ASTFrontendAction { + ASTUnit &Unit; + +public: + explicit PrecompilePreambleAction(ASTUnit &Unit) : Unit(Unit) {} + + virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, + llvm::StringRef InFile) { + std::string Sysroot; + llvm::raw_ostream *OS = 0; + bool Chaining; + if (GeneratePCHAction::ComputeASTConsumerArguments(CI, InFile, Sysroot, + OS, Chaining)) + return 0; + + const char *isysroot = CI.getFrontendOpts().RelocatablePCH ? + Sysroot.c_str() : 0; + return new PrecompilePreambleConsumer(Unit, CI.getPreprocessor(), Chaining, + isysroot, OS); + } + + virtual bool hasCodeCompletionSupport() const { return false; } + virtual bool hasASTFileSupport() const { return false; } +}; + } /// Parse the source file into a translation unit using the given compiler @@ -819,8 +868,8 @@ llvm::MemoryBuffer *ASTUnit::BuildPrecompiledPreamble() { Clang.setSourceManager(new SourceManager(getDiagnostics())); // FIXME: Eventually, we'll have to track top-level declarations here, too. - llvm::OwningPtr<GeneratePCHAction> Act; - Act.reset(new GeneratePCHAction); + llvm::OwningPtr<PrecompilePreambleAction> Act; + Act.reset(new PrecompilePreambleAction(*this)); if (!Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second, Clang.getFrontendOpts().Inputs[0].first)) { Clang.takeDiagnosticClient(); |