/
Static.mo
13946 lines (13039 loc) · 553 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
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linköping University,
* 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
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköping University, 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.
*
*/
package Static
" file: Static.mo
package: 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 evalExp which takes an Absyn.Exp and transform it
into an DAE.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 elabBuiltinHandler.
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 elabExp, which calls
elabCallInteractive.
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 ConnectionGraph;
public import Convert;
public import DAE;
public import Env;
public import Interactive;
public import MetaUtil;
public import RTOpts;
public import SCode;
public import SCodeUtil;
public import Values;
public import Prefix;
public type Ident = String;
public
uniontype Slot
record SLOT
DAE.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<DAE.Exp> expExpOption;
list<DAE.Dimension> typesArrayDimLst;
end SLOT;
end Slot;
protected import Ceval;
protected import ClassInf;
protected import Connect;
protected import Debug;
protected import Dump;
protected import Error;
protected import ErrorExt;
protected import Exp;
protected import Inst;
protected import InstSection;
protected import InnerOuter;
protected import Lookup;
protected import Mod;
protected import ModUtil;
protected import OptManager;
protected import Print;
protected import System;
protected import Types;
protected import UnitAbsyn;
protected import Util;
protected import ValuesUtil;
protected import DAEUtil;
protected import PrefixUtil;
protected import CevalScript;
// protected import AbsynDep;
protected constant DAE.Exp defaultOutputFormat = DAE.SCONST("plt");
public type Prefix = Prefix.Prefix "a prefix";
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;
input Prefix inPrefix;
output Env.Cache outCache;
output list<DAE.Exp> outExpExpLst;
output list<DAE.Properties> outTypesPropertiesLst;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
output DAE.DAElist outDae "contain functions";
algorithm
(outCache,outExpExpLst,outTypesPropertiesLst,outInteractiveInteractiveSymbolTableOption,outDae):=
matchcontinue (inCache,inEnv,inAbsynExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization,inPrefix)
local
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st,st_1,st_2;
DAE.Exp exp;
DAE.Properties p;
list<DAE.Exp> exps;
list<DAE.Properties> props;
list<Env.Frame> env;
Absyn.Exp e;
list<Absyn.Exp> rest;
Env.Cache cache;
Boolean doVect;
DAE.DAElist dae,dae1,dae2;
Prefix pre;
case (cache,_,{},impl,st,doVect,_) then (cache,{},{},st,DAEUtil.emptyDae);
case (cache,env,(e :: rest),impl,st,doVect,pre)
equation
(cache,exp,p,st_1,dae1) = elabExp(cache,env, e, impl, st,doVect,pre);
(cache,exps,props,st_2,dae2) = elabExpList(cache,env, rest, impl, st_1,doVect,pre);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,(exp :: exps),(p :: props),st_2,dae);
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;
input Prefix inPrefix;
output Env.Cache outCache;
output list<list<DAE.Exp>> outExpExpLstLst;
output list<list<DAE.Properties>> outTypesPropertiesLstLst;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
output DAE.DAElist outDae "contain functions";
algorithm
(outCache,outExpExpLstLst,outTypesPropertiesLstLst,outInteractiveInteractiveSymbolTableOption,outDae):=
matchcontinue (inCache,inEnv,inAbsynExpLstLst,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization,inPrefix)
local
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st,st_1,st_2;
list<DAE.Exp> exp;
list<DAE.Properties> p;
list<list<DAE.Exp>> exps;
list<list<DAE.Properties>> props;
list<Env.Frame> env;
list<Absyn.Exp> e;
list<list<Absyn.Exp>> rest;
Env.Cache cache;
Boolean doVect;
DAE.DAElist dae,dae1,dae2;
Prefix pre;
case (cache,_,{},impl,st,doVect,_) then (cache,{},{},st,DAEUtil.emptyDae);
case (cache,env,(e :: rest),impl,st,doVect,pre)
equation
(cache,exp,p,st_1,dae1) = elabExpList(cache,env, e, impl, st,doVect,pre);
(cache,exps,props,st_2,dae2) = elabExpListList(cache,env, rest, impl, st_1,doVect,pre);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,(exp :: exps),(p :: props),st_2,dae);
end matchcontinue;
end elabExpListList;
public function elabExp "
function: elabExp
Static analysis of expressions means finding out the properties of
the expression. These properties are described by the
`DAE.Properties\' type, and include the type and the variability of the
expression. This function performs analysis, and returns an
`DAE.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;
input Prefix inPrefix;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProperties;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
output DAE.DAElist outDae "contains functions";
algorithm
(outCache,outExp,outProperties,outInteractiveInteractiveSymbolTableOption,outDae):=
matchcontinue (inCache,inEnv,inExp,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization,inPrefix)
local
Integer x,l,nmax;
DAE.Dimension dim1,dim2;
Boolean impl,a,havereal;
Option<Interactive.InteractiveSymbolTable> st,st_1,st_2,st_3;
Ident id,expstr,envstr;
DAE.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;
DAE.Properties prop,prop_1,prop1,prop2,prop3;
list<Env.Frame> env;
Absyn.ComponentRef cr,fn;
DAE.Type t1,t2,arrtp,rtype,t,start_t,stop_t,step_t,t_1,t_2,tp;
DAE.Const c1,c2,c,c_start,c_stop,const,c_step;
list<tuple<DAE.Operator, list<tuple<DAE.TType, Option<Absyn.Path>>>, tuple<DAE.TType, Option<Absyn.Path>>>> ops;
DAE.Operator op_1;
Absyn.Exp e,e1,e2,e,e3,iterexp,start,stop,step;
Absyn.Operator op;
list<Absyn.Exp> args,rest,es;
list<Absyn.NamedArg> nargs;
list<DAE.Exp> es_1;
list<DAE.Properties> props;
list<tuple<DAE.TType, Option<Absyn.Path>>> types,tps_2;
list<DAE.TupleConst> consts;
DAE.ExpType rt,at,tp_1;
list<list<DAE.Properties>> tps;
list<list<tuple<DAE.TType, Option<Absyn.Path>>>> tps_1;
Env.Cache cache;
Boolean doVect;
Absyn.ForIterators iterators;
DAE.DAElist dae1,dae2,dae3,dae;
Prefix pre;
/* uncomment for debuging
case (cache,_,inExp,impl,st,doVect,_)
equation
print("Static.elabExp: " +& Dump.dumpExpStr(inExp) +& "\n");
then
fail();
*/
// 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,DAE.ICONST(x),DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_CONST()),st,DAEUtil.emptyDae);
case (cache,_,Absyn.REAL(value = x),impl,st,doVect,_)
local Real x;
then
(cache,DAE.RCONST(x),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_CONST()),st,DAEUtil.emptyDae);
case (cache,_,Absyn.STRING(value = x),impl,st,doVect,_)
local Ident x;
then
(cache,DAE.SCONST(x),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_CONST()),st,DAEUtil.emptyDae);
case (cache,_,Absyn.BOOL(value = x),impl,st,doVect,_)
local Boolean x;
then
(cache,DAE.BCONST(x),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST()),st,DAEUtil.emptyDae);
case (cache,_,Absyn.END(),impl,st,doVect,_)
then (cache,DAE.END(),DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_CONST()),st,DAEUtil.emptyDae);
case (cache,env,Absyn.CREF(componentRef = cr),impl,st,doVect,pre) // BoschRexroth specifics
local DAE.Type ty;
equation
false = OptManager.getOption("cevalEquation");
(cache,exp,prop as DAE.PROP(ty,DAE.C_PARAM()),_,dae) = elabCref(cache,env, cr, impl,doVect,pre);
then
(cache,exp,DAE.PROP(ty,DAE.C_VAR()),st,dae);
case (cache,env,Absyn.CREF(componentRef = cr),impl,st,doVect,pre)
equation
(cache,exp,prop,_,dae) = elabCref(cache,env, cr, impl,doVect,pre);
then
(cache,exp,prop,st,dae);
case (cache,env,(exp as Absyn.BINARY(exp1 = e1,op = op,exp2 = e2)),impl,st,doVect,pre) /* Binary and unary operations */
local Absyn.Exp exp;
equation
(cache,e1_1,DAE.PROP(t1,c1),st_1,dae1) = elabExp(cache,env, e1, impl, st,doVect,pre);
(cache,e2_1,DAE.PROP(t2,c2),st_2,dae2) = elabExp(cache,env, e2, impl, st_1,doVect,pre);
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,pre);
exp_1 = replaceOperatorWithFcall(DAE.BINARY(e1_2,op_1,e2_2), c);
exp_1 = Exp.simplify(exp_1);
prop = DAE.PROP(rtype,c);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,exp_1,prop,st_2,dae);
case (cache,env,(exp as Absyn.UNARY(op = op,exp = e)),impl,st,doVect,pre)
local Absyn.Exp exp;
equation
(cache,e_1,DAE.PROP(t,c),st_1,dae1) = elabExp(cache,env, e, impl, st,doVect,pre);
(cache,ops) = operators(cache,op, env, t, (DAE.T_NOTYPE(),NONE));
(op_1,{e_2},rtype) = deoverload(ops, {(e_1,t)}, exp,pre);
exp_1 = replaceOperatorWithFcall(DAE.UNARY(op_1,e_2), c);
exp_1 = Exp.simplify(exp_1);
prop = DAE.PROP(rtype,c);
then
(cache,exp_1,prop,st_1,dae1);
case (cache,env,(exp as Absyn.LBINARY(exp1 = e1,op = op,exp2 = e2)),impl,st,doVect,pre)
local Absyn.Exp exp;
equation
(cache,e1_1,DAE.PROP(t1,c1),st_1,dae1) = elabExp(cache,env, e1, impl, st,doVect,pre) "Logical binary expressions" ;
(cache,e2_1,DAE.PROP(t2,c2),st_2,dae2) = elabExp(cache,env, e2, impl, st_1,doVect,pre);
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,pre);
exp_1 = replaceOperatorWithFcall(DAE.LBINARY(e1_2,op_1,e2_2), c);
exp_1 = Exp.simplify(exp_1);
prop = DAE.PROP(rtype,c);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,exp_1,prop,st_2,dae);
case (cache,env,(exp as Absyn.LUNARY(op = op,exp = e)),impl,st,doVect,pre)
local Absyn.Exp exp;
equation
(cache,e_1,DAE.PROP(t,c),st_1,dae) = elabExp(cache,env, e, impl, st,doVect,pre) "Logical unary expressions" ;
(cache,ops) = operators(cache,op, env, t, (DAE.T_NOTYPE(),NONE));
(op_1,{e_2},rtype) = deoverload(ops, {(e_1,t)}, exp,pre);
exp_1 = replaceOperatorWithFcall(DAE.LUNARY(op_1,e_2), c);
exp_1 = Exp.simplify(exp_1);
prop = DAE.PROP(rtype,c);
then
(cache,exp_1,prop,st_1,dae);
case (cache,env,(exp as Absyn.RELATION(exp1 = e1,op = op,exp2 = e2)),impl,st,doVect,pre)
local Absyn.Exp exp;
equation
(cache,e1_1,DAE.PROP(t1,c1),st_1,dae1) = elabExp(cache,env, e1, impl, st,doVect,pre) "Relations, e.g. a < b" ;
(cache,e2_1,DAE.PROP(t2,c2),st_2,dae2) = elabExp(cache,env, e2, impl, st_1,doVect,pre);
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,pre);
exp_1 = replaceOperatorWithFcall(DAE.RELATION(e1_2,op_1,e2_2), c);
exp_1 = Exp.simplify(exp_1);
prop = DAE.PROP(rtype,c);
warnUnsafeRelations(env,c,t1,t2,e1_2,e2_2,op_1,pre);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,exp_1,prop,st_2,dae);
case (cache,env,e as Absyn.IFEXP(ifExp = _),impl,st,doVect,pre) /* Conditional expressions */
equation
Absyn.IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3) = Absyn.canonIfExp(e);
(cache,e1_1,prop1,st_1,dae1) = elabExp(cache,env, e1, impl, st,doVect,pre) "if expressions" ;
(cache,e2_1,prop2,st_2,dae2) = elabExp(cache,env, e2, impl, st_1,doVect,pre);
(cache,e3_1,prop3,st_3,dae3) = elabExp(cache,env, e3, impl, st_2,doVect,pre);
(cache,e_1,prop) = elabIfexp(cache,env, e1_1, prop1, e2_1, prop2, e3_1, prop3, impl, st,pre);
dae = DAEUtil.joinDaeLst({dae1,dae2,dae3});
then
(cache,e_1,prop,st_3,dae);
/*--------------------------------*/
/* Part of MetaModelica extension. KS */
case (cache,env,Absyn.CALL(function_ = Absyn.CREF_IDENT("SOME",_),functionArgs = Absyn.FUNCTIONARGS(args = (e1 :: _),argNames = _)),impl,st,doVect,pre)
local DAE.Exp e;
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,e,prop,st_1,dae) = elabExp(cache,env, e1, impl, st,doVect,pre);
t = Types.getPropType(prop);
e = DAE.META_OPTION(SOME(e));
c = Types.propAllConst(prop);
prop1 = DAE.PROP((DAE.T_METAOPTION(t),NONE()),c);
then
(cache,e,prop1,st,dae);
case (cache,env,Absyn.CALL(function_ = Absyn.CREF_IDENT("NONE",_),functionArgs = Absyn.FUNCTIONARGS(args = {},argNames = _)),impl,st,doVect,_)
local DAE.Exp e;
equation
true = RTOpts.acceptMetaModelicaGrammar();
e = DAE.META_OPTION(NONE());
prop1 = DAE.PROP((DAE.T_METAOPTION((DAE.T_NOTYPE(),NONE)),NONE()),DAE.C_CONST());
then
(cache,e,prop1,st,DAEUtil.emptyDae);
/* case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect)
local DAE.Exp e;
equation
//true = RTOpts.acceptMetaModelicaGrammar();
(cache,env,args,nargs) = MetaUtil.fixListConstructorsInArgs(cache,env,fn,args,nargs);
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);
Debug.fprintln("sei", "elab_exp CALL done");
then
(cache,e_1,prop_1,st_1); */
/*--------------------------------*/
/* If fail to elaborate e2 or e3 above check if cond is constant and make non-selected branch
undefined. NOTE: Dirty hack to make MSL CombiTable models work!!! */
case (cache,env,Absyn.IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3),impl,st,doVect,pre) /* Conditional expressions */
local DAE.Exp e; Boolean b;
equation
(cache,e1_1,prop1,st_1,dae1) = elabExp(cache,env, e1, impl, st,doVect,pre);
true = Types.isParameterOrConstant(Types.propAllConst(prop1));
(cache,Values.BOOL(b),_) = Ceval.ceval(cache, env, e1_1, impl, NONE, NONE, Ceval.NO_MSG());
(cache,e,prop,st_2,dae2) = elabIfexpBranch(cache,env,b,e1_1,e2,e3, impl, st_1,doVect,pre);
/* TODO elseif part */
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,e,prop,st_2,dae);
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect,pre)
local DAE.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,dae) = elabCall(cache,env, fn, args, nargs, impl, st,pre);
c = Types.propAllConst(prop);
e = Exp.simplify(e);
Debug.fprintln("sei", "elab_exp CALL done");
then
(cache,e,prop,st_1,dae);
// stefan
/*case (cache,env,e1 as Absyn.PARTEVALFUNCTION(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect)
local DAE.Exp e;
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,e,prop,st_1) = elabPartEvalFunction(cache,env,e1,st,impl,doVect);
then
(cache,e,prop,st_1);*/
case (cache,env,e1 as Absyn.PARTEVALFUNCTION(function_ = _),impl,st,doVect,pre)
local DAE.Exp e;
equation
(cache,e,prop,st_1,dae) = elabPartEvalFunction(cache,env,e1,st,impl,doVect,pre);
then
(cache,e,prop,st_1,dae);
case (cache,env,Absyn.TUPLE(expressions = e),impl,st,doVect,pre) /* PR. Get the properties for each expression in the tuple.
Each expression has its own constflag.
*/
local
list<DAE.Exp> e_1;
list<Absyn.Exp> e;
list<tuple<Absyn.Ident, Absyn.Exp>> iterators;
equation
(cache,e_1,props,dae) = elabTuple(cache,env, e, impl,doVect,pre) "Tuple function calls" ;
(types,consts) = splitProps(props);
then
(cache,DAE.TUPLE(e_1),DAE.PROP_TUPLE((DAE.T_TUPLE(types),NONE),DAE.TUPLE_CONST(consts)),st,dae);
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FOR_ITER_FARG(exp = exp, iterators=iterators)),impl,st,doVect,pre) /* Array-related expressions Elab reduction expressions, including array() constructor */
local
DAE.Exp e;
Absyn.Exp exp;
equation
(cache,e,prop,st_1,dae) = elabCallReduction(cache,env, fn, exp, iterators, impl, st,doVect,pre);
c = Types.propAllConst(prop);
e = Exp.simplify(e);
then
(cache,e,prop,st_1,dae);
case (cache,env,Absyn.RANGE(start = start,step = NONE,stop = stop),impl,st,doVect,pre)
equation
(cache,start_1,DAE.PROP(start_t,c_start),st_1,dae1) = elabExp(cache,env, start, impl, st,doVect,pre) "Range expressions without step value, e.g. 1:5" ;
(cache,stop_1,DAE.PROP(stop_t,c_stop),st_2,dae2) = elabExp(cache,env, stop, impl, st_1,doVect,pre);
(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,pre);
exp_2 = DAE.RANGE(rt, start_2, NONE, stop_2);
prop_1 = DAE.PROP(t, const);
exp_2 = Exp.simplify(exp_2);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,exp_2,prop_1,st_2,dae);
case (cache,env,Absyn.RANGE(start = start,step = SOME(step),stop = stop),impl,st,doVect,pre)
equation
(cache,start_1,DAE.PROP(start_t,c_start),st_1,dae1) = elabExp(cache,env, start, impl, st,doVect,pre) "Range expressions with step value, e.g. 1:0.5:4" ;
(cache,step_1,DAE.PROP(step_t,c_step),st_2,dae2) = elabExp(cache,env, step, impl, st_1,doVect,pre);
(cache,stop_1,DAE.PROP(stop_t,c_stop),st_3,dae3) = elabExp(cache,env, stop, impl, st_2,doVect,pre);
(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,pre);
exp_2 = DAE.RANGE(rt, start_2, SOME(step_2), stop_2);
prop_1 = DAE.PROP(t, const);
exp_2 = Exp.simplify(exp_2);
dae = DAEUtil.joinDaeLst({dae1,dae2,dae3});
then
(cache,exp_2,prop_1,st_3,dae);
// Part of the MetaModelica extension. This eliminates elab_array failed failtraces when using the empty list. sjoelund
case (cache,env,Absyn.ARRAY({}),impl,st,doVect,pre)
local equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,exp,prop,st,dae) = elabExp(cache,env,Absyn.LIST({}),impl,st,doVect,pre);
then (cache,exp,prop,st,dae);
case (cache,env,Absyn.ARRAY(arrayExp = es),impl,st,doVect,pre)
local DAE.Exp arrexp;
equation
(cache,es_1,DAE.PROP(t,const),dae) = elabArray(cache,env, es, impl, st,doVect,pre) "array expressions, e.g. {1,2,3}" ;
l = listLength(es_1);
arrtp = (DAE.T_ARRAY(DAE.DIM_INTEGER(l),t),NONE);
at = Types.elabType(arrtp);
a = Types.isArray(t);
a = boolNot(a); // scalar = !array
arrexp = DAE.ARRAY(at,a,es_1);
(arrexp,arrtp) = MetaUtil.tryToConvertArrayToList(arrexp,arrtp) "converts types that cannot be arrays into lists";
arrexp = tryToConvertArrayToMatrix(arrexp);
then
(cache,arrexp,DAE.PROP(arrtp,const),st,dae);
case (cache,env,Absyn.MATRIX(matrix = es),impl,st,doVect,pre)
local list<list<Absyn.Exp>> es;
Integer d1,d2;
equation
(cache,_,tps,_,dae1) = elabExpListList(cache, env, es, impl, st,doVect,pre) "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,DAE.PROP(t,c),dim1,dim2,dae2)
= elabMatrixSemi(cache,env, es, impl, st, havereal, nmax,doVect,pre);
mexp = Util.if_(havereal,DAE.CAST(DAE.ET_ARRAY(DAE.ET_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" ;
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,mexp_1,DAE.PROP((DAE.T_ARRAY(dim1,(DAE.T_ARRAY(dim2,t_2),NONE)),NONE),c),st,dae);
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,DAE.CODE(c,tp_1),DAE.PROP(tp,DAE.C_CONST()),st,DAEUtil.emptyDae);
case (cache,env,Absyn.VALUEBLOCK(ld,body,res),impl,st,doVect,pre)
local
Absyn.ValueblockBody body;
list<Absyn.ElementItem> ld;
list<Absyn.AlgorithmItem> b,b2;
list<DAE.Statement> b_alg;
DAE.DAElist dae1,dae2;
list<DAE.Element> dae1_2Elts;
Absyn.Exp res;
DAE.Exp res2;
DAE.Properties prop;
DAE.FunctionTree funcs;
equation
// debug_print("elabExp->VALUEBLOCKALGORITHMS", b);
(cache,env,DAE.DAE(dae1_2Elts,funcs),b2) = addLocalDecls(cache,env,ld,impl);
(b,cache) = fromValueblockBodyToAlgs(body,cache,env,pre);
b = listAppend(b2,b);
//----------------------------------------------------------------------
(cache,b_alg,dae1) = InstSection.instStatements(cache, env,
InnerOuter.emptyInstHierarchy,
Prefix.NOPRE(), SCodeUtil.translateClassdefAlgorithmitems(b), DAE.emptyElementSource, SCode.NON_INITIAL(), true, Inst.neverUnroll);
// debug_print("before -> res",res);
(cache,res2,prop as DAE.PROP(tp,_),st,dae2) = elabExp(cache,env,res,impl,st,doVect,pre);
// debug_print("after -> res",res2);
tp_1 = Types.elabType(tp);
// debug_print("end",tp_1);
// TODO: PA: I do not know which dae:s to collect here. It should collect all dae:s that comes from
// elaborating expressions (since they can contain function calls and that is what we want to collect)
dae = DAEUtil.joinDaeLst({dae1,dae2,DAE.DAE({},funcs)});
then (cache,DAE.VALUEBLOCK(tp_1,dae1_2Elts,b_alg,res2),prop,st,dae);
//-------------------------------------
// Part of the MetaModelica extension. KS
case (cache,env,Absyn.ARRAY(es),impl,st,doVect,pre)
local equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,exp,prop,st,dae) = elabExp(cache,env,Absyn.LIST(es),impl,st,doVect,pre);
then (cache,exp,prop,st,dae);
case (cache,env,Absyn.CONS(e1,e2),impl,st,doVect,pre)
local
Boolean correctTypes;
DAE.Type t;
equation
(e1 :: _) = MetaUtil.transformArrayNodesToListNodes({e1},{});
(e2 :: _) = MetaUtil.transformArrayNodesToListNodes({e2},{});
(cache,e1_1,prop1,st_1,dae1) = elabExp(cache,env, e1, impl, st,doVect,pre);
(cache,e2_1,DAE.PROP((DAE.T_LIST(t2),_),c2),st_1,dae2) = elabExp(cache,env, e2, impl, st,doVect,pre);
t1 = Types.getPropType(prop1);
c1 = Types.propAllConst(prop1);
t = Types.superType(t1,t2);
(e1_1,_) = Types.matchType(e1_1, t1, t, true);
(e2_1,_) = Types.matchType(e2_1, t2, t, true);
// If the second expression is a DAE.LIST, then we can create a DAE.LIST
// instead of DAE.CONS
tp_1 = Types.elabType(t);
exp = MetaUtil.simplifyListExp(tp_1,e1_1,e2_1);
c = Types.constAnd(c1,c2);
prop = DAE.PROP((DAE.T_LIST(t),NONE()),c);
dae = DAEUtil.joinDaes(dae1,dae2);
then (cache,exp,prop,st,dae);
// The Absyn.LIST() node is used for list expressions that are
// transformed from Absyn.ARRAY()
case (cache,env,Absyn.LIST({}),impl,st,doVect,_)
local
list<DAE.Properties> propList;
Boolean correctTypes;
DAE.Type t;
equation
t = (DAE.T_LIST((DAE.T_NOTYPE,NONE)),NONE);
prop = DAE.PROP(t,DAE.C_CONST());
then (cache,DAE.LIST(DAE.ET_LIST(DAE.ET_OTHER()),{}),prop,st,DAEUtil.emptyDae);
case (cache,env,Absyn.LIST(es),impl,st,doVect,pre)
local
list<DAE.Properties> propList;
list<DAE.Type> typeList;
list<DAE.Const> constList;
Boolean correctTypes;
DAE.Type t;
equation
(cache,es_1,propList,st_2,dae) = elabExpList(cache,env, es, impl, st,doVect,pre);
typeList = Util.listMap(propList, Types.getPropType);
constList = Types.getConstList(propList);
c = Util.listReduce(constList, Types.constAnd) "The case empty list is handled above";
(es_1, t, _) = Types.listMatchSuperType(es_1, typeList, {}, Types.matchTypeRegular, true);
prop = DAE.PROP((DAE.T_LIST(t),NONE()),c);
tp_1 = Types.elabType(t);
then (cache,DAE.LIST(tp_1,es_1),prop,st_2,dae);
// ----------------------------------
case (cache,env,e,_,_,_,pre)
equation
/* FAILTRACE REMOVE
true = RTOpts.debugFlag("failtrace");
Debug.fprint("failtrace", "- Static.elabExp failed: ");
Debug.traceln(Dump.printExpStr(e));
Debug.traceln(" Scope: " +& Env.printEnvPathStr(env));
Debug.traceln(" Prefix: " +& PrefixUtil.printPrefixStr(pre));
//Debug.traceln("\n env : ");
//Debug.traceln(Env.printEnvStr(env));
//Debug.traceln("\n----------------------- FINISHED ENV ------------------------\n");
*/
then
fail();
end matchcontinue;
end elabExp;
// Part of MetaModelica extension
public function elabListExp "function: elabListExp
Function that elaborates the MetaModelica list type,
for instance list<Integer>.
This is used by Inst.mo when handling a var := {...} statement
"
input Env.Cache inCache;
input Env.Env inEnv;
input list<Absyn.Exp> inExpList;
input DAE.Properties inProp;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Boolean performVectorization;
input Prefix inPrefix;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProperties;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outExp,outProperties,outInteractiveInteractiveSymbolTableOption) :=
matchcontinue (inCache,inEnv,inExpList,inProp,inBoolean,inInteractiveInteractiveSymbolTableOption,performVectorization,inPrefix)
local
Env.Cache cache;
Env.Env env;
Boolean impl,doVect;
Option<Interactive.InteractiveSymbolTable> st;
DAE.Properties prop;
DAE.Const c;
Prefix pre;
case (cache,env,{},prop,_,st,_,_)
then (cache,DAE.LIST(DAE.ET_OTHER(),{}),prop,st);
case (cache,env,expList,prop as DAE.PROP((DAE.T_LIST(t),_),c),impl,st,doVect,pre)
local
list<Absyn.Exp> expList;
list<DAE.Exp> expExpList;
DAE.Type t;
list<Boolean> boolList;
list<DAE.Properties> propList;
list<DAE.Type> typeList;
DAE.ExpType t2;
equation
(cache,expExpList,propList,st,_) = elabExpList(cache,env,expList,impl,st,doVect,pre);
typeList = Util.listMap(propList, Types.getPropType);
(expExpList, t, _) = Types.listMatchSuperType(expExpList, typeList, {}, Types.matchTypeRegular, true);
t2 = Types.elabType(t);
then
(cache,DAE.LIST(t2,expExpList),DAE.PROP((DAE.T_LIST(t),NONE),c),st);
case (_,_,_,_,_,_,_,_)
equation
Debug.fprint("failtrace", "- elabListExp failed, non-matching args in list constructor?");
then
fail();
end matchcontinue;
end elabListExp;
/* ------------------------------- */
public function fromValueblockBodyToAlgs
input Absyn.ValueblockBody body;
input Env.Cache cache;
input Env.Env env;
input Prefix inPrefix;
output list<Absyn.AlgorithmItem> outAlgs;
output Env.Cache outCache;
algorithm
(outAlgs,cache) := matchcontinue (body,cache,env,inPrefix)
local
list<Absyn.AlgorithmItem> algs1,algs2,eqAlgs,algs;
list<Absyn.EquationItem> eq1;
Prefix pre;
case (Absyn.VALUEBLOCKALGORITHMS(algs1),cache,_,_)
then (algs1,cache);
case (Absyn.VALUEBLOCKMATCHCASE(algs1,eq1,algs2),cache,env,pre)
equation
(cache,eqAlgs) = fromEquationsToAlgAssignments(eq1,{},cache,env,pre);
algs = listAppend(eqAlgs,algs2);
algs = listAppend(algs1,algs);
then (algs,cache);
end matchcontinue;
end fromValueblockBodyToAlgs;
protected function fromEquationsToAlgAssignments "function: fromEquationsToAlgAssignments
Converts equations to algorithm assignments.
Matchcontinue expressions may contain statements that you won't find
in a normal equation section. For instance:
case(...)
local
equation
(var1,_,MYREC(...)) = func(...);
fail();
then 1;
"
input list<Absyn.EquationItem> eqsIn;
input list<Absyn.AlgorithmItem> accList;
input Env.Cache cache;
input Env.Env env;
input Prefix inPrefix;
output Env.Cache outCache;
output list<Absyn.AlgorithmItem> algsOut;
algorithm
(outCache,algOut) :=
matchcontinue (eqsIn,accList,cache,env,inPrefix)
local
list<Absyn.AlgorithmItem> localAccList;
Env.Cache localCache;
Env.Env localEnv;
Prefix pre;
Option<Absyn.Comment> comment;
Absyn.Info info;
Absyn.Equation first;
list<Absyn.EquationItem> rest;
list<Absyn.AlgorithmItem> alg;
case ({},localAccList,localCache,localEnv,_) then (localCache,listReverse(localAccList));
case (Absyn.EQUATIONITEM(equation_ = first, comment = comment, info = info) :: rest,localAccList,localCache,localEnv,pre)
equation
(localCache,alg) = fromEquationToAlgAssignment(first,comment,info,localCache,localEnv,pre);
(localCache,localAccList) = fromEquationsToAlgAssignments(rest,listAppend(alg,localAccList),localCache,localEnv,pre);
then (localCache,localAccList);
end matchcontinue;
end fromEquationsToAlgAssignments;
protected function fromEquationBranchesToAlgBranches
"Converts equations to algorithm assignments."
input list<tuple<Absyn.Exp,list<Absyn.EquationItem>>> eqsIn;
input list<tuple<Absyn.Exp,list<Absyn.AlgorithmItem>>> accList;
input Env.Cache cache;
input Env.Env env;
input Prefix inPrefix;
output Env.Cache outCache;
output list<tuple<Absyn.Exp,list<Absyn.AlgorithmItem>>> algsOut;
algorithm
(outCache,algOut) :=
matchcontinue (eqsIn,accList,cache,env,inPrefix)
local
list<tuple<Absyn.Exp,list<Absyn.AlgorithmItem>>> localAccList;
list<tuple<Absyn.Exp,list<Absyn.EquationItem>>> rest;
Env.Cache localCache;
Env.Env localEnv;
Prefix pre;
Absyn.Exp e;
list<Absyn.AlgorithmItem> algs;
list<Absyn.EquationItem> eqs;
case ({},localAccList,localCache,localEnv,_) then (localCache,listReverse(localAccList));
case ((e,eqs)::rest,localAccList,localCache,localEnv,pre)
equation
(localCache,algs) = fromEquationsToAlgAssignments(eqs,{},localCache,localEnv,pre);
(localCache,localAccList) = fromEquationBranchesToAlgBranches(rest,(e,algs)::localAccList,localCache,localEnv,pre);
then (localCache,localAccList);
end matchcontinue;
end fromEquationBranchesToAlgBranches;
protected function fromEquationToAlgAssignment "function: fromEquationToAlgAssignment"
input Absyn.Equation eq;
input Option<Absyn.Comment> comment;
input Absyn.Info info;
input Env.Cache cache;
input Env.Env env;
input Prefix inPrefix;
output Env.Cache outCache;
output list<Absyn.AlgorithmItem> algStatement;
algorithm
(outCache,algStatement) := matchcontinue (eq,comment,info,cache,env,inPrefix)
local
Env.Cache localCache;
Env.Env localEnv;
Prefix pre;
String str,strLeft,strRight;
Absyn.Exp left,right,lhsExp,rhsExp,e;
Absyn.AlgorithmItem algItem,algItem1,algItem2;
Absyn.Equation eq2;
Option<Absyn.Comment> comment2;
Absyn.Info info2;
Absyn.AlgorithmItem brk,try,catchBreak,res,throw;
Absyn.ComponentRef cref,cRef;
Absyn.FunctionArgs fargs;
list<Absyn.Exp> expL,varList;
Absyn.Path p;
SCode.Element cl;
SCode.Class class_, cl1;
list<Absyn.ElementItem> elemList;
DAE.Type ty, resType;
DAE.Properties prop;
list<Absyn.AlgorithmItem> algs, algTrueItems, algElseItems;
list<tuple<Absyn.Exp,list<Absyn.AlgorithmItem>>> algBranches;
list<Absyn.EquationItem> eqTrueItems, eqElseItems;
list<tuple<Absyn.Exp,list<Absyn.EquationItem>>> eqBranches;
case (Absyn.EQ_EQUALS(Absyn.CREF(Absyn.CREF_IDENT(strLeft,{})),Absyn.CREF(Absyn.CREF_IDENT(strRight,{}))),comment,info,localCache,_,_)
equation
true = strLeft ==& strRight;
// match x case x then ... produces equation x = x; we save a bit of time by removing it here :)
then (localCache,{});
// The syntax n>=0 = true; is also used
case (Absyn.EQ_EQUALS(left,Absyn.BOOL(true)),comment,info,localCache,_,_)
equation
failure(Absyn.CREF(_) = left); // If lhs is a CREF, it should be an assignment
algItem1 = Absyn.ALGORITHMITEM(Absyn.ALG_THROW(),comment,info);
algItem2 = Absyn.ALGORITHMITEM(Absyn.ALG_IF(Absyn.LUNARY(Absyn.NOT(),left),{algItem1},{},{}),comment,info);
then (localCache,{algItem2});
case (Absyn.EQ_EQUALS(left,Absyn.BOOL(false)),comment,info,localCache,_,_)
equation
failure(Absyn.CREF(_) = left); // If lhs is a CREF, it should be an assignment
algItem1 = Absyn.ALGORITHMITEM(Absyn.ALG_THROW(),comment,info);
algItem2 = Absyn.ALGORITHMITEM(Absyn.ALG_IF(left,{algItem1},{},{}),comment,info);
then (localCache,{algItem2});
case (Absyn.EQ_NORETCALL(Absyn.CREF_IDENT("fail",_),_),comment,info,localCache,_,_)
equation
algItem = Absyn.ALGORITHMITEM(Absyn.ALG_THROW(),comment,info);
then (localCache,{algItem});
case (Absyn.EQ_NORETCALL(cref,fargs),comment,info,localCache,_,_)
equation
algItem = Absyn.ALGORITHMITEM(Absyn.ALG_NORETCALL(cref,fargs),comment,info);
then (localCache,{algItem});
case (Absyn.EQ_EQUALS(left,right),comment,info,localCache,_,_)
equation
algItem = Absyn.ALGORITHMITEM(Absyn.ALG_ASSIGN(left,right),comment,info);
then (localCache,{algItem});
case (Absyn.EQ_FAILURE(Absyn.EQUATIONITEM(eq2,comment2,info2)),comment,info,cache,env,pre)
equation
(cache,algs) = fromEquationToAlgAssignment(eq2,comment2,info2,cache,env,pre);
try = Absyn.ALGORITHMITEM(Absyn.ALG_TRY(algs),comment,info);
brk = Absyn.ALGORITHMITEM(Absyn.ALG_BREAK(),comment,info);
throw = Absyn.ALGORITHMITEM(Absyn.ALG_THROW(),comment,info);
catchBreak = Absyn.ALGORITHMITEM(Absyn.ALG_CATCH({brk}),comment,info);
res = Absyn.ALGORITHMITEM(Absyn.ALG_WHILE(Absyn.BOOL(true), {try,catchBreak,throw}),comment,info);
then (cache,{res});
case (Absyn.EQ_IF(ifExp = e, equationTrueItems = eqTrueItems, elseIfBranches = eqBranches, equationElseItems = eqElseItems),comment,info,cache,env,pre)
equation
(cache,algTrueItems) = fromEquationsToAlgAssignments(eqTrueItems,{},cache,env,pre);
(cache,algElseItems) = fromEquationsToAlgAssignments(eqElseItems,{},cache,env,pre);
(cache,algBranches) = fromEquationBranchesToAlgBranches(eqBranches,{},cache,env,pre);
res = Absyn.ALGORITHMITEM(Absyn.ALG_IF(e, algTrueItems, algBranches, algElseItems),comment,info);
then (cache,{res});
case (eq,_,info,_,_,_)
equation
str = Dump.equationName(eq);
Error.addSourceMessage(Error.META_MATCH_EQUATION_FORBIDDEN, {str}, info);
then fail();
end matchcontinue;
end fromEquationToAlgAssignment;
protected function elabMatrixGetDimensions "function: elabMatrixGetDimensions
Helper function to elab_exp (MATRIX). Calculates the dimensions of the
matrix by investigating the elaborated expression.
"
input DAE.Exp inExp;
output Integer outInteger1;
output Integer outInteger2;
algorithm
(outInteger1,outInteger2):=
matchcontinue (inExp)
local
Integer dim1,dim2;
list<DAE.Exp> lst2,lst;
case (DAE.ARRAY(array = lst))
equation
dim1 = listLength(lst);
(DAE.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 DAE.Exp inExp;
output DAE.Exp outExp;
algorithm
outExp:=
matchcontinue (inExp)
local
list<list<tuple<DAE.Exp, Boolean>>> mexpl;
Integer dim;
DAE.ExpType a,elt_ty;
Boolean at;
Option<Integer> dim;
Integer d1;
list<DAE.Exp> expl;
DAE.Exp e;
case (DAE.ARRAY(ty = a,scalar = at,array = expl))
equation
mexpl = elabMatrixToMatrixExp2(expl);
d1 = listLength(mexpl);
then
DAE.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<DAE.Exp> inExpExpLst;
output list<list<tuple<DAE.Exp, Boolean>>> outTplExpExpBooleanLstLst;
algorithm
(outTplExpExpBooleanLstLst):=
matchcontinue (inExpExpLst)
local
list<tuple<DAE.Exp, Boolean>> expl_1;
list<list<tuple<DAE.Exp, Boolean>>> es_1;
DAE.ExpType a;
Boolean at;
list<DAE.Exp> expl,es;
case ({}) then {};
case ((DAE.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;