Skip to content

Commit

Permalink
[NF] Fix function variability.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Sep 7, 2020
1 parent 3256d68 commit f694016
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 2 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -315,11 +315,8 @@ public
typed_args := matchedFunc.args;

args := {};
// if is impure, make it a parameter expression
// see https://trac.openmodelica.org/OpenModelica/ticket/5133
var := if Function.isImpure(func) or Function.isOMImpure(func)
then Variability.PARAMETER
else Variability.CONSTANT;
var := Variability.CONSTANT;

for a in typed_args loop
(arg_exp, _, arg_var) := a;
args := arg_exp :: args;
Expand Down
16 changes: 16 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4787,5 +4787,21 @@ public
end if;
end foldReduction2;

function isPure
input Expression exp;
output Boolean isPure;
algorithm
isPure := match exp
case Expression.CREF() then not ComponentRef.isIterator(exp.cref);
case Expression.CALL()
then match AbsynUtil.pathFirstIdent(Call.functionName(exp.call))
case "Connections" then false;
case "cardinality" then false;
else not Call.isImpure(exp.call);
end match;
else true;
end match;
end isPure;

annotation(__OpenModelica_Interface="frontend");
end NFExpression;
4 changes: 3 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -1141,7 +1141,9 @@ algorithm

// Evaluate structural conditions.
if var <= Variability.STRUCTURAL_PARAMETER then
cond := Ceval.evalExp(cond, target);
if Expression.isPure(cond) then
cond := Ceval.evalExp(cond, target);
end if;

// Conditions in an if-equation that contains connects must be possible to evaluate.
if not Expression.isBoolean(cond) and has_connect then
Expand Down

0 comments on commit f694016

Please sign in to comment.