1 //===-- TypeCategory.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_TypeCategory_h_
11 #define lldb_TypeCategory_h_
16 // Other libraries and framework includes
18 #include "lldb/lldb-public.h"
19 #include "lldb/lldb-enumerations.h"
21 #include "lldb/DataFormatters/FormatClasses.h"
22 #include "lldb/DataFormatters/FormattersContainer.h"
24 namespace lldb_private {
26 template <typename FormatterImpl>
27 class FormatterContainerPair
30 typedef FormattersContainer<ConstString, FormatterImpl> ExactMatchContainer;
31 typedef FormattersContainer<lldb::RegularExpressionSP, FormatterImpl> RegexMatchContainer;
33 typedef typename ExactMatchContainer::MapType ExactMatchMap;
34 typedef typename RegexMatchContainer::MapType RegexMatchMap;
36 typedef typename ExactMatchContainer::MapValueType MapValueType;
38 typedef typename ExactMatchContainer::SharedPointer ExactMatchContainerSP;
39 typedef typename RegexMatchContainer::SharedPointer RegexMatchContainerSP;
41 FormatterContainerPair (const char* exact_name,
42 const char* regex_name,
43 IFormatChangeListener* clist) :
44 m_exact_sp(new ExactMatchContainer(std::string(exact_name),clist)),
45 m_regex_sp(new RegexMatchContainer(std::string(regex_name),clist))
49 ~FormatterContainerPair () = default;
52 GetExactMatch () const
58 GetRegexMatch () const
64 ExactMatchContainerSP m_exact_sp;
65 RegexMatchContainerSP m_regex_sp;
68 class TypeCategoryImpl
71 typedef FormatterContainerPair<TypeFormatImpl> FormatContainer;
72 typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer;
73 typedef FormatterContainerPair<TypeFilterImpl> FilterContainer;
74 typedef FormatterContainerPair<TypeValidatorImpl> ValidatorContainer;
76 #ifndef LLDB_DISABLE_PYTHON
77 typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer;
78 #endif // #ifndef LLDB_DISABLE_PYTHON
82 typedef uint16_t FormatCategoryItems;
83 static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
85 typedef FormatContainer::ExactMatchContainerSP FormatContainerSP;
86 typedef FormatContainer::RegexMatchContainerSP RegexFormatContainerSP;
88 typedef SummaryContainer::ExactMatchContainerSP SummaryContainerSP;
89 typedef SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP;
91 typedef FilterContainer::ExactMatchContainerSP FilterContainerSP;
92 typedef FilterContainer::RegexMatchContainerSP RegexFilterContainerSP;
93 #ifndef LLDB_DISABLE_PYTHON
94 typedef SynthContainer::ExactMatchContainerSP SynthContainerSP;
95 typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP;
96 #endif // #ifndef LLDB_DISABLE_PYTHON
98 typedef ValidatorContainer::ExactMatchContainerSP ValidatorContainerSP;
99 typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP;
101 TypeCategoryImpl (IFormatChangeListener* clist,
105 GetTypeFormatsContainer ()
107 return m_format_cont.GetExactMatch();
110 RegexFormatContainerSP
111 GetRegexTypeFormatsContainer ()
113 return m_format_cont.GetRegexMatch();
117 GetTypeSummariesContainer ()
119 return m_summary_cont.GetExactMatch();
122 RegexSummaryContainerSP
123 GetRegexTypeSummariesContainer ()
125 return m_summary_cont.GetRegexMatch();
129 GetTypeFiltersContainer ()
131 return m_filter_cont.GetExactMatch();
134 RegexFilterContainerSP
135 GetRegexTypeFiltersContainer ()
137 return m_filter_cont.GetRegexMatch();
140 FormatContainer::MapValueType
141 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
143 SummaryContainer::MapValueType
144 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
146 FilterContainer::MapValueType
147 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
149 #ifndef LLDB_DISABLE_PYTHON
150 SynthContainer::MapValueType
151 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
154 ValidatorContainer::MapValueType
155 GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
157 lldb::TypeNameSpecifierImplSP
158 GetTypeNameSpecifierForFormatAtIndex (size_t index);
160 lldb::TypeNameSpecifierImplSP
161 GetTypeNameSpecifierForSummaryAtIndex (size_t index);
163 FormatContainer::MapValueType
164 GetFormatAtIndex (size_t index);
166 SummaryContainer::MapValueType
167 GetSummaryAtIndex (size_t index);
169 FilterContainer::MapValueType
170 GetFilterAtIndex (size_t index);
172 lldb::TypeNameSpecifierImplSP
173 GetTypeNameSpecifierForFilterAtIndex (size_t index);
175 #ifndef LLDB_DISABLE_PYTHON
177 GetTypeSyntheticsContainer ()
179 return m_synth_cont.GetExactMatch();
182 RegexSynthContainerSP
183 GetRegexTypeSyntheticsContainer ()
185 return m_synth_cont.GetRegexMatch();
188 SynthContainer::MapValueType
189 GetSyntheticAtIndex (size_t index);
191 lldb::TypeNameSpecifierImplSP
192 GetTypeNameSpecifierForSyntheticAtIndex (size_t index);
193 #endif // #ifndef LLDB_DISABLE_PYTHON
196 GetTypeValidatorsContainer ()
198 return m_validator_cont.GetExactMatch();
201 RegexValidatorContainerSP
202 GetRegexTypeValidatorsContainer ()
204 return m_validator_cont.GetRegexMatch();
207 ValidatorContainer::MapValueType
208 GetValidatorAtIndex (size_t index);
210 lldb::TypeNameSpecifierImplSP
211 GetTypeNameSpecifierForValidatorAtIndex (size_t index);
222 if (m_enabled == false)
225 return m_enabled_position;
229 Get (ValueObject& valobj,
230 const FormattersMatchVector& candidates,
231 lldb::TypeFormatImplSP& entry,
232 uint32_t* reason = NULL);
235 Get (ValueObject& valobj,
236 const FormattersMatchVector& candidates,
237 lldb::TypeSummaryImplSP& entry,
238 uint32_t* reason = NULL);
241 Get (ValueObject& valobj,
242 const FormattersMatchVector& candidates,
243 lldb::SyntheticChildrenSP& entry,
244 uint32_t* reason = NULL);
247 Get (ValueObject& valobj,
248 const FormattersMatchVector& candidates,
249 lldb::TypeValidatorImplSP& entry,
250 uint32_t* reason = NULL);
253 Clear (FormatCategoryItems items = ALL_ITEM_TYPES);
256 Delete (ConstString name,
257 FormatCategoryItems items = ALL_ITEM_TYPES);
260 GetCount (FormatCategoryItems items = ALL_ITEM_TYPES);
265 return m_name.GetCString();
269 AnyMatches (ConstString type_name,
270 FormatCategoryItems items = ALL_ITEM_TYPES,
271 bool only_enabled = true,
272 const char** matching_category = NULL,
273 FormatCategoryItems* matching_type = NULL);
275 typedef std::shared_ptr<TypeCategoryImpl> SharedPointer;
278 FormatContainer m_format_cont;
279 SummaryContainer m_summary_cont;
280 FilterContainer m_filter_cont;
281 #ifndef LLDB_DISABLE_PYTHON
282 SynthContainer m_synth_cont;
283 #endif // #ifndef LLDB_DISABLE_PYTHON
284 ValidatorContainer m_validator_cont;
288 IFormatChangeListener* m_change_listener;
294 uint32_t m_enabled_position;
297 Enable (bool value, uint32_t position);
302 Enable(false, UINT32_MAX);
306 GetLastEnabledPosition ()
308 return m_enabled_position;
312 SetEnabledPosition (uint32_t p)
314 m_enabled_position = p;
317 friend class TypeCategoryMap;
319 friend class FormattersContainer<ConstString, TypeFormatImpl>;
320 friend class FormattersContainer<lldb::RegularExpressionSP, TypeFormatImpl>;
322 friend class FormattersContainer<ConstString, TypeSummaryImpl>;
323 friend class FormattersContainer<lldb::RegularExpressionSP, TypeSummaryImpl>;
325 friend class FormattersContainer<ConstString, TypeFilterImpl>;
326 friend class FormattersContainer<lldb::RegularExpressionSP, TypeFilterImpl>;
328 #ifndef LLDB_DISABLE_PYTHON
329 friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>;
330 friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>;
331 #endif // #ifndef LLDB_DISABLE_PYTHON
333 friend class FormattersContainer<ConstString, TypeValidatorImpl>;
334 friend class FormattersContainer<lldb::RegularExpressionSP, TypeValidatorImpl>;
337 } // namespace lldb_private
339 #endif // lldb_TypeCategory_h_