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 void closeFile()
const;
102 return !(LHS == RHS);
105 return !(LHS == RHS);
117 using MapEntry = llvm::StringMapEntry<llvm::ErrorOr<MapValue>>;
126 llvm::PointerUnion<FileEntry *, const MapEntry *>
V;
156 operator const FileEntry *()
const {
return &getFileEntry(); }
160 assert(ME.second &&
"Expected payload");
161 assert(ME.second->V &&
"Expected non-null");
171 while (
const auto *Next =
Base->second->V.dyn_cast<
const MapEntry *>())
178 struct optional_none_tag {};
181 FileEntryRef(optional_none_tag) : ME(nullptr) {}
182 bool hasOptionalValue()
const {
return ME; }
185 struct dense_map_empty_tag {};
186 struct dense_map_tombstone_tag {};
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()));
201static_assert(
sizeof(FileEntryRef) ==
sizeof(
const FileEntry *),
202 "FileEntryRef must avoid size overhead");
204static_assert(std::is_trivially_copyable<FileEntryRef>::value,
205 "FileEntryRef must be trivially copyable");
209namespace optional_detail {
222 template <
class... ArgTypes>
227 StorageImpl::operator=(Ref);
233 "OptionalFileEntryRef must avoid size overhead");
235static_assert(std::is_trivially_copyable<OptionalFileEntryRef>::value,
236 "OptionalFileEntryRef should be trivially copyable");
244template <>
struct DenseMapInfo<
clang::FileEntryRef> {
263 if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())
276 if (RHS.isSpecialDenseMapKey())
294 return !(LHS == RHS);
297 return !(LHS == RHS);
312 std::string RealPathName;
316 llvm::sys::fs::UniqueID UniqueID;
318 bool IsNamedPipe =
false;
321 mutable std::unique_ptr<llvm::vfs::File> File;
324 std::unique_ptr<llvm::MemoryBuffer> Content;
332 void setSize(off_t NewSize) { Size = NewSize; }
334 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)
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)