/
NFSimplifyExp.mo
738 lines (651 loc) · 20.5 KB
/
NFSimplifyExp.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package NFSimplifyExp
import Expression = NFExpression;
import Operator = NFOperator;
import Type = NFType;
import Call = NFCall;
import Subscript = NFSubscript;
import NFOperator.Op;
import NFPrefixes.Variability;
import NFInstNode.InstNode;
protected
import Dimension = NFDimension;
import Ceval = NFCeval;
import NFCeval.EvalTarget;
import NFFunction.Function;
import ComponentRef = NFComponentRef;
import ExpandExp = NFExpandExp;
import TypeCheck = NFTypeCheck;
import Absyn;
import AbsynUtil;
import ErrorExt;
import Flags;
import Debug;
public
function simplify
input output Expression exp;
algorithm
exp := match exp
case Expression.CREF()
algorithm
exp.cref := ComponentRef.simplifySubscripts(exp.cref);
exp.ty := ComponentRef.getSubscriptedType(exp.cref);
then
exp;
case Expression.ARRAY()
algorithm
exp.elements := list(simplify(e) for e in exp.elements);
then
exp;
case Expression.RANGE()
then simplifyRange(exp);
case Expression.RECORD()
algorithm
exp.elements := list(simplify(e) for e in exp.elements);
then
exp;
case Expression.CALL() then simplifyCall(exp);
case Expression.SIZE() then simplifySize(exp);
case Expression.BINARY() then simplifyBinary(exp);
case Expression.UNARY() then simplifyUnary(exp);
case Expression.LBINARY() then simplifyLogicBinary(exp);
case Expression.LUNARY() then simplifyLogicUnary(exp);
case Expression.RELATION() then simplifyRelation(exp);
case Expression.IF() then simplifyIf(exp);
case Expression.CAST() then simplifyCast(simplify(exp.exp), exp.ty);
case Expression.UNBOX() then Expression.UNBOX(simplify(exp.exp), exp.ty);
case Expression.SUBSCRIPTED_EXP() then simplifySubscriptedExp(exp);
case Expression.TUPLE_ELEMENT() then simplifyTupleElement(exp);
case Expression.BOX() then Expression.BOX(simplify(exp.exp));
case Expression.MUTABLE() then simplify(Mutable.access(exp.exp));
else exp;
end match;
end simplify;
function simplifyOpt
input output Option<Expression> exp;
protected
Expression e;
algorithm
exp := match exp
case SOME(e) then SOME(simplify(e));
else exp;
end match;
end simplifyOpt;
function simplifyRange
input Expression range;
output Expression exp;
protected
Expression start_exp1, stop_exp1, start_exp2, stop_exp2;
Option<Expression> step_exp1, step_exp2;
Type ty;
algorithm
Expression.RANGE(ty = ty, start = start_exp1, step = step_exp1, stop = stop_exp1) := range;
start_exp2 := simplify(start_exp1);
step_exp2 := simplifyOpt(step_exp1);
stop_exp2 := simplify(stop_exp1);
if referenceEq(start_exp1, start_exp2) and
referenceEq(step_exp1, step_exp2) and
referenceEq(stop_exp1, stop_exp2) then
exp := range;
else
ty := TypeCheck.getRangeType(start_exp2, step_exp2, stop_exp2,
Type.arrayElementType(ty), AbsynUtil.dummyInfo);
exp := Expression.RANGE(ty, start_exp2, step_exp2, stop_exp2);
end if;
end simplifyRange;
function simplifyCall
input output Expression callExp;
protected
Call call;
list<Expression> args;
Boolean builtin, is_pure;
algorithm
Expression.CALL(call = call) := callExp;
callExp := match call
case Call.TYPED_CALL(arguments = args) guard not Call.isExternal(call)
algorithm
if Flags.isSet(Flags.NF_EXPAND_FUNC_ARGS) then
args := list(if Expression.hasArrayCall(arg) then arg else ExpandExp.expand(arg) for arg in args);
end if;
// HACK, TODO, FIXME! handle DynamicSelect properly in OMEdit, then disable this stuff!
if Flags.isSet(Flags.NF_API) and not Flags.isSet(Flags.NF_API_DYNAMIC_SELECT) then
if stringEq("DynamicSelect", AbsynUtil.pathString(Function.nameConsiderBuiltin(call.fn))) then
callExp := simplify(listHead(args));
return;
end if;
end if;
args := list(simplify(arg) for arg in args);
call.arguments := args;
builtin := Function.isBuiltin(call.fn);
is_pure := not Function.isImpure(call.fn);
// Use Ceval for builtin pure functions with literal arguments.
if builtin then
if is_pure and List.all(args, Expression.isLiteral) then
try
callExp := Ceval.evalCall(call, EvalTarget.IGNORE_ERRORS());
callExp := Expression.stripBindingInfo(callExp);
else
end try;
else
// do not expand builtin calls if we should not scalarize
if Flags.isSet(Flags.NF_SCALARIZE) then
callExp := simplifyBuiltinCall(Function.nameConsiderBuiltin(call.fn), args, call);
else
// nothing
end if;
end if;
elseif Flags.isSet(Flags.NF_EVAL_CONST_ARG_FUNCS) and is_pure and List.all(args, Expression.isLiteral) then
callExp := simplifyCall2(call);
else
callExp := Expression.CALL(call);
end if;
then
callExp;
case Call.TYPED_ARRAY_CONSTRUCTOR() then simplifyArrayConstructor(call);
case Call.TYPED_REDUCTION()
algorithm
call.exp := simplify(call.exp);
call.iters := list((Util.tuple21(i), simplify(Util.tuple22(i))) for i in call.iters);
then
Expression.CALL(call);
else callExp;
end match;
end simplifyCall;
function simplifyCall2
input Call call;
output Expression outExp;
algorithm
ErrorExt.setCheckpoint(getInstanceName());
try
outExp := Ceval.evalCall(call, EvalTarget.IGNORE_ERRORS());
outExp := Expression.stripBindingInfo(outExp);
ErrorExt.delCheckpoint(getInstanceName());
else
if Flags.isSet(Flags.FAILTRACE) then
ErrorExt.delCheckpoint(getInstanceName());
Debug.traceln("- " + getInstanceName() + " failed to evaluate " + Call.toString(call) + "\n");
else
ErrorExt.rollBack(getInstanceName());
end if;
outExp := Expression.CALL(call);
end try;
end simplifyCall2;
function simplifyBuiltinCall
input Absyn.Path name;
input list<Expression> args;
input Call call;
output Expression exp;
algorithm
exp := match AbsynUtil.pathFirstIdent(name)
case "cat"
algorithm
exp := ExpandExp.expandBuiltinCat(args, call);
then
exp;
case "sum" then simplifySumProduct(listHead(args), call, isSum = true);
case "product" then simplifySumProduct(listHead(args), call, isSum = false);
case "transpose" then simplifyTranspose(listHead(args), call);
else Expression.CALL(call);
end match;
end simplifyBuiltinCall;
function simplifySumProduct
input Expression arg;
input Call call;
input Boolean isSum;
output Expression exp;
protected
Boolean expanded;
list<Expression> args;
Type ty;
Operator op;
algorithm
(exp, expanded) := ExpandExp.expand(arg);
if expanded then
args := Expression.arrayScalarElements(exp);
ty := Type.arrayElementType(Expression.typeOf(arg));
if listEmpty(args) then
exp := if isSum then Expression.makeZero(ty) else Expression.makeOne(ty);
else
exp :: args := args;
op := if isSum then Operator.makeAdd(ty) else
Operator.makeMul(ty);
for e in args loop
exp := Expression.BINARY(exp, op, e);
end for;
end if;
else
exp := Expression.CALL(call);
end if;
end simplifySumProduct;
function simplifyTranspose
input Expression arg;
input Call call;
output Expression exp;
protected
Expression e;
algorithm
e := if Expression.hasArrayCall(arg) then arg else ExpandExp.expand(arg);
exp := match e
case Expression.ARRAY()
guard List.all(e.elements, Expression.isArray)
then Expression.transposeArray(e);
else Expression.CALL(call);
end match;
end simplifyTranspose;
function simplifyArrayConstructor
input Call call;
output Expression outExp;
protected
Type ty;
Variability var;
Expression exp, e;
list<tuple<InstNode, Expression>> iters;
InstNode iter;
Dimension dim;
Integer dim_size;
Boolean expanded;
algorithm
Call.TYPED_ARRAY_CONSTRUCTOR(ty, var, exp, iters) := call;
iters := list((Util.tuple21(i), simplify(Util.tuple22(i))) for i in iters);
outExp := matchcontinue (iters)
case {(iter, e)}
algorithm
Type.ARRAY(dimensions = {dim}) := Expression.typeOf(e);
dim_size := Dimension.size(dim);
if dim_size == 0 then
// Result is Array[0], return empty array expression.
outExp := Expression.makeEmptyArray(ty);
elseif dim_size == 1 then
// Result is Array[1], return array with the single element.
(Expression.ARRAY(elements = {e}), _) := ExpandExp.expand(e);
exp := Expression.replaceIterator(exp, iter, e);
exp := Expression.makeArray(ty, {exp});
outExp := simplify(exp);
else
fail();
end if;
then
outExp;
else
algorithm
exp := simplify(exp);
then
Expression.CALL(Call.TYPED_ARRAY_CONSTRUCTOR(ty, var, exp, iters));
end matchcontinue;
end simplifyArrayConstructor;
function simplifySize
input output Expression sizeExp;
algorithm
sizeExp := match sizeExp
local
Expression exp, index;
Dimension dim;
list<Dimension> dims;
case Expression.SIZE(exp, SOME(index))
algorithm
index := simplify(index);
if Expression.isLiteral(index) then
dim := listGet(Type.arrayDims(Expression.typeOf(exp)), Expression.toInteger(index));
if Dimension.isKnown(dim) then
exp := Expression.INTEGER(Dimension.size(dim));
else
exp := Expression.SIZE(exp, SOME(index));
end if;
else
exp := Expression.SIZE(exp, SOME(index));
end if;
then
exp;
case Expression.SIZE()
algorithm
dims := Type.arrayDims(Expression.typeOf(sizeExp.exp));
if List.all(dims, function Dimension.isKnown(allowExp = true)) then
exp := Expression.makeArray(Type.ARRAY(Type.INTEGER(), {Dimension.fromInteger(listLength(dims))}),
list(Dimension.sizeExp(d) for d in dims));
else
exp := sizeExp;
end if;
then
exp;
end match;
end simplifySize;
function simplifyBinary
input output Expression binaryExp;
protected
Expression e1, e2, se1, se2;
Operator op;
algorithm
Expression.BINARY(e1, op, e2) := binaryExp;
se1 := simplify(e1);
se2 := simplify(e2);
binaryExp := simplifyBinaryOp(se1, op, se2);
if Flags.isSet(Flags.NF_EXPAND_OPERATIONS) and not Expression.hasArrayCall(binaryExp) then
binaryExp := ExpandExp.expand(binaryExp);
end if;
end simplifyBinary;
function simplifyBinaryOp
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression outExp;
import NFOperator.Op;
algorithm
if Expression.isLiteral(exp1) and Expression.isLiteral(exp2) then
outExp := Ceval.evalBinaryOp(ExpandExp.expand(exp1), op, ExpandExp.expand(exp2));
outExp := Expression.stripBindingInfo(outExp);
else
outExp := match op.op
case Op.ADD then simplifyBinaryAdd(exp1, op, exp2);
case Op.SUB then simplifyBinarySub(exp1, op, exp2);
case Op.MUL then simplifyBinaryMul(exp1, op, exp2);
case Op.DIV then simplifyBinaryDiv(exp1, op, exp2);
case Op.POW then simplifyBinaryPow(exp1, op, exp2);
else Expression.BINARY(exp1, op, exp2);
end match;
end if;
end simplifyBinaryOp;
function simplifyBinaryAdd
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression outExp;
algorithm
if Expression.isZero(exp1) then
// 0 + e = e
outExp := exp2;
elseif Expression.isZero(exp2) then
// e + 0 = e
outExp := exp1;
elseif Expression.isNegated(exp2) then
// e1 + -(e2) = e1 - e2
outExp := Expression.BINARY(exp1, Operator.negate(op), Expression.negate(exp2));
else
outExp := Expression.BINARY(exp1, op, exp2);
end if;
end simplifyBinaryAdd;
function simplifyBinarySub
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression outExp;
algorithm
if Expression.isZero(exp1) then
// 0 - e = -e
outExp := Expression.UNARY(Operator.makeUMinus(Operator.typeOf(op)), exp2);
elseif Expression.isZero(exp2) then
// e - 0 = e
outExp := exp1;
elseif Expression.isNegated(exp2) then
// e1 - -(e2) = e1 + e2
outExp := Expression.BINARY(exp1, Operator.negate(op), Expression.negate(exp2));
else
outExp := Expression.BINARY(exp1, op, exp2);
end if;
end simplifyBinarySub;
function simplifyBinaryMul
input Expression exp1;
input Operator op;
input Expression exp2;
input Boolean switched = false;
output Expression outExp;
algorithm
outExp := match exp1
// 0 * e = 0
case Expression.INTEGER(value = 0) then exp1;
case Expression.REAL(value = 0.0) then exp1;
// 1 * e = e
case Expression.INTEGER(value = 1) then exp2;
case Expression.REAL(value = 1.0) then exp2;
else
if switched then
Expression.BINARY(exp2, op, exp1)
else
simplifyBinaryMul(exp2, op, exp1, true);
end match;
end simplifyBinaryMul;
function simplifyBinaryDiv
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression outExp;
algorithm
// e / 1 = e
if Expression.isOne(exp2) then
outExp := exp1;
else
outExp := Expression.BINARY(exp1, op, exp2);
end if;
end simplifyBinaryDiv;
function simplifyBinaryPow
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression outExp;
algorithm
if Expression.isZero(exp2) then
outExp := Expression.makeOne(Operator.typeOf(op));
elseif Expression.isOne(exp2) then
outExp := exp1;
else
outExp := Expression.BINARY(exp1, op, exp2);
end if;
end simplifyBinaryPow;
function simplifyUnary
input output Expression unaryExp;
protected
Expression e, se;
Operator op;
algorithm
Expression.UNARY(op, e) := unaryExp;
se := simplify(e);
unaryExp := simplifyUnaryOp(se, op);
if Flags.isSet(Flags.NF_EXPAND_OPERATIONS) and not Expression.hasArrayCall(unaryExp) then
unaryExp := ExpandExp.expand(unaryExp);
end if;
end simplifyUnary;
function simplifyUnaryOp
input Expression exp;
input Operator op;
output Expression outExp;
algorithm
if Expression.isLiteral(exp) then
outExp := Ceval.evalUnaryOp(exp, op);
outExp := Expression.stripBindingInfo(outExp);
else
outExp := Expression.UNARY(op, exp);
end if;
end simplifyUnaryOp;
function simplifyLogicBinary
input output Expression binaryExp;
protected
Expression e1, e2, se1, se2;
Operator op;
algorithm
Expression.LBINARY(e1, op, e2) := binaryExp;
se1 := simplify(e1);
se2 := simplify(e2);
binaryExp := match op.op
case Op.AND then simplifyLogicBinaryAnd(se1, op, se2);
case Op.OR then simplifyLogicBinaryOr(se1, op, se2);
end match;
end simplifyLogicBinary;
function simplifyLogicBinaryAnd
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression exp;
algorithm
exp := match (exp1, exp2)
local
list<Expression> expl;
Operator o;
// false and e => false
case (Expression.BOOLEAN(false), _) then exp1;
// e and false => false
case (_, Expression.BOOLEAN(false)) then exp2;
// true and e => e
case (Expression.BOOLEAN(true), _) then exp2;
// e and true => e
case (_, Expression.BOOLEAN(true)) then exp1;
case (Expression.ARRAY(), Expression.ARRAY())
algorithm
o := Operator.unlift(op);
expl := list(simplifyLogicBinaryAnd(e1, o, e2)
threaded for e1 in exp1.elements, e2 in exp2.elements);
then
Expression.makeArray(Operator.typeOf(op), expl);
else Expression.LBINARY(exp1, op, exp2);
end match;
end simplifyLogicBinaryAnd;
function simplifyLogicBinaryOr
input Expression exp1;
input Operator op;
input Expression exp2;
output Expression exp;
algorithm
exp := match (exp1, exp2)
local
list<Expression> expl;
Operator o;
// true or e => true
case (Expression.BOOLEAN(true), _) then exp1;
// e or true => true
case (_, Expression.BOOLEAN(true)) then exp2;
// false or e => e
case (Expression.BOOLEAN(false), _) then exp2;
// e or false => e
case (_, Expression.BOOLEAN(false)) then exp1;
case (Expression.ARRAY(), Expression.ARRAY())
algorithm
o := Operator.unlift(op);
expl := list(simplifyLogicBinaryAnd(e1, o, e2)
threaded for e1 in exp1.elements, e2 in exp2.elements);
then
Expression.makeArray(Operator.typeOf(op), expl);
else Expression.LBINARY(exp1, op, exp2);
end match;
end simplifyLogicBinaryOr;
function simplifyLogicUnary
input output Expression unaryExp;
protected
Expression e, se;
Operator op;
algorithm
Expression.LUNARY(op, e) := unaryExp;
se := simplify(e);
if Expression.isLiteral(se) then
unaryExp := Ceval.evalLogicUnaryOp(se, op);
unaryExp := Expression.stripBindingInfo(unaryExp);
elseif not referenceEq(e, se) then
unaryExp := Expression.LUNARY(op, se);
end if;
end simplifyLogicUnary;
function simplifyRelation
input output Expression relationExp;
protected
Expression e1, e2, se1, se2;
Operator op;
algorithm
Expression.RELATION(e1, op, e2) := relationExp;
se1 := simplify(e1);
se2 := simplify(e2);
if Expression.isLiteral(se1) and Expression.isLiteral(se2) then
relationExp := Ceval.evalRelationOp(se1, op, se2);
relationExp := Expression.stripBindingInfo(relationExp);
elseif not (referenceEq(e1, se1) and referenceEq(e2, se2)) then
relationExp := Expression.RELATION(se1, op, se2);
end if;
end simplifyRelation;
function simplifyIf
input output Expression ifExp;
protected
Type ty;
Expression cond, tb, fb;
algorithm
Expression.IF(ty, cond, tb, fb) := ifExp;
cond := simplify(cond);
ifExp := match cond
case Expression.BOOLEAN()
then simplify(if cond.value then tb else fb);
else
algorithm
tb := simplify(tb);
fb := simplify(fb);
then
if Expression.isEqual(tb, fb) then tb else Expression.IF(ty, cond, tb, fb);
end match;
end simplifyIf;
function simplifyCast
input Expression exp;
input Type ty;
output Expression castExp;
algorithm
castExp := match (ty, exp)
local
Type ety;
case (Type.REAL(), Expression.INTEGER())
then Expression.REAL(intReal(exp.value));
case (Type.ARRAY(elementType = Type.REAL()), Expression.ARRAY())
algorithm
ety := Type.unliftArray(ty);
exp.elements := list(simplifyCast(e, ety) for e in exp.elements);
exp.ty := Type.setArrayElementType(exp.ty, Type.arrayElementType(ty));
then
exp;
else Expression.CAST(ty, exp);
end match;
end simplifyCast;
function simplifySubscriptedExp
input output Expression subscriptedExp;
protected
Expression e;
list<Subscript> subs;
Type ty;
algorithm
Expression.SUBSCRIPTED_EXP(e, subs, ty) := subscriptedExp;
subscriptedExp := simplify(e);
subs := Subscript.simplifyList(subs, Type.arrayDims(Expression.typeOf(e)));
subscriptedExp := Expression.applySubscripts(subs, subscriptedExp);
end simplifySubscriptedExp;
function simplifyTupleElement
input output Expression tupleExp;
protected
Expression e;
Integer index;
Type ty;
algorithm
Expression.TUPLE_ELEMENT(e, index, ty) := tupleExp;
e := simplify(e);
tupleExp := Expression.tupleElement(e, ty, index);
end simplifyTupleElement;
annotation(__OpenModelica_Interface="frontend");
end NFSimplifyExp;