1 //===-- DataVisualization.cpp ---------------------------------------*- C++
2 //-*-===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #include "lldb/DataFormatters/DataVisualization.h"
12
13
14 using namespace lldb;
15 using namespace lldb_private;
16
GetFormatManager()17 static FormatManager &GetFormatManager() {
18 static FormatManager g_format_manager;
19 return g_format_manager;
20 }
21
ForceUpdate()22 void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); }
23
GetCurrentRevision()24 uint32_t DataVisualization::GetCurrentRevision() {
25 return GetFormatManager().GetCurrentRevision();
26 }
27
ShouldPrintAsOneLiner(ValueObject & valobj)28 bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) {
29 return GetFormatManager().ShouldPrintAsOneLiner(valobj);
30 }
31
32 lldb::TypeFormatImplSP
GetFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)33 DataVisualization::GetFormat(ValueObject &valobj,
34 lldb::DynamicValueType use_dynamic) {
35 return GetFormatManager().GetFormat(valobj, use_dynamic);
36 }
37
38 lldb::TypeFormatImplSP
GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)39 DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
40 return GetFormatManager().GetFormatForType(type_sp);
41 }
42
43 lldb::TypeSummaryImplSP
GetSummaryFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)44 DataVisualization::GetSummaryFormat(ValueObject &valobj,
45 lldb::DynamicValueType use_dynamic) {
46 return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
47 }
48
49 lldb::TypeSummaryImplSP
GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)50 DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
51 return GetFormatManager().GetSummaryForType(type_sp);
52 }
53
54 #ifndef LLDB_DISABLE_PYTHON
55 lldb::SyntheticChildrenSP
GetSyntheticChildren(ValueObject & valobj,lldb::DynamicValueType use_dynamic)56 DataVisualization::GetSyntheticChildren(ValueObject &valobj,
57 lldb::DynamicValueType use_dynamic) {
58 return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
59 }
60 #endif
61
62 #ifndef LLDB_DISABLE_PYTHON
GetSyntheticChildrenForType(lldb::TypeNameSpecifierImplSP type_sp)63 lldb::SyntheticChildrenSP DataVisualization::GetSyntheticChildrenForType(
64 lldb::TypeNameSpecifierImplSP type_sp) {
65 return GetFormatManager().GetSyntheticChildrenForType(type_sp);
66 }
67 #endif
68
69 lldb::TypeFilterImplSP
GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)70 DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
71 return GetFormatManager().GetFilterForType(type_sp);
72 }
73
74 #ifndef LLDB_DISABLE_PYTHON
75 lldb::ScriptedSyntheticChildrenSP
GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)76 DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
77 return GetFormatManager().GetSyntheticForType(type_sp);
78 }
79 #endif
80
81 lldb::TypeValidatorImplSP
GetValidator(ValueObject & valobj,lldb::DynamicValueType use_dynamic)82 DataVisualization::GetValidator(ValueObject &valobj,
83 lldb::DynamicValueType use_dynamic) {
84 return GetFormatManager().GetValidator(valobj, use_dynamic);
85 }
86
87 lldb::TypeValidatorImplSP
GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp)88 DataVisualization::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) {
89 return GetFormatManager().GetValidatorForType(type_sp);
90 }
91
AnyMatches(ConstString type_name,TypeCategoryImpl::FormatCategoryItems items,bool only_enabled,const char ** matching_category,TypeCategoryImpl::FormatCategoryItems * matching_type)92 bool DataVisualization::AnyMatches(
93 ConstString type_name, TypeCategoryImpl::FormatCategoryItems items,
94 bool only_enabled, const char **matching_category,
95 TypeCategoryImpl::FormatCategoryItems *matching_type) {
96 return GetFormatManager().AnyMatches(type_name, items, only_enabled,
97 matching_category, matching_type);
98 }
99
GetCategory(const ConstString & category,lldb::TypeCategoryImplSP & entry,bool allow_create)100 bool DataVisualization::Categories::GetCategory(const ConstString &category,
101 lldb::TypeCategoryImplSP &entry,
102 bool allow_create) {
103 entry = GetFormatManager().GetCategory(category, allow_create);
104 return (entry.get() != NULL);
105 }
106
GetCategory(lldb::LanguageType language,lldb::TypeCategoryImplSP & entry)107 bool DataVisualization::Categories::GetCategory(
108 lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) {
109 if (LanguageCategory *lang_category =
110 GetFormatManager().GetCategoryForLanguage(language))
111 entry = lang_category->GetCategory();
112 return (entry.get() != nullptr);
113 }
114
Add(const ConstString & category)115 void DataVisualization::Categories::Add(const ConstString &category) {
116 GetFormatManager().GetCategory(category);
117 }
118
Delete(const ConstString & category)119 bool DataVisualization::Categories::Delete(const ConstString &category) {
120 GetFormatManager().DisableCategory(category);
121 return GetFormatManager().DeleteCategory(category);
122 }
123
Clear()124 void DataVisualization::Categories::Clear() {
125 GetFormatManager().ClearCategories();
126 }
127
Clear(const ConstString & category)128 void DataVisualization::Categories::Clear(const ConstString &category) {
129 GetFormatManager().GetCategory(category)->Clear(
130 eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
131 }
132
Enable(const ConstString & category,TypeCategoryMap::Position pos)133 void DataVisualization::Categories::Enable(const ConstString &category,
134 TypeCategoryMap::Position pos) {
135 if (GetFormatManager().GetCategory(category)->IsEnabled())
136 GetFormatManager().DisableCategory(category);
137 GetFormatManager().EnableCategory(
138 category, pos, std::initializer_list<lldb::LanguageType>());
139 }
140
Enable(lldb::LanguageType lang_type)141 void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) {
142 if (LanguageCategory *lang_category =
143 GetFormatManager().GetCategoryForLanguage(lang_type))
144 lang_category->Enable();
145 }
146
Disable(const ConstString & category)147 void DataVisualization::Categories::Disable(const ConstString &category) {
148 if (GetFormatManager().GetCategory(category)->IsEnabled())
149 GetFormatManager().DisableCategory(category);
150 }
151
Disable(lldb::LanguageType lang_type)152 void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) {
153 if (LanguageCategory *lang_category =
154 GetFormatManager().GetCategoryForLanguage(lang_type))
155 lang_category->Disable();
156 }
157
Enable(const lldb::TypeCategoryImplSP & category,TypeCategoryMap::Position pos)158 void DataVisualization::Categories::Enable(
159 const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) {
160 if (category.get()) {
161 if (category->IsEnabled())
162 GetFormatManager().DisableCategory(category);
163 GetFormatManager().EnableCategory(category, pos);
164 }
165 }
166
Disable(const lldb::TypeCategoryImplSP & category)167 void DataVisualization::Categories::Disable(
168 const lldb::TypeCategoryImplSP &category) {
169 if (category.get() && category->IsEnabled())
170 GetFormatManager().DisableCategory(category);
171 }
172
EnableStar()173 void DataVisualization::Categories::EnableStar() {
174 GetFormatManager().EnableAllCategories();
175 }
176
DisableStar()177 void DataVisualization::Categories::DisableStar() {
178 GetFormatManager().DisableAllCategories();
179 }
180
ForEach(TypeCategoryMap::ForEachCallback callback)181 void DataVisualization::Categories::ForEach(
182 TypeCategoryMap::ForEachCallback callback) {
183 GetFormatManager().ForEachCategory(callback);
184 }
185
GetCount()186 uint32_t DataVisualization::Categories::GetCount() {
187 return GetFormatManager().GetCategoriesCount();
188 }
189
190 lldb::TypeCategoryImplSP
GetCategoryAtIndex(size_t index)191 DataVisualization::Categories::GetCategoryAtIndex(size_t index) {
192 return GetFormatManager().GetCategoryAtIndex(index);
193 }
194
GetSummaryFormat(const ConstString & type,lldb::TypeSummaryImplSP & entry)195 bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
196 const ConstString &type, lldb::TypeSummaryImplSP &entry) {
197 return GetFormatManager().GetNamedSummaryContainer().Get(type, entry);
198 }
199
Add(const ConstString & type,const lldb::TypeSummaryImplSP & entry)200 void DataVisualization::NamedSummaryFormats::Add(
201 const ConstString &type, const lldb::TypeSummaryImplSP &entry) {
202 GetFormatManager().GetNamedSummaryContainer().Add(
203 FormatManager::GetValidTypeName(type), entry);
204 }
205
Delete(const ConstString & type)206 bool DataVisualization::NamedSummaryFormats::Delete(const ConstString &type) {
207 return GetFormatManager().GetNamedSummaryContainer().Delete(type);
208 }
209
Clear()210 void DataVisualization::NamedSummaryFormats::Clear() {
211 GetFormatManager().GetNamedSummaryContainer().Clear();
212 }
213
ForEach(std::function<bool (ConstString,const lldb::TypeSummaryImplSP &)> callback)214 void DataVisualization::NamedSummaryFormats::ForEach(
215 std::function<bool(ConstString, const lldb::TypeSummaryImplSP &)>
216 callback) {
217 GetFormatManager().GetNamedSummaryContainer().ForEach(callback);
218 }
219
GetCount()220 uint32_t DataVisualization::NamedSummaryFormats::GetCount() {
221 return GetFormatManager().GetNamedSummaryContainer().GetCount();
222 }
223