1 //===-- DataVisualization.cpp ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/DataFormatters/DataVisualization.h"
13 using namespace lldb_private
;
15 static FormatManager
&GetFormatManager() {
16 static FormatManager g_format_manager
;
17 return g_format_manager
;
20 void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); }
22 uint32_t DataVisualization::GetCurrentRevision() {
23 return GetFormatManager().GetCurrentRevision();
26 bool DataVisualization::ShouldPrintAsOneLiner(ValueObject
&valobj
) {
27 return GetFormatManager().ShouldPrintAsOneLiner(valobj
);
30 lldb::TypeFormatImplSP
31 DataVisualization::GetFormat(ValueObject
&valobj
,
32 lldb::DynamicValueType use_dynamic
) {
33 return GetFormatManager().GetFormat(valobj
, use_dynamic
);
36 lldb::TypeFormatImplSP
37 DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp
) {
38 return GetFormatManager().GetFormatForType(type_sp
);
41 lldb::TypeSummaryImplSP
42 DataVisualization::GetSummaryFormat(ValueObject
&valobj
,
43 lldb::DynamicValueType use_dynamic
) {
44 return GetFormatManager().GetSummaryFormat(valobj
, use_dynamic
);
47 lldb::TypeSummaryImplSP
48 DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp
) {
49 return GetFormatManager().GetSummaryForType(type_sp
);
52 lldb::SyntheticChildrenSP
53 DataVisualization::GetSyntheticChildren(ValueObject
&valobj
,
54 lldb::DynamicValueType use_dynamic
) {
55 return GetFormatManager().GetSyntheticChildren(valobj
, use_dynamic
);
58 lldb::TypeFilterImplSP
59 DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp
) {
60 return GetFormatManager().GetFilterForType(type_sp
);
63 lldb::ScriptedSyntheticChildrenSP
64 DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp
) {
65 return GetFormatManager().GetSyntheticForType(type_sp
);
68 bool 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
);
77 bool DataVisualization::Categories::GetCategory(ConstString category
,
78 lldb::TypeCategoryImplSP
&entry
,
80 entry
= GetFormatManager().GetCategory(category
, allow_create
);
81 return (entry
.get() != nullptr);
84 bool DataVisualization::Categories::GetCategory(
85 lldb::LanguageType language
, lldb::TypeCategoryImplSP
&entry
) {
86 if (LanguageCategory
*lang_category
=
87 GetFormatManager().GetCategoryForLanguage(language
))
88 entry
= lang_category
->GetCategory();
89 return (entry
.get() != nullptr);
92 void DataVisualization::Categories::Add(ConstString category
) {
93 GetFormatManager().GetCategory(category
);
96 bool DataVisualization::Categories::Delete(ConstString category
) {
97 GetFormatManager().DisableCategory(category
);
98 return GetFormatManager().DeleteCategory(category
);
101 void DataVisualization::Categories::Clear() {
102 GetFormatManager().ClearCategories();
105 void DataVisualization::Categories::Clear(ConstString category
) {
106 GetFormatManager().GetCategory(category
)->Clear(eFormatCategoryItemSummary
);
109 void DataVisualization::Categories::Enable(ConstString category
,
110 TypeCategoryMap::Position pos
) {
111 if (GetFormatManager().GetCategory(category
)->IsEnabled())
112 GetFormatManager().DisableCategory(category
);
113 GetFormatManager().EnableCategory(category
, pos
, {});
116 void DataVisualization::Categories::Enable(lldb::LanguageType lang_type
) {
117 if (LanguageCategory
*lang_category
=
118 GetFormatManager().GetCategoryForLanguage(lang_type
))
119 lang_category
->Enable();
122 void DataVisualization::Categories::Disable(ConstString category
) {
123 if (GetFormatManager().GetCategory(category
)->IsEnabled())
124 GetFormatManager().DisableCategory(category
);
127 void DataVisualization::Categories::Disable(lldb::LanguageType lang_type
) {
128 if (LanguageCategory
*lang_category
=
129 GetFormatManager().GetCategoryForLanguage(lang_type
))
130 lang_category
->Disable();
133 void 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
);
142 void DataVisualization::Categories::Disable(
143 const lldb::TypeCategoryImplSP
&category
) {
144 if (category
.get() && category
->IsEnabled())
145 GetFormatManager().DisableCategory(category
);
148 void DataVisualization::Categories::EnableStar() {
149 GetFormatManager().EnableAllCategories();
152 void DataVisualization::Categories::DisableStar() {
153 GetFormatManager().DisableAllCategories();
156 void DataVisualization::Categories::ForEach(
157 TypeCategoryMap::ForEachCallback callback
) {
158 GetFormatManager().ForEachCategory(callback
);
161 uint32_t DataVisualization::Categories::GetCount() {
162 return GetFormatManager().GetCategoriesCount();
165 lldb::TypeCategoryImplSP
166 DataVisualization::Categories::GetCategoryAtIndex(size_t index
) {
167 return GetFormatManager().GetCategoryAtIndex(index
);
170 bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
171 ConstString type
, lldb::TypeSummaryImplSP
&entry
) {
172 return GetFormatManager().GetNamedSummaryContainer().GetExact(type
, entry
);
175 void DataVisualization::NamedSummaryFormats::Add(
176 ConstString type
, const lldb::TypeSummaryImplSP
&entry
) {
177 GetFormatManager().GetNamedSummaryContainer().Add(type
, entry
);
180 bool DataVisualization::NamedSummaryFormats::Delete(ConstString type
) {
181 return GetFormatManager().GetNamedSummaryContainer().Delete(type
);
184 void DataVisualization::NamedSummaryFormats::Clear() {
185 GetFormatManager().GetNamedSummaryContainer().Clear();
188 void DataVisualization::NamedSummaryFormats::ForEach(
189 std::function
<bool(const TypeMatcher
&, const lldb::TypeSummaryImplSP
&)>
191 GetFormatManager().GetNamedSummaryContainer().ForEach(callback
);
194 uint32_t DataVisualization::NamedSummaryFormats::GetCount() {
195 return GetFormatManager().GetNamedSummaryContainer().GetCount();