File indexing completed on 2026-05-10 08:36:56
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_INDEXSERIALIZATION_SERIALIZABLEPATHCOLLECTION_H
0010 #define LLVM_CLANG_INDEXSERIALIZATION_SERIALIZABLEPATHCOLLECTION_H
0011
0012 #include "clang/Basic/FileManager.h"
0013 #include "llvm/ADT/APInt.h"
0014 #include "llvm/ADT/DenseMap.h"
0015 #include "llvm/ADT/SmallString.h"
0016 #include "llvm/ADT/StringMap.h"
0017 #include "llvm/ADT/StringRef.h"
0018 #include "llvm/ADT/iterator.h"
0019
0020 #include <string>
0021 #include <vector>
0022
0023 namespace clang {
0024 namespace index {
0025
0026
0027 class StringPool {
0028 llvm::SmallString<512> Buffer;
0029
0030 public:
0031 struct StringOffsetSize {
0032 std::size_t Offset;
0033 std::size_t Size;
0034
0035 StringOffsetSize(size_t Offset, size_t Size) : Offset(Offset), Size(Size) {}
0036 };
0037
0038 StringOffsetSize add(StringRef Str);
0039 StringRef getBuffer() const { return Buffer; }
0040 };
0041
0042
0043 class PathPool {
0044 public:
0045
0046 enum class RootDirKind {
0047 Regular = 0,
0048 CurrentWorkDir = 1,
0049 SysRoot = 2,
0050 };
0051
0052 struct DirPath {
0053 RootDirKind Root;
0054 StringPool::StringOffsetSize Path;
0055
0056 DirPath(RootDirKind Root, const StringPool::StringOffsetSize &Path)
0057 : Root(Root), Path(Path) {}
0058 };
0059
0060 struct FilePath {
0061 DirPath Dir;
0062 StringPool::StringOffsetSize Filename;
0063
0064 FilePath(const DirPath &Dir, const StringPool::StringOffsetSize &Filename)
0065 : Dir(Dir), Filename(Filename) {}
0066 };
0067
0068
0069 size_t addFilePath(RootDirKind Root, const StringPool::StringOffsetSize &Dir,
0070 StringRef Filename);
0071
0072
0073 StringPool::StringOffsetSize addDirPath(StringRef Dir);
0074
0075 llvm::ArrayRef<FilePath> getFilePaths() const;
0076
0077 StringRef getPaths() const;
0078
0079 private:
0080 StringPool Paths;
0081 std::vector<FilePath> FilePaths;
0082 };
0083
0084
0085 class SerializablePathCollection {
0086 std::string WorkDir;
0087 std::string SysRoot;
0088
0089 PathPool Paths;
0090 llvm::DenseMap<const clang::FileEntry *, std::size_t> UniqueFiles;
0091 llvm::StringMap<PathPool::DirPath, llvm::BumpPtrAllocator> UniqueDirs;
0092
0093 public:
0094 const StringPool::StringOffsetSize WorkDirPath;
0095 const StringPool::StringOffsetSize SysRootPath;
0096 const StringPool::StringOffsetSize OutputFilePath;
0097
0098 SerializablePathCollection(llvm::StringRef CurrentWorkDir,
0099 llvm::StringRef SysRoot,
0100 llvm::StringRef OutputFile);
0101
0102
0103 llvm::StringRef getPathsBuffer() const { return Paths.getPaths(); }
0104
0105
0106
0107 ArrayRef<PathPool::FilePath> getFilePaths() const {
0108 return Paths.getFilePaths();
0109 }
0110
0111
0112
0113 size_t tryStoreFilePath(FileEntryRef FE);
0114
0115 private:
0116
0117
0118
0119 StringPool::StringOffsetSize storePath(llvm::StringRef Path);
0120
0121
0122 PathPool::DirPath tryStoreDirPath(llvm::StringRef dirStr);
0123 };
0124
0125 }
0126 }
0127
0128 #endif