1 //===-- FormatManager.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_FormatManager_h_
11 #define lldb_FormatManager_h_
16 // Other libraries and framework includes
18 #include "lldb/lldb-public.h"
19 #include "lldb/lldb-enumerations.h"
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"
30 namespace lldb_private {
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
37 class FormatManager : public IFormatChangeListener
39 typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap;
40 typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
43 template <typename FormatterType>
44 using HardcodedFormatterFinder = std::function<typename FormatterType::SharedPointer (lldb_private::ValueObject&,
45 lldb::DynamicValueType,
48 template <typename FormatterType>
49 using HardcodedFormatterFinders = std::vector<HardcodedFormatterFinder<FormatterType>>;
51 typedef TypeCategoryMap::CallbackType CategoryCallback;
56 GetNamedSummaryContainer ()
58 return m_named_summaries_map;
62 EnableCategory (const ConstString& category_name,
63 TypeCategoryMap::Position pos = TypeCategoryMap::Default)
65 m_categories_map.Enable(category_name,
70 DisableCategory (const ConstString& category_name)
72 m_categories_map.Disable(category_name);
76 EnableCategory (const lldb::TypeCategoryImplSP& category,
77 TypeCategoryMap::Position pos = TypeCategoryMap::Default)
79 m_categories_map.Enable(category,
84 DisableCategory (const lldb::TypeCategoryImplSP& category)
86 m_categories_map.Disable(category);
90 EnableAllCategories ()
92 m_categories_map.EnableAllCategories ();
96 DisableAllCategories ()
98 m_categories_map.DisableAllCategories ();
102 DeleteCategory (const ConstString& category_name)
104 return m_categories_map.Delete(category_name);
110 return m_categories_map.Clear();
114 GetCategoriesCount ()
116 return m_categories_map.GetCount();
119 lldb::TypeCategoryImplSP
120 GetCategoryAtIndex (size_t index)
122 return m_categories_map.GetAtIndex(index);
126 LoopThroughCategories (CategoryCallback callback, void* param)
128 m_categories_map.LoopThrough(callback, param);
131 lldb::TypeCategoryImplSP
132 GetCategory (const char* category_name = NULL,
133 bool can_create = true)
136 return GetCategory(m_default_category_name);
137 return GetCategory(ConstString(category_name));
140 lldb::TypeCategoryImplSP
141 GetCategory (const ConstString& category_name,
142 bool can_create = true);
144 lldb::TypeFormatImplSP
145 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
147 lldb::TypeSummaryImplSP
148 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
150 lldb::TypeFilterImplSP
151 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
153 #ifndef LLDB_DISABLE_PYTHON
154 lldb::ScriptedSyntheticChildrenSP
155 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
158 #ifndef LLDB_DISABLE_PYTHON
159 lldb::SyntheticChildrenSP
160 GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
163 lldb::TypeValidatorImplSP
164 GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
166 lldb::TypeFormatImplSP
167 GetFormat (ValueObject& valobj,
168 lldb::DynamicValueType use_dynamic);
170 lldb::TypeSummaryImplSP
171 GetSummaryFormat (ValueObject& valobj,
172 lldb::DynamicValueType use_dynamic);
174 #ifndef LLDB_DISABLE_PYTHON
175 lldb::SyntheticChildrenSP
176 GetSyntheticChildren (ValueObject& valobj,
177 lldb::DynamicValueType use_dynamic);
180 lldb::TypeValidatorImplSP
181 GetValidator (ValueObject& valobj,
182 lldb::DynamicValueType use_dynamic);
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)
191 return m_categories_map.AnyMatches(type_name,
199 GetFormatFromCString (const char *format_cstr,
200 bool partial_match_ok,
201 lldb::Format &format);
204 GetFormatAsFormatChar (lldb::Format format);
207 GetFormatAsCString (lldb::Format format);
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
214 GetValidTypeName (const ConstString& type);
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
219 GetSingleItemFormat (lldb::Format vector_format);
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
226 ShouldPrintAsOneLiner (ValueObject& valobj);
232 m_format_cache.Clear ();
236 GetCurrentRevision ()
238 return m_last_revision;
245 static FormattersMatchVector
246 GetPossibleMatches (ValueObject& valobj,
247 lldb::DynamicValueType use_dynamic)
249 FormattersMatchVector matches;
250 GetPossibleMatches (valobj,
251 valobj.GetClangType(),
252 lldb_private::eFormatterChoiceCriterionDirectChoice,
265 GetPossibleMatches (ValueObject& valobj,
266 ClangASTType clang_type,
268 lldb::DynamicValueType use_dynamic,
269 FormattersMatchVector& entries,
272 bool did_strip_typedef,
273 bool root_level = false);
275 FormatCache m_format_cache;
276 NamedSummariesMap m_named_summaries_map;
277 std::atomic<uint32_t> m_last_revision;
278 TypeCategoryMap m_categories_map;
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;
291 HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
292 HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
293 HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
294 HardcodedFormatterFinders<TypeValidatorImpl> m_hardcoded_validators;
296 lldb::TypeFormatImplSP
297 GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
299 lldb::TypeSummaryImplSP
300 GetHardcodedSummaryFormat (ValueObject&,lldb::DynamicValueType);
302 lldb::SyntheticChildrenSP
303 GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);
305 lldb::TypeValidatorImplSP
306 GetHardcodedValidator (ValueObject&,lldb::DynamicValueType);
311 return m_categories_map;
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
319 LoadLibStdcppFormatters ();
322 LoadLibcxxFormatters ();
325 LoadSystemFormatters ();
328 LoadObjCFormatters ();
331 LoadHardcodedFormatters ();
334 } // namespace lldb_private
336 #endif // lldb_FormatManager_h_