[cfe-dev] From addMatcher(varDecl(...)) -> callExpr

Allan Nielsen a at awn.dk
Sun Jun 1 13:58:24 PDT 2014


I finally found what I was looking for:

for (auto i = expr->child_begin(); i != expr->child_end(); ++i, ++cnt)

Thanks for a great tool :-)


On Sun, Jun 1, 2014 at 6:41 PM, Allan Nielsen <a at awn.dk> wrote:

> Hi,
>
> (let me know if requests like this should go to the "users" list instead)
>
> I'm playing around with the tooling facilities in clang, and have been
> using RemoveCStrCalls.cpp as an example.
>
> Here is the problem I'm trying to solve:
>
> I have a set of variables of a given type, I would like to refactor to use
> another type. To do this, I need to change the template arguments, and
> re-organize the arguments to the constructor.
>
> Example:
>
> Say we have: Foo<int, long> my_foo(1, 2);
>
> We want: Bar<my_int, my_long> my_bar(my_int(1), my_long(2));
>
> To find all the instances of Foo, I have written a matcher like this:
>
>   Finder.addMatcher(
>       id("foo_instance",
>          varDecl(hasType(recordDecl(hasName("::Foo"))))),
>       &Callback);
>
> In my callback function I have managed to get access to the template
> arguments as I wanted to, and I got access to the instance name. So far so
> good...
>
> But I can not figure out how I get access to the constructor arguments. I
> think I want to convert the VarDecl type to a CallExpr but I'm not sure
> that this is the right approach.
>
> In my callback rutine I have the following code:
>
> const VarDecl *decl = Result.Nodes.getNodeAs<VarDecl>("foo_instance");
> auto expr = decl->getInit();
>
> And then I do not know how to continue...
>
> A hint will be most appreciated.
>
> Best regards
> Allan W. Nielsen
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140601/d962a03d/attachment.html>


More information about the cfe-dev mailing list