TypeCategory.h revision 263363
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/FormatNavigator.h"
22
23namespace lldb_private {
24    class TypeCategoryImpl
25    {
26    private:
27        typedef FormatNavigator<ConstString, TypeFormatImpl> ValueNavigator;
28        typedef FormatNavigator<lldb::RegularExpressionSP, TypeFormatImpl> RegexValueNavigator;
29
30        typedef FormatNavigator<ConstString, TypeSummaryImpl> SummaryNavigator;
31        typedef FormatNavigator<lldb::RegularExpressionSP, TypeSummaryImpl> RegexSummaryNavigator;
32
33        typedef FormatNavigator<ConstString, TypeFilterImpl> FilterNavigator;
34        typedef FormatNavigator<lldb::RegularExpressionSP, TypeFilterImpl> RegexFilterNavigator;
35
36#ifndef LLDB_DISABLE_PYTHON
37        typedef FormatNavigator<ConstString, ScriptedSyntheticChildren> SynthNavigator;
38        typedef FormatNavigator<lldb::RegularExpressionSP, ScriptedSyntheticChildren> RegexSynthNavigator;
39#endif // #ifndef LLDB_DISABLE_PYTHON
40
41        typedef ValueNavigator::MapType ValueMap;
42        typedef RegexValueNavigator::MapType RegexValueMap;
43
44        typedef SummaryNavigator::MapType SummaryMap;
45        typedef RegexSummaryNavigator::MapType RegexSummaryMap;
46
47        typedef FilterNavigator::MapType FilterMap;
48        typedef RegexFilterNavigator::MapType RegexFilterMap;
49
50#ifndef LLDB_DISABLE_PYTHON
51        typedef SynthNavigator::MapType SynthMap;
52        typedef RegexSynthNavigator::MapType RegexSynthMap;
53#endif // #ifndef LLDB_DISABLE_PYTHON
54
55    public:
56
57        typedef uint16_t FormatCategoryItems;
58        static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
59
60        typedef ValueNavigator::SharedPointer ValueNavigatorSP;
61        typedef RegexValueNavigator::SharedPointer RegexValueNavigatorSP;
62
63        typedef SummaryNavigator::SharedPointer SummaryNavigatorSP;
64        typedef RegexSummaryNavigator::SharedPointer RegexSummaryNavigatorSP;
65
66        typedef FilterNavigator::SharedPointer FilterNavigatorSP;
67        typedef RegexFilterNavigator::SharedPointer RegexFilterNavigatorSP;
68#ifndef LLDB_DISABLE_PYTHON
69        typedef SynthNavigator::SharedPointer SynthNavigatorSP;
70        typedef RegexSynthNavigator::SharedPointer RegexSynthNavigatorSP;
71#endif // #ifndef LLDB_DISABLE_PYTHON
72
73        TypeCategoryImpl (IFormatChangeListener* clist,
74                          ConstString name);
75
76        ValueNavigatorSP
77        GetValueNavigator ()
78        {
79            return ValueNavigatorSP(m_value_nav);
80        }
81
82        RegexValueNavigatorSP
83        GetRegexValueNavigator ()
84        {
85            return RegexValueNavigatorSP(m_regex_value_nav);
86        }
87
88        SummaryNavigatorSP
89        GetSummaryNavigator ()
90        {
91            return SummaryNavigatorSP(m_summary_nav);
92        }
93
94        RegexSummaryNavigatorSP
95        GetRegexSummaryNavigator ()
96        {
97            return RegexSummaryNavigatorSP(m_regex_summary_nav);
98        }
99
100        FilterNavigatorSP
101        GetFilterNavigator ()
102        {
103            return FilterNavigatorSP(m_filter_nav);
104        }
105
106        RegexFilterNavigatorSP
107        GetRegexFilterNavigator ()
108        {
109            return RegexFilterNavigatorSP(m_regex_filter_nav);
110        }
111
112        ValueNavigator::MapValueType
113        GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
114
115        SummaryNavigator::MapValueType
116        GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
117
118        FilterNavigator::MapValueType
119        GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
120
121#ifndef LLDB_DISABLE_PYTHON
122        SynthNavigator::MapValueType
123        GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
124#endif
125
126        lldb::TypeNameSpecifierImplSP
127        GetTypeNameSpecifierForFormatAtIndex (size_t index);
128
129        lldb::TypeNameSpecifierImplSP
130        GetTypeNameSpecifierForSummaryAtIndex (size_t index);
131
132        ValueNavigator::MapValueType
133        GetFormatAtIndex (size_t index);
134
135        SummaryNavigator::MapValueType
136        GetSummaryAtIndex (size_t index);
137
138        FilterNavigator::MapValueType
139        GetFilterAtIndex (size_t index);
140
141        lldb::TypeNameSpecifierImplSP
142        GetTypeNameSpecifierForFilterAtIndex (size_t index);
143
144#ifndef LLDB_DISABLE_PYTHON
145        SynthNavigatorSP
146        GetSyntheticNavigator ()
147        {
148            return SynthNavigatorSP(m_synth_nav);
149        }
150
151        RegexSynthNavigatorSP
152        GetRegexSyntheticNavigator ()
153        {
154            return RegexSynthNavigatorSP(m_regex_synth_nav);
155        }
156
157        SynthNavigator::MapValueType
158        GetSyntheticAtIndex (size_t index);
159
160        lldb::TypeNameSpecifierImplSP
161        GetTypeNameSpecifierForSyntheticAtIndex (size_t index);
162
163#endif // #ifndef LLDB_DISABLE_PYTHON
164
165        bool
166        IsEnabled () const
167        {
168            return m_enabled;
169        }
170
171        uint32_t
172        GetEnabledPosition()
173        {
174            if (m_enabled == false)
175                return UINT32_MAX;
176            else
177                return m_enabled_position;
178        }
179
180
181        bool
182        Get (ValueObject& valobj,
183             lldb::TypeFormatImplSP& entry,
184             lldb::DynamicValueType use_dynamic,
185             uint32_t* reason = NULL);
186
187        bool
188        Get (ValueObject& valobj,
189             lldb::TypeSummaryImplSP& entry,
190             lldb::DynamicValueType use_dynamic,
191             uint32_t* reason = NULL);
192
193        bool
194        Get (ValueObject& valobj,
195             lldb::SyntheticChildrenSP& entry,
196             lldb::DynamicValueType use_dynamic,
197             uint32_t* reason = NULL);
198
199        void
200        Clear (FormatCategoryItems items = ALL_ITEM_TYPES);
201
202        bool
203        Delete (ConstString name,
204                FormatCategoryItems items = ALL_ITEM_TYPES);
205
206        uint32_t
207        GetCount (FormatCategoryItems items = ALL_ITEM_TYPES);
208
209        const char*
210        GetName ()
211        {
212            return m_name.GetCString();
213        }
214
215        bool
216        AnyMatches (ConstString type_name,
217                    FormatCategoryItems items = ALL_ITEM_TYPES,
218                    bool only_enabled = true,
219                    const char** matching_category = NULL,
220                    FormatCategoryItems* matching_type = NULL);
221
222        typedef std::shared_ptr<TypeCategoryImpl> SharedPointer;
223
224    private:
225        ValueNavigator::SharedPointer m_value_nav;
226        RegexValueNavigator::SharedPointer m_regex_value_nav;
227
228        SummaryNavigator::SharedPointer m_summary_nav;
229        RegexSummaryNavigator::SharedPointer m_regex_summary_nav;
230
231        FilterNavigator::SharedPointer m_filter_nav;
232        RegexFilterNavigator::SharedPointer m_regex_filter_nav;
233
234#ifndef LLDB_DISABLE_PYTHON
235        SynthNavigator::SharedPointer m_synth_nav;
236        RegexSynthNavigator::SharedPointer m_regex_synth_nav;
237#endif // #ifndef LLDB_DISABLE_PYTHON
238
239        bool m_enabled;
240
241        IFormatChangeListener* m_change_listener;
242
243        Mutex m_mutex;
244
245        ConstString m_name;
246
247        uint32_t m_enabled_position;
248
249        void
250        Enable (bool value, uint32_t position);
251
252        void
253        Disable ()
254        {
255            Enable(false, UINT32_MAX);
256        }
257
258        friend class TypeCategoryMap;
259
260        friend class FormatNavigator<ConstString, TypeFormatImpl>;
261        friend class FormatNavigator<lldb::RegularExpressionSP, TypeFormatImpl>;
262
263        friend class FormatNavigator<ConstString, TypeSummaryImpl>;
264        friend class FormatNavigator<lldb::RegularExpressionSP, TypeSummaryImpl>;
265
266        friend class FormatNavigator<ConstString, TypeFilterImpl>;
267        friend class FormatNavigator<lldb::RegularExpressionSP, TypeFilterImpl>;
268
269#ifndef LLDB_DISABLE_PYTHON
270        friend class FormatNavigator<ConstString, ScriptedSyntheticChildren>;
271        friend class FormatNavigator<lldb::RegularExpressionSP, ScriptedSyntheticChildren>;
272#endif // #ifndef LLDB_DISABLE_PYTHON
273    };
274
275} // namespace lldb_private
276
277#endif	// lldb_TypeCategory_h_
278