LLDB mainline
LanguageCategory.cpp
Go to the documentation of this file.
1//===-- LanguageCategory.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
17
18using namespace lldb;
19using namespace lldb_private;
20
22 : m_category_sp(), m_hardcoded_formats(), m_hardcoded_summaries(),
23 m_hardcoded_synthetics(), m_format_cache(), m_enabled(false) {
24 if (Language *language_plugin = Language::FindPlugin(lang_type)) {
25 m_category_sp = language_plugin->GetFormatters();
26 m_hardcoded_formats = language_plugin->GetHardcodedFormats();
27 m_hardcoded_summaries = language_plugin->GetHardcodedSummaries();
28 m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics();
29 }
30 Enable();
31}
32
33template<typename ImplSP>
35 ImplSP &retval_sp) {
36 if (!m_category_sp)
37 return false;
38
39 if (!IsEnabled())
40 return false;
41
42 if (match_data.GetTypeForCache()) {
43 if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp))
44 return (bool)retval_sp;
45 }
46
47 ValueObject &valobj(match_data.GetValueObject());
48 bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(),
49 match_data.GetMatchesVector(), retval_sp);
50 if (match_data.GetTypeForCache() &&
51 (!retval_sp || !retval_sp->NonCacheable())) {
52 m_format_cache.Set(match_data.GetTypeForCache(), retval_sp);
53 }
54 return result;
55}
56
57namespace lldb_private {
58
59/// Explicit instantiations for the three types.
60/// \{
61template bool
62LanguageCategory::Get<lldb::TypeFormatImplSP>(FormattersMatchData &,
64template bool
65LanguageCategory::Get<lldb::TypeSummaryImplSP>(FormattersMatchData &,
67template bool
68LanguageCategory::Get<lldb::SyntheticChildrenSP>(FormattersMatchData &,
70/// \}
71
72template <>
73auto &LanguageCategory::GetHardcodedFinder<lldb::TypeFormatImplSP>() {
74 return m_hardcoded_formats;
75}
76
77template <>
78auto &LanguageCategory::GetHardcodedFinder<lldb::TypeSummaryImplSP>() {
79 return m_hardcoded_summaries;
80}
81
82template <>
83auto &LanguageCategory::GetHardcodedFinder<lldb::SyntheticChildrenSP>() {
84 return m_hardcoded_synthetics;
85}
86
87} // namespace lldb_private
88
89template <typename ImplSP>
91 FormattersMatchData &match_data,
92 ImplSP &retval_sp) {
93 if (!IsEnabled())
94 return false;
95
96 ValueObject &valobj(match_data.GetValueObject());
97 lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
98
99 for (auto &candidate : GetHardcodedFinder<ImplSP>()) {
100 if (auto result = candidate(valobj, use_dynamic, fmt_mgr)) {
101 retval_sp = result;
102 break;
103 }
104 }
105 return (bool)retval_sp;
106}
107
108/// Explicit instantiations for the three types.
109/// \{
110template bool LanguageCategory::GetHardcoded<lldb::TypeFormatImplSP>(
112template bool LanguageCategory::GetHardcoded<lldb::TypeSummaryImplSP>(
114template bool LanguageCategory::GetHardcoded<lldb::SyntheticChildrenSP>(
116/// \}
117
119 return m_category_sp;
120}
121
123
125 if (m_category_sp)
127 m_enabled = true;
128}
129
131 if (m_category_sp)
132 m_category_sp->Disable();
133 m_enabled = false;
134}
135
void Set(ConstString type, lldb::TypeFormatImplSP &format_sp)
Definition: FormatCache.cpp:94
bool Get(ConstString type, ImplSP &format_impl_sp)
Definition: FormatCache.cpp:69
lldb::DynamicValueType GetDynamicValueType()
FormattersMatchVector GetMatchesVector()
HardcodedFormatters::HardcodedSummaryFinder m_hardcoded_summaries
lldb::TypeCategoryImplSP GetCategory() const
HardcodedFormatters::HardcodedFormatFinder m_hardcoded_formats
HardcodedFormatters::HardcodedSyntheticFinder m_hardcoded_synthetics
LanguageCategory(lldb::LanguageType lang_type)
bool Get(FormattersMatchData &match_data, ImplSP &format_sp)
lldb::TypeCategoryImplSP m_category_sp
lldb_private::FormatCache m_format_cache
bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, ImplSP &format_sp)
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:83
static const Position Default
lldb::LanguageType GetObjectRuntimeLanguage()
Definition: ValueObject.h:373
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:463
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
Definition: lldb-forward.h:460
LanguageType
Programming language type.
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
Definition: lldb-forward.h:433
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
Definition: lldb-forward.h:451