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

Commit 1fd1dd9

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Collapse arrays with same call on each element, ticket:5110
This particularly applies to {previous(x[1]), previous(x[2])}. Belonging to [master]: - #2645
1 parent df1914c commit 1fd1dd9

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Compiler/BackEnd/BackendDAETransform.mo

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ protected
842842
list<Integer> ds;
843843
Integer len;
844844
list<DAE.Exp> exps;
845+
DAE.Exp exp1;
846+
Absyn.Ident call1, call2;
845847
DAE.ComponentRef cr1,cr2;
846848
list<DAE.Subscript> subs;
847849
Integer ndim;
@@ -859,7 +861,13 @@ algorithm
859861
ndim := listLength(ds);
860862
len := product(i for i in ds);
861863
true := len > 0;
862-
(DAE.CREF(componentRef=cr1)::exps) := Expression.flattenArrayExpToList(e); // TODO: Use a better routine? We now get all expressions even if no expression is a cref...
864+
//(DAE.CREF(componentRef=cr1)::exps) := Expression.flattenArrayExpToList(e); // TODO: Use a better routine? We now get all expressions even if no expression is a cref...
865+
(exp1::exps) := Expression.flattenArrayExpToList(e);
866+
(cr1, call1) := match exp1
867+
case DAE.CREF(componentRef=cr1) then (cr1, "");
868+
case DAE.CALL(path=Absyn.IDENT(name=call1), expLst={DAE.CREF(componentRef=cr1)}) then (cr1, call1);
869+
else fail();
870+
end match;
863871
// Check that the first element starts at index [1,...,1]
864872
subs := ComponentReference.crefLastSubs(cr1);
865873
true := ndim==listLength(subs);
@@ -870,14 +878,23 @@ algorithm
870878
// Same number of expressions as expected...
871879
true := (1+listLength(exps))==len;
872880
for exp in exps loop
873-
DAE.CREF(componentRef=cr2) := exp;
881+
//DAE.CREF(componentRef=cr2) := exp;
882+
(cr2, call2) := match exp
883+
case DAE.CREF(componentRef=cr2) then (cr2, "");
884+
case DAE.CALL(path=Absyn.IDENT(name=call2), expLst={DAE.CREF(componentRef=cr2)}) then (cr2, call2);
885+
else fail();
886+
end match;
874887
true := ndim==listLength(ComponentReference.crefLastSubs(cr2));
875888
true := ComponentReference.crefEqualWithoutSubs(cr1,cr2);
876889
true := 1==ComponentReference.crefCompareIntSubscript(cr2,cr1); // cr2 > cr1
890+
true := call1==call2;
877891
cr1 := cr2;
878892
end for;
879893
// All of the crefs are in ascending order; the first one starts at 1,1; the length is the full array... So it is the complete cref!
880894
e := Expression.makeCrefExp(ComponentReference.crefStripLastSubs(cr1), ty);
895+
if call1 <> "" then
896+
e := DAE.CALL(Absyn.IDENT(name = call1), {e}, DAE.callAttrBuiltinImpureReal);
897+
end if;
881898
end collapseArrayCrefExpWork2;
882899

883900
annotation(__OpenModelica_Interface="backend");

0 commit comments

Comments
 (0)