diff --git a/lldb/include/lldb/DataFormatters/LanguageCategory.h b/lldb/include/lldb/DataFormatters/LanguageCategory.h index f109d46194ad..c6604ec80fad 100644 --- a/lldb/include/lldb/DataFormatters/LanguageCategory.h +++ b/lldb/include/lldb/DataFormatters/LanguageCategory.h @@ -25,27 +25,11 @@ public: LanguageCategory(lldb::LanguageType lang_type); - bool Get(FormattersMatchData &match_data, lldb::TypeFormatImplSP &format_sp); - - bool Get(FormattersMatchData &match_data, lldb::TypeSummaryImplSP &format_sp); - - bool Get(FormattersMatchData &match_data, - lldb::SyntheticChildrenSP &format_sp); - - bool Get(FormattersMatchData &match_data, - lldb::TypeValidatorImplSP &format_sp); - + template + bool Get(FormattersMatchData &match_data, ImplSP &format_sp); + template bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, - lldb::TypeFormatImplSP &format_sp); - - bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, - lldb::TypeSummaryImplSP &format_sp); - - bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, - lldb::SyntheticChildrenSP &format_sp); - - bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, - lldb::TypeValidatorImplSP &format_sp); + ImplSP &format_sp); lldb::TypeCategoryImplSP GetCategory() const; @@ -65,6 +49,9 @@ private: HardcodedFormatters::HardcodedSyntheticFinder m_hardcoded_synthetics; HardcodedFormatters::HardcodedValidatorFinder m_hardcoded_validators; + template + auto &GetHardcodedFinder(); + lldb_private::FormatCache m_format_cache; bool m_enabled; diff --git a/lldb/source/DataFormatters/LanguageCategory.cpp b/lldb/source/DataFormatters/LanguageCategory.cpp index 86de28060254..78237e18fb20 100644 --- a/lldb/source/DataFormatters/LanguageCategory.cpp +++ b/lldb/source/DataFormatters/LanguageCategory.cpp @@ -34,8 +34,9 @@ LanguageCategory::LanguageCategory(lldb::LanguageType lang_type) Enable(); } +template bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::TypeFormatImplSP &format_sp) { + ImplSP &retval_sp) { if (!m_category_sp) return false; @@ -43,168 +44,90 @@ bool LanguageCategory::Get(FormattersMatchData &match_data, return false; if (match_data.GetTypeForCache()) { - if (m_format_cache.Get(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; + if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) + return (bool)retval_sp; } ValueObject &valobj(match_data.GetValueObject()); bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(), - match_data.GetMatchesVector(), format_sp); + match_data.GetMatchesVector(), retval_sp); if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); + (!retval_sp || !retval_sp->NonCacheable())) { + m_format_cache.Set(match_data.GetTypeForCache(), retval_sp); } return result; } -bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::TypeSummaryImplSP &format_sp) { - if (!m_category_sp) - return false; +/// Explicit instantiations for the four types. +/// \{ +template bool +LanguageCategory::Get(FormattersMatchData &, + lldb::TypeValidatorImplSP &); +template bool +LanguageCategory::Get(FormattersMatchData &, + lldb::TypeFormatImplSP &); +template bool +LanguageCategory::Get(FormattersMatchData &, + lldb::TypeSummaryImplSP &); +template bool +LanguageCategory::Get(FormattersMatchData &, + lldb::SyntheticChildrenSP &); +/// \} - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) { - if (m_format_cache.Get(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject &valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(), - match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); - } - return result; +template <> +auto &LanguageCategory::GetHardcodedFinder() { + return m_hardcoded_formats; } -bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::SyntheticChildrenSP &format_sp) { - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) { - if (m_format_cache.Get(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject &valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(), - match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); - } - return result; +template <> +auto &LanguageCategory::GetHardcodedFinder() { + return m_hardcoded_summaries; } -bool LanguageCategory::Get(FormattersMatchData &match_data, - lldb::TypeValidatorImplSP &format_sp) { - if (!m_category_sp) - return false; - - if (!IsEnabled()) - return false; - - if (match_data.GetTypeForCache()) { - if (m_format_cache.Get(match_data.GetTypeForCache(), format_sp)) - return format_sp.get() != nullptr; - } - - ValueObject &valobj(match_data.GetValueObject()); - bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(), - match_data.GetMatchesVector(), format_sp); - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); - } - return result; +template <> +auto &LanguageCategory::GetHardcodedFinder() { + return m_hardcoded_synthetics; } +template <> +auto &LanguageCategory::GetHardcodedFinder() { + return m_hardcoded_validators; +} + +template bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, - lldb::TypeFormatImplSP &format_sp) { + ImplSP &retval_sp) { if (!IsEnabled()) return false; ValueObject &valobj(match_data.GetValueObject()); lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - for (auto &candidate : m_hardcoded_formats) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) + for (auto &candidate : GetHardcodedFinder()) { + if (auto result = candidate(valobj, use_dynamic, fmt_mgr)) { + retval_sp = result; break; + } } if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); + (!retval_sp || !retval_sp->NonCacheable())) { + m_format_cache.Set(match_data.GetTypeForCache(), retval_sp); } - return format_sp.get() != nullptr; + return (bool)retval_sp; } -bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, - FormattersMatchData &match_data, - lldb::TypeSummaryImplSP &format_sp) { - if (!IsEnabled()) - return false; - - ValueObject &valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto &candidate : m_hardcoded_summaries) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; -} - -bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, - FormattersMatchData &match_data, - lldb::SyntheticChildrenSP &format_sp) { - if (!IsEnabled()) - return false; - - ValueObject &valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto &candidate : m_hardcoded_synthetics) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; -} - -bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, - FormattersMatchData &match_data, - lldb::TypeValidatorImplSP &format_sp) { - if (!IsEnabled()) - return false; - - ValueObject &valobj(match_data.GetValueObject()); - lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType()); - - for (auto &candidate : m_hardcoded_validators) { - if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr))) - break; - } - if (match_data.GetTypeForCache() && - (!format_sp || !format_sp->NonCacheable())) { - m_format_cache.Set(match_data.GetTypeForCache(), format_sp); - } - return format_sp.get() != nullptr; -} +/// Explicit instantiations for the four types. +/// \{ +template bool LanguageCategory::GetHardcoded( + FormatManager &, FormattersMatchData &, lldb::TypeValidatorImplSP &); +template bool LanguageCategory::GetHardcoded( + FormatManager &, FormattersMatchData &, lldb::TypeFormatImplSP &); +template bool LanguageCategory::GetHardcoded( + FormatManager &, FormattersMatchData &, lldb::TypeSummaryImplSP &); +template bool LanguageCategory::GetHardcoded( + FormatManager &, FormattersMatchData &, lldb::SyntheticChildrenSP &); +/// \} lldb::TypeCategoryImplSP LanguageCategory::GetCategory() const { return m_category_sp;