/
Static.mo
8506 lines (7978 loc) · 319 KB
/
Static.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
package Static "
This file is part of OpenModelica.
Copyright (c) 1998-2006, Linköpings universitet, Department of
Computer and Information Science, PELAB
All rights reserved.
(The new BSD license, see also
http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
Neither the name of Linköpings universitet nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
file: Static.mo
module: Static
description: Static analysis of expressions
RCS: $Id$
This module does static analysis on expressions.
The analyzed expressions are built using the
constructors in the `Exp\' module from expressions defined in \'Absyn\'.
Also, a set of properties of the expressions is calculated during analysis.
Properties of expressions include type information and a boolean indicating if the
expression is constant or not.
If the expression is constant, the \'Ceval\' module is used to evaluate the expression
value. A value of an expression is described using the \'Values\' module.
The main function in this module is \'eval_exp\' which takes an Absyn.Exp and transform it
into an Exp.Exp, while performing type checking and automatic type conversions, etc.
To determine types of builtin functions and operators, the module also contain an elaboration
handler for functions and operators. This function is called \'elab_builtin_handler\'.
NOTE: These functions should only determine the type and properties of the builtin functions and
operators and not evaluate them. Constant evaluation is performed by the \'Ceval\' module.
The module also contain a function for deoverloading of operators, in the \'deoverload\' function.
It transforms operators like \'+\' to its specific form, ADD, ADD_ARR, etc.
Interactive function calls are also given their types by \'elab_exp\', which calls
\'elab_call_interactive\'.
Elaboration for functions involve checking the types of the arguments by filling slots of the
argument list with first positional and then named arguments to find a matching function. The
details of this mechanism can be found in the Modelica specification.
The elaboration also contain function deoverloading which will be added to Modelica in the future.
"
public import Absyn;
public import Exp;
public import SCode;
public import Types;
public import Env;
public import Values;
public import Interactive;
public
type Ident = String;
public
uniontype Slot
record SLOT
Types.FuncArg an "An argument to a function" ;
Boolean true_ "True if the slot has been filled, i.e. argument has been given a value" ;
Option<Exp.Exp> expExpOption;
list<Types.ArrayDim> typesArrayDimLst;
end SLOT;
end Slot;
protected import ClassInf;
protected import Dump;
protected import Print;
protected import System;
protected import Lookup;
protected import Debug;
protected import Inst;
protected import Codegen;
protected import ModUtil;
protected import DAE;
protected import Util;
protected import Mod;
protected import Prefix;
protected import Ceval;
protected import Connect;
protected import Error;
public function elabExpList "Expression elaboration of Absyn.Exp list, i.e. lists of expressions."
input Env.Cache inCache;
input Env.Env inEnv;
input list<Absyn.Exp> inAbsynExpLst;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Boolean performVectorization;
output Env.Cache outCache;
output list<Exp.Exp> outExpExpLst;
output list<Types.Properties> outTypesPropertiesLst;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outExpExpLst,outTypesPropertiesLst,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inAbsynExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization)
local
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st,st_1,st_2;
Exp.Exp exp;
Types.Properties p;
list<Exp.Exp> exps;
list<Types.Properties> props;
list<Env.Frame> env;
Absyn.Exp e;
list<Absyn.Exp> rest;
Env.Cache cache;
Boolean doVect;
case (cache,_,{},impl,st,doVect) then (cache,{},{},st);
case (cache,env,(e :: rest),impl,st,doVect)
equation
(cache,exp,p,st_1) = elabExp(cache,env, e, impl, st,doVect);
(cache,exps,props,st_2) = elabExpList(cache,env, rest, impl, st_1,doVect);
then
(cache,(exp :: exps),(p :: props),st_2);
end matchcontinue;
end elabExpList;
public function elabExpListList "function: elabExpListList
Expression elaboration of lists of lists of expressions. Used in for
instance matrices, etc.
"
input Env.Cache inCache;
input Env.Env inEnv;
input list<list<Absyn.Exp>> inAbsynExpLstLst;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Boolean performVectorization;
output Env.Cache outCache;
output list<list<Exp.Exp>> outExpExpLstLst;
output list<list<Types.Properties>> outTypesPropertiesLstLst;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outExpExpLstLst,outTypesPropertiesLstLst,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inAbsynExpLstLst,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization)
local
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st,st_1,st_2;
list<Exp.Exp> exp;
list<Types.Properties> p;
list<list<Exp.Exp>> exps;
list<list<Types.Properties>> props;
list<Env.Frame> env;
list<Absyn.Exp> e;
list<list<Absyn.Exp>> rest;
Env.Cache cache;
Boolean doVect;
case (cache,_,{},impl,st,doVect) then (cache,{},{},st);
case (cache,env,(e :: rest),impl,st,doVect)
equation
(cache,exp,p,st_1) = elabExpList(cache,env, e, impl, st,doVect);
(cache,exps,props,st_2) = elabExpListList(cache,env, rest, impl, st_1,doVect);
then
(cache,(exp :: exps),(p :: props),st_2);
end matchcontinue;
end elabExpListList;
protected function cevalIfConstant "function: cevalIfConstant
This function calls Ceval.ceval if the Constant parameter indicates
C_CONST. If not constant, it also tries to simplify the expression using
Exp.simplify
"
input Env.Cache inCache;
input Exp.Exp inExp;
input Types.Properties inProperties;
input Types.Const inConst;
input Boolean inBoolean;
input Env.Env inEnv;
output Env.Cache outCache;
output Exp.Exp outExp;
output Types.Properties outProperties;
algorithm
(outCache,outExp,outProperties):=
matchcontinue (inCache,inExp,inProperties,inConst,inBoolean,inEnv)
local
Exp.Exp e_1,e;
String before, after;
Types.Properties prop;
Boolean impl;
Values.Value v;
tuple<Types.TType, Option<Absyn.Path>> vt;
Types.Const c,const;
list<Env.Frame> env;
Env.Cache cache;
case (cache,e,prop,Types.C_VAR(),_,_) /* impl */
equation
e_1 = Exp.simplify(e);
then
(cache,e_1,prop);
case (cache,e,prop,Types.C_PARAM(),_,_)
equation
e_1 = Exp.simplify(e);
then
(cache,e_1,prop);
case (cache,e,prop,Types.C_CONST(),(impl as true),_)
equation
e_1 = Exp.simplify(e);
then
(cache,e_1,prop);
case (cache,e,(prop as Types.PROP(constFlag = c)),Types.C_CONST(),impl,env) /* as false */
equation
(cache,v,_) = Ceval.ceval(cache,env, e, impl, NONE, NONE, Ceval.MSG());
e_1 = valueExp(v);
vt = valueType(v);
then
(cache,e_1,Types.PROP(vt,c));
case (cache,e,(prop as Types.PROP_TUPLE(tupleConst = c)),Types.C_CONST(),impl,env) /* as false */
local Types.TupleConst c;
equation
(cache,v,_) = Ceval.ceval(cache,env, e, impl, NONE, NONE, Ceval.MSG());
e_1 = valueExp(v);
vt = valueType(v);
then
(cache,e_1,Types.PROP_TUPLE(vt,c));
case (cache,e,prop,const,impl,env)
equation
e_1 = Exp.simplify(e);
then
(cache,e_1,prop);
end matchcontinue;
end cevalIfConstant;
public function elabExp "function: elabExp
Static analysis of expressions means finding out the properties of
the expression. These properties are described by the
`Types.Properties\' type, and include the type and the variability of the
expression. This function performs analysis, and returns an
`Exp.Exp\' and the properties.
"
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Exp inExp;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Boolean performVectorization;
output Env.Cache outCache;
output Exp.Exp outExp;
output Types.Properties outProperties;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outExp,outProperties,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inExp,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization)
local
Integer x,l,nmax;
Option<Integer> dim1,dim2;
Boolean impl,a,havereal;
Option<Interactive.InteractiveSymbolTable> st,st_1,st_2,st_3;
Ident id,expstr,envstr;
Exp.Exp exp,e1_1,e2_1,e1_2,e2_2,exp_1,exp_2,e_1,e_2,e3_1,start_1,stop_1,start_2,stop_2,step_1,step_2,mexp,mexp_1;
Types.Properties prop,prop_1,prop1,prop2,prop3;
list<Env.Frame> env;
Absyn.ComponentRef cr,fn;
tuple<Types.TType, Option<Absyn.Path>> t1,t2,rtype,t,start_t,stop_t,step_t,t_1,t_2,tp;
Types.Const c1,c2,c,c_start,c_stop,const,c_step;
list<tuple<Exp.Operator, list<tuple<Types.TType, Option<Absyn.Path>>>, tuple<Types.TType, Option<Absyn.Path>>>> ops;
Exp.Operator op_1;
Absyn.Exp e1,e2,e,e3,iterexp,start,stop,step;
Absyn.Operator op;
list<Absyn.Exp> args,rest,es;
list<Absyn.NamedArg> nargs;
list<Exp.Exp> es_1;
list<Types.Properties> props;
list<tuple<Types.TType, Option<Absyn.Path>>> types,tps_2;
list<Types.TupleConst> consts;
Exp.Type rt,at,tp_1;
list<list<Types.Properties>> tps;
list<list<tuple<Types.TType, Option<Absyn.Path>>>> tps_1;
Env.Cache cache;
Boolean doVect;
/* The types below should contain the default values of the attributes of the builtin
types. But since they are default, we can leave them out for now, unit=\"\" is not
that interesting to find out.
*/
case (cache,_,Absyn.INTEGER(value = x),impl,st,doVect) then (cache,Exp.ICONST(x),Types.PROP((Types.T_INTEGER({}),NONE),Types.C_CONST()),st);
case (cache,_,Absyn.REAL(value = x),impl,st,doVect)
local Real x;
then
(cache,Exp.RCONST(x),Types.PROP((Types.T_REAL({}),NONE),Types.C_CONST()),st);
case (cache,_,Absyn.STRING(value = x),impl,st,doVect)
local Ident x;
then
(cache,Exp.SCONST(x),Types.PROP((Types.T_STRING({}),NONE),Types.C_CONST()),st);
case (cache,_,Absyn.BOOL(value = x),impl,st,doVect)
local Boolean x;
then
(cache,Exp.BCONST(x),Types.PROP((Types.T_BOOL({}),NONE),Types.C_CONST()),st);
case (cache,_,Absyn.END(),impl,st,doVect)
then (cache,Exp.END(),Types.PROP((Types.T_INTEGER({}),NONE),Types.C_CONST()),st);
case (cache,env,Absyn.CREF(componentReg = cr),impl,st,doVect)
equation
(cache,exp,prop,_) = elabCref(cache,env, cr, impl,doVect);
then
(cache,exp,prop,st);
case (cache,env,(exp as Absyn.BINARY(exp1 = e1,op = op,exp2 = e2)),impl,st,doVect) /* Binary and unary operations */
local Absyn.Exp exp;
equation
(cache,e1_1,Types.PROP(t1,c1),st_1) = elabExp(cache,env, e1, impl, st,doVect);
(cache,e2_1,Types.PROP(t2,c2),st_2) = elabExp(cache,env, e2, impl, st_1,doVect);
c = Types.constAnd(c1, c2);
(cache,ops) = operators(cache,op, env, t1, t2);
(op_1,{e1_2,e2_2},rtype) = deoverload(ops, {(e1_1,t1),(e2_1,t2)}, exp);
exp_1 = replaceOperatorWithFcall(Exp.BINARY(e1_2,op_1,e2_2), c);
prop = Types.PROP(rtype,c);
(cache,exp_2,prop_1) = cevalIfConstant(cache,exp_1, prop, c, impl, env);
then
(cache,exp_2,prop_1,st_2);
case (cache,env,(exp as Absyn.UNARY(op = op,exp = e)),impl,st,doVect)
local Absyn.Exp exp;
equation
(cache,e_1,Types.PROP(t,c),st_1) = elabExp(cache,env, e, impl, st,doVect);
(cache,ops) = operators(cache,op, env, t, (Types.T_NOTYPE(),NONE));
(op_1,{e_2},rtype) = deoverload(ops, {(e_1,t)}, exp);
exp_1 = replaceOperatorWithFcall(Exp.UNARY(op_1,e_2), c);
prop = Types.PROP(rtype,c);
(cache,exp_2,prop_1) = cevalIfConstant(cache,exp_1, prop, c, impl, env);
then
(cache,exp_2,prop_1,st_1);
case (cache,env,(exp as Absyn.LBINARY(exp1 = e1,op = op,exp2 = e2)),impl,st,doVect)
local Absyn.Exp exp;
equation
(cache,e1_1,Types.PROP(t1,c1),st_1) = elabExp(cache,env, e1, impl, st,doVect) "Logical binary expressions" ;
(cache,e2_1,Types.PROP(t2,c2),st_2) = elabExp(cache,env, e2, impl, st_1,doVect);
c = Types.constAnd(c1, c2);
(cache,ops) = operators(cache,op, env, t1, t2);
(op_1,{e1_2,e2_2},rtype) = deoverload(ops, {(e1_1,t1),(e2_1,t2)}, exp);
exp_1 = replaceOperatorWithFcall(Exp.LBINARY(e1_2,op_1,e2_2), c);
prop = Types.PROP(rtype,c);
(cache,exp_2,prop_1) = cevalIfConstant(cache,exp_1, prop, c, impl, env);
then
(cache,exp_2,prop_1,st_2);
case (cache,env,(exp as Absyn.LUNARY(op = op,exp = e)),impl,st,doVect)
local Absyn.Exp exp;
equation
(cache,e_1,Types.PROP(t,c),st_1) = elabExp(cache,env, e, impl, st,doVect) "Logical unary expressions" ;
(cache,ops) = operators(cache,op, env, t, (Types.T_NOTYPE(),NONE));
(op_1,{e_2},rtype) = deoverload(ops, {(e_1,t)}, exp);
exp_1 = replaceOperatorWithFcall(Exp.LUNARY(op_1,e_2), c);
prop = Types.PROP(rtype,c);
(cache,exp_2,prop_1) = cevalIfConstant(cache,exp_1, prop, c, impl, env);
then
(cache,exp_2,prop_1,st_1);
case (cache,env,(exp as Absyn.RELATION(exp1 = e1,op = op,exp2 = e2)),impl,st,doVect)
local Absyn.Exp exp;
equation
(cache,e1_1,Types.PROP(t1,c1),st_1) = elabExp(cache,env, e1, impl, st,doVect) "Relations, e.g. a < b" ;
(cache,e2_1,Types.PROP(t2,c2),st_2) = elabExp(cache,env, e2, impl, st_1,doVect);
c = Types.constAnd(c1, c2);
(cache,ops) = operators(cache,op, env, t1, t2);
(op_1,{e1_2,e2_2},rtype) = deoverload(ops, {(e1_1,t1),(e2_1,t2)}, exp);
exp_1 = replaceOperatorWithFcall(Exp.RELATION(e1_2,op_1,e2_2), c);
prop = Types.PROP(rtype,c);
(cache,exp_2,prop_1) = cevalIfConstant(cache,exp_1, prop, c, impl, env);
then
(cache,exp_2,prop_1,st_2);
case (cache,env,Absyn.IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3),impl,st,doVect) /* Conditional expressions */
local Exp.Exp e;
equation
(cache,e1_1,prop1,st_1) = elabExp(cache,env, e1, impl, st,doVect) "if expressions" ;
(cache,e2_1,prop2,st_2) = elabExp(cache,env, e2, impl, st_1,doVect);
(cache,e3_1,prop3,st_3) = elabExp(cache,env, e3, impl, st_2,doVect);
(cache,e,prop) = elabIfexp(cache,env, e1_1, prop1, e2_1, prop2, e3_1, prop3, impl, st);
/* TODO elseif part */
then
(cache,e,prop,st_3);
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect)
local Exp.Exp e;
equation
Debug.fprintln("sei", "elab_exp CALL...") "Function calls PA. Only positional arguments are elaborated for now. TODO: Implement elaboration of named arguments." ;
(cache,e,prop,st_1) = elabCall(cache,env, fn, args, nargs, impl, st);
c = Types.propAllConst(prop);
(cache,e_1,prop_1) = cevalIfConstant(cache,e, prop, c, impl, env);
Debug.fprintln("sei", "elab_exp CALL done");
then
(cache,e_1,prop_1,st_1);
case (cache,env,Absyn.TUPLE(expressions = (e as (e1 :: rest))),impl,st,doVect) /* PR. Get the properties for each expression in the tuple.
Each expression has its own constflag.
!!The output from functions does just have one const flag.
Fix this!!
*/
local
list<Exp.Exp> e_1;
list<Absyn.Exp> e;
equation
(cache,e_1,props) = elabTuple(cache,env, e, impl,doVect) "Tuple function calls" ;
(types,consts) = splitProps(props);
then
(cache,Exp.TUPLE(e_1),Types.PROP_TUPLE((Types.T_TUPLE(types),NONE),Types.TUPLE_CONST(consts)),st);
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FOR_ITER_FARG(from = exp,var = id,to = iterexp)),impl,st,doVect) /* Array-related expressions Elab reduction expressions, including array() constructor */
local
Exp.Exp e;
Absyn.Exp exp;
equation
(cache,e,prop,st_1) = elabCallReduction(cache,env, fn, exp, id, iterexp, impl, st,doVect);
then
(cache,e,prop,st_1);
case (cache,env,Absyn.RANGE(start = start,step = NONE,stop = stop),impl,st,doVect)
equation
(cache,start_1,Types.PROP(start_t,c_start),st_1) = elabExp(cache,env, start, impl, st,doVect) "Range expressions without step value, e.g. 1:5" ;
(cache,stop_1,Types.PROP(stop_t,c_stop),st_2) = elabExp(cache,env, stop, impl, st_1,doVect);
(start_2,NONE,stop_2,rt) = deoverloadRange((start_1,start_t), NONE, (stop_1,stop_t));
const = Types.constAnd(c_start, c_stop);
(cache,t) = elabRangeType(cache,env, start_2, NONE, stop_2, const, rt, impl);
then
(cache,Exp.RANGE(rt,start_1,NONE,stop_1),Types.PROP(t,const),st_2);
case (cache,env,Absyn.RANGE(start = start,step = SOME(step),stop = stop),impl,st,doVect)
equation
(cache,start_1,Types.PROP(start_t,c_start),st_1) = elabExp(cache,env, start, impl, st,doVect) "Range expressions with step value, e.g. 1:0.5:4" ;
(cache,step_1,Types.PROP(step_t,c_step),st_2) = elabExp(cache,env, step, impl, st_1,doVect);
(cache,stop_1,Types.PROP(stop_t,c_stop),st_3) = elabExp(cache,env, stop, impl, st_2,doVect);
(start_2,SOME(step_2),stop_2,rt) = deoverloadRange((start_1,start_t), SOME((step_1,step_t)), (stop_1,stop_t));
c1 = Types.constAnd(c_start, c_step);
const = Types.constAnd(c1, c_stop);
(cache,t) = elabRangeType(cache,env, start_2, SOME(step_2), stop_2, const, rt, impl);
then
(cache,Exp.RANGE(rt,start_2,SOME(step_2),stop_2),Types.PROP(t,const),st_3);
case (cache,env,Absyn.ARRAY(arrayExp = es),impl,st,doVect)
equation
(cache,es_1,Types.PROP(t,const)) = elabArray(cache,env, es, impl, st,doVect) "array expressions, e.g. {1,2,3}" ;
l = listLength(es_1);
at = Types.elabType(t);
a = Types.isArray(t);
a = boolNot(a); // scalar = !array
then
(cache,Exp.ARRAY(at,a,es_1),Types.PROP((Types.T_ARRAY(Types.DIM(SOME(l)),t),NONE),const),st);
case (cache,env,Absyn.MATRIX(matrix = es),impl,st,doVect)
local list<list<Absyn.Exp>> es;
Integer d1,d2;
equation
(cache,_,tps,_) = elabExpListList(cache,env, es, impl, st,doVect) "matrix expressions, e.g. {1,0;0,1} with elements of simple type." ;
tps_1 = Util.listListMap(tps, Types.getPropType);
tps_2 = Util.listFlatten(tps_1);
nmax = matrixConstrMaxDim(tps_2);
havereal = Types.containReal(tps_2);
(cache,mexp,Types.PROP(t,c),dim1,dim2)
= elabMatrixSemi(cache,env, es, impl, st, havereal, nmax,doVect);
mexp = Util.if_(havereal,Exp.CAST(Exp.T_ARRAY(Exp.REAL(),{dim1,dim2}),mexp)
, mexp);
mexp=Exp.simplify(mexp); // to propagate cast down to scalar elts
mexp_1 = elabMatrixToMatrixExp(mexp);
t_1 = Types.unliftArray(t);
t_2 = Types.unliftArray(t_1) "All elts promoted to matrix, therefore unlifting" ;
then
(cache,mexp_1,Types.PROP(
(
Types.T_ARRAY(Types.DIM(dim1),
(Types.T_ARRAY(Types.DIM(dim2),t_2),NONE)),NONE),c),st);
case (cache,env,Absyn.CODE(code = c),impl,st,doVect)
local Absyn.CodeNode c;
equation
tp = elabCodeType(env, c) "Code expressions" ;
tp_1 = Types.elabType(tp);
then
(cache,Exp.CODE(c,tp_1),Types.PROP(tp,Types.C_CONST()),st);
case (cache,env,e,_,_,_)
equation
Debug.fprint("failtrace", "- elab_exp failed: ");
expstr = Debug.fcallret("failtrace", Dump.dumpExpStr, e, "");
Debug.fprintln("failtrace", expstr);
Debug.fprint("failtrace", "\n env : ");
envstr = Debug.fcallret("failtrace", Env.printEnvStr, env, "");
Debug.fprintln("failtrace", envstr);
Debug.fprintln("failtrace", "\n----------------------- FINISHED ENV ------------------------\n");
then
fail();
end matchcontinue;
end elabExp;
protected function elabMatrixGetDimensions "function: elabMatrixGetDimensions
Helper function to elab_exp (MATRIX). Calculates the dimensions of the
matrix by investigating the elaborated expression.
"
input Exp.Exp inExp;
output Integer outInteger1;
output Integer outInteger2;
algorithm
(outInteger1,outInteger2):=
matchcontinue (inExp)
local
Integer dim1,dim2;
list<Exp.Exp> lst2,lst;
case (Exp.ARRAY(array = lst))
equation
dim1 = listLength(lst);
(Exp.ARRAY(array = lst2) :: _) = lst;
dim2 = listLength(lst2);
then
(dim1,dim2);
end matchcontinue;
end elabMatrixGetDimensions;
protected function elabMatrixToMatrixExp "function: elabMatrixToMatrixExp
Convert an array expression (which is a matrix or higher dim.) to
a matrix expression (using MATRIX).
"
input Exp.Exp inExp;
output Exp.Exp outExp;
algorithm
outExp:=
matchcontinue (inExp)
local
list<list<tuple<Exp.Exp, Boolean>>> mexpl;
Integer dim;
Exp.Type a,elt_ty;
Boolean at;
Option<Integer> dim;
Integer d1;
list<Exp.Exp> expl;
Exp.Exp e;
case (Exp.ARRAY(ty = a,scalar = at,array = expl))
equation
mexpl = elabMatrixToMatrixExp2(expl);
d1 = listLength(mexpl);
a = Exp.liftArray(a,SOME(d1));
then
Exp.MATRIX(a,d1,mexpl);
case (e) then e; /* if fails, skip conversion, use generic array expression as is. */
end matchcontinue;
end elabMatrixToMatrixExp;
protected function elabMatrixToMatrixExp2 "function: elabMatrixToMatrixExp2
Helper function to elab_matrix_to_matrix_exp
"
input list<Exp.Exp> inExpExpLst;
output list<list<tuple<Exp.Exp, Boolean>>> outTplExpExpBooleanLstLst;
algorithm
(outTplExpExpBooleanLstLst):=
matchcontinue (inExpExpLst)
local
list<tuple<Exp.Exp, Boolean>> expl_1;
list<list<tuple<Exp.Exp, Boolean>>> es_1;
Exp.Type a;
Boolean at;
list<Exp.Exp> expl,es;
case ({}) then {};
case ((Exp.ARRAY(ty = a,scalar = at,array = expl) :: es))
equation
expl_1 = elabMatrixToMatrixExp3(expl);
es_1 = elabMatrixToMatrixExp2(es);
then
expl_1 :: es_1;
end matchcontinue;
end elabMatrixToMatrixExp2;
protected function elabMatrixToMatrixExp3
input list<Exp.Exp> inExpExpLst;
output list<tuple<Exp.Exp, Boolean>> outTplExpExpBooleanLst;
algorithm
outTplExpExpBooleanLst:=
matchcontinue (inExpExpLst)
local
Exp.Type tp;
Boolean scalar;
Ident s;
list<tuple<Exp.Exp, Boolean>> es_1;
Exp.Exp e;
list<Exp.Exp> es;
case ({}) then {};
case ((e :: es))
equation
tp = Exp.typeof(e);
scalar = Exp.typeBuiltin(tp);
s = Util.boolString(scalar);
es_1 = elabMatrixToMatrixExp3(es);
then
((e,scalar) :: es_1);
end matchcontinue;
end elabMatrixToMatrixExp3;
protected function matrixConstrMaxDim "function: matrixConstrMaxDim
Helper function to elab_exp (MATRIX).
Determines the maximum dimension of the array arguments to the matrix
constructor as.
max(2, ndims(A), ndims(B), ndims(C),..) for matrix constructor arguments
A, B, C, ...
"
input list<Types.Type> inTypesTypeLst;
output Integer outInteger;
algorithm
outInteger:=
matchcontinue (inTypesTypeLst)
local
Integer tn,tn2,res;
tuple<Types.TType, Option<Absyn.Path>> t;
list<tuple<Types.TType, Option<Absyn.Path>>> ts;
case ({}) then 2;
case ((t :: ts))
equation
tn = Types.ndims(t);
tn2 = matrixConstrMaxDim(ts);
res = intMax(tn, tn2);
then
res;
case (_)
equation
Debug.fprint("failtrace", "-matrix_constr_max_dim failed\n");
then
fail();
end matchcontinue;
end matrixConstrMaxDim;
protected function addForLoopScopeConst "function: addForLoopScopeConst
Creates a new scope on the environment used for loops and adds a loop
variable which is named by the second argument. The variable is given
the value 1 (one) such that elaboration of expressions of containing the
loop variable become constant.
"
input Env.Env env;
input Ident i;
input Types.Type typ;
output Env.Env env_2;
list<Env.Frame> env_1,env_2;
algorithm
env_1 := Env.openScope(env, false, SOME("$for loop scope$")) "encapsulated?" ;
env_2 := Env.extendFrameV(env_1,
Types.VAR(i,Types.ATTR(false,SCode.RW(),SCode.PARAM(),Absyn.BIDIR()),
false,typ,Types.VALBOUND(Values.INTEGER(1))), NONE, Env.VAR_UNTYPED(), {});
end addForLoopScopeConst;
protected function elabCallReduction "function: elabCallReduction
This function elaborates reduction expressions, that look like function
calls. For example an array constructor.
"
input Env.Cache inCache;
input Env.Env inEnv1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.Exp inExp3;
input Ident inIdent4;
input Absyn.Exp inExp5;
input Boolean inBoolean6;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption7;
input Boolean performVectorization;
output Env.Cache outCache;
output Exp.Exp outExp;
output Types.Properties outProperties;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outExp,outProperties,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv1,inComponentRef2,inExp3,inIdent4,inExp5,inBoolean6,inInteractiveInteractiveSymbolTableOption7,performVectorization)
local
Exp.Exp iterexp_1,exp_1;
Types.ArrayDim arraydim;
tuple<Types.TType, Option<Absyn.Path>> iterty,expty;
Types.Const iterconst,expconst,const;
list<Env.Frame> env_1,env;
Option<Interactive.InteractiveSymbolTable> st;
Types.Properties prop;
Absyn.Path fn_1;
Absyn.ComponentRef fn;
Absyn.Exp exp,iterexp;
Ident iter;
Boolean impl,doVect;
Env.Cache cache;
case (cache,env,fn,exp,iter,iterexp,impl,st,doVect)
equation
(cache,iterexp_1,Types.PROP((Types.T_ARRAY((arraydim as Types.DIM(_)),iterty),_),iterconst),_)
= elabExp(cache,env, iterexp, impl, st,doVect);
env_1 = addForLoopScopeConst(env, iter, iterty);
(cache,exp_1,Types.PROP(expty,expconst),st) = elabExp(cache,env_1, exp, impl, st,doVect) "const so that expr is elaborated to const" ;
const = Types.constAnd(expconst, iterconst);
prop = Types.PROP((Types.T_ARRAY(arraydim,expty),NONE),const);
fn_1 = Absyn.crefToPath(fn);
then
(cache,Exp.REDUCTION(fn_1,exp_1,iter,iterexp_1),prop,st);
end matchcontinue;
end elabCallReduction;
protected function replaceOperatorWithFcall "function: replaceOperatorWithFcall
Replaces a userdefined operator expression with a corresponding function
call expression. Other expressions just passes through.
"
input Exp.Exp inExp;
input Types.Const inConst;
output Exp.Exp outExp;
algorithm
outExp:=
matchcontinue (inExp,inConst)
local
Exp.Exp e1,e2,e;
Absyn.Path funcname;
Types.Const c;
case (Exp.BINARY(exp1 = e1,operator = Exp.USERDEFINED(fqName = funcname),exp2 = e2),c) then Exp.CALL(funcname,{e1,e2},false,false,Exp.OTHER());
case (Exp.UNARY(operator = Exp.USERDEFINED(fqName = funcname),exp = e1),c) then Exp.CALL(funcname,{e1},false,false,Exp.OTHER());
case (Exp.LBINARY(exp1 = e1,operator = Exp.USERDEFINED(fqName = funcname),exp2 = e2),c) then Exp.CALL(funcname,{e1,e2},false,false,Exp.OTHER());
case (Exp.LUNARY(operator = Exp.USERDEFINED(fqName = funcname),exp = e1),c) then Exp.CALL(funcname,{e1},false,false,Exp.OTHER());
case (Exp.RELATION(exp1 = e1,operator = Exp.USERDEFINED(fqName = funcname),exp2 = e2),c) then Exp.CALL(funcname,{e1,e2},false,false,Exp.OTHER());
case (e,_) then e;
end matchcontinue;
end replaceOperatorWithFcall;
protected function elabCodeType "function: elabCodeType
This function will construct the correct type for the given Code
expression. The types are built-in classes of different types. E.g.
the class TypeName is the type
of Code expressions corresponding to a type name Code expression.
"
input Env.Env inEnv;
input Absyn.CodeNode inCode;
output Types.Type outType;
algorithm
outType:=
matchcontinue (inEnv,inCode)
local list<Env.Frame> env;
case (env,Absyn.C_TYPENAME(path = _)) then ((Types.T_COMPLEX(ClassInf.UNKNOWN("TypeName"),{},NONE),NONE));
case (env,Absyn.C_VARIABLENAME(componentRef = _)) then ((Types.T_COMPLEX(ClassInf.UNKNOWN("VariableName"),{},NONE),
NONE));
case (env,Absyn.C_EQUATIONSECTION(boolean = _)) then ((
Types.T_COMPLEX(ClassInf.UNKNOWN("EquationSection"),{},NONE),NONE));
case (env,Absyn.C_ALGORITHMSECTION(boolean = _)) then ((
Types.T_COMPLEX(ClassInf.UNKNOWN("AlgorithmSection"),{},NONE),NONE));
case (env,Absyn.C_ELEMENT(element = _)) then ((Types.T_COMPLEX(ClassInf.UNKNOWN("Element"),{},NONE),NONE));
case (env,Absyn.C_EXPRESSION(exp = _)) then ((Types.T_COMPLEX(ClassInf.UNKNOWN("Expression"),{},NONE),
NONE));
case (env,Absyn.C_MODIFICATION(modification = _)) then ((Types.T_COMPLEX(ClassInf.UNKNOWN("Modification"),{},NONE),
NONE));
end matchcontinue;
end elabCodeType;
public function elabGraphicsExp "function elabGraphicsExp
This function is specially designed for elaboration of expressions when
investigating Modelica 2.0 graphical annotations.
These have an array of records representing graphical objects. These
elements can have different types, therefore elab_graphic_exp will allow
arrays with elements of varying types.
"
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Exp inExp;
input Boolean inBoolean;
output Env.Cache outCache;
output Exp.Exp outExp;
output Types.Properties outProperties;
algorithm
(outCache,outExp,outProperties):=
matchcontinue (inCache,inEnv,inExp,inBoolean)
local
Integer x,l,nmax;
Option<Integer> dim1,dim2;
Boolean impl,a,havereal;
Ident fnstr;
Exp.Exp exp,e1_1,e2_1,e1_2,e2_2,e_1,e_2,e3_1,start_1,stop_1,start_2,stop_2,step_1,step_2,mexp,mexp_1;
Types.Properties prop,prop1,prop2,prop3;
list<Env.Frame> env;
Absyn.ComponentRef cr,fn;
tuple<Types.TType, Option<Absyn.Path>> t1,t2,rtype,t,start_t,stop_t,step_t,t_1,t_2;
Types.Const c1,c2,c,c_start,c_stop,const,c_step;
list<tuple<Exp.Operator, list<tuple<Types.TType, Option<Absyn.Path>>>, tuple<Types.TType, Option<Absyn.Path>>>> ops;
Exp.Operator op_1;
Absyn.Exp e1,e2,e,e3,start,stop,step;
Absyn.Operator op;
list<Absyn.Exp> args,rest,es;
list<Absyn.NamedArg> nargs;
list<Exp.Exp> es_1;
list<Types.Properties> props;
list<tuple<Types.TType, Option<Absyn.Path>>> types,tps_2;
list<Types.TupleConst> consts;
Exp.Type rt,at;
list<list<Types.Properties>> tps;
list<list<tuple<Types.TType, Option<Absyn.Path>>>> tps_1;
Env.Cache cache;
case (cache,_,Absyn.INTEGER(value = x),impl) then (cache,Exp.ICONST(x),Types.PROP((Types.T_INTEGER({}),NONE),Types.C_CONST())); /* impl */
case (cache,_,Absyn.REAL(value = x),impl)
local Real x;
then
(cache,Exp.RCONST(x),Types.PROP((Types.T_REAL({}),NONE),Types.C_CONST()));
case (cache,_,Absyn.STRING(value = x),impl)
local Ident x;
then
(cache,Exp.SCONST(x),Types.PROP((Types.T_STRING({}),NONE),Types.C_CONST()));
case (cache,_,Absyn.BOOL(value = x),impl)
local Boolean x;
then
(cache,Exp.BCONST(x),Types.PROP((Types.T_BOOL({}),NONE),Types.C_CONST()));
case (cache,env,Absyn.CREF(componentReg = cr),impl)
equation
Debug.fprint("tcvt","before elabCref in elabGraphicsExp\n");
(cache,exp,prop,_) = elabCref(cache,env, cr, impl,true/*perform vectorization*/);
Debug.fprint("tcvt","after elabCref in elabGraphicsExp\n");
then
(cache,exp,prop);
case (cache,env,(exp as Absyn.BINARY(exp1 = e1,op = op,exp2 = e2)),impl) /* Binary and unary operations */
local Absyn.Exp exp;
equation
(cache,e1_1,Types.PROP(t1,c1)) = elabGraphicsExp(cache,env, e1, impl);
(cache,e2_1,Types.PROP(t2,c2)) = elabGraphicsExp(cache,env, e2, impl);
c = Types.constAnd(c1, c2);
(cache,ops) = operators(cache,op, env, t1, t2);
(op_1,{e1_2,e2_2},rtype) = deoverload(ops, {(e1_1,t1),(e2_1,t2)}, exp);
then
(cache,Exp.BINARY(e1_2,op_1,e2_2),Types.PROP(rtype,c));
case (cache,env,(exp as Absyn.UNARY(op = op,exp = e)),impl)
local Absyn.Exp exp;
equation
(cache,e_1,Types.PROP(t,c)) = elabGraphicsExp(cache,env, e, impl);
(cache,ops) = operators(cache,op, env, t, (Types.T_NOTYPE(),NONE));
(op_1,{e_2},rtype) = deoverload(ops, {(e_1,t)}, exp);
then
(cache,Exp.UNARY(op_1,e_2),Types.PROP(rtype,c));
case (cache,env,(exp as Absyn.LBINARY(exp1 = e1,op = op,exp2 = e2)),impl)
local Absyn.Exp exp;
equation
(cache,e1_1,Types.PROP(t1,c1)) = elabGraphicsExp(cache,env, e1, impl) "Logical binary expressions" ;
(cache,e2_1,Types.PROP(t2,c2)) = elabGraphicsExp(cache,env, e2, impl);
c = Types.constAnd(c1, c2);
(cache,ops) = operators(cache,op, env, t1, t2);
(op_1,{e1_2,e2_2},rtype) = deoverload(ops, {(e1_1,t1),(e2_1,t2)}, exp);
then
(cache,Exp.LBINARY(e1_2,op_1,e2_2),Types.PROP(rtype,c));
case (cache,env,(exp as Absyn.LUNARY(op = op,exp = e)),impl)
local Absyn.Exp exp;
equation
(cache,e_1,Types.PROP(t,c)) = elabGraphicsExp(cache,env, e, impl) "Logical unary expressions" ;
(cache,ops) = operators(cache,op, env, t, (Types.T_NOTYPE(),NONE));
(op_1,{e_2},rtype) = deoverload(ops, {(e_1,t)}, exp);
then
(cache,Exp.LUNARY(op_1,e_2),Types.PROP(rtype,c));
case (cache,env,(exp as Absyn.RELATION(exp1 = e1,op = op,exp2 = e2)),impl)
local Absyn.Exp exp;
equation
(cache,e1_1,Types.PROP(t1,c1)) = elabGraphicsExp(cache,env, e1, impl) "Relation expressions" ;
(cache,e2_1,Types.PROP(t2,c2)) = elabGraphicsExp(cache,env, e2, impl);
c = Types.constAnd(c1, c2);
(cache,ops) = operators(cache,op, env, t1, t2);
(op_1,{e1_2,e2_2},rtype) = deoverload(ops, {(e1_1,t1),(e2_1,t2)}, exp);
then
(cache,Exp.RELATION(e1_2,op_1,e2_2),Types.PROP(rtype,c));
case (cache,env,Absyn.IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3),impl) /* Conditional expressions */
local Exp.Exp e;
equation
(cache,e1_1,prop1) = elabGraphicsExp(cache,env, e1, impl);
(cache,e2_1,prop2) = elabGraphicsExp(cache,env, e2, impl);
(cache,e3_1,prop3) = elabGraphicsExp(cache,env, e3, impl);
(cache,e,prop) = elabIfexp(cache,env, e1_1, prop1, e2_1, prop2, e3_1, prop3, impl, NONE);
/* TODO elseif part */
then
(cache,e,prop);
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl) /* Function calls */
local Exp.Exp e;
equation
fnstr = Dump.printComponentRefStr(fn);
(cache,e,prop,_) = elabCall(cache,env, fn, args, nargs, true, NONE);
then
(cache,e,prop);
case (cache,env,Absyn.TUPLE(expressions = (e as (e1 :: rest))),impl) /* PR. Get the properties for each expression in the tuple.
Each expression has its own constflag.
!!The output from functions does just have one const flag.
Fix this!!
*/
local
list<Exp.Exp> e_1;
list<Absyn.Exp> e;
equation
(cache,e_1,props) = elabTuple(cache,env, e, impl,false);
(types,consts) = splitProps(props);
then
(cache,Exp.TUPLE(e_1),Types.PROP_TUPLE((Types.T_TUPLE(types),NONE),Types.TUPLE_CONST(consts)));
case (cache,env,Absyn.RANGE(start = start,step = NONE,stop = stop),impl) /* Array-related expressions */
equation
(cache,start_1,Types.PROP(start_t,c_start)) = elabGraphicsExp(cache,env, start, impl);
(cache,stop_1,Types.PROP(stop_t,c_stop)) = elabGraphicsExp(cache,env, stop, impl);
(start_2,NONE,stop_2,rt) = deoverloadRange((start_1,start_t), NONE, (stop_1,stop_t));
const = Types.constAnd(c_start, c_stop);
(cache,t) = elabRangeType(cache,env, start_2, NONE, stop_2, const, rt, impl);
then
(cache,Exp.RANGE(rt,start_1,NONE,stop_1),Types.PROP(t,const));
case (cache,env,Absyn.RANGE(start = start,step = SOME(step),stop = stop),impl)
equation
(cache,start_1,Types.PROP(start_t,c_start)) = elabGraphicsExp(cache,env, start, impl) "Debug.fprintln(\"setr\", \"elab_graphics_exp_range2\") &" ;
(cache,step_1,Types.PROP(step_t,c_step)) = elabGraphicsExp(cache,env, step, impl);
(cache,stop_1,Types.PROP(stop_t,c_stop)) = elabGraphicsExp(cache,env, stop, impl);
(start_2,SOME(step_2),stop_2,rt) = deoverloadRange((start_1,start_t), SOME((step_1,step_t)), (stop_1,stop_t));
c1 = Types.constAnd(c_start, c_step);
const = Types.constAnd(c1, c_stop);
(cache,t) = elabRangeType(cache,env, start_2, SOME(step_2), stop_2, const, rt, impl);
then
(cache,Exp.RANGE(rt,start_2,SOME(step_2),stop_2),Types.PROP(t,const));
case (cache,env,Absyn.ARRAY(arrayExp = es),impl)
equation
(cache,es_1,Types.PROP(t,const)) = elabGraphicsArray(cache,env, es, impl);
l = listLength(es_1);
at = Types.elabType(t);
a = Types.isArray(t);
then
(cache,Exp.ARRAY(at,a,es_1),Types.PROP((Types.T_ARRAY(Types.DIM(SOME(l)),t),NONE),const));
case (cache,env,Absyn.MATRIX(matrix = es),impl)
local list<list<Absyn.Exp>> es;
equation
(cache,_,tps,_) = elabExpListList(cache,env, es, impl, NONE,true);
tps_1 = Util.listListMap(tps, Types.getPropType);
tps_2 = Util.listFlatten(tps_1);
nmax = matrixConstrMaxDim(tps_2);
havereal = Types.containReal(tps_2);
(cache,mexp,Types.PROP(t,c),dim1,dim2) = elabMatrixSemi(cache,env, es, impl, NONE, havereal, nmax,true);
at = Types.elabType(t);
mexp_1 = elabMatrixToMatrixExp(mexp);
t_1 = Types.unliftArray(t);
t_2 = Types.unliftArray(t_1);
then
(cache,mexp,Types.PROP(
(
Types.T_ARRAY(Types.DIM(dim1),
(Types.T_ARRAY(Types.DIM(dim2),t_2),NONE)),NONE),c));
case (cache,_,e,impl)
local Ident es;
equation
Print.printErrorBuf("- elab_graphics_exp failed: ");
es = Dump.printExpStr(e);
Print.printErrorBuf(es);
Print.printErrorBuf("\n");
then
fail();
end matchcontinue;
end elabGraphicsExp;
protected function deoverloadRange "function: deoverloadRange
Does deoverloading of range expressions. They can be both Integer ranges
and Real ranges. This function determines which one to use.
"
input tuple<Exp.Exp, Types.Type> inTplExpExpTypesType1;
input Option<tuple<Exp.Exp, Types.Type>> inTplExpExpTypesTypeOption2;
input tuple<Exp.Exp, Types.Type> inTplExpExpTypesType3;
output Exp.Exp outExp1;
output Option<Exp.Exp> outExpExpOption2;
output Exp.Exp outExp3;
output Exp.Type outType4;
algorithm
(outExp1,outExpExpOption2,outExp3,outType4):=
matchcontinue (inTplExpExpTypesType1,inTplExpExpTypesTypeOption2,inTplExpExpTypesType3)
local
Exp.Exp e1,e3,e2,e1_1,e3_1,e2_1;
tuple<Types.TType, Option<Absyn.Path>> t1,t3,t2;
case ((e1,(Types.T_INTEGER(varLstInt = _),_)),NONE,(e3,(Types.T_INTEGER(varLstInt = _),_))) then (e1,NONE,e3,Exp.INT());
case ((e1,(Types.T_INTEGER(varLstInt = _),_)),SOME((e2,(Types.T_INTEGER(_),_))),(e3,(Types.T_INTEGER(varLstInt = _),_))) then (e1,SOME(e2),e3,Exp.INT());
case ((e1,t1),NONE,(e3,t3))
equation
({e1_1,e3_1},_) = elabArglist({(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},
{(e1,t1),(e3,t3)});
then
(e1_1,NONE,e3_1,Exp.REAL());
case ((e1,t1),SOME((e2,t2)),(e3,t3))
equation
({e1_1,e2_1,e3_1},_) = elabArglist(
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE),
(Types.T_REAL({}),NONE)}, {(e1,t1),(e2,t2),(e3,t3)});
then
(e1_1,SOME(e2_1),e3_1,Exp.REAL());
end matchcontinue;
end deoverloadRange;
protected function elabRangeType "function: elabRangeType