clang 8.0.0

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