@@ -730,6 +730,24 @@ public
730730 input output ComponentRef cref;
731731 input UnorderedMap < list< Dimension > , list< ComponentRef >> dims_map;
732732 input UnorderedMap < ComponentRef , Subscript > iter_map;
733+ protected
734+ function checkLocalDimensions
735+ "checks if the current dimension configuration results in new subscripts for the cref"
736+ input output ComponentRef cref;
737+ input list< Dimension > dims;
738+ input UnorderedMap < list< Dimension > , list< ComponentRef >> dims_map;
739+ input UnorderedMap < ComponentRef , Subscript > iter_map;
740+ protected
741+ Option < list< ComponentRef >> iter_crefs;
742+ list< Subscript > new_subs;
743+ algorithm
744+ iter_crefs := UnorderedMap . get(dims, dims_map);
745+ if Util . isSome(iter_crefs) then
746+ // dimension configuration was found, map to subscripts and apply in reverse
747+ new_subs := list(UnorderedMap . getSafe(iter_name, iter_map, sourceInfo()) for iter_name in Util . getOption(iter_crefs));
748+ cref := mergeSubscripts(new_subs, cref, true , true , true );
749+ end if ;
750+ end checkLocalDimensions;
733751 algorithm
734752 cref := match cref
735753 local
@@ -738,20 +756,22 @@ public
738756 ComponentRef new_cref;
739757 list< Subscript > new_subs, rest_subs;
740758 Type ty = getSubscriptedType(cref);
759+ Integer num_local_dims;
741760
742761 // local array type -> try to find the current dimension configuration in the map and add subscripts
743762 case CREF () guard(Type . isArray(ty)) algorithm
744763 // get dimensions and check in map
745- dims := Type . arrayDims(ty);
746- iter_crefs := UnorderedMap . get(dims, dims_map);
747- if Util . isSome(iter_crefs) then
748- // dimension configuration was found, map to subscripts and apply in reverse
749- new_subs := list(UnorderedMap . getSafe(iter_name, iter_map, sourceInfo()) for iter_name in Util . getOption(iter_crefs));
750- new_cref := mergeSubscripts(new_subs, cref, true , true , true );
751- else
752- // not found, just keep current cref
753- new_cref := cref;
754- end if ;
764+ dims := Type . arrayDims(ty);
765+ num_local_dims := listLength(Type . arrayDims(cref. ty));
766+
767+ // check if the dimension configuration exists in the map
768+ // and iteratively remove one dimension to check all local configurations
769+ new_cref := cref;
770+ while num_local_dims > 0 loop
771+ new_cref := checkLocalDimensions(new_cref, dims, dims_map, iter_map);
772+ dims := List . stripLast(dims);
773+ num_local_dims := num_local_dims - 1 ;
774+ end while ;
755775
756776 // apply to restCref afterwards such that the outermost dimensions are handled first
757777 // this is important because the full dimension list is considered when checking in the map
0 commit comments