Skip to content

Commit ce7a54a

Browse files
committed
[lldb] Add operator StringRef to ConstString
Add a `StringRef` conversion function to `ConstString`. This will make using llvm, and other non-ConstString, APIs more convenient. For demonstration, this updates Module.cpp. Differential Revision: https://reviews.llvm.org/D148175
1 parent 0a09f64 commit ce7a54a

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lldb/include/lldb/Utility/ConstString.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ class ConstString {
180180

181181
bool operator<(ConstString rhs) const;
182182

183+
// Implicitly convert \class ConstString instances to \class StringRef.
184+
operator llvm::StringRef() const { return GetStringRef(); }
185+
183186
/// Get the string value as a C string.
184187
///
185188
/// Get the value of the contained string as a NULL terminated C string

lldb/source/Core/Module.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ bool Module::LookupInfo::NameMatchesLookupInfo(
748748
// relatively inexpensive since no demangling is actually occuring. See
749749
// Mangled::SetValue for more context.
750750
const bool function_name_may_be_mangled =
751-
Mangled::GetManglingScheme(function_name.GetStringRef()) !=
752-
Mangled::eManglingSchemeNone;
751+
Mangled::GetManglingScheme(function_name) != Mangled::eManglingSchemeNone;
753752
ConstString demangled_function_name = function_name;
754753
if (function_name_may_be_mangled) {
755754
Mangled mangled_function_name(function_name);
@@ -760,11 +759,10 @@ bool Module::LookupInfo::NameMatchesLookupInfo(
760759
// Otherwise just check that the demangled function name contains the
761760
// demangled user-provided name.
762761
if (Language *language = Language::FindPlugin(language_type))
763-
return language->DemangledNameContainsPath(m_name.GetStringRef(),
764-
demangled_function_name);
762+
return language->DemangledNameContainsPath(m_name, demangled_function_name);
765763

766-
llvm::StringRef function_name_ref = demangled_function_name.GetStringRef();
767-
return function_name_ref.contains(m_name.GetStringRef());
764+
llvm::StringRef function_name_ref = demangled_function_name;
765+
return function_name_ref.contains(m_name);
768766
}
769767

770768
void Module::LookupInfo::Prune(SymbolContextList &sc_list,
@@ -803,7 +801,7 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
803801
CPlusPlusLanguage::MethodName cpp_method(full_name);
804802
if (cpp_method.IsValid()) {
805803
if (cpp_method.GetContext().empty()) {
806-
if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0) {
804+
if (cpp_method.GetBasename().compare(m_name) != 0) {
807805
sc_list.RemoveContextAtIndex(i);
808806
continue;
809807
}
@@ -1026,8 +1024,8 @@ void Module::FindTypes(
10261024
FindTypes_Impl(name, CompilerDeclContext(), UINT_MAX,
10271025
searched_symbol_files, typesmap);
10281026
if (exact_match) {
1029-
typesmap.RemoveMismatchedTypes(type_scope, name.GetStringRef(),
1030-
type_class, exact_match);
1027+
typesmap.RemoveMismatchedTypes(type_scope, name, type_class,
1028+
exact_match);
10311029
}
10321030
}
10331031
}
@@ -1132,7 +1130,7 @@ void Module::ReportWarningOptimization(
11321130
return;
11331131

11341132
StreamString ss;
1135-
ss << file_name.GetStringRef()
1133+
ss << file_name
11361134
<< " was compiled with optimization - stepping may behave "
11371135
"oddly; variables may not be available.";
11381136
Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
@@ -1668,7 +1666,7 @@ uint32_t Module::Hash() {
16681666
llvm::raw_string_ostream id_strm(identifier);
16691667
id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
16701668
if (m_object_name)
1671-
id_strm << '(' << m_object_name.GetStringRef() << ')';
1669+
id_strm << '(' << m_object_name << ')';
16721670
if (m_object_offset > 0)
16731671
id_strm << m_object_offset;
16741672
const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
@@ -1682,7 +1680,7 @@ std::string Module::GetCacheKey() {
16821680
llvm::raw_string_ostream strm(key);
16831681
strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
16841682
if (m_object_name)
1685-
strm << '(' << m_object_name.GetStringRef() << ')';
1683+
strm << '(' << m_object_name << ')';
16861684
strm << '-' << llvm::format_hex(Hash(), 10);
16871685
return strm.str();
16881686
}

0 commit comments

Comments
 (0)