如何在clangpython绑定中公开ImplicitCastExpr节点?

2024-10-02 22:35:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有C代码:

int func4b(float *x, int (*fp)(int *hello, float *goodbye));

int hello(int *x, float *y) {
  return 0;
}

void callerb() {
  float x=6.0;
  func4b(&x, &hello);   // This is line 28
}

clang-12  -cc1 -ast-dump t2_calls.c 
provides:
   ...
   ...
   `-CallExpr 0x55ee03be4d68 <line:28:3, col:20> 'int'
      |-ImplicitCastExpr 0x55ee03be4d50 <col:3> 'int (*)(float *, int (*)(int *, float *))' <FunctionToPointerDecay>

使用clang的python绑定,我得到了第28行的函数调用:

CursorKind.CALL_EXPR func4b line=28 col=3
CursorKind.UNEXPOSED_EXPR func4b line=28 col=3

在我的python代码中,我很想了解这两个方面

  1. 这是节点类型“ImplicitCastExpr”,并且
  2. 该函数调用的参数签名是“int(*)(float,int()(int*,float*)”

这是不是可以通过几个小时的工作来实现的?我一直在读:

https://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang但那已经是9年前的事了,我希望python绑定现在更加完整


Tags: 代码helloreturnlinecolfloatintclang