clang 10.0.0git

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