clang API Documentation
Implements support for file system lookup, file system caching, and directory search management. More...
#include <FileManager.h>
Public Member Functions | |
FileManager (const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< vfs::FileSystem > FS=nullptr) | |
~FileManager () | |
void | addStatCache (std::unique_ptr< FileSystemStatCache > statCache, bool AtBeginning=false) |
Installs the provided FileSystemStatCache object within the FileManager. | |
void | removeStatCache (FileSystemStatCache *statCache) |
Removes the specified FileSystemStatCache object from the manager. | |
void | clearStatCaches () |
Removes all FileSystemStatCache objects from the manager. | |
const DirectoryEntry * | getDirectory (StringRef DirName, bool CacheFailure=true) |
Lookup, cache, and verify the specified directory (real or virtual). | |
const FileEntry * | getFile (StringRef Filename, bool OpenFile=false, bool CacheFailure=true) |
Lookup, cache, and verify the specified file (real or virtual). | |
const FileSystemOptions & | getFileSystemOptions () |
Returns the current file system options. | |
IntrusiveRefCntPtr < vfs::FileSystem > | getVirtualFileSystem () const |
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. | |
llvm::ErrorOr< std::unique_ptr < llvm::MemoryBuffer > > | getBufferForFile (const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=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 | getNoncachedStatValue (StringRef Path, vfs::Status &Result) |
Get the 'stat' information for the given Path . | |
void | invalidateCache (const FileEntry *Entry) |
Remove the real file Entry from the cache. | |
void | 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. | |
void | GetUniqueIDMapping (SmallVectorImpl< const FileEntry * > &UIDToFiles) const |
Produce an array mapping from the unique IDs assigned to each file to the corresponding FileEntry pointer. | |
StringRef | getCanonicalName (const DirectoryEntry *Dir) |
Retrieve the canonical name for a given directory. | |
void | PrintStats () const |
Static Public Member Functions | |
static void | modifyFileEntry (FileEntry *File, off_t Size, time_t ModificationTime) |
Modifies the size and modification time of a previously created FileEntry. Use with caution. |
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 123 of file FileManager.h.
FileManager::FileManager | ( | const FileSystemOptions & | FileSystemOpts, |
IntrusiveRefCntPtr< vfs::FileSystem > | FS = nullptr |
||
) |
Definition at line 47 of file FileManager.cpp.
References clang::vfs::getRealFileSystem().
Definition at line 60 of file FileManager.cpp.
void FileManager::addStatCache | ( | std::unique_ptr< FileSystemStatCache > | statCache, |
bool | AtBeginning = false |
||
) |
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. |
AtBeginning | whether this new stat cache must be installed at the beginning of the chain of stat caches. Otherwise, it will be added to the end of the chain. |
Definition at line 67 of file FileManager.cpp.
References clang::FileSystemStatCache::getNextStatCache(), and clang::FileSystemStatCache::setNextStatCache().
Referenced by clang::CacheTokens(), and clang::Preprocessor::setPTHManager().
void FileManager::clearStatCaches | ( | ) |
Removes all FileSystemStatCache objects from the manager.
Definition at line 102 of file FileManager.cpp.
Referenced by clang::tooling::FrontendActionFactory::runInvocation().
void 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.
Definition at line 390 of file FileManager.cpp.
References clang::FileSystemOptions::WorkingDir.
Referenced by getBufferForFile(), and getNoncachedStatValue().
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > FileManager::getBufferForFile | ( | const FileEntry * | Entry, |
bool | isVolatile = false , |
||
bool | ShouldCloseOpenFile = true |
||
) |
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
Definition at line 403 of file FileManager.cpp.
References FixupRelativePath(), clang::FileEntry::getName(), clang::FileEntry::getSize(), and clang::FileSystemOptions::WorkingDir.
Referenced by clang::serialization::ModuleManager::addModule(), clang::HeaderMap::Create(), clang::CodeGenAction::CreateASTConsumer(), clang::PrintPreambleAction::ExecuteAction(), clang::SrcMgr::ContentCache::getBuffer(), clang::ASTReader::getOriginalSourceFile(), clang::CompilerInstance::InitializeSourceManager(), clang::ASTReader::readASTFileControlBlock(), and clang::serialized_diags::SerializedDiagnosticReader::readDiagnostics().
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > FileManager::getBufferForFile | ( | StringRef | Filename | ) |
Definition at line 437 of file FileManager.cpp.
References FixupRelativePath(), and clang::FileSystemOptions::WorkingDir.
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 515 of file FileManager.cpp.
References clang::DirectoryEntry::getName().
Referenced by getTopFrameworkDir(), and clang::ModuleMap::inferFrameworkModule().
const DirectoryEntry * FileManager::getDirectory | ( | StringRef | DirName, |
bool | CacheFailure = true |
||
) |
Lookup, cache, and verify the specified directory (real or virtual).
This returns NULL if the directory doesn't exist.
CacheFailure | If true and the file does not exist, we'll cache the failure to find this file. |
Definition at line 152 of file FileManager.cpp.
References clang::DirectoryEntry::getName(), NON_EXISTENT_DIR, and clang::FileData::UniqueID.
Referenced by clang::ApplyHeaderSearchOptions(), clang::FrontendAction::BeginSourceFile(), clang::HeaderSearch::collectAllModules(), computeRelativePath(), getDirectoryFromFile(), getTopFrameworkDir(), clang::HeaderSearch::hasModuleMap(), clang::ModuleMap::inferFrameworkModule(), clang::ModuleMap::isHeaderUnavailableInModule(), clang::Preprocessor::LookupFile(), clang::HeaderSearch::lookupModule(), clang::HeaderSearch::LookupSubframeworkHeader(), and clang::ModuleMap::parseModuleMapFile().
const FileEntry * FileManager::getFile | ( | StringRef | Filename, |
bool | OpenFile = false , |
||
bool | CacheFailure = true |
||
) |
Lookup, cache, and verify the specified file (real or virtual).
This returns NULL if the file doesn't exist.
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 216 of file FileManager.cpp.
References getDirectoryFromFile(), clang::FileData::InPCH, clang::FileData::IsNamedPipe, clang::FileEntry::isValid(), clang::FileData::IsVFSMapped, clang::FileData::ModTime, clang::FileData::Name, NON_EXISTENT_FILE, clang::FileData::Size, and clang::FileData::UniqueID.
Referenced by clang::tooling::Replacement::apply(), clang::GenerateModuleAction::BeginSourceFileAction(), collectModuleHeaderIncludes(), clang::BackendConsumer::EmitOptimizationMessage(), EnableCodeCompletion(), clang::serialization::reader::HeaderFileInfoTrait::EqualKey(), getFileAndSuggestModule(), getPrivateModuleMap(), clang::Module::getTopHeaders(), clang::Preprocessor::HandleEndOfFile(), clang::ASTImporter::Import(), inferFrameworkLink(), clang::ModuleMap::inferFrameworkModule(), InitializeFileRemapping(), clang::CompilerInstance::InitializeSourceManager(), clang::serialization::ModuleManager::lookup(), clang::serialization::ModuleManager::lookupBuffer(), clang::HeaderMap::LookupFile(), clang::DirectoryLookup::LookupFile(), clang::HeaderSearch::LookupFile(), clang::serialization::ModuleManager::lookupModuleFile(), clang::HeaderSearch::lookupModuleMapFile(), clang::HeaderSearch::LookupSubframeworkHeader(), clang::serialization::reader::HeaderFileInfoTrait::ReadData(), and clang::GlobalModuleIndex::writeIndex().
const FileSystemOptions& clang::FileManager::getFileSystemOptions | ( | ) | [inline] |
Returns the current file system options.
Definition at line 229 of file FileManager.h.
bool FileManager::getNoncachedStatValue | ( | StringRef | Path, |
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.
Definition at line 465 of file FileManager.cpp.
References FixupRelativePath(), and S.
Referenced by clang::serialization::ModuleManager::addModule().
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 489 of file FileManager.cpp.
References NON_EXISTENT_FILE.
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 322 of file FileManager.cpp.
References getDirectoryFromFile(), clang::FileData::InPCH, clang::FileData::IsNamedPipe, clang::FileEntry::isValid(), clang::FileData::ModTime, NON_EXISTENT_FILE, clang::FileData::Size, and clang::FileData::UniqueID.
Referenced by clang::serialization::ModuleManager::addInMemoryBuffer(), clang::tooling::applyAllReplacements(), clang::index::SimpleFormatContext::createInMemoryFile(), InitializeFileRemapping(), clang::CompilerInstance::InitializeSourceManager(), and clang::format::reformat().
IntrusiveRefCntPtr<vfs::FileSystem> clang::FileManager::getVirtualFileSystem | ( | ) | const [inline] |
Definition at line 231 of file FileManager.h.
Referenced by clang::Preprocessor::HandleEndOfFile(), and clang::CompilerInstance::setFileManager().
void FileManager::invalidateCache | ( | const FileEntry * | Entry | ) |
Remove the real file Entry
from the cache.
Definition at line 477 of file FileManager.cpp.
References clang::FileEntry::getName(), and clang::FileEntry::getUniqueID().
Referenced by clang::serialization::ModuleManager::removeModules().
void FileManager::modifyFileEntry | ( | FileEntry * | File, |
off_t | Size, | ||
time_t | ModificationTime | ||
) | [static] |
Modifies the size and modification time of a previously created FileEntry. Use with caution.
Definition at line 509 of file FileManager.cpp.
void FileManager::PrintStats | ( | ) | const |
Definition at line 539 of file FileManager.cpp.
Referenced by clang::CompilerInstance::ExecuteAction().
void FileManager::removeStatCache | ( | FileSystemStatCache * | statCache | ) |
Removes the specified FileSystemStatCache object from the manager.
Definition at line 83 of file FileManager.cpp.
References clang::FileSystemStatCache::getNextStatCache(), clang::FileSystemStatCache::setNextStatCache(), and clang::FileSystemStatCache::takeNextStatCache().
Referenced by clang::CacheTokens().