clang 20.0.0git
|
This class is used for tools that requires cross translation unit capability. More...
#include "clang/CrossTU/CrossTranslationUnit.h"
Public Member Functions | |
CrossTranslationUnitContext (CompilerInstance &CI) | |
~CrossTranslationUnitContext () | |
llvm::Expected< const FunctionDecl * > | getCrossTUDefinition (const FunctionDecl *FD, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false) |
This function loads a function or variable definition from an external AST file and merges it into the original AST. | |
llvm::Expected< const VarDecl * > | getCrossTUDefinition (const VarDecl *VD, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false) |
llvm::Expected< ASTUnit * > | loadExternalAST (StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false) |
This function loads a definition from an external AST file. | |
llvm::Expected< const FunctionDecl * > | importDefinition (const FunctionDecl *FD, ASTUnit *Unit) |
This function merges a definition from a separate AST Unit into the current one which was created by the compiler instance that was passed to the constructor. | |
llvm::Expected< const VarDecl * > | importDefinition (const VarDecl *VD, ASTUnit *Unit) |
void | emitCrossTUDiagnostics (const IndexError &IE) |
Emit diagnostics for the user for potential configuration errors. | |
std::optional< clang::MacroExpansionContext > | getMacroExpansionContextForSourceLocation (const clang::SourceLocation &ToLoc) const |
Returns the MacroExpansionContext for the imported TU to which the given source-location corresponds. | |
bool | isImportedAsNew (const Decl *ToDecl) const |
Returns true if the given Decl is newly created during the import. | |
bool | hasError (const Decl *ToDecl) const |
Returns true if the given Decl is mapped (or created) during an import but there was an unrecoverable error (the AST node cannot be erased, it is marked with an Error object in this case). | |
Static Public Member Functions | |
static std::optional< std::string > | getLookupName (const NamedDecl *ND) |
Get a name to identify a named decl. | |
This class is used for tools that requires cross translation unit capability.
This class can load definitions from external AST sources. The loaded definition will be merged back to the original AST using the AST Importer. In order to use this class, an index file is required that describes the locations of the AST files for each definition.
Note that this class also implements caching.
Definition at line 127 of file CrossTranslationUnit.h.
clang::cross_tu::CrossTranslationUnitContext::CrossTranslationUnitContext | ( | CompilerInstance & | CI | ) |
Definition at line 239 of file CrossTranslationUnit.cpp.
clang::cross_tu::CrossTranslationUnitContext::~CrossTranslationUnitContext | ( | ) |
Definition at line 242 of file CrossTranslationUnit.cpp.
void clang::cross_tu::CrossTranslationUnitContext::emitCrossTUDiagnostics | ( | const IndexError & | IE | ) |
Emit diagnostics for the user for potential configuration errors.
Definition at line 370 of file CrossTranslationUnit.cpp.
References clang::cross_tu::IndexError::getCode(), clang::ASTContext::getDiagnostics(), clang::cross_tu::IndexError::getFileName(), clang::cross_tu::IndexError::getLineNum(), clang::cross_tu::IndexError::getTripleFromName(), clang::cross_tu::IndexError::getTripleToName(), clang::cross_tu::invalid_index_format, clang::cross_tu::missing_index_file, clang::cross_tu::multiple_definitions, clang::DiagnosticsEngine::Report(), and clang::cross_tu::triple_mismatch.
llvm::Expected< const FunctionDecl * > clang::cross_tu::CrossTranslationUnitContext::getCrossTUDefinition | ( | const FunctionDecl * | FD, |
StringRef | CrossTUDir, | ||
StringRef | IndexName, | ||
bool | DisplayCTUProgress = false |
||
) |
This function loads a function or variable definition from an external AST file and merges it into the original AST.
This method should only be used on functions that have no definitions or variables that have no initializer in the current translation unit. A function definition with the same declaration will be looked up in the index file which should be in the CrossTUDir
directory, called IndexName
. In case the declaration is found in the index the corresponding AST will be loaded and the definition will be merged into the original AST using the AST Importer.
Note that the AST files should also be in the CrossTUDir
.
Definition at line 353 of file CrossTranslationUnit.cpp.
Referenced by clang::ento::AnyFunctionCall::getRuntimeDefinition().
llvm::Expected< const VarDecl * > clang::cross_tu::CrossTranslationUnitContext::getCrossTUDefinition | ( | const VarDecl * | VD, |
StringRef | CrossTUDir, | ||
StringRef | IndexName, | ||
bool | DisplayCTUProgress = false |
||
) |
Definition at line 362 of file CrossTranslationUnit.cpp.
|
static |
Get a name to identify a named decl.
Definition at line 245 of file CrossTranslationUnit.cpp.
References clang::index::generateUSRForDecl().
std::optional< clang::MacroExpansionContext > clang::cross_tu::CrossTranslationUnitContext::getMacroExpansionContextForSourceLocation | ( | const clang::SourceLocation & | ToLoc | ) | const |
Returns the MacroExpansionContext for the imported TU to which the given source-location corresponds.
ToLoc
Source location in the imported-to AST.
ToLoc
is a non-imported source-location, empty is returned. Definition at line 797 of file CrossTranslationUnit.cpp.
Referenced by getExpandedMacro().
Returns true if the given Decl is mapped (or created) during an import but there was an unrecoverable error (the AST node cannot be erased, it is marked with an Error object in this case).
Definition at line 809 of file CrossTranslationUnit.cpp.
Referenced by clang::ento::AnyFunctionCall::getRuntimeDefinition().
llvm::Expected< const FunctionDecl * > clang::cross_tu::CrossTranslationUnitContext::importDefinition | ( | const FunctionDecl * | FD, |
ASTUnit * | Unit | ||
) |
This function merges a definition from a separate AST Unit into the current one which was created by the compiler instance that was passed to the constructor.
Definition at line 764 of file CrossTranslationUnit.cpp.
llvm::Expected< const VarDecl * > clang::cross_tu::CrossTranslationUnitContext::importDefinition | ( | const VarDecl * | VD, |
ASTUnit * | Unit | ||
) |
Definition at line 770 of file CrossTranslationUnit.cpp.
Returns true if the given Decl is newly created during the import.
Definition at line 803 of file CrossTranslationUnit.cpp.
Referenced by clang::ento::AnyFunctionCall::getRuntimeDefinition().
llvm::Expected< ASTUnit * > clang::cross_tu::CrossTranslationUnitContext::loadExternalAST | ( | StringRef | LookupName, |
StringRef | CrossTUDir, | ||
StringRef | IndexName, | ||
bool | DisplayCTUProgress = false |
||
) |
This function loads a definition from an external AST file.
A definition with the same declaration will be looked up in the index file which should be in the CrossTUDir
directory, called IndexName
. In case the declaration is found in the index the corresponding AST will be loaded. If the number of TUs imported reaches CTULoadTreshold
, no loading is performed.
Note that the AST files should also be in the CrossTUDir
.
Definition at line 510 of file CrossTranslationUnit.cpp.
References clang::cross_tu::failed_to_get_external_ast.