Python 如何用clang获得变量定义的文字位置

Python 如何用clang获得变量定义的文字位置,python,clang,libclang,Python,Clang,Libclang,我有下面的场景 一些头 #define SOME_VARS \ int first_var; \ char other_var; source_file.c #include "some_header.h" SOME_VARS 现在,通过clang,我可以转储AST,并看到它知道这些变量的确切定义: clang -Xclang -ast-dump -fsyntax-only source_file.c TranslationUnitDecl 0x8007f4c0 <<

我有下面的场景

一些头

#define SOME_VARS \
  int first_var; \
  char other_var;
source_file.c

#include "some_header.h"

SOME_VARS
现在,通过clang,我可以转储AST,并看到它知道这些变量的确切定义:

clang -Xclang -ast-dump -fsyntax-only source_file.c

TranslationUnitDecl 0x8007f4c0 <<invalid sloc>>
|-TypedefDecl 0x8007f790 <<invalid sloc>> __builtin_va_list 'char *'
|-VarDecl 0x8007f7d0 <./some_header.h:2:3, col:7> first_var 'int'
                      -------------------------- this is the part i'm looking for
`-VarDecl 0x8007f810 <line:3:3, col:8> other_var 'char'
                     ----------------- and this
我正试图使用libclang和python获取这些信息,但到目前为止我还没有成功


我需要在哪里查找此信息?此信息是否在C接口中可用,但可能尚未移植到Python?

您是要查找带有某些变量的.h文件的位置,还是要查找最终定义它的.C文件的位置?@rmmh试图查找程序员编写第一个变量和其他变量的位置。@rmmh是,如零件发布的输出所示。