1 //===-- TypeCategory.cpp -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/DataFormatters/TypeCategory.h"
14 // Other libraries and framework includes
18 using namespace lldb_private;
20 TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener* clist,
22 m_format_cont("format","regex-format",clist),
23 m_summary_cont("summary","regex-summary",clist),
24 m_filter_cont("filter","regex-filter",clist),
25 #ifndef LLDB_DISABLE_PYTHON
26 m_synth_cont("synth","regex-synth",clist),
28 m_validator_cont("validator","regex-validator",clist),
30 m_change_listener(clist),
31 m_mutex(Mutex::eMutexTypeRecursive),
36 TypeCategoryImpl::Get (ValueObject& valobj,
37 const FormattersMatchVector& candidates,
38 lldb::TypeFormatImplSP& entry,
43 if (GetTypeFormatsContainer()->Get(candidates, entry, reason))
45 bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason);
47 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
52 TypeCategoryImpl::Get (ValueObject& valobj,
53 const FormattersMatchVector& candidates,
54 lldb::TypeSummaryImplSP& entry,
59 if (GetTypeSummariesContainer()->Get(candidates, entry, reason))
61 bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason);
63 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
68 TypeCategoryImpl::Get (ValueObject& valobj,
69 const FormattersMatchVector& candidates,
70 lldb::SyntheticChildrenSP& entry,
75 TypeFilterImpl::SharedPointer filter_sp;
76 uint32_t reason_filter = 0;
77 bool regex_filter = false;
78 // first find both Filter and Synth, and then check which is most recent
80 if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter))
81 regex_filter = GetRegexTypeFiltersContainer()->Get (candidates, filter_sp, &reason_filter);
83 #ifndef LLDB_DISABLE_PYTHON
84 bool regex_synth = false;
85 uint32_t reason_synth = 0;
86 bool pick_synth = false;
87 ScriptedSyntheticChildren::SharedPointer synth;
88 if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth))
89 regex_synth = GetRegexTypeSyntheticsContainer()->Get (candidates, synth, &reason_synth);
90 if (!filter_sp.get() && !synth.get())
92 else if (!filter_sp.get() && synth.get())
95 else if (filter_sp.get() && !synth.get())
98 else /*if (filter_sp.get() && synth.get())*/
100 if (filter_sp->GetRevision() > synth->GetRevision())
107 if (regex_synth && reason)
108 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter;
114 if (regex_filter && reason)
115 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter;
132 TypeCategoryImpl::Get (ValueObject& valobj,
133 const FormattersMatchVector& candidates,
134 lldb::TypeValidatorImplSP& entry,
139 if (GetTypeValidatorsContainer()->Get(candidates, entry, reason))
141 bool regex = GetRegexTypeValidatorsContainer()->Get(candidates, entry, reason);
143 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
148 TypeCategoryImpl::Clear (FormatCategoryItems items)
150 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
151 GetTypeFormatsContainer()->Clear();
152 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
153 GetRegexTypeFormatsContainer()->Clear();
155 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
156 GetTypeSummariesContainer()->Clear();
157 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
158 GetRegexTypeSummariesContainer()->Clear();
160 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
161 GetTypeFiltersContainer()->Clear();
162 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
163 GetRegexTypeFiltersContainer()->Clear();
165 #ifndef LLDB_DISABLE_PYTHON
166 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
167 GetTypeSyntheticsContainer()->Clear();
168 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
169 GetRegexTypeSyntheticsContainer()->Clear();
172 if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator )
173 GetTypeValidatorsContainer()->Clear();
174 if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator )
175 GetRegexTypeValidatorsContainer()->Clear();
179 TypeCategoryImpl::Delete (ConstString name,
180 FormatCategoryItems items)
182 bool success = false;
184 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
185 success = GetTypeFormatsContainer()->Delete(name) || success;
186 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
187 success = GetRegexTypeFormatsContainer()->Delete(name) || success;
189 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
190 success = GetTypeSummariesContainer()->Delete(name) || success;
191 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
192 success = GetRegexTypeSummariesContainer()->Delete(name) || success;
194 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
195 success = GetTypeFiltersContainer()->Delete(name) || success;
196 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
197 success = GetRegexTypeFiltersContainer()->Delete(name) || success;
199 #ifndef LLDB_DISABLE_PYTHON
200 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
201 success = GetTypeSyntheticsContainer()->Delete(name) || success;
202 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
203 success = GetRegexTypeSyntheticsContainer()->Delete(name) || success;
206 if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator )
207 success = GetTypeValidatorsContainer()->Delete(name) || success;
208 if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator )
209 success = GetRegexTypeValidatorsContainer()->Delete(name) || success;
215 TypeCategoryImpl::GetCount (FormatCategoryItems items)
219 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
220 count += GetTypeFormatsContainer()->GetCount();
221 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
222 count += GetRegexTypeFormatsContainer()->GetCount();
224 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
225 count += GetTypeSummariesContainer()->GetCount();
226 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
227 count += GetRegexTypeSummariesContainer()->GetCount();
229 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
230 count += GetTypeFiltersContainer()->GetCount();
231 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
232 count += GetRegexTypeFiltersContainer()->GetCount();
234 #ifndef LLDB_DISABLE_PYTHON
235 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
236 count += GetTypeSyntheticsContainer()->GetCount();
237 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
238 count += GetRegexTypeSyntheticsContainer()->GetCount();
241 if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator )
242 count += GetTypeValidatorsContainer()->GetCount();
243 if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator )
244 count += GetRegexTypeValidatorsContainer()->GetCount();
250 TypeCategoryImpl::AnyMatches(ConstString type_name,
251 FormatCategoryItems items,
253 const char** matching_category,
254 FormatCategoryItems* matching_type)
256 if (!IsEnabled() && only_enabled)
259 lldb::TypeFormatImplSP format_sp;
260 lldb::TypeSummaryImplSP summary_sp;
261 TypeFilterImpl::SharedPointer filter_sp;
262 #ifndef LLDB_DISABLE_PYTHON
263 ScriptedSyntheticChildren::SharedPointer synth_sp;
265 TypeValidatorImpl::SharedPointer validator_sp;
267 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
269 if (GetTypeFormatsContainer()->Get(type_name, format_sp))
271 if (matching_category)
272 *matching_category = m_name.GetCString();
274 *matching_type = eFormatCategoryItemValue;
278 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
280 if (GetRegexTypeFormatsContainer()->Get(type_name, format_sp))
282 if (matching_category)
283 *matching_category = m_name.GetCString();
285 *matching_type = eFormatCategoryItemRegexValue;
290 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
292 if (GetTypeSummariesContainer()->Get(type_name, summary_sp))
294 if (matching_category)
295 *matching_category = m_name.GetCString();
297 *matching_type = eFormatCategoryItemSummary;
301 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
303 if (GetRegexTypeSummariesContainer()->Get(type_name, summary_sp))
305 if (matching_category)
306 *matching_category = m_name.GetCString();
308 *matching_type = eFormatCategoryItemRegexSummary;
313 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
315 if (GetTypeFiltersContainer()->Get(type_name, filter_sp))
317 if (matching_category)
318 *matching_category = m_name.GetCString();
320 *matching_type = eFormatCategoryItemFilter;
324 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
326 if (GetRegexTypeFiltersContainer()->Get(type_name, filter_sp))
328 if (matching_category)
329 *matching_category = m_name.GetCString();
331 *matching_type = eFormatCategoryItemRegexFilter;
336 #ifndef LLDB_DISABLE_PYTHON
337 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
339 if (GetTypeSyntheticsContainer()->Get(type_name, synth_sp))
341 if (matching_category)
342 *matching_category = m_name.GetCString();
344 *matching_type = eFormatCategoryItemSynth;
348 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
350 if (GetRegexTypeSyntheticsContainer()->Get(type_name, synth_sp))
352 if (matching_category)
353 *matching_category = m_name.GetCString();
355 *matching_type = eFormatCategoryItemRegexSynth;
361 if ( (items & eFormatCategoryItemValidator) == eFormatCategoryItemValidator )
363 if (GetTypeValidatorsContainer()->Get(type_name, validator_sp))
365 if (matching_category)
366 *matching_category = m_name.GetCString();
368 *matching_type = eFormatCategoryItemValidator;
372 if ( (items & eFormatCategoryItemRegexValidator) == eFormatCategoryItemRegexValidator )
374 if (GetRegexTypeValidatorsContainer()->Get(type_name, validator_sp))
376 if (matching_category)
377 *matching_category = m_name.GetCString();
379 *matching_type = eFormatCategoryItemRegexValidator;
387 TypeCategoryImpl::FormatContainer::MapValueType
388 TypeCategoryImpl::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp)
390 FormatContainer::MapValueType retval;
394 if (type_sp->IsRegex())
395 GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
397 GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
403 TypeCategoryImpl::SummaryContainer::MapValueType
404 TypeCategoryImpl::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp)
406 SummaryContainer::MapValueType retval;
410 if (type_sp->IsRegex())
411 GetRegexTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval);
413 GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval);
419 TypeCategoryImpl::FilterContainer::MapValueType
420 TypeCategoryImpl::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp)
422 FilterContainer::MapValueType retval;
426 if (type_sp->IsRegex())
427 GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval);
429 GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval);
435 #ifndef LLDB_DISABLE_PYTHON
436 TypeCategoryImpl::SynthContainer::MapValueType
437 TypeCategoryImpl::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp)
439 SynthContainer::MapValueType retval;
443 if (type_sp->IsRegex())
444 GetRegexTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
446 GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
453 TypeCategoryImpl::ValidatorContainer::MapValueType
454 TypeCategoryImpl::GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp)
456 ValidatorContainer::MapValueType retval;
460 if (type_sp->IsRegex())
461 GetRegexTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
463 GetTypeValidatorsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
469 lldb::TypeNameSpecifierImplSP
470 TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex (size_t index)
472 if (index < GetTypeSummariesContainer()->GetCount())
473 return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index);
475 return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeSummariesContainer()->GetCount());
478 TypeCategoryImpl::FormatContainer::MapValueType
479 TypeCategoryImpl::GetFormatAtIndex (size_t index)
481 if (index < GetTypeFormatsContainer()->GetCount())
482 return GetTypeFormatsContainer()->GetAtIndex(index);
484 return GetRegexTypeFormatsContainer()->GetAtIndex(index-GetTypeFormatsContainer()->GetCount());
487 TypeCategoryImpl::SummaryContainer::MapValueType
488 TypeCategoryImpl::GetSummaryAtIndex (size_t index)
490 if (index < GetTypeSummariesContainer()->GetCount())
491 return GetTypeSummariesContainer()->GetAtIndex(index);
493 return GetRegexTypeSummariesContainer()->GetAtIndex(index-GetTypeSummariesContainer()->GetCount());
496 TypeCategoryImpl::FilterContainer::MapValueType
497 TypeCategoryImpl::GetFilterAtIndex (size_t index)
499 if (index < GetTypeFiltersContainer()->GetCount())
500 return GetTypeFiltersContainer()->GetAtIndex(index);
502 return GetRegexTypeFiltersContainer()->GetAtIndex(index-GetTypeFiltersContainer()->GetCount());
505 lldb::TypeNameSpecifierImplSP
506 TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex (size_t index)
508 if (index < GetTypeFormatsContainer()->GetCount())
509 return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index);
511 return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFormatsContainer()->GetCount());
514 lldb::TypeNameSpecifierImplSP
515 TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex (size_t index)
517 if (index < GetTypeFiltersContainer()->GetCount())
518 return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index);
520 return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFiltersContainer()->GetCount());
523 #ifndef LLDB_DISABLE_PYTHON
524 TypeCategoryImpl::SynthContainer::MapValueType
525 TypeCategoryImpl::GetSyntheticAtIndex (size_t index)
527 if (index < GetTypeSyntheticsContainer()->GetCount())
528 return GetTypeSyntheticsContainer()->GetAtIndex(index);
530 return GetRegexTypeSyntheticsContainer()->GetAtIndex(index-GetTypeSyntheticsContainer()->GetCount());
533 lldb::TypeNameSpecifierImplSP
534 TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex (size_t index)
536 if (index < GetTypeSyntheticsContainer()->GetCount())
537 return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index);
539 return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index - GetTypeSyntheticsContainer()->GetCount());
543 TypeCategoryImpl::ValidatorContainer::MapValueType
544 TypeCategoryImpl::GetValidatorAtIndex (size_t index)
546 if (index < GetTypeValidatorsContainer()->GetCount())
547 return GetTypeValidatorsContainer()->GetAtIndex(index);
549 return GetRegexTypeValidatorsContainer()->GetAtIndex(index-GetTypeValidatorsContainer()->GetCount());
552 lldb::TypeNameSpecifierImplSP
553 TypeCategoryImpl::GetTypeNameSpecifierForValidatorAtIndex (size_t index)
555 if (index < GetTypeValidatorsContainer()->GetCount())
556 return GetTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index);
558 return GetRegexTypeValidatorsContainer()->GetTypeNameSpecifierAtIndex(index - GetTypeValidatorsContainer()->GetCount());
562 TypeCategoryImpl::Enable (bool value, uint32_t position)
564 Mutex::Locker locker(m_mutex);
565 if ( (m_enabled = value) )
566 m_enabled_position = position;
567 if (m_change_listener)
568 m_change_listener->Changed();