clang  8.0.0svn
Public Member Functions | Static Public Member Functions | List of all members
clang::FileManager Class Reference

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

#include "clang/Basic/FileManager.h"

Inheritance diagram for clang::FileManager:
Inheritance graph
[legend]
Collaboration diagram for clang::FileManager:
Collaboration graph
[legend]

Public Member Functions

 FileManager (const FileSystemOptions &FileSystemOpts, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
 
 ~FileManager ()
 
void addStatCache (std::unique_ptr< FileSystemStatCache > statCache, bool AtBeginning=false)
 Installs the provided FileSystemStatCache object within the FileManager. More...
 
void removeStatCache (FileSystemStatCache *statCache)
 Removes the specified FileSystemStatCache object from the manager. More...
 
void clearStatCaches ()
 Removes all FileSystemStatCache objects from the manager. More...
 
const DirectoryEntrygetDirectory (StringRef DirName, bool CacheFailure=true)
 Lookup, cache, and verify the specified directory (real or virtual). More...
 
const FileEntrygetFile (StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
 Lookup, cache, and verify the specified file (real or virtual). More...
 
FileSystemOptionsgetFileSystemOpts ()
 Returns the current file system options. More...
 
const FileSystemOptionsgetFileSystemOpts () const
 
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getVirtualFileSystem () const
 
const FileEntrygetVirtualFile (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::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. More...
 
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile (StringRef Filename, bool isVolatile=false)
 
bool getNoncachedStatValue (StringRef Path, llvm::vfs::Status &Result)
 Get the 'stat' information for the given Path. More...
 
void invalidateCache (const FileEntry *Entry)
 Remove the real file Entry from the cache. 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...
 
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. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ FileManager()

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

Definition at line 51 of file FileManager.cpp.

References ~FileManager().

◆ ~FileManager()

FileManager::~FileManager ( )
default

Referenced by FileManager().

Member Function Documentation

◆ addStatCache()

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.

Parameters
statCachethe new stat cache to install. Ownership of this object is transferred to the FileManager.
AtBeginningwhether 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 66 of file FileManager.cpp.

References clang::FileSystemStatCache::getNextStatCache(), and clang::FileSystemStatCache::setNextStatCache().

◆ clearStatCaches()

void FileManager::clearStatCaches ( )

Removes all FileSystemStatCache objects from the manager.

Definition at line 101 of file FileManager.cpp.

Referenced by clang::tooling::FrontendActionFactory::runInvocation().

◆ FixupRelativePath()

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.

Returns
true if path changed.

Definition at line 410 of file FileManager.cpp.

References clang::FileSystemOptions::WorkingDir.

Referenced by getBufferForFile(), hasSuperInitCall(), and makeAbsolutePath().

◆ getBufferForFile() [1/2]

llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > FileManager::getBufferForFile ( const FileEntry Entry,
bool  isVolatile = false,
bool  ShouldCloseOpenFile = true 
)

◆ getBufferForFile() [2/2]

llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > FileManager::getBufferForFile ( StringRef  Filename,
bool  isVolatile = false 
)

◆ getCanonicalName()

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

References clang::DirectoryEntry::getName().

Referenced by clang::HeaderSearch::getCachedModuleFileName(), getTopFrameworkDir(), clang::ModuleMap::inferFrameworkModule(), clang::ModuleMap::isBuiltinHeader(), and clang::TextDiagnostic::printDiagnosticMessage().

◆ getDirectory()

const DirectoryEntry * FileManager::getDirectory ( StringRef  DirName,
bool  CacheFailure = true 
)

◆ getFile()

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.

Parameters
OpenFileif true and the file exists, it will be opened.
CacheFailureIf 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 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::tooling::applyAllReplacements(), clang::FrontendAction::BeginSourceFile(), collectModuleHeaderIncludes(), EnableCodeCompletion(), clang::serialization::reader::HeaderFileInfoTrait::EqualKey(), clang::tooling::formatAndApplyAllReplacements(), clang::DirectoryLookup::getName(), getPrivateModuleMap(), getPublicModuleMap(), clang::Module::getTopHeaders(), clang::tooling::groupReplacementsByFile(), clang::ASTImporter::Import(), inferFrameworkLink(), InitializeFileRemapping(), clang::CompilerInstance::InitializeSourceManager(), llvm::DenseMapInfo< EditEntry >::isEqual(), clang::HeaderMap::LookupFile(), clang::DirectoryLookup::LookupFile(), clang::serialization::ModuleManager::lookupModuleFile(), needModuleLookup(), prepareToBuildModule(), clang::serialization::reader::HeaderFileInfoTrait::ReadData(), clang::SourceManagerForFile::SourceManagerForFile(), and clang::RewriteIncludesAction::RewriteImportsListener::visitModuleFile().

◆ getFileSystemOpts() [1/2]

FileSystemOptions& clang::FileManager::getFileSystemOpts ( )
inline

Returns the current file system options.

Definition at line 231 of file FileManager.h.

Referenced by clang::ASTUnit::LoadFromCompilerInvocation(), and clang::tooling::ToolInvocation::run().

◆ getFileSystemOpts() [2/2]

const FileSystemOptions& clang::FileManager::getFileSystemOpts ( ) const
inline

Definition at line 232 of file FileManager.h.

◆ getNoncachedStatValue()

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

Returns
false on success, true on error.

Definition at line 508 of file FileManager.cpp.

◆ GetUniqueIDMapping()

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

References NON_EXISTENT_FILE.

Referenced by CreateSLocExpansionAbbrev().

◆ getVirtualFile()

const FileEntry * FileManager::getVirtualFile ( StringRef  Filename,
off_t  Size,
time_t  ModificationTime 
)

◆ getVirtualFileSystem()

IntrusiveRefCntPtr<llvm::vfs::FileSystem> clang::FileManager::getVirtualFileSystem ( ) const
inline

◆ invalidateCache()

void FileManager::invalidateCache ( const FileEntry Entry)

Remove the real file Entry from the cache.

Definition at line 520 of file FileManager.cpp.

References clang::FileEntry::getName(), and clang::FileEntry::getUniqueID().

Referenced by clang::serialization::ModuleManager::removeModules().

◆ makeAbsolutePath()

bool FileManager::makeAbsolutePath ( SmallVectorImpl< char > &  Path) const

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

Returns
true if Path changed to absolute.

Definition at line 423 of file FileManager.cpp.

References FixupRelativePath().

Referenced by cleanPathForOutput().

◆ modifyFileEntry()

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

◆ PrintStats()

void FileManager::PrintStats ( ) const

Definition at line 572 of file FileManager.cpp.

◆ removeStatCache()

void FileManager::removeStatCache ( FileSystemStatCache statCache)

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