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 *getBaseMapEntry().second->V.get<
FileEntry *>();
75 inline off_t getSize()
const;
76 inline unsigned getUID()
const;
77 inline const llvm::sys::fs::UniqueID &getUniqueID()
const;
78 inline time_t getModificationTime()
const;
79 inline bool isNamedPipe()
const;
80 inline void closeFile()
const;
100 return !(LHS == RHS);
112 using MapEntry = llvm::StringMapEntry<llvm::ErrorOr<MapValue>>;
121 llvm::PointerUnion<FileEntry *, const MapEntry *>
V;
151 operator const FileEntry *()
const {
return &getFileEntry(); }
155 assert(ME.second &&
"Expected payload");
156 assert(ME.second->V &&
"Expected non-null");
166 while (
const auto *Next =
Base->second->V.dyn_cast<
const MapEntry *>())
173 struct optional_none_tag {};
176 FileEntryRef(optional_none_tag) : ME(nullptr) {}
177 bool hasOptionalValue()
const {
return ME; }
180 struct dense_map_empty_tag {};
181 struct dense_map_tombstone_tag {};
184 FileEntryRef(dense_map_empty_tag)
185 : ME(
llvm::DenseMapInfo<const MapEntry *>::getEmptyKey()) {}
186 FileEntryRef(dense_map_tombstone_tag)
187 : ME(
llvm::DenseMapInfo<const MapEntry *>::getTombstoneKey()) {}
188 bool isSpecialDenseMapKey()
const {
189 return isSameRef(FileEntryRef(dense_map_empty_tag())) ||
190 isSameRef(FileEntryRef(dense_map_tombstone_tag()));
196static_assert(
sizeof(FileEntryRef) ==
sizeof(
const FileEntry *),
197 "FileEntryRef must avoid size overhead");
199static_assert(std::is_trivially_copyable<FileEntryRef>::value,
200 "FileEntryRef must be trivially copyable");
204namespace optional_detail {
217 template <
class... ArgTypes>
222 StorageImpl::operator=(Ref);
228 "OptionalFileEntryRef must avoid size overhead");
230static_assert(std::is_trivially_copyable<OptionalFileEntryRef>::value,
231 "OptionalFileEntryRef should be trivially copyable");
239template <>
struct DenseMapInfo<
clang::FileEntryRef> {
258 if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())
271 if (RHS.isSpecialDenseMapKey())
289 return !(LHS == RHS);
292 return !(LHS == RHS);
307 std::string RealPathName;
311 llvm::sys::fs::UniqueID UniqueID;
313 bool IsNamedPipe =
false;
316 mutable std::unique_ptr<llvm::vfs::File> File;
319 std::unique_ptr<llvm::MemoryBuffer> Content;
327 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 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)
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
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)