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

Commit e073cfc

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fixes for Modelica tables.
- 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]: - #2755
1 parent d39b07b commit e073cfc

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

Compiler/NFFrontEnd/NFEvalConstants.mo

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,36 +130,53 @@ end evaluateExp;
130130
function evaluateExpTraverser
131131
input Expression exp;
132132
input Boolean changed;
133+
input Boolean isExternalArg = false;
133134
output Expression outExp;
134135
output Boolean outChanged;
135136
protected
136137
Expression e;
138+
ComponentRef cref;
139+
Type ty;
137140
algorithm
138-
(e, outChanged) := Expression.mapFoldShallow(exp, evaluateExpTraverser, false);
139-
140-
outExp := match e
141+
outExp := match exp
141142
case Expression.CREF()
142143
algorithm
143-
if ComponentRef.nodeVariability(e.cref) <= Variability.STRUCTURAL_PARAMETER then
144+
(outExp as Expression.CREF(cref = cref, ty = ty), outChanged) := Expression.mapFoldShallow(exp,
145+
function evaluateExpTraverser(isExternalArg = false), false);
146+
147+
// Evaluate constants and structural parameters, except for arrays that
148+
// are used as arguments to an external function.
149+
150+
// TODO: The runtime doesn't handle array literals well when used as
151+
// arguments of external functions, since it sometimes tries to
152+
// write to them (e.g. when trying to pack them). Until that's
153+
// fixed we keep them as they are here.
154+
if ComponentRef.nodeVariability(cref) <= Variability.STRUCTURAL_PARAMETER and
155+
not (isExternalArg and Type.isArray(ty)) then
144156
// Evaluate all constants and structural parameters.
145-
outExp := Ceval.evalCref(e.cref, e, Ceval.EvalTarget.IGNORE_ERRORS(), evalSubscripts = false);
157+
outExp := Ceval.evalCref(cref, outExp, Ceval.EvalTarget.IGNORE_ERRORS(), evalSubscripts = false);
146158
outChanged := true;
147159
elseif outChanged then
148160
// If the cref's subscripts changed, recalculate its type.
149-
outExp := Expression.CREF(ComponentRef.getSubscriptedType(e.cref), e.cref);
150-
else
151-
outExp := e;
161+
outExp := Expression.CREF(ComponentRef.getSubscriptedType(cref), cref);
152162
end if;
153163
then
154164
outExp;
155165

156166
case Expression.CALL()
157167
algorithm
158-
evaluateFunction(Call.typedFunction(e.call));
168+
(outExp, outChanged) := Expression.mapFoldShallow(exp,
169+
function evaluateExpTraverser(isExternalArg = Call.isExternal(exp.call)), false);
170+
evaluateFunction(Call.typedFunction(exp.call));
159171
then
160-
e;
172+
outExp;
161173

162-
else if outChanged then Expression.retype(e) else e;
174+
else
175+
algorithm
176+
(outExp, outChanged) := Expression.mapFoldShallow(exp,
177+
function evaluateExpTraverser(isExternalArg = false), false);
178+
then
179+
if outChanged then Expression.retype(outExp) else outExp;
163180
end match;
164181

165182
outChanged := changed or outChanged;

Compiler/NFFrontEnd/NFSimplifyModel.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ algorithm
8282
if Binding.isBound(binding) then
8383
exp := Binding.getTypedExp(binding);
8484
sexp := SimplifyExp.simplify(exp);
85+
sexp := removeEmptyFunctionArguments(sexp);
8586

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

0 commit comments

Comments
 (0)