@@ -50,6 +50,11 @@ class TypeMatcher {
50
50
// / - eFormatterMatchCallback: run the function in m_name to decide if a type
51
51
// / matches or not.
52
52
lldb::FormatterMatchType m_match_type;
53
+ // / An optional additional check for a FormattersMatchCandidate.
54
+ // /
55
+ // / If set, the name/regex is still checked first and this function will be
56
+ // / called if the name matches.
57
+ CxxTypeCandidateMatchFn *m_match_fn = nullptr ;
53
58
54
59
// if the user tries to add formatters for, say, "struct Foo" those will not
55
60
// match any type because of the way we strip qualifiers from typenames this
@@ -86,32 +91,19 @@ class TypeMatcher {
86
91
// / name specifier.
87
92
TypeMatcher (lldb::TypeNameSpecifierImplSP type_specifier)
88
93
: m_name(type_specifier->GetName ()),
89
- m_match_type(type_specifier->GetMatchType ()) {
94
+ m_match_type(type_specifier->GetMatchType ()),
95
+ m_match_fn(type_specifier->GetCxxMatchFunction ()) {
90
96
if (m_match_type == lldb::eFormatterMatchRegex)
91
97
m_type_name_regex = RegularExpression (type_specifier->GetName ());
92
98
}
93
99
94
100
// / True iff this matches the given type.
95
101
bool Matches (FormattersMatchCandidate candidate_type) const {
96
- ConstString type_name = candidate_type.GetTypeName ();
97
- switch (m_match_type) {
98
- case lldb::eFormatterMatchExact:
99
- return m_name == type_name ||
100
- StripTypeName (m_name) == StripTypeName (type_name);
101
- case lldb::eFormatterMatchRegex:
102
- return m_type_name_regex.Execute (type_name.GetStringRef ());
103
- case lldb::eFormatterMatchCallback:
104
- // CommandObjectType{Synth,Filter}Add tries to prevent the user from
105
- // creating both a synthetic child provider and a filter for the same type
106
- // in the same category, but we don't have a type object at that point, so
107
- // it creates a dummy candidate without type or script interpreter.
108
- // Skip callback matching in these cases.
109
- if (candidate_type.GetScriptInterpreter ())
110
- return candidate_type.GetScriptInterpreter ()->FormatterCallbackFunction (
111
- m_name.AsCString (),
112
- std::make_shared<TypeImpl>(candidate_type.GetType ()));
113
- }
114
- return false ;
102
+ if (!MatchesName (candidate_type))
103
+ return false ;
104
+ if (m_match_fn && !m_match_fn (candidate_type))
105
+ return false ;
106
+ return true ;
115
107
}
116
108
117
109
lldb::FormatterMatchType GetMatchType () const { return m_match_type; }
@@ -134,7 +126,31 @@ class TypeMatcher {
134
126
// / (lldb) type summary add --summary-string \"A\" -x TypeName
135
127
// / (lldb) type summary delete TypeName
136
128
bool CreatedBySameMatchString (TypeMatcher other) const {
137
- return GetMatchString () == other.GetMatchString ();
129
+ return GetMatchString () == other.GetMatchString () &&
130
+ m_match_fn == other.m_match_fn ;
131
+ }
132
+
133
+ private:
134
+ bool MatchesName (FormattersMatchCandidate candidate_type) const {
135
+ ConstString type_name = candidate_type.GetTypeName ();
136
+ switch (m_match_type) {
137
+ case lldb::eFormatterMatchExact:
138
+ return m_name == type_name ||
139
+ StripTypeName (m_name) == StripTypeName (type_name);
140
+ case lldb::eFormatterMatchRegex:
141
+ return m_type_name_regex.Execute (type_name.GetStringRef ());
142
+ case lldb::eFormatterMatchCallback:
143
+ // CommandObjectType{Synth,Filter}Add tries to prevent the user from
144
+ // creating both a synthetic child provider and a filter for the same type
145
+ // in the same category, but we don't have a type object at that point, so
146
+ // it creates a dummy candidate without type or script interpreter.
147
+ // Skip callback matching in these cases.
148
+ if (candidate_type.GetScriptInterpreter ())
149
+ return candidate_type.GetScriptInterpreter ()->FormatterCallbackFunction (
150
+ m_name.AsCString (),
151
+ std::make_shared<TypeImpl>(candidate_type.GetType ()));
152
+ }
153
+ return false ;
138
154
}
139
155
};
140
156
0 commit comments