TheAhmad
TheAhmad

Reputation: 940

Matching Function Pointers in Clang-Query

What is the query to match a function pointer, e.g., in the following code:

int foo(struct A *a, int b)
{
    return a->x->y(b);
}

y is the function pointer to match.

Upvotes: 0

Views: 562

Answers (1)

TheAhmad
TheAhmad

Reputation: 940

Finally, this is the answer for a call to a function pointer. The main difficulty was to detect the type of function pointers using the query. So I added the ignoringParens(functionType()) traversal matcher to solve the problem. A simple usage of functionType() will not work.

match callExpr(hasDescendant(memberExpr(hasType(pointerType(pointee(ignoringParens(functionType()))))).bind("member")))

Upvotes: 2

Related Questions