@@ -31,32 +31,16 @@ class File;
31
31
32
32
namespace clang {
33
33
34
- class FileEntryRef ;
35
-
36
- } // namespace clang
37
-
38
- namespace llvm {
39
- namespace optional_detail {
40
-
41
- // / Forward declare a template specialization for OptionalStorage.
42
- template <>
43
- class OptionalStorage <clang::FileEntryRef, /* is_trivially_copyable*/ true >;
44
-
45
- } // namespace optional_detail
46
- } // namespace llvm
47
-
48
- namespace clang {
49
-
50
34
class DirectoryEntry ;
51
35
class FileEntry ;
52
36
53
37
// / A reference to a \c FileEntry that includes the name of the file as it was
54
38
// / accessed by the FileManager's client.
55
39
class FileEntryRef {
56
40
public:
57
- StringRef getName () const { return ME ->first (); }
41
+ const StringRef getName () const { return Entry ->first (); }
58
42
const FileEntry &getFileEntry () const {
59
- return *ME ->second ->V .get <FileEntry *>();
43
+ return *Entry ->second ->V .get <FileEntry *>();
60
44
}
61
45
62
46
inline bool isValid () const ;
@@ -65,26 +49,12 @@ class FileEntryRef {
65
49
inline const llvm::sys::fs::UniqueID &getUniqueID () const ;
66
50
inline time_t getModificationTime () const ;
67
51
68
- // / Check if the underlying FileEntry is the same, intentially ignoring
69
- // / whether the file was referenced with the same spelling of the filename.
70
52
friend bool operator ==(const FileEntryRef &LHS, const FileEntryRef &RHS) {
71
- return &LHS.getFileEntry () == &RHS.getFileEntry ();
72
- }
73
- friend bool operator ==(const FileEntry *LHS, const FileEntryRef &RHS) {
74
- return LHS == &RHS.getFileEntry ();
75
- }
76
- friend bool operator ==(const FileEntryRef &LHS, const FileEntry *RHS) {
77
- return &LHS.getFileEntry () == RHS;
53
+ return LHS.Entry == RHS.Entry ;
78
54
}
79
55
friend bool operator !=(const FileEntryRef &LHS, const FileEntryRef &RHS) {
80
56
return !(LHS == RHS);
81
57
}
82
- friend bool operator !=(const FileEntry *LHS, const FileEntryRef &RHS) {
83
- return !(LHS == RHS);
84
- }
85
- friend bool operator !=(const FileEntryRef &LHS, const FileEntry *RHS) {
86
- return !(LHS == RHS);
87
- }
88
58
89
59
struct MapValue ;
90
60
@@ -108,191 +78,20 @@ class FileEntryRef {
108
78
MapValue (MapEntry &ME) : V(&ME) {}
109
79
};
110
80
111
- // / Check if RHS referenced the file in exactly the same way.
112
- bool isSameRef (const FileEntryRef &RHS) const { return ME == RHS.ME ; }
113
-
114
- // / Allow FileEntryRef to degrade into 'const FileEntry*' to facilitate
115
- // / incremental adoption.
116
- // /
117
- // / The goal is to avoid code churn due to dances like the following:
118
- // / \code
119
- // / // Old code.
120
- // / lvalue = rvalue;
121
- // /
122
- // / // Temporary code from an incremental patch.
123
- // / lvalue = &rvalue.getFileEntry();
124
- // /
125
- // / // Final code.
126
- // / lvalue = rvalue;
127
- // / \endcode
128
- // /
129
- // / FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
130
- // / FileEntry::getName have been deleted, delete this implicit conversion.
131
- operator const FileEntry *() const { return &getFileEntry (); }
132
-
133
- FileEntryRef () = delete ;
134
- explicit FileEntryRef (const MapEntry &ME) : ME(&ME) {
135
- assert (ME.second && " Expected payload" );
136
- assert (ME.second ->V && " Expected non-null" );
137
- assert (ME.second ->V .is <FileEntry *>() && " Expected FileEntry" );
138
- }
139
-
140
- // / Expose the underlying MapEntry to simplify packing in a PointerIntPair or
141
- // / PointerUnion and allow construction in Optional.
142
- const clang::FileEntryRef::MapEntry &getMapEntry () const { return *ME; }
143
-
144
81
private:
145
- friend class llvm ::optional_detail::OptionalStorage<
146
- FileEntryRef, /* is_trivially_copyable*/ true >;
147
- struct optional_none_tag {};
148
-
149
- // Private constructor for use by OptionalStorage.
150
- FileEntryRef (optional_none_tag) : ME(nullptr ) {}
151
- constexpr bool hasOptionalValue () const { return ME; }
152
-
153
- const MapEntry *ME;
154
- };
155
-
156
- static_assert (sizeof (FileEntryRef) == sizeof (const FileEntry *),
157
- " FileEntryRef must avoid size overhead" );
158
-
159
- static_assert (std::is_trivially_copyable<FileEntryRef>::value,
160
- " FileEntryRef must be trivially copyable" );
161
-
162
- } // end namespace clang
163
-
164
- namespace llvm {
165
- namespace optional_detail {
166
-
167
- // / Customize OptionalStorage<FileEntryRef> to use FileEntryRef and its
168
- // / optional_none_tag to keep it the size of a single pointer.
169
- template <> class OptionalStorage <clang::FileEntryRef> {
170
- clang::FileEntryRef MaybeRef;
171
-
172
- public:
173
- ~OptionalStorage () = default ;
174
- constexpr OptionalStorage () noexcept
175
- : MaybeRef(clang::FileEntryRef::optional_none_tag) {}
176
- constexpr OptionalStorage (OptionalStorage const &Other) = default;
177
- constexpr OptionalStorage (OptionalStorage &&Other) = default;
178
- OptionalStorage &operator =(OptionalStorage const &Other) = default ;
179
- OptionalStorage &operator =(OptionalStorage &&Other) = default ;
180
-
181
- template <class ... ArgTypes>
182
- constexpr explicit OptionalStorage (in_place_t , ArgTypes &&...Args)
183
- : MaybeRef(std::forward<ArgTypes>(Args)...) {}
184
-
185
- void reset () noexcept { MaybeRef = clang::FileEntryRef::optional_none_tag (); }
186
-
187
- constexpr bool hasValue () const noexcept {
188
- return MaybeRef.hasOptionalValue ();
189
- }
190
-
191
- clang::FileEntryRef &getValue () LLVM_LVALUE_FUNCTION noexcept {
192
- assert (hasValue ());
193
- return MaybeRef;
194
- }
195
- constexpr clang::FileEntryRef const &
196
- getValue () const LLVM_LVALUE_FUNCTION noexcept {
197
- assert (hasValue ());
198
- return MaybeRef;
199
- }
200
- #if LLVM_HAS_RVALUE_REFERENCE_THIS
201
- clang::FileEntryRef &&getValue() &&noexcept {
202
- assert (hasValue ());
203
- return std::move (MaybeRef);
204
- }
205
- #endif
206
-
207
- template <class ... Args> void emplace (Args &&...args) {
208
- MaybeRef = clang::FileEntryRef (std::forward<Args>(args)...);
209
- }
210
-
211
- OptionalStorage &operator =(clang::FileEntryRef Ref) {
212
- MaybeRef = Ref;
213
- return *this ;
214
- }
215
- };
216
-
217
- static_assert (sizeof (Optional<clang::FileEntryRef>) ==
218
- sizeof (clang::FileEntryRef),
219
- " Optional<FileEntryRef> must avoid size overhead" );
220
-
221
- static_assert (std::is_trivially_copyable<Optional<clang::FileEntryRef>>::value,
222
- " Optional<FileEntryRef> should be trivially copyable" );
223
-
224
- } // end namespace optional_detail
225
- } // end namespace llvm
226
-
227
- namespace clang {
82
+ friend class FileManager ;
228
83
229
- // / Wrapper around Optional<FileEntryRef> that degrades to 'const FileEntry*',
230
- // / facilitating incremental patches to propagate FileEntryRef.
231
- // /
232
- // / This class can be used as return value or field where it's convenient for
233
- // / an Optional<FileEntryRef> to degrade to a 'const FileEntry*'. The purpose
234
- // / is to avoid code churn due to dances like the following:
235
- // / \code
236
- // / // Old code.
237
- // / lvalue = rvalue;
238
- // /
239
- // / // Temporary code from an incremental patch.
240
- // / Optional<FileEntryRef> MaybeF = rvalue;
241
- // / lvalue = MaybeF ? &MaybeF.getFileEntry() : nullptr;
242
- // /
243
- // / // Final code.
244
- // / lvalue = rvalue;
245
- // / \endcode
246
- // /
247
- // / FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
248
- // / FileEntry::getName have been deleted, delete this class and replace
249
- // / instances with Optional<FileEntryRef>.
250
- class OptionalFileEntryRefDegradesToFileEntryPtr
251
- : public Optional<FileEntryRef> {
252
- public:
253
- constexpr OptionalFileEntryRefDegradesToFileEntryPtr () noexcept = default;
254
- constexpr OptionalFileEntryRefDegradesToFileEntryPtr (
255
- OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
256
- constexpr OptionalFileEntryRefDegradesToFileEntryPtr (
257
- const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
258
- OptionalFileEntryRefDegradesToFileEntryPtr &
259
- operator =(OptionalFileEntryRefDegradesToFileEntryPtr &&) = default ;
260
- OptionalFileEntryRefDegradesToFileEntryPtr &
261
- operator =(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default ;
262
-
263
- OptionalFileEntryRefDegradesToFileEntryPtr (llvm::NoneType) {}
264
- OptionalFileEntryRefDegradesToFileEntryPtr (FileEntryRef Ref)
265
- : Optional<FileEntryRef>(Ref) {}
266
- OptionalFileEntryRefDegradesToFileEntryPtr (Optional<FileEntryRef> MaybeRef)
267
- : Optional<FileEntryRef>(MaybeRef) {}
268
-
269
- OptionalFileEntryRefDegradesToFileEntryPtr &operator =(llvm::NoneType) {
270
- Optional<FileEntryRef>::operator =(None);
271
- return *this ;
272
- }
273
- OptionalFileEntryRefDegradesToFileEntryPtr &operator =(FileEntryRef Ref) {
274
- Optional<FileEntryRef>::operator =(Ref);
275
- return *this ;
276
- }
277
- OptionalFileEntryRefDegradesToFileEntryPtr &
278
- operator =(Optional<FileEntryRef> MaybeRef) {
279
- Optional<FileEntryRef>::operator =(MaybeRef);
280
- return *this ;
84
+ FileEntryRef () = delete ;
85
+ explicit FileEntryRef (const MapEntry &Entry)
86
+ : Entry(&Entry) {
87
+ assert (Entry.second && " Expected payload" );
88
+ assert (Entry.second ->V && " Expected non-null" );
89
+ assert (Entry.second ->V .is <FileEntry *>() && " Expected FileEntry" );
281
90
}
282
91
283
- // / Degrade to 'const FileEntry *' to allow FileEntry::LastRef and
284
- // / FileEntry::getName have been deleted, delete this class and replace
285
- // / instances with Optional<FileEntryRef>
286
- operator const FileEntry *() const {
287
- return hasValue () ? &getValue ().getFileEntry () : nullptr ;
288
- }
92
+ const MapEntry *Entry;
289
93
};
290
94
291
- static_assert (
292
- std::is_trivially_copyable<
293
- OptionalFileEntryRefDegradesToFileEntryPtr>::value,
294
- " OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable" );
295
-
296
95
// / Cached information about one file (either on disk
297
96
// / or in the virtual file system).
298
97
// /
@@ -348,6 +147,10 @@ class FileEntry {
348
147
bool isNamedPipe () const { return IsNamedPipe; }
349
148
350
149
void closeFile () const ;
150
+
151
+ // Only for use in tests to see if deferred opens are happening, rather than
152
+ // relying on RealPathName being empty.
153
+ bool isOpenForTests () const { return File != nullptr ; }
351
154
};
352
155
353
156
bool FileEntryRef::isValid () const { return getFileEntry ().isValid (); }
0 commit comments