Skip to content

Commit

Permalink
Fix PWL map visitor constant assignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinffernandez committed Apr 20, 2023
1 parent 3927fd4 commit 7299075
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/mmoc/util/visitors/pwl_map_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ AST_Expression PWLMapValues::foldTraverseElement(AST_Expression exp)
break;
}
case EXPINTEGER:
_constant = exp->getAsInteger()->val();
_slope = 0;
if (!_in_bin_op) {
_constant = exp->getAsInteger()->val();
_slope = 0;
}
break;
default:
return exp;
Expand All @@ -57,7 +59,7 @@ AST_Expression PWLMapValues::foldTraverseElement(AST_Expression exp)
}

AST_Expression PWLMapValues::foldTraverseElement(AST_Expression left, AST_Expression right, BinOpType type)
{
{
EvalInitExp eval_exp;
static const bool EVAL_INT = true;
IsConstantExpression constant_exp(EVAL_INT);
Expand Down Expand Up @@ -101,21 +103,21 @@ void PWLMapValues::assign(AST_Expression left, AST_Expression right, bool cte_le
{
EvalInitExp eval_exp;
if (cte_left && cte_right) {
_constant = sign * (eval_exp.apply(left) + eval_exp.apply(right));
_constant = eval_exp.apply(left) + sign * eval_exp.apply(right);
} else if (cte_right) {
_constant = sign * eval_exp.apply(right);
} else {
_constant = sign * eval_exp.apply(left);
}
}

int PWLMapValues::constant() const { return _constant; }
int PWLMapValues::constant() const { return _constant; }

int PWLMapValues::slope() const { return _slope; }
int PWLMapValues::slope() const { return _slope; }

std::string PWLMapValues::variable() const { return _variable; }
std::string PWLMapValues::variable() const { return _variable; }

bool PWLMapValues::isScalar() const { return _slope == 0;}
bool PWLMapValues::isScalar() const { return _slope == 0; }

} // namespace Util
} // namespace MicroModelica

0 comments on commit 7299075

Please sign in to comment.