clang
10.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. More... | |
~FileManager () | |
void | setStatCache (std::unique_ptr< FileSystemStatCache > statCache) |
Installs the provided FileSystemStatCache object within the FileManager. More... | |
void | clearStatCache () |
Removes the FileSystemStatCache object from the manager. More... | |
size_t | getNumUniqueRealFiles () const |
Returns the number of unique real file entries cached by the file manager. More... | |
llvm::Expected< DirectoryEntryRef > | getDirectoryRef (StringRef DirName, bool CacheFailure=true) |
Lookup, cache, and verify the specified directory (real or virtual). More... | |
llvm::Optional< DirectoryEntryRef > | getOptionalDirectoryRef (StringRef DirName, bool CacheFailure=true) |
Get a DirectoryEntryRef if it exists, without doing anything on error. More... | |
llvm::ErrorOr< const DirectoryEntry * > | getDirectory (StringRef DirName, bool CacheFailure=true) |
Lookup, cache, and verify the specified directory (real or virtual). More... | |
llvm::ErrorOr< const FileEntry * > | getFile (StringRef Filename, bool OpenFile=false, bool CacheFailure=true) |
Lookup, cache, and verify the specified file (real or virtual). More... | |
llvm::Expected< FileEntryRef > | getFileRef (StringRef Filename, bool OpenFile=false, bool CacheFailure=true) |
Lookup, cache, and verify the specified file (real or virtual). More... | |
llvm::Optional< FileEntryRef > | getOptionalFileRef (StringRef Filename, bool OpenFile=false, bool CacheFailure=true) |
Get a FileEntryRef if it exists, without doing anything on error. More... | |
FileSystemOptions & | getFileSystemOpts () |
Returns the current file system options. More... | |
const FileSystemOptions & | getFileSystemOpts () const |
llvm::vfs::FileSystem & | getVirtualFileSystem () const |
void | setVirtualFileSystem (IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS) |
const FileEntry * | getVirtualFile (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. More... | |
llvm::Optional< FileEntryRef > | getBypassFile (FileEntryRef VFE) |
Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual file entry, to access the real file. More... | |
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > | getBufferForFile (const FileEntry *Entry, bool isVolatile=false) |
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null. More... | |
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > | getBufferForFile (StringRef Filename, bool isVolatile=false) |
std::error_code | getNoncachedStatValue (StringRef Path, llvm::vfs::Status &Result) |
Get the 'stat' information for the given Path . More... | |
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. More... | |
bool | makeAbsolutePath (SmallVectorImpl< char > &Path) const |
Makes Path absolute taking into account FileSystemOptions and the working directory option. More... | |
void | GetUniqueIDMapping (SmallVectorImpl< const FileEntry *> &UIDToFiles) const |
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntry pointer. More... | |
StringRef | getCanonicalName (const DirectoryEntry *Dir) |
Retrieve the canonical name for a given directory. More... | |
StringRef | getCanonicalName (const FileEntry *File) |
Retrieve the canonical name for a given file. More... | |
void | PrintStats () const |
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 171 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 51 of file FileManager.cpp.
|
default |
void FileManager::clearStatCache | ( | ) |
Removes the FileSystemStatCache object from the manager.
Definition at line 68 of file FileManager.cpp.
Referenced by clang::tooling::FrontendActionFactory::runInvocation().
bool FileManager::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.
path
changed. Definition at line 425 of file FileManager.cpp.
References clang::FileSystemOptions::WorkingDir.
Referenced by getBufferForFile(), hasSuperInitCall(), and makeAbsolutePath().
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > FileManager::getBufferForFile | ( | const FileEntry * | Entry, |
bool | isVolatile = false |
||
) |
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
Definition at line 461 of file FileManager.cpp.
References clang::FileEntry::closeFile(), Filename, FixupRelativePath(), clang::FileEntry::getName(), clang::FileEntry::getSize(), clang::Result, and clang::FileSystemOptions::WorkingDir.
Referenced by clang::HeaderMap::Create(), clang::CodeGenAction::CreateASTConsumer(), clang::DumpModuleInfoAction::ExecuteAction(), clang::PrintPreambleAction::ExecuteAction(), clang::SrcMgr::ContentCache::getBuffer(), clang::ASTReader::getOriginalSourceFile(), clang::CompilerInstance::InitializeSourceManager(), clang::ASTReader::readASTFileControlBlock(), and clang::serialized_diags::SerializedDiagnosticReader::readDiagnostics().
|
inline |
Definition at line 383 of file FileManager.h.
llvm::Optional< FileEntryRef > 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 406 of file FileManager.cpp.
Referenced by clang::SourceManager::bypassFileContentsOverride().
StringRef FileManager::getCanonicalName | ( | const DirectoryEntry * | 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 550 of file FileManager.cpp.
References clang::DirectoryEntry::getName().
Referenced by clang::HeaderSearch::getCachedModuleFileName(), getTopFrameworkDir(), clang::ModuleMap::inferFrameworkModule(), clang::ModuleMap::isBuiltinHeader(), and clang::TextDiagnostic::printDiagnosticMessage().
StringRef FileManager::getCanonicalName | ( | const FileEntry * | 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 566 of file FileManager.cpp.
References clang::FileEntry::getName().
llvm::ErrorOr< const DirectoryEntry * > FileManager::getDirectory | ( | StringRef | DirName, |
bool | CacheFailure = true |
||
) |
Lookup, cache, and verify the specified directory (real or virtual).
This function is deprecated and will be removed at some point in the future, new clients should use getDirectoryRef
.
This returns a std::error_code
if there was an error reading the directory. If there is no error, the DirectoryEntry is guaranteed to be non-NULL.
CacheFailure | If true and the file does not exist, we'll cache the failure to find this file. |
Definition at line 187 of file FileManager.cpp.
References getDirectoryRef(), and clang::Result.
Referenced by clang::ApplyHeaderSearchOptions(), clang::FrontendAction::BeginSourceFile(), collectIncludePCH(), computeRelativePath(), clang::HeaderSearch::getCachedModuleFileName(), getDirectoryFromFile(), getTopFrameworkDir(), clang::ModuleMap::inferFrameworkModule(), clang::ModuleMap::isBuiltinHeader(), clang::Preprocessor::LookupFile(), clang::HeaderSearch::lookupModule(), and needModuleLookup().
llvm::Expected< DirectoryEntryRef > FileManager::getDirectoryRef | ( | StringRef | DirName, |
bool | CacheFailure = true |
||
) |
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 117 of file FileManager.cpp.
Referenced by getDirectory().
llvm::ErrorOr< const FileEntry * > FileManager::getFile | ( | StringRef | Filename, |
bool | OpenFile = false , |
||
bool | CacheFailure = true |
||
) |
Lookup, cache, and verify the specified file (real or virtual).
This function is deprecated and will be removed at some point in the future, new clients should use getFileRef
.
This returns a std::error_code
if there was an error loading the file. If there is no error, the FileEntry is guaranteed to be non-NULL.
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 195 of file FileManager.cpp.
References getFileRef(), and clang::Result.
Referenced by clang::tooling::Replacement::apply(), clang::tooling::applyAllReplacements(), clang::FrontendAction::BeginSourceFile(), clang::PrecompiledPreamble::Build(), EnableCodeCompletion(), clang::serialization::reader::HeaderFileInfoTrait::EqualKey(), clang::tooling::formatAndApplyAllReplacements(), getPrivateModuleMap(), getPublicModuleMap(), clang::Module::getTopHeaders(), clang::tooling::groupReplacementsByFile(), clang::ASTImporter::Import(), inferFrameworkLink(), InitializeFileRemapping(), llvm::DenseMapInfo< EditEntry >::isEqual(), clang::serialization::ModuleManager::lookupModuleFile(), prepareToBuildModule(), clang::TextDiagnostic::printDiagnosticMessage(), clang::serialization::reader::HeaderFileInfoTrait::ReadData(), clang::SourceManagerForFile::SourceManagerForFile(), and clang::RewriteIncludesAction::RewriteImportsListener::visitModuleFile().
llvm::Expected< FileEntryRef > FileManager::getFileRef | ( | StringRef | Filename, |
bool | OpenFile = false , |
||
bool | CacheFailure = true |
||
) |
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 203 of file FileManager.cpp.
References Filename, and getDirectoryFromFile().
Referenced by getFile(), clang::DirectoryLookup::getName(), and clang::CompilerInstance::InitializeSourceManager().
|
inline |
Returns the current file system options.
Definition at line 352 of file FileManager.h.
Referenced by clang::ASTUnit::LoadFromCompilerInvocation(), and clang::tooling::ToolInvocation::run().
|
inline |
Definition at line 353 of file FileManager.h.
std::error_code FileManager::getNoncachedStatValue | ( | StringRef | Path, |
llvm::vfs::Status & | Result | ||
) |
Get the 'stat' information for the given Path
.
If the path is relative, it will be resolved against the WorkingDir of the FileManager's FileSystemOptions.
std::error_code
describing an error, if there was one Definition at line 517 of file FileManager.cpp.
|
inline |
Returns the number of unique real file entries cached by the file manager.
Definition at line 271 of file FileManager.h.
|
inline |
Get a DirectoryEntryRef
if it exists, without doing anything on error.
Definition at line 288 of file FileManager.h.
References Filename.
|
inline |
Get a FileEntryRef if it exists, without doing anything on error.
Definition at line 344 of file FileManager.h.
Referenced by clang::HeaderMap::LookupFile(), clang::DirectoryLookup::LookupFile(), and needModuleLookup().
void FileManager::GetUniqueIDMapping | ( | SmallVectorImpl< const FileEntry *> & | UIDToFiles | ) | const |
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntry pointer.
Definition at line 529 of file FileManager.cpp.
Referenced by CreateSLocExpansionAbbrev().
const FileEntry * FileManager::getVirtualFile | ( | 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 336 of file FileManager.cpp.
References Filename, and getDirectoryFromFile().
Referenced by clang::serialization::ModuleManager::addInMemoryBuffer(), InitializeFileRemapping(), and clang::CompilerInstance::InitializeSourceManager().
|
inline |
Definition at line 355 of file FileManager.h.
Referenced by clang::ASTUnit::CodeComplete(), and clang::tooling::ToolInvocation::run().
bool FileManager::makeAbsolutePath | ( | SmallVectorImpl< char > & | Path | ) | const |
Makes Path
absolute taking into account FileSystemOptions and the working directory option.
Path
changed to absolute. Definition at line 438 of file FileManager.cpp.
References FixupRelativePath().
Referenced by cleanPathForOutput().
void FileManager::PrintStats | ( | ) | const |
Definition at line 582 of file FileManager.cpp.
void FileManager::setStatCache | ( | std::unique_ptr< FileSystemStatCache > | statCache | ) |
Installs the provided FileSystemStatCache object within the FileManager.
Ownership of this object is transferred to the FileManager.
statCache | the new stat cache to install. Ownership of this object is transferred to the FileManager. |
Definition at line 63 of file FileManager.cpp.
|
inline |
Definition at line 357 of file FileManager.h.