13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/YAMLTraits.h"
29 std::vector<std::string> includeDirs;
37 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(YamlFileInfo)
42 struct MappingTraits<YamlFileInfo> {
43 static void mapping(IO &io, YamlFileInfo &info) {
46 io.mapRequired(
"filepath", info.filename);
51 info.filename = uri->file().str();
55 std::string combinedIncludes;
56 io.mapRequired(
"includes", combinedIncludes);
57 for (StringRef include : llvm::split(combinedIncludes,
";")) {
59 info.includeDirs.push_back(include.str());
67 for (StringRef filename : databases)
68 loadDatabase(filename);
73 auto it = files.find(filename);
74 return it == files.end() ? defaultFileInfo : it->second;
77 void CompilationDatabase::loadDatabase(StringRef filename) {
82 std::string errorMessage;
83 std::unique_ptr<llvm::MemoryBuffer> inputFile =
86 Logger::error(
"Failed to open compilation database: {0}", errorMessage);
89 llvm::yaml::Input yaml(inputFile->getBuffer());
92 std::vector<YamlFileInfo> parsedFiles;
96 for (
auto &file : parsedFiles) {
97 auto it = files.try_emplace(file.filename, std::move(file.includeDirs));
101 Logger::info(
"Duplicate file in compilation database: {0}",
107 for (StringRef include : it.first->second.includeDirs)
108 knownIncludes.insert(include);
116 for (StringRef include : knownIncludes)
117 defaultFileInfo.
includeDirs.push_back(include.str());
const FileInfo & getFileInfo(StringRef filename) const
Get the compilation information for the provided file.
CompilationDatabase(ArrayRef< std::string > databases)
Construct a compilation database from the provided files containing YAML descriptions of the database...
static void info(const char *fmt, Ts &&...vals)
static void error(const char *fmt, Ts &&...vals)
static llvm::Expected< URIForFile > fromFile(StringRef absoluteFilepath, StringRef scheme="file")
Try to build a URIForFile from the given absolute file path and optional scheme.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
std::unique_ptr< llvm::MemoryBuffer > openInputFile(llvm::StringRef inputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for reading.
static void mapping(IO &io, YamlFileInfo &info)
Compilation information for a specific file within the database.
std::vector< std::string > includeDirs
The include directories available for the file.