SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ExpressionConverter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/variant.hpp>
4 
5 #include "../../Common.h"
6 
7 #include "ExpressionTypes.h"
8 
9 namespace smtrat {
10 namespace expression {
11 
12  struct ExpressionConverter: boost::static_visitor<FormulaT> {
13  protected:
15  FormulaT convert(const Expression& expr) {
16  return boost::apply_visitor(*this, expr.getContent().content);
17  }
18  public:
19 
20  FormulaT operator()(carl::Variable::Arg var) {
21  return FormulaT(var);
22  }
24  //FormulaT _if = convert(expr.condition);
25  //mGlobalFormulas.
26  return FormulaT();
27  }
29  return FormulaT();
30  }
32  FormulaT arg = convert(expr.expression);
33  switch (expr.type) {
34  case NOT:
35  return FormulaT(carl::FormulaType::NOT, std::move(arg));
36  }
37  }
39  FormulaT lhs = convert(expr.lhs);
40  FormulaT rhs = convert(expr.rhs);
41  switch (expr.type) {
42  }
43  }
45  FormulasT args;
46  for (const auto& e: expr.expressions) {
47  args.push_back(convert(e));
48  }
49  switch (expr.type) {
50  case NaryType::AND:
51  return FormulaT(carl::FormulaType::AND, std::move(args));
52  case NaryType::OR:
53  return FormulaT(carl::FormulaType::OR, std::move(args));
54  case NaryType::XOR:
55  return FormulaT(carl::FormulaType::XOR, std::move(args));
56  case NaryType::IFF:
57  return FormulaT(carl::FormulaType::IFF, std::move(args));
58  }
59  }
60 
62  FormulaT res = convert(expr);
63  if (mGlobalFormulas.empty()) return res;
64  mGlobalFormulas.push_back(res);
66  // Safe as argued in http://stackoverflow.com/a/9168917
67  mGlobalFormulas.clear();
68  return res;
69  }
70  };
71 
72 }
73 }
const ExpressionContent & getContent() const
Definition: Expression.h:37
int var(Lit p)
Definition: SolverTypes.h:64
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Formulas< Poly > FormulasT
Definition: types.h:39
FormulaT operator()(const Expression &expr)
FormulaT operator()(const ITEExpression &expr)
FormulaT operator()(const BinaryExpression &expr)
FormulaT operator()(const UnaryExpression &expr)
FormulaT operator()(carl::Variable::Arg var)
FormulaT convert(const Expression &expr)
FormulaT operator()(const NaryExpression &expr)
FormulaT operator()(const QuantifierExpression &expr)