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
21
22static bool IsApplicable(lldb::LanguageType category_lang,
23 lldb::LanguageType valobj_lang) {
24 switch (category_lang) {
25 // Unless we know better, allow only exact equality.
26 default:
27 return category_lang == valobj_lang;
28
29 // the C family, we consider it as one
31 case eLanguageTypeC:
33 return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
34 valobj_lang == eLanguageTypeC99;
35
36 // ObjC knows about C and itself
38 return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
39 valobj_lang == eLanguageTypeC99 || valobj_lang == eLanguageTypeObjC;
40
41 // C++ knows about C and C++
43 return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
44 valobj_lang == eLanguageTypeC99 ||
45 valobj_lang == eLanguageTypeC_plus_plus;
46
47 // ObjC++ knows about C,C++,ObjC and ObjC++
49 return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
50 valobj_lang == eLanguageTypeC99 ||
51 valobj_lang == eLanguageTypeC_plus_plus ||
52 valobj_lang == eLanguageTypeObjC;
53
54 // Categories with unspecified language match everything.
56 return true;
57 }
58}
59
61 for (size_t idx = 0; idx < GetNumLanguages(); idx++) {
62 const lldb::LanguageType category_lang = GetLanguageAtIndex(idx);
63 if (::IsApplicable(category_lang, lang))
64 return true;
65 }
66 return false;
67}
68
70 if (m_languages.empty())
71 return 1;
72 return m_languages.size();
73}
74
80
84
86 const FormattersMatchVector &candidates,
88 if (!IsEnabled() || !IsApplicable(lang))
89 return false;
90 return m_format_cont.Get(candidates, entry);
91}
92
94 const FormattersMatchVector &candidates,
96 if (!IsEnabled() || !IsApplicable(lang))
97 return false;
98 return m_summary_cont.Get(candidates, entry);
99}
100
102 const FormattersMatchVector &candidates,
104 if (!IsEnabled() || !IsApplicable(lang))
105 return false;
106
107 // first find both Filter and Synth, and then check which is most recent
108 bool pick_synth = false;
109
111 m_filter_cont.Get(candidates, filter_sp);
112
114 m_synth_cont.Get(candidates, synth_sp);
115
116 if (!filter_sp.get() && !synth_sp.get())
117 return false;
118 else if (!filter_sp.get() && synth_sp.get())
119 pick_synth = true;
120 else if (filter_sp.get() && !synth_sp.get())
121 pick_synth = false;
122 else /*if (filter_sp.get() && synth_sp.get())*/
123 {
124 pick_synth = filter_sp->GetRevision() <= synth_sp->GetRevision();
125 }
126
127 if (pick_synth) {
128 entry = synth_sp;
129 return true;
130 } else {
131 entry = filter_sp;
132 return true;
133 }
134 return false;
135}
136
138 if (items & eFormatCategoryItemFormat)
139 m_format_cont.Clear();
140
141 if (items & eFormatCategoryItemSummary)
142 m_summary_cont.Clear();
143
144 if (items & eFormatCategoryItemFilter)
145 m_filter_cont.Clear();
146
147 if (items & eFormatCategoryItemSynth)
148 m_synth_cont.Clear();
149}
150
152 bool success = false;
153
154 if (items & eFormatCategoryItemFormat)
155 success = m_format_cont.Delete(name) || success;
156
157 if (items & eFormatCategoryItemSummary)
158 success = m_summary_cont.Delete(name) || success;
159
160 if (items & eFormatCategoryItemFilter)
161 success = m_filter_cont.Delete(name) || success;
162
163 if (items & eFormatCategoryItemSynth)
164 success = m_synth_cont.Delete(name) || success;
165
166 return success;
167}
168
170 uint32_t count = 0;
171
172 if (items & eFormatCategoryItemFormat)
173 count += m_format_cont.GetCount();
174
175 if (items & eFormatCategoryItemSummary)
176 count += m_summary_cont.GetCount();
177
178 if (items & eFormatCategoryItemFilter)
179 count += m_filter_cont.GetCount();
180
181 if (items & eFormatCategoryItemSynth)
182 count += m_synth_cont.GetCount();
183
184 return count;
185}
186
188 const FormattersMatchCandidate &candidate_type, FormatCategoryItems items) {
189 if (items & eFormatCategoryItemFormat) {
190 if (m_format_cont.AnyMatches(candidate_type)) {
191 return true;
192 }
193 }
194
195 if (items & eFormatCategoryItemSummary) {
196 if (m_summary_cont.AnyMatches(candidate_type)) {
197 return true;
198 }
199 }
200
201 if (items & eFormatCategoryItemFilter) {
202 if (m_filter_cont.AnyMatches(candidate_type)) {
203 return true;
204 }
205 }
206
207 if (items & eFormatCategoryItemSynth) {
208 if (m_synth_cont.AnyMatches(candidate_type)) {
209 return true;
210 }
211 }
212
213 return false;
214}
215
217 FormatCategoryItems items) {
218 if (items & eFormatCategoryItemFormat)
219 m_format_cont.AutoComplete(request);
220 if (items & eFormatCategoryItemSummary)
221 m_summary_cont.AutoComplete(request);
222 if (items & eFormatCategoryItemFilter)
223 m_filter_cont.AutoComplete(request);
224 if (items & eFormatCategoryItemSynth)
225 m_synth_cont.AutoComplete(request);
226}
227
230 return m_format_cont.GetForTypeNameSpecifier(type_sp);
231}
232
235 return m_summary_cont.GetForTypeNameSpecifier(type_sp);
236}
237
240 return m_filter_cont.GetForTypeNameSpecifier(type_sp);
241}
242
245 return m_synth_cont.GetForTypeNameSpecifier(type_sp);
246}
247
250 return m_format_cont.GetAtIndex(index);
251}
252
255 return m_summary_cont.GetAtIndex(index);
256}
257
260 return m_filter_cont.GetAtIndex(index);
261}
262
265 return m_synth_cont.GetAtIndex(index);
266}
267
270 return m_format_cont.GetTypeNameSpecifierAtIndex(index);
271}
272
275 return m_summary_cont.GetTypeNameSpecifierAtIndex(index);
276}
277
280 return m_filter_cont.GetTypeNameSpecifierAtIndex(index);
281}
282
285 return m_synth_cont.GetTypeNameSpecifierAtIndex(index);
286}
287
288void TypeCategoryImpl::Enable(bool value, uint32_t position) {
289 std::lock_guard<std::recursive_mutex> guard(m_mutex);
290 if ((m_enabled = value))
291 m_enabled_position = position;
293 m_change_listener->Changed();
294}
295
297 StreamString stream;
298 stream.Printf("%s (%s", GetName(), (IsEnabled() ? "enabled" : "disabled"));
299 StreamString lang_stream;
300 lang_stream.Printf(", applicable for language(s): ");
301 bool print_lang = false;
302 for (size_t idx = 0; idx < GetNumLanguages(); idx++) {
303 const lldb::LanguageType lang = GetLanguageAtIndex(idx);
304 if (lang != lldb::eLanguageTypeUnknown)
305 print_lang = true;
306 lang_stream.Printf("%s%s", Language::GetNameForLanguageType(lang),
307 idx + 1 < GetNumLanguages() ? ", " : "");
308 }
309 if (print_lang)
310 stream.PutCString(lang_stream.GetString());
311 stream.PutChar(')');
312 return std::string(stream.GetString());
313}
static bool IsApplicable(lldb::LanguageType category_lang, lldb::LanguageType valobj_lang)
"lldb/Utility/ArgCompletionRequest.h"
A uniqued constant string class.
Definition ConstString.h:40
static const char * GetNameForLanguageType(lldb::LanguageType language)
Returns the internal LLDB name for the specified language.
Definition Language.cpp:305
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)
IFormatChangeListener * m_change_listener
std::recursive_mutex m_mutex
void AddLanguage(lldb::LanguageType lang)
lldb::LanguageType GetLanguageAtIndex(size_t idx)
TypeCategoryImpl(IFormatChangeListener *clist, ConstString name)
bool AnyMatches(const FormattersMatchCandidate &candidate_type, FormatCategoryItems items=ALL_ITEM_TYPES)
bool Delete(ConstString name, 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.
@ eLanguageTypeC99
ISO C:1999.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeC89
ISO C:1989.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP