Modernize Module::RemapFile to return an Optional (NFC)

This addresses feedback raised in https://reviews.llvm.org/D104404.

Differential Revision: https://reviews.llvm.org/D104724
This commit is contained in:
Adrian Prantl 2021-06-29 15:19:31 -07:00
parent 302b1b9718
commit a0e1b11fac
3 changed files with 14 additions and 18 deletions

View File

@ -850,13 +850,10 @@ public:
/// \param[in] path
/// The original source file path to try and remap.
///
/// \param[out] new_path
/// The newly remapped filespec that is may or may not exist.
///
/// \return
/// /b true if \a path was successfully located and \a new_path
/// is filled in with a new source path, \b false otherwise.
bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
/// The newly remapped filespec that is may or may not exist if
/// \a path was successfully located.
llvm::Optional<std::string> RemapSourceFile(llvm::StringRef path) const;
bool RemapSourceFile(const char *, std::string &) const = delete;
/// Update the ArchSpec to a more specific variant.

View File

@ -1605,14 +1605,11 @@ bool Module::FindSourceFile(const FileSpec &orig_spec,
return false;
}
bool Module::RemapSourceFile(llvm::StringRef path,
std::string &new_path) const {
llvm::Optional<std::string> Module::RemapSourceFile(llvm::StringRef path) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (auto remapped = m_source_mappings.RemapPath(path)) {
new_path = remapped->GetPath();
return true;
}
return false;
if (auto remapped = m_source_mappings.RemapPath(path))
return remapped->GetPath();
return {};
}
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {

View File

@ -240,9 +240,12 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
const size_t number_of_files = prologue.FileNames.size();
for (size_t idx = first_file; idx <= number_of_files; ++idx) {
std::string remapped_file;
if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style))
if (!module->RemapSourceFile(llvm::StringRef(*file_path), remapped_file))
if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style)) {
if (auto remapped = module->RemapSourceFile(llvm::StringRef(*file_path)))
remapped_file = *remapped;
else
remapped_file = std::move(*file_path);
}
// Unconditionally add an entry, so the indices match up.
support_files.EmplaceBack(remapped_file, style);
@ -681,9 +684,8 @@ static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu,
// files are NFS mounted.
file_spec.MakeAbsolute(dwarf_cu.GetCompilationDirectory());
std::string remapped_file;
if (module_sp->RemapSourceFile(file_spec.GetPath(), remapped_file))
file_spec.SetFile(remapped_file, FileSpec::Style::native);
if (auto remapped_file = module_sp->RemapSourceFile(file_spec.GetPath()))
file_spec.SetFile(*remapped_file, FileSpec::Style::native);
}
lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {