[Lldb-commits] [PATCH] D69641: [Symbol] Change ClangASTContext::GetCXXClassName return type

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 30 14:02:59 PDT 2019


xiaobai created this revision.
xiaobai added reviewers: JDevlieghere, labath, compnerd.
Herald added a project: LLDB.

Instead of filling out a std::string and returning a bool to indicate
success, returning a std::string directly and testing to see if it's
empty seems like a cleaner solution overall.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69641

Files:
  lldb/include/lldb/Symbol/ClangASTContext.h
  lldb/source/Core/ValueObject.cpp
  lldb/source/Symbol/ClangASTContext.cpp


Index: lldb/source/Symbol/ClangASTContext.cpp
===================================================================
--- lldb/source/Symbol/ClangASTContext.cpp
+++ lldb/source/Symbol/ClangASTContext.cpp
@@ -3850,20 +3850,19 @@
   return ClangASTContextSupportsLanguage(language);
 }
 
-bool ClangASTContext::GetCXXClassName(const CompilerType &type,
-                                      std::string &class_name) {
-  if (type) {
-    clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
-    if (!qual_type.isNull()) {
-      clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
-      if (cxx_record_decl) {
-        class_name.assign(cxx_record_decl->getIdentifier()->getNameStart());
-        return true;
-      }
-    }
-  }
-  class_name.clear();
-  return false;
+std::string ClangASTContext::GetCXXClassName(const CompilerType &type) {
+  if (!type)
+    return std::string();
+
+  clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
+  if (qual_type.isNull())
+    return std::string();
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+  if (!cxx_record_decl)
+    return std::string();
+
+  return cxx_record_decl->getIdentifier()->getNameStart();
 }
 
 bool ClangASTContext::IsCXXClassType(const CompilerType &type) {
Index: lldb/source/Core/ValueObject.cpp
===================================================================
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -2023,15 +2023,14 @@
     bool parent_had_base_class =
         GetParent() && GetParent()->GetBaseClassPath(s);
     CompilerType compiler_type = GetCompilerType();
-    std::string cxx_class_name;
-    bool this_had_base_class =
-        ClangASTContext::GetCXXClassName(compiler_type, cxx_class_name);
-    if (this_had_base_class) {
+    std::string cxx_class_name =
+        ClangASTContext::GetCXXClassName(compiler_type);
+    if (!cxx_class_name.empty()) {
       if (parent_had_base_class)
         s.PutCString("::");
       s.PutCString(cxx_class_name);
     }
-    return parent_had_base_class || this_had_base_class;
+    return parent_had_base_class || !cxx_class_name.empty();
   }
   return false;
 }
Index: lldb/include/lldb/Symbol/ClangASTContext.h
===================================================================
--- lldb/include/lldb/Symbol/ClangASTContext.h
+++ lldb/include/lldb/Symbol/ClangASTContext.h
@@ -601,8 +601,7 @@
 
   bool SupportsLanguage(lldb::LanguageType language) override;
 
-  static bool GetCXXClassName(const CompilerType &type,
-                              std::string &class_name);
+  static std::string GetCXXClassName(const CompilerType &type);
 
   // Type Completion
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69641.227175.patch
Type: text/x-patch
Size: 2712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191030/dff97d16/attachment.bin>


More information about the lldb-commits mailing list