]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/DataFormatters/TypeCategory.cpp
MFV r319744,r319745: 8269 dtrace stddev aggregation is normalized incorrectly
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / DataFormatters / TypeCategory.cpp
1 //===-- TypeCategory.cpp -----------------------------------------*- 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 #include "lldb/DataFormatters/TypeCategory.h"
11 #include "lldb/Target/Language.h"
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 TypeCategoryImpl::TypeCategoryImpl(
22     IFormatChangeListener *clist, ConstString name,
23     std::initializer_list<lldb::LanguageType> langs)
24     : m_format_cont("format", "regex-format", clist),
25       m_summary_cont("summary", "regex-summary", clist),
26       m_filter_cont("filter", "regex-filter", clist),
27 #ifndef LLDB_DISABLE_PYTHON
28       m_synth_cont("synth", "regex-synth", clist),
29 #endif
30       m_validator_cont("validator", "regex-validator", clist), m_enabled(false),
31       m_change_listener(clist), m_mutex(), m_name(name), m_languages() {
32   for (const lldb::LanguageType lang : langs)
33     AddLanguage(lang);
34 }
35
36 static bool IsApplicable(lldb::LanguageType category_lang,
37                          lldb::LanguageType valobj_lang) {
38   switch (category_lang) {
39   // these are not languages that LLDB would ordinarily deal with
40   // only allow an exact equality here, since we really don't know
41   // any better
42   case eLanguageTypeAda83:
43   case eLanguageTypeCobol74:
44   case eLanguageTypeCobol85:
45   case eLanguageTypeFortran77:
46   case eLanguageTypeFortran90:
47   case eLanguageTypePascal83:
48   case eLanguageTypeModula2:
49   case eLanguageTypeJava:
50   case eLanguageTypeAda95:
51   case eLanguageTypeFortran95:
52   case eLanguageTypePLI:
53   case eLanguageTypeUPC:
54   case eLanguageTypeD:
55   case eLanguageTypePython:
56     return category_lang == valobj_lang;
57
58   // the C family, we consider it as one
59   case eLanguageTypeC89:
60   case eLanguageTypeC:
61   case eLanguageTypeC99:
62     return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
63            valobj_lang == eLanguageTypeC99;
64
65   // ObjC knows about C and itself
66   case eLanguageTypeObjC:
67     return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
68            valobj_lang == eLanguageTypeC99 || valobj_lang == eLanguageTypeObjC;
69
70   // C++ knows about C and C++
71   case eLanguageTypeC_plus_plus:
72     return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
73            valobj_lang == eLanguageTypeC99 ||
74            valobj_lang == eLanguageTypeC_plus_plus;
75
76   // ObjC++ knows about C,C++,ObjC and ObjC++
77   case eLanguageTypeObjC_plus_plus:
78     return valobj_lang == eLanguageTypeC89 || valobj_lang == eLanguageTypeC ||
79            valobj_lang == eLanguageTypeC99 ||
80            valobj_lang == eLanguageTypeC_plus_plus ||
81            valobj_lang == eLanguageTypeObjC;
82
83   default:
84   case eLanguageTypeUnknown:
85     return true;
86   }
87 }
88
89 bool TypeCategoryImpl::IsApplicable(ValueObject &valobj) {
90   lldb::LanguageType valobj_lang = valobj.GetObjectRuntimeLanguage();
91   for (size_t idx = 0; idx < GetNumLanguages(); idx++) {
92     const lldb::LanguageType category_lang = GetLanguageAtIndex(idx);
93     if (::IsApplicable(category_lang, valobj_lang))
94       return true;
95   }
96   return false;
97 }
98
99 size_t TypeCategoryImpl::GetNumLanguages() {
100   if (m_languages.empty())
101     return 1;
102   return m_languages.size();
103 }
104
105 lldb::LanguageType TypeCategoryImpl::GetLanguageAtIndex(size_t idx) {
106   if (m_languages.empty())
107     return lldb::eLanguageTypeUnknown;
108   return m_languages[idx];
109 }
110
111 void TypeCategoryImpl::AddLanguage(lldb::LanguageType lang) {
112   m_languages.push_back(lang);
113 }
114
115 bool TypeCategoryImpl::HasLanguage(lldb::LanguageType lang) {
116   const auto iter = std::find(m_languages.begin(), m_languages.end(), lang),
117              end = m_languages.end();
118   return (iter != end);
119 }
120
121 bool TypeCategoryImpl::Get(ValueObject &valobj,
122                            const FormattersMatchVector &candidates,
123                            lldb::TypeFormatImplSP &entry, uint32_t *reason) {
124   if (!IsEnabled() || !IsApplicable(valobj))
125     return false;
126   if (GetTypeFormatsContainer()->Get(candidates, entry, reason))
127     return true;
128   bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason);
129   if (regex && reason)
130     *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
131   return regex;
132 }
133
134 bool TypeCategoryImpl::Get(ValueObject &valobj,
135                            const FormattersMatchVector &candidates,
136                            lldb::TypeSummaryImplSP &entry, uint32_t *reason) {
137   if (!IsEnabled() || !IsApplicable(valobj))
138     return false;
139   if (GetTypeSummariesContainer()->Get(candidates, entry, reason))
140     return true;
141   bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason);
142   if (regex && reason)
143     *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
144   return regex;
145 }
146
147 bool TypeCategoryImpl::Get(ValueObject &valobj,
148                            const FormattersMatchVector &candidates,
149                            lldb::SyntheticChildrenSP &entry, uint32_t *reason) {
150   if (!IsEnabled() || !IsApplicable(valobj))
151     return false;
152   TypeFilterImpl::SharedPointer filter_sp;
153   uint32_t reason_filter = 0;
154   bool regex_filter = false;
155   // first find both Filter and Synth, and then check which is most recent
156
157   if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter))
158     regex_filter = GetRegexTypeFiltersContainer()->Get(candidates, filter_sp,
159                                                        &reason_filter);
160
161 #ifndef LLDB_DISABLE_PYTHON
162   bool regex_synth = false;
163   uint32_t reason_synth = 0;
164   bool pick_synth = false;
165   ScriptedSyntheticChildren::SharedPointer synth;
166   if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth))
167     regex_synth = GetRegexTypeSyntheticsContainer()->Get(candidates, synth,
168                                                          &reason_synth);
169   if (!filter_sp.get() && !synth.get())
170     return false;
171   else if (!filter_sp.get() && synth.get())
172     pick_synth = true;
173
174   else if (filter_sp.get() && !synth.get())
175     pick_synth = false;
176
177   else /*if (filter_sp.get() && synth.get())*/
178   {
179     if (filter_sp->GetRevision() > synth->GetRevision())
180       pick_synth = false;
181     else
182       pick_synth = true;
183   }
184   if (pick_synth) {
185     if (regex_synth && reason)
186       *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter;
187     entry = synth;
188     return true;
189   } else {
190     if (regex_filter && reason)
191       *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter;
192     entry = filter_sp;
193     return true;
194   }
195
196 #else
197   if (filter_sp) {
198     entry = filter_sp;
199     return true;
200   }
201 #endif
202
203   return false;
204 }
205
206 bool TypeCategoryImpl::Get(ValueObject &valobj,
207                            const FormattersMatchVector &candidates,
208                            lldb::TypeValidatorImplSP &entry, uint32_t *reason) {
209   if (!IsEnabled())
210     return false;
211   if (GetTypeValidatorsContainer()->Get(candidates, entry, reason))
212     return true;
213   bool regex =
214       GetRegexTypeValidatorsContainer()->Get(candidates, entry, reason);
215   if (regex && reason)
216     *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
217   return regex;
218 }
219
220 void TypeCategoryImpl::Clear(FormatCategoryItems items) {
221   if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue)
222     GetTypeFormatsContainer()->Clear();
223   if ((items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue)
224     GetRegexTypeFormatsContainer()->Clear();
225
226   if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary)
227     GetTypeSummariesContainer()->Clear();
228   if ((items & eFormatCategoryItemRegexSummary) ==
229       eFormatCategoryItemRegexSummary)
230     GetRegexTypeSummariesContainer()->Clear();
231
232   if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter)
233     GetTypeFiltersContainer()->Clear();
234   if ((items & eFormatCategoryItemRegexFilter) ==
235       eFormatCategoryItemRegexFilter)
236     GetRegexTypeFiltersContainer()->Clear();
237
238 #ifndef LLDB_DISABLE_PYTHON
239   if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth)
240     GetTypeSyntheticsContainer()->Clear();
241   if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth)
242     GetRegexTypeSyntheticsContainer()->Clear();
243 #endif
244
245   if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator)
246     GetTypeValidatorsContainer()->Clear();
247   if ((items & eFormatCategoryItemRegexValidator) ==
248       eFormatCategoryItemRegexValidator)
249     GetRegexTypeValidatorsContainer()->Clear();
250 }
251
252 bool TypeCategoryImpl::Delete(ConstString name, FormatCategoryItems items) {
253   bool success = false;
254
255   if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue)
256     success = GetTypeFormatsContainer()->Delete(name) || success;
257   if ((items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue)
258     success = GetRegexTypeFormatsContainer()->Delete(name) || success;
259
260   if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary)
261     success = GetTypeSummariesContainer()->Delete(name) || success;
262   if ((items & eFormatCategoryItemRegexSummary) ==
263       eFormatCategoryItemRegexSummary)
264     success = GetRegexTypeSummariesContainer()->Delete(name) || success;
265
266   if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter)
267     success = GetTypeFiltersContainer()->Delete(name) || success;
268   if ((items & eFormatCategoryItemRegexFilter) ==
269       eFormatCategoryItemRegexFilter)
270     success = GetRegexTypeFiltersContainer()->Delete(name) || success;
271
272 #ifndef LLDB_DISABLE_PYTHON
273   if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth)
274     success = GetTypeSyntheticsContainer()->Delete(name) || success;
275   if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth)
276     success = GetRegexTypeSyntheticsContainer()->Delete(name) || success;
277 #endif
278
279   if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator)
280     success = GetTypeValidatorsContainer()->Delete(name) || success;
281   if ((items & eFormatCategoryItemRegexValidator) ==
282       eFormatCategoryItemRegexValidator)
283     success = GetRegexTypeValidatorsContainer()->Delete(name) || success;
284
285   return success;
286 }
287
288 uint32_t TypeCategoryImpl::GetCount(FormatCategoryItems items) {
289   uint32_t count = 0;
290
291   if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue)
292     count += GetTypeFormatsContainer()->GetCount();
293   if ((items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue)
294     count += GetRegexTypeFormatsContainer()->GetCount();
295
296   if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary)
297     count += GetTypeSummariesContainer()->GetCount();
298   if ((items & eFormatCategoryItemRegexSummary) ==
299       eFormatCategoryItemRegexSummary)
300     count += GetRegexTypeSummariesContainer()->GetCount();
301
302   if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter)
303     count += GetTypeFiltersContainer()->GetCount();
304   if ((items & eFormatCategoryItemRegexFilter) ==
305       eFormatCategoryItemRegexFilter)
306     count += GetRegexTypeFiltersContainer()->GetCount();
307
308 #ifndef LLDB_DISABLE_PYTHON
309   if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth)
310     count += GetTypeSyntheticsContainer()->GetCount();
311   if ((items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth)
312     count += GetRegexTypeSyntheticsContainer()->GetCount();
313 #endif
314
315   if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator)
316     count += GetTypeValidatorsContainer()->GetCount();
317   if ((items & eFormatCategoryItemRegexValidator) ==
318       eFormatCategoryItemRegexValidator)
319     count += GetRegexTypeValidatorsContainer()->GetCount();
320
321   return count;
322 }
323
324 bool TypeCategoryImpl::AnyMatches(ConstString type_name,
325                                   FormatCategoryItems items, bool only_enabled,
326                                   const char **matching_category,
327                                   FormatCategoryItems *matching_type) {
328   if (!IsEnabled() && only_enabled)
329     return false;
330
331   lldb::TypeFormatImplSP format_sp;
332   lldb::TypeSummaryImplSP summary_sp;
333   TypeFilterImpl::SharedPointer filter_sp;
334 #ifndef LLDB_DISABLE_PYTHON
335   ScriptedSyntheticChildren::SharedPointer synth_sp;
336 #endif
337   TypeValidatorImpl::SharedPointer validator_sp;
338
339   if ((items & eFormatCategoryItemValue) == eFormatCategoryItemValue) {
340     if (GetTypeFormatsContainer()->Get(type_name, format_sp)) {
341       if (matching_category)
342         *matching_category = m_name.GetCString();
343       if (matching_type)
344         *matching_type = eFormatCategoryItemValue;
345       return true;
346     }
347   }
348   if ((items & eFormatCategoryItemRegexValue) ==
349       eFormatCategoryItemRegexValue) {
350     if (GetRegexTypeFormatsContainer()->Get(type_name, format_sp)) {
351       if (matching_category)
352         *matching_category = m_name.GetCString();
353       if (matching_type)
354         *matching_type = eFormatCategoryItemRegexValue;
355       return true;
356     }
357   }
358
359   if ((items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary) {
360     if (GetTypeSummariesContainer()->Get(type_name, summary_sp)) {
361       if (matching_category)
362         *matching_category = m_name.GetCString();
363       if (matching_type)
364         *matching_type = eFormatCategoryItemSummary;
365       return true;
366     }
367   }
368   if ((items & eFormatCategoryItemRegexSummary) ==
369       eFormatCategoryItemRegexSummary) {
370     if (GetRegexTypeSummariesContainer()->Get(type_name, summary_sp)) {
371       if (matching_category)
372         *matching_category = m_name.GetCString();
373       if (matching_type)
374         *matching_type = eFormatCategoryItemRegexSummary;
375       return true;
376     }
377   }
378
379   if ((items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter) {
380     if (GetTypeFiltersContainer()->Get(type_name, filter_sp)) {
381       if (matching_category)
382         *matching_category = m_name.GetCString();
383       if (matching_type)
384         *matching_type = eFormatCategoryItemFilter;
385       return true;
386     }
387   }
388   if ((items & eFormatCategoryItemRegexFilter) ==
389       eFormatCategoryItemRegexFilter) {
390     if (GetRegexTypeFiltersContainer()->Get(type_name, filter_sp)) {
391       if (matching_category)
392         *matching_category = m_name.GetCString();
393       if (matching_type)
394         *matching_type = eFormatCategoryItemRegexFilter;
395       return true;
396     }
397   }
398
399 #ifndef LLDB_DISABLE_PYTHON
400   if ((items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth) {
401     if (GetTypeSyntheticsContainer()->Get(type_name, synth_sp)) {
402       if (matching_category)
403         *matching_category = m_name.GetCString();
404       if (matching_type)
405         *matching_type = eFormatCategoryItemSynth;
406       return true;
407     }
408   }
409   if ((items & eFormatCategoryItemRegexSynth) ==
410       eFormatCategoryItemRegexSynth) {
411     if (GetRegexTypeSyntheticsContainer()->Get(type_name, synth_sp)) {
412       if (matching_category)
413         *matching_category = m_name.GetCString();
414       if (matching_type)
415         *matching_type = eFormatCategoryItemRegexSynth;
416       return true;
417     }
418   }
419 #endif
420
421   if ((items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator) {
422     if (GetTypeValidatorsContainer()->Get(type_name, validator_sp)) {
423       if (matching_category)
424         *matching_category = m_name.GetCString();
425       if (matching_type)
426         *matching_type = eFormatCategoryItemValidator;
427       return true;
428     }
429   }
430   if ((items & eFormatCategoryItemRegexValidator) ==
431       eFormatCategoryItemRegexValidator) {
432     if (GetRegexTypeValidatorsContainer()->Get(type_name, validator_sp)) {
433       if (matching_category)
434         *matching_category = m_name.GetCString();
435       if (matching_type)
436         *matching_type = eFormatCategoryItemRegexValidator;
437       return true;
438     }
439   }
440
441   return false;
442 }
443
444 TypeCategoryImpl::FormatContainer::MapValueType
445 TypeCategoryImpl::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
446   FormatContainer::MapValueType retval;
447
448   if (type_sp) {
449     if (type_sp->IsRegex())
450       GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),
451                                                retval);
452     else
453       GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),
454                                           retval);
455   }
456
457   return retval;
458 }
459
460 TypeCategoryImpl::SummaryContainer::MapValueType
461 TypeCategoryImpl::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
462   SummaryContainer::MapValueType retval;
463
464   if (type_sp) {
465     if (type_sp->IsRegex())
466       GetRegexTypeSummariesContainer()->GetExact(
467           ConstString(type_sp->GetName()), retval);
468     else
469       GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),
470                                             retval);
471   }
472
473   return retval;
474 }
475
476 TypeCategoryImpl::FilterContainer::MapValueType
477 TypeCategoryImpl::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
478   FilterContainer::MapValueType retval;
479
480   if (type_sp) {
481     if (type_sp->IsRegex())
482       GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),
483                                                retval);
484     else
485       GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),
486                                           retval);
487   }
488
489   return retval;
490 }
491
492 #ifndef LLDB_DISABLE_PYTHON
493 TypeCategoryImpl::SynthContainer::MapValueType
494 TypeCategoryImpl::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
495   SynthContainer::MapValueType retval;
496
497   if (type_sp) {
498     if (type_sp->IsRegex())
499       GetRegexTypeSyntheticsContainer()->GetExact(
500           ConstString(type_sp->GetName()), retval);
501     else
502       GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),
503                                              retval);
504   }
505
506   return retval;
507 }
508 #endif
509
510 TypeCategoryImpl::ValidatorContainer::MapValueType
511 TypeCategoryImpl::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) {
512   ValidatorContainer::MapValueType retval;
513
514   if (type_sp) {
515     if (type_sp->IsRegex())
516       GetRegexTypeValidatorsContainer()->GetExact(
517           ConstString(type_sp->GetName()), retval);
518     else
519       GetTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()),
520                                              retval);
521   }
522
523   return retval;
524 }
525
526 lldb::TypeNameSpecifierImplSP
527 TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex(size_t index) {
528   if (index < GetTypeSummariesContainer()->GetCount())
529     return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index);
530   else
531     return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(
532         index - GetTypeSummariesContainer()->GetCount());
533 }
534
535 TypeCategoryImpl::FormatContainer::MapValueType
536 TypeCategoryImpl::GetFormatAtIndex(size_t index) {
537   if (index < GetTypeFormatsContainer()->GetCount())
538     return GetTypeFormatsContainer()->GetAtIndex(index);
539   else
540     return GetRegexTypeFormatsContainer()->GetAtIndex(
541         index - GetTypeFormatsContainer()->GetCount());
542 }
543
544 TypeCategoryImpl::SummaryContainer::MapValueType
545 TypeCategoryImpl::GetSummaryAtIndex(size_t index) {
546   if (index < GetTypeSummariesContainer()->GetCount())
547     return GetTypeSummariesContainer()->GetAtIndex(index);
548   else
549     return GetRegexTypeSummariesContainer()->GetAtIndex(
550         index - GetTypeSummariesContainer()->GetCount());
551 }
552
553 TypeCategoryImpl::FilterContainer::MapValueType
554 TypeCategoryImpl::GetFilterAtIndex(size_t index) {
555   if (index < GetTypeFiltersContainer()->GetCount())
556     return GetTypeFiltersContainer()->GetAtIndex(index);
557   else
558     return GetRegexTypeFiltersContainer()->GetAtIndex(
559         index - GetTypeFiltersContainer()->GetCount());
560 }
561
562 lldb::TypeNameSpecifierImplSP
563 TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex(size_t index) {
564   if (index < GetTypeFormatsContainer()->GetCount())
565     return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index);
566   else
567     return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(
568         index - GetTypeFormatsContainer()->GetCount());
569 }
570
571 lldb::TypeNameSpecifierImplSP
572 TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex(size_t index) {
573   if (index < GetTypeFiltersContainer()->GetCount())
574     return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index);
575   else
576     return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(
577         index - GetTypeFiltersContainer()->GetCount());
578 }
579
580 #ifndef LLDB_DISABLE_PYTHON
581 TypeCategoryImpl::SynthContainer::MapValueType
582 TypeCategoryImpl::GetSyntheticAtIndex(size_t index) {
583   if (index < GetTypeSyntheticsContainer()->GetCount())
584     return GetTypeSyntheticsContainer()->GetAtIndex(index);
585   else
586     return GetRegexTypeSyntheticsContainer()->GetAtIndex(
587         index - GetTypeSyntheticsContainer()->GetCount());
588 }
589
590 lldb::TypeNameSpecifierImplSP
591 TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex(size_t index) {
592   if (index < GetTypeSyntheticsContainer()->GetCount())
593     return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index);
594   else
595     return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(
596         index - GetTypeSyntheticsContainer()->GetCount());
597 }
598 #endif
599
600 TypeCategoryImpl::ValidatorContainer::MapValueType
601 TypeCategoryImpl::GetValidatorAtIndex(size_t index) {
602   if (index < GetTypeValidatorsContainer()->GetCount())
603     return GetTypeValidatorsContainer()->GetAtIndex(index);
604   else
605     return GetRegexTypeValidatorsContainer()->GetAtIndex(
606         index - GetTypeValidatorsContainer()->GetCount());
607 }
608
609 lldb::TypeNameSpecifierImplSP
610 TypeCategoryImpl::GetTypeNameSpecifierForValidatorAtIndex(size_t index) {
611   if (index < GetTypeValidatorsContainer()->GetCount())
612     return GetTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index);
613   else
614     return GetRegexTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(
615         index - GetTypeValidatorsContainer()->GetCount());
616 }
617
618 void TypeCategoryImpl::Enable(bool value, uint32_t position) {
619   std::lock_guard<std::recursive_mutex> guard(m_mutex);
620   if ((m_enabled = value))
621     m_enabled_position = position;
622   if (m_change_listener)
623     m_change_listener->Changed();
624 }
625
626 std::string TypeCategoryImpl::GetDescription() {
627   StreamString stream;
628   stream.Printf("%s (%s", GetName(), (IsEnabled() ? "enabled" : "disabled"));
629   StreamString lang_stream;
630   lang_stream.Printf(", applicable for language(s): ");
631   bool print_lang = false;
632   for (size_t idx = 0; idx < GetNumLanguages(); idx++) {
633     const lldb::LanguageType lang = GetLanguageAtIndex(idx);
634     if (lang != lldb::eLanguageTypeUnknown)
635       print_lang = true;
636     lang_stream.Printf("%s%s", Language::GetNameForLanguageType(lang),
637                        idx + 1 < GetNumLanguages() ? ", " : "");
638   }
639   if (print_lang)
640     stream.PutCString(lang_stream.GetString());
641   stream.PutChar(')');
642   return stream.GetString();
643 }