MLIR  19.0.0git
CompilationDatabase.h
Go to the documentation of this file.
1 //===- CompilationDatabase.h - LSP Compilation Database ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a definition of a generic compilation database that can be
10 // used to provide information about the compilation of a given source file. It
11 // contains generic components, leaving more complex interpretation to the
12 // specific language servers that consume it.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
17 #define MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
18 
19 #include "mlir/Support/LLVM.h"
20 #include "llvm/ADT/StringMap.h"
21 #include <memory>
22 #include <string>
23 
24 namespace mlir {
25 namespace lsp {
26 /// This class contains a collection of compilation information for files
27 /// provided to the language server, such as the available include directories.
28 /// This database acts as an aggregate in-memory form of compilation databases
29 /// used by the current language client. The textual form of a compilation
30 /// database is a YAML file containing documents of the following form:
31 ///
32 /// --- !FileInfo:
33 /// filepath: <string> - Absolute file path of the file.
34 /// includes: <string> - Semi-colon delimited list of include directories.
35 ///
37 public:
38  /// Compilation information for a specific file within the database.
39  struct FileInfo {
40  FileInfo() = default;
41  FileInfo(std::vector<std::string> &&includeDirs)
42  : includeDirs(std::move(includeDirs)) {}
43 
44  /// The include directories available for the file.
45  std::vector<std::string> includeDirs;
46  };
47 
48  /// Construct a compilation database from the provided files containing YAML
49  /// descriptions of the database.
51 
52  /// Get the compilation information for the provided file.
53  const FileInfo &getFileInfo(StringRef filename) const;
54 
55 private:
56  /// Load the given database file into this database.
57  void loadDatabase(StringRef filename);
58 
59  /// A map of filename to file information for each known file within the
60  /// databases.
61  llvm::StringMap<FileInfo> files;
62 
63  /// A default file info that contains basic information for use by files that
64  /// weren't explicitly in the database.
65  FileInfo defaultFileInfo;
66 };
67 } // namespace lsp
68 } // namespace mlir
69 
70 #endif // MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
This class contains a collection of compilation information for files provided to the language server...
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...
Include the generated interface declarations.
Compilation information for a specific file within the database.
FileInfo(std::vector< std::string > &&includeDirs)
std::vector< std::string > includeDirs
The include directories available for the file.