forked from OSchip/llvm-project
Replace redundant code in LanguageCategory with templates (NFC)
Differential Revision: https://reviews.llvm.org/D71296
This commit is contained in:
parent
636c93ed11
commit
b3801de7c5
|
@ -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 <typename ImplSP>
|
||||
bool Get(FormattersMatchData &match_data, ImplSP &format_sp);
|
||||
template <typename ImplSP>
|
||||
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 <typename ImplSP>
|
||||
auto &GetHardcodedFinder();
|
||||
|
||||
lldb_private::FormatCache m_format_cache;
|
||||
|
||||
bool m_enabled;
|
||||
|
|
|
@ -34,8 +34,9 @@ LanguageCategory::LanguageCategory(lldb::LanguageType lang_type)
|
|||
Enable();
|
||||
}
|
||||
|
||||
template<typename ImplSP>
|
||||
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<lldb::TypeValidatorImplSP>(FormattersMatchData &,
|
||||
lldb::TypeValidatorImplSP &);
|
||||
template bool
|
||||
LanguageCategory::Get<lldb::TypeFormatImplSP>(FormattersMatchData &,
|
||||
lldb::TypeFormatImplSP &);
|
||||
template bool
|
||||
LanguageCategory::Get<lldb::TypeSummaryImplSP>(FormattersMatchData &,
|
||||
lldb::TypeSummaryImplSP &);
|
||||
template bool
|
||||
LanguageCategory::Get<lldb::SyntheticChildrenSP>(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<lldb::TypeFormatImplSP>() {
|
||||
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<lldb::TypeSummaryImplSP>() {
|
||||
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<lldb::SyntheticChildrenSP>() {
|
||||
return m_hardcoded_synthetics;
|
||||
}
|
||||
|
||||
template <>
|
||||
auto &LanguageCategory::GetHardcodedFinder<lldb::TypeValidatorImplSP>() {
|
||||
return m_hardcoded_validators;
|
||||
}
|
||||
|
||||
template <typename ImplSP>
|
||||
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<ImplSP>()) {
|
||||
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<lldb::TypeValidatorImplSP>(
|
||||
FormatManager &, FormattersMatchData &, lldb::TypeValidatorImplSP &);
|
||||
template bool LanguageCategory::GetHardcoded<lldb::TypeFormatImplSP>(
|
||||
FormatManager &, FormattersMatchData &, lldb::TypeFormatImplSP &);
|
||||
template bool LanguageCategory::GetHardcoded<lldb::TypeSummaryImplSP>(
|
||||
FormatManager &, FormattersMatchData &, lldb::TypeSummaryImplSP &);
|
||||
template bool LanguageCategory::GetHardcoded<lldb::SyntheticChildrenSP>(
|
||||
FormatManager &, FormattersMatchData &, lldb::SyntheticChildrenSP &);
|
||||
/// \}
|
||||
|
||||
lldb::TypeCategoryImplSP LanguageCategory::GetCategory() const {
|
||||
return m_category_sp;
|
||||
|
|
Loading…
Reference in New Issue