[cfe-dev] Python bindings questions

Joxean Koret joxeankoret at yahoo.es
Wed Dec 28 11:53:24 PST 2011


Hi,

Thanks Manuel, however, your approach doesn't work always. For example,
for a CursorKind.CSTYLE_CAST_EXPR object it will return the complete
casting line (i.e., "(const unsigned char *)var"), for
CursorKind.COMPOUND_STMT objects it will return the complete compound
statement (which may happily be the complete function you're analysing),
etc... You need to code very ugly hacks in order to get the real data
you want which, IMHO, should be exposed in an easier way.

Apart from that, there is also some information still not available (not
related to your code but to the main code). For example, the following C
code:

void foo(int i)
{
  if ( i == 0 || i == 1 )
    stuff();
}

and this one:

void foo(int i)
{
  if ( i == 0 && i == 1 )
    stuff();
}

...will return the same AST as the "&&" or "||" operator doesn't appear.
But, curiously, in this case:

void foo(int i)
{
  if ( i && i == 1 )
    stuff();
}

...it returns correctly the && operator. It seems to be a bug. Just in
case any of you want to take a look, attached goes the script I wrote
and a simple C test file (BTW, using the code Manuel Holtgrewe provided
in his previous e-mail, available here [1]).

[1] https://github.com/holtgrewe/linty/blob/master/clang/cindex.py

Thanks & Regards,
Joxean Koret

El mar, 27-12-2011 a las 14:03 +0100, Manuel Holtgrewe escribió:
> 
> There are two solutions I can up with: (1) Extract the string of the 
> extent of the INTEGER_LITERAL, (2) Annotate the tokens.
> 
> (2) requires wrapping of the libclang tokenization API that is not 
> available in the clang SVN's python wrapper yet (I think). I have an 
> experimental version of this living at
> 
> https://github.com/holtgrewe/linty/blob/master/clang/cindex.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang2xml.py
Type: text/x-python
Size: 4110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111228/21aa077e/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111228/21aa077e/attachment.sig>


More information about the cfe-dev mailing list