[cfe-dev] How to find all references to specific using libclang python bindings?

Vanush Vaswani via cfe-dev cfe-dev at lists.llvm.org
Sun Sep 3 00:42:12 PDT 2017


Hi All

I'm trying to find code matching the below pattern

====
...
if (foo->bar->data_x) {
...
====

I'm trying to find all references to the type of 'bar' appearing within an
if statement, and with each reference, list the struct member being
accessed within type 'bar' (be it data_x, or data_y or data_z). The
dereference "hierarchy" may be variable (i.e to get to the type of 'bar'),
but it should always contain the type of 'bar' before accessing the last
member.

After dumping an example AST and observing the structure of 'IfStmt', it
looks like I need to finger on 'DeclRefExpr'. But when I check the type, it
is always of the 'top' of the hierarchy (i.e the 'spelling' attribute will
report 'foo').

My question is how do I get from here to the rest of the chain of struct
dereferences, and finally to the member declaration of the struct of type
'bar'?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170903/0471c241/attachment.html>


More information about the cfe-dev mailing list