nickdesaulniers created this revision.
Herald added subscribers: JDevlieghere, hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

I was doing this API conversion to use std::string_view top-down in
D149104 <https://reviews.llvm.org/D149104>, but this exposed issues in 
individual demanglers that needed to
get fixed first. There's no issue with the conversion for the Rust
demangler, so convert it first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149784

Files:
  lldb/include/lldb/Utility/ConstString.h
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h
  llvm/lib/Demangle/RustDemangle.cpp

Index: llvm/lib/Demangle/RustDemangle.cpp
===================================================================
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -20,11 +20,13 @@
 #include <cstdint>
 #include <cstring>
 #include <limits>
+#include <string_view>
 
 using namespace llvm;
 
 using llvm::itanium_demangle::OutputBuffer;
 using llvm::itanium_demangle::ScopedOverride;
+using llvm::itanium_demangle::starts_with;
 
 namespace {
 
@@ -146,17 +148,13 @@
 
 } // namespace
 
-char *llvm::rustDemangle(const char *MangledName) {
-  if (MangledName == nullptr)
-    return nullptr;
-
+char *llvm::rustDemangle(std::string_view MangledName) {
   // Return early if mangled name doesn't look like a Rust symbol.
-  std::string_view Mangled(MangledName);
-  if (!llvm::itanium_demangle::starts_with(Mangled, "_R"))
+  if (MangledName.empty() || !starts_with(MangledName, "_R"))
     return nullptr;
 
   Demangler D;
-  if (!D.demangle(Mangled)) {
+  if (!D.demangle(MangledName)) {
     std::free(D.Output.getBuffer());
     return nullptr;
   }
@@ -196,7 +194,7 @@
   RecursionLevel = 0;
   BoundLifetimes = 0;
 
-  if (!llvm::itanium_demangle::starts_with(Mangled, "_R")) {
+  if (!starts_with(Mangled, "_R")) {
     Error = true;
     return false;
   }
Index: llvm/include/llvm/Demangle/Demangle.h
===================================================================
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -11,6 +11,7 @@
 
 #include <cstddef>
 #include <string>
+#include <string_view>
 
 namespace llvm {
 /// This is a llvm local version of __cxa_demangle. Other than the name and
@@ -54,7 +55,7 @@
                         MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol.
-char *rustDemangle(const char *MangledName);
+char *rustDemangle(std::string_view MangledName);
 
 // Demangles a D mangled symbol.
 char *dlangDemangle(const char *MangledName);
Index: lldb/source/Core/Mangled.cpp
===================================================================
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -25,6 +25,7 @@
 
 #include <mutex>
 #include <string>
+#include <string_view>
 #include <utility>
 
 #include <cstdlib>
@@ -150,7 +151,7 @@
   return demangled_cstr;
 }
 
-static char *GetRustV0DemangledStr(const char *M) {
+static char *GetRustV0DemangledStr(std::string_view M) {
   char *demangled_cstr = llvm::rustDemangle(M);
 
   if (Log *log = GetLog(LLDBLog::Demangle)) {
@@ -259,7 +260,7 @@
         break;
       }
       case eManglingSchemeRustV0:
-        demangled_name = GetRustV0DemangledStr(mangled_name);
+        demangled_name = GetRustV0DemangledStr(m_mangled.GetStringRef());
         break;
       case eManglingSchemeD:
         demangled_name = GetDLangDemangledStr(mangled_name);
Index: lldb/include/lldb/Utility/ConstString.h
===================================================================
--- lldb/include/lldb/Utility/ConstString.h
+++ lldb/include/lldb/Utility/ConstString.h
@@ -14,6 +14,7 @@
 #include "llvm/Support/FormatVariadic.h"
 
 #include <cstddef>
+#include <string_view>
 
 namespace lldb_private {
 class Stream;
@@ -182,6 +183,8 @@
 
   // Implicitly convert \class ConstString instances to \class StringRef.
   operator llvm::StringRef() const { return GetStringRef(); }
+  // Implicitly convert \class ConstString instances to \calss std::string_view.
+  operator std::string_view() const { return std::string_view(m_string, GetLength()); }
 
   /// Get the string value as a C string.
   ///
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to