简体   繁体   中英

Matching Function Pointers in Clang-Query

What is the query to match a function pointer, eg, in the following code:

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

y is the function pointer to match.

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")))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM