clang  8.0.0svn
Public Member Functions | List of all members
clang::vfs::InMemoryFileSystem Class Reference

An in-memory file system. More...

#include "clang/Basic/VirtualFileSystem.h"

Inheritance diagram for clang::vfs::InMemoryFileSystem:
Inheritance graph
[legend]
Collaboration diagram for clang::vfs::InMemoryFileSystem:
Collaboration graph
[legend]

Public Member Functions

 InMemoryFileSystem (bool UseNormalizedPaths=true)
 
 ~InMemoryFileSystem () override
 
bool addFile (const Twine &Path, time_t ModificationTime, std::unique_ptr< llvm::MemoryBuffer > Buffer, Optional< uint32_t > User=None, Optional< uint32_t > Group=None, Optional< llvm::sys::fs::file_type > Type=None, Optional< llvm::sys::fs::perms > Perms=None)
 Add a file containing a buffer or a directory to the VFS with a path. More...
 
bool addHardLink (const Twine &From, const Twine &To)
 Add a hard link to a file. More...
 
bool addFileNoOwn (const Twine &Path, time_t ModificationTime, llvm::MemoryBuffer *Buffer, Optional< uint32_t > User=None, Optional< uint32_t > Group=None, Optional< llvm::sys::fs::file_type > Type=None, Optional< llvm::sys::fs::perms > Perms=None)
 Add a buffer to the VFS with a path. More...
 
std::string toString () const
 
bool useNormalizedPaths () const
 Return true if this file system normalizes . and .. in paths. More...
 
llvm::ErrorOr< Statusstatus (const Twine &Path) override
 Get the status of the entry at Path, if one exists. More...
 
llvm::ErrorOr< std::unique_ptr< File > > openFileForRead (const Twine &Path) override
 Get a File object for the file at Path, if one exists. More...
 
directory_iterator dir_begin (const Twine &Dir, std::error_code &EC) override
 Get a directory_iterator for Dir. More...
 
llvm::ErrorOr< std::string > getCurrentWorkingDirectory () const override
 Get the working directory of this file system. More...
 
std::error_code getRealPath (const Twine &Path, SmallVectorImpl< char > &Output) const override
 Canonicalizes Path by combining with the current working directory and normalizing the path (e.g. More...
 
std::error_code setCurrentWorkingDirectory (const Twine &Path) override
 Set the working directory. More...
 
- Public Member Functions inherited from clang::vfs::FileSystem
virtual ~FileSystem ()
 
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile (const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
 This is a convenience method that opens a file, gets its content and then closes the file. More...
 
bool exists (const Twine &Path)
 Check whether a file exists. Provided for convenience. More...
 
std::error_code makeAbsolute (SmallVectorImpl< char > &Path) const
 Make Path an absolute path. More...
 

Detailed Description

An in-memory file system.

Definition at line 346 of file VirtualFileSystem.h.

Constructor & Destructor Documentation

◆ InMemoryFileSystem()

clang::vfs::InMemoryFileSystem::InMemoryFileSystem ( bool  UseNormalizedPaths = true)
explicit

Definition at line 624 of file VirtualFileSystem.cpp.

References ~InMemoryFileSystem().

◆ ~InMemoryFileSystem()

clang::vfs::InMemoryFileSystem::~InMemoryFileSystem ( )
overridedefault

Referenced by InMemoryFileSystem().

Member Function Documentation

◆ addFile()

bool clang::vfs::InMemoryFileSystem::addFile ( const Twine &  Path,
time_t  ModificationTime,
std::unique_ptr< llvm::MemoryBuffer >  Buffer,
Optional< uint32_t >  User = None,
Optional< uint32_t >  Group = None,
Optional< llvm::sys::fs::file_type >  Type = None,
Optional< llvm::sys::fs::perms >  Perms = None 
)

Add a file containing a buffer or a directory to the VFS with a path.

The VFS owns the buffer. If present, User, Group, Type and Perms apply to the newly-created file or directory.

Returns
true if the file or directory was successfully added, false if the file or directory already exists in the file system with different contents.

Definition at line 728 of file VirtualFileSystem.cpp.

◆ addFileNoOwn()

bool clang::vfs::InMemoryFileSystem::addFileNoOwn ( const Twine &  Path,
time_t  ModificationTime,
llvm::MemoryBuffer *  Buffer,
Optional< uint32_t >  User = None,
Optional< uint32_t >  Group = None,
Optional< llvm::sys::fs::file_type >  Type = None,
Optional< llvm::sys::fs::perms >  Perms = None 
)

Add a buffer to the VFS with a path.

The VFS does not own the buffer. If present, User, Group, Type and Perms apply to the newly-created file or directory.

Returns
true if the file or directory was successfully added, false if the file or directory already exists in the file system with different contents.

Definition at line 738 of file VirtualFileSystem.cpp.

◆ addHardLink()

bool clang::vfs::InMemoryFileSystem::addHardLink ( const Twine &  From,
const Twine &  To 
)

Add a hard link to a file.

Here hard links are not intended to be fully equivalent to the classical filesystem. Both the hard link and the file share the same buffer and status (and thus have the same UniqueID). Because of this there is no way to distinguish between the link and the file after the link has been added.

The To path must be an existing file or a hardlink. The From file must not have been added before. The To Path must not be a directory. The From Node is added as a hard link which points to the resolved file of To Node.

Returns
true if the above condition is satisfied and hardlink was successfully created, false otherwise.

Definition at line 795 of file VirtualFileSystem.cpp.

References clang::vfs::lookupInMemoryNode().

◆ dir_begin()

directory_iterator clang::vfs::InMemoryFileSystem::dir_begin ( const Twine &  Dir,
std::error_code &  EC 
)
overridevirtual

Get a directory_iterator for Dir.

Note
The 'end' iterator is directory_iterator().

Implements clang::vfs::FileSystem.

Definition at line 879 of file VirtualFileSystem.cpp.

References clang::vfs::lookupInMemoryNode(), clang::make_error_code(), and Node.

◆ getCurrentWorkingDirectory()

llvm::ErrorOr<std::string> clang::vfs::InMemoryFileSystem::getCurrentWorkingDirectory ( ) const
inlineoverridevirtual

Get the working directory of this file system.

Implements clang::vfs::FileSystem.

Definition at line 413 of file VirtualFileSystem.h.

References clang::vfs::getNextVirtualUniqueID(), clang::vfs::getRealFileSystem(), and clang::vfs::getVFSFromYAML().

Referenced by getRealPath().

◆ getRealPath()

std::error_code clang::vfs::InMemoryFileSystem::getRealPath ( const Twine &  Path,
SmallVectorImpl< char > &  Output 
) const
overridevirtual

Canonicalizes Path by combining with the current working directory and normalizing the path (e.g.

remove dots). If the current working directory is not set, this returns errc::operation_not_permitted.

This doesn't resolve symlinks as they are not supported in in-memory file system.

Reimplemented from clang::vfs::FileSystem.

Definition at line 913 of file VirtualFileSystem.cpp.

References getCurrentWorkingDirectory(), and clang::vfs::FileSystem::makeAbsolute().

◆ openFileForRead()

llvm::ErrorOr< std::unique_ptr< File > > clang::vfs::InMemoryFileSystem::openFileForRead ( const Twine &  Path)
overridevirtual

Get a File object for the file at Path, if one exists.

Implements clang::vfs::FileSystem.

Definition at line 815 of file VirtualFileSystem.cpp.

References clang::vfs::lookupInMemoryNode(), clang::make_error_code(), and Node.

◆ setCurrentWorkingDirectory()

std::error_code clang::vfs::InMemoryFileSystem::setCurrentWorkingDirectory ( const Twine &  Path)
overridevirtual

Set the working directory.

This will affect all following operations on this file system and may propagate down for nested file systems.

Implements clang::vfs::FileSystem.

Definition at line 895 of file VirtualFileSystem.cpp.

References clang::vfs::FileSystem::makeAbsolute(), and useNormalizedPaths().

◆ status()

llvm::ErrorOr< Status > clang::vfs::InMemoryFileSystem::status ( const Twine &  Path)
overridevirtual

Get the status of the entry at Path, if one exists.

Implements clang::vfs::FileSystem.

Definition at line 807 of file VirtualFileSystem.cpp.

References clang::vfs::lookupInMemoryNode(), and Node.

◆ toString()

std::string clang::vfs::InMemoryFileSystem::toString ( ) const

◆ useNormalizedPaths()

bool clang::vfs::InMemoryFileSystem::useNormalizedPaths ( ) const
inline

Return true if this file system normalizes . and .. in paths.

Definition at line 406 of file VirtualFileSystem.h.

Referenced by clang::vfs::lookupInMemoryNode(), setCurrentWorkingDirectory(), and toString().


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