xiaobai updated this revision to Diff 227188. xiaobai added a comment. Use llvm::Optional
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D69641/new/ 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,20 @@ 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) { 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) { + 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; } 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 llvm::Optional<std::string> GetCXXClassName(const CompilerType &type); // Type Completion
Index: lldb/source/Symbol/ClangASTContext.cpp =================================================================== --- lldb/source/Symbol/ClangASTContext.cpp +++ lldb/source/Symbol/ClangASTContext.cpp @@ -3850,20 +3850,20 @@ 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) { 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) { + 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; } 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 llvm::Optional<std::string> GetCXXClassName(const CompilerType &type); // Type Completion
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits