Skip to content

Commit

Permalink
[BE] fix iterator handling in algorithms (#7853)
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
kabdelhak committed Sep 3, 2021
1 parent 0f49ff7 commit 8c59b8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 22 additions & 3 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -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
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -2828,6 +2828,8 @@ algorithm
outCref := crefStripSubsExceptModelSubs(cr);
then
makeCrefQual(id,ty,{},outCref);

else inCref;
end match;
end crefStripSubsExceptModelSubs;

Expand Down

0 comments on commit 8c59b8e

Please sign in to comment.