[Lldb-commits] [lldb] [lldb] Refactor TypeQuery::ContextMatches (PR #99305)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 18 04:50:01 PDT 2024
================
@@ -153,19 +127,89 @@ void TypeQuery::SetLanguages(LanguageSet languages) {
bool TypeQuery::ContextMatches(
llvm::ArrayRef<CompilerContext> context_chain) const {
- if (GetExactMatch() || context_chain.size() == m_context.size())
- return ::contextMatches(context_chain, m_context);
-
- // We don't have an exact match, we need to bottom m_context.size() items to
- // match for a successful lookup.
- if (context_chain.size() < m_context.size())
- return false; // Not enough items in context_chain to allow for a match.
-
- size_t compare_count = context_chain.size() - m_context.size();
- return ::contextMatches(
- llvm::ArrayRef<CompilerContext>(context_chain.data() + compare_count,
- m_context.size()),
- m_context);
+ auto ctx = context_chain.rbegin(), ctx_end = context_chain.rend();
+ for (auto pat = m_context.rbegin(), pat_end = m_context.rend();
+ pat != pat_end;) {
+
+ // Handle AnyModule matches. These are tricky as they can match any number
+ // of modules.
+ if (pat->kind == CompilerContextKind::AnyModule) {
+ // Successive wildcards are equivalent to a single wildcard.
+ while (pat->kind == CompilerContextKind::AnyModule)
+ ++pat;
+
+ // [ctx, ctx_module_end) is the range of entries that may be matched by
+ // our wildcard.
+ auto ctx_module_end =
+ std::find_if(ctx, ctx_end, [](const CompilerContext &c) {
+ return c.kind != CompilerContextKind::Module;
+ });
+
+ // [pat, exact_pat_end) is the range of exact module match patterns. If
+ // it's not empty, we need to make sure our wildcard does not consume
+ // entries matched by those.
+ auto exact_pat_end =
+ std::find_if(pat, pat_end, [](const CompilerContext &p) {
+ return (p.kind & CompilerContextKind::AnyModule) !=
+ CompilerContextKind::Module;
----------------
Michael137 wrote:
Couldn't this just be:
```suggestion
std::find_if(pat, pat_end, [](const CompilerContext &p) {
return p.kind != CompilerContextKind::Module;
```
Since we've already skipped all the `AnyModule` patterns before we get here?
https://github.com/llvm/llvm-project/pull/99305
More information about the lldb-commits
mailing list