25#include "llvm/ADT/Statistic.h"
26#include "llvm/Option/ArgList.h"
27#include "llvm/Support/ErrorHandling.h"
28#include "llvm/Support/IOSandbox.h"
29#include "llvm/Support/ManagedStatic.h"
30#include "llvm/Support/Path.h"
31#include "llvm/Support/YAMLParser.h"
32#include "llvm/Support/raw_ostream.h"
33#include "llvm/TargetParser/Triple.h"
45#define DEBUG_TYPE "CrossTranslationUnit"
46STATISTIC(NumGetCTUCalled,
"The # of getCTUDefinition function called");
49 "The # of getCTUDefinition called but the function is not in any other TU");
51 "The # of getCTUDefinition successfully returned the "
52 "requested function's body");
53STATISTIC(NumUnsupportedNodeFound,
"The # of imports when the ASTImporter "
54 "encountered an unsupported AST Node");
55STATISTIC(NumNameConflicts,
"The # of imports when the ASTImporter "
56 "encountered an ODR error");
57STATISTIC(NumTripleMismatch,
"The # of triple mismatches");
58STATISTIC(NumLangMismatch,
"The # of language mismatches");
59STATISTIC(NumLangDialectMismatch,
"The # of language dialect mismatches");
61 "The # of ASTs not loaded because of threshold");
65bool hasEqualKnownFields(
const llvm::Triple &Lhs,
const llvm::Triple &Rhs) {
67 if (Lhs.getArch() != Triple::UnknownArch &&
68 Rhs.getArch() != Triple::UnknownArch && Lhs.getArch() != Rhs.getArch())
70 if (Lhs.getSubArch() != Triple::NoSubArch &&
71 Rhs.getSubArch() != Triple::NoSubArch &&
72 Lhs.getSubArch() != Rhs.getSubArch())
74 if (Lhs.getVendor() != Triple::UnknownVendor &&
75 Rhs.getVendor() != Triple::UnknownVendor &&
76 Lhs.getVendor() != Rhs.getVendor())
78 if (!Lhs.isOSUnknown() && !Rhs.isOSUnknown() &&
79 Lhs.getOS() != Rhs.getOS())
81 if (Lhs.getEnvironment() != Triple::UnknownEnvironment &&
82 Rhs.getEnvironment() != Triple::UnknownEnvironment &&
83 Lhs.getEnvironment() != Rhs.getEnvironment())
85 if (Lhs.getObjectFormat() != Triple::UnknownObjectFormat &&
86 Rhs.getObjectFormat() != Triple::UnknownObjectFormat &&
87 Lhs.getObjectFormat() != Rhs.getObjectFormat())
93class IndexErrorCategory :
public std::error_category {
95 const char *
name() const noexcept
override {
return "clang.index"; }
97 std::string message(
int Condition)
const override {
104 return "An unknown error has occurred.";
106 return "The index file is missing.";
108 return "Invalid index file format.";
110 return "Multiple definitions in the index file.";
112 return "Missing definition from the index file.";
114 return "Failed to import the definition.";
116 return "Failed to load external AST source.";
118 return "Failed to generate USR.";
120 return "Triple mismatch";
122 return "Language mismatch";
124 return "Language dialect mismatch";
126 return "Load threshold reached";
128 return "Invocation list file contains multiple references to the same "
131 return "Invocation list file is not found.";
133 return "Invocation list file is empty.";
135 return "Invocation list file is in wrong format.";
137 return "Invocation list file does not contain the requested source file.";
139 llvm_unreachable(
"Unrecognized index_error_code.");
143static llvm::ManagedStatic<IndexErrorCategory> Category;
174 OS << Category->message(
static_cast<int>(Code)) <<
'\n';
178 return std::error_code(
static_cast<int>(Code), *Category);
188 StringRef &FilePath) {
191 size_t USRLength = 0;
192 if (LineRef.consumeInteger(10, USRLength))
194 assert(USRLength &&
"USRLength should be greater than zero.");
196 if (!LineRef.consume_front(
":"))
202 if (USRLength >= LineRef.size() ||
' ' != LineRef[USRLength])
205 LookupName = LineRef.substr(0, USRLength);
206 FilePath = LineRef.substr(USRLength + 1);
212 std::ifstream ExternalMapFile{std::string(IndexPath)};
213 if (!ExternalMapFile)
217 llvm::StringMap<std::string>
Result;
220 while (std::getline(ExternalMapFile,
Line)) {
222 StringRef LookupName, FilePathInIndex;
224 return llvm::make_error<IndexError>(
229 llvm::sys::path::native(FilePath, llvm::sys::path::Style::posix);
231 bool InsertionOccurred;
232 std::tie(std::ignore, InsertionOccurred) =
233 Result.try_emplace(LookupName, FilePath.begin(), FilePath.end());
234 if (!InsertionOccurred)
235 return llvm::make_error<IndexError>(
245 std::ostringstream
Result;
246 for (
const auto &E : Index)
247 Result << E.getKey().size() <<
':' << E.getKey().str() <<
' '
248 << E.getValue() <<
'\n';
269 : Context(CI.getASTContext()), ASTStorage(CI) {
272 auto S = CI.getVirtualFileSystem().status(CI.getAnalyzerOpts().CTUDir);
273 if (!S || S->getType() != llvm::sys::fs::file_type::directory_file)
274 CI.getDiagnostics().Report(diag::err_analyzer_config_invalid_input)
282std::optional<std::string>
288 return std::string(DeclUSR);
295CrossTranslationUnitContext::findDefInDeclContext(
const DeclContext *DC,
296 StringRef LookupName) {
297 assert(DC &&
"Declaration Context must not be null");
299 const auto *SubDC = dyn_cast<DeclContext>(D);
301 if (
const auto *ND = findDefInDeclContext<T>(SubDC, LookupName))
304 const auto *ND = dyn_cast<T>(D);
308 std::optional<std::string> ResultLookupName =
getLookupName(ResultDecl);
309 if (!ResultLookupName || *ResultLookupName != LookupName)
318 const T *D, StringRef CrossTUDir, StringRef IndexName,
319 bool DisplayCTUProgress) {
320 assert(D &&
"D is missing, bad call to this function!");
322 "D has a body or init in current translation unit!");
324 const std::optional<std::string> LookupName =
getLookupName(D);
326 return llvm::make_error<IndexError>(
329 loadExternalAST(*LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
331 return ASTUnitOrError.takeError();
332 ASTUnit *Unit = *ASTUnitOrError;
333 assert(&Unit->getFileManager() ==
334 &Unit->getASTContext().getSourceManager().getFileManager());
336 const llvm::Triple &TripleTo = Context.getTargetInfo().getTriple();
337 const llvm::Triple &TripleFrom =
338 Unit->getASTContext().getTargetInfo().getTriple();
343 if (!hasEqualKnownFields(TripleTo, TripleFrom)) {
348 std::string(Unit->getMainFileName()),
349 TripleTo.str(), TripleFrom.str());
352 const auto &LangTo = Context.getLangOpts();
353 const auto &LangFrom = Unit->getASTContext().getLangOpts();
357 if (LangTo.CPlusPlus != LangFrom.CPlusPlus) {
359 return llvm::make_error<IndexError>(
377 if (LangTo.CPlusPlus11 != LangFrom.CPlusPlus11 ||
378 LangTo.CPlusPlus14 != LangFrom.CPlusPlus14 ||
379 LangTo.CPlusPlus17 != LangFrom.CPlusPlus17 ||
380 LangTo.CPlusPlus20 != LangFrom.CPlusPlus20) {
381 ++NumLangDialectMismatch;
383 std::string(Unit->getMainFileName()),
388 TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
389 if (
const T *ResultDecl = findDefInDeclContext<T>(TU, *LookupName))
394llvm::Expected<const FunctionDecl *>
396 StringRef CrossTUDir,
398 bool DisplayCTUProgress) {
399 return getCrossTUDefinitionImpl(FD, CrossTUDir, IndexName,
405 StringRef CrossTUDir,
407 bool DisplayCTUProgress) {
408 return getCrossTUDefinitionImpl(VD, CrossTUDir, IndexName,
420 Context.getDiagnostics().Report(Loc, diag::err_ctu_error_opening)
425 Context.getDiagnostics().Report(Loc, diag::err_extdefmap_parsing)
430 Context.getDiagnostics().Report(Loc, diag::err_multiple_def_index)
435 Context.getDiagnostics().Report(Loc, diag::warn_ctu_incompat_triple)
451 Context.getDiagnostics().Report(Loc, diag::warn_ctu_import_failure)
452 << Category->message(
static_cast<int>(IE.
getCode()));
460 Context.getDiagnostics().Report(Loc, diag::err_ctu_import_failure)
461 << Category->message(
static_cast<int>(IE.
getCode()));
467 if (!HasEmittedLoadThresholdRemark) {
468 HasEmittedLoadThresholdRemark =
true;
469 Context.getDiagnostics().Report(
470 Loc, diag::remark_ctu_import_threshold_reached);
477 Context.getDiagnostics().Report(Loc, diag::warn_ctu_incompat_lang)
484 Context.getDiagnostics().Report(Loc, diag::err_invlist_parsing)
492 Context.getDiagnostics().Report(Loc, diag::warn_multiple_entries_invlist)
500 Context.getDiagnostics().Report(Loc, diag::warn_invlist_missing_file)
505 llvm_unreachable(
"Success is not an error.");
508 llvm_unreachable(
"Unrecognized index_error_code.");
511CrossTranslationUnitContext::ASTUnitStorage::ASTUnitStorage(
513 : Loader(CI, CI.getAnalyzerOpts().CTUDir,
514 CI.getAnalyzerOpts().CTUInvocationList),
515 LoadGuard(CI.getASTContext().getLangOpts().
CPlusPlus
516 ? CI.getAnalyzerOpts().CTUImportCppThreshold
517 : CI.getAnalyzerOpts().CTUImportThreshold) {}
520CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile(
521 StringRef
FileName,
bool DisplayCTUProgress) {
523 auto ASTCacheEntry = FileASTUnitMap.find(
FileName);
524 if (ASTCacheEntry == FileASTUnitMap.end()) {
528 ++NumASTLoadThresholdReached;
529 return llvm::make_error<IndexError>(
533 auto LoadAttempt = Loader.load(
FileName);
536 return LoadAttempt.takeError();
538 std::unique_ptr<ASTUnit> LoadedUnit = std::move(LoadAttempt.get());
541 ASTUnit *Unit = LoadedUnit.get();
544 FileASTUnitMap[
FileName] = std::move(LoadedUnit);
546 LoadGuard.indicateLoadSuccess();
548 if (DisplayCTUProgress)
549 llvm::errs() <<
"CTU loaded AST file: " <<
FileName <<
"\n";
555 return ASTCacheEntry->second.get();
559llvm::Expected<ASTUnit *>
560CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
561 StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName,
562 bool DisplayCTUProgress) {
564 auto ASTCacheEntry = NameASTUnitMap.find(FunctionName);
565 if (ASTCacheEntry == NameASTUnitMap.end()) {
569 if (llvm::Error IndexLoadError =
570 ensureCTUIndexLoaded(CrossTUDir, IndexName))
571 return std::move(IndexLoadError);
574 auto It = NameFileMap.find(FunctionName);
575 if (It == NameFileMap.end()) {
582 if (llvm::Expected<ASTUnit *> FoundForFile =
583 getASTUnitForFile(It->second, DisplayCTUProgress)) {
586 NameASTUnitMap[FunctionName] = *FoundForFile;
587 return *FoundForFile;
590 return FoundForFile.takeError();
594 return ASTCacheEntry->second;
598llvm::Expected<std::string>
599CrossTranslationUnitContext::ASTUnitStorage::getFileForFunction(
600 StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName) {
601 if (llvm::Error IndexLoadError = ensureCTUIndexLoaded(CrossTUDir, IndexName))
602 return std::move(IndexLoadError);
603 return NameFileMap[FunctionName];
606llvm::Error CrossTranslationUnitContext::ASTUnitStorage::ensureCTUIndexLoaded(
607 StringRef CrossTUDir, StringRef IndexName) {
609 if (!NameFileMap.empty())
610 return llvm::Error::success();
613 SmallString<256> IndexFile = CrossTUDir;
614 if (llvm::sys::path::is_absolute(IndexName))
615 IndexFile = IndexName;
617 llvm::sys::path::append(IndexFile, IndexName);
621 NameFileMap = *IndexMapping;
622 return llvm::Error::success();
625 return IndexMapping.takeError();
630 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
631 bool DisplayCTUProgress) {
639 LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
642 return Unit.takeError();
646 return llvm::make_error<IndexError>(
652CrossTranslationUnitContext::ASTLoader::ASTLoader(
654 : CI(CI), CTUDir(CTUDir), InvocationListFilePath(InvocationListFilePath) {}
656CrossTranslationUnitContext::LoadResultTy
657CrossTranslationUnitContext::ASTLoader::load(StringRef Identifier) {
659 if (llvm::sys::path::is_absolute(Identifier, PathStyle)) {
663 llvm::sys::path::append(Path, PathStyle, Identifier);
668 llvm::sys::path::native(Path, PathStyle);
671 llvm::sys::path::remove_dots(Path,
true, PathStyle);
673 if (Path.ends_with(
".ast"))
674 return loadFromDump(Path);
676 return loadFromSource(Path);
679CrossTranslationUnitContext::LoadResultTy
680CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) {
681 auto DiagOpts = std::make_shared<DiagnosticOptions>();
682 TextDiagnosticPrinter *DiagClient =
683 new TextDiagnosticPrinter(llvm::errs(), *DiagOpts);
684 auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(
687 ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(),
689 CI.getFileSystemOpts(), CI.getHeaderSearchOpts());
703CrossTranslationUnitContext::LoadResultTy
704CrossTranslationUnitContext::ASTLoader::loadFromSource(
705 StringRef SourceFilePath) {
707 if (llvm::Error InitError = lazyInitInvocationList())
708 return std::move(InitError);
709 assert(InvocationList);
711 auto Invocation = InvocationList->find(SourceFilePath);
712 if (Invocation == InvocationList->end())
713 return llvm::make_error<IndexError>(
715 SourceFilePath.str());
717 const InvocationListTy::mapped_type &InvocationCommand = Invocation->second;
719 SmallVector<const char *, 32> CommandLineArgs(InvocationCommand.size());
720 std::transform(InvocationCommand.begin(), InvocationCommand.end(),
721 CommandLineArgs.begin(),
722 [](
auto &&CmdPart) { return CmdPart.c_str(); });
724 auto DiagOpts = std::make_shared<DiagnosticOptions>(CI.getDiagnosticOpts());
725 auto *DiagClient =
new ForwardingDiagnosticConsumer{CI.getDiagnosticClient()};
726 IntrusiveRefCntPtr<DiagnosticIDs> DiagID{
727 CI.getDiagnostics().getDiagnosticIDs()};
728 auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(DiagID, *DiagOpts,
732 auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
734 CommandLineArgs.begin(), (CommandLineArgs.end()),
735 CI.getPCHContainerOperations(), DiagOpts, Diags,
736 CI.getHeaderSearchOpts().ResourceDir);
739llvm::Expected<InvocationListTy>
741 StringRef FilePath) {
746 llvm::yaml::Stream InvocationFile(FileContent, SM);
748 auto GetLine = [&SM](
const llvm::yaml::Node *N) ->
int {
749 return N ? SM.FindLineNumber(N->getSourceRange().Start) : 0;
751 auto WrongFormatError = [&](
const llvm::yaml::Node *N) {
752 return llvm::make_error<IndexError>(
758 llvm::yaml::document_iterator FirstInvocationFile = InvocationFile.begin();
761 if (FirstInvocationFile == InvocationFile.end())
762 return llvm::make_error<IndexError>(
765 llvm::yaml::Node *DocumentRoot = FirstInvocationFile->getRoot();
767 return llvm::make_error<IndexError>(
773 auto *Mappings = dyn_cast<llvm::yaml::MappingNode>(DocumentRoot);
775 return WrongFormatError(DocumentRoot);
777 for (
auto &NextMapping : *Mappings) {
780 dyn_cast_if_present<llvm::yaml::ScalarNode>(NextMapping.getKey());
782 return WrongFormatError(NextMapping.getKey());
785 StringRef SourcePath = Key->getValue(ValueStorage);
789 llvm::sys::path::native(NativeSourcePath, PathStyle);
791 StringRef InvocationKey = NativeSourcePath;
793 if (InvocationList.contains(InvocationKey))
794 return llvm::make_error<IndexError>(
800 dyn_cast_if_present<llvm::yaml::SequenceNode>(NextMapping.getValue());
802 return WrongFormatError(NextMapping.getValue());
804 for (
auto &Arg : *Args) {
805 auto *CmdString = dyn_cast<llvm::yaml::ScalarNode>(&Arg);
807 return WrongFormatError(&Arg);
810 ValueStorage.clear();
811 InvocationList[InvocationKey].emplace_back(
812 CmdString->getValue(ValueStorage));
815 if (InvocationList[InvocationKey].empty())
816 return WrongFormatError(Key);
819 return InvocationList;
822llvm::Error CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
825 return llvm::Error::success();
827 return llvm::make_error<IndexError>(*PreviousError);
829 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileContent =
830 CI.getVirtualFileSystem().getBufferForFile(InvocationListFilePath);
833 InvocationListFilePath.str());
834 return llvm::make_error<IndexError>(*PreviousError);
836 std::unique_ptr<llvm::MemoryBuffer> ContentBuffer = std::move(*FileContent);
837 assert(ContentBuffer &&
"If no error was produced after loading, the pointer "
838 "should not be nullptr.");
841 ContentBuffer->getBuffer(), PathStyle, InvocationListFilePath);
843 if (!ExpectedInvocationList) {
844 llvm::handleAllErrors(
845 ExpectedInvocationList.takeError(),
846 [
this](
const IndexError &E) { this->PreviousError = E; });
847 return llvm::make_error<IndexError>(*PreviousError);
850 InvocationList = *ExpectedInvocationList;
852 return llvm::Error::success();
856llvm::Expected<const T *>
857CrossTranslationUnitContext::importDefinitionImpl(
const T *D, ASTUnit *Unit) {
858 assert(
hasBodyOrInit(D) &&
"Decls to be imported should have body or init.");
860 assert(&D->getASTContext() == &Unit->getASTContext() &&
861 "ASTContext of Decl and the unit should match.");
862 ASTImporter &Importer = getOrCreateASTImporter(Unit);
864 auto ToDeclOrError = Importer.Import(D);
865 if (!ToDeclOrError) {
866 handleAllErrors(ToDeclOrError.takeError(), [&](
const ASTImportError &IE) {
868 case ASTImportError::NameConflict:
871 case ASTImportError::UnsupportedConstruct:
872 ++NumUnsupportedNodeFound;
874 case ASTImportError::Unknown:
875 llvm_unreachable(
"Unknown import error happened.");
881 auto *ToDecl =
cast<T>(*ToDeclOrError);
882 assert(
hasBodyOrInit(ToDecl) &&
"Imported Decl should have body or init.");
886 ToDecl->getASTContext().getParentMapContext().clear();
891llvm::Expected<const FunctionDecl *>
894 return importDefinitionImpl(FD, Unit);
900 return importDefinitionImpl(VD, Unit);
903void CrossTranslationUnitContext::lazyInitImporterSharedSt(
905 if (!ImporterSharedSt)
906 ImporterSharedSt = std::make_shared<ASTImporterSharedState>(*ToTU);
910CrossTranslationUnitContext::getOrCreateASTImporter(
ASTUnit *Unit) {
914 if (I != ASTUnitImporterMap.end())
916 lazyInitImporterSharedSt(Context.getTranslationUnitDecl());
918 Context, Context.getSourceManager().getFileManager(), From,
924std::optional<clang::MacroExpansionContext>
932 if (!ImporterSharedSt)
934 return ImporterSharedSt->isNewDecl(
const_cast<Decl *
>(ToDecl));
938 if (!ImporterSharedSt)
940 return static_cast<bool>(
941 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.
Top level wrappers for InstallAPI frontend operations.
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.
const FunctionProtoType * T
U cast(CodeGen::Address addr)