Skip to content

Commit de54d7f

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 (cherry-picked from commit ce7a54a)
1 parent 17b0aad commit de54d7f

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
@@ -771,8 +771,7 @@ bool Module::LookupInfo::NameMatchesLookupInfo(
771771
// relatively inexpensive since no demangling is actually occuring. See
772772
// Mangled::SetValue for more context.
773773
const bool function_name_may_be_mangled =
774-
Mangled::GetManglingScheme(function_name.GetStringRef()) !=
775-
Mangled::eManglingSchemeNone;
774+
Mangled::GetManglingScheme(function_name) != Mangled::eManglingSchemeNone;
776775
ConstString demangled_function_name = function_name;
777776
if (function_name_may_be_mangled) {
778777
Mangled mangled_function_name(function_name);
@@ -783,11 +782,10 @@ bool Module::LookupInfo::NameMatchesLookupInfo(
783782
// Otherwise just check that the demangled function name contains the
784783
// demangled user-provided name.
785784
if (Language *language = Language::FindPlugin(language_type))
786-
return language->DemangledNameContainsPath(m_name.GetStringRef(),
787-
demangled_function_name);
785+
return language->DemangledNameContainsPath(m_name, demangled_function_name);
788786

789-
llvm::StringRef function_name_ref = demangled_function_name.GetStringRef();
790-
return function_name_ref.contains(m_name.GetStringRef());
787+
llvm::StringRef function_name_ref = demangled_function_name;
788+
return function_name_ref.contains(m_name);
791789
}
792790

793791
void Module::LookupInfo::Prune(SymbolContextList &sc_list,
@@ -831,7 +829,7 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
831829
CPlusPlusLanguage::MethodName cpp_method(full_name);
832830
if (cpp_method.IsValid()) {
833831
if (cpp_method.GetContext().empty()) {
834-
if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0) {
832+
if (cpp_method.GetBasename().compare(m_name) != 0) {
835833
sc_list.RemoveContextAtIndex(i);
836834
continue;
837835
}
@@ -1054,8 +1052,8 @@ void Module::FindTypes(
10541052
FindTypes_Impl(name, CompilerDeclContext(), UINT_MAX,
10551053
searched_symbol_files, typesmap);
10561054
if (exact_match) {
1057-
typesmap.RemoveMismatchedTypes(type_scope, name.GetStringRef(),
1058-
type_class, exact_match);
1055+
typesmap.RemoveMismatchedTypes(type_scope, name, type_class,
1056+
exact_match);
10591057
}
10601058
}
10611059
}
@@ -1160,7 +1158,7 @@ void Module::ReportWarningOptimization(
11601158
return;
11611159

11621160
StreamString ss;
1163-
ss << file_name.GetStringRef()
1161+
ss << file_name
11641162
<< " was compiled with optimization - stepping may behave "
11651163
"oddly; variables may not be available.";
11661164
Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
@@ -1872,7 +1870,7 @@ uint32_t Module::Hash() {
18721870
llvm::raw_string_ostream id_strm(identifier);
18731871
id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
18741872
if (m_object_name)
1875-
id_strm << '(' << m_object_name.GetStringRef() << ')';
1873+
id_strm << '(' << m_object_name << ')';
18761874
if (m_object_offset > 0)
18771875
id_strm << m_object_offset;
18781876
const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
@@ -1886,7 +1884,7 @@ std::string Module::GetCacheKey() {
18861884
llvm::raw_string_ostream strm(key);
18871885
strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
18881886
if (m_object_name)
1889-
strm << '(' << m_object_name.GetStringRef() << ')';
1887+
strm << '(' << m_object_name << ')';
18901888
strm << '-' << llvm::format_hex(Hash(), 10);
18911889
return strm.str();
18921890
}

0 commit comments

Comments
 (0)