How to implement equals(0) in clang-query

Hi,

I have been wondering how to implement ‘equals’ for integer literals in clang-query. It doesn’t seem to be working for string literals either. In Registry.cpp it says: “TODO: Here is the list of the missing matchers, grouped by reason.” - here ‘equals’ is listed under ‘Other’.

So I guess there is a reason why it is not working for clang-query. Does anyone know what this reason is? I wouldn’t mind fixing it, but the few things I have tried have all resulted in failures. I am not sure why it works in clang-tidy, but not in clang-query. Aren’t they using the same code-base for matchers? I can see equals implemented in ASTMatchers.h, but why can’t clang-query use that?

Can anyone point me in the right direction as how to implement this in clang-query? I imagine there is some blocking issue since it is not implemented already.

Best regards,
Mads Ravn

+kramerb

Hi,

I have been wondering how to implement ‘equals’ for integer literals in clang-query. It doesn’t seem to be working for string literals either. In Registry.cpp it says: “TODO: Here is the list of the missing matchers, grouped by reason.” - here ‘equals’ is listed under ‘Other’.

So I guess there is a reason why it is not working for clang-query. Does anyone know what this reason is? I wouldn’t mind fixing it, but the few things I have tried have all resulted in failures. I am not sure why it works in clang-tidy, but not in clang-query. Aren’t they using the same code-base for matchers? I can see equals implemented in ASTMatchers.h, but why can’t clang-query use that?

clang-tidy is just C++ code. clang-query uses a custom expression parser to just support the matcher expressions; this will always be slightly different from the full C++ template metaprogramming support, even if close.

Generally, we’ll need to make the clang-query expression parser understand the literal 0 and then make it understand that equals can take that literal.

Hi,

I have been wondering how to implement 'equals' for integer literals in
clang-query. It doesn't seem to be working for string literals either. In
Registry.cpp it says: "TODO: Here is the list of the missing matchers,
grouped by reason." - here 'equals' is listed under 'Other'.

So I guess there is a reason why it is not working for clang-query. Does
anyone know what this reason is?

I put it in the list.
It requires more work than seemed appropriate at the time.
The function is a template, which we don't support yet in the dynamic
matcher layer.
Also, it supports types that are not supported in the parser, like floats.

I wouldn't mind fixing it, but the few things I have tried have all
resulted in failures. I am not sure why it works in clang-tidy, but not in
clang-query. Aren't they using the same code-base for matchers? I can see
equals implemented in ASTMatchers.h, but why can't clang-query use that?

Can anyone point me in the right direction as how to implement this in
clang-query? I imagine there is some blocking issue since it is not
implemented already.

I think the "easiest" way is to make a custom dynamic matcher.
But we tried very hard not to make these.
Instead, we made the original matchers compatible to make sure we are
running the same code in both.

There are a couple ways to make this work:
1) Remove the template on equals() and list all the overloads we want
manually.
2) Make equals a functor, add a type list of "accepted types" and add a
special marshaller for that pattern.

(2) is a lot of work, but would be a generic solution.
This is how polymorphic matchers work.
However, I think for this case (1) is best. I don't know if we would reuse
the generality of (2).

Another option similar to (1) is to add the specific overloads we want in
clang-query and leave the template to handle everything else.

Thank you both for your input.

I think I will dig into it over the weekend. Hopefully I can make a little headway with it :slight_smile:

Best regards,
Mads Ravn