[Lldb-commits] [lldb] 1f2a218 - [NFCI] Refactor FormatterContainerPair into TieredFormatterContainer.
Jorge Gorbe Moya via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 27 14:29:55 PDT 2022
Author: Jorge Gorbe Moya
Date: 2022-09-27T14:28:41-07:00
New Revision: 1f2a21820dfa2c97de8cc9e09cd03cf1c1684e31
URL: https://github.com/llvm/llvm-project/commit/1f2a21820dfa2c97de8cc9e09cd03cf1c1684e31
DIFF: https://github.com/llvm/llvm-project/commit/1f2a21820dfa2c97de8cc9e09cd03cf1c1684e31.diff
LOG: [NFCI] Refactor FormatterContainerPair into TieredFormatterContainer.
`FormatterContainerPair` is (as its name indicates) a very thin wrapper
over two formatter containers, one for exact matches and another one for
regex matches. The logic to decide which subcontainer to access is
replicated everywhere `FormatterContainerPair`s are used.
So, for example, when we look for a formatter there's some adhoc code
that does a lookup in the exact match formatter container, and if it
fails it does a lookup in the regex match formatter container. The same
logic is then copied and pasted for summaries, filters, and synthetic
child providers.
This change introduces a new `TieredFormatterContainer` that has two
main characteristics:
- It generalizes `FormatterContainerPair` from 2 to any number of
subcontainers, that are looked up in priority order.
- It centralizes all the logic to choose which subcontainer to use for
lookups, add/delete, and indexing.
This allows us to have a single copy of the same logic, templatized for
each kind of formatter. It also simplifies the upcoming addition of a
new tier of callback-based matches. See
https://discourse.llvm.org/t/rfc-python-callback-for-data-formatters-type-matching/64204
for more details about this.
The rest of the change is mostly replacing copy-pasted code with calls
to methods of the relevant `TieredFormatterContainer`, and adding some
methods to the `TypeCategoryImpl` class so we can remove some of this
copy-pasted code from `SBTypeCategory`.
Differential Revision: https://reviews.llvm.org/D133910
Added:
Modified:
lldb/include/lldb/DataFormatters/FormattersContainer.h
lldb/include/lldb/DataFormatters/TypeCategory.h
lldb/source/API/SBTypeCategory.cpp
lldb/source/DataFormatters/TypeCategory.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/DataFormatters/FormattersContainer.h b/lldb/include/lldb/DataFormatters/FormattersContainer.h
index 58df8b9610734..8a93c0345cbe5 100644
--- a/lldb/include/lldb/DataFormatters/FormattersContainer.h
+++ b/lldb/include/lldb/DataFormatters/FormattersContainer.h
@@ -78,6 +78,14 @@ class TypeMatcher {
TypeMatcher(RegularExpression regex)
: m_type_name_regex(std::move(regex)),
m_match_type(lldb::eFormatterMatchRegex) {}
+ /// Creates a matcher using the matching type and string from the given type
+ /// name specifier.
+ TypeMatcher(lldb::TypeNameSpecifierImplSP type_specifier)
+ : m_type_name(type_specifier->GetName()),
+ m_match_type(type_specifier->GetMatchType()) {
+ if (m_match_type == lldb::eFormatterMatchRegex)
+ m_type_name_regex = RegularExpression(type_specifier->GetName());
+ }
/// True iff this matches the given type name.
bool Matches(ConstString type_name) const {
@@ -158,6 +166,20 @@ template <typename ValueType> class FormattersContainer {
return false;
}
+ bool Get(const FormattersMatchVector &candidates, ValueSP &entry) {
+ for (const FormattersMatchCandidate &candidate : candidates) {
+ if (Get(candidate.GetTypeName(), entry)) {
+ if (candidate.IsMatch(entry) == false) {
+ entry.reset();
+ continue;
+ } else {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
bool GetExact(TypeMatcher matcher, ValueSP &entry) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
for (const auto &pos : m_map)
@@ -219,20 +241,6 @@ template <typename ValueType> class FormattersContainer {
FormattersContainer(const FormattersContainer &) = delete;
const FormattersContainer &operator=(const FormattersContainer &) = delete;
- bool Get(const FormattersMatchVector &candidates, ValueSP &entry) {
- for (const FormattersMatchCandidate &candidate : candidates) {
- if (Get(candidate.GetTypeName(), entry)) {
- if (candidate.IsMatch(entry) == false) {
- entry.reset();
- continue;
- } else {
- return true;
- }
- }
- }
- return false;
- }
-
MapType m_map;
std::recursive_mutex m_map_mutex;
IFormatChangeListener *listener;
diff --git a/lldb/include/lldb/DataFormatters/TypeCategory.h b/lldb/include/lldb/DataFormatters/TypeCategory.h
index 16255f9488bda..2f0cb6c78472f 100644
--- a/lldb/include/lldb/DataFormatters/TypeCategory.h
+++ b/lldb/include/lldb/DataFormatters/TypeCategory.h
@@ -9,6 +9,7 @@
#ifndef LLDB_DATAFORMATTERS_TYPECATEGORY_H
#define LLDB_DATAFORMATTERS_TYPECATEGORY_H
+#include <array>
#include <initializer_list>
#include <memory>
#include <mutex>
@@ -23,66 +24,128 @@
namespace lldb_private {
-template <typename FormatterImpl> class FormatterContainerPair {
+// A formatter container with sub-containers for
diff erent priority tiers, that
+// also exposes a flat view of all formatters in it.
+//
+// Formatters have
diff erent priority during matching, depending on the type of
+// matching specified at registration. Exact matchers are processed first, then
+// regex, and finally callback matchers. However, the scripting API presents a
+// flat view of formatters in a category, with methods like `GetNumFormats()`
+// and `GetFormatAtIndex(i)`. So we need something that can behave like both
+// representations.
+template <typename FormatterImpl> class TieredFormatterContainer {
public:
- typedef FormattersContainer<FormatterImpl> ExactMatchContainer;
- typedef FormattersContainer<FormatterImpl> RegexMatchContainer;
+ using Subcontainer = FormattersContainer<FormatterImpl>;
+ using SubcontainerSP = std::shared_ptr<Subcontainer>;
+ using ForEachCallback = typename Subcontainer::ForEachCallback;
+ using MapValueType = typename Subcontainer::ValueSP;
+
+ TieredFormatterContainer(IFormatChangeListener *change_listener) {
+ for (auto& sc : m_subcontainers)
+ sc = std::make_shared<Subcontainer>(change_listener);
+ }
- typedef TypeMatcher ExactMatchMap;
- typedef TypeMatcher RegexMatchMap;
+ /// Returns the subcontainer containing formatters for exact matching.
+ std::shared_ptr<Subcontainer> GetExactMatch() const {
+ return m_subcontainers[lldb::eFormatterMatchExact];
+ }
- typedef typename ExactMatchContainer::ValueSP MapValueType;
+ /// Returns the subcontainer containing formatters for regex matching.
+ std::shared_ptr<Subcontainer> GetRegexMatch() const {
+ return m_subcontainers[lldb::eFormatterMatchRegex];
+ }
- typedef typename ExactMatchContainer::SharedPointer ExactMatchContainerSP;
- typedef typename RegexMatchContainer::SharedPointer RegexMatchContainerSP;
+ /// Adds a formatter to the right subcontainer depending on the matching type
+ /// specified by `type_sp`.
+ void Add(lldb::TypeNameSpecifierImplSP type_sp,
+ std::shared_ptr<FormatterImpl> format_sp) {
+ m_subcontainers[type_sp->GetMatchType()]->Add(TypeMatcher(type_sp),
+ format_sp);
+ }
- typedef
- typename ExactMatchContainer::ForEachCallback ExactMatchForEachCallback;
- typedef
- typename RegexMatchContainer::ForEachCallback RegexMatchForEachCallback;
+ /// Deletes the formatter specified by `type_sp`.
+ bool Delete(lldb::TypeNameSpecifierImplSP type_sp) {
+ return m_subcontainers[type_sp->GetMatchType()]->Delete(
+ TypeMatcher(type_sp));
+ }
- FormatterContainerPair(IFormatChangeListener *clist)
- : m_exact_sp(new ExactMatchContainer(clist)),
- m_regex_sp(new RegexMatchContainer(clist)) {}
+ /// Returns the total count of elements across all subcontainers.
+ uint32_t GetCount() {
+ uint32_t result = 0;
+ for (auto sc : m_subcontainers)
+ result += sc->GetCount();
+ return result;
+ }
- ~FormatterContainerPair() = default;
+ /// Returns the formatter at `index`, simulating a flattened view of all
+ /// subcontainers in priority order.
+ MapValueType GetAtIndex(size_t index) {
+ for (auto sc : m_subcontainers) {
+ if (index < sc->GetCount())
+ return sc->GetAtIndex(index);
+ index -= sc->GetCount();
+ }
+ return MapValueType();
+ }
- ExactMatchContainerSP GetExactMatch() const { return m_exact_sp; }
+ /// Looks for a matching candidate across all priority tiers, in priority
+ /// order. If a match is found, returns `true` and puts the matching entry in
+ /// `entry`.
+ bool Get(const FormattersMatchVector &candidates,
+ std::shared_ptr<FormatterImpl> &entry) {
+ for (auto sc : m_subcontainers) {
+ if (sc->Get(candidates, entry))
+ return true;
+ }
+ return false;
+ }
- RegexMatchContainerSP GetRegexMatch() const { return m_regex_sp; }
+ /// Returns a formatter that is an exact match for `type_specifier_sp`. It
+ /// looks for a formatter with the same matching type that was created from
+ /// the same string. This is useful so we can refer to a formatter using the
+ /// same string used to register it.
+ ///
+ /// For example, `type_specifier_sp` can be something like
+ /// {"std::vector<.*>", eFormatterMatchRegex}, and we'd look for a regex
+ /// matcher with that exact regex string, NOT try to match that string using
+ /// regex.
+ MapValueType
+ GetForTypeNameSpecifier(lldb::TypeNameSpecifierImplSP type_specifier_sp) {
+ MapValueType retval;
+ if (type_specifier_sp) {
+ m_subcontainers[type_specifier_sp->GetMatchType()]->GetExact(
+ ConstString(type_specifier_sp->GetName()), retval);
+ }
+ return retval;
+ }
- uint32_t GetCount() {
- return GetExactMatch()->GetCount() + GetRegexMatch()->GetCount();
+ /// Returns the type name specifier at `index`, simulating a flattened view of
+ /// all subcontainers in priority order.
+ lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierAtIndex(size_t index) {
+ for (auto sc : m_subcontainers) {
+ if (index < sc->GetCount())
+ return sc->GetTypeNameSpecifierAtIndex(index);
+ index -= sc->GetCount();
+ }
+ return lldb::TypeNameSpecifierImplSP();
}
-private:
- ExactMatchContainerSP m_exact_sp;
- RegexMatchContainerSP m_regex_sp;
+ private:
+ std::array<std::shared_ptr<Subcontainer>, lldb::eLastFormatterMatchType + 1>
+ m_subcontainers;
};
class TypeCategoryImpl {
private:
- typedef FormatterContainerPair<TypeFormatImpl> FormatContainer;
- typedef FormatterContainerPair<TypeSummaryImpl> SummaryContainer;
- typedef FormatterContainerPair<TypeFilterImpl> FilterContainer;
- typedef FormatterContainerPair<SyntheticChildren> SynthContainer;
+ typedef TieredFormatterContainer<TypeFormatImpl> FormatContainer;
+ typedef TieredFormatterContainer<TypeSummaryImpl> SummaryContainer;
+ typedef TieredFormatterContainer<TypeFilterImpl> FilterContainer;
+ typedef TieredFormatterContainer<SyntheticChildren> SynthContainer;
public:
typedef uint16_t FormatCategoryItems;
static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
- typedef FormatContainer::ExactMatchContainerSP FormatContainerSP;
- typedef FormatContainer::RegexMatchContainerSP RegexFormatContainerSP;
-
- typedef SummaryContainer::ExactMatchContainerSP SummaryContainerSP;
- typedef SummaryContainer::RegexMatchContainerSP RegexSummaryContainerSP;
-
- typedef FilterContainer::ExactMatchContainerSP FilterContainerSP;
- typedef FilterContainer::RegexMatchContainerSP RegexFilterContainerSP;
-
- typedef SynthContainer::ExactMatchContainerSP SynthContainerSP;
- typedef SynthContainer::RegexMatchContainerSP RegexSynthContainerSP;
-
template <typename T> class ForEachCallbacks {
public:
ForEachCallbacks() = default;
@@ -90,98 +153,96 @@ class TypeCategoryImpl {
template <typename U = TypeFormatImpl>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetExact(FormatContainer::ExactMatchForEachCallback callback) {
+ SetExact(FormatContainer::ForEachCallback callback) {
m_format_exact = std::move(callback);
return *this;
}
template <typename U = TypeFormatImpl>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetWithRegex(FormatContainer::RegexMatchForEachCallback callback) {
+ SetWithRegex(FormatContainer::ForEachCallback callback) {
m_format_regex = std::move(callback);
return *this;
}
template <typename U = TypeSummaryImpl>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetExact(SummaryContainer::ExactMatchForEachCallback callback) {
+ SetExact(SummaryContainer::ForEachCallback callback) {
m_summary_exact = std::move(callback);
return *this;
}
template <typename U = TypeSummaryImpl>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetWithRegex(SummaryContainer::RegexMatchForEachCallback callback) {
+ SetWithRegex(SummaryContainer::ForEachCallback callback) {
m_summary_regex = std::move(callback);
return *this;
}
template <typename U = TypeFilterImpl>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetExact(FilterContainer::ExactMatchForEachCallback callback) {
+ SetExact(FilterContainer::ForEachCallback callback) {
m_filter_exact = std::move(callback);
return *this;
}
template <typename U = TypeFilterImpl>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetWithRegex(FilterContainer::RegexMatchForEachCallback callback) {
+ SetWithRegex(FilterContainer::ForEachCallback callback) {
m_filter_regex = std::move(callback);
return *this;
}
template <typename U = SyntheticChildren>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetExact(SynthContainer::ExactMatchForEachCallback callback) {
+ SetExact(SynthContainer::ForEachCallback callback) {
m_synth_exact = std::move(callback);
return *this;
}
template <typename U = SyntheticChildren>
typename std::enable_if<std::is_same<U, T>::value, ForEachCallbacks &>::type
- SetWithRegex(SynthContainer::RegexMatchForEachCallback callback) {
+ SetWithRegex(SynthContainer::ForEachCallback callback) {
m_synth_regex = std::move(callback);
return *this;
}
- FormatContainer::ExactMatchForEachCallback GetFormatExactCallback() const {
+ FormatContainer::ForEachCallback GetFormatExactCallback() const {
return m_format_exact;
}
- FormatContainer::RegexMatchForEachCallback GetFormatRegexCallback() const {
+ FormatContainer::ForEachCallback GetFormatRegexCallback() const {
return m_format_regex;
}
- SummaryContainer::ExactMatchForEachCallback
- GetSummaryExactCallback() const {
+ SummaryContainer::ForEachCallback GetSummaryExactCallback() const {
return m_summary_exact;
}
- SummaryContainer::RegexMatchForEachCallback
- GetSummaryRegexCallback() const {
+ SummaryContainer::ForEachCallback GetSummaryRegexCallback() const {
return m_summary_regex;
}
- FilterContainer::ExactMatchForEachCallback GetFilterExactCallback() const {
+ FilterContainer::ForEachCallback GetFilterExactCallback() const {
return m_filter_exact;
}
- FilterContainer::RegexMatchForEachCallback GetFilterRegexCallback() const {
+ FilterContainer::ForEachCallback GetFilterRegexCallback() const {
return m_filter_regex;
}
- SynthContainer::ExactMatchForEachCallback GetSynthExactCallback() const {
+ SynthContainer::ForEachCallback GetSynthExactCallback() const {
return m_synth_exact;
}
- SynthContainer::RegexMatchForEachCallback GetSynthRegexCallback() const {
+ SynthContainer::ForEachCallback GetSynthRegexCallback() const {
return m_synth_regex;
}
private:
- FormatContainer::ExactMatchForEachCallback m_format_exact;
- FormatContainer::RegexMatchForEachCallback m_format_regex;
+ FormatContainer::ForEachCallback m_format_exact;
+ FormatContainer::ForEachCallback m_format_regex;
- SummaryContainer::ExactMatchForEachCallback m_summary_exact;
- SummaryContainer::RegexMatchForEachCallback m_summary_regex;
+ SummaryContainer::ForEachCallback m_summary_exact;
+ SummaryContainer::ForEachCallback m_summary_regex;
- FilterContainer::ExactMatchForEachCallback m_filter_exact;
- FilterContainer::RegexMatchForEachCallback m_filter_regex;
+ FilterContainer::ForEachCallback m_filter_exact;
+ FilterContainer::ForEachCallback m_filter_regex;
- SynthContainer::ExactMatchForEachCallback m_synth_exact;
- SynthContainer::RegexMatchForEachCallback m_synth_regex;
+ SynthContainer::ForEachCallback m_synth_exact;
+ SynthContainer::ForEachCallback m_synth_regex;
};
TypeCategoryImpl(IFormatChangeListener *clist, ConstString name);
@@ -201,31 +262,31 @@ class TypeCategoryImpl {
GetRegexTypeSyntheticsContainer()->ForEach(foreach.GetSynthRegexCallback());
}
- FormatContainerSP GetTypeFormatsContainer() {
+ FormatContainer::SubcontainerSP GetTypeFormatsContainer() {
return m_format_cont.GetExactMatch();
}
- RegexFormatContainerSP GetRegexTypeFormatsContainer() {
+ FormatContainer::SubcontainerSP GetRegexTypeFormatsContainer() {
return m_format_cont.GetRegexMatch();
}
FormatContainer &GetFormatContainer() { return m_format_cont; }
- SummaryContainerSP GetTypeSummariesContainer() {
+ SummaryContainer::SubcontainerSP GetTypeSummariesContainer() {
return m_summary_cont.GetExactMatch();
}
- RegexSummaryContainerSP GetRegexTypeSummariesContainer() {
+ SummaryContainer::SubcontainerSP GetRegexTypeSummariesContainer() {
return m_summary_cont.GetRegexMatch();
}
SummaryContainer &GetSummaryContainer() { return m_summary_cont; }
- FilterContainerSP GetTypeFiltersContainer() {
+ FilterContainer::SubcontainerSP GetTypeFiltersContainer() {
return m_filter_cont.GetExactMatch();
}
- RegexFilterContainerSP GetRegexTypeFiltersContainer() {
+ FilterContainer::SubcontainerSP GetRegexTypeFiltersContainer() {
return m_filter_cont.GetRegexMatch();
}
@@ -243,35 +304,80 @@ class TypeCategoryImpl {
SynthContainer::MapValueType
GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp);
+ void AddTypeFormat(lldb::TypeNameSpecifierImplSP type_sp,
+ lldb::TypeFormatImplSP format_sp) {
+ m_format_cont.Add(type_sp, format_sp);
+ }
+
+ void AddTypeSummary(lldb::TypeNameSpecifierImplSP type_sp,
+ lldb::TypeSummaryImplSP summary_sp) {
+ m_summary_cont.Add(type_sp, summary_sp);
+ }
+
+ void AddTypeFilter(lldb::TypeNameSpecifierImplSP type_sp,
+ lldb::TypeFilterImplSP filter_sp) {
+ m_filter_cont.Add(type_sp, filter_sp);
+ }
+
+ void AddTypeSynthetic(lldb::TypeNameSpecifierImplSP type_sp,
+ lldb::SyntheticChildrenSP synth_sp) {
+ m_synth_cont.Add(type_sp, synth_sp);
+ }
+
+ bool DeleteTypeFormat(lldb::TypeNameSpecifierImplSP type_sp) {
+ return m_format_cont.Delete(type_sp);
+ }
+
+ bool DeleteTypeSummary(lldb::TypeNameSpecifierImplSP type_sp) {
+ return m_summary_cont.Delete(type_sp);
+ }
+
+ bool DeleteTypeFilter(lldb::TypeNameSpecifierImplSP type_sp) {
+ return m_filter_cont.Delete(type_sp);
+ }
+
+ bool DeleteTypeSynthetic(lldb::TypeNameSpecifierImplSP type_sp) {
+ return m_synth_cont.Delete(type_sp);
+ }
+
+ uint32_t GetNumFormats() { return m_format_cont.GetCount(); }
+
+ uint32_t GetNumSummaries() { return m_summary_cont.GetCount(); }
+
+ uint32_t GetNumFilters() { return m_filter_cont.GetCount(); }
+
+ uint32_t GetNumSynthetics() { return m_synth_cont.GetCount(); }
+
lldb::TypeNameSpecifierImplSP
GetTypeNameSpecifierForFormatAtIndex(size_t index);
lldb::TypeNameSpecifierImplSP
GetTypeNameSpecifierForSummaryAtIndex(size_t index);
+ lldb::TypeNameSpecifierImplSP
+ GetTypeNameSpecifierForFilterAtIndex(size_t index);
+
+ lldb::TypeNameSpecifierImplSP
+ GetTypeNameSpecifierForSyntheticAtIndex(size_t index);
+
FormatContainer::MapValueType GetFormatAtIndex(size_t index);
SummaryContainer::MapValueType GetSummaryAtIndex(size_t index);
FilterContainer::MapValueType GetFilterAtIndex(size_t index);
- lldb::TypeNameSpecifierImplSP
- GetTypeNameSpecifierForFilterAtIndex(size_t index);
+ SynthContainer::MapValueType GetSyntheticAtIndex(size_t index);
- SynthContainerSP GetTypeSyntheticsContainer() {
+ SynthContainer::SubcontainerSP GetTypeSyntheticsContainer() {
return m_synth_cont.GetExactMatch();
}
- RegexSynthContainerSP GetRegexTypeSyntheticsContainer() {
+ SynthContainer::SubcontainerSP GetRegexTypeSyntheticsContainer() {
return m_synth_cont.GetRegexMatch();
}
SynthContainer &GetSyntheticsContainer() { return m_synth_cont; }
- SynthContainer::MapValueType GetSyntheticAtIndex(size_t index);
-
- lldb::TypeNameSpecifierImplSP
- GetTypeNameSpecifierForSyntheticAtIndex(size_t index);
bool IsEnabled() const { return m_enabled; }
diff --git a/lldb/source/API/SBTypeCategory.cpp b/lldb/source/API/SBTypeCategory.cpp
index c6b13498bb1ee..e2911a4c50f68 100644
--- a/lldb/source/API/SBTypeCategory.cpp
+++ b/lldb/source/API/SBTypeCategory.cpp
@@ -105,8 +105,7 @@ uint32_t SBTypeCategory::GetNumFormats() {
if (!IsValid())
return 0;
- return m_opaque_sp->GetTypeFormatsContainer()->GetCount() +
- m_opaque_sp->GetRegexTypeFormatsContainer()->GetCount();
+ return m_opaque_sp->GetNumFormats();
}
uint32_t SBTypeCategory::GetNumSummaries() {
@@ -114,8 +113,7 @@ uint32_t SBTypeCategory::GetNumSummaries() {
if (!IsValid())
return 0;
- return m_opaque_sp->GetTypeSummariesContainer()->GetCount() +
- m_opaque_sp->GetRegexTypeSummariesContainer()->GetCount();
+ return m_opaque_sp->GetNumSummaries();
}
uint32_t SBTypeCategory::GetNumFilters() {
@@ -123,8 +121,7 @@ uint32_t SBTypeCategory::GetNumFilters() {
if (!IsValid())
return 0;
- return m_opaque_sp->GetTypeFiltersContainer()->GetCount() +
- m_opaque_sp->GetRegexTypeFiltersContainer()->GetCount();
+ return m_opaque_sp->GetNumFilters();
}
uint32_t SBTypeCategory::GetNumSynthetics() {
@@ -132,8 +129,7 @@ uint32_t SBTypeCategory::GetNumSynthetics() {
if (!IsValid())
return 0;
- return m_opaque_sp->GetTypeSyntheticsContainer()->GetCount() +
- m_opaque_sp->GetRegexTypeSyntheticsContainer()->GetCount();
+ return m_opaque_sp->GetNumSynthetics();
}
lldb::SBTypeNameSpecifier
@@ -316,13 +312,7 @@ bool SBTypeCategory::AddTypeFormat(SBTypeNameSpecifier type_name,
if (!format.IsValid())
return false;
- if (type_name.IsRegex())
- m_opaque_sp->GetRegexTypeFormatsContainer()->Add(
- RegularExpression(type_name.GetName()), format.GetSP());
- else
- m_opaque_sp->GetTypeFormatsContainer()->Add(
- ConstString(type_name.GetName()), format.GetSP());
-
+ m_opaque_sp->AddTypeFormat(type_name.GetSP(), format.GetSP());
return true;
}
@@ -335,12 +325,7 @@ bool SBTypeCategory::DeleteTypeFormat(SBTypeNameSpecifier type_name) {
if (!type_name.IsValid())
return false;
- if (type_name.IsRegex())
- return m_opaque_sp->GetRegexTypeFormatsContainer()->Delete(
- ConstString(type_name.GetName()));
- else
- return m_opaque_sp->GetTypeFormatsContainer()->Delete(
- ConstString(type_name.GetName()));
+ return m_opaque_sp->DeleteTypeFormat(type_name.GetSP());
}
bool SBTypeCategory::AddTypeSummary(SBTypeNameSpecifier type_name,
@@ -390,13 +375,7 @@ bool SBTypeCategory::AddTypeSummary(SBTypeNameSpecifier type_name,
}
}
- if (type_name.IsRegex())
- m_opaque_sp->GetRegexTypeSummariesContainer()->Add(
- RegularExpression(type_name.GetName()), summary.GetSP());
- else
- m_opaque_sp->GetTypeSummariesContainer()->Add(
- ConstString(type_name.GetName()), summary.GetSP());
-
+ m_opaque_sp->AddTypeSummary(type_name.GetSP(), summary.GetSP());
return true;
}
@@ -409,12 +388,7 @@ bool SBTypeCategory::DeleteTypeSummary(SBTypeNameSpecifier type_name) {
if (!type_name.IsValid())
return false;
- if (type_name.IsRegex())
- return m_opaque_sp->GetRegexTypeSummariesContainer()->Delete(
- ConstString(type_name.GetName()));
- else
- return m_opaque_sp->GetTypeSummariesContainer()->Delete(
- ConstString(type_name.GetName()));
+ return m_opaque_sp->DeleteTypeSummary(type_name.GetSP());
}
bool SBTypeCategory::AddTypeFilter(SBTypeNameSpecifier type_name,
@@ -430,13 +404,7 @@ bool SBTypeCategory::AddTypeFilter(SBTypeNameSpecifier type_name,
if (!filter.IsValid())
return false;
- if (type_name.IsRegex())
- m_opaque_sp->GetRegexTypeFiltersContainer()->Add(
- RegularExpression(type_name.GetName()), filter.GetSP());
- else
- m_opaque_sp->GetTypeFiltersContainer()->Add(
- ConstString(type_name.GetName()), filter.GetSP());
-
+ m_opaque_sp->AddTypeFilter(type_name.GetSP(), filter.GetSP());
return true;
}
@@ -449,12 +417,7 @@ bool SBTypeCategory::DeleteTypeFilter(SBTypeNameSpecifier type_name) {
if (!type_name.IsValid())
return false;
- if (type_name.IsRegex())
- return m_opaque_sp->GetRegexTypeFiltersContainer()->Delete(
- ConstString(type_name.GetName()));
- else
- return m_opaque_sp->GetTypeFiltersContainer()->Delete(
- ConstString(type_name.GetName()));
+ return m_opaque_sp->DeleteTypeFilter(type_name.GetSP());
}
bool SBTypeCategory::AddTypeSynthetic(SBTypeNameSpecifier type_name,
@@ -504,13 +467,7 @@ bool SBTypeCategory::AddTypeSynthetic(SBTypeNameSpecifier type_name,
}
}
- if (type_name.IsRegex())
- m_opaque_sp->GetRegexTypeSyntheticsContainer()->Add(
- RegularExpression(type_name.GetName()), synth.GetSP());
- else
- m_opaque_sp->GetTypeSyntheticsContainer()->Add(
- ConstString(type_name.GetName()), synth.GetSP());
-
+ m_opaque_sp->AddTypeSynthetic(type_name.GetSP(), synth.GetSP());
return true;
}
@@ -523,12 +480,7 @@ bool SBTypeCategory::DeleteTypeSynthetic(SBTypeNameSpecifier type_name) {
if (!type_name.IsValid())
return false;
- if (type_name.IsRegex())
- return m_opaque_sp->GetRegexTypeSyntheticsContainer()->Delete(
- ConstString(type_name.GetName()));
- else
- return m_opaque_sp->GetTypeSyntheticsContainer()->Delete(
- ConstString(type_name.GetName()));
+ return m_opaque_sp->DeleteTypeSynthetic(type_name.GetSP());
}
bool SBTypeCategory::GetDescription(lldb::SBStream &description,
diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp
index f9f8cbb364a0f..0a80806e17e87 100644
--- a/lldb/source/DataFormatters/TypeCategory.cpp
+++ b/lldb/source/DataFormatters/TypeCategory.cpp
@@ -87,10 +87,7 @@ bool TypeCategoryImpl::Get(lldb::LanguageType lang,
lldb::TypeFormatImplSP &entry) {
if (!IsEnabled() || !IsApplicable(lang))
return false;
- if (GetTypeFormatsContainer()->Get(candidates, entry))
- return true;
- bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry);
- return regex;
+ return m_format_cont.Get(candidates, entry);
}
bool TypeCategoryImpl::Get(lldb::LanguageType lang,
@@ -98,10 +95,7 @@ bool TypeCategoryImpl::Get(lldb::LanguageType lang,
lldb::TypeSummaryImplSP &entry) {
if (!IsEnabled() || !IsApplicable(lang))
return false;
- if (GetTypeSummariesContainer()->Get(candidates, entry))
- return true;
- bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry);
- return regex;
+ return m_summary_cont.Get(candidates, entry);
}
bool TypeCategoryImpl::Get(lldb::LanguageType lang,
@@ -109,30 +103,29 @@ bool TypeCategoryImpl::Get(lldb::LanguageType lang,
lldb::SyntheticChildrenSP &entry) {
if (!IsEnabled() || !IsApplicable(lang))
return false;
- TypeFilterImpl::SharedPointer filter_sp;
+
// first find both Filter and Synth, and then check which is most recent
+ bool pick_synth = false;
- if (!GetTypeFiltersContainer()->Get(candidates, filter_sp))
- GetRegexTypeFiltersContainer()->Get(candidates, filter_sp);
+ TypeFilterImpl::SharedPointer filter_sp;
+ m_filter_cont.Get(candidates, filter_sp);
- bool pick_synth = false;
- ScriptedSyntheticChildren::SharedPointer synth;
- if (!GetTypeSyntheticsContainer()->Get(candidates, synth))
- GetRegexTypeSyntheticsContainer()->Get(candidates, synth);
- if (!filter_sp.get() && !synth.get())
+ ScriptedSyntheticChildren::SharedPointer synth_sp;
+ m_synth_cont.Get(candidates, synth_sp);
+
+ if (!filter_sp.get() && !synth_sp.get())
return false;
- else if (!filter_sp.get() && synth.get())
+ else if (!filter_sp.get() && synth_sp.get())
pick_synth = true;
-
- else if (filter_sp.get() && !synth.get())
+ else if (filter_sp.get() && !synth_sp.get())
pick_synth = false;
-
- else /*if (filter_sp.get() && synth.get())*/
+ else /*if (filter_sp.get() && synth_sp.get())*/
{
- pick_synth = filter_sp->GetRevision() <= synth->GetRevision();
+ pick_synth = filter_sp->GetRevision() <= synth_sp->GetRevision();
}
+
if (pick_synth) {
- entry = synth;
+ entry = synth_sp;
return true;
} else {
entry = filter_sp;
@@ -276,138 +269,62 @@ bool TypeCategoryImpl::AnyMatches(ConstString type_name,
TypeCategoryImpl::FormatContainer::MapValueType
TypeCategoryImpl::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
- FormatContainer::MapValueType retval;
-
- if (type_sp) {
- if (type_sp->IsRegex())
- GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),
- retval);
- else
- GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),
- retval);
- }
-
- return retval;
+ return m_format_cont.GetForTypeNameSpecifier(type_sp);
}
TypeCategoryImpl::SummaryContainer::MapValueType
TypeCategoryImpl::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
- SummaryContainer::MapValueType retval;
-
- if (type_sp) {
- if (type_sp->IsRegex())
- GetRegexTypeSummariesContainer()->GetExact(
- ConstString(type_sp->GetName()), retval);
- else
- GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),
- retval);
- }
-
- return retval;
+ return m_summary_cont.GetForTypeNameSpecifier(type_sp);
}
TypeCategoryImpl::FilterContainer::MapValueType
TypeCategoryImpl::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
- FilterContainer::MapValueType retval;
-
- if (type_sp) {
- if (type_sp->IsRegex())
- GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),
- retval);
- else
- GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),
- retval);
- }
-
- return retval;
+ return m_filter_cont.GetForTypeNameSpecifier(type_sp);
}
TypeCategoryImpl::SynthContainer::MapValueType
TypeCategoryImpl::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
- SynthContainer::MapValueType retval;
-
- if (type_sp) {
- if (type_sp->IsRegex())
- GetRegexTypeSyntheticsContainer()->GetExact(
- ConstString(type_sp->GetName()), retval);
- else
- GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),
- retval);
- }
-
- return retval;
-}
-
-lldb::TypeNameSpecifierImplSP
-TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex(size_t index) {
- if (index < GetTypeSummariesContainer()->GetCount())
- return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index);
- else
- return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(
- index - GetTypeSummariesContainer()->GetCount());
+ return m_synth_cont.GetForTypeNameSpecifier(type_sp);
}
TypeCategoryImpl::FormatContainer::MapValueType
TypeCategoryImpl::GetFormatAtIndex(size_t index) {
- if (index < GetTypeFormatsContainer()->GetCount())
- return GetTypeFormatsContainer()->GetAtIndex(index);
- else
- return GetRegexTypeFormatsContainer()->GetAtIndex(
- index - GetTypeFormatsContainer()->GetCount());
+ return m_format_cont.GetAtIndex(index);
}
TypeCategoryImpl::SummaryContainer::MapValueType
TypeCategoryImpl::GetSummaryAtIndex(size_t index) {
- if (index < GetTypeSummariesContainer()->GetCount())
- return GetTypeSummariesContainer()->GetAtIndex(index);
- else
- return GetRegexTypeSummariesContainer()->GetAtIndex(
- index - GetTypeSummariesContainer()->GetCount());
+ return m_summary_cont.GetAtIndex(index);
}
TypeCategoryImpl::FilterContainer::MapValueType
TypeCategoryImpl::GetFilterAtIndex(size_t index) {
- if (index < GetTypeFiltersContainer()->GetCount())
- return GetTypeFiltersContainer()->GetAtIndex(index);
- else
- return GetRegexTypeFiltersContainer()->GetAtIndex(
- index - GetTypeFiltersContainer()->GetCount());
+ return m_filter_cont.GetAtIndex(index);
+}
+
+TypeCategoryImpl::SynthContainer::MapValueType
+TypeCategoryImpl::GetSyntheticAtIndex(size_t index) {
+ return m_synth_cont.GetAtIndex(index);
}
lldb::TypeNameSpecifierImplSP
TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex(size_t index) {
- if (index < GetTypeFormatsContainer()->GetCount())
- return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index);
- else
- return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(
- index - GetTypeFormatsContainer()->GetCount());
+ return m_format_cont.GetTypeNameSpecifierAtIndex(index);
}
lldb::TypeNameSpecifierImplSP
-TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex(size_t index) {
- if (index < GetTypeFiltersContainer()->GetCount())
- return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index);
- else
- return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(
- index - GetTypeFiltersContainer()->GetCount());
+TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex(size_t index) {
+ return m_summary_cont.GetTypeNameSpecifierAtIndex(index);
}
-TypeCategoryImpl::SynthContainer::MapValueType
-TypeCategoryImpl::GetSyntheticAtIndex(size_t index) {
- if (index < GetTypeSyntheticsContainer()->GetCount())
- return GetTypeSyntheticsContainer()->GetAtIndex(index);
- else
- return GetRegexTypeSyntheticsContainer()->GetAtIndex(
- index - GetTypeSyntheticsContainer()->GetCount());
+lldb::TypeNameSpecifierImplSP
+TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex(size_t index) {
+ return m_filter_cont.GetTypeNameSpecifierAtIndex(index);
}
lldb::TypeNameSpecifierImplSP
TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex(size_t index) {
- if (index < GetTypeSyntheticsContainer()->GetCount())
- return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index);
- else
- return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(
- index - GetTypeSyntheticsContainer()->GetCount());
+ return m_synth_cont.GetTypeNameSpecifierAtIndex(index);
}
void TypeCategoryImpl::Enable(bool value, uint32_t position) {
More information about the lldb-commits
mailing list