/
Types.mo
8976 lines (8084 loc) · 273 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-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package Types
" file: Types.mo
package: Types
description: Type system
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 InstTypes;
public import Values;
public import SCode;
protected type Binding = DAE.Binding;
protected type Const = DAE.Const;
protected type EqualityConstraint = DAE.EqualityConstraint;
protected type FuncArg = DAE.FuncArg;
protected type Properties = DAE.Properties;
protected type TupleConst = DAE.TupleConst;
protected type Type = DAE.Type;
protected type Var = DAE.Var;
protected type EqMod = DAE.EqMod;
protected import ComponentReference;
protected import Config;
protected import Dump;
protected import Debug;
protected import Error;
protected import Expression;
protected import ExpressionDump;
protected import ExpressionSimplify;
protected import Flags;
protected import List;
protected import Patternm;
protected import Print;
protected import Util;
protected import System;
protected import ValuesUtil;
protected import DAEUtil;
protected import SCodeDump;
protected import MetaModelica.Dangerous.listReverseInPlace;
public function discreteType "Succeeds for all the discrete types, Integer, String, Boolean and enumeration."
input DAE.Type inType;
algorithm
true := isDiscreteType(inType);
end discreteType;
public function isDiscreteType
input DAE.Type inType;
output Boolean outIsDiscrete;
algorithm
outIsDiscrete := match inType
case DAE.T_INTEGER() then true;
case DAE.T_STRING() then true;
case DAE.T_BOOL() then true;
case DAE.T_CLOCK() then true;
case DAE.T_ENUMERATION() then true;
case DAE.T_SUBTYPE_BASIC() then isDiscreteType(inType.complexType);
else false;
end match;
end isDiscreteType;
public function propsAnd "Function for merging a list of properties, currently only working on DAE.PROP() and not TUPLE_DAE.PROP()."
input list<DAE.Properties> inProps;
output DAE.Properties outProp;
algorithm outProp := matchcontinue(inProps)
local
Properties prop,prop2;
Const c,c2;
Type ty,ty2;
list<DAE.Properties> props;
case(prop::{}) then prop;
case((DAE.PROP(ty,c))::props)
equation
(DAE.PROP(ty2,c2)) = propsAnd(props);
c = constAnd(c,c2);
true = equivtypes(ty,ty2);
then
DAE.PROP(ty,c);
end matchcontinue;
end propsAnd;
public function makePropsNotConst
"returns the same Properties but with the const flag set to Var"
input DAE.Properties inProperties;
output DAE.Properties outProperties;
algorithm outProperties := match (inProperties)
local
Type t;
case(DAE.PROP(type_=t)) then DAE.PROP(t,DAE.C_VAR());
end match;
end makePropsNotConst;
// stefan
public function getConstList
"retrieves a list of Consts from a list of Properties"
input list<DAE.Properties> inPropertiesList;
output list<DAE.Const> outConstList;
algorithm
outConstList := match(inPropertiesList)
local
Const c;
list<DAE.Const> ccdr;
list<DAE.Properties> pcdr;
TupleConst tc;
case({}) then {};
case(DAE.PROP(constFlag=c) :: pcdr)
equation
ccdr = getConstList(pcdr);
then
c :: ccdr;
case(DAE.PROP_TUPLE(tupleConst=tc) :: pcdr)
equation
c = propertiesListToConst2(tc);
ccdr = getConstList(pcdr);
then
c :: ccdr;
end match;
end getConstList;
public function propertiesListToConst "this function elaborates on a DAE.Properties and return the DAE.Const value."
input list<DAE.Properties> p;
output DAE.Const c;
algorithm
c := match (p)
local
Properties p1;
list<DAE.Properties> pps;
Const c1,c2;
TupleConst tc1;
case({}) then DAE.C_CONST();
case ((DAE.PROP(_,c1))::pps)
equation
c2 = propertiesListToConst(pps);
c1 = constAnd(c1, c2);
then
c1;
case((DAE.PROP_TUPLE(_,tc1))::pps)
equation
c1 = propertiesListToConst2(tc1);
c2 = propertiesListToConst(pps);
c1 = constAnd(c1, c2);
then
c1;
end match;
end propertiesListToConst;
protected function propertiesListToConst2 ""
input DAE.TupleConst t;
output DAE.Const c;
algorithm
c := match (t)
local
TupleConst p1;
Const c1,c2;
list<TupleConst> tcxl;
TupleConst tc1;
case (DAE.SINGLE_CONST(c1)) then c1;
case(DAE.TUPLE_CONST(tc1::tcxl))
equation
c1 = propertiesListToConst2(tc1);
c2 = tupleConstListToConst(tcxl);
c1 = constAnd(c1, c2);
then
c1;
end match;
end propertiesListToConst2;
public function tupleConstListToConst ""
input list<DAE.TupleConst> t;
output DAE.Const c;
algorithm
c := match (t)
local
TupleConst p1;
Const c1,c2;
list<TupleConst> tcxl;
case({}) then DAE.C_CONST();
case((DAE.SINGLE_CONST(c1))::tcxl)
equation
c2 = tupleConstListToConst(tcxl);
c1 = constAnd(c1, c2);
then
c1;
case((p1 as DAE.TUPLE_CONST(_))::tcxl)
equation
c1 = propertiesListToConst2(p1);
c2 = tupleConstListToConst(tcxl);
c1 = constAnd(c1, c2);
then
c1;
end match;
end tupleConstListToConst;
public function externalObjectType
"author: PA
Succeeds if type is ExternalObject"
input DAE.Type inType;
algorithm
_ := match (inType)
case DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(_)) then ();
end match;
end externalObjectType;
public function varName "
Author BZ, 2009-09
Function for getting the name of a DAE.Var"
input DAE.Var v;
output String s;
algorithm
DAE.TYPES_VAR(name = s) := v;
end varName;
public function varBinding
input DAE.Var inVar;
output DAE.Binding outBinding;
algorithm
DAE.TYPES_VAR(binding = outBinding) := inVar;
end varBinding;
public function varEqualName
input DAE.Var inVar1;
input DAE.Var inVar2;
output Boolean outEqual;
protected
String name1, name2;
algorithm
DAE.TYPES_VAR(name = name1) := inVar1;
DAE.TYPES_VAR(name = name2) := inVar2;
outEqual := name1 == name2;
end varEqualName;
public function externalObjectConstructorType "author: PA
Succeeds if type is ExternalObject constructor function"
input DAE.Type inType;
algorithm
_ := match (inType)
local Type tp;
case DAE.T_FUNCTION(funcResultType = tp)
equation
externalObjectType(tp);
then ();
end match;
end externalObjectConstructorType;
public function simpleType "author: PA
Succeeds for all the builtin types, Integer, String, Real, Boolean"
input DAE.Type inType;
algorithm
true := isSimpleType(inType);
end simpleType;
public function isSimpleType
"Returns true for all the builtin types, Integer, String, Real, Boolean"
input DAE.Type inType;
output Boolean b;
algorithm
b := match (inType)
local DAE.Type t;
case (DAE.T_REAL()) then true;
case (DAE.T_INTEGER()) then true;
case (DAE.T_STRING()) then true;
case (DAE.T_BOOL()) then true;
// BTH
case (DAE.T_CLOCK()) then true;
case (DAE.T_ENUMERATION()) then true;
case (DAE.T_SUBTYPE_BASIC(complexType = t)) then isSimpleType(t);
else false;
end match;
end isSimpleType;
public function isSimpleNumericType
"Returns true for simple numeric builtin types, Integer and Real"
input DAE.Type inType;
output Boolean b;
algorithm
b := match (inType)
local DAE.Type t;
case (DAE.T_REAL()) then true;
case (DAE.T_INTEGER()) then true;
case (DAE.T_SUBTYPE_BASIC(complexType = t)) then isSimpleNumericType(t);
else false;
end match;
end isSimpleNumericType;
public function isNumericType "This function checks if the element type is Numeric type or array of Numeric type."
input DAE.Type inType;
output Boolean outBool;
algorithm
outBool := match (inType)
local Type ty;
case (DAE.T_ARRAY(ty = ty)) then isNumericType(ty);
case (DAE.T_SUBTYPE_BASIC(complexType = ty)) then isNumericType(ty);
else isSimpleNumericType(inType);
end match;
end isNumericType;
public function isConnector
"Returns true if the given type is a connector type, otherwise false."
input DAE.Type inType;
output Boolean outIsConnector;
algorithm
outIsConnector := match(inType)
case DAE.T_COMPLEX(complexClassType = ClassInf.CONNECTOR()) then true;
case DAE.T_SUBTYPE_BASIC(complexClassType = ClassInf.CONNECTOR()) then true;
else false;
end match;
end isConnector;
public function isComplexConnector
"Returns true if the given type is a complex connector type, i.e. a connector
with components, otherwise false."
input DAE.Type inType;
output Boolean outIsComplexConnector;
algorithm
outIsComplexConnector := match(inType)
case DAE.T_COMPLEX(complexClassType = ClassInf.CONNECTOR()) then true;
else false;
end match;
end isComplexConnector;
public function isComplexExpandableConnector
"Returns true if the given type is an expandable connector, otherwise false."
input DAE.Type inType;
output Boolean outResult;
algorithm
outResult := match(inType)
case DAE.T_COMPLEX(complexClassType =
ClassInf.CONNECTOR(isExpandable = true)) then true;
case DAE.T_SUBTYPE_BASIC(complexClassType =
ClassInf.CONNECTOR(isExpandable = true)) then true;
else false;
end match;
end isComplexExpandableConnector;
public function isComplexType "
Author: BZ, 2008-11
This function checks wheter a type is complex AND not extending a base type."
input DAE.Type ity;
output Boolean b;
algorithm
b := match(ity)
local Type ty;
case (DAE.T_SUBTYPE_BASIC(complexType = ty)) then isComplexType(ty);
case (DAE.T_COMPLEX(varLst = _::_)) then true; // not derived from baseclass
else false;
end match;
end isComplexType;
public function isExternalObject "Returns true if type is COMPLEX and external object (ClassInf)"
input DAE.Type tp;
output Boolean b;
algorithm
b := match(tp)
case (DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(_))) then true;
else false;
end match;
end isExternalObject;
public function expTypetoTypesType
" Converts a DAE.Type to a DAE.Type
NOTE: This function should not be used in general, since it is not recommended to translate DAE.Type into DAE.Type."
input DAE.Type inType;
output DAE.Type oType;
algorithm
oType := matchcontinue(inType)
local
Type ty,tty;
Type at;
DAE.Dimensions ad;
DAE.Dimension dim;
DAE.TypeSource ts;
Integer ll;
list<DAE.Var> vars;
ClassInf.State CIS;
DAE.EqualityConstraint ec;
// convert just the array!
case(DAE.T_ARRAY(at,dim::ad,ts))
equation
ll = listLength(ad);
true = (ll == 0);
ty = expTypetoTypesType(at);
tty = DAE.T_ARRAY(ty,{dim},ts);
then
tty;
case(DAE.T_ARRAY(at,dim::ad,ts))
equation
ll = listLength(ad);
true = (ll > 0);
ty = expTypetoTypesType(DAE.T_ARRAY(at,ad,ts));
tty = DAE.T_ARRAY(ty,{dim},ts);
then
tty;
case (DAE.T_COMPLEX(CIS, vars, ec, ts))
equation
vars = List.map(vars, convertFromExpToTypesVar);
then
DAE.T_COMPLEX(CIS, vars, ec, ts);
case (DAE.T_SUBTYPE_BASIC(CIS, vars, ty, ec, ts))
equation
vars = List.map(vars, convertFromExpToTypesVar);
ty = expTypetoTypesType(ty);
then
DAE.T_SUBTYPE_BASIC(CIS, vars, ty, ec, ts);
case (DAE.T_METABOXED(ty, ts))
equation
ty = expTypetoTypesType(ty);
then
DAE.T_METABOXED(ty, ts);
// the rest fall in line!
else inType;
end matchcontinue;
end expTypetoTypesType;
protected function convertFromExpToTypesVar ""
input DAE.Var inVar;
output DAE.Var outVar;
algorithm
outVar := matchcontinue(inVar)
local
String name;
Type ty;
DAE.Attributes attributes;
Binding binding;
Option<DAE.Const> constOfForIteratorRange;
case(DAE.TYPES_VAR(name, attributes, ty, binding, constOfForIteratorRange))
equation
ty = expTypetoTypesType(ty);
then
DAE.TYPES_VAR(name, attributes, ty, binding, constOfForIteratorRange);
else equation print("error in Types.convertFromExpToTypesVar\n"); then fail();
end matchcontinue;
end convertFromExpToTypesVar;
public function isTuple "Returns true if type is TUPLE"
input DAE.Type tp;
output Boolean b;
algorithm
b := match(tp)
case (DAE.T_TUPLE()) then true;
else false;
end match;
end isTuple;
public function isMetaTuple "Returns true if type is TUPLE"
input DAE.Type tp;
output Boolean b;
algorithm
b := match(tp)
case (DAE.T_METATUPLE()) then true;
else false;
end match;
end isMetaTuple;
public function isRecord "Returns true if type is COMPLEX and a record (ClassInf)"
input DAE.Type tp;
output Boolean b;
algorithm
b := match(tp)
case (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(_))) then true;
else false;
end match;
end isRecord;
public function getRecordPath "gets the record path"
input DAE.Type tp;
output Absyn.Path p;
algorithm
p := match(tp)
case (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(p)))
then p;
end match;
end getRecordPath;
public function isRecordWithOnlyReals "Returns true if type is a record only containing Reals"
input DAE.Type tp;
output Boolean b;
algorithm
b := match (tp)
local
list<DAE.Var> varLst;
case (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(_),varLst = varLst))
then List.mapAllValueBool(List.map(varLst,getVarType),isReal,true);
// otherwise false
else false;
end match;
end isRecordWithOnlyReals;
public function getVarType "Return the Type of a Var"
input DAE.Var v;
output DAE.Type tp;
algorithm
tp := match (v)
case(DAE.TYPES_VAR(ty = tp)) then tp;
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"Types.getVarType failed"});
then fail();
end match;
end getVarType;
public function varIsVariable
input DAE.Var v;
output Boolean b;
algorithm
b := match v
case DAE.TYPES_VAR(attributes=DAE.ATTR(variability=SCode.VAR())) then true;
case DAE.TYPES_VAR(attributes=DAE.ATTR(variability=SCode.DISCRETE())) then true;
else false;
end match;
end varIsVariable;
public function getVarName "Return the name of a Var"
input DAE.Var v;
output String name;
algorithm
name := match (v)
case(DAE.TYPES_VAR(name = name)) then name;
end match;
end getVarName;
public function isReal "Returns true if type is Real"
input DAE.Type tp;
output Boolean res;
algorithm
res := isScalarReal(arrayElementType(tp));
end isReal;
public function isScalarReal
input DAE.Type inType;
output Boolean outIsScalarReal;
algorithm
outIsScalarReal := match(inType)
local
Type ty;
case DAE.T_REAL() then true;
case DAE.T_SUBTYPE_BASIC(complexType = ty) then isScalarReal(ty);
else false;
end match;
end isScalarReal;
public function isRealOrSubTypeReal "
Author BZ 2008-05
This function verifies if it is some kind of a Real type we are working with."
input DAE.Type inType;
output Boolean b;
protected
Boolean lb1, lb2;
algorithm
lb1 := isReal(inType);
lb2 := equivtypes(inType, DAE.T_REAL_DEFAULT);
b := lb1 or lb2;
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 DAE.Type inType;
output Boolean b;
protected
Boolean lb1, lb2;
algorithm
lb1 := isInteger(inType);
lb2 := equivtypes(inType, DAE.T_INTEGER_DEFAULT);
b := lb1 or lb2;
end isIntegerOrSubTypeInteger;
protected function isClockOrSubTypeClock1
input DAE.Type inType;
output Boolean b;
protected
Boolean lb1, lb2, lb3;
algorithm
lb1 := isClock(inType);
lb2 := equivtypes(inType, DAE.T_CLOCK_DEFAULT);
lb3 := not equivtypes(inType, DAE.T_UNKNOWN_DEFAULT);
b := lb1 or (lb2 and lb3);
end isClockOrSubTypeClock1;
public function isClockOrSubTypeClock
input DAE.Type inType;
output Boolean b;
algorithm
b := match inType
local
DAE.Type ty;
case DAE.T_FUNCTION(funcResultType=ty)
then isClockOrSubTypeClock1(ty);
else isClockOrSubTypeClock1(inType);
end match;
end isClockOrSubTypeClock;
public function isBooleanOrSubTypeBoolean
"@author: adrpo
This function verifies if it is some kind of a Boolean type we are working with."
input DAE.Type inType;
output Boolean b;
protected
Boolean lb1, lb2;
algorithm
lb1 := isBoolean(inType);
lb2 := equivtypes(inType, DAE.T_BOOL_DEFAULT);
b := lb1 or lb2;
end isBooleanOrSubTypeBoolean;
public function isStringOrSubTypeString
"@author: adrpo
This function verifies if it is some kind of a String type we are working with."
input DAE.Type inType;
output Boolean b;
protected
Boolean lb1, lb2;
algorithm
lb1 := isString(inType);
lb2 := equivtypes(inType, DAE.T_STRING_DEFAULT);
b := lb1 or lb2;
end isStringOrSubTypeString;
public function isIntegerOrRealOrSubTypeOfEither
"Checks if a type is either some Integer or Real type."
input DAE.Type t;
output Boolean b;
algorithm
b := match(t)
case _ guard isRealOrSubTypeReal(t) then true;
case _ guard isIntegerOrSubTypeInteger(t) then true;
else false;
end match;
end isIntegerOrRealOrSubTypeOfEither;
public function isIntegerOrRealOrBooleanOrSubTypeOfEither
"Checks if a type is either some Integer or Real type."
input DAE.Type t;
output Boolean b;
algorithm
b := match(t)
case _ guard isRealOrSubTypeReal(t) then true;
case _ guard isIntegerOrSubTypeInteger(t) then true;
case _ guard isBooleanOrSubTypeBoolean(t) then true;
else false;
end match;
end isIntegerOrRealOrBooleanOrSubTypeOfEither;
public function isClock
input DAE.Type tp;
output Boolean res;
algorithm
res := isScalarClock(arrayElementType(tp));
end isClock;
public function isScalarClock
input DAE.Type inType;
output Boolean res;
algorithm
res := match inType
local
Type ty;
case DAE.T_CLOCK() then true;
case DAE.T_SUBTYPE_BASIC(complexType = ty) then isScalarClock(ty);
else false;
end match;
end isScalarClock;
public function isInteger "Returns true if type is Integer"
input DAE.Type tp;
output Boolean res;
algorithm
res := isScalarInteger(arrayElementType(tp));
end isInteger;
public function isScalarInteger
input DAE.Type inType;
output Boolean outIsScalarInteger;
algorithm
outIsScalarInteger := match(inType)
local
Type ty;
case DAE.T_INTEGER() then true;
case DAE.T_SUBTYPE_BASIC(complexType = ty) then isScalarInteger(ty);
else false;
end match;
end isScalarInteger;
public function isBoolean "Returns true if type is Boolean"
input DAE.Type tp;
output Boolean res;
algorithm
res := isScalarBoolean(arrayElementType(tp));
end isBoolean;
public function isScalarBoolean
input DAE.Type inType;
output Boolean outIsScalarBoolean;
algorithm
outIsScalarBoolean := match(inType)
local
Type ty;
case DAE.T_BOOL() then true;
case DAE.T_SUBTYPE_BASIC(complexType = ty) then isScalarBoolean(ty);
else false;
end match;
end isScalarBoolean;
public function integerOrReal "author: PA
Succeeds for the builtin types Integer and Real
(including classes extending the basetype Integer or Real)."
input DAE.Type inType;
algorithm
_ := match (inType)
local Type tp;
case (DAE.T_REAL()) then ();
case (DAE.T_INTEGER()) then ();
case (DAE.T_SUBTYPE_BASIC(complexType = tp))
equation
integerOrReal(tp);
then ();
end match;
end integerOrReal;
public function isNonscalarArray
"Returns true if Type is an nonscalar array (array of arrays)."
input DAE.Type inType;
input DAE.Dimensions inDims;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inType,inDims)
local
Type t;
list<Type> tys;
Boolean b;
// several (at least 2) dimensions means array!
case (_, _::_::_) then true;
// if the type is an array, then is an array
case (DAE.T_ARRAY(),_) then true;
// if is a type extending basic type
case (DAE.T_SUBTYPE_BASIC(complexType = t),_) then isNonscalarArray(t, {});
case (DAE.T_TUPLE(types = tys), _)
equation
b = List.applyAndFold1(tys, boolOr, isNonscalarArray, {}, false);
then
b;
else false;
end matchcontinue;
end isNonscalarArray;
public function isArray
"Returns true if the given type is an array type."
input DAE.Type inType;
output Boolean outIsArray;
algorithm
outIsArray := match inType
case DAE.T_ARRAY() then true;
case DAE.T_SUBTYPE_BASIC() then isArray(inType.complexType);
case DAE.T_FUNCTION() then isArray(inType.funcResultType);
else false;
end match;
end isArray;
public function isEmptyArray
input DAE.Type inType;
output Boolean outBoolean;
algorithm
outBoolean := match(inType)
case DAE.T_ARRAY(dims = {DAE.DIM_INTEGER(0)}) then true;
else false;
end match;
end isEmptyArray;
public function isString "Return true if Type is the builtin String type."
input DAE.Type inType;
output Boolean outBoolean;
algorithm
outBoolean := match(inType)
case (DAE.T_STRING()) then true;
else false;
end match;
end isString;
public function isEnumeration "Return true if Type is the builtin String type."
input DAE.Type inType;
output Boolean outBoolean;
algorithm
outBoolean := match(inType)
case (DAE.T_ENUMERATION()) then true;
else false;
end match;
end isEnumeration;
public function isArrayOrString "Return true if Type is array or the builtin String type."
input DAE.Type inType;
output Boolean outBoolean;
algorithm
outBoolean := match (inType)
local Type ty;
case ty guard isArray(ty) then true;
case ty guard isString(ty) then true;
else false;
end match;
end isArrayOrString;
public function numberOfDimensions "Return the number of dimensions of a Type."
input DAE.Type inType;
output Integer outInteger;
algorithm
outInteger := matchcontinue (inType)
local
Integer n;
Type t;
DAE.Dimensions dims;
case (DAE.T_ARRAY(ty = t, dims = dims))
equation
n = numberOfDimensions(t);
n = n + listLength(dims);
then
n;
case (DAE.T_SUBTYPE_BASIC(complexType = t))
equation
n = numberOfDimensions(t);
then n;
else 0;
end matchcontinue;
end numberOfDimensions;
public function dimensionsKnown
"Returns true if the dimensions of the type is known."
input DAE.Type inType;
output Boolean outRes;
algorithm
outRes := matchcontinue(inType)
local
DAE.Dimension d;
DAE.Dimensions dims;
Type tp;
DAE.TypeSource ts;
case (DAE.T_ARRAY(dims = d::dims, ty = tp, source = ts))
equation
true = Expression.dimensionKnown(d);
true = dimensionsKnown(DAE.T_ARRAY(tp, dims, ts));
then
true;
case (DAE.T_ARRAY(dims = {}, ty = tp))
equation
true = dimensionsKnown(tp);
then
true;
case (DAE.T_ARRAY())
then false;
case (DAE.T_SUBTYPE_BASIC(complexType = tp))
then dimensionsKnown(tp);
else true;
end matchcontinue;
end dimensionsKnown;
public function getDimensionSizes "Return the dimension sizes of a Type."
input DAE.Type inType;
output list<Integer> outIntegerLst;
algorithm
outIntegerLst := matchcontinue (inType)
local
list<Integer> res;
DAE.Dimension d;
DAE.Dimensions dims;
Integer i;
Type tp;
DAE.TypeSource ts;
case (DAE.T_ARRAY(dims = d::dims,ty = tp, source = ts))
equation
i = Expression.dimensionSize(d);
res = getDimensionSizes(DAE.T_ARRAY(tp, dims, ts));
then
(i :: res);
case (DAE.T_ARRAY(dims = _::dims, ty = tp, source = ts))
equation
res = getDimensionSizes(DAE.T_ARRAY(tp, dims, ts));
then
(0 :: res);
case (DAE.T_ARRAY(dims = {},ty = tp))
equation
res = getDimensionSizes(tp);
then
res;
case (DAE.T_SUBTYPE_BASIC(complexType=tp))
then getDimensionSizes(tp);
else
equation
false = arrayType(inType);
then
{};
end matchcontinue;
end getDimensionSizes;
public function getDimensionProduct "Return the dimension sizes of a Type."
input DAE.Type inType;
output Integer sz;
algorithm
sz := match (inType)
local
list<Integer> res;
DAE.Dimensions dims;
Integer i;
Type tp;
DAE.TypeSource ts;
case (DAE.T_ARRAY(dims = dims,ty = tp, source = ts))
then product(Expression.dimensionSize(d) for d in dims) * getDimensionProduct(tp);
case (DAE.T_SUBTYPE_BASIC(complexType=tp))
then getDimensionProduct(tp);
else
equation
false = arrayType(inType);
then 1;
end match;
end getDimensionProduct;
public function getDimensions
"Returns the dimensions of a Type."
input DAE.Type inType;
output DAE.Dimensions outDimensions;
algorithm