[klee-dev] ExprVisitor::visitExpr[Post] and ExprReplaceVisitor[2]

Nguyễn Gia Phong cnx at loang.net
Wed Aug 16 05:54:22 BST 2023


Hi,

In lib/Expr/Constraints.cpp I notice

class ExprReplaceVisitor : public ExprVisitor {
public:
  Action visitExpr(const Expr &e) override {
    if (e == *src) {
      return Action::changeTo(dst);
    }
    return Action::doChildren();
  }

  Action visitExprPost(const Expr &e) override {
    if (e == *src) {
      return Action::changeTo(dst);
    }
    return Action::doChildren();
  }
};

while ExprReplaceVisitor2 : ExprVisitor only overrides visitExprPost.
Why does ExprReplaceVisitor have the duplicated code there?
Following ExprVisitor::visitActual,

switch (visitExpr(e)) {
  case Action::ChangeTo:
    return [replacement expr];
  case Action::DoChildren:
    if (!isa<ConstantExpr>(e))
      if (visitExprPost(*e.get()) == Action::ChangeTo)
        return [replacement expr post];
    return e;
}

it seems to me overriding visitExprPost is unnecessary
for replacing an expression.  Is my analisys correct
and if not, what did I miss?

Kind regards,
Phong



More information about the klee-dev mailing list