Line data Source code
1 : //===--- CompileArgsCache.h -------------------------------------*- C++-*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===---------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILEARGSCACHE_H
11 : #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILEARGSCACHE_H
12 :
13 : #include "GlobalCompilationDatabase.h"
14 : #include "Path.h"
15 : #include "clang/Tooling/CompilationDatabase.h"
16 :
17 : namespace clang {
18 : namespace clangd {
19 :
20 : /// A helper class used by ClangdServer to get compile commands from CDB.
21 : /// Also caches CompileCommands produced by compilation database on per-file
22 : /// basis. This avoids queries to CDB that can be much more expensive than a
23 : /// table lookup.
24 0 : class CompileArgsCache {
25 : public:
26 : CompileArgsCache(GlobalCompilationDatabase &CDB, Path ResourceDir);
27 :
28 : /// Gets compile command for \p File from cache or CDB if it's not in the
29 : /// cache.
30 : tooling::CompileCommand getCompileCommand(PathRef File);
31 :
32 : /// Removes a cache entry for \p File, if it's present in the cache.
33 : void invalidate(PathRef File);
34 :
35 : private:
36 : GlobalCompilationDatabase &CDB;
37 : const Path ResourceDir;
38 : llvm::StringMap<tooling::CompileCommand> Cached;
39 : };
40 :
41 : } // namespace clangd
42 : } // namespace clang
43 : #endif
|