34std::string NormalizePath(llvm::StringRef path) {
44 : m_pairs(), m_callback(callback), m_callback_baton(callback_baton) {}
47 : m_pairs(rhs.m_pairs) {}
51 std::scoped_lock<std::mutex, std::mutex, std::mutex> locks(
64 llvm::StringRef replacement) {
66 m_pairs.emplace_back(
pair(NormalizePath(path), NormalizePath(replacement)));
71 void *baton =
nullptr;
77 if (notify && callback)
78 callback(*
this, baton);
98 for (pos = rhs.
m_pairs.begin(); pos != end; ++pos)
105 llvm::StringRef replacement,
bool notify) {
106 auto normalized_path = NormalizePath(path);
107 auto normalized_replacement = NormalizePath(replacement);
111 if (
pair.first.GetStringRef() == normalized_path &&
112 pair.second.GetStringRef() == normalized_replacement)
122 uint32_t index,
bool notify) {
130 insert_iter =
m_pairs.begin() + index;
132 pair(NormalizePath(path), NormalizePath(replacement)));
138 uint32_t index,
bool notify) {
144 m_pairs[index] =
pair(NormalizePath(path), NormalizePath(replacement));
168 unsigned int numPairs =
m_pairs.size();
170 if (pair_index < 0) {
172 for (index = 0; index < numPairs; ++index)
173 s->
Printf(
"[%d] \"%s\" -> \"%s\"\n", index,
174 m_pairs[index].first.GetCString(),
175 m_pairs[index].second.GetCString());
177 if (
static_cast<unsigned int>(pair_index) < numPairs)
178 s->
Printf(
"%s -> %s",
m_pairs[pair_index].first.GetCString(),
179 m_pairs[pair_index].second.GetCString());
184 llvm::json::Array entries;
187 llvm::json::Array entry{
pair.first.GetStringRef().str(),
188 pair.second.GetStringRef().str()};
189 entries.emplace_back(std::move(entry));
215 llvm::sys::path::Style style) {
216 auto component = llvm::sys::path::begin(components, style);
217 auto e = llvm::sys::path::end(components);
218 while (component != e &&
219 llvm::sys::path::is_separator(*component->data(), style))
221 for (; component != e; ++component)
226 bool only_if_exists)
const {
228 if (
m_pairs.empty() || mapping_path.empty())
232 for (
const auto &it :
m_pairs) {
233 llvm::StringRef prefix = it.first.GetStringRef();
236 llvm::StringRef path = mapping_path;
237 if (!path.consume_front(prefix)) {
249 if (!path_is_relative)
252 FileSpec remapped(it.second.GetStringRef());
254 llvm::sys::path::Style::native);
262std::optional<llvm::StringRef>
264 std::string path = file.
GetPath();
265 llvm::StringRef path_ref(path);
267 for (
const auto &it :
m_pairs) {
268 llvm::StringRef removed_prefix = it.second.GetStringRef();
269 if (!path_ref.consume_front(it.second.GetStringRef()))
271 auto orig_file = it.first.GetStringRef();
273 llvm::sys::path::Style::native);
274 fixed.
SetFile(orig_file, orig_style);
276 return removed_prefix;
281std::optional<FileSpec>
328 for (pos = begin; pos != end; ++pos) {
329 if (pos->first == path)
342 for (pos = begin; pos != end; ++pos) {
343 if (pos->first == path)
354 new_path =
m_pairs[idx].second;
367 for (pos = begin; pos != end; ++pos) {
368 if (pos->first == path)
369 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.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
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.
uint32_t FindIndexForPathNoLock(llvm::StringRef path) const
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)
void(* ChangedCallback)(const PathMappingList &path_list, void *baton)
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 AppendNoLock(llvm::StringRef path, llvm::StringRef replacement)
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()
uint32_t m_mod_id
Incremented anytime anything is added to or removed from m_pairs.
void Notify(bool notify) const
std::mutex m_callback_mutex
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.