<div dir="ltr">I think you will have to expose the function(s) you need through libclang and then clang.cindex.<div><br></div><div>Functions are generally exposed as and when they are needed.</div><div><br></div><div>You can look at <a href="https://reviews.llvm.org/D34091">https://reviews.llvm.org/D34091</a> to see how this is done.</div><div><br></div><div>let me know if you need any further input.</div><div><br></div><div>regards,</div><div><br></div><div>Jon</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 3 May 2018 at 09:50, Joxean Koret via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi guys!<br>
<br>
I'm using the CLang Python Bindings for getting 'artifacts' from C/C++<br>
source codes. One of the easiest things I have to do is to just get the<br>
number of conditions, however, considering that getCond() is not<br>
exposed in the Python bindings, I don't know how to do that.<br>
<br>
For example, consider the following example C code:<br>
<br>
if ( a == 1 && b == 2 )<br>
  ...<br>
<br>
I need to get '2', as there are 2 conditions. My Python code basically<br>
traverses all elements in a translation unit similarly to the following<br>
code:<br>
<br>
(...)<br>
def recurse_cursor(cur):<br>
  for children in cur.get_children():<br>
    if<br>
children.kind == CursorKind.IF_STMT<br>
    do_stuff(children)<br>
   <br>
recurse_cursor(children)<br>
<br>
idx = clang.cindex.Index.create()<br>
tu = idx.parse('my_source.c')<br>
<br>
recurse_cursor(tu)<br>
(...)<br>
<br>
Then, in the function I named here 'do_stuff' I check if the element is<br>
a CursorKind.IF_STMT and then I should do 'something' to count the<br>
number of conditions in that IF_STMT. However, as getCond() is not<br>
published, I don't know how to do that. I can try to get the tokens by<br>
calling get_tokens() and iterating them to check if some comparison<br>
operator is used (==, !=, etc...), but it will not work for expressions<br>
like the following:<br>
<br>
if ( some_bool )<br>
  do_something()<br>
<br>
So, how can I get the number of conditional expressions? Or,<br>
alternatively, is there any way I can call IF_STMT.getCond() in Python<br>
or other non exposed functions?<br>
<br>
Thanks & regards,<br>
Joxean Koret<br>
<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>