how VisitBin## methods for binary operators are called
I am working on a static analysis tool for C. I am finding it strange -
traversal of AST using VisitBin## calls. For example x = x + y + z; AST
would be like:
Using pre-order DFS traversal, I want to know in what order
VisitBinAdd() are called?
For RHS of assignment operator =, first VisitBinAdd() should be called
for +2 (add). Then again VisitBinAdd() would be called for +1 (add) with
LHS and RHS as x, y. Further it should walk up and see z as RHS of +2
But when printed LHS and RHS inside VisitBinAdd(), I see something
it prints RHS of +2 (add)
it prints LHS and RHS of +1 (add)
Additive Op +
RHS identifier = z
Additive Op +
LHS identifier = x
RHS identifier = y
Why it is so? Why it doesn't print LHS and RHS for +1 and then RHS for
Please do correct me if something is wrong here.
Re: how VisitBin## methods for binary operators are called
Can someone help on how VisitBin## methods are called and how to walk up in Visit methods?
I want to understand in case of pre-order DFS traversal by clang, how to walk up in the tree?
e.g. for expression x + y + z, I am creating an abstract expression whenever I see an arithmetic operator, how to walk up in tree to get (x+y) as lhs and z as rhs operand?
I need this for x = x + y + z; to get abstract expression for x+y+z as rhs of assignment operator.