@@ -1185,195 +1185,125 @@ public
11851185 end mapSubscript;
11861186
11871187 function mapShallow
1188- input output Expression exp;
1188+ input Expression exp;
11891189 input MapFunc func ;
1190+ output Expression outExp;
11901191
11911192 partial function MapFunc
11921193 input output Expression e;
11931194 end MapFunc ;
11941195 algorithm
1195- () := match exp
1196+ outExp := match exp
11961197 local
11971198 Expression e1, e2, e3, e4;
11981199
1199- case CREF ()
1200- algorithm
1201- exp. cref := mapCrefShallow(exp. cref, func );
1202- then
1203- ();
1204-
1205- case ARRAY ()
1206- algorithm
1207- exp. elements := list(func (e) for e in exp. elements);
1208- then
1209- ();
1200+ case CREF () then CREF (exp. ty, mapCrefShallow(exp. cref, func ));
1201+ case ARRAY () then ARRAY (exp. ty, list(func (e) for e in exp. elements));
12101202
12111203 case RANGE (step = SOME (e2))
12121204 algorithm
12131205 e1 := func (exp. start);
12141206 e4 := func (e2);
12151207 e3 := func (exp. stop);
1216-
1217- if referenceEq(exp. start, e1) and referenceEq(e2, e4) and referenceEq(exp. stop, e3) then
1218- exp := RANGE (exp. ty, e1, SOME (e4), e3);
1219- end if ;
12201208 then
1221- ();
1209+ if referenceEq(exp. start, e1) and referenceEq(e2, e4) and
1210+ referenceEq(exp. stop, e3) then exp else RANGE (exp. ty, e1, SOME (e4), e3);
12221211
12231212 case RANGE ()
12241213 algorithm
12251214 e1 := func (exp. start);
12261215 e3 := func (exp. stop);
1227-
1228- if referenceEq(exp. start, e1) and referenceEq(exp. stop, e3) then
1229- exp := RANGE (exp. ty, e1, NONE (), e3);
1230- end if ;
12311216 then
1232- ();
1217+ if referenceEq(exp. start, e1) and referenceEq(exp. stop, e3)
1218+ then exp else RANGE (exp. ty, e1, NONE (), e3);
12331219
1234- case TUPLE ()
1235- algorithm
1236- exp. elements := list(func (e) for e in exp. elements);
1237- then
1238- ();
1220+ case TUPLE () then TUPLE (exp. ty, list(func (e) for e in exp. elements));
12391221
12401222 case RECORD ()
1241- algorithm
1242- exp. elements := list(func (e) for e in exp. elements);
1243- then
1244- ();
1223+ then RECORD (exp. path, exp. ty, list(func (e) for e in exp. elements));
12451224
1246- case CALL ()
1247- algorithm
1248- exp. call := mapCallShallow(exp. call, func );
1249- then
1250- ();
1225+ case CALL () then CALL (mapCallShallow(exp. call, func ));
12511226
12521227 case SIZE (dimIndex = SOME (e2))
12531228 algorithm
12541229 e1 := func (exp. exp);
12551230 e3 := func (e2);
1256-
1257- if referenceEq(exp. exp, e1) and referenceEq(e2, e3) then
1258- exp := SIZE (e1, SOME (e3));
1259- end if ;
12601231 then
1261- ( );
1232+ if referenceEq(exp . exp, e1) and referenceEq(e2, e3) then exp else SIZE (e1, SOME (e3) );
12621233
12631234 case SIZE ()
12641235 algorithm
12651236 e1 := func (exp. exp);
1266-
1267- if referenceEq(exp. exp, e1) then
1268- exp := SIZE (e1, NONE ());
1269- end if ;
12701237 then
1271- ( );
1238+ if referenceEq(exp . exp, e1) then exp else SIZE (e1, NONE () );
12721239
12731240 case BINARY ()
12741241 algorithm
12751242 e1 := func (exp. exp1);
12761243 e2 := func (exp. exp2);
1277-
1278- if referenceEq(exp. exp1, e1) and referenceEq(exp. exp2, e2) then
1279- exp := BINARY (e1, exp. operator, e2);
1280- end if ;
12811244 then
1282- ();
1245+ if referenceEq(exp. exp1, e1) and referenceEq(exp. exp2, e2)
1246+ then exp else BINARY (e1, exp. operator, e2);
12831247
12841248 case UNARY ()
12851249 algorithm
12861250 e1 := func (exp. exp);
1287-
1288- if referenceEq(exp. exp, e1) then
1289- exp := UNARY (exp. operator, e1);
1290- end if ;
12911251 then
1292- ( );
1252+ if referenceEq(exp . exp, e1) then exp else UNARY (exp . operator, e1 );
12931253
12941254 case LBINARY ()
12951255 algorithm
12961256 e1 := func (exp. exp1);
12971257 e2 := func (exp. exp2);
1298-
1299- if referenceEq(exp. exp1, e1) and referenceEq(exp. exp2, e2) then
1300- exp := LBINARY (e1, exp. operator, e2);
1301- end if ;
13021258 then
1303- ();
1259+ if referenceEq(exp. exp1, e1) and referenceEq(exp. exp2, e2)
1260+ then exp else LBINARY (e1, exp. operator, e2);
13041261
13051262 case LUNARY ()
13061263 algorithm
13071264 e1 := func (exp. exp);
1308-
1309- if referenceEq(exp. exp, e1) then
1310- exp := LUNARY (exp. operator, e1);
1311- end if ;
13121265 then
1313- ( );
1266+ if referenceEq(exp . exp, e1) then exp else LUNARY (exp . operator, e1 );
13141267
13151268 case RELATION ()
13161269 algorithm
13171270 e1 := func (exp. exp1);
13181271 e2 := func (exp. exp2);
1319-
1320- if referenceEq(exp. exp1, e1) and referenceEq(exp. exp2, e2) then
1321- exp := RELATION (e1, exp. operator, e2);
1322- end if ;
13231272 then
1324- ();
1273+ if referenceEq(exp. exp1, e1) and referenceEq(exp. exp2, e2)
1274+ then exp else RELATION (e1, exp. operator, e2);
13251275
13261276 case IF ()
13271277 algorithm
13281278 e1 := func (exp. condition);
13291279 e2 := func (exp. trueBranch);
13301280 e3 := func (exp. falseBranch);
1331-
1332- if referenceEq(exp. condition, e1) and referenceEq(exp. trueBranch, e2) and
1333- referenceEq(exp. falseBranch, e3) then
1334- exp := IF (e1, e2, e3);
1335- end if ;
13361281 then
1337- ();
1282+ if referenceEq(exp. condition, e1) and referenceEq(exp. trueBranch, e2) and
1283+ referenceEq(exp. falseBranch, e3) then exp else IF (e1, e2, e3);
13381284
13391285 case CAST ()
13401286 algorithm
13411287 e1 := func (exp. exp);
1342-
1343- if referenceEq(exp. exp, e1) then
1344- exp := CAST (exp. ty, e1);
1345- end if ;
13461288 then
1347- ( );
1289+ if referenceEq(exp . exp, e1) then exp else CAST (exp . ty, e1 );
13481290
13491291 case UNBOX ()
13501292 algorithm
13511293 e1 := func (exp. exp);
1352-
1353- if referenceEq(exp. exp, e1) then
1354- exp := UNBOX (e1, exp. ty);
1355- end if ;
13561294 then
1357- ( );
1295+ if referenceEq(exp . exp, e1) then exp else UNBOX (e1, exp . ty );
13581296
13591297 case SUBSCRIPTED_EXP ()
1360- algorithm
1361- exp. exp := func (exp. exp);
1362- exp. subscripts := list(func (e) for e in exp. subscripts);
1363- then
1364- ();
1298+ then SUBSCRIPTED_EXP (func (exp. exp), list(func (e) for e in exp. subscripts), exp. ty);
13651299
13661300 case TUPLE_ELEMENT ()
13671301 algorithm
13681302 e1 := func (exp. tupleExp);
1369-
1370- if referenceEq(exp. tupleExp, e1) then
1371- exp := TUPLE_ELEMENT (e1, exp. index, exp. ty);
1372- end if ;
13731303 then
1374- ( );
1304+ if referenceEq(exp . tupleExp, e1) then exp else TUPLE_ELEMENT (e1, exp . index, exp . ty );
13751305
1376- else () ;
1306+ else exp ;
13771307 end match;
13781308 end mapShallow;
13791309
0 commit comments