@@ -3277,7 +3277,8 @@ algorithm
32773277 Integer indx;
32783278 list< Integer > indxs;
32793279 list< BackendDAE . Var > vLst;
3280- list< DAE . ComponentRef > crlst;
3280+ list< DAE . ComponentRef > crlst;
3281+ DAE . ComponentRef cr1;
32813282 case (_,_)
32823283 equation
32833284 (v,indx) = getVar2(cr, inVariables) "if scalar found, return it" ;
@@ -3289,6 +3290,15 @@ algorithm
32893290 (vLst as _::_,indxs) = getVarLst(crlst,inVariables,{},{});
32903291 then
32913292 (vLst,indxs);
3293+ // try again check if variable indexes used
3294+ case (_,_)
3295+ equation
3296+ // replace variables with WHOLEDIM()
3297+ (cr1,true ) = replaceVarWithWholeDim(cr, false );
3298+ crlst = ComponentReference . expandCref(cr1,true );
3299+ (vLst as _::_,indxs) = getVarLst(crlst,inVariables,{},{});
3300+ then
3301+ (vLst,indxs);
32923302 /* failure
32933303 case (cr,vars)
32943304 equation
@@ -3299,6 +3309,90 @@ algorithm
32993309 end matchcontinue;
33003310end getVar;
33013311
3312+ protected function replaceVarWithWholeDim
3313+ "Helper function to traverseExp. Traverses any expressions in a
3314+ component reference (i.e. in it's subscripts)."
3315+ input DAE . ComponentRef inCref;
3316+ input Boolean iPerformed;
3317+ output DAE . ComponentRef outCref;
3318+ output Boolean oPerformed;
3319+ algorithm
3320+ (outCref, oPerformed) := match(inCref, iPerformed)
3321+ local
3322+ DAE . Ident name;
3323+ DAE . ComponentRef cr,cr_1;
3324+ DAE . Type ty;
3325+ list< DAE . Subscript > subs,subs_1;
3326+ Boolean b;
3327+
3328+ case (DAE . CREF_QUAL (ident = name, identType = ty, subscriptLst = subs, componentRef = cr), _)
3329+ equation
3330+ (subs_1, b) = replaceVarWithWholeDimSubs(subs, iPerformed);
3331+ (cr_1, b) = replaceVarWithWholeDim(cr, b);
3332+ then
3333+ (DAE . CREF_QUAL (name, ty, subs_1, cr_1), b);
3334+
3335+ case (DAE . CREF_IDENT (ident = name, identType = ty, subscriptLst = subs), _)
3336+ equation
3337+ (subs_1, b) = replaceVarWithWholeDimSubs(subs, iPerformed);
3338+ then
3339+ (DAE . CREF_IDENT (name, ty, subs_1), b);
3340+
3341+ case (DAE . CREF_ITER (ident = _), _) then (inCref, iPerformed);
3342+ case (DAE . OPTIMICA_ATTR_INST_CREF (componentRef = _), _) then (inCref, iPerformed);
3343+ case (DAE . WILD (), _) then (inCref, iPerformed);
3344+
3345+ else
3346+ equation
3347+ Error . addMessage(Error . INTERNAL_ERROR , {"BackendVariable.replaceVarWithWholeDim: Unknown cref" });
3348+ then fail();
3349+ end match;
3350+ end replaceVarWithWholeDim;
3351+
3352+ protected function replaceVarWithWholeDimSubs
3353+ input list< DAE . Subscript > inSubscript;
3354+ input Boolean iPerformed;
3355+ output list< DAE . Subscript > outSubscript;
3356+ output Boolean oPerformed;
3357+ algorithm
3358+ (outSubscript, oPerformed) := match(inSubscript, iPerformed)
3359+ local
3360+ DAE . Exp sub_exp,sub_exp_1;
3361+ list< DAE . Subscript > rest,res;
3362+ Boolean b,const;
3363+
3364+ case ({}, _) then (inSubscript,iPerformed);
3365+ case (DAE . WHOLEDIM ()::rest, _)
3366+ equation
3367+ (res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3368+ then (DAE . WHOLEDIM ()::rest, b);
3369+
3370+ case (DAE . SLICE (exp = sub_exp)::rest, _)
3371+ equation
3372+ (res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3373+ const = Expression . isConst(sub_exp);
3374+ res = Util . if_(const,DAE . SLICE (sub_exp)::rest,DAE . WHOLEDIM ()::rest);
3375+ then
3376+ (res, b or not const);
3377+
3378+ case (DAE . INDEX (exp = sub_exp)::rest, _)
3379+ equation
3380+ (res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3381+ const = Expression . isConst(sub_exp);
3382+ res = Util . if_(const,DAE . INDEX (sub_exp)::rest,DAE . WHOLEDIM ()::rest);
3383+ then
3384+ (res, b or not const);
3385+
3386+ case (DAE . WHOLE_NONEXP (exp = sub_exp)::rest, _)
3387+ equation
3388+ (res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
3389+ const = Expression . isConst(sub_exp);
3390+ res = Util . if_(const,DAE . WHOLE_NONEXP (sub_exp)::rest,DAE . WHOLEDIM ()::rest);
3391+ then
3392+ (res, b or not const);
3393+ end match;
3394+ end replaceVarWithWholeDimSubs;
3395+
33023396public function getVarLst
33033397 input list< DAE . ComponentRef > inComponentRefLst;
33043398 input BackendDAE . Variables inVariables;
0 commit comments