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

45

47

48

50

51}

52

53class FileEntry;

54

55

56

58public:

59

60

62

63

64

65

66

67

69

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 bool isDeviceFile() const;

86 inline void closeFile() const;

87

88

89

100 return !(LHS == RHS);

101 }

103 return !(LHS == RHS);

104 }

106 return !(LHS == RHS);

107 }

108

109

110

114

115 struct MapValue;

116

117

118 using MapEntry = llvm::StringMapEntry<llvm::ErrorOr>;

119

120

122

123

124

125

126

127 llvm::PointerUnion<FileEntry *, const MapEntry *> V;

128

129

131

135 };

136

137

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

158

161 assert(ME.second && "Expected payload");

162 assert(ME.second->V && "Expected non-null");

163 }

164

165

166

168

169

172 while (const auto *Next = Base->second->V.dyn_cast<const MapEntry *>())

174 return *Base;

175 }

176

177private:

179 struct optional_none_tag {};

180

181

182 FileEntryRef(optional_none_tag) : ME(nullptr) {}

183 bool hasOptionalValue() const { return ME; }

184

185 friend struct llvm::DenseMapInfo<FileEntryRef>;

186 struct dense_map_empty_tag {};

187 struct dense_map_tombstone_tag {};

188

189

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()));

197 }

198

199 const MapEntry *ME;

200};

201

202static_assert(sizeof(FileEntryRef) == sizeof(const FileEntry *),

203 "FileEntryRef must avoid size overhead");

204

205static_assert(std::is_trivially_copyable::value,

206 "FileEntryRef must be trivially copyable");

207

209

211

212

213

214template <>

217 using StorageImpl =

219

220public:

221 using StorageImpl::StorageImpl;

222

227};

228

230 "OptionalFileEntryRef must avoid size overhead");

231

232static_assert(std::is_trivially_copyable::value,

233 "OptionalFileEntryRef should be trivially copyable");

234

235}

236}

237

238namespace llvm {

239

240

241template <> struct DenseMapInfo<clang::FileEntryRef> {

245

249

253

255

257 return true;

258

259

260 if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey())

261 return false;

262

263

264 return LHS == RHS;

265 }

266

267

268

273 if (RHS.isSpecialDenseMapKey())

274 return false;

275 return LHS == RHS;

276 }

277

278};

279

280}

281

282namespace clang {

283

285 return LHS == (RHS ? &RHS->getFileEntry() : nullptr);

286}

288 return (LHS ? &LHS->getFileEntry() : nullptr) == RHS;

289}

291 return !(LHS == RHS);

292}

294 return !(LHS == RHS);

295}

296

297

298

299

300

301

302class FileEntry {

305 FileEntry();

306 FileEntry(const FileEntry &) = delete;

307 FileEntry &operator=(const FileEntry &) = delete;

308

309 std::string RealPathName;

310 off_t Size = 0;

311 time_t ModTime = 0;

312 const DirectoryEntry *Dir = nullptr;

313 llvm::sys::fs::UniqueID UniqueID;

314 unsigned UID = 0;

315 bool IsNamedPipe = false;

316 bool IsDeviceFile = false;

317

318

319 mutable std::unique_ptrllvm::vfs::File File;

320

321

322 std::unique_ptrllvm::MemoryBuffer Content;

323

324public:

326

328 off_t getSize() const { return Size; }

329

330 void setSize(off_t NewSize) { Size = NewSize; }

331 unsigned getUID() const { return UID; }

332 const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }

334

335

337

338

339

342

344};

345

347

349

353

357

362

364

368

369}

370

371#endif

Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.

FormatToken * Next

The next token in the unwrapped line.

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...

Definition FileEntry.h:57

friend bool operator==(const FileEntry *LHS, const FileEntryRef &RHS)

Definition FileEntry.h:93

bool isDeviceFile() const

Definition FileEntry.h:359

friend llvm::hash_code hash_value(FileEntryRef Ref)

Hash code is based on the FileEntry, not the specific named reference, just like operator==.

Definition FileEntry.h:111

const MapEntry & getBaseMapEntry() const

Retrieve the base MapEntry after redirects.

Definition FileEntry.h:170

const FileEntry & getFileEntry() const

Definition FileEntry.h:70

bool isSameRef(const FileEntryRef &RHS) const

Check if RHS referenced the file in exactly the same way.

Definition FileEntry.h:138

const clang::FileEntryRef::MapEntry & getMapEntry() const

Expose the underlying MapEntry to simplify packing in a PointerIntPair or PointerUnion and allow cons...

Definition FileEntry.h:167

void closeFile() const

Definition FileEntry.h:363

time_t getModificationTime() const

Definition FileEntry.h:354

friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS)

Definition FileEntry.h:99

llvm::StringMapEntry< llvm::ErrorOr< MapValue > > MapEntry

Type used in the StringMap.

Definition FileEntry.h:118

bool isNamedPipe() const

Definition FileEntry.h:358

void updateFileEntryBufferSize(unsigned BufferSize)

Definition FileEntry.h:365

FileEntryRef(const MapEntry &ME)

Definition FileEntry.h:160

friend bool operator!=(const FileEntry *LHS, const FileEntryRef &RHS)

Definition FileEntry.h:102

off_t getSize() const

Definition FileEntry.h:346

StringRef getName() const

The name of this FileEntry.

Definition FileEntry.h:61

friend bool operator!=(const FileEntryRef &LHS, const FileEntry *RHS)

Definition FileEntry.h:105

const llvm::sys::fs::UniqueID & getUniqueID() const

Definition FileEntry.h:350

StringRef getNameAsRequested() const

The name of this FileEntry, as originally requested without applying any remappings for VFS 'use-exte...

Definition FileEntry.h:68

DirectoryEntryRef getDir() const

Definition FileEntry.h:78

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...

Definition FileEntry.h:90

unsigned getUID() const

Definition FileEntry.h:348

friend bool operator==(const FileEntryRef &LHS, const FileEntry *RHS)

Definition FileEntry.h:96

Cached information about one file (either on disk or in the virtual file system).

Definition FileEntry.h:302

bool isDeviceFile() const

Definition FileEntry.h:341

const DirectoryEntry * getDir() const

Return the directory the file lives in.

Definition FileEntry.h:336

StringRef tryGetRealPathName() const

Definition FileEntry.h:327

friend class FileEntryTestHelper

Definition FileEntry.h:304

void setSize(off_t NewSize)

Definition FileEntry.h:330

time_t getModificationTime() const

Definition FileEntry.h:333

unsigned getUID() const

Definition FileEntry.h:331

friend class FileManager

Definition FileEntry.h:303

bool isNamedPipe() const

Check whether the file is a named pipe (and thus can't be opened by the native FileManager methods).

Definition FileEntry.h:340

off_t getSize() const

Definition FileEntry.h:328

const llvm::sys::fs::UniqueID & getUniqueID() const

Definition FileEntry.h:332

Customized storage for refs derived from map entires in FileManager, using the private optional_none_...

MapEntryOptionalStorage & operator=(clang::FileEntryRef Ref)

OptionalStorage & operator=(clang::FileEntryRef Ref)

Definition FileEntry.h:223

The JSON file list parser is used to communicate input to InstallAPI.

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

Definition FileEntry.h:208

bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)

nullptr

This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...

bool operator!=(CanQual< T > x, CanQual< U > y)

U cast(CodeGen::Address addr)

Diagnostic wrappers for TextAPI types for error reporting.

hash_code hash_value(const clang::dependencies::ModuleID &ID)

DirectoryEntryRef Dir

Directory the file was found in.

Definition FileEntry.h:130

MapValue(FileEntry &FE, DirectoryEntryRef Dir)

Definition FileEntry.h:133

MapValue(MapEntry &ME, DirectoryEntryRef Dir)

Definition FileEntry.h:134

llvm::PointerUnion< FileEntry *, const MapEntry * > V

The pointer at another MapEntry is used when the FileManager should silently forward from one name to...

Definition FileEntry.h:127

static unsigned getHashValue(const clang::FileEntry *Val)

Support for finding const FileEntry * in a DenseMap<FileEntryRef, T>.

Definition FileEntry.h:269

static unsigned getHashValue(clang::FileEntryRef Val)

Definition FileEntry.h:250

static bool isEqual(const clang::FileEntry *LHS, clang::FileEntryRef RHS)

Definition FileEntry.h:272

static clang::FileEntryRef getTombstoneKey()

Definition FileEntry.h:246

static clang::FileEntryRef getEmptyKey()

Definition FileEntry.h:242

static bool isEqual(clang::FileEntryRef LHS, clang::FileEntryRef RHS)

Definition FileEntry.h:254