25#include "llvm/ADT/SmallString.h"
26#include "llvm/ADT/StringSet.h"
27#include "llvm/ADT/iterator_range.h"
28#include "llvm/Config/llvm-config.h"
29#include "llvm/Support/CrashRecoveryContext.h"
30#include "llvm/Support/FileSystem.h"
31#include "llvm/Support/ManagedStatic.h"
32#include "llvm/Support/Path.h"
33#include "llvm/Support/Process.h"
34#include "llvm/Support/VirtualFileSystem.h"
43StringRef getInMemoryPreamblePath() {
44#if defined(LLVM_ON_UNIX)
45 return "/__clang_tmp/___clang_inmemory_preamble___";
47 return "C:\\__clang_tmp\\___clang_inmemory_preamble___";
49#warning "Unknown platform. Defaulting to UNIX-style paths for in-memory PCHs"
50 return "/__clang_tmp/___clang_inmemory_preamble___";
55createVFSOverlayForPreamblePCH(StringRef PCHFilename,
56 std::unique_ptr<llvm::MemoryBuffer>
PCHBuffer,
61 new llvm::vfs::InMemoryFileSystem());
62 PCHFS->addFile(PCHFilename, 0, std::move(
PCHBuffer));
64 new llvm::vfs::OverlayFileSystem(VFS));
65 Overlay->pushOverlay(PCHFS);
89 llvm::StringSet<> &Out;
94 MissingFileCollector(llvm::StringSet<> &Out,
const HeaderSearch &Search,
96 : Out(Out), Search(Search),
SM(
SM) {}
102 StringRef RelativePath,
const Module *SuggestedModule,
111 if (llvm::sys::path::is_absolute(
FileName)) {
120 llvm::sys::path::append(Buf,
FileName);
121 llvm::sys::path::remove_dots(Buf,
true);
128 if (IncludingFile->getDir())
129 NotFoundRelativeTo(IncludingFile->getDir());
132 for (
const auto &Dir : llvm::make_range(
136 if (Dir.isNormalDir())
137 NotFoundRelativeTo(*Dir.getDirRef());
143class TemporaryFiles {
146 static TemporaryFiles &getInstance();
150 TemporaryFiles() =
default;
152 TemporaryFiles(
const TemporaryFiles &) =
delete;
158 void addFile(StringRef
File);
161 void removeFile(StringRef
File);
165 llvm::StringSet<> Files;
168TemporaryFiles &TemporaryFiles::getInstance() {
169 static TemporaryFiles Instance;
173TemporaryFiles::~TemporaryFiles() {
174 std::lock_guard<std::mutex> Guard(Mutex);
175 for (
const auto &
File : Files)
176 llvm::sys::fs::remove(
File.getKey());
179void TemporaryFiles::addFile(StringRef
File) {
180 std::lock_guard<std::mutex> Guard(Mutex);
181 auto IsInserted = Files.insert(
File).second;
183 assert(IsInserted &&
"File has already been added");
186void TemporaryFiles::removeFile(StringRef
File) {
187 std::lock_guard<std::mutex> Guard(Mutex);
188 auto WasPresent = Files.erase(
File);
190 assert(WasPresent &&
"File was not tracked");
191 llvm::sys::fs::remove(
File);
202 static std::unique_ptr<TempPCHFile>
create(StringRef StoragePath) {
206 if (
const char *TmpFile = ::getenv(
"CINDEXTEST_PREAMBLE_FILE"))
207 return std::unique_ptr<TempPCHFile>(
new TempPCHFile(TmpFile));
216 if (StoragePath.empty())
217 EC = llvm::sys::fs::createTemporaryFile(
"preamble",
"pch", FD,
File);
221 llvm::sys::path::append(TempPath,
"preamble-%%%%%%.pch");
222 namespace fs = llvm::sys::fs;
224 EC = fs::createUniqueFile(TempPath, FD,
File, fs::OF_None,
225 fs::owner_read | fs::owner_write);
230 llvm::sys::Process::SafelyCloseFileDescriptor(FD);
231 return std::unique_ptr<TempPCHFile>(
new TempPCHFile(
File.str().str()));
234 TempPCHFile &operator=(
const TempPCHFile &) =
delete;
235 TempPCHFile(
const TempPCHFile &) =
delete;
236 ~TempPCHFile() { TemporaryFiles::getInstance().removeFile(FilePath); };
239 llvm::StringRef getFilePath()
const {
return FilePath; };
242 TempPCHFile(std::string FilePath) : FilePath(
std::move(FilePath)) {
243 TemporaryFiles::getInstance().addFile(this->FilePath);
246 std::string FilePath;
251 PrecompilePreambleAction(std::shared_ptr<PCHBuffer> Buffer,
bool WritePCHFile,
253 : Buffer(
std::move(Buffer)), WritePCHFile(WritePCHFile),
254 Callbacks(Callbacks) {}
257 StringRef InFile)
override;
259 bool hasEmittedPreamblePCH()
const {
return HasEmittedPreamblePCH; }
261 void setEmittedPreamblePCH(
ASTWriter &Writer) {
263 *FileOS << Buffer->Data;
268 this->HasEmittedPreamblePCH =
true;
269 Callbacks.AfterPCHEmitted(Writer);
283 friend class PrecompilePreambleConsumer;
285 bool HasEmittedPreamblePCH =
false;
286 std::shared_ptr<PCHBuffer> Buffer;
288 std::unique_ptr<llvm::raw_pwrite_stream> FileOS;
294 PrecompilePreambleConsumer(PrecompilePreambleAction &Action,
Preprocessor &PP,
297 std::shared_ptr<PCHBuffer> Buffer)
304 Action.Callbacks.HandleTopLevelDecl(DG);
312 Action.setEmittedPreamblePCH(
getWriter());
316 return Action.Callbacks.shouldSkipFunctionBody(
D);
320 PrecompilePreambleAction &Action;
323std::unique_ptr<ASTConsumer>
331 std::string OutputFile;
340 return std::make_unique<PrecompilePreambleConsumer>(
344template <
class T>
bool moveOnNoError(llvm::ErrorOr<T> Val,
T &Output) {
347 Output = std::move(*Val);
354 const llvm::MemoryBufferRef &Buffer,
361 static std::unique_ptr<PCHStorage>
file(std::unique_ptr<TempPCHFile> File) {
363 std::unique_ptr<PCHStorage> S(
new PCHStorage());
364 S->File = std::move(
File);
367 static std::unique_ptr<PCHStorage>
inMemory(std::shared_ptr<PCHBuffer> Buf) {
368 std::unique_ptr<PCHStorage> S(
new PCHStorage());
369 S->Memory = std::move(Buf);
373 enum class Kind { InMemory, TempFile };
376 return Kind::InMemory;
378 return Kind::TempFile;
379 llvm_unreachable(
"Neither Memory nor File?");
382 assert(
getKind() == Kind::TempFile);
383 return File->getFilePath();
386 assert(
getKind() == Kind::InMemory);
387 return StringRef(Memory->Data.data(), Memory->Data.size());
396 Memory->Data =
decltype(Memory->Data)(Memory->Data);
404 std::shared_ptr<PCHBuffer> Memory;
405 std::unique_ptr<TempPCHFile>
File;
418 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
bool StoreInMemory,
420 assert(VFS &&
"VFS is null");
422 auto PreambleInvocation = std::make_shared<CompilerInvocation>(Invocation);
425 PreambleInvocation->getPreprocessorOpts();
427 std::shared_ptr<PCHBuffer> Buffer = std::make_shared<PCHBuffer>();
428 std::unique_ptr<PCHStorage> Storage;
434 std::unique_ptr<TempPCHFile> PreamblePCHFile =
435 TempPCHFile::create(StoragePath);
436 if (!PreamblePCHFile)
443 std::vector<char> PreambleBytes(MainFileBuffer->getBufferStart(),
444 MainFileBuffer->getBufferStart() +
451 StoreInMemory ? getInMemoryPreamblePath() : Storage->filePath());
458 std::unique_ptr<CompilerInstance> Clang(
462 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance> CICleanup(
465 Clang->setInvocation(std::move(PreambleInvocation));
466 Clang->setDiagnostics(&Diagnostics);
469 if (!Clang->createTarget())
472 if (Clang->getFrontendOpts().Inputs.size() != 1 ||
473 Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
475 Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() ==
488 Clang->setFileManager(
new FileManager(Clang->getFileSystemOpts(), VFS));
491 Clang->setSourceManager(
494 auto PreambleDepCollector = std::make_shared<PreambleDependencyCollector>();
495 Clang->addDependencyCollector(PreambleDepCollector);
497 Clang->getLangOpts().CompilingPCH =
true;
500 StringRef MainFilePath = FrontendOpts.
Inputs[0].getFile();
501 auto PreambleInputBuffer = llvm::MemoryBuffer::getMemBufferCopy(
502 MainFileBuffer->getBuffer().slice(0, Bounds.
Size), MainFilePath);
505 PreprocessorOpts.
addRemappedFile(MainFilePath, PreambleInputBuffer.get());
510 PreambleInputBuffer.release());
513 auto Act = std::make_unique<PrecompilePreambleAction>(
515 Storage->getKind() == PCHStorage::Kind::TempFile,
517 if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
524 std::unique_ptr<PPCallbacks> DelegatedPPCallbacks =
526 if (DelegatedPPCallbacks)
527 Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks));
530 llvm::StringSet<> MissingFiles;
531 Clang->getPreprocessor().addPPCallbacks(
532 std::make_unique<MissingFileCollector>(
533 MissingFiles, Clang->getPreprocessor().getHeaderSearchInfo(),
534 Clang->getSourceManager()));
536 if (llvm::Error Err = Act->Execute())
537 return errorToErrorCode(std::move(Err));
542 Act->EndSourceFile();
544 if (!Act->hasEmittedPreamblePCH())
550 llvm::StringMap<PrecompiledPreamble::PreambleFileHash> FilesInPreamble;
553 for (
auto &
Filename : PreambleDepCollector->getDependencies()) {
558 auto File = *MaybeFile;
559 if (time_t ModTime =
File.getModificationTime()) {
560 FilesInPreamble[
File.getName()] =
561 PrecompiledPreamble::PreambleFileHash::createForFile(
File.getSize(),
564 llvm::MemoryBufferRef Buffer =
566 FilesInPreamble[
File.getName()] =
567 PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer);
573 CICleanup.unregister();
577 std::move(Storage), std::move(PreambleBytes), PreambleEndsAtStartOfLine,
578 std::move(FilesInPreamble), std::move(MissingFiles));
582 return PreambleBounds(PreambleBytes.size(), PreambleEndsAtStartOfLine);
586 switch (Storage->getKind()) {
587 case PCHStorage::Kind::InMemory:
588 return Storage->memoryContents().size();
589 case PCHStorage::Kind::TempFile: {
591 if (llvm::sys::fs::file_size(Storage->filePath(),
Result))
594 assert(
Result <= std::numeric_limits<std::size_t>::max() &&
595 "file size did not fit into size_t");
599 llvm_unreachable(
"Unhandled storage kind");
603 const llvm::MemoryBufferRef &MainFileBuffer,
605 llvm::vfs::FileSystem &VFS)
const {
608 Bounds.
Size <= MainFileBuffer.getBufferSize() &&
609 "Buffer is too large. Bounds were calculated from a different buffer?");
611 auto PreambleInvocation = std::make_shared<CompilerInvocation>(Invocation);
613 PreambleInvocation->getPreprocessorOpts();
619 if (PreambleBytes.size() != Bounds.
Size ||
621 !std::equal(PreambleBytes.begin(), PreambleBytes.end(),
622 MainFileBuffer.getBuffer().begin()))
630 std::map<llvm::sys::fs::UniqueID, PreambleFileHash> OverriddenFiles;
631 llvm::StringSet<> OverriddenAbsPaths;
633 llvm::vfs::Status Status;
641 if (!VFS.makeAbsolute(MappedPath))
642 OverriddenAbsPaths.insert(MappedPath);
644 OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
645 Status.getSize(), llvm::sys::toTimeT(Status.getLastModificationTime()));
649 llvm::StringMap<PreambleFileHash> OverridenFileBuffers;
651 const PrecompiledPreamble::PreambleFileHash PreambleHash =
652 PreambleFileHash::createForMemoryBuffer(RB.second->getMemBufferRef());
653 llvm::vfs::Status Status;
655 OverriddenFiles[Status.getUniqueID()] = PreambleHash;
657 OverridenFileBuffers[RB.first] = PreambleHash;
660 if (!VFS.makeAbsolute(MappedPath))
661 OverriddenAbsPaths.insert(MappedPath);
665 for (
const auto &F : FilesInPreamble) {
666 auto OverridenFileBuffer = OverridenFileBuffers.find(F.first());
667 if (OverridenFileBuffer != OverridenFileBuffers.end()) {
670 if (OverridenFileBuffer->second != F.second)
675 llvm::vfs::Status Status;
682 std::map<llvm::sys::fs::UniqueID, PreambleFileHash>::iterator Overridden =
683 OverriddenFiles.find(Status.getUniqueID());
684 if (Overridden != OverriddenFiles.end()) {
687 if (Overridden->second != F.second)
694 if (Status.getSize() != uint64_t(F.second.Size) ||
695 llvm::sys::toTimeT(Status.getLastModificationTime()) !=
699 for (
const auto &F : MissingFiles) {
701 if (OverriddenAbsPaths.count(F.getKey()))
705 if (
auto Status = VFS.status(F.getKey())) {
706 if (Status->isRegularFile())
715 llvm::MemoryBuffer *MainFileBuffer)
const {
716 PreambleBounds Bounds(PreambleBytes.size(), PreambleEndsAtStartOfLine);
717 configurePreamble(Bounds, CI, VFS, MainFileBuffer);
722 llvm::MemoryBuffer *MainFileBuffer)
const {
724 configurePreamble(Bounds, CI, VFS, MainFileBuffer);
728 std::unique_ptr<PCHStorage> Storage, std::vector<char> PreambleBytes,
729 bool PreambleEndsAtStartOfLine,
730 llvm::StringMap<PreambleFileHash> FilesInPreamble,
731 llvm::StringSet<> MissingFiles)
732 : Storage(
std::move(Storage)), FilesInPreamble(
std::move(FilesInPreamble)),
733 MissingFiles(
std::move(MissingFiles)),
734 PreambleBytes(
std::move(PreambleBytes)),
735 PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {
736 assert(this->Storage !=
nullptr);
739PrecompiledPreamble::PreambleFileHash
740PrecompiledPreamble::PreambleFileHash::createForFile(off_t Size,
749PrecompiledPreamble::PreambleFileHash
750PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(
751 const llvm::MemoryBufferRef &Buffer) {
753 Result.Size = Buffer.getBufferSize();
757 MD5Ctx.update(Buffer.getBuffer().data());
763void PrecompiledPreamble::configurePreamble(
766 llvm::MemoryBuffer *MainFileBuffer)
const {
773 PreprocessorOpts.addRemappedFile(MainFilePath, MainFileBuffer);
776 PreprocessorOpts.PrecompiledPreambleBytes.first = Bounds.
Size;
777 PreprocessorOpts.PrecompiledPreambleBytes.second =
779 PreprocessorOpts.DisablePCHOrModuleValidation =
784 PreprocessorOpts.UsePredefines =
false;
786 setupPreambleStorage(*Storage, PreprocessorOpts, VFS);
789void PrecompiledPreamble::setupPreambleStorage(
792 if (
Storage.getKind() == PCHStorage::Kind::TempFile) {
793 llvm::StringRef PCHPath =
Storage.filePath();
798 llvm::vfs::getRealFileSystem();
799 if (VFS == RealFS ||
VFS->exists(PCHPath))
801 auto Buf = RealFS->getBufferForFile(PCHPath);
811 VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(*Buf), VFS);
813 assert(
Storage.getKind() == PCHStorage::Kind::InMemory);
816 StringRef PCHPath = getInMemoryPreamblePath();
819 auto Buf = llvm::MemoryBuffer::getMemBuffer(
820 Storage.memoryContents(), PCHPath,
false);
821 VFS = createVFSOverlayForPreamblePCH(PCHPath, std::move(Buf), VFS);
841 return "build-preamble.error";
847 return "Could not create temporary file for PCH";
849 return "CreateTargetInfo() return null";
851 return "BeginSourceFile() return an error";
853 return "Could not emit PCH";
855 return "Command line arguments must contain exactly one source file";
857 llvm_unreachable(
"unexpected BuildPreambleError");
static bool moveOnNoError(llvm::ErrorOr< T > Val, T &Output)
Defines the clang::FileManager interface and associated types.
llvm::MachO::FileType FileType
static llvm::ManagedStatic< BuildPreambleErrorCategory > BuildPreambleErrCategory
Defines the clang::Preprocessor interface.
llvm::StringRef memoryContents() const
static std::unique_ptr< PCHStorage > file(std::unique_ptr< TempPCHFile > File)
static std::unique_ptr< PCHStorage > inMemory(std::shared_ptr< PCHBuffer > Buf)
llvm::StringRef filePath() const
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
virtual bool shouldSkipFunctionBody(Decl *D)
This callback is called for each function if the Parser was initialized with SkipFunctionBodies set t...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Abstract base class to use for AST consumer-based frontend actions.
Writes an AST file containing the contents of a translation unit.
std::string message(int condition) const override
const char * name() const noexcept override
Represents a character-granular source range.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
InMemoryModuleCache & getModuleCache() const
Preprocessor & getPreprocessor() const
Return the current preprocessor.
FrontendOptions & getFrontendOpts()
LangOptions & getLangOpts()
Helper class for holding the data necessary to invoke the compiler.
PreprocessorOptions & getPreprocessorOpts()
LangOptions & getLangOpts()
Mutable getters.
FrontendOptions & getFrontendOpts()
Decl - This represents one declaration (or definition), e.g.
An interface for collecting the dependencies of a compilation.
virtual bool needSystemDependencies()
Return true if system files should be passed to sawDependency().
Concrete class used by the front-end to report problems and issues.
void Reset(bool soft=false)
Reset the state of the diagnostic object to its initial configuration.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Implements support for file system lookup, file system caching, and directory search management.
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile)=0
Create the AST consumer object for this action, if supported.
virtual bool hasASTFileSupport() const
Does this action support use with AST files?
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we're handling.
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
FrontendOptions - Options for controlling the behavior of the frontend.
std::string OutputFile
The output file, if any.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
SmallVector< FrontendInputFile, 0 > Inputs
The input files and their types.
frontend::ActionKind ProgramAction
The frontend action to perform.
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.
static bool ComputeASTConsumerArguments(CompilerInstance &CI, std::string &Sysroot)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
In-memory cache for modules.
Record the location of an inclusion directive, such as an #include or #import statement.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static PreambleBounds ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, unsigned MaxLines=0)
Compute the preamble of the given file.
An abstract superclass that describes a custom extension to the module/precompiled header file format...
Describes a module or submodule.
AST and semantic-analysis consumer that generates a precompiled header from the parsed source code.
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
bool hasEmittedPCH() const
This interface provides a way to observe the actions of the preprocessor as it does its thing.
A set of callbacks to gather useful information while building a preamble.
virtual void AfterPCHEmitted(ASTWriter &Writer)
Called after PCH has been emitted.
virtual void BeforeExecute(CompilerInstance &CI)
Called before FrontendAction::Execute.
virtual CommentHandler * getCommentHandler()
The returned CommentHandler will be added to the preprocessor if not null.
virtual void HandleTopLevelDecl(DeclGroupRef DG)
Called for each TopLevelDecl.
virtual std::unique_ptr< PPCallbacks > createPPCallbacks()
Creates wrapper class for PPCallbacks so we can also process information about includes that are insi...
virtual void AfterExecute(CompilerInstance &CI)
Called after FrontendAction::Execute(), but before FrontendAction::EndSourceFile().
A class holding a PCH and all information to check whether it is valid to reuse the PCH for the subse...
void OverridePreamble(CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
Configure CI to use this preamble.
PrecompiledPreamble & operator=(PrecompiledPreamble &&)
static llvm::ErrorOr< PrecompiledPreamble > Build(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, bool StoreInMemory, StringRef StoragePath, PreambleCallbacks &Callbacks)
Try to build PrecompiledPreamble for Invocation.
bool CanReuse(const CompilerInvocation &Invocation, const llvm::MemoryBufferRef &MainFileBuffer, PreambleBounds Bounds, llvm::vfs::FileSystem &VFS) const
Check whether PrecompiledPreamble can be reused for the new contents(MainFileBuffer) of the main file...
void AddImplicitPreamble(CompilerInvocation &CI, IntrusiveRefCntPtr< llvm::vfs::FileSystem > &VFS, llvm::MemoryBuffer *MainFileBuffer) const
Changes options inside CI to use PCH from this preamble.
std::size_t getSize() const
Returns the size, in bytes, that preamble takes on disk or in memory.
PreambleBounds getBounds() const
PreambleBounds used to build the preamble.
PrecompiledPreamble(PrecompiledPreamble &&)
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
std::vector< std::pair< std::string, std::string > > RemappedFiles
The set of file remappings, which take existing files on the system (the first part of each pair) and...
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
bool RetainRemappedFileBuffers
Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
void addRemappedFile(StringRef From, StringRef To)
bool GeneratePreamble
True indicates that a preamble is being generated.
std::vector< std::pair< std::string, llvm::MemoryBuffer * > > RemappedFileBuffers
The set of file-to-buffer remappings, which take existing files on the system (the first part of each...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
llvm::MemoryBufferRef getMemoryBufferForFileOrFake(FileEntryRef File)
Retrieve the memory buffer associated with the given file.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
@ GeneratePCH
Generate pre-compiled header.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
The JSON file list parser is used to communicate input to InstallAPI.
void ProcessWarningOptions(DiagnosticsEngine &Diags, const DiagnosticOptions &Opts, bool ReportDiags=true)
ProcessWarningOptions - Initialize the diagnostic client and process the warning options specified on...
std::error_code make_error_code(BuildPreambleError Error)
@ Result
The result type of a method or function.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
const FunctionProtoType * T
@ PCH
Disable validation for a precompiled header and the modules it depends on.
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, const llvm::MemoryBufferRef &Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
@ CouldntCreateTargetInfo
Describes the bounds (start, size) of the preamble and a flag required by PreprocessorOptions::Precom...
unsigned Size
Size of the preamble in bytes.
bool PreambleEndsAtStartOfLine
Whether the preamble ends at the start of a new line.