Skip to content

Commit

Permalink
Make Evaluate=false have an effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Jun 8, 2017
1 parent e116454 commit d84ea13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1389,6 +1389,24 @@ algorithm
end match;
end hasVarEvaluateAnnotation;

public function hasVarEvaluateAnnotationFalse
"Returns true if var has Evaluate=false annotation
author: ptaeuber"
input BackendDAE.Var inVar;
output Boolean isFalse;
protected
SCode.Annotation ann;
Absyn.Exp val;
algorithm
try
BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(ann)))) := inVar;
(val,_) := SCode.getNamedAnnotation(ann, "Evaluate");
isFalse := stringEqual(Dump.printExpStr(val), "false");
else
isFalse := false;
end try;
end hasVarEvaluateAnnotationFalse;

public function hasAnnotation"checks if the variable has an annotation"
input BackendDAE.Var inVar;
output Boolean hasAnnot;
Expand Down
9 changes: 7 additions & 2 deletions Compiler/BackEnd/EvaluateParameter.mo
Expand Up @@ -847,8 +847,13 @@ algorithm
else e;
end match;
v = BackendVariable.setBindExp(v, SOME(e));
(repl, replEvaluate) = addConstExpReplacement(e, cr, repl, replEvaluate);
v = if Expression.isConst(e) then BackendVariable.setVarFinal(v, true) else v;

// Add evaluated expression if constant to the replacements
// unless the user suggests not to evaluate the variable with annotation(Evaluate=false)
if not BackendVariable.hasVarEvaluateAnnotationFalse(v) then
(repl, replEvaluate) = addConstExpReplacement(e, cr, repl, replEvaluate);
v = if Expression.isConst(e) then BackendVariable.setVarFinal(v, true) else v;
end if;
end if;
end if;
// apply replacements in variable attributes
Expand Down

0 comments on commit d84ea13

Please sign in to comment.