[cfe-dev] AST matcher: ForEach FunctionDecl -> ParmVarDecl

FarSight Studios via cfe-dev cfe-dev at lists.llvm.org
Sun Dec 30 06:00:26 PST 2018


Dear all,

Is there any AST matcher that can produce an iteration operation like:
FOR-EACH parameter of function?
I am trying to match call expressions where the caller arguments are the
parameters of another, outer function.
For this solution I am using equalsBoundNode() as a narrowing matcher.

My problem is that I am unable to find a way to match all the function
parameters. The matcher only matches the first parameter.

Here is the full matcher:

auto calleeArgVarDecl = declRefExpr(to(varDecl().bind("callerArg")))

auto innerCallExpr = callExpr(
forEachArgumentWithParam(
anyOf(
unaryOperator(hasDescendant(calleeArgVarDecl)),
calleeArgVarDecl
),
parmVarDecl().bind("calleeParam")
),
callee(functionDecl().bind("calleeFunc")),
unless(isExpansionInSystemHeader())).bind("callExpr")

auto fullMatcher =  functionDecl(
forEachDescendant(innerCallExpr),
hasAnyParameter(
parmVarDecl(equalsBoundNode("callerArg")).bind("outerFuncParam")
)
).bind("outerFunc")


I tryed to use the folowing matchers but none of them solved my problem:
hasAnyParameter(...) - It only binds the first parameter that is matched.
hasParameter(n,...) - I can use this one only if the function has a known
number of parameters. This solution is not so good because the number of
parameters is unknown.
forEachArgumentWithParam - only works for caller expressions, and I am
matching parameters of a functionDecl.

Any help would be greatly appreciated
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181230/150c5523/attachment.html>


More information about the cfe-dev mailing list