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

Commit 8017c67

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Expand complex array crefs.
- Expand crefs where one of the prefix nodes is an array, i.e. a.b.c => {a.b[1].c, a.b[2].c}, to work around backend issues. - Fix order of equations in if-equations. Belonging to [master]: - #2919 - OpenModelica/OpenModelica-testsuite#1119
1 parent 71414e4 commit 8017c67

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

Compiler/NFFrontEnd/NFComponentRef.mo

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,5 +850,29 @@ public
850850
end match;
851851
end depth;
852852

853+
function isComplexArray
854+
input ComponentRef cref;
855+
output Boolean complexArray;
856+
algorithm
857+
complexArray := match cref
858+
case CREF() then isComplexArray2(cref.restCref);
859+
else false;
860+
end match;
861+
end isComplexArray;
862+
863+
function isComplexArray2
864+
input ComponentRef cref;
865+
output Boolean complexArray;
866+
algorithm
867+
complexArray := match cref
868+
case CREF(ty = Type.ARRAY())
869+
guard Type.isArray(Type.subscript(cref.ty, cref.subscripts))
870+
then true;
871+
872+
case CREF() then isComplexArray2(cref.restCref);
873+
else false;
874+
end match;
875+
end isComplexArray2;
876+
853877
annotation(__OpenModelica_Interface="frontend");
854878
end NFComponentRef;

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ algorithm
997997
algorithm
998998
// Flatten the condition and body of the branch.
999999
cond := flattenExp(cond, prefix);
1000-
eql := flattenEquations(eql, prefix);
1000+
eql := listReverseInPlace(flattenEquations(eql, prefix));
10011001

10021002
// Evaluate structural conditions.
10031003
if var <= Variability.STRUCTURAL_PARAMETER then

Compiler/NFFrontEnd/NFScalarize.mo

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ algorithm
7070
end for;
7171

7272
flatModel.variables := listReverseInPlace(vars);
73+
flatModel.equations := Equation.mapExpList(flatModel.equations, expandComplexCref);
7374
flatModel.equations := scalarizeEquations(flatModel.equations);
75+
flatModel.initialEquations := Equation.mapExpList(flatModel.initialEquations, expandComplexCref);
7476
flatModel.initialEquations := scalarizeEquations(flatModel.initialEquations);
7577
flatModel.algorithms := list(scalarizeAlgorithm(a) for a in flatModel.algorithms);
7678
flatModel.initialAlgorithms := list(scalarizeAlgorithm(a) for a in flatModel.initialAlgorithms);
@@ -111,7 +113,7 @@ algorithm
111113
(ty_attr_names, ty_attr_iters) := scalarizeTypeAttributes(ty_attr);
112114

113115
if Binding.isBound(binding) then
114-
binding_iter := ExpressionIterator.fromExp(Binding.getTypedExp(binding));
116+
binding_iter := ExpressionIterator.fromExp(expandComplexCref(Binding.getTypedExp(binding)));
115117
bind_var := Binding.variability(binding);
116118

117119
for cr in crefs loop
@@ -127,6 +129,7 @@ algorithm
127129
end for;
128130
end if;
129131
else
132+
var.binding := Binding.mapExp(var.binding, expandComplexCref);
130133
vars := var :: vars;
131134
end if;
132135
end scalarizeVariable;
@@ -169,6 +172,32 @@ algorithm
169172
end for;
170173
end nextTypeAttributes;
171174

175+
function expandComplexCref
176+
input output Expression exp;
177+
algorithm
178+
exp := Expression.map(exp, expandComplexCref_traverser);
179+
end expandComplexCref;
180+
181+
function expandComplexCref_traverser
182+
input output Expression exp;
183+
algorithm
184+
() := match exp
185+
case Expression.CREF(ty = Type.ARRAY())
186+
algorithm
187+
// Expand crefs where any of the prefix nodes are arrays. For example if
188+
// b in a.b.c is SomeType[2] we expand it into {a.b[1].c, a.b[2].c}.
189+
// TODO: This is only done due to backend issues and shouldn't be
190+
// necessary.
191+
if ComponentRef.isComplexArray(exp.cref) then
192+
exp := ExpandExp.expand(exp);
193+
end if;
194+
then
195+
();
196+
197+
else ();
198+
end match;
199+
end expandComplexCref_traverser;
200+
172201
function scalarizeEquations
173202
input list<Equation> eql;
174203
output list<Equation> equations = {};

0 commit comments

Comments
 (0)