0

I have following scenario.

some_header.h

#define SOME_VARS \
  int first_var; \
  char other_var;

source_file.c

#include "some_header.h"

SOME_VARS

Now with clang I can dump the AST and see that it knows where those variables are literally defined:

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

I'm trying to get this information using libclang and python but so far I have been unsuccessful.

Where do I need to look for this information? Is this inforamiton available in the C interface but maybe not yet ported to Python?

RedX
  • 14,749
  • 1
  • 53
  • 76
  • are you trying to find the location of the .h file with SOME_VARS, or the .c file where it ends up being defined? – rmmh May 15 '15 at 10:33
  • @rmmh Trying to find the location where `first_var` and `other_var` have been written by the programmer. – RedX May 16 '15 at 16:56
  • @rmmh Yes, as seen on the output posted by the `<./some_header.h:2:3, col:7>` part. – RedX May 19 '15 at 18:30

0 Answers0