From 8c59b8e5f6a7562673c25f9da8bb839ff1884380 Mon Sep 17 00:00:00 2001 From: kabdelhak <38032125+kabdelhak@users.noreply.github.com> Date: Fri, 3 Sep 2021 12:13:01 +0200 Subject: [PATCH] [BE] fix iterator handling in algorithms (#7853) - fixes ticket: #7832 - Problem: for loops in algorithms did not handle manipulated iterators correctly (i+1) -> missing entries in adjacency matrix - remove all non model subscripts on the lhs of an assignment - (Modelica Specification v3.5 : 11.1.2) --- OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo | 25 ++++++++++++++++--- .../Compiler/FrontEnd/ComponentReference.mo | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo b/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo index 95bb55ba962..2a4a9df377c 100644 --- a/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo +++ b/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo @@ -4162,6 +4162,16 @@ protected function traverseStmts "Author: Frenkel TUD 2012-06 input output Type_a arg2; end FuncExpType; replaceable type Type_a subtypeof Any; + function removeSubscripts + input output DAE.Exp exp; + algorithm + exp := match exp + case DAE.CREF() algorithm + exp.componentRef := ComponentReference.crefStripSubsExceptModelSubs(exp.componentRef); + then exp; + else exp; + end match; + end removeSubscripts; algorithm oextraArg := matchcontinue(inStmts,func,iextraArg) local @@ -4180,22 +4190,31 @@ algorithm case ((DAE.STMT_ASSIGN(exp1 = e2,exp = e)::xs),_,extraArg) equation + // kabdelhak: remove left hand side subscripts + // (Modelica Specification v3.5 : 11.1.2) + // solves ticket #7832 extraArg = func(e, extraArg); - extraArg = func(e2, extraArg); + extraArg = func(removeSubscripts(e2), extraArg); then traverseStmts(xs, func, extraArg); case ((DAE.STMT_TUPLE_ASSIGN(expExpLst = expl1, exp = e)::xs),_,extraArg) equation + // kabdelhak: remove left hand side subscripts + // (Modelica Specification v3.5 : 11.1.2) + // solves ticket #7832 extraArg = func(e, extraArg); - extraArg = List.fold(expl1,func,extraArg); + extraArg = List.fold(list(removeSubscripts(ex) for ex in expl1),func,extraArg); then traverseStmts(xs, func, extraArg); case ((DAE.STMT_ASSIGN_ARR(lhs = e2, exp = e)::xs),_,extraArg) equation + // kabdelhak: remove left hand side subscripts + // (Modelica Specification v3.5 : 11.1.2) + // solves ticket #7832 extraArg = func(e, extraArg); - extraArg = func(e2, extraArg); + extraArg = func(removeSubscripts(e2), extraArg); then traverseStmts(xs, func, extraArg); diff --git a/OMCompiler/Compiler/FrontEnd/ComponentReference.mo b/OMCompiler/Compiler/FrontEnd/ComponentReference.mo index b2c86b478c4..f51c3dbe517 100644 --- a/OMCompiler/Compiler/FrontEnd/ComponentReference.mo +++ b/OMCompiler/Compiler/FrontEnd/ComponentReference.mo @@ -2828,6 +2828,8 @@ algorithm outCref := crefStripSubsExceptModelSubs(cr); then makeCrefQual(id,ty,{},outCref); + + else inCref; end match; end crefStripSubsExceptModelSubs;