1435933ddSDimitry Andric //===-- DataVisualization.cpp ---------------------------------------*- C++
2435933ddSDimitry Andric //-*-===//
3ac7ddfbfSEd Maste //
4ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
5ac7ddfbfSEd Maste //
6ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
7ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
8ac7ddfbfSEd Maste //
9ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
10ac7ddfbfSEd Maste
11ac7ddfbfSEd Maste #include "lldb/DataFormatters/DataVisualization.h"
12ac7ddfbfSEd Maste
13ac7ddfbfSEd Maste
14ac7ddfbfSEd Maste using namespace lldb;
15ac7ddfbfSEd Maste using namespace lldb_private;
16ac7ddfbfSEd Maste
GetFormatManager()17435933ddSDimitry Andric static FormatManager &GetFormatManager() {
18ac7ddfbfSEd Maste static FormatManager g_format_manager;
19ac7ddfbfSEd Maste return g_format_manager;
20ac7ddfbfSEd Maste }
21ac7ddfbfSEd Maste
ForceUpdate()22435933ddSDimitry Andric void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); }
23ac7ddfbfSEd Maste
GetCurrentRevision()24435933ddSDimitry Andric uint32_t DataVisualization::GetCurrentRevision() {
25ac7ddfbfSEd Maste return GetFormatManager().GetCurrentRevision();
26ac7ddfbfSEd Maste }
27ac7ddfbfSEd Maste
ShouldPrintAsOneLiner(ValueObject & valobj)28435933ddSDimitry Andric bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) {
2935617911SEd Maste return GetFormatManager().ShouldPrintAsOneLiner(valobj);
30ac7ddfbfSEd Maste }
31ac7ddfbfSEd Maste
32ac7ddfbfSEd Maste lldb::TypeFormatImplSP
GetFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)33435933ddSDimitry Andric DataVisualization::GetFormat(ValueObject &valobj,
34435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
3535617911SEd Maste return GetFormatManager().GetFormat(valobj, use_dynamic);
3635617911SEd Maste }
3735617911SEd Maste
3835617911SEd Maste lldb::TypeFormatImplSP
GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)39435933ddSDimitry Andric DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
4035617911SEd Maste return GetFormatManager().GetFormatForType(type_sp);
41ac7ddfbfSEd Maste }
42ac7ddfbfSEd Maste
43ac7ddfbfSEd Maste lldb::TypeSummaryImplSP
GetSummaryFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)44435933ddSDimitry Andric DataVisualization::GetSummaryFormat(ValueObject &valobj,
45435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
46ac7ddfbfSEd Maste return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
47ac7ddfbfSEd Maste }
48ac7ddfbfSEd Maste
49ac7ddfbfSEd Maste lldb::TypeSummaryImplSP
GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)50435933ddSDimitry Andric DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
51ac7ddfbfSEd Maste return GetFormatManager().GetSummaryForType(type_sp);
52ac7ddfbfSEd Maste }
53ac7ddfbfSEd Maste
54ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON
55ac7ddfbfSEd Maste lldb::SyntheticChildrenSP
GetSyntheticChildren(ValueObject & valobj,lldb::DynamicValueType use_dynamic)56ac7ddfbfSEd Maste DataVisualization::GetSyntheticChildren(ValueObject &valobj,
57435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
58ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
59ac7ddfbfSEd Maste }
60ac7ddfbfSEd Maste #endif
61ac7ddfbfSEd Maste
62ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON
GetSyntheticChildrenForType(lldb::TypeNameSpecifierImplSP type_sp)63435933ddSDimitry Andric lldb::SyntheticChildrenSP DataVisualization::GetSyntheticChildrenForType(
64435933ddSDimitry Andric lldb::TypeNameSpecifierImplSP type_sp) {
65ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticChildrenForType(type_sp);
66ac7ddfbfSEd Maste }
67ac7ddfbfSEd Maste #endif
68ac7ddfbfSEd Maste
69ac7ddfbfSEd Maste lldb::TypeFilterImplSP
GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)70435933ddSDimitry Andric DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
71ac7ddfbfSEd Maste return GetFormatManager().GetFilterForType(type_sp);
72ac7ddfbfSEd Maste }
73ac7ddfbfSEd Maste
74ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON
75ac7ddfbfSEd Maste lldb::ScriptedSyntheticChildrenSP
GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)76435933ddSDimitry Andric DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
77ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticForType(type_sp);
78ac7ddfbfSEd Maste }
79ac7ddfbfSEd Maste #endif
80ac7ddfbfSEd Maste
817aa51b79SEd Maste lldb::TypeValidatorImplSP
GetValidator(ValueObject & valobj,lldb::DynamicValueType use_dynamic)82435933ddSDimitry Andric DataVisualization::GetValidator(ValueObject &valobj,
83435933ddSDimitry Andric lldb::DynamicValueType use_dynamic) {
847aa51b79SEd Maste return GetFormatManager().GetValidator(valobj, use_dynamic);
857aa51b79SEd Maste }
867aa51b79SEd Maste
877aa51b79SEd Maste lldb::TypeValidatorImplSP
GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp)88435933ddSDimitry Andric DataVisualization::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) {
897aa51b79SEd Maste return GetFormatManager().GetValidatorForType(type_sp);
907aa51b79SEd Maste }
917aa51b79SEd Maste
AnyMatches(ConstString type_name,TypeCategoryImpl::FormatCategoryItems items,bool only_enabled,const char ** matching_category,TypeCategoryImpl::FormatCategoryItems * matching_type)92435933ddSDimitry Andric bool DataVisualization::AnyMatches(
93435933ddSDimitry Andric ConstString type_name, TypeCategoryImpl::FormatCategoryItems items,
94435933ddSDimitry Andric bool only_enabled, const char **matching_category,
95435933ddSDimitry Andric TypeCategoryImpl::FormatCategoryItems *matching_type) {
96435933ddSDimitry Andric return GetFormatManager().AnyMatches(type_name, items, only_enabled,
97435933ddSDimitry Andric matching_category, matching_type);
98ac7ddfbfSEd Maste }
99ac7ddfbfSEd Maste
GetCategory(const ConstString & category,lldb::TypeCategoryImplSP & entry,bool allow_create)100435933ddSDimitry Andric bool DataVisualization::Categories::GetCategory(const ConstString &category,
101435933ddSDimitry Andric lldb::TypeCategoryImplSP &entry,
102435933ddSDimitry Andric bool allow_create) {
103ac7ddfbfSEd Maste entry = GetFormatManager().GetCategory(category, allow_create);
104ac7ddfbfSEd Maste return (entry.get() != NULL);
105ac7ddfbfSEd Maste }
106ac7ddfbfSEd Maste
GetCategory(lldb::LanguageType language,lldb::TypeCategoryImplSP & entry)107435933ddSDimitry Andric bool DataVisualization::Categories::GetCategory(
108435933ddSDimitry Andric lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) {
109435933ddSDimitry Andric if (LanguageCategory *lang_category =
110435933ddSDimitry Andric GetFormatManager().GetCategoryForLanguage(language))
1119f2f44ceSEd Maste entry = lang_category->GetCategory();
1129f2f44ceSEd Maste return (entry.get() != nullptr);
1139f2f44ceSEd Maste }
1149f2f44ceSEd Maste
Add(const ConstString & category)115435933ddSDimitry Andric void DataVisualization::Categories::Add(const ConstString &category) {
116ac7ddfbfSEd Maste GetFormatManager().GetCategory(category);
117ac7ddfbfSEd Maste }
118ac7ddfbfSEd Maste
Delete(const ConstString & category)119435933ddSDimitry Andric bool DataVisualization::Categories::Delete(const ConstString &category) {
120ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category);
121ac7ddfbfSEd Maste return GetFormatManager().DeleteCategory(category);
122ac7ddfbfSEd Maste }
123ac7ddfbfSEd Maste
Clear()124435933ddSDimitry Andric void DataVisualization::Categories::Clear() {
125ac7ddfbfSEd Maste GetFormatManager().ClearCategories();
126ac7ddfbfSEd Maste }
127ac7ddfbfSEd Maste
Clear(const ConstString & category)128435933ddSDimitry Andric void DataVisualization::Categories::Clear(const ConstString &category) {
129435933ddSDimitry Andric GetFormatManager().GetCategory(category)->Clear(
130435933ddSDimitry Andric eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
131ac7ddfbfSEd Maste }
132ac7ddfbfSEd Maste
Enable(const ConstString & category,TypeCategoryMap::Position pos)133435933ddSDimitry Andric void DataVisualization::Categories::Enable(const ConstString &category,
134435933ddSDimitry Andric TypeCategoryMap::Position pos) {
135ac7ddfbfSEd Maste if (GetFormatManager().GetCategory(category)->IsEnabled())
136ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category);
137435933ddSDimitry Andric GetFormatManager().EnableCategory(
138435933ddSDimitry Andric category, pos, std::initializer_list<lldb::LanguageType>());
1399f2f44ceSEd Maste }
1409f2f44ceSEd Maste
Enable(lldb::LanguageType lang_type)141435933ddSDimitry Andric void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) {
142435933ddSDimitry Andric if (LanguageCategory *lang_category =
143435933ddSDimitry Andric GetFormatManager().GetCategoryForLanguage(lang_type))
1449f2f44ceSEd Maste lang_category->Enable();
145ac7ddfbfSEd Maste }
146ac7ddfbfSEd Maste
Disable(const ConstString & category)147435933ddSDimitry Andric void DataVisualization::Categories::Disable(const ConstString &category) {
148*b5893f02SDimitry Andric if (GetFormatManager().GetCategory(category)->IsEnabled())
149ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category);
150ac7ddfbfSEd Maste }
151ac7ddfbfSEd Maste
Disable(lldb::LanguageType lang_type)152435933ddSDimitry Andric void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) {
153435933ddSDimitry Andric if (LanguageCategory *lang_category =
154435933ddSDimitry Andric GetFormatManager().GetCategoryForLanguage(lang_type))
1559f2f44ceSEd Maste lang_category->Disable();
1569f2f44ceSEd Maste }
1579f2f44ceSEd Maste
Enable(const lldb::TypeCategoryImplSP & category,TypeCategoryMap::Position pos)158435933ddSDimitry Andric void DataVisualization::Categories::Enable(
159435933ddSDimitry Andric const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) {
160435933ddSDimitry Andric if (category.get()) {
161ac7ddfbfSEd Maste if (category->IsEnabled())
162ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category);
163ac7ddfbfSEd Maste GetFormatManager().EnableCategory(category, pos);
164ac7ddfbfSEd Maste }
165ac7ddfbfSEd Maste }
166ac7ddfbfSEd Maste
Disable(const lldb::TypeCategoryImplSP & category)167435933ddSDimitry Andric void DataVisualization::Categories::Disable(
168435933ddSDimitry Andric const lldb::TypeCategoryImplSP &category) {
169*b5893f02SDimitry Andric if (category.get() && category->IsEnabled())
170ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category);
171ac7ddfbfSEd Maste }
172ac7ddfbfSEd Maste
EnableStar()173435933ddSDimitry Andric void DataVisualization::Categories::EnableStar() {
1747aa51b79SEd Maste GetFormatManager().EnableAllCategories();
1757aa51b79SEd Maste }
1767aa51b79SEd Maste
DisableStar()177435933ddSDimitry Andric void DataVisualization::Categories::DisableStar() {
1787aa51b79SEd Maste GetFormatManager().DisableAllCategories();
1797aa51b79SEd Maste }
1807aa51b79SEd Maste
ForEach(TypeCategoryMap::ForEachCallback callback)181435933ddSDimitry Andric void DataVisualization::Categories::ForEach(
182435933ddSDimitry Andric TypeCategoryMap::ForEachCallback callback) {
1839f2f44ceSEd Maste GetFormatManager().ForEachCategory(callback);
184ac7ddfbfSEd Maste }
185ac7ddfbfSEd Maste
GetCount()186435933ddSDimitry Andric uint32_t DataVisualization::Categories::GetCount() {
187ac7ddfbfSEd Maste return GetFormatManager().GetCategoriesCount();
188ac7ddfbfSEd Maste }
189ac7ddfbfSEd Maste
190ac7ddfbfSEd Maste lldb::TypeCategoryImplSP
GetCategoryAtIndex(size_t index)191435933ddSDimitry Andric DataVisualization::Categories::GetCategoryAtIndex(size_t index) {
192ac7ddfbfSEd Maste return GetFormatManager().GetCategoryAtIndex(index);
193ac7ddfbfSEd Maste }
194ac7ddfbfSEd Maste
GetSummaryFormat(const ConstString & type,lldb::TypeSummaryImplSP & entry)195435933ddSDimitry Andric bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
196435933ddSDimitry Andric const ConstString &type, lldb::TypeSummaryImplSP &entry) {
19712b93ac6SEd Maste return GetFormatManager().GetNamedSummaryContainer().Get(type, entry);
198ac7ddfbfSEd Maste }
199ac7ddfbfSEd Maste
Add(const ConstString & type,const lldb::TypeSummaryImplSP & entry)200435933ddSDimitry Andric void DataVisualization::NamedSummaryFormats::Add(
201435933ddSDimitry Andric const ConstString &type, const lldb::TypeSummaryImplSP &entry) {
202435933ddSDimitry Andric GetFormatManager().GetNamedSummaryContainer().Add(
203435933ddSDimitry Andric FormatManager::GetValidTypeName(type), entry);
204ac7ddfbfSEd Maste }
205ac7ddfbfSEd Maste
Delete(const ConstString & type)206435933ddSDimitry Andric bool DataVisualization::NamedSummaryFormats::Delete(const ConstString &type) {
20712b93ac6SEd Maste return GetFormatManager().GetNamedSummaryContainer().Delete(type);
208ac7ddfbfSEd Maste }
209ac7ddfbfSEd Maste
Clear()210435933ddSDimitry Andric void DataVisualization::NamedSummaryFormats::Clear() {
21112b93ac6SEd Maste GetFormatManager().GetNamedSummaryContainer().Clear();
212ac7ddfbfSEd Maste }
213ac7ddfbfSEd Maste
ForEach(std::function<bool (ConstString,const lldb::TypeSummaryImplSP &)> callback)214435933ddSDimitry Andric void DataVisualization::NamedSummaryFormats::ForEach(
215435933ddSDimitry Andric std::function<bool(ConstString, const lldb::TypeSummaryImplSP &)>
216435933ddSDimitry Andric callback) {
2179f2f44ceSEd Maste GetFormatManager().GetNamedSummaryContainer().ForEach(callback);
218ac7ddfbfSEd Maste }
219ac7ddfbfSEd Maste
GetCount()220435933ddSDimitry Andric uint32_t DataVisualization::NamedSummaryFormats::GetCount() {
22112b93ac6SEd Maste return GetFormatManager().GetNamedSummaryContainer().GetCount();
222ac7ddfbfSEd Maste }
223