/
Ceval.mo
5598 lines (5222 loc) · 191 KB
/
Ceval.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
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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 Ceval
" file: Ceval.mo
package: Ceval
description: Constant propagation of expressions
This module handles constant propagation (or evaluation)
When elaborating expressions, in the Static module, expressions are checked to
find out its type. It also checks whether the expressions are constant and the function
ceval in this module will then evaluate the expression to a constant value, defined
in the Values module.
Input:
Env: Environment with bindings
Exp: Expression to check for constant evaluation
Bool flag determines whether the current instantiation is implicit
InteractiveSymbolTable is optional, and used in interactive mode, e.g. from OMShell
Output:
Value: The evaluated value
InteractiveSymbolTable: Modified symbol table
Subscript list : Evaluates subscripts and generates constant expressions."
public import Absyn;
public import AbsynUtil;
public import DAE;
public import FCore;
public import FGraph;
public import FNode;
public import InstTypes;
public import Values;
public import Lookup;
// protected imports
protected
import AvlTreeStringString;
protected import BackendInterface;
protected import ComponentReference;
protected import Config;
protected import Debug;
protected import Error;
protected import Expression;
protected import ExpressionDump;
protected import ExpressionSimplify;
protected import Flags;
protected import InstBinding;
protected import InstUtil;
protected import List;
protected import ModelicaExternalC;
protected import Prefix;
protected import Print;
protected import SCode;
import SCodeUtil;
protected import Static;
protected import System;
protected import Types;
protected import Util;
protected import ValuesUtil;
protected import ClassInf;
protected import Global;
protected import MetaModelica.Dangerous.listReverseInPlace;
public function ceval "
This function is used when the value of a constant expression is
needed. It takes an environment and an expression and calculates
its value.
The third argument indicates whether the evaluation is performed in the
interactive environment (implicit instantiation), in which case function
calls are evaluated.
The last argument is an optional dimension."
input FCore.Cache inCache;
input FCore.Graph inEnv;
input DAE.Exp inExp;
input Boolean inBoolean "impl";
input Absyn.Msg inMsg = Absyn.MSG(AbsynUtil.dummyInfo);
input Integer numIter = 0 "Maximum recursion depth";
output FCore.Cache outCache;
output Values.Value outValue;
algorithm
(outCache,outValue) := cevalWork1(inCache,inEnv,inExp,inBoolean,inMsg,numIter,numIter > Global.recursionDepthLimit);
end ceval;
protected function cevalWork1
input FCore.Cache inCache;
input FCore.Graph inEnv;
input DAE.Exp inExp;
input Boolean inBoolean "impl";
input Absyn.Msg inMsg;
input Integer numIter "Maximum recursion depth";
input Boolean iterReached;
output FCore.Cache outCache;
output Values.Value outValue;
algorithm
(outCache,outValue) := match (inCache,inEnv,inExp,inBoolean,inMsg,numIter,iterReached)
local
SourceInfo info;
String str1,str2,str3;
case (_,_,_,_,_,_,false)
equation
(outCache,outValue) = cevalWork2(inCache,inEnv,inExp,inBoolean,inMsg,numIter);
then (outCache,outValue);
case (_,_,_,_,Absyn.MSG(info=info),_,true)
equation
str1 = intString(Global.recursionDepthLimit);
str2 = ExpressionDump.printExpStr(inExp);
Error.addSourceMessage(Error.RECURSION_DEPTH_WARNING, {str1,str2,FGraph.printGraphPathStr(inEnv)}, info);
then fail();
end match;
end cevalWork1;
protected function cevalWork2 "
This function is used when the value of a constant expression is
needed. It takes an environment and an expression and calculates
its value.
The third argument indicates whether the evaluation is performed in the
interactive environment (implicit instantiation), in which case function
calls are evaluated.
The last argument is an optional dimension."
input FCore.Cache inCache;
input FCore.Graph inEnv;
input DAE.Exp inExp;
input Boolean inBoolean "impl";
input Absyn.Msg inMsg;
input Integer numIter;
output FCore.Cache outCache;
output Values.Value outValue;
partial function ReductionOperator
input Values.Value v1;
input Values.Value v2;
output Values.Value res;
end ReductionOperator;
algorithm
(outCache,outValue):=
matchcontinue (inCache,inEnv,inExp,inBoolean,inMsg,numIter)
local
Integer start_1,stop_1,step_1,i,indx_1,indx,index;
Real lhvReal,rhvReal,sum,r,realStart1,realStop1,realStep1;
String str,lhvStr,rhvStr,s,foldName,resultName;
Boolean impl,b,b_1,lhvBool,rhvBool,resBool, bstart, bstop;
Absyn.Exp exp_1,exp;
FCore.Graph env;
Absyn.Msg msg;
Absyn.Element elt_1,elt;
Absyn.CodeNode c;
list<Values.Value> es_1,elts,vallst,vlst1,vlst2,reslst,aval,rhvals,lhvals,arr,arr_1,ivals,rvals,vals;
list<DAE.Exp> es,expl;
list<list<DAE.Exp>> expll;
Values.Value v,newval,value,sval,elt1,elt2,v_1,lhs_1,rhs_1,resVal,lhvVal,rhvVal;
DAE.Exp lh,rh,e,lhs,rhs,start,stop,step,e1,e2,cond;
Absyn.Path funcpath, name, recName;
DAE.Operator relop;
FCore.Cache cache;
DAE.Exp expExp;
list<Integer> dims;
DAE.Dimensions arrayDims;
DAE.ComponentRef cr;
list<String> fieldNames, n, names;
DAE.Type t;
DAE.Exp daeExp;
Absyn.Path path;
Option<Values.Value> ov;
Option<DAE.Exp> foldExp;
DAE.Type ty;
list<DAE.Type> tys;
DAE.ReductionIterators iterators;
list<list<Values.Value>> valMatrix;
SourceInfo info;
list<Values.Value> orderd;
list<String> comp;
DAE.ClockKind ck;
Absyn.ReductionIterType iterType;
// uncomment for debugging
// case (cache,env,inExp,_,_,_)
// equation print("Ceval.ceval: " + ExpressionDump.printExpStr(inExp) + " in env: " + FGraph.printGraphPathStr(env) + "\n");
// then fail();
case (cache,_,DAE.ICONST(integer = i),_,_,_) then (cache,Values.INTEGER(i));
case (cache,_,DAE.RCONST(real = r),_,_,_) then (cache,Values.REAL(r));
case (cache,_,DAE.SCONST(string = s),_,_,_) then (cache,Values.STRING(s));
case (cache,_,DAE.BCONST(bool = b),_,_,_) then (cache,Values.BOOL(b));
case (cache,_,DAE.ENUM_LITERAL(name = name, index = i),_,_,_)
then (cache, Values.ENUM_LITERAL(name, i));
case (cache,env,DAE.CODE(code = Absyn.C_EXPRESSION(exp = exp)),impl,msg,_)
equation
(cache, exp_1) = cevalAstExp(cache, env, exp, impl, msg, AbsynUtil.dummyInfo);
then
(cache,Values.CODE(Absyn.C_EXPRESSION(exp_1)));
case (cache,env,DAE.CODE(code = Absyn.C_ELEMENT(element = elt)),impl,msg,_)
equation
(cache,elt_1) = cevalAstElt(cache,env, elt, impl, msg);
then
(cache,Values.CODE(Absyn.C_ELEMENT(elt_1)));
case (cache,_,DAE.CODE(code = c),_,_,_) then (cache,Values.CODE(c));
case (cache,env,DAE.ARRAY(array = es, ty = DAE.T_ARRAY(dims = arrayDims)),impl,msg,_)
equation
(cache, es_1) = cevalList(cache, env, es, impl, msg, numIter);
v =
matchcontinue()
case ()
equation
dims = List.map(arrayDims, Expression.dimensionSize);
v = Values.ARRAY(es_1,dims);
then v;
else
equation
v = ValuesUtil.makeArray(es_1);
then
v;
end matchcontinue;
then
(cache,v);
case (cache,env,DAE.MATRIX(matrix = expll, ty = DAE.T_ARRAY(dims = arrayDims)),impl,msg,_)
equation
dims = List.map(arrayDims, Expression.dimensionSize);
(cache,elts) = cevalMatrixElt(cache, env, expll, impl,msg,numIter+1);
then
(cache,Values.ARRAY(elts,dims));
// MetaModelica
case (cache,env,DAE.LIST(valList = expl),impl,msg,_)
equation
(cache,es_1) = cevalList(cache,env, expl, impl, msg,numIter);
then
(cache,Values.LIST(es_1));
case (cache,env,DAE.BOX(exp=e1),impl,msg,_)
equation
(cache,v) = ceval(cache,env,e1,impl,msg,numIter+1);
then
(cache,v);
case (cache,env,DAE.UNBOX(exp=e1),impl,msg,_)
equation
(cache,Values.META_BOX(v)) = ceval(cache,env,e1,impl,msg,numIter+1);
then
(cache,v);
case (cache,env,DAE.CONS(car=e1,cdr=e2),impl,msg,_)
equation
(cache,v) = ceval(cache,env,e1,impl,msg,numIter+1);
(cache,Values.LIST(vallst)) = ceval(cache,env,e2,impl,msg,numIter);
then
(cache,Values.LIST(v::vallst));
// MetaModelica Partial Function
case (_,_,DAE.CREF(componentRef = cr, ty = DAE.T_FUNCTION_REFERENCE_VAR()),
_, _, _)
then
fail();
// MetaModelica Uniontype Constructor
case (cache,env,DAE.METARECORDCALL(path=funcpath,args=expl,fieldNames=fieldNames,index=index),impl,msg,_)
equation
(cache,vallst) = cevalList(cache, env, expl, impl, msg,numIter);
then (cache,Values.RECORD(funcpath,vallst,fieldNames,index));
// MetaModelica Option type. sjoelund 2009-07-01
case (cache,_,DAE.META_OPTION(NONE()),_,_,_)
then (cache,Values.OPTION(NONE()));
case (cache,env,DAE.META_OPTION(SOME(expExp)),impl,msg,_)
equation
(cache,value) = ceval(cache,env,expExp,impl,msg,numIter+1);
then (cache,Values.OPTION(SOME(value)));
// MetaModelica Tuple. sjoelund 2009-07-02
case (cache,env,DAE.META_TUPLE(expl),impl,msg,_)
equation
true = Config.acceptMetaModelicaGrammar();
(cache,vallst) = cevalList(cache, env, expl, impl, msg,numIter);
then (cache,Values.META_TUPLE(vallst));
case (cache,env,DAE.TUPLE(expl),impl,msg,_)
equation
// true = Config.acceptMetaModelicaGrammar();
(cache,vallst) = cevalList(cache, env, expl, impl, msg,numIter);
then (cache,Values.TUPLE(vallst));
case (cache,env,DAE.CREF(componentRef = cr),(false),msg,_)
equation
(cache,v) = cevalCref(cache, env, cr, false, msg, numIter+1) "When in interactive mode, always evaluate crefs, i.e non-implicit mode.." ;
//Debug.traceln("cevalCref cr: " + ComponentReference.printComponentRefStr(c) + " in s: " + FGraph.printGraphPathStr(env) + " v:" + ValuesUtil.valString(v));
then
(cache,v);
case (cache,env,DAE.CREF(componentRef = cr),impl,msg,_)
equation
(cache,v) = cevalCref(cache,env, cr, impl,msg,numIter+1);
//Debug.traceln("cevalCref cr: " + ComponentReference.printComponentRefStr(c) + " in s: " + FGraph.printGraphPathStr(env) + " v:" + ValuesUtil.valString(v));
then
(cache,v);
// Evaluates for build in types. ADD, SUB, MUL, DIV for Reals and Integers.
case (cache,env,expExp,impl,msg,_)
equation
(cache,v) = cevalBuiltin(cache,env, expExp, impl, msg,numIter+1);
then
(cache,v);
// ceval smooth(0, expr) -> expr
case (cache, env, (DAE.CALL(path=funcpath, expLst={DAE.ICONST(0), expExp}, attr=DAE.CALL_ATTR(isImpure=false))), impl, msg,_)
equation
Absyn.IDENT("smooth") = AbsynUtil.makeNotFullyQualified(funcpath);
(cache,value) = ceval(cache,env,expExp,impl,msg,numIter+1);
then
(cache,value);
// adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem
// lochel: do not evaluate impure function calls
case (cache, env, (e as DAE.CALL(path=funcpath, expLst=expl, attr=DAE.CALL_ATTR(isImpure=false))), impl, msg,_)
equation
// do not handle Connection.isRoot here!
false = AbsynUtil.pathEqual(Absyn.QUALIFIED("Connection",Absyn.IDENT("isRoot")), funcpath);
// do not roll back errors generated by evaluating the arguments
(cache, vallst) = cevalList(cache, env, expl, impl, msg,numIter);
(cache, newval)= BackendInterface.cevalCallFunction(cache, env, e, vallst, impl, msg,numIter+1);
then
(cache,newval);
// Cast of records (Check done by static, so ok to just evaluate the expression and return)
case(cache,env,DAE.CAST(ty = ty,exp = e),impl,msg,_)
equation
true = Types.isRecord(ty);
(cache,value) = ceval(cache, env, e, impl, msg, numIter+1);
then (cache,value);
// Try Interactive functions last
case (cache,env,(e as DAE.CALL()),(true),msg,_)
equation
(cache,value) = BackendInterface.cevalInteractiveFunctions(cache, env, e, msg,numIter+1);
then
(cache,value);
case (_,_,e as DAE.CALL(),_,_,_)
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("- Ceval.ceval DAE.CALL failed: ");
str = ExpressionDump.printExpStr(e);
Debug.traceln(str);
then
fail();
case (cache, env, DAE.RECORD(path=funcpath, exps=expl, comp = fieldNames), impl, msg,_)
equation
(cache, vallst) = cevalList(cache, env, expl, impl, msg,numIter);
then
(cache,Values.RECORD(funcpath,vallst,fieldNames,-1));
// Strings
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.ADD(ty = DAE.T_STRING()),exp2 = rh),impl,msg,_)
equation
(cache,Values.STRING(lhvStr)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.STRING(rhvStr)) = ceval(cache,env, rh, impl, msg,numIter);
str = stringAppend(lhvStr, rhvStr);
then
(cache,Values.STRING(str));
// Numerical
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.ADD(ty = DAE.T_REAL()),exp2 = rh),impl,msg,_)
equation
(cache,Values.REAL(lhvReal)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.REAL(rhvReal)) = ceval(cache,env, rh, impl, msg,numIter);
sum = lhvReal + rhvReal;
then
(cache,Values.REAL(sum));
// Array addition
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.ADD_ARR(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(vlst1,dims)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(vlst2,_)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.addElementwiseArrayelt(vlst1, vlst2);
then
(cache,Values.ARRAY(reslst,dims));
// Array subtraction
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.SUB_ARR(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(vlst1,dims)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(vlst2,_)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.subElementwiseArrayelt(vlst1, vlst2);
then
(cache,Values.ARRAY(reslst,dims));
// Array multiplication
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL_ARR(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(vlst1,dims)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(vlst2,_)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.mulElementwiseArrayelt(vlst1, vlst2);
then
(cache,Values.ARRAY(reslst,dims));
// Array division
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.DIV_ARR(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(vlst1,dims)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(vlst2,_)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.divElementwiseArrayelt(vlst1, vlst2);
then
(cache,Values.ARRAY(reslst,dims));
// Array power
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.POW_ARR2(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(vlst1,dims)) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(vlst2,_)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.powElementwiseArrayelt(vlst1, vlst2);
then
(cache,Values.ARRAY(reslst,dims));
// Array multipled scalar
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL_ARRAY_SCALAR(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, rh, impl, msg,numIter);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, lh, impl, msg,numIter);
reslst = ValuesUtil.multScalarArrayelt(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// Array add scalar
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.ADD_ARRAY_SCALAR(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, rh, impl, msg,numIter);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, lh, impl, msg,numIter);
reslst = ValuesUtil.addScalarArrayelt(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// Array subtract scalar
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.SUB_SCALAR_ARRAY(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.subScalarArrayelt(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// Array power scalar
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.POW_SCALAR_ARRAY(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.powScalarArrayelt(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// Array power scalar
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.POW_ARRAY_SCALAR(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, rh, impl, msg,numIter);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, lh, impl, msg,numIter);
reslst = ValuesUtil.powArrayeltScalar(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// scalar div array
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.DIV_SCALAR_ARRAY(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, lh, impl, msg,numIter);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, rh, impl, msg,numIter);
reslst = ValuesUtil.divScalarArrayelt(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// array div scalar
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.DIV_ARRAY_SCALAR(),exp2 = rh),impl,msg,_)
equation
(cache,sval) = ceval(cache,env, rh, impl, msg,numIter+1);
(cache,Values.ARRAY(aval,dims)) = ceval(cache,env, lh, impl, msg,numIter);
reslst = ValuesUtil.divArrayeltScalar(sval, aval);
then
(cache,Values.ARRAY(reslst,dims));
// scalar multiplied array
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL_SCALAR_PRODUCT(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(valueLst = rhvals)) = ceval(cache,env, rh, impl, msg,numIter);
(cache,Values.ARRAY(valueLst = lhvals)) = ceval(cache,env, lh, impl, msg,numIter);
resVal = ValuesUtil.multScalarProduct(rhvals, lhvals);
then
(cache,resVal);
// array multipled array
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL_MATRIX_PRODUCT(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(valueLst = (lhvals as (elt1 :: _)))) = ceval(cache,env, lh, impl, msg,numIter) "{{..}..{..}} {...}" ;
(cache,Values.ARRAY(valueLst = (rhvals as (elt2 :: _)))) = ceval(cache,env, rh, impl, msg,numIter);
true = ValuesUtil.isArray(elt1);
false = ValuesUtil.isArray(elt2);
resVal = ValuesUtil.multScalarProduct(lhvals, rhvals);
then
(cache,resVal);
// array multiplied array
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL_MATRIX_PRODUCT(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY(valueLst = (rhvals as (elt1 :: _)))) = ceval(cache,env, rh, impl, msg,numIter) "{...} {{..}..{..}}" ;
(cache,Values.ARRAY(valueLst = (lhvals as (elt2 :: _)))) = ceval(cache,env, lh, impl, msg,numIter);
true = ValuesUtil.isArray(elt1);
false = ValuesUtil.isArray(elt2);
resVal = ValuesUtil.multScalarProduct(lhvals, rhvals);
then
(cache,resVal);
// array multiplied array
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL_MATRIX_PRODUCT(),exp2 = rh),impl,msg,_)
equation
(cache,Values.ARRAY((rhvals as (elt1 :: _)),_)) = ceval(cache,env, rh, impl, msg,numIter+1) "{{..}..{..}} {{..}..{..}}" ;
(cache,Values.ARRAY((lhvals as (elt2 :: _)),_)) = ceval(cache,env, lh, impl, msg,numIter+1);
true = ValuesUtil.isArray(elt1);
true = ValuesUtil.isArray(elt2);
vallst = ValuesUtil.multMatrix(lhvals, rhvals);
then
(cache,ValuesUtil.makeArray(vallst));
//POW (integer or real)
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.POW(),exp2 = rh),impl,msg,_)
equation
(cache,lhvVal) = ceval(cache,env, lh, impl, msg,numIter);
(cache,rhvVal) = ceval(cache,env, rh, impl, msg,numIter);
resVal = ValuesUtil.safeIntRealOp(lhvVal, rhvVal, Values.POWOP());
then
(cache,resVal);
//MUL (integer or real)
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.MUL(),exp2 = rh),impl,msg,_)
equation
(cache,lhvVal) = ceval(cache,env, lh, impl, msg,numIter);
(cache,rhvVal) = ceval(cache,env, rh, impl, msg,numIter);
resVal = ValuesUtil.safeIntRealOp(lhvVal, rhvVal, Values.MULOP());
then
(cache,resVal);
//DIV (integer or real)
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.DIV(),exp2 = rh),impl,msg,_)
equation
(cache,lhvVal) = ceval(cache,env, lh, impl, msg,numIter);
(cache,rhvVal) = ceval(cache,env, rh, impl, msg,numIter);
resVal = ValuesUtil.safeIntRealOp(lhvVal, rhvVal, Values.DIVOP());
then
(cache,resVal);
//DIV (handle div by zero)
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.DIV(), exp2 = rh),
impl, msg as Absyn.MSG(info = info),_)
equation
(_,lhvVal) = ceval(cache,env, rh, impl, msg,numIter);
true = ValuesUtil.isZero(lhvVal);
lhvStr = ExpressionDump.printExpStr(lh);
rhvStr = ExpressionDump.printExpStr(rh);
Error.addSourceMessage(Error.DIVISION_BY_ZERO, {lhvStr,rhvStr}, info);
then
fail();
//ADD (integer or real)
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.ADD(),exp2 = rh),impl,msg,_)
equation
(cache,lhvVal) = ceval(cache,env, lh, impl, msg,numIter);
(cache,rhvVal) = ceval(cache,env, rh, impl, msg,numIter);
resVal = ValuesUtil.safeIntRealOp(lhvVal, rhvVal, Values.ADDOP());
then
(cache,resVal);
//SUB (integer or real)
case (cache,env,DAE.BINARY(exp1 = lh,operator = DAE.SUB(),exp2 = rh),impl,msg,_)
equation
(cache,lhvVal) = ceval(cache,env, lh, impl, msg,numIter);
(cache,rhvVal) = ceval(cache,env, rh, impl, msg,numIter);
resVal = ValuesUtil.safeIntRealOp(lhvVal, rhvVal, Values.SUBOP());
then
(cache,resVal);
// unary minus of array
case (cache,env,DAE.UNARY(operator = DAE.UMINUS_ARR(),exp = daeExp),impl,msg,_)
equation
(cache,Values.ARRAY(arr,dims)) = ceval(cache,env, daeExp, impl, msg,numIter+1);
arr_1 = List.map(arr, ValuesUtil.valueNeg);
then
(cache,Values.ARRAY(arr_1,dims));
// unary minus of expression
case (cache,env,DAE.UNARY(operator = DAE.UMINUS(),exp = daeExp),impl,msg,_)
equation
(cache,v) = ceval(cache,env, daeExp, impl, msg,numIter+1);
v_1 = ValuesUtil.valueNeg(v);
then
(cache,v_1);
// Logical lhs AND rhs (handle lhs = false)
case (cache,env,DAE.LBINARY(exp1 = lh,operator = DAE.AND(_),exp2 = rh),impl,msg,_)
equation
(cache,Values.BOOL(lhvBool)) = ceval(cache,env, lh, impl, msg,numIter);
if not lhvBool then
v = Values.BOOL(false);
else
(cache,Values.BOOL(rhvBool)) = ceval(cache,env, rh, impl, msg,numIter);
resBool = boolAnd(lhvBool, rhvBool);
v = Values.BOOL(resBool);
end if;
then
(cache,v);
// lhs OR rhs (handle lhs = true)
case (cache,env,DAE.LBINARY(exp1 = lh,operator = DAE.OR(_),exp2 = rh),impl,msg,_)
equation
(cache,Values.BOOL(lhvBool)) = ceval(cache, env, lh, impl, msg, numIter);
if lhvBool then
v = Values.BOOL(true);
else
(cache,Values.BOOL(rhvBool)) = ceval(cache, env, rh, impl, msg, numIter);
resBool = boolOr(lhvBool, rhvBool);
v = Values.BOOL(resBool);
end if;
then
(cache,v);
// Special case for a boolean expression like if( expression or ARRAY_IDEX_OUT_OF_BOUNDS_ERROR)
// "expression" in this case we return the lh expression to be equall to
// the previous c-code generation.
case (cache,env,DAE.LBINARY(exp1 = lh,operator = DAE.OR(_),exp2 = rh),impl,msg,_)
equation
(cache,v as Values.BOOL(_)) = ceval(cache,env, lh, impl,msg,numIter);
failure(ceval(cache,env, rh, impl, msg, numIter));
then
(cache,v);
// NOT
case (cache,env,DAE.LUNARY(operator = DAE.NOT(_),exp = e),impl,msg,_)
equation
(cache,Values.BOOL(b)) = ceval(cache,env, e, impl, msg,numIter+1);
b_1 = boolNot(b);
then
(cache,Values.BOOL(b_1));
// relations <, >, <=, >=, <>
case (cache,env,DAE.RELATION(exp1 = lhs,operator = relop,exp2 = rhs),impl,msg,_)
equation
(cache,lhs_1) = ceval(cache,env, lhs, impl,msg,numIter);
(cache,rhs_1) = ceval(cache,env, rhs, impl,msg,numIter);
v = cevalRelation(lhs_1, relop, rhs_1);
then
(cache,v);
case (cache, env, DAE.RANGE(ty = DAE.T_BOOL(), start = start, step = NONE(),stop = stop), impl, msg,_)
equation
(cache, Values.BOOL(bstart)) = ceval(cache, env, start, impl, msg,numIter+1);
(cache, Values.BOOL(bstop)) = ceval(cache, env, stop, impl, msg,numIter+1);
arr = List.map(ExpressionSimplify.simplifyRangeBool(bstart, bstop),
ValuesUtil.makeBoolean);
then
(cache, ValuesUtil.makeArray(arr));
// range first:last for integers
case (cache,env,DAE.RANGE(ty = DAE.T_INTEGER(),start = start,step = NONE(),stop = stop),impl,msg,_)
equation
(cache,Values.INTEGER(start_1)) = ceval(cache,env, start, impl, msg,numIter+1);
(cache,Values.INTEGER(stop_1)) = ceval(cache,env, stop, impl, msg,numIter+1);
arr = List.map(ExpressionSimplify.simplifyRange(start_1, 1, stop_1), ValuesUtil.makeInteger);
then
(cache,ValuesUtil.makeArray(arr));
// range first:step:last for integers
case (cache,env,DAE.RANGE(ty = DAE.T_INTEGER(),start = start,step = SOME(step),stop = stop),impl,msg,_)
equation
(cache,Values.INTEGER(start_1)) = ceval(cache,env, start, impl, msg,numIter+1);
(cache,Values.INTEGER(step_1)) = ceval(cache,env, step, impl, msg,numIter+1);
(cache,Values.INTEGER(stop_1)) = ceval(cache,env, stop, impl, msg,numIter+1);
arr = List.map(ExpressionSimplify.simplifyRange(start_1, step_1, stop_1), ValuesUtil.makeInteger);
then
(cache,ValuesUtil.makeArray(arr));
// range first:last for enumerations.
case (cache,env,DAE.RANGE(ty = t as DAE.T_ENUMERATION(),start = start,step = NONE(),stop = stop),impl,msg,_)
equation
(cache,Values.ENUM_LITERAL(index = start_1)) = ceval(cache,env, start, impl, msg,numIter+1);
(cache,Values.ENUM_LITERAL(index = stop_1)) = ceval(cache,env, stop, impl, msg,numIter+1);
arr = cevalRangeEnum(start_1, stop_1, t);
then
(cache,ValuesUtil.makeArray(arr));
// range first:last for reals
case (cache,env,DAE.RANGE(ty = DAE.T_REAL(),start = start,step = NONE(),stop = stop),impl,msg,_)
equation
(cache,Values.REAL(realStart1)) = ceval(cache,env, start, impl, msg,numIter+1);
(cache,Values.REAL(realStop1)) = ceval(cache,env, stop, impl, msg,numIter+1);
// diff = realStop1 - realStart1;
realStep1 = intReal(1);
arr = List.map(ExpressionSimplify.simplifyRangeReal(realStart1, realStep1, realStop1), ValuesUtil.makeReal);
then
(cache,ValuesUtil.makeArray(arr));
// range first:step:last for reals
case (cache,env,DAE.RANGE(ty = DAE.T_REAL(),start = start,step = SOME(step),stop = stop),impl,msg,_)
equation
(cache,Values.REAL(realStart1)) = ceval(cache,env, start, impl, msg,numIter+1);
(cache,Values.REAL(realStep1)) = ceval(cache,env, step, impl, msg,numIter+1);
(cache,Values.REAL(realStop1)) = ceval(cache,env, stop, impl, msg,numIter+1);
arr = List.map(ExpressionSimplify.simplifyRangeReal(realStart1, realStep1, realStop1), ValuesUtil.makeReal);
then
(cache,ValuesUtil.makeArray(arr));
// cast integer to real
case (cache,env,DAE.CAST(ty = DAE.T_REAL(),exp = e),impl,msg,_)
equation
(cache,Values.INTEGER(i)) = ceval(cache,env, e, impl, msg,numIter+1);
r = intReal(i);
then
(cache,Values.REAL(r));
// cast real to integer
case (cache,env,DAE.CAST(ty = DAE.T_INTEGER(), exp = e),impl,msg,_)
equation
(cache,Values.REAL(r)) = ceval(cache, env, e, impl,msg,numIter+1);
i = realInt(r);
then
(cache,Values.INTEGER(i));
// cast integer to enum
case (cache,env,DAE.CAST(ty = DAE.T_ENUMERATION(path = path, names = n), exp = e), impl, msg,_)
equation
(cache, Values.INTEGER(i)) = ceval(cache, env, e, impl, msg,numIter+1);
str = listGet(n, i);
path = AbsynUtil.joinPaths(path, Absyn.IDENT(str));
then
(cache, Values.ENUM_LITERAL(path, i));
// cast integer array to real array
case (cache,env,DAE.CAST(ty = DAE.T_ARRAY(ty = DAE.T_REAL()),exp = e),impl,msg,_)
equation
(cache,Values.ARRAY(ivals,dims)) = ceval(cache,env, e, impl, msg,numIter+1);
rvals = ValuesUtil.typeConvert(DAE.T_INTEGER_DEFAULT, DAE.T_REAL_DEFAULT, ivals);
then
(cache,Values.ARRAY(rvals,dims));
// if expressions, select then/else branch if condition is true/false
case (cache,env,DAE.IFEXP(expCond = cond,expThen = e1,expElse = e2),impl,msg,_)
equation
(cache,v) = ceval(cache, env, cond, impl, msg, numIter+1);
// ifexp true then then branch, else else branch"
Values.BOOL(resBool) = v;
(cache, v) = ceval(cache, env, if resBool then e1 else e2, impl, msg,numIter);
then
(cache,v);
// indexing for array[integer index]
case (cache,env,DAE.ASUB(exp = e,sub = ((DAE.ICONST(indx))::{})),impl,msg,_)
equation
(cache,Values.ARRAY(vals,_)) = ceval(cache,env, e, impl, msg,numIter+1) "asub" ;
v = listGet(vals, indx);
then
(cache,v);
// indexing for array[subscripts]
case (cache, env, DAE.ASUB(exp = e,sub = expl ), impl, msg,_)
equation
(cache,Values.ARRAY(vals,dims)) = ceval(cache,env, e, impl, msg,numIter+1);
(cache,es_1) = cevalList(cache,env, expl, impl, msg,numIter);
v = listHead(es_1);
v = ValuesUtil.nthnthArrayelt(es_1,Values.ARRAY(vals,dims),v);
then
(cache,v);
// indexing for tuple[index]
case (cache, env, DAE.TSUB(exp = e,ix = indx), impl, msg,_)
equation
(cache,Values.TUPLE(vals)) = ceval(cache,env, e, impl, msg,numIter+1);
v = listGet(vals, indx);
then
(cache,v);
case (cache, env, DAE.REDUCTION(reductionInfo=DAE.REDUCTIONINFO(iterType = iterType, path = path, foldName=foldName, resultName=resultName, foldExp = foldExp, defaultValue = ov, exprType = ty), expr = daeExp, iterators = iterators), impl, msg,_)
equation
env = FGraph.openScope(env, SCode.NOT_ENCAPSULATED(), FCore.forScopeName, NONE());
(cache, valMatrix, names, dims, tys) = cevalReductionIterators(cache, env, iterators, impl, msg,numIter+1);
// print("Before:\n");print(stringDelimitList(List.map1(List.mapList(valMatrix, ValuesUtil.valString), stringDelimitList, ","), "\n") + "\n");
valMatrix = makeReductionAllCombinations(valMatrix,iterType);
// print("After:\n");print(stringDelimitList(List.map1(List.mapList(valMatrix, ValuesUtil.valString), stringDelimitList, ","), "\n") + "\n");
// print("Start cevalReduction: " + AbsynUtil.pathString(path) + " " + ExpressionDump.printExpStr(daeExp) + "\n");
(cache, ov) = cevalReduction(cache, env, path, ov, daeExp, ty, foldName, resultName, foldExp, names, listReverse(valMatrix), tys, impl, msg,numIter+1);
value = Util.getOptionOrDefault(ov, Values.META_FAIL());
value = backpatchArrayReduction(path, iterType, value, dims);
then (cache, value);
case (_, _, DAE.EMPTY(), _, _, _)
algorithm
s := ComponentReference.printComponentRefStr(inExp.name);
v := Types.typeToValue(inExp.ty);
then
(inCache, Values.EMPTY(inExp.scope, s, v, inExp.tyStr));
case (_,_,_,_,_,_) guard Config.getGraphicsExpMode()
algorithm
ty := Expression.typeof(inExp);
v := Types.typeToValue(ty);
then (inCache, Values.EMPTY("#graphicsExp#", ExpressionDump.printExpStr(inExp), v, Types.unparseType(ty)));
// ceval can fail and that is ok, caught by other rules...
case (_,env,e,_,_,_) // Absyn.MSG())
equation
true = Flags.isSet(Flags.CEVAL);
Debug.traceln("- Ceval.ceval failed: " + ExpressionDump.printExpStr(e));
Debug.traceln(" Scope: " + FGraph.printGraphPathStr(env));
// Debug.traceln(" Env:" + FGraph.printGraphStr(env));
then
fail();
end matchcontinue;
end cevalWork2;
public function cevalIfConstant
"This function constant evaluates an expression if the expression is constant,
or if the expression is a call of parameter constness whose return type
contains unknown dimensions (in which case we need to determine the size of
those dimensions)."
input output FCore.Cache cache;
input FCore.Graph inEnv;
input output DAE.Exp exp;
input output DAE.Properties prop;
input Boolean impl;
input SourceInfo inInfo;
algorithm
if Expression.isEvaluatedConst(exp) then
// Don't mess up the dimensions, etc by using the Values module
return;
end if;
(cache, exp, prop) := matchcontinue prop
local
Values.Value v;
DAE.Type tp;
case DAE.PROP(constFlag = DAE.C_PARAM(), type_ = tp)
// BoschRexroth specifics
guard not Flags.getConfigBool(Flags.CEVAL_EQUATION)
then (cache, exp, DAE.PROP(tp, DAE.C_VAR()));
case DAE.PROP(constFlag = DAE.C_CONST(), type_ = tp)
algorithm
(cache, v) := ceval(cache, inEnv, exp, impl, Absyn.MSG(inInfo), 0);
exp := ValuesUtil.valueExp(v,SOME(exp));
exp := ValuesUtil.fixZeroSizeArray(exp, tp);
then (cache, exp, prop);
case DAE.PROP_TUPLE()
algorithm
DAE.C_CONST() := Types.propAllConst(prop);
(cache, v) := ceval(cache, inEnv, exp, false, Absyn.MSG(inInfo), 0);
exp := ValuesUtil.valueExp(v, SOME(exp));
then (cache, exp, prop);
case DAE.PROP_TUPLE()
// BoschRexroth specifics
guard not Flags.getConfigBool(Flags.CEVAL_EQUATION)
algorithm
DAE.C_PARAM() := Types.propAllConst(prop);
print(" tuple non constant evaluation not implemented yet\n");
then fail();
case _
// Structural parameters and the like... we can ceval them if we want to
guard Expression.isConst(exp) and not Config.acceptMetaModelicaGrammar()
algorithm
(_, v) := ceval(cache, inEnv, exp, impl, Absyn.MSG(inInfo), 0);
exp := ValuesUtil.valueExp(v,SOME(exp));
exp := ValuesUtil.fixZeroSizeArray(exp, Types.getPropType(prop));
then (cache, exp, prop);
else
algorithm
// If we fail to evaluate, at least we should simplify the expression
(exp,_) := ExpressionSimplify.simplify1(exp);
then (cache, exp, prop);
end matchcontinue;
end cevalIfConstant;
protected function cevalWholedimRetCall
"Helper function to cevalIfConstant. Determines the size of any unknown
dimensions in a function calls return type."
input DAE.Exp inExp;
input FCore.Cache inCache;
input FCore.Graph inEnv;
input SourceInfo inInfo;
input Integer numIter;
output DAE.Exp outExp;
output DAE.Properties outProp;
algorithm
(outExp, outProp) := match(inExp, inCache, inEnv, inInfo, numIter)
local
DAE.Exp e;
Absyn.Path p;
list<DAE.Exp> el;
Boolean t, b, isImpure, isFunctionPointerCall;
DAE.InlineType i;
DAE.Dimensions dims;
Values.Value v;
DAE.Type cevalType, ty;
DAE.TailCall tc;
DAE.CallAttributes attr;
case (e as DAE.CALL(path = p, expLst = el, attr = attr as DAE.CALL_ATTR(ty = DAE.T_ARRAY(dims = dims))), _, _, _, _)
equation
true = Expression.arrayContainWholeDimension(dims);
(_, v) = ceval(inCache, inEnv, e, true, Absyn.MSG(inInfo), numIter+1);
ty = Types.typeOfValue(v);
cevalType = Types.simplifyType(ty);
attr.ty = cevalType;
then
(DAE.CALL(p, el, attr), DAE.PROP(ty, DAE.C_PARAM()));
end match;
end cevalWholedimRetCall;
public function cevalRangeIfConstant
"Constant evaluates the limits of a range if they are constant."
input FCore.Cache inCache;
input FCore.Graph inEnv;
input DAE.Exp inExp;
input DAE.Properties inProp;
input Boolean impl;
input SourceInfo inInfo;
output FCore.Cache outCache;
output DAE.Exp outExp;
algorithm
(outCache, outExp) := matchcontinue(inCache, inEnv, inExp, inProp, impl, inInfo)
local
DAE.Exp e1, e2;
Option<DAE.Exp> e3;
DAE.Type ty;
FCore.Cache cache;
case (_, _, DAE.RANGE(ty = ty, start = e1, stop = e2, step = e3), _, _, _)
equation
(cache, e1, _) = cevalIfConstant(inCache, inEnv, e1, inProp, impl, inInfo);
(_, e2, _) = cevalIfConstant(cache, inEnv, e2, inProp, impl, inInfo);
then
(inCache, DAE.RANGE(ty, e1, e3, e2));
else (inCache, inExp);
end matchcontinue;
end cevalRangeIfConstant;
protected function cevalBuiltin
"Helper for ceval. Parts for builtin calls are moved here, for readability.
See ceval for documentation.
NOTE: It\'s ok if cevalBuiltin fails. Just means the call was not a builtin function"
input FCore.Cache inCache;
input FCore.Graph inEnv;
input DAE.Exp inExp;
input Boolean inBoolean "impl";
input Absyn.Msg inMsg;
input Integer numIter;
output FCore.Cache outCache;
output Values.Value outValue;
partial function HandlerFunc
input FCore.Cache inCache;
input FCore.Graph inEnvFrameLst;
input list<DAE.Exp> inExpExpLst;
input Boolean inBoolean;
input Absyn.Msg inMsg;
input Integer numIter;