]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormatManager.h
Restore packaging subdir to enable running unmodified configure script.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / FormatManager.h
1 //===-- FormatManager.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_FormatManager_h_
11 #define lldb_FormatManager_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/FormatCache.h"
22 #include "lldb/DataFormatters/FormatClasses.h"
23 #include "lldb/DataFormatters/FormattersContainer.h"
24 #include "lldb/DataFormatters/TypeCategory.h"
25 #include "lldb/DataFormatters/TypeCategoryMap.h"
26
27 #include <atomic>
28 #include <functional>
29
30 namespace lldb_private {
31     
32 // this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization
33 // class DataVisualization is the high-level front-end of this feature
34 // clients should refer to that class as the entry-point into the data formatters
35 // unless they have a good reason to bypass it and prefer to use this file's objects directly
36
37 class FormatManager : public IFormatChangeListener
38 {
39     typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap;
40     typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
41 public:
42     
43     template <typename FormatterType>
44     using HardcodedFormatterFinder = std::function<typename FormatterType::SharedPointer (lldb_private::ValueObject&,
45                                                                                           lldb::DynamicValueType,
46                                                                                           FormatManager&)>;
47     
48     template <typename FormatterType>
49     using HardcodedFormatterFinders = std::vector<HardcodedFormatterFinder<FormatterType>>;
50     
51     typedef TypeCategoryMap::CallbackType CategoryCallback;
52     
53     FormatManager ();
54     
55     NamedSummariesMap&
56     GetNamedSummaryContainer ()
57     {
58         return m_named_summaries_map;
59     }
60     
61     void
62     EnableCategory (const ConstString& category_name,
63                     TypeCategoryMap::Position pos = TypeCategoryMap::Default)
64     {
65         m_categories_map.Enable(category_name,
66                                 pos);
67     }
68     
69     void
70     DisableCategory (const ConstString& category_name)
71     {
72         m_categories_map.Disable(category_name);
73     }
74     
75     void
76     EnableCategory (const lldb::TypeCategoryImplSP& category,
77                     TypeCategoryMap::Position pos = TypeCategoryMap::Default)
78     {
79         m_categories_map.Enable(category,
80                                 pos);
81     }
82     
83     void
84     DisableCategory (const lldb::TypeCategoryImplSP& category)
85     {
86         m_categories_map.Disable(category);
87     }
88     
89     void
90     EnableAllCategories ()
91     {
92         m_categories_map.EnableAllCategories ();
93     }
94     
95     void
96     DisableAllCategories ()
97     {
98         m_categories_map.DisableAllCategories ();
99     }
100     
101     bool
102     DeleteCategory (const ConstString& category_name)
103     {
104         return m_categories_map.Delete(category_name);
105     }
106     
107     void
108     ClearCategories ()
109     {
110         return m_categories_map.Clear();
111     }
112     
113     uint32_t
114     GetCategoriesCount ()
115     {
116         return m_categories_map.GetCount();
117     }
118     
119     lldb::TypeCategoryImplSP
120     GetCategoryAtIndex (size_t index)
121     {
122         return m_categories_map.GetAtIndex(index);
123     }
124     
125     void
126     LoopThroughCategories (CategoryCallback callback, void* param)
127     {
128         m_categories_map.LoopThrough(callback, param);
129     }
130     
131     lldb::TypeCategoryImplSP
132     GetCategory (const char* category_name = NULL,
133                  bool can_create = true)
134     {
135         if (!category_name)
136             return GetCategory(m_default_category_name);
137         return GetCategory(ConstString(category_name));
138     }
139     
140     lldb::TypeCategoryImplSP
141     GetCategory (const ConstString& category_name,
142                  bool can_create = true);
143
144     lldb::TypeFormatImplSP
145     GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
146     
147     lldb::TypeSummaryImplSP
148     GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
149
150     lldb::TypeFilterImplSP
151     GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
152
153 #ifndef LLDB_DISABLE_PYTHON
154     lldb::ScriptedSyntheticChildrenSP
155     GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
156 #endif
157     
158 #ifndef LLDB_DISABLE_PYTHON
159     lldb::SyntheticChildrenSP
160     GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
161 #endif
162     
163     lldb::TypeValidatorImplSP
164     GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
165     
166     lldb::TypeFormatImplSP
167     GetFormat (ValueObject& valobj,
168                lldb::DynamicValueType use_dynamic);
169     
170     lldb::TypeSummaryImplSP
171     GetSummaryFormat (ValueObject& valobj,
172                       lldb::DynamicValueType use_dynamic);
173
174 #ifndef LLDB_DISABLE_PYTHON
175     lldb::SyntheticChildrenSP
176     GetSyntheticChildren (ValueObject& valobj,
177                           lldb::DynamicValueType use_dynamic);
178 #endif
179     
180     lldb::TypeValidatorImplSP
181     GetValidator (ValueObject& valobj,
182                   lldb::DynamicValueType use_dynamic);
183     
184     bool
185     AnyMatches (ConstString type_name,
186                 TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
187                 bool only_enabled = true,
188                 const char** matching_category = NULL,
189                 TypeCategoryImpl::FormatCategoryItems* matching_type = NULL)
190     {
191         return m_categories_map.AnyMatches(type_name,
192                                            items,
193                                            only_enabled,
194                                            matching_category,
195                                            matching_type);
196     }
197
198     static bool
199     GetFormatFromCString (const char *format_cstr,
200                           bool partial_match_ok,
201                           lldb::Format &format);
202
203     static char
204     GetFormatAsFormatChar (lldb::Format format);
205
206     static const char *
207     GetFormatAsCString (lldb::Format format);
208     
209     // if the user tries to add formatters for, say, "struct Foo"
210     // those will not match any type because of the way we strip qualifiers from typenames
211     // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
212     // and strips the unnecessary qualifier
213     static ConstString
214     GetValidTypeName (const ConstString& type);
215     
216     // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item
217     // this method returns it, or eFormatInvalid if vector_format is not a vectorOf
218     static lldb::Format
219     GetSingleItemFormat (lldb::Format vector_format);
220     
221     // this returns true if the ValueObjectPrinter is *highly encouraged*
222     // to actually represent this ValueObject in one-liner format
223     // If this object has a summary formatter, however, we should not
224     // try and do one-lining, just let the summary do the right thing
225     bool
226     ShouldPrintAsOneLiner (ValueObject& valobj);
227     
228     void
229     Changed ()
230     {
231         ++m_last_revision;
232         m_format_cache.Clear ();
233     }
234     
235     uint32_t
236     GetCurrentRevision ()
237     {
238         return m_last_revision;
239     }
240     
241     ~FormatManager ()
242     {
243     }
244     
245     static FormattersMatchVector
246     GetPossibleMatches (ValueObject& valobj,
247                         lldb::DynamicValueType use_dynamic)
248     {
249         FormattersMatchVector matches;
250         GetPossibleMatches (valobj,
251                             valobj.GetClangType(),
252                             lldb_private::eFormatterChoiceCriterionDirectChoice,
253                             use_dynamic,
254                             matches,
255                             false,
256                             false,
257                             false,
258                             true);
259         return matches;
260     }
261
262 private:
263     
264     static void
265     GetPossibleMatches (ValueObject& valobj,
266                         ClangASTType clang_type,
267                         uint32_t reason,
268                         lldb::DynamicValueType use_dynamic,
269                         FormattersMatchVector& entries,
270                         bool did_strip_ptr,
271                         bool did_strip_ref,
272                         bool did_strip_typedef,
273                         bool root_level = false);
274     
275     FormatCache m_format_cache;
276     NamedSummariesMap m_named_summaries_map;
277     std::atomic<uint32_t> m_last_revision;
278     TypeCategoryMap m_categories_map;
279     
280     ConstString m_default_category_name;
281     ConstString m_system_category_name;
282     ConstString m_gnu_cpp_category_name;
283     ConstString m_libcxx_category_name;
284     ConstString m_objc_category_name;
285     ConstString m_corefoundation_category_name;
286     ConstString m_coregraphics_category_name;
287     ConstString m_coreservices_category_name;
288     ConstString m_vectortypes_category_name;
289     ConstString m_appkit_category_name;
290     
291     HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
292     HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
293     HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
294     HardcodedFormatterFinders<TypeValidatorImpl> m_hardcoded_validators;
295     
296     lldb::TypeFormatImplSP
297     GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
298     
299     lldb::TypeSummaryImplSP
300     GetHardcodedSummaryFormat (ValueObject&,lldb::DynamicValueType);
301
302     lldb::SyntheticChildrenSP
303     GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);
304     
305     lldb::TypeValidatorImplSP
306     GetHardcodedValidator (ValueObject&,lldb::DynamicValueType);
307     
308     TypeCategoryMap&
309     GetCategories ()
310     {
311         return m_categories_map;
312     }
313     
314     // WARNING: these are temporary functions that setup formatters
315     // while a few of these actually should be globally available and setup by LLDB itself
316     // most would actually belong to the users' lldbinit file or to some other form of configurable
317     // storage
318     void
319     LoadLibStdcppFormatters ();
320     
321     void
322     LoadLibcxxFormatters ();
323     
324     void
325     LoadSystemFormatters ();
326     
327     void
328     LoadObjCFormatters ();
329     
330     void
331     LoadHardcodedFormatters ();
332 };
333     
334 } // namespace lldb_private
335     
336 #endif  // lldb_FormatManager_h_