clang 20.0.0git
SerializablePathCollection.h
Go to the documentation of this file.
1//===--- SerializablePathCollection.h -- Index of paths ---------*- 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#ifndef LLVM_CLANG_INDEXSERIALIZATION_SERIALIZABLEPATHCOLLECTION_H
10#define LLVM_CLANG_INDEXSERIALIZATION_SERIALIZABLEPATHCOLLECTION_H
11
13#include "llvm/ADT/APInt.h"
14#include "llvm/ADT/DenseMap.h"
15#include "llvm/ADT/SmallString.h"
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/iterator.h"
19
20#include <string>
21#include <vector>
22
23namespace clang {
24namespace index {
25
26/// Pool of strings
29
30public:
32 std::size_t Offset;
33 std::size_t Size;
34
36 };
37
38 StringOffsetSize add(StringRef Str);
39 StringRef getBuffer() const { return Buffer; }
40};
41
42/// Pool of filesystem paths backed by a StringPool
43class PathPool {
44public:
45 /// Special root directory of a filesystem path.
46 enum class RootDirKind {
47 Regular = 0,
49 SysRoot = 2,
50 };
51
52 struct DirPath {
55
57 : Root(Root), Path(Path) {}
58 };
59
60 struct FilePath {
63
65 : Dir(Dir), Filename(Filename) {}
66 };
67
68 /// \returns index of the newly added file in FilePaths.
70 StringRef Filename);
71
72 /// \returns offset in Paths and size of newly added directory.
74
76
77 StringRef getPaths() const;
78
79private:
80 StringPool Paths;
81 std::vector<FilePath> FilePaths;
82};
83
84/// Stores file paths and produces serialization-friendly representation.
86 std::string WorkDir;
87 std::string SysRoot;
88
89 PathPool Paths;
90 llvm::DenseMap<const clang::FileEntry *, std::size_t> UniqueFiles;
91 llvm::StringMap<PathPool::DirPath, llvm::BumpPtrAllocator> UniqueDirs;
92
93public:
97
98 SerializablePathCollection(llvm::StringRef CurrentWorkDir,
99 llvm::StringRef SysRoot,
100 llvm::StringRef OutputFile);
101
102 /// \returns buffer containing all the paths.
103 llvm::StringRef getPathsBuffer() const { return Paths.getPaths(); }
104
105 /// \returns file paths (no directories) backed by buffer exposed in
106 /// getPathsBuffer.
108 return Paths.getFilePaths();
109 }
110
111 /// Stores path to \p FE if it hasn't been stored yet.
112 /// \returns index to array exposed by getPathsBuffer().
114
115private:
116 /// Stores \p Path if it is non-empty.
117 /// Warning: this method doesn't check for uniqueness.
118 /// \returns offset of \p Path value begin in buffer with stored paths.
119 StringPool::StringOffsetSize storePath(llvm::StringRef Path);
120
121 /// Stores \p dirStr path if it hasn't been stored yet.
122 PathPool::DirPath tryStoreDirPath(llvm::StringRef dirStr);
123};
124
125} // namespace index
126} // namespace clang
127
128#endif // LLVM_CLANG_INDEXSERIALIZATION_SERIALIZABLEPATHCOLLECTION_H
IndirectLocalPath & Path
Defines the clang::FileManager interface and associated types.
StringRef Filename
Definition: Format.cpp:3001
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:57
Pool of filesystem paths backed by a StringPool.
size_t addFilePath(RootDirKind Root, const StringPool::StringOffsetSize &Dir, StringRef Filename)
StringPool::StringOffsetSize addDirPath(StringRef Dir)
llvm::ArrayRef< FilePath > getFilePaths() const
RootDirKind
Special root directory of a filesystem path.
Stores file paths and produces serialization-friendly representation.
size_t tryStoreFilePath(FileEntryRef FE)
Stores path to FE if it hasn't been stored yet.
const StringPool::StringOffsetSize OutputFilePath
ArrayRef< PathPool::FilePath > getFilePaths() const
const StringPool::StringOffsetSize WorkDirPath
const StringPool::StringOffsetSize SysRootPath
StringOffsetSize add(StringRef Str)
The JSON file list parser is used to communicate input to InstallAPI.
DirPath(RootDirKind Root, const StringPool::StringOffsetSize &Path)
StringPool::StringOffsetSize Filename
FilePath(const DirPath &Dir, const StringPool::StringOffsetSize &Filename)