代码之家  ›  专栏  ›  技术社区  ›  TheAhmad

clang查询中的函数指针匹配

  •  0
  • TheAhmad  · 技术社区  · 6 年前

    与函数指针匹配的查询是什么,例如在以下代码中:

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

    y 是要匹配的函数指针。

    1 回复  |  直到 6 年前
        1
  •  1
  •   TheAhmad    6 年前

    最后,这是调用函数指针的答案。主要的困难是使用查询检测函数指针的类型。所以我加了 ignoringParens(functionType()) 遍历匹配器来解决这个问题。一个简单的用法 functionType() 不会起作用。

    match callExpr(hasDescendant(memberExpr(hasType(pointerType(pointee(ignoringParens(functionType()))))).bind("member")))
    
    推荐文章