Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 1 | //===--- FrontendAction.cpp -----------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/FrontendAction.h" |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTConsumer.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 12 | #include "clang/AST/ASTContext.h" |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 13 | #include "clang/AST/DeclGroup.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/ASTUnit.h" |
Chandler Carruth | 71088d1 | 2011-12-09 01:55:54 +0000 | [diff] [blame] | 15 | #include "clang/Frontend/ChainedIncludesSource.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 16 | #include "clang/Frontend/CompilerInstance.h" |
| 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/FrontendPluginRegistry.h" |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/LayoutOverrideSource.h" |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/MultiplexConsumer.h" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 21 | #include "clang/Frontend/Utils.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/Lex/HeaderSearch.h" |
| 23 | #include "clang/Lex/Preprocessor.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 24 | #include "clang/Parse/ParseAST.h" |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 25 | #include "clang/Serialization/ASTDeserializationListener.h" |
Jonathan D. Turner | e735e2d | 2011-08-05 22:17:03 +0000 | [diff] [blame] | 26 | #include "clang/Serialization/ASTReader.h" |
Douglas Gregor | a6b00fc | 2013-01-23 22:38:11 +0000 | [diff] [blame] | 27 | #include "clang/Serialization/GlobalModuleIndex.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 29 | #include "llvm/Support/FileSystem.h" |
| 30 | #include "llvm/Support/MemoryBuffer.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Timer.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 33 | #include "llvm/Support/system_error.h" |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 34 | using namespace clang; |
| 35 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 36 | namespace { |
| 37 | |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 38 | class DelegatingDeserializationListener : public ASTDeserializationListener { |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 39 | ASTDeserializationListener *Previous; |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 40 | bool DeletePrevious; |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 41 | |
| 42 | public: |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 43 | explicit DelegatingDeserializationListener( |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 44 | ASTDeserializationListener *Previous, bool DeletePrevious) |
| 45 | : Previous(Previous), DeletePrevious(DeletePrevious) {} |
| 46 | virtual ~DelegatingDeserializationListener() { |
| 47 | if (DeletePrevious) |
| 48 | delete Previous; |
| 49 | } |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 50 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 51 | void ReaderInitialized(ASTReader *Reader) override { |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 52 | if (Previous) |
| 53 | Previous->ReaderInitialized(Reader); |
| 54 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 55 | void IdentifierRead(serialization::IdentID ID, |
| 56 | IdentifierInfo *II) override { |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 57 | if (Previous) |
| 58 | Previous->IdentifierRead(ID, II); |
| 59 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 60 | void TypeRead(serialization::TypeIdx Idx, QualType T) override { |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 61 | if (Previous) |
| 62 | Previous->TypeRead(Idx, T); |
| 63 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 64 | void DeclRead(serialization::DeclID ID, const Decl *D) override { |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 65 | if (Previous) |
| 66 | Previous->DeclRead(ID, D); |
| 67 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 68 | void SelectorRead(serialization::SelectorID ID, Selector Sel) override { |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 69 | if (Previous) |
| 70 | Previous->SelectorRead(ID, Sel); |
| 71 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 72 | void MacroDefinitionRead(serialization::PreprocessedEntityID PPID, |
| 73 | MacroDefinition *MD) override { |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 74 | if (Previous) |
| 75 | Previous->MacroDefinitionRead(PPID, MD); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | /// \brief Dumps deserialized declarations. |
| 80 | class DeserializedDeclsDumper : public DelegatingDeserializationListener { |
| 81 | public: |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 82 | explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous, |
| 83 | bool DeletePrevious) |
| 84 | : DelegatingDeserializationListener(Previous, DeletePrevious) {} |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 85 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 86 | void DeclRead(serialization::DeclID ID, const Decl *D) override { |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 87 | llvm::outs() << "PCH DECL: " << D->getDeclKindName(); |
| 88 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
Benjamin Kramer | a59d20b | 2012-02-07 11:57:57 +0000 | [diff] [blame] | 89 | llvm::outs() << " - " << *ND; |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 90 | llvm::outs() << "\n"; |
| 91 | |
Argyrios Kyrtzidis | 407ef9a | 2011-10-28 22:54:31 +0000 | [diff] [blame] | 92 | DelegatingDeserializationListener::DeclRead(ID, D); |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 93 | } |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
David Blaikie | e3f3411 | 2012-05-29 17:05:42 +0000 | [diff] [blame] | 96 | /// \brief Checks deserialized declarations and emits error if a name |
| 97 | /// matches one given in command-line using -error-on-deserialized-decl. |
| 98 | class DeserializedDeclsChecker : public DelegatingDeserializationListener { |
| 99 | ASTContext &Ctx; |
| 100 | std::set<std::string> NamesToCheck; |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 101 | |
David Blaikie | e3f3411 | 2012-05-29 17:05:42 +0000 | [diff] [blame] | 102 | public: |
| 103 | DeserializedDeclsChecker(ASTContext &Ctx, |
| 104 | const std::set<std::string> &NamesToCheck, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 105 | ASTDeserializationListener *Previous, |
| 106 | bool DeletePrevious) |
| 107 | : DelegatingDeserializationListener(Previous, DeletePrevious), Ctx(Ctx), |
| 108 | NamesToCheck(NamesToCheck) {} |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 109 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 110 | void DeclRead(serialization::DeclID ID, const Decl *D) override { |
David Blaikie | e3f3411 | 2012-05-29 17:05:42 +0000 | [diff] [blame] | 111 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
| 112 | if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) { |
| 113 | unsigned DiagID |
| 114 | = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, |
| 115 | "%0 was deserialized"); |
| 116 | Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID) |
| 117 | << ND->getNameAsString(); |
| 118 | } |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 119 | |
David Blaikie | e3f3411 | 2012-05-29 17:05:42 +0000 | [diff] [blame] | 120 | DelegatingDeserializationListener::DeclRead(ID, D); |
| 121 | } |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 124 | } // end anonymous namespace |
| 125 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 126 | FrontendAction::FrontendAction() : Instance(nullptr) {} |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 127 | |
| 128 | FrontendAction::~FrontendAction() {} |
| 129 | |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 130 | void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, |
| 131 | ASTUnit *AST) { |
| 132 | this->CurrentInput = CurrentInput; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 133 | CurrentASTUnit.reset(AST); |
| 134 | } |
| 135 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 136 | ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 137 | StringRef InFile) { |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 138 | ASTConsumer* Consumer = CreateASTConsumer(CI, InFile); |
| 139 | if (!Consumer) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 140 | return nullptr; |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 141 | |
| 142 | if (CI.getFrontendOpts().AddPluginActions.size() == 0) |
| 143 | return Consumer; |
| 144 | |
| 145 | // Make sure the non-plugin consumer is first, so that plugins can't |
| 146 | // modifiy the AST. |
| 147 | std::vector<ASTConsumer*> Consumers(1, Consumer); |
| 148 | |
| 149 | for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); |
| 150 | i != e; ++i) { |
| 151 | // This is O(|plugins| * |add_plugins|), but since both numbers are |
| 152 | // way below 50 in practice, that's ok. |
| 153 | for (FrontendPluginRegistry::iterator |
| 154 | it = FrontendPluginRegistry::begin(), |
| 155 | ie = FrontendPluginRegistry::end(); |
| 156 | it != ie; ++it) { |
| 157 | if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 158 | std::unique_ptr<PluginASTAction> P(it->instantiate()); |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 159 | FrontendAction* c = P.get(); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 160 | if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 161 | Consumers.push_back(c->CreateASTConsumer(CI, InFile)); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return new MultiplexConsumer(Consumers); |
| 167 | } |
| 168 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 169 | bool FrontendAction::BeginSourceFile(CompilerInstance &CI, |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 170 | const FrontendInputFile &Input) { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 171 | assert(!Instance && "Already processing a source file!"); |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 172 | assert(!Input.isEmpty() && "Unexpected empty filename!"); |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 173 | setCurrentInput(Input); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 174 | setCompilerInstance(&CI); |
| 175 | |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 176 | StringRef InputFile = Input.getFile(); |
Jordan Rose | af6cf43 | 2012-08-10 01:06:08 +0000 | [diff] [blame] | 177 | bool HasBegunSourceFile = false; |
Argyrios Kyrtzidis | e665d69 | 2011-06-18 00:53:41 +0000 | [diff] [blame] | 178 | if (!BeginInvocation(CI)) |
| 179 | goto failure; |
| 180 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 181 | // AST files follow a very different path, since they share objects via the |
| 182 | // AST unit. |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 183 | if (Input.getKind() == IK_AST) { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 184 | assert(!usesPreprocessorOnly() && |
| 185 | "Attempt to pass AST file to preprocessor only action!"); |
Daniel Dunbar | eb58d83 | 2010-06-07 23:24:43 +0000 | [diff] [blame] | 186 | assert(hasASTFileSupport() && |
| 187 | "This action does not have AST file support!"); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 188 | |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 189 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics()); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 190 | |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 191 | ASTUnit *AST = ASTUnit::LoadFromASTFile(InputFile, Diags, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 192 | CI.getFileSystemOpts()); |
Daniel Dunbar | 5262fda | 2009-12-03 01:45:44 +0000 | [diff] [blame] | 193 | if (!AST) |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 194 | goto failure; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 195 | |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 196 | setCurrentInput(Input, AST); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 197 | |
Argyrios Kyrtzidis | 62ba4ba | 2013-03-18 22:55:24 +0000 | [diff] [blame] | 198 | // Inform the diagnostic client we are processing a source file. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 199 | CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); |
Argyrios Kyrtzidis | 62ba4ba | 2013-03-18 22:55:24 +0000 | [diff] [blame] | 200 | HasBegunSourceFile = true; |
| 201 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 202 | // Set the shared objects, these are reset when we finish processing the |
| 203 | // file, otherwise the CompilerInstance will happily destroy them. |
| 204 | CI.setFileManager(&AST->getFileManager()); |
| 205 | CI.setSourceManager(&AST->getSourceManager()); |
| 206 | CI.setPreprocessor(&AST->getPreprocessor()); |
| 207 | CI.setASTContext(&AST->getASTContext()); |
| 208 | |
| 209 | // Initialize the action. |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 210 | if (!BeginSourceFileAction(CI, InputFile)) |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 211 | goto failure; |
| 212 | |
James Dennett | 18f43a6 | 2013-01-23 00:45:44 +0000 | [diff] [blame] | 213 | // Create the AST consumer. |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 214 | CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile)); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 215 | if (!CI.hasASTConsumer()) |
| 216 | goto failure; |
| 217 | |
| 218 | return true; |
| 219 | } |
| 220 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 221 | if (!CI.hasVirtualFileSystem()) { |
| 222 | if (IntrusiveRefCntPtr<vfs::FileSystem> VFS = |
| 223 | createVFSFromCompilerInvocation(CI.getInvocation(), |
| 224 | CI.getDiagnostics())) |
| 225 | CI.setVirtualFileSystem(VFS); |
| 226 | else |
| 227 | goto failure; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 230 | // Set up the file and source managers, if needed. |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 231 | if (!CI.hasFileManager()) |
| 232 | CI.createFileManager(); |
| 233 | if (!CI.hasSourceManager()) |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 234 | CI.createSourceManager(CI.getFileManager()); |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 235 | |
| 236 | // IR files bypass the rest of initialization. |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 237 | if (Input.getKind() == IK_LLVM_IR) { |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 238 | assert(hasIRSupport() && |
| 239 | "This action does not have IR file support!"); |
| 240 | |
| 241 | // Inform the diagnostic client we are processing a source file. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 242 | CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr); |
Jordan Rose | af6cf43 | 2012-08-10 01:06:08 +0000 | [diff] [blame] | 243 | HasBegunSourceFile = true; |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 244 | |
| 245 | // Initialize the action. |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 246 | if (!BeginSourceFileAction(CI, InputFile)) |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 247 | goto failure; |
| 248 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 249 | // Initialize the main file entry. |
| 250 | if (!CI.InitializeSourceManager(CurrentInput)) |
| 251 | goto failure; |
| 252 | |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 256 | // If the implicit PCH include is actually a directory, rather than |
| 257 | // a single file, search for a suitable PCH file in that directory. |
| 258 | if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { |
| 259 | FileManager &FileMgr = CI.getFileManager(); |
| 260 | PreprocessorOptions &PPOpts = CI.getPreprocessorOpts(); |
| 261 | StringRef PCHInclude = PPOpts.ImplicitPCHInclude; |
| 262 | if (const DirectoryEntry *PCHDir = FileMgr.getDirectory(PCHInclude)) { |
| 263 | llvm::error_code EC; |
| 264 | SmallString<128> DirNative; |
| 265 | llvm::sys::path::native(PCHDir->getName(), DirNative); |
| 266 | bool Found = false; |
| 267 | for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd; |
| 268 | Dir != DirEnd && !EC; Dir.increment(EC)) { |
| 269 | // Check whether this is an acceptable AST file. |
| 270 | if (ASTReader::isAcceptableASTFile(Dir->path(), FileMgr, |
| 271 | CI.getLangOpts(), |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 272 | CI.getTargetOpts(), |
| 273 | CI.getPreprocessorOpts())) { |
Argyrios Kyrtzidis | 3ad86fd | 2013-02-05 16:36:52 +0000 | [diff] [blame] | 274 | PPOpts.ImplicitPCHInclude = Dir->path(); |
| 275 | Found = true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if (!Found) { |
| 281 | CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude; |
| 282 | return true; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 287 | // Set up the preprocessor. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 288 | CI.createPreprocessor(getTranslationUnitKind()); |
Daniel Dunbar | 2056048 | 2010-06-07 23:23:50 +0000 | [diff] [blame] | 289 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 290 | // Inform the diagnostic client we are processing a source file. |
| 291 | CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), |
| 292 | &CI.getPreprocessor()); |
Jordan Rose | af6cf43 | 2012-08-10 01:06:08 +0000 | [diff] [blame] | 293 | HasBegunSourceFile = true; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 294 | |
| 295 | // Initialize the action. |
Argyrios Kyrtzidis | 8616f9a | 2012-11-09 19:40:39 +0000 | [diff] [blame] | 296 | if (!BeginSourceFileAction(CI, InputFile)) |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 297 | goto failure; |
| 298 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 299 | // Initialize the main file entry. It is important that this occurs after |
| 300 | // BeginSourceFileAction, which may change CurrentInput during module builds. |
| 301 | if (!CI.InitializeSourceManager(CurrentInput)) |
| 302 | goto failure; |
| 303 | |
James Dennett | 18f43a6 | 2013-01-23 00:45:44 +0000 | [diff] [blame] | 304 | // Create the AST context and consumer unless this is a preprocessor only |
| 305 | // action. |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 306 | if (!usesPreprocessorOnly()) { |
| 307 | CI.createASTContext(); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 308 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 309 | std::unique_ptr<ASTConsumer> Consumer( |
| 310 | CreateWrappedASTConsumer(CI, InputFile)); |
Fariborz Jahanian | d305719 | 2010-10-29 19:49:13 +0000 | [diff] [blame] | 311 | if (!Consumer) |
| 312 | goto failure; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 313 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 314 | CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener()); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 315 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 316 | if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) { |
| 317 | // Convert headers to PCH and chain them. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 318 | IntrusiveRefCntPtr<ChainedIncludesSource> source; |
| 319 | source = ChainedIncludesSource::create(CI); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 320 | if (!source) |
| 321 | goto failure; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 322 | CI.setModuleManager(static_cast<ASTReader*>(&source->getFinalReader())); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 323 | CI.getASTContext().setExternalSource(source); |
| 324 | |
| 325 | } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { |
| 326 | // Use PCH. |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 327 | assert(hasPCHSupport() && "This action does not have PCH support!"); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 328 | ASTDeserializationListener *DeserialListener = |
| 329 | Consumer->GetASTDeserializationListener(); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 330 | bool DeleteDeserialListener = false; |
| 331 | if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) { |
| 332 | DeserialListener = new DeserializedDeclsDumper(DeserialListener, |
| 333 | DeleteDeserialListener); |
| 334 | DeleteDeserialListener = true; |
| 335 | } |
| 336 | if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) { |
| 337 | DeserialListener = new DeserializedDeclsChecker( |
| 338 | CI.getASTContext(), |
| 339 | CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn, |
| 340 | DeserialListener, DeleteDeserialListener); |
| 341 | DeleteDeserialListener = true; |
| 342 | } |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 343 | CI.createPCHExternalASTSource( |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 344 | CI.getPreprocessorOpts().ImplicitPCHInclude, |
| 345 | CI.getPreprocessorOpts().DisablePCHValidation, |
| 346 | CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener, |
| 347 | DeleteDeserialListener); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 348 | if (!CI.getASTContext().getExternalSource()) |
| 349 | goto failure; |
| 350 | } |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 351 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 352 | CI.setASTConsumer(Consumer.release()); |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 353 | if (!CI.hasASTConsumer()) |
| 354 | goto failure; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Jonathan D. Turner | e735e2d | 2011-08-05 22:17:03 +0000 | [diff] [blame] | 357 | // Initialize built-in info as long as we aren't using an external AST |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 358 | // source. |
| 359 | if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) { |
| 360 | Preprocessor &PP = CI.getPreprocessor(); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 361 | |
| 362 | // If modules are enabled, create the module manager before creating |
| 363 | // any builtins, so that all declarations know that they might be |
| 364 | // extended by an external source. |
| 365 | if (CI.getLangOpts().Modules) |
| 366 | CI.createModuleManager(); |
| 367 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 368 | PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 369 | PP.getLangOpts()); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 370 | } else { |
| 371 | // FIXME: If this is a problem, recover from it by creating a multiplex |
| 372 | // source. |
| 373 | assert((!CI.getLangOpts().Modules || CI.getModuleManager()) && |
| 374 | "modules enabled but created an external source that " |
| 375 | "doesn't support modules"); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 378 | // If there is a layout overrides file, attach an external AST source that |
| 379 | // provides the layouts from that file. |
| 380 | if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() && |
| 381 | CI.hasASTContext() && !CI.getASTContext().getExternalSource()) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 382 | IntrusiveRefCntPtr<ExternalASTSource> |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 383 | Override(new LayoutOverrideSource( |
| 384 | CI.getFrontendOpts().OverrideRecordLayoutsFile)); |
| 385 | CI.getASTContext().setExternalSource(Override); |
| 386 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 387 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 388 | return true; |
| 389 | |
| 390 | // If we failed, reset state since the client will not end up calling the |
| 391 | // matching EndSourceFile(). |
| 392 | failure: |
| 393 | if (isCurrentFileAST()) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 394 | CI.setASTContext(nullptr); |
| 395 | CI.setPreprocessor(nullptr); |
| 396 | CI.setSourceManager(nullptr); |
| 397 | CI.setFileManager(nullptr); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Jordan Rose | af6cf43 | 2012-08-10 01:06:08 +0000 | [diff] [blame] | 400 | if (HasBegunSourceFile) |
| 401 | CI.getDiagnosticClient().EndSourceFile(); |
Benjamin Kramer | ac447fc | 2012-10-14 19:21:21 +0000 | [diff] [blame] | 402 | CI.clearOutputFiles(/*EraseFiles=*/true); |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 403 | setCurrentInput(FrontendInputFile()); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 404 | setCompilerInstance(nullptr); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 405 | return false; |
| 406 | } |
| 407 | |
Argyrios Kyrtzidis | 374a00b | 2012-06-08 05:48:06 +0000 | [diff] [blame] | 408 | bool FrontendAction::Execute() { |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 409 | CompilerInstance &CI = getCompilerInstance(); |
| 410 | |
Kovarththanan Rajaratnam | f79bafa | 2009-11-29 09:57:35 +0000 | [diff] [blame] | 411 | if (CI.hasFrontendTimer()) { |
| 412 | llvm::TimeRegion Timer(CI.getFrontendTimer()); |
| 413 | ExecuteAction(); |
| 414 | } |
| 415 | else ExecuteAction(); |
Argyrios Kyrtzidis | 374a00b | 2012-06-08 05:48:06 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | a6b00fc | 2013-01-23 22:38:11 +0000 | [diff] [blame] | 417 | // If we are supposed to rebuild the global module index, do so now unless |
Douglas Gregor | f575d6e | 2013-01-25 00:45:27 +0000 | [diff] [blame] | 418 | // there were any module-build failures. |
| 419 | if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() && |
| 420 | CI.hasPreprocessor()) { |
Douglas Gregor | a6b00fc | 2013-01-23 22:38:11 +0000 | [diff] [blame] | 421 | GlobalModuleIndex::writeIndex( |
| 422 | CI.getFileManager(), |
| 423 | CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath()); |
| 424 | } |
| 425 | |
Argyrios Kyrtzidis | 374a00b | 2012-06-08 05:48:06 +0000 | [diff] [blame] | 426 | return true; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void FrontendAction::EndSourceFile() { |
| 430 | CompilerInstance &CI = getCompilerInstance(); |
| 431 | |
Douglas Gregor | 92b97f2 | 2011-02-09 18:47:31 +0000 | [diff] [blame] | 432 | // Inform the diagnostic client we are done with this source file. |
| 433 | CI.getDiagnosticClient().EndSourceFile(); |
| 434 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 435 | // Finalize the action. |
| 436 | EndSourceFileAction(); |
| 437 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 438 | // Sema references the ast consumer, so reset sema first. |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 439 | // |
| 440 | // FIXME: There is more per-file stuff we could just drop here? |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 441 | bool DisableFree = CI.getFrontendOpts().DisableFree; |
| 442 | if (DisableFree) { |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 443 | if (!isCurrentFileAST()) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 444 | CI.resetAndLeakSema(); |
Ted Kremenek | 4f32786 | 2011-03-21 18:40:17 +0000 | [diff] [blame] | 445 | CI.resetAndLeakASTContext(); |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 446 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 447 | BuryPointer(CI.takeASTConsumer()); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 448 | } else { |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 449 | if (!isCurrentFileAST()) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 450 | CI.setSema(nullptr); |
| 451 | CI.setASTContext(nullptr); |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 452 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 453 | CI.setASTConsumer(nullptr); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Daniel Dunbar | dbd8209 | 2010-03-23 05:09:10 +0000 | [diff] [blame] | 456 | // Inform the preprocessor we are done. |
| 457 | if (CI.hasPreprocessor()) |
| 458 | CI.getPreprocessor().EndSourceFile(); |
| 459 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 460 | if (CI.getFrontendOpts().ShowStats) { |
| 461 | llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n"; |
| 462 | CI.getPreprocessor().PrintStats(); |
| 463 | CI.getPreprocessor().getIdentifierTable().PrintStats(); |
| 464 | CI.getPreprocessor().getHeaderSearchInfo().PrintStats(); |
| 465 | CI.getSourceManager().PrintStats(); |
| 466 | llvm::errs() << "\n"; |
| 467 | } |
| 468 | |
Argyrios Kyrtzidis | 1f01f7c | 2013-06-11 00:36:55 +0000 | [diff] [blame] | 469 | // Cleanup the output streams, and erase the output files if instructed by the |
| 470 | // FrontendAction. |
| 471 | CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles()); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 472 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 473 | // FIXME: Only do this if DisableFree is set. |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 474 | if (isCurrentFileAST()) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 475 | CI.resetAndLeakSema(); |
Ted Kremenek | 4f32786 | 2011-03-21 18:40:17 +0000 | [diff] [blame] | 476 | CI.resetAndLeakASTContext(); |
| 477 | CI.resetAndLeakPreprocessor(); |
| 478 | CI.resetAndLeakSourceManager(); |
| 479 | CI.resetAndLeakFileManager(); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 482 | setCompilerInstance(nullptr); |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 483 | setCurrentInput(FrontendInputFile()); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Argyrios Kyrtzidis | 1f01f7c | 2013-06-11 00:36:55 +0000 | [diff] [blame] | 486 | bool FrontendAction::shouldEraseOutputFiles() { |
| 487 | return getCompilerInstance().getDiagnostics().hasErrorOccurred(); |
| 488 | } |
| 489 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 490 | //===----------------------------------------------------------------------===// |
| 491 | // Utility Actions |
| 492 | //===----------------------------------------------------------------------===// |
| 493 | |
| 494 | void ASTFrontendAction::ExecuteAction() { |
| 495 | CompilerInstance &CI = getCompilerInstance(); |
Rafael Espindola | 0046ce5 | 2013-07-28 13:23:37 +0000 | [diff] [blame] | 496 | if (!CI.hasPreprocessor()) |
| 497 | return; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 498 | |
| 499 | // FIXME: Move the truncation aspect of this into Sema, we delayed this till |
| 500 | // here so the source manager would be initialized. |
| 501 | if (hasCodeCompletionSupport() && |
| 502 | !CI.getFrontendOpts().CodeCompletionAt.FileName.empty()) |
| 503 | CI.createCodeCompletionConsumer(); |
| 504 | |
| 505 | // Use a code completion consumer? |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame^] | 506 | CodeCompleteConsumer *CompletionConsumer = nullptr; |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 507 | if (CI.hasCodeCompletionConsumer()) |
| 508 | CompletionConsumer = &CI.getCodeCompletionConsumer(); |
| 509 | |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 510 | if (!CI.hasSema()) |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 511 | CI.createSema(getTranslationUnitKind(), CompletionConsumer); |
Douglas Gregor | f18d0d8 | 2010-08-12 23:31:19 +0000 | [diff] [blame] | 512 | |
Erik Verbruggen | 6a91d38 | 2012-04-12 10:11:59 +0000 | [diff] [blame] | 513 | ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats, |
| 514 | CI.getFrontendOpts().SkipFunctionBodies); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 515 | } |
| 516 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 517 | void PluginASTAction::anchor() { } |
| 518 | |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 519 | ASTConsumer * |
| 520 | PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 521 | StringRef InFile) { |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 522 | llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); |
Daniel Dunbar | 4ee2409 | 2009-11-14 10:42:35 +0000 | [diff] [blame] | 523 | } |
Chandler Carruth | f7f8188 | 2011-06-16 16:17:05 +0000 | [diff] [blame] | 524 | |
| 525 | ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 526 | StringRef InFile) { |
Chandler Carruth | f7f8188 | 2011-06-16 16:17:05 +0000 | [diff] [blame] | 527 | return WrappedAction->CreateASTConsumer(CI, InFile); |
| 528 | } |
Argyrios Kyrtzidis | e665d69 | 2011-06-18 00:53:41 +0000 | [diff] [blame] | 529 | bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { |
| 530 | return WrappedAction->BeginInvocation(CI); |
| 531 | } |
Chandler Carruth | f7f8188 | 2011-06-16 16:17:05 +0000 | [diff] [blame] | 532 | bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 533 | StringRef Filename) { |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 534 | WrappedAction->setCurrentInput(getCurrentInput()); |
Argyrios Kyrtzidis | e665d69 | 2011-06-18 00:53:41 +0000 | [diff] [blame] | 535 | WrappedAction->setCompilerInstance(&CI); |
Chandler Carruth | f7f8188 | 2011-06-16 16:17:05 +0000 | [diff] [blame] | 536 | return WrappedAction->BeginSourceFileAction(CI, Filename); |
| 537 | } |
| 538 | void WrapperFrontendAction::ExecuteAction() { |
| 539 | WrappedAction->ExecuteAction(); |
| 540 | } |
| 541 | void WrapperFrontendAction::EndSourceFileAction() { |
| 542 | WrappedAction->EndSourceFileAction(); |
| 543 | } |
| 544 | |
| 545 | bool WrapperFrontendAction::usesPreprocessorOnly() const { |
| 546 | return WrappedAction->usesPreprocessorOnly(); |
| 547 | } |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 548 | TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() { |
| 549 | return WrappedAction->getTranslationUnitKind(); |
Chandler Carruth | f7f8188 | 2011-06-16 16:17:05 +0000 | [diff] [blame] | 550 | } |
| 551 | bool WrapperFrontendAction::hasPCHSupport() const { |
| 552 | return WrappedAction->hasPCHSupport(); |
| 553 | } |
| 554 | bool WrapperFrontendAction::hasASTFileSupport() const { |
| 555 | return WrappedAction->hasASTFileSupport(); |
| 556 | } |
| 557 | bool WrapperFrontendAction::hasIRSupport() const { |
| 558 | return WrappedAction->hasIRSupport(); |
| 559 | } |
| 560 | bool WrapperFrontendAction::hasCodeCompletionSupport() const { |
| 561 | return WrappedAction->hasCodeCompletionSupport(); |
| 562 | } |
| 563 | |
| 564 | WrapperFrontendAction::WrapperFrontendAction(FrontendAction *WrappedAction) |
| 565 | : WrappedAction(WrappedAction) {} |
| 566 | |