[cfe-dev] Python bindings questions

Manuel Holtgrewe manuel.holtgrewe at fu-berlin.de
Tue Dec 27 05:03:12 PST 2011


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

The main "problem" is that tokens are not managed as single objects but 
as arrays. Additionally, the tokens can be annotated back to their AST 
cursors but this information lives in an additional array.

My take on a pythonic wrapper was to write a TokenCollection class and 
some more icing. This new API part works pretty well for me.

I have not yet asked for people's opinion on this list since I wanted to 
find out how this works out for my projects. If anyone is interested in 
doing a review, they are welcome to it.

HTH,
Manuel

On 12/27/2011 01:45 PM, Joxean Koret wrote:
 > Hi all,
 >
 > I'm writing a simple tool that generates one XML file based on the AST
 > given by the clang Python bindings. The problem is that I don't know how
 > to get the operator used, the constant values, etc... I mean, given this
 > simple C code:
 >
 > void foo(void)
 > {
 >    int i = 29;
 > }
 >
 > I first get a VAR_DECL cursor object with displayname "i" and, then, I
 > get an INTEGER_LITERAL cursor object but I don't know how to get the
 > value "29". The same goes for BINARY_OPERATOR, etc...
 >
 > So, my question is: how do I get this information with the python
 > bindings? Sorry if it's a dumb question!
 >
 > Thanks in advance!
 > Joxean Koret
 >



More information about the cfe-dev mailing list