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/FormatNavigator.h"
23 #include "lldb/DataFormatters/TypeCategory.h"
24 #include "lldb/DataFormatters/TypeCategoryMap.h"
26 namespace lldb_private {
28 // this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization
29 // class DataVisualization is the high-level front-end of this feature
30 // clients should refer to that class as the entry-point into the data formatters
31 // unless they have a good reason to bypass it and prefer to use this file's objects directly
33 class FormatManager : public IFormatChangeListener
35 typedef FormatNavigator<ConstString, TypeFormatImpl> ValueNavigator;
36 typedef ValueNavigator::MapType ValueMap;
37 typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap;
38 typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
41 typedef TypeCategoryMap::CallbackType CategoryCallback;
52 GetNamedSummaryNavigator ()
54 return m_named_summaries_map;
58 EnableCategory (const ConstString& category_name,
59 TypeCategoryMap::Position pos = TypeCategoryMap::Default)
61 m_categories_map.Enable(category_name,
66 DisableCategory (const ConstString& category_name)
68 m_categories_map.Disable(category_name);
72 EnableCategory (const lldb::TypeCategoryImplSP& category,
73 TypeCategoryMap::Position pos = TypeCategoryMap::Default)
75 m_categories_map.Enable(category,
80 DisableCategory (const lldb::TypeCategoryImplSP& category)
82 m_categories_map.Disable(category);
86 DeleteCategory (const ConstString& category_name)
88 return m_categories_map.Delete(category_name);
94 return m_categories_map.Clear();
100 return m_categories_map.GetCount();
103 lldb::TypeCategoryImplSP
104 GetCategoryAtIndex (size_t index)
106 return m_categories_map.GetAtIndex(index);
110 LoopThroughCategories (CategoryCallback callback, void* param)
112 m_categories_map.LoopThrough(callback, param);
115 lldb::TypeCategoryImplSP
116 GetCategory (const char* category_name = NULL,
117 bool can_create = true)
120 return GetCategory(m_default_category_name);
121 return GetCategory(ConstString(category_name));
124 lldb::TypeCategoryImplSP
125 GetCategory (const ConstString& category_name,
126 bool can_create = true);
128 lldb::TypeSummaryImplSP
129 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
131 lldb::TypeFilterImplSP
132 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
134 #ifndef LLDB_DISABLE_PYTHON
135 lldb::ScriptedSyntheticChildrenSP
136 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
139 #ifndef LLDB_DISABLE_PYTHON
140 lldb::SyntheticChildrenSP
141 GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
144 lldb::TypeSummaryImplSP
145 GetSummaryFormat (ValueObject& valobj,
146 lldb::DynamicValueType use_dynamic);
148 #ifndef LLDB_DISABLE_PYTHON
149 lldb::SyntheticChildrenSP
150 GetSyntheticChildren (ValueObject& valobj,
151 lldb::DynamicValueType use_dynamic);
155 AnyMatches (ConstString type_name,
156 TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
157 bool only_enabled = true,
158 const char** matching_category = NULL,
159 TypeCategoryImpl::FormatCategoryItems* matching_type = NULL)
161 return m_categories_map.AnyMatches(type_name,
169 GetFormatFromCString (const char *format_cstr,
170 bool partial_match_ok,
171 lldb::Format &format);
174 GetFormatAsFormatChar (lldb::Format format);
177 GetFormatAsCString (lldb::Format format);
179 // if the user tries to add formatters for, say, "struct Foo"
180 // those will not match any type because of the way we strip qualifiers from typenames
181 // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
182 // and strips the unnecessary qualifier
184 GetValidTypeName (const ConstString& type);
186 // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item
187 // this method returns it, or eFormatInvalid if vector_format is not a vectorOf
189 GetSingleItemFormat (lldb::Format vector_format);
194 __sync_add_and_fetch(&m_last_revision, +1);
195 m_format_cache.Clear ();
199 GetCurrentRevision ()
201 return m_last_revision;
209 FormatCache m_format_cache;
210 ValueNavigator m_value_nav;
211 NamedSummariesMap m_named_summaries_map;
212 uint32_t m_last_revision;
213 TypeCategoryMap m_categories_map;
215 ConstString m_default_category_name;
216 ConstString m_system_category_name;
217 ConstString m_gnu_cpp_category_name;
218 ConstString m_libcxx_category_name;
219 ConstString m_objc_category_name;
220 ConstString m_corefoundation_category_name;
221 ConstString m_coregraphics_category_name;
222 ConstString m_coreservices_category_name;
223 ConstString m_vectortypes_category_name;
224 ConstString m_appkit_category_name;
229 return m_categories_map;
232 // WARNING: these are temporary functions that setup formatters
233 // while a few of these actually should be globally available and setup by LLDB itself
234 // most would actually belong to the users' lldbinit file or to some other form of configurable
237 LoadLibStdcppFormatters ();
240 LoadLibcxxFormatters ();
243 LoadSystemFormatters ();
246 LoadObjCFormatters ();
249 } // namespace lldb_private
251 #endif // lldb_FormatManager_h_