annotate clang-tools-extra/clangd/FS.h @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 1f2b6ac9f198
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--- FS.h - File system related utils ------------------------*- C++-*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FS_H
anatofuz
parents:
diff changeset
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FS_H
anatofuz
parents:
diff changeset
11
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
12 #include "support/Path.h"
150
anatofuz
parents:
diff changeset
13 #include "clang/Basic/LLVM.h"
anatofuz
parents:
diff changeset
14 #include "llvm/ADT/Optional.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 #include "llvm/ADT/StringMap.h"
150
anatofuz
parents:
diff changeset
16 #include "llvm/Support/VirtualFileSystem.h"
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 namespace clang {
anatofuz
parents:
diff changeset
19 namespace clangd {
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 /// Records status information for files open()ed or stat()ed during preamble
anatofuz
parents:
diff changeset
22 /// build (except for the main file), so we can avoid stat()s on the underlying
anatofuz
parents:
diff changeset
23 /// FS when reusing the preamble. For example, code completion can re-stat files
anatofuz
parents:
diff changeset
24 /// when getting FileID for source locations stored in preamble (e.g. checking
anatofuz
parents:
diff changeset
25 /// whether a location is in the main file).
anatofuz
parents:
diff changeset
26 ///
anatofuz
parents:
diff changeset
27 /// The cache is keyed by absolute path of file name in cached status, as this
anatofuz
parents:
diff changeset
28 /// is what preamble stores.
anatofuz
parents:
diff changeset
29 ///
anatofuz
parents:
diff changeset
30 /// The cache is not thread-safe when updates happen, so the use pattern should
anatofuz
parents:
diff changeset
31 /// be:
anatofuz
parents:
diff changeset
32 /// - One FS writes to the cache from one thread (or several but strictly
anatofuz
parents:
diff changeset
33 /// sequenced), e.g. when building preamble.
anatofuz
parents:
diff changeset
34 /// - Sequence point (no writes after this point, no reads before).
anatofuz
parents:
diff changeset
35 /// - Several FSs can read from the cache, e.g. code completions.
anatofuz
parents:
diff changeset
36 ///
anatofuz
parents:
diff changeset
37 /// Note that the cache is only valid when reusing preamble.
anatofuz
parents:
diff changeset
38 class PreambleFileStatusCache {
anatofuz
parents:
diff changeset
39 public:
anatofuz
parents:
diff changeset
40 /// \p MainFilePath is the absolute path of the main source file this preamble
anatofuz
parents:
diff changeset
41 /// corresponds to. The stat for the main file will not be cached.
anatofuz
parents:
diff changeset
42 PreambleFileStatusCache(llvm::StringRef MainFilePath);
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 void update(const llvm::vfs::FileSystem &FS, llvm::vfs::Status S);
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 /// \p Path is a path stored in preamble.
anatofuz
parents:
diff changeset
47 llvm::Optional<llvm::vfs::Status> lookup(llvm::StringRef Path) const;
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 /// Returns a VFS that collects file status.
anatofuz
parents:
diff changeset
50 /// Only cache stats for files that exist because
anatofuz
parents:
diff changeset
51 /// 1) we only care about existing files when reusing preamble, unlike
anatofuz
parents:
diff changeset
52 /// building preamble.
anatofuz
parents:
diff changeset
53 /// 2) we use the file name in the Status as the cache key.
anatofuz
parents:
diff changeset
54 ///
anatofuz
parents:
diff changeset
55 /// Note that the returned VFS should not outlive the cache.
anatofuz
parents:
diff changeset
56 IntrusiveRefCntPtr<llvm::vfs::FileSystem>
anatofuz
parents:
diff changeset
57 getProducingFS(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 /// Returns a VFS that uses the cache collected.
anatofuz
parents:
diff changeset
60 ///
anatofuz
parents:
diff changeset
61 /// Note that the returned VFS should not outlive the cache.
anatofuz
parents:
diff changeset
62 IntrusiveRefCntPtr<llvm::vfs::FileSystem>
anatofuz
parents:
diff changeset
63 getConsumingFS(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) const;
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 private:
anatofuz
parents:
diff changeset
66 std::string MainFilePath;
anatofuz
parents:
diff changeset
67 llvm::StringMap<llvm::vfs::Status> StatCache;
anatofuz
parents:
diff changeset
68 };
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 /// Returns a version of \p File that doesn't contain dots and dot dots.
anatofuz
parents:
diff changeset
71 /// e.g /a/b/../c -> /a/c
anatofuz
parents:
diff changeset
72 /// /a/b/./c -> /a/b/c
anatofuz
parents:
diff changeset
73 /// FIXME: We should avoid encountering such paths in clangd internals by
anatofuz
parents:
diff changeset
74 /// filtering everything we get over LSP, CDB, etc.
anatofuz
parents:
diff changeset
75 Path removeDots(PathRef File);
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 } // namespace clangd
anatofuz
parents:
diff changeset
78 } // namespace clang
anatofuz
parents:
diff changeset
79
anatofuz
parents:
diff changeset
80 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_FS_H