FrontendAction.cpp revision bef35c91b594f66216f4aab303b71a6c5ab7abcf
14ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar//===--- FrontendAction.cpp -----------------------------------------------===// 24ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// 34ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// The LLVM Compiler Infrastructure 44ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// 54ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// This file is distributed under the University of Illinois Open Source 64ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// License. See LICENSE.TXT for details. 74ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// 84ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar//===----------------------------------------------------------------------===// 94ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 104ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/Frontend/FrontendAction.h" 11ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl#include "clang/AST/ASTConsumer.h" 124ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/AST/ASTContext.h" 135aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber#include "clang/AST/DeclGroup.h" 144ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/Lex/HeaderSearch.h" 154ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/Lex/Preprocessor.h" 164ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/Frontend/ASTUnit.h" 1771088d1af241ad114294ec3fe03cd9baea39ee08Chandler Carruth#include "clang/Frontend/ChainedIncludesSource.h" 184ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/Frontend/CompilerInstance.h" 194ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "clang/Frontend/FrontendDiagnostic.h" 205aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber#include "clang/Frontend/FrontendPluginRegistry.h" 21453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor#include "clang/Frontend/LayoutOverrideSource.h" 225aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber#include "clang/Frontend/MultiplexConsumer.h" 2319510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Parse/ParseAST.h" 24b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis#include "clang/Serialization/ASTDeserializationListener.h" 25e735e2deb9e57d9b62c1258ee236ccfeba8e84b2Jonathan D. Turner#include "clang/Serialization/ASTReader.h" 264ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "llvm/Support/MemoryBuffer.h" 274ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "llvm/Support/Timer.h" 284ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "llvm/Support/ErrorHandling.h" 294ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar#include "llvm/Support/raw_ostream.h" 304ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbarusing namespace clang; 314ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 32b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidisnamespace { 33b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 34407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidisclass DelegatingDeserializationListener : public ASTDeserializationListener { 35b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis ASTDeserializationListener *Previous; 36b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 37b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidispublic: 38407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis explicit DelegatingDeserializationListener( 39407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis ASTDeserializationListener *Previous) 40b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis : Previous(Previous) { } 41b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 42407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis virtual void ReaderInitialized(ASTReader *Reader) { 43407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis if (Previous) 44407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Previous->ReaderInitialized(Reader); 45407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis } 46407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis virtual void IdentifierRead(serialization::IdentID ID, 47407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis IdentifierInfo *II) { 48407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis if (Previous) 49407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Previous->IdentifierRead(ID, II); 50407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis } 51407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis virtual void TypeRead(serialization::TypeIdx Idx, QualType T) { 52407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis if (Previous) 53407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Previous->TypeRead(Idx, T); 54407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis } 55407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis virtual void DeclRead(serialization::DeclID ID, const Decl *D) { 56407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis if (Previous) 57407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Previous->DeclRead(ID, D); 58407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis } 59407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis virtual void SelectorRead(serialization::SelectorID ID, Selector Sel) { 60407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis if (Previous) 61407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Previous->SelectorRead(ID, Sel); 62407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis } 63407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis virtual void MacroDefinitionRead(serialization::PreprocessedEntityID PPID, 64407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis MacroDefinition *MD) { 65407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis if (Previous) 66407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Previous->MacroDefinitionRead(PPID, MD); 67407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis } 68407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis}; 69407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis 70407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis/// \brief Dumps deserialized declarations. 71407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidisclass DeserializedDeclsDumper : public DelegatingDeserializationListener { 72407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidispublic: 73407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous) 74407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis : DelegatingDeserializationListener(Previous) { } 75407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis 76b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis virtual void DeclRead(serialization::DeclID ID, const Decl *D) { 77b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis llvm::outs() << "PCH DECL: " << D->getDeclKindName(); 78b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) 79a59d20b135bfde058a5a69045bab5ec4e2553f74Benjamin Kramer llvm::outs() << " - " << *ND; 80b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis llvm::outs() << "\n"; 81b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 82407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis DelegatingDeserializationListener::DeclRead(ID, D); 83b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis } 84b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis}; 85b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 863e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis /// \brief Checks deserialized declarations and emits error if a name 873e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis /// matches one given in command-line using -error-on-deserialized-decl. 88407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis class DeserializedDeclsChecker : public DelegatingDeserializationListener { 893e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis ASTContext &Ctx; 903e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis std::set<std::string> NamesToCheck; 913e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis 923e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis public: 933e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis DeserializedDeclsChecker(ASTContext &Ctx, 943e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis const std::set<std::string> &NamesToCheck, 953e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis ASTDeserializationListener *Previous) 96407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis : DelegatingDeserializationListener(Previous), 97407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis Ctx(Ctx), NamesToCheck(NamesToCheck) { } 983e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis 993e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis virtual void DeclRead(serialization::DeclID ID, const Decl *D) { 1003e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) 1013e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) { 1023e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis unsigned DiagID 103d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, 1043e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis "%0 was deserialized"); 1053e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID) 1063e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis << ND->getNameAsString(); 1073e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis } 1083e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis 109407ef9a9286a05bd286174471889295f6615c1b2Argyrios Kyrtzidis DelegatingDeserializationListener::DeclRead(ID, D); 1103e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis } 1113e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis}; 1123e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis 113b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis} // end anonymous namespace 114b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 115f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan RajaratnamFrontendAction::FrontendAction() : Instance(0) {} 1164ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1174ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel DunbarFrontendAction::~FrontendAction() {} 1184ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1191f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregorvoid FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, 1201f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor ASTUnit *AST) { 1211f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor this->CurrentInput = CurrentInput; 1224ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CurrentASTUnit.reset(AST); 1234ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar} 1244ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1255aa74affa5d61d04c4b034b3722ca41aec0cba6eNico WeberASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, 1265f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef InFile) { 1275aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber ASTConsumer* Consumer = CreateASTConsumer(CI, InFile); 1285aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber if (!Consumer) 1295aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber return 0; 1305aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber 1315aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber if (CI.getFrontendOpts().AddPluginActions.size() == 0) 1325aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber return Consumer; 1335aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber 1345aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber // Make sure the non-plugin consumer is first, so that plugins can't 1355aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber // modifiy the AST. 1365aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber std::vector<ASTConsumer*> Consumers(1, Consumer); 1375aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber 1385aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); 1395aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber i != e; ++i) { 1405aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber // This is O(|plugins| * |add_plugins|), but since both numbers are 1415aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber // way below 50 in practice, that's ok. 1425aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber for (FrontendPluginRegistry::iterator 1435aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber it = FrontendPluginRegistry::begin(), 1445aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber ie = FrontendPluginRegistry::end(); 1455aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber it != ie; ++it) { 1465aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { 1476f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PluginASTAction> P(it->instantiate()); 1485aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber FrontendAction* c = P.get(); 149f25649c74397d2620e6ac61f1045261644707c80Nico Weber if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) 1505aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber Consumers.push_back(c->CreateASTConsumer(CI, InFile)); 1515aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber } 1525aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber } 1535aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber } 1545aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber 1555aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber return new MultiplexConsumer(Consumers); 1565aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber} 1575aa74affa5d61d04c4b034b3722ca41aec0cba6eNico Weber 1584ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbarbool FrontendAction::BeginSourceFile(CompilerInstance &CI, 1591f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor const FrontendInputFile &Input) { 1604ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar assert(!Instance && "Already processing a source file!"); 1611f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor assert(!Input.File.empty() && "Unexpected empty filename!"); 1621f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor setCurrentInput(Input); 1634ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar setCompilerInstance(&CI); 1644ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 165e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidis if (!BeginInvocation(CI)) 166e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidis goto failure; 167e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidis 1684ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // AST files follow a very different path, since they share objects via the 1694ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // AST unit. 1701f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor if (Input.Kind == IK_AST) { 1714ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar assert(!usesPreprocessorOnly() && 1724ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar "Attempt to pass AST file to preprocessor only action!"); 173eb58d831b283a9fa030a2eccc6e23480108d2fa1Daniel Dunbar assert(hasASTFileSupport() && 174eb58d831b283a9fa030a2eccc6e23480108d2fa1Daniel Dunbar "This action does not have AST file support!"); 1754ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 176c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics()); 1774ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar std::string Error; 1781f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor ASTUnit *AST = ASTUnit::LoadFromASTFile(Input.File, Diags, 179389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis CI.getFileSystemOpts()); 1805262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar if (!AST) 1814ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar goto failure; 1824ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1831f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor setCurrentInput(Input, AST); 1844ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1854ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Set the shared objects, these are reset when we finish processing the 1864ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // file, otherwise the CompilerInstance will happily destroy them. 1874ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.setFileManager(&AST->getFileManager()); 1884ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.setSourceManager(&AST->getSourceManager()); 1894ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.setPreprocessor(&AST->getPreprocessor()); 1904ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.setASTContext(&AST->getASTContext()); 1914ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1924ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Initialize the action. 1931f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor if (!BeginSourceFileAction(CI, Input.File)) 1944ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar goto failure; 1954ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 1964ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar /// Create the AST consumer. 1971f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor CI.setASTConsumer(CreateWrappedASTConsumer(CI, Input.File)); 1984ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (!CI.hasASTConsumer()) 1994ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar goto failure; 2004ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 2014ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar return true; 2024ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 2034ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 204faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar // Set up the file and source managers, if needed. 2052056048f0f619adadc9a5416a2c4cdf95c58eef7Daniel Dunbar if (!CI.hasFileManager()) 2062056048f0f619adadc9a5416a2c4cdf95c58eef7Daniel Dunbar CI.createFileManager(); 2072056048f0f619adadc9a5416a2c4cdf95c58eef7Daniel Dunbar if (!CI.hasSourceManager()) 20839b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner CI.createSourceManager(CI.getFileManager()); 209faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar 210faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar // IR files bypass the rest of initialization. 2111f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor if (Input.Kind == IK_LLVM_IR) { 212faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar assert(hasIRSupport() && 213faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar "This action does not have IR file support!"); 214faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar 215faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar // Inform the diagnostic client we are processing a source file. 216faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 0); 217faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar 218faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar // Initialize the action. 2191f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor if (!BeginSourceFileAction(CI, Input.File)) 220faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar goto failure; 221faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar 222faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar return true; 223faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar } 224faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar 225faddc3e53a95c68f2c3a966e0f1e6eba110dafd6Daniel Dunbar // Set up the preprocessor. 2262056048f0f619adadc9a5416a2c4cdf95c58eef7Daniel Dunbar CI.createPreprocessor(); 2272056048f0f619adadc9a5416a2c4cdf95c58eef7Daniel Dunbar 2284ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Inform the diagnostic client we are processing a source file. 2294ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 2304ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar &CI.getPreprocessor()); 2314ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 2324ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Initialize the action. 2331f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor if (!BeginSourceFileAction(CI, Input.File)) 2344ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar goto failure; 2354ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 2364ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar /// Create the AST context and consumer unless this is a preprocessor only 2374ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar /// action. 2384ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (!usesPreprocessorOnly()) { 2394ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.createASTContext(); 2404ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 2416f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<ASTConsumer> Consumer( 2421f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor CreateWrappedASTConsumer(CI, Input.File)); 243d305719f9b7e154a822ff6688c663cbd32bb1d7bFariborz Jahanian if (!Consumer) 244d305719f9b7e154a822ff6688c663cbd32bb1d7bFariborz Jahanian goto failure; 245ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl 2467b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); 2477b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 248b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) { 249b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis // Convert headers to PCH and chain them. 2506f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<ExternalASTSource> source; 251b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis source.reset(ChainedIncludesSource::create(CI)); 252b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis if (!source) 253b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis goto failure; 254b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis CI.getASTContext().setExternalSource(source); 255b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis 256b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { 257b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis // Use PCH. 2584ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar assert(hasPCHSupport() && "This action does not have PCH support!"); 259f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor ASTDeserializationListener *DeserialListener = 260f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Consumer->GetASTDeserializationListener(); 261b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) 262b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis DeserialListener = new DeserializedDeclsDumper(DeserialListener); 2633e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) 2643e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis DeserialListener = new DeserializedDeclsChecker(CI.getASTContext(), 2653e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn, 2663e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis DeserialListener); 2674ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.createPCHExternalASTSource( 268fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor CI.getPreprocessorOpts().ImplicitPCHInclude, 269ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl CI.getPreprocessorOpts().DisablePCHValidation, 2708ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor CI.getPreprocessorOpts().DisableStatCache, 271bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, 272b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis DeserialListener); 2734ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (!CI.getASTContext().getExternalSource()) 2744ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar goto failure; 2754ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 27677f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl 277ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl CI.setASTConsumer(Consumer.take()); 27877f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl if (!CI.hasASTConsumer()) 27977f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl goto failure; 2804ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 2814ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 282e735e2deb9e57d9b62c1258ee236ccfeba8e84b2Jonathan D. Turner // Initialize built-in info as long as we aren't using an external AST 2834ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // source. 2844ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) { 2854ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar Preprocessor &PP = CI.getPreprocessor(); 2864ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(), 28767aba816901503d9cf7ba699525fa62cc7f8e5e4Fariborz Jahanian PP.getLangOptions()); 2884ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 2894ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 290453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor // If there is a layout overrides file, attach an external AST source that 291453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor // provides the layouts from that file. 292453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() && 293453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor CI.hasASTContext() && !CI.getASTContext().getExternalSource()) { 2946f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<ExternalASTSource> 295453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor Override(new LayoutOverrideSource( 296453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor CI.getFrontendOpts().OverrideRecordLayoutsFile)); 297453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor CI.getASTContext().setExternalSource(Override); 298453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor } 299453dbcbe30093fbf947a0bec2fbd46e9694eafe9Douglas Gregor 3004ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar return true; 3014ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3024ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // If we failed, reset state since the client will not end up calling the 3034ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // matching EndSourceFile(). 3044ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar failure: 3054ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (isCurrentFileAST()) { 3064f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.setASTContext(0); 3074f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.setPreprocessor(0); 3084f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.setSourceManager(0); 3094f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.setFileManager(0); 3104ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 3114ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3124ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.getDiagnosticClient().EndSourceFile(); 3131f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor setCurrentInput(FrontendInputFile()); 3144ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar setCompilerInstance(0); 3154ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar return false; 3164ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar} 3174ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3184ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbarvoid FrontendAction::Execute() { 3194ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CompilerInstance &CI = getCompilerInstance(); 3204ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3214ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Initialize the main file entry. This needs to be delayed until after PCH 3224ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // has loaded. 323b8c879a5363f36bdae8831112b563333e3c05acbArgyrios Kyrtzidis if (!isCurrentFileAST()) { 324a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor if (!CI.InitializeSourceManager(getCurrentFile(), 325a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor getCurrentInput().IsSystem 326a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor ? SrcMgr::C_System 327a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor : SrcMgr::C_User)) 3284ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar return; 3294ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 3304ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 331f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam if (CI.hasFrontendTimer()) { 332f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam llvm::TimeRegion Timer(CI.getFrontendTimer()); 333f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam ExecuteAction(); 334f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam } 335f79bafa608a5d7c49ec40ad199af5e32f3038b47Kovarththanan Rajaratnam else ExecuteAction(); 3364ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar} 3374ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3384ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbarvoid FrontendAction::EndSourceFile() { 3394ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CompilerInstance &CI = getCompilerInstance(); 3404ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 34192b97f2d279405751447488504816d82e1906f4fDouglas Gregor // Inform the diagnostic client we are done with this source file. 34292b97f2d279405751447488504816d82e1906f4fDouglas Gregor CI.getDiagnosticClient().EndSourceFile(); 34392b97f2d279405751447488504816d82e1906f4fDouglas Gregor 3444ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Finalize the action. 3454ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar EndSourceFileAction(); 3464ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3474ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Release the consumer and the AST, in that order since the consumer may 3484ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // perform actions in its destructor which require the context. 3494ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // 3504ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // FIXME: There is more per-file stuff we could just drop here? 3514ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (CI.getFrontendOpts().DisableFree) { 3524ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.takeASTConsumer(); 353f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor if (!isCurrentFileAST()) { 354f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CI.takeSema(); 3554f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.resetAndLeakASTContext(); 356f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 3574ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } else { 358f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor if (!isCurrentFileAST()) { 359f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CI.setSema(0); 3604ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.setASTContext(0); 361f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor } 362f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CI.setASTConsumer(0); 3634ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 3644ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 365dbd8209b33e6c9f151e4913a9c095d64a95439c4Daniel Dunbar // Inform the preprocessor we are done. 366dbd8209b33e6c9f151e4913a9c095d64a95439c4Daniel Dunbar if (CI.hasPreprocessor()) 367dbd8209b33e6c9f151e4913a9c095d64a95439c4Daniel Dunbar CI.getPreprocessor().EndSourceFile(); 368dbd8209b33e6c9f151e4913a9c095d64a95439c4Daniel Dunbar 3694ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (CI.getFrontendOpts().ShowStats) { 3704ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n"; 3714ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.getPreprocessor().PrintStats(); 3724ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.getPreprocessor().getIdentifierTable().PrintStats(); 3734ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.getPreprocessor().getHeaderSearchInfo().PrintStats(); 3744ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.getSourceManager().PrintStats(); 3754ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar llvm::errs() << "\n"; 3764ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 3774ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3784ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Cleanup the output streams, and erase the output files if we encountered 3794ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // an error. 380be3aab6abe5e66bb86596da806acc49614eacb69Argyrios Kyrtzidis CI.clearOutputFiles(/*EraseFiles=*/CI.getDiagnostics().hasErrorOccurred()); 3814ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3824ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (isCurrentFileAST()) { 383f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor CI.takeSema(); 3844f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.resetAndLeakASTContext(); 3854f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.resetAndLeakPreprocessor(); 3864f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.resetAndLeakSourceManager(); 3874f32786ac45210143654390177105eb749b614e9Ted Kremenek CI.resetAndLeakFileManager(); 3884ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar } 3894ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3904ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar setCompilerInstance(0); 3911f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor setCurrentInput(FrontendInputFile()); 3924ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar} 3934ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3944ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar//===----------------------------------------------------------------------===// 3954ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar// Utility Actions 3964ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar//===----------------------------------------------------------------------===// 3974ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 3984ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbarvoid ASTFrontendAction::ExecuteAction() { 3994ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CompilerInstance &CI = getCompilerInstance(); 4004ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 4014ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // FIXME: Move the truncation aspect of this into Sema, we delayed this till 4024ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // here so the source manager would be initialized. 4034ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (hasCodeCompletionSupport() && 4044ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar !CI.getFrontendOpts().CodeCompletionAt.FileName.empty()) 4054ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CI.createCodeCompletionConsumer(); 4064ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 4074ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar // Use a code completion consumer? 4084ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CodeCompleteConsumer *CompletionConsumer = 0; 4094ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar if (CI.hasCodeCompletionConsumer()) 4104ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar CompletionConsumer = &CI.getCodeCompletionConsumer(); 4114ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 412f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor if (!CI.hasSema()) 413467dc88512b4ba4bb16e274ea3771dc1415d31daDouglas Gregor CI.createSema(getTranslationUnitKind(), CompletionConsumer); 414f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor 415f18d0d8b39e891460d50f8a8b85029885b264986Douglas Gregor ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats); 4164ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar} 4174ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar 41899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikievoid PluginASTAction::anchor() { } 41999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 4204ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel DunbarASTConsumer * 4214ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel DunbarPreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, 4225f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef InFile) { 4239f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); 4244ee24097a8050b885c1d75ca4ee9f6d534c3f20bDaniel Dunbar} 425f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth 426f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler CarruthASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, 4275f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef InFile) { 428f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->CreateASTConsumer(CI, InFile); 429f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 430e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidisbool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { 431e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidis return WrappedAction->BeginInvocation(CI); 432e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidis} 433f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthbool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI, 4345f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Filename) { 4351f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor WrappedAction->setCurrentInput(getCurrentInput()); 436e665d6929e11796620ff799bc0186ebd747bfc76Argyrios Kyrtzidis WrappedAction->setCompilerInstance(&CI); 437f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->BeginSourceFileAction(CI, Filename); 438f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 439f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthvoid WrapperFrontendAction::ExecuteAction() { 440f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth WrappedAction->ExecuteAction(); 441f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 442f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthvoid WrapperFrontendAction::EndSourceFileAction() { 443f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth WrappedAction->EndSourceFileAction(); 444f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 445f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth 446f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthbool WrapperFrontendAction::usesPreprocessorOnly() const { 447f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->usesPreprocessorOnly(); 448f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 449467dc88512b4ba4bb16e274ea3771dc1415d31daDouglas GregorTranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() { 450467dc88512b4ba4bb16e274ea3771dc1415d31daDouglas Gregor return WrappedAction->getTranslationUnitKind(); 451f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 452f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthbool WrapperFrontendAction::hasPCHSupport() const { 453f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->hasPCHSupport(); 454f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 455f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthbool WrapperFrontendAction::hasASTFileSupport() const { 456f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->hasASTFileSupport(); 457f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 458f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthbool WrapperFrontendAction::hasIRSupport() const { 459f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->hasIRSupport(); 460f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 461f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruthbool WrapperFrontendAction::hasCodeCompletionSupport() const { 462f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth return WrappedAction->hasCodeCompletionSupport(); 463f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth} 464f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth 465f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler CarruthWrapperFrontendAction::WrapperFrontendAction(FrontendAction *WrappedAction) 466f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth : WrappedAction(WrappedAction) {} 467f7f8188fac71e34e09ee457ff6f039f5d14ad117Chandler Carruth 468