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;
75 #ifndef LLDB_DISABLE_PYTHON
76 typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer;
77 #endif // #ifndef LLDB_DISABLE_PYTHON
81 typedef uint16_t FormatCategoryItems;
82 static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
84 typedef FormatContainer::ExactMatchContainerSP FormatContainerSP;
85 typedef FormatContainer::RegexMatchContainerSP RegexFormatContainerSP;
87 typedef SummaryContainer::ExactMatchContainerSP SummaryContainerSP;
88 typedef SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP;
90 typedef FilterContainer::ExactMatchContainerSP FilterContainerSP;
91 typedef FilterContainer::RegexMatchContainerSP RegexFilterContainerSP;
92 #ifndef LLDB_DISABLE_PYTHON
93 typedef SynthContainer::ExactMatchContainerSP SynthContainerSP;
94 typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP;
95 #endif // #ifndef LLDB_DISABLE_PYTHON
97 TypeCategoryImpl (IFormatChangeListener* clist,
101 GetTypeFormatsContainer ()
103 return m_format_cont.GetExactMatch();
106 RegexFormatContainerSP
107 GetRegexTypeFormatsContainer ()
109 return m_format_cont.GetRegexMatch();
113 GetTypeSummariesContainer ()
115 return m_summary_cont.GetExactMatch();
118 RegexSummaryContainerSP
119 GetRegexTypeSummariesContainer ()
121 return m_summary_cont.GetRegexMatch();
125 GetTypeFiltersContainer ()
127 return m_filter_cont.GetExactMatch();
130 RegexFilterContainerSP
131 GetRegexTypeFiltersContainer ()
133 return m_filter_cont.GetRegexMatch();
136 FormatContainer::MapValueType
137 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
139 SummaryContainer::MapValueType
140 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
142 FilterContainer::MapValueType
143 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
145 #ifndef LLDB_DISABLE_PYTHON
146 SynthContainer::MapValueType
147 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
150 lldb::TypeNameSpecifierImplSP
151 GetTypeNameSpecifierForFormatAtIndex (size_t index);
153 lldb::TypeNameSpecifierImplSP
154 GetTypeNameSpecifierForSummaryAtIndex (size_t index);
156 FormatContainer::MapValueType
157 GetFormatAtIndex (size_t index);
159 SummaryContainer::MapValueType
160 GetSummaryAtIndex (size_t index);
162 FilterContainer::MapValueType
163 GetFilterAtIndex (size_t index);
165 lldb::TypeNameSpecifierImplSP
166 GetTypeNameSpecifierForFilterAtIndex (size_t index);
168 #ifndef LLDB_DISABLE_PYTHON
170 GetTypeSyntheticsContainer ()
172 return m_synth_cont.GetExactMatch();
175 RegexSynthContainerSP
176 GetRegexTypeSyntheticsContainer ()
178 return m_synth_cont.GetRegexMatch();
181 SynthContainer::MapValueType
182 GetSyntheticAtIndex (size_t index);
184 lldb::TypeNameSpecifierImplSP
185 GetTypeNameSpecifierForSyntheticAtIndex (size_t index);
187 #endif // #ifndef LLDB_DISABLE_PYTHON
198 if (m_enabled == false)
201 return m_enabled_position;
205 Get (ValueObject& valobj,
206 const FormattersMatchVector& candidates,
207 lldb::TypeFormatImplSP& entry,
208 uint32_t* reason = NULL);
211 Get (ValueObject& valobj,
212 const FormattersMatchVector& candidates,
213 lldb::TypeSummaryImplSP& entry,
214 uint32_t* reason = NULL);
217 Get (ValueObject& valobj,
218 const FormattersMatchVector& candidates,
219 lldb::SyntheticChildrenSP& entry,
220 uint32_t* reason = NULL);
223 Clear (FormatCategoryItems items = ALL_ITEM_TYPES);
226 Delete (ConstString name,
227 FormatCategoryItems items = ALL_ITEM_TYPES);
230 GetCount (FormatCategoryItems items = ALL_ITEM_TYPES);
235 return m_name.GetCString();
239 AnyMatches (ConstString type_name,
240 FormatCategoryItems items = ALL_ITEM_TYPES,
241 bool only_enabled = true,
242 const char** matching_category = NULL,
243 FormatCategoryItems* matching_type = NULL);
245 typedef std::shared_ptr<TypeCategoryImpl> SharedPointer;
248 FormatContainer m_format_cont;
250 SummaryContainer m_summary_cont;
252 FilterContainer m_filter_cont;
254 #ifndef LLDB_DISABLE_PYTHON
255 SynthContainer m_synth_cont;
256 #endif // #ifndef LLDB_DISABLE_PYTHON
260 IFormatChangeListener* m_change_listener;
266 uint32_t m_enabled_position;
269 Enable (bool value, uint32_t position);
274 Enable(false, UINT32_MAX);
277 friend class TypeCategoryMap;
279 friend class FormattersContainer<ConstString, TypeFormatImpl>;
280 friend class FormattersContainer<lldb::RegularExpressionSP, TypeFormatImpl>;
282 friend class FormattersContainer<ConstString, TypeSummaryImpl>;
283 friend class FormattersContainer<lldb::RegularExpressionSP, TypeSummaryImpl>;
285 friend class FormattersContainer<ConstString, TypeFilterImpl>;
286 friend class FormattersContainer<lldb::RegularExpressionSP, TypeFilterImpl>;
288 #ifndef LLDB_DISABLE_PYTHON
289 friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>;
290 friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>;
291 #endif // #ifndef LLDB_DISABLE_PYTHON
294 } // namespace lldb_private
296 #endif // lldb_TypeCategory_h_