blob: 439a124f3bb6b6db6bb04cc07c30c6c246a16ffa [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
Chris Lattner5f9e2722011-07-23 10:55:15 +0000118void FrontendAction::setCurrentFile(StringRef Value, InputKind Kind,
Daniel Dunbar685ac662010-06-07 23:25:49 +0000119 ASTUnit *AST) {
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000120 CurrentFile = Value;
Daniel Dunbar685ac662010-06-07 23:25:49 +0000121 CurrentFileKind = Kind;
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000122 CurrentASTUnit.reset(AST);
123}
124
Nico Weber5aa74af2011-01-25 20:34:14 +0000125ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000126 StringRef InFile) {
Nico Weber5aa74af2011-01-25 20:34:14 +0000127 ASTConsumer* Consumer = CreateASTConsumer(CI, InFile);
128 if (!Consumer)
129 return 0;
130
131 if (CI.getFrontendOpts().AddPluginActions.size() == 0)
132 return Consumer;
133
134 // Make sure the non-plugin consumer is first, so that plugins can't
135 // modifiy the AST.
136 std::vector<ASTConsumer*> Consumers(1, Consumer);
137
138 for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size();
139 i != e; ++i) {
140 // This is O(|plugins| * |add_plugins|), but since both numbers are
141 // way below 50 in practice, that's ok.
142 for (FrontendPluginRegistry::iterator
143 it = FrontendPluginRegistry::begin(),
144 ie = FrontendPluginRegistry::end();
145 it != ie; ++it) {
146 if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) {
147 llvm::OwningPtr<PluginASTAction> P(it->instantiate());
148 FrontendAction* c = P.get();
Nico Weberf25649c2011-01-29 21:21:49 +0000149 if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i]))
Nico Weber5aa74af2011-01-25 20:34:14 +0000150 Consumers.push_back(c->CreateASTConsumer(CI, InFile));
151 }
152 }
153 }
154
155 return new MultiplexConsumer(Consumers);
156}
157
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000158bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000159 StringRef Filename,
Daniel Dunbard3598a62010-06-07 23:23:06 +0000160 InputKind InputKind) {
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000161 assert(!Instance && "Already processing a source file!");
162 assert(!Filename.empty() && "Unexpected empty filename!");
Daniel Dunbar685ac662010-06-07 23:25:49 +0000163 setCurrentFile(Filename, InputKind);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000164 setCompilerInstance(&CI);
165
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +0000166 if (!BeginInvocation(CI))
167 goto failure;
168
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000169 // AST files follow a very different path, since they share objects via the
170 // AST unit.
Daniel Dunbar20560482010-06-07 23:23:50 +0000171 if (InputKind == IK_AST) {
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000172 assert(!usesPreprocessorOnly() &&
173 "Attempt to pass AST file to preprocessor only action!");
Daniel Dunbareb58d832010-06-07 23:24:43 +0000174 assert(hasASTFileSupport() &&
175 "This action does not have AST file support!");
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000176
David Blaikied6471f72011-09-25 23:23:43 +0000177 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000178 std::string Error;
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +0000179 ASTUnit *AST = ASTUnit::LoadFromASTFile(Filename, Diags,
180 CI.getFileSystemOpts());
Daniel Dunbar5262fda2009-12-03 01:45:44 +0000181 if (!AST)
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000182 goto failure;
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000183
Daniel Dunbar685ac662010-06-07 23:25:49 +0000184 setCurrentFile(Filename, InputKind, AST);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000185
186 // Set the shared objects, these are reset when we finish processing the
187 // file, otherwise the CompilerInstance will happily destroy them.
188 CI.setFileManager(&AST->getFileManager());
189 CI.setSourceManager(&AST->getSourceManager());
190 CI.setPreprocessor(&AST->getPreprocessor());
191 CI.setASTContext(&AST->getASTContext());
192
193 // Initialize the action.
194 if (!BeginSourceFileAction(CI, Filename))
195 goto failure;
196
197 /// Create the AST consumer.
Nico Weber5aa74af2011-01-25 20:34:14 +0000198 CI.setASTConsumer(CreateWrappedASTConsumer(CI, Filename));
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000199 if (!CI.hasASTConsumer())
200 goto failure;
201
202 return true;
203 }
204
Daniel Dunbarfaddc3e2010-06-07 23:26:47 +0000205 // Set up the file and source managers, if needed.
Daniel Dunbar20560482010-06-07 23:23:50 +0000206 if (!CI.hasFileManager())
207 CI.createFileManager();
208 if (!CI.hasSourceManager())
Chris Lattner39b49bc2010-11-23 08:35:12 +0000209 CI.createSourceManager(CI.getFileManager());
Daniel Dunbarfaddc3e2010-06-07 23:26:47 +0000210
211 // IR files bypass the rest of initialization.
212 if (InputKind == IK_LLVM_IR) {
213 assert(hasIRSupport() &&
214 "This action does not have IR file support!");
215
216 // Inform the diagnostic client we are processing a source file.
217 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 0);
218
219 // Initialize the action.
220 if (!BeginSourceFileAction(CI, Filename))
221 goto failure;
222
223 return true;
224 }
225
226 // Set up the preprocessor.
Daniel Dunbar20560482010-06-07 23:23:50 +0000227 CI.createPreprocessor();
228
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000229 // Inform the diagnostic client we are processing a source file.
230 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
231 &CI.getPreprocessor());
232
233 // Initialize the action.
234 if (!BeginSourceFileAction(CI, Filename))
235 goto failure;
236
237 /// Create the AST context and consumer unless this is a preprocessor only
238 /// action.
239 if (!usesPreprocessorOnly()) {
240 CI.createASTContext();
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000241
Nico Weber5aa74af2011-01-25 20:34:14 +0000242 llvm::OwningPtr<ASTConsumer> Consumer(
243 CreateWrappedASTConsumer(CI, Filename));
Fariborz Jahaniand3057192010-10-29 19:49:13 +0000244 if (!Consumer)
245 goto failure;
Sebastian Redlffaab3e2010-07-30 00:29:29 +0000246
Argyrios Kyrtzidis7b903402010-10-24 17:26:36 +0000247 CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
248
Argyrios Kyrtzidisb0f4b9a2011-03-09 17:21:42 +0000249 if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
250 // Convert headers to PCH and chain them.
251 llvm::OwningPtr<ExternalASTSource> source;
252 source.reset(ChainedIncludesSource::create(CI));
253 if (!source)
254 goto failure;
255 CI.getASTContext().setExternalSource(source);
256
257 } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
258 // Use PCH.
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000259 assert(hasPCHSupport() && "This action does not have PCH support!");
Douglas Gregorf62d43d2011-07-19 16:10:42 +0000260 ASTDeserializationListener *DeserialListener =
261 Consumer->GetASTDeserializationListener();
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +0000262 if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls)
263 DeserialListener = new DeserializedDeclsDumper(DeserialListener);
Argyrios Kyrtzidis3e785932010-10-14 20:14:25 +0000264 if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty())
265 DeserialListener = new DeserializedDeclsChecker(CI.getASTContext(),
266 CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn,
267 DeserialListener);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000268 CI.createPCHExternalASTSource(
Douglas Gregorfae3b2f2010-07-27 00:27:13 +0000269 CI.getPreprocessorOpts().ImplicitPCHInclude,
Sebastian Redlffaab3e2010-07-30 00:29:29 +0000270 CI.getPreprocessorOpts().DisablePCHValidation,
Douglas Gregor8ef6c8c2011-02-05 19:42:43 +0000271 CI.getPreprocessorOpts().DisableStatCache,
Argyrios Kyrtzidisb9728582010-10-14 20:14:18 +0000272 DeserialListener);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000273 if (!CI.getASTContext().getExternalSource())
274 goto failure;
275 }
Sebastian Redl77f46032010-07-09 21:00:24 +0000276
Sebastian Redlffaab3e2010-07-30 00:29:29 +0000277 CI.setASTConsumer(Consumer.take());
Sebastian Redl77f46032010-07-09 21:00:24 +0000278 if (!CI.hasASTConsumer())
279 goto failure;
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000280 }
281
Jonathan D. Turnere735e2d2011-08-05 22:17:03 +0000282 // Initialize built-in info as long as we aren't using an external AST
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000283 // source.
284 if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) {
285 Preprocessor &PP = CI.getPreprocessor();
286 PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000287 PP.getLangOptions());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000288 }
289
290 return true;
291
292 // If we failed, reset state since the client will not end up calling the
293 // matching EndSourceFile().
294 failure:
295 if (isCurrentFileAST()) {
Ted Kremenek4f327862011-03-21 18:40:17 +0000296 CI.setASTContext(0);
297 CI.setPreprocessor(0);
298 CI.setSourceManager(0);
299 CI.setFileManager(0);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000300 }
301
302 CI.getDiagnosticClient().EndSourceFile();
Daniel Dunbar685ac662010-06-07 23:25:49 +0000303 setCurrentFile("", IK_None);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000304 setCompilerInstance(0);
305 return false;
306}
307
308void FrontendAction::Execute() {
309 CompilerInstance &CI = getCompilerInstance();
310
311 // Initialize the main file entry. This needs to be delayed until after PCH
312 // has loaded.
313 if (isCurrentFileAST()) {
314 // Set the main file ID to an empty file.
315 //
316 // FIXME: We probably shouldn't need this, but for now this is the
317 // simplest way to reuse the logic in ParseAST.
318 const char *EmptyStr = "";
319 llvm::MemoryBuffer *SB =
Chris Lattnera0a270c2010-04-05 22:42:27 +0000320 llvm::MemoryBuffer::getMemBuffer(EmptyStr, "<dummy input>");
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000321 CI.getSourceManager().createMainFileIDForMemBuffer(SB);
322 } else {
323 if (!CI.InitializeSourceManager(getCurrentFile()))
324 return;
325 }
326
Kovarththanan Rajaratnamf79bafa2009-11-29 09:57:35 +0000327 if (CI.hasFrontendTimer()) {
328 llvm::TimeRegion Timer(CI.getFrontendTimer());
329 ExecuteAction();
330 }
331 else ExecuteAction();
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000332}
333
334void FrontendAction::EndSourceFile() {
335 CompilerInstance &CI = getCompilerInstance();
336
Douglas Gregor92b97f22011-02-09 18:47:31 +0000337 // Inform the diagnostic client we are done with this source file.
338 CI.getDiagnosticClient().EndSourceFile();
339
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000340 // Finalize the action.
341 EndSourceFileAction();
342
343 // Release the consumer and the AST, in that order since the consumer may
344 // perform actions in its destructor which require the context.
345 //
346 // FIXME: There is more per-file stuff we could just drop here?
347 if (CI.getFrontendOpts().DisableFree) {
348 CI.takeASTConsumer();
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000349 if (!isCurrentFileAST()) {
350 CI.takeSema();
Ted Kremenek4f327862011-03-21 18:40:17 +0000351 CI.resetAndLeakASTContext();
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000352 }
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000353 } else {
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000354 if (!isCurrentFileAST()) {
355 CI.setSema(0);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000356 CI.setASTContext(0);
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000357 }
358 CI.setASTConsumer(0);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000359 }
360
Daniel Dunbardbd82092010-03-23 05:09:10 +0000361 // Inform the preprocessor we are done.
362 if (CI.hasPreprocessor())
363 CI.getPreprocessor().EndSourceFile();
364
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000365 if (CI.getFrontendOpts().ShowStats) {
366 llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";
367 CI.getPreprocessor().PrintStats();
368 CI.getPreprocessor().getIdentifierTable().PrintStats();
369 CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
370 CI.getSourceManager().PrintStats();
371 llvm::errs() << "\n";
372 }
373
374 // Cleanup the output streams, and erase the output files if we encountered
375 // an error.
Argyrios Kyrtzidisbe3aab62010-11-18 21:47:07 +0000376 CI.clearOutputFiles(/*EraseFiles=*/CI.getDiagnostics().hasErrorOccurred());
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000377
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000378 if (isCurrentFileAST()) {
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000379 CI.takeSema();
Ted Kremenek4f327862011-03-21 18:40:17 +0000380 CI.resetAndLeakASTContext();
381 CI.resetAndLeakPreprocessor();
382 CI.resetAndLeakSourceManager();
383 CI.resetAndLeakFileManager();
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000384 }
385
386 setCompilerInstance(0);
Daniel Dunbar685ac662010-06-07 23:25:49 +0000387 setCurrentFile("", IK_None);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000388}
389
390//===----------------------------------------------------------------------===//
391// Utility Actions
392//===----------------------------------------------------------------------===//
393
394void ASTFrontendAction::ExecuteAction() {
395 CompilerInstance &CI = getCompilerInstance();
396
397 // FIXME: Move the truncation aspect of this into Sema, we delayed this till
398 // here so the source manager would be initialized.
399 if (hasCodeCompletionSupport() &&
400 !CI.getFrontendOpts().CodeCompletionAt.FileName.empty())
401 CI.createCodeCompletionConsumer();
402
403 // Use a code completion consumer?
404 CodeCompleteConsumer *CompletionConsumer = 0;
405 if (CI.hasCodeCompletionConsumer())
406 CompletionConsumer = &CI.getCodeCompletionConsumer();
407
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000408 if (!CI.hasSema())
Douglas Gregor467dc882011-08-25 22:30:56 +0000409 CI.createSema(getTranslationUnitKind(), CompletionConsumer);
Douglas Gregorf18d0d82010-08-12 23:31:19 +0000410
411 ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats);
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000412}
413
414ASTConsumer *
415PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000416 StringRef InFile) {
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000417 llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
Daniel Dunbar4ee24092009-11-14 10:42:35 +0000418}
Chandler Carruthf7f81882011-06-16 16:17:05 +0000419
420ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000421 StringRef InFile) {
Chandler Carruthf7f81882011-06-16 16:17:05 +0000422 return WrappedAction->CreateASTConsumer(CI, InFile);
423}
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +0000424bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) {
425 return WrappedAction->BeginInvocation(CI);
426}
Chandler Carruthf7f81882011-06-16 16:17:05 +0000427bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000428 StringRef Filename) {
Argyrios Kyrtzidise665d692011-06-18 00:53:41 +0000429 WrappedAction->setCurrentFile(getCurrentFile(), getCurrentFileKind());
430 WrappedAction->setCompilerInstance(&CI);
Chandler Carruthf7f81882011-06-16 16:17:05 +0000431 return WrappedAction->BeginSourceFileAction(CI, Filename);
432}
433void WrapperFrontendAction::ExecuteAction() {
434 WrappedAction->ExecuteAction();
435}
436void WrapperFrontendAction::EndSourceFileAction() {
437 WrappedAction->EndSourceFileAction();
438}
439
440bool WrapperFrontendAction::usesPreprocessorOnly() const {
441 return WrappedAction->usesPreprocessorOnly();
442}
Douglas Gregor467dc882011-08-25 22:30:56 +0000443TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() {
444 return WrappedAction->getTranslationUnitKind();
Chandler Carruthf7f81882011-06-16 16:17:05 +0000445}
446bool WrapperFrontendAction::hasPCHSupport() const {
447 return WrappedAction->hasPCHSupport();
448}
449bool WrapperFrontendAction::hasASTFileSupport() const {
450 return WrappedAction->hasASTFileSupport();
451}
452bool WrapperFrontendAction::hasIRSupport() const {
453 return WrappedAction->hasIRSupport();
454}
455bool WrapperFrontendAction::hasCodeCompletionSupport() const {
456 return WrappedAction->hasCodeCompletionSupport();
457}
458
459WrapperFrontendAction::WrapperFrontendAction(FrontendAction *WrappedAction)
460 : WrappedAction(WrappedAction) {}
461