CLang Python Bindings getCond(), getElse(), etc...

Hi guys!

I'm using the CLang Python Bindings for getting 'artifacts' from C/C++
source codes. One of the easiest things I have to do is to just get the
number of conditions, however, considering that getCond() is not
exposed in the Python bindings, I don't know how to do that.

For example, consider the following example C code:

if ( a == 1 && b == 2 )

I need to get '2', as there are 2 conditions. My Python code basically
traverses all elements in a translation unit similarly to the following

def recurse_cursor(cur):
for children in cur.get_children():
children.kind == CursorKind.IF_STMT


idx = clang.cindex.Index.create()
tu = idx.parse('my_source.c')


Then, in the function I named here 'do_stuff' I check if the element is
a CursorKind.IF_STMT and then I should do 'something' to count the
number of conditions in that IF_STMT. However, as getCond() is not
published, I don't know how to do that. I can try to get the tokens by
calling get_tokens() and iterating them to check if some comparison
operator is used (==, !=, etc...), but it will not work for expressions
like the following:

if ( some_bool )

So, how can I get the number of conditional expressions? Or,
alternatively, is there any way I can call IF_STMT.getCond() in Python
or other non exposed functions?

Thanks & regards,
Joxean Koret

I think you will have to expose the function(s) you need through libclang and then clang.cindex.

Functions are generally exposed as and when they are needed.

You can look at to see how this is done.

let me know if you need any further input.