<div dir="ltr"><div dir="ltr">Hi Stephen,<div><br></div><div>thanks for the input.</div><div><br></div><div>Fortunately it's just C I'm interested in.</div><div><br></div><div>It's not just the order of certain function calls that are relevant; the ordering of some conditional expressions and return stmts are also relevant. And some of them are done via macros in which case, if I recall, I see the source location being the location of the macro definition - not the location of the macro usage.</div><div><br></div><div>It still sounds to me like MatchFinder is not doing exactly what it says on the tin "The order of matches is guaranteed to be equivalent to doing a pre-order traversal on the AST, and applying the matchers in the order in which they were added to the MatchFinder." </div><div><br></div><div>I've experimented with RecursiveASTVisitor and that does invoke the Visit<Node> functions in a natural/source-code order. So I will stick with that strategy for now.<br></div><div><br></div><div>Cheers,</div><div>Billy.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 17 Jun 2020 at 23:21, Stephen Kelly <<a href="mailto:steveire@gmail.com">steveire@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 15/06/2020 14:28, Billy O'Mahony via cfe-dev wrote:<br>
> I was expecting the matches to be in line-number order. In fact I'm <br>
> really depending on that for the custom tool I want to build as it <br>
> needs to analyze the order in which certain fns are called.<br>
<br>
<br>
I'm not sure line numbers are the thing to rely on if that is your goal. <br>
Consider for example a lambda inside a function (though maybe you are <br>
only working on C, not C++?). Your matcher for callExpr() would need to <br>
distinguish between calls inside and outside the lambda.<br>
<br>
Regardless of whether C++ is relevant to you, as David pointed out, this <br>
appears to be an optimization, so an alternative implementation might <br>
make sense anyway.<br>
<br>
I would recommend you match functions as you are with functionDecl() and <br>
then in your match callback, use something like (not tested)<br>
<br>
ast_matchers::match(functionDecl(<br>
<br>
forEachDescendant(callExpr(forFunction(functionDecl(equalsNode(FN)))))<br>
<br>
), *FN, *Result.Context);<br>
<br>
<br>
The forFunction() matcher is the important part which will ensure that <br>
for example callExpr() in nested lambdas are not part of your result set.<br>
<br>
Then order the resulting nodes by their getBeginLoc() perhaps. (Macros <br>
may need to be accounted for).<br>
<br>
Thanks,<br>
<br>
Stephen.<br>
<br>
</blockquote></div></div>