Author: Alex Langford Date: 2019-10-31T11:57:37-07:00 New Revision: db542455dc0f5873851e220bf72a8394767c61fb
URL: https://github.com/llvm/llvm-project/commit/db542455dc0f5873851e220bf72a8394767c61fb DIFF: https://github.com/llvm/llvm-project/commit/db542455dc0f5873851e220bf72a8394767c61fb.diff LOG: [Symbol] Change ClangASTContext::GetCXXClassName return type Summary: 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. Differential Revision: https://reviews.llvm.org/D69641 Added: Modified: lldb/include/lldb/Symbol/ClangASTContext.h lldb/source/Core/ValueObject.cpp lldb/source/Symbol/ClangASTContext.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index e59e756276c8..9538deccbe04 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -601,8 +601,7 @@ class ClangASTContext : public TypeSystem { bool SupportsLanguage(lldb::LanguageType language) override; - static bool GetCXXClassName(const CompilerType &type, - std::string &class_name); + static llvm::Optional<std::string> GetCXXClassName(const CompilerType &type); // Type Completion diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index aa03e3b9f499..7b4034c06400 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -2023,15 +2023,14 @@ bool ValueObject::GetBaseClassPath(Stream &s) { 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) { + llvm::Optional<std::string> cxx_class_name = + ClangASTContext::GetCXXClassName(compiler_type); + if (cxx_class_name) { if (parent_had_base_class) s.PutCString("::"); - s.PutCString(cxx_class_name); + s.PutCString(cxx_class_name.getValue()); } - return parent_had_base_class || this_had_base_class; + return parent_had_base_class || cxx_class_name; } return false; } diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 4a44ee0b1c73..61b08ab9f516 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -3850,20 +3850,20 @@ bool ClangASTContext::SupportsLanguage(lldb::LanguageType language) { 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; +Optional<std::string> +ClangASTContext::GetCXXClassName(const CompilerType &type) { + if (!type) + return llvm::None; + + clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); + if (qual_type.isNull()) + return llvm::None; + + clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); + if (!cxx_record_decl) + return llvm::None; + + return std::string(cxx_record_decl->getIdentifier()->getNameStart()); } bool ClangASTContext::IsCXXClassType(const CompilerType &type) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits