]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeCategory.h
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / TypeCategory.h
1 //===-- TypeCategory.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_TypeCategory_h_
11 #define lldb_TypeCategory_h_
12
13 // C Includes
14 // C++ Includes
15
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/lldb-public.h"
19 #include "lldb/lldb-enumerations.h"
20
21 #include "lldb/DataFormatters/FormatClasses.h"
22 #include "lldb/DataFormatters/FormattersContainer.h"
23
24 namespace lldb_private {
25     
26     template <typename FormatterImpl>
27     class FormatterContainerPair
28     {
29     public:
30         typedef FormattersContainer<ConstString, FormatterImpl> ExactMatchContainer;
31         typedef FormattersContainer<lldb::RegularExpressionSP, FormatterImpl> RegexMatchContainer;
32         
33         typedef typename ExactMatchContainer::MapType ExactMatchMap;
34         typedef typename RegexMatchContainer::MapType RegexMatchMap;
35
36         typedef typename ExactMatchContainer::MapValueType MapValueType;
37         
38         typedef typename ExactMatchContainer::SharedPointer ExactMatchContainerSP;
39         typedef typename RegexMatchContainer::SharedPointer RegexMatchContainerSP;
40         
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))
46         {
47         }
48         
49         ~FormatterContainerPair () = default;
50         
51         ExactMatchContainerSP
52         GetExactMatch () const
53         {
54             return m_exact_sp;
55         }
56         
57         RegexMatchContainerSP
58         GetRegexMatch () const
59         {
60             return m_regex_sp;
61         }
62         
63     private:
64         ExactMatchContainerSP m_exact_sp;
65         RegexMatchContainerSP m_regex_sp;
66     };
67
68     class TypeCategoryImpl
69     {
70     private:
71         typedef FormatterContainerPair<TypeFormatImpl> FormatContainer;
72         typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer;
73         typedef FormatterContainerPair<TypeFilterImpl> FilterContainer;
74         typedef FormatterContainerPair<TypeValidatorImpl> ValidatorContainer;
75         
76 #ifndef LLDB_DISABLE_PYTHON
77         typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer;
78 #endif // #ifndef LLDB_DISABLE_PYTHON
79
80     public:
81         
82         typedef uint16_t FormatCategoryItems;
83         static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
84
85         typedef FormatContainer::ExactMatchContainerSP FormatContainerSP;
86         typedef FormatContainer::RegexMatchContainerSP RegexFormatContainerSP;
87         
88         typedef SummaryContainer::ExactMatchContainerSP SummaryContainerSP;
89         typedef SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP;
90
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
97         
98         typedef ValidatorContainer::ExactMatchContainerSP ValidatorContainerSP;
99         typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP;
100         
101         TypeCategoryImpl (IFormatChangeListener* clist,
102                           ConstString name);
103         
104         FormatContainerSP
105         GetTypeFormatsContainer ()
106         {
107             return m_format_cont.GetExactMatch();
108         }
109         
110         RegexFormatContainerSP
111         GetRegexTypeFormatsContainer ()
112         {
113             return m_format_cont.GetRegexMatch();
114         }
115         
116         SummaryContainerSP
117         GetTypeSummariesContainer ()
118         {
119             return m_summary_cont.GetExactMatch();
120         }
121         
122         RegexSummaryContainerSP
123         GetRegexTypeSummariesContainer ()
124         {
125             return m_summary_cont.GetRegexMatch();
126         }
127         
128         FilterContainerSP
129         GetTypeFiltersContainer ()
130         {
131             return m_filter_cont.GetExactMatch();
132         }
133         
134         RegexFilterContainerSP
135         GetRegexTypeFiltersContainer ()
136         {
137             return m_filter_cont.GetRegexMatch();
138         }
139
140         FormatContainer::MapValueType
141         GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
142         
143         SummaryContainer::MapValueType
144         GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
145         
146         FilterContainer::MapValueType
147         GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
148         
149 #ifndef LLDB_DISABLE_PYTHON
150         SynthContainer::MapValueType
151         GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
152 #endif
153         
154         ValidatorContainer::MapValueType
155         GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
156         
157         lldb::TypeNameSpecifierImplSP
158         GetTypeNameSpecifierForFormatAtIndex (size_t index);
159         
160         lldb::TypeNameSpecifierImplSP
161         GetTypeNameSpecifierForSummaryAtIndex (size_t index);
162
163         FormatContainer::MapValueType
164         GetFormatAtIndex (size_t index);
165         
166         SummaryContainer::MapValueType
167         GetSummaryAtIndex (size_t index);
168         
169         FilterContainer::MapValueType
170         GetFilterAtIndex (size_t index);
171         
172         lldb::TypeNameSpecifierImplSP
173         GetTypeNameSpecifierForFilterAtIndex (size_t index);
174         
175 #ifndef LLDB_DISABLE_PYTHON
176         SynthContainerSP
177         GetTypeSyntheticsContainer ()
178         {
179             return m_synth_cont.GetExactMatch();
180         }
181         
182         RegexSynthContainerSP
183         GetRegexTypeSyntheticsContainer ()
184         {
185             return m_synth_cont.GetRegexMatch();
186         }
187         
188         SynthContainer::MapValueType
189         GetSyntheticAtIndex (size_t index);
190         
191         lldb::TypeNameSpecifierImplSP
192         GetTypeNameSpecifierForSyntheticAtIndex (size_t index);
193 #endif // #ifndef LLDB_DISABLE_PYTHON
194         
195         ValidatorContainerSP
196         GetTypeValidatorsContainer ()
197         {
198             return m_validator_cont.GetExactMatch();
199         }
200         
201         RegexValidatorContainerSP
202         GetRegexTypeValidatorsContainer ()
203         {
204             return m_validator_cont.GetRegexMatch();
205         }
206         
207         ValidatorContainer::MapValueType
208         GetValidatorAtIndex (size_t index);
209         
210         lldb::TypeNameSpecifierImplSP
211         GetTypeNameSpecifierForValidatorAtIndex (size_t index);
212         
213         bool
214         IsEnabled () const
215         {
216             return m_enabled;
217         }
218         
219         uint32_t
220         GetEnabledPosition()
221         {
222             if (m_enabled == false)
223                 return UINT32_MAX;
224             else
225                 return m_enabled_position;
226         }
227         
228         bool
229         Get (ValueObject& valobj,
230              const FormattersMatchVector& candidates,
231              lldb::TypeFormatImplSP& entry,
232              uint32_t* reason = NULL);
233         
234         bool
235         Get (ValueObject& valobj,
236              const FormattersMatchVector& candidates,
237              lldb::TypeSummaryImplSP& entry,
238              uint32_t* reason = NULL);
239         
240         bool
241         Get (ValueObject& valobj,
242              const FormattersMatchVector& candidates,
243              lldb::SyntheticChildrenSP& entry,
244              uint32_t* reason = NULL);
245         
246         bool
247         Get (ValueObject& valobj,
248              const FormattersMatchVector& candidates,
249              lldb::TypeValidatorImplSP& entry,
250              uint32_t* reason = NULL);
251         
252         void
253         Clear (FormatCategoryItems items = ALL_ITEM_TYPES);
254         
255         bool
256         Delete (ConstString name,
257                 FormatCategoryItems items = ALL_ITEM_TYPES);
258         
259         uint32_t
260         GetCount (FormatCategoryItems items = ALL_ITEM_TYPES);
261         
262         const char*
263         GetName ()
264         {
265             return m_name.GetCString();
266         }
267         
268         bool
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);
274         
275         typedef std::shared_ptr<TypeCategoryImpl> SharedPointer;
276         
277     private:
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;
285         
286         bool m_enabled;
287         
288         IFormatChangeListener* m_change_listener;
289         
290         Mutex m_mutex;
291         
292         ConstString m_name;
293         
294         uint32_t m_enabled_position;
295         
296         void
297         Enable (bool value, uint32_t position);
298         
299         void
300         Disable ()
301         {
302             Enable(false, UINT32_MAX);
303         }
304         
305         uint32_t
306         GetLastEnabledPosition ()
307         {
308             return m_enabled_position;
309         }
310         
311         void
312         SetEnabledPosition (uint32_t p)
313         {
314             m_enabled_position = p;
315         }
316         
317         friend class TypeCategoryMap;
318         
319         friend class FormattersContainer<ConstString, TypeFormatImpl>;
320         friend class FormattersContainer<lldb::RegularExpressionSP, TypeFormatImpl>;
321         
322         friend class FormattersContainer<ConstString, TypeSummaryImpl>;
323         friend class FormattersContainer<lldb::RegularExpressionSP, TypeSummaryImpl>;
324         
325         friend class FormattersContainer<ConstString, TypeFilterImpl>;
326         friend class FormattersContainer<lldb::RegularExpressionSP, TypeFilterImpl>;
327         
328 #ifndef LLDB_DISABLE_PYTHON
329         friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>;
330         friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>;
331 #endif // #ifndef LLDB_DISABLE_PYTHON
332         
333         friend class FormattersContainer<ConstString, TypeValidatorImpl>;
334         friend class FormattersContainer<lldb::RegularExpressionSP, TypeValidatorImpl>;
335     };
336     
337 } // namespace lldb_private
338
339 #endif  // lldb_TypeCategory_h_