TypeCategory.h revision 269024
1//===-- TypeCategory.h -------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef lldb_TypeCategory_h_ 11#define lldb_TypeCategory_h_ 12 13// C Includes 14// C++ Includes 15 16// Other libraries and framework includes 17// Project includes 18#include "lldb/lldb-public.h" 19#include "lldb/lldb-enumerations.h" 20 21#include "lldb/DataFormatters/FormatClasses.h" 22#include "lldb/DataFormatters/FormattersContainer.h" 23 24namespace lldb_private { 25 26 template <typename FormatterImpl> 27 class FormatterContainerPair 28 { 29 public: 30 typedef FormattersContainer<ConstString, FormatterImpl> ExactMatchContainer; 31 typedef FormattersContainer<lldb::RegularExpressionSP, FormatterImpl> RegexMatchContainer; 32 33 typedef typename ExactMatchContainer::MapType ExactMatchMap; 34 typedef typename RegexMatchContainer::MapType RegexMatchMap; 35 36 typedef typename ExactMatchContainer::MapValueType MapValueType; 37 38 typedef typename ExactMatchContainer::SharedPointer ExactMatchContainerSP; 39 typedef typename RegexMatchContainer::SharedPointer RegexMatchContainerSP; 40 41 FormatterContainerPair (const char* exact_name, 42 const char* regex_name, 43 IFormatChangeListener* clist) : 44 m_exact_sp(new ExactMatchContainer(std::string(exact_name),clist)), 45 m_regex_sp(new RegexMatchContainer(std::string(regex_name),clist)) 46 { 47 } 48 49 ~FormatterContainerPair () = default; 50 51 ExactMatchContainerSP 52 GetExactMatch () const 53 { 54 return m_exact_sp; 55 } 56 57 RegexMatchContainerSP 58 GetRegexMatch () const 59 { 60 return m_regex_sp; 61 } 62 63 private: 64 ExactMatchContainerSP m_exact_sp; 65 RegexMatchContainerSP m_regex_sp; 66 }; 67 68 class TypeCategoryImpl 69 { 70 private: 71 typedef FormatterContainerPair<TypeFormatImpl> FormatContainer; 72 typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer; 73 typedef FormatterContainerPair<TypeFilterImpl> FilterContainer; 74 75#ifndef LLDB_DISABLE_PYTHON 76 typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer; 77#endif // #ifndef LLDB_DISABLE_PYTHON 78 79 public: 80 81 typedef uint16_t FormatCategoryItems; 82 static const uint16_t ALL_ITEM_TYPES = UINT16_MAX; 83 84 typedef FormatContainer::ExactMatchContainerSP FormatContainerSP; 85 typedef FormatContainer::RegexMatchContainerSP RegexFormatContainerSP; 86 87 typedef SummaryContainer::ExactMatchContainerSP SummaryContainerSP; 88 typedef SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP; 89 90 typedef FilterContainer::ExactMatchContainerSP FilterContainerSP; 91 typedef FilterContainer::RegexMatchContainerSP RegexFilterContainerSP; 92#ifndef LLDB_DISABLE_PYTHON 93 typedef SynthContainer::ExactMatchContainerSP SynthContainerSP; 94 typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP; 95#endif // #ifndef LLDB_DISABLE_PYTHON 96 97 TypeCategoryImpl (IFormatChangeListener* clist, 98 ConstString name); 99 100 FormatContainerSP 101 GetTypeFormatsContainer () 102 { 103 return m_format_cont.GetExactMatch(); 104 } 105 106 RegexFormatContainerSP 107 GetRegexTypeFormatsContainer () 108 { 109 return m_format_cont.GetRegexMatch(); 110 } 111 112 SummaryContainerSP 113 GetTypeSummariesContainer () 114 { 115 return m_summary_cont.GetExactMatch(); 116 } 117 118 RegexSummaryContainerSP 119 GetRegexTypeSummariesContainer () 120 { 121 return m_summary_cont.GetRegexMatch(); 122 } 123 124 FilterContainerSP 125 GetTypeFiltersContainer () 126 { 127 return m_filter_cont.GetExactMatch(); 128 } 129 130 RegexFilterContainerSP 131 GetRegexTypeFiltersContainer () 132 { 133 return m_filter_cont.GetRegexMatch(); 134 } 135 136 FormatContainer::MapValueType 137 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp); 138 139 SummaryContainer::MapValueType 140 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp); 141 142 FilterContainer::MapValueType 143 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp); 144 145#ifndef LLDB_DISABLE_PYTHON 146 SynthContainer::MapValueType 147 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp); 148#endif 149 150 lldb::TypeNameSpecifierImplSP 151 GetTypeNameSpecifierForFormatAtIndex (size_t index); 152 153 lldb::TypeNameSpecifierImplSP 154 GetTypeNameSpecifierForSummaryAtIndex (size_t index); 155 156 FormatContainer::MapValueType 157 GetFormatAtIndex (size_t index); 158 159 SummaryContainer::MapValueType 160 GetSummaryAtIndex (size_t index); 161 162 FilterContainer::MapValueType 163 GetFilterAtIndex (size_t index); 164 165 lldb::TypeNameSpecifierImplSP 166 GetTypeNameSpecifierForFilterAtIndex (size_t index); 167 168#ifndef LLDB_DISABLE_PYTHON 169 SynthContainerSP 170 GetTypeSyntheticsContainer () 171 { 172 return m_synth_cont.GetExactMatch(); 173 } 174 175 RegexSynthContainerSP 176 GetRegexTypeSyntheticsContainer () 177 { 178 return m_synth_cont.GetRegexMatch(); 179 } 180 181 SynthContainer::MapValueType 182 GetSyntheticAtIndex (size_t index); 183 184 lldb::TypeNameSpecifierImplSP 185 GetTypeNameSpecifierForSyntheticAtIndex (size_t index); 186 187#endif // #ifndef LLDB_DISABLE_PYTHON 188 189 bool 190 IsEnabled () const 191 { 192 return m_enabled; 193 } 194 195 uint32_t 196 GetEnabledPosition() 197 { 198 if (m_enabled == false) 199 return UINT32_MAX; 200 else 201 return m_enabled_position; 202 } 203 204 bool 205 Get (ValueObject& valobj, 206 const FormattersMatchVector& candidates, 207 lldb::TypeFormatImplSP& entry, 208 uint32_t* reason = NULL); 209 210 bool 211 Get (ValueObject& valobj, 212 const FormattersMatchVector& candidates, 213 lldb::TypeSummaryImplSP& entry, 214 uint32_t* reason = NULL); 215 216 bool 217 Get (ValueObject& valobj, 218 const FormattersMatchVector& candidates, 219 lldb::SyntheticChildrenSP& entry, 220 uint32_t* reason = NULL); 221 222 void 223 Clear (FormatCategoryItems items = ALL_ITEM_TYPES); 224 225 bool 226 Delete (ConstString name, 227 FormatCategoryItems items = ALL_ITEM_TYPES); 228 229 uint32_t 230 GetCount (FormatCategoryItems items = ALL_ITEM_TYPES); 231 232 const char* 233 GetName () 234 { 235 return m_name.GetCString(); 236 } 237 238 bool 239 AnyMatches (ConstString type_name, 240 FormatCategoryItems items = ALL_ITEM_TYPES, 241 bool only_enabled = true, 242 const char** matching_category = NULL, 243 FormatCategoryItems* matching_type = NULL); 244 245 typedef std::shared_ptr<TypeCategoryImpl> SharedPointer; 246 247 private: 248 FormatContainer m_format_cont; 249 250 SummaryContainer m_summary_cont; 251 252 FilterContainer m_filter_cont; 253 254#ifndef LLDB_DISABLE_PYTHON 255 SynthContainer m_synth_cont; 256#endif // #ifndef LLDB_DISABLE_PYTHON 257 258 bool m_enabled; 259 260 IFormatChangeListener* m_change_listener; 261 262 Mutex m_mutex; 263 264 ConstString m_name; 265 266 uint32_t m_enabled_position; 267 268 void 269 Enable (bool value, uint32_t position); 270 271 void 272 Disable () 273 { 274 Enable(false, UINT32_MAX); 275 } 276 277 friend class TypeCategoryMap; 278 279 friend class FormattersContainer<ConstString, TypeFormatImpl>; 280 friend class FormattersContainer<lldb::RegularExpressionSP, TypeFormatImpl>; 281 282 friend class FormattersContainer<ConstString, TypeSummaryImpl>; 283 friend class FormattersContainer<lldb::RegularExpressionSP, TypeSummaryImpl>; 284 285 friend class FormattersContainer<ConstString, TypeFilterImpl>; 286 friend class FormattersContainer<lldb::RegularExpressionSP, TypeFilterImpl>; 287 288#ifndef LLDB_DISABLE_PYTHON 289 friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>; 290 friend class FormattersContainer<lldb::RegularExpressionSP, ScriptedSyntheticChildren>; 291#endif // #ifndef LLDB_DISABLE_PYTHON 292 }; 293 294} // namespace lldb_private 295 296#endif // lldb_TypeCategory_h_ 297