Commit 415ad6d0 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add expr_clone

parent bcb3023e
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -114,6 +114,26 @@ const std::string& expr_get_value(const Expr* expr) {
  return expr->value;
}

ExprStorage expr_clone(const Expr* e) {
  ExprStorage copy;
  ExprStorage* c = ©

  while (e) {
    *c = ExprStorage(new Expr, bind(&expr_destroy, _1));
    (*c)->type = e->type;
    (*c)->value = e->value;

    if (e->list) {
      (*c)->list = expr_clone(e->list.get());
    }

    c = expr_get_next_storage(&**c);
    e = e->next.get();
  }

  return copy;
}

std::string expr_inspect(const Expr* expr) {
  std::stringstream s;

+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ bool expr_is_value_quoted(const Expr* expr);
bool expr_is_value_quoted(const Expr* expr, const std::string& cmp);
const std::string& expr_get_value(const Expr* expr);

ExprStorage expr_clone(const Expr* e);

std::string expr_inspect(const Expr* expr);

} // namespace fviz