LLVM: llvm::sys::path Namespace Reference (original) (raw)

Enumerations
enum class Style { native, posix, windows_slash, windows_backslash, windows = windows_backslash }
Functions
constexpr bool is_style_posix (Style S)
Check if S uses POSIX path rules.
constexpr bool is_style_windows (Style S)
Check if S uses Windows path rules.
reverse_iterator rbegin (StringRef Path, Style style)
reverse_iterator rend (StringRef Path)
static bool starts_with (StringRef Path, StringRef Prefix, Style style=Style::native)
StringRef remove_leading_dotslash (StringRef Path, Style style)
Lexical Component Iterator
LLVM_ABI const_iterator begin (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
LLVM_ABI const_iterator end (StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
LLVM_ABI reverse_iterator rbegin (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get reverse begin iterator over path.
LLVM_ABI reverse_iterator rend (StringRef path LLVM_LIFETIME_BOUND)
Get reverse end iterator over path.
Lexical Modifiers
LLVM_ABI void remove_filename (SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
LLVM_ABI void replace_extension (SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
LLVM_ABI bool replace_path_prefix (SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
LLVM_ABI StringRef remove_leading_dotslash (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
LLVM_ABI bool remove_dots (SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
LLVM_ABI void append (SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI void append (SmallVectorImpl< char > &path, Style style, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
LLVM_ABI void append (SmallVectorImpl< char > &path, const_iterator begin, const_iterator end, Style style=Style::native)
Append to path.
Transforms (or some other better name)
LLVM_ABI void native (const Twine &path, SmallVectorImpl< char > &result, Style style=Style::native)
Convert path to the native form.
LLVM_ABI void native (SmallVectorImpl< char > &path, Style style=Style::native)
Convert path to the native form in place.
void make_preferred (SmallVectorImpl< char > &path, Style style=Style::native)
For Windows path styles, convert path to use the preferred path separators.
LLVM_ABI std::string convert_to_slash (StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Lexical Observers
LLVM_ABI StringRef root_name (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root name.
LLVM_ABI StringRef root_directory (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root directory.
LLVM_ABI StringRef root_path (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root path.
LLVM_ABI StringRef relative_path (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get relative path.
LLVM_ABI StringRef parent_path (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI StringRef filename (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI StringRef stem (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get stem.
LLVM_ABI StringRef extension (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get extension.
LLVM_ABI bool is_separator (char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
LLVM_ABI StringRef get_separator (Style style=Style::native)
Return the preferred separator for this platform.
LLVM_ABI void system_temp_directory (bool erasedOnReboot, SmallVectorImpl< char > &result)
Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
LLVM_ABI bool home_directory (SmallVectorImpl< char > &result)
Get the user's home directory.
LLVM_ABI bool user_config_directory (SmallVectorImpl< char > &result)
Get the directory where packages should read user-specific configurations.
LLVM_ABI bool cache_directory (SmallVectorImpl< char > &result)
Get the directory where installed packages should put their machine-local cache, e.g.
LLVM_ABI bool has_root_name (const Twine &path, Style style=Style::native)
Has root name?
LLVM_ABI bool has_root_directory (const Twine &path, Style style=Style::native)
Has root directory?
LLVM_ABI bool has_root_path (const Twine &path, Style style=Style::native)
Has root path?
LLVM_ABI bool has_relative_path (const Twine &path, Style style=Style::native)
Has relative path?
LLVM_ABI bool has_parent_path (const Twine &path, Style style=Style::native)
Has parent path?
LLVM_ABI bool has_filename (const Twine &path, Style style=Style::native)
Has filename?
LLVM_ABI bool has_stem (const Twine &path, Style style=Style::native)
Has stem?
LLVM_ABI bool has_extension (const Twine &path, Style style=Style::native)
Has extension?
LLVM_ABI bool is_absolute (const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI bool is_absolute_gnu (const Twine &path, Style style=Style::native)
Is path absolute using GNU rules?
LLVM_ABI bool is_relative (const Twine &path, Style style=Style::native)
Is path relative?
LLVM_ABI void make_absolute (const Twine &current_directory, SmallVectorImpl< char > &path)
Make path an absolute path.

Style

enum class llvm::sys::path::Style strong
Enumerator
native
posix
windows_slash
windows_backslash
windows

Definition at line 28 of file Path.h.

append() [1/3]

Append to path.

/foo + bar/f => /foo/bar/f

/foo/ + bar/f => /foo/bar/f

foo + bar/f => foo/bar/f

foo + /bar/f => foo/bar/f (FIXME: will be changed to /bar/f to align

with C++17 std::filesystem::path::append)

@ C

The default llvm calling convention, compatible with C.

Parameters

path Set to path + component.
a The component to be appended to path.

Definition at line 456 of file Path.cpp.

References append(), and native.

Referenced by llvm::FileCollector::addFileImpl(), llvm::analyzeImportedModule(), llvm::dwarf_linker::parallel::CompileUnit::analyzeImportedModule(), append(), append(), llvm::appendArchToWindowsSDKLibPath(), codegen(), llvm::cas::ondisk::UnifiedOnDiskCache::collectGarbage(), llvm::computeArchiveRelativePath(), llvm::logicalview::LVReader::createAlternativePath(), llvm::sys::fs::createUniquePath(), llvm::remarks::createYAMLParserFromMeta(), ExpandBasePaths(), llvm:🆑:ExpansionContext::expandResponseFiles(), llvm::object::BuildIDFetcher::fetch(), fillLineInfoFromLocation(), llvm:🆑:ExpansionContext::findConfigFile(), llvm::object::MachOObjectFile::findDsymObjectMembers(), llvm::sys::Process::FindInEnvPath(), findInputFile(), findSrcDirMap(), llvm::findVCToolChainViaCommandLine(), llvm::findVCToolChainViaEnvironment(), llvm::findVCToolChainViaRegistry(), llvm::findVCToolChainViaSetupConfig(), llvm::DiagnosticLocation::getAbsolutePath(), llvm::getCachedOrDownloadArtifact(), llvm::getDebuginfodDebuginfoUrlPath(), llvm::getDebuginfodExecutableUrlPath(), llvm::getDebuginfodSourceUrlPath(), llvm::getDefaultDebuginfodCacheDirectory(), llvm::LineEditor::getDefaultHistoryPath(), llvm::dwarf_linker::parallel::CompileUnit::getDirAndFilenameFromLineTable(), llvm::dwarf_linker::parallel::CompileUnit::getFileName(), getFilename(), llvm::DWARFDebugLine::Prologue::getFileNameByIndex(), llvm::object::Archive::Child::getFullName(), llvm::unittest::getInputFileDirectory(), llvm::vfs::RedirectingFileSystem::LookupResult::getPath(), llvm::gsym::LookupResult::getSourceFile(), llvm::getSubDirectoryPath(), getVFSEntries(), getWindows10SDKVersionFromPath(), llvm::getWindowsSDKDir(), getWindowsSDKDirViaCommandLine(), llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::loadClangModule(), llvm::localCache(), llvm::vfs::RedirectingFileSystem::LookupResult::LookupResult(), make_absolute(), llvm::MachO::make_relative(), llvm::codegen::MaybeSaveStatistics(), llvm::cas::ondisk::OnDiskGraphDB::open(), llvm::cas::ondisk::OnDiskKeyValueDB::open(), llvm::cas::ondisk::UnifiedOnDiskCache::open(), llvm::SourceMgr::OpenIncludeFile(), llvm::unittest::TempDir::path(), llvm::pruneCache(), llvm::orc::PathResolver::realpathCached(), llvm::sys::fs::directory_entry::replace_filename(), llvm::dwarf_linker::classic::CachedPathResolver::resolve(), llvm::orc::SearchPathResolver::resolve(), llvm::resolveRelativeObjectPath(), resolveRelativeObjectPath(), llvm::AMDGPUSplitModulePass::run(), llvm::pdb::NativeSession::searchForPdb(), llvm::MCContext::setGenDwarfRootFile(), llvm::useUniversalCRT(), llvm::cas::ondisk::UnifiedOnDiskCache::validateIfNeeded(), and llvm::ThinLTOCodeGenerator::writeGeneratedObject().

append() [2/3]

Append to path.

/foo + [bar,f] => /foo/bar/f

/foo/ + [bar,f] => /foo/bar/f

foo + [bar,f] => foo/bar/f

Parameters

path Set to path + [begin, end).
begin Start of components to append.
end One past the end of components to append.

Definition at line 461 of file Path.cpp.

References append(), begin(), and end().

append() [3/3]

begin()

cache_directory()

Get the directory where installed packages should put their machine-local cache, e.g.

$XDG_CACHE_HOME.

Parameters

result Holds the resulting path name.

Returns

True if the appropriate path was determined, it need not exist.

References LLVM_ABI, and native.

Referenced by llvm::getDefaultDebuginfodCacheDirectory().

convert_to_slash()

std::string llvm::sys::path::convert_to_slash ( StringRef path,
Style style = Style::native )

end()

extension()

Get extension.

If filename contains a dot but not solely one or two dots, result is the substring of filename starting at (and including) the last dot, and ending at the end of path. Otherwise "".

/foo/bar.txt => .txt

/foo/bar =>

/foo/.txt => .txt

Parameters

Returns

The extension of path.

Definition at line 590 of file Path.cpp.

References filename(), llvm::StringRef::find_last_of(), llvm::StringRef::npos, llvm::StringRef::size(), and llvm::StringRef::substr().

Referenced by llvm::DWARFContext::dump(), llvm::object::MachOObjectFile::findDsymObjectMembers(), llvm::pdb::PDBSymbolCompiland::getSourceFileFullPath(), has_extension(), rend(), and replace_extension().

filename()

Get filename.

/foo.txt => foo.txt

. => .

.. => ..

/ => /

Parameters

Returns

The filename part of path. This is defined as the last component of path. Similar to the POSIX "basename" utility.

Definition at line 577 of file Path.cpp.

References rbegin().

Referenced by llvm::vfs::RedirectingFileSystem::create(), llvm::logicalview::LVReader::createAlternativePath(), llvm::objcopy::coff::createGnuDebugLinkSectionContents(), llvm::AsmPrinter::doInitialization(), llvm::emitSourceFileHeader(), llvm::objcopy::macho::executeObjcopyOnBinary(), llvm::ModuleSummaryIndex::exportToDot(), extension(), llvm::findVCToolChainViaEnvironment(), getAllDBDirs(), llvm::dwarf_linker::parallel::CompileUnit::getFileName(), llvm::orc::LibraryManager::LibraryInfo::getFileName(), llvm::DWARFDebugLine::Prologue::getFileNameByIndex(), getHighestNumericTupleInDirectory(), llvm::pdb::PDBSymbolCompiland::getSourceFileName(), has_filename(), llvm::gsym::GsymCreator::insertFile(), llvm::dwarf_linker::classic::DWARFLinker::link(), mangleCoveragePath(), llvm::codegen::MaybeSaveStatistics(), llvm::dwarf_linker::parallel::DWARFLinkerImpl::printStatistic(), llvm::pruneCache(), llvm::MachO::replace_extension(), llvm::dwarf_linker::classic::CachedPathResolver::resolve(), llvm::CtxProfAnalysis::run(), llvm::pdb::NativeSession::searchForPdb(), stem(), llvm::timeTraceProfilerInitialize(), llvm::MCDwarfLineTableHeader::tryGetFile(), and llvm::object::writeImportLibrary().

get_separator()

has_extension()

has_filename()

has_parent_path()

has_relative_path()

has_root_directory()

has_root_name()

has_root_path()

has_stem()

home_directory()

is_absolute()

Is path absolute?

According to cppreference.com, C++17 states: "An absolute path is a path that unambiguously identifies the location of a file without reference to an additional starting location."

In other words, the rules are: 1) POSIX style paths with nonempty root directory are absolute. 2) Windows style paths with nonempty root name and root directory are absolute. 3) No other paths are absolute.

See also

has_root_name

has_root_directory

Parameters

Returns

True if the path is absolute, false if it is not.

Definition at line 671 of file Path.cpp.

References has_root_directory(), has_root_name(), and is_style_posix().

Referenced by llvm::sys::fs::createUniquePath(), ExpandBasePaths(), llvm::FileCollector::FileCollector(), llvm::sys::Process::FindInEnvPath(), llvm::DiagnosticLocation::getAbsolutePath(), llvm::object::Archive::Child::getFullName(), llvm::pdb::PDBSymbolCompiland::getSourceFileFullPath(), is_relative(), isPathAbsoluteOnWindowsOrPosix(), llvm::dwarf_linker::isPathAbsoluteOnWindowsOrPosix(), llvm::sys::fs::make_absolute(), llvm::vfs::FileSystem::makeAbsolute(), llvm::vfs::RedirectingFileSystem::makeAbsolute(), and llvm::orc::DylibResolverImpl::resolve().

is_absolute_gnu()

Is path absolute using GNU rules?

GNU rules are: 1) Paths starting with a path separator are absolute. 2) Windows style paths are also absolute if they start with a character followed by ':'. 3) No other paths are absolute.

On Windows style the path "C:\Users\Default" has "C:" as root name and "\" as root directory. Hence "C:" on Windows is absolute under GNU rules and not absolute under C++17 because it has no root directory. Likewise "/" and "" on Windows are absolute under GNU and are not absolute under C++17 due to empty root name.

See also

has_root_name

has_root_directory

Parameters

path Input path.
style The style of path (e.g. Windows or POSIX). "native" style means to derive the style from the host.

Returns

True if the path is absolute following GNU rules, false if it is not.

Definition at line 681 of file Path.cpp.

References is_separator(), and is_style_windows().

is_relative()

is_separator()

bool llvm::sys::path::is_separator ( char value,
Style style = Style::native )

Check whether the given char is a path separator on the host OS.

Parameters

Returns

true if value is a path separator character on the host OS

Definition at line 601 of file Path.cpp.

References is_style_windows().

Referenced by append(), llvm::orc::createComponent(), llvm::orc::DumpObjects::DumpObjects(), is_absolute_gnu(), isNetworkPath(), native(), llvm::sys::path::const_iterator::operator++(), llvm::sys::path::reverse_iterator::operator++(), remove_leading_dotslash(), root_directory(), root_name(), root_path(), llvm::MCContext::setGenDwarfRootFile(), starts_with(), and llvm::stripDirPrefix().

is_style_posix()

bool llvm::sys::path::is_style_posix ( Style S) constexpr

is_style_windows()

bool llvm::sys::path::is_style_windows ( Style S) constexpr

make_absolute()

Make path an absolute path.

Makes path absolute using the current_directory if it is not already. An empty path will result in the current_directory.

/absolute/path => /absolute/path relative/../path => /relative/../path

Parameters

path A path that is modified to be an absolute path.

Definition at line 703 of file Path.cpp.

References append(), llvm::StringRef::begin(), llvm::StringRef::end(), has_root_directory(), has_root_name(), is_style_posix(), llvm_unreachable, native, relative_path(), root_directory(), root_name(), and llvm::Twine::toVector().

Referenced by llvm::sys::fs::make_absolute(), and llvm::vfs::FileSystem::makeAbsolute().

make_preferred()

For Windows path styles, convert path to use the preferred path separators.

For other styles, do nothing.

Parameters

path A path that is transformed to preferred format.

Definition at line 278 of file Path.h.

References is_style_windows(), and native.

Referenced by remove_dots().

native() [1/2]

native() [2/2]

parent_path()

Get parent path.

/ =>

/foo => /

foo/../bar => foo/..

Parameters

Returns

The parent path of path if one exists, otherwise "".

Definition at line 467 of file Path.cpp.

References llvm::StringRef::npos.

Referenced by llvm::computeArchiveRelativePath(), llvm::FileCollector::copyFiles(), llvm::vfs::RedirectingFileSystem::create(), llvm::vfs::RedirectingFileSystem::create(), llvm::sys::fs::create_directories(), llvm::logicalview::LVReader::createAlternativePath(), createDirectoriesOnDemand(), findSrcDirMap(), llvm::findVCToolChainViaEnvironment(), llvm::orc::LibraryManager::LibraryInfo::getBasePath(), llvm::pdb::PDBFile::getFileDirectory(), llvm::dwarf_linker::parallel::CompileUnit::getFileName(), llvm::object::Archive::Child::getFullName(), llvm::lto::getThinLTOOutputFile(), has_parent_path(), llvm::gsym::GsymCreator::insertFile(), llvm::MachO::make_relative(), prepareDumpIRFileDescriptor(), llvm::MachO::replace_extension(), llvm::sys::fs::directory_entry::replace_filename(), llvm::dwarf_linker::classic::CachedPathResolver::resolve(), llvm::MachO::shouldSkipSymLink(), and llvm::MCDwarfLineTableHeader::tryGetFile().

rbegin() [1/2]

rbegin() [2/2]

relative_path()

remove_dots()

In-place remove any '.

/' and optionally '../' components from a path.

Parameters

path processed path
remove_dot_dot specify if '../' (except for leading "../") should be removed

Returns

True if path was changed

Definition at line 764 of file Path.cpp.

References llvm::ArrayRef(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::CallingConv::C, llvm::SmallVectorTemplateCommon< T, typename >::data(), llvm::StringRef::drop_front(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::StringRef::empty(), llvm::StringRef::find_first_of(), llvm::StringRef::front(), make_preferred(), llvm::StringRef::npos, llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), root_path(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::StringRef::size(), llvm::SmallVectorImpl< T >::swap(), and llvm::StringRef::take_front().

Referenced by llvm::FileCollector::PathCanonicalizer::canonicalize(), llvm::canonicalizePath(), llvm::object::MachOObjectFile::findDsymObjectMembers(), llvm::vfs::InMemoryFileSystem::getRealPath(), and llvm::vfs::InMemoryFileSystem::setCurrentWorkingDirectory().

remove_filename()

remove_leading_dotslash() [1/2]

remove_leading_dotslash() [2/2]

rend() [1/2]

rend() [2/2]

replace_extension()

Replace the file extension of path with extension.

./filename.cpp => ./filename.extension

./filename => ./filename.extension

./ => ./.extension

Parameters

path A path that has its extension replaced with extension.
extension The extension to be added. It may be empty. It may also optionally start with a '.', if it does not, one will be prepended.

Definition at line 480 of file Path.cpp.

References llvm::StringRef::begin(), llvm::StringRef::end(), extension(), llvm::StringRef::npos, and llvm::StringRef::size().

Referenced by getDefaultOutputPath(), llvm::codegen::MaybeSaveStatistics(), llvm::MachO::replace_extension(), searchForExe(), searchForObj(), and llvm::TableGenMain().

replace_path_prefix()

Replace matching path prefix with another path.

/foo, /old, /new => /foo

/old, /old, /new => /new

/old, /old/, /new => /old

/old/foo, /old, /new => /new/foo

/old/foo, /old/, /new => /new/foo

/old/foo, /old/, /new/ => /new/foo

/oldfoo, /old, /new => /oldfoo

/foo, , /new => /new/foo

/foo, , new => new/foo

/old/foo, /old, => /foo

Parameters

Path If Path starts with OldPrefix modify to instead start with NewPrefix.
OldPrefix The path prefix to strip from Path.
NewPrefix The path prefix to replace NewPrefix with.
style The style used to match the prefix. Exact match using Posix style, case/separator insensitive match for Windows style.

Returns

true if Path begins with OldPrefix

Definition at line 518 of file Path.cpp.

References llvm::copy(), llvm::StringRef::empty(), llvm::StringRef::size(), starts_with(), and llvm::StringRef::substr().

Referenced by llvm::lto::getThinLTOOutputFile(), llvm::MCContext::remapDebugPath(), llvm::remapPath(), and remapPath().

root_directory()

root_name()

root_path()

starts_with()

stem()

system_temp_directory()

Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".

Parameters

erasedOnReboot Whether to favor a path that is erased on reboot rather than one that potentially persists longer. This parameter will be ignored if the user or system has set the typical environment variable (e.g., TEMP on Windows, TMPDIR on *nix) to specify a temporary directory.
result Holds the resulting path name.

References LLVM_ABI.

Referenced by llvm::sys::fs::createUniquePath(), and llvm::AMDGPUSplitModulePass::run().

user_config_directory()

Get the directory where packages should read user-specific configurations.

e.g. $XDG_CONFIG_HOME.

Parameters

result Holds the resulting path name.

Returns

True if the appropriate path was determined, it need not exist.

References LLVM_ABI.