LLDB mainline
TypeCategory.cpp
Go to the documentation of this file.
1//===-- TypeCategory.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
11
12
13using namespace lldb;
14using namespace lldb_private;
15
17 std::string name)
18 : m_format_cont(clist), m_summary_cont(clist), m_filter_cont(clist),
19 m_synth_cont(clist), m_enabled(false), m_change_listener(clist),
20 m_mutex(), m_name(std::move(name)), m_languages() {}
21
22static bool IsApplicable(lldb::LanguageType category_lang,
23 lldb::LanguageType valobj_lang) {
24 // Categories with unspecified language match everything.
25 if (category_lang == eLanguageTypeUnknown)
26 return true;
27
28 // No language plugin claims C, whose versions we consider as one.
29 if (Language::LanguageIsC(category_lang))
30 return Language::LanguageIsC(valobj_lang);
31
32 if (Language *language = Language::FindPlugin(category_lang))
33 return language->IsCategoryApplicable(category_lang, valobj_lang);
34
35 // Unless we know better, allow only exact equality.
36 return category_lang == valobj_lang;
37}
38
40 for (size_t idx = 0; idx < GetNumLanguages(); idx++) {
41 const lldb::LanguageType category_lang = GetLanguageAtIndex(idx);
42 if (::IsApplicable(category_lang, lang))
43 return true;
44 }
45 return false;
46}
47
49 if (m_languages.empty())
50 return 1;
51 return m_languages.size();
52}
53
59
63
65 const FormattersMatchVector &candidates,
67 if (!IsEnabled() || !IsApplicable(lang))
68 return false;
69 return m_format_cont.Get(candidates, entry);
70}
71
73 const FormattersMatchVector &candidates,
75 if (!IsEnabled() || !IsApplicable(lang))
76 return false;
77 return m_summary_cont.Get(candidates, entry);
78}
79
81 const FormattersMatchVector &candidates,
83 if (!IsEnabled() || !IsApplicable(lang))
84 return false;
85
86 // first find both Filter and Synth, and then check which is most recent
87 bool pick_synth = false;
88
90 m_filter_cont.Get(candidates, filter_sp);
91
93 m_synth_cont.Get(candidates, synth_sp);
94
95 if (!filter_sp.get() && !synth_sp.get())
96 return false;
97 else if (!filter_sp.get() && synth_sp.get())
98 pick_synth = true;
99 else if (filter_sp.get() && !synth_sp.get())
100 pick_synth = false;
101 else /*if (filter_sp.get() && synth_sp.get())*/
102 {
103 pick_synth = filter_sp->GetRevision() <= synth_sp->GetRevision();
104 }
105
106 if (pick_synth) {
107 entry = synth_sp;
108 return true;
109 } else {
110 entry = filter_sp;
111 return true;
112 }
113 return false;
114}
115
117 if (items & eFormatCategoryItemFormat)
118 m_format_cont.Clear();
119
120 if (items & eFormatCategoryItemSummary)
121 m_summary_cont.Clear();
122
123 if (items & eFormatCategoryItemFilter)
124 m_filter_cont.Clear();
125
126 if (items & eFormatCategoryItemSynth)
127 m_synth_cont.Clear();
128}
129
130bool TypeCategoryImpl::Delete(llvm::StringRef name, FormatCategoryItems items) {
131 bool success = false;
132
133 if (items & eFormatCategoryItemFormat)
134 success = m_format_cont.Delete(name) || success;
135
136 if (items & eFormatCategoryItemSummary)
137 success = m_summary_cont.Delete(name) || success;
138
139 if (items & eFormatCategoryItemFilter)
140 success = m_filter_cont.Delete(name) || success;
141
142 if (items & eFormatCategoryItemSynth)
143 success = m_synth_cont.Delete(name) || success;
144
145 return success;
146}
147
149 uint32_t count = 0;
150
151 if (items & eFormatCategoryItemFormat)
152 count += m_format_cont.GetCount();
153
154 if (items & eFormatCategoryItemSummary)
155 count += m_summary_cont.GetCount();
156
157 if (items & eFormatCategoryItemFilter)
158 count += m_filter_cont.GetCount();
159
160 if (items & eFormatCategoryItemSynth)
161 count += m_synth_cont.GetCount();
162
163 return count;
164}
165
167 const FormattersMatchCandidate &candidate_type, FormatCategoryItems items) {
168 if (items & eFormatCategoryItemFormat) {
169 if (m_format_cont.AnyMatches(candidate_type)) {
170 return true;
171 }
172 }
173
174 if (items & eFormatCategoryItemSummary) {
175 if (m_summary_cont.AnyMatches(candidate_type)) {
176 return true;
177 }
178 }
179
180 if (items & eFormatCategoryItemFilter) {
181 if (m_filter_cont.AnyMatches(candidate_type)) {
182 return true;
183 }
184 }
185
186 if (items & eFormatCategoryItemSynth) {
187 if (m_synth_cont.AnyMatches(candidate_type)) {
188 return true;
189 }
190 }
191
192 return false;
193}
194
196 FormatCategoryItems items) {
197 if (items & eFormatCategoryItemFormat)
198 m_format_cont.AutoComplete(request);
199 if (items & eFormatCategoryItemSummary)
200 m_summary_cont.AutoComplete(request);
201 if (items & eFormatCategoryItemFilter)
202 m_filter_cont.AutoComplete(request);
203 if (items & eFormatCategoryItemSynth)
204 m_synth_cont.AutoComplete(request);
205}
206
209 return m_format_cont.GetForTypeNameSpecifier(type_sp);
210}
211
214 return m_summary_cont.GetForTypeNameSpecifier(type_sp);
215}
216
219 return m_filter_cont.GetForTypeNameSpecifier(type_sp);
220}
221
224 return m_synth_cont.GetForTypeNameSpecifier(type_sp);
225}
226
229 return m_format_cont.GetAtIndex(index);
230}
231
234 return m_summary_cont.GetAtIndex(index);
235}
236
239 return m_filter_cont.GetAtIndex(index);
240}
241
244 return m_synth_cont.GetAtIndex(index);
245}
246
249 return m_format_cont.GetTypeNameSpecifierAtIndex(index);
250}
251
254 return m_summary_cont.GetTypeNameSpecifierAtIndex(index);
255}
256
259 return m_filter_cont.GetTypeNameSpecifierAtIndex(index);
260}
261
264 return m_synth_cont.GetTypeNameSpecifierAtIndex(index);
265}
266
267void TypeCategoryImpl::Enable(bool value, uint32_t position) {
268 std::lock_guard<std::recursive_mutex> guard(m_mutex);
269 if ((m_enabled = value))
270 m_enabled_position = position;
272 m_change_listener->Changed();
273}
274
276 StreamString stream;
277 stream.Printf("%s (%s", GetName(), (IsEnabled() ? "enabled" : "disabled"));
278 StreamString lang_stream;
279 lang_stream.PutCString(", applicable for language(s): ");
280 bool print_lang = false;
281 for (size_t idx = 0; idx < GetNumLanguages(); idx++) {
282 const lldb::LanguageType lang = GetLanguageAtIndex(idx);
283 if (lang != lldb::eLanguageTypeUnknown)
284 print_lang = true;
285 lang_stream.Printf("%s%s", Language::GetNameForLanguageType(lang),
286 idx + 1 < GetNumLanguages() ? ", " : "");
287 }
288 if (print_lang)
289 stream.PutCString(lang_stream.GetString());
290 stream.PutChar(')');
291 return std::string(stream.GetString());
292}
static bool IsApplicable(lldb::LanguageType category_lang, lldb::LanguageType valobj_lang)
"lldb/Utility/ArgCompletionRequest.h"
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:61
static const char * GetNameForLanguageType(lldb::LanguageType language)
Returns the internal LLDB name for the specified language.
Definition Language.cpp:292
static bool LanguageIsC(lldb::LanguageType language)
Definition Language.cpp:354
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t PutChar(char ch)
Definition Stream.cpp:131
std::shared_ptr< SyntheticChildren > SharedPointer
bool Get(const FormattersMatchVector &candidates, std::shared_ptr< FormatterImpl > &entry)
Looks for a matching candidate across all priority tiers, in priority order.
uint32_t GetCount(FormatCategoryItems items=ALL_ITEM_TYPES)
SummaryContainer::MapValueType GetSummaryAtIndex(size_t index)
lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierForSyntheticAtIndex(size_t index)
SummaryContainer::MapValueType GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
FilterContainer::MapValueType GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)
lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierForSummaryAtIndex(size_t index)
lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierForFormatAtIndex(size_t index)
bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, lldb::TypeFormatImplSP &entry)
lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierForFilterAtIndex(size_t index)
FormatContainer::MapValueType GetFormatAtIndex(size_t index)
TypeCategoryImpl(IFormatChangeListener *clist, std::string name)
IFormatChangeListener * m_change_listener
std::recursive_mutex m_mutex
void AddLanguage(lldb::LanguageType lang)
lldb::LanguageType GetLanguageAtIndex(size_t idx)
bool Delete(llvm::StringRef name, FormatCategoryItems items=ALL_ITEM_TYPES)
bool AnyMatches(const FormattersMatchCandidate &candidate_type, FormatCategoryItems items=ALL_ITEM_TYPES)
void AutoComplete(CompletionRequest &request, FormatCategoryItems items)
FilterContainer::MapValueType GetFilterAtIndex(size_t index)
SynthContainer::MapValueType GetSyntheticAtIndex(size_t index)
bool IsApplicable(lldb::LanguageType lang)
FormatContainer::MapValueType GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)
std::vector< lldb::LanguageType > m_languages
void Clear(FormatCategoryItems items=ALL_ITEM_TYPES)
SynthContainer::MapValueType GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)
void Enable(bool value, uint32_t position)
std::shared_ptr< TypeFilterImpl > SharedPointer
A class that represents a running process on the host machine.
std::vector< FormattersMatchCandidate > FormattersMatchVector
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
std::shared_ptr< lldb_private::TypeNameSpecifierImpl > TypeNameSpecifierImplSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP