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

source code of lldb/source/DataFormatters/DataVisualization.cpp