forked from OSchip/llvm-project
Change PathMappingList::FindFile to return an optional result (NFC)
This is an NFC modernization refactoring that replaces the combination of a bool return + reference argument, with an Optional return value. Differential Revision: https://reviews.llvm.org/D104405
This commit is contained in:
parent
e0b90771c3
commit
a346372200
|
@ -90,14 +90,9 @@ public:
|
|||
/// \param[in] orig_spec
|
||||
/// The original source file path to try and remap.
|
||||
///
|
||||
/// \param[out] new_spec
|
||||
/// The newly remapped filespec that is guaranteed to exist.
|
||||
///
|
||||
/// \return
|
||||
/// /b true if \a orig_spec was successfully located and
|
||||
/// \a new_spec is filled in with an existing file spec,
|
||||
/// \b false otherwise.
|
||||
bool FindFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
|
||||
/// The newly remapped filespec that is guaranteed to exist.
|
||||
llvm::Optional<FileSpec> FindFile(const FileSpec &orig_spec) const;
|
||||
|
||||
uint32_t FindIndexForPath(ConstString path) const;
|
||||
|
||||
|
|
|
@ -1598,7 +1598,11 @@ bool Module::MatchesModuleSpec(const ModuleSpec &module_ref) {
|
|||
bool Module::FindSourceFile(const FileSpec &orig_spec,
|
||||
FileSpec &new_spec) const {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||
return m_source_mappings.FindFile(orig_spec, new_spec);
|
||||
if (auto remapped = m_source_mappings.FindFile(orig_spec)) {
|
||||
new_spec = *remapped;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Module::RemapSourceFile(llvm::StringRef path,
|
||||
|
|
|
@ -441,13 +441,17 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec,
|
|||
}
|
||||
// Try remapping if m_file_spec does not correspond to an existing file.
|
||||
if (!FileSystem::Instance().Exists(m_file_spec)) {
|
||||
FileSpec new_file_spec;
|
||||
// Check target specific source remappings first, then fall back to
|
||||
// modules objects can have individual path remappings that were
|
||||
// detected when the debug info for a module was found. then
|
||||
if (target->GetSourcePathMap().FindFile(m_file_spec, new_file_spec) ||
|
||||
target->GetImages().FindSourceFile(m_file_spec, new_file_spec)) {
|
||||
m_file_spec = new_file_spec;
|
||||
// Check target specific source remappings (i.e., the
|
||||
// target.source-map setting), then fall back to the module
|
||||
// specific remapping (i.e., the .dSYM remapping dictionary).
|
||||
auto remapped = target->GetSourcePathMap().FindFile(m_file_spec);
|
||||
if (!remapped) {
|
||||
FileSpec new_spec;
|
||||
if (target->GetImages().FindSourceFile(m_file_spec, new_spec))
|
||||
remapped = new_spec;
|
||||
}
|
||||
if (remapped) {
|
||||
m_file_spec = *remapped;
|
||||
m_mod_time = FileSystem::Instance().GetModificationTime(m_file_spec);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,9 +252,9 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange(
|
|||
|
||||
void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) {
|
||||
if (target_sp) {
|
||||
// Apply any file remappings to our file
|
||||
FileSpec new_file_spec;
|
||||
if (target_sp->GetSourcePathMap().FindFile(original_file, new_file_spec))
|
||||
file = new_file_spec;
|
||||
// Apply any file remappings to our file.
|
||||
if (auto new_file_spec =
|
||||
target_sp->GetSourcePathMap().FindFile(original_file))
|
||||
file = *new_file_spec;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,16 +194,16 @@ bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) co
|
|||
return false;
|
||||
}
|
||||
|
||||
bool PathMappingList::FindFile(const FileSpec &orig_spec,
|
||||
FileSpec &new_spec) const {
|
||||
llvm::Optional<FileSpec>
|
||||
PathMappingList::FindFile(const FileSpec &orig_spec) const {
|
||||
if (m_pairs.empty())
|
||||
return false;
|
||||
|
||||
return {};
|
||||
|
||||
std::string orig_path = orig_spec.GetPath();
|
||||
|
||||
if (orig_path.empty())
|
||||
return false;
|
||||
|
||||
return {};
|
||||
|
||||
bool orig_is_relative = orig_spec.IsRelative();
|
||||
|
||||
for (auto entry : m_pairs) {
|
||||
|
@ -228,15 +228,15 @@ bool PathMappingList::FindFile(const FileSpec &orig_spec,
|
|||
continue;
|
||||
|
||||
if (orig_ref.consume_front(prefix_ref)) {
|
||||
FileSpec new_spec;
|
||||
new_spec.SetFile(entry.second.GetCString(), FileSpec::Style::native);
|
||||
new_spec.AppendPathComponent(orig_ref);
|
||||
if (FileSystem::Instance().Exists(new_spec))
|
||||
return true;
|
||||
return new_spec;
|
||||
}
|
||||
}
|
||||
|
||||
new_spec.Clear();
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool PathMappingList::Replace(ConstString path,
|
||||
|
|
Loading…
Reference in New Issue