clang 8.0.0

FrontendActions.cpp
Go to the documentation of this file.
1 //===--- FrontendActions.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/FrontendActions.h"
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/Basic/FileManager.h"
13 #include "clang/Frontend/ASTConsumers.h"
14 #include "clang/Frontend/CompilerInstance.h"
15 #include "clang/Frontend/FrontendDiagnostic.h"
16 #include "clang/Frontend/MultiplexConsumer.h"
17 #include "clang/Frontend/Utils.h"
18 #include "clang/Lex/HeaderSearch.h"
19 #include "clang/Lex/Preprocessor.h"
20 #include "clang/Lex/PreprocessorOptions.h"
21 #include "clang/Sema/TemplateInstCallback.h"
22 #include "clang/Serialization/ASTReader.h"
23 #include "clang/Serialization/ASTWriter.h"
24 #include "llvm/Support/FileSystem.h"
25 #include "llvm/Support/MemoryBuffer.h"
26 #include "llvm/Support/Path.h"
27 #include "llvm/Support/raw_ostream.h"
28 #include "llvm/Support/YAMLTraits.h"
29 #include <memory>
30 #include <system_error>
31
32 using namespace clang;
33
34 namespace {
35 CodeCompleteConsumer *GetCodeCompletionConsumer(CompilerInstance &CI) {
36 return CI.hasCodeCompletionConsumer() ? &CI.getCodeCompletionConsumer()
37 : nullptr;
38 }
39
40 void EnsureSemaIsCreated(CompilerInstance &CI, FrontendAction &Action) {
41 if (Action.hasCodeCompletionSupport() &&
42 !CI.getFrontendOpts().CodeCompletionAt.FileName.empty())
43 CI.createCodeCompletionConsumer();
44
45 if (!CI.hasSema())
46 CI.createSema(Action.getTranslationUnitKind(),
47 GetCodeCompletionConsumer(CI));
48 }
49 } // namespace
50
51 //===----------------------------------------------------------------------===//
52 // Custom Actions
53 //===----------------------------------------------------------------------===//
54
55 std::unique_ptr<ASTConsumer>
56 InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
57 return llvm::make_unique<ASTConsumer>();
58 }
59
60 void InitOnlyAction::ExecuteAction() {
61 }
62
63 //===----------------------------------------------------------------------===//
64 // AST Consumer Actions
65 //===----------------------------------------------------------------------===//
66
67 std::unique_ptr<ASTConsumer>
68 ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
69 if (std::unique_ptr<raw_ostream> OS =
70 CI.createDefaultOutputFile(false, InFile))
71 return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter);
72 return nullptr;
73 }
74
75 std::unique_ptr<ASTConsumer>
76 ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
77 return CreateASTDumper(nullptr /*Dump to stdout.*/,
78 CI.getFrontendOpts().ASTDumpFilter,
79 CI.getFrontendOpts().ASTDumpDecls,
80 CI.getFrontendOpts().ASTDumpAll,
81 CI.getFrontendOpts().ASTDumpLookups);
82 }
83
84 std::unique_ptr<ASTConsumer>
85 ASTDeclListAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
86 return CreateASTDeclNodeLister();
87 }
88
89 std::unique_ptr<ASTConsumer>
90 ASTViewAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
91 return CreateASTViewer();
92 }
93
94 std::unique_ptr<ASTConsumer>
95 GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
96 std::string Sysroot;
97 if (!ComputeASTConsumerArguments(CI, /*ref*/ Sysroot))
98 return nullptr;
99
100 std::string OutputFile;
101 std::unique_ptr<raw_pwrite_stream> OS =
102 CreateOutputFile(CI, InFile, /*ref*/ OutputFile);
103 if (!OS)
104 return nullptr;
105
106 if (!CI.getFrontendOpts().RelocatablePCH)
107 Sysroot.clear();
108
109 const auto &FrontendOpts = CI.getFrontendOpts();
110 auto Buffer = std::make_shared<PCHBuffer>();
111 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
112 Consumers.push_back(llvm::make_unique<PCHGenerator>(
113 CI.getPreprocessor(), OutputFile, Sysroot,
114 Buffer, FrontendOpts.ModuleFileExtensions,
115 CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
116 FrontendOpts.IncludeTimestamps));
117 Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
118 CI, InFile, OutputFile, std::move(OS), Buffer));
119
120 return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
121 }
122
123 bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI,
124 std::string &Sysroot) {
125 Sysroot = CI.getHeaderSearchOpts().Sysroot;
126 if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
127 CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
128 return false;
129 }
130
131 return true;
132 }
133
134 std::unique_ptr<llvm::raw_pwrite_stream>
135 GeneratePCHAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile,
136 std::string &OutputFile) {
137 // We use createOutputFile here because this is exposed via libclang, and we
138 // must disable the RemoveFileOnSignal behavior.
139 // We use a temporary to avoid race conditions.
140 std::unique_ptr<raw_pwrite_stream> OS =
141 CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
142 /*RemoveFileOnSignal=*/false, InFile,
143 /*Extension=*/"", /*useTemporary=*/true);
144 if (!OS)
145 return nullptr;
146
147 OutputFile = CI.getFrontendOpts().OutputFile;
148 return OS;
149 }
150
151 bool GeneratePCHAction::shouldEraseOutputFiles() {
152 if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors)
153 return false;
154 return ASTFrontendAction::shouldEraseOutputFiles();
155 }
156
157 bool GeneratePCHAction::BeginSourceFileAction(CompilerInstance &CI) {
158 CI.getLangOpts().CompilingPCH = true;
159 return true;
160 }
161
162 std::unique_ptr<ASTConsumer>
163 GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
164 StringRef InFile) {
165 std::unique_ptr<raw_pwrite_stream> OS = CreateOutputFile(CI, InFile);
166 if (!OS)
167 return nullptr;
168
169 std::string OutputFile = CI.getFrontendOpts().OutputFile;
170 std::string Sysroot;
171
172 auto Buffer = std::make_shared<PCHBuffer>();
173 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
174
175 Consumers.push_back(llvm::make_unique<PCHGenerator>(
176 CI.getPreprocessor(), OutputFile, Sysroot,
177 Buffer, CI.getFrontendOpts().ModuleFileExtensions,
178 /*AllowASTWithErrors=*/false,
179 /*IncludeTimestamps=*/
180 +CI.getFrontendOpts().BuildingImplicitModule));
181 Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
182 CI, InFile, OutputFile, std::move(OS), Buffer));
183 return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
184 }
185
186 bool GenerateModuleFromModuleMapAction::BeginSourceFileAction(
187 CompilerInstance &CI) {
188 if (!CI.getLangOpts().Modules) {
189 CI.getDiagnostics().Report(diag::err_module_build_requires_fmodules);
190 return false;
191 }
192
193 return GenerateModuleAction::BeginSourceFileAction(CI);
194 }
195
196 std::unique_ptr<raw_pwrite_stream>
197 GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
198 StringRef InFile) {
199 // If no output file was provided, figure out where this module would go
200 // in the module cache.
201 if (CI.getFrontendOpts().OutputFile.empty()) {
202 StringRef ModuleMapFile = CI.getFrontendOpts().OriginalModuleMap;
203 if (ModuleMapFile.empty())
204 ModuleMapFile = InFile;
205
206 HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
207 CI.getFrontendOpts().OutputFile =
208 HS.getCachedModuleFileName(CI.getLangOpts().CurrentModule,
209 ModuleMapFile);
210 }
211
212 // We use createOutputFile here because this is exposed via libclang, and we
213 // must disable the RemoveFileOnSignal behavior.
214 // We use a temporary to avoid race conditions.
215 return CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
216 /*RemoveFileOnSignal=*/false, InFile,
217 /*Extension=*/"", /*useTemporary=*/true,
218 /*CreateMissingDirectories=*/true);
219 }
220
221 bool GenerateModuleInterfaceAction::BeginSourceFileAction(
222 CompilerInstance &CI) {
223 if (!CI.getLangOpts().ModulesTS) {
224 CI.getDiagnostics().Report(diag::err_module_interface_requires_modules_ts);
225 return false;
226 }
227
228 CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
229
230 return GenerateModuleAction::BeginSourceFileAction(CI);
231 }
232
233 std::unique_ptr<raw_pwrite_stream>
234 GenerateModuleInterfaceAction::CreateOutputFile(CompilerInstance &CI,
235 StringRef InFile) {
236 return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
237 }
238
239 bool GenerateHeaderModuleAction::PrepareToExecuteAction(
240 CompilerInstance &CI) {
241 if (!CI.getLangOpts().Modules && !CI.getLangOpts().ModulesTS) {
242 CI.getDiagnostics().Report(diag::err_header_module_requires_modules);
243 return false;
244 }
245
246 auto &Inputs = CI.getFrontendOpts().Inputs;
247 if (Inputs.empty())
248 return GenerateModuleAction::BeginInvocation(CI);
249
250 auto Kind = Inputs[0].getKind();
251
252 // Convert the header file inputs into a single module input buffer.
253 SmallString<256> HeaderContents;
254 ModuleHeaders.reserve(Inputs.size());
255 for (const FrontendInputFile &FIF : Inputs) {
256 // FIXME: We should support re-compiling from an AST file.
257 if (FIF.getKind().getFormat() != InputKind::Source || !FIF.isFile()) {
258 CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
259 << (FIF.isFile() ? FIF.getFile()
260 : FIF.getBuffer()->getBufferIdentifier());
261 return true;
262 }
263
264 HeaderContents += "#include \"";
265 HeaderContents += FIF.getFile();
266 HeaderContents += "\"\n";
267 ModuleHeaders.push_back(FIF.getFile());
268 }
269 Buffer = llvm::MemoryBuffer::getMemBufferCopy(
270 HeaderContents, Module::getModuleInputBufferName());
271
272 // Set that buffer up as our "real" input.
273 Inputs.clear();
274 Inputs.push_back(FrontendInputFile(Buffer.get(), Kind, /*IsSystem*/false));
275
276 return GenerateModuleAction::PrepareToExecuteAction(CI);
277 }
278
279 bool GenerateHeaderModuleAction::BeginSourceFileAction(
280 CompilerInstance &CI) {
281 CI.getLangOpts().setCompilingModule(LangOptions::CMK_HeaderModule);
282
283 // Synthesize a Module object for the given headers.
284 auto &HS = CI.getPreprocessor().getHeaderSearchInfo();
285 SmallVector<Module::Header, 16> Headers;
286 for (StringRef Name : ModuleHeaders) {
287 const DirectoryLookup *CurDir = nullptr;
288 const FileEntry *FE = HS.LookupFile(
289 Name, SourceLocation(), /*Angled*/ false, nullptr, CurDir,
290 None, nullptr, nullptr, nullptr, nullptr, nullptr);
291 if (!FE) {
292 CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
293 << Name;
294 continue;
295 }
296 Headers.push_back({Name, FE});
297 }
298 HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
299
300 return GenerateModuleAction::BeginSourceFileAction(CI);
301 }
302
303 std::unique_ptr<raw_pwrite_stream>
304 GenerateHeaderModuleAction::CreateOutputFile(CompilerInstance &CI,
305 StringRef InFile) {
306 return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
307 }
308
309 SyntaxOnlyAction::~SyntaxOnlyAction() {
310 }
311
312 std::unique_ptr<ASTConsumer>
313 SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
314 return llvm::make_unique<ASTConsumer>();
315 }
316
317 std::unique_ptr<ASTConsumer>
318 DumpModuleInfoAction::CreateASTConsumer(CompilerInstance &CI,
319 StringRef InFile) {
320 return llvm::make_unique<ASTConsumer>();
321 }
322
323 std::unique_ptr<ASTConsumer>
324 VerifyPCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
325 return llvm::make_unique<ASTConsumer>();
326 }
327
328 void VerifyPCHAction::ExecuteAction() {
329 CompilerInstance &CI = getCompilerInstance();
330 bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
331 const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
332 std::unique_ptr<ASTReader> Reader(new ASTReader(
333 CI.getPreprocessor(), &CI.getASTContext(), CI.getPCHContainerReader(),
334 CI.getFrontendOpts().ModuleFileExtensions,
335 Sysroot.empty() ? "" : Sysroot.c_str(),
336 /*DisableValidation*/ false,
337 /*AllowPCHWithCompilerErrors*/ false,
338 /*AllowConfigurationMismatch*/ true,
339 /*ValidateSystemInputs*/ true));
340
341 Reader->ReadAST(getCurrentFile(),
342 Preamble ? serialization::MK_Preamble
343 : serialization::MK_PCH,
344 SourceLocation(),
345 ASTReader::ARR_ConfigurationMismatch);
346 }
347
348 namespace {
349 struct TemplightEntry {
350 std::string Name;
351 std::string Kind;
352 std::string Event;
353 std::string DefinitionLocation;
354 std::string PointOfInstantiation;
355 };
356 } // namespace
357
358 namespace llvm {
359 namespace yaml {
360 template <> struct MappingTraits<TemplightEntry> {
361 static void mapping(IO &io, TemplightEntry &fields) {
362 io.mapRequired("name", fields.Name);
363 io.mapRequired("kind", fields.Kind);
364 io.mapRequired("event", fields.Event);
365 io.mapRequired("orig", fields.DefinitionLocation);
366 io.mapRequired("poi", fields.PointOfInstantiation);
367 }
368 };
369 } // namespace yaml
370 } // namespace llvm
371
372 namespace {
373 class DefaultTemplateInstCallback : public TemplateInstantiationCallback {
374 using CodeSynthesisContext = Sema::CodeSynthesisContext;
375
376 public:
377 void initialize(const Sema &) override {}
378
379 void finalize(const Sema &) override {}
380
381 void atTemplateBegin(const Sema &TheSema,
382 const CodeSynthesisContext &Inst) override {
383 displayTemplightEntry<true>(llvm::outs(), TheSema, Inst);
384 }
385
386 void atTemplateEnd(const Sema &TheSema,
387 const CodeSynthesisContext &Inst) override {
388 displayTemplightEntry<false>(llvm::outs(), TheSema, Inst);
389 }
390
391 private:
392 static std::string toString(CodeSynthesisContext::SynthesisKind Kind) {
393 switch (Kind) {
394 case CodeSynthesisContext::TemplateInstantiation:
395 return "TemplateInstantiation";
396 case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
397 return "DefaultTemplateArgumentInstantiation";
398 case CodeSynthesisContext::DefaultFunctionArgumentInstantiation:
399 return "DefaultFunctionArgumentInstantiation";
400 case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution:
401 return "ExplicitTemplateArgumentSubstitution";
402 case CodeSynthesisContext::DeducedTemplateArgumentSubstitution:
403 return "DeducedTemplateArgumentSubstitution";
404 case CodeSynthesisContext::PriorTemplateArgumentSubstitution:
405 return "PriorTemplateArgumentSubstitution";
406 case CodeSynthesisContext::DefaultTemplateArgumentChecking:
407 return "DefaultTemplateArgumentChecking";
408 case CodeSynthesisContext::ExceptionSpecEvaluation:
409 return "ExceptionSpecEvaluation";
410 case CodeSynthesisContext::ExceptionSpecInstantiation:
411 return "ExceptionSpecInstantiation";
412 case CodeSynthesisContext::DeclaringSpecialMember:
413 return "DeclaringSpecialMember";
414 case CodeSynthesisContext::DefiningSynthesizedFunction:
415 return "DefiningSynthesizedFunction";
416 case CodeSynthesisContext::Memoization:
417 return "Memoization";
418 }
419 return "";
420 }
421
422 template <bool BeginInstantiation>
423 static void displayTemplightEntry(llvm::raw_ostream &Out, const Sema &TheSema,
424 const CodeSynthesisContext &Inst) {
425 std::string YAML;
426 {
427 llvm::raw_string_ostream OS(YAML);
428 llvm::yaml::Output YO(OS);
429 TemplightEntry Entry =
430 getTemplightEntry<BeginInstantiation>(TheSema, Inst);
431 llvm::yaml::EmptyContext Context;
432 llvm::yaml::yamlize(YO, Entry, true, Context);
433 }
434 Out << "---" << YAML << "\n";
435 }
436
437 template <bool BeginInstantiation>
438 static TemplightEntry getTemplightEntry(const Sema &TheSema,
439 const CodeSynthesisContext &Inst) {
440 TemplightEntry Entry;
441 Entry.Kind = toString(Inst.Kind);
442 Entry.Event = BeginInstantiation ? "Begin" : "End";
443 if (auto *NamedTemplate = dyn_cast_or_null<NamedDecl>(Inst.Entity)) {
444 llvm::raw_string_ostream OS(Entry.Name);
445 NamedTemplate->getNameForDiagnostic(OS, TheSema.getLangOpts(), true);
446 const PresumedLoc DefLoc =
447 TheSema.getSourceManager().getPresumedLoc(Inst.Entity->getLocation());
448 if(!DefLoc.isInvalid())
449 Entry.DefinitionLocation = std::string(DefLoc.getFilename()) + ":" +
450 std::to_string(DefLoc.getLine()) + ":" +
451 std::to_string(DefLoc.getColumn());
452 }
453 const PresumedLoc PoiLoc =
454 TheSema.getSourceManager().getPresumedLoc(Inst.PointOfInstantiation);
455 if (!PoiLoc.isInvalid()) {
456 Entry.PointOfInstantiation = std::string(PoiLoc.getFilename()) + ":" +
457 std::to_string(PoiLoc.getLine()) + ":" +
458 std::to_string(PoiLoc.getColumn());
459 }
460 return Entry;
461 }
462 };
463 } // namespace
464
465 std::unique_ptr<ASTConsumer>
466 TemplightDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
467 return llvm::make_unique<ASTConsumer>();
468 }
469
470 void TemplightDumpAction::ExecuteAction() {
471 CompilerInstance &CI = getCompilerInstance();
472
473 // This part is normally done by ASTFrontEndAction, but needs to happen
474 // before Templight observers can be created
475 // FIXME: Move the truncation aspect of this into Sema, we delayed this till
476 // here so the source manager would be initialized.
477 EnsureSemaIsCreated(CI, *this);
478
479 CI.getSema().TemplateInstCallbacks.push_back(
480 llvm::make_unique<DefaultTemplateInstCallback>());
481 ASTFrontendAction::ExecuteAction();
482 }
483
484 namespace {
485 /// AST reader listener that dumps module information for a module
486 /// file.
487 class DumpModuleInfoListener : public ASTReaderListener {
488 llvm::raw_ostream &Out;
489
490 public:
491 DumpModuleInfoListener(llvm::raw_ostream &Out) : Out(Out) { }
492
493 #define DUMP_BOOLEAN(Value, Text) \
494 Out.indent(4) << Text << ": " << (Value? "Yes" : "No") << "\n"
495
496 bool ReadFullVersionInformation(StringRef FullVersion) override {
497 Out.indent(2)
498 << "Generated by "
499 << (FullVersion == getClangFullRepositoryVersion()? "this"
500 : "a different")
501 << " Clang: " << FullVersion << "\n";
502 return ASTReaderListener::ReadFullVersionInformation(FullVersion);
503 }
504
505 void ReadModuleName(StringRef ModuleName) override {
506 Out.indent(2) << "Module name: " << ModuleName << "\n";
507 }
508 void ReadModuleMapFile(StringRef ModuleMapPath) override {
509 Out.indent(2) << "Module map file: " << ModuleMapPath << "\n";
510 }
511
512 bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
513 bool AllowCompatibleDifferences) override {
514 Out.indent(2) << "Language options:\n";
515 #define LANGOPT(Name, Bits, Default, Description) \
516 DUMP_BOOLEAN(LangOpts.Name, Description);
517 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
518 Out.indent(4) << Description << ": " \
519 << static_cast<unsigned>(LangOpts.get##Name()) << "\n";
520 #define VALUE_LANGOPT(Name, Bits, Default, Description) \
521 Out.indent(4) << Description << ": " << LangOpts.Name << "\n";
522 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
523 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
524 #include "clang/Basic/LangOptions.def"
525
526 if (!LangOpts.ModuleFeatures.empty()) {
527 Out.indent(4) << "Module features:\n";
528 for (StringRef Feature : LangOpts.ModuleFeatures)
529 Out.indent(6) << Feature << "\n";
530 }
531
532 return false;
533 }
534
535 bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
536 bool AllowCompatibleDifferences) override {
537 Out.indent(2) << "Target options:\n";
538 Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n";
539 Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n";
540 Out.indent(4) << " ABI: " << TargetOpts.ABI << "\n";
541
542 if (!TargetOpts.FeaturesAsWritten.empty()) {
543 Out.indent(4) << "Target features:\n";
544 for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size();
545 I != N; ++I) {
546 Out.indent(6) << TargetOpts.FeaturesAsWritten[I] << "\n";
547 }
548 }
549
550 return false;
551 }
552
553 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
554 bool Complain) override {
555 Out.indent(2) << "Diagnostic options:\n";
556 #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name);
557 #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
558 Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n";
559 #define VALUE_DIAGOPT(Name, Bits, Default) \
560 Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n";
561 #include "clang/Basic/DiagnosticOptions.def"
562
563 Out.indent(4) << "Diagnostic flags:\n";
564 for (const std::string &Warning : DiagOpts->Warnings)
565 Out.indent(6) << "-W" << Warning << "\n";
566 for (const std::string &Remark : DiagOpts->Remarks)
567 Out.indent(6) << "-R" << Remark << "\n";
568
569 return false;
570 }
571
572 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
573 StringRef SpecificModuleCachePath,
574 bool Complain) override {
575 Out.indent(2) << "Header search options:\n";
576 Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n";
577 Out.indent(4) << "Resource dir [ -resource-dir=]: '" << HSOpts.ResourceDir << "'\n";
578 Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n";
579 DUMP_BOOLEAN(HSOpts.UseBuiltinIncludes,
580 "Use builtin include directories [-nobuiltininc]");
581 DUMP_BOOLEAN(HSOpts.UseStandardSystemIncludes,
582 "Use standard system include directories [-nostdinc]");
583 DUMP_BOOLEAN(HSOpts.UseStandardCXXIncludes,
584 "Use standard C++ include directories [-nostdinc++]");
585 DUMP_BOOLEAN(HSOpts.UseLibcxx,
586 "Use libc++ (rather than libstdc++) [-stdlib=]");
587 return false;
588 }
589
590 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
591 bool Complain,
592 std::string &SuggestedPredefines) override {
593 Out.indent(2) << "Preprocessor options:\n";
594 DUMP_BOOLEAN(PPOpts.UsePredefines,
595 "Uses compiler/target-specific predefines [-undef]");
596 DUMP_BOOLEAN(PPOpts.DetailedRecord,
597 "Uses detailed preprocessing record (for indexing)");
598
599 if (!PPOpts.Macros.empty()) {
600 Out.indent(4) << "Predefined macros:\n";
601 }
602
603 for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
604 I = PPOpts.Macros.begin(), IEnd = PPOpts.Macros.end();
605 I != IEnd; ++I) {
606 Out.indent(6);
607 if (I->second)
608 Out << "-U";
609 else
610 Out << "-D";
611 Out << I->first << "\n";
612 }
613 return false;
614 }
615
616 /// Indicates that a particular module file extension has been read.
617 void readModuleFileExtension(
618 const ModuleFileExtensionMetadata &Metadata) override {
619 Out.indent(2) << "Module file extension '"
620 << Metadata.BlockName << "' " << Metadata.MajorVersion
621 << "." << Metadata.MinorVersion;
622 if (!Metadata.UserInfo.empty()) {
623 Out << ": ";
624 Out.write_escaped(Metadata.UserInfo);
625 }
626
627 Out << "\n";
628 }
629
630 /// Tells the \c ASTReaderListener that we want to receive the
631 /// input files of the AST file via \c visitInputFile.
632 bool needsInputFileVisitation() override { return true; }
633
634 /// Tells the \c ASTReaderListener that we want to receive the
635 /// input files of the AST file via \c visitInputFile.
636 bool needsSystemInputFileVisitation() override { return true; }
637
638 /// Indicates that the AST file contains particular input file.
639 ///
640 /// \returns true to continue receiving the next input file, false to stop.
641 bool visitInputFile(StringRef Filename, bool isSystem,
642 bool isOverridden, bool isExplicitModule) override {
643
644 Out.indent(2) << "Input file: " << Filename;
645
646 if (isSystem || isOverridden || isExplicitModule) {
647 Out << " [";
648 if (isSystem) {
649 Out << "System";
650 if (isOverridden || isExplicitModule)
651 Out << ", ";
652 }
653 if (isOverridden) {
654 Out << "Overridden";
655 if (isExplicitModule)
656 Out << ", ";
657 }
658 if (isExplicitModule)
659 Out << "ExplicitModule";
660
661 Out << "]";
662 }
663
664 Out << "\n";
665
666 return true;
667 }
668
669 /// Returns true if this \c ASTReaderListener wants to receive the
670 /// imports of the AST file via \c visitImport, false otherwise.
671 bool needsImportVisitation() const override { return true; }
672
673 /// If needsImportVisitation returns \c true, this is called for each
674 /// AST file imported by this AST file.
675 void visitImport(StringRef ModuleName, StringRef Filename) override {
676 Out.indent(2) << "Imports module '" << ModuleName
677 << "': " << Filename.str() << "\n";
678 }
679 #undef DUMP_BOOLEAN
680 };
681 }
682
683 bool DumpModuleInfoAction::BeginInvocation(CompilerInstance &CI) {
684 // The Object file reader also supports raw ast files and there is no point in
685 // being strict about the module file format in -module-file-info mode.
686 CI.getHeaderSearchOpts().ModuleFormat = "obj";
687 return true;
688 }
689
690 void DumpModuleInfoAction::ExecuteAction() {
691 // Set up the output file.
692 std::unique_ptr<llvm::raw_fd_ostream> OutFile;
693 StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
694 if (!OutputFileName.empty() && OutputFileName != "-") {
695 std::error_code EC;
696 OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
697 llvm::sys::fs::F_Text));
698 }
699 llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
700
701 Out << "Information for module file '" << getCurrentFile() << "':\n";
702 auto &FileMgr = getCompilerInstance().getFileManager();
703 auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
704 StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
705 bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
706 Magic[2] == 'C' && Magic[3] == 'H');
707 Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
708
709 Preprocessor &PP = getCompilerInstance().getPreprocessor();
710 DumpModuleInfoListener Listener(Out);
711 HeaderSearchOptions &HSOpts =
712 PP.getHeaderSearchInfo().getHeaderSearchOpts();
713 ASTReader::readASTFileControlBlock(
714 getCurrentFile(), FileMgr, getCompilerInstance().getPCHContainerReader(),
715 /*FindModuleFileExtensions=*/true, Listener,
716 HSOpts.ModulesValidateDiagnosticOptions);
717 }
718
719 //===----------------------------------------------------------------------===//
720 // Preprocessor Actions
721 //===----------------------------------------------------------------------===//
722
723 void DumpRawTokensAction::ExecuteAction() {
724 Preprocessor &PP = getCompilerInstance().getPreprocessor();
725 SourceManager &SM = PP.getSourceManager();
726
727 // Start lexing the specified input file.
728 const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID());
729 Lexer RawLex(SM.getMainFileID(), FromFile, SM, PP.getLangOpts());
730 RawLex.SetKeepWhitespaceMode(true);
731
732 Token RawTok;
733 RawLex.LexFromRawLexer(RawTok);
734 while (RawTok.isNot(tok::eof)) {
735 PP.DumpToken(RawTok, true);
736 llvm::errs() << "\n";
737 RawLex.LexFromRawLexer(RawTok);
738 }
739 }
740
741 void DumpTokensAction::ExecuteAction() {
742 Preprocessor &PP = getCompilerInstance().getPreprocessor();
743 // Start preprocessing the specified input file.
744 Token Tok;
745 PP.EnterMainSourceFile();
746 do {
747 PP.Lex(Tok);
748 PP.DumpToken(Tok, true);
749 llvm::errs() << "\n";
750 } while (Tok.isNot(tok::eof));
751 }
752
753 void PreprocessOnlyAction::ExecuteAction() {
754 Preprocessor &PP = getCompilerInstance().getPreprocessor();
755
756 // Ignore unknown pragmas.
757 PP.IgnorePragmas();
758
759 Token Tok;
760 // Start parsing the specified input file.
761 PP.EnterMainSourceFile();
762 do {
763 PP.Lex(Tok);
764 } while (Tok.isNot(tok::eof));
765 }
766
767 void PrintPreprocessedAction::ExecuteAction() {
768 CompilerInstance &CI = getCompilerInstance();
769 // Output file may need to be set to 'Binary', to avoid converting Unix style
770 // line feeds (<LF>) to Microsoft style line feeds (<CR><LF>).
771 //
772 // Look to see what type of line endings the file uses. If there's a
773 // CRLF, then we won't open the file up in binary mode. If there is
774 // just an LF or CR, then we will open the file up in binary mode.
775 // In this fashion, the output format should match the input format, unless
776 // the input format has inconsistent line endings.
777 //
778 // This should be a relatively fast operation since most files won't have
779 // all of their source code on a single line. However, that is still a
780 // concern, so if we scan for too long, we'll just assume the file should
781 // be opened in binary mode.
782 bool BinaryMode = true;
783 bool InvalidFile = false;
784 const SourceManager& SM = CI.getSourceManager();
785 const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(),
786 &InvalidFile);
787 if (!InvalidFile) {
788 const char *cur = Buffer->getBufferStart();
789 const char *end = Buffer->getBufferEnd();
790 const char *next = (cur != end) ? cur + 1 : end;
791
792 // Limit ourselves to only scanning 256 characters into the source
793 // file. This is mostly a sanity check in case the file has no
794 // newlines whatsoever.
795 if (end - cur > 256) end = cur + 256;
796
797 while (next < end) {
798 if (*cur == 0x0D) { // CR
799 if (*next == 0x0A) // CRLF
800 BinaryMode = false;
801
802 break;
803 } else if (*cur == 0x0A) // LF
804 break;
805
806 ++cur;
807 ++next;
808 }
809 }
810
811 std::unique_ptr<raw_ostream> OS =
812 CI.createDefaultOutputFile(BinaryMode, getCurrentFileOrBufferName());
813 if (!OS) return;
814
815 // If we're preprocessing a module map, start by dumping the contents of the
816 // module itself before switching to the input buffer.
817 auto &Input = getCurrentInput();
818 if (Input.getKind().getFormat() == InputKind::ModuleMap) {
819 if (Input.isFile()) {
820 (*OS) << "# 1 \"";
821 OS->write_escaped(Input.getFile());
822 (*OS) << "\"\n";
823 }
824 getCurrentModule()->print(*OS);
825 (*OS) << "#pragma clang module contents\n";
826 }
827
828 DoPrintPreprocessedInput(CI.getPreprocessor(), OS.get(),
829 CI.getPreprocessorOutputOpts());
830 }
831
832 void PrintPreambleAction::ExecuteAction() {
833 switch (getCurrentFileKind().getLanguage()) {
834 case InputKind::C:
835 case InputKind::CXX:
836 case InputKind::ObjC:
837 case InputKind::ObjCXX:
838 case InputKind::OpenCL:
839 case InputKind::CUDA:
840 case InputKind::HIP:
841 break;
842
843 case InputKind::Unknown:
844 case InputKind::Asm:
845 case InputKind::LLVM_IR:
846 case InputKind::RenderScript:
847 // We can't do anything with these.
848 return;
849 }
850
851 // We don't expect to find any #include directives in a preprocessed input.
852 if (getCurrentFileKind().isPreprocessed())
853 return;
854
855 CompilerInstance &CI = getCompilerInstance();
856 auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile());
857 if (Buffer) {
858 unsigned Preamble =
859 Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).Size;
860 llvm::outs().write((*Buffer)->getBufferStart(), Preamble);
861 }
862 }
863
864 void DumpCompilerOptionsAction::ExecuteAction() {
865 CompilerInstance &CI = getCompilerInstance();
866 std::unique_ptr<raw_ostream> OSP =
867 CI.createDefaultOutputFile(false, getCurrentFile());
868 if (!OSP)
869 return;
870
871 raw_ostream &OS = *OSP;
872 const Preprocessor &PP = CI.getPreprocessor();
873 const LangOptions &LangOpts = PP.getLangOpts();
874
875 // FIXME: Rather than manually format the JSON (which is awkward due to
876 // needing to remove trailing commas), this should make use of a JSON library.
877 // FIXME: Instead of printing enums as an integral value and specifying the
878 // type as a separate field, use introspection to print the enumerator.
879
880 OS << "{\n";
881 OS << "\n\"features\" : [\n";
882 {
883 llvm::SmallString<128> Str;
884 #define FEATURE(Name, Predicate) \
885 ("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
886 .toVector(Str);
887 #include "clang/Basic/Features.def"
888 #undef FEATURE
889 // Remove the newline and comma from the last entry to ensure this remains
890 // valid JSON.
891 OS << Str.substr(0, Str.size() - 2);
892 }
893 OS << "\n],\n";
894
895 OS << "\n\"extensions\" : [\n";
896 {
897 llvm::SmallString<128> Str;
898 #define EXTENSION(Name, Predicate) \
899 ("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
900 .toVector(Str);
901 #include "clang/Basic/Features.def"
902 #undef EXTENSION
903 // Remove the newline and comma from the last entry to ensure this remains
904 // valid JSON.
905 OS << Str.substr(0, Str.size() - 2);
906 }
907 OS << "\n]\n";
908
909 OS << "}";
910 }
clang::FrontendOptions::OutputFile
std::string OutputFile
The output file, if any.
Definition: FrontendOptions.h:382
clang::CompilerInstance::getLangOpts
LangOptions & getLangOpts()
Definition: CompilerInstance.h:310
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
clang::ASTPrintAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:68
clang::CompilerInstance::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts()
Definition: CompilerInstance.h:317
clang::GeneratePCHAction::shouldEraseOutputFiles
bool shouldEraseOutputFiles() override
Callback at the end of processing a single input, to determine if the output files should be erased o...
Definition: FrontendActions.cpp:151
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::PreprocessorOptions::Macros
std::vector< std::pair< std::string, bool > > Macros
Definition: PreprocessorOptions.h:45
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:77
FrontendActions.h
clang::HeaderSearchOptions::UseLibcxx
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
Definition: HeaderSearchOptions.h:186
clang::Sema::TemplateInstCallbacks
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained)...
Definition: Sema.h:7343
FileManager.h
Defines the clang::FileManager interface and associated types.
llvm
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
clang::ASTFrontendAction::ExecuteAction
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Definition: FrontendAction.cpp:1017
clang::ASTDeclListAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:85
clang::CompilerInstance::createSema
void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)
Create the Sema object to be used for parsing.
Definition: CompilerInstance.cpp:626
clang::FrontendAction
Abstract base class for actions which can be performed by the frontend.
Definition: FrontendAction.h:36
ASTReader.h
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1295
HeaderSearch.h
clang::finalize
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
Definition: TemplateInstCallback.h:53
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:43
clang::FrontendOptions::ASTDumpFilter
std::string ASTDumpFilter
If given, filter dumped AST Decl nodes by this substring.
Definition: FrontendOptions.h:388
clang::CompilerInstance::getASTContext
ASTContext & getASTContext() const
Definition: CompilerInstance.h:469
clang::LangOptions::CMK_ModuleInterface
Compiling a C++ modules TS module interface unit.
Definition: LangOptions.h:85
clang::Preprocessor::IgnorePragmas
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:1841
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:27
clang::DiagnosticLevelMask::Remark
clang::Sema::CodeSynthesisContext
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition: Sema.h:7170
clang::FrontendAction::hasCodeCompletionSupport
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
Definition: FrontendAction.h:200
clang::DumpModuleInfoAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:318
clang::InputKind::CXX
Definition: FrontendOptions.h:158
clang::Module::getModuleInputBufferName
static StringRef getModuleInputBufferName()
Definition: Module.h:574
toString
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Definition: SanitizerArgs.cpp:775
clang::DumpTokensAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendActions.cpp:741
clang::FrontendAction::getCurrentModule
Module * getCurrentModule() const
Definition: FrontendAction.cpp:142
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
clang::ASTReader::ARR_ConfigurationMismatch
The client can handle an AST file that cannot load because it&#39;s compiled configuration doesn&#39;t match ...
Definition: ASTReader.h:1525
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::DumpRawTokensAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendActions.cpp:723
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:815
clang::FrontendOptions::BuildingImplicitModule
unsigned BuildingImplicitModule
Whether we are performing an implicit module build.
Definition: FrontendOptions.h:298
clang::GeneratePCHAction::BeginSourceFileAction
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
Definition: FrontendActions.cpp:157
clang::FrontendOptions::RelocatablePCH
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
Definition: FrontendOptions.h:249
clang::InputKind::C
Languages that the frontend can parse and compile.
Definition: FrontendOptions.h:157
clang::GeneratePCHAction::ComputeASTConsumerArguments
static bool ComputeASTConsumerArguments(CompilerInstance &CI, std::string &Sysroot)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
Definition: FrontendActions.cpp:123
clang::TemplateInstantiationCallback
This is a base class for callbacks that will be notified at every template instantiation.
Definition: TemplateInstCallback.h:24
clang::FrontendAction::getCompilerInstance
CompilerInstance & getCompilerInstance() const
Definition: FrontendAction.h:119
clang::ModuleFileExtensionMetadata::UserInfo
std::string UserInfo
A string containing additional user information that will be stored with the metadata.
Definition: ModuleFileExtension.h:50
clang::CompilerInstance::getPCHContainerWriter
const PCHContainerWriter & getPCHContainerWriter() const
Return the appropriate PCHContainerWriter depending on the current CodeGenOptions.
Definition: CompilerInstance.h:535
ASTWriter.h
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:821
clang::HeaderSearch::getCachedModuleFileName
std::string getCachedModuleFileName(Module *Module)
Retrieve the name of the cached module file that should be used to load the given module...
Definition: HeaderSearch.cpp:128
clang::CompilerInstance::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInstance.h:293
clang::format::Tok
const FormatToken & Tok
Definition: BreakableToken.h:244
llvm::yaml::MappingTraits< TemplightEntry >::mapping
static void mapping(IO &io, TemplightEntry &fields)
Definition: FrontendActions.cpp:361
clang::FrontendAction::getCurrentFileOrBufferName
StringRef getCurrentFileOrBufferName() const
Definition: FrontendAction.h:144
clang::CompilerInstance::getPreprocessorOutputOpts
PreprocessorOutputOptions & getPreprocessorOutputOpts()
Definition: CompilerInstance.h:324
clang::InputKind::Source
Definition: FrontendOptions.h:170
clang::HeaderSearchOptions::ResourceDir
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
Definition: HeaderSearchOptions.h:109
clang::ASTDumpAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:76
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
clang::DumpModuleInfoAction::BeginInvocation
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
Definition: FrontendActions.cpp:683
Utils.h
DUMP_BOOLEAN
#define DUMP_BOOLEAN(Value, Text)
Definition: FrontendActions.cpp:493
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1231
clang::CompilerInstance::getHeaderSearchOpts
HeaderSearchOptions & getHeaderSearchOpts()
Definition: CompilerInstance.h:300
clang::DumpModuleInfoAction::ExecuteAction
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Definition: FrontendActions.cpp:690
llvm::SmallString
Definition: LLVM.h:35
clang::CompilerInstance::getCodeCompletionConsumer
CodeCompleteConsumer & getCodeCompletionConsumer() const
Definition: CompilerInstance.h:567
FrontendDiagnostic.h
clang::LangOptions::ModuleFeatures
std::vector< std::string > ModuleFeatures
The names of any features to enable in module &#39;requires&#39; decls in addition to the hard-coded list in ...
Definition: LangOptions.h:233
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::CompilerInstance::getSema
Sema & getSema() const
Definition: CompilerInstance.h:510
clang::PreprocessorOptions::DetailedRecord
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
Definition: PreprocessorOptions.h:55
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
CompilerInstance.h
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::DiagnosticLevelMask::Warning
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::FrontendOptions::ASTDumpAll
unsigned ASTDumpAll
Whether we deserialize all decls when forming AST dumps.
Definition: FrontendOptions.h:292
clang::CreateASTDumper
std::unique_ptr< ASTConsumer > CreateASTDumper(std::unique_ptr< raw_ostream > OS, StringRef FilterString, bool DumpDecls, bool Deserialize, bool DumpLookups)
Definition: ASTConsumers.cpp:143
clang::DoPrintPreprocessedInput
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, const PreprocessorOutputOptions &Opts)
DoPrintPreprocessedInput - Implement -E mode.
Definition: PrintPreprocessedOutput.cpp:829
clang::TemplightDumpAction::ExecuteAction
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Definition: FrontendActions.cpp:470
clang::Lexer::ComputePreamble
static PreambleBounds ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, unsigned MaxLines=0)
Compute the preamble of the given file.
Definition: Lexer.cpp:574
clang::PresumedLoc::isInvalid
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Definition: SourceLocation.h:299
clang::PresumedLoc::getLine
unsigned getLine() const
Return the presumed line number of this location.
Definition: SourceLocation.h:313
clang::LangOptions::CMK_HeaderModule
Compiling a module from a list of header files.
Definition: LangOptions.h:82
clang::Preprocessor::EnterMainSourceFile
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc...
Definition: Preprocessor.cpp:526
clang::Module::print
void print(raw_ostream &OS, unsigned Indent=0) const
Print the module map for this module to the given stream.
Definition: Module.cpp:405
Preprocessor.h
Defines the clang::Preprocessor interface.
clang::HeaderSearchOptions::UseBuiltinIncludes
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
Definition: HeaderSearchOptions.h:177
clang::PresumedLoc
Represents an unpacked "presumed" location which can be presented to the user.
Definition: SourceLocation.h:285
clang::FrontendInputFile
An input file for the front end.
Definition: FrontendOptions.h:199
clang::FrontendAction::getCurrentFileKind
InputKind getCurrentFileKind() const
Definition: FrontendAction.h:151
ASTConsumer.h
clang::SkipFunctionBodiesScope::Preamble
SM
const SourceManager & SM
Definition: Format.cpp:1490
clang::ModuleFileExtensionMetadata::MajorVersion
unsigned MajorVersion
The major version of the extension data.
Definition: ModuleFileExtension.h:43
clang::CompilerInstance::createOutputFile
std::unique_ptr< raw_pwrite_stream > createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, StringRef BaseInput, StringRef Extension, bool UseTemporary, bool CreateMissingDirectories=false)
Create a new output file and add it to the list of tracked output files, optionally deriving the outp...
Definition: CompilerInstance.cpp:687
clang::DirectoryLookup
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
Definition: DirectoryLookup.h:32
clang::ModuleFileExtensionMetadata::MinorVersion
unsigned MinorVersion
The minor version of the extension data.
Definition: ModuleFileExtension.h:46
clang::PreprocessorOptions::AllowPCHWithCompilerErrors
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
Definition: PreprocessorOptions.h:85
clang::TargetOptions::CPU
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:37
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:819
clang::PresumedLoc::getFilename
const char * getFilename() const
Return the presumed filename of this location.
Definition: SourceLocation.h:305
clang::InputKind::Unknown
Definition: FrontendOptions.h:147
clang::TemplightDumpAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:466
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::SourceManager::getBuffer
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
Definition: SourceManager.h:955
clang::TargetOptions::ABI
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:43
clang::serialization::MK_Preamble
File is a PCH file treated as the preamble.
Definition: Module.h:54
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:45
clang::PresumedLoc::getColumn
unsigned getColumn() const
Return the presumed column number of this location.
Definition: SourceLocation.h:321
clang::PreprocessOnlyAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendActions.cpp:753
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::HeaderSearchOptions::UseStandardSystemIncludes
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
Definition: HeaderSearchOptions.h:180
clang::atTemplateBegin
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Definition: TemplateInstCallback.h:62
clang::InputKind::Asm
Assembly: we accept this only so that we can preprocess it.
Definition: FrontendOptions.h:150
clang::serialization::MK_PCH
File is a PCH file treated as such.
Definition: Module.h:51
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::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::FrontendOptions::Inputs
std::vector< FrontendInputFile > Inputs
The input files and their types.
Definition: FrontendOptions.h:375
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:60
clang::InputKind::RenderScript
Definition: FrontendOptions.h:163
TemplateInstCallback.h
clang::getClangFullRepositoryVersion
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:90
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:863
clang::ParsedSourceLocation::FileName
std::string FileName
Definition: CommandLineSourceLoc.h:26
clang::FrontendAction::PrepareToExecuteAction
virtual bool PrepareToExecuteAction(CompilerInstance &CI)
Prepare to execute the action on the given CompilerInstance.
Definition: FrontendAction.h:55
clang::ASTReaderListener::ReadFullVersionInformation
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition: ASTReader.h:135
clang::FrontendOptions::ASTDumpLookups
unsigned ASTDumpLookups
Whether we include lookup table dumps in AST dumps.
Definition: FrontendOptions.h:295
llvm::SmallVector
Definition: LLVM.h:36
clang::TargetOptions::FeaturesAsWritten
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:52
clang::Preprocessor::DumpToken
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
Definition: Preprocessor.cpp:225
clang::MultiVersionKind::None
clang::PrintPreambleAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendActions.cpp:832
clang::CodeCompleteConsumer
Abstract interface for a consumer of code-completion information.
Definition: CodeCompleteConsumer.h:999
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::InputKind::ModuleMap
Definition: FrontendOptions.h:171
clang::InputKind::ObjC
Definition: FrontendOptions.h:159
clang::CompilerInstance::getFileManager
FileManager & getFileManager() const
Return the current file manager to the caller.
Definition: CompilerInstance.h:409
clang::PrintPreprocessedAction::ExecuteAction
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: FrontendActions.cpp:767
clang::GeneratePCHAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:95
clang::FrontendAction::getCurrentInput
const FrontendInputFile & getCurrentInput() const
Definition: FrontendAction.h:135
clang::PreprocessorOptions::UsePredefines
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
Definition: PreprocessorOptions.h:51
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:355
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::FileManager::getBufferForFile
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
Definition: FileManager.cpp:401
clang::InputKind::OpenCL
Definition: FrontendOptions.h:161
clang::PCHContainerWriter::CreatePCHContainerGenerator
virtual std::unique_ptr< ASTConsumer > CreatePCHContainerGenerator(CompilerInstance &CI, const std::string &MainFileName, const std::string &OutputFileName, std::unique_ptr< llvm::raw_pwrite_stream > OS, std::shared_ptr< PCHBuffer > Buffer) const =0
Return an ASTConsumer that can be chained with a PCHGenerator that produces a wrapper file format con...
clang::CompilerInstance::getSourceManager
SourceManager & getSourceManager() const
Return the current source manager.
Definition: CompilerInstance.h:429
clang::SourceManager::getPresumedLoc
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
Definition: SourceManager.cpp:1414
clang::GenerateModuleAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:163
clang::ModuleFileExtensionMetadata::BlockName
std::string BlockName
The name used to identify this particular extension block within the resulting module file...
Definition: ModuleFileExtension.h:40
clang::ASTReaderListener
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:127
clang::HeaderSearchOptions::ModulesValidateDiagnosticOptions
unsigned ModulesValidateDiagnosticOptions
Definition: HeaderSearchOptions.h:202
clang::comments::tok::eof
Definition: CommentLexer.h:34
clang::SyntaxOnlyAction::~SyntaxOnlyAction
~SyntaxOnlyAction() override
Definition: FrontendActions.cpp:309
clang::FrontendOptions::ModuleFileExtensions
std::vector< std::shared_ptr< ModuleFileExtension > > ModuleFileExtensions
The list of module file extensions.
Definition: FrontendOptions.h:409
ASTConsumers.h
clang::CompilerInstance::createDefaultOutputFile
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="")
Create the default output file (from the invocation&#39;s options) and add it to the list of tracked outp...
Definition: CompilerInstance.cpp:675
MultiplexConsumer.h
clang::CreateASTViewer
std::unique_ptr< ASTConsumer > CreateASTViewer()
Definition: ASTConsumers.cpp:193
clang::ModuleFileExtensionMetadata
Metadata for a module file extension.
Definition: ModuleFileExtension.h:35
clang::InputKind::ObjCXX
Definition: FrontendOptions.h:160
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::CreateASTDeclNodeLister
std::unique_ptr< ASTConsumer > CreateASTDeclNodeLister()
Definition: ASTConsumers.cpp:156
clang::FrontendAction::BeginSourceFileAction
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
Definition: FrontendAction.h:85
clang::FrontendOptions::ASTDumpDecls
unsigned ASTDumpDecls
Whether we include declaration dumps in AST dumps.
Definition: FrontendOptions.h:289
clang::atTemplateEnd
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Definition: TemplateInstCallback.h:72
clang::CompilerInstance::getPCHContainerReader
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
Definition: CompilerInstance.h:549
clang::Sema::getSourceManager
SourceManager & getSourceManager() const
Definition: Sema.h:1236
clang::ASTViewAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:90
clang::PreprocessorOptions::PrecompiledPreambleBytes
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
Definition: PreprocessorOptions.h:99
clang::InputKind::HIP
Definition: FrontendOptions.h:164
clang::CompilerInstance::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
Definition: CompilerInstance.h:345
clang::HeaderSearchOptions
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Definition: HeaderSearchOptions.h:67
clang::initialize
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
Definition: TemplateInstCallback.h:44
clang::ASTReader::readASTFileControlBlock
static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener, bool ValidateDiagnosticOptions)
Read the control block for the named AST file.
Definition: ASTReader.cpp:4718
clang::HeaderSearchOptions::Sysroot
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
Definition: HeaderSearchOptions.h:99
clang::SyntaxOnlyAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:313
clang::InputKind::CUDA
Definition: FrontendOptions.h:162
clang::GeneratePCHAction::CreateOutputFile
static std::unique_ptr< llvm::raw_pwrite_stream > CreateOutputFile(CompilerInstance &CI, StringRef InFile, std::string &OutputFile)
Creates file to write the PCH into and returns a stream to write it into.
Definition: FrontendActions.cpp:135
clang::CreateASTPrinter
std::unique_ptr< ASTConsumer > CreateASTPrinter(std::unique_ptr< raw_ostream > OS, StringRef FilterString)
Definition: ASTConsumers.cpp:136
clang::VerifyPCHAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: FrontendActions.cpp:324
clang::HeaderSearchOptions::UseStandardCXXIncludes
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
Definition: HeaderSearchOptions.h:183
clang::Lexer::SetKeepWhitespaceMode
void SetKeepWhitespaceMode(bool Val)
SetKeepWhitespaceMode - This method lets clients enable or disable whitespace retention mode...
Definition: Lexer.h:213
clang::TargetOptions::Triple
std::string Triple
The name of the target triple to compile for.
Definition: TargetOptions.h:30
clang::SrcMgr::isSystem
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:83
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:582
clang::HeaderSearchOptions::ModuleFormat
std::string ModuleFormat
The module/pch container format.
Definition: HeaderSearchOptions.h:124
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::VerifyPCHAction::ExecuteAction
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Definition: FrontendActions.cpp:328