Skip to content

Commit

Permalink
[NF] Fixes for Modelica tables.
Browse files Browse the repository at this point in the history
- Remove empty arrays in function calls from component bindings too.
- Don't evaluate constant arguments to external functions, the runtime
  doesn't handle array literals well in that context.

Belonging to [master]:
  - OpenModelica/OMCompiler#2755
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 31, 2018
1 parent d39b07b commit e073cfc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
39 changes: 28 additions & 11 deletions Compiler/NFFrontEnd/NFEvalConstants.mo
Expand Up @@ -130,36 +130,53 @@ end evaluateExp;
function evaluateExpTraverser
input Expression exp;
input Boolean changed;
input Boolean isExternalArg = false;
output Expression outExp;
output Boolean outChanged;
protected
Expression e;
ComponentRef cref;
Type ty;
algorithm
(e, outChanged) := Expression.mapFoldShallow(exp, evaluateExpTraverser, false);

outExp := match e
outExp := match exp
case Expression.CREF()
algorithm
if ComponentRef.nodeVariability(e.cref) <= Variability.STRUCTURAL_PARAMETER then
(outExp as Expression.CREF(cref = cref, ty = ty), outChanged) := Expression.mapFoldShallow(exp,
function evaluateExpTraverser(isExternalArg = false), false);

// Evaluate constants and structural parameters, except for arrays that
// are used as arguments to an external function.

// TODO: The runtime doesn't handle array literals well when used as
// arguments of external functions, since it sometimes tries to
// write to them (e.g. when trying to pack them). Until that's
// fixed we keep them as they are here.
if ComponentRef.nodeVariability(cref) <= Variability.STRUCTURAL_PARAMETER and
not (isExternalArg and Type.isArray(ty)) then
// Evaluate all constants and structural parameters.
outExp := Ceval.evalCref(e.cref, e, Ceval.EvalTarget.IGNORE_ERRORS(), evalSubscripts = false);
outExp := Ceval.evalCref(cref, outExp, Ceval.EvalTarget.IGNORE_ERRORS(), evalSubscripts = false);
outChanged := true;
elseif outChanged then
// If the cref's subscripts changed, recalculate its type.
outExp := Expression.CREF(ComponentRef.getSubscriptedType(e.cref), e.cref);
else
outExp := e;
outExp := Expression.CREF(ComponentRef.getSubscriptedType(cref), cref);
end if;
then
outExp;

case Expression.CALL()
algorithm
evaluateFunction(Call.typedFunction(e.call));
(outExp, outChanged) := Expression.mapFoldShallow(exp,
function evaluateExpTraverser(isExternalArg = Call.isExternal(exp.call)), false);
evaluateFunction(Call.typedFunction(exp.call));
then
e;
outExp;

else if outChanged then Expression.retype(e) else e;
else
algorithm
(outExp, outChanged) := Expression.mapFoldShallow(exp,
function evaluateExpTraverser(isExternalArg = false), false);
then
if outChanged then Expression.retype(outExp) else outExp;
end match;

outChanged := changed or outChanged;
Expand Down
1 change: 1 addition & 0 deletions Compiler/NFFrontEnd/NFSimplifyModel.mo
Expand Up @@ -82,6 +82,7 @@ algorithm
if Binding.isBound(binding) then
exp := Binding.getTypedExp(binding);
sexp := SimplifyExp.simplify(exp);
sexp := removeEmptyFunctionArguments(sexp);

if not referenceEq(exp, sexp) then
binding := Binding.setTypedExp(sexp, binding);
Expand Down

0 comments on commit e073cfc

Please sign in to comment.