@@ -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;
313303end 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+
315361function removeEmptyTupleElements
316362 "Replaces tuple elements that has one or more zero dimension with _."
317363 input output Expression exp;
0 commit comments