<div dir="ltr"><div dir="ltr">Hi,</div><div dir="ltr">I am really sorry I did not gave a proper explanation of what I am trying to do.</div><div dir="ltr"><div>I want to match the call expressions where at least SOME of its arguments are the parameters or SOME of the parameters of the outer function.</div><div>Not all arguments have to be the parameters of the outer function.</div><div>I don't really need to forward all parameters to arguments.</div><div><br></div><div>The combination of the built-in matches that I used, only matched the first parameter because I was unable to do some sort of loop there.</div><div>As a result, only first parameter of the outer function is matched, others are were not matched.</div></div><div><br></div><div>Is there an option to make an iteration over all outer function parameters and still use the equalsBoundNode("callerArg") narrowing matcher?</div><div>Or the only option is to try implementing a custom matcher?</div><div><br></div><div>Thank you so much for your help.</div><br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 30, 2018 at 4:41 PM Stephen Kelly via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</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">On 30/12/2018 14:00, FarSight Studios via cfe-dev wrote:<br>
> I am trying to match call expressions where the caller arguments are the <br>
> parameters of another, outer function.<br>
<br>
You need to write your own matcher.<br>
<br>
These untested/uncompiled snippets should get you started:<br>
<br>
bool callArgsAreFuncParams(CallExpr const& C, FunctionDecl const& F)<br>
{<br>
// TODO: Handle variadic args<br>
<br>
// TODO: Handle default arguments in call<br>
<br>
if (C.argumentCount() != F.parameterCount())<br>
return false;<br>
<br>
for (auto i = 0; i < C.argumentCount(); ++i)<br>
{<br>
if (C.getArg(i).getDecl() != F.getParameter(i))<br>
return false;<br>
}<br>
return true;<br>
}<br>
<br>
AST_MATCHER(CallExpr, forwardsAllParameters) {<br>
const auto &Parents = Finder->getASTContext().getParents(Node, true);<br>
<br>
llvm::SmallVector<ast_type_traits::DynTypedNode, 8> <br>
Stack(Parents.begin(),<br>
Parents.end());<br>
while(!Stack.empty()) {<br>
const auto &CurNode = Stack.back();<br>
Stack.pop_back();<br>
if(const auto *FuncDeclNode = CurNode.get<FunctionDecl>()) {<br>
if (callArgsAreFuncParams(Node, *FuncDeclNode))<br>
return true;<br>
} else if(const auto *LambdaExprNode = CurNode.get<LambdaExpr>()) {<br>
if (callArgsAreFuncParams(Node, *LambdaExprNode->getCallOperator()))<br>
return true;<br>
} else {<br>
for (const auto &Parent :<br>
Finder->getASTContext().getParents(CurNode, true))<br>
Stack.push_back(Parent);<br>
}<br>
}<br>
return false;<br>
}<br>
<br>
<br>
<br>
auto fullMatcher = callExpr(<br>
forwardsAllParameters(),<br>
forFunction(functionDecl().bind("outerFunction"))<br>
).bind("innerCall")<br>
<br>
<br>
It would also be possible to design the matcher such that it is used <br>
like this:<br>
<br>
forwardsAllParametersFrom(functionDecl().bind("outerFunction"))<br>
<br>
<br>
That's left as an exercise for the reader.<br>
<br>
Thanks,<br>
<br>
Stephen.<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">-------------------------------------<br>FarSight Studios<br><a href="http://design.shadas.net" target="_blank">http://design.shadas.net</a></div></div>