LLVM API Documentation
#include <Path.h>
Collaboration diagram for llvm::sys::Path:
Constructors | |
Path () | |
Construct an empty (and invalid) path. | |
Path (const std::string &unverified_path) | |
Construct a Path from a string. | |
static Path | GetRootDirectory () |
static Path | GetTemporaryDirectory () |
Constrct a path to an new, unique, existing temporary directory. | |
static void | GetSystemLibraryPaths (std::vector< sys::Path > &Paths) |
Construct a path to the system library directory. | |
static void | GetBytecodeLibraryPaths (std::vector< sys::Path > &Paths) |
Construct a list of directories in which bytecode could be found. | |
static Path | FindLibrary (std::string &short_name) |
Find a library. | |
static Path | GetLLVMDefaultConfigDir () |
Construct a path to the default LLVM configuration directory. | |
static Path | GetLLVMConfigDir () |
Construct a path to the LLVM installed configuration directory. | |
static Path | GetUserHomeDirectory () |
Construct a path to the current user's "home" directory. | |
static std::string | GetDLLSuffix () |
Return the dynamic link library suffix. | |
Public Member Functions | |
Operators | |
Path & | operator= (const Path &that) |
Assignment Operator. | |
bool | operator== (const Path &that) const |
Equality Operator. | |
bool | operator!= (const Path &that) const |
Inequality Operator. | |
bool | operator< (const Path &that) const |
Less Than Operator. | |
Path Accessors | |
bool | isValid () const |
Determine if a path is syntactically valid or not. | |
bool | isEmpty () const |
Determines if the path name is empty (invalid). | |
const std::string & | toString () const |
Returns the path as a std::string. | |
std::string | getLast () const |
Returns the last component of the path name. | |
std::string | getBasename () const |
Get the base name of the path. | |
const char *const | c_str () const |
Returns the path as a C string. | |
Disk Accessors | |
bool | isFile () const |
Determines if the path name references a file. | |
bool | isDirectory () const |
Determines if the path name references a directory. | |
bool | isHidden () const |
Determines if the path name references a hidden file. | |
bool | isRootDirectory () const |
Determines if the path references the root directory. | |
bool | hasMagicNumber (const std::string &magic) const |
Determine if file has a specific magic number. | |
bool | getMagicNumber (std::string &Magic, unsigned len) const |
Get the file's magic number. | |
bool | isArchive () const |
Determine if the path references an archive file. | |
bool | isBytecodeFile () const |
Determine if the path references a bytecode file. | |
bool | isDynamicLibrary () const |
Determine if the path reference a dynamic library. | |
bool | exists () const |
Determines if the path is a file or directory in the file system. | |
bool | canRead () const |
Determines if the path is a readable file or directory in the file system. | |
bool | canWrite () const |
Determines if the path is a writable file or directory in the file system. | |
bool | canExecute () const |
Determines if the path is an executable file in the file system. | |
bool | getDirectoryContents (std::set< Path > &paths) const |
Build a list of directory's contents. | |
void | getStatusInfo (StatusInfo &info) const |
Get file status. | |
TimeValue | getTimestamp () const |
Get file timestamp. | |
size_t | getSize () const |
Get file size. | |
Path Mutators | |
void | clear () |
Make the path empty. | |
bool | set (const std::string &unverified_path) |
Set a full path from a std::string. | |
bool | eraseComponent () |
Removes the last directory component of the Path. | |
bool | appendComponent (const std::string &component) |
Appends one path component to the Path. | |
bool | appendSuffix (const std::string &suffix) |
Adds a period and the suffix to the end of the pathname. | |
bool | eraseSuffix () |
Remove the suffix from a path name. | |
void | makeUnique (bool reuse_current=true) |
Make the current path name unique in the file system. | |
Disk Mutators | |
void | makeReadableOnDisk () |
Make the file readable;. | |
void | makeWriteableOnDisk () |
Make the file writable;. | |
void | makeExecutableOnDisk () |
Make the file readable;. | |
bool | setStatusInfoOnDisk (const StatusInfo &si) const |
Set the status information. | |
bool | createDirectoryOnDisk (bool create_parents=false) |
Create the directory this Path refers to. | |
bool | createFileOnDisk () |
Create the file this Path refers to. | |
bool | createTemporaryFileOnDisk (bool reuse_current=false) |
Create a unique temporary file. | |
bool | renamePathOnDisk (const Path &newName) |
Rename one file as another. | |
bool | eraseFromDisk (bool destroy_contents=false) const |
Removes the file or directory from the filesystem. | |
Classes | |
struct | StatusInfo |
File status structure. More... |
This class provides an abstraction for the path to a file or directory in the operating system's filesystem and provides various basic operations on it. Note that this class only represents the name of a path to a file or directory which may or may not be valid for a given machine's file system. The class is patterned after the java.io.File class with various extensions and several omissions (not relevant to LLVM). A Path object ensures that the path it encapsulates is syntactically valid for the operating system it is running on but does not ensure correctness for any particular file system. That is, a syntactically valid path might specify path components that do not exist in the file system and using such a Path to act on the file system could produce errors. There is one invalid Path value which is permitted: the empty path. The class should never allow a syntactically invalid non-empty path name to be assigned. Empty paths are required in order to indicate an error result in some situations. If the path is empty, the isValid operation will return false. All operations will fail if isValid is false. Operations that change the path will either return false if it would cause a syntactically invalid path name (in which case the Path object is left unchanged) or throw an std::string exception indicating the error. The methods are grouped into four basic categories: Path Accessors (provide information about the path without accessing disk), Disk Accessors (provide information about the underlying file or directory), Path Mutators (change the path information, not the disk), and Disk Mutators (change the disk file/directory referenced by the path). The Disk Mutator methods all have the word "disk" embedded in their method name to reinforce the notion that the operation modifies the file system.
Definition at line 54 of file Path.h.
llvm::sys::Path::Path | ( | ) | [inline] |
Construct an empty (and invalid) path.
This is one of the very few ways in which a path can be constructed with a syntactically invalid name. The only *legal* invalid name is an empty one. Other invalid names are not permitted. Empty paths are provided so that they can be used to indicate null or error results in other lib/System functionality.
llvm::sys::Path::Path | ( | const std::string & | unverified_path | ) | [explicit] |
Construct a Path from a string.
This constructor will accept a std::string as a path but it verifies that the path string has a legal syntax for the operating system on which it is running. This allows a path to be taken in from outside the program. However, if the path is not valid, the Path object will be set to an empty string and an exception will be thrown.
std::string | if unverified_path is not legal. |
unverified_path | The path to verify and assign. |
bool llvm::sys::Path::appendComponent | ( | const std::string & | component | ) |
Appends one path component to the Path.
The component
is added to the end of the Path if it is a legal name for the operating system. A directory separator will be added if needed.
Referenced by llvm::FindExecutable(), IsLibrary(), and llvm::SelectionDAG::viewGraph().
bool llvm::sys::Path::appendSuffix | ( | const std::string & | suffix | ) |
Adds a period and the suffix
to the end of the pathname.
A period and the suffix
are appended to the end of the pathname. The precondition for this function is that the Path reference a file name (i.e. isFile() returns true). If the Path is not a file, no action is taken and the function returns false. If the path would become invalid for the host operating system, false is returned.
Referenced by IsLibrary().
const char* const llvm::sys::Path::c_str | ( | ) | const [inline] |
Returns the path as a C string.
Obtain a 'C' string for the path name.
Definition at line 250 of file Path.h.
Referenced by llvm::GCC::ExecuteProgram(), llvm::GCC::MakeSharedObject(), llvm::LLC::OutputAsm(), llvm::CBE::OutputC(), ProcessFailure(), and llvm::Archive::writeToDisk().
bool llvm::sys::Path::canExecute | ( | ) | const |
Determines if the path is an executable file in the file system.
This function determines if the path name references an executable file in the file system. This function checks for the existence and executability (by the current program) of the file.
Referenced by llvm::FindExecutable().
bool llvm::sys::Path::canRead | ( | ) | const |
Determines if the path is a readable file or directory in the file system.
This function determines if the path name references a readable file or directory in the file system. This function checks for the existence and readability (by the current program) of the file or directory.
Referenced by llvm::Linker::FindLib(), isArchive(), isDynamicLibrary(), and llvm::Linker::LinkInFile().
bool llvm::sys::Path::canWrite | ( | ) | const |
Determines if the path is a writable file or directory in the file system.
This function determines if the path name references a writable file or directory in the file system. This function checks for the existence and writability (by the current program) of the file or directory.
void llvm::sys::Path::clear | ( | ) | [inline] |
Make the path empty.
The path name is cleared and becomes empty. This is an invalid path name but is the *only* invalid path name. This is provided so that path objects can be used to indicate the lack of a valid path being found.
Definition at line 399 of file Path.h.
Referenced by IsLibrary().
bool llvm::sys::Path::createDirectoryOnDisk | ( | bool | create_parents = false |
) |
Create the directory this Path refers to.
This method attempts to create a directory in the file system with the same name as the Path object. The create_parents
parameter controls whether intermediate directories are created or not. if create_parents
is true, then an attempt will be made to create all intermediate directories, as needed. If create_parents
is false, then only the final directory component of the Path name will be created. The created directory will have no entries.
create_parents | Determines whether non-existent directory components other than the last one (the "parents") are created or not. |
std::string | if an error occurs. |
bool llvm::sys::Path::createFileOnDisk | ( | ) |
Create the file this Path refers to.
This method attempts to create a file in the file system with the same name as the Path object. The intermediate directories must all exist at the time this method is called. Use createDirectoriesOnDisk to accomplish that. The created file will be empty upon return from this function.
std::string | if an error occurs. |
bool llvm::sys::Path::createTemporaryFileOnDisk | ( | bool | reuse_current = false |
) |
Create a unique temporary file.
This is like createFile except that it creates a temporary file. A unique temporary file name is generated based on the contents of this
before the call. The new name is assigned to this
and the file is created. Note that this will both change the Path object and* create the corresponding file. This function will ensure that the newly generated temporary file name is unique in the file system.
reuse_current | When set to true, this parameter indicates that if the current file name does not exist then it will be used without modification. |
std::string | if there is a hard error creating the temp file name. |
Referenced by llvm::Archive::writeToDisk().
bool llvm::sys::Path::eraseComponent | ( | ) |
Removes the last directory component of the Path.
One path component is removed from the Path. If only one component is present in the path, the Path object becomes empty. If the Path object is empty, no change is made.
Referenced by llvm::FindExecutable().
bool llvm::sys::Path::eraseFromDisk | ( | bool | destroy_contents = false |
) | const |
Removes the file or directory from the filesystem.
This method attempts to destroy the file or directory named by the last component of the Path. If the Path refers to a directory and the destroy_contents
is false, an attempt will be made to remove just the directory (the final Path component). If destroy_contents
is true, an attempt will be made to remove the entire contents of the directory, recursively. If the Path refers to a file, the destroy_contents
parameter is ignored.
destroy_contents | Indicates whether the contents of a destroyed directory should also be destroyed (recursively). |
std::string | if there is an error. |
Referenced by llvm::CBE::compileProgram(), llvm::LLC::compileProgram(), ProcessFailure(), llvm::SelectionDAG::viewGraph(), llvm::Archive::writeToDisk(), and llvm::FileRemover::~FileRemover().
bool llvm::sys::Path::eraseSuffix | ( | ) |
Remove the suffix from a path name.
The suffix of the filename is erased. The suffix begins with and includes the last . character in the filename after the last directory separator and extends until the end of the name. If no . character is after the last directory separator, then the file name is left unchanged (i.e. it was already without a suffix) but the function returns false.
Referenced by IsLibrary().
bool llvm::sys::Path::exists | ( | ) | const |
Determines if the path is a file or directory in the file system.
This function determines if the path name references an existing file or directory in the file system.
Referenced by llvm::Archive::addFileBefore(), llvm::ArchiveMember::replaceWith(), and llvm::Archive::writeToDisk().
Path llvm::Path::FindLibrary | ( | std::string & | short_name | ) | [static] |
Find a library.
Find the path to a library using its short name. Use the system dependent library paths to locate the library.
Definition at line 78 of file Path.cpp.
References GetSystemLibraryPaths(), and LTDL_SHLIB_EXT.
std::string llvm::sys::Path::getBasename | ( | ) | const |
Get the base name of the path.
This function strips off the path and suffix of the file or directory name and returns just the basename. For example /a/foo.bar would cause this function to return "foo".
Referenced by llvm::Linker::LinkModules().
static void llvm::sys::Path::GetBytecodeLibraryPaths | ( | std::vector< sys::Path > & | Paths | ) | [static] |
Construct a list of directories in which bytecode could be found.
Construct a vector of sys::Path that contains the "standard" bytecode library paths suitable for linking into an llvm program. This function must* return the value of LLVM_LIB_SEARCH_PATH as well as the value of LLVM_LIBDIR. It also must provide the System library paths as returned by GetSystemLibraryPaths.
Referenced by llvm::Linker::addSystemPaths().
bool llvm::sys::Path::getDirectoryContents | ( | std::set< Path > & | paths | ) | const |
Build a list of directory's contents.
This function builds a list of paths that are the names of the files and directories in a directory.
this
is not a directory, true otherwise std::string | if the directory cannot be searched |
std::string llvm::Path::GetDLLSuffix | ( | ) | [static] |
Return the dynamic link library suffix.
Return the suffix commonly used on file names that contain a shared object, shared archive, or dynamic link library. Such files are linked at runtime into a process and their code images are shared between processes.
Definition at line 95 of file Path.cpp.
References LTDL_SHLIB_EXT.
std::string llvm::sys::Path::getLast | ( | ) | const |
Returns the last component of the path name.
This function returns the last component of the path name. The last component is the file or directory name occuring after the last directory separator. If no directory separator is present, the entire path name is returned (i.e. same as toString).
Path llvm::Path::GetLLVMConfigDir | ( | ) | [static] |
Construct a path to the LLVM installed configuration directory.
Construct a path to the LLVM installed configuration directory. The implementation must ensure that this refers to the "etc" directory of the LLVM installation. This is the location where configuration files will be located for a particular installation of LLVM on a machine.
Definition at line 27 of file Path.cpp.
References GetLLVMDefaultConfigDir(), LLVM_ETCDIR, and set().
static Path llvm::sys::Path::GetLLVMDefaultConfigDir | ( | ) | [static] |
Construct a path to the default LLVM configuration directory.
Construct a path to the default LLVM configuration directory. The implementation must ensure that this is a well-known (same on many systems) directory in which llvm configuration files exist. For example, on Unix, the /etc/llvm directory has been selected.
Referenced by GetLLVMConfigDir().
bool llvm::sys::Path::getMagicNumber | ( | std::string & | Magic, | |
unsigned | len | |||
) | const |
Get the file's magic number.
This function retrieves the first len
bytes of the file associated with this
. These bytes are returned as the "magic number" in the Magic
parameter.
Referenced by llvm::Linker::LinkInLibrary(), and llvm::ArchiveMember::replaceWith().
static Path llvm::sys::Path::GetRootDirectory | ( | ) | [static] |
Construct a path to the root directory of the file system. The root directory is a top level directory above which there are no more directories. For example, on UNIX, the root directory is /. On Windows it is C:\. Other operating systems may have different notions of what the root directory is or none at all. In that case, a consistent default root directory will be used.
size_t llvm::sys::Path::getSize | ( | ) | const [inline] |
Get file size.
This function returns the size of the file referenced by this path.
Definition at line 386 of file Path.h.
References llvm::sys::Path::StatusInfo::fileSize, and getStatusInfo().
Referenced by llvm::DiffFilesWithTolerance().
void llvm::sys::Path::getStatusInfo | ( | StatusInfo & | info | ) | const |
Get file status.
This function returns status information about the file. The type of path (file or directory) is updated to reflect the actual contents of the file system. If the file does not exist, false is returned. For other (hard I/O) errors, a std::string is thrown indicating the problem.
std::string | if an error occurs. |
Referenced by getSize(), getTimestamp(), and llvm::ArchiveMember::replaceWith().
static void llvm::sys::Path::GetSystemLibraryPaths | ( | std::vector< sys::Path > & | Paths | ) | [static] |
Construct a path to the system library directory.
Construct a vector of sys::Path that contains the "standard" system library paths suitable for linking into programs. This function *must* return the value of LLVM_LIB_SEARCH_PATH as the first item in Paths
if that environment variable is set and it references a directory.
Referenced by FindLibrary().
static Path llvm::sys::Path::GetTemporaryDirectory | ( | ) | [static] |
Constrct a path to an new, unique, existing temporary directory.
Construct a path to a unique temporary directory that is created in a "standard" place for the operating system. The directory is guaranteed to be created on exit from this function. If the directory cannot be created, the function will throw an exception.
std::string | indicating why the directory could not be created. |
Referenced by llvm::SelectionDAG::viewGraph().
TimeValue llvm::sys::Path::getTimestamp | ( | ) | const [inline] |
Get file timestamp.
This function returns the last modified time stamp for the file referenced by this path. The Path may reference a file or a directory. If the file does not exist, a ZeroTime timestamp is returned.
Definition at line 380 of file Path.h.
References getStatusInfo(), and llvm::sys::Path::StatusInfo::modTime.
static Path llvm::sys::Path::GetUserHomeDirectory | ( | ) | [static] |
Construct a path to the current user's "home" directory.
Construct a path to the current user's home directory. The implementation must use an operating system specific mechanism for determining the user's home directory. For example, the environment variable "HOME" could be used on Unix. If a given operating system does not have the concept of a user's home directory, this static constructor must provide the same result as GetRootDirectory.
bool llvm::sys::Path::hasMagicNumber | ( | const std::string & | magic | ) | const |
Determine if file has a specific magic number.
This function opens the file associated with the path name provided by the Path object and reads its magic number. If the magic number at the start of the file matches magic
, true is returned. In all other cases (file not found, file not accessible, etc.) it returns false.
magic
. Referenced by isArchive(), and isDynamicLibrary().
bool llvm::Path::isArchive | ( | ) | const |
Determine if the path references an archive file.
This function determines if the path name in the object references an archive file by looking at its magic number.
Definition at line 64 of file Path.cpp.
References canRead(), and hasMagicNumber().
Referenced by llvm::Linker::FindLib(), IsLibrary(), and llvm::Linker::LinkInFile().
bool llvm::sys::Path::isBytecodeFile | ( | ) | const |
Determine if the path references a bytecode file.
This function determines if the path name in the object references an LLVM Bytecode file by looking at its magic number.
Referenced by llvm::Linker::LinkInFile().
bool llvm::sys::Path::isDirectory | ( | ) | const |
Determines if the path name references a directory.
This function determines if the object referenced by this path is a directory or not. This function accesses the underlying file system to determine the type of entity referenced by the path.
Referenced by IsLibrary().
bool llvm::Path::isDynamicLibrary | ( | ) | const |
Determine if the path reference a dynamic library.
This function determines if the path name in the object references a native Dynamic Library (shared library, shared object) by looking at the file's magic number. The Path object must reference a file, not a directory.
Definition at line 71 of file Path.cpp.
References canRead(), and hasMagicNumber().
Referenced by llvm::Linker::FindLib().
bool llvm::sys::Path::isEmpty | ( | ) | const [inline] |
Determines if the path name is empty (invalid).
This function determines if the contents of the path name are empty. That is, the path has a zero length. This does NOT determine if if the file is empty. Use the getSize method for that.
Definition at line 224 of file Path.h.
Referenced by llvm::GCC::create(), llvm::AbstractInterpreter::createCBE(), llvm::FindExecutable(), llvm::Linker::FindLib(), llvm::Linker::LinkInLibrary(), and llvm::Linker::LinkModules().
bool llvm::sys::Path::isFile | ( | ) | const |
Determines if the path name references a file.
This function determines if the object referenced by this path is a file or not. This function accesses the underlying file system to determine the type of entity referenced by the path.
bool llvm::sys::Path::isHidden | ( | ) | const |
Determines if the path name references a hidden file.
This function determines if the path refers to a hidden file. The notion of hidden files is defined by the underlying system. The system may not support hidden files in which case this function always returns false on such systems. Hidden files have the "hidden" attribute set on Win32. On Unix, hidden files start with a period.
bool llvm::sys::Path::isRootDirectory | ( | ) | const |
Determines if the path references the root directory.
This function determines if the path name in this object references the root (top level directory) of the file system. The details of what is considered the "root" may vary from system to system so this method will do the necessary checking.
bool llvm::sys::Path::isValid | ( | ) | const |
Determine if a path is syntactically valid or not.
This function will use an operating system specific algorithm to determine if the current value of this
is a syntactically valid path name for the operating system. The path name does not need to exist, validity is simply syntactical. Empty paths are always invalid.
void llvm::sys::Path::makeExecutableOnDisk | ( | ) |
Make the file readable;.
This method attempts to make the file referenced by the Path object available for execution so that the canExecute() method will return true.
void llvm::sys::Path::makeReadableOnDisk | ( | ) |
void llvm::sys::Path::makeUnique | ( | bool | reuse_current = true |
) |
Make the current path name unique in the file system.
The current Path name is made unique in the file system. Upon return, the Path will have been changed to make a unique file in the file system or it will not have been changed if the current path name is already unique.
std::string | if an unrecoverable error occurs. |
Referenced by llvm::GCC::ExecuteProgram(), llvm::GCC::MakeSharedObject(), llvm::LLC::OutputAsm(), llvm::CBE::OutputC(), and ProcessFailure().
void llvm::sys::Path::makeWriteableOnDisk | ( | ) |
Make the file writable;.
This method attempts to make the file referenced by the Path object available for writing so that the canWrite() method will return true.
bool llvm::sys::Path::operator!= | ( | const Path & | that | ) | const [inline] |
bool llvm::sys::Path::operator< | ( | const Path & | that | ) | const [inline] |
Less Than Operator.
Determines if this
Path is less than that
Path. This is required so that Path objects can be placed into ordered collections (e.g. std::map). The comparison is done lexicographically as defined by the std::string::compare method.
this
path is lexicographically less than that
. Definition at line 202 of file Path.h.
References path.
bool llvm::sys::Path::operator== | ( | const Path & | that | ) | const [inline] |
bool llvm::sys::Path::renamePathOnDisk | ( | const Path & | newName | ) |
Rename one file as another.
This method renames the file referenced by this
as newName
. The file referenced by this
must exist. The file referenced by newName
does not need to exist.
std::string | if there is an file system error. |
Referenced by llvm::Archive::writeToDisk().
bool llvm::sys::Path::set | ( | const std::string & | unverified_path | ) |
Set a full path from a std::string.
This method sets the Path object to unverified_path
. This can fail if the unverified_path
does not pass the syntactic checks of the isValid() method. If verification fails, the Path object remains unchanged and false is returned. Otherwise true is returned and the Path object takes on the path value of unverified_path
unverified_path | The path to be set in Path object. |
Referenced by GetLLVMConfigDir(), llvm::Linker::LinkModules(), and llvm::Archive::parseMemberHeader().
bool llvm::sys::Path::setStatusInfoOnDisk | ( | const StatusInfo & | si | ) | const |
Set the status information.
This method allows the last modified time stamp and permission bits to be set on the disk object referenced by the Path.
std::string | if an error occurs. |
const std::string& llvm::sys::Path::toString | ( | ) | const [inline] |
Returns the path as a std::string.
This function returns the current contents of the path as a std::string. This allows the underlying path string to be manipulated.
Definition at line 230 of file Path.h.
Referenced by llvm::Archive::addFileBefore(), llvm::GCC::create(), llvm::AbstractInterpreter::createCBE(), llvm::AbstractInterpreter::createJIT(), llvm::AbstractInterpreter::createLLC(), llvm::AbstractInterpreter::createLLI(), llvm::CBE::ExecuteProgram(), llvm::LLC::ExecuteProgram(), llvm::Archive::fillHeader(), llvm::Archive::findModuleDefiningSymbol(), llvm::Archive::findModulesDefiningSymbols(), llvm::Archive::getAllModules(), llvm::GetBytecodeSymbols(), llvm::SourceFile::getFilename(), llvm::ArchiveMember::getMemberSize(), llvm::Archive::isBytecodeArchive(), llvm::Linker::LinkInFile(), llvm::Linker::LinkInLibrary(), llvm::GCC::MakeSharedObject(), llvm::operator<<(), llvm::ArchiveMember::replaceWith(), llvm::SelectionDAG::viewGraph(), llvm::Archive::writeMember(), and llvm::Archive::writeToDisk().