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:
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
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
Thanks Richard for the explanation!
| | | |-IfStmt 0x78b6d90
| | | | |-<<>>
| | | | |-<<>>
| | | | |-BinaryOperator 0x78b5f08 'int' '=='
| | | | | |-ImplicitCastExpr 0x78b5eb0 'int'
| | | | | | `-ImplicitCastExpr 0x78b5e58
'example_tree':'enum example_tree_
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
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
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