Re: [cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-08-07 Thread Richard Trieu via cfe-users
The declarations are "ptr" and "bar". "*ptr" and "&bar" are expressions since * and & are C++ operators. If you want the type of "*ptr" or "&bar", then you need to get the associated UnaryOperator (a sub-class of Expr) and call getType() on it. On Wed, Aug 7, 2019 at 2:28 PM Ayush Mittal wrote:

Re: [cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-08-07 Thread Ayush Mittal via cfe-users
Sure, Not a problem. What's the way to get the declarations such as *ptr and &bar as it is inside the *DeclRefExpr *block*. * *Example: * void foo(){ int bar=1; int **ptr; **ptr = &bar;* // this line } *If I query like this way:* if (const ValueDecl *VD = dyn_cast(DRE->getDecl())){ O

Re: [cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-08-06 Thread Richard Trieu via cfe-users
RecursiveASTVisitor should have an ASTContext available. ASTContext has a getParents function, which may be of some use. Unfortunately, I haven't used this part of the ASTContext before, so I can't give any more concrete advice. As you've seen, it's easier to traverse down the AST than up it. O

Re: [cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-08-06 Thread Ayush Mittal via cfe-users
Thanks Richard for the explanation! | | | |-IfStmt 0x78b6d90 | | | | |-<<>> | | | | |-<<>> | | | | |-BinaryOperator 0x78b5f08 'int' '==' | | | | | |-ImplicitCastExpr 0x78b5eb0 'int' | | | | | | `-ImplicitCastExpr 0x78b5e58 'example_tree':'enum example_tree_

Re: [cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-08-01 Thread Richard Trieu via cfe-users
Adding back the mailing list. Please reply all to keep the discussion on the mailing list. On Thu, Aug 1, 2019 at 2:47 PM Ayush Mittal wrote: > Thanks Richard for the explanation. Really appreciate it. > One quick question, Within VisitStmt (BinaryOperator) how could I get an > access to DeclRe

Re: [cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-07-30 Thread Richard Trieu via cfe-users
Hi Ayush, First, you need to know the classes associated with each of your target AST nodes. These are IfStmt, WhileStmt, ForStmt, BinaryOperator, and UnaryOperator. Each of these are sub-classes of Stmt. IfStmt, WhileStmt, ForStmt and direct sub-classes while BinaryOperator and UnaryOperator a

[cfe-users] AST Recursive Visitor- Statements (Stmt *)

2019-07-30 Thread Ayush Mittal via cfe-users
Hello Clangers, I'm new to clang. I'm writing an AST Consumer plug-in to visit the statements node and record the data in one of my table with line numbers. I've this function callback ready: *VisitStmt(Stmt *S)*. My question is how could I traverse If, while, for loop, boolean and Unary Operators