Commit 91fba579 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add expr_rewritev, add a new expr_build_next overload

parent 12c815dd
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -71,6 +71,15 @@ std::vector<const Expr*> expr_collect(const Expr* expr) {
  return exprs;
}

ReturnCode expr_rewritev(
    const Expr* expr,
    const std::string& prefix,
    std::vector<ExprStorage>* destination) {
  destination->emplace_back(expr_create_value(prefix));
  destination->emplace_back(expr_clone(expr));
  return OK;
}

} // namespace fviz

+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,11 @@ ExprVisitor expr_calln_fn(const std::initializer_list<ExprVisitor>& fns);

std::vector<const Expr*> expr_collect(const Expr* expr);

ReturnCode expr_rewritev(
    const Expr* expr,
    const std::string& prefix,
    std::vector<ExprStorage>* destination);

template <typename... T>
ExprStorage expr_build(T&&... items);

+22 −0
Original line number Diff line number Diff line
@@ -28,6 +28,28 @@ ExprStorage expr_build_next(ExprStorage head, T&&... tail) {
  return e;
}

template <typename... T>
ExprStorage expr_build_next(std::vector<ExprStorage> head, T&&... tail) {
  auto n = expr_build_next(std::forward<T>(tail)...);

  ExprStorage e;
  for (auto iter = head.rbegin(); iter != head.rend(); ++iter) {
    if (e) {
      expr_set_next(iter->get(), std::move(e));
    } else {
      expr_set_next(iter->get(), std::move(n));
    }

    e = std::move(*iter);
  }

  if (e) {
    return e;
  } else {
    return n;
  }
}

template <typename... T>
ExprStorage expr_build_next(std::string head, T&&... tail) {
  auto e = expr_create_value(head);