clang 18.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
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/IntrusiveRefCntPtr.h"
24#include "llvm/ADT/StringRef.h"
25#include "llvm/Support/BuryPointer.h"
26#include "llvm/Support/FileSystem.h"
27#include <cassert>
28#include <list>
29#include <memory>
30#include <optional>
31#include <string>
32#include <utility>
33
34namespace llvm {
35class raw_fd_ostream;
36class Timer;
37class TimerGroup;
38}
39
40namespace clang {
41class ASTContext;
42class ASTReader;
43
44namespace serialization {
45class ModuleFile;
46}
47
48class CodeCompleteConsumer;
49class DiagnosticsEngine;
50class DiagnosticConsumer;
51class FileManager;
52class FrontendAction;
53class InMemoryModuleCache;
54class Module;
55class Preprocessor;
56class Sema;
57class SourceManager;
58class TargetInfo;
60
61/// CompilerInstance - Helper class for managing a single instance of the Clang
62/// compiler.
63///
64/// The CompilerInstance serves two purposes:
65/// (1) It manages the various objects which are necessary to run the compiler,
66/// for example the preprocessor, the target information, and the AST
67/// context.
68/// (2) It provides utility routines for constructing and manipulating the
69/// common Clang objects.
70///
71/// The compiler instance generally owns the instance of all the objects that it
72/// manages. However, clients can still share objects by manually setting the
73/// object and retaking ownership prior to destroying the CompilerInstance.
74///
75/// The compiler instance is intended to simplify clients, but not to lock them
76/// in to the compiler instance for everything. When possible, utility functions
77/// come in two forms; a short form that reuses the CompilerInstance objects,
78/// and a long form that takes explicit instances of any required objects.
80 /// The options used in this compiler instance.
81 std::shared_ptr<CompilerInvocation> Invocation;
82
83 /// The diagnostics engine instance.
85
86 /// The target being compiled for.
88
89 /// Auxiliary Target info.
91
92 /// The file manager.
94
95 /// The source manager.
97
98 /// The cache of PCM files.
100
101 /// The preprocessor.
102 std::shared_ptr<Preprocessor> PP;
103
104 /// The AST context.
106
107 /// An optional sema source that will be attached to sema.
109
110 /// The AST consumer.
111 std::unique_ptr<ASTConsumer> Consumer;
112
113 /// The code completion consumer.
114 std::unique_ptr<CodeCompleteConsumer> CompletionConsumer;
115
116 /// The semantic analysis object.
117 std::unique_ptr<Sema> TheSema;
118
119 /// The frontend timer group.
120 std::unique_ptr<llvm::TimerGroup> FrontendTimerGroup;
121
122 /// The frontend timer.
123 std::unique_ptr<llvm::Timer> FrontendTimer;
124
125 /// The ASTReader, if one exists.
127
128 /// The module dependency collector for crashdumps
129 std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
130
131 /// The module provider.
132 std::shared_ptr<PCHContainerOperations> ThePCHContainerOperations;
133
134 std::vector<std::shared_ptr<DependencyCollector>> DependencyCollectors;
135
136 /// The set of top-level modules that has already been built on the
137 /// fly as part of this overall compilation action.
138 std::map<std::string, std::string, std::less<>> BuiltModules;
139
140 /// Should we delete the BuiltModules when we're done?
141 bool DeleteBuiltModules = true;
142
143 /// The location of the module-import keyword for the last module
144 /// import.
145 SourceLocation LastModuleImportLoc;
146
147 /// The result of the last module import.
148 ///
149 ModuleLoadResult LastModuleImportResult;
150
151 /// Whether we should (re)build the global module index once we
152 /// have finished with this translation unit.
153 bool BuildGlobalModuleIndex = false;
154
155 /// We have a full global module index, with all modules.
156 bool HaveFullGlobalModuleIndex = false;
157
158 /// One or more modules failed to build.
159 bool DisableGeneratingGlobalModuleIndex = false;
160
161 /// The stream for verbose output if owned, otherwise nullptr.
162 std::unique_ptr<raw_ostream> OwnedVerboseOutputStream;
163
164 /// The stream for verbose output.
165 raw_ostream *VerboseOutputStream = &llvm::errs();
166
167 /// Holds information about the output file.
168 ///
169 /// If TempFilename is not empty we must rename it to Filename at the end.
170 /// TempFilename may be empty and Filename non-empty if creating the temporary
171 /// failed.
172 struct OutputFile {
173 std::string Filename;
174 std::optional<llvm::sys::fs::TempFile> File;
175
176 OutputFile(std::string filename,
177 std::optional<llvm::sys::fs::TempFile> file)
178 : Filename(std::move(filename)), File(std::move(file)) {}
179 };
180
181 /// The list of active output files.
182 std::list<OutputFile> OutputFiles;
183
184 /// Force an output buffer.
185 std::unique_ptr<llvm::raw_pwrite_stream> OutputStream;
186
187 CompilerInstance(const CompilerInstance &) = delete;
188 void operator=(const CompilerInstance &) = delete;
189public:
190 explicit CompilerInstance(
191 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
192 std::make_shared<PCHContainerOperations>(),
193 InMemoryModuleCache *SharedModuleCache = nullptr);
194 ~CompilerInstance() override;
195
196 /// @name High-Level Operations
197 /// @{
198
199 /// ExecuteAction - Execute the provided action against the compiler's
200 /// CompilerInvocation object.
201 ///
202 /// This function makes the following assumptions:
203 ///
204 /// - The invocation options should be initialized. This function does not
205 /// handle the '-help' or '-version' options, clients should handle those
206 /// directly.
207 ///
208 /// - The diagnostics engine should have already been created by the client.
209 ///
210 /// - No other CompilerInstance state should have been initialized (this is
211 /// an unchecked error).
212 ///
213 /// - Clients should have initialized any LLVM target features that may be
214 /// required.
215 ///
216 /// - Clients should eventually call llvm_shutdown() upon the completion of
217 /// this routine to ensure that any managed objects are properly destroyed.
218 ///
219 /// Note that this routine may write output to 'stderr'.
220 ///
221 /// \param Act - The action to execute.
222 /// \return - True on success.
223 //
224 // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
225 // of the context or else not CompilerInstance specific.
226 bool ExecuteAction(FrontendAction &Act);
227
228 /// Load the list of plugins requested in the \c FrontendOptions.
230
231 /// @}
232 /// @name Compiler Invocation and Options
233 /// @{
234
235 bool hasInvocation() const { return Invocation != nullptr; }
236
238 assert(Invocation && "Compiler instance has no invocation!");
239 return *Invocation;
240 }
241
242 std::shared_ptr<CompilerInvocation> getInvocationPtr() { return Invocation; }
243
244 /// setInvocation - Replace the current invocation.
245 void setInvocation(std::shared_ptr<CompilerInvocation> Value);
246
247 /// Indicates whether we should (re)build the global module index.
248 bool shouldBuildGlobalModuleIndex() const;
249
250 /// Set the flag indicating whether we should (re)build the global
251 /// module index.
252 void setBuildGlobalModuleIndex(bool Build) {
253 BuildGlobalModuleIndex = Build;
254 }
255
256 /// @}
257 /// @name Forwarding Methods
258 /// @{
259
260 AnalyzerOptions &getAnalyzerOpts() { return Invocation->getAnalyzerOpts(); }
261
263 return Invocation->getCodeGenOpts();
264 }
266 return Invocation->getCodeGenOpts();
267 }
268
270 return Invocation->getDependencyOutputOpts();
271 }
273 return Invocation->getDependencyOutputOpts();
274 }
275
277 return Invocation->getDiagnosticOpts();
278 }
280 return Invocation->getDiagnosticOpts();
281 }
282
284 return Invocation->getFileSystemOpts();
285 }
287 return Invocation->getFileSystemOpts();
288 }
289
291 return Invocation->getFrontendOpts();
292 }
294 return Invocation->getFrontendOpts();
295 }
296
298 return Invocation->getHeaderSearchOpts();
299 }
301 return Invocation->getHeaderSearchOpts();
302 }
303 std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
304 return Invocation->getHeaderSearchOptsPtr();
305 }
306
307 LangOptions &getLangOpts() { return Invocation->getLangOpts(); }
308 const LangOptions &getLangOpts() const { return Invocation->getLangOpts(); }
309
311 return Invocation->getPreprocessorOpts();
312 }
314 return Invocation->getPreprocessorOpts();
315 }
316
318 return Invocation->getPreprocessorOutputOpts();
319 }
321 return Invocation->getPreprocessorOutputOpts();
322 }
323
325 return Invocation->getTargetOpts();
326 }
328 return Invocation->getTargetOpts();
329 }
330
331 /// @}
332 /// @name Diagnostics Engine
333 /// @{
334
335 bool hasDiagnostics() const { return Diagnostics != nullptr; }
336
337 /// Get the current diagnostics engine.
339 assert(Diagnostics && "Compiler instance has no diagnostics!");
340 return *Diagnostics;
341 }
342
344 assert(Diagnostics && "Compiler instance has no diagnostics!");
345 return Diagnostics;
346 }
347
348 /// setDiagnostics - Replace the current diagnostics engine.
350
352 assert(Diagnostics && Diagnostics->getClient() &&
353 "Compiler instance has no diagnostic client!");
354 return *Diagnostics->getClient();
355 }
356
357 /// @}
358 /// @name VerboseOutputStream
359 /// @{
360
361 /// Replace the current stream for verbose output.
362 void setVerboseOutputStream(raw_ostream &Value);
363
364 /// Replace the current stream for verbose output.
365 void setVerboseOutputStream(std::unique_ptr<raw_ostream> Value);
366
367 /// Get the current stream for verbose output.
368 raw_ostream &getVerboseOutputStream() {
369 return *VerboseOutputStream;
370 }
371
372 /// @}
373 /// @name Target Info
374 /// @{
375
376 bool hasTarget() const { return Target != nullptr; }
377
379 assert(Target && "Compiler instance has no target!");
380 return *Target;
381 }
382
384 assert(Target && "Compiler instance has no target!");
385 return Target;
386 }
387
388 /// Replace the current Target.
390
391 /// @}
392 /// @name AuxTarget Info
393 /// @{
394
395 TargetInfo *getAuxTarget() const { return AuxTarget.get(); }
396
397 /// Replace the current AuxTarget.
399
400 // Create Target and AuxTarget based on current options
401 bool createTarget();
402
403 /// @}
404 /// @name Virtual File System
405 /// @{
406
407 llvm::vfs::FileSystem &getVirtualFileSystem() const;
408
409 /// @}
410 /// @name File Manager
411 /// @{
412
413 bool hasFileManager() const { return FileMgr != nullptr; }
414
415 /// Return the current file manager to the caller.
417 assert(FileMgr && "Compiler instance has no file manager!");
418 return *FileMgr;
419 }
420
422 assert(FileMgr && "Compiler instance has no file manager!");
423 return FileMgr;
424 }
425
427 llvm::BuryPointer(FileMgr.get());
428 FileMgr.resetWithoutRelease();
429 }
430
431 /// Replace the current file manager and virtual file system.
433
434 /// @}
435 /// @name Source Manager
436 /// @{
437
438 bool hasSourceManager() const { return SourceMgr != nullptr; }
439
440 /// Return the current source manager.
442 assert(SourceMgr && "Compiler instance has no source manager!");
443 return *SourceMgr;
444 }
445
447 assert(SourceMgr && "Compiler instance has no source manager!");
448 return SourceMgr;
449 }
450
452 llvm::BuryPointer(SourceMgr.get());
453 SourceMgr.resetWithoutRelease();
454 }
455
456 /// setSourceManager - Replace the current source manager.
458
459 /// @}
460 /// @name Preprocessor
461 /// @{
462
463 bool hasPreprocessor() const { return PP != nullptr; }
464
465 /// Return the current preprocessor.
467 assert(PP && "Compiler instance has no preprocessor!");
468 return *PP;
469 }
470
471 std::shared_ptr<Preprocessor> getPreprocessorPtr() { return PP; }
472
474 llvm::BuryPointer(new std::shared_ptr<Preprocessor>(PP));
475 }
476
477 /// Replace the current preprocessor.
478 void setPreprocessor(std::shared_ptr<Preprocessor> Value);
479
480 /// @}
481 /// @name ASTContext
482 /// @{
483
484 bool hasASTContext() const { return Context != nullptr; }
485
487 assert(Context && "Compiler instance has no AST context!");
488 return *Context;
489 }
490
492 assert(Context && "Compiler instance has no AST context!");
493 return Context;
494 }
495
497 llvm::BuryPointer(Context.get());
498 Context.resetWithoutRelease();
499 }
500
501 /// setASTContext - Replace the current AST context.
503
504 /// Replace the current Sema; the compiler instance takes ownership
505 /// of S.
506 void setSema(Sema *S);
507
508 /// @}
509 /// @name ASTConsumer
510 /// @{
511
512 bool hasASTConsumer() const { return (bool)Consumer; }
513
515 assert(Consumer && "Compiler instance has no AST consumer!");
516 return *Consumer;
517 }
518
519 /// takeASTConsumer - Remove the current AST consumer and give ownership to
520 /// the caller.
521 std::unique_ptr<ASTConsumer> takeASTConsumer() { return std::move(Consumer); }
522
523 /// setASTConsumer - Replace the current AST consumer; the compiler instance
524 /// takes ownership of \p Value.
525 void setASTConsumer(std::unique_ptr<ASTConsumer> Value);
526
527 /// @}
528 /// @name Semantic analysis
529 /// @{
530 bool hasSema() const { return (bool)TheSema; }
531
532 Sema &getSema() const {
533 assert(TheSema && "Compiler instance has no Sema object!");
534 return *TheSema;
535 }
536
537 std::unique_ptr<Sema> takeSema();
538 void resetAndLeakSema();
539
540 /// @}
541 /// @name Module Management
542 /// @{
543
546
547 std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
549 std::shared_ptr<ModuleDependencyCollector> Collector);
550
551 std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
552 return ThePCHContainerOperations;
553 }
554
555 /// Return the appropriate PCHContainerWriter depending on the
556 /// current CodeGenOptions.
558 assert(Invocation && "cannot determine module format without invocation");
559 StringRef Format = getHeaderSearchOpts().ModuleFormat;
560 auto *Writer = ThePCHContainerOperations->getWriterOrNull(Format);
561 if (!Writer) {
562 if (Diagnostics)
563 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
564 llvm::report_fatal_error("unknown module format");
565 }
566 return *Writer;
567 }
568
569 /// Return the appropriate PCHContainerReader depending on the
570 /// current CodeGenOptions.
572 assert(Invocation && "cannot determine module format without invocation");
573 StringRef Format = getHeaderSearchOpts().ModuleFormat;
574 auto *Reader = ThePCHContainerOperations->getReaderOrNull(Format);
575 if (!Reader) {
576 if (Diagnostics)
577 Diagnostics->Report(diag::err_module_format_unhandled) << Format;
578 llvm::report_fatal_error("unknown module format");
579 }
580 return *Reader;
581 }
582
583 /// @}
584 /// @name Code Completion
585 /// @{
586
587 bool hasCodeCompletionConsumer() const { return (bool)CompletionConsumer; }
588
590 assert(CompletionConsumer &&
591 "Compiler instance has no code completion consumer!");
592 return *CompletionConsumer;
593 }
594
595 /// setCodeCompletionConsumer - Replace the current code completion consumer;
596 /// the compiler instance takes ownership of \p Value.
598
599 /// @}
600 /// @name Frontend timer
601 /// @{
602
603 bool hasFrontendTimer() const { return (bool)FrontendTimer; }
604
605 llvm::Timer &getFrontendTimer() const {
606 assert(FrontendTimer && "Compiler instance has no frontend timer!");
607 return *FrontendTimer;
608 }
609
610 /// @}
611 /// @name Output Files
612 /// @{
613
614 /// clearOutputFiles - Clear the output file list. The underlying output
615 /// streams must have been closed beforehand.
616 ///
617 /// \param EraseFiles - If true, attempt to erase the files from disk.
618 void clearOutputFiles(bool EraseFiles);
619
620 /// @}
621 /// @name Construction Utility Methods
622 /// @{
623
624 /// Create the diagnostics engine using the invocation's diagnostic options
625 /// and replace any existing one with it.
626 ///
627 /// Note that this routine also replaces the diagnostic client,
628 /// allocating one if one is not provided.
629 ///
630 /// \param Client If non-NULL, a diagnostic client that will be
631 /// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
632 /// unit.
633 ///
634 /// \param ShouldOwnClient If Client is non-NULL, specifies whether
635 /// the diagnostic object should take ownership of the client.
636 void createDiagnostics(DiagnosticConsumer *Client = nullptr,
637 bool ShouldOwnClient = true);
638
639 /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
640 ///
641 /// If no diagnostic client is provided, this creates a
642 /// DiagnosticConsumer that is owned by the returned diagnostic
643 /// object, if using directly the caller is responsible for
644 /// releasing the returned DiagnosticsEngine's client eventually.
645 ///
646 /// \param Opts - The diagnostic options; note that the created text
647 /// diagnostic object contains a reference to these options.
648 ///
649 /// \param Client If non-NULL, a diagnostic client that will be
650 /// attached to (and, then, owned by) the returned DiagnosticsEngine
651 /// object.
652 ///
653 /// \param CodeGenOpts If non-NULL, the code gen options in use, which may be
654 /// used by some diagnostics printers (for logging purposes only).
655 ///
656 /// \return The new object on success, or null on failure.
659 DiagnosticConsumer *Client = nullptr,
660 bool ShouldOwnClient = true,
661 const CodeGenOptions *CodeGenOpts = nullptr);
662
663 /// Create the file manager and replace any existing one with it.
664 ///
665 /// \return The new file manager on success, or null on failure.
668
669 /// Create the source manager and replace any existing one with it.
670 void createSourceManager(FileManager &FileMgr);
671
672 /// Create the preprocessor, using the invocation, file, and source managers,
673 /// and replace any existing one with it.
675
676 std::string getSpecificModuleCachePath(StringRef ModuleHash);
678 return getSpecificModuleCachePath(getInvocation().getModuleHash());
679 }
680
681 /// Create the AST context.
682 void createASTContext();
683
684 /// Create an external AST source to read a PCH file and attach it to the AST
685 /// context.
687 StringRef Path, DisableValidationForModuleKind DisableValidation,
688 bool AllowPCHWithCompilerErrors, void *DeserializationListener,
689 bool OwnDeserializationListener);
690
691 /// Create an external AST source to read a PCH file.
692 ///
693 /// \return - The new object on success, or null on failure.
695 StringRef Path, StringRef Sysroot,
696 DisableValidationForModuleKind DisableValidation,
697 bool AllowPCHWithCompilerErrors, Preprocessor &PP,
698 InMemoryModuleCache &ModuleCache, ASTContext &Context,
699 const PCHContainerReader &PCHContainerRdr,
700 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
701 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
702 void *DeserializationListener, bool OwnDeserializationListener,
703 bool Preamble, bool UseGlobalModuleIndex);
704
705 /// Create a code completion consumer using the invocation; note that this
706 /// will cause the source manager to truncate the input source file at the
707 /// completion point.
709
710 /// Create a code completion consumer to print code completion results, at
711 /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
713 Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column,
714 const CodeCompleteOptions &Opts, raw_ostream &OS);
715
716 /// Create the Sema object to be used for parsing.
718 CodeCompleteConsumer *CompletionConsumer);
719
720 /// Create the frontend timer and replace any existing one with it.
721 void createFrontendTimer();
722
723 /// Create the default output file (from the invocation's options) and add it
724 /// to the list of tracked output files.
725 ///
726 /// The files created by this are usually removed on signal, and, depending
727 /// on FrontendOptions, may also use a temporary file (that is, the data is
728 /// written to a temporary file which will atomically replace the target
729 /// output on success).
730 ///
731 /// \return - Null on error.
732 std::unique_ptr<raw_pwrite_stream> createDefaultOutputFile(
733 bool Binary = true, StringRef BaseInput = "", StringRef Extension = "",
734 bool RemoveFileOnSignal = true, bool CreateMissingDirectories = false,
735 bool ForceUseTemporary = false);
736
737 /// Create a new output file, optionally deriving the output path name, and
738 /// add it to the list of tracked output files.
739 ///
740 /// \return - Null on error.
741 std::unique_ptr<raw_pwrite_stream>
742 createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal,
743 bool UseTemporary, bool CreateMissingDirectories = false);
744
745private:
746 /// Create a new output file and add it to the list of tracked output files.
747 ///
748 /// If \p OutputPath is empty, then createOutputFile will derive an output
749 /// path location as \p BaseInput, with any suffix removed, and \p Extension
750 /// appended. If \p OutputPath is not stdout and \p UseTemporary
751 /// is true, createOutputFile will create a new temporary file that must be
752 /// renamed to \p OutputPath in the end.
753 ///
754 /// \param OutputPath - If given, the path to the output file.
755 /// \param Binary - The mode to open the file in.
756 /// \param RemoveFileOnSignal - Whether the file should be registered with
757 /// llvm::sys::RemoveFileOnSignal. Note that this is not safe for
758 /// multithreaded use, as the underlying signal mechanism is not reentrant
759 /// \param UseTemporary - Create a new temporary file that must be renamed to
760 /// OutputPath in the end.
761 /// \param CreateMissingDirectories - When \p UseTemporary is true, create
762 /// missing directories in the output path.
764 createOutputFileImpl(StringRef OutputPath, bool Binary,
765 bool RemoveFileOnSignal, bool UseTemporary,
766 bool CreateMissingDirectories);
767
768public:
769 std::unique_ptr<raw_pwrite_stream> createNullOutputFile();
770
771 /// @}
772 /// @name Initialization Utility Methods
773 /// @{
774
775 /// InitializeSourceManager - Initialize the source manager to set InputFile
776 /// as the main file.
777 ///
778 /// \return True on success.
780
781 /// InitializeSourceManager - Initialize the source manager to set InputFile
782 /// as the main file.
783 ///
784 /// \return True on success.
785 static bool InitializeSourceManager(const FrontendInputFile &Input,
786 DiagnosticsEngine &Diags,
787 FileManager &FileMgr,
788 SourceManager &SourceMgr);
789
790 /// @}
791
792 void setOutputStream(std::unique_ptr<llvm::raw_pwrite_stream> OutStream) {
793 OutputStream = std::move(OutStream);
794 }
795
796 std::unique_ptr<llvm::raw_pwrite_stream> takeOutputStream() {
797 return std::move(OutputStream);
798 }
799
800 void createASTReader();
801
802 bool loadModuleFile(StringRef FileName,
803 serialization::ModuleFile *&LoadedModuleFile);
804
805private:
806 /// Find a module, potentially compiling it, before reading its AST. This is
807 /// the guts of loadModule.
808 ///
809 /// For prebuilt modules, the Module is not expected to exist in
810 /// HeaderSearch's ModuleMap. If a ModuleFile by that name is in the
811 /// ModuleManager, then it will be loaded and looked up.
812 ///
813 /// For implicit modules, the Module is expected to already be in the
814 /// ModuleMap. First attempt to load it from the given path on disk. If that
815 /// fails, defer to compileModuleAndReadAST, which will first build and then
816 /// load it.
817 ModuleLoadResult findOrCompileModuleAndReadAST(StringRef ModuleName,
818 SourceLocation ImportLoc,
819 SourceLocation ModuleNameLoc,
820 bool IsInclusionDirective);
821
822public:
825 bool IsInclusionDirective) override;
826
827 void createModuleFromSource(SourceLocation ImportLoc, StringRef ModuleName,
828 StringRef Source) override;
829
831 SourceLocation ImportLoc) override;
832
835 }
836
838
839 bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
840
841 void addDependencyCollector(std::shared_ptr<DependencyCollector> Listener) {
842 DependencyCollectors.push_back(std::move(Listener));
843 }
844
846
847 InMemoryModuleCache &getModuleCache() const { return *ModuleCache; }
848};
849
850} // end namespace clang
851
852#endif
Defines the Diagnostic-related interfaces.
StringRef Filename
Definition: Format.cpp:2936
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
Stores options for the analyzer from the command line.
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...
AnalyzerOptions & getAnalyzerOpts()
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.
IntrusiveRefCntPtr< DiagnosticsEngine > getDiagnosticsPtr() const
std::unique_ptr< Sema > takeSema()
const PreprocessorOptions & getPreprocessorOpts() const
void setASTConsumer(std::unique_ptr< ASTConsumer > Value)
setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value.
PreprocessorOutputOptions & getPreprocessorOutputOpts()
IntrusiveRefCntPtr< FileManager > getFileManagerPtr() const
IntrusiveRefCntPtr< ASTContext > getASTContextPtr() const
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()
IntrusiveRefCntPtr< TargetInfo > getTargetPtr() const
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
std::shared_ptr< CompilerInvocation > getInvocationPtr()
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.
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.
IntrusiveRefCntPtr< SourceManager > getSourceManagerPtr() const
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.
bool loadModuleFile(StringRef FileName, serialization::ModuleFile *&LoadedModuleFile)
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:83
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:104
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:363
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:207
Options for controlling the target.
Definition: TargetOptions.h:26
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:124
Defines the clang::TargetInfo interface.
@ ModuleFile
The module file (.pcm). Required.
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:932
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