[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 05:29:30 PDT 2017
Woops. Clearly didn't look closely enough at the AST.
CursorKind.MEMBER_REF_EXPR is what I'm looking for.
On Sun, Sep 3, 2017 at 5:42 PM, Vanush Vaswani <vanush at gmail.com> wrote:
> 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/9aba12de/attachment.html>
More information about the cfe-dev
mailing list