Commit 49fa8ed9 authored by Paul's avatar Paul
Browse files

Check number of args match in args matcher

parent 0c0032b4
...@@ -271,6 +271,11 @@ inline auto name(std::string name) ...@@ -271,6 +271,11 @@ inline auto name(std::string name)
[ =, name = std::move(name) ](instruction_ref ins) { return ins->name() == name; }); [ =, name = std::move(name) ](instruction_ref ins) { return ins->name() == name; });
} }
inline auto nargs(std::size_t n)
{
return make_basic_pred_matcher([=](instruction_ref ins) { return ins->inputs().size() == n; });
}
inline auto arg(std::size_t i) inline auto arg(std::size_t i)
{ {
return make_basic_fun_matcher([=](matcher_context& ctx, instruction_ref ins) { return make_basic_fun_matcher([=](matcher_context& ctx, instruction_ref ins) {
...@@ -289,7 +294,7 @@ struct args_impl_ints ...@@ -289,7 +294,7 @@ struct args_impl_ints
template <std::size_t... Ns, class... Ms> template <std::size_t... Ns, class... Ms>
auto args_impl(args_impl_ints<Ns...>, Ms... ms) auto args_impl(args_impl_ints<Ns...>, Ms... ms)
{ {
return matchers::all_of(arg(Ns)(ms)...); return matchers::all_of(nargs(sizeof...(Ns)), arg(Ns)(ms)...);
} }
template <class... Ms> template <class... Ms>
......
...@@ -191,7 +191,7 @@ void match_args3() ...@@ -191,7 +191,7 @@ void match_args3()
auto m = matchers::name("sum")(matchers::args(matchers::name("@literal")), auto m = matchers::name("sum")(matchers::args(matchers::name("@literal")),
matchers::standard_shape()); matchers::standard_shape());
auto r = find_match(p, m); auto r = find_match(p, m);
EXPECT(bool{r.result == sum}); EXPECT(bool{r.result == p.end()});
} }
void match_args4() void match_args4()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment