Skip to content

Commit 632f717

Browse files
committed
Fix for #2532:
- Fixed slicing of qualified crefs. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18725 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 81e2c12 commit 632f717

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

Compiler/FrontEnd/Expression.mo

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,28 @@ algorithm
13191319
end matchcontinue;
13201320
end subscriptsAppend;
13211321

1322+
public function subscriptsReplaceSlice
1323+
"Replaces the first slice subscript in the given list with the given subscript."
1324+
input list<DAE.Subscript> inSubscripts;
1325+
input DAE.Subscript inSubscript;
1326+
output list<DAE.Subscript> outSubscripts;
1327+
algorithm
1328+
outSubscripts := match(inSubscripts, inSubscript)
1329+
local
1330+
list<DAE.Subscript> rest_subs;
1331+
DAE.Subscript sub;
1332+
1333+
case (DAE.WHOLEDIM() :: rest_subs, _) then inSubscript :: rest_subs;
1334+
case (DAE.SLICE(exp = _) :: rest_subs, _) then inSubscript :: rest_subs;
1335+
case (sub :: rest_subs, _)
1336+
equation
1337+
rest_subs = subscriptsReplaceSlice(rest_subs, inSubscript);
1338+
then
1339+
sub :: rest_subs;
1340+
1341+
end match;
1342+
end subscriptsReplaceSlice;
1343+
13221344
public function unliftArrayTypeWithSubs "
13231345
helper function for renameVarsToUnderlineVar2 unlifts array type as much as we have subscripts"
13241346
input list<DAE.Subscript> subs;

Compiler/FrontEnd/ExpressionSimplify.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,6 +3010,12 @@ algorithm
30103010
then
30113011
c_1;
30123012

3013+
case (DAE.CREF_QUAL(idn, t2, s, c), _)
3014+
equation
3015+
s = Expression.subscriptsReplaceSlice(s, DAE.INDEX(sub));
3016+
then
3017+
ComponentReference.makeCrefQual(idn, t2, s, c);
3018+
30133019
case (DAE.CREF_QUAL(idn,t2,s,c),_)
30143020
equation
30153021
c_1 = simplifyAsubCref(c,sub);

Compiler/FrontEnd/Static.mo

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10523,14 +10523,28 @@ algorithm
1052310523
// qualified ident with non-empty subscrips
1052410524
case (e as (DAE.CREF_QUAL(ident = id,subscriptLst = subs,componentRef = cref,identType = ty2 )),t)
1052510525
equation
10526-
// TODO!FIXME!
10527-
// ComponentReference.makeCrefIdent(id, ty2, subs) = fillCrefSubscripts(ComponentReference.makeCrefIdent(id, ty2, subs),t);
10526+
subs = fillSubscripts(subs, ty2);
10527+
t = stripPrefixType(t, ty2);
1052810528
cref_1 = fillCrefSubscripts(cref, t);
1052910529
then
1053010530
ComponentReference.makeCrefQual(id,ty2,subs,cref_1);
1053110531
end matchcontinue;
1053210532
end fillCrefSubscripts;
1053310533

10534+
protected function stripPrefixType
10535+
input DAE.Type inType;
10536+
input DAE.Type inPrefixType;
10537+
output DAE.Type outType;
10538+
algorithm
10539+
outType := match(inType, inPrefixType)
10540+
local
10541+
DAE.Type t, pt;
10542+
10543+
case (DAE.T_ARRAY(ty = t), DAE.T_ARRAY(ty = pt)) then stripPrefixType(t, pt);
10544+
else inType;
10545+
end match;
10546+
end stripPrefixType;
10547+
1053410548
protected function fillSubscripts
1053510549
"Helper function to fillCrefSubscripts."
1053610550
input list<DAE.Subscript> inExpSubscriptLst;

0 commit comments

Comments
 (0)