LLVM 24.0.0git
llvm::PrefixMapper Class Reference

Remap path prefixes. More...

#include "llvm/Support/PrefixMapper.h"

Public Member Functions

virtual ~PrefixMapper ()=default
bool map (StringRef Path, SmallVectorImpl< char > &NewPath) const
 Map Path, and saving the new (or existing) path in NewPath.
bool map (StringRef Path, std::string &NewPath) const
 Map Path, and saving the new (or existing) path in NewPath.
std::string mapToString (StringRef Path) const
 Map Path, returning std::string.
bool mapInPlace (SmallVectorImpl< char > &Path) const
 Map Path in place.
bool mapInPlace (std::string &Path) const
 Map Path in place.
virtual void add (const MappedPrefix &MP)
void sort ()
 A path-based reverse lexicographic sort, putting deeper paths first so that deeper paths are prioritized over their parent paths.
template<class RangeT>
void addRange (const RangeT &Mappings)
template<class RangeT>
void addInverseRange (const RangeT &Mappings)
bool empty () const
ArrayRef< MappedPrefix > getMappings () const
sys::path::Style getPathStyle () const
 PrefixMapper (sys::path::Style PathStyle=sys::path::Style::native)

Protected Member Functions

virtual std::optional< StringRef > mapImpl (StringRef Path, SmallVectorImpl< char > &Storage) const
 Map (or unmap) Path.

Detailed Description

Remap path prefixes.

Mappings are tried in order and the first match wins. A mapping only matches whole path components: Old must be followed by a separator or the end of the path, unless Old itself ends with a separator. For example, "/old=/new" remaps "/old" and "/old/a" but not "/old-a", and "/=/new" remaps every absolute path. With a Windows path style, matching is case- and separator-insensitive.

The rest of the path is joined to New with sys::path::append(): a separator is added if neither side has one, and leading separators are dropped from the rest if New ends with one. For example, "/old/a" maps to "/new/a" with either "/old=/new" or "/old/=/new/".

Paths are not canonicalized, so "/old/../a" maps to "/new/../a", "/old//a" maps to "/new//a", and "//old" is not matched by "/old".

Definition at line 76 of file PrefixMapper.h.

Constructor & Destructor Documentation

◆ ~PrefixMapper()

virtual llvm::PrefixMapper::~PrefixMapper ( )
virtualdefault

◆ PrefixMapper()

llvm::PrefixMapper::PrefixMapper ( sys::path::Style PathStyle = sys::path::Style::native)
inlineexplicit

Definition at line 141 of file PrefixMapper.h.

References llvm::sys::path::native.

Member Function Documentation

◆ add()

virtual void llvm::PrefixMapper::add ( const MappedPrefix & MP)
inlinevirtual

Definition at line 111 of file PrefixMapper.h.

Referenced by addInverseRange(), and addRange().

◆ addInverseRange()

template<class RangeT>
void llvm::PrefixMapper::addInverseRange ( const RangeT & Mappings)
inline

Definition at line 130 of file PrefixMapper.h.

References add().

◆ addRange()

template<class RangeT>
void llvm::PrefixMapper::addRange ( const RangeT & Mappings)
inline

Definition at line 125 of file PrefixMapper.h.

References add().

◆ empty()

bool llvm::PrefixMapper::empty ( ) const
inline

Definition at line 135 of file PrefixMapper.h.

References getMappings().

◆ getMappings()

ArrayRef< MappedPrefix > llvm::PrefixMapper::getMappings ( ) const
inline

Definition at line 137 of file PrefixMapper.h.

Referenced by empty().

◆ getPathStyle()

sys::path::Style llvm::PrefixMapper::getPathStyle ( ) const
inline

Definition at line 139 of file PrefixMapper.h.

◆ map() [1/2]

bool PrefixMapper::map ( StringRef Path,
SmallVectorImpl< char > & NewPath ) const

Map Path, and saving the new (or existing) path in NewPath.

Precondition
Path is not a reference into NewPath.
Returns
true if NewPath was mapped.

Definition at line 136 of file PrefixMapper.cpp.

References llvm::SmallVectorImpl< T >::assign(), llvm::SmallVectorImpl< T >::clear(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), mapImpl(), and Modified.

Referenced by ~PrefixMapper().

◆ map() [2/2]

bool PrefixMapper::map ( StringRef Path,
std::string & NewPath ) const

Map Path, and saving the new (or existing) path in NewPath.

Precondition
Path is not a reference into NewPath.
Returns
true if NewPath was mapped.

Definition at line 148 of file PrefixMapper.cpp.

References mapImpl().

◆ mapImpl()

std::optional< StringRef > PrefixMapper::mapImpl ( StringRef Path,
SmallVectorImpl< char > & Storage ) const
protectedvirtual

◆ mapInPlace() [1/2]

bool PrefixMapper::mapInPlace ( SmallVectorImpl< char > & Path) const

Map Path in place.

Returns
true if the path was modified.

Definition at line 161 of file PrefixMapper.cpp.

References llvm::SmallVectorTemplateCommon< T, typename >::empty(), mapImpl(), and llvm::SmallVectorImpl< T >::swap().

Referenced by ~PrefixMapper().

◆ mapInPlace() [2/2]

bool PrefixMapper::mapInPlace ( std::string & Path) const

Map Path in place.

Returns
true if the path was modified.

Definition at line 174 of file PrefixMapper.cpp.

References mapImpl().

◆ mapToString()

std::string PrefixMapper::mapToString ( StringRef Path) const

Map Path, returning std::string.

Definition at line 155 of file PrefixMapper.cpp.

References mapImpl().

Referenced by ~PrefixMapper().

◆ sort()

void PrefixMapper::sort ( )

A path-based reverse lexicographic sort, putting deeper paths first so that deeper paths are prioritized over their parent paths.

For example, if both the source and build directories are remapped and one is nested inside the other, the nested one will come first.

FIXME: The comparison is case- and separator-sensitive, unlike matching with a Windows path style.

FIXME: Should probably be done implicitly, maybe by moving to a std::set or std::map.

Definition at line 183 of file PrefixMapper.cpp.


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