0

I have detected all the places where there are assignment statements by visiting Binary Operators that are "="

From there I got the LHS and RHS by doing binaryOperator->getLHS() and getRHS() respectively

How should I go about iterating through all the nodes within the RHS.

Currently I have tried to use Stmt::child_iterator recursively to visit all the child nodes but it seems to only be going 1 level down.

bool recursiveVisit (Stmt *stmt) {
  for (Stmt::child_iterator i = stmt->child_begin(), e = stmt->child_end(); i != e; ++i) {
    Stmt *currStmt = *i;
    errs() << "Hello";
    recursiveVisit(currStmt);
  }
}

Am I doing something wrong in the code? Some of my trees only have "Hello" printed once, it's not going any further down. Others don't even print "Hello" once at all.

Jeremy Kuah
  • 519
  • 1
  • 6
  • 18
  • child_iterator only goes one level down, or recursiveVisit only goes one level down? – user253751 Jun 24 '16 at 02:50
  • I found the recurse code works but whenever it hits OpaqueValueExpr, it doesn't break down further and recurse into it's children. Is there anything special or unique about OpaqueValueExpr? @immibis – Jeremy Kuah Jun 24 '16 at 05:21
  • I know this is old, but [here](https://stackoverflow.com/questions/37586677/how-to-get-the-children-of-opaquevalueexpr-in-clang-ast) is a related question and answer to your concern about `OpaqueValueExpr` – Brent Pappas May 05 '23 at 13:47

0 Answers0