18 std::shared_ptr<BaseExpression const> conditionExpression =
19 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getCondition()->accept(*
this, data));
20 std::shared_ptr<BaseExpression const> thenExpression =
21 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getThenExpression()->accept(*
this, data));
22 std::shared_ptr<BaseExpression const> elseExpression =
23 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getElseExpression()->accept(*
this, data));
30 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
35template<
typename BinaryFunc>
36std::vector<std::shared_ptr<BaseExpression const>>
getAllOperands(BinaryFunc
const& binaryExpression) {
37 auto opType = binaryExpression.getOperatorType();
38 std::vector<std::shared_ptr<BaseExpression const>> stack = {binaryExpression.getSharedPointer()};
39 std::vector<std::shared_ptr<BaseExpression const>> res;
40 while (!stack.empty()) {
41 auto f = std::move(stack.back());
44 for (uint64_t opIndex = 0; opIndex < 2; ++opIndex) {
45 BinaryFunc
const* subexp =
dynamic_cast<BinaryFunc const*
>(f->getOperand(opIndex).get());
46 if (subexp !=
nullptr && subexp->getOperatorType() == opType) {
47 stack.push_back(f->getOperand(opIndex));
49 res.push_back(f->getOperand(opIndex));
61 std::vector<std::shared_ptr<BaseExpression const>> operands = getAllOperands<BinaryBooleanFunctionExpression>(expression);
64 if (operands.size() >= 4) {
65 for (
auto& operand : operands) {
66 operand = boost::any_cast<std::shared_ptr<BaseExpression const>>(operand->accept(*
this, data));
69 auto opIt = operands.begin();
70 while (operands.size() > 1) {
71 if (opIt == operands.end() || opIt == operands.end() - 1) {
72 opIt = operands.begin();
74 *opIt = std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
79 return operands.front();
83 std::shared_ptr<BaseExpression const> firstExpression =
84 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getFirstOperand()->accept(*
this, data));
85 std::shared_ptr<BaseExpression const> secondExpression =
86 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getSecondOperand()->accept(*
this, data));
103 std::vector<std::shared_ptr<BaseExpression const>> operands = getAllOperands<BinaryNumericalFunctionExpression>(expression);
106 if (operands.size() >= 4) {
107 for (
auto& operand : operands) {
108 operand = boost::any_cast<std::shared_ptr<BaseExpression const>>(operand->accept(*
this, data));
111 auto opIt = operands.begin();
112 while (operands.size() > 1) {
113 if (opIt == operands.end() || opIt == operands.end() - 1) {
114 opIt = operands.begin();
121 return operands.front();
125 std::shared_ptr<BaseExpression const> firstExpression =
126 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getFirstOperand()->accept(*
this, data));
127 std::shared_ptr<BaseExpression const> secondExpression =
128 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getSecondOperand()->accept(*
this, data));
140 std::shared_ptr<BaseExpression const> firstExpression =
141 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getFirstOperand()->accept(*
this, data));
142 std::shared_ptr<BaseExpression const> secondExpression =
143 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getSecondOperand()->accept(*
this, data));
149 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
159 std::shared_ptr<BaseExpression const> operandExpression =
160 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getOperand()->accept(*
this, data));
163 if (operandExpression.get() == expression.
getOperand().get()) {
166 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
172 std::shared_ptr<BaseExpression const> operandExpression =
173 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.
getOperand()->accept(*
this, data));
176 if (operandExpression.get() == expression.
getOperand().get()) {
179 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const =0
Accepts the given visitor by calling its visit method.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Type const & getType() const
Retrieves the type of the expression.
std::shared_ptr< BaseExpression const > getSharedPointer() const
Retrieves a shared pointer to this expression.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
std::shared_ptr< BaseExpression const > const & getSecondOperand() const
Retrieves the second operand of the expression.
std::shared_ptr< BaseExpression const > const & getFirstOperand() const
Retrieves the first operand of the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
RelationType getRelationType() const
Retrieves the relation associated with the expression.
BaseExpression const & getBaseExpression() const
Retrieves the base expression underlying this expression object.
std::shared_ptr< BaseExpression const > getElseExpression() const
Retrieves the else expression of the if-then-else expression.
std::shared_ptr< BaseExpression const > getCondition() const
Retrieves the condition expression of the if-then-else expression.
std::shared_ptr< BaseExpression const > getThenExpression() const
Retrieves the then expression of the if-then-else expression.
Expression reduceNesting(Expression const &expression)
Reduces the nesting in the given expression.
ReduceNestingVisitor()
Creates a new reduce nesting visitor.
virtual boost::any visit(IfThenElseExpression const &expression, boost::any const &data) override
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const override
Retrieves the given operand from the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
std::vector< std::shared_ptr< BaseExpression const > > getAllOperands(BinaryFunc const &binaryExpression)