[cfe-dev] ast_matchers::MatchFinder to CallExpr that's a macro call

Manuel Klimek klimek at google.com
Fri Apr 26 06:31:48 PDT 2013


On Fri, Apr 26, 2013 at 3:02 PM, Peeter Joot <peeter.joot at gmail.com> wrote:

>
> On Fri, Apr 26, 2013 at 12:45 AM, Manuel Klimek <klimek at google.com> wrote:
>
>> Note that the AST dump does not contain all the information there is (or
>> it would be completely unreadable).
>>
>> Is there any way to do a very verbose dump rooted at a specific
> expression?
>

Nope. Patches welcome, I guess :)


>
>
>> With AST matchers, you can currently only match the "C++" names of
>> things. After matching the call, you can look at the expansion location of
>> the identifier that references the function (get it via the SourceManager)
>> or try to directly use the Lexer's makeFileCharRange.
>>
>
> To simplify the problem, I'll hack the code in this case to use a fake
> prototype, one that looks like the macro interface.  Then the problem
> becomes manipulating the parameters.
>
> I see in the match test code stuff like:
>
>   const char Program[] =
>       "struct T { };"
>       "int f(int, T*, int, int);"
>       "void g(int x) { T t; f(x, &t, 3, 4); }";
>  ...
>   EXPECT_TRUE(matches(Program,
>       callExpr(allOf(callee(functionDecl(hasName("f"))),
>                      hasArgument(0, declRefExpr(to(varDecl()))),
>                      hasArgument(1, hasType(pointsTo(
>                                         recordDecl(hasName("T"))))),
>                      hasArgument(2, integerLiteral(equals(3))),
>                      hasArgument(3, integerLiteral(equals(4)))))));
>
>
> How would I bind the matcher to one of these parameters?
>


integerLiteral(equals(3)).bind("x"); same for declRefExpr. The only thing
you cannot bind here is "hasType", but I'm surprised this compiles at
all... stmt(hasType(pointsTo(...))).bind("x") should work...

Cheers,
/Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130426/efa5fdca/attachment.html>


More information about the cfe-dev mailing list