clang: clang::FileManager Class Reference (original) (raw)

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

#include "[clang/Basic/FileManager.h](FileManager%5F8h%5Fsource.html)"

Public Member Functions
FileManager (const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
Construct a file manager, optionally with a custom VFS.
~FileManager ()
void setStatCache (std::unique_ptr< FileSystemStatCache > statCache)
Installs the provided FileSystemStatCache object within the FileManager.
void clearStatCache ()
Removes the FileSystemStatCache object from the manager.
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_DEPRECATED("Functions returning DirectoryEntry are deprecated.", "getOptionalDirectoryRef()") llvm LLVM_DEPRECATED("Functions returning FileEntry are deprecated.", "getOptionalFileRef()") llvm llvm::Expected< FileEntryRef > getFileRef (StringRef Filename, bool OpenFile=false, bool CacheFailure=true, bool IsText=true)
Lookup, cache, and verify the specified directory (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)
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.
LLVM_DEPRECATED ("Functions returning FileEntry are deprecated.", "getVirtualFileRef()") const FileEntry *getVirtualFile(StringRef Filename
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
std::error_code getNoncachedStatValue (StringRef Path, llvm::vfs::Status &Result)
Get the 'stat' information for the given Path.
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) const
Makes Path absolute taking into account FileSystemOptions and the working directory option.
void GetUniqueIDMapping (SmallVectorImpl< OptionalFileEntryRef > &UIDToFiles) const
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntryRef.
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.

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 53 of file FileManager.h.

Construct a file manager, optionally with a custom VFS.

Parameters

FS if non-null, the VFS to use. Otherwise uses llvm::vfs::getRealFileSystem().

Definition at line 46 of file FileManager.cpp.

~FileManager()

FileManager::~FileManager ( ) default

AddStats()

void FileManager::AddStats ( const FileManager & Other )

clearStatCache()

void FileManager::clearStatCache ( )

FixupRelativePath()

getBufferForFile() [1/2]

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 534 of file FileManager.cpp.

References clang::FileEntry::closeFile(), Filename, clang::FileEntryRef::getFileEntry(), clang::FileEntryRef::getName(), clang::FileEntry::getSize(), clang::FileEntry::isNamedPipe(), and clang::Result.

Referenced by clang::serialization::ModuleManager::addModule(), clang::extractapi::APIIgnoresList::create(), clang::HeaderMap::Create(), clang::DumpModuleInfoAction::ExecuteAction(), clang::PrintPreambleAction::ExecuteAction(), clang::SrcMgr::ContentCache::getBufferOrNone(), clang::ASTReader::getOriginalSourceFile(), and clang::ASTReader::readASTFileControlBlock().

getBufferForFile() [2/2]

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

getBypassFile()

getCanonicalName() [1/2]

getCanonicalName() [2/2]

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 638 of file FileManager.cpp.

References clang::File, and getCanonicalName().

getDirectoryRef()

getFileRef()

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.

Parameters

CacheFailure If true and the file does not exist, we'll cache the failure to find this file. 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.

Parameters

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. 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](classclang%5F1%5F1FileEntryRef.html "A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...") otherwise.

Parameters

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 215 of file FileManager.cpp.

References Filename, getDirectoryFromFile(), and clang::DirectoryEntryRef::getDirEntry().

Referenced by clang::tooling::formatAndApplyAllReplacements(), getOptionalFileRef(), clang::CompilerInstance::InitializeSourceManager(), and clang::Preprocessor::LookupEmbedFile().

getFileSystemOpts() [1/2]

getFileSystemOpts() [2/2]

getNoncachedStatValue()

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

getNumUniqueRealFiles()

size_t clang::FileManager::getNumUniqueRealFiles ( ) const inline

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

Definition at line 159 of file FileManager.h.

getOptionalDirectoryRef()

Get a [DirectoryEntryRef](classclang%5F1%5F1DirectoryEntryRef.html "A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...") if it exists, without doing anything on error.

Definition at line 175 of file FileManager.h.

References getDirectoryRef().

Referenced by clang::ApplyHeaderSearchOptions(), clang::FrontendAction::BeginSourceFile(), clang::HeaderSearch::collectAllModules(), collectIncludePCH(), computeRelativePath(), clang::api_notes::APINotesManager::findAPINotes(), clang::api_notes::APINotesManager::getCurrentModuleAPINotes(), getTopFrameworkDir(), clang::HeaderSearch::hasModuleMap(), clang::ModuleMap::isHeaderUnavailableInModule(), clang::HeaderSearch::loadModuleMapFile(), loadModuleMapForModuleBuild(), clang::Preprocessor::LookupFile(), and clang::HeaderSearch::LookupSubframeworkHeader().

getOptionalFileRef()

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

Definition at line 245 of file FileManager.h.

References Filename, and getFileRef().

Referenced by clang::installapi::InstallAPIContext::addKnownHeader(), clang::tooling::applyAllReplacements(), clang::FrontendAction::BeginSourceFile(), clang::PrecompiledPreamble::Build(), collectModuleHeaderIncludes(), EnableCodeCompletion(), clang::api_notes::APINotesManager::findAPINotes(), clang::installapi::findLibrary(), clang::BackendConsumer::getBestLocationFromDebugLoc(), getPrivateModuleMap(), getPublicModuleMap(), clang::Module::getTopHeaders(), clang::tooling::groupReplacementsByFile(), clang::ASTImporter::Import(), InitializeFileRemapping(), clang::serialization::ModuleManager::lookupBuffer(), clang::serialization::ModuleManager::lookupByFileName(), clang::DirectoryLookup::LookupFile(), clang::serialization::ModuleManager::lookupModuleFile(), clang::HeaderSearch::lookupModuleMapFile(), clang::HeaderSearch::LookupSubframeworkHeader(), prepareToBuildModule(), clang::RewriteIncludesAction::RewriteImportsListener::visitModuleFile(), and clang::GlobalModuleIndex::writeIndex().

getSTDIN()

GetUniqueIDMapping()

getVirtualFileRef()

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

getVirtualFileSystem()

llvm::vfs::FileSystem & clang::FileManager::getVirtualFileSystem ( ) const inline

Definition at line 256 of file FileManager.h.

Referenced by clang::FrontendAction::BeginSourceFile(), clang::ASTUnit::CodeComplete(), clang::SemaCodeCompletion::CodeCompleteIncludedFile(), clang::HeaderSearch::collectAllModules(), collectIncludePCH(), collectModuleHeaderIncludes(), clang::HeaderSearch::collectVFSUsageAndClear(), clang::installapi::enumerateFiles(), forEachDriverJob(), clang::Sema::getDarwinSDKInfoForAvailabilityChecking(), clang::CompilerInstance::getVirtualFileSystem(), clang::ASTUnit::LoadFromCompilerInvocationAction(), PrintStats(), clang::PCHValidator::ReadDiagnosticOptions(), clang::PCHValidator::ReadHeaderSearchOptions(), clang::tooling::ToolInvocation::run(), and clang::tooling::FrontendActionFactory::runInvocation().

getVirtualFileSystemPtr()

LLVM_DEPRECATED()

clang::FileManager::LLVM_DEPRECATED ( "Functions returning FileEntry are deprecated." ,
"getVirtualFileRef()"
) const

makeAbsolutePath()

PrintStats()

void FileManager::PrintStats ( ) const

setStatCache()

setVirtualFileSystem()

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

trackVFSUsage()

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 380 of file FileManager.cpp.

ModificationTime

off_t time_t clang::FileManager::ModificationTime

Size

off_t clang::FileManager::Size


The documentation for this class was generated from the following files: