Skip to content

Commit

Permalink
[NF] Hack to fix some array conditions.
Browse files Browse the repository at this point in the history
- Handle component and if expression conditions that evaluate to
  arrays (due to array modifiers) by checking if all scalar elements
  are the same value, and in that case use that value.

Belonging to [master]:
  - OpenModelica/OMCompiler#2962
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 4, 2019
1 parent ae2ddcb commit f211539
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -317,6 +317,11 @@ algorithm
exp := Binding.getTypedExp(cond);
exp := Ceval.evalExp(exp, Ceval.EvalTarget.CONDITION(Binding.getInfo(cond)));

// Hack to make arrays work when all elements have the same value.
if Expression.arrayAllEqual(exp) then
exp := Expression.arrayFirstScalar(exp);
end if;

isDeleted := match exp
case Expression.BOOLEAN() then not exp.value;
else
Expand Down
4 changes: 4 additions & 0 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -2022,6 +2022,10 @@ protected
algorithm
cond_exp := Ceval.evalExp(condExp, Ceval.EvalTarget.GENERIC(info));

if Expression.arrayAllEqual(cond_exp) then
cond_exp := Expression.arrayFirstScalar(cond_exp);
end if;

condBool := match cond_exp
case Expression.BOOLEAN() then cond_exp.value;
else
Expand Down

0 comments on commit f211539

Please sign in to comment.