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

Commit c3159ae

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Change cref evaluation strategy.
- Evaluate all crefs that refer to a constant, even if the subscripts aren't constant. Belonging to [master]: - #2561 - OpenModelica/OpenModelica-testsuite#1001
1 parent 5ae39b9 commit c3159ae

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ function evalComponentBinding
289289
input Expression defaultExp "The expression returned if the binding couldn't be evaluated";
290290
input EvalTarget target;
291291
output Expression exp;
292+
output Boolean evaluated;
292293
protected
293294
ExpOrigin.Type exp_origin;
294295
Component comp;
@@ -305,7 +306,7 @@ algorithm
305306
binding := makeComponentBinding(comp, node, Expression.toCref(defaultExp), target);
306307
end if;
307308

308-
exp := match binding
309+
(exp, evaluated) := match binding
309310
case Binding.TYPED_BINDING()
310311
algorithm
311312
exp := evalExp(binding.bindingExp, target);
@@ -316,15 +317,15 @@ algorithm
316317
InstNode.updateComponent(comp, node);
317318
end if;
318319
then
319-
exp;
320+
(exp, true);
320321

321-
case Binding.CEVAL_BINDING() then binding.bindingExp;
322+
case Binding.CEVAL_BINDING() then (binding.bindingExp, true);
322323

323324
case Binding.UNBOUND()
324325
algorithm
325326
printUnboundError(target, defaultExp);
326327
then
327-
defaultExp;
328+
(defaultExp, false);
328329

329330
else
330331
algorithm

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -931,23 +931,12 @@ algorithm
931931
ComponentRef cref;
932932
Integer next_origin;
933933

934-
case Expression.INTEGER() then (exp, Type.INTEGER(), Variability.CONSTANT);
935-
case Expression.REAL() then (exp, Type.REAL(), Variability.CONSTANT);
936-
case Expression.STRING() then (exp, Type.STRING(), Variability.CONSTANT);
937-
case Expression.BOOLEAN() then (exp, Type.BOOLEAN(), Variability.CONSTANT);
938-
case Expression.ENUM_LITERAL() then (exp, exp.ty, Variability.CONSTANT);
939-
940-
case Expression.CREF()
941-
algorithm
942-
(cref, ty, variability) := typeCref(exp.cref, origin, info);
943-
e1 := Expression.CREF(ty, cref);
944-
945-
if replaceConstants and variability <= Variability.STRUCTURAL_PARAMETER and
946-
not Expression.containsIterator(e1, origin) then
947-
e1 := Ceval.evalExp(e1, Ceval.EvalTarget.GENERIC(info));
948-
end if;
949-
then
950-
(e1, ty, variability);
934+
case Expression.INTEGER() then (exp, Type.INTEGER(), Variability.CONSTANT);
935+
case Expression.REAL() then (exp, Type.REAL(), Variability.CONSTANT);
936+
case Expression.STRING() then (exp, Type.STRING(), Variability.CONSTANT);
937+
case Expression.BOOLEAN() then (exp, Type.BOOLEAN(), Variability.CONSTANT);
938+
case Expression.ENUM_LITERAL() then (exp, exp.ty, Variability.CONSTANT);
939+
case Expression.CREF() then typeCrefExp(exp.cref, origin, info, replaceConstants);
951940

952941
case Expression.TYPENAME()
953942
algorithm
@@ -959,11 +948,11 @@ algorithm
959948
then
960949
(exp, exp.ty, Variability.CONSTANT);
961950

962-
case Expression.ARRAY() then typeArray(exp.elements, origin, info);
951+
case Expression.ARRAY() then typeArray(exp.elements, origin, info);
963952
case Expression.MATRIX() then typeMatrix(exp.elements, origin, info);
964-
case Expression.RANGE() then typeRange(exp, origin, info);
965-
case Expression.TUPLE() then typeTuple(exp.elements, origin, info);
966-
case Expression.SIZE() then typeSize(exp, origin, info);
953+
case Expression.RANGE() then typeRange(exp, origin, info);
954+
case Expression.TUPLE() then typeTuple(exp.elements, origin, info);
955+
case Expression.SIZE() then typeSize(exp, origin, info);
967956

968957
case Expression.END()
969958
algorithm
@@ -1245,12 +1234,42 @@ algorithm
12451234
end if;
12461235
end nthDimensionBoundsChecked;
12471236

1237+
function typeCrefExp
1238+
input ComponentRef cref;
1239+
input ExpOrigin.Type origin;
1240+
input SourceInfo info;
1241+
input Boolean replaceConstants;
1242+
output Expression exp;
1243+
output Type ty;
1244+
output Variability variability;
1245+
protected
1246+
ComponentRef cr;
1247+
Variability node_var, subs_var;
1248+
Boolean eval;
1249+
algorithm
1250+
(cr, ty, node_var, subs_var) := typeCref(cref, origin, info);
1251+
exp := Expression.CREF(ty, cr);
1252+
1253+
if replaceConstants and node_var <= Variability.STRUCTURAL_PARAMETER and
1254+
not ComponentRef.isIterator(cr) then
1255+
(exp, eval) := Ceval.evalComponentBinding(ComponentRef.node(cr), exp,
1256+
Ceval.EvalTarget.IGNORE_ERRORS());
1257+
1258+
if eval then
1259+
exp := Expression.applySubscripts(ComponentRef.getSubscripts(cr), exp);
1260+
end if;
1261+
end if;
1262+
1263+
variability := Prefixes.variabilityMax(node_var, subs_var);
1264+
end typeCrefExp;
1265+
12481266
function typeCref
12491267
input output ComponentRef cref;
12501268
input ExpOrigin.Type origin;
12511269
input SourceInfo info;
12521270
output Type ty;
1253-
output Variability variability;
1271+
output Variability nodeVariability;
1272+
output Variability subsVariability;
12541273
protected
12551274
Variability subs_var;
12561275
algorithm
@@ -1263,9 +1282,9 @@ algorithm
12631282
fail();
12641283
end if;
12651284

1266-
(cref, subs_var) := typeCref2(cref, origin, info);
1285+
(cref, subsVariability) := typeCref2(cref, origin, info);
12671286
ty := ComponentRef.getSubscriptedType(cref);
1268-
variability := Prefixes.variabilityMax(ComponentRef.nodeVariability(cref), subs_var);
1287+
nodeVariability := ComponentRef.nodeVariability(cref);
12691288
end typeCref;
12701289

12711290
function typeCref2

0 commit comments

Comments
 (0)