[cfe-dev] from source code to a specific AST cursor with libclang.

Juan Jose Lopez Villarejo jj.lopezvillarejo at cern.ch
Mon Oct 7 01:31:16 PDT 2013


Hello,

I'd like to get the AST cursor of a function/method call from a line of code, with libclang (or better, with the python bindings).

These are two sample lines of C++ code:

helSum[0] = antUsrPtr->antennaFunction(y12ant,y23ant,mu1ant,mu2ant,mu3ant, //$
        9,9,9,9,9);

The first line has a special-format comment '//$' that indicates to me that in that code line there is a relevant call:  antennaFunction( , , , , , , , , ...). I want to pick it up usign libclang (the AST node / cursor of that precise call). This is the general problem. More precisions follow.

======
I have the information on the extent of the source code where my call is being done:
(line, start_column) --> (line, end_column)
In the example, start_column corresponds to the starting 'h' and end_column corresponds to the ending ','

I know that I can get a Cursor from a given location in libclang with
clang_getCursor(tu, location)
I am actually using the python bindings (so there is an extra point if you can reply in the pythonic language :-)

Is that cursor a good starting point? What algorithm would you use next to identify the call? parent nodes? childs? siblings?

======

Thank you for reading. I would appreciate any ideas.
Best regards,

Juan J. Lopez-Villarejo
Postdoc, Paris, CEA-Saclay

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131007/dd145acc/attachment.html>


More information about the cfe-dev mailing list