forked from ballerina-platform/nballerina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboolean.bal
58 lines (49 loc) · 1.69 KB
/
boolean.bal
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
// Implementation specific to basic type boolean.
public type BooleanSubtype readonly & record {|
boolean value;
|};
public function booleanConst(boolean value) returns ComplexSemType {
BooleanSubtype t = { value };
return basicSubtype(BT_BOOLEAN, t);
}
function booleanSubtypeSingleValue(SubtypeData d) returns boolean? {
if d is boolean {
return ();
}
BooleanSubtype b = <BooleanSubtype>d;
return b.value;
}
function booleanSubtypeContains(SubtypeData d, boolean b) returns boolean {
if d is boolean {
return d;
}
BooleanSubtype r = <BooleanSubtype>d;
return r.value == b;
}
function booleanSubtypeUnion(ProperSubtypeData d1, ProperSubtypeData d2) returns SubtypeData {
BooleanSubtype v1 = <BooleanSubtype>d1;
BooleanSubtype v2 = <BooleanSubtype>d2;
return v1.value == v2.value ? v1 : true;
}
function booleanSubtypeIntersect(ProperSubtypeData d1, ProperSubtypeData d2) returns SubtypeData {
BooleanSubtype v1 = <BooleanSubtype>d1;
BooleanSubtype v2 = <BooleanSubtype>d2;
return v1.value == v2.value ? v1 : false;
}
function booleanSubtypeDiff(ProperSubtypeData d1, ProperSubtypeData d2) returns SubtypeData {
BooleanSubtype v1 = <BooleanSubtype>d1;
BooleanSubtype v2 = <BooleanSubtype>d2;
return v1.value == v2.value ? false : v1;
}
function booleanSubtypeComplement(ProperSubtypeData d) returns ProperSubtypeData {
BooleanSubtype v = <BooleanSubtype>d;
BooleanSubtype t = { value: !v.value };
return t;
}
final BasicTypeOps booleanOps = {
union: booleanSubtypeUnion,
intersect: booleanSubtypeIntersect,
diff: booleanSubtypeDiff,
complement: booleanSubtypeComplement,
isEmpty: notIsEmpty
};