clang 20.0.0git
Classes | Typedefs | Enumerations | Functions
clang::cross_tu Namespace Reference

Classes

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

Typedefs

using InvocationListTy = llvm::StringMap< llvm::SmallVector< std::string, 32 > >
 

Enumerations

enum class  index_error_code {
  success = 0 , unspecified = 1 , missing_index_file , invalid_index_format ,
  multiple_definitions , missing_definition , failed_import , failed_to_get_external_ast ,
  failed_to_generate_usr , triple_mismatch , lang_mismatch , lang_dialect_mismatch ,
  load_threshold_reached , invocation_list_ambiguous , invocation_list_file_not_found , invocation_list_empty ,
  invocation_list_wrong_format , invocation_list_lookup_unsuccessful
}
 

Functions

llvm::Expected< llvm::StringMap< std::string > > parseCrossTUIndex (StringRef IndexPath)
 This function parses an index file that determines which translation unit contains which definition.
 
std::string createCrossTUIndexString (const llvm::StringMap< std::string > &Index)
 
llvm::Expected< InvocationListTyparseInvocationList (StringRef FileContent, llvm::sys::path::Style PathStyle=llvm::sys::path::Style::posix)
 Parse the YAML formatted invocation list file content FileContent.
 
bool shouldImport (const VarDecl *VD, const ASTContext &ACtx)
 Returns true if it makes sense to import a foreign variable definition.
 
static bool parseCrossTUIndexItem (StringRef LineRef, StringRef &LookupName, StringRef &FilePath)
 Parse one line of the input CTU index file.
 
static bool hasBodyOrInit (const FunctionDecl *D, const FunctionDecl *&DefD)
 
static bool hasBodyOrInit (const VarDecl *D, const VarDecl *&DefD)
 
template<typename T >
static bool hasBodyOrInit (const T *D)
 

Typedef Documentation

◆ InvocationListTy

using clang::cross_tu::InvocationListTy = typedef llvm::StringMap<llvm::SmallVector<std::string, 32> >

Definition at line 102 of file CrossTranslationUnit.h.

Enumeration Type Documentation

◆ index_error_code

Enumerator
success 
unspecified 
missing_index_file 
invalid_index_format 
multiple_definitions 
missing_definition 
failed_import 
failed_to_get_external_ast 
failed_to_generate_usr 
triple_mismatch 
lang_mismatch 
lang_dialect_mismatch 
load_threshold_reached 
invocation_list_ambiguous 
invocation_list_file_not_found 
invocation_list_empty 
invocation_list_wrong_format 
invocation_list_lookup_unsuccessful 

Definition at line 40 of file CrossTranslationUnit.h.

Function Documentation

◆ createCrossTUIndexString()

std::string clang::cross_tu::createCrossTUIndexString ( const llvm::StringMap< std::string > &  Index)

Definition at line 215 of file CrossTranslationUnit.cpp.

References E, and clang::Result.

◆ hasBodyOrInit() [1/3]

static bool clang::cross_tu::hasBodyOrInit ( const FunctionDecl D,
const FunctionDecl *&  DefD 
)
static

Definition at line 228 of file CrossTranslationUnit.cpp.

References D.

Referenced by hasBodyOrInit().

◆ hasBodyOrInit() [2/3]

template<typename T >
static bool clang::cross_tu::hasBodyOrInit ( const T D)
static

Definition at line 234 of file CrossTranslationUnit.cpp.

References D, hasBodyOrInit(), clang::T, and Unused.

◆ hasBodyOrInit() [3/3]

static bool clang::cross_tu::hasBodyOrInit ( const VarDecl D,
const VarDecl *&  DefD 
)
static

Definition at line 231 of file CrossTranslationUnit.cpp.

References D.

◆ parseCrossTUIndex()

llvm::Expected< llvm::StringMap< std::string > > clang::cross_tu::parseCrossTUIndex ( StringRef  IndexPath)

This function parses an index file that determines which translation unit contains which definition.

The IndexPath is not prefixed with CTUDir, so an absolute path is expected for consistent results.

The index file format is the following: each line consists of an USR and a filepath separated by a space.

Returns
Returns a map where the USR is the key and the filepath is the value or an error.

Definition at line 182 of file CrossTranslationUnit.cpp.

References invalid_index_format, clang::Line, missing_index_file, multiple_definitions, parseCrossTUIndexItem(), and clang::Result.

◆ parseCrossTUIndexItem()

static bool clang::cross_tu::parseCrossTUIndexItem ( StringRef  LineRef,
StringRef &  LookupName,
StringRef &  FilePath 
)
static

Parse one line of the input CTU index file.

Parameters
[in]LineRefThe input CTU index item in format "<USR-Length>:<USR> <File-Path>".
[out]LookupNameThe lookup name in format "<USR-Length>:<USR>".
[out]FilePathThe file path "<File-Path>".

Definition at line 158 of file CrossTranslationUnit.cpp.

Referenced by parseCrossTUIndex().

◆ parseInvocationList()

llvm::Expected< InvocationListTy > clang::cross_tu::parseInvocationList ( StringRef  FileContent,
llvm::sys::path::Style  PathStyle = llvm::sys::path::Style::posix 
)

Parse the YAML formatted invocation list file content FileContent.

The format is expected to be a mapping from absolute source file paths in the filesystem to a list of command-line parts, which constitute the invocation needed to compile that file. That invocation will be used to produce the AST of the TU.

LLVM YAML parser is used to extract information from invocation list file.

Only the first document is processed.

There has to be at least one document available.

According to the format specified the document must be a mapping, where the keys are paths to source files, and values are sequences of invocation parts.

The keys should be strings, which represent a source-file path.

The values should be sequences of strings, each representing a part of the invocation.

Every conversion starts with an empty working storage, as it is not clear if this is a requirement of the YAML parser.

LLVM YAML parser is used to extract information from invocation list file.

Only the first document is processed.

There has to be at least one document available.

According to the format specified the document must be a mapping, where the keys are paths to source files, and values are sequences of invocation parts.

The keys should be strings, which represent a source-file path.

The values should be sequences of strings, each representing a part of the invocation.

Every conversion starts with an empty working storage, as it is not clear if this is a requirement of the YAML parser.

Definition at line 619 of file CrossTranslationUnit.cpp.

References invocation_list_ambiguous, invocation_list_empty, invocation_list_wrong_format, and SM.

◆ shouldImport()

bool clang::cross_tu::shouldImport ( const VarDecl VD,
const ASTContext ACtx 
)

Returns true if it makes sense to import a foreign variable definition.

For instance, we don't want to import variables that have non-trivial types because the constructor might have side-effects.

Definition at line 223 of file CrossTranslationUnit.cpp.

References clang::ASTContext::getCanonicalType(), clang::ValueDecl::getType(), clang::CanQual< T >::isConstQualified(), and clang::QualType::isTrivialType().