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

Commit 50bc1b1

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Split TUPLE() := TUPLE() assigments.
- Split assigments where both sides are tuple expressions after simplification into separate assigments, since the code generation expects it to be done. Belonging to [master]: - #2964 - OpenModelica/OpenModelica-testsuite#1132
1 parent 5c656ca commit 50bc1b1

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ public
345345
end match;
346346
end isCref;
347347

348+
function isWildCref
349+
input Expression exp;
350+
output Boolean wild;
351+
algorithm
352+
wild := match exp
353+
case CREF(cref = ComponentRef.WILD()) then true;
354+
else false;
355+
end match;
356+
end isWildCref;
357+
348358
function isCall
349359
input Expression exp;
350360
output Boolean isCall;

Compiler/NFFrontEnd/NFSimplifyModel.mo

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,7 @@ algorithm
254254
Dimension dim;
255255
list<Statement> body;
256256

257-
case Statement.ASSIGNMENT()
258-
algorithm
259-
ty := Type.mapDims(stmt.ty, simplifyDimension);
260-
261-
if not Type.isEmptyArray(ty) then
262-
lhs := removeEmptyTupleElements(SimplifyExp.simplify(stmt.lhs));
263-
rhs := removeEmptyFunctionArguments(SimplifyExp.simplify(stmt.rhs));
264-
statements := Statement.ASSIGNMENT(lhs, rhs, ty, stmt.source) :: statements;
265-
end if;
266-
then
267-
statements;
257+
case Statement.ASSIGNMENT() then simplifyAssignment(stmt, statements);
268258

269259
case Statement.FOR(range = SOME(e))
270260
algorithm
@@ -312,6 +302,62 @@ algorithm
312302
end match;
313303
end simplifyStatement;
314304

305+
function simplifyAssignment
306+
input Statement stmt;
307+
input output list<Statement> statements;
308+
protected
309+
Expression lhs, rhs, rhs_exp;
310+
list<Expression> rhs_rest;
311+
Type ty;
312+
DAE.ElementSource src;
313+
algorithm
314+
Statement.ASSIGNMENT(lhs = lhs, rhs = rhs, ty = ty, source = src) := stmt;
315+
ty := Type.mapDims(ty, simplifyDimension);
316+
317+
if Type.isEmptyArray(ty) then
318+
return;
319+
end if;
320+
321+
lhs := SimplifyExp.simplify(lhs);
322+
lhs := removeEmptyTupleElements(lhs);
323+
rhs := SimplifyExp.simplify(rhs);
324+
rhs := removeEmptyFunctionArguments(rhs);
325+
326+
statements := match (lhs, rhs)
327+
case (Expression.TUPLE(), Expression.TUPLE())
328+
then simplifyTupleAssignment(lhs.elements, rhs.elements, ty, src, statements);
329+
330+
else Statement.ASSIGNMENT(lhs, rhs, ty, src) :: statements;
331+
end match;
332+
end simplifyAssignment;
333+
334+
function simplifyTupleAssignment
335+
"Helper function to simplifyAssignment.
336+
Handles Expression.TUPLE() := Expression.TUPLE() assignments by splitting
337+
them into a separate assignment statement for each pair of tuple elements."
338+
input list<Expression> lhsTuple;
339+
input list<Expression> rhsTuple;
340+
input Type ty;
341+
input DAE.ElementSource src;
342+
input output list<Statement> statements;
343+
protected
344+
Expression rhs;
345+
list<Expression> rest_rhs = rhsTuple;
346+
Type ety;
347+
list<Type> rest_ty;
348+
algorithm
349+
Type.TUPLE(types = rest_ty) := ty;
350+
351+
for lhs in lhsTuple loop
352+
rhs :: rest_rhs := rest_rhs;
353+
ety :: rest_ty := rest_ty;
354+
355+
if not Expression.isWildCref(lhs) then
356+
statements := Statement.ASSIGNMENT(lhs, rhs, ety, src) :: statements;
357+
end if;
358+
end for;
359+
end simplifyTupleAssignment;
360+
315361
function removeEmptyTupleElements
316362
"Replaces tuple elements that has one or more zero dimension with _."
317363
input output Expression exp;

0 commit comments

Comments
 (0)