LLDB  mainline
TypeCategory.h
Go to the documentation of this file.
1 //===-- TypeCategory.h ------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_DATAFORMATTERS_TYPECATEGORY_H
10 #define LLDB_DATAFORMATTERS_TYPECATEGORY_H
11 
12 #include <initializer_list>
13 #include <memory>
14 #include <mutex>
15 #include <string>
16 #include <vector>
17 
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-public.h"
20 
23 
24 namespace lldb_private {
25 
26 template <typename FormatterImpl> class FormatterContainerPair {
27 public:
31 
34 
36 
39 
40  typedef
42  typedef
44 
45  FormatterContainerPair(const char *exact_name, const char *regex_name,
46  IFormatChangeListener *clist)
47  : m_exact_sp(new ExactMatchContainer(std::string(exact_name), clist)),
48  m_regex_sp(new RegexMatchContainer(std::string(regex_name), clist)) {}
49 
50  ~FormatterContainerPair() = default;
51 
52  ExactMatchContainerSP GetExactMatch() const { return m_exact_sp; }
53 
54  RegexMatchContainerSP GetRegexMatch() const { return m_regex_sp; }
55 
57  return GetExactMatch()->GetCount() + GetRegexMatch()->GetCount();
58  }
59 
60 private:
61  ExactMatchContainerSP m_exact_sp;
62  RegexMatchContainerSP m_regex_sp;
63 };
64 
66 private:
71 
72 public:
74  static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
75 
78 
81 
84 
87 
88  template <typename T> class ForEachCallbacks {
89  public:
90  ForEachCallbacks() = default;
91  ~ForEachCallbacks() = default;
92 
93  template <typename U = TypeFormatImpl>
94  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
96  m_format_exact = callback;
97  return *this;
98  }
99  template <typename U = TypeFormatImpl>
100  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
102  m_format_regex = callback;
103  return *this;
104  }
105 
106  template <typename U = TypeSummaryImpl>
107  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
109  m_summary_exact = callback;
110  return *this;
111  }
112  template <typename U = TypeSummaryImpl>
113  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
115  m_summary_regex = callback;
116  return *this;
117  }
118 
119  template <typename U = TypeFilterImpl>
120  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
122  m_filter_exact = callback;
123  return *this;
124  }
125  template <typename U = TypeFilterImpl>
126  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
128  m_filter_regex = callback;
129  return *this;
130  }
131 
132  template <typename U = SyntheticChildren>
133  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
135  m_synth_exact = callback;
136  return *this;
137  }
138  template <typename U = SyntheticChildren>
139  typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
141  m_synth_regex = callback;
142  return *this;
143  }
144 
146  return m_format_exact;
147  }
149  return m_format_regex;
150  }
151 
154  return m_summary_exact;
155  }
158  return m_summary_regex;
159  }
160 
162  return m_filter_exact;
163  }
165  return m_filter_regex;
166  }
167 
169  return m_synth_exact;
170  }
172  return m_synth_regex;
173  }
174 
175  private:
178 
181 
184 
187  };
188 
190 
191  template <typename T> void ForEach(const ForEachCallbacks<T> &foreach) {
192  GetTypeFormatsContainer()->ForEach(foreach.GetFormatExactCallback());
193  GetRegexTypeFormatsContainer()->ForEach(foreach.GetFormatRegexCallback());
194 
195  GetTypeSummariesContainer()->ForEach(foreach.GetSummaryExactCallback());
196  GetRegexTypeSummariesContainer()->ForEach(
197  foreach.GetSummaryRegexCallback());
198 
199  GetTypeFiltersContainer()->ForEach(foreach.GetFilterExactCallback());
200  GetRegexTypeFiltersContainer()->ForEach(foreach.GetFilterRegexCallback());
201 
202  GetTypeSyntheticsContainer()->ForEach(foreach.GetSynthExactCallback());
203  GetRegexTypeSyntheticsContainer()->ForEach(foreach.GetSynthRegexCallback());
204  }
205 
206  FormatContainerSP GetTypeFormatsContainer() {
207  return m_format_cont.GetExactMatch();
208  }
209 
210  RegexFormatContainerSP GetRegexTypeFormatsContainer() {
211  return m_format_cont.GetRegexMatch();
212  }
213 
214  FormatContainer &GetFormatContainer() { return m_format_cont; }
215 
216  SummaryContainerSP GetTypeSummariesContainer() {
217  return m_summary_cont.GetExactMatch();
218  }
219 
220  RegexSummaryContainerSP GetRegexTypeSummariesContainer() {
221  return m_summary_cont.GetRegexMatch();
222  }
223 
224  SummaryContainer &GetSummaryContainer() { return m_summary_cont; }
225 
226  FilterContainerSP GetTypeFiltersContainer() {
227  return m_filter_cont.GetExactMatch();
228  }
229 
230  RegexFilterContainerSP GetRegexTypeFiltersContainer() {
231  return m_filter_cont.GetRegexMatch();
232  }
233 
234  FilterContainer &GetFilterContainer() { return m_filter_cont; }
235 
237  GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp);
238 
240  GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp);
241 
243  GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp);
244 
246  GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp);
247 
248  lldb::TypeNameSpecifierImplSP
249  GetTypeNameSpecifierForFormatAtIndex(size_t index);
250 
251  lldb::TypeNameSpecifierImplSP
252  GetTypeNameSpecifierForSummaryAtIndex(size_t index);
253 
254  FormatContainer::MapValueType GetFormatAtIndex(size_t index);
255 
256  SummaryContainer::MapValueType GetSummaryAtIndex(size_t index);
257 
258  FilterContainer::MapValueType GetFilterAtIndex(size_t index);
259 
260  lldb::TypeNameSpecifierImplSP
261  GetTypeNameSpecifierForFilterAtIndex(size_t index);
262 
263  SynthContainerSP GetTypeSyntheticsContainer() {
264  return m_synth_cont.GetExactMatch();
265  }
266 
267  RegexSynthContainerSP GetRegexTypeSyntheticsContainer() {
268  return m_synth_cont.GetRegexMatch();
269  }
270 
271  SynthContainer &GetSyntheticsContainer() { return m_synth_cont; }
272 
273  SynthContainer::MapValueType GetSyntheticAtIndex(size_t index);
274 
275  lldb::TypeNameSpecifierImplSP
276  GetTypeNameSpecifierForSyntheticAtIndex(size_t index);
277 
278  bool IsEnabled() const { return m_enabled; }
279 
281  if (!m_enabled)
282  return UINT32_MAX;
283  else
284  return m_enabled_position;
285  }
286 
287  bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
288  lldb::TypeFormatImplSP &entry);
289 
290  bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
291  lldb::TypeSummaryImplSP &entry);
292 
293  bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
294  lldb::SyntheticChildrenSP &entry);
295 
296  void Clear(FormatCategoryItems items = ALL_ITEM_TYPES);
297 
298  bool Delete(ConstString name, FormatCategoryItems items = ALL_ITEM_TYPES);
299 
300  uint32_t GetCount(FormatCategoryItems items = ALL_ITEM_TYPES);
301 
302  const char *GetName() { return m_name.GetCString(); }
303 
304  size_t GetNumLanguages();
305 
306  lldb::LanguageType GetLanguageAtIndex(size_t idx);
307 
308  void AddLanguage(lldb::LanguageType lang);
309 
310  std::string GetDescription();
311 
312  bool AnyMatches(ConstString type_name,
313  FormatCategoryItems items = ALL_ITEM_TYPES,
314  bool only_enabled = true,
315  const char **matching_category = nullptr,
316  FormatCategoryItems *matching_type = nullptr);
317 
318  typedef std::shared_ptr<TypeCategoryImpl> SharedPointer;
319 
320 private:
321  FormatContainer m_format_cont;
322  SummaryContainer m_summary_cont;
323  FilterContainer m_filter_cont;
324  SynthContainer m_synth_cont;
325 
326  bool m_enabled;
327 
329 
330  std::recursive_mutex m_mutex;
331 
333 
334  std::vector<lldb::LanguageType> m_languages;
335 
337 
338  void Enable(bool value, uint32_t position);
339 
340  void Disable() { Enable(false, UINT32_MAX); }
341 
342  bool IsApplicable(lldb::LanguageType lang);
343 
344  uint32_t GetLastEnabledPosition() { return m_enabled_position; }
345 
346  void SetEnabledPosition(uint32_t p) { m_enabled_position = p; }
347 
348  friend class FormatManager;
349  friend class LanguageCategory;
350  friend class TypeCategoryMap;
351 
353  friend class FormattersContainer<lldb::RegularExpressionSP, TypeFormatImpl>;
354 
355  friend class FormattersContainer<ConstString, TypeSummaryImpl>;
356  friend class FormattersContainer<lldb::RegularExpressionSP, TypeSummaryImpl>;
357 
358  friend class FormattersContainer<ConstString, TypeFilterImpl>;
359  friend class FormattersContainer<lldb::RegularExpressionSP, TypeFilterImpl>;
360 
361  friend class FormattersContainer<ConstString, ScriptedSyntheticChildren>;
362  friend class FormattersContainer<lldb::RegularExpressionSP,
363  ScriptedSyntheticChildren>;
364 
365 };
366 
367 } // namespace lldb_private
368 
369 #endif // LLDB_DATAFORMATTERS_TYPECATEGORY_H
FormatContainer & GetFormatContainer()
Definition: TypeCategory.h:214
FormatterContainerPair(const char *exact_name, const char *regex_name, IFormatChangeListener *clist)
Definition: TypeCategory.h:45
FormatContainer::RegexMatchContainerSP RegexFormatContainerSP
Definition: TypeCategory.h:77
BackEndType::ForEachCallback ForEachCallback
A class that represents a running process on the host machine.
FilterContainer::RegexMatchForEachCallback GetFilterRegexCallback() const
Definition: TypeCategory.h:164
FilterContainer::RegexMatchForEachCallback m_filter_regex
Definition: TypeCategory.h:183
RegexMatchContainer::ForEachCallback RegexMatchForEachCallback
Definition: TypeCategory.h:43
SynthContainerSP GetTypeSyntheticsContainer()
Definition: TypeCategory.h:263
FormatterContainerPair< TypeFilterImpl > FilterContainer
Definition: TypeCategory.h:69
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetWithRegex(SynthContainer::RegexMatchForEachCallback callback)
Definition: TypeCategory.h:140
FilterContainer::ExactMatchForEachCallback GetFilterExactCallback() const
Definition: TypeCategory.h:161
ExactMatchContainer::MapValueType MapValueType
Definition: TypeCategory.h:35
FormatterContainerPair< SyntheticChildren > SynthContainer
Definition: TypeCategory.h:70
FormattersContainer< RegularExpression, FormatterImpl > RegexMatchContainer
Definition: TypeCategory.h:30
RegexMatchContainerSP m_regex_sp
Definition: TypeCategory.h:62
RegexMatchContainer::MapType RegexMatchMap
Definition: TypeCategory.h:33
SummaryContainer::ExactMatchForEachCallback m_summary_exact
Definition: TypeCategory.h:179
FormatContainerSP GetTypeFormatsContainer()
Definition: TypeCategory.h:206
SummaryContainer m_summary_cont
Definition: TypeCategory.h:322
ExactMatchContainerSP m_exact_sp
Definition: TypeCategory.h:61
SummaryContainer::RegexMatchForEachCallback m_summary_regex
Definition: TypeCategory.h:180
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetWithRegex(SummaryContainer::RegexMatchForEachCallback callback)
Definition: TypeCategory.h:114
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:318
std::vector< FormattersMatchCandidate > FormattersMatchVector
Definition: FormatClasses.h:81
FormatContainer::ExactMatchForEachCallback GetFormatExactCallback() const
Definition: TypeCategory.h:145
SummaryContainer::ExactMatchForEachCallback GetSummaryExactCallback() const
Definition: TypeCategory.h:153
ExactMatchContainer::MapType ExactMatchMap
Definition: TypeCategory.h:32
SynthContainer::RegexMatchForEachCallback GetSynthRegexCallback() const
Definition: TypeCategory.h:171
ExactMatchContainerSP GetExactMatch() const
Definition: TypeCategory.h:52
FilterContainer & GetFilterContainer()
Definition: TypeCategory.h:234
void SetEnabledPosition(uint32_t p)
Definition: TypeCategory.h:346
RegexFilterContainerSP GetRegexTypeFiltersContainer()
Definition: TypeCategory.h:230
FilterContainerSP GetTypeFiltersContainer()
Definition: TypeCategory.h:226
#define UINT32_MAX
Definition: lldb-defines.h:31
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetWithRegex(FilterContainer::RegexMatchForEachCallback callback)
Definition: TypeCategory.h:127
SummaryContainer::RegexMatchForEachCallback GetSummaryRegexCallback() const
Definition: TypeCategory.h:157
static bool IsApplicable(lldb::LanguageType category_lang, lldb::LanguageType valobj_lang)
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetExact(SummaryContainer::ExactMatchForEachCallback callback)
Definition: TypeCategory.h:108
LanguageType
Programming language type.
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetExact(FormatContainer::ExactMatchForEachCallback callback)
Definition: TypeCategory.h:95
FormatterContainerPair< TypeFormatImpl > FormatContainer
Definition: TypeCategory.h:67
SummaryContainerSP GetTypeSummariesContainer()
Definition: TypeCategory.h:216
ExactMatchContainer::ForEachCallback ExactMatchForEachCallback
Definition: TypeCategory.h:41
SynthContainer & GetSyntheticsContainer()
Definition: TypeCategory.h:271
FilterContainer::ExactMatchContainerSP FilterContainerSP
Definition: TypeCategory.h:82
void ForEach(const ForEachCallbacks< T > &foreach)
Definition: TypeCategory.h:191
SynthContainer::ExactMatchContainerSP SynthContainerSP
Definition: TypeCategory.h:85
FilterContainer::ExactMatchForEachCallback m_filter_exact
Definition: TypeCategory.h:182
FormatContainer::ExactMatchContainerSP FormatContainerSP
Definition: TypeCategory.h:76
std::shared_ptr< FormattersContainer< KeyType, ValueType > > SharedPointer
FormatContainer::RegexMatchForEachCallback m_format_regex
Definition: TypeCategory.h:177
FormatContainer::ExactMatchForEachCallback m_format_exact
Definition: TypeCategory.h:176
std::recursive_mutex m_mutex
Definition: TypeCategory.h:330
RegexFormatContainerSP GetRegexTypeFormatsContainer()
Definition: TypeCategory.h:210
RegexMatchContainer::SharedPointer RegexMatchContainerSP
Definition: TypeCategory.h:38
RegexSummaryContainerSP GetRegexTypeSummariesContainer()
Definition: TypeCategory.h:220
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetExact(SynthContainer::ExactMatchForEachCallback callback)
Definition: TypeCategory.h:134
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetExact(FilterContainer::ExactMatchForEachCallback callback)
Definition: TypeCategory.h:121
SummaryContainer::ExactMatchContainerSP SummaryContainerSP
Definition: TypeCategory.h:79
FormatContainer::RegexMatchForEachCallback GetFormatRegexCallback() const
Definition: TypeCategory.h:148
A uniqued constant string class.
Definition: ConstString.h:40
Definition: SBAddress.h:15
SynthContainer::RegexMatchForEachCallback m_synth_regex
Definition: TypeCategory.h:186
SynthContainer::ExactMatchForEachCallback GetSynthExactCallback() const
Definition: TypeCategory.h:168
std::shared_ptr< ValueType > MapValueType
FormattersContainer< ConstString, FormatterImpl > ExactMatchContainer
Definition: TypeCategory.h:28
SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP
Definition: TypeCategory.h:80
SummaryContainer & GetSummaryContainer()
Definition: TypeCategory.h:224
std::vector< lldb::LanguageType > m_languages
Definition: TypeCategory.h:334
IFormatChangeListener * m_change_listener
Definition: TypeCategory.h:328
FormatterContainerPair< TypeSummaryImpl > SummaryContainer
Definition: TypeCategory.h:68
std::enable_if< std::is_same< U, T >::value, ForEachCallbacks & >::type SetWithRegex(FormatContainer::RegexMatchForEachCallback callback)
Definition: TypeCategory.h:101
RegexMatchContainerSP GetRegexMatch() const
Definition: TypeCategory.h:54
SynthContainer::RegexMatchContainerSP RegexSynthContainerSP
Definition: TypeCategory.h:86
RegexSynthContainerSP GetRegexTypeSyntheticsContainer()
Definition: TypeCategory.h:267
SynthContainer::ExactMatchForEachCallback m_synth_exact
Definition: TypeCategory.h:185
FilterContainer::RegexMatchContainerSP RegexFilterContainerSP
Definition: TypeCategory.h:83
ExactMatchContainer::SharedPointer ExactMatchContainerSP
Definition: TypeCategory.h:37