<div dir="ltr">On Thu, Apr 25, 2013 at 11:57 PM, Peeter Joot <span dir="ltr"><<a href="mailto:peeter.joot@gmail.com" target="_blank">peeter.joot@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">With code like:<div><br></div><div>ast_matchers::MatchFinder Finder;</div><div><div>  CallRenamer gmblkCallCallback(&Tool.getReplacements(), "myfunc", "xxmyfunc");</div>
<div>  Finder.addMatcher(</div>
<div>        callExpr( callee(functionDecl(hasName("myfunc")))).bind("myfunc"),</div><div>    &gmblkCallCallback);</div><div><br></div><div><br></div><div>I'm able to match to a function call, such as:<br>

<br>int myfunc( void ** ppBlkPtr ) ;<br></div><div><div>void blah(void)</div><div>{</div><div>   int * r ;</div><div><br></div><div>   myfunc( (void **)&r ) ;</div><div>}</div><div><br></div><div>(I've also got a working version of the replacement callback that renames such a call).</div>

<div><br>However, the declaration of "myfunc" is actually of the form:<br><br><div>int myfuncEx( void ** ppBlkPtr, int line ) ;</div><div><br></div><div>#define myfunc( x ) myfuncEx( (x), __LINE__ )</div><div>
<br></div></div></div><div>Such a call generates a different sort of AST structure:</div><div><br></div><div><div>    `-CallExpr 0x14963a0 <line:1468:21, col:45> 'int'</div><div>      |-ImplicitCastExpr 0x1496388 <col:21> 'int (*)(void **, int)' <FunctionToPointerDecay></div>

<div>      | `-DeclRefExpr 0x1496338 <col:21> 'int (void **, int)' lvalue Function 0x1495b00 'myfuncEx' 'int (void **, int)'</div><div>      |-ParenExpr 0x14962f8 <col:31, col:33> 'void **'</div>

<div>      | `-CStyleCastExpr 0x14962d0 <line:1478:12, col:22> 'void **' <BitCast></div><div>      |   `-UnaryOperator 0x1496298 <col:21, col:22> 'int **' prefix '&'</div><div>

      |     `-DeclRefExpr 0x1496248 <col:22> 'int *' lvalue Var 0x1496180 'r' 'int *'</div><div>      `-IntegerLiteral 0x1496318 <<scratch space>:2:1> 'int' 1478</div><div>

<br></div>How can I match to such a "macro call" AST?</div><div><br></div><div>My final goal is to have my replacement callback to remove that (void **) cast from all such parameters for this macro, so a better (but harder) question is probably:<br>

<br>How do I match to the (void **) cast operation of parameter N of a macro call named "myfunc"?</div><div><br></div><div>It's not clear to me that the AST even has this info (see how the AST dump has lost the original macro origins, and has info only about the myfuncEx function).</div>
</div></div></blockquote><div><br></div><div style>Note that the AST dump does not contain all the information there is (or it would be completely unreadable).</div><div style><br></div><div style>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.</div>
<div style><br></div><div style>Cheers,</div><div style>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span class="HOEnZb"><font color="#888888">
<div><br></div>-- <br>Peeter
</font></span></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>