14#ifndef LLVM_CLANG_BASIC_FILEENTRY_H
15#define LLVM_CLANG_BASIC_FILEENTRY_H
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"
46namespace optional_detail {
49template <>
class OptionalStorage<
clang::FileEntryRef>;
61 StringRef
getName()
const {
return getBaseMapEntry().first(); }
71 return *cast<FileEntry *>(getBaseMapEntry().second->V);
76 inline void updateFileEntryBufferSize(
unsigned BufferSize);
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 bool isDeviceFile()
const;
86 inline void closeFile()
const;
100 return !(LHS == RHS);
103 return !(LHS == RHS);
106 return !(LHS == RHS);
118 using MapEntry = llvm::StringMapEntry<llvm::ErrorOr<MapValue>>;
127 llvm::PointerUnion<FileEntry *, const MapEntry *>
V;
157 operator const FileEntry *()
const {
return &getFileEntry(); }
161 assert(ME.second &&
"Expected payload");
162 assert(ME.second->V &&
"Expected non-null");
172 while (
const auto *Next =
Base->second->V.dyn_cast<
const MapEntry *>())
179 struct optional_none_tag {};
182 FileEntryRef(optional_none_tag) : ME(nullptr) {}
183 bool hasOptionalValue()
const {
return ME; }
186 struct dense_map_empty_tag {};
187 struct dense_map_tombstone_tag {};
190 FileEntryRef(dense_map_empty_tag)
191 : ME(
llvm::DenseMapInfo<const MapEntry *>::getEmptyKey()) {}
192 FileEntryRef(dense_map_tombstone_tag)
193 : ME(
llvm::DenseMapInfo<const MapEntry *>::getTombstoneKey()) {}
194 bool isSpecialDenseMapKey()
const {
195 return isSameRef(FileEntryRef(dense_map_empty_tag())) ||
196 isSameRef(FileEntryRef(dense_map_tombstone_tag()));
202static_assert(
sizeof(FileEntryRef) ==
sizeof(
const FileEntry *),
203 "FileEntryRef must avoid size overhead");
205static_assert(std::is_trivially_copyable<FileEntryRef>::value,
206 "FileEntryRef must be trivially copyable");
210namespace optional_detail {
223 template <
class... ArgTypes>
228 StorageImpl::operator=(Ref);
234 "OptionalFileEntryRef must avoid size overhead");
236static_assert(std::is_trivially_copyable<OptionalFileEntryRef>::value,
237 "OptionalFileEntryRef should be trivially copyable");
245template <>
struct DenseMapInfo<
clang::FileEntryRef> {
264 if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())
277 if (RHS.isSpecialDenseMapKey())
295 return !(LHS == RHS);
298 return !(LHS == RHS);
313 std::string RealPathName;
317 llvm::sys::fs::UniqueID UniqueID;
319 bool IsNamedPipe =
false;
320 bool IsDeviceFile =
false;
323 mutable std::unique_ptr<llvm::vfs::File> File;
326 std::unique_ptr<llvm::MemoryBuffer> Content;
334 void setSize(off_t NewSize) { Size = NewSize; }
336 const llvm::sys::fs::UniqueID &
getUniqueID()
const {
return UniqueID; }
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)
bool isDeviceFile() const
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).
bool isDeviceFile() const
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)