AST matcher "refersToType"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

AST matcher "refersToType"

Kristof Beyls via cfe-dev
I believe I've found a mistake in the documentation for the `refersToType` AST matcher: https://clang.llvm.org/docs/LibASTMatchersReference.html#refersToType0

The example code makes use of a matcher called `class`, but I am unable to find such a matcher in the docs, and when I try to use it in clang-query I get a "matcher not found" error.

I'd be happy to make a patch to the docs, but am actually having trouble using the `refersToType` matcher at the moment. I'm trying to match calls to `std::make_unique` specialized with a particular class. That is, I want `std::make_unique<Demo::Widget>`, but not `std::make_unique<Something::Else>`. I'd also be happy with a way to filter for the correct matches in the MatchCallback.

There's a stackoverflow post with a complete code example and a couple things I've tried available at https://stackoverflow.com/q/58443058/1586229

Thanks,
-Brian

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: AST matcher "refersToType"

Kristof Beyls via cfe-dev
On 18/10/2019 20:56, Brian Schiller via cfe-dev wrote:

> I believe I've found a mistake in the documentation for the
> `refersToType` AST matcher:
> https://clang.llvm.org/docs/LibASTMatchersReference.html#refersToType0
>
> The example code makes use of a matcher called `class`, but I am unable
> to find such a matcher in the docs, and when I try to use it in
> clang-query I get a "matcher not found" error.
>
> I'd be happy to make a patch to the docs, but am actually having trouble
> using the `refersToType` matcher at the moment. I'm trying to match
> calls to `std::make_unique` specialized with a particular class. That
> is, I want `std::make_unique<Demo::Widget>`, but not
> `std::make_unique<Something::Else>`. I'd also be happy with a way to
> filter for the correct matches in the MatchCallback.


You need `refersToType(asString("class Demo::Widget")))`.

Unfortunately this is not very discoverable. I showed some tooling to
make this discoverable here:
https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools-eurollvm-and-accu/ 
but it's not generally available yet.

Thanks,

Stephen.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev