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 DeleteCategory (const ConstString& category_name)
92 return m_categories_map.Delete(category_name);
98 return m_categories_map.Clear();
102 GetCategoriesCount ()
104 return m_categories_map.GetCount();
107 lldb::TypeCategoryImplSP
108 GetCategoryAtIndex (size_t index)
110 return m_categories_map.GetAtIndex(index);
114 LoopThroughCategories (CategoryCallback callback, void* param)
116 m_categories_map.LoopThrough(callback, param);
119 lldb::TypeCategoryImplSP
120 GetCategory (const char* category_name = NULL,
121 bool can_create = true)
124 return GetCategory(m_default_category_name);
125 return GetCategory(ConstString(category_name));
128 lldb::TypeCategoryImplSP
129 GetCategory (const ConstString& category_name,
130 bool can_create = true);
132 lldb::TypeFormatImplSP
133 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
135 lldb::TypeSummaryImplSP
136 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
138 lldb::TypeFilterImplSP
139 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
141 #ifndef LLDB_DISABLE_PYTHON
142 lldb::ScriptedSyntheticChildrenSP
143 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
146 #ifndef LLDB_DISABLE_PYTHON
147 lldb::SyntheticChildrenSP
148 GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
151 lldb::TypeFormatImplSP
152 GetFormat (ValueObject& valobj,
153 lldb::DynamicValueType use_dynamic);
155 lldb::TypeSummaryImplSP
156 GetSummaryFormat (ValueObject& valobj,
157 lldb::DynamicValueType use_dynamic);
159 #ifndef LLDB_DISABLE_PYTHON
160 lldb::SyntheticChildrenSP
161 GetSyntheticChildren (ValueObject& valobj,
162 lldb::DynamicValueType use_dynamic);
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)
172 return m_categories_map.AnyMatches(type_name,
180 GetFormatFromCString (const char *format_cstr,
181 bool partial_match_ok,
182 lldb::Format &format);
185 GetFormatAsFormatChar (lldb::Format format);
188 GetFormatAsCString (lldb::Format format);
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
195 GetValidTypeName (const ConstString& type);
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
200 GetSingleItemFormat (lldb::Format vector_format);
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
207 ShouldPrintAsOneLiner (ValueObject& valobj);
213 m_format_cache.Clear ();
217 GetCurrentRevision ()
219 return m_last_revision;
226 static FormattersMatchVector
227 GetPossibleMatches (ValueObject& valobj,
228 lldb::DynamicValueType use_dynamic)
230 FormattersMatchVector matches;
231 GetPossibleMatches (valobj,
232 valobj.GetClangType(),
233 lldb_private::eFormatterChoiceCriterionDirectChoice,
246 GetPossibleMatches (ValueObject& valobj,
247 ClangASTType clang_type,
249 lldb::DynamicValueType use_dynamic,
250 FormattersMatchVector& entries,
253 bool did_strip_typedef,
254 bool root_level = false);
256 FormatCache m_format_cache;
257 NamedSummariesMap m_named_summaries_map;
258 std::atomic<uint32_t> m_last_revision;
259 TypeCategoryMap m_categories_map;
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;
272 HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
273 HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
274 HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
276 lldb::TypeFormatImplSP
277 GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
279 lldb::TypeSummaryImplSP
280 GetHardcodedSummaryFormat (ValueObject&,lldb::DynamicValueType);
282 lldb::SyntheticChildrenSP
283 GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);
288 return m_categories_map;
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
296 LoadLibStdcppFormatters ();
299 LoadLibcxxFormatters ();
302 LoadSystemFormatters ();
305 LoadObjCFormatters ();
308 LoadHardcodedFormatters ();
311 } // namespace lldb_private
313 #endif // lldb_FormatManager_h_