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/lldb-python.h"
12 #include "lldb/DataFormatters/TypeCategory.h"
16 // Other libraries and framework includes
20 using namespace lldb_private;
22 TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener* clist,
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),
31 m_change_listener(clist),
32 m_mutex(Mutex::eMutexTypeRecursive),
37 TypeCategoryImpl::Get (ValueObject& valobj,
38 const FormattersMatchVector& candidates,
39 lldb::TypeFormatImplSP& entry,
44 if (GetTypeFormatsContainer()->Get(candidates, entry, reason))
46 bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason);
48 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
53 TypeCategoryImpl::Get (ValueObject& valobj,
54 const FormattersMatchVector& candidates,
55 lldb::TypeSummaryImplSP& entry,
60 if (GetTypeSummariesContainer()->Get(candidates, entry, reason))
62 bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason);
64 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
69 TypeCategoryImpl::Get (ValueObject& valobj,
70 const FormattersMatchVector& candidates,
71 lldb::SyntheticChildrenSP& entry,
76 TypeFilterImpl::SharedPointer filter_sp;
77 uint32_t reason_filter = 0;
78 bool regex_filter = false;
79 // first find both Filter and Synth, and then check which is most recent
81 if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter))
82 regex_filter = GetRegexTypeFiltersContainer()->Get (candidates, filter_sp, &reason_filter);
84 #ifndef LLDB_DISABLE_PYTHON
85 bool regex_synth = false;
86 uint32_t reason_synth = 0;
87 bool pick_synth = false;
88 ScriptedSyntheticChildren::SharedPointer synth;
89 if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth))
90 regex_synth = GetRegexTypeSyntheticsContainer()->Get (candidates, synth, &reason_synth);
91 if (!filter_sp.get() && !synth.get())
93 else if (!filter_sp.get() && synth.get())
96 else if (filter_sp.get() && !synth.get())
99 else /*if (filter_sp.get() && synth.get())*/
101 if (filter_sp->GetRevision() > synth->GetRevision())
108 if (regex_synth && reason)
109 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter;
115 if (regex_filter && reason)
116 *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter;
133 TypeCategoryImpl::Clear (FormatCategoryItems items)
135 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
136 GetTypeFormatsContainer()->Clear();
137 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
138 GetRegexTypeFormatsContainer()->Clear();
140 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
141 GetTypeSummariesContainer()->Clear();
142 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
143 GetRegexTypeSummariesContainer()->Clear();
145 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
146 GetTypeFiltersContainer()->Clear();
147 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
148 GetRegexTypeFiltersContainer()->Clear();
150 #ifndef LLDB_DISABLE_PYTHON
151 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
152 GetTypeSyntheticsContainer()->Clear();
153 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
154 GetRegexTypeSyntheticsContainer()->Clear();
159 TypeCategoryImpl::Delete (ConstString name,
160 FormatCategoryItems items)
162 bool success = false;
164 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
165 success = GetTypeFormatsContainer()->Delete(name) || success;
166 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
167 success = GetRegexTypeFormatsContainer()->Delete(name) || success;
169 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
170 success = GetTypeSummariesContainer()->Delete(name) || success;
171 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
172 success = GetRegexTypeSummariesContainer()->Delete(name) || success;
174 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
175 success = GetTypeFiltersContainer()->Delete(name) || success;
176 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
177 success = GetRegexTypeFiltersContainer()->Delete(name) || success;
179 #ifndef LLDB_DISABLE_PYTHON
180 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
181 success = GetTypeSyntheticsContainer()->Delete(name) || success;
182 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
183 success = GetRegexTypeSyntheticsContainer()->Delete(name) || success;
189 TypeCategoryImpl::GetCount (FormatCategoryItems items)
193 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
194 count += GetTypeFormatsContainer()->GetCount();
195 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
196 count += GetRegexTypeFormatsContainer()->GetCount();
198 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
199 count += GetTypeSummariesContainer()->GetCount();
200 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
201 count += GetRegexTypeSummariesContainer()->GetCount();
203 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
204 count += GetTypeFiltersContainer()->GetCount();
205 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
206 count += GetRegexTypeFiltersContainer()->GetCount();
208 #ifndef LLDB_DISABLE_PYTHON
209 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
210 count += GetTypeSyntheticsContainer()->GetCount();
211 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
212 count += GetRegexTypeSyntheticsContainer()->GetCount();
218 TypeCategoryImpl::AnyMatches(ConstString type_name,
219 FormatCategoryItems items,
221 const char** matching_category,
222 FormatCategoryItems* matching_type)
224 if (!IsEnabled() && only_enabled)
227 lldb::TypeFormatImplSP format_sp;
228 lldb::TypeSummaryImplSP summary_sp;
229 TypeFilterImpl::SharedPointer filter_sp;
230 #ifndef LLDB_DISABLE_PYTHON
231 ScriptedSyntheticChildren::SharedPointer synth_sp;
234 if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
236 if (GetTypeFormatsContainer()->Get(type_name, format_sp))
238 if (matching_category)
239 *matching_category = m_name.GetCString();
241 *matching_type = eFormatCategoryItemValue;
245 if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
247 if (GetRegexTypeFormatsContainer()->Get(type_name, format_sp))
249 if (matching_category)
250 *matching_category = m_name.GetCString();
252 *matching_type = eFormatCategoryItemRegexValue;
257 if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
259 if (GetTypeSummariesContainer()->Get(type_name, summary_sp))
261 if (matching_category)
262 *matching_category = m_name.GetCString();
264 *matching_type = eFormatCategoryItemSummary;
268 if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
270 if (GetRegexTypeSummariesContainer()->Get(type_name, summary_sp))
272 if (matching_category)
273 *matching_category = m_name.GetCString();
275 *matching_type = eFormatCategoryItemRegexSummary;
280 if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
282 if (GetTypeFiltersContainer()->Get(type_name, filter_sp))
284 if (matching_category)
285 *matching_category = m_name.GetCString();
287 *matching_type = eFormatCategoryItemFilter;
291 if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
293 if (GetRegexTypeFiltersContainer()->Get(type_name, filter_sp))
295 if (matching_category)
296 *matching_category = m_name.GetCString();
298 *matching_type = eFormatCategoryItemRegexFilter;
303 #ifndef LLDB_DISABLE_PYTHON
304 if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
306 if (GetTypeSyntheticsContainer()->Get(type_name, synth_sp))
308 if (matching_category)
309 *matching_category = m_name.GetCString();
311 *matching_type = eFormatCategoryItemSynth;
315 if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
317 if (GetRegexTypeSyntheticsContainer()->Get(type_name, synth_sp))
319 if (matching_category)
320 *matching_category = m_name.GetCString();
322 *matching_type = eFormatCategoryItemRegexSynth;
330 TypeCategoryImpl::FormatContainer::MapValueType
331 TypeCategoryImpl::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp)
333 FormatContainer::MapValueType retval;
337 if (type_sp->IsRegex())
338 GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
340 GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
346 TypeCategoryImpl::SummaryContainer::MapValueType
347 TypeCategoryImpl::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp)
349 SummaryContainer::MapValueType retval;
353 if (type_sp->IsRegex())
354 GetRegexTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval);
356 GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval);
362 TypeCategoryImpl::FilterContainer::MapValueType
363 TypeCategoryImpl::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp)
365 FilterContainer::MapValueType retval;
369 if (type_sp->IsRegex())
370 GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval);
372 GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval);
378 #ifndef LLDB_DISABLE_PYTHON
379 TypeCategoryImpl::SynthContainer::MapValueType
380 TypeCategoryImpl::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp)
382 SynthContainer::MapValueType retval;
386 if (type_sp->IsRegex())
387 GetRegexTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
389 GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
396 lldb::TypeNameSpecifierImplSP
397 TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex (size_t index)
399 if (index < GetTypeSummariesContainer()->GetCount())
400 return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index);
402 return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeSummariesContainer()->GetCount());
405 TypeCategoryImpl::FormatContainer::MapValueType
406 TypeCategoryImpl::GetFormatAtIndex (size_t index)
408 if (index < GetTypeFormatsContainer()->GetCount())
409 return GetTypeFormatsContainer()->GetAtIndex(index);
411 return GetRegexTypeFormatsContainer()->GetAtIndex(index-GetTypeFormatsContainer()->GetCount());
414 TypeCategoryImpl::SummaryContainer::MapValueType
415 TypeCategoryImpl::GetSummaryAtIndex (size_t index)
417 if (index < GetTypeSummariesContainer()->GetCount())
418 return GetTypeSummariesContainer()->GetAtIndex(index);
420 return GetRegexTypeSummariesContainer()->GetAtIndex(index-GetTypeSummariesContainer()->GetCount());
423 TypeCategoryImpl::FilterContainer::MapValueType
424 TypeCategoryImpl::GetFilterAtIndex (size_t index)
426 if (index < GetTypeFiltersContainer()->GetCount())
427 return GetTypeFiltersContainer()->GetAtIndex(index);
429 return GetRegexTypeFiltersContainer()->GetAtIndex(index-GetTypeFiltersContainer()->GetCount());
432 lldb::TypeNameSpecifierImplSP
433 TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex (size_t index)
435 if (index < GetTypeFormatsContainer()->GetCount())
436 return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index);
438 return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFormatsContainer()->GetCount());
441 lldb::TypeNameSpecifierImplSP
442 TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex (size_t index)
444 if (index < GetTypeFiltersContainer()->GetCount())
445 return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index);
447 return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFiltersContainer()->GetCount());
450 #ifndef LLDB_DISABLE_PYTHON
451 TypeCategoryImpl::SynthContainer::MapValueType
452 TypeCategoryImpl::GetSyntheticAtIndex (size_t index)
454 if (index < GetTypeSyntheticsContainer()->GetCount())
455 return GetTypeSyntheticsContainer()->GetAtIndex(index);
457 return GetRegexTypeSyntheticsContainer()->GetAtIndex(index-GetTypeSyntheticsContainer()->GetCount());
460 lldb::TypeNameSpecifierImplSP
461 TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex (size_t index)
463 if (index < GetTypeSyntheticsContainer()->GetCount())
464 return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index);
466 return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index - GetTypeSyntheticsContainer()->GetCount());
471 TypeCategoryImpl::Enable (bool value, uint32_t position)
473 Mutex::Locker locker(m_mutex);
475 m_enabled_position = position;
476 if (m_change_listener)
477 m_change_listener->Changed();