From 3e3701f8a0bfafdbca91d4a9cae56c69242c754c Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Wed, 15 Apr 2020 07:34:14 +0200 Subject: [PATCH] [lldb][NFC] Remove FormatterChoiceCriterion Summary: The formatters code has a lot of 'reason' or 'why' values that we keep or-ing FormatterChoiceCriterion enum values into. These values are only read by a single log statement and don't have any functional purpose. It also seems the implementation is not finished (for example, display names and type names don't have any dedicated enum values). Also everything is of course not tested or documented. Let's just remove all of this. Reviewers: labath, JDevlieghere, jingham, davide, vsk Reviewed By: labath, vsk Subscribers: JDevlieghere Differential Revision: https://reviews.llvm.org/D77968 --- lldb/include/lldb/DataFormatters/FormatClasses.h | 7 ++--- lldb/include/lldb/DataFormatters/FormatManager.h | 3 +- .../lldb/DataFormatters/FormattersContainer.h | 12 ++------ lldb/include/lldb/DataFormatters/TypeCategory.h | 6 ++-- lldb/include/lldb/lldb-private-enumerations.h | 12 -------- lldb/source/DataFormatters/FormatManager.cpp | 21 ++++--------- lldb/source/DataFormatters/TypeCategory.cpp | 34 +++++++--------------- lldb/source/DataFormatters/TypeCategoryMap.cpp | 8 ++--- 8 files changed, 28 insertions(+), 75 deletions(-) diff --git a/lldb/include/lldb/DataFormatters/FormatClasses.h b/lldb/include/lldb/DataFormatters/FormatClasses.h index 1b9d27a..fe6e4c8 100644 --- a/lldb/include/lldb/DataFormatters/FormatClasses.h +++ b/lldb/include/lldb/DataFormatters/FormatClasses.h @@ -43,17 +43,15 @@ public: class FormattersMatchCandidate { public: - FormattersMatchCandidate(ConstString name, uint32_t reason, bool strip_ptr, + FormattersMatchCandidate(ConstString name, bool strip_ptr, bool strip_ref, bool strip_tydef) - : m_type_name(name), m_reason(reason), m_stripped_pointer(strip_ptr), + : m_type_name(name), m_stripped_pointer(strip_ptr), m_stripped_reference(strip_ref), m_stripped_typedef(strip_tydef) {} ~FormattersMatchCandidate() = default; ConstString GetTypeName() const { return m_type_name; } - uint32_t GetReason() const { return m_reason; } - bool DidStripPointer() const { return m_stripped_pointer; } bool DidStripReference() const { return m_stripped_reference; } @@ -75,7 +73,6 @@ public: private: ConstString m_type_name; - uint32_t m_reason; bool m_stripped_pointer; bool m_stripped_reference; bool m_stripped_typedef; diff --git a/lldb/include/lldb/DataFormatters/FormatManager.h b/lldb/include/lldb/DataFormatters/FormatManager.h index 8599699..56a0303 100644 --- a/lldb/include/lldb/DataFormatters/FormatManager.h +++ b/lldb/include/lldb/DataFormatters/FormatManager.h @@ -170,7 +170,6 @@ public: GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) { FormattersMatchVector matches; GetPossibleMatches(valobj, valobj.GetCompilerType(), - lldb_private::eFormatterChoiceCriterionDirectChoice, use_dynamic, matches, false, false, false, true); return matches; } @@ -184,7 +183,7 @@ public: private: static void GetPossibleMatches(ValueObject &valobj, - CompilerType compiler_type, uint32_t reason, + CompilerType compiler_type, lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries, bool did_strip_ptr, bool did_strip_ref, diff --git a/lldb/include/lldb/DataFormatters/FormattersContainer.h b/lldb/include/lldb/DataFormatters/FormattersContainer.h index 253f20f..708aa95 100644 --- a/lldb/include/lldb/DataFormatters/FormattersContainer.h +++ b/lldb/include/lldb/DataFormatters/FormattersContainer.h @@ -181,16 +181,13 @@ public: } bool Get(ValueObject &valobj, MapValueType &entry, - lldb::DynamicValueType use_dynamic, uint32_t *why = nullptr) { - uint32_t value = lldb_private::eFormatterChoiceCriterionDirectChoice; + lldb::DynamicValueType use_dynamic) { CompilerType ast_type(valobj.GetCompilerType()); - bool ret = Get(valobj, ast_type, entry, use_dynamic, value); + bool ret = Get(valobj, ast_type, entry, use_dynamic); if (ret) entry = MapValueType(entry); else entry = MapValueType(); - if (why) - *why = value; return ret; } @@ -308,16 +305,13 @@ protected: return false; } - bool Get(const FormattersMatchVector &candidates, MapValueType &entry, - uint32_t *reason) { + bool Get(const FormattersMatchVector &candidates, MapValueType &entry) { for (const FormattersMatchCandidate &candidate : candidates) { if (Get(candidate.GetTypeName(), entry)) { if (candidate.IsMatch(entry) == false) { entry.reset(); continue; } else { - if (reason) - *reason = candidate.GetReason(); return true; } } diff --git a/lldb/include/lldb/DataFormatters/TypeCategory.h b/lldb/include/lldb/DataFormatters/TypeCategory.h index 8a098db..820872a 100644 --- a/lldb/include/lldb/DataFormatters/TypeCategory.h +++ b/lldb/include/lldb/DataFormatters/TypeCategory.h @@ -285,13 +285,13 @@ public: } bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::TypeFormatImplSP &entry, uint32_t *reason = nullptr); + lldb::TypeFormatImplSP &entry); bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::TypeSummaryImplSP &entry, uint32_t *reason = nullptr); + lldb::TypeSummaryImplSP &entry); bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::SyntheticChildrenSP &entry, uint32_t *reason = nullptr); + lldb::SyntheticChildrenSP &entry); void Clear(FormatCategoryItems items = ALL_ITEM_TYPES); diff --git a/lldb/include/lldb/lldb-private-enumerations.h b/lldb/include/lldb/lldb-private-enumerations.h index ccc36db..7009d1b 100644 --- a/lldb/include/lldb/lldb-private-enumerations.h +++ b/lldb/include/lldb/lldb-private-enumerations.h @@ -148,18 +148,6 @@ enum ExecutionPolicy { eExecutionPolicyTopLevel // used for top-level code }; -// Ways that the FormatManager picks a particular format for a type -enum FormatterChoiceCriterion { - eFormatterChoiceCriterionDirectChoice = 0x00000000, - eFormatterChoiceCriterionStrippedPointerReference = 0x00000001, - eFormatterChoiceCriterionNavigatedTypedefs = 0x00000002, - eFormatterChoiceCriterionRegularExpressionSummary = 0x00000004, - eFormatterChoiceCriterionRegularExpressionFilter = 0x00000004, - eFormatterChoiceCriterionLanguagePlugin = 0x00000008, - eFormatterChoiceCriterionStrippedBitField = 0x00000010, - eFormatterChoiceCriterionWentToStaticValue = 0x00000020 -}; - // Synchronicity behavior of scripted commands enum ScriptedCommandSynchronicity { eScriptedCommandSynchronicitySynchronous, diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index cce8934..ad02d37 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -174,7 +174,7 @@ void FormatManager::DisableAllCategories() { } void FormatManager::GetPossibleMatches( - ValueObject &valobj, CompilerType compiler_type, uint32_t reason, + ValueObject &valobj, CompilerType compiler_type, lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries, bool did_strip_ptr, bool did_strip_ref, bool did_strip_typedef, bool root_level) { @@ -185,17 +185,16 @@ void FormatManager::GetPossibleMatches( sstring.Printf("%s:%d", type_name.AsCString(), valobj.GetBitfieldBitSize()); ConstString bitfieldname(sstring.GetString()); entries.push_back( - {bitfieldname, 0, did_strip_ptr, did_strip_ref, did_strip_typedef}); - reason |= lldb_private::eFormatterChoiceCriterionStrippedBitField; + {bitfieldname, did_strip_ptr, did_strip_ref, did_strip_typedef}); } if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) { entries.push_back( - {type_name, reason, did_strip_ptr, did_strip_ref, did_strip_typedef}); + {type_name, did_strip_ptr, did_strip_ref, did_strip_typedef}); ConstString display_type_name(compiler_type.GetTypeName()); if (display_type_name != type_name) - entries.push_back({display_type_name, reason, did_strip_ptr, + entries.push_back({display_type_name, did_strip_ptr, did_strip_ref, did_strip_typedef}); } @@ -204,8 +203,6 @@ void FormatManager::GetPossibleMatches( CompilerType non_ref_type = compiler_type.GetNonReferenceType(); GetPossibleMatches( valobj, non_ref_type, - reason | - lldb_private::eFormatterChoiceCriterionStrippedPointerReference, use_dynamic, entries, did_strip_ptr, true, did_strip_typedef); if (non_ref_type.IsTypedefType()) { CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType(); @@ -214,7 +211,6 @@ void FormatManager::GetPossibleMatches( : deffed_referenced_type.GetLValueReferenceType(); GetPossibleMatches( valobj, deffed_referenced_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, true); // this is not exactly the usual meaning of stripping typedefs } @@ -224,8 +220,6 @@ void FormatManager::GetPossibleMatches( CompilerType non_ptr_type = compiler_type.GetPointeeType(); GetPossibleMatches( valobj, non_ptr_type, - reason | - lldb_private::eFormatterChoiceCriterionStrippedPointerReference, use_dynamic, entries, true, did_strip_ref, did_strip_typedef); if (non_ptr_type.IsTypedefType()) { CompilerType deffed_pointed_type = @@ -233,7 +227,6 @@ void FormatManager::GetPossibleMatches( const bool stripped_typedef = true; GetPossibleMatches( valobj, deffed_pointed_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, stripped_typedef); // this is not exactly the usual meaning of // stripping typedefs @@ -253,7 +246,6 @@ void FormatManager::GetPossibleMatches( const bool stripped_typedef = true; GetPossibleMatches( valobj, deffed_array_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, stripped_typedef); // this is not exactly the usual meaning of // stripping typedefs @@ -267,7 +259,6 @@ void FormatManager::GetPossibleMatches( language->GetPossibleFormattersMatches(valobj, use_dynamic)) { entries.push_back( {candidate, - reason | lldb_private::eFormatterChoiceCriterionLanguagePlugin, did_strip_ptr, did_strip_ref, did_strip_typedef}); } } @@ -278,7 +269,6 @@ void FormatManager::GetPossibleMatches( CompilerType deffed_type = compiler_type.GetTypedefedType(); GetPossibleMatches( valobj, deffed_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, true); } @@ -293,7 +283,7 @@ void FormatManager::GetPossibleMatches( break; if (unqual_compiler_ast_type.GetOpaqueQualType() != compiler_type.GetOpaqueQualType()) - GetPossibleMatches(valobj, unqual_compiler_ast_type, reason, + GetPossibleMatches(valobj, unqual_compiler_ast_type, use_dynamic, entries, did_strip_ptr, did_strip_ref, did_strip_typedef); } while (false); @@ -304,7 +294,6 @@ void FormatManager::GetPossibleMatches( if (static_value_sp) GetPossibleMatches( *static_value_sp.get(), static_value_sp->GetCompilerType(), - reason | lldb_private::eFormatterChoiceCriterionWentToStaticValue, use_dynamic, entries, did_strip_ptr, did_strip_ref, did_strip_typedef, true); } diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp index 7bfbb30a..0cfa8d7 100644 --- a/lldb/source/DataFormatters/TypeCategory.cpp +++ b/lldb/source/DataFormatters/TypeCategory.cpp @@ -86,51 +86,43 @@ void TypeCategoryImpl::AddLanguage(lldb::LanguageType lang) { bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::TypeFormatImplSP &entry, uint32_t *reason) { + lldb::TypeFormatImplSP &entry) { if (!IsEnabled() || !IsApplicable(lang)) return false; - if (GetTypeFormatsContainer()->Get(candidates, entry, reason)) + if (GetTypeFormatsContainer()->Get(candidates, entry)) return true; - bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry); return regex; } bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::TypeSummaryImplSP &entry, uint32_t *reason) { + lldb::TypeSummaryImplSP &entry) { if (!IsEnabled() || !IsApplicable(lang)) return false; - if (GetTypeSummariesContainer()->Get(candidates, entry, reason)) + if (GetTypeSummariesContainer()->Get(candidates, entry)) return true; - bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry); return regex; } bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::SyntheticChildrenSP &entry, uint32_t *reason) { + lldb::SyntheticChildrenSP &entry) { if (!IsEnabled() || !IsApplicable(lang)) return false; TypeFilterImpl::SharedPointer filter_sp; - uint32_t reason_filter = 0; bool regex_filter = false; // first find both Filter and Synth, and then check which is most recent - if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter)) - regex_filter = GetRegexTypeFiltersContainer()->Get(candidates, filter_sp, - &reason_filter); + if (!GetTypeFiltersContainer()->Get(candidates, filter_sp)) + regex_filter = GetRegexTypeFiltersContainer()->Get(candidates, filter_sp); bool regex_synth = false; - uint32_t reason_synth = 0; bool pick_synth = false; ScriptedSyntheticChildren::SharedPointer synth; - if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth)) - regex_synth = GetRegexTypeSyntheticsContainer()->Get(candidates, synth, - &reason_synth); + if (!GetTypeSyntheticsContainer()->Get(candidates, synth)) + regex_synth = GetRegexTypeSyntheticsContainer()->Get(candidates, synth); if (!filter_sp.get() && !synth.get()) return false; else if (!filter_sp.get() && synth.get()) @@ -144,13 +136,9 @@ bool TypeCategoryImpl::Get(lldb::LanguageType lang, pick_synth = filter_sp->GetRevision() <= synth->GetRevision(); } if (pick_synth) { - if (regex_synth && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; entry = synth; return true; } else { - if (regex_filter && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; entry = filter_sp; return true; } diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index 36ec0dd..a011c54 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -172,7 +172,6 @@ template void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { std::lock_guard guard(m_map_mutex); - uint32_t reason_why; ActiveCategoriesIterator begin, end = m_active_categories.end(); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); @@ -181,13 +180,12 @@ void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { for (auto match : match_data.GetMatchesVector()) { LLDB_LOGF( log, - "[%s] candidate match = %s %s %s %s reason = %" PRIu32, + "[%s] candidate match = %s %s %s %s", __FUNCTION__, match.GetTypeName().GetCString(), match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); + match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef"); } } @@ -198,7 +196,7 @@ void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { category_sp->GetName()); if (!category_sp->Get( match_data.GetValueObject().GetObjectRuntimeLanguage(), - match_data.GetMatchesVector(), current_format, &reason_why)) + match_data.GetMatchesVector(), current_format)) continue; retval = std::move(current_format); -- 2.7.4