clang: include/clang/Basic/FileEntry.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_BASIC_FILEENTRY_H
15#define LLVM_CLANG_BASIC_FILEENTRY_H
16
20#include "llvm/ADT/DenseMapInfo.h"
21#include "llvm/ADT/Hashing.h"
22#include "llvm/ADT/PointerUnion.h"
23#include "llvm/ADT/StringMap.h"
24#include "llvm/ADT/StringRef.h"
25#include "llvm/Support/ErrorOr.h"
26#include "llvm/Support/FileSystem/UniqueID.h"
27
28#include
29#include
30
31namespace llvm {
32
33class MemoryBuffer;
34
35namespace vfs {
36
38
39}
40}
41
43
44class FileEntryRef;
45
46namespace optional_detail {
47
48
49template <> class OptionalStorage<clang::FileEntryRef>;
50
51}
52
53class FileEntry;
54
55
56
58public:
59
60
61 StringRef getName() const { return getBaseMapEntry().first(); }
62
63
64
65
66
67
69
71 return *cast<FileEntry *>(getBaseMapEntry().second->V);
72 }
73
74
75
76 inline void updateFileEntryBufferSize(unsigned BufferSize);
77
79
80 inline off_t getSize() const;
81 inline unsigned getUID() const;
82 inline const llvm::sys::fs::UniqueID &getUniqueID() const;
83 inline time_t getModificationTime() const;
84 inline bool isNamedPipe() const;
85 inline void closeFile() const;
86
87
88
91 }
94 }
97 }
99 return !(LHS == RHS);
100 }
102 return !(LHS == RHS);
103 }
105 return !(LHS == RHS);
106 }
107
108
109
112 }
113
114 struct MapValue;
115
116
117 using MapEntry = llvm::StringMapEntry<llvm::ErrorOr>;
118
119
121
122
123
124
125
126 llvm::PointerUnion<FileEntry *, const MapEntry *> V;
127
128
130
134 };
135
136
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 operator const FileEntry *() const { return &getFileEntry(); }
157
160 assert(ME.second && "Expected payload");
161 assert(ME.second->V && "Expected non-null");
162 }
163
164
165
167
168
169 const MapEntry &getBaseMapEntry() const {
171 while (const auto *Next = Base->second->V.dyn_cast<const MapEntry *>())
173 return *Base;
174 }
175
176private:
178 struct optional_none_tag {};
179
180
181 FileEntryRef(optional_none_tag) : ME(nullptr) {}
182 bool hasOptionalValue() const { return ME; }
183
184 friend struct llvm::DenseMapInfo<FileEntryRef>;
185 struct dense_map_empty_tag {};
186 struct dense_map_tombstone_tag {};
187
188
189 FileEntryRef(dense_map_empty_tag)
190 : ME(llvm::DenseMapInfo<const MapEntry *>::getEmptyKey()) {}
191 FileEntryRef(dense_map_tombstone_tag)
192 : ME(llvm::DenseMapInfo<const MapEntry *>::getTombstoneKey()) {}
193 bool isSpecialDenseMapKey() const {
194 return isSameRef(FileEntryRef(dense_map_empty_tag())) ||
195 isSameRef(FileEntryRef(dense_map_tombstone_tag()));
196 }
197
198 const MapEntry *ME;
199};
200
201static_assert(sizeof(FileEntryRef) == sizeof(const FileEntry *),
202 "FileEntryRef must avoid size overhead");
203
204static_assert(std::is_trivially_copyable::value,
205 "FileEntryRef must be trivially copyable");
206
208
209namespace optional_detail {
210
211
212
213template <>
218
219public:
221
222 template <class... ArgTypes>
225
227 StorageImpl::operator=(Ref);
228 return *this;
229 }
230};
231
233 "OptionalFileEntryRef must avoid size overhead");
234
235static_assert(std::is_trivially_copyable::value,
236 "OptionalFileEntryRef should be trivially copyable");
237
238}
239}
240
241namespace llvm {
242
243
244template <> struct DenseMapInfo<clang::FileEntryRef> {
247 }
248
250 return clang::FileEntryRef(clang::FileEntryRef::dense_map_tombstone_tag());
251 }
252
255 }
256
258
260 return true;
261
262
263 if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())
264 return false;
265
266
267 return LHS == RHS;
268 }
269
270
271
274 }
276 if (RHS.isSpecialDenseMapKey())
277 return false;
278 return LHS == RHS;
279 }
280
281};
282
283}
284
286
288 return LHS == (RHS ? &RHS->getFileEntry() : nullptr);
289}
291 return (LHS ? &LHS->getFileEntry() : nullptr) == RHS;
292}
294 return !(LHS == RHS);
295}
297 return !(LHS == RHS);
298}
299
300
301
302
303
304
311
312 std::string RealPathName;
313 off_t Size = 0;
314 time_t ModTime = 0;
315 const DirectoryEntry *Dir = nullptr;
316 llvm::sys::fs::UniqueID UniqueID;
317 unsigned UID = 0;
318 bool IsNamedPipe = false;
319
320
321 mutable std::unique_ptrllvm::vfs::File File;
322
323
324 std::unique_ptrllvm::MemoryBuffer Content;
325
326public:
328
330 off_t getSize() const { return Size; }
331
332 void setSize(off_t NewSize) { Size = NewSize; }
333 unsigned getUID() const { return UID; }
334 const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
336
337
339
340
341
343
345};
346
348
350
353}
354
357}
358
360
362
364 cast<FileEntry *>(getBaseMapEntry().second->V)->setSize(BufferSize);
365}
366
367}
368
369#endif
Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Cached information about one directory (either on disk or in the virtual file system).
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
friend bool operator==(const FileEntry *LHS, const FileEntryRef &RHS)
friend llvm::hash_code hash_value(FileEntryRef Ref)
Hash code is based on the FileEntry, not the specific named reference, just like operator==.
const MapEntry & getBaseMapEntry() const
Retrieve the base MapEntry after redirects.
const FileEntry & getFileEntry() const
bool isSameRef(const FileEntryRef &RHS) const
Check if RHS referenced the file in exactly the same way.
const clang::FileEntryRef::MapEntry & getMapEntry() const
Expose the underlying MapEntry to simplify packing in a PointerIntPair or PointerUnion and allow cons...
time_t getModificationTime() const
friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS)
void updateFileEntryBufferSize(unsigned BufferSize)
FileEntryRef(const MapEntry &ME)
friend bool operator!=(const FileEntry *LHS, const FileEntryRef &RHS)
llvm::StringMapEntry< llvm::ErrorOr< MapValue > > MapEntry
Type used in the StringMap.
StringRef getName() const
The name of this FileEntry.
friend bool operator!=(const FileEntryRef &LHS, const FileEntry *RHS)
const llvm::sys::fs::UniqueID & getUniqueID() const
StringRef getNameAsRequested() const
The name of this FileEntry, as originally requested without applying any remappings for VFS 'use-exte...
DirectoryEntryRef getDir() const
friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS)
Check if the underlying FileEntry is the same, intentially ignoring whether the file was referenced w...
friend bool operator==(const FileEntryRef &LHS, const FileEntry *RHS)
Cached information about one file (either on disk or in the virtual file system).
const DirectoryEntry * getDir() const
Return the directory the file lives in.
StringRef tryGetRealPathName() const
friend class FileEntryTestHelper
void setSize(off_t NewSize)
time_t getModificationTime() const
bool isNamedPipe() const
Check whether the file is a named pipe (and thus can't be opened by the native FileManager methods).
const llvm::sys::fs::UniqueID & getUniqueID() const
Implements support for file system lookup, file system caching, and directory search management.
Customized storage for refs derived from map entires in FileManager, using the private optional_none_...
OptionalStorage(std::in_place_t, ArgTypes &&...Args)
OptionalStorage & operator=(clang::FileEntryRef Ref)
OptionalStorage()=default
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
bool operator!=(CanQual< T > x, CanQual< U > y)
Diagnostic wrappers for TextAPI types for error reporting.
hash_code hash_value(const clang::tooling::dependencies::ModuleID &ID)
Type stored in the StringMap.
DirectoryEntryRef Dir
Directory the file was found in.
MapValue(FileEntry &FE, DirectoryEntryRef Dir)
MapValue(MapEntry &ME, DirectoryEntryRef Dir)
llvm::PointerUnion< FileEntry *, const MapEntry * > V
The pointer at another MapEntry is used when the FileManager should silently forward from one name to...
static unsigned getHashValue(const clang::FileEntry *Val)
Support for finding const FileEntry * in a DenseMap<FileEntryRef, T>.
static unsigned getHashValue(clang::FileEntryRef Val)
static bool isEqual(const clang::FileEntry *LHS, clang::FileEntryRef RHS)
static clang::FileEntryRef getTombstoneKey()
static clang::FileEntryRef getEmptyKey()
static bool isEqual(clang::FileEntryRef LHS, clang::FileEntryRef RHS)