clang 18.0.0git
|
Utility class for loading a ASTContext from an AST file. More...
#include "clang/Frontend/ASTUnit.h"
Classes | |
struct | ASTWriterData |
struct | CachedCodeCompletionResult |
A cached code-completion result, which may be introduced in one of many different contexts. More... | |
class | ConcurrencyCheck |
struct | StandaloneDiagnostic |
struct | StandaloneFixIt |
Public Types | |
enum | WhatToLoad { LoadPreprocessorOnly , LoadASTOnly , LoadEverything } |
using | top_level_iterator = std::vector< Decl * >::iterator |
using | stored_diag_iterator = StoredDiagnostic * |
using | stored_diag_const_iterator = const StoredDiagnostic * |
using | cached_completion_iterator = std::vector< CachedCodeCompletionResult >::iterator |
using | DeclVisitorFn = bool(*)(void *context, const Decl *D) |
Type for a function iterating over a number of declarations. | |
using | RemappedFile = std::pair< std::string, llvm::MemoryBuffer * > |
A mapping from a file name to the memory buffer that stores the remapped contents of that file. | |
Public Member Functions | |
llvm::StringMap< unsigned > & | getCachedCompletionTypes () |
Retrieve the mapping from formatted type names to unique type identifiers. | |
std::shared_ptr< GlobalCodeCompletionAllocator > | getCachedCompletionAllocator () |
Retrieve the allocator used to cache global code completions. | |
CodeCompletionTUInfo & | getCodeCompletionTUInfo () |
ASTUnit (const ASTUnit &)=delete | |
ASTUnit & | operator= (const ASTUnit &)=delete |
~ASTUnit () | |
bool | isMainFileAST () const |
bool | isUnsafeToFree () const |
void | setUnsafeToFree (bool Value) |
const DiagnosticsEngine & | getDiagnostics () const |
DiagnosticsEngine & | getDiagnostics () |
const SourceManager & | getSourceManager () const |
SourceManager & | getSourceManager () |
const Preprocessor & | getPreprocessor () const |
Preprocessor & | getPreprocessor () |
std::shared_ptr< Preprocessor > | getPreprocessorPtr () const |
const ASTContext & | getASTContext () const |
ASTContext & | getASTContext () |
void | setASTContext (ASTContext *ctx) |
void | setPreprocessor (std::shared_ptr< Preprocessor > pp) |
void | enableSourceFileDiagnostics () |
Enable source-range based diagnostic messages. | |
bool | hasSema () const |
Sema & | getSema () const |
const LangOptions & | getLangOpts () const |
const HeaderSearchOptions & | getHeaderSearchOpts () const |
const PreprocessorOptions & | getPreprocessorOpts () const |
const FileManager & | getFileManager () const |
FileManager & | getFileManager () |
const FileSystemOptions & | getFileSystemOpts () const |
IntrusiveRefCntPtr< ASTReader > | getASTReader () const |
StringRef | getOriginalSourceFileName () const |
ASTMutationListener * | getASTMutationListener () |
ASTDeserializationListener * | getDeserializationListener () |
bool | getOnlyLocalDecls () const |
bool | getOwnsRemappedFileBuffers () const |
void | setOwnsRemappedFileBuffers (bool val) |
StringRef | getMainFileName () const |
StringRef | getASTFileName () const |
If this ASTUnit came from an AST file, returns the filename for it. | |
top_level_iterator | top_level_begin () |
top_level_iterator | top_level_end () |
std::size_t | top_level_size () const |
bool | top_level_empty () const |
void | addTopLevelDecl (Decl *D) |
Add a new top-level declaration. | |
void | addFileLevelDecl (Decl *D) |
Add a new local file-level declaration. | |
void | findFileRegionDecls (FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls) |
Get the decls that are contained in a file in the Offset/Length range. | |
unsigned & | getCurrentTopLevelHashValue () |
Retrieve a reference to the current top-level name hash value. | |
SourceLocation | getLocation (const FileEntry *File, unsigned Line, unsigned Col) const |
Get the source location for the given file:line:col triplet. | |
SourceLocation | getLocation (const FileEntry *File, unsigned Offset) const |
Get the source location for the given file:offset pair. | |
SourceLocation | mapLocationFromPreamble (SourceLocation Loc) const |
If Loc is a loaded location from the preamble, returns the corresponding local location of the main file, otherwise it returns Loc . | |
SourceLocation | mapLocationToPreamble (SourceLocation Loc) const |
If Loc is a local location of the main file but inside the preamble chunk, returns the corresponding loaded location from the preamble, otherwise it returns Loc . | |
bool | isInPreambleFileID (SourceLocation Loc) const |
bool | isInMainFileID (SourceLocation Loc) const |
SourceLocation | getStartOfMainFileID () const |
SourceLocation | getEndOfPreambleFileID () const |
SourceRange | mapRangeFromPreamble (SourceRange R) const |
SourceRange | mapRangeToPreamble (SourceRange R) const |
unsigned | getPreambleCounterForTests () const |
stored_diag_const_iterator | stored_diag_begin () const |
stored_diag_iterator | stored_diag_begin () |
stored_diag_const_iterator | stored_diag_end () const |
stored_diag_iterator | stored_diag_end () |
unsigned | stored_diag_size () const |
stored_diag_iterator | stored_diag_afterDriver_begin () |
cached_completion_iterator | cached_completion_begin () |
cached_completion_iterator | cached_completion_end () |
unsigned | cached_completion_size () const |
llvm::iterator_range< PreprocessingRecord::iterator > | getLocalPreprocessingEntities () const |
Returns an iterator range for the local preprocessing entities of the local Preprocessor, if this is a parsed source file, or the loaded preprocessing entities of the primary module if this is an AST file. | |
bool | visitLocalTopLevelDecls (void *context, DeclVisitorFn Fn) |
Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declarations of the primary module if this is an AST file). | |
OptionalFileEntryRef | getPCHFile () |
Get the PCH file if one was included. | |
bool | isModuleFile () const |
Returns true if the ASTUnit was constructed from a serialized module file. | |
std::unique_ptr< llvm::MemoryBuffer > | getBufferForFile (StringRef Filename, std::string *ErrorStr=nullptr) |
TranslationUnitKind | getTranslationUnitKind () const |
Determine what kind of translation unit this AST represents. | |
InputKind | getInputKind () const |
Determine the input kind this AST unit represents. | |
bool | Reparse (std::shared_ptr< PCHContainerOperations > PCHContainerOps, ArrayRef< RemappedFile > RemappedFiles=std::nullopt, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr) |
Reparse the source files using the same command-line options that were originally used to produce this translation unit. | |
void | ResetForParse () |
Free data that will be re-generated on the next parse. | |
void | CodeComplete (StringRef File, unsigned Line, unsigned Column, ArrayRef< RemappedFile > RemappedFiles, bool IncludeMacros, bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SmallVectorImpl< const llvm::MemoryBuffer * > &OwnedBuffers, std::unique_ptr< SyntaxOnlyAction > Act=nullptr) |
Perform code completion at the given file, line, and column within this translation unit. | |
bool | Save (StringRef File) |
Save this translation unit to a file with the given name. | |
bool | serialize (raw_ostream &OS) |
Serialize this translation unit with the given output stream. | |
Static Public Member Functions | |
static std::unique_ptr< ASTUnit > | create (std::shared_ptr< CompilerInvocation > CI, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile) |
Create a ASTUnit. Gets ownership of the passed CompilerInvocation. | |
static std::unique_ptr< ASTUnit > | LoadFromASTFile (const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, std::shared_ptr< HeaderSearchOptions > HSOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowASTWithCompilerErrors=false, bool UserFilesAreVolatile=false, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=llvm::vfs::getRealFileSystem()) |
Create a ASTUnit from an AST file. | |
static ASTUnit * | LoadFromCompilerInvocationAction (std::shared_ptr< CompilerInvocation > CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, FrontendAction *Action=nullptr, ASTUnit *Unit=nullptr, bool Persistent=true, StringRef ResourceFilesPath=StringRef(), bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, unsigned PrecompilePreambleAfterNParses=0, bool CacheCodeCompletionResults=false, bool UserFilesAreVolatile=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr) |
Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally provided ASTFrontendAction. | |
static std::unique_ptr< ASTUnit > | LoadFromCompilerInvocation (std::shared_ptr< CompilerInvocation > CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, FileManager *FileMgr, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, unsigned PrecompilePreambleAfterNParses=0, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool UserFilesAreVolatile=false) |
LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a CompilerInvocation object. | |
static std::unique_ptr< ASTUnit > | LoadFromCommandLine (const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool StorePreamblesInMemory=false, StringRef PreambleStoragePath=StringRef(), bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, ArrayRef< RemappedFile > RemappedFiles=std::nullopt, bool RemappedFilesKeepOriginalName=true, unsigned PrecompilePreambleAfterNParses=0, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, SkipFunctionBodiesScope SkipFunctionBodies=SkipFunctionBodiesScope::None, bool SingleFileParse=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, bool RetainExcludedConditionalBlocks=false, std::optional< StringRef > ModuleFormat=std::nullopt, std::unique_ptr< ASTUnit > *ErrAST=nullptr, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr) |
LoadFromCommandLine - Create an ASTUnit from a vector of command line arguments, which must specify exactly one source file. | |
Friends | |
class | ConcurrencyCheck |
Utility class for loading a ASTContext from an AST file.
using clang::ASTUnit::cached_completion_iterator = std::vector<CachedCodeCompletionResult>::iterator |
using clang::ASTUnit::DeclVisitorFn = bool (*)(void *context, const Decl *D) |
using clang::ASTUnit::RemappedFile = std::pair<std::string, llvm::MemoryBuffer *> |
using clang::ASTUnit::stored_diag_const_iterator = const StoredDiagnostic * |
using clang::ASTUnit::top_level_iterator = std::vector<Decl *>::iterator |
|
delete |
ASTUnit::~ASTUnit | ( | ) |
Definition at line 249 of file ASTUnit.cpp.
References ActiveASTUnitObjects, clang::DiagnosticConsumer::EndSourceFile(), clang::DiagnosticsEngine::getClient(), getDiagnostics(), and clang::PreprocessorOptions::RemappedFileBuffers.
void ASTUnit::addFileLevelDecl | ( | Decl * | D | ) |
Add a new local file-level declaration.
Definition at line 2434 of file ASTUnit.cpp.
References clang::Decl::getLexicalDeclContext(), clang::Decl::getLocation(), clang::DeclContext::isFileContext(), clang::Decl::isFromASTFile(), clang::FileID::isInvalid(), clang::SourceLocation::isInvalid(), and SM.
|
inline |
|
inline |
|
inline |
|
inline |
void ASTUnit::CodeComplete | ( | StringRef | File, |
unsigned | Line, | ||
unsigned | Column, | ||
ArrayRef< RemappedFile > | RemappedFiles, | ||
bool | IncludeMacros, | ||
bool | IncludeCodePatterns, | ||
bool | IncludeBriefComments, | ||
CodeCompleteConsumer & | Consumer, | ||
std::shared_ptr< PCHContainerOperations > | PCHContainerOps, | ||
DiagnosticsEngine & | Diag, | ||
LangOptions & | LangOpts, | ||
SourceManager & | SourceMgr, | ||
FileManager & | FileMgr, | ||
SmallVectorImpl< StoredDiagnostic > & | StoredDiagnostics, | ||
SmallVectorImpl< const llvm::MemoryBuffer * > & | OwnedBuffers, | ||
std::unique_ptr< SyntaxOnlyAction > | Act = nullptr |
||
) |
Perform code completion at the given file, line, and column within this translation unit.
File | The file in which code completion will occur. |
Line | The line at which code completion will occur. |
Column | The column at which code completion will occur. |
IncludeMacros | Whether to include macros in the code-completion results. |
IncludeCodePatterns | Whether to include code patterns (such as a for loop) in the code-completion results. |
IncludeBriefComments | Whether to include brief documentation within the set of code completions returned. |
Act | If supplied, this argument is used to parse the input file, allowing customized parsing by overriding SyntaxOnlyAction lifecycle methods. |
FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and OwnedBuffers parameters are all disgusting hacks. They will go away.
Definition at line 2167 of file ASTUnit.cpp.
References clang::PreprocessorOptions::addRemappedFile(), clang::All, clang::PreprocessorOptions::clearRemappedFiles(), clang::FrontendOptions::CodeCompleteOpts, clang::FrontendOptions::CodeCompletionAt, clang::ParsedSourceLocation::Column, clang::PreprocessorOptions::DetailedRecord, Diag(), clang::File, clang::ParsedSourceLocation::FileName, Filename, clang::FileManager::getVirtualFileSystem(), clang::CodeCompleteOptions::IncludeBriefComments, clang::CodeCompleteOptions::IncludeCodePatterns, clang::CodeCompleteConsumer::includeFixIts(), clang::CodeCompleteOptions::IncludeFixIts, clang::CodeCompleteOptions::IncludeGlobals, clang::CodeCompleteOptions::IncludeMacros, clang::ParsedSourceLocation::Line, clang::LLVM_IR, clang::CodeCompleteConsumer::loadExternal(), clang::CodeCompleteOptions::LoadExternal, clang::PreprocessorOptions::PrecompiledPreambleBytes, clang::ProcessWarningOptions(), clang::PreprocessorOptions::RetainRemappedFileBuffers, and clang::InputKind::Source.
|
static |
Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
Definition at line 1518 of file ASTUnit.cpp.
References clang::createVFSFromCompilerInvocation().
Referenced by LoadFromCompilerInvocationAction().
void ASTUnit::enableSourceFileDiagnostics | ( | ) |
Enable source-range based diagnostic messages.
If diagnostic messages with source-range information are to be expected and AST comes not from file (e.g. after LoadFromCompilerInvocation) this function has to be called. The function is to be called only once and the AST should be associated with the same source file afterwards.
Definition at line 277 of file ASTUnit.cpp.
References clang::DiagnosticConsumer::BeginSourceFile(), clang::DiagnosticsEngine::getClient(), and getDiagnostics().
void ASTUnit::findFileRegionDecls | ( | FileID | File, |
unsigned | Offset, | ||
unsigned | Length, | ||
SmallVectorImpl< Decl * > & | Decls | ||
) |
Get the decls that are contained in a file in the Offset/Length range.
Length
can be 0 to indicate a point at Offset
instead of a range.
Definition at line 2475 of file ASTUnit.cpp.
References clang::File, and clang::SourceManager::isLoadedFileID().
|
inline |
|
inline |
Definition at line 441 of file ASTUnit.h.
Referenced by clang::index::indexASTUnit().
StringRef ASTUnit::getASTFileName | ( | ) | const |
If this ASTUnit came from an AST file, returns the filename for it.
Definition at line 1508 of file ASTUnit.cpp.
References clang::serialization::ModuleFile::FileName, and isMainFileAST().
ASTMutationListener * ASTUnit::getASTMutationListener | ( | ) |
Definition at line 755 of file ASTUnit.cpp.
IntrusiveRefCntPtr< ASTReader > ASTUnit::getASTReader | ( | ) | const |
Definition at line 751 of file ASTUnit.cpp.
Referenced by clang::DumpModuleInfoAction::ExecuteAction().
std::unique_ptr< llvm::MemoryBuffer > ASTUnit::getBufferForFile | ( | StringRef | Filename, |
std::string * | ErrorStr = nullptr |
||
) |
Definition at line 768 of file ASTUnit.cpp.
References Filename.
|
inline |
|
inline |
|
inline |
|
inline |
Retrieve a reference to the current top-level name hash value.
Note: This is used internally by the top-level tracking action
Definition at line 545 of file ASTUnit.h.
Referenced by LoadFromCompilerInvocationAction().
ASTDeserializationListener * ASTUnit::getDeserializationListener | ( | ) |
Definition at line 761 of file ASTUnit.cpp.
|
inline |
|
inline |
Definition at line 431 of file ASTUnit.h.
Referenced by enableSourceFileDiagnostics(), LoadFromCompilerInvocationAction(), Reparse(), serialize(), and ~ASTUnit().
SourceLocation ASTUnit::getEndOfPreambleFileID | ( | ) | const |
Definition at line 2596 of file ASTUnit.cpp.
References clang::SourceManager::getLocForEndOfFile(), clang::SourceManager::getPreambleFileID(), and clang::FileID::isInvalid().
|
inline |
|
inline |
Definition at line 478 of file ASTUnit.h.
Referenced by LoadFromCompilerInvocationAction().
|
inline |
|
inline |
Definition at line 468 of file ASTUnit.h.
Referenced by LoadFromCompilerInvocationAction().
InputKind ASTUnit::getInputKind | ( | ) | const |
Determine the input kind this AST unit represents.
Definition at line 2687 of file ASTUnit.cpp.
References clang::C, clang::LangOptions::CMK_ModuleMap, clang::CUDA, clang::CXX, getLangOpts(), clang::InputKind::ModuleMap, clang::ObjC, clang::ObjCXX, clang::OpenCL, clang::RenderScript, and clang::InputKind::Source.
|
inline |
Definition at line 463 of file ASTUnit.h.
Referenced by clang::DumpModuleInfoAction::ExecuteAction(), getInputKind(), and isModuleFile().
llvm::iterator_range< PreprocessingRecord::iterator > ASTUnit::getLocalPreprocessingEntities | ( | ) | const |
Returns an iterator range for the local preprocessing entities of the local Preprocessor, if this is a parsed source file, or the loaded preprocessing entities of the primary module if this is an AST file.
Definition at line 2619 of file ASTUnit.cpp.
References clang::Preprocessor::getPreprocessingRecord(), and isMainFileAST().
SourceLocation ASTUnit::getLocation | ( | const FileEntry * | File, |
unsigned | Line, | ||
unsigned | Col | ||
) | const |
Get the source location for the given file:line:col triplet.
The difference with SourceManager::getLocation is that this method checks whether the requested location points inside the precompiled preamble in which case the returned source location will be a "loaded" one.
Definition at line 2518 of file ASTUnit.cpp.
References clang::File, getSourceManager(), and SM.
SourceLocation ASTUnit::getLocation | ( | const FileEntry * | File, |
unsigned | Offset | ||
) | const |
Get the source location for the given file:offset pair.
Definition at line 2525 of file ASTUnit.cpp.
References clang::File, clang::SourceLocation::getLocWithOffset(), getSourceManager(), and SM.
StringRef ASTUnit::getMainFileName | ( | ) | const |
Definition at line 1490 of file ASTUnit.cpp.
References clang::FrontendInputFile::getBuffer(), clang::FrontendInputFile::getFile(), clang::SourceManager::getFileEntryRefForID(), clang::SourceManager::getMainFileID(), and clang::FrontendInputFile::isFile().
Referenced by Reparse().
|
inline |
|
inline |
OptionalFileEntryRef ASTUnit::getPCHFile | ( | ) |
Get the PCH file if one was included.
Definition at line 2655 of file ASTUnit.cpp.
References clang::serialization::ModuleFile::File, and clang::serialization::ModuleFile::Kind.
|
inline |
|
inline |
|
inline |
Definition at line 437 of file ASTUnit.h.
Referenced by clang::index::indexASTUnit().
|
inline |
|
inline |
Definition at line 439 of file ASTUnit.h.
Referenced by clang::index::indexASTUnit().
|
inline |
Definition at line 458 of file ASTUnit.h.
Referenced by serialize().
|
inline |
|
inline |
Definition at line 434 of file ASTUnit.h.
Referenced by getLocation(), and LoadFromCompilerInvocationAction().
SourceLocation ASTUnit::getStartOfMainFileID | ( | ) | const |
Definition at line 2607 of file ASTUnit.cpp.
References clang::SourceManager::getLocForStartOfFile(), clang::SourceManager::getMainFileID(), and clang::FileID::isInvalid().
|
inline |
bool ASTUnit::isInMainFileID | ( | SourceLocation | Loc | ) | const |
Definition at line 2585 of file ASTUnit.cpp.
References clang::SourceManager::getMainFileID(), clang::SourceManager::isInFileID(), clang::FileID::isInvalid(), and clang::SourceLocation::isInvalid().
bool ASTUnit::isInPreambleFileID | ( | SourceLocation | Loc | ) | const |
Definition at line 2574 of file ASTUnit.cpp.
References clang::SourceManager::getPreambleFileID(), clang::SourceManager::isInFileID(), clang::FileID::isInvalid(), and clang::SourceLocation::isInvalid().
|
inline |
Definition at line 426 of file ASTUnit.h.
Referenced by getASTFileName(), getLocalPreprocessingEntities(), isModuleFile(), top_level_begin(), top_level_empty(), top_level_end(), top_level_size(), and visitLocalTopLevelDecls().
bool ASTUnit::isModuleFile | ( | ) | const |
Returns true if the ASTUnit was constructed from a serialized module file.
Definition at line 2683 of file ASTUnit.cpp.
References getLangOpts(), clang::LangOptions::isCompilingModule(), and isMainFileAST().
|
static |
Create a ASTUnit from an AST file.
Filename | - The AST file to load. |
PCHContainerRdr | - The PCHContainerOperations to use for loading and creating modules. |
Diags | - The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit. |
Definition at line 789 of file ASTUnit.cpp.
References clang::All, clang::ASTReader::ARR_None, clang::ASTReader::ConfigurationMismatch, clang::ASTReader::Failure, Filename, clang::Preprocessor::getBuiltinInfo(), clang::PCHContainerReader::getFormats(), clang::Preprocessor::getIdentifierTable(), clang::Preprocessor::getLangOpts(), clang::Preprocessor::getSelectorTable(), clang::ASTReader::HadErrors, clang::Module::isModulePurview(), LoadASTOnly, LoadEverything, clang::HeaderSearch::lookupModule(), clang::ASTReader::Missing, clang::serialization::MK_MainFile, clang::None, clang::ASTReader::OutOfDate, clang::Preprocessor::setCounterValue(), clang::ASTReader::Success, and clang::ASTReader::VersionMismatch.
Referenced by clang::FrontendAction::BeginSourceFile(), and clang::ASTMergeAction::ExecuteAction().
|
static |
LoadFromCommandLine - Create an ASTUnit from a vector of command line arguments, which must specify exactly one source file.
ArgBegin | - The beginning of the argument vector. |
ArgEnd | - The end of the argument vector. |
PCHContainerOps | - The PCHContainerOperations to use for loading and creating modules. |
Diags | - The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit. |
ResourceFilesPath | - The path to the compiler resource files. |
StorePreamblesInMemory | - Whether to store PCH in memory. If false, PCH are stored in temporary files. |
PreambleStoragePath | - The path to a directory, in which to create temporary PCH files. If empty, the default system temporary directory is used. This parameter is ignored if StorePreamblesInMemory is true. |
ModuleFormat | - If provided, uses the specific module format. |
ErrAST | - If non-null and parsing failed without any AST to return (e.g. because the PCH could not be loaded), this accepts the ASTUnit mainly to allow the caller to see the diagnostics. |
VFS | - A llvm::vfs::FileSystem to be used for all file accesses. Note that preamble is saved to a temporary directory on a RealFileSystem, so in order for it to be loaded correctly, VFS should have access to it(i.e., be an overlay over RealFileSystem). RealFileSystem will be used if VFS is nullptr. |
Definition at line 1746 of file ASTUnit.cpp.
References clang::PreprocessorOptions::AllowPCHWithCompilerErrors, clang::createInvocation(), clang::createVFSFromCompilerInvocation(), clang::CreateInvocationOptions::Diags, clang::PreambleAndMainFile, clang::CreateInvocationOptions::ProbePrecompiled, clang::PreprocessorOptions::RemappedFilesKeepOriginalName, clang::PreprocessorOptions::RetainExcludedConditionalBlocks, clang::PreprocessorOptions::SingleFileParseMode, and clang::CreateInvocationOptions::VFS.
|
static |
LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a CompilerInvocation object.
CI | - The compiler invocation to use; it must have exactly one input source file. The ASTUnit takes ownership of the CompilerInvocation object. |
PCHContainerOps | - The PCHContainerOperations to use for loading and creating modules. |
Diags | - The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit. |
Definition at line 1709 of file ASTUnit.cpp.
References clang::FileManager::getFileSystemOpts().
|
static |
Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally provided ASTFrontendAction.
CI | - The compiler invocation to use; it must have exactly one input source file. The ASTUnit takes ownership of the CompilerInvocation object. |
PCHContainerOps | - The PCHContainerOperations to use for loading and creating modules. |
Diags | - The diagnostics engine to use for reporting errors; its lifetime is expected to extend past that of the returned ASTUnit. |
Action | - The ASTFrontendAction to invoke. Its ownership is not transferred. |
Unit | - optionally an already created ASTUnit. Its ownership is not transferred. |
Persistent | - if true the returned ASTUnit will be complete. false means the caller is only interested in getting info through the provided |
ErrAST | - If non-null and parsing failed without any AST to return (e.g. because the PCH could not be loaded), this accepts the ASTUnit mainly to allow the caller to see the diagnostics. This will only receive an ASTUnit if a new one was created. If an already created ASTUnit was passed in Unit then the caller can check that. |
Definition at line 1538 of file ASTUnit.cpp.
References clang::FrontendAction::BeginSourceFile(), create(), clang::FrontendAction::EndSourceFile(), clang::FrontendAction::Execute(), getCurrentTopLevelHashValue(), getDiagnostics(), getFileManager(), getHeaderSearchOpts(), getSourceManager(), clang::FrontendAction::getTranslationUnitKind(), clang::LLVM_IR, clang::ProcessWarningOptions(), clang::HeaderSearchOptions::ResourceDir, clang::InputKind::Source, and clang::TU_Complete.
Referenced by clang::arcmt::MigrationProcess::applyTransform(), clang::arcmt::checkForManualIssues(), and clang::codeComplete().
SourceLocation ASTUnit::mapLocationFromPreamble | ( | SourceLocation | Loc | ) | const |
If Loc
is a loaded location from the preamble, returns the corresponding local location of the main file, otherwise it returns Loc
.
If.
Definition at line 2535 of file ASTUnit.cpp.
References clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), clang::SourceManager::getMainFileID(), clang::SourceManager::getPreambleFileID(), clang::SourceManager::isInFileID(), clang::FileID::isInvalid(), and clang::SourceLocation::isInvalid().
Referenced by mapRangeFromPreamble().
SourceLocation ASTUnit::mapLocationToPreamble | ( | SourceLocation | Loc | ) | const |
If Loc
is a local location of the main file but inside the preamble chunk, returns the corresponding loaded location from the preamble, otherwise it returns Loc
.
If.
Definition at line 2556 of file ASTUnit.cpp.
References clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), clang::SourceManager::getMainFileID(), clang::SourceManager::getPreambleFileID(), clang::SourceManager::isInFileID(), clang::FileID::isInvalid(), and clang::SourceLocation::isInvalid().
Referenced by mapRangeToPreamble().
|
inline |
Definition at line 574 of file ASTUnit.h.
References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), and mapLocationFromPreamble().
|
inline |
Definition at line 580 of file ASTUnit.h.
References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), and mapLocationToPreamble().
bool ASTUnit::Reparse | ( | std::shared_ptr< PCHContainerOperations > | PCHContainerOps, |
ArrayRef< RemappedFile > | RemappedFiles = std::nullopt , |
||
IntrusiveRefCntPtr< llvm::vfs::FileSystem > | VFS = nullptr |
||
) |
Reparse the source files using the same command-line options that were originally used to produce this translation unit.
VFS | - A llvm::vfs::FileSystem to be used for all file accesses. Note that preamble is saved to a temporary directory on a RealFileSystem, so in order for it to be loaded correctly, VFS should give an access to this(i.e. be an overlay over RealFileSystem). FileMgr->getVirtualFileSystem() will be used if VFS is nullptr. |
Definition at line 1852 of file ASTUnit.cpp.
References getDiagnostics(), getMainFileName(), clang::ProcessWarningOptions(), clang::PreprocessorOptions::RemappedFileBuffers, clang::DiagnosticsEngine::Reset(), clang::Result, and clang::DiagnosticsEngine::setNumWarnings().
void ASTUnit::ResetForParse | ( | ) |
Free data that will be re-generated on the next parse.
Preamble-related data is not affected.
Definition at line 1910 of file ASTUnit.cpp.
bool ASTUnit::Save | ( | StringRef | File | ) |
Save this translation unit to a file with the given name.
Definition at line 2324 of file ASTUnit.cpp.
References clang::File, and serialize().
bool ASTUnit::serialize | ( | raw_ostream & | OS | ) |
Serialize this translation unit with the given output stream.
Definition at line 2358 of file ASTUnit.cpp.
References getDiagnostics(), getSema(), clang::DiagnosticsEngine::hasUncompilableErrorOccurred(), and serializeUnit().
Referenced by Save().
|
inline |
|
inline |
void ASTUnit::setPreprocessor | ( | std::shared_ptr< Preprocessor > | pp | ) |
Definition at line 273 of file ASTUnit.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 504 of file ASTUnit.h.
References isMainFileAST().
Referenced by visitLocalTopLevelDecls().
|
inline |
Definition at line 523 of file ASTUnit.h.
References isMainFileAST().
|
inline |
Definition at line 511 of file ASTUnit.h.
References isMainFileAST().
Referenced by visitLocalTopLevelDecls().
|
inline |
Definition at line 518 of file ASTUnit.h.
References isMainFileAST().
bool ASTUnit::visitLocalTopLevelDecls | ( | void * | context, |
DeclVisitorFn | Fn | ||
) |
Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declarations of the primary module if this is an AST file).
Definition at line 2633 of file ASTUnit.cpp.
References isMainFileAST(), top_level_begin(), and top_level_end().
Referenced by indexTranslationUnit().
|
friend |