TypeCategory.h revision 262528
1254721Semaste//===-- TypeCategory.h -------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef lldb_TypeCategory_h_ 11254721Semaste#define lldb_TypeCategory_h_ 12254721Semaste 13254721Semaste// C Includes 14254721Semaste// C++ Includes 15254721Semaste 16254721Semaste// Other libraries and framework includes 17254721Semaste// Project includes 18254721Semaste#include "lldb/lldb-public.h" 19254721Semaste#include "lldb/lldb-enumerations.h" 20254721Semaste 21258884Semaste#include "lldb/DataFormatters/FormatClasses.h" 22262528Semaste#include "lldb/DataFormatters/FormattersContainer.h" 23254721Semaste 24262528Semastenamespace lldb_private { 25262528Semaste 26262528Semaste template <typename FormatterImpl> 27262528Semaste class FormatterContainerPair 28254721Semaste { 29262528Semaste public: 30262528Semaste typedef FormattersContainer<ConstString, FormatterImpl> ExactMatchContainer; 31262528Semaste typedef FormattersContainer<lldb::RegularExpressionSP, FormatterImpl> RegexMatchContainer; 32254721Semaste 33262528Semaste typedef typename ExactMatchContainer::MapType ExactMatchMap; 34262528Semaste typedef typename RegexMatchContainer::MapType RegexMatchMap; 35262528Semaste 36262528Semaste typedef typename ExactMatchContainer::MapValueType MapValueType; 37254721Semaste 38262528Semaste typedef typename ExactMatchContainer::SharedPointer ExactMatchContainerSP; 39262528Semaste typedef typename RegexMatchContainer::SharedPointer RegexMatchContainerSP; 40254721Semaste 41262528Semaste FormatterContainerPair (const char* exact_name, 42262528Semaste const char* regex_name, 43262528Semaste IFormatChangeListener* clist) : 44262528Semaste m_exact_sp(new ExactMatchContainer(std::string(exact_name),clist)), 45262528Semaste m_regex_sp(new RegexMatchContainer(std::string(regex_name),clist)) 46262528Semaste { 47262528Semaste } 48262528Semaste 49262528Semaste ~FormatterContainerPair () = default; 50262528Semaste 51262528Semaste ExactMatchContainerSP 52262528Semaste GetExactMatch () const 53262528Semaste { 54262528Semaste return m_exact_sp; 55262528Semaste } 56262528Semaste 57262528Semaste RegexMatchContainerSP 58262528Semaste GetRegexMatch () const 59262528Semaste { 60262528Semaste return m_regex_sp; 61262528Semaste } 62262528Semaste 63262528Semaste private: 64262528Semaste ExactMatchContainerSP m_exact_sp; 65262528Semaste RegexMatchContainerSP m_regex_sp; 66262528Semaste }; 67258054Semaste 68262528Semaste class TypeCategoryImpl 69262528Semaste { 70262528Semaste private: 71262528Semaste typedef FormatterContainerPair<TypeFormatImpl> FormatContainer; 72262528Semaste typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer; 73262528Semaste typedef FormatterContainerPair<TypeFilterImpl> FilterContainer; 74258054Semaste 75254721Semaste#ifndef LLDB_DISABLE_PYTHON 76262528Semaste typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer; 77254721Semaste#endif // #ifndef LLDB_DISABLE_PYTHON 78262528Semaste 79254721Semaste public: 80254721Semaste 81254721Semaste typedef uint16_t FormatCategoryItems; 82254721Semaste static const uint16_t ALL_ITEM_TYPES = UINT16_MAX; 83258054Semaste 84262528Semaste typedef FormatContainer::ExactMatchContainerSP FormatContainerSP; 85262528Semaste typedef FormatContainer::RegexMatchContainerSP RegexFormatContainerSP; 86254721Semaste 87262528Semaste typedef SummaryContainer::ExactMatchContainerSP SummaryContainerSP; 88262528Semaste typedef SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP; 89258054Semaste 90262528Semaste typedef FilterContainer::ExactMatchContainerSP FilterContainerSP; 91262528Semaste typedef FilterContainer::RegexMatchContainerSP RegexFilterContainerSP; 92254721Semaste#ifndef LLDB_DISABLE_PYTHON 93262528Semaste typedef SynthContainer::ExactMatchContainerSP SynthContainerSP; 94262528Semaste typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP; 95254721Semaste#endif // #ifndef LLDB_DISABLE_PYTHON 96254721Semaste 97254721Semaste TypeCategoryImpl (IFormatChangeListener* clist, 98254721Semaste ConstString name); 99254721Semaste 100262528Semaste FormatContainerSP 101262528Semaste GetTypeFormatsContainer () 102258054Semaste { 103262528Semaste return m_format_cont.GetExactMatch(); 104258054Semaste } 105258054Semaste 106262528Semaste RegexFormatContainerSP 107262528Semaste GetRegexTypeFormatsContainer () 108258054Semaste { 109262528Semaste return m_format_cont.GetRegexMatch(); 110258054Semaste } 111258054Semaste 112262528Semaste SummaryContainerSP 113262528Semaste GetTypeSummariesContainer () 114254721Semaste { 115262528Semaste return m_summary_cont.GetExactMatch(); 116254721Semaste } 117254721Semaste 118262528Semaste RegexSummaryContainerSP 119262528Semaste GetRegexTypeSummariesContainer () 120254721Semaste { 121262528Semaste return m_summary_cont.GetRegexMatch(); 122254721Semaste } 123254721Semaste 124262528Semaste FilterContainerSP 125262528Semaste GetTypeFiltersContainer () 126254721Semaste { 127262528Semaste return m_filter_cont.GetExactMatch(); 128254721Semaste } 129254721Semaste 130262528Semaste RegexFilterContainerSP 131262528Semaste GetRegexTypeFiltersContainer () 132254721Semaste { 133262528Semaste return m_filter_cont.GetRegexMatch(); 134254721Semaste } 135258054Semaste 136262528Semaste FormatContainer::MapValueType 137258054Semaste GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp); 138254721Semaste 139262528Semaste SummaryContainer::MapValueType 140254721Semaste GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp); 141254721Semaste 142262528Semaste FilterContainer::MapValueType 143254721Semaste GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp); 144254721Semaste 145254721Semaste#ifndef LLDB_DISABLE_PYTHON 146262528Semaste SynthContainer::MapValueType 147254721Semaste GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp); 148254721Semaste#endif 149254721Semaste 150254721Semaste lldb::TypeNameSpecifierImplSP 151258054Semaste GetTypeNameSpecifierForFormatAtIndex (size_t index); 152258054Semaste 153258054Semaste lldb::TypeNameSpecifierImplSP 154254721Semaste GetTypeNameSpecifierForSummaryAtIndex (size_t index); 155258054Semaste 156262528Semaste FormatContainer::MapValueType 157258054Semaste GetFormatAtIndex (size_t index); 158254721Semaste 159262528Semaste SummaryContainer::MapValueType 160254721Semaste GetSummaryAtIndex (size_t index); 161254721Semaste 162262528Semaste FilterContainer::MapValueType 163254721Semaste GetFilterAtIndex (size_t index); 164254721Semaste 165254721Semaste lldb::TypeNameSpecifierImplSP 166254721Semaste GetTypeNameSpecifierForFilterAtIndex (size_t index); 167254721Semaste 168254721Semaste#ifndef LLDB_DISABLE_PYTHON 169262528Semaste SynthContainerSP 170262528Semaste GetTypeSyntheticsContainer () 171254721Semaste { 172262528Semaste return m_synth_cont.GetExactMatch(); 173254721Semaste } 174254721Semaste 175262528Semaste RegexSynthContainerSP 176262528Semaste GetRegexTypeSyntheticsContainer () 177254721Semaste { 178262528Semaste return m_synth_cont.GetRegexMatch(); 179254721Semaste } 180254721Semaste 181262528Semaste SynthContainer::MapValueType 182254721Semaste GetSyntheticAtIndex (size_t index); 183254721Semaste 184254721Semaste lldb::TypeNameSpecifierImplSP 185254721Semaste GetTypeNameSpecifierForSyntheticAtIndex (size_t index); 186254721Semaste 187254721Semaste#endif // #ifndef LLDB_DISABLE_PYTHON 188254721Semaste 189254721Semaste bool 190254721Semaste IsEnabled () const 191254721Semaste { 192254721Semaste return m_enabled; 193254721Semaste } 194254721Semaste 195254721Semaste uint32_t 196254721Semaste GetEnabledPosition() 197254721Semaste { 198254721Semaste if (m_enabled == false) 199254721Semaste return UINT32_MAX; 200254721Semaste else 201254721Semaste return m_enabled_position; 202254721Semaste } 203254721Semaste 204254721Semaste bool 205254721Semaste Get (ValueObject& valobj, 206258884Semaste const FormattersMatchVector& candidates, 207258054Semaste lldb::TypeFormatImplSP& entry, 208258054Semaste uint32_t* reason = NULL); 209258054Semaste 210258054Semaste bool 211258054Semaste Get (ValueObject& valobj, 212258884Semaste const FormattersMatchVector& candidates, 213254721Semaste lldb::TypeSummaryImplSP& entry, 214254721Semaste uint32_t* reason = NULL); 215254721Semaste 216254721Semaste bool 217254721Semaste Get (ValueObject& valobj, 218258884Semaste const FormattersMatchVector& candidates, 219254721Semaste lldb::SyntheticChildrenSP& entry, 220254721Semaste uint32_t* reason = NULL); 221254721Semaste 222254721Semaste void 223254721Semaste Clear (FormatCategoryItems items = ALL_ITEM_TYPES); 224254721Semaste 225254721Semaste bool 226254721Semaste Delete (ConstString name, 227254721Semaste FormatCategoryItems items = ALL_ITEM_TYPES); 228254721Semaste 229254721Semaste uint32_t 230254721Semaste GetCount (FormatCategoryItems items = ALL_ITEM_TYPES); 231254721Semaste 232254721Semaste const char* 233254721Semaste GetName () 234254721Semaste { 235254721Semaste return m_name.GetCString(); 236254721Semaste } 237254721Semaste 238254721Semaste bool 239254721Semaste AnyMatches (ConstString type_name, 240254721Semaste FormatCategoryItems items = ALL_ITEM_TYPES, 241254721Semaste bool only_enabled = true, 242254721Semaste const char** matching_category = NULL, 243254721Semaste FormatCategoryItems* matching_type = NULL); 244254721Semaste 245254721Semaste typedef std::shared_ptr<TypeCategoryImpl> SharedPointer; 246254721Semaste 247254721Semaste private: 248262528Semaste FormatContainer m_format_cont; 249258054Semaste 250262528Semaste SummaryContainer m_summary_cont; 251258054Semaste 252262528Semaste FilterContainer m_filter_cont; 253258054Semaste 254254721Semaste#ifndef LLDB_DISABLE_PYTHON 255262528Semaste SynthContainer m_synth_cont; 256254721Semaste#endif // #ifndef LLDB_DISABLE_PYTHON 257254721Semaste 258254721Semaste bool m_enabled; 259254721Semaste 260254721Semaste IFormatChangeListener* m_change_listener; 261254721Semaste 262254721Semaste Mutex m_mutex; 263254721Semaste 264254721Semaste ConstString m_name; 265254721Semaste 266254721Semaste uint32_t m_enabled_position; 267254721Semaste 268254721Semaste void 269254721Semaste Enable (bool value, uint32_t position); 270254721Semaste 271254721Semaste void 272254721Semaste Disable () 273254721Semaste { 274254721Semaste Enable(false, UINT32_MAX); 275254721Semaste } 276254721Semaste 277254721Semaste friend class TypeCategoryMap; 278254721Semaste 279262528Semaste friend class FormattersContainer<ConstString, TypeFormatImpl>; 280262528Semaste friend class FormattersContainer<lldb::RegularExpressionSP, TypeFormatImpl>; 281258054Semaste 282262528Semaste friend class FormattersContainer<ConstString, TypeSummaryImpl>; 283262528Semaste friend class FormattersContainer<lldb::RegularExpressionSP, TypeSummaryImpl>; 284254721Semaste 285262528Semaste friend class FormattersContainer<ConstString, TypeFilterImpl>; 286262528Semaste friend class FormattersContainer<lldb::RegularExpressionSP, TypeFilterImpl>; 287254721Semaste 288254721Semaste#ifndef LLDB_DISABLE_PYTHON 289262528Semaste friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>; 290262528Semaste friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>; 291254721Semaste#endif // #ifndef LLDB_DISABLE_PYTHON 292254721Semaste }; 293254721Semaste 294254721Semaste} // namespace lldb_private 295254721Semaste 296254721Semaste#endif // lldb_TypeCategory_h_ 297