//===--- CrossTranslationUnit.h - -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file provides an interface to load binary AST dumps on demand. This // feature can be utilized for tools that require cross translation unit // support. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H #define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H #include "clang/AST/ASTImporterSharedState.h" #include "clang/Analysis/MacroExpansionContext.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/Error.h" #include "llvm/Support/Path.h" #include <optional> namespace clang { class CompilerInstance; class ASTContext; class ASTImporter; class ASTUnit; class DeclContext; class FunctionDecl; class VarDecl; class NamedDecl; class TranslationUnitDecl; namespace cross_tu { enum class index_error_code { … }; class IndexError : public llvm::ErrorInfo<IndexError> { … }; /// 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. /// /// \return Returns a map where the USR is the key and the filepath is the value /// or an error. llvm::Expected<llvm::StringMap<std::string>> parseCrossTUIndex(StringRef IndexPath); std::string createCrossTUIndexString(const llvm::StringMap<std::string> &Index); InvocationListTy; /// Parse the YAML formatted invocation list file content \p 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::Expected<InvocationListTy> parseInvocationList( StringRef FileContent, llvm::sys::path::Style PathStyle = llvm::sys::path::Style::posix); /// 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. bool shouldImport(const VarDecl *VD, const ASTContext &ACtx); /// This class is used for tools that requires cross translation /// unit capability. /// /// This class can load definitions from external AST sources. /// 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. class CrossTranslationUnitContext { … }; } // namespace cross_tu } // namespace clang #endif // LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H