1ac7ddfbfSEd Maste //===-- DataVisualization.cpp ---------------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/DataFormatters/DataVisualization.h" 11ac7ddfbfSEd Maste 12ac7ddfbfSEd Maste // C Includes 13ac7ddfbfSEd Maste // C++ Includes 14ac7ddfbfSEd Maste // Other libraries and framework includes 15ac7ddfbfSEd Maste // Project includes 16ac7ddfbfSEd Maste 17ac7ddfbfSEd Maste using namespace lldb; 18ac7ddfbfSEd Maste using namespace lldb_private; 19ac7ddfbfSEd Maste 20ac7ddfbfSEd Maste static FormatManager& 21ac7ddfbfSEd Maste GetFormatManager() 22ac7ddfbfSEd Maste { 23ac7ddfbfSEd Maste static FormatManager g_format_manager; 24ac7ddfbfSEd Maste return g_format_manager; 25ac7ddfbfSEd Maste } 26ac7ddfbfSEd Maste 27ac7ddfbfSEd Maste void 28ac7ddfbfSEd Maste DataVisualization::ForceUpdate () 29ac7ddfbfSEd Maste { 30ac7ddfbfSEd Maste GetFormatManager().Changed(); 31ac7ddfbfSEd Maste } 32ac7ddfbfSEd Maste 33ac7ddfbfSEd Maste uint32_t 34ac7ddfbfSEd Maste DataVisualization::GetCurrentRevision () 35ac7ddfbfSEd Maste { 36ac7ddfbfSEd Maste return GetFormatManager().GetCurrentRevision(); 37ac7ddfbfSEd Maste } 38ac7ddfbfSEd Maste 39ac7ddfbfSEd Maste bool 4035617911SEd Maste DataVisualization::ShouldPrintAsOneLiner (ValueObject& valobj) 41ac7ddfbfSEd Maste { 4235617911SEd Maste return GetFormatManager().ShouldPrintAsOneLiner(valobj); 43ac7ddfbfSEd Maste } 44ac7ddfbfSEd Maste 45ac7ddfbfSEd Maste lldb::TypeFormatImplSP 4635617911SEd Maste DataVisualization::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) 47ac7ddfbfSEd Maste { 4835617911SEd Maste return GetFormatManager().GetFormat(valobj, use_dynamic); 4935617911SEd Maste } 5035617911SEd Maste 5135617911SEd Maste lldb::TypeFormatImplSP 5235617911SEd Maste DataVisualization::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp) 5335617911SEd Maste { 5435617911SEd Maste return GetFormatManager().GetFormatForType(type_sp); 55ac7ddfbfSEd Maste } 56ac7ddfbfSEd Maste 57ac7ddfbfSEd Maste lldb::TypeSummaryImplSP 5835617911SEd Maste DataVisualization::GetSummaryFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) 59ac7ddfbfSEd Maste { 60ac7ddfbfSEd Maste return GetFormatManager().GetSummaryFormat(valobj, use_dynamic); 61ac7ddfbfSEd Maste } 62ac7ddfbfSEd Maste 63ac7ddfbfSEd Maste lldb::TypeSummaryImplSP 64ac7ddfbfSEd Maste DataVisualization::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) 65ac7ddfbfSEd Maste { 66ac7ddfbfSEd Maste return GetFormatManager().GetSummaryForType(type_sp); 67ac7ddfbfSEd Maste } 68ac7ddfbfSEd Maste 69ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON 70ac7ddfbfSEd Maste lldb::SyntheticChildrenSP 71ac7ddfbfSEd Maste DataVisualization::GetSyntheticChildren (ValueObject& valobj, 72ac7ddfbfSEd Maste lldb::DynamicValueType use_dynamic) 73ac7ddfbfSEd Maste { 74ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic); 75ac7ddfbfSEd Maste } 76ac7ddfbfSEd Maste #endif 77ac7ddfbfSEd Maste 78ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON 79ac7ddfbfSEd Maste lldb::SyntheticChildrenSP 80ac7ddfbfSEd Maste DataVisualization::GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp) 81ac7ddfbfSEd Maste { 82ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticChildrenForType(type_sp); 83ac7ddfbfSEd Maste } 84ac7ddfbfSEd Maste #endif 85ac7ddfbfSEd Maste 86ac7ddfbfSEd Maste lldb::TypeFilterImplSP 87ac7ddfbfSEd Maste DataVisualization::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp) 88ac7ddfbfSEd Maste { 89ac7ddfbfSEd Maste return GetFormatManager().GetFilterForType(type_sp); 90ac7ddfbfSEd Maste } 91ac7ddfbfSEd Maste 92ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON 93ac7ddfbfSEd Maste lldb::ScriptedSyntheticChildrenSP 94ac7ddfbfSEd Maste DataVisualization::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp) 95ac7ddfbfSEd Maste { 96ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticForType(type_sp); 97ac7ddfbfSEd Maste } 98ac7ddfbfSEd Maste #endif 99ac7ddfbfSEd Maste 1007aa51b79SEd Maste lldb::TypeValidatorImplSP 1017aa51b79SEd Maste DataVisualization::GetValidator (ValueObject& valobj, lldb::DynamicValueType use_dynamic) 1027aa51b79SEd Maste { 1037aa51b79SEd Maste return GetFormatManager().GetValidator(valobj, use_dynamic); 1047aa51b79SEd Maste } 1057aa51b79SEd Maste 1067aa51b79SEd Maste lldb::TypeValidatorImplSP 1077aa51b79SEd Maste DataVisualization::GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp) 1087aa51b79SEd Maste { 1097aa51b79SEd Maste return GetFormatManager().GetValidatorForType(type_sp); 1107aa51b79SEd Maste } 1117aa51b79SEd Maste 112ac7ddfbfSEd Maste bool 113ac7ddfbfSEd Maste DataVisualization::AnyMatches (ConstString type_name, 114ac7ddfbfSEd Maste TypeCategoryImpl::FormatCategoryItems items, 115ac7ddfbfSEd Maste bool only_enabled, 116ac7ddfbfSEd Maste const char** matching_category, 117ac7ddfbfSEd Maste TypeCategoryImpl::FormatCategoryItems* matching_type) 118ac7ddfbfSEd Maste { 119ac7ddfbfSEd Maste return GetFormatManager().AnyMatches(type_name, 120ac7ddfbfSEd Maste items, 121ac7ddfbfSEd Maste only_enabled, 122ac7ddfbfSEd Maste matching_category, 123ac7ddfbfSEd Maste matching_type); 124ac7ddfbfSEd Maste } 125ac7ddfbfSEd Maste 126ac7ddfbfSEd Maste bool 127ac7ddfbfSEd Maste DataVisualization::Categories::GetCategory (const ConstString &category, lldb::TypeCategoryImplSP &entry, 128ac7ddfbfSEd Maste bool allow_create) 129ac7ddfbfSEd Maste { 130ac7ddfbfSEd Maste entry = GetFormatManager().GetCategory(category, allow_create); 131ac7ddfbfSEd Maste return (entry.get() != NULL); 132ac7ddfbfSEd Maste } 133ac7ddfbfSEd Maste 1349f2f44ceSEd Maste bool 1359f2f44ceSEd Maste DataVisualization::Categories::GetCategory (lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) 1369f2f44ceSEd Maste { 1379f2f44ceSEd Maste if (LanguageCategory *lang_category = GetFormatManager().GetCategoryForLanguage(language)) 1389f2f44ceSEd Maste entry = lang_category->GetCategory(); 1399f2f44ceSEd Maste return (entry.get() != nullptr); 1409f2f44ceSEd Maste } 1419f2f44ceSEd Maste 142ac7ddfbfSEd Maste void 143ac7ddfbfSEd Maste DataVisualization::Categories::Add (const ConstString &category) 144ac7ddfbfSEd Maste { 145ac7ddfbfSEd Maste GetFormatManager().GetCategory(category); 146ac7ddfbfSEd Maste } 147ac7ddfbfSEd Maste 148ac7ddfbfSEd Maste bool 149ac7ddfbfSEd Maste DataVisualization::Categories::Delete (const ConstString &category) 150ac7ddfbfSEd Maste { 151ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 152ac7ddfbfSEd Maste return GetFormatManager().DeleteCategory(category); 153ac7ddfbfSEd Maste } 154ac7ddfbfSEd Maste 155ac7ddfbfSEd Maste void 156ac7ddfbfSEd Maste DataVisualization::Categories::Clear () 157ac7ddfbfSEd Maste { 158ac7ddfbfSEd Maste GetFormatManager().ClearCategories(); 159ac7ddfbfSEd Maste } 160ac7ddfbfSEd Maste 161ac7ddfbfSEd Maste void 162ac7ddfbfSEd Maste DataVisualization::Categories::Clear (const ConstString &category) 163ac7ddfbfSEd Maste { 164ac7ddfbfSEd Maste GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); 165ac7ddfbfSEd Maste } 166ac7ddfbfSEd Maste 167ac7ddfbfSEd Maste void 168ac7ddfbfSEd Maste DataVisualization::Categories::Enable (const ConstString& category, 169ac7ddfbfSEd Maste TypeCategoryMap::Position pos) 170ac7ddfbfSEd Maste { 171ac7ddfbfSEd Maste if (GetFormatManager().GetCategory(category)->IsEnabled()) 172ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 1739f2f44ceSEd Maste GetFormatManager().EnableCategory(category, pos, std::initializer_list<lldb::LanguageType>()); 1749f2f44ceSEd Maste } 1759f2f44ceSEd Maste 1769f2f44ceSEd Maste void 1779f2f44ceSEd Maste DataVisualization::Categories::Enable (lldb::LanguageType lang_type) 1789f2f44ceSEd Maste { 1799f2f44ceSEd Maste if (LanguageCategory* lang_category = GetFormatManager().GetCategoryForLanguage(lang_type)) 1809f2f44ceSEd Maste lang_category->Enable(); 181ac7ddfbfSEd Maste } 182ac7ddfbfSEd Maste 183ac7ddfbfSEd Maste void 184ac7ddfbfSEd Maste DataVisualization::Categories::Disable (const ConstString& category) 185ac7ddfbfSEd Maste { 186ac7ddfbfSEd Maste if (GetFormatManager().GetCategory(category)->IsEnabled() == true) 187ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 188ac7ddfbfSEd Maste } 189ac7ddfbfSEd Maste 190ac7ddfbfSEd Maste void 1919f2f44ceSEd Maste DataVisualization::Categories::Disable (lldb::LanguageType lang_type) 1929f2f44ceSEd Maste { 1939f2f44ceSEd Maste if (LanguageCategory* lang_category = GetFormatManager().GetCategoryForLanguage(lang_type)) 1949f2f44ceSEd Maste lang_category->Disable(); 1959f2f44ceSEd Maste } 1969f2f44ceSEd Maste 1979f2f44ceSEd Maste void 198ac7ddfbfSEd Maste DataVisualization::Categories::Enable (const lldb::TypeCategoryImplSP& category, 199ac7ddfbfSEd Maste TypeCategoryMap::Position pos) 200ac7ddfbfSEd Maste { 201ac7ddfbfSEd Maste if (category.get()) 202ac7ddfbfSEd Maste { 203ac7ddfbfSEd Maste if (category->IsEnabled()) 204ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 205ac7ddfbfSEd Maste GetFormatManager().EnableCategory(category, pos); 206ac7ddfbfSEd Maste } 207ac7ddfbfSEd Maste } 208ac7ddfbfSEd Maste 209ac7ddfbfSEd Maste void 210ac7ddfbfSEd Maste DataVisualization::Categories::Disable (const lldb::TypeCategoryImplSP& category) 211ac7ddfbfSEd Maste { 212ac7ddfbfSEd Maste if (category.get() && category->IsEnabled() == true) 213ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 214ac7ddfbfSEd Maste } 215ac7ddfbfSEd Maste 216ac7ddfbfSEd Maste void 2177aa51b79SEd Maste DataVisualization::Categories::EnableStar () 2187aa51b79SEd Maste { 2197aa51b79SEd Maste GetFormatManager().EnableAllCategories (); 2207aa51b79SEd Maste } 2217aa51b79SEd Maste 2227aa51b79SEd Maste void 2237aa51b79SEd Maste DataVisualization::Categories::DisableStar () 2247aa51b79SEd Maste { 2257aa51b79SEd Maste GetFormatManager().DisableAllCategories(); 2267aa51b79SEd Maste } 2277aa51b79SEd Maste 2287aa51b79SEd Maste void 2299f2f44ceSEd Maste DataVisualization::Categories::ForEach (TypeCategoryMap::ForEachCallback callback) 230ac7ddfbfSEd Maste { 2319f2f44ceSEd Maste GetFormatManager().ForEachCategory(callback); 232ac7ddfbfSEd Maste } 233ac7ddfbfSEd Maste 234ac7ddfbfSEd Maste uint32_t 235ac7ddfbfSEd Maste DataVisualization::Categories::GetCount () 236ac7ddfbfSEd Maste { 237ac7ddfbfSEd Maste return GetFormatManager().GetCategoriesCount(); 238ac7ddfbfSEd Maste } 239ac7ddfbfSEd Maste 240ac7ddfbfSEd Maste lldb::TypeCategoryImplSP 241ac7ddfbfSEd Maste DataVisualization::Categories::GetCategoryAtIndex (size_t index) 242ac7ddfbfSEd Maste { 243ac7ddfbfSEd Maste return GetFormatManager().GetCategoryAtIndex(index); 244ac7ddfbfSEd Maste } 245ac7ddfbfSEd Maste 246ac7ddfbfSEd Maste bool 247ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::GetSummaryFormat (const ConstString &type, lldb::TypeSummaryImplSP &entry) 248ac7ddfbfSEd Maste { 24912b93ac6SEd Maste return GetFormatManager().GetNamedSummaryContainer().Get(type,entry); 250ac7ddfbfSEd Maste } 251ac7ddfbfSEd Maste 252ac7ddfbfSEd Maste void 253ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::Add (const ConstString &type, const lldb::TypeSummaryImplSP &entry) 254ac7ddfbfSEd Maste { 25512b93ac6SEd Maste GetFormatManager().GetNamedSummaryContainer().Add(FormatManager::GetValidTypeName(type),entry); 256ac7ddfbfSEd Maste } 257ac7ddfbfSEd Maste 258ac7ddfbfSEd Maste bool 259ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::Delete (const ConstString &type) 260ac7ddfbfSEd Maste { 26112b93ac6SEd Maste return GetFormatManager().GetNamedSummaryContainer().Delete(type); 262ac7ddfbfSEd Maste } 263ac7ddfbfSEd Maste 264ac7ddfbfSEd Maste void 265ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::Clear () 266ac7ddfbfSEd Maste { 26712b93ac6SEd Maste GetFormatManager().GetNamedSummaryContainer().Clear(); 268ac7ddfbfSEd Maste } 269ac7ddfbfSEd Maste 270ac7ddfbfSEd Maste void 2719f2f44ceSEd Maste DataVisualization::NamedSummaryFormats::ForEach (std::function<bool(ConstString, const lldb::TypeSummaryImplSP&)> callback) 272ac7ddfbfSEd Maste { 2739f2f44ceSEd Maste GetFormatManager().GetNamedSummaryContainer().ForEach(callback); 274ac7ddfbfSEd Maste } 275ac7ddfbfSEd Maste 276ac7ddfbfSEd Maste uint32_t 277ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::GetCount () 278ac7ddfbfSEd Maste { 27912b93ac6SEd Maste return GetFormatManager().GetNamedSummaryContainer().GetCount(); 280ac7ddfbfSEd Maste } 281