clang 10.0.0git

Classes | Public Member Functions | Static Public Member Functions | List of all members
clang::cross_tu::CrossTranslationUnitContext Class Reference

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. More...
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. More...
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. More...
llvm::Expected< const VarDecl * > | importDefinition (const VarDecl *VD, ASTUnit *Unit)
void | emitCrossTUDiagnostics (const IndexError &IE)
| Emit diagnostics for the user for potential configuration errors. More...
llvm::Optional< std::pair< SourceLocation, ASTUnit * > > | getImportedFromSourceLocation (const clang::SourceLocation &ToLoc) const
| Determine the original source location in the original TU for an imported source location. More...

## Static Public Member Functions
static llvm::Optional< std::string > | getLookupName (const NamedDecl *ND)
| Get a name to identify a named decl. More...

## Detailed Description

This class is used for tools that requires cross translation unit capability.

This class can load definitions from external AST files. 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 106 of file CrossTranslationUnit.h.

## Constructor & Destructor Documentation

## ◆ CrossTranslationUnitContext()

clang::cross_tu::CrossTranslationUnitContext::CrossTranslationUnitContext | ( | CompilerInstance & | CI | ) |

Definition at line 190 of file CrossTranslationUnit.cpp.

## ◆ ~CrossTranslationUnitContext()

clang::cross_tu::CrossTranslationUnitContext::~CrossTranslationUnitContext | ( |  | ) |

Definition at line 193 of file CrossTranslationUnit.cpp.

## Member Function Documentation

## ◆ emitCrossTUDiagnostics()

void clang::cross_tu::CrossTranslationUnitContext::emitCrossTUDiagnostics | ( | const IndexError & | IE | ) |

Emit diagnostics for the user for potential configuration errors.

Definition at line 321 of file CrossTranslationUnit.cpp.

References clang::Error, clang::cross_tu::IndexError::getCode(), clang::ASTContext::getDiagnostics(), clang::cross_tu::IndexError::getFileName(), clang::CompilerInstance::getFileSystemOpts(), clang::cross_tu::IndexError::getLineNum(), clang::CompilerInstance::getPCHContainerOperations(), clang::cross_tu::IndexError::getTripleFromName(), clang::cross_tu::IndexError::getTripleToName(), clang::cross_tu::invalid_index_format, clang::cross_tu::load_threshold_reached, clang::ASTUnit::LoadEverything, clang::ASTUnit::LoadFromASTFile(), clang::cross_tu::missing_definition, clang::cross_tu::missing_index_file, clang::cross_tu::multiple_definitions, clang::cross_tu::parseCrossTUIndex(), clang::DiagnosticsEngine::Report(), and clang::cross_tu::triple_mismatch.

Referenced by clang::ento::AnyFunctionCall::getRuntimeDefinition().

## ◆ getCrossTUDefinition() [1/2]

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 file will be loaded and the definition will be merged into the original AST using the AST Importer.

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.

Note that the AST files should also be in the `CrossTUDir`.

Definition at line 304 of file CrossTranslationUnit.cpp.

Referenced by clang::ento::AnyFunctionCall::getRuntimeDefinition().

## ◆ getCrossTUDefinition() [2/2]

llvm::Expected< const VarDecl * > clang::cross_tu::CrossTranslationUnitContext::getCrossTUDefinition | ( | const VarDecl * | VD,
|  | StringRef | CrossTUDir,
|  | StringRef | IndexName,
|  | bool | DisplayCTUProgress = `false`
| ) |  |

Definition at line 313 of file CrossTranslationUnit.cpp.

## ◆ getImportedFromSourceLocation()

llvm::Optional< std::pair< SourceLocation, ASTUnit * > > clang::cross_tu::CrossTranslationUnitContext::getImportedFromSourceLocation | ( | const clang::SourceLocation & | ToLoc | ) | const

Determine the original source location in the original TU for an imported source location.

`ToLoc` Source location in the imported-to AST.

Returns
  Source location in the imported-from AST and the corresponding ASTUnit object (the AST was loaded from a file using an internal ASTUnit object that is returned here). If any error happens (ToLoc is a non-imported source location) empty is returned.

Definition at line 570 of file CrossTranslationUnit.cpp.

References clang::SourceManager::getComposedLoc(), clang::SourceManager::getDecomposedLoc(), clang::ASTUnit::getSourceManager(), clang::ASTContext::getSourceManager(), and SM.

## ◆ getLookupName()

llvm::Optional< std::string > clang::cross_tu::CrossTranslationUnitContext::getLookupName | ( | const NamedDecl * | ND | ) |
| static

Get a name to identify a named decl.

Definition at line 196 of file CrossTranslationUnit.cpp.

References clang::DeclContext::decls(), clang::cross_tu::failed_import, clang::cross_tu::failed_to_generate_usr, clang::index::generateUSRForDecl(), clang::ASTUnit::getASTContext(), clang::ASTUnit::getFileManager(), clang::SourceManager::getFileManager(), clang::ASTContext::getLangOpts(), clang::ASTUnit::getMainFileName(), clang::ASTContext::getSourceManager(), clang::ASTContext::getTargetInfo(), clang::ASTContext::getTranslationUnitDecl(), clang::TargetInfo::getTriple(), clang::cross_tu::hasBodyOrInit(), importDefinition(), clang::cross_tu::lang_dialect_mismatch, clang::cross_tu::lang_mismatch, loadExternalAST(), Ret(), and clang::cross_tu::triple_mismatch.

## ◆ importDefinition() [1/2]

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.

Returns
  Returns the resulting definition or an error.

Definition at line 532 of file CrossTranslationUnit.cpp.

Referenced by getLookupName().

## ◆ importDefinition() [2/2]

llvm::Expected< const VarDecl * > clang::cross_tu::CrossTranslationUnitContext::importDefinition | ( | const VarDecl * | VD,
|  | ASTUnit * | Unit
| ) |  |

Definition at line 538 of file CrossTranslationUnit.cpp.

References clang::ASTUnit::getASTContext(), clang::SourceManager::getFileManager(), clang::ASTContext::getSourceManager(), clang::ASTContext::getTranslationUnitDecl(), and clang::ASTImporter::setFileIDImportHandler().

## ◆ loadExternalAST()

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 file will be loaded. If the number of TUs imported reaches `CTULoadTreshold`, no loading is performed.

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.

Note that the AST files should also be in the `CrossTUDir`.

Definition at line 474 of file CrossTranslationUnit.cpp.

References clang::cross_tu::failed_import, clang::cross_tu::failed_to_get_external_ast, clang::ASTUnit::getASTContext(), clang::cross_tu::hasBodyOrInit(), clang::ImportError::NameConflict, clang::ImportError::Unknown, and clang::ImportError::UnsupportedConstruct.

Referenced by getLookupName().

The documentation for this class was generated from the following files:

- include/clang/CrossTU/CrossTranslationUnit.h
- lib/CrossTU/CrossTranslationUnit.cpp