This revision was automatically updated to reflect the committed changes.
Closed by commit rG8e0001eb95ce: [lldb][NFCI] Refactor 
Language::GetFormatterPrefixSuffix (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151603/new/

https://reviews.llvm.org/D151603

Files:
  lldb/include/lldb/Target/Language.h
  lldb/source/Plugins/Language/ObjC/CF.cpp
  lldb/source/Plugins/Language/ObjC/Cocoa.cpp
  lldb/source/Plugins/Language/ObjC/NSArray.cpp
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  lldb/source/Plugins/Language/ObjC/NSString.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Target/Language.cpp

Index: lldb/source/Target/Language.cpp
===================================================================
--- lldb/source/Target/Language.cpp
+++ lldb/source/Target/Language.cpp
@@ -452,11 +452,9 @@
   return result;
 }
 
-bool Language::GetFormatterPrefixSuffix(ValueObject &valobj,
-                                        ConstString type_hint,
-                                        std::string &prefix,
-                                        std::string &suffix) {
-  return false;
+std::pair<llvm::StringRef, llvm::StringRef>
+Language::GetFormatterPrefixSuffix(llvm::StringRef type_hint) {
+  return std::pair<llvm::StringRef, llvm::StringRef>();
 }
 
 bool Language::DemangledNameContainsPath(llvm::StringRef path, 
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
===================================================================
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -150,9 +150,8 @@
 
   std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
 
-  bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint,
-                                std::string &prefix,
-                                std::string &suffix) override;
+  std::pair<llvm::StringRef, llvm::StringRef>
+  GetFormatterPrefixSuffix(llvm::StringRef type_hint) override;
 
   bool IsNilReference(ValueObject &valobj) override;
 
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -998,78 +998,27 @@
                                         ObjCDebugInfoScavenger>());
 }
 
-bool ObjCLanguage::GetFormatterPrefixSuffix(ValueObject &valobj,
-                                            ConstString type_hint,
-                                            std::string &prefix,
-                                            std::string &suffix) {
-  static ConstString g_CFBag("CFBag");
-  static ConstString g_CFBinaryHeap("CFBinaryHeap");
-
-  static ConstString g_NSNumberChar("NSNumber:char");
-  static ConstString g_NSNumberShort("NSNumber:short");
-  static ConstString g_NSNumberInt("NSNumber:int");
-  static ConstString g_NSNumberLong("NSNumber:long");
-  static ConstString g_NSNumberInt128("NSNumber:int128_t");
-  static ConstString g_NSNumberFloat("NSNumber:float");
-  static ConstString g_NSNumberDouble("NSNumber:double");
-
-  static ConstString g_NSData("NSData");
-  static ConstString g_NSArray("NSArray");
-  static ConstString g_NSString("NSString");
-  static ConstString g_NSStringStar("NSString*");
-
-  if (type_hint.IsEmpty())
-    return false;
-
-  prefix.clear();
-  suffix.clear();
-
-  if (type_hint == g_CFBag || type_hint == g_CFBinaryHeap) {
-    prefix = "@";
-    return true;
-  }
-
-  if (type_hint == g_NSNumberChar) {
-    prefix = "(char)";
-    return true;
-  }
-  if (type_hint == g_NSNumberShort) {
-    prefix = "(short)";
-    return true;
-  }
-  if (type_hint == g_NSNumberInt) {
-    prefix = "(int)";
-    return true;
-  }
-  if (type_hint == g_NSNumberLong) {
-    prefix = "(long)";
-    return true;
-  }
-  if (type_hint == g_NSNumberInt128) {
-    prefix = "(int128_t)";
-    return true;
-  }
-  if (type_hint == g_NSNumberFloat) {
-    prefix = "(float)";
-    return true;
-  }
-  if (type_hint == g_NSNumberDouble) {
-    prefix = "(double)";
-    return true;
-  }
-
-  if (type_hint == g_NSData || type_hint == g_NSArray) {
-    prefix = "@\"";
-    suffix = "\"";
-    return true;
-  }
-
-  if (type_hint == g_NSString || type_hint == g_NSStringStar) {
-    prefix = "@";
-    return true;
-  }
-
-  return false;
+std::pair<llvm::StringRef, llvm::StringRef>
+ObjCLanguage::GetFormatterPrefixSuffix(llvm::StringRef type_hint) {
+  static constexpr llvm::StringRef empty;
+  static const llvm::StringMap<
+      std::pair<const llvm::StringRef, const llvm::StringRef>>
+      g_affix_map = {
+          {"CFBag", {"@", empty}},
+          {"CFBinaryHeap", {"@", empty}},
+          {"NSString", {"@", empty}},
+          {"NSString*", {"@", empty}},
+          {"NSNumber:char", {"(char)", empty}},
+          {"NSNumber:short", {"(short)", empty}},
+          {"NSNumber:int", {"(int)", empty}},
+          {"NSNumber:long", {"(long)", empty}},
+          {"NSNumber:int128_t", {"(int128_t)", empty}},
+          {"NSNumber:float", {"(float)", empty}},
+          {"NSNumber:double", {"(double)", empty}},
+          {"NSData", {"@\"", "\""}},
+          {"NSArray", {"@\"", "\""}},
+      };
+  return g_affix_map.lookup(type_hint);
 }
 
 bool ObjCLanguage::IsNilReference(ValueObject &valobj) {
Index: lldb/source/Plugins/Language/ObjC/NSString.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/NSString.cpp
+++ lldb/source/Plugins/Language/ObjC/NSString.cpp
@@ -33,7 +33,7 @@
 bool lldb_private::formatters::NSStringSummaryProvider(
     ValueObject &valobj, Stream &stream,
     const TypeSummaryOptions &summary_options) {
-  static ConstString g_TypeHint("NSString");
+  static constexpr llvm::StringLiteral g_TypeHint("NSString");
 
   ProcessSP process_sp = valobj.GetProcessSP();
   if (!process_sp)
@@ -126,19 +126,13 @@
     return true;
   }
 
-  std::string prefix, suffix;
-  if (Language *language =
-          Language::FindPlugin(summary_options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(summary_options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
   StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
-  options.SetPrefixToken(prefix);
-  options.SetSuffixToken(suffix);
+  options.SetPrefixToken(prefix.str());
+  options.SetSuffixToken(suffix.str());
 
   if (is_mutable) {
     uint64_t location = 2 * ptr_size + valobj_addr;
@@ -318,7 +312,7 @@
 bool lldb_private::formatters::NSTaggedString_SummaryProvider(
     ValueObject &valobj, ObjCLanguageRuntime::ClassDescriptorSP descriptor,
     Stream &stream, const TypeSummaryOptions &summary_options) {
-  static ConstString g_TypeHint("NSString");
+  static constexpr llvm::StringLiteral g_TypeHint("NSString");
 
   if (!descriptor)
     return false;
@@ -336,23 +330,17 @@
   if (len_bits > g_fiveBitMaxLen)
     return false;
 
-  std::string prefix, suffix;
-  if (Language *language =
-          Language::FindPlugin(summary_options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(summary_options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
   // this is a fairly ugly trick - pretend that the numeric value is actually a
   // char* this works under a few assumptions: little endian architecture
   // sizeof(uint64_t) > g_MaxNonBitmaskedLen
   if (len_bits <= g_MaxNonBitmaskedLen) {
-    stream.Printf("%s", prefix.c_str());
+    stream << prefix;
     stream.Printf("\"%s\"", (const char *)&data_bits);
-    stream.Printf("%s", suffix.c_str());
+    stream << suffix;
     return true;
   }
 
@@ -375,8 +363,8 @@
     bytes.insert(bytes.begin(), sixBitToCharLookup[packed]);
   }
 
-  stream.Printf("%s", prefix.c_str());
+  stream << prefix;
   stream.Printf("\"%s\"", &bytes[0]);
-  stream.Printf("%s", suffix.c_str());
+  stream << suffix;
   return true;
 }
Index: lldb/source/Plugins/Language/ObjC/NSSet.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/NSSet.cpp
+++ lldb/source/Plugins/Language/ObjC/NSSet.cpp
@@ -249,7 +249,7 @@
 template <bool cf_style>
 bool lldb_private::formatters::NSSetSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  static ConstString g_TypeHint("NSSet");
+  static constexpr llvm::StringLiteral g_TypeHint("NSSet");
 
   ProcessSP process_sp = valobj.GetProcessSP();
   if (!process_sp)
@@ -322,17 +322,13 @@
       return false;
   }
 
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%" PRIu64 " %s%s%s", prefix.c_str(), value, "element",
-                value == 1 ? "" : "s", suffix.c_str());
+  stream << prefix;
+  stream.Printf("%" PRIu64 " %s%s", value, "element", value == 1 ? "" : "s");
+  stream << suffix;
   return true;
 }
 
Index: lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
+++ lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
@@ -409,7 +409,7 @@
 template <bool name_entries>
 bool lldb_private::formatters::NSDictionarySummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  static ConstString g_TypeHint("NSDictionary");
+  static constexpr llvm::StringLiteral g_TypeHint("NSDictionary");
   ProcessSP process_sp = valobj.GetProcessSP();
   if (!process_sp)
     return false;
@@ -501,17 +501,14 @@
     return false;
   }
 
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%" PRIu64 " %s%s%s", prefix.c_str(), value, "key/value pair",
-                value == 1 ? "" : "s", suffix.c_str());
+  stream << prefix;
+  stream.Printf("%" PRIu64 " %s%s", value, "key/value pair",
+                value == 1 ? "" : "s");
+  stream << suffix;
   return true;
 }
 
Index: lldb/source/Plugins/Language/ObjC/NSArray.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/NSArray.cpp
+++ lldb/source/Plugins/Language/ObjC/NSArray.cpp
@@ -334,7 +334,7 @@
 
 bool lldb_private::formatters::NSArraySummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  static ConstString g_TypeHint("NSArray");
+  static constexpr llvm::StringLiteral g_TypeHint("NSArray");
 
   ProcessSP process_sp = valobj.GetProcessSP();
   if (!process_sp)
@@ -445,17 +445,13 @@
       return false;
   }
 
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%" PRIu64 " %s%s%s", prefix.c_str(), value, "element",
-                value == 1 ? "" : "s", suffix.c_str());
+  stream << prefix;
+  stream.Printf("%" PRIu64 " %s%s", value, "element", value == 1 ? "" : "s");
+  stream << suffix;
   return true;
 }
 
Index: lldb/source/Plugins/Language/ObjC/Cocoa.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -305,120 +305,97 @@
 
 static void NSNumber_FormatChar(ValueObject &valobj, Stream &stream, char value,
                                 lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:char");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:char");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%hhd%s", prefix.c_str(), value, suffix.c_str());
+  stream << prefix;
+  stream.Printf("%hhd", value);
+  stream << suffix;
 }
 
 static void NSNumber_FormatShort(ValueObject &valobj, Stream &stream,
                                  short value, lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:short");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:short");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%hd%s", prefix.c_str(), value, suffix.c_str());
+  stream << prefix;
+  stream.Printf("%hd", value);
+  stream << suffix;
 }
 
 static void NSNumber_FormatInt(ValueObject &valobj, Stream &stream, int value,
                                lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:int");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:int");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%d%s", prefix.c_str(), value, suffix.c_str());
+  stream << prefix;
+  stream.Printf("%d", value);
+  stream << suffix;
 }
 
 static void NSNumber_FormatLong(ValueObject &valobj, Stream &stream,
                                 int64_t value, lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:long");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:long");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%" PRId64 "%s", prefix.c_str(), value, suffix.c_str());
+  stream << prefix;
+  stream.Printf("%" PRId64 "", value);
+  stream << suffix;
 }
 
 static void NSNumber_FormatInt128(ValueObject &valobj, Stream &stream,
                                   const llvm::APInt &value,
                                   lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:int128_t");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:int128_t");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.PutCString(prefix.c_str());
+  stream << prefix;
   const int radix = 10;
   const bool isSigned = true;
   std::string str = llvm::toString(value, radix, isSigned);
   stream.PutCString(str.c_str());
-  stream.PutCString(suffix.c_str());
+  stream << suffix;
 }
 
 static void NSNumber_FormatFloat(ValueObject &valobj, Stream &stream,
                                  float value, lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:float");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:float");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%f%s", prefix.c_str(), value, suffix.c_str());
+  stream << prefix;
+  stream.Printf("%f", value);
+  stream << suffix;
 }
 
 static void NSNumber_FormatDouble(ValueObject &valobj, Stream &stream,
                                   double value, lldb::LanguageType lang) {
-  static ConstString g_TypeHint("NSNumber:double");
-
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(lang)) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral g_TypeHint("NSNumber:double");
+
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(lang))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s%g%s", prefix.c_str(), value, suffix.c_str());
+  stream << prefix;
+  stream.Printf("%g", value);
+  stream << suffix;
 }
 
 bool lldb_private::formatters::NSNumberSummaryProvider(
@@ -813,29 +790,27 @@
   if (!NSStringSummaryProvider(*text, summary, options) || summary.Empty())
     return false;
 
-  const char quote_char = '"';
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(*text, ConstString("NSString"),
-                                            prefix, suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  static constexpr llvm::StringLiteral quote_char("\"");
+  static constexpr llvm::StringLiteral g_TypeHint("NSString");
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
+
   // @"A" -> @"A
   llvm::StringRef summary_str = summary.GetString();
-  bool back_consumed = summary_str.consume_back(quote_char + suffix);
+  bool back_consumed =
+      summary_str.consume_back(suffix) && summary_str.consume_back(quote_char);
   assert(back_consumed);
   UNUSED_IF_ASSERT_DISABLED(back_consumed);
   // @"B" -> B"
   llvm::StringRef base_summary_str = base_summary.GetString();
-  bool front_consumed = base_summary_str.consume_front(prefix + quote_char);
+  bool front_consumed = base_summary_str.consume_front(prefix) &&
+                        base_summary_str.consume_front(quote_char);
   assert(front_consumed);
   UNUSED_IF_ASSERT_DISABLED(front_consumed);
   // @"A -- B"
   if (!summary_str.empty() && !base_summary_str.empty()) {
-    stream.Printf("%s -- %s", summary_str.str().c_str(),
-                  base_summary_str.str().c_str());
+    stream << summary_str << " -- " << base_summary_str;
     return true;
   }
 
Index: lldb/source/Plugins/Language/ObjC/CF.cpp
===================================================================
--- lldb/source/Plugins/Language/ObjC/CF.cpp
+++ lldb/source/Plugins/Language/ObjC/CF.cpp
@@ -44,7 +44,7 @@
 
 bool lldb_private::formatters::CFBagSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  static ConstString g_TypeHint("CFBag");
+  static constexpr llvm::StringLiteral g_TypeHint("CFBag");
 
   ProcessSP process_sp = valobj.GetProcessSP();
   if (!process_sp)
@@ -92,17 +92,13 @@
   } else
     return false;
 
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s\"%u value%s\"%s", prefix.c_str(), count,
-                (count == 1 ? "" : "s"), suffix.c_str());
+  stream << prefix;
+  stream.Printf("\"%u value%s\"", count, (count == 1 ? "" : "s"));
+  stream << suffix;
   return true;
 }
 
@@ -226,7 +222,7 @@
 
 bool lldb_private::formatters::CFBinaryHeapSummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  static ConstString g_TypeHint("CFBinaryHeap");
+  static constexpr llvm::StringLiteral g_TypeHint("CFBinaryHeap");
 
   ProcessSP process_sp = valobj.GetProcessSP();
   if (!process_sp)
@@ -279,16 +275,12 @@
   } else
     return false;
 
-  std::string prefix, suffix;
-  if (Language *language = Language::FindPlugin(options.GetLanguage())) {
-    if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
-                                            suffix)) {
-      prefix.clear();
-      suffix.clear();
-    }
-  }
+  llvm::StringRef prefix, suffix;
+  if (Language *language = Language::FindPlugin(options.GetLanguage()))
+    std::tie(prefix, suffix) = language->GetFormatterPrefixSuffix(g_TypeHint);
 
-  stream.Printf("%s\"%u item%s\"%s", prefix.c_str(), count,
-                (count == 1 ? "" : "s"), suffix.c_str());
+  stream << prefix;
+  stream.Printf("\"%u item%s\"", count, (count == 1 ? "" : "s"));
+  stream << suffix;
   return true;
 }
Index: lldb/include/lldb/Target/Language.h
===================================================================
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -208,14 +208,21 @@
   /// that the name actually belongs to this language.
   virtual bool SymbolNameFitsToLanguage(Mangled name) const { return false; }
 
-  // if an individual data formatter can apply to several types and cross a
-  // language boundary it makes sense for individual languages to want to
-  // customize the printing of values of that type by appending proper
-  // prefix/suffix information in language-specific ways
-  virtual bool GetFormatterPrefixSuffix(ValueObject &valobj,
-                                        ConstString type_hint,
-                                        std::string &prefix,
-                                        std::string &suffix);
+  /// An individual data formatter may apply to several types and cross language
+  /// boundaries. Each of those languages may want to customize the display of
+  /// values of said types by appending proper prefix/suffix information in
+  /// language-specific ways. This function returns that prefix and suffix.
+  ///
+  /// \param[in] type_hint
+  ///   A StringRef used to determine what the prefix and suffix should be. It
+  ///   is called a hint because some types may have multiple variants for which
+  ///   the prefix and/or suffix may vary.
+  ///
+  /// \return
+  ///   A std::pair<StringRef, StringRef>, the first being the prefix and the
+  ///   second being the suffix. They may be empty.
+  virtual std::pair<llvm::StringRef, llvm::StringRef>
+  GetFormatterPrefixSuffix(llvm::StringRef type_hint);
 
   // When looking up functions, we take a user provided string which may be a
   // partial match to the full demangled name and compare it to the actual
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits]... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Felipe de Azevedo Piovezan via Phabricator via lldb-commits
    • [Lldb-com... Michael Buch via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits
    • [Lldb-com... Jonas Devlieghere via Phabricator via lldb-commits
    • [Lldb-com... Alex Langford via Phabricator via lldb-commits

Reply via email to