clang 17.0.0git
CompilerInstance.h
Go to the documentation of this file.
1//===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
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#ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
10#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
11
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/IntrusiveRefCntPtr.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/Support/BuryPointer.h"
25#include "llvm/Support/FileSystem.h"
26#include <cassert>
27#include <list>
28#include <memory>
29#include <optional>
30#include <string>
31#include <utility>
32
33namespace llvm {
34class raw_fd_ostream;
35class Timer;
36class TimerGroup;
37}
38
39namespace clang {
40class ASTContext;
41class ASTReader;
42class CodeCompleteConsumer;
43class DiagnosticsEngine;
44class DiagnosticConsumer;
45class FileManager;
46class FrontendAction;
47class InMemoryModuleCache;
48class Module;
49class Preprocessor;
50class Sema;
51class SourceManager;
52class TargetInfo;
54
55/// CompilerInstance - Helper class for managing a single instance of the Clang
56/// compiler.
57///
58/// The CompilerInstance serves two purposes:
59/// (1) It manages the various objects which are necessary to run the compiler,
60/// for example the preprocessor, the target information, and the AST
61/// context.
62/// (2) It provides utility routines for constructing and manipulating the
63/// common Clang objects.
64///
65/// The compiler instance generally owns the instance of all the objects that it
66/// manages. However, clients can still share objects by manually setting the
67/// object and retaking ownership prior to destroying the CompilerInstance.
68///
69/// The compiler instance is intended to simplify clients, but not to lock them
70/// in to the compiler instance for everything. When possible, utility functions
71/// come in two forms; a short form that reuses the CompilerInstance objects,
72/// and a long form that takes explicit instances of any required objects.
74 /// The options used in this compiler instance.
75 std::shared_ptr<CompilerInvocation> Invocation;
76
77 /// The diagnostics engine instance.
79
80 /// The target being compiled for.
82
83 /// Auxiliary Target info.
85
86 /// The file manager.
88
89 /// The source manager.
91
92 /// The cache of PCM files.
94
95 /// The preprocessor.
96 std::shared_ptr<Preprocessor> PP;
97
98 /// The AST context.
100
101 /// An optional sema source that will be attached to sema.
103
104 /// The AST consumer.
105 std::unique_ptr<ASTConsumer> Consumer;
106
107 /// The code completion consumer.
108 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
109
110 /// The semantic analysis object.
111 std::unique_ptr<Sema> TheSema;
112
113 /// The frontend timer group.
114 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
115
116 /// The frontend timer.
117 std::unique_ptr<llvm::Timer> FrontendTimer;
118
119 /// The ASTReader, if one exists.
121
122 /// The module dependency collector for crashdumps
123 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
124
125 /// The module provider.
126 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
127
128 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
129
130 /// The set of top-level modules that has already been built on the
131 /// fly as part of this overall compilation action.
132 std::map<std::string, std::string, std::less<>> BuiltModules;
133
134 /// Should we delete the BuiltModules when we're done?
135 bool DeleteBuiltModules = true;
136
137 /// The location of the module-import keyword for the last module
138 /// import.
139 SourceLocation LastModuleImportLoc;
140
141 /// The result of the last module import.
142 ///
143 ModuleLoadResult LastModuleImportResult;
144
145 /// Whether we should (re)build the global module index once we
146 /// have finished with this translation unit.
147 bool BuildGlobalModuleIndex = false;
148
149 /// We have a full global module index, with all modules.
150 bool HaveFullGlobalModuleIndex = false;
151
152 /// One or more modules failed to build.
153 bool DisableGeneratingGlobalModuleIndex = false;
154
155 /// The stream for verbose output if owned, otherwise nullptr.
156 std::unique_ptr<raw_ostream> OwnedVerboseOutputStream;
157
158 /// The stream for verbose output.
159 raw_ostream *VerboseOutputStream = &llvm::errs();
160
161 /// Holds information about the output file.
162 ///
163 /// If TempFilename is not empty we must rename it to Filename at the end.
164 /// TempFilename may be empty and Filename non-empty if creating the temporary
165 /// failed.
166 struct OutputFile {
167 std::string Filename;
168 std::optional<llvm::sys::fs::TempFile> File;
169
170 OutputFile(std::string filename,
171 std::optional<llvm::sys::fs::TempFile> file)
172 : Filename(std::move(filename)), File(std::move(file)) {}
173 };
174
175 /// The list of active output files.
176 std::list<OutputFile> OutputFiles;
177
178 /// Force an output buffer.
179 std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
180
181 CompilerInstance(const CompilerInstance &) = delete;
182 void operator=(const CompilerInstance &) = delete;
183public:
184 explicit CompilerInstance(
185 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
186 std::make_shared<PCHContainerOperations>(),
187 InMemoryModuleCache *SharedModuleCache = nullptr);
188 ~CompilerInstance() override;
189
190 /// @name High-Level Operations
191 /// {
192
193 /// ExecuteAction - Execute the provided action against the compiler's
194 /// CompilerInvocation object.
195 ///
196 /// This function makes the following assumptions:
197 ///
198 /// - The invocation options should be initialized. This function does not
199 /// handle the '-help' or '-version' options, clients should handle those
200 /// directly.
201 ///
202 /// - The diagnostics engine should have already been created by the client.
203 ///
204 /// - No other CompilerInstance state should have been initialized (this is
205 /// an unchecked error).
206 ///
207 /// - Clients should have initialized any LLVM target features that may be
208 /// required.
209 ///
210 /// - Clients should eventually call llvm_shutdown() upon the completion of
211 /// this routine to ensure that any managed objects are properly destroyed.
212 ///
213 /// Note that this routine may write output to 'stderr'.
214 ///
215 /// \param Act - The action to execute.
216 /// \return - True on success.
217 //
218 // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
219 // of the context or else not CompilerInstance specific.
220 bool ExecuteAction(FrontendAction &Act);
221
222 /// Load the list of plugins requested in the \c FrontendOptions.
224
225 /// }
226 /// @name Compiler Invocation and Options
227 /// {
228
229 bool hasInvocation() const { return Invocation != nullptr; }
230
232 assert(Invocation && "Compiler instance has no invocation!");
233 return *Invocation;
234 }
235
236 /// setInvocation - Replace the current invocation.
237 void setInvocation(std::shared_ptr<CompilerInvocation> Value);
238
239 /// Indicates whether we should (re)build the global module index.
240 bool shouldBuildGlobalModuleIndex() const;
241
242 /// Set the flag indicating whether we should (re)build the global
243 /// module index.
244 void setBuildGlobalModuleIndex(bool Build) {
245 BuildGlobalModuleIndex = Build;
246 }
247
248 /// }
249 /// @name Forwarding Methods
250 /// {
251
253 return Invocation->getAnalyzerOpts();
254 }
255
257 return Invocation->getCodeGenOpts();
258 }
260 return Invocation->getCodeGenOpts();
261 }
262
264 return Invocation->getDependencyOutputOpts();
265 }
267 return Invocation->getDependencyOutputOpts();
268 }
269
271 return Invocation->getDiagnosticOpts();
272 }
274 return Invocation->getDiagnosticOpts();
275 }
276
278 return Invocation->getFileSystemOpts();
279 }
281 return Invocation->getFileSystemOpts();
282 }
283
285 return Invocation->getFrontendOpts();
286 }
288 return Invocation->getFrontendOpts();
289 }
290
292 return Invocation->getHeaderSearchOpts();
293 }
295 return Invocation->getHeaderSearchOpts();
296 }
297 std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
298 return Invocation->getHeaderSearchOptsPtr();
299 }
300
302 return *Invocation->getLangOpts();
303 }
304 const LangOptions &getLangOpts() const {
305 return *Invocation->getLangOpts();
306 }
307
309 return Invocation->getPreprocessorOpts();
310 }
312 return Invocation->getPreprocessorOpts();
313 }
314
316 return Invocation->getPreprocessorOutputOpts();
317 }
319 return Invocation->getPreprocessorOutputOpts();
320 }
321
323 return Invocation->getTargetOpts();
324 }
326 return Invocation->getTargetOpts();
327 }
328
329 /// }
330 /// @name Diagnostics Engine
331 /// {
332
333 bool hasDiagnostics() const { return Diagnostics != nullptr; }
334
335 /// Get the current diagnostics engine.
337 assert(Diagnostics && "Compiler instance has no diagnostics!");
338 return *Diagnostics;
339 }
340
341 /// setDiagnostics - Replace the current diagnostics engine.
343
345 assert(Diagnostics && Diagnostics->getClient() &&
346 "Compiler instance has no diagnostic client!");
347 return *Diagnostics->getClient();
348 }
349
350 /// }
351 /// @name VerboseOutputStream
352 /// }
353
354 /// Replace the current stream for verbose output.
355 void setVerboseOutputStream(raw_ostream &Value);
356
357 /// Replace the current stream for verbose output.
358 void setVerboseOutputStream(std::unique_ptr<raw_ostream> Value);
359
360 /// Get the current stream for verbose output.
361 raw_ostream &getVerboseOutputStream() {
362 return *VerboseOutputStream;
363 }
364
365 /// }
366 /// @name Target Info
367 /// {
368
369 bool hasTarget() const { return Target != nullptr; }
370
372 assert(Target && "Compiler instance has no target!");
373 return *Target;
374 }
375
376 /// Replace the current Target.
378
379 /// }
380 /// @name AuxTarget Info
381 /// {
382
383 TargetInfo *getAuxTarget() const { return AuxTarget.get(); }
384
385 /// Replace the current AuxTarget.
387
388 // Create Target and AuxTarget based on current options
389 bool createTarget();
390
391 /// }
392 /// @name Virtual File System
393 /// {
394
395 llvm::vfs::FileSystem &getVirtualFileSystem() const;
396
397 /// }
398 /// @name File Manager
399 /// {
400
401 bool hasFileManager() const { return FileMgr != nullptr; }
402
403 /// Return the current file manager to the caller.
405 assert(FileMgr && "Compiler instance has no file manager!");
406 return *FileMgr;
407 }
408
410 llvm::BuryPointer(FileMgr.get());
411 FileMgr.resetWithoutRelease();
412 }
413
414 /// Replace the current file manager and virtual file system.
416
417 /// }
418 /// @name Source Manager
419 /// {
420
421 bool hasSourceManager() const { return SourceMgr != nullptr; }
422
423 /// Return the current source manager.
425 assert(SourceMgr && "Compiler instance has no source manager!");
426 return *SourceMgr;
427 }
428
430 llvm::BuryPointer(SourceMgr.get());
431 SourceMgr.resetWithoutRelease();
432 }
433
434 /// setSourceManager - Replace the current source manager.
436
437 /// }
438 /// @name Preprocessor
439 /// {
440
441 bool hasPreprocessor() const { return PP != nullptr; }
442
443 /// Return the current preprocessor.
445 assert(PP && "Compiler instance has no preprocessor!");
446 return *PP;
447 }
448
449 std::shared_ptr<Preprocessor> getPreprocessorPtr() { return PP; }
450
452 llvm::BuryPointer(new std::shared_ptr<Preprocessor>(PP));
453 }
454
455 /// Replace the current preprocessor.
456 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
457
458 /// }
459 /// @name ASTContext
460 /// {
461
462 bool hasASTContext() const { return Context != nullptr; }
463
465 assert(Context && "Compiler instance has no AST context!");
466 return *Context;
467 }
468
470 llvm::BuryPointer(Context.get());
471 Context.resetWithoutRelease();
472 }
473
474 /// setASTContext - Replace the current AST context.
476
477 /// Replace the current Sema; the compiler instance takes ownership
478 /// of S.
479 void setSema(Sema *S);
480
481 /// }
482 /// @name ASTConsumer
483 /// {
484
485 bool hasASTConsumer() const { return (bool)Consumer; }
486
488 assert(Consumer && "Compiler instance has no AST consumer!");
489 return *Consumer;
490 }
491
492 /// takeASTConsumer - Remove the current AST consumer and give ownership to
493 /// the caller.
494 std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); }
495
496 /// setASTConsumer - Replace the current AST consumer; the compiler instance
497 /// takes ownership of \p Value.
498 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
499
500 /// }
501 /// @name Semantic analysis
502 /// {
503 bool hasSema() const { return (bool)TheSema; }
504
505 Sema &getSema() const {
506 assert(TheSema && "Compiler instance has no Sema object!");
507 return *TheSema;
508 }
509
510 std::unique_ptr<Sema> takeSema();
511 void resetAndLeakSema();
512
513 /// }
514 /// @name Module Management
515 /// {
516
519
520 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
522 std::shared_ptr<ModuleDependencyCollector> Collector);
523
524 std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
525 return ThePCHContainerOperations;
526 }
527
528 /// Return the appropriate PCHContainerWriter depending on the
529 /// current CodeGenOptions.
531 assert(Invocation && "cannot determine module format without invocation");
532 StringRef Format = getHeaderSearchOpts().ModuleFormat;
533 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
534 if (!Writer) {
535 if (Diagnostics)
536 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
537 llvm::report_fatal_error("unknown module format");
538 }
539 return *Writer;
540 }
541
542 /// Return the appropriate PCHContainerReader depending on the
543 /// current CodeGenOptions.
545 assert(Invocation && "cannot determine module format without invocation");
546 StringRef Format = getHeaderSearchOpts().ModuleFormat;
547 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
548 if (!Reader) {
549 if (Diagnostics)
550 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
551 llvm::report_fatal_error("unknown module format");
552 }
553 return *Reader;
554 }
555
556 /// }
557 /// @name Code Completion
558 /// {
559
560 bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
561
563 assert(CompletionConsumer &&
564 "Compiler instance has no code completion consumer!");
565 return *CompletionConsumer;
566 }
567
568 /// setCodeCompletionConsumer - Replace the current code completion consumer;
569 /// the compiler instance takes ownership of \p Value.
571
572 /// }
573 /// @name Frontend timer
574 /// {
575
576 bool hasFrontendTimer() const { return (bool)FrontendTimer; }
577
578 llvm::Timer &getFrontendTimer() const {
579 assert(FrontendTimer && "Compiler instance has no frontend timer!");
580 return *FrontendTimer;
581 }
582
583 /// }
584 /// @name Output Files
585 /// {
586
587 /// clearOutputFiles - Clear the output file list. The underlying output
588 /// streams must have been closed beforehand.
589 ///
590 /// \param EraseFiles - If true, attempt to erase the files from disk.
591 void clearOutputFiles(bool EraseFiles);
592
593 /// }
594 /// @name Construction Utility Methods
595 /// {
596
597 /// Create the diagnostics engine using the invocation's diagnostic options
598 /// and replace any existing one with it.
599 ///
600 /// Note that this routine also replaces the diagnostic client,
601 /// allocating one if one is not provided.
602 ///
603 /// \param Client If non-NULL, a diagnostic client that will be
604 /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
605 /// unit.
606 ///
607 /// \param ShouldOwnClient If Client is non-NULL, specifies whether
608 /// the diagnostic object should take ownership of the client.
609 void createDiagnostics(DiagnosticConsumer *Client = nullptr,
610 bool ShouldOwnClient = true);
611
612 /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
613 ///
614 /// If no diagnostic client is provided, this creates a
615 /// DiagnosticConsumer that is owned by the returned diagnostic
616 /// object, if using directly the caller is responsible for
617 /// releasing the returned DiagnosticsEngine's client eventually.
618 ///
619 /// \param Opts - The diagnostic options; note that the created text
620 /// diagnostic object contains a reference to these options.
621 ///
622 /// \param Client If non-NULL, a diagnostic client that will be
623 /// attached to (and, then, owned by) the returned DiagnosticsEngine
624 /// object.
625 ///
626 /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
627 /// used by some diagnostics printers (for logging purposes only).
628 ///
629 /// \return The new object on success, or null on failure.
632 DiagnosticConsumer *Client = nullptr,
633 bool ShouldOwnClient = true,
634 const CodeGenOptions *CodeGenOpts = nullptr);
635
636 /// Create the file manager and replace any existing one with it.
637 ///
638 /// \return The new file manager on success, or null on failure.
641
642 /// Create the source manager and replace any existing one with it.
643 void createSourceManager(FileManager &FileMgr);
644
645 /// Create the preprocessor, using the invocation, file, and source managers,
646 /// and replace any existing one with it.
648
649 std::string getSpecificModuleCachePath(StringRef ModuleHash);
651 return getSpecificModuleCachePath(getInvocation().getModuleHash());
652 }
653
654 /// Create the AST context.
655 void createASTContext();
656
657 /// Create an external AST source to read a PCH file and attach it to the AST
658 /// context.
660 StringRef Path, DisableValidationForModuleKind DisableValidation,
661 bool AllowPCHWithCompilerErrors, void *DeserializationListener,
662 bool OwnDeserializationListener);
663
664 /// Create an external AST source to read a PCH file.
665 ///
666 /// \return - The new object on success, or null on failure.
668 StringRef Path, StringRef Sysroot,
669 DisableValidationForModuleKind DisableValidation,
670 bool AllowPCHWithCompilerErrors, Preprocessor &PP,
671 InMemoryModuleCache &ModuleCache, ASTContext &Context,
672 const PCHContainerReader &PCHContainerRdr,
673 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
674 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
675 void *DeserializationListener, bool OwnDeserializationListener,
676 bool Preamble, bool UseGlobalModuleIndex);
677
678 /// Create a code completion consumer using the invocation; note that this
679 /// will cause the source manager to truncate the input source file at the
680 /// completion point.
682
683 /// Create a code completion consumer to print code completion results, at
684 /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
686 Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column,
687 const CodeCompleteOptions &Opts, raw_ostream &OS);
688
689 /// Create the Sema object to be used for parsing.
691 CodeCompleteConsumer *CompletionConsumer);
692
693 /// Create the frontend timer and replace any existing one with it.
694 void createFrontendTimer();
695
696 /// Create the default output file (from the invocation's options) and add it
697 /// to the list of tracked output files.
698 ///
699 /// The files created by this are usually removed on signal, and, depending
700 /// on FrontendOptions, may also use a temporary file (that is, the data is
701 /// written to a temporary file which will atomically replace the target
702 /// output on success).
703 ///
704 /// \return - Null on error.
705 std::unique_ptr<raw_pwrite_stream> createDefaultOutputFile(
706 bool Binary = true, StringRef BaseInput = "", StringRef Extension = "",
707 bool RemoveFileOnSignal = true, bool CreateMissingDirectories = false,
708 bool ForceUseTemporary = false);
709
710 /// Create a new output file, optionally deriving the output path name, and
711 /// add it to the list of tracked output files.
712 ///
713 /// \return - Null on error.
714 std::unique_ptr<raw_pwrite_stream>
715 createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal,
716 bool UseTemporary, bool CreateMissingDirectories = false);
717
718private:
719 /// Create a new output file and add it to the list of tracked output files.
720 ///
721 /// If \p OutputPath is empty, then createOutputFile will derive an output
722 /// path location as \p BaseInput, with any suffix removed, and \p Extension
723 /// appended. If \p OutputPath is not stdout and \p UseTemporary
724 /// is true, createOutputFile will create a new temporary file that must be
725 /// renamed to \p OutputPath in the end.
726 ///
727 /// \param OutputPath - If given, the path to the output file.
728 /// \param Binary - The mode to open the file in.
729 /// \param RemoveFileOnSignal - Whether the file should be registered with
730 /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for
731 /// multithreaded use, as the underlying signal mechanism is not reentrant
732 /// \param UseTemporary - Create a new temporary file that must be renamed to
733 /// OutputPath in the end.
734 /// \param CreateMissingDirectories - When \p UseTemporary is true, create
735 /// missing directories in the output path.
737 createOutputFileImpl(StringRef OutputPath, bool Binary,
738 bool RemoveFileOnSignal, bool UseTemporary,
739 bool CreateMissingDirectories);
740
741public:
742 std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
743
744 /// }
745 /// @name Initialization Utility Methods
746 /// {
747
748 /// InitializeSourceManager - Initialize the source manager to set InputFile
749 /// as the main file.
750 ///
751 /// \return True on success.
753
754 /// InitializeSourceManager - Initialize the source manager to set InputFile
755 /// as the main file.
756 ///
757 /// \return True on success.
758 static bool InitializeSourceManager(const FrontendInputFile &Input,
759 DiagnosticsEngine &Diags,
760 FileManager &FileMgr,
761 SourceManager &SourceMgr);
762
763 /// }
764
765 void setOutputStream(std::unique_ptr<llvm::raw_pwrite_stream> OutStream) {
766 OutputStream = std::move(OutStream);
767 }
768
769 std::unique_ptr<llvm::raw_pwrite_stream> takeOutputStream() {
770 return std::move(OutputStream);
771 }
772
773 void createASTReader();
774
775 bool loadModuleFile(StringRef FileName);
776
777private:
778 /// Find a module, potentially compiling it, before reading its AST. This is
779 /// the guts of loadModule.
780 ///
781 /// For prebuilt modules, the Module is not expected to exist in
782 /// HeaderSearch's ModuleMap. If a ModuleFile by that name is in the
783 /// ModuleManager, then it will be loaded and looked up.
784 ///
785 /// For implicit modules, the Module is expected to already be in the
786 /// ModuleMap. First attempt to load it from the given path on disk. If that
787 /// fails, defer to compileModuleAndReadAST, which will first build and then
788 /// load it.
789 ModuleLoadResult findOrCompileModuleAndReadAST(StringRef ModuleName,
790 SourceLocation ImportLoc,
791 SourceLocation ModuleNameLoc,
792 bool IsInclusionDirective);
793
794public:
797 bool IsInclusionDirective) override;
798
799 void createModuleFromSource(SourceLocation ImportLoc, StringRef ModuleName,
800 StringRef Source) override;
801
803 SourceLocation ImportLoc) override;
804
807 }
808
810
811 bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
812
813 void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) {
814 DependencyCollectors.push_back(std::move(Listener));
815 }
816
818
819 InMemoryModuleCache &getModuleCache() const { return *ModuleCache; }
820};
821
822} // end namespace clang
823
824#endif
Defines the Diagnostic-related interfaces.
StringRef Filename
Definition: Format.cpp:2774
llvm::raw_ostream & OS
Definition: Logger.cpp:24
Defines the SourceManager interface.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Abstract interface for a consumer of code-completion information.
Options controlling the behavior of code completion.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
void createPCHExternalASTSource(StringRef Path, DisableValidationForModuleKind DisableValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)
Create an external AST source to read a PCH file and attach it to the AST context.
DiagnosticConsumer & getDiagnosticClient() const
void createPreprocessor(TranslationUnitKind TUKind)
Create the preprocessor, using the invocation, file, and source managers, and replace any existing on...
bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
Check global module index for missing imports.
void createSourceManager(FileManager &FileMgr)
Create the source manager and replace any existing one with it.
void createDiagnostics(DiagnosticConsumer *Client=nullptr, bool ShouldOwnClient=true)
Create the diagnostics engine using the invocation's diagnostic options and replace any existing one ...
FileManager * createFileManager(IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Create the file manager and replace any existing one with it.
const HeaderSearchOptions & getHeaderSearchOpts() const
DependencyOutputOptions & getDependencyOutputOpts()
const DependencyOutputOptions & getDependencyOutputOpts() const
std::shared_ptr< Preprocessor > getPreprocessorPtr()
TargetInfo * getAuxTarget() const
const PCHContainerReader & getPCHContainerReader() const
Return the appropriate PCHContainerReader depending on the current CodeGenOptions.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
GlobalModuleIndex * loadGlobalModuleIndex(SourceLocation TriggerLoc) override
Load, create, or return global module.
raw_ostream & getVerboseOutputStream()
Get the current stream for verbose output.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="", bool RemoveFileOnSignal=true, bool CreateMissingDirectories=false, bool ForceUseTemporary=false)
Create the default output file (from the invocation's options) and add it to the list of tracked outp...
void setExternalSemaSource(IntrusiveRefCntPtr< ExternalSemaSource > ESS)
const DiagnosticOptions & getDiagnosticOpts() const
std::string getSpecificModuleCachePath()
ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) override
Attempt to load the given module.
void setInvocation(std::shared_ptr< CompilerInvocation > Value)
setInvocation - Replace the current invocation.
const CodeGenOptions & getCodeGenOpts() const
FileSystemOptions & getFileSystemOpts()
llvm::Timer & getFrontendTimer() const
const TargetOptions & getTargetOpts() const
bool InitializeSourceManager(const FrontendInputFile &Input)
InitializeSourceManager - Initialize the source manager to set InputFile as the main file.
void setOutputStream(std::unique_ptr< llvm::raw_pwrite_stream > OutStream)
}
FileManager & getFileManager() const
Return the current file manager to the caller.
void setBuildGlobalModuleIndex(bool Build)
Set the flag indicating whether we should (re)build the global module index.
std::unique_ptr< Sema > takeSema()
const PreprocessorOptions & getPreprocessorOpts() const
bool loadModuleFile(StringRef FileName)
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value.
PreprocessorOutputOptions & getPreprocessorOutputOpts()
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
IntrusiveRefCntPtr< ASTReader > getASTReader() const
void setTarget(TargetInfo *Value)
Replace the current Target.
void setModuleDepCollector(std::shared_ptr< ModuleDependencyCollector > Collector)
InMemoryModuleCache & getModuleCache() const
void addDependencyCollector(std::shared_ptr< DependencyCollector > Listener)
void createASTContext()
Create the AST context.
std::unique_ptr< raw_pwrite_stream > createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, bool UseTemporary, bool CreateMissingDirectories=false)
Create a new output file, optionally deriving the output path name, and add it to the list of tracked...
void createModuleFromSource(SourceLocation ImportLoc, StringRef ModuleName, StringRef Source) override
Attempt to create the given module from the specified source buffer.
std::shared_ptr< HeaderSearchOptions > getHeaderSearchOptsPtr() const
void setASTContext(ASTContext *Value)
setASTContext - Replace the current AST context.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
ASTContext & getASTContext() const
void LoadRequestedPlugins()
Load the list of plugins requested in the FrontendOptions.
TargetOptions & getTargetOpts()
void setASTReader(IntrusiveRefCntPtr< ASTReader > Reader)
std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()
FrontendOptions & getFrontendOpts()
const FrontendOptions & getFrontendOpts() const
std::shared_ptr< ModuleDependencyCollector > getModuleDepCollector() const
bool hadModuleLoaderFatalFailure() const
void setSema(Sema *S)
Replace the current Sema; the compiler instance takes ownership of S.
HeaderSearchOptions & getHeaderSearchOpts()
void createFrontendTimer()
Create the frontend timer and replace any existing one with it.
void setDiagnostics(DiagnosticsEngine *Value)
setDiagnostics - Replace the current diagnostics engine.
bool hasCodeCompletionConsumer() const
const LangOptions & getLangOpts() const
CompilerInvocation & getInvocation()
const PCHContainerWriter & getPCHContainerWriter() const
Return the appropriate PCHContainerWriter depending on the current CodeGenOptions.
void setVerboseOutputStream(raw_ostream &Value)
Replace the current stream for verbose output.
AnalyzerOptionsRef getAnalyzerOpts()
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
PreprocessorOptions & getPreprocessorOpts()
ASTConsumer & getASTConsumer() const
TargetInfo & getTarget() const
llvm::vfs::FileSystem & getVirtualFileSystem() const
const FileSystemOptions & getFileSystemOpts() const
void createCodeCompletionConsumer()
Create a code completion consumer using the invocation; note that this will cause the source manager ...
void setCodeCompletionConsumer(CodeCompleteConsumer *Value)
setCodeCompletionConsumer - Replace the current code completion consumer; the compiler instance takes...
bool ExecuteAction(FrontendAction &Act)
ExecuteAction - Execute the provided action against the compiler's CompilerInvocation object.
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
void clearOutputFiles(bool EraseFiles)
clearOutputFiles - Clear the output file list.
DiagnosticOptions & getDiagnosticOpts()
LangOptions & getLangOpts()
CodeGenOptions & getCodeGenOpts()
SourceManager & getSourceManager() const
Return the current source manager.
CodeCompleteConsumer & getCodeCompletionConsumer() const
bool shouldBuildGlobalModuleIndex() const
Indicates whether we should (re)build the global module index.
std::unique_ptr< raw_pwrite_stream > createNullOutputFile()
void setAuxTarget(TargetInfo *Value)
Replace the current AuxTarget.
void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc) override
Make the given module visible.
void setPreprocessor(std::shared_ptr< Preprocessor > Value)
Replace the current preprocessor.
void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)
Create the Sema object to be used for parsing.
Helper class for holding the data necessary to invoke the compiler.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1740
Options for controlling the compiler diagnostics engine.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
Keeps track of options that affect how file operations are performed.
Abstract base class for actions which can be performed by the frontend.
An input file for the front end.
FrontendOptions - Options for controlling the behavior of the frontend.
A global index for a set of module files, providing information about the identifiers within those mo...
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
std::string ModuleFormat
The module/pch container format.
In-memory cache for modules.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:82
Describes the result of attempting to load a module.
Definition: ModuleLoader.h:35
Abstract interface for a module loader.
Definition: ModuleLoader.h:82
Describes a module or submodule.
Definition: Module.h:98
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:349
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
This abstract interface provides operations for creating containers for serialized ASTs (precompiled ...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g....
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
Encodes a location in the source.
This class handles loading and caching of source files into memory.
Exposes information about the current target.
Definition: TargetInfo.h:206
Options for controlling the target.
Definition: TargetOptions.h:26
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:917
DisableValidationForModuleKind
Whether to disable the normal validation performed on precompiled headers and module files when they ...
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:33
YAML serialization mapping.
Definition: Dominators.h:30