blob: 42ba4d5a09e07f27b280036b05a4a473d4746831 [file] [log] [blame]
Daniel Dunbar4ee24092009-11-14 10:42:35 +00001//===--- 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 Redlffaab3e2010-07-30 00:29:29 +000011#include "clang/AST/ASTConsumer.h"
Daniel Dunbar4ee24092009-11-14 10:42:35 +000012#include "clang/AST/ASTContext.h"
Nico Weber5aa74af2011-01-25 20:34:14 +000013#include "clang/AST/DeclGroup.h"
Daniel Dunbar4ee24092009-11-14 10:42:35 +000014#include "clang/Lex/HeaderSearch.h"
15#include "clang/Lex/Preprocessor.h"
16#include "clang/Frontend/ASTUnit.h"
Chandler Carruth71088d12011-12-09 01:55:54 +000017#include "clang/Frontend/ChainedIncludesSource.h"
Daniel Dunbar4ee24092009-11-14 10:42:35 +000018#include "clang/Frontend/CompilerInstance.h"
19#include "clang/Frontend/FrontendDiagnostic.h"
Nico Weber5aa74af2011-01-25 20:34:14 +000020#include "clang/Frontend/FrontendPluginRegistry.h"
21#include "clang/Frontend/MultiplexConsumer.h"
John McCall19510852010-08-20 18:27:03 +000022#include "clang/Parse/ParseAST.h"
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000023#include "clang/Serialization/ASTDeserializationListener.h"
Jonathan D. Turnere735e2d2011-08-05 22:17:03 +000024#include "clang/Serialization/ASTReader.h"
Daniel Dunbar4ee24092009-11-14 10:42:35 +000025#include "llvm/Support/MemoryBuffer.h"
26#include "llvm/Support/Timer.h"
27#include "llvm/Support/ErrorHandling.h"
28#include "llvm/Support/raw_ostream.h"
29using namespace clang;
30
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000031namespace {
32
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +000033class DelegatingDeserializationListener : public ASTDeserializationListener {
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000034 ASTDeserializationListener *Previous;
35
36public:
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +000037 explicit DelegatingDeserializationListener(
38 ASTDeserializationListener *Previous)
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000039 : Previous(Previous) { }
40
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +000041 virtual void ReaderInitialized(ASTReader *Reader) {
42 if (Previous)
43 Previous->ReaderInitialized(Reader);
44 }
45 virtual void IdentifierRead(serialization::IdentID ID,
46 IdentifierInfo *II) {
47 if (Previous)
48 Previous->IdentifierRead(ID, II);
49 }
50 virtual void TypeRead(serialization::TypeIdx Idx, QualType T) {
51 if (Previous)
52 Previous->TypeRead(Idx, T);
53 }
54 virtual void DeclRead(serialization::DeclID ID, const Decl *D) {
55 if (Previous)
56 Previous->DeclRead(ID, D);
57 }
58 virtual void SelectorRead(serialization::SelectorID ID, Selector Sel) {
59 if (Previous)
60 Previous->SelectorRead(ID, Sel);
61 }
62 virtual void MacroDefinitionRead(serialization::PreprocessedEntityID PPID,
63 MacroDefinition *MD) {
64 if (Previous)
65 Previous->MacroDefinitionRead(PPID, MD);
66 }
67};
68
69/// \brief Dumps deserialized declarations.
70class DeserializedDeclsDumper : public DelegatingDeserializationListener {
71public:
72 explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous)
73 : DelegatingDeserializationListener(Previous) { }
74
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000075 virtual void DeclRead(serialization::DeclID ID, const Decl *D) {
76 llvm::outs() << "PCH DECL: " << D->getDeclKindName();
77 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
78 llvm::outs() << " - " << ND->getNameAsString();
79 llvm::outs() << "\n";
80
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +000081 DelegatingDeserializationListener::DeclRead(ID, D);
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000082 }
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +000083};
84
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +000085 /// \brief Checks deserialized declarations and emits error if a name
86 /// matches one given in command-line using -error-on-deserialized-decl.
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +000087 class DeserializedDeclsChecker : public DelegatingDeserializationListener {
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +000088 ASTContext &Ctx;
89 std::set<std::string> NamesToCheck;
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +000090
91 public:
92 DeserializedDeclsChecker(ASTContext &Ctx,
93 const std::set<std::string> &NamesToCheck,
94 ASTDeserializationListener *Previous)
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +000095 : DelegatingDeserializationListener(Previous),
96 Ctx(Ctx), NamesToCheck(NamesToCheck) { }
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +000097
98 virtual void DeclRead(serialization::DeclID ID, const Decl *D) {
99 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
100 if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) {
101 unsigned DiagID
David Blaikied6471f72011-09-25 23:23:43 +0000102 = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error,
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +0000103 "%0 was deserialized");
104 Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID)
105 << ND->getNameAsString();
106 }
107
Argyrios Kyrtzidis407ef9a2011-10-28 22:54:31 +0000108 DelegatingDeserializationListener::DeclRead(ID, D);
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +0000109 }
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +0000110};
111
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +0000112} // end anonymous namespace
113
Kovarththanan Rajaratnamf79bafa2009-11-29 09:57:35 +0000114FrontendAction::FrontendAction() : Instance(0) {}
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000115
116FrontendAction::~FrontendAction() {}
117
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000118void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput,
119 ASTUnit *AST) {
120 this->CurrentInput = CurrentInput;
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000121 CurrentASTUnit.reset(AST);
122}
123
Nico Weber5aa74af2011-01-25 20:34:14 +0000124ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000125 StringRef InFile) {
Nico Weber5aa74af2011-01-25 20:34:14 +0000126 ASTConsumer* Consumer = CreateASTConsumer(CI, InFile);
127 if (!Consumer)
128 return 0;
129
130 if (CI.getFrontendOpts().AddPluginActions.size() == 0)
131 return Consumer;
132
133 // Make sure the non-plugin consumer is first, so that plugins can't
134 // modifiy the AST.
135 std::vector<ASTConsumer*> Consumers(1, Consumer);
136
137 for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size();
138 i != e; ++i) {
139 // This is O(|plugins| * |add_plugins|), but since both numbers are
140 // way below 50 in practice, that's ok.
141 for (FrontendPluginRegistry::iterator
142 it = FrontendPluginRegistry::begin(),
143 ie = FrontendPluginRegistry::end();
144 it != ie; ++it) {
145 if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) {
146 llvm::OwningPtr<PluginASTAction> P(it->instantiate());
147 FrontendAction* c = P.get();
Nico Weberf25649c2011-01-29 21:21:49 +0000148 if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i]))
Nico Weber5aa74af2011-01-25 20:34:14 +0000149 Consumers.push_back(c->CreateASTConsumer(CI, InFile));
150 }
151 }
152 }
153
154 return new MultiplexConsumer(Consumers);
155}
156
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000157bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000158 const FrontendInputFile &Input) {
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000159 assert(!Instance && "Already processing a source file!");
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000160 assert(!Input.File.empty() && "Unexpected empty filename!");
161 setCurrentInput(Input);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000162 setCompilerInstance(&CI);
163
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +0000164 if (!BeginInvocation(CI))
165 goto failure;
166
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000167 // AST files follow a very different path, since they share objects via the
168 // AST unit.
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000169 if (Input.Kind == IK_AST) {
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000170 assert(!usesPreprocessorOnly() &&
171 "Attempt to pass AST file to preprocessor only action!");
Daniel Dunbareb58d832010-06-07 23:24:43 +0000172 assert(hasASTFileSupport() &&
173 "This action does not have AST file support!");
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000174
David Blaikied6471f72011-09-25 23:23:43 +0000175 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000176 std::string Error;
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000177 ASTUnit *AST = ASTUnit::LoadFromASTFile(Input.File, Diags,
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +0000178 CI.getFileSystemOpts());
Daniel Dunbar5262fda2009-12-03 01:45:44 +0000179 if (!AST)
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000180 goto failure;
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000181
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000182 setCurrentInput(Input, AST);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000183
184 // Set the shared objects, these are reset when we finish processing the
185 // file, otherwise the CompilerInstance will happily destroy them.
186 CI.setFileManager(&AST->getFileManager());
187 CI.setSourceManager(&AST->getSourceManager());
188 CI.setPreprocessor(&AST->getPreprocessor());
189 CI.setASTContext(&AST->getASTContext());
190
191 // Initialize the action.
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000192 if (!BeginSourceFileAction(CI, Input.File))
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000193 goto failure;
194
195 /// Create the AST consumer.
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000196 CI.setASTConsumer(CreateWrappedASTConsumer(CI, Input.File));
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000197 if (!CI.hasASTConsumer())
198 goto failure;
199
200 return true;
201 }
202
Daniel Dunbarfaddc3e2010-06-07 23:26:47 +0000203 // Set up the file and source managers, if needed.
Daniel Dunbar20560482010-06-07 23:23:50 +0000204 if (!CI.hasFileManager())
205 CI.createFileManager();
206 if (!CI.hasSourceManager())
Chris Lattner39b49bc2010-11-23 08:35:12 +0000207 CI.createSourceManager(CI.getFileManager());
Daniel Dunbarfaddc3e2010-06-07 23:26:47 +0000208
209 // IR files bypass the rest of initialization.
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000210 if (Input.Kind == IK_LLVM_IR) {
Daniel Dunbarfaddc3e2010-06-07 23:26:47 +0000211 assert(hasIRSupport() &&
212 "This action does not have IR file support!");
213
214 // Inform the diagnostic client we are processing a source file.
215 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 0);
216
217 // Initialize the action.
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000218 if (!BeginSourceFileAction(CI, Input.File))
Daniel Dunbarfaddc3e2010-06-07 23:26:47 +0000219 goto failure;
220
221 return true;
222 }
223
224 // Set up the preprocessor.
Daniel Dunbar20560482010-06-07 23:23:50 +0000225 CI.createPreprocessor();
226
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000227 // Inform the diagnostic client we are processing a source file.
228 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
229 &CI.getPreprocessor());
230
231 // Initialize the action.
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000232 if (!BeginSourceFileAction(CI, Input.File))
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000233 goto failure;
234
235 /// Create the AST context and consumer unless this is a preprocessor only
236 /// action.
237 if (!usesPreprocessorOnly()) {
238 CI.createASTContext();
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000239
Nico Weber5aa74af2011-01-25 20:34:14 +0000240 llvm::OwningPtr<ASTConsumer> Consumer(
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000241 CreateWrappedASTConsumer(CI, Input.File));
Fariborz Jahaniand3057192010-10-29 19:49:13 +0000242 if (!Consumer)
243 goto failure;
Sebastian Redlffaab3e2010-07-30 00:29:29 +0000244
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000245 CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
246
Argyrios Kyrtzidisb0f4b9a2011-03-09 17:21:42 +0000247 if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
248 // Convert headers to PCH and chain them.
249 llvm::OwningPtr<ExternalASTSource> source;
250 source.reset(ChainedIncludesSource::create(CI));
251 if (!source)
252 goto failure;
253 CI.getASTContext().setExternalSource(source);
254
255 } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
256 // Use PCH.
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000257 assert(hasPCHSupport() && "This action does not have PCH support!");
Douglas Gregorf62d43d2011-07-19 16:10:42 +0000258 ASTDeserializationListener *DeserialListener =
259 Consumer->GetASTDeserializationListener();
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +0000260 if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls)
261 DeserialListener = new DeserializedDeclsDumper(DeserialListener);
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +0000262 if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty())
263 DeserialListener = new DeserializedDeclsChecker(CI.getASTContext(),
264 CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn,
265 DeserialListener);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000266 CI.createPCHExternalASTSource(
Douglas Gregorfae3b2f2010-07-27 00:27:13 +0000267 CI.getPreprocessorOpts().ImplicitPCHInclude,
Sebastian Redlffaab3e2010-07-30 00:29:29 +0000268 CI.getPreprocessorOpts().DisablePCHValidation,
Douglas Gregor8ef6c8c2011-02-05 19:42:43 +0000269 CI.getPreprocessorOpts().DisableStatCache,
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +0000270 DeserialListener);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000271 if (!CI.getASTContext().getExternalSource())
272 goto failure;
273 }
Sebastian Redl77f46032010-07-09 21:00:24 +0000274
Sebastian Redlffaab3e2010-07-30 00:29:29 +0000275 CI.setASTConsumer(Consumer.take());
Sebastian Redl77f46032010-07-09 21:00:24 +0000276 if (!CI.hasASTConsumer())
277 goto failure;
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000278 }
279
Jonathan D. Turnere735e2d2011-08-05 22:17:03 +0000280 // Initialize built-in info as long as we aren't using an external AST
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000281 // source.
282 if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) {
283 Preprocessor &PP = CI.getPreprocessor();
284 PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000285 PP.getLangOptions());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000286 }
287
288 return true;
289
290 // If we failed, reset state since the client will not end up calling the
291 // matching EndSourceFile().
292 failure:
293 if (isCurrentFileAST()) {
Ted Kremenek4f327862011-03-21 18:40:17 +0000294 CI.setASTContext(0);
295 CI.setPreprocessor(0);
296 CI.setSourceManager(0);
297 CI.setFileManager(0);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000298 }
299
300 CI.getDiagnosticClient().EndSourceFile();
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000301 setCurrentInput(FrontendInputFile());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000302 setCompilerInstance(0);
303 return false;
304}
305
306void FrontendAction::Execute() {
307 CompilerInstance &CI = getCompilerInstance();
308
309 // Initialize the main file entry. This needs to be delayed until after PCH
310 // has loaded.
Argyrios Kyrtzidisb8c879a2012-01-05 21:36:25 +0000311 if (!isCurrentFileAST()) {
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000312 if (!CI.InitializeSourceManager(getCurrentFile()))
313 return;
314 }
315
Kovarththanan Rajaratnamf79bafa2009-11-29 09:57:35 +0000316 if (CI.hasFrontendTimer()) {
317 llvm::TimeRegion Timer(CI.getFrontendTimer());
318 ExecuteAction();
319 }
320 else ExecuteAction();
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000321}
322
323void FrontendAction::EndSourceFile() {
324 CompilerInstance &CI = getCompilerInstance();
325
Douglas Gregor92b97f22011-02-09 18:47:31 +0000326 // Inform the diagnostic client we are done with this source file.
327 CI.getDiagnosticClient().EndSourceFile();
328
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000329 // Finalize the action.
330 EndSourceFileAction();
331
332 // Release the consumer and the AST, in that order since the consumer may
333 // perform actions in its destructor which require the context.
334 //
335 // FIXME: There is more per-file stuff we could just drop here?
336 if (CI.getFrontendOpts().DisableFree) {
337 CI.takeASTConsumer();
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000338 if (!isCurrentFileAST()) {
339 CI.takeSema();
Ted Kremenek4f327862011-03-21 18:40:17 +0000340 CI.resetAndLeakASTContext();
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000341 }
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000342 } else {
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000343 if (!isCurrentFileAST()) {
344 CI.setSema(0);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000345 CI.setASTContext(0);
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000346 }
347 CI.setASTConsumer(0);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000348 }
349
Daniel Dunbardbd82092010-03-23 05:09:10 +0000350 // Inform the preprocessor we are done.
351 if (CI.hasPreprocessor())
352 CI.getPreprocessor().EndSourceFile();
353
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000354 if (CI.getFrontendOpts().ShowStats) {
355 llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";
356 CI.getPreprocessor().PrintStats();
357 CI.getPreprocessor().getIdentifierTable().PrintStats();
358 CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
359 CI.getSourceManager().PrintStats();
360 llvm::errs() << "\n";
361 }
362
363 // Cleanup the output streams, and erase the output files if we encountered
364 // an error.
Argyrios Kyrtzidisbe3aab62010-11-18 21:47:07 +0000365 CI.clearOutputFiles(/*EraseFiles=*/CI.getDiagnostics().hasErrorOccurred());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000366
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000367 if (isCurrentFileAST()) {
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000368 CI.takeSema();
Ted Kremenek4f327862011-03-21 18:40:17 +0000369 CI.resetAndLeakASTContext();
370 CI.resetAndLeakPreprocessor();
371 CI.resetAndLeakSourceManager();
372 CI.resetAndLeakFileManager();
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000373 }
374
375 setCompilerInstance(0);
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000376 setCurrentInput(FrontendInputFile());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000377}
378
379//===----------------------------------------------------------------------===//
380// Utility Actions
381//===----------------------------------------------------------------------===//
382
383void ASTFrontendAction::ExecuteAction() {
384 CompilerInstance &CI = getCompilerInstance();
385
386 // FIXME: Move the truncation aspect of this into Sema, we delayed this till
387 // here so the source manager would be initialized.
388 if (hasCodeCompletionSupport() &&
389 !CI.getFrontendOpts().CodeCompletionAt.FileName.empty())
390 CI.createCodeCompletionConsumer();
391
392 // Use a code completion consumer?
393 CodeCompleteConsumer *CompletionConsumer = 0;
394 if (CI.hasCodeCompletionConsumer())
395 CompletionConsumer = &CI.getCodeCompletionConsumer();
396
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000397 if (!CI.hasSema())
Douglas Gregor467dc882011-08-25 22:30:56 +0000398 CI.createSema(getTranslationUnitKind(), CompletionConsumer);
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000399
400 ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000401}
402
David Blaikie99ba9e32011-12-20 02:48:34 +0000403void PluginASTAction::anchor() { }
404
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000405ASTConsumer *
406PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000407 StringRef InFile) {
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000408 llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000409}
Chandler Carruthf7f81882011-06-16 16:17:05 +0000410
411ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000412 StringRef InFile) {
Chandler Carruthf7f81882011-06-16 16:17:05 +0000413 return WrappedAction->CreateASTConsumer(CI, InFile);
414}
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +0000415bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) {
416 return WrappedAction->BeginInvocation(CI);
417}
Chandler Carruthf7f81882011-06-16 16:17:05 +0000418bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000419 StringRef Filename) {
Douglas Gregor1f6b2b52012-01-20 16:28:04 +0000420 WrappedAction->setCurrentInput(getCurrentInput());
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +0000421 WrappedAction->setCompilerInstance(&CI);
Chandler Carruthf7f81882011-06-16 16:17:05 +0000422 return WrappedAction->BeginSourceFileAction(CI, Filename);
423}
424void WrapperFrontendAction::ExecuteAction() {
425 WrappedAction->ExecuteAction();
426}
427void WrapperFrontendAction::EndSourceFileAction() {
428 WrappedAction->EndSourceFileAction();
429}
430
431bool WrapperFrontendAction::usesPreprocessorOnly() const {
432 return WrappedAction->usesPreprocessorOnly();
433}
Douglas Gregor467dc882011-08-25 22:30:56 +0000434TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() {
435 return WrappedAction->getTranslationUnitKind();
Chandler Carruthf7f81882011-06-16 16:17:05 +0000436}
437bool WrapperFrontendAction::hasPCHSupport() const {
438 return WrappedAction->hasPCHSupport();
439}
440bool WrapperFrontendAction::hasASTFileSupport() const {
441 return WrappedAction->hasASTFileSupport();
442}
443bool WrapperFrontendAction::hasIRSupport() const {
444 return WrappedAction->hasIRSupport();
445}
446bool WrapperFrontendAction::hasCodeCompletionSupport() const {
447 return WrappedAction->hasCodeCompletionSupport();
448}
449
450WrapperFrontendAction::WrapperFrontendAction(FrontendAction *WrappedAction)
451 : WrappedAction(WrappedAction) {}
452