]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormatManager.h
Merge llvm 3.6.0rc1 from ^/vendor/llvm/dist, merge clang 3.6.0rc1 from
[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     bool
90     DeleteCategory (const ConstString& category_name)
91     {
92         return m_categories_map.Delete(category_name);
93     }
94     
95     void
96     ClearCategories ()
97     {
98         return m_categories_map.Clear();
99     }
100     
101     uint32_t
102     GetCategoriesCount ()
103     {
104         return m_categories_map.GetCount();
105     }
106     
107     lldb::TypeCategoryImplSP
108     GetCategoryAtIndex (size_t index)
109     {
110         return m_categories_map.GetAtIndex(index);
111     }
112     
113     void
114     LoopThroughCategories (CategoryCallback callback, void* param)
115     {
116         m_categories_map.LoopThrough(callback, param);
117     }
118     
119     lldb::TypeCategoryImplSP
120     GetCategory (const char* category_name = NULL,
121                  bool can_create = true)
122     {
123         if (!category_name)
124             return GetCategory(m_default_category_name);
125         return GetCategory(ConstString(category_name));
126     }
127     
128     lldb::TypeCategoryImplSP
129     GetCategory (const ConstString& category_name,
130                  bool can_create = true);
131
132     lldb::TypeFormatImplSP
133     GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
134     
135     lldb::TypeSummaryImplSP
136     GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
137
138     lldb::TypeFilterImplSP
139     GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
140
141 #ifndef LLDB_DISABLE_PYTHON
142     lldb::ScriptedSyntheticChildrenSP
143     GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
144 #endif
145     
146 #ifndef LLDB_DISABLE_PYTHON
147     lldb::SyntheticChildrenSP
148     GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
149 #endif
150     
151     lldb::TypeFormatImplSP
152     GetFormat (ValueObject& valobj,
153                lldb::DynamicValueType use_dynamic);
154     
155     lldb::TypeSummaryImplSP
156     GetSummaryFormat (ValueObject& valobj,
157                       lldb::DynamicValueType use_dynamic);
158
159 #ifndef LLDB_DISABLE_PYTHON
160     lldb::SyntheticChildrenSP
161     GetSyntheticChildren (ValueObject& valobj,
162                           lldb::DynamicValueType use_dynamic);
163 #endif
164     
165     bool
166     AnyMatches (ConstString type_name,
167                 TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
168                 bool only_enabled = true,
169                 const char** matching_category = NULL,
170                 TypeCategoryImpl::FormatCategoryItems* matching_type = NULL)
171     {
172         return m_categories_map.AnyMatches(type_name,
173                                            items,
174                                            only_enabled,
175                                            matching_category,
176                                            matching_type);
177     }
178
179     static bool
180     GetFormatFromCString (const char *format_cstr,
181                           bool partial_match_ok,
182                           lldb::Format &format);
183
184     static char
185     GetFormatAsFormatChar (lldb::Format format);
186
187     static const char *
188     GetFormatAsCString (lldb::Format format);
189     
190     // if the user tries to add formatters for, say, "struct Foo"
191     // those will not match any type because of the way we strip qualifiers from typenames
192     // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
193     // and strips the unnecessary qualifier
194     static ConstString
195     GetValidTypeName (const ConstString& type);
196     
197     // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item
198     // this method returns it, or eFormatInvalid if vector_format is not a vectorOf
199     static lldb::Format
200     GetSingleItemFormat (lldb::Format vector_format);
201     
202     // this returns true if the ValueObjectPrinter is *highly encouraged*
203     // to actually represent this ValueObject in one-liner format
204     // If this object has a summary formatter, however, we should not
205     // try and do one-lining, just let the summary do the right thing
206     bool
207     ShouldPrintAsOneLiner (ValueObject& valobj);
208     
209     void
210     Changed ()
211     {
212         ++m_last_revision;
213         m_format_cache.Clear ();
214     }
215     
216     uint32_t
217     GetCurrentRevision ()
218     {
219         return m_last_revision;
220     }
221     
222     ~FormatManager ()
223     {
224     }
225     
226     static FormattersMatchVector
227     GetPossibleMatches (ValueObject& valobj,
228                         lldb::DynamicValueType use_dynamic)
229     {
230         FormattersMatchVector matches;
231         GetPossibleMatches (valobj,
232                             valobj.GetClangType(),
233                             lldb_private::eFormatterChoiceCriterionDirectChoice,
234                             use_dynamic,
235                             matches,
236                             false,
237                             false,
238                             false,
239                             true);
240         return matches;
241     }
242
243 private:
244     
245     static void
246     GetPossibleMatches (ValueObject& valobj,
247                         ClangASTType clang_type,
248                         uint32_t reason,
249                         lldb::DynamicValueType use_dynamic,
250                         FormattersMatchVector& entries,
251                         bool did_strip_ptr,
252                         bool did_strip_ref,
253                         bool did_strip_typedef,
254                         bool root_level = false);
255     
256     FormatCache m_format_cache;
257     NamedSummariesMap m_named_summaries_map;
258     std::atomic<uint32_t> m_last_revision;
259     TypeCategoryMap m_categories_map;
260     
261     ConstString m_default_category_name;
262     ConstString m_system_category_name;
263     ConstString m_gnu_cpp_category_name;
264     ConstString m_libcxx_category_name;
265     ConstString m_objc_category_name;
266     ConstString m_corefoundation_category_name;
267     ConstString m_coregraphics_category_name;
268     ConstString m_coreservices_category_name;
269     ConstString m_vectortypes_category_name;
270     ConstString m_appkit_category_name;
271     
272     HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
273     HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
274     HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
275     
276     lldb::TypeFormatImplSP
277     GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
278     
279     lldb::TypeSummaryImplSP
280     GetHardcodedSummaryFormat (ValueObject&,lldb::DynamicValueType);
281
282     lldb::SyntheticChildrenSP
283     GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);
284     
285     TypeCategoryMap&
286     GetCategories ()
287     {
288         return m_categories_map;
289     }
290     
291     // WARNING: these are temporary functions that setup formatters
292     // while a few of these actually should be globally available and setup by LLDB itself
293     // most would actually belong to the users' lldbinit file or to some other form of configurable
294     // storage
295     void
296     LoadLibStdcppFormatters ();
297     
298     void
299     LoadLibcxxFormatters ();
300     
301     void
302     LoadSystemFormatters ();
303     
304     void
305     LoadObjCFormatters ();
306     
307     void
308     LoadHardcodedFormatters ();
309 };
310     
311 } // namespace lldb_private
312     
313 #endif  // lldb_FormatManager_h_