vendredi 25 septembre 2015

Parsing clang AST using clang plugin

I am writing a clang plugin. Using AST matchers, I am able to filter out the part of AST I am interested in (Basically I am looking for a particular function, say foo, which has certain number of arguments. I need to get those arguments to work with them).

Below is one the arguments to foo():

CallExpr 0xa2d33e0 'int'
|-ImplicitCastExpr 0xa2d33c8 'int (*)(class Graph *, int)'<FunctionToPointerDecay>
| `-DeclRefExpr 0xa2d3330 'int (class Graph *, int)' lvalue Function 0xa2d3220 'read_set' 'int (class Graph *, int)' (FunctionTemplate 0xa2ce9f8 'read_set')
|-UnaryOperator 0xa2d2eb8 'class Graph *' prefix '&'
| `-DeclRefExpr 0xa2d2e68 'class Graph' lvalue Var 0xa2cef08 'g' 'class Graph'
`-IntegerLiteral 0xa2d2ed8 'int' 1

Next this is getting 'g' from the DeclRefExpr as shown above. How can I traverse this part of AST to get get the arguments to the read_set?

Also, In general how to traverse the AST from CallExpr to say DeclRefExpr? Is dyn_cast enough to go from CallExpr to DeclRefExpr?

Let me know if more information is required.

Thank you.

Aucun commentaire:

Enregistrer un commentaire