clang 10.0.0git

FrontendAction.cpp
Go to the documentation of this file.
1 //===--- FrontendAction.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "clang/Frontend/FrontendAction.h"
10 #include "clang/AST/ASTConsumer.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/AST/DeclGroup.h"
13 #include "clang/Basic/Builtins.h"
14 #include "clang/Basic/LangStandard.h"
15 #include "clang/Frontend/ASTUnit.h"
16 #include "clang/Frontend/CompilerInstance.h"
17 #include "clang/Frontend/FrontendDiagnostic.h"
18 #include "clang/Frontend/FrontendPluginRegistry.h"
19 #include "clang/Frontend/LayoutOverrideSource.h"
20 #include "clang/Frontend/MultiplexConsumer.h"
21 #include "clang/Frontend/Utils.h"
22 #include "clang/Lex/HeaderSearch.h"
23 #include "clang/Lex/LiteralSupport.h"
24 #include "clang/Lex/Preprocessor.h"
25 #include "clang/Lex/PreprocessorOptions.h"
26 #include "clang/Parse/ParseAST.h"
27 #include "clang/Serialization/ASTDeserializationListener.h"
28 #include "clang/Serialization/ASTReader.h"
29 #include "clang/Serialization/GlobalModuleIndex.h"
30 #include "llvm/Support/BuryPointer.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/FileSystem.h"
33 #include "llvm/Support/Path.h"
34 #include "llvm/Support/Timer.h"
35 #include "llvm/Support/raw_ostream.h"
36 #include <system_error>
37 using namespace clang;
38
39 LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
40
41 namespace {
42
43 class DelegatingDeserializationListener : public ASTDeserializationListener {
44 ASTDeserializationListener *Previous;
45 bool DeletePrevious;
46
47 public:
48 explicit DelegatingDeserializationListener(
49 ASTDeserializationListener *Previous, bool DeletePrevious)
50 : Previous(Previous), DeletePrevious(DeletePrevious) {}
51 ~DelegatingDeserializationListener() override {
52 if (DeletePrevious)
53 delete Previous;
54 }
55
56 void ReaderInitialized(ASTReader *Reader) override {
57 if (Previous)
58 Previous->ReaderInitialized(Reader);
59 }
60 void IdentifierRead(serialization::IdentID ID,
61 IdentifierInfo *II) override {
62 if (Previous)
63 Previous->IdentifierRead(ID, II);
64 }
65 void TypeRead(serialization::TypeIdx Idx, QualType T) override {
66 if (Previous)
67 Previous->TypeRead(Idx, T);
68 }
69 void DeclRead(serialization::DeclID ID, const Decl *D) override {
70 if (Previous)
71 Previous->DeclRead(ID, D);
72 }
73 void SelectorRead(serialization::SelectorID ID, Selector Sel) override {
74 if (Previous)
75 Previous->SelectorRead(ID, Sel);
76 }
77 void MacroDefinitionRead(serialization::PreprocessedEntityID PPID,
78 MacroDefinitionRecord *MD) override {
79 if (Previous)
80 Previous->MacroDefinitionRead(PPID, MD);
81 }
82 };
83
84 /// Dumps deserialized declarations.
85 class DeserializedDeclsDumper : public DelegatingDeserializationListener {
86 public:
87 explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous,
88 bool DeletePrevious)
89 : DelegatingDeserializationListener(Previous, DeletePrevious) {}
90
91 void DeclRead(serialization::DeclID ID, const Decl *D) override {
92 llvm::outs() << "PCH DECL: " << D->getDeclKindName();
93 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
94 llvm::outs() << " - ";
95 ND->printQualifiedName(llvm::outs());
96 }
97 llvm::outs() << "\n";
98
99 DelegatingDeserializationListener::DeclRead(ID, D);
100 }
101 };
102
103 /// Checks deserialized declarations and emits error if a name
104 /// matches one given in command-line using -error-on-deserialized-decl.
105 class DeserializedDeclsChecker : public DelegatingDeserializationListener {
106 ASTContext &Ctx;
107 std::set<std::string> NamesToCheck;
108
109 public:
110 DeserializedDeclsChecker(ASTContext &Ctx,
111 const std::set<std::string> &NamesToCheck,
112 ASTDeserializationListener *Previous,
113 bool DeletePrevious)
114 : DelegatingDeserializationListener(Previous, DeletePrevious), Ctx(Ctx),
115 NamesToCheck(NamesToCheck) {}
116
117 void DeclRead(serialization::DeclID ID, const Decl *D) override {
118 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
119 if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) {
120 unsigned DiagID
121 = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error,
122 "%0 was deserialized");
123 Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID)
124 << ND->getNameAsString();
125 }
126
127 DelegatingDeserializationListener::DeclRead(ID, D);
128 }
129 };
130
131 } // end anonymous namespace
132
133 FrontendAction::FrontendAction() : Instance(nullptr) {}
134
135 FrontendAction::~FrontendAction() {}
136
137 void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput,
138 std::unique_ptr<ASTUnit> AST) {
139 this->CurrentInput = CurrentInput;
140 CurrentASTUnit = std::move(AST);
141 }
142
143 Module *FrontendAction::getCurrentModule() const {
144 CompilerInstance &CI = getCompilerInstance();
145 return CI.getPreprocessor().getHeaderSearchInfo().lookupModule(
146 CI.getLangOpts().CurrentModule, /*AllowSearch*/false);
147 }
148
149 std::unique_ptr<ASTConsumer>
150 FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
151 StringRef InFile) {
152 std::unique_ptr<ASTConsumer> Consumer = CreateASTConsumer(CI, InFile);
153 if (!Consumer)
154 return nullptr;
155
156 // Validate -add-plugin args.
157 bool FoundAllPlugins = true;
158 for (const std::string &Arg : CI.getFrontendOpts().AddPluginActions) {
159 bool Found = false;
160 for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
161 ie = FrontendPluginRegistry::end();
162 it != ie; ++it) {
163 if (it->getName() == Arg)
164 Found = true;
165 }
166 if (!Found) {
167 CI.getDiagnostics().Report(diag::err_fe_invalid_plugin_name) << Arg;
168 FoundAllPlugins = false;
169 }
170 }
171 if (!FoundAllPlugins)
172 return nullptr;
173
174 // If there are no registered plugins we don't need to wrap the consumer
175 if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
176 return Consumer;
177
178 // If this is a code completion run, avoid invoking the plugin consumers
179 if (CI.hasCodeCompletionConsumer())
180 return Consumer;
181
182 // Collect the list of plugins that go before the main action (in Consumers)
183 // or after it (in AfterConsumers)
184 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
185 std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers;
186 for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
187 ie = FrontendPluginRegistry::end();
188 it != ie; ++it) {
189 std::unique_ptr<PluginASTAction> P = it->instantiate();
190 PluginASTAction::ActionType ActionType = P->getActionType();
191 if (ActionType == PluginASTAction::Cmdline) {
192 // This is O(|plugins| * |add_plugins|), but since both numbers are
193 // way below 50 in practice, that's ok.
194 for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size();
195 i != e; ++i) {
196 if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) {
197 ActionType = PluginASTAction::AddAfterMainAction;
198 break;
199 }
200 }
201 }
202 if ((ActionType == PluginASTAction::AddBeforeMainAction ||
203 ActionType == PluginASTAction::AddAfterMainAction) &&
204 P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs[it->getName()])) {
205 std::unique_ptr<ASTConsumer> PluginConsumer = P->CreateASTConsumer(CI, InFile);
206 if (ActionType == PluginASTAction::AddBeforeMainAction) {
207 Consumers.push_back(std::move(PluginConsumer));
208 } else {
209 AfterConsumers.push_back(std::move(PluginConsumer));
210 }
211 }
212 }
213
214 // Add to Consumers the main consumer, then all the plugins that go after it
215 Consumers.push_back(std::move(Consumer));
216 for (auto &C : AfterConsumers) {
217 Consumers.push_back(std::move(C));
218 }
219
220 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
221 }
222
223 /// For preprocessed files, if the first line is the linemarker and specifies
224 /// the original source file name, use that name as the input file name.
225 /// Returns the location of the first token after the line marker directive.
226 ///
227 /// \param CI The compiler instance.
228 /// \param InputFile Populated with the filename from the line marker.
229 /// \param IsModuleMap If \c true, add a line note corresponding to this line
230 /// directive. (We need to do this because the directive will not be
231 /// visited by the preprocessor.)
232 static SourceLocation ReadOriginalFileName(CompilerInstance &CI,
233 std::string &InputFile,
234 bool IsModuleMap = false) {
235 auto &SourceMgr = CI.getSourceManager();
236 auto MainFileID = SourceMgr.getMainFileID();
237
238 bool Invalid = false;
239 const auto *MainFileBuf = SourceMgr.getBuffer(MainFileID, &Invalid);
240 if (Invalid)
241 return SourceLocation();
242
243 std::unique_ptr<Lexer> RawLexer(
244 new Lexer(MainFileID, MainFileBuf, SourceMgr, CI.getLangOpts()));
245
246 // If the first line has the syntax of
247 //
248 // # NUM "FILENAME"
249 //
250 // we use FILENAME as the input file name.
251 Token T;
252 if (RawLexer->LexFromRawLexer(T) || T.getKind() != tok::hash)
253 return SourceLocation();
254 if (RawLexer->LexFromRawLexer(T) || T.isAtStartOfLine() ||
255 T.getKind() != tok::numeric_constant)
256 return SourceLocation();
257
258 unsigned LineNo;
259 SourceLocation LineNoLoc = T.getLocation();
260 if (IsModuleMap) {
261 llvm::SmallString<16> Buffer;
262 if (Lexer::getSpelling(LineNoLoc, Buffer, SourceMgr, CI.getLangOpts())
263 .getAsInteger(10, LineNo))
264 return SourceLocation();
265 }
266
267 RawLexer->LexFromRawLexer(T);
268 if (T.isAtStartOfLine() || T.getKind() != tok::string_literal)
269 return SourceLocation();
270
271 StringLiteralParser Literal(T, CI.getPreprocessor());
272 if (Literal.hadError)
273 return SourceLocation();
274 RawLexer->LexFromRawLexer(T);
275 if (T.isNot(tok::eof) && !T.isAtStartOfLine())
276 return SourceLocation();
277 InputFile = Literal.GetString().str();
278
279 if (IsModuleMap)
280 CI.getSourceManager().AddLineNote(
281 LineNoLoc, LineNo, SourceMgr.getLineTableFilenameID(InputFile), false,
282 false, SrcMgr::C_User_ModuleMap);
283
284 return T.getLocation();
285 }
286
287 static SmallVectorImpl<char> &
288 operator+=(SmallVectorImpl<char> &Includes, StringRef RHS) {
289 Includes.append(RHS.begin(), RHS.end());
290 return Includes;
291 }
292
293 static void addHeaderInclude(StringRef HeaderName,
294 SmallVectorImpl<char> &Includes,
295 const LangOptions &LangOpts,
296 bool IsExternC) {
297 if (IsExternC && LangOpts.CPlusPlus)
298 Includes += "extern \"C\" {\n";
299 if (LangOpts.ObjC)
300 Includes += "#import \"";
301 else
302 Includes += "#include \"";
303
304 Includes += HeaderName;
305
306 Includes += "\"\n";
307 if (IsExternC && LangOpts.CPlusPlus)
308 Includes += "}\n";
309 }
310
311 /// Collect the set of header includes needed to construct the given
312 /// module and update the TopHeaders file set of the module.
313 ///
314 /// \param Module The module we're collecting includes from.
315 ///
316 /// \param Includes Will be augmented with the set of \#includes or \#imports
317 /// needed to load all of the named headers.
318 static std::error_code collectModuleHeaderIncludes(
319 const LangOptions &LangOpts, FileManager &FileMgr, DiagnosticsEngine &Diag,
320 ModuleMap &ModMap, clang::Module *Module, SmallVectorImpl<char> &Includes) {
321 // Don't collect any headers for unavailable modules.
322 if (!Module->isAvailable())
323 return std::error_code();
324
325 // Resolve all lazy header directives to header files.
326 ModMap.resolveHeaderDirectives(Module);
327
328 // If any headers are missing, we can't build this module. In most cases,
329 // diagnostics for this should have already been produced; we only get here
330 // if explicit stat information was provided.
331 // FIXME: If the name resolves to a file with different stat information,
332 // produce a better diagnostic.
333 if (!Module->MissingHeaders.empty()) {
334 auto &MissingHeader = Module->MissingHeaders.front();
335 Diag.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
336 << MissingHeader.IsUmbrella << MissingHeader.FileName;
337 return std::error_code();
338 }
339
340 // Add includes for each of these headers.
341 for (auto HK : {Module::HK_Normal, Module::HK_Private}) {
342 for (Module::Header &H : Module->Headers[HK]) {
343 Module->addTopHeader(H.Entry);
344 // Use the path as specified in the module map file. We'll look for this
345 // file relative to the module build directory (the directory containing
346 // the module map file) so this will find the same file that we found
347 // while parsing the module map.
348 addHeaderInclude(H.NameAsWritten, Includes, LangOpts, Module->IsExternC);
349 }
350 }
351 // Note that Module->PrivateHeaders will not be a TopHeader.
352
353 if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) {
354 Module->addTopHeader(UmbrellaHeader.Entry);
355 if (Module->Parent)
356 // Include the umbrella header for submodules.
357 addHeaderInclude(UmbrellaHeader.NameAsWritten, Includes, LangOpts,
358 Module->IsExternC);
359 } else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) {
360 // Add all of the headers we find in this subdirectory.
361 std::error_code EC;
362 SmallString<128> DirNative;
363 llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);
364
365 llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
366 for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End;
367 Dir != End && !EC; Dir.increment(EC)) {
368 // Check whether this entry has an extension typically associated with
369 // headers.
370 if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
371 .Cases(".h", ".H", ".hh", ".hpp", true)
372 .Default(false))
373 continue;
374
375 auto Header = FileMgr.getFile(Dir->path());
376 // FIXME: This shouldn't happen unless there is a file system race. Is
377 // that worth diagnosing?
378 if (!Header)
379 continue;
380
381 // If this header is marked 'unavailable' in this module, don't include
382 // it.
383 if (ModMap.isHeaderUnavailableInModule(*Header, Module))
384 continue;
385
386 // Compute the relative path from the directory to this file.
387 SmallVector<StringRef, 16> Components;
388 auto PathIt = llvm::sys::path::rbegin(Dir->path());
389 for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt)
390 Components.push_back(*PathIt);
391 SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten);
392 for (auto It = Components.rbegin(), End = Components.rend(); It != End;
393 ++It)
394 llvm::sys::path::append(RelativeHeader, *It);
395
396 // Include this header as part of the umbrella directory.
397 Module->addTopHeader(*Header);
398 addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC);
399 }
400
401 if (EC)
402 return EC;
403 }
404
405 // Recurse into submodules.
406 for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
407 SubEnd = Module->submodule_end();
408 Sub != SubEnd; ++Sub)
409 if (std::error_code Err = collectModuleHeaderIncludes(
410 LangOpts, FileMgr, Diag, ModMap, *Sub, Includes))
411 return Err;
412
413 return std::error_code();
414 }
415
416 static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
417 bool IsPreprocessed,
418 std::string &PresumedModuleMapFile,
419 unsigned &Offset) {
420 auto &SrcMgr = CI.getSourceManager();
421 HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
422
423 // Map the current input to a file.
424 FileID ModuleMapID = SrcMgr.getMainFileID();
425 const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID);
426
427 // If the module map is preprocessed, handle the initial line marker;
428 // line directives are not part of the module map syntax in general.
429 Offset = 0;
430 if (IsPreprocessed) {
431 SourceLocation EndOfLineMarker =
432 ReadOriginalFileName(CI, PresumedModuleMapFile, /*IsModuleMap*/ true);
433 if (EndOfLineMarker.isValid())
434 Offset = CI.getSourceManager().getDecomposedLoc(EndOfLineMarker).second;
435 }
436
437 // Load the module map file.
438 if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,
439 PresumedModuleMapFile))
440 return true;
441
442 if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
443 Offset = 0;
444
445 return false;
446 }
447
448 static Module *prepareToBuildModule(CompilerInstance &CI,
449 StringRef ModuleMapFilename) {
450 if (CI.getLangOpts().CurrentModule.empty()) {
451 CI.getDiagnostics().Report(diag::err_missing_module_name);
452
453 // FIXME: Eventually, we could consider asking whether there was just
454 // a single module described in the module map, and use that as a
455 // default. Then it would be fairly trivial to just "compile" a module
456 // map with a single module (the common case).
457 return nullptr;
458 }
459
460 // Dig out the module definition.
461 HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
462 Module *M = HS.lookupModule(CI.getLangOpts().CurrentModule,
463 /*AllowSearch=*/false);
464 if (!M) {
465 CI.getDiagnostics().Report(diag::err_missing_module)
466 << CI.getLangOpts().CurrentModule << ModuleMapFilename;
467
468 return nullptr;
469 }
470
471 // Check whether we can build this module at all.
472 if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(),
473 CI.getDiagnostics(), M))
474 return nullptr;
475
476 // Inform the preprocessor that includes from within the input buffer should
477 // be resolved relative to the build directory of the module map file.
478 CI.getPreprocessor().setMainFileDir(M->Directory);
479
480 // If the module was inferred from a different module map (via an expanded
481 // umbrella module definition), track that fact.
482 // FIXME: It would be preferable to fill this in as part of processing
483 // the module map, rather than adding it after the fact.
484 StringRef OriginalModuleMapName = CI.getFrontendOpts().OriginalModuleMap;
485 if (!OriginalModuleMapName.empty()) {
486 auto OriginalModuleMap =
487 CI.getFileManager().getFile(OriginalModuleMapName,
488 /*openFile*/ true);
489 if (!OriginalModuleMap) {
490 CI.getDiagnostics().Report(diag::err_module_map_not_found)
491 << OriginalModuleMapName;
492 return nullptr;
493 }
494 if (*OriginalModuleMap != CI.getSourceManager().getFileEntryForID(
495 CI.getSourceManager().getMainFileID())) {
496 M->IsInferred = true;
497 CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()
498 .setInferredModuleAllowedBy(M, *OriginalModuleMap);
499 }
500 }
501
502 // If we're being run from the command-line, the module build stack will not
503 // have been filled in yet, so complete it now in order to allow us to detect
504 // module cycles.
505 SourceManager &SourceMgr = CI.getSourceManager();
506 if (SourceMgr.getModuleBuildStack().empty())
507 SourceMgr.pushModuleBuildStack(CI.getLangOpts().CurrentModule,
508 FullSourceLoc(SourceLocation(), SourceMgr));
509 return M;
510 }
511
512 /// Compute the input buffer that should be used to build the specified module.
513 static std::unique_ptr<llvm::MemoryBuffer>
514 getInputBufferForModule(CompilerInstance &CI, Module *M) {
515 FileManager &FileMgr = CI.getFileManager();
516
517 // Collect the set of #includes we need to build the module.
518 SmallString<256> HeaderContents;
519 std::error_code Err = std::error_code();
520 if (Module::Header UmbrellaHeader = M->getUmbrellaHeader())
521 addHeaderInclude(UmbrellaHeader.NameAsWritten, HeaderContents,
522 CI.getLangOpts(), M->IsExternC);
523 Err = collectModuleHeaderIncludes(
524 CI.getLangOpts(), FileMgr, CI.getDiagnostics(),
525 CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(), M,
526 HeaderContents);
527
528 if (Err) {
529 CI.getDiagnostics().Report(diag::err_module_cannot_create_includes)
530 << M->getFullModuleName() << Err.message();
531 return nullptr;
532 }
533
534 return llvm::MemoryBuffer::getMemBufferCopy(
535 HeaderContents, Module::getModuleInputBufferName());
536 }
537
538 bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
539 const FrontendInputFile &RealInput) {
540 FrontendInputFile Input(RealInput);
541 assert(!Instance && "Already processing a source file!");
542 assert(!Input.isEmpty() && "Unexpected empty filename!");
543 setCurrentInput(Input);
544 setCompilerInstance(&CI);
545
546 bool HasBegunSourceFile = false;
547 bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&
548 usesPreprocessorOnly();
549 if (!BeginInvocation(CI))
550 goto failure;
551
552 // If we're replaying the build of an AST file, import it and set up
553 // the initial state from its build.
554 if (ReplayASTFile) {
555 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
556
557 // The AST unit populates its own diagnostics engine rather than ours.
558 IntrusiveRefCntPtr<DiagnosticsEngine> ASTDiags(
559 new DiagnosticsEngine(Diags->getDiagnosticIDs(),
560 &Diags->getDiagnosticOptions()));
561 ASTDiags->setClient(Diags->getClient(), /*OwnsClient*/false);
562
563 // FIXME: What if the input is a memory buffer?
564 StringRef InputFile = Input.getFile();
565
566 std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
567 InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly,
568 ASTDiags, CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs);
569 if (!AST)
570 goto failure;
571
572 // Options relating to how we treat the input (but not what we do with it)
573 // are inherited from the AST unit.
574 CI.getHeaderSearchOpts() = AST->getHeaderSearchOpts();
575 CI.getPreprocessorOpts() = AST->getPreprocessorOpts();
576 CI.getLangOpts() = AST->getLangOpts();
577
578 // Set the shared objects, these are reset when we finish processing the
579 // file, otherwise the CompilerInstance will happily destroy them.
580 CI.setFileManager(&AST->getFileManager());
581 CI.createSourceManager(CI.getFileManager());
582 CI.getSourceManager().initializeForReplay(AST->getSourceManager());
583
584 // Preload all the module files loaded transitively by the AST unit. Also
585 // load all module map files that were parsed as part of building the AST
586 // unit.
587 if (auto ASTReader = AST->getASTReader()) {
588 auto &MM = ASTReader->getModuleManager();
589 auto &PrimaryModule = MM.getPrimaryModule();
590
591 for (serialization::ModuleFile &MF : MM)
592 if (&MF != &PrimaryModule)
593 CI.getFrontendOpts().ModuleFiles.push_back(MF.FileName);
594
595 ASTReader->visitTopLevelModuleMaps(PrimaryModule,
596 [&](const FileEntry *FE) {
597 CI.getFrontendOpts().ModuleMapFiles.push_back(FE->getName());
598 });
599 }
600
601 // Set up the input file for replay purposes.
602 auto Kind = AST->getInputKind();
603 if (Kind.getFormat() == InputKind::ModuleMap) {
604 Module *ASTModule =
605 AST->getPreprocessor().getHeaderSearchInfo().lookupModule(
606 AST->getLangOpts().CurrentModule, /*AllowSearch*/ false);
607 assert(ASTModule && "module file does not define its own module");
608 Input = FrontendInputFile(ASTModule->PresumedModuleMapFile, Kind);
609 } else {
610 auto &OldSM = AST->getSourceManager();
611 FileID ID = OldSM.getMainFileID();
612 if (auto *File = OldSM.getFileEntryForID(ID))
613 Input = FrontendInputFile(File->getName(), Kind);
614 else
615 Input = FrontendInputFile(OldSM.getBuffer(ID), Kind);
616 }
617 setCurrentInput(Input, std::move(AST));
618 }
619
620 // AST files follow a very different path, since they share objects via the
621 // AST unit.
622 if (Input.getKind().getFormat() == InputKind::Precompiled) {
623 assert(!usesPreprocessorOnly() && "this case was handled above");
624 assert(hasASTFileSupport() &&
625 "This action does not have AST file support!");
626
627 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
628
629 // FIXME: What if the input is a memory buffer?
630 StringRef InputFile = Input.getFile();
631
632 std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
633 InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
634 CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs);
635
636 if (!AST)
637 goto failure;
638
639 // Inform the diagnostic client we are processing a source file.
640 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
641 HasBegunSourceFile = true;
642
643 // Set the shared objects, these are reset when we finish processing the
644 // file, otherwise the CompilerInstance will happily destroy them.
645 CI.setFileManager(&AST->getFileManager());
646 CI.setSourceManager(&AST->getSourceManager());
647 CI.setPreprocessor(AST->getPreprocessorPtr());
648 Preprocessor &PP = CI.getPreprocessor();
649 PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
650 PP.getLangOpts());
651 CI.setASTContext(&AST->getASTContext());
652
653 setCurrentInput(Input, std::move(AST));
654
655 // Initialize the action.
656 if (!BeginSourceFileAction(CI))
657 goto failure;
658
659 // Create the AST consumer.
660 CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
661 if (!CI.hasASTConsumer())
662 goto failure;
663
664 return true;
665 }
666
667 // Set up the file and source managers, if needed.
668 if (!CI.hasFileManager()) {
669 if (!CI.createFileManager()) {
670 goto failure;
671 }
672 }
673 if (!CI.hasSourceManager())
674 CI.createSourceManager(CI.getFileManager());
675
676 // Set up embedding for any specified files. Do this before we load any
677 // source files, including the primary module map for the compilation.
678 for (const auto &F : CI.getFrontendOpts().ModulesEmbedFiles) {
679 if (auto FE = CI.getFileManager().getFile(F, /*openFile*/true))
680 CI.getSourceManager().setFileIsTransient(*FE);
681 else
682 CI.getDiagnostics().Report(diag::err_modules_embed_file_not_found) << F;
683 }
684 if (CI.getFrontendOpts().ModulesEmbedAllFiles)
685 CI.getSourceManager().setAllFilesAreTransient(true);
686
687 // IR files bypass the rest of initialization.
688 if (Input.getKind().getLanguage() == Language::LLVM_IR) {
689 assert(hasIRSupport() &&
690 "This action does not have IR file support!");
691
692 // Inform the diagnostic client we are processing a source file.
693 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
694 HasBegunSourceFile = true;
695
696 // Initialize the action.
697 if (!BeginSourceFileAction(CI))
698 goto failure;
699
700 // Initialize the main file entry.
701 if (!CI.InitializeSourceManager(CurrentInput))
702 goto failure;
703
704 return true;
705 }
706
707 // If the implicit PCH include is actually a directory, rather than
708 // a single file, search for a suitable PCH file in that directory.
709 if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
710 FileManager &FileMgr = CI.getFileManager();
711 PreprocessorOptions &PPOpts = CI.getPreprocessorOpts();
712 StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
713 std::string SpecificModuleCachePath = CI.getSpecificModuleCachePath();
714 if (auto PCHDir = FileMgr.getDirectory(PCHInclude)) {
715 std::error_code EC;
716 SmallString<128> DirNative;
717 llvm::sys::path::native((*PCHDir)->getName(), DirNative);
718 bool Found = false;
719 llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
720 for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC),
721 DirEnd;
722 Dir != DirEnd && !EC; Dir.increment(EC)) {
723 // Check whether this is an acceptable AST file.
724 if (ASTReader::isAcceptableASTFile(
725 Dir->path(), FileMgr, CI.getPCHContainerReader(),
726 CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(),
727 SpecificModuleCachePath)) {
728 PPOpts.ImplicitPCHInclude = Dir->path();
729 Found = true;
730 break;
731 }
732 }
733
734 if (!Found) {
735 CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
736 goto failure;
737 }
738 }
739 }
740
741 // Set up the preprocessor if needed. When parsing model files the
742 // preprocessor of the original source is reused.
743 if (!isModelParsingAction())
744 CI.createPreprocessor(getTranslationUnitKind());
745
746 // Inform the diagnostic client we are processing a source file.
747 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
748 &CI.getPreprocessor());
749 HasBegunSourceFile = true;
750
751 // Initialize the main file entry.
752 if (!CI.InitializeSourceManager(Input))
753 goto failure;
754
755 // For module map files, we first parse the module map and synthesize a
756 // "<module-includes>" buffer before more conventional processing.
757 if (Input.getKind().getFormat() == InputKind::ModuleMap) {
758 CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleMap);
759
760 std::string PresumedModuleMapFile;
761 unsigned OffsetToContents;
762 if (loadModuleMapForModuleBuild(CI, Input.isSystem(),
763 Input.isPreprocessed(),
764 PresumedModuleMapFile, OffsetToContents))
765 goto failure;
766
767 auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());
768 if (!CurrentModule)
769 goto failure;
770
771 CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;
772
773 if (OffsetToContents)
774 // If the module contents are in the same file, skip to them.
775 CI.getPreprocessor().setSkipMainFilePreamble(OffsetToContents, true);
776 else {
777 // Otherwise, convert the module description to a suitable input buffer.
778 auto Buffer = getInputBufferForModule(CI, CurrentModule);
779 if (!Buffer)
780 goto failure;
781
782 // Reinitialize the main file entry to refer to the new input.
783 auto Kind = CurrentModule->IsSystem ? SrcMgr::C_System : SrcMgr::C_User;
784 auto &SourceMgr = CI.getSourceManager();
785 auto BufferID = SourceMgr.createFileID(std::move(Buffer), Kind);
786 assert(BufferID.isValid() && "couldn't creaate module buffer ID");
787 SourceMgr.setMainFileID(BufferID);
788 }
789 }
790
791 // Initialize the action.
792 if (!BeginSourceFileAction(CI))
793 goto failure;
794
795 // If we were asked to load any module map files, do so now.
796 for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
797 if (auto File = CI.getFileManager().getFile(Filename))
798 CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
799 *File, /*IsSystem*/false);
800 else
801 CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
802 }
803
804 // Add a module declaration scope so that modules from -fmodule-map-file
805 // arguments may shadow modules found implicitly in search paths.
806 CI.getPreprocessor()
807 .getHeaderSearchInfo()
808 .getModuleMap()
809 .finishModuleDeclarationScope();
810
811 // Create the AST context and consumer unless this is a preprocessor only
812 // action.
813 if (!usesPreprocessorOnly()) {
814 // Parsing a model file should reuse the existing ASTContext.
815 if (!isModelParsingAction())
816 CI.createASTContext();
817
818 // For preprocessed files, check if the first line specifies the original
819 // source file name with a linemarker.
820 std::string PresumedInputFile = getCurrentFileOrBufferName();
821 if (Input.isPreprocessed())
822 ReadOriginalFileName(CI, PresumedInputFile);
823
824 std::unique_ptr<ASTConsumer> Consumer =
825 CreateWrappedASTConsumer(CI, PresumedInputFile);
826 if (!Consumer)
827 goto failure;
828
829 // FIXME: should not overwrite ASTMutationListener when parsing model files?
830 if (!isModelParsingAction())
831 CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
832
833 if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
834 // Convert headers to PCH and chain them.
835 IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader;
836 source = createChainedIncludesSource(CI, FinalReader);
837 if (!source)
838 goto failure;
839 CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get()));
840 CI.getASTContext().setExternalSource(source);
841 } else if (CI.getLangOpts().Modules ||
842 !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
843 // Use PCM or PCH.
844 assert(hasPCHSupport() && "This action does not have PCH support!");
845 ASTDeserializationListener *DeserialListener =
846 Consumer->GetASTDeserializationListener();
847 bool DeleteDeserialListener = false;
848 if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) {
849 DeserialListener = new DeserializedDeclsDumper(DeserialListener,
850 DeleteDeserialListener);
851 DeleteDeserialListener = true;
852 }
853 if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) {
854 DeserialListener = new DeserializedDeclsChecker(
855 CI.getASTContext(),
856 CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn,
857 DeserialListener, DeleteDeserialListener);
858 DeleteDeserialListener = true;
859 }
860 if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
861 CI.createPCHExternalASTSource(
862 CI.getPreprocessorOpts().ImplicitPCHInclude,
863 CI.getPreprocessorOpts().DisablePCHValidation,
864 CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener,
865 DeleteDeserialListener);
866 if (!CI.getASTContext().getExternalSource())
867 goto failure;
868 }
869 // If modules are enabled, create the module manager before creating
870 // any builtins, so that all declarations know that they might be
871 // extended by an external source.
872 if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
873 !CI.getASTContext().getExternalSource()) {
874 CI.createASTReader();
875 CI.getASTReader()->setDeserializationListener(DeserialListener,
876 DeleteDeserialListener);
877 }
878 }
879
880 CI.setASTConsumer(std::move(Consumer));
881 if (!CI.hasASTConsumer())
882 goto failure;
883 }
884
885 // Initialize built-in info as long as we aren't using an external AST
886 // source.
887 if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
888 !CI.getASTContext().getExternalSource()) {
889 Preprocessor &PP = CI.getPreprocessor();
890 PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
891 PP.getLangOpts());
892 } else {
893 // FIXME: If this is a problem, recover from it by creating a multiplex
894 // source.
895 assert((!CI.getLangOpts().Modules || CI.getASTReader()) &&
896 "modules enabled but created an external source that "
897 "doesn't support modules");
898 }
899
900 // If we were asked to load any module files, do so now.
901 for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles)
902 if (!CI.loadModuleFile(ModuleFile))
903 goto failure;
904
905 // If there is a layout overrides file, attach an external AST source that
906 // provides the layouts from that file.
907 if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() &&
908 CI.hasASTContext() && !CI.getASTContext().getExternalSource()) {
909 IntrusiveRefCntPtr<ExternalASTSource>
910 Override(new LayoutOverrideSource(
911 CI.getFrontendOpts().OverrideRecordLayoutsFile));
912 CI.getASTContext().setExternalSource(Override);
913 }
914
915 return true;
916
917 // If we failed, reset state since the client will not end up calling the
918 // matching EndSourceFile().
919 failure:
920 if (HasBegunSourceFile)
921 CI.getDiagnosticClient().EndSourceFile();
922 CI.clearOutputFiles(/*EraseFiles=*/true);
923 CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
924 setCurrentInput(FrontendInputFile());
925 setCompilerInstance(nullptr);
926 return false;
927 }
928
929 llvm::Error FrontendAction::Execute() {
930 CompilerInstance &CI = getCompilerInstance();
931
932 if (CI.hasFrontendTimer()) {
933 llvm::TimeRegion Timer(CI.getFrontendTimer());
934 ExecuteAction();
935 }
936 else ExecuteAction();
937
938 // If we are supposed to rebuild the global module index, do so now unless
939 // there were any module-build failures.
940 if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
941 CI.hasPreprocessor()) {
942 StringRef Cache =
943 CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath();
944 if (!Cache.empty()) {
945 if (llvm::Error Err = GlobalModuleIndex::writeIndex(
946 CI.getFileManager(), CI.getPCHContainerReader(), Cache)) {
947 // FIXME this drops the error on the floor, but
948 // Index/pch-from-libclang.c seems to rely on dropping at least some of
949 // the error conditions!
950 consumeError(std::move(Err));
951 }
952 }
953 }
954
955 return llvm::Error::success();
956 }
957
958 void FrontendAction::EndSourceFile() {
959 CompilerInstance &CI = getCompilerInstance();
960
961 // Inform the diagnostic client we are done with this source file.
962 CI.getDiagnosticClient().EndSourceFile();
963
964 // Inform the preprocessor we are done.
965 if (CI.hasPreprocessor())
966 CI.getPreprocessor().EndSourceFile();
967
968 // Finalize the action.
969 EndSourceFileAction();
970
971 // Sema references the ast consumer, so reset sema first.
972 //
973 // FIXME: There is more per-file stuff we could just drop here?
974 bool DisableFree = CI.getFrontendOpts().DisableFree;
975 if (DisableFree) {
976 CI.resetAndLeakSema();
977 CI.resetAndLeakASTContext();
978 llvm::BuryPointer(CI.takeASTConsumer().get());
979 } else {
980 CI.setSema(nullptr);
981 CI.setASTContext(nullptr);
982 CI.setASTConsumer(nullptr);
983 }
984
985 if (CI.getFrontendOpts().ShowStats) {
986 llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";
987 CI.getPreprocessor().PrintStats();
988 CI.getPreprocessor().getIdentifierTable().PrintStats();
989 CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
990 CI.getSourceManager().PrintStats();
991 llvm::errs() << "\n";
992 }
993
994 // Cleanup the output streams, and erase the output files if instructed by the
995 // FrontendAction.
996 CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles());
997
998 if (isCurrentFileAST()) {
999 if (DisableFree) {
1000 CI.resetAndLeakPreprocessor();
1001 CI.resetAndLeakSourceManager();
1002 CI.resetAndLeakFileManager();
1003 llvm::BuryPointer(std::move(CurrentASTUnit));
1004 } else {
1005 CI.setPreprocessor(nullptr);
1006 CI.setSourceManager(nullptr);
1007 CI.setFileManager(nullptr);
1008 }
1009 }
1010
1011 setCompilerInstance(nullptr);
1012 setCurrentInput(FrontendInputFile());
1013 CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
1014 }
1015
1016 bool FrontendAction::shouldEraseOutputFiles() {
1017 return getCompilerInstance().getDiagnostics().hasErrorOccurred();
1018 }
1019
1020 //===----------------------------------------------------------------------===//
1021 // Utility Actions
1022 //===----------------------------------------------------------------------===//
1023
1024 void ASTFrontendAction::ExecuteAction() {
1025 CompilerInstance &CI = getCompilerInstance();
1026 if (!CI.hasPreprocessor())
1027 return;
1028
1029 // FIXME: Move the truncation aspect of this into Sema, we delayed this till
1030 // here so the source manager would be initialized.
1031 if (hasCodeCompletionSupport() &&
1032 !CI.getFrontendOpts().CodeCompletionAt.FileName.empty())
1033 CI.createCodeCompletionConsumer();
1034
1035 // Use a code completion consumer?
1036 CodeCompleteConsumer *CompletionConsumer = nullptr;
1037 if (CI.hasCodeCompletionConsumer())
1038 CompletionConsumer = &CI.getCodeCompletionConsumer();
1039
1040 if (!CI.hasSema())
1041 CI.createSema(getTranslationUnitKind(), CompletionConsumer);
1042
1043 ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats,
1044 CI.getFrontendOpts().SkipFunctionBodies);
1045 }
1046
1047 void PluginASTAction::anchor() { }
1048
1049 std::unique_ptr<ASTConsumer>
1050 PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI,
1051 StringRef InFile) {
1052 llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
1053 }
1054
1055 bool WrapperFrontendAction::PrepareToExecuteAction(CompilerInstance &CI) {
1056 return WrappedAction->PrepareToExecuteAction(CI);
1057 }
1058 std::unique_ptr<ASTConsumer>
1059 WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI,
1060 StringRef InFile) {
1061 return WrappedAction->CreateASTConsumer(CI, InFile);
1062 }
1063 bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) {
1064 return WrappedAction->BeginInvocation(CI);
1065 }
1066 bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI) {
1067 WrappedAction->setCurrentInput(getCurrentInput());
1068 WrappedAction->setCompilerInstance(&CI);
1069 auto Ret = WrappedAction->BeginSourceFileAction(CI);
1070 // BeginSourceFileAction may change CurrentInput, e.g. during module builds.
1071 setCurrentInput(WrappedAction->getCurrentInput());
1072 return Ret;
1073 }
1074 void WrapperFrontendAction::ExecuteAction() {
1075 WrappedAction->ExecuteAction();
1076 }
1077 void WrapperFrontendAction::EndSourceFileAction() {
1078 WrappedAction->EndSourceFileAction();
1079 }
1080
1081 bool WrapperFrontendAction::usesPreprocessorOnly() const {
1082 return WrappedAction->usesPreprocessorOnly();
1083 }
1084 TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() {
1085 return WrappedAction->getTranslationUnitKind();
1086 }
1087 bool WrapperFrontendAction::hasPCHSupport() const {
1088 return WrappedAction->hasPCHSupport();
1089 }
1090 bool WrapperFrontendAction::hasASTFileSupport() const {
1091 return WrappedAction->hasASTFileSupport();
1092 }
1093 bool WrapperFrontendAction::hasIRSupport() const {
1094 return WrappedAction->hasIRSupport();
1095 }
1096 bool WrapperFrontendAction::hasCodeCompletionSupport() const {
1097 return WrappedAction->hasCodeCompletionSupport();
1098 }
1099
1100 WrapperFrontendAction::WrapperFrontendAction(
1101 std::unique_ptr<FrontendAction> WrappedAction)
1102 : WrappedAction(std::move(WrappedAction)) {}
1103
clang::ASTContext::setExternalSource
void setExternalSource(IntrusiveRefCntPtr< ExternalASTSource > Source)
Attach an external AST source to the AST context.
Definition: ASTContext.cpp:1096
clang::Builtin::ID
ID
Definition: Builtins.h:46
ASTContext.h
Defines the clang::ASTContext interface.
clang::ASTReader::isAcceptableASTFile
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, StringRef ExistingModuleCachePath)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
Definition: ASTReader.cpp:5376
clang::Lexer::getSpelling
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer...
Definition: Lexer.cpp:397
clang::ModuleMap::setInferredModuleAllowedBy
void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap)
Definition: ModuleMap.cpp:1240
clang::CompilerInstance::getLangOpts
LangOptions & getLangOpts()
Definition: CompilerInstance.h:302
clang::CompilerInstance::resetAndLeakFileManager
void resetAndLeakFileManager()
Definition: CompilerInstance.h:409
clang::FrontendOptions::OriginalModuleMap
std::string OriginalModuleMap
When the input is a module map, the original module map file from which that map was inferred...
Definition: FrontendOptions.h:376
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:77
clang::CompilerInstance::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts()
Definition: CompilerInstance.h:309
clang::CompilerInstance::createCodeCompletionConsumer
void createCodeCompletionConsumer()
Create a code completion consumer using the invocation; note that this will cause the source manager ...
Definition: CompilerInstance.cpp:583
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:76
clang::DiagnosticsEngine::hasErrorOccurred
bool hasErrorOccurred() const
Definition: Diagnostic.h:753
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:685
clang::Module::MissingHeaders
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system...
Definition: Module.h:194
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:654
clang::Decl::getDeclKindName
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
clang::CompilerInstance::createFileManager
FileManager * createFileManager(IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Create the file manager and replace any existing one with it.
Definition: CompilerInstance.cpp:310
clang::Module::submodule_iterator
std::vector< Module * >::iterator submodule_iterator
Definition: Module.h:560
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:171
ASTDeserializationListener.h
clang::createChainedIncludesSource
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
The ChainedIncludesSource class converts headers to chained PCHs in memory, mainly for testing...
Definition: ChainedIncludesSource.cpp:113
clang::IdentifierTable::PrintStats
void PrintStats() const
Print some statistics to stderr that indicate how well the hashing is doing.
Definition: IdentifierTable.cpp:321
clang::FrontendAction::EndSourceFile
void EndSourceFile()
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
Definition: FrontendAction.cpp:958
clang::Module::submodule_begin
submodule_iterator submodule_begin()
Definition: Module.h:563
Cache
TypePropertyCache< Private > Cache
Definition: Type.cpp:3625
clang::FrontendAction::hasIRSupport
virtual bool hasIRSupport() const
Does this action support use with IR files?
Definition: FrontendAction.h:197
clang::ASTFrontendAction::ExecuteAction
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Definition: FrontendAction.cpp:1024
clang::InputKind::getFormat
Format getFormat() const
Definition: FrontendOptions.h:163
clang::Module::IsExternC
unsigned IsExternC
Whether this is an &#39;extern "C"&#39; module (which implicitly puts all headers in it within an &#39;extern "C"...
Definition: Module.h:237
clang::CompilerInstance::createSema
void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)
Create the Sema object to be used for parsing.
Definition: CompilerInstance.cpp:622
clang::ASTUnit::LoadEverything
Load everything, including Sema.
Definition: ASTUnit.h:678
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
clang::Preprocessor::EndSourceFile
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
Definition: Preprocessor.cpp:687
P
StringRef P
Definition: ASTMatchersInternal.cpp:485
clang::FrontendAction::usesPreprocessorOnly
virtual bool usesPreprocessorOnly() const =0
Does this action only use the preprocessor?
clang::PreprocessorFrontendAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Provide a default implementation which returns aborts; this method should never be called by Frontend...
Definition: FrontendAction.cpp:1050
clang::FrontendAction::hasASTFileSupport
virtual bool hasASTFileSupport() const
Does this action support use with AST files?
Definition: FrontendAction.h:194
FrontendPluginRegistry.h
clang::ASTContext::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: ASTContext.cpp:1516
ASTReader.h
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1300
clang::CompilerInstance::InitializeSourceManager
bool InitializeSourceManager(const FrontendInputFile &Input)
InitializeSourceManager - Initialize the source manager to set InputFile as the main file...
Definition: CompilerInstance.cpp:813
HeaderSearch.h
LiteralSupport.h
clang::ASTDeserializationListener::IdentifierRead
virtual void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II)
An identifier was deserialized from the AST file.
Definition: ASTDeserializationListener.h:38
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:45
clang::CompilerInstance::getASTContext
ASTContext & getASTContext() const
Definition: CompilerInstance.h:464
clang::CompilerInstance::setModuleManager
void setModuleManager(IntrusiveRefCntPtr< ASTReader > Reader)
Definition: CompilerInstance.cpp:141
ReadOriginalFileName
static SourceLocation ReadOriginalFileName(CompilerInstance &CI, std::string &InputFile, bool IsModuleMap=false)
For preprocessed files, if the first line is the linemarker and specifies the original source file na...
Definition: FrontendAction.cpp:232
clang::CompilerInstance::setSourceManager
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
Definition: CompilerInstance.cpp:104
clang::DiagnosticConsumer::EndSourceFile
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1531
clang::SrcMgr::C_System
Definition: SourceManager.h:78
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:652
clang::Preprocessor::getBuiltinInfo
Builtin::Context & getBuiltinInfo()
Definition: Preprocessor.h:917
clang::FrontendAction::hasCodeCompletionSupport
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
Definition: FrontendAction.h:200
clang::CompilerInstance::getASTReader
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Definition: CompilerInstance.cpp:138
clang::Module::PresumedModuleMapFile
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition: Module.h:101
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:57
clang::Preprocessor::PrintStats
void PrintStats()
Definition: Preprocessor.cpp:270
clang::FrontendInputFile::isEmpty
bool isEmpty() const
Definition: FrontendOptions.h:210
clang::Module::getModuleInputBufferName
static StringRef getModuleInputBufferName()
Definition: Module.h:581
clang::ASTDeserializationListener::ReaderInitialized
virtual void ReaderInitialized(ASTReader *Reader)
The ASTReader was initialized.
Definition: ASTDeserializationListener.h:35
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:168
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:148
clang::WrapperFrontendAction::usesPreprocessorOnly
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
Definition: FrontendAction.cpp:1081
clang::FrontendAction::BeginSourceFile
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)
Prepare the action for processing the input file Input.
Definition: FrontendAction.cpp:538
clang::CompilerInstance::createSourceManager
void createSourceManager(FileManager &FileMgr)
Create the source manager and replace any existing one with it.
Definition: CompilerInstance.cpp:323
clang::GlobalModuleIndex::writeIndex
static llvm::Error writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, llvm::StringRef Path)
Write a global index into the given.
Definition: GlobalModuleIndex.cpp:853
clang::ModuleMap::resolveHeaderDirectives
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
Definition: ModuleMap.cpp:1159
std
Definition: Format.h:2445
clang::FrontendAction::getCurrentModule
Module * getCurrentModule() const
Definition: FrontendAction.cpp:143
clang::WrapperFrontendAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendAction.cpp:1059
clang::Module::getUmbrellaHeader
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:489
clang::ModuleMap::isHeaderUnavailableInModule
bool isHeaderUnavailableInModule(const FileEntry *Header, const Module *RequestingModule) const
Determine whether the given header is unavailable as part of the specified module.
Definition: ModuleMap.cpp:675
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::CompilerInstance::setASTContext
void setASTContext(ASTContext *Value)
setASTContext - Replace the current AST context.
Definition: CompilerInstance.cpp:112
clang::CompilerInstance::getCodeGenOpts
CodeGenOptions & getCodeGenOpts()
Definition: CompilerInstance.h:257
clang::ModuleMap::finishModuleDeclarationScope
void finishModuleDeclarationScope()
Creates a new declaration scope for module names, allowing previously defined modules to shadow defin...
Definition: ModuleMap.h:567
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:53
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:907
clang::LangOptions::CMK_ModuleMap
Compiling a module from a module map.
Definition: LangOptions.h:82
clang::FrontendOptions::ModulesEmbedFiles
std::vector< std::string > ModulesEmbedFiles
The list of files to embed into the compiled module file.
Definition: FrontendOptions.h:416
clang::Module
Describes a module or submodule.
Definition: Module.h:64
llvm::SmallVectorImpl< char >
clang::PluginASTAction::AddBeforeMainAction
Execute the action before the main action.
Definition: FrontendAction.h:275
clang::FrontendAction::getCompilerInstance
CompilerInstance & getCompilerInstance() const
Definition: FrontendAction.h:119
clang::WrapperFrontendAction::hasPCHSupport
bool hasPCHSupport() const override
Does this action support use with PCH?
Definition: FrontendAction.cpp:1087
clang::FileManager::getDirectory
llvm::ErrorOr< const DirectoryEntry * > getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
Definition: FileManager.cpp:187
clang::PluginASTAction::Cmdline
Action is determined by the cc1 command-line.
Definition: FrontendAction.h:273
clang::FrontendOptions::ShowStats
unsigned ShowStats
Show frontend performance metrics and statistics.
Definition: FrontendOptions.h:240
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:213
clang::SourceManager::getModuleBuildStack
ModuleBuildStack getModuleBuildStack() const
Retrieve the module build stack.
Definition: SourceManager.h:787
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:912
clang::CompilerInstance::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInstance.h:285
clang::ASTUnit::LoadFromASTFile
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, ArrayRef< RemappedFile > RemappedFiles=None, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowPCHWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
Definition: ASTUnit.cpp:756
clang::ASTReader::getModuleManager
ModuleManager & getModuleManager()
Retrieve the module manager.
Definition: ASTReader.h:1655
clang::FrontendAction::getCurrentFileOrBufferName
StringRef getCurrentFileOrBufferName() const
Definition: FrontendAction.h:144
clang::ASTUnit::LoadPreprocessorOnly
Load options and the preprocessor state.
Definition: ASTUnit.h:672
clang::CompilerInstance::hasFrontendTimer
bool hasFrontendTimer() const
Definition: CompilerInstance.h:576
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
clang::FrontendAction::~FrontendAction
virtual ~FrontendAction()
Definition: FrontendAction.cpp:135
clang::Module::Parent
Module * Parent
The parent of this module.
Definition: Module.h:92
clang::Module::IsInferred
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition: Module.h:240
prepareToBuildModule
static Module * prepareToBuildModule(CompilerInstance &CI, StringRef ModuleMapFilename)
Definition: FrontendAction.cpp:448
clang::CompilerInstance::setASTConsumer
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value...
Definition: CompilerInstance.cpp:123
clang::FrontendOptions::SkipFunctionBodies
unsigned SkipFunctionBodies
Skip over function bodies to speed up parsing in cases you do not need them (e.g. ...
Definition: FrontendOptions.h:271
clang::HeaderSearch::loadModuleMapFile
bool loadModuleMapFile(const FileEntry *File, bool IsSystem, FileID ID=FileID(), unsigned *Offset=nullptr, StringRef OriginalModuleMapFile=StringRef())
Read the contents of the given module map file.
Definition: HeaderSearch.cpp:1475
clang::Module::submodule_end
submodule_iterator submodule_end()
Definition: Module.h:565
clang::FrontendAction::BeginInvocation
virtual bool BeginInvocation(CompilerInstance &CI)
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: FrontendAction.h:79
Utils.h
clang::CompilerInstance::hasASTConsumer
bool hasASTConsumer() const
Definition: CompilerInstance.h:485
clang::FrontendInputFile::getKind
InputKind getKind() const
Definition: FrontendOptions.h:207
clang::CompilerInstance::setFileManager
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
Definition: CompilerInstance.cpp:100
clang::WrapperFrontendAction::BeginInvocation
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: FrontendAction.cpp:1063
clang::CompilerInstance::getHeaderSearchOpts
HeaderSearchOptions & getHeaderSearchOpts()
Definition: CompilerInstance.h:292
llvm::SmallString< 16 >
clang::PreprocessorOptions::DisablePCHValidation
bool DisablePCHValidation
When true, disables most of the normal validation performed on precompiled headers.
Definition: PreprocessorOptions.h:84
clang::CompilerInstance::getCodeCompletionConsumer
CodeCompleteConsumer & getCodeCompletionConsumer() const
Definition: CompilerInstance.h:562
FrontendDiagnostic.h
loadModuleMapForModuleBuild
static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem, bool IsPreprocessed, std::string &PresumedModuleMapFile, unsigned &Offset)
Definition: FrontendAction.cpp:416
clang::ASTDeserializationListener::SelectorRead
virtual void SelectorRead(serialization::SelectorID iD, Selector Sel)
A selector was read from the AST file.
Definition: ASTDeserializationListener.h:49
clang::CompilerInstance::createPCHExternalASTSource
void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)
Create an external AST source to read a PCH file and attach it to the AST context.
Definition: CompilerInstance.cpp:493
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:158
clang::SourceManager::initializeForReplay
void initializeForReplay(const SourceManager &Old)
Initialize this source manager suitably to replay the compilation described by Old.
Definition: SourceManager.cpp:392
clang::CompilerInstance::getSema
Sema & getSema() const
Definition: CompilerInstance.h:505
clang::Module::HK_Private
Definition: Module.h:149
clang::HeaderSearch::getModuleCachePath
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:328
clang::ASTDeserializationListener::DeclRead
virtual void DeclRead(serialization::DeclID ID, const Decl *D)
A decl was deserialized from the AST file.
Definition: ASTDeserializationListener.h:47
clang::FrontendPluginRegistry
llvm::Registry< PluginASTAction > FrontendPluginRegistry
The frontend plugin registry.
Definition: FrontendPluginRegistry.h:22
clang::FrontendAction::FrontendAction
FrontendAction()
Definition: FrontendAction.cpp:133
CompilerInstance.h
clang::WrapperFrontendAction::hasCodeCompletionSupport
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
Definition: FrontendAction.cpp:1096
clang::LangOptions::CurrentModule
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:277
Filename
StringRef Filename
Definition: Format.cpp:1825
clang::FrontendAction::shouldEraseOutputFiles
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
Definition: FrontendAction.cpp:1016
clang::PreprocessorOptions::ChainedIncludes
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
Definition: PreprocessorOptions.h:80
clang::CompilerInstance::resetAndLeakPreprocessor
void resetAndLeakPreprocessor()
Definition: CompilerInstance.h:451
clang::FrontendAction::setCurrentInput
void setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
Definition: FrontendAction.cpp:137
clang::ModuleMap
Definition: ModuleMap.h:75
clang::SourceManager::setFileIsTransient
void setFileIsTransient(const FileEntry *SourceFile)
Specify that a file is transient.
Definition: SourceManager.cpp:697
Offset
unsigned Offset
Definition: Format.cpp:1827
clang::WrapperFrontendAction::hasIRSupport
bool hasIRSupport() const override
Does this action support use with IR files?
Definition: FrontendAction.cpp:1093
End
SourceLocation End
Definition: USRLocFinder.cpp:166
clang::CompilerInstance::getSpecificModuleCachePath
std::string getSpecificModuleCachePath()
Definition: CompilerInstance.cpp:470
clang::WrapperFrontendAction::WrapperFrontendAction
WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)
Construct a WrapperFrontendAction from an existing action, taking ownership of it.
Definition: FrontendAction.cpp:1100
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1015
Previous
StateNode * Previous
Definition: UnwrappedLineFormatter.cpp:934
clang::SourceManager::createFileID
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
Definition: SourceManager.h:831
clang::FrontendInputFile::getFile
StringRef getFile() const
Definition: FrontendOptions.h:215
clang::PreprocessorOptions::DeserializedPCHDeclsToErrorOn
std::set< std::string > DeserializedPCHDeclsToErrorOn
This is a set of names for decls that we do not want to be deserialized, and we emit an error if they...
Definition: PreprocessorOptions.h:94
LangStandard.h
clang::CompilerInstance::hasFileManager
bool hasFileManager() const
Definition: CompilerInstance.h:401
clang::WrapperFrontendAction::BeginSourceFileAction
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
Definition: FrontendAction.cpp:1066
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:126
Preprocessor.h
Defines the clang::Preprocessor interface.
clang::LangOptions::CMK_None
Not compiling a module interface at all.
Definition: LangOptions.h:79
clang::CompilerInstance::createASTContext
void createASTContext()
Create the AST context.
Definition: CompilerInstance.cpp:482
clang::FrontendAction::EndSourceFileAction
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
Definition: FrontendAction.h:100
clang::WrapperFrontendAction::getTranslationUnitKind
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we&#39;re handling.
Definition: FrontendAction.cpp:1084
clang::Preprocessor::checkModuleIsAvailable
static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M)
Check that the given module is available, producing a diagnostic if not.
Definition: PPDirectives.cpp:1644
clang::serialization::ModuleFile
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:107
clang::FrontendOptions::ModulesEmbedAllFiles
unsigned ModulesEmbedAllFiles
Whether we should embed all used files into the PCM file.
Definition: FrontendOptions.h:292
clang::CompilerInstance::setSema
void setSema(Sema *S)
Replace the current Sema; the compiler instance takes ownership of S.
Definition: CompilerInstance.cpp:119
clang::DiagnosticLevelMask::Error
clang::WrapperFrontendAction::PrepareToExecuteAction
bool PrepareToExecuteAction(CompilerInstance &CI) override
Prepare to execute the action on the given CompilerInstance.
Definition: FrontendAction.cpp:1055
clang::FrontendInputFile
An input file for the front end.
Definition: FrontendOptions.h:184
clang::FrontendAction::CreateASTConsumer
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile)=0
Create the AST consumer object for this action, if supported.
clang::Module::isAvailable
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
Definition: Module.h:385
ASTConsumer.h
clang::Module::Header
Information about a header directive as found in the module map file.
Definition: Module.h:157
clang::PluginASTAction::ActionType
ActionType
Definition: FrontendAction.h:272
clang::FrontendAction::ExecuteAction
virtual void ExecuteAction()=0
Callback to run the program action, using the initialized compiler instance.
clang::WrapperFrontendAction::EndSourceFileAction
void EndSourceFileAction() override
Callback at the end of processing a single input.
Definition: FrontendAction.cpp:1077
clang::ASTDeserializationListener
Definition: ASTDeserializationListener.h:30
clang::PreprocessorOptions::AllowPCHWithCompilerErrors
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
Definition: PreprocessorOptions.h:87
clang::Module::Directory
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:97
clang::CompilerInstance::resetAndLeakSema
void resetAndLeakSema()
Definition: CompilerInstance.cpp:2189
clang::FrontendAction::hasPCHSupport
virtual bool hasPCHSupport() const
Does this action support use with PCH?
Definition: FrontendAction.h:191
clang::CompilerInstance::getFileSystemOpts
FileSystemOptions & getFileSystemOpts()
Definition: CompilerInstance.h:278
clang::CompilerInstance::hasPreprocessor
bool hasPreprocessor() const
Definition: CompilerInstance.h:441
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::HeaderSearch::PrintStats
void PrintStats()
Definition: HeaderSearch.cpp:89
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:44
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::CompilerInstance::resetAndLeakSourceManager
void resetAndLeakSourceManager()
Definition: CompilerInstance.h:429
clang::FileEntry::getName
StringRef getName() const
Definition: FileManager.h:102
clang::FrontendOptions::ModuleFiles
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input. ...
Definition: FrontendOptions.h:413
clang::FrontendOptions::CodeCompletionAt
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
Definition: FrontendOptions.h:388
PreprocessorOptions.h
clang::FrontendAction::getTranslationUnitKind
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we&#39;re handling.
Definition: FrontendAction.h:188
clang::PreprocessorOptions::ImplicitPCHInclude
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
Definition: PreprocessorOptions.h:77
clang::ASTDeserializationListener::MacroDefinitionRead
virtual void MacroDefinitionRead(serialization::PreprocessedEntityID, MacroDefinitionRecord *MD)
A macro definition was read from the AST file.
Definition: ASTDeserializationListener.h:51
Ret
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
clang::WrapperFrontendAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendAction.cpp:1074
clang::Module::DirectoryName
Information about a directory name as found in the module map file.
Definition: Module.h:166
clang::Preprocessor::getIdentifierTable
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:914
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:78
clang::Module::Headers
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:174
clang::CompilerInstance::createASTReader
void createASTReader()
Definition: CompilerInstance.cpp:1481
clang::InputKind::Precompiled
Definition: FrontendOptions.h:155
clang::ParseAST
void ParseAST(Preprocessor &pp, ASTConsumer *C, ASTContext &Ctx, bool PrintStats=false, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr, bool SkipFunctionBodies=false)
Parse the entire file specified, notifying the ASTConsumer as the file is parsed. ...
Definition: ParseAST.cpp:99
collectModuleHeaderIncludes
static std::error_code collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, DiagnosticsEngine &Diag, ModuleMap &ModMap, clang::Module *Module, SmallVectorImpl< char > &Includes)
Collect the set of header includes needed to construct the given module and update the TopHeaders fil...
Definition: FrontendAction.cpp:318
GlobalModuleIndex.h
clang::Builtin::Context::initializeBuiltins
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
Definition: Builtins.cpp:89
clang::ParsedSourceLocation::FileName
std::string FileName
Definition: CommandLineSourceLoc.h:25
clang::CompilerInstance::hasSourceManager
bool hasSourceManager() const
Definition: CompilerInstance.h:421
clang::FrontendOptions::PluginArgs
std::unordered_map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
Definition: FrontendOptions.h:397
clang::Token::isAtStartOfLine
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:268
clang::PluginASTAction::AddAfterMainAction
Execute the action after the main action.
Definition: FrontendAction.h:276
llvm::SmallVector< StringRef, 16 >
clang::DiagnosticsEngine::getCustomDiagID
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:782
clang::SourceManager::pushModuleBuildStack
void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)
Push an entry to the module build stack.
Definition: SourceManager.h:798
clang::CompilerInstance::createPreprocessor
void createPreprocessor(TranslationUnitKind TUKind)
Create the preprocessor, using the invocation, file, and source managers, and replace any existing on...
Definition: CompilerInstance.cpp:379
clang::ASTDeserializationListener::TypeRead
virtual void TypeRead(serialization::TypeIdx Idx, QualType T)
A type was deserialized from the AST file.
Definition: ASTDeserializationListener.h:45
clang::CompilerInstance::shouldBuildGlobalModuleIndex
bool shouldBuildGlobalModuleIndex() const
Indicates whether we should (re)build the global module index.
Definition: CompilerInstance.cpp:76
clang::serialization::PreprocessedEntityID
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:168
clang::FrontendOptions::OverrideRecordLayoutsFile
std::string OverrideRecordLayoutsFile
File name of the file that will provide record layouts (in the format produced by -fdump-record-layou...
Definition: FrontendOptions.h:427
ParseAST.h
clang::CodeCompleteConsumer
Abstract interface for a consumer of code-completion information.
Definition: CodeCompleteConsumer.h:1000
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
clang::FrontendInputFile::isPreprocessed
bool isPreprocessed() const
Definition: FrontendOptions.h:213
clang::serialization::SelectorID
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:153
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:106
clang::CompilerInstance::setPreprocessor
void setPreprocessor(std::shared_ptr< Preprocessor > Value)
Replace the current preprocessor.
Definition: CompilerInstance.cpp:108
clang::InputKind::ModuleMap
Definition: FrontendOptions.h:154
clang::CompilerInstance::getFileManager
FileManager & getFileManager() const
Return the current file manager to the caller.
Definition: CompilerInstance.h:404
clang::CompilerInstance::getFrontendTimer
llvm::Timer & getFrontendTimer() const
Definition: CompilerInstance.h:578
clang::FrontendAction::getCurrentInput
const FrontendInputFile & getCurrentInput() const
Definition: FrontendAction.h:135
clang::InputKind::getLanguage
Language getLanguage() const
Definition: FrontendOptions.h:162
clang::FrontendAction::Execute
llvm::Error Execute()
Set the source manager&#39;s main input file, and run the action.
Definition: FrontendAction.cpp:929
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:340
clang::serialization::ModuleManager::getPrimaryModule
ModuleFile & getPrimaryModule()
Returns the primary module associated with the manager, that is, the first module loaded...
Definition: ModuleManager.h:173
clang::SrcMgr::C_User
Definition: SourceManager.h:78
LayoutOverrideSource.h
clang::SourceManager::PrintStats
void PrintStats() const
Print statistics to stderr.
Definition: SourceManager.cpp:2044
clang::SourceManager::getMainFileID
FileID getMainFileID() const
Returns the FileID of the main source file.
Definition: SourceManager.h:807
clang::FrontendAction::getCurrentFile
StringRef getCurrentFile() const
Definition: FrontendAction.h:139
clang::CompilerInstance::loadModuleFile
bool loadModuleFile(StringRef FileName)
Definition: CompilerInstance.cpp:1529
clang::ASTContext::setASTMutationListener
void setASTMutationListener(ASTMutationListener *Listener)
Attach an AST mutation listener to the AST context.
Definition: ASTContext.h:1095
clang::SourceManager::AddLineNote
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
Definition: SourceManager.cpp:310
clang::CompilerInstance::getSourceManager
SourceManager & getSourceManager() const
Return the current source manager.
Definition: CompilerInstance.h:424
clang::SrcMgr::C_User_ModuleMap
Definition: SourceManager.h:78
clang::Module::addTopHeader
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
Definition: Module.h:502
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1086
clang::serialization::DeclID
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:68
clang::CompilerInstance::clearOutputFiles
void clearOutputFiles(bool EraseFiles)
clearOutputFiles - Clear the output file list.
Definition: CompilerInstance.cpp:639
ASTUnit.h
clang::FileManager::getFile
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:195
clang::comments::tok::eof
Definition: CommentLexer.h:33
clang::DiagnosticsEngine::Error
Definition: Diagnostic.h:157
clang::CompilerInstance::getTarget
TargetInfo & getTarget() const
Definition: CompilerInstance.h:372
clang::serialization::IdentID
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:134
clang::WrapperFrontendAction::hasASTFileSupport
bool hasASTFileSupport() const override
Does this action support use with AST files?
Definition: FrontendAction.cpp:1090
clang::ASTReader::visitTopLevelModuleMaps
void visitTopLevelModuleMaps(serialization::ModuleFile &MF, llvm::function_ref< void(const FileEntry *)> Visitor)
Visit all the top-level module maps loaded when building the given module file.
Definition: ASTReader.cpp:9044
clang::FrontendAction::setCompilerInstance
void setCompilerInstance(CompilerInstance *Value)
Definition: FrontendAction.h:124
clang::HeaderSearch::lookupModule
Module * lookupModule(StringRef ModuleName, bool AllowSearch=true, bool AllowExtraModuleMapSearch=false)
Lookup a module Search for a module with the given name.
Definition: HeaderSearch.cpp:206
clang::FrontendInputFile::isSystem
bool isSystem() const
Definition: FrontendOptions.h:208
clang::Module::getUmbrellaDir
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:238
clang::FrontendOptions::AddPluginActions
std::vector< std::string > AddPluginActions
The list of plugin actions to run in addition to the normal action.
Definition: FrontendOptions.h:400
MultiplexConsumer.h
clang::CompilerInstance::hasASTContext
bool hasASTContext() const
Definition: CompilerInstance.h:462
clang::Module::HK_Normal
Definition: Module.h:147
clang::FrontendOptions::DisableFree
unsigned DisableFree
Disable memory freeing on exit.
Definition: FrontendOptions.h:230
clang::TypePropertyCache
The type-property cache.
Definition: Type.cpp:3579
clang::CompilerInstance::getPreprocessor
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Definition: CompilerInstance.h:444
clang::CompilerInstance::hasCodeCompletionConsumer
bool hasCodeCompletionConsumer() const
Definition: CompilerInstance.h:560
clang::CompilerInstance::getDiagnosticClient
DiagnosticConsumer & getDiagnosticClient() const
Definition: CompilerInstance.h:345
clang::LayoutOverrideSource
An external AST source that overrides the layout of a specified set of record types.
Definition: LayoutOverrideSource.h:24
clang::CompilerInstance::resetAndLeakASTContext
void resetAndLeakASTContext()
Definition: CompilerInstance.h:469
clang::FrontendAction::BeginSourceFileAction
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
Definition: FrontendAction.h:85
clang::Preprocessor::setMainFileDir
void setMainFileDir(const DirectoryEntry *Dir)
Set the directory in which the main file should be considered to have been found, if it is not a real...
Definition: Preprocessor.h:1642
DeclGroup.h
clang::AttrSyntax::C
clang::TranslationUnitKind
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:412
clang::StringLiteralParser
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
Definition: LiteralSupport.h:205
clang::CompilerInstance::getPCHContainerReader
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
Definition: CompilerInstance.h:544
clang::FullSourceLoc
A SourceLocation and its associated SourceManager.
Definition: SourceLocation.h:361
clang::CompilerInstance::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Definition: CompilerInstance.h:337
clang::FrontendAction::isCurrentFileAST
bool isCurrentFileAST() const
Definition: FrontendAction.h:130
clang::Language::LLVM_IR
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
FrontendAction.h
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
clang::CompilerInstance::takeASTConsumer
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
Definition: CompilerInstance.h:494
getInputBufferForModule
static std::unique_ptr< llvm::MemoryBuffer > getInputBufferForModule(CompilerInstance &CI, Module *M)
Compute the input buffer that should be used to build the specified module.
Definition: FrontendAction.cpp:514
clang::SourceManager::setAllFilesAreTransient
void setAllFilesAreTransient(bool Transient)
Specify that all files that are read during this compilation are transient.
Definition: SourceManager.h:972
clang::Preprocessor::setSkipMainFilePreamble
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
Definition: Preprocessor.h:1652
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
clang::PreprocessorOptions::DumpDeserializedPCHDecls
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
Definition: PreprocessorOptions.h:90
clang::DiagnosticConsumer::BeginSourceFile
virtual void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: Diagnostic.h:1523
operator+=
static SmallVectorImpl< char > & operator+=(SmallVectorImpl< char > &Includes, StringRef RHS)
Definition: FrontendAction.cpp:288
clang::CompilerInstance::getTargetOpts
TargetOptions & getTargetOpts()
Definition: CompilerInstance.h:323
clang::ASTContext::getFullLoc
FullSourceLoc getFullLoc(SourceLocation Loc) const
Definition: ASTContext.h:736
clang::FileManager::getVirtualFileSystem
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:355
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:596
addHeaderInclude
static void addHeaderInclude(StringRef HeaderName, SmallVectorImpl< char > &Includes, const LangOptions &LangOpts, bool IsExternC)
Definition: FrontendAction.cpp:293
Builtins.h
Defines enum values for all the target-independent builtin functions.
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:140
clang::serialization::TypeIdx
A type index; the type ID with the qualifier bits removed.
Definition: ASTBitCodes.h:88
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:429
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1238
clang::CompilerInstance::hasSema
bool hasSema() const
Definition: CompilerInstance.h:503
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128
clang::FrontendAction::isModelParsingAction
virtual bool isModelParsingAction() const
Is this action invoked on a model file?
Definition: FrontendAction.h:179
clang::FrontendOptions::ModuleMapFiles
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.
Definition: FrontendOptions.h:409