/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/DataFormatters/TypeCategory.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- TypeCategory.h ------------------------------------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLDB_DATAFORMATTERS_TYPECATEGORY_H |
10 | | #define LLDB_DATAFORMATTERS_TYPECATEGORY_H |
11 | | |
12 | | #include <array> |
13 | | #include <initializer_list> |
14 | | #include <memory> |
15 | | #include <mutex> |
16 | | #include <string> |
17 | | #include <vector> |
18 | | |
19 | | #include "lldb/lldb-enumerations.h" |
20 | | #include "lldb/lldb-public.h" |
21 | | |
22 | | #include "lldb/DataFormatters/FormatClasses.h" |
23 | | #include "lldb/DataFormatters/FormattersContainer.h" |
24 | | |
25 | | namespace lldb_private { |
26 | | |
27 | | // A formatter container with sub-containers for different priority tiers, that |
28 | | // also exposes a flat view of all formatters in it. |
29 | | // |
30 | | // Formatters have different priority during matching, depending on the type of |
31 | | // matching specified at registration. Exact matchers are processed first, then |
32 | | // regex, and finally callback matchers. However, the scripting API presents a |
33 | | // flat view of formatters in a category, with methods like `GetNumFormats()` |
34 | | // and `GetFormatAtIndex(i)`. So we need something that can behave like both |
35 | | // representations. |
36 | | template <typename FormatterImpl> class TieredFormatterContainer { |
37 | | public: |
38 | | using Subcontainer = FormattersContainer<FormatterImpl>; |
39 | | using SubcontainerSP = std::shared_ptr<Subcontainer>; |
40 | | using ForEachCallback = typename Subcontainer::ForEachCallback; |
41 | | using MapValueType = typename Subcontainer::ValueSP; |
42 | | |
43 | 13.3k | TieredFormatterContainer(IFormatChangeListener *change_listener) { |
44 | 13.3k | for (auto& sc : m_subcontainers) |
45 | 40.0k | sc = std::make_shared<Subcontainer>(change_listener); |
46 | 13.3k | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::TieredFormatterContainer(lldb_private::IFormatChangeListener*) Line | Count | Source | 43 | 3.33k | TieredFormatterContainer(IFormatChangeListener *change_listener) { | 44 | 3.33k | for (auto& sc : m_subcontainers) | 45 | 10.0k | sc = std::make_shared<Subcontainer>(change_listener); | 46 | 3.33k | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::TieredFormatterContainer(lldb_private::IFormatChangeListener*) Line | Count | Source | 43 | 3.33k | TieredFormatterContainer(IFormatChangeListener *change_listener) { | 44 | 3.33k | for (auto& sc : m_subcontainers) | 45 | 10.0k | sc = std::make_shared<Subcontainer>(change_listener); | 46 | 3.33k | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::TieredFormatterContainer(lldb_private::IFormatChangeListener*) Line | Count | Source | 43 | 3.33k | TieredFormatterContainer(IFormatChangeListener *change_listener) { | 44 | 3.33k | for (auto& sc : m_subcontainers) | 45 | 10.0k | sc = std::make_shared<Subcontainer>(change_listener); | 46 | 3.33k | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::TieredFormatterContainer(lldb_private::IFormatChangeListener*) Line | Count | Source | 43 | 3.33k | TieredFormatterContainer(IFormatChangeListener *change_listener) { | 44 | 3.33k | for (auto& sc : m_subcontainers) | 45 | 10.0k | sc = std::make_shared<Subcontainer>(change_listener); | 46 | 3.33k | } |
|
47 | | |
48 | | /// Clears all subcontainers. |
49 | 422 | void Clear() { |
50 | 422 | for (auto sc : m_subcontainers) |
51 | 1.26k | sc->Clear(); |
52 | 422 | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::Clear() Line | Count | Source | 49 | 123 | void Clear() { | 50 | 123 | for (auto sc : m_subcontainers) | 51 | 369 | sc->Clear(); | 52 | 123 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::Clear() Line | Count | Source | 49 | 155 | void Clear() { | 50 | 155 | for (auto sc : m_subcontainers) | 51 | 465 | sc->Clear(); | 52 | 155 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::Clear() Line | Count | Source | 49 | 40 | void Clear() { | 50 | 40 | for (auto sc : m_subcontainers) | 51 | 120 | sc->Clear(); | 52 | 40 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::Clear() Line | Count | Source | 49 | 104 | void Clear() { | 50 | 104 | for (auto sc : m_subcontainers) | 51 | 312 | sc->Clear(); | 52 | 104 | } |
|
53 | | |
54 | | /// Adds a formatter to the right subcontainer depending on the matching type |
55 | | /// specified by `type_sp`. |
56 | | void Add(lldb::TypeNameSpecifierImplSP type_sp, |
57 | 190k | std::shared_ptr<FormatterImpl> format_sp) { |
58 | 190k | m_subcontainers[type_sp->GetMatchType()]->Add(TypeMatcher(type_sp), |
59 | 190k | format_sp); |
60 | 190k | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::Add(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>, std::__1::shared_ptr<lldb_private::TypeFormatImpl>) Line | Count | Source | 57 | 702 | std::shared_ptr<FormatterImpl> format_sp) { | 58 | 702 | m_subcontainers[type_sp->GetMatchType()]->Add(TypeMatcher(type_sp), | 59 | 702 | format_sp); | 60 | 702 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::Add(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>, std::__1::shared_ptr<lldb_private::TypeSummaryImpl>) Line | Count | Source | 57 | 139k | std::shared_ptr<FormatterImpl> format_sp) { | 58 | 139k | m_subcontainers[type_sp->GetMatchType()]->Add(TypeMatcher(type_sp), | 59 | 139k | format_sp); | 60 | 139k | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::Add(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>, std::__1::shared_ptr<lldb_private::TypeFilterImpl>) Line | Count | Source | 57 | 33 | std::shared_ptr<FormatterImpl> format_sp) { | 58 | 33 | m_subcontainers[type_sp->GetMatchType()]->Add(TypeMatcher(type_sp), | 59 | 33 | format_sp); | 60 | 33 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::Add(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>, std::__1::shared_ptr<lldb_private::SyntheticChildren>) Line | Count | Source | 57 | 49.7k | std::shared_ptr<FormatterImpl> format_sp) { | 58 | 49.7k | m_subcontainers[type_sp->GetMatchType()]->Add(TypeMatcher(type_sp), | 59 | 49.7k | format_sp); | 60 | 49.7k | } |
|
61 | | |
62 | | /// Deletes the formatter specified by `type_sp`. |
63 | 12 | bool Delete(lldb::TypeNameSpecifierImplSP type_sp) { |
64 | 12 | return m_subcontainers[type_sp->GetMatchType()]->Delete( |
65 | 12 | TypeMatcher(type_sp)); |
66 | 12 | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::Delete(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) Line | Count | Source | 63 | 3 | bool Delete(lldb::TypeNameSpecifierImplSP type_sp) { | 64 | 3 | return m_subcontainers[type_sp->GetMatchType()]->Delete( | 65 | 3 | TypeMatcher(type_sp)); | 66 | 3 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::Delete(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) Line | Count | Source | 63 | 5 | bool Delete(lldb::TypeNameSpecifierImplSP type_sp) { | 64 | 5 | return m_subcontainers[type_sp->GetMatchType()]->Delete( | 65 | 5 | TypeMatcher(type_sp)); | 66 | 5 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::Delete(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) Line | Count | Source | 63 | 3 | bool Delete(lldb::TypeNameSpecifierImplSP type_sp) { | 64 | 3 | return m_subcontainers[type_sp->GetMatchType()]->Delete( | 65 | 3 | TypeMatcher(type_sp)); | 66 | 3 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::Delete(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) Line | Count | Source | 63 | 1 | bool Delete(lldb::TypeNameSpecifierImplSP type_sp) { | 64 | 1 | return m_subcontainers[type_sp->GetMatchType()]->Delete( | 65 | 1 | TypeMatcher(type_sp)); | 66 | 1 | } |
|
67 | | |
68 | | /// Deletes all formatters registered with the string `name`, in all |
69 | | /// subcontainers. |
70 | 80 | bool Delete(ConstString name) { |
71 | 80 | bool success = false; |
72 | 80 | for (auto sc : m_subcontainers) |
73 | 240 | success = sc->Delete(name) || success174 ; |
74 | 80 | return success; |
75 | 80 | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::Delete(lldb_private::ConstString) Line | Count | Source | 70 | 10 | bool Delete(ConstString name) { | 71 | 10 | bool success = false; | 72 | 10 | for (auto sc : m_subcontainers) | 73 | 30 | success = sc->Delete(name) || success26 ; | 74 | 10 | return success; | 75 | 10 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::Delete(lldb_private::ConstString) Line | Count | Source | 70 | 54 | bool Delete(ConstString name) { | 71 | 54 | bool success = false; | 72 | 54 | for (auto sc : m_subcontainers) | 73 | 162 | success = sc->Delete(name) || success116 ; | 74 | 54 | return success; | 75 | 54 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::Delete(lldb_private::ConstString) Line | Count | Source | 70 | 4 | bool Delete(ConstString name) { | 71 | 4 | bool success = false; | 72 | 4 | for (auto sc : m_subcontainers) | 73 | 12 | success = sc->Delete(name) || success8 ; | 74 | 4 | return success; | 75 | 4 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::Delete(lldb_private::ConstString) Line | Count | Source | 70 | 12 | bool Delete(ConstString name) { | 71 | 12 | bool success = false; | 72 | 12 | for (auto sc : m_subcontainers) | 73 | 36 | success = sc->Delete(name) || success24 ; | 74 | 12 | return success; | 75 | 12 | } |
|
76 | | |
77 | | /// Returns the total count of elements across all subcontainers. |
78 | 120 | uint32_t GetCount() { |
79 | 120 | uint32_t result = 0; |
80 | 120 | for (auto sc : m_subcontainers) |
81 | 360 | result += sc->GetCount(); |
82 | 120 | return result; |
83 | 120 | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::GetCount() Line | Count | Source | 78 | 30 | uint32_t GetCount() { | 79 | 30 | uint32_t result = 0; | 80 | 30 | for (auto sc : m_subcontainers) | 81 | 90 | result += sc->GetCount(); | 82 | 30 | return result; | 83 | 30 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::GetCount() Line | Count | Source | 78 | 30 | uint32_t GetCount() { | 79 | 30 | uint32_t result = 0; | 80 | 30 | for (auto sc : m_subcontainers) | 81 | 90 | result += sc->GetCount(); | 82 | 30 | return result; | 83 | 30 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::GetCount() Line | Count | Source | 78 | 30 | uint32_t GetCount() { | 79 | 30 | uint32_t result = 0; | 80 | 30 | for (auto sc : m_subcontainers) | 81 | 90 | result += sc->GetCount(); | 82 | 30 | return result; | 83 | 30 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::GetCount() Line | Count | Source | 78 | 30 | uint32_t GetCount() { | 79 | 30 | uint32_t result = 0; | 80 | 30 | for (auto sc : m_subcontainers) | 81 | 90 | result += sc->GetCount(); | 82 | 30 | return result; | 83 | 30 | } |
|
84 | | |
85 | | /// Returns the formatter at `index`, simulating a flattened view of all |
86 | | /// subcontainers in priority order. |
87 | 0 | MapValueType GetAtIndex(size_t index) { |
88 | 0 | for (auto sc : m_subcontainers) { |
89 | 0 | if (index < sc->GetCount()) |
90 | 0 | return sc->GetAtIndex(index); |
91 | 0 | index -= sc->GetCount(); |
92 | 0 | } |
93 | 0 | return MapValueType(); |
94 | 0 | } Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::GetAtIndex(unsigned long) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::GetAtIndex(unsigned long) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::GetAtIndex(unsigned long) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::GetAtIndex(unsigned long) |
95 | | |
96 | | /// Looks for a matching candidate across all priority tiers, in priority |
97 | | /// order. If a match is found, returns `true` and puts the matching entry in |
98 | | /// `entry`. |
99 | | bool Get(const FormattersMatchVector &candidates, |
100 | 111k | std::shared_ptr<FormatterImpl> &entry) { |
101 | 331k | for (auto sc : m_subcontainers) { |
102 | 331k | if (sc->Get(candidates, entry)) |
103 | 1.94k | return true; |
104 | 331k | } |
105 | 109k | return false; |
106 | 111k | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::Get(std::__1::vector<lldb_private::FormattersMatchCandidate, std::__1::allocator<lldb_private::FormattersMatchCandidate> > const&, std::__1::shared_ptr<lldb_private::TypeFormatImpl>&) Line | Count | Source | 100 | 30.1k | std::shared_ptr<FormatterImpl> &entry) { | 101 | 90.4k | for (auto sc : m_subcontainers) { | 102 | 90.4k | if (sc->Get(candidates, entry)) | 103 | 49 | return true; | 104 | 90.4k | } | 105 | 30.1k | return false; | 106 | 30.1k | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::Get(std::__1::vector<lldb_private::FormattersMatchCandidate, std::__1::allocator<lldb_private::FormattersMatchCandidate> > const&, std::__1::shared_ptr<lldb_private::TypeSummaryImpl>&) Line | Count | Source | 100 | 25.7k | std::shared_ptr<FormatterImpl> &entry) { | 101 | 75.0k | for (auto sc : m_subcontainers) { | 102 | 75.0k | if (sc->Get(candidates, entry)) | 103 | 1.38k | return true; | 104 | 75.0k | } | 105 | 24.3k | return false; | 106 | 25.7k | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::Get(std::__1::vector<lldb_private::FormattersMatchCandidate, std::__1::allocator<lldb_private::FormattersMatchCandidate> > const&, std::__1::shared_ptr<lldb_private::TypeFilterImpl>&) Line | Count | Source | 100 | 27.8k | std::shared_ptr<FormatterImpl> &entry) { | 101 | 83.2k | for (auto sc : m_subcontainers) { | 102 | 83.2k | if (sc->Get(candidates, entry)) | 103 | 58 | return true; | 104 | 83.2k | } | 105 | 27.7k | return false; | 106 | 27.8k | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::Get(std::__1::vector<lldb_private::FormattersMatchCandidate, std::__1::allocator<lldb_private::FormattersMatchCandidate> > const&, std::__1::shared_ptr<lldb_private::SyntheticChildren>&) Line | Count | Source | 100 | 27.8k | std::shared_ptr<FormatterImpl> &entry) { | 101 | 82.7k | for (auto sc : m_subcontainers) { | 102 | 82.7k | if (sc->Get(candidates, entry)) | 103 | 446 | return true; | 104 | 82.7k | } | 105 | 27.3k | return false; | 106 | 27.8k | } |
|
107 | | |
108 | 52 | bool AnyMatches(const FormattersMatchCandidate &candidate) { |
109 | 52 | std::shared_ptr<FormatterImpl> entry; |
110 | 148 | for (auto sc : m_subcontainers) { |
111 | 148 | if (sc->Get(FormattersMatchVector{candidate}, entry)) |
112 | 4 | return true; |
113 | 148 | } |
114 | 48 | return false; |
115 | 52 | } Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::AnyMatches(lldb_private::FormattersMatchCandidate const&) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::AnyMatches(lldb_private::FormattersMatchCandidate const&) lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::AnyMatches(lldb_private::FormattersMatchCandidate const&) Line | Count | Source | 108 | 27 | bool AnyMatches(const FormattersMatchCandidate &candidate) { | 109 | 27 | std::shared_ptr<FormatterImpl> entry; | 110 | 77 | for (auto sc : m_subcontainers) { | 111 | 77 | if (sc->Get(FormattersMatchVector{candidate}, entry)) | 112 | 2 | return true; | 113 | 77 | } | 114 | 25 | return false; | 115 | 27 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::AnyMatches(lldb_private::FormattersMatchCandidate const&) Line | Count | Source | 108 | 25 | bool AnyMatches(const FormattersMatchCandidate &candidate) { | 109 | 25 | std::shared_ptr<FormatterImpl> entry; | 110 | 71 | for (auto sc : m_subcontainers) { | 111 | 71 | if (sc->Get(FormattersMatchVector{candidate}, entry)) | 112 | 2 | return true; | 113 | 71 | } | 114 | 23 | return false; | 115 | 25 | } |
|
116 | | |
117 | | /// Returns a formatter that is an exact match for `type_specifier_sp`. It |
118 | | /// looks for a formatter with the same matching type that was created from |
119 | | /// the same string. This is useful so we can refer to a formatter using the |
120 | | /// same string used to register it. |
121 | | /// |
122 | | /// For example, `type_specifier_sp` can be something like |
123 | | /// {"std::vector<.*>", eFormatterMatchRegex}, and we'd look for a regex |
124 | | /// matcher with that exact regex string, NOT try to match that string using |
125 | | /// regex. |
126 | | MapValueType |
127 | 156 | GetForTypeNameSpecifier(lldb::TypeNameSpecifierImplSP type_specifier_sp) { |
128 | 156 | MapValueType retval; |
129 | 156 | if (type_specifier_sp) { |
130 | 156 | m_subcontainers[type_specifier_sp->GetMatchType()]->GetExact( |
131 | 156 | ConstString(type_specifier_sp->GetName()), retval); |
132 | 156 | } |
133 | 156 | return retval; |
134 | 156 | } Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::GetForTypeNameSpecifier(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::GetForTypeNameSpecifier(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) Line | Count | Source | 127 | 150 | GetForTypeNameSpecifier(lldb::TypeNameSpecifierImplSP type_specifier_sp) { | 128 | 150 | MapValueType retval; | 129 | 150 | if (type_specifier_sp) { | 130 | 150 | m_subcontainers[type_specifier_sp->GetMatchType()]->GetExact( | 131 | 150 | ConstString(type_specifier_sp->GetName()), retval); | 132 | 150 | } | 133 | 150 | return retval; | 134 | 150 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::GetForTypeNameSpecifier(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) Line | Count | Source | 127 | 6 | GetForTypeNameSpecifier(lldb::TypeNameSpecifierImplSP type_specifier_sp) { | 128 | 6 | MapValueType retval; | 129 | 6 | if (type_specifier_sp) { | 130 | 6 | m_subcontainers[type_specifier_sp->GetMatchType()]->GetExact( | 131 | 6 | ConstString(type_specifier_sp->GetName()), retval); | 132 | 6 | } | 133 | 6 | return retval; | 134 | 6 | } |
Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::GetForTypeNameSpecifier(std::__1::shared_ptr<lldb_private::TypeNameSpecifierImpl>) |
135 | | |
136 | | /// Returns the type name specifier at `index`, simulating a flattened view of |
137 | | /// all subcontainers in priority order. |
138 | 0 | lldb::TypeNameSpecifierImplSP GetTypeNameSpecifierAtIndex(size_t index) { |
139 | 0 | for (auto sc : m_subcontainers) { |
140 | 0 | if (index < sc->GetCount()) |
141 | 0 | return sc->GetTypeNameSpecifierAtIndex(index); |
142 | 0 | index -= sc->GetCount(); |
143 | 0 | } |
144 | 0 | return lldb::TypeNameSpecifierImplSP(); |
145 | 0 | } Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::GetTypeNameSpecifierAtIndex(unsigned long) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::GetTypeNameSpecifierAtIndex(unsigned long) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::GetTypeNameSpecifierAtIndex(unsigned long) Unexecuted instantiation: lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::GetTypeNameSpecifierAtIndex(unsigned long) |
146 | | |
147 | | /// Iterates through tiers in order, running `callback` on each element of |
148 | | /// each tier. |
149 | | void ForEach(std::function<bool(const TypeMatcher &, |
150 | | const std::shared_ptr<FormatterImpl> &)> |
151 | 190 | callback) { |
152 | 570 | for (auto sc : m_subcontainers) { |
153 | 570 | sc->ForEach(callback); |
154 | 570 | } |
155 | 190 | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::ForEach(std::__1::function<bool (lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::TypeFormatImpl> const&)>) Line | Count | Source | 151 | 22 | callback) { | 152 | 66 | for (auto sc : m_subcontainers) { | 153 | 66 | sc->ForEach(callback); | 154 | 66 | } | 155 | 22 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::ForEach(std::__1::function<bool (lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::TypeSummaryImpl> const&)>) Line | Count | Source | 151 | 118 | callback) { | 152 | 354 | for (auto sc : m_subcontainers) { | 153 | 354 | sc->ForEach(callback); | 154 | 354 | } | 155 | 118 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::ForEach(std::__1::function<bool (lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::TypeFilterImpl> const&)>) Line | Count | Source | 151 | 20 | callback) { | 152 | 60 | for (auto sc : m_subcontainers) { | 153 | 60 | sc->ForEach(callback); | 154 | 60 | } | 155 | 20 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::ForEach(std::__1::function<bool (lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::SyntheticChildren> const&)>) Line | Count | Source | 151 | 30 | callback) { | 152 | 90 | for (auto sc : m_subcontainers) { | 153 | 90 | sc->ForEach(callback); | 154 | 90 | } | 155 | 30 | } |
|
156 | | |
157 | 40 | void AutoComplete(CompletionRequest &request) { |
158 | 40 | for (auto sc: m_subcontainers) |
159 | 120 | sc->AutoComplete(request); |
160 | 40 | } lldb_private::TieredFormatterContainer<lldb_private::TypeFormatImpl>::AutoComplete(lldb_private::CompletionRequest&) Line | Count | Source | 157 | 10 | void AutoComplete(CompletionRequest &request) { | 158 | 10 | for (auto sc: m_subcontainers) | 159 | 30 | sc->AutoComplete(request); | 160 | 10 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeSummaryImpl>::AutoComplete(lldb_private::CompletionRequest&) Line | Count | Source | 157 | 10 | void AutoComplete(CompletionRequest &request) { | 158 | 10 | for (auto sc: m_subcontainers) | 159 | 30 | sc->AutoComplete(request); | 160 | 10 | } |
lldb_private::TieredFormatterContainer<lldb_private::TypeFilterImpl>::AutoComplete(lldb_private::CompletionRequest&) Line | Count | Source | 157 | 10 | void AutoComplete(CompletionRequest &request) { | 158 | 10 | for (auto sc: m_subcontainers) | 159 | 30 | sc->AutoComplete(request); | 160 | 10 | } |
lldb_private::TieredFormatterContainer<lldb_private::SyntheticChildren>::AutoComplete(lldb_private::CompletionRequest&) Line | Count | Source | 157 | 10 | void AutoComplete(CompletionRequest &request) { | 158 | 10 | for (auto sc: m_subcontainers) | 159 | 30 | sc->AutoComplete(request); | 160 | 10 | } |
|
161 | | |
162 | | private: |
163 | | std::array<std::shared_ptr<Subcontainer>, lldb::eLastFormatterMatchType + 1> |
164 | | m_subcontainers; |
165 | | }; |
166 | | |
167 | | class TypeCategoryImpl { |
168 | | private: |
169 | | typedef TieredFormatterContainer<TypeFormatImpl> FormatContainer; |
170 | | typedef TieredFormatterContainer<TypeSummaryImpl> SummaryContainer; |
171 | | typedef TieredFormatterContainer<TypeFilterImpl> FilterContainer; |
172 | | typedef TieredFormatterContainer<SyntheticChildren> SynthContainer; |
173 | | |
174 | | public: |
175 | | typedef uint16_t FormatCategoryItems; |
176 | | static const uint16_t ALL_ITEM_TYPES = UINT16_MAX; |
177 | | |
178 | | // TypeFilterImpl inherits from SyntheticChildren, so we can't simply overload |
179 | | // ForEach on the type of the callback because it would result in "call to |
180 | | // member function 'ForEach' is ambiguous" errors. Instead we use this |
181 | | // templated struct to hold the formatter type and the callback. |
182 | | template<typename T> |
183 | | struct ForEachCallback { |
184 | | // Make it constructible from any callable that fits. This allows us to use |
185 | | // lambdas a bit more easily at the call site. For example: |
186 | | // ForEachCallback<TypeFormatImpl> callback = [](...) {...}; |
187 | 190 | template <typename Callable> ForEachCallback(Callable c) : callback(c) {} lldb_private::TypeCategoryImpl::ForEachCallback<lldb_private::TypeFilterImpl>::ForEachCallback<CommandObjectTypeFormatterList<lldb_private::TypeFilterImpl>::DoExecute(lldb_private::Args&, lldb_private::CommandReturnObject&)::'lambda'(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&)::operator()(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&) const::'lambda'(lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::TypeFilterImpl> const&)>(lldb_private::TypeFilterImpl) Line | Count | Source | 187 | 20 | template <typename Callable> ForEachCallback(Callable c) : callback(c) {} |
lldb_private::TypeCategoryImpl::ForEachCallback<lldb_private::TypeFormatImpl>::ForEachCallback<CommandObjectTypeFormatterList<lldb_private::TypeFormatImpl>::DoExecute(lldb_private::Args&, lldb_private::CommandReturnObject&)::'lambda'(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&)::operator()(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&) const::'lambda'(lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::TypeFormatImpl> const&)>(lldb_private::TypeFormatImpl) Line | Count | Source | 187 | 22 | template <typename Callable> ForEachCallback(Callable c) : callback(c) {} |
lldb_private::TypeCategoryImpl::ForEachCallback<lldb_private::TypeSummaryImpl>::ForEachCallback<CommandObjectTypeFormatterList<lldb_private::TypeSummaryImpl>::DoExecute(lldb_private::Args&, lldb_private::CommandReturnObject&)::'lambda'(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&)::operator()(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&) const::'lambda'(lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::TypeSummaryImpl> const&)>(lldb_private::TypeSummaryImpl) Line | Count | Source | 187 | 118 | template <typename Callable> ForEachCallback(Callable c) : callback(c) {} |
lldb_private::TypeCategoryImpl::ForEachCallback<lldb_private::SyntheticChildren>::ForEachCallback<CommandObjectTypeFormatterList<lldb_private::SyntheticChildren>::DoExecute(lldb_private::Args&, lldb_private::CommandReturnObject&)::'lambda'(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&)::operator()(std::__1::shared_ptr<lldb_private::TypeCategoryImpl> const&) const::'lambda'(lldb_private::TypeMatcher const&, std::__1::shared_ptr<lldb_private::SyntheticChildren> const&)>(lldb_private::SyntheticChildren) Line | Count | Source | 187 | 30 | template <typename Callable> ForEachCallback(Callable c) : callback(c) {} |
|
188 | | std::function<bool(const TypeMatcher &, const std::shared_ptr<T> &)> |
189 | | callback; |
190 | | }; |
191 | | |
192 | | TypeCategoryImpl(IFormatChangeListener *clist, ConstString name); |
193 | | |
194 | 22 | void ForEach(ForEachCallback<TypeFormatImpl> callback) { |
195 | 22 | m_format_cont.ForEach(callback.callback); |
196 | 22 | } |
197 | | |
198 | 118 | void ForEach(ForEachCallback<TypeSummaryImpl> callback) { |
199 | 118 | m_summary_cont.ForEach(callback.callback); |
200 | 118 | } |
201 | | |
202 | 20 | void ForEach(ForEachCallback<TypeFilterImpl> callback) { |
203 | 20 | m_filter_cont.ForEach(callback.callback); |
204 | 20 | } |
205 | | |
206 | 30 | void ForEach(ForEachCallback<SyntheticChildren> callback) { |
207 | 30 | m_synth_cont.ForEach(callback.callback); |
208 | 30 | } |
209 | | |
210 | | FormatContainer::MapValueType |
211 | | GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp); |
212 | | |
213 | | SummaryContainer::MapValueType |
214 | | GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp); |
215 | | |
216 | | FilterContainer::MapValueType |
217 | | GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp); |
218 | | |
219 | | SynthContainer::MapValueType |
220 | | GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp); |
221 | | |
222 | | void AddTypeFormat(lldb::TypeNameSpecifierImplSP type_sp, |
223 | 702 | lldb::TypeFormatImplSP format_sp) { |
224 | 702 | m_format_cont.Add(type_sp, format_sp); |
225 | 702 | } |
226 | | |
227 | | void AddTypeFormat(llvm::StringRef name, lldb::FormatterMatchType match_type, |
228 | 699 | lldb::TypeFormatImplSP format_sp) { |
229 | 699 | AddTypeFormat( |
230 | 699 | std::make_shared<lldb_private::TypeNameSpecifierImpl>(name, match_type), |
231 | 699 | format_sp); |
232 | 699 | } |
233 | | |
234 | | void AddTypeSummary(lldb::TypeNameSpecifierImplSP type_sp, |
235 | 139k | lldb::TypeSummaryImplSP summary_sp) { |
236 | 139k | m_summary_cont.Add(type_sp, summary_sp); |
237 | 139k | } |
238 | | |
239 | | void AddTypeSummary(llvm::StringRef name, lldb::FormatterMatchType match_type, |
240 | 139k | lldb::TypeSummaryImplSP summary_sp) { |
241 | 139k | AddTypeSummary( |
242 | 139k | std::make_shared<lldb_private::TypeNameSpecifierImpl>(name, match_type), |
243 | 139k | summary_sp); |
244 | 139k | } |
245 | | |
246 | | void AddTypeFilter(lldb::TypeNameSpecifierImplSP type_sp, |
247 | 33 | lldb::TypeFilterImplSP filter_sp) { |
248 | 33 | m_filter_cont.Add(type_sp, filter_sp); |
249 | 33 | } |
250 | | |
251 | | void AddTypeFilter(llvm::StringRef name, lldb::FormatterMatchType match_type, |
252 | 28 | lldb::TypeFilterImplSP filter_sp) { |
253 | 28 | AddTypeFilter( |
254 | 28 | std::make_shared<lldb_private::TypeNameSpecifierImpl>(name, match_type), |
255 | 28 | filter_sp); |
256 | 28 | } |
257 | | |
258 | | void AddTypeSynthetic(lldb::TypeNameSpecifierImplSP type_sp, |
259 | 49.7k | lldb::SyntheticChildrenSP synth_sp) { |
260 | 49.7k | m_synth_cont.Add(type_sp, synth_sp); |
261 | 49.7k | } |
262 | | |
263 | | void AddTypeSynthetic(llvm::StringRef name, |
264 | | lldb::FormatterMatchType match_type, |
265 | 49.7k | lldb::SyntheticChildrenSP synth_sp) { |
266 | 49.7k | AddTypeSynthetic( |
267 | 49.7k | std::make_shared<lldb_private::TypeNameSpecifierImpl>(name, match_type), |
268 | 49.7k | synth_sp); |
269 | 49.7k | } |
270 | | |
271 | 3 | bool DeleteTypeFormat(lldb::TypeNameSpecifierImplSP type_sp) { |
272 | 3 | return m_format_cont.Delete(type_sp); |
273 | 3 | } |
274 | | |
275 | 5 | bool DeleteTypeSummary(lldb::TypeNameSpecifierImplSP type_sp) { |
276 | 5 | return m_summary_cont.Delete(type_sp); |
277 | 5 | } |
278 | | |
279 | 3 | bool DeleteTypeFilter(lldb::TypeNameSpecifierImplSP type_sp) { |
280 | 3 | return m_filter_cont.Delete(type_sp); |
281 | 3 | } |
282 | | |
283 | 1 | bool DeleteTypeSynthetic(lldb::TypeNameSpecifierImplSP type_sp) { |
284 | 1 | return m_synth_cont.Delete(type_sp); |
285 | 1 | } |
286 | | |
287 | 0 | uint32_t GetNumFormats() { return m_format_cont.GetCount(); } |
288 | | |
289 | 0 | uint32_t GetNumSummaries() { return m_summary_cont.GetCount(); } |
290 | | |
291 | 0 | uint32_t GetNumFilters() { return m_filter_cont.GetCount(); } |
292 | | |
293 | 0 | uint32_t GetNumSynthetics() { return m_synth_cont.GetCount(); } |
294 | | |
295 | | lldb::TypeNameSpecifierImplSP |
296 | | GetTypeNameSpecifierForFormatAtIndex(size_t index); |
297 | | |
298 | | lldb::TypeNameSpecifierImplSP |
299 | | GetTypeNameSpecifierForSummaryAtIndex(size_t index); |
300 | | |
301 | | lldb::TypeNameSpecifierImplSP |
302 | | GetTypeNameSpecifierForFilterAtIndex(size_t index); |
303 | | |
304 | | lldb::TypeNameSpecifierImplSP |
305 | | GetTypeNameSpecifierForSyntheticAtIndex(size_t index); |
306 | | |
307 | | FormatContainer::MapValueType GetFormatAtIndex(size_t index); |
308 | | |
309 | | SummaryContainer::MapValueType GetSummaryAtIndex(size_t index); |
310 | | |
311 | | FilterContainer::MapValueType GetFilterAtIndex(size_t index); |
312 | | |
313 | | SynthContainer::MapValueType GetSyntheticAtIndex(size_t index); |
314 | | |
315 | 85.0k | bool IsEnabled() const { return m_enabled; } |
316 | | |
317 | 1 | uint32_t GetEnabledPosition() { |
318 | 1 | if (!m_enabled) |
319 | 0 | return UINT32_MAX; |
320 | 1 | else |
321 | 1 | return m_enabled_position; |
322 | 1 | } |
323 | | |
324 | | bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, |
325 | | lldb::TypeFormatImplSP &entry); |
326 | | |
327 | | bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, |
328 | | lldb::TypeSummaryImplSP &entry); |
329 | | |
330 | | bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, |
331 | | lldb::SyntheticChildrenSP &entry); |
332 | | |
333 | | void Clear(FormatCategoryItems items = ALL_ITEM_TYPES); |
334 | | |
335 | | bool Delete(ConstString name, FormatCategoryItems items = ALL_ITEM_TYPES); |
336 | | |
337 | | uint32_t GetCount(FormatCategoryItems items = ALL_ITEM_TYPES); |
338 | | |
339 | 576 | const char *GetName() { return m_name.GetCString(); } |
340 | | |
341 | | size_t GetNumLanguages(); |
342 | | |
343 | | lldb::LanguageType GetLanguageAtIndex(size_t idx); |
344 | | |
345 | | void AddLanguage(lldb::LanguageType lang); |
346 | | |
347 | | std::string GetDescription(); |
348 | | |
349 | | bool AnyMatches(const FormattersMatchCandidate &candidate_type, |
350 | | FormatCategoryItems items = ALL_ITEM_TYPES, |
351 | | bool only_enabled = true, |
352 | | const char **matching_category = nullptr, |
353 | | FormatCategoryItems *matching_type = nullptr); |
354 | | |
355 | | void AutoComplete(CompletionRequest &request, FormatCategoryItems items); |
356 | | |
357 | | typedef std::shared_ptr<TypeCategoryImpl> SharedPointer; |
358 | | |
359 | | private: |
360 | | FormatContainer m_format_cont; |
361 | | SummaryContainer m_summary_cont; |
362 | | FilterContainer m_filter_cont; |
363 | | SynthContainer m_synth_cont; |
364 | | |
365 | | bool m_enabled; |
366 | | |
367 | | IFormatChangeListener *m_change_listener; |
368 | | |
369 | | std::recursive_mutex m_mutex; |
370 | | |
371 | | ConstString m_name; |
372 | | |
373 | | std::vector<lldb::LanguageType> m_languages; |
374 | | |
375 | | uint32_t m_enabled_position = 0; |
376 | | |
377 | | void Enable(bool value, uint32_t position); |
378 | | |
379 | 60 | void Disable() { Enable(false, UINT32_MAX); } |
380 | | |
381 | | bool IsApplicable(lldb::LanguageType lang); |
382 | | |
383 | 20 | uint32_t GetLastEnabledPosition() { return m_enabled_position; } |
384 | | |
385 | 12 | void SetEnabledPosition(uint32_t p) { m_enabled_position = p; } |
386 | | |
387 | | friend class FormatManager; |
388 | | friend class LanguageCategory; |
389 | | friend class TypeCategoryMap; |
390 | | |
391 | | friend class FormattersContainer<TypeFormatImpl>; |
392 | | |
393 | | friend class FormattersContainer<TypeSummaryImpl>; |
394 | | |
395 | | friend class FormattersContainer<TypeFilterImpl>; |
396 | | |
397 | | friend class FormattersContainer<ScriptedSyntheticChildren>; |
398 | | }; |
399 | | |
400 | | } // namespace lldb_private |
401 | | |
402 | | #endif // LLDB_DATAFORMATTERS_TYPECATEGORY_H |