|
clang 23.0.0git
|
Implements support for file system lookup, file system caching, and directory search management. More...
#include "clang/Basic/FileManager.h"
Public Member Functions | |
| FileManager (const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr) | |
| Construct a file manager, optionally with a custom VFS. | |
| ~FileManager () | |
| size_t | getNumUniqueRealFiles () const |
| Returns the number of unique real file entries cached by the file manager. | |
| llvm::Expected< DirectoryEntryRef > | getDirectoryRef (StringRef DirName, bool CacheFailure=true) |
| Lookup, cache, and verify the specified directory (real or virtual). | |
| OptionalDirectoryEntryRef | getOptionalDirectoryRef (StringRef DirName, bool CacheFailure=true) |
Get a DirectoryEntryRef if it exists, without doing anything on error. | |
| 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). | |
| llvm::Expected< FileEntryRef > | getSTDIN () |
| Get the FileEntryRef for stdin, returning an error if stdin cannot be read. | |
| OptionalFileEntryRef | getOptionalFileRef (StringRef Filename, bool OpenFile=false, bool CacheFailure=true, bool IsText=true) |
| Get a FileEntryRef if it exists, without doing anything on error. | |
| FileSystemOptions & | getFileSystemOpts () |
| Returns the current file system options. | |
| const FileSystemOptions & | getFileSystemOpts () const |
| llvm::vfs::FileSystem & | getVirtualFileSystem () const |
| llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > | getVirtualFileSystemPtr () const |
| void | trackVFSUsage (bool Active) |
| Enable or disable tracking of VFS usage. | |
| void | setVirtualFileSystem (IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS) |
| 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 disk. | |
| OptionalFileEntryRef | getBypassFile (FileEntryRef VFE) |
| Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual file entry, to access the real file. | |
| 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, otherwise returning null. | |
| 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 |
| bool | FixupRelativePath (SmallVectorImpl< char > &Path) const |
| If path is not absolute and FileSystemOptions set the working directory, the path is modified to be relative to the given working directory. | |
| bool | makeAbsolutePath (SmallVectorImpl< char > &Path, bool Canonicalize=false) const |
Makes Path absolute taking into account FileSystemOptions and the working directory option, and canonicalizes through llvm::path::remove_dots if Canonicalize is true. | |
| StringRef | getCanonicalName (DirectoryEntryRef Dir) |
| Retrieve the canonical name for a given directory. | |
| StringRef | getCanonicalName (FileEntryRef File) |
| Retrieve the canonical name for a given file. | |
| void | PrintStats () const |
| void | AddStats (const FileManager &Other) |
| Import statistics from a child FileManager and add them to this current FileManager. | |
Static Public Member Functions | |
| static bool | fixupRelativePath (const FileSystemOptions &FileSystemOpts, SmallVectorImpl< char > &Path) |
Implements support for file system lookup, file system caching, and directory search management.
This also handles more advanced properties, such as uniquing files based on "inode", so that a file with two names (e.g. symlinked) will be treated as a single file.
Definition at line 52 of file FileManager.h.
| FileManager::FileManager | ( | const FileSystemOptions & | FileSystemOpts, |
| IntrusiveRefCntPtr< llvm::vfs::FileSystem > | FS = nullptr ) |
Construct a file manager, optionally with a custom VFS.
| FS | if non-null, the VFS to use. Otherwise uses llvm::vfs::getRealFileSystem(). |
Definition at line 66 of file FileManager.cpp.
Referenced by AddStats().
|
default |
| void FileManager::AddStats | ( | const FileManager & | Other | ) |
Import statistics from a child FileManager and add them to this current FileManager.
Definition at line 691 of file FileManager.cpp.
References FileManager(), and clang::Other.
Referenced by clang::CompilerInstance::compileModule().
|
inline |
If path is not absolute and FileSystemOptions set the working directory, the path is modified to be relative to the given working directory.
Path changed. Definition at line 295 of file FileManager.h.
References fixupRelativePath().
Referenced by makeAbsolutePath().
|
static |
Definition at line 482 of file FileManager.cpp.
Referenced by FixupRelativePath().
| llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > FileManager::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, otherwise returning null.
The IsText parameter controls whether the file should be opened as a text or binary file, and should be set to false if the file contents should be treated as binary.
Definition at line 523 of file FileManager.cpp.
References clang::FileEntry::closeFile(), clang::FileEntryRef::getFileEntry(), clang::FileEntryRef::getName(), clang::FileEntry::getSize(), clang::FileEntry::isNamedPipe(), and clang::Result.
Referenced by clang::HeaderMap::Create(), clang::extractapi::APIIgnoresList::create(), clang::PrintPreambleAction::ExecuteAction(), clang::SrcMgr::ContentCache::getBufferOrNone(), clang::ASTUnit::LoadFromASTFile(), and clang::loadLinkModules().
|
inline |
Definition at line 274 of file FileManager.h.
| OptionalFileEntryRef FileManager::getBypassFile | ( | FileEntryRef | VFE | ) |
Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual file entry, to access the real file.
The returned FileEntry will have the same filename as FE but a different identity and its own stat.
This should be used only for rare error recovery paths because it bypasses all mapping and uniquing, blindly creating a new FileEntry. There is no attempt to deduplicate these; if you bypass the same file twice, you get two new file entries.
Definition at line 453 of file FileManager.cpp.
References clang::FileEntryRef::getDir(), clang::FileEntryRef::getFileEntry(), and clang::FileEntryRef::getName().
| StringRef FileManager::getCanonicalName | ( | DirectoryEntryRef | Dir | ) |
Retrieve the canonical name for a given directory.
This is a very expensive operation, despite its results being cached, and should only be used when the physical layout of the file system is required, which is (almost) never.
Definition at line 645 of file FileManager.cpp.
References getCanonicalName(), and clang::DirectoryEntryRef::getName().
Referenced by clang::ModuleMap::canonicalizeModuleMapPath(), getCanonicalName(), and getCanonicalName().
| StringRef FileManager::getCanonicalName | ( | FileEntryRef | File | ) |
Retrieve the canonical name for a given file.
This is a very expensive operation, despite its results being cached, and should only be used when the physical layout of the file system is required, which is (almost) never.
Definition at line 649 of file FileManager.cpp.
References clang::File, and getCanonicalName().
|
inline |
Lookup, cache, and verify the specified directory (real or virtual).
This returns a std::error_code if there was an error reading the directory. On success, returns the reference to the directory entry together with the exact path that was used to access a file by a particular call to getDirectoryRef.
| CacheFailure | If true and the file does not exist, we'll cache the failure to find this file. |
Definition at line 170 of file FileManager.h.
Referenced by clang::ModuleMap::canonicalizeModuleMapPath().
|
inline |
Lookup, cache, and verify the specified file (real or virtual).
Return the reference to the file entry together with the exact path that was used to access a file by a particular call to getFileRef. If the underlying VFS is a redirecting VFS that uses external file names, the returned FileEntryRef will use the external name instead of the filename that was passed to this method.
This returns a std::error_code if there was an error loading the file, or a FileEntryRef otherwise.
| OpenFile | if true and the file exists, it will be opened. |
| CacheFailure | If true and the file does not exist, we'll cache the failure to find this file. |
Definition at line 200 of file FileManager.h.
Referenced by clang::tooling::formatAndApplyAllReplacements().
|
inline |
Returns the current file system options.
Definition at line 229 of file FileManager.h.
|
inline |
Definition at line 230 of file FileManager.h.
|
inline |
Returns the number of unique real file entries cached by the file manager.
Definition at line 158 of file FileManager.h.
|
inline |
Get a DirectoryEntryRef if it exists, without doing anything on error.
Definition at line 179 of file FileManager.h.
Referenced by clang::ApplyHeaderSearchOptions(), clang::FrontendAction::BeginSourceFile(), computeRelativePath(), clang::api_notes::APINotesManager::getCurrentModuleAPINotes(), loadModuleMapForModuleBuild(), and clang::Preprocessor::LookupEmbedFile().
|
inline |
Get a FileEntryRef if it exists, without doing anything on error.
Definition at line 219 of file FileManager.h.
Referenced by clang::tooling::applyAllReplacements(), clang::FrontendAction::BeginSourceFile(), clang::BackendConsumer::DontCallDiagHandler(), EnableCodeCompletion(), clang::installapi::findLibrary(), clang::Preprocessor::LookupEmbedFile(), clang::DirectoryLookup::LookupFile(), and prepareToBuildModule().
| llvm::Expected< FileEntryRef > FileManager::getSTDIN | ( | ) |
Get the FileEntryRef for stdin, returning an error if stdin cannot be read.
This reads and caches stdin before returning. Subsequent calls return the same file entry, and a reference to the cached input is returned by calls to getBufferForFile.
Definition at line 347 of file FileManager.cpp.
References getVirtualFileRef().
Referenced by clang::ASTUnit::LoadFromASTFile().
| FileEntryRef FileManager::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 disk.
The file itself is not accessed.
Definition at line 376 of file FileManager.cpp.
References clang::cast(), clang::DirectoryEntryRef::getDirEntry(), and clang::isa().
Referenced by getSTDIN().
|
inline |
Definition at line 232 of file FileManager.h.
Referenced by clang::installapi::enumerateFiles(), clang::ento::getConfiguration(), clang::ASTUnit::LoadFromCompilerInvocationAction(), and PrintStats().
|
inline |
Definition at line 234 of file FileManager.h.
Referenced by clang::CodeGenAction::ExecuteAction(), and clang::tooling::FrontendActionFactory::runInvocation().
| bool FileManager::makeAbsolutePath | ( | SmallVectorImpl< char > & | Path, |
| bool | Canonicalize = false ) const |
Makes Path absolute taking into account FileSystemOptions and the working directory option, and canonicalizes through llvm::path::remove_dots if Canonicalize is true.
Path was changed. Definition at line 496 of file FileManager.cpp.
References FixupRelativePath().
Referenced by makeAbsoluteAndCanonicalize(), and clang::Rewriter::overwriteChangedFiles().
| void FileManager::PrintStats | ( | ) | const |
Definition at line 699 of file FileManager.cpp.
References getVirtualFileSystem().
Referenced by clang::CompilerInstance::ExecuteAction().
|
inline |
Definition at line 242 of file FileManager.h.
| void FileManager::trackVFSUsage | ( | bool | Active | ) |
Enable or disable tracking of VFS usage.
Used to not track full header search and implicit modulemap lookup.
Definition at line 369 of file FileManager.cpp.