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