Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit d84ea13

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Make Evaluate=false have an effect
1 parent e116454 commit d84ea13

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Compiler/BackEnd/BackendVariable.mo

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,24 @@ algorithm
13891389
end match;
13901390
end hasVarEvaluateAnnotation;
13911391

1392+
public function hasVarEvaluateAnnotationFalse
1393+
"Returns true if var has Evaluate=false annotation
1394+
author: ptaeuber"
1395+
input BackendDAE.Var inVar;
1396+
output Boolean isFalse;
1397+
protected
1398+
SCode.Annotation ann;
1399+
Absyn.Exp val;
1400+
algorithm
1401+
try
1402+
BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(ann)))) := inVar;
1403+
(val,_) := SCode.getNamedAnnotation(ann, "Evaluate");
1404+
isFalse := stringEqual(Dump.printExpStr(val), "false");
1405+
else
1406+
isFalse := false;
1407+
end try;
1408+
end hasVarEvaluateAnnotationFalse;
1409+
13921410
public function hasAnnotation"checks if the variable has an annotation"
13931411
input BackendDAE.Var inVar;
13941412
output Boolean hasAnnot;

Compiler/BackEnd/EvaluateParameter.mo

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,13 @@ algorithm
847847
else e;
848848
end match;
849849
v = BackendVariable.setBindExp(v, SOME(e));
850-
(repl, replEvaluate) = addConstExpReplacement(e, cr, repl, replEvaluate);
851-
v = if Expression.isConst(e) then BackendVariable.setVarFinal(v, true) else v;
850+
851+
// Add evaluated expression if constant to the replacements
852+
// unless the user suggests not to evaluate the variable with annotation(Evaluate=false)
853+
if not BackendVariable.hasVarEvaluateAnnotationFalse(v) then
854+
(repl, replEvaluate) = addConstExpReplacement(e, cr, repl, replEvaluate);
855+
v = if Expression.isConst(e) then BackendVariable.setVarFinal(v, true) else v;
856+
end if;
852857
end if;
853858
end if;
854859
// apply replacements in variable attributes

0 commit comments

Comments
 (0)