clang: include/clang/Basic/FileManager.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_BASIC_FILEMANAGER_H

15#define LLVM_CLANG_BASIC_FILEMANAGER_H

16

21#include "llvm/ADT/DenseMap.h"

22#include "llvm/ADT/IntrusiveRefCntPtr.h"

23#include "llvm/ADT/PointerUnion.h"

24#include "llvm/ADT/SmallVector.h"

25#include "llvm/ADT/StringMap.h"

26#include "llvm/ADT/StringRef.h"

27#include "llvm/Support/Allocator.h"

28#include "llvm/Support/ErrorOr.h"

29#include "llvm/Support/FileSystem.h"

30#include "llvm/Support/VirtualFileSystem.h"

31#include

32#include

33#include

34#include

35

36namespace llvm {

37

38class MemoryBuffer;

39

40}

41

43

45

46

47

48

49

50

51

52

56 llvm::SpecificBumpPtrAllocator FilesAlloc;

57 llvm::SpecificBumpPtrAllocator DirsAlloc;

58

59

60 llvm::DenseMap<llvm::sys::fs::UniqueID, DirectoryEntry *> UniqueRealDirs;

61

62

63 llvm::DenseMap<llvm::sys::fs::UniqueID, FileEntry *> UniqueRealFiles;

64

65

66

67

68

70

72

73

74

76

77

78

79

80

81

82

83

84

85

86 llvm::StringMap<llvm::ErrorOr<DirectoryEntry &>, llvm::BumpPtrAllocator>

87 SeenDirEntries;

88

89

90

91

92

93

94 llvm::StringMap<llvm::ErrorOrFileEntryRef::MapValue, llvm::BumpPtrAllocator>

95 SeenFileEntries;

96

97

98

99

100

101 std::unique_ptr<llvm::StringMap<llvm::ErrorOrFileEntryRef::MapValue>>

102 SeenBypassFileEntries;

103

104

106

107

108 llvm::DenseMap<const void *, llvm::StringRef> CanonicalNames;

109

110

111 llvm::BumpPtrAllocator CanonicalNameStorage;

112

113

114

115 unsigned NextFileUID;

116

117

118 unsigned NumDirLookups = 0;

119 unsigned NumFileLookups = 0;

120 unsigned NumDirCacheMisses = 0;

121 unsigned NumFileCacheMisses = 0;

122

123

124 std::unique_ptr StatCache;

125

126 std::error_code getStatValue(StringRef Path, llvm::vfs::Status &Status,

127 bool isFile, std::unique_ptrllvm::vfs::File *F,

128 bool IsText = true);

129

130

131

132 void addAncestorsAsVirtualDirs(StringRef Path);

133

134

136

137public:

138

139

140

141

145

146

147

148

149

150

151

152

153 void setStatCache(std::unique_ptr statCache);

154

155

157

158

160

161

162

163

164

165

166

167

168

169

170

172 bool CacheFailure = true);

173

174

176 bool CacheFailure = true) {

177 return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure));

178 }

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

195 bool OpenFile = false,

196 bool CacheFailure = true,

197 bool IsText = true);

198

199

200

201

202

203

204

206

207

209 bool OpenFile = false,

210 bool CacheFailure = true) {

211 return llvm::expectedToOptional(

212 getFileRef(Filename, OpenFile, CacheFailure));

213 }

214

215

218

224

225

226

228

230 this->FS = std::move(FS);

231 }

232

233

234

235

236

238 time_t ModificationTime);

239

240

241

242

243

244

245

246

247

249

250

251

252

253

254

255 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer>

257 bool RequiresNullTerminator = true,

258 std::optional<int64_t> MaybeLimit = std::nullopt,

259 bool IsText = true);

260 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer>

262 bool RequiresNullTerminator = true,

263 std::optional<int64_t> MaybeLimit = std::nullopt,

264 bool IsText = true) const {

265 return getBufferForFileImpl(Filename,

266 MaybeLimit.value_or(-1),

267 isVolatile, RequiresNullTerminator, IsText);

268 }

269

270private:

271 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer>

272 getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile,

273 bool RequiresNullTerminator, bool IsText) const;

274

275 DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status);

276

277public:

278

279

280

281

282

283

285 llvm::vfs::Status &Result);

286

287

288

289

290

296

297

298

299

301

302

303

304 void

306

307

308

309

310

311

313

314

315

316

317

318

320

321private:

322

323

324

325 StringRef getCanonicalName(const void *Entry, StringRef Name);

326

327public:

329

330

331

333};

334

335}

336

337#endif

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

Defines interfaces for clang::FileEntry and clang::FileEntryRef.

Defines the clang::FileSystemOptions interface.

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

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

Implements support for file system lookup, file system caching, and directory search management.

Definition FileManager.h:53

void AddStats(const FileManager &Other)

Import statistics from a child FileManager and add them to this current FileManager.

void trackVFSUsage(bool Active)

Enable or disable tracking of VFS usage.

void clearStatCache()

Removes the FileSystemStatCache object from the manager.

llvm::vfs::FileSystem & getVirtualFileSystem() const

Definition FileManager.h:219

llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(FileEntryRef Entry, bool isVolatile=false, bool RequiresNullTerminator=true, std::optional< int64_t > MaybeLimit=std::nullopt, bool IsText=true)

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...

std::error_code getNoncachedStatValue(StringRef Path, llvm::vfs::Status &Result)

Get the 'stat' information for the given Path.

FileManager(const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)

Construct a file manager, optionally with a custom VFS.

OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)

Get a FileEntryRef if it exists, without doing anything on error.

Definition FileManager.h:208

llvm::Expected< FileEntryRef > getSTDIN()

Get the FileEntryRef for stdin, returning an error if stdin cannot be read.

StringRef getCanonicalName(DirectoryEntryRef Dir)

Retrieve the canonical name for a given directory.

void GetUniqueIDMapping(SmallVectorImpl< OptionalFileEntryRef > &UIDToFiles) const

Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntryRef.

bool makeAbsolutePath(SmallVectorImpl< char > &Path) const

Makes Path absolute taking into account FileSystemOptions and the working directory option.

llvm::Expected< DirectoryEntryRef > getDirectoryRef(StringRef DirName, bool CacheFailure=true)

Lookup, cache, and verify the specified directory (real or virtual).

void setStatCache(std::unique_ptr< FileSystemStatCache > statCache)

Installs the provided FileSystemStatCache object within the FileManager.

FileSystemOptions & getFileSystemOpts()

Returns the current file system options.

Definition FileManager.h:216

llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > getVirtualFileSystemPtr() const

Definition FileManager.h:221

const FileSystemOptions & getFileSystemOpts() const

Definition FileManager.h:217

FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size, time_t ModificationTime)

Retrieve a file entry for a "virtual" file that acts as if there were a file with the given name on d...

bool FixupRelativePath(SmallVectorImpl< char > &Path) const

If path is not absolute and FileSystemOptions set the working directory, the path is modified to be r...

Definition FileManager.h:291

size_t getNumUniqueRealFiles() const

Returns the number of unique real file entries cached by the file manager.

Definition FileManager.h:159

llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(StringRef Filename, bool isVolatile=false, bool RequiresNullTerminator=true, std::optional< int64_t > MaybeLimit=std::nullopt, bool IsText=true) const

Definition FileManager.h:261

OptionalFileEntryRef getBypassFile(FileEntryRef VFE)

Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual file entry,...

static bool fixupRelativePath(const FileSystemOptions &FileSystemOpts, SmallVectorImpl< char > &Path)

void setVirtualFileSystem(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)

Definition FileManager.h:229

OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)

Get a DirectoryEntryRef if it exists, without doing anything on error.

Definition FileManager.h:175

llvm::Expected< FileEntryRef > getFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true, bool IsText=true)

Lookup, cache, and verify the specified file (real or virtual).

Keeps track of options that affect how file operations are performed.

Abstract interface for introducing a FileManager cache for 'stat' system calls, which is used by prec...

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

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

@ Result

The result type of a method or function.

CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef

@ Other

Other implicit parameter.

Diagnostic wrappers for TextAPI types for error reporting.