24#include "llvm/ADT/Statistic.h"
25#include "llvm/Option/ArgList.h"
26#include "llvm/Support/ErrorHandling.h"
27#include "llvm/Support/IOSandbox.h"
28#include "llvm/Support/ManagedStatic.h"
29#include "llvm/Support/Path.h"
30#include "llvm/Support/YAMLParser.h"
31#include "llvm/Support/raw_ostream.h"
32#include "llvm/TargetParser/Triple.h"
44#define DEBUG_TYPE "CrossTranslationUnit"
45STATISTIC(NumGetCTUCalled,
"The # of getCTUDefinition function called");
48 "The # of getCTUDefinition called but the function is not in any other TU");
50 "The # of getCTUDefinition successfully returned the "
51 "requested function's body");
52STATISTIC(NumUnsupportedNodeFound,
"The # of imports when the ASTImporter "
53 "encountered an unsupported AST Node");
54STATISTIC(NumNameConflicts,
"The # of imports when the ASTImporter "
55 "encountered an ODR error");
56STATISTIC(NumTripleMismatch,
"The # of triple mismatches");
57STATISTIC(NumLangMismatch,
"The # of language mismatches");
58STATISTIC(NumLangDialectMismatch,
"The # of language dialect mismatches");
60 "The # of ASTs not loaded because of threshold");
64bool hasEqualKnownFields(
const llvm::Triple &Lhs,
const llvm::Triple &Rhs) {
66 if (Lhs.getArch() != Triple::UnknownArch &&
67 Rhs.getArch() != Triple::UnknownArch && Lhs.getArch() != Rhs.getArch())
69 if (Lhs.getSubArch() != Triple::NoSubArch &&
70 Rhs.getSubArch() != Triple::NoSubArch &&
71 Lhs.getSubArch() != Rhs.getSubArch())
73 if (Lhs.getVendor() != Triple::UnknownVendor &&
74 Rhs.getVendor() != Triple::UnknownVendor &&
75 Lhs.getVendor() != Rhs.getVendor())
77 if (!Lhs.isOSUnknown() && !Rhs.isOSUnknown() &&
78 Lhs.getOS() != Rhs.getOS())
80 if (Lhs.getEnvironment() != Triple::UnknownEnvironment &&
81 Rhs.getEnvironment() != Triple::UnknownEnvironment &&
82 Lhs.getEnvironment() != Rhs.getEnvironment())
84 if (Lhs.getObjectFormat() != Triple::UnknownObjectFormat &&
85 Rhs.getObjectFormat() != Triple::UnknownObjectFormat &&
86 Lhs.getObjectFormat() != Rhs.getObjectFormat())
92class IndexErrorCategory :
public std::error_category {
94 const char *
name() const noexcept
override {
return "clang.index"; }
96 std::string message(
int Condition)
const override {
103 return "An unknown error has occurred.";
105 return "The index file is missing.";
107 return "Invalid index file format.";
109 return "Multiple definitions in the index file.";
111 return "Missing definition from the index file.";
113 return "Failed to import the definition.";
115 return "Failed to load external AST source.";
117 return "Failed to generate USR.";
119 return "Triple mismatch";
121 return "Language mismatch";
123 return "Language dialect mismatch";
125 return "Load threshold reached";
127 return "Invocation list file contains multiple references to the same "
130 return "Invocation list file is not found.";
132 return "Invocation list file is empty.";
134 return "Invocation list file is in wrong format.";
136 return "Invocation list file does not contain the requested source file.";
138 llvm_unreachable(
"Unrecognized index_error_code.");
142static llvm::ManagedStatic<IndexErrorCategory> Category;
171 OS << Category->message(
static_cast<int>(Code)) <<
'\n';
175 return std::error_code(
static_cast<int>(Code), *Category);
185 StringRef &FilePath) {
188 size_t USRLength = 0;
189 if (LineRef.consumeInteger(10, USRLength))
191 assert(USRLength &&
"USRLength should be greater than zero.");
193 if (!LineRef.consume_front(
":"))
199 if (USRLength >= LineRef.size() ||
' ' != LineRef[USRLength])
202 LookupName = LineRef.substr(0, USRLength);
203 FilePath = LineRef.substr(USRLength + 1);
209 std::ifstream ExternalMapFile{std::string(IndexPath)};
210 if (!ExternalMapFile)
214 llvm::StringMap<std::string>
Result;
217 while (std::getline(ExternalMapFile,
Line)) {
219 StringRef LookupName, FilePathInIndex;
221 return llvm::make_error<IndexError>(
226 llvm::sys::path::native(FilePath, llvm::sys::path::Style::posix);
228 bool InsertionOccurred;
229 std::tie(std::ignore, InsertionOccurred) =
230 Result.try_emplace(LookupName, FilePath.begin(), FilePath.end());
231 if (!InsertionOccurred)
232 return llvm::make_error<IndexError>(
242 std::ostringstream
Result;
243 for (
const auto &E : Index)
244 Result << E.getKey().size() <<
':' << E.getKey().str() <<
' '
245 << E.getValue() <<
'\n';
266 : Context(CI.getASTContext()), ASTStorage(CI) {
269 auto S = CI.getVirtualFileSystem().status(CI.getAnalyzerOpts().CTUDir);
270 if (!S || S->getType() != llvm::sys::fs::file_type::directory_file)
271 CI.getDiagnostics().Report(diag::err_analyzer_config_invalid_input)
279std::optional<std::string>
285 return std::string(DeclUSR);
292CrossTranslationUnitContext::findDefInDeclContext(
const DeclContext *DC,
293 StringRef LookupName) {
294 assert(DC &&
"Declaration Context must not be null");
296 const auto *SubDC = dyn_cast<DeclContext>(D);
298 if (
const auto *ND = findDefInDeclContext<T>(SubDC, LookupName))
301 const auto *ND = dyn_cast<T>(D);
305 std::optional<std::string> ResultLookupName =
getLookupName(ResultDecl);
306 if (!ResultLookupName || *ResultLookupName != LookupName)
315 const T *D, StringRef CrossTUDir, StringRef IndexName,
316 bool DisplayCTUProgress) {
317 assert(D &&
"D is missing, bad call to this function!");
319 "D has a body or init in current translation unit!");
321 const std::optional<std::string> LookupName =
getLookupName(D);
323 return llvm::make_error<IndexError>(
326 loadExternalAST(*LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
328 return ASTUnitOrError.takeError();
329 ASTUnit *Unit = *ASTUnitOrError;
330 assert(&Unit->getFileManager() ==
331 &Unit->getASTContext().getSourceManager().getFileManager());
333 const llvm::Triple &TripleTo = Context.getTargetInfo().getTriple();
334 const llvm::Triple &TripleFrom =
335 Unit->getASTContext().getTargetInfo().getTriple();
340 if (!hasEqualKnownFields(TripleTo, TripleFrom)) {
345 std::string(Unit->getMainFileName()),
346 TripleTo.str(), TripleFrom.str());
349 const auto &LangTo = Context.getLangOpts();
350 const auto &LangFrom = Unit->getASTContext().getLangOpts();
354 if (LangTo.CPlusPlus != LangFrom.CPlusPlus) {
356 return llvm::make_error<IndexError>(
374 if (LangTo.CPlusPlus11 != LangFrom.CPlusPlus11 ||
375 LangTo.CPlusPlus14 != LangFrom.CPlusPlus14 ||
376 LangTo.CPlusPlus17 != LangFrom.CPlusPlus17 ||
377 LangTo.CPlusPlus20 != LangFrom.CPlusPlus20) {
378 ++NumLangDialectMismatch;
380 std::string(Unit->getMainFileName()),
385 TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
386 if (
const T *ResultDecl = findDefInDeclContext<T>(TU, *LookupName))
391llvm::Expected<const FunctionDecl *>
393 StringRef CrossTUDir,
395 bool DisplayCTUProgress) {
396 return getCrossTUDefinitionImpl(FD, CrossTUDir, IndexName,
402 StringRef CrossTUDir,
404 bool DisplayCTUProgress) {
405 return getCrossTUDefinitionImpl(VD, CrossTUDir, IndexName,
417 Context.getDiagnostics().Report(Loc, diag::err_ctu_error_opening)
422 Context.getDiagnostics().Report(Loc, diag::err_extdefmap_parsing)
427 Context.getDiagnostics().Report(Loc, diag::err_multiple_def_index)
432 Context.getDiagnostics().Report(Loc, diag::warn_ctu_incompat_triple)
448 Context.getDiagnostics().Report(Loc, diag::warn_ctu_import_failure)
449 << Category->message(
static_cast<int>(IE.
getCode()));
457 Context.getDiagnostics().Report(Loc, diag::err_ctu_import_failure)
458 << Category->message(
static_cast<int>(IE.
getCode()));
464 if (!HasEmittedLoadThresholdRemark) {
465 HasEmittedLoadThresholdRemark =
true;
466 Context.getDiagnostics().Report(
467 Loc, diag::remark_ctu_import_threshold_reached);
474 Context.getDiagnostics().Report(Loc, diag::warn_ctu_incompat_lang)
481 Context.getDiagnostics().Report(Loc, diag::err_invlist_parsing)
489 Context.getDiagnostics().Report(Loc, diag::warn_multiple_entries_invlist)
497 Context.getDiagnostics().Report(Loc, diag::warn_invlist_missing_file)
502 llvm_unreachable(
"Success is not an error.");
505 llvm_unreachable(
"Unrecognized index_error_code.");
508CrossTranslationUnitContext::ASTUnitStorage::ASTUnitStorage(
510 : Loader(CI, CI.getAnalyzerOpts().CTUDir,
511 CI.getAnalyzerOpts().CTUInvocationList),
512 LoadGuard(CI.getASTContext().getLangOpts().
CPlusPlus
513 ? CI.getAnalyzerOpts().CTUImportCppThreshold
514 : CI.getAnalyzerOpts().CTUImportThreshold) {}
517CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile(
518 StringRef
FileName,
bool DisplayCTUProgress) {
520 auto ASTCacheEntry = FileASTUnitMap.find(
FileName);
521 if (ASTCacheEntry == FileASTUnitMap.end()) {
525 ++NumASTLoadThresholdReached;
526 return llvm::make_error<IndexError>(
530 auto LoadAttempt = Loader.load(
FileName);
533 return LoadAttempt.takeError();
535 std::unique_ptr<ASTUnit> LoadedUnit = std::move(LoadAttempt.get());
538 ASTUnit *Unit = LoadedUnit.get();
541 FileASTUnitMap[
FileName] = std::move(LoadedUnit);
543 LoadGuard.indicateLoadSuccess();
545 if (DisplayCTUProgress)
546 llvm::errs() <<
"CTU loaded AST file: " <<
FileName <<
"\n";
552 return ASTCacheEntry->second.get();
556llvm::Expected<ASTUnit *>
557CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
558 StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName,
559 bool DisplayCTUProgress) {
561 auto ASTCacheEntry = NameASTUnitMap.find(FunctionName);
562 if (ASTCacheEntry == NameASTUnitMap.end()) {
566 if (llvm::Error IndexLoadError =
567 ensureCTUIndexLoaded(CrossTUDir, IndexName))
568 return std::move(IndexLoadError);
571 auto It = NameFileMap.find(FunctionName);
572 if (It == NameFileMap.end()) {
579 if (llvm::Expected<ASTUnit *> FoundForFile =
580 getASTUnitForFile(It->second, DisplayCTUProgress)) {
583 NameASTUnitMap[FunctionName] = *FoundForFile;
584 return *FoundForFile;
587 return FoundForFile.takeError();
591 return ASTCacheEntry->second;
595llvm::Expected<std::string>
596CrossTranslationUnitContext::ASTUnitStorage::getFileForFunction(
597 StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName) {
598 if (llvm::Error IndexLoadError = ensureCTUIndexLoaded(CrossTUDir, IndexName))
599 return std::move(IndexLoadError);
600 return NameFileMap[FunctionName];
603llvm::Error CrossTranslationUnitContext::ASTUnitStorage::ensureCTUIndexLoaded(
604 StringRef CrossTUDir, StringRef IndexName) {
606 if (!NameFileMap.empty())
607 return llvm::Error::success();
610 SmallString<256> IndexFile = CrossTUDir;
611 if (llvm::sys::path::is_absolute(IndexName))
612 IndexFile = IndexName;
614 llvm::sys::path::append(IndexFile, IndexName);
618 NameFileMap = *IndexMapping;
619 return llvm::Error::success();
622 return IndexMapping.takeError();
627 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
628 bool DisplayCTUProgress) {
636 LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
639 return Unit.takeError();
643 return llvm::make_error<IndexError>(
649CrossTranslationUnitContext::ASTLoader::ASTLoader(
651 : CI(CI), CTUDir(CTUDir), InvocationListFilePath(InvocationListFilePath) {}
653CrossTranslationUnitContext::LoadResultTy
654CrossTranslationUnitContext::ASTLoader::load(StringRef Identifier) {
656 if (llvm::sys::path::is_absolute(Identifier, PathStyle)) {
660 llvm::sys::path::append(Path, PathStyle, Identifier);
665 llvm::sys::path::native(Path, PathStyle);
668 llvm::sys::path::remove_dots(Path,
true, PathStyle);
670 if (Path.ends_with(
".ast"))
671 return loadFromDump(Path);
673 return loadFromSource(Path);
676CrossTranslationUnitContext::LoadResultTy
677CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) {
678 auto DiagOpts = std::make_shared<DiagnosticOptions>();
679 TextDiagnosticPrinter *DiagClient =
680 new TextDiagnosticPrinter(llvm::errs(), *DiagOpts);
681 auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(
684 ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(),
686 CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
700CrossTranslationUnitContext::LoadResultTy
701CrossTranslationUnitContext::ASTLoader::loadFromSource(
702 StringRef SourceFilePath) {
704 if (llvm::Error InitError = lazyInitInvocationList())
705 return std::move(InitError);
706 assert(InvocationList);
708 auto Invocation = InvocationList->find(SourceFilePath);
709 if (Invocation == InvocationList->end())
710 return llvm::make_error<IndexError>(
712 SourceFilePath.str());
714 const InvocationListTy::mapped_type &InvocationCommand = Invocation->second;
716 SmallVector<const char *, 32> CommandLineArgs(InvocationCommand.size());
717 std::transform(InvocationCommand.begin(), InvocationCommand.end(),
718 CommandLineArgs.begin(),
719 [](
auto &&CmdPart) { return CmdPart.c_str(); });
721 auto DiagOpts = std::make_shared<DiagnosticOptions>(CI.getDiagnosticOpts());
722 auto *DiagClient =
new ForwardingDiagnosticConsumer{CI.getDiagnosticClient()};
723 IntrusiveRefCntPtr<DiagnosticIDs> DiagID{
724 CI.getDiagnostics().getDiagnosticIDs()};
725 auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(DiagID, *DiagOpts,
729 auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
731 CommandLineArgs.begin(), (CommandLineArgs.end()),
732 CI.getPCHContainerOperations(), DiagOpts, Diags,
733 CI.getHeaderSearchOpts().ResourceDir);
736llvm::Expected<InvocationListTy>
738 StringRef FilePath) {
743 llvm::yaml::Stream InvocationFile(FileContent,
SM);
745 auto GetLine = [&
SM](
const llvm::yaml::Node *N) ->
int {
746 return N ?
SM.FindLineNumber(N->getSourceRange().Start) : 0;
748 auto WrongFormatError = [&](
const llvm::yaml::Node *N) {
749 return llvm::make_error<IndexError>(
755 llvm::yaml::document_iterator FirstInvocationFile = InvocationFile.begin();
758 if (FirstInvocationFile == InvocationFile.end())
759 return llvm::make_error<IndexError>(
762 llvm::yaml::Node *DocumentRoot = FirstInvocationFile->getRoot();
764 return llvm::make_error<IndexError>(
770 auto *Mappings = dyn_cast<llvm::yaml::MappingNode>(DocumentRoot);
772 return WrongFormatError(DocumentRoot);
774 for (
auto &NextMapping : *Mappings) {
777 dyn_cast_if_present<llvm::yaml::ScalarNode>(NextMapping.getKey());
779 return WrongFormatError(NextMapping.getKey());
782 StringRef SourcePath = Key->getValue(ValueStorage);
786 llvm::sys::path::native(NativeSourcePath, PathStyle);
788 StringRef InvocationKey = NativeSourcePath;
790 if (InvocationList.contains(InvocationKey))
791 return llvm::make_error<IndexError>(
797 dyn_cast_if_present<llvm::yaml::SequenceNode>(NextMapping.getValue());
799 return WrongFormatError(NextMapping.getValue());
801 for (
auto &Arg : *Args) {
802 auto *CmdString = dyn_cast<llvm::yaml::ScalarNode>(&Arg);
804 return WrongFormatError(&Arg);
807 ValueStorage.clear();
808 InvocationList[InvocationKey].emplace_back(
809 CmdString->getValue(ValueStorage));
812 if (InvocationList[InvocationKey].empty())
813 return WrongFormatError(Key);
816 return InvocationList;
819llvm::Error CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
822 return llvm::Error::success();
824 return llvm::make_error<IndexError>(*PreviousError);
826 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileContent =
827 CI.getVirtualFileSystem().getBufferForFile(InvocationListFilePath);
830 InvocationListFilePath.str());
831 return llvm::make_error<IndexError>(*PreviousError);
833 std::unique_ptr<llvm::MemoryBuffer> ContentBuffer = std::move(*FileContent);
834 assert(ContentBuffer &&
"If no error was produced after loading, the pointer "
835 "should not be nullptr.");
838 ContentBuffer->getBuffer(), PathStyle, InvocationListFilePath);
840 if (!ExpectedInvocationList) {
841 llvm::handleAllErrors(
842 ExpectedInvocationList.takeError(),
843 [
this](
const IndexError &E) { this->PreviousError = E; });
844 return llvm::make_error<IndexError>(*PreviousError);
847 InvocationList = *ExpectedInvocationList;
849 return llvm::Error::success();
853llvm::Expected<const T *>
854CrossTranslationUnitContext::importDefinitionImpl(
const T *D, ASTUnit *Unit) {
855 assert(
hasBodyOrInit(D) &&
"Decls to be imported should have body or init.");
857 assert(&D->getASTContext() == &Unit->getASTContext() &&
858 "ASTContext of Decl and the unit should match.");
859 ASTImporter &Importer = getOrCreateASTImporter(Unit);
861 auto ToDeclOrError = Importer.Import(D);
862 if (!ToDeclOrError) {
863 handleAllErrors(ToDeclOrError.takeError(), [&](
const ASTImportError &IE) {
865 case ASTImportError::NameConflict:
868 case ASTImportError::UnsupportedConstruct:
869 ++NumUnsupportedNodeFound;
871 case ASTImportError::Unknown:
872 llvm_unreachable(
"Unknown import error happened.");
878 auto *ToDecl =
cast<T>(*ToDeclOrError);
879 assert(
hasBodyOrInit(ToDecl) &&
"Imported Decl should have body or init.");
883 ToDecl->getASTContext().getParentMapContext().clear();
888llvm::Expected<const FunctionDecl *>
891 return importDefinitionImpl(FD, Unit);
897 return importDefinitionImpl(VD, Unit);
900void CrossTranslationUnitContext::lazyInitImporterSharedSt(
902 if (!ImporterSharedSt)
903 ImporterSharedSt = std::make_shared<ASTImporterSharedState>(*ToTU);
907CrossTranslationUnitContext::getOrCreateASTImporter(
ASTUnit *Unit) {
911 if (I != ASTUnitImporterMap.end())
913 lazyInitImporterSharedSt(Context.getTranslationUnitDecl());
915 Context, Context.getSourceManager().getFileManager(), From,
921std::optional<clang::MacroExpansionContext>
929 if (!ImporterSharedSt)
931 return ImporterSharedSt->isNewDecl(
const_cast<Decl *
>(ToDecl));
935 if (!ImporterSharedSt)
937 return static_cast<bool>(
938 ImporterSharedSt->getImportDeclErrorIfAny(
const_cast<Decl *
>(ToDecl)));
STATISTIC(NumObjCCallEdges, "Number of Objective-C method call edges")
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
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.
static std::unique_ptr< ASTUnit > LoadFromASTFile(StringRef Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< DiagnosticOptions > DiagOpts, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts=nullptr, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowASTWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
@ LoadEverything
Load everything, including Sema.
const ASTContext & getASTContext() const
unsigned ShouldEmitErrorsOnInvalidConfigValue
bool isConstQualified() const
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
AnalyzerOptions & getAnalyzerOpts()
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
static llvm::IntrusiveRefCntPtr< DiagnosticIDs > create()
Represents a function declaration or definition.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Encodes a location in the source.
FileManager & getFileManager() const
The top declaration context.
Represents a variable declaration or definition.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
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 ...
CrossTranslationUnitContext(CompilerInstance &CI)
void emitCrossTUDiagnostics(const IndexError &IE, SourceLocation Loc)
Emit diagnostics for the user for potential configuration errors.
static std::optional< std::string > getLookupName(const Decl *D)
Get a name to identify a decl.
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 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.
index_error_code getCode() const
std::error_code convertToErrorCode() const override
void log(raw_ostream &OS) const override
std::string getConfigFromName() const
std::string getConfigToName() const
std::string getFileName() const
Defines the clang::TargetInfo interface.
bool shouldImport(const VarDecl *VD, const ASTContext &ACtx)
Returns true if it makes sense to import a foreign variable definition.
static std::string getLangDescription(const LangOptions &LO)
Returns a human-readable language/dialect description for diagnostics.
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)
static bool hasBodyOrInit(const FunctionDecl *D, const FunctionDecl *&DefD)
@ invocation_list_wrong_format
@ invocation_list_file_not_found
@ invocation_list_lookup_unsuccessful
@ failed_to_get_external_ast
@ invocation_list_ambiguous
static bool parseCrossTUIndexItem(StringRef LineRef, StringRef &LookupName, StringRef &FilePath)
Parse one line of the input CTU index file.
llvm::Expected< InvocationListTy > parseInvocationList(StringRef FileContent, llvm::sys::path::Style PathStyle=llvm::sys::path::Style::posix, StringRef FilePath="")
Parse the YAML formatted invocation list file content FileContent.
llvm::StringMap< llvm::SmallVector< std::string, 32 > > InvocationListTy
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
std::unique_ptr< ASTUnit > CreateASTUnitFromCommandLine(const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, std::shared_ptr< DiagnosticOptions > DiagOpts, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool StorePreamblesInMemory=false, StringRef PreambleStoragePath=StringRef(), bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, ArrayRef< ASTUnit::RemappedFile > RemappedFiles={}, bool RemappedFilesKeepOriginalName=true, unsigned PrecompilePreambleAfterNParses=0, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, SkipFunctionBodiesScope SkipFunctionBodies=SkipFunctionBodiesScope::None, bool SingleFileParse=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, bool RetainExcludedConditionalBlocks=false, std::optional< StringRef > ModuleFormat=std::nullopt, std::unique_ptr< ASTUnit > *ErrAST=nullptr, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Create an ASTUnit from a vector of command line arguments, which must specify exactly one source file...
@ Result
The result type of a method or function.
U cast(CodeGen::Address addr)