14#ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
15#define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/SmallPtrSet.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/Support/Error.h"
24#include "llvm/Support/Path.h"
28class CompilerInstance;
36class TranslationUnitDecl;
68 std::string TripleFromName)
70 TripleToName(
std::move(TripleToName)),
71 TripleFromName(
std::move(TripleFromName)) {}
72 void log(raw_ostream &OS)
const override;
84 std::string TripleToName;
85 std::string TripleFromName;
109 StringRef FileContent,
110 llvm::sys::path::Style PathStyle = llvm::sys::path::Style::posix);
150 StringRef IndexName,
bool DisplayCTUProgress =
false);
153 StringRef IndexName,
bool DisplayCTUProgress =
false);
169 StringRef CrossTUDir,
171 bool DisplayCTUProgress =
false);
196 std::optional<clang::MacroExpansionContext>
211 template <
typename T>
213 StringRef CrossTUDir,
215 bool DisplayCTUProgress);
216 template <
typename T>
218 StringRef LookupName);
219 template <
typename T>
222 using ImporterMapTy =
223 llvm::DenseMap<TranslationUnitDecl *, std::unique_ptr<ASTImporter>>;
225 ImporterMapTy ASTUnitImporterMap;
228 std::shared_ptr<ASTImporterSharedState> ImporterSharedSt;
236 StringRef InvocationListFilePath);
246 llvm::Error lazyInitInvocationList();
251 const llvm::sys::path::Style PathStyle = llvm::sys::path::Style::posix;
263 StringRef InvocationListFilePath;
266 std::optional<InvocationListTy> InvocationList;
273 ASTLoadGuard(
unsigned Limit) : Limit(Limit) {}
277 operator bool()
const {
return Count < Limit; }
280 void indicateLoadSuccess() { ++Count; }
286 const unsigned Limit;
291 class ASTUnitStorage {
306 StringRef CrossTUDir,
308 bool DisplayCTUProgress);
320 StringRef CrossTUDir,
321 StringRef IndexName);
324 llvm::Error ensureCTUIndexLoaded(StringRef CrossTUDir, StringRef IndexName);
326 bool DisplayCTUProgress);
328 template <
typename...
T>
using BaseMapTy = llvm::StringMap<
T...>;
329 using OwningMapTy = BaseMapTy<std::unique_ptr<clang::ASTUnit>>;
330 using NonOwningMapTy = BaseMapTy<clang::ASTUnit *>;
332 OwningMapTy FileASTUnitMap;
333 NonOwningMapTy NameASTUnitMap;
335 using IndexMapTy = BaseMapTy<std::string>;
336 IndexMapTy NameFileMap;
345 ASTLoadGuard LoadGuard;
348 ASTUnitStorage ASTStorage;
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Utility class for loading a ASTContext from an AST file.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
Represents a function declaration or definition.
This represents a decl that may have a name.
Encodes a location in the source.
The top declaration context.
Represents a variable declaration or definition.
This class is used for tools that requires cross translation unit capability.
void emitCrossTUDiagnostics(const IndexError &IE)
Emit diagnostics for the user for potential configuration errors.
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 th...
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 ...
std::optional< clang::MacroExpansionContext > getMacroExpansionContextForSourceLocation(const clang::SourceLocation &ToLoc) const
Returns the MacroExpansionContext for the imported TU to which the given source-location corresponds.
static std::optional< std::string > getLookupName(const NamedDecl *ND)
Get a name to identify a named decl.
bool hasError(const Decl *ToDecl) const
Returns true if the given Decl is mapped (or created) during an import but there was an unrecoverable...
bool isImportedAsNew(const Decl *ToDecl) const
Returns true if the given Decl is newly created during the import.
~CrossTranslationUnitContext()
llvm::Expected< ASTUnit * > loadExternalAST(StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false)
This function loads a definition from an external AST file.
IndexError(index_error_code C, std::string FileName, std::string TripleToName, std::string TripleFromName)
index_error_code getCode() const
std::string getTripleToName() const
IndexError(index_error_code C, std::string FileName, int LineNo=0)
std::error_code convertToErrorCode() const override
std::string getTripleFromName() const
std::string getFileName() const
IndexError(index_error_code C)
bool shouldImport(const VarDecl *VD, const ASTContext &ACtx)
Returns true if it makes sense to import a foreign variable definition.
llvm::StringMap< llvm::SmallVector< std::string, 32 > > InvocationListTy
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< InvocationListTy > parseInvocationList(StringRef FileContent, llvm::sys::path::Style PathStyle=llvm::sys::path::Style::posix)
Parse the YAML formatted invocation list file content FileContent.
@ invocation_list_wrong_format
@ invocation_list_file_not_found
@ invocation_list_lookup_unsuccessful
@ failed_to_get_external_ast
@ invocation_list_ambiguous
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T