class CrossTranslationUnitContext
Declaration
class CrossTranslationUnitContext { /* full declaration omitted */ };
Description
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.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:127
Member Variables
- private clang::cross_tu::CrossTranslationUnitContext:: ImporterMapTy ASTUnitImporterMap
- private clang::ASTContext& Context
- private clang::cross_tu::CrossTranslationUnitContext:: ASTUnitStorage ASTStorage
Method Overview
- public CrossTranslationUnitContext(clang::CompilerInstance & CI)
- public void emitCrossTUDiagnostics(const clang::cross_tu::IndexError & IE)
- private template <typename T>const T * findDefInDeclContext(const clang::DeclContext * DC, llvm::StringRef LookupName)
- public llvm::Expected<const FunctionDecl *> getCrossTUDefinition(const clang::FunctionDecl * FD, llvm::StringRef CrossTUDir, llvm::StringRef IndexName, bool DisplayCTUProgress = false)
- public llvm::Expected<const VarDecl *> getCrossTUDefinition(const clang::VarDecl * VD, llvm::StringRef CrossTUDir, llvm::StringRef IndexName, bool DisplayCTUProgress = false)
- private template <typename T>llvm::Expected<const T *> getCrossTUDefinitionImpl(const T * D, llvm::StringRef CrossTUDir, llvm::StringRef IndexName, bool DisplayCTUProgress)
- public static llvm::Optional<std::string> getLookupName(const clang::NamedDecl * ND)
- public llvm::Optional<clang::MacroExpansionContext> getMacroExpansionContextForSourceLocation(const clang::SourceLocation & ToLoc) const
- private clang::ASTImporter & getOrCreateASTImporter(clang::ASTUnit * Unit)
- public bool hasError(const clang::Decl * ToDecl) const
- public llvm::Expected<const FunctionDecl *> importDefinition(const clang::FunctionDecl * FD, clang::ASTUnit * Unit)
- public llvm::Expected<const VarDecl *> importDefinition(const clang::VarDecl * VD, clang::ASTUnit * Unit)
- private template <typename T>llvm::Expected<const T *> importDefinitionImpl(const T * D, clang::ASTUnit * Unit)
- public bool isImportedAsNew(const clang::Decl * ToDecl) const
- private void lazyInitImporterSharedSt(clang::TranslationUnitDecl * ToTU)
- public llvm::Expected<ASTUnit *> loadExternalAST(llvm::StringRef LookupName, llvm::StringRef CrossTUDir, llvm::StringRef IndexName, bool DisplayCTUProgress = false)
- public ~CrossTranslationUnitContext()
Methods
¶CrossTranslationUnitContext(
clang::CompilerInstance& CI)
CrossTranslationUnitContext(
clang::CompilerInstance& CI)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:129
Parameters
¶void emitCrossTUDiagnostics(
const clang::cross_tu::IndexError& IE)
void emitCrossTUDiagnostics(
const clang::cross_tu::IndexError& IE)
Description
Emit diagnostics for the user for potential configuration errors.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:187
Parameters
- const clang::cross_tu::IndexError& IE
¶template <typename T>
const T* findDefInDeclContext(
const clang::DeclContext* DC,
llvm::StringRef LookupName)
template <typename T>
const T* findDefInDeclContext(
const clang::DeclContext* DC,
llvm::StringRef LookupName)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:217
Templates
- T
Parameters
- const clang::DeclContext* DC
- llvm::StringRef LookupName
¶llvm::Expected<const FunctionDecl*>
getCrossTUDefinition(
const clang::FunctionDecl* FD,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress = false)
llvm::Expected<const FunctionDecl*>
getCrossTUDefinition(
const clang::FunctionDecl* FD,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress = false)
Description
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\p CrossTUDir directory, called \p 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 \p CrossTUDir.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:149
Parameters
- const clang::FunctionDecl* FD
- llvm::StringRef CrossTUDir
- llvm::StringRef IndexName
- bool DisplayCTUProgress = false
Returns
The declaration with the definition will be returned. If no suitable definition is found in the index file or multiple definitions found error will be returned.
¶llvm::Expected<const VarDecl*>
getCrossTUDefinition(
const clang::VarDecl* VD,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress = false)
llvm::Expected<const VarDecl*>
getCrossTUDefinition(
const clang::VarDecl* VD,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress = false)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:152
Parameters
- const clang::VarDecl* VD
- llvm::StringRef CrossTUDir
- llvm::StringRef IndexName
- bool DisplayCTUProgress = false
¶template <typename T>
llvm::Expected<const T*> getCrossTUDefinitionImpl(
const T* D,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress)
template <typename T>
llvm::Expected<const T*> getCrossTUDefinitionImpl(
const T* D,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:212
Templates
- T
Parameters
- const T* D
- llvm::StringRef CrossTUDir
- llvm::StringRef IndexName
- bool DisplayCTUProgress
¶static llvm::Optional<std::string> getLookupName(
const clang::NamedDecl* ND)
static llvm::Optional<std::string> getLookupName(
const clang::NamedDecl* ND)
Description
Get a name to identify a named decl.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:184
Parameters
- const clang::NamedDecl* ND
¶llvm::Optional<clang::MacroExpansionContext>
getMacroExpansionContextForSourceLocation(
const clang::SourceLocation& ToLoc) const
llvm::Optional<clang::MacroExpansionContext>
getMacroExpansionContextForSourceLocation(
const clang::SourceLocation& ToLoc) const
Description
Returns the MacroExpansionContext for the imported TU to which the given source-location corresponds.\p ToLoc Source location in the imported-to AST.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:197
Parameters
- const clang::SourceLocation& ToLoc
¶clang::ASTImporter& getOrCreateASTImporter(
clang::ASTUnit* Unit)
clang::ASTImporter& getOrCreateASTImporter(
clang::ASTUnit* Unit)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:210
Parameters
- clang::ASTUnit* Unit
¶bool hasError(const clang::Decl* ToDecl) const
bool hasError(const clang::Decl* ToDecl) const
Description
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).
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:206
Parameters
- const clang::Decl* ToDecl
¶llvm::Expected<const FunctionDecl*>
importDefinition(const clang::FunctionDecl* FD,
clang::ASTUnit* Unit)
llvm::Expected<const FunctionDecl*>
importDefinition(const clang::FunctionDecl* FD,
clang::ASTUnit* Unit)
Description
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.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:178
Parameters
- const clang::FunctionDecl* FD
- clang::ASTUnit* Unit
Returns
Returns the resulting definition or an error.
¶llvm::Expected<const VarDecl*> importDefinition(
const clang::VarDecl* VD,
clang::ASTUnit* Unit)
llvm::Expected<const VarDecl*> importDefinition(
const clang::VarDecl* VD,
clang::ASTUnit* Unit)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:180
Parameters
- const clang::VarDecl* VD
- clang::ASTUnit* Unit
¶template <typename T>
llvm::Expected<const T*> importDefinitionImpl(
const T* D,
clang::ASTUnit* Unit)
template <typename T>
llvm::Expected<const T*> importDefinitionImpl(
const T* D,
clang::ASTUnit* Unit)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:220
Templates
- T
Parameters
- const T* D
- clang::ASTUnit* Unit
¶bool isImportedAsNew(
const clang::Decl* ToDecl) const
bool isImportedAsNew(
const clang::Decl* ToDecl) const
Description
Returns true if the given Decl is newly created during the import.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:201
Parameters
- const clang::Decl* ToDecl
¶void lazyInitImporterSharedSt(
clang::TranslationUnitDecl* ToTU)
void lazyInitImporterSharedSt(
clang::TranslationUnitDecl* ToTU)
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:209
Parameters
¶llvm::Expected<ASTUnit*> loadExternalAST(
llvm::StringRef LookupName,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress = false)
llvm::Expected<ASTUnit*> loadExternalAST(
llvm::StringRef LookupName,
llvm::StringRef CrossTUDir,
llvm::StringRef IndexName,
bool DisplayCTUProgress = false)
Description
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 \p CrossTUDir directory, called\p IndexName. In case the declaration is found in the index the corresponding AST will be loaded. If the number of TUs imported reaches \p CTULoadTreshold, no loading is performed. Note that the AST files should also be in the \p CrossTUDir.
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:168
Parameters
- llvm::StringRef LookupName
- llvm::StringRef CrossTUDir
- llvm::StringRef IndexName
- bool DisplayCTUProgress = false
Returns
Returns a pointer to the ASTUnit that contains the definition of the looked up name or an Error. The returned pointer is never a nullptr.
¶~CrossTranslationUnitContext()
~CrossTranslationUnitContext()
Declared at: clang/include/clang/CrossTU/CrossTranslationUnit.h:130