-
Notifications
You must be signed in to change notification settings - Fork 299
/
Types.mo
5636 lines (5216 loc) · 177 KB
/
Types.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 Types
" file: Types.mo
package: Types
description: Type system
RCS: $Id$
This file specifies the type system, as defined in the modelica
specification. It contains an MetaModelica Compiler (MMC) type called `Type\' which
defines types. It also contains functions for
determining subtyping etc.
There are a few known problems with this module. It currently
depends on SCode.Attributes, which in turn depends on
Absyn.ArrayDim. However, the only things used from those
modules are constants that could be moved to their own modules."
public import ClassInf;
public import Absyn;
public import DAE;
public import Values;
public import SCode;
public type ArrayDim = DAE.ArrayDim;
public type Attributes = DAE.Attributes;
public type Binding = DAE.Binding;
public type Const = DAE.Const;
public type EqualityConstraint = DAE.EqualityConstraint;
public type EqMod = DAE.EqMod;
public type FuncArg = DAE.FuncArg;
public type Ident = String;
public type Mod = DAE.Mod;
public type PolymorphicBindings = list<tuple<String,Type>>;
public type Properties = DAE.Properties;
public type SubMod = DAE.SubMod;
public type TType = DAE.TType;
public type TupleConst = DAE.TupleConst;
public type Type = DAE.Type;
public type Var = DAE.Var;
protected import Dump;
protected import Debug;
protected import Exp;
protected import Print;
protected import Util;
protected import Static;
protected import RTOpts;
protected import ValuesUtil;
public function discreteType
"function: discreteType
author: PA
Succeeds for all the discrete types, Integer, String, Boolean and enumeration."
input Type inType;
algorithm
_ := matchcontinue (inType)
case ((DAE.T_INTEGER(varLstInt = _),_)) then ();
case ((DAE.T_STRING(varLstString = _),_)) then ();
case ((DAE.T_BOOL(varLstBool = _),_)) then ();
case ((DAE.T_ENUMERATION(names = _),_)) then ();
end matchcontinue;
end discreteType;
public function propsAnd "
Author BZ, 2008-09
Function for merging a list of properties, currently only working on DAE.PROP() and not TUPLE_DAE.PROP()."
input list<Properties> inProps;
output Properties outProp;
algorithm outProp := matchcontinue(inProps)
local
Properties prop,prop2;
Const c,c2;
Type ty,ty2;
case(prop::{}) then prop;
case((prop as DAE.PROP(ty,c))::inProps)
equation
(prop2 as DAE.PROP(ty2,c2)) = propsAnd(inProps);
c = constAnd(c,c2);
true = equivtypes(ty,ty2);
then
DAE.PROP(ty,c);
end matchcontinue;
end propsAnd;
// stefan
public function makePropsNotConst
"function: makePropsNotConst
returns the same Properties but with the const flag set to Var"
input Properties inProperties;
output Properties outProperties;
algorithm outProperties := matchcontinue (inProperties)
local
Type t;
case(DAE.PROP(type_=t,constFlag=_)) then DAE.PROP(t,DAE.C_VAR());
end matchcontinue;
end makePropsNotConst;
// stefan
public function setTypeInProps
"function: setTypeInProps
sets the Type in a Properties record"
input DAE.Type inType;
input DAE.Properties inProperties;
output DAE.Properties outProperties;
algorithm
outProperties := matchcontinue(inType,inProperties)
local
DAE.Const cf;
DAE.TupleConst tc;
DAE.Type ty;
case(ty,DAE.PROP(_,cf)) then DAE.PROP(ty,cf);
case(ty,DAE.PROP_TUPLE(_,tc)) then DAE.PROP_TUPLE(ty,tc);
end matchcontinue;
end setTypeInProps;
// stefan
public function getConstList
"function: getConstList
retrieves a list of Consts from a list of Properties"
input list<Properties> inPropertiesList;
output list<Const> outConstList;
algorithm
outConstList := matchcontinue(inPropertiesList)
local
Const c;
list<Const> ccdr;
list<Properties> pcdr;
TupleConst tc;
case({}) then {};
case(DAE.PROP(type_=_,constFlag=c) :: pcdr)
equation
ccdr = getConstList(pcdr);
then
c :: ccdr;
case(DAE.PROP_TUPLE(type_=_,tupleConst=tc) :: pcdr)
equation
c = elabTypePropToConst2(tc);
ccdr = getConstList(pcdr);
then
c :: ccdr;
end matchcontinue;
end getConstList;
public function elabTypePropToConst " function elabTypePropToConst
this function elaborates on a DAE.Properties and return the DAE.Const value.
"
input list<Properties> p;
output Const c;
algorithm
c :=
matchcontinue (p)
local
Properties p1;
list<Properties> pps;
Const c1,c2;
TupleConst tc1;
case({}) then DAE.C_CONST();
case ((p1 as DAE.PROP(_,c1))::pps)
equation
c2 = elabTypePropToConst(pps);
c1 = constAnd(c1, c2);
then
c1;
case((p1 as DAE.PROP_TUPLE(_,tc1))::pps)
equation
c1 = elabTypePropToConst2(tc1);
c2 = elabTypePropToConst(pps);
c1 = constAnd(c1, c2);
then
c1;
end matchcontinue;
end elabTypePropToConst;
protected function elabTypePropToConst2 ""
input TupleConst t;
output Const c;
algorithm
c :=
matchcontinue (t)
local
TupleConst p1;
Const c1,c2;
list<TupleConst> tcxl;
TupleConst tc1;
case (p1 as DAE.SINGLE_CONST(c1))
then
c1;
case(p1 as DAE.TUPLE_CONST(tc1::tcxl))
equation
c1 = elabTypePropToConst2(tc1);
c2 = elabTypePropToConst3(tcxl);
c1 = constAnd(c1, c2);
then
c1;
end matchcontinue;
end elabTypePropToConst2;
protected function elabTypePropToConst3 ""
input list<TupleConst> t;
output Const c;
algorithm
c :=
matchcontinue (t)
local
TupleConst p1;
Const c1,c2;
list<TupleConst> tcxl;
TupleConst tc1;
case({}) then DAE.C_CONST();
case((p1 as DAE.SINGLE_CONST(c1))::tcxl)
equation
c2 = elabTypePropToConst3(tcxl);
c1 = constAnd(c1, c2);
then
c1;
case((p1 as DAE.TUPLE_CONST(_))::tcxl)
equation
c1 = elabTypePropToConst2(p1);
c2 = elabTypePropToConst3(tcxl);
c1 = constAnd(c1, c2);
then
c1;
end matchcontinue;
end elabTypePropToConst3;
public function externalObjectType "author: PA
Succeeds if type is ExternalObject
"
input Type inType;
algorithm
_:=
matchcontinue (inType)
case ((DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(_)),_)) then ();
end matchcontinue;
end externalObjectType;
public function varName "
Author BZ, 2009-09
Function for getting the name of a DAE.Var"
input Var v;
output String s;
algorithm
s := matchcontinue(v)
case(DAE.TYPES_VAR(name = s)) then s;
end matchcontinue;
end varName;
public function externalObjectConstructorType "author: PA
Succeeds if type is ExternalObject constructor function"
input Type inType;
algorithm
_ := matchcontinue (inType)
local Type tp;
case ((DAE.T_FUNCTION(funcResultType = tp),_))
equation
externalObjectType(tp);
then ();
end matchcontinue;
end externalObjectConstructorType;
public function simpleType "function: simpleType
author: PA
Succeeds for all the builtin types, Integer, String, Real, Boolean"
input Type inType;
algorithm
_ := matchcontinue (inType)
case ((DAE.T_REAL(varLstReal = _),_)) then ();
case ((DAE.T_INTEGER(varLstInt = _),_)) then ();
case ((DAE.T_STRING(varLstString = _),_)) then ();
case ((DAE.T_BOOL(varLstBool = _),_)) then ();
end matchcontinue;
end simpleType;
public function isComplexConnector ""
input Type t;
output Boolean b;
algorithm b := matchcontinue(t)
case((DAE.T_COMPLEX(ClassInf.CONNECTOR(_,_),_,_,_),_)) then true;
case(_) then false;
end matchcontinue;
end isComplexConnector;
public function isComplexType "
Author: BZ, 2008-11
This function checks wheter a type is complex AND not extending a base type."
input Type ty;
output Boolean b;
algorithm b := matchcontinue(ty)
case((DAE.T_COMPLEX(_,_::_,_,_),_)) then true; // not derived from baseclass
case(_) then false;
end matchcontinue;
end isComplexType;
public function isExternalObject "Returns true if type is COMPLEX and external object (ClassInf)"
input Type tp;
output Boolean b;
algorithm
b := matchcontinue(tp)
case((DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(_)),_)) then true;
case(_) then false;
end matchcontinue;
end isExternalObject;
public function expTypetoTypesType "Function: expTypetoTypesType Converts a DAE.ExpType to a DAE.Type
NOTE: This function should not be used in general,
since it is not recommended to translate DAE.ExpType into DAE.Type."
input DAE.ExpType inexp;
output Type oType;
algorithm
oType := matchcontinue(inexp)
local Type ty,ty2;
case(DAE.ET_INT)
equation
ty = DAE.T_INTEGER_DEFAULT;
then ty;
case(DAE.ET_REAL)
equation
ty = DAE.T_REAL_DEFAULT;
then ty;
case(DAE.ET_BOOL)
equation
ty = DAE.T_BOOL_DEFAULT;
then ty;
case(DAE.ET_STRING)
equation
ty = DAE.T_STRING_DEFAULT;
then ty;
case(DAE.ET_ENUMERATION(index,path,names,evars))
local
Option<Integer> index;
Absyn.Path path;
list<String> names;
list<DAE.ExpVar> evars;
list<Var> tvars;
// case(Exp.ENUM)
equation
tvars = Util.listMap(evars, convertFromExpToTypesVar);
ty = (DAE.T_ENUMERATION(index,path,names,tvars),NONE());
// ty = (DAE.T_ENUM,NONE);
then ty;
case(DAE.ET_ARRAY(at,SOME(dim)::ad))
local DAE.ExpType at;
list<Option<Integer>> ad;
Integer dim;
Integer ll;
Integer currDim;
ArrayDim ard;
TType tty;
equation
ll = listLength(ad);
true = (ll == 0);
ty = expTypetoTypesType(at);
ard = DAE.DIM(SOME(dim));
tty = DAE.T_ARRAY(ard,ty);
ty2 = (tty,NONE);
then
ty2;
case(DAE.ET_ARRAY(at,SOME(dim)::ad))
local DAE.ExpType at;
list<Option<Integer>> ad;
Integer dim;
Integer ll;
Integer currDim;
ArrayDim ard;
TType tty;
equation
ll = listLength(ad);
true = (ll > 0);
ty = expTypetoTypesType(DAE.ET_ARRAY(at,ad));
ard = DAE.DIM(SOME(dim));
tty = DAE.T_ARRAY(ard,ty);
ty2 = (tty,NONE);
then
ty2;
case(DAE.ET_COMPLEX(complexClassType = complexClassType, varLst = evars)) //record COMPLEX "Complex types, currently only used for records "
local
list<DAE.ExpVar> evars;
list<Var> tvars;
ClassInf.State complexClassType;
equation
tvars = Util.listMap(evars, convertFromExpToTypesVar);
ty = (DAE.T_COMPLEX(complexClassType,tvars,NONE,NONE),NONE);
then
ty;
case(DAE.ET_UNIONTYPE()) then ((DAE.T_UNIONTYPE({}),NONE));
case(DAE.ET_BOXED(at))
local DAE.ExpType at;
equation
ty = expTypetoTypesType(at);
ty2 = (DAE.T_BOXED(ty),NONE);
then ty2;
case(DAE.ET_LIST(at))
local DAE.ExpType at;
equation
ty = expTypetoTypesType(at);
ty2 = (DAE.T_LIST(ty),NONE);
then ty2;
case(_)
equation
Debug.fprint("failtrace", "-Types.expTypetoTypesType Conversion of all Exp types not yet implemented\n");
then
fail();
end matchcontinue;
end expTypetoTypesType;
protected function convertFromExpToTypesVar ""
input DAE.ExpVar inVars;
output Var outVars;
algorithm outVars := matchcontinue(inVars)
local
String name;
DAE.ExpType tp;
Type ty;
DAE.ExpVar ev;
Var tv;
case(ev as DAE.COMPLEX_VAR(name,tp))
equation
ty = expTypetoTypesType(tp);
tv = DAE.TYPES_VAR(name,DAE.ATTR(false,false,SCode.RW, SCode.VAR, Absyn.BIDIR, Absyn.UNSPECIFIED),false,ty,DAE.UNBOUND(),NONE());
then
tv;
case(_) equation print("error in convertFromExpToTypesVar\n"); then fail();
end matchcontinue;
end convertFromExpToTypesVar;
protected function convertFromTypesToExpVar ""
input Var inVars;
output DAE.ExpVar outVars;
algorithm outVars := matchcontinue(inVars)
local
String tname;
DAE.ExpType tp;
Type ty;
Var ev;
DAE.ExpVar tv;
case(ev as DAE.TYPES_VAR(name=tname,type_=ty))
equation
tp = elabType(ty);
tv = DAE.COMPLEX_VAR(tname,tp);
then
tv;
case(_)
equation
print("-Types.convertFromTypesToExpVar failed\n");
Debug.fprint("failtrace", "-Types.convertFromTypesToExpVar failed\n");
then fail();
end matchcontinue;
end convertFromTypesToExpVar;
public function isTuple "Returns true if type is TUPLE"
input Type tp;
output Boolean b;
algorithm
b := matchcontinue(tp)
case((DAE.T_TUPLE(_),_)) then true;
case(_) then false;
end matchcontinue;
end isTuple;
public function isRecord "Returns true if type is COMPLEX and a record (ClassInf)"
input Type tp;
output Boolean b;
algorithm
b := matchcontinue(tp)
case((DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(_)),_)) then true;
case(_) then false;
end matchcontinue;
end isRecord;
public function isRecordWithOnlyReals "Returns true if type is a record only containing Reals"
input Type tp;
output Boolean b;
algorithm
b := matchcontinue(tp)
local list<Boolean> bLst;
list<Var> varLst;
case((DAE.T_COMPLEX(ClassInf.RECORD(_),varLst,_,_),_)) equation
bLst = Util.listMap(Util.listMap(varLst,getVarType),isReal);
b = Util.boolAndList(bLst);
then b;
case(_) then false;
end matchcontinue;
end isRecordWithOnlyReals;
public function getVarType "Return the Type of a Var"
input Var v;
output Type tp;
algorithm
tp := matchcontinue(v)
case(DAE.TYPES_VAR(type_ = tp)) then tp;
end matchcontinue;
end getVarType;
public function getVarName "Return the name of a Var"
input Var v;
output String name;
algorithm
name := matchcontinue(v)
case(DAE.TYPES_VAR(name = name)) then name;
end matchcontinue;
end getVarName;
public function isReal "Returns true if type is Real"
input Type tp;
output Boolean res;
algorithm
res := matchcontinue(tp)
case(tp) equation
((DAE.T_REAL(_),_)) = arrayElementType(tp);
then true;
case(_) then false;
end matchcontinue;
end isReal;
public function isRealOrSubTypeReal "
Author BZ 2008-05
This function verifies if it is some kind of a Real type we are working with.
"
input Type inType;
output Boolean b;
algorithm b := matchcontinue(inType)
local Type ty; Boolean lb1,lb2,lb3;
case(ty)
equation
lb1 = isReal(ty);
lb2 = subtype(ty, DAE.T_REAL_DEFAULT);
lb3 = subtype(DAE.T_REAL_DEFAULT,ty);
lb1 = boolOr(lb1,boolAnd(lb2,lb3));
then lb1;
case(_) then false;
end matchcontinue;
end isRealOrSubTypeReal;
public function isIntegerOrSubTypeInteger "
Author BZ 2009-02
This function verifies if it is some kind of a Integer type we are working with.
"
input Type inType;
output Boolean b;
algorithm b := matchcontinue(inType)
local Type ty; Boolean lb1,lb2,lb3;
case(ty)
equation
lb1 = isInteger(ty);
lb2 = subtype(ty, DAE.T_INTEGER_DEFAULT);
lb3 = subtype(DAE.T_INTEGER_DEFAULT,ty);
lb1 = boolOr(lb1,boolAnd(lb2,lb3));
//lb1 = boolOr(lb1,lb2);
then lb1;
case(_) then false;
end matchcontinue;
end isIntegerOrSubTypeInteger;
public function isIntegerOrRealOrSubTypeOfEither
"Checks if a type is either some Integer or Real type."
input Type t;
output Boolean b;
algorithm
b := matchcontinue(t)
case(_) equation true = isRealOrSubTypeReal(t); then true;
case(_) equation true = isIntegerOrSubTypeInteger(t); then true;
case(_) then false;
end matchcontinue;
end isIntegerOrRealOrSubTypeOfEither;
public function isInteger "Returns true if type is Integer"
input Type tp;
output Boolean res;
algorithm
res := matchcontinue(tp)
case(tp) equation
((DAE.T_INTEGER(_),_)) = arrayElementType(tp);
then true;
case(_) then false;
end matchcontinue;
end isInteger;
public function isBoolean "Returns true if type is Boolean"
input Type tp;
output Boolean res;
algorithm
res := matchcontinue(tp)
case(tp) equation
((DAE.T_BOOL(_),_)) = arrayElementType(tp);
then true;
case(_) then false;
end matchcontinue;
end isBoolean;
public function integerOrReal "function: integerOrReal
author: PA
Succeeds for the builtin types Integer and Real (including classes extending the basetype Integer or Real).
"
input Type inType;
algorithm
_:=
matchcontinue (inType)
local Type tp;
case ((DAE.T_REAL(varLstReal = _),_)) then ();
case ((DAE.T_INTEGER(varLstInt = _),_)) then ();
case ((DAE.T_COMPLEX( complexTypeOption=SOME(tp)),_))
equation integerOrReal(tp);
then ();
end matchcontinue;
end integerOrReal;
public function isArray "function: isArray
Returns true if Type is an array.
"
input Type inType;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inType)
local Type t;
case ((DAE.T_ARRAY(arrayDim = _),_)) then true;
case ((DAE.T_COMPLEX(_,_,SOME(t),_),_)) then isArray(t);
case ((_,_)) then false;
end matchcontinue;
end isArray;
public function isString "function: isString
Return true if Type is the builtin String type.
"
input Type inType;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inType)
case ((DAE.T_STRING(varLstString = _),_)) then true;
case ((_,_)) then false;
end matchcontinue;
end isString;
public function isEnumeration "function: isEnumeration
Return true if Type is the builtin String type.
"
input Type inType;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inType)
case ((DAE.T_ENUMERATION(_, _, _, _),_)) then true;
case ((_,_)) then false;
end matchcontinue;
end isEnumeration;
public function isArrayOrString "function: isArrayOrString
Return true if Type is array or the builtin String type.
"
input Type inType;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inType)
local Type ty;
case ty
equation
true = isArray(ty);
then
true;
case ty
equation
true = isString(ty);
then
true;
case _ then false;
end matchcontinue;
end isArrayOrString;
public function ndims "function: ndims
Return the number of dimensions of a Type.
"
input Type inType;
output Integer outInteger;
algorithm
outInteger:=
matchcontinue (inType)
local
Integer n;
Type t;
case ((DAE.T_ARRAY(arrayType = t),_))
equation
n = ndims(t);
then
n + 1;
case ((DAE.T_COMPLEX(_,_,SOME(t),_),_)) equation
n = ndims(t);
then n;
case ((_,_)) then 0;
end matchcontinue;
end ndims;
public function dimensionsKnown
"function: dimensionsKnown
Returns true of the dimensions of the type is known."
input Type inType;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inType)
local Type tp;
case (tp)
equation
{} = getDimensionSizes(tp);
then
false;
case (tp)
equation
_ = getDimensionSizes(tp);
then
true;
end matchcontinue;
end dimensionsKnown;
public function stripSubmod
"function: stripSubmod
author: PA
Removes the sub modifiers of a modifier."
input Mod inMod;
output Mod outMod;
algorithm
outMod := matchcontinue (inMod)
local
Boolean f;
Absyn.Each each_;
list<SubMod> subs;
Option<EqMod> eq;
Mod m;
case (DAE.MOD(finalPrefix = f,each_ = each_,subModLst = subs,eqModOption = eq)) then DAE.MOD(f,each_,{},eq);
case (m) then m;
end matchcontinue;
end stripSubmod;
public function removeFirstSubsRedecl "
Author: BZ, 2009-08
Removed REDECLARE() statements at first level of SubMods
"
input Mod inMod;
output Mod outMod;
algorithm
outMod:=
matchcontinue (inMod)
local
Boolean f;
Absyn.Each each_;
list<SubMod> subs;
Option<EqMod> eq;
Mod m;
case (DAE.MOD(finalPrefix = f,each_ = each_,subModLst = {},eqModOption = eq)) then DAE.MOD(f,each_,{},eq);
case (DAE.MOD(finalPrefix = f,each_ = each_,subModLst = subs,eqModOption = NONE))
equation
{} = removeRedecl(subs);
then
DAE.NOMOD();
case (DAE.MOD(finalPrefix = f,each_ = each_,subModLst = subs,eqModOption = eq))
equation
subs = removeRedecl(subs);
then
DAE.MOD(f,each_,subs,eq);
case (m) then m;
end matchcontinue;
end removeFirstSubsRedecl;
protected function removeRedecl "
Author BZ
helper function for removeFirstSubsRedecl
"
input list<SubMod> subs;
output list<SubMod> osubs;
algorithm osubs := matchcontinue(subs)
local
SubMod sm;
String s;
case({}) then {};
case(DAE.NAMEMOD(s,DAE.REDECL(_,_))::subs)
equation
then removeRedecl(subs);
case(sm::subs)
equation
osubs = removeRedecl(subs);
then
sm::osubs;
end matchcontinue;
end removeRedecl;
public function removeModList "
Author BZ, 2009-07
Delete a list of named modifiers
"
input Mod inMod;
input list<String> remStrings;
output Mod outMod;
String s;
algorithm outMod := matchcontinue(inMod,remStrings)
case(inMod,{}) then inMod;
case(inMod, s::remStrings)
equation
inMod = removeMod(inMod,s);
then removeModList(inMod,remStrings);
end matchcontinue;
end removeModList;
public function removeMod "
Author: BZ, 2009-05
Remove a modifier(/s) on a specified component.
TODO: implement IDXMOD and a better support for redeclare.
"
input Mod inmod;
input String componentModified;
output Mod outmod;
algorithm outmod := matchcontinue(inmod,componentModified)
local
Boolean b;
Absyn.Each e;
list<SubMod> subs;
Option<EqMod> oem;
list<tuple<SCode.Element, Mod>> redecls;
case(DAE.NOMOD(),_) then DAE.NOMOD();
case((inmod as DAE.REDECL(b,redecls)),componentModified)
equation
redecls = removeRedeclareMods(redecls,componentModified);
outmod = Util.if_(listLength(redecls) > 0,DAE.REDECL(b,redecls), DAE.NOMOD());
then
outmod;
case(DAE.MOD(b,e,subs,oem),componentModified)
equation
subs = removeModInSubs(subs,componentModified);
then
DAE.MOD(b,e,subs,oem);
end matchcontinue;
end removeMod;
protected function removeRedeclareMods "
"
input list<tuple<SCode.Element, Mod>> inLst;
input String currComp;
output list<tuple<SCode.Element, Mod>> outLst;
algorithm outLst := matchcontinue(inLst,currComp)
local
SCode.Element comp;
Mod mod;
String s1;
case({},_) then {};
case((comp,mod)::inLst,currComp)
equation
outLst = removeRedeclareMods(inLst,currComp);
s1 = SCode.elementName(comp);
true = stringEqual(s1,currComp);
then
outLst;
case((comp,mod)::inLst,currComp)
equation
outLst = removeRedeclareMods(inLst,currComp);
then
(comp,mod)::outLst;
case(_,_) equation print("removeRedeclareMods failed\n"); then fail();
end matchcontinue;
end removeRedeclareMods;
protected function removeModInSubs "
Author BZ, 2009-05
Helper function for removeMod, removes modifiers in submods;
"
input list<SubMod> insubs;
input String componentName;
output list<SubMod> outsubs;
algorithm outsubs := matchcontinue(insubs,componentName)
local
Mod m1,m2;
list<SubMod> subs1,subs2;
String s1;
SubMod sub;
case({},_) then {};
case((sub as DAE.NAMEMOD(s1,m1))::insubs,componentName)
equation
subs1 = Util.if_(stringEqual(s1,componentName),{},{DAE.NAMEMOD(s1,m1)});
subs2 = removeModInSubs(insubs,componentName) "check for multiple mod on same comp";
outsubs = listAppend(subs1,subs2);
then
outsubs;
case((sub as DAE.IDXMOD(_,m1))::insubs,componentName)
equation
//TODO: implement check for idxmod?
subs2 = removeModInSubs(insubs,componentName);
then
sub::subs2;
end matchcontinue;
end removeModInSubs;
public function getDimensionSizes "function: getDimensionSizes
Return the dimension sizes of a Type.
"
input Type inType;
output list<Integer> outIntegerLst;
algorithm
outIntegerLst:=
matchcontinue (inType)
local
list<Integer> res;
Integer i;
Type tp;
case ((DAE.T_ARRAY(arrayDim = DAE.DIM(integerOption = SOME(i)),arrayType = tp),_))
equation
res = getDimensionSizes(tp);
then
(i :: res);
case ((DAE.T_COMPLEX(_,_,SOME(tp),_),_))
then getDimensionSizes(tp);
case ((_,_)) then {};
end matchcontinue;
end getDimensionSizes;
public function getDimensions
"Returns the dimensions of a Type.
This is a list of Option<Integer> with the dimension size for
each dimension, NONE corresponds to ':' dimension, i.e. not known."
input Type inType;
output list<Option<Integer>> outIntegerLst;
algorithm
outIntegerLst:=
matchcontinue (inType)
local
list<Option<Integer>> res;
Option<Integer> dimopt;
Type tp;
case ((DAE.T_ARRAY(arrayDim = DAE.DIM(integerOption = dimopt),arrayType = tp),_))
equation
res = getDimensions(tp);
then
(dimopt :: res);
case ((DAE.T_COMPLEX(_,_,SOME(tp),_),_))
then getDimensions(tp);
case ((_,_)) then {};
end matchcontinue;
end getDimensions;
public function printDimensionsStr "Prints dimensions to a string"
input list<Option<Integer>> dims;
output String res;
algorithm
res:=Util.stringDelimitList(Util.listMap(dims,printDimensionStr),",");
end printDimensionsStr;
protected function printDimensionStr "help function to printDimensionsStr"
input Option<Integer> dim;
output String str;
algorithm
str := matchcontinue(dim)
local Integer i;
case(SOME(i)) then intString(i);
case(NONE) then ":";
end matchcontinue;
end printDimensionStr;
protected function makeDim