34std::string NormalizePath(llvm::StringRef path) {
44 : m_pairs(), m_callback(callback), m_callback_baton(callback_baton) {}
47 : m_pairs(rhs.m_pairs) {}
64 m_pairs.emplace_back(
pair(NormalizePath(path), NormalizePath(replacement)));
73 for (pos = rhs.
m_pairs.begin(); pos != end; ++pos)
81 llvm::StringRef replacement,
bool notify) {
82 auto normalized_path = NormalizePath(path);
83 auto normalized_replacement = NormalizePath(replacement);
85 if (
pair.first.GetStringRef().equals(normalized_path) &&
86 pair.second.GetStringRef().equals(normalized_replacement))
89 Append(path, replacement, notify);
100 insert_iter =
m_pairs.begin() + index;
101 m_pairs.emplace(insert_iter,
pair(NormalizePath(path),
102 NormalizePath(replacement)));
112 m_pairs[index] =
pair(NormalizePath(path), NormalizePath(replacement));
133 unsigned int numPairs =
m_pairs.size();
135 if (pair_index < 0) {
137 for (index = 0; index < numPairs; ++index)
138 s->
Printf(
"[%d] \"%s\" -> \"%s\"\n", index,
139 m_pairs[index].first.GetCString(),
140 m_pairs[index].second.GetCString());
142 if (
static_cast<unsigned int>(pair_index) < numPairs)
143 s->
Printf(
"%s -> %s",
m_pairs[pair_index].first.GetCString(),
144 m_pairs[pair_index].second.GetCString());
149 llvm::json::Array entries;
151 llvm::json::Array entry{
pair.first.GetStringRef().str(),
152 pair.second.GetStringRef().str()};
153 entries.emplace_back(std::move(entry));
177 llvm::sys::path::Style style) {
178 auto component = llvm::sys::path::begin(components, style);
179 auto e = llvm::sys::path::end(components);
180 while (component != e &&
181 llvm::sys::path::is_separator(*component->data(), style))
183 for (; component != e; ++component)
188 bool only_if_exists)
const {
189 if (
m_pairs.empty() || mapping_path.empty())
193 for (
const auto &it :
m_pairs) {
194 llvm::StringRef prefix = it.first.GetStringRef();
197 llvm::StringRef path = mapping_path;
198 if (!path.consume_front(prefix)) {
210 if (!path_is_relative)
213 FileSpec remapped(it.second.GetStringRef());
215 llvm::sys::path::Style::native);
223std::optional<llvm::StringRef>
225 std::string path = file.
GetPath();
226 llvm::StringRef path_ref(path);
227 for (
const auto &it :
m_pairs) {
228 llvm::StringRef removed_prefix = it.second.GetStringRef();
229 if (!path_ref.consume_front(it.second.GetStringRef()))
231 auto orig_file = it.first.GetStringRef();
233 llvm::sys::path::Style::native);
234 fixed.
SetFile(orig_file, orig_style);
236 return removed_prefix;
241std::optional<FileSpec>
284 for (pos = begin; pos != end; ++pos) {
285 if (pos->first == path)
297 for (pos = begin; pos != end; ++pos) {
298 if (pos->first == path)
308 new_path =
m_pairs[idx].second;
320 for (pos = begin; pos != end; ++pos) {
321 if (pos->first == path)
322 return std::distance(begin, pos);
static void AppendPathComponents(FileSpec &path, llvm::StringRef components, llvm::sys::path::Style style)
Append components to path, applying style.
A uniqued constant string class.
void SetString(const llvm::StringRef &s)
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
void AppendPathComponent(llvm::StringRef component)
static std::optional< Style > GuessPathStyle(llvm::StringRef absolute_path)
Attempt to guess path style for a given path string.
bool IsRelative() const
Returns true if the filespec represents a relative path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
bool Remove(size_t index, bool notify)
bool AppendUnique(llvm::StringRef path, llvm::StringRef replacement, bool notify)
Append <path, replacement> pair without duplication.
iterator FindIteratorForPath(ConstString path)
std::optional< FileSpec > FindFile(const FileSpec &orig_spec) const
Finds a source file given a file spec using the path remappings.
bool Replace(llvm::StringRef path, llvm::StringRef replacement, bool notify)
uint32_t FindIndexForPath(llvm::StringRef path) const
void Insert(llvm::StringRef path, llvm::StringRef replacement, uint32_t insert_idx, bool notify)
collection::const_iterator const_iterator
ChangedCallback m_callback
const PathMappingList & operator=(const PathMappingList &rhs)
void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify)
bool RemapPath(ConstString path, ConstString &new_path) const
bool GetPathsAtIndex(uint32_t idx, ConstString &path, ConstString &new_path) const
collection::iterator iterator
std::pair< ConstString, ConstString > pair
llvm::json::Value ToJSON()
std::optional< llvm::StringRef > ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const
Perform reverse source path remap for input file.
void Dump(Stream *s, int pair_index=-1)
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
A class that represents a running process on the host machine.