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/FormatNavigator.h"
24 #include "lldb/DataFormatters/TypeCategory.h"
25 #include "lldb/DataFormatters/TypeCategoryMap.h"
29 namespace lldb_private {
31 // this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization
32 // class DataVisualization is the high-level front-end of this feature
33 // clients should refer to that class as the entry-point into the data formatters
34 // unless they have a good reason to bypass it and prefer to use this file's objects directly
36 class FormatManager : public IFormatChangeListener
38 typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap;
39 typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
42 typedef TypeCategoryMap::CallbackType CategoryCallback;
47 GetNamedSummaryNavigator ()
49 return m_named_summaries_map;
53 EnableCategory (const ConstString& category_name,
54 TypeCategoryMap::Position pos = TypeCategoryMap::Default)
56 m_categories_map.Enable(category_name,
61 DisableCategory (const ConstString& category_name)
63 m_categories_map.Disable(category_name);
67 EnableCategory (const lldb::TypeCategoryImplSP& category,
68 TypeCategoryMap::Position pos = TypeCategoryMap::Default)
70 m_categories_map.Enable(category,
75 DisableCategory (const lldb::TypeCategoryImplSP& category)
77 m_categories_map.Disable(category);
81 DeleteCategory (const ConstString& category_name)
83 return m_categories_map.Delete(category_name);
89 return m_categories_map.Clear();
95 return m_categories_map.GetCount();
98 lldb::TypeCategoryImplSP
99 GetCategoryAtIndex (size_t index)
101 return m_categories_map.GetAtIndex(index);
105 LoopThroughCategories (CategoryCallback callback, void* param)
107 m_categories_map.LoopThrough(callback, param);
110 lldb::TypeCategoryImplSP
111 GetCategory (const char* category_name = NULL,
112 bool can_create = true)
115 return GetCategory(m_default_category_name);
116 return GetCategory(ConstString(category_name));
119 lldb::TypeCategoryImplSP
120 GetCategory (const ConstString& category_name,
121 bool can_create = true);
123 lldb::TypeFormatImplSP
124 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
126 lldb::TypeSummaryImplSP
127 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
129 lldb::TypeFilterImplSP
130 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
132 #ifndef LLDB_DISABLE_PYTHON
133 lldb::ScriptedSyntheticChildrenSP
134 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
137 #ifndef LLDB_DISABLE_PYTHON
138 lldb::SyntheticChildrenSP
139 GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
142 lldb::TypeFormatImplSP
143 GetFormat (ValueObject& valobj,
144 lldb::DynamicValueType use_dynamic);
146 lldb::TypeSummaryImplSP
147 GetSummaryFormat (ValueObject& valobj,
148 lldb::DynamicValueType use_dynamic);
150 #ifndef LLDB_DISABLE_PYTHON
151 lldb::SyntheticChildrenSP
152 GetSyntheticChildren (ValueObject& valobj,
153 lldb::DynamicValueType use_dynamic);
157 AnyMatches (ConstString type_name,
158 TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
159 bool only_enabled = true,
160 const char** matching_category = NULL,
161 TypeCategoryImpl::FormatCategoryItems* matching_type = NULL)
163 return m_categories_map.AnyMatches(type_name,
171 GetFormatFromCString (const char *format_cstr,
172 bool partial_match_ok,
173 lldb::Format &format);
176 GetFormatAsFormatChar (lldb::Format format);
179 GetFormatAsCString (lldb::Format format);
181 // if the user tries to add formatters for, say, "struct Foo"
182 // those will not match any type because of the way we strip qualifiers from typenames
183 // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
184 // and strips the unnecessary qualifier
186 GetValidTypeName (const ConstString& type);
188 // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item
189 // this method returns it, or eFormatInvalid if vector_format is not a vectorOf
191 GetSingleItemFormat (lldb::Format vector_format);
193 // this returns true if the ValueObjectPrinter is *highly encouraged*
194 // to actually represent this ValueObject in one-liner format
195 // If this object has a summary formatter, however, we should not
196 // try and do one-lining, just let the summary do the right thing
198 ShouldPrintAsOneLiner (ValueObject& valobj);
204 m_format_cache.Clear ();
208 GetCurrentRevision ()
210 return m_last_revision;
217 static FormattersMatchVector
218 GetPossibleMatches (ValueObject& valobj,
219 lldb::DynamicValueType use_dynamic)
221 FormattersMatchVector matches;
222 GetPossibleMatches (valobj,
223 valobj.GetClangType(),
224 lldb_private::eFormatterChoiceCriterionDirectChoice,
237 GetPossibleMatches (ValueObject& valobj,
238 ClangASTType clang_type,
240 lldb::DynamicValueType use_dynamic,
241 FormattersMatchVector& entries,
244 bool did_strip_typedef,
245 bool root_level = false);
247 FormatCache m_format_cache;
248 NamedSummariesMap m_named_summaries_map;
249 std::atomic<uint32_t> m_last_revision;
250 TypeCategoryMap m_categories_map;
252 ConstString m_default_category_name;
253 ConstString m_system_category_name;
254 ConstString m_gnu_cpp_category_name;
255 ConstString m_libcxx_category_name;
256 ConstString m_objc_category_name;
257 ConstString m_corefoundation_category_name;
258 ConstString m_coregraphics_category_name;
259 ConstString m_coreservices_category_name;
260 ConstString m_vectortypes_category_name;
261 ConstString m_appkit_category_name;
266 return m_categories_map;
269 // WARNING: these are temporary functions that setup formatters
270 // while a few of these actually should be globally available and setup by LLDB itself
271 // most would actually belong to the users' lldbinit file or to some other form of configurable
274 LoadLibStdcppFormatters ();
277 LoadLibcxxFormatters ();
280 LoadSystemFormatters ();
283 LoadObjCFormatters ();
286 } // namespace lldb_private
288 #endif // lldb_FormatManager_h_