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