11 #include "llvm/ADT/SetVector.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/LSP/Logging.h"
14 #include "llvm/Support/LSP/Protocol.h"
15 #include "llvm/Support/YAMLTraits.h"
19 using llvm::lsp::Logger;
30 std::vector<std::string> includeDirs;
38 LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(YamlFileInfo)
43 struct MappingTraits<YamlFileInfo> {
44 static void mapping(IO &io, YamlFileInfo &info) {
47 io.mapRequired(
"filepath", info.filename);
51 lsp::URIForFile::fromFile(info.filename))
52 info.filename = uri->file().str();
56 std::string combinedIncludes;
57 io.mapRequired(
"includes", combinedIncludes);
58 for (StringRef include : llvm::split(combinedIncludes,
";")) {
60 info.includeDirs.push_back(include.str());
68 for (StringRef filename : databases)
69 loadDatabase(filename);
74 auto it = files.find(filename);
75 return it == files.end() ? defaultFileInfo : it->second;
78 void CompilationDatabase::loadDatabase(StringRef filename) {
83 std::string errorMessage;
84 std::unique_ptr<llvm::MemoryBuffer> inputFile =
87 Logger::error(
"Failed to open compilation database: {0}", errorMessage);
90 llvm::yaml::Input yaml(inputFile->getBuffer());
93 std::vector<YamlFileInfo> parsedFiles;
97 for (
auto &file : parsedFiles) {
98 auto it = files.try_emplace(file.filename, std::move(file.includeDirs));
102 Logger::info(
"Duplicate file in compilation database: {0}",
108 knownIncludes.insert_range(it.first->second.includeDirs);
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...
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.