@@ -16,6 +16,215 @@ extension Expression {
16
16
func toBridge( ) -> ExprBridge {
17
17
return ( self as! BridgeWrapper ) . bridge
18
18
}
19
+
20
+ /// Creates an expression applying bitwise AND between this expression and an integer literal.
21
+ /// Assumes `self` evaluates to an Integer or Bytes.
22
+ ///
23
+ /// - Note: This API is in beta.
24
+ ///
25
+ /// ```swift
26
+ /// // Bitwise AND of "flags" field and 0xFF
27
+ /// Field("flags").bitAnd(0xFF)
28
+ /// ```
29
+ ///
30
+ /// - Parameter otherBits: The integer literal operand.
31
+ /// - Returns: A new "FunctionExpression" representing the bitwise AND operation.
32
+ func bitAnd( _ otherBits: Int ) -> FunctionExpression {
33
+ return FunctionExpression ( " bit_and " , [ self , Helper . sendableToExpr ( otherBits) ] )
34
+ }
35
+
36
+ /// Creates an expression applying bitwise AND between this expression and a UInt8 literal (often
37
+ /// for byte masks).
38
+ /// Assumes `self` evaluates to an Integer or Bytes.
39
+ /// - Note: This API is in beta.
40
+ /// ```swift
41
+ /// // Bitwise AND of "byteFlags" field and a byte mask
42
+ /// Field("byteFlags").bitAnd(0b00001111 as UInt8)
43
+ /// ```
44
+ /// - Parameter otherBits: The UInt8 literal operand.
45
+ /// - Returns: A new "FunctionExpression" representing the bitwise AND operation.
46
+ func bitAnd( _ otherBits: UInt8 ) -> FunctionExpression {
47
+ return FunctionExpression ( " bit_and " , [ self , Helper . sendableToExpr ( otherBits) ] )
48
+ }
49
+
50
+ /// Creates an expression applying bitwise AND between this expression and another expression.
51
+ /// Assumes `self` and `bitsExpression` evaluate to Integer or Bytes.
52
+ /// - Note: This API is in beta.
53
+ ///
54
+ /// ```swift
55
+ /// // Bitwise AND of "mask1" and "mask2" fields
56
+ /// Field("mask1").bitAnd(Field("mask2"))
57
+ /// ```
58
+ /// - Parameter bitsExpression: The other `Expr` operand.
59
+ /// - Returns: A new "FunctionExpression" representing the bitwise AND operation.
60
+ func bitAnd( _ bitsExpression: Expression ) -> FunctionExpression {
61
+ return FunctionExpression ( " bit_and " , [ self , bitsExpression] )
62
+ }
63
+
64
+ /// Creates an expression applying bitwise OR between this expression and an integer literal.
65
+ /// Assumes `self` evaluates to an Integer or Bytes.
66
+ ///
67
+ /// - Note: This API is in beta.
68
+ ///
69
+ /// ```swift
70
+ /// // Bitwise OR of "flags" field and 0x01
71
+ /// Field("flags").bitOr(0x01)
72
+ /// ```
73
+ ///
74
+ /// - Parameter otherBits: The integer literal operand.
75
+ /// - Returns: A new "FunctionExpression" representing the bitwise OR operation.
76
+ func bitOr( _ otherBits: Int ) -> FunctionExpression {
77
+ return FunctionExpression ( " bit_or " , [ self , Helper . sendableToExpr ( otherBits) ] )
78
+ }
79
+
80
+ /// Creates an expression applying bitwise OR between this expression and a UInt8 literal.
81
+ /// Assumes `self` evaluates to an Integer or Bytes.
82
+ /// - Note: This API is in beta.
83
+ /// ```swift
84
+ /// // Set specific bits in "controlByte"
85
+ /// Field("controlByte").bitOr(0b10000001 as UInt8)
86
+ /// ```
87
+ /// - Parameter otherBits: The UInt8 literal operand.
88
+ /// - Returns: A new "FunctionExpression" representing the bitwise OR operation.
89
+ func bitOr( _ otherBits: UInt8 ) -> FunctionExpression {
90
+ return FunctionExpression ( " bit_or " , [ self , Helper . sendableToExpr ( otherBits) ] )
91
+ }
92
+
93
+ /// Creates an expression applying bitwise OR between this expression and another expression.
94
+ /// Assumes `self` and `bitsExpression` evaluate to Integer or Bytes.
95
+ /// - Note: This API is in beta.
96
+ ///
97
+ /// ```swift
98
+ /// // Bitwise OR of "permissionSet1" and "permissionSet2" fields
99
+ /// Field("permissionSet1").bitOr(Field("permissionSet2"))
100
+ /// ```
101
+ /// - Parameter bitsExpression: The other `Expr` operand.
102
+ /// - Returns: A new "FunctionExpression" representing the bitwise OR operation.
103
+ func bitOr( _ bitsExpression: Expression ) -> FunctionExpression {
104
+ return FunctionExpression ( " bit_or " , [ self , bitsExpression] )
105
+ }
106
+
107
+ /// Creates an expression applying bitwise XOR between this expression and an integer literal.
108
+ /// Assumes `self` evaluates to an Integer or Bytes.
109
+ ///
110
+ /// - Note: This API is in beta.
111
+ ///
112
+ /// ```swift
113
+ /// // Bitwise XOR of "toggle" field and 0xFFFF
114
+ /// Field("toggle").bitXor(0xFFFF)
115
+ /// ```
116
+ ///
117
+ /// - Parameter otherBits: The integer literal operand.
118
+ /// - Returns: A new "FunctionExpression" representing the bitwise XOR operation.
119
+ func bitXor( _ otherBits: Int ) -> FunctionExpression {
120
+ return FunctionExpression ( " bit_xor " , [ self , Helper . sendableToExpr ( otherBits) ] )
121
+ }
122
+
123
+ /// Creates an expression applying bitwise XOR between this expression and a UInt8 literal.
124
+ /// Assumes `self` evaluates to an Integer or Bytes.
125
+ /// - Note: This API is in beta.
126
+ /// ```swift
127
+ /// // Toggle bits in "statusByte" using a XOR mask
128
+ /// Field("statusByte").bitXor(0b01010101 as UInt8)
129
+ /// ```
130
+ /// - Parameter otherBits: The UInt8 literal operand.
131
+ /// - Returns: A new "FunctionExpression" representing the bitwise XOR operation.
132
+ func bitXor( _ otherBits: UInt8 ) -> FunctionExpression {
133
+ return FunctionExpression ( " bit_xor " , [ self , Helper . sendableToExpr ( otherBits) ] )
134
+ }
135
+
136
+ /// Creates an expression applying bitwise XOR between this expression and another expression.
137
+ /// Assumes `self` and `bitsExpression` evaluate to Integer or Bytes.
138
+ /// - Note: This API is in beta.
139
+ ///
140
+ /// ```swift
141
+ /// // Bitwise XOR of "key1" and "key2" fields (assuming Bytes)
142
+ /// Field("key1").bitXor(Field("key2"))
143
+ /// ```
144
+ /// - Parameter bitsExpression: The other `Expr` operand.
145
+ /// - Returns: A new "FunctionExpression" representing the bitwise XOR operation.
146
+ func bitXor( _ bitsExpression: Expression ) -> FunctionExpression {
147
+ return FunctionExpression ( " bit_xor " , [ self , bitsExpression] )
148
+ }
149
+
150
+ /// Creates an expression applying bitwise NOT to this expression.
151
+ /// Assumes `self` evaluates to an Integer or Bytes.
152
+ ///
153
+ /// - Note: This API is in beta.
154
+ ///
155
+ /// ```swift
156
+ /// // Bitwise NOT of "mask" field
157
+ /// Field("mask").bitNot()
158
+ /// ```
159
+ ///
160
+ /// - Returns: A new "FunctionExpression" representing the bitwise NOT operation.
161
+ func bitNot( ) -> FunctionExpression {
162
+ return FunctionExpression ( " bit_not " , [ self ] )
163
+ }
164
+
165
+ /// Creates an expression applying bitwise left shift to this expression by a literal number of
166
+ /// bits.
167
+ /// Assumes `self` evaluates to Integer or Bytes.
168
+ ///
169
+ /// - Note: This API is in beta.
170
+ ///
171
+ /// ```swift
172
+ /// // Left shift "value" field by 2 bits
173
+ /// Field("value").bitLeftShift(2)
174
+ /// ```
175
+ ///
176
+ /// - Parameter y: The number of bits (Int literal) to shift by.
177
+ /// - Returns: A new "FunctionExpression" representing the bitwise left shift operation.
178
+ func bitLeftShift( _ y: Int ) -> FunctionExpression {
179
+ return FunctionExpression ( " bit_left_shift " , [ self , Helper . sendableToExpr ( y) ] )
180
+ }
181
+
182
+ /// Creates an expression applying bitwise left shift to this expression by a number of bits
183
+ /// specified by an expression.
184
+ /// Assumes `self` evaluates to Integer or Bytes, and `numberExpr` evaluates to an Integer.
185
+ /// - Note: This API is in beta.
186
+ ///
187
+ /// ```swift
188
+ /// // Left shift "data" by number of bits in "shiftCount" field
189
+ /// Field("data").bitLeftShift(Field("shiftCount"))
190
+ /// ```
191
+ /// - Parameter numberExpr: An `Expr` (evaluating to an Int) for the number of bits to shift by.
192
+ /// - Returns: A new "FunctionExpression" representing the bitwise left shift operation.
193
+ func bitLeftShift( _ numberExpression: Expression ) -> FunctionExpression {
194
+ return FunctionExpression ( " bit_left_shift " , [ self , numberExpression] )
195
+ }
196
+
197
+ /// Creates an expression applying bitwise right shift to this expression by a literal number of
198
+ /// bits.
199
+ /// Assumes `self` evaluates to Integer or Bytes.
200
+ ///
201
+ /// - Note: This API is in beta.
202
+ ///
203
+ /// ```swift
204
+ /// // Right shift "value" field by 4 bits
205
+ /// Field("value").bitRightShift(4)
206
+ /// ```
207
+ ///
208
+ /// - Parameter y: The number of bits (Int literal) to shift by.
209
+ /// - Returns: A new "FunctionExpression" representing the bitwise right shift operation.
210
+ func bitRightShift( _ y: Int ) -> FunctionExpression {
211
+ return FunctionExpression ( " bit_right_shift " , [ self , Helper . sendableToExpr ( y) ] )
212
+ }
213
+
214
+ /// Creates an expression applying bitwise right shift to this expression by a number of bits
215
+ /// specified by an expression.
216
+ /// Assumes `self` evaluates to Integer or Bytes, and `numberExpr` evaluates to an Integer.
217
+ /// - Note: This API is in beta.
218
+ ///
219
+ /// ```swift
220
+ /// // Right shift "data" by number of bits in "shiftCount" field
221
+ /// Field("data").bitRightShift(Field("shiftCount"))
222
+ /// ```
223
+ /// - Parameter numberExpr: An `Expr` (evaluating to an Int) for the number of bits to shift by.
224
+ /// - Returns: A new "FunctionExpression" representing the bitwise right shift operation.
225
+ func bitRightShift( _ numberExpression: Expression ) -> FunctionExpression {
226
+ return FunctionExpression ( " bit_right_shift " , [ self , numberExpression] )
227
+ }
19
228
}
20
229
21
230
public extension Expression {
@@ -533,64 +742,6 @@ public extension Expression {
533
742
)
534
743
}
535
744
536
- // MARK: - Bitwise operations
537
-
538
- func bitAnd( _ otherBits: Int ) -> FunctionExpression {
539
- return FunctionExpression ( " bit_and " , [ self , Helper . sendableToExpr ( otherBits) ] )
540
- }
541
-
542
- func bitAnd( _ otherBits: UInt8 ) -> FunctionExpression {
543
- return FunctionExpression ( " bit_and " , [ self , Helper . sendableToExpr ( otherBits) ] )
544
- }
545
-
546
- func bitAnd( _ bitsExpression: Expression ) -> FunctionExpression {
547
- return FunctionExpression ( " bit_and " , [ self , bitsExpression] )
548
- }
549
-
550
- func bitOr( _ otherBits: Int ) -> FunctionExpression {
551
- return FunctionExpression ( " bit_or " , [ self , Helper . sendableToExpr ( otherBits) ] )
552
- }
553
-
554
- func bitOr( _ otherBits: UInt8 ) -> FunctionExpression {
555
- return FunctionExpression ( " bit_or " , [ self , Helper . sendableToExpr ( otherBits) ] )
556
- }
557
-
558
- func bitOr( _ bitsExpression: Expression ) -> FunctionExpression {
559
- return FunctionExpression ( " bit_or " , [ self , bitsExpression] )
560
- }
561
-
562
- func bitXor( _ otherBits: Int ) -> FunctionExpression {
563
- return FunctionExpression ( " bit_xor " , [ self , Helper . sendableToExpr ( otherBits) ] )
564
- }
565
-
566
- func bitXor( _ otherBits: UInt8 ) -> FunctionExpression {
567
- return FunctionExpression ( " bit_xor " , [ self , Helper . sendableToExpr ( otherBits) ] )
568
- }
569
-
570
- func bitXor( _ bitsExpression: Expression ) -> FunctionExpression {
571
- return FunctionExpression ( " bit_xor " , [ self , bitsExpression] )
572
- }
573
-
574
- func bitNot( ) -> FunctionExpression {
575
- return FunctionExpression ( " bit_not " , [ self ] )
576
- }
577
-
578
- func bitLeftShift( _ y: Int ) -> FunctionExpression {
579
- return FunctionExpression ( " bit_left_shift " , [ self , Helper . sendableToExpr ( y) ] )
580
- }
581
-
582
- func bitLeftShift( _ numberExpression: Expression ) -> FunctionExpression {
583
- return FunctionExpression ( " bit_left_shift " , [ self , numberExpression] )
584
- }
585
-
586
- func bitRightShift( _ y: Int ) -> FunctionExpression {
587
- return FunctionExpression ( " bit_right_shift " , [ self , Helper . sendableToExpr ( y) ] )
588
- }
589
-
590
- func bitRightShift( _ numberExpression: Expression ) -> FunctionExpression {
591
- return FunctionExpression ( " bit_right_shift " , [ self , numberExpression] )
592
- }
593
-
594
745
func documentId( ) -> FunctionExpression {
595
746
return FunctionExpression ( " document_id " , [ self ] )
596
747
}
0 commit comments