| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.operators; | 5 library dart2js.operators; |
| 6 | 6 |
| 7 import '../elements/elements.dart'; | 7 import '../elements/elements.dart'; |
| 8 | 8 |
| 9 enum UnaryOperatorKind { | 9 enum UnaryOperatorKind { |
| 10 NOT, | 10 NOT, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 SHR, | 59 SHR, |
| 60 GTEQ, | 60 GTEQ, |
| 61 GT, | 61 GT, |
| 62 LTEQ, | 62 LTEQ, |
| 63 LT, | 63 LT, |
| 64 AND, | 64 AND, |
| 65 OR, | 65 OR, |
| 66 XOR, | 66 XOR, |
| 67 LOGICAL_AND, | 67 LOGICAL_AND, |
| 68 LOGICAL_OR, | 68 LOGICAL_OR, |
| 69 IF_NULL, |
| 69 } | 70 } |
| 70 | 71 |
| 71 class BinaryOperator { | 72 class BinaryOperator { |
| 72 final BinaryOperatorKind kind; | 73 final BinaryOperatorKind kind; |
| 73 final String name; | 74 final String name; |
| 74 | 75 |
| 75 const BinaryOperator._(this.kind, this.name); | 76 const BinaryOperator._(this.kind, this.name); |
| 76 | 77 |
| 77 /// `true` if this operator can be implemented through an `operator [name]` | 78 /// `true` if this operator can be implemented through an `operator [name]` |
| 78 /// method. | 79 /// method. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 const BinaryOperator._(BinaryOperatorKind.XOR, '^'); | 155 const BinaryOperator._(BinaryOperatorKind.XOR, '^'); |
| 155 | 156 |
| 156 /// The logical && operator. | 157 /// The logical && operator. |
| 157 static const BinaryOperator LOGICAL_AND = | 158 static const BinaryOperator LOGICAL_AND = |
| 158 const _LogicalOperator(BinaryOperatorKind.LOGICAL_AND, '&&'); | 159 const _LogicalOperator(BinaryOperatorKind.LOGICAL_AND, '&&'); |
| 159 | 160 |
| 160 /// The binary | operator. | 161 /// The binary | operator. |
| 161 static const BinaryOperator LOGICAL_OR = | 162 static const BinaryOperator LOGICAL_OR = |
| 162 const _LogicalOperator(BinaryOperatorKind.LOGICAL_OR, '||'); | 163 const _LogicalOperator(BinaryOperatorKind.LOGICAL_OR, '||'); |
| 163 | 164 |
| 165 /// The if-null ?? operator. |
| 166 static const BinaryOperator IF_NULL = |
| 167 const _LogicalOperator(BinaryOperatorKind.IF_NULL, '??'); |
| 168 |
| 164 static BinaryOperator parse(String value) { | 169 static BinaryOperator parse(String value) { |
| 165 switch (value) { | 170 switch (value) { |
| 166 case '==': return EQ; | 171 case '==': return EQ; |
| 167 case '!=': return NOT_EQ; | 172 case '!=': return NOT_EQ; |
| 168 case '[]': return INDEX; | 173 case '[]': return INDEX; |
| 169 case '*': return MUL; | 174 case '*': return MUL; |
| 170 case '/': return DIV; | 175 case '/': return DIV; |
| 171 case '%': return MOD; | 176 case '%': return MOD; |
| 172 case '~/': return IDIV; | 177 case '~/': return IDIV; |
| 173 case '+': return ADD; | 178 case '+': return ADD; |
| 174 case '-': return SUB; | 179 case '-': return SUB; |
| 175 case '<<': return SHL; | 180 case '<<': return SHL; |
| 176 case '>>': return SHR; | 181 case '>>': return SHR; |
| 177 case '>=': return GTEQ; | 182 case '>=': return GTEQ; |
| 178 case '>': return GT; | 183 case '>': return GT; |
| 179 case '<=': return LTEQ; | 184 case '<=': return LTEQ; |
| 180 case '<': return LT; | 185 case '<': return LT; |
| 181 case '&': return AND; | 186 case '&': return AND; |
| 182 case '^': return XOR; | 187 case '^': return XOR; |
| 183 case '|': return OR; | 188 case '|': return OR; |
| 184 case '&&': return LOGICAL_AND; | 189 case '&&': return LOGICAL_AND; |
| 185 case '||': return LOGICAL_OR; | 190 case '||': return LOGICAL_OR; |
| 191 case '??': return IF_NULL; |
| 186 default: return null; | 192 default: return null; |
| 187 } | 193 } |
| 188 } | 194 } |
| 189 } | 195 } |
| 190 | 196 |
| 191 /// The operator !=, which is not user definable operator but instead is a | 197 /// The operator !=, which is not user definable operator but instead is a |
| 192 /// negation of a call to user definable operator, namely ==. | 198 /// negation of a call to user definable operator, namely ==. |
| 193 class _NotEqualsOperator extends BinaryOperator { | 199 class _NotEqualsOperator extends BinaryOperator { |
| 194 const _NotEqualsOperator() : super._(BinaryOperatorKind.NOT_EQ, '!='); | 200 const _NotEqualsOperator() : super._(BinaryOperatorKind.NOT_EQ, '!='); |
| 195 | 201 |
| 196 bool get isUserDefinable => false; | 202 bool get isUserDefinable => false; |
| 197 | 203 |
| 198 String get selectorName => '=='; | 204 String get selectorName => '=='; |
| 199 } | 205 } |
| 200 | 206 |
| 201 /// The operators && and || which are not user definable operators but control | 207 /// The operators && and || which are not user definable operators but control |
| 202 /// structures. | 208 /// structures. |
| 203 class _LogicalOperator extends BinaryOperator { | 209 class _LogicalOperator extends BinaryOperator { |
| 204 const _LogicalOperator(BinaryOperatorKind kind, String name) | 210 const _LogicalOperator(BinaryOperatorKind kind, String name) |
| 205 : super._(kind, name); | 211 : super._(kind, name); |
| 206 | 212 |
| 207 bool get isUserDefinable => false; | 213 bool get isUserDefinable => false; |
| 208 | 214 |
| 209 String get selectorName => null; | 215 String get selectorName => null; |
| 210 } | 216 } |
| 211 | 217 |
| 212 enum AssignmentOperatorKind { | 218 enum AssignmentOperatorKind { |
| 213 ASSIGN, | 219 ASSIGN, |
| 220 IF_NULL, |
| 214 ADD, | 221 ADD, |
| 215 SUB, | 222 SUB, |
| 216 MUL, | 223 MUL, |
| 217 DIV, | 224 DIV, |
| 218 IDIV, | 225 IDIV, |
| 219 MOD, | 226 MOD, |
| 220 SHL, | 227 SHL, |
| 221 SHR, | 228 SHR, |
| 222 AND, | 229 AND, |
| 223 OR, | 230 OR, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 237 return binaryOperator != null ? binaryOperator.selectorName: null; | 244 return binaryOperator != null ? binaryOperator.selectorName: null; |
| 238 } | 245 } |
| 239 | 246 |
| 240 String toString() => name; | 247 String toString() => name; |
| 241 | 248 |
| 242 /// The = operator. | 249 /// The = operator. |
| 243 static const AssignmentOperator ASSIGN = | 250 static const AssignmentOperator ASSIGN = |
| 244 const AssignmentOperator._(AssignmentOperatorKind.ASSIGN, '=', | 251 const AssignmentOperator._(AssignmentOperatorKind.ASSIGN, '=', |
| 245 null, isUserDefinable: false); | 252 null, isUserDefinable: false); |
| 246 | 253 |
| 254 /// The ??= operator. |
| 255 static const AssignmentOperator IF_NULL = |
| 256 const AssignmentOperator._(AssignmentOperatorKind.IF_NULL, '??=', |
| 257 BinaryOperator.IF_NULL, |
| 258 isUserDefinable: false); |
| 259 |
| 247 /// The += assignment operator. | 260 /// The += assignment operator. |
| 248 static const AssignmentOperator ADD = | 261 static const AssignmentOperator ADD = |
| 249 const AssignmentOperator._(AssignmentOperatorKind.ADD, '+=', | 262 const AssignmentOperator._(AssignmentOperatorKind.ADD, '+=', |
| 250 BinaryOperator.ADD); | 263 BinaryOperator.ADD); |
| 251 | 264 |
| 252 /// The -= assignment operator. | 265 /// The -= assignment operator. |
| 253 static const AssignmentOperator SUB = | 266 static const AssignmentOperator SUB = |
| 254 const AssignmentOperator._(AssignmentOperatorKind.SUB, '-=', | 267 const AssignmentOperator._(AssignmentOperatorKind.SUB, '-=', |
| 255 BinaryOperator.SUB); | 268 BinaryOperator.SUB); |
| 256 | 269 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 BinaryOperator.OR); | 308 BinaryOperator.OR); |
| 296 | 309 |
| 297 /// The ^= assignment operator. | 310 /// The ^= assignment operator. |
| 298 static const AssignmentOperator XOR = | 311 static const AssignmentOperator XOR = |
| 299 const AssignmentOperator._(AssignmentOperatorKind.XOR, '^=', | 312 const AssignmentOperator._(AssignmentOperatorKind.XOR, '^=', |
| 300 BinaryOperator.XOR); | 313 BinaryOperator.XOR); |
| 301 | 314 |
| 302 static AssignmentOperator parse(String value) { | 315 static AssignmentOperator parse(String value) { |
| 303 switch (value) { | 316 switch (value) { |
| 304 case '=': return ASSIGN; | 317 case '=': return ASSIGN; |
| 318 case '??=': return IF_NULL; |
| 305 case '*=': return MUL; | 319 case '*=': return MUL; |
| 306 case '/=': return DIV; | 320 case '/=': return DIV; |
| 307 case '%=': return MOD; | 321 case '%=': return MOD; |
| 308 case '~/=': return IDIV; | 322 case '~/=': return IDIV; |
| 309 case '+=': return ADD; | 323 case '+=': return ADD; |
| 310 case '-=': return SUB; | 324 case '-=': return SUB; |
| 311 case '<<=': return SHL; | 325 case '<<=': return SHL; |
| 312 case '>>=': return SHR; | 326 case '>>=': return SHR; |
| 313 case '&=': return AND; | 327 case '&=': return AND; |
| 314 case '^=': return XOR; | 328 case '^=': return XOR; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 342 static const IncDecOperator DEC = | 356 static const IncDecOperator DEC = |
| 343 const IncDecOperator._(IncDecOperatorKind.DEC, '--', BinaryOperator.SUB); | 357 const IncDecOperator._(IncDecOperatorKind.DEC, '--', BinaryOperator.SUB); |
| 344 | 358 |
| 345 static IncDecOperator parse(String value) { | 359 static IncDecOperator parse(String value) { |
| 346 switch (value) { | 360 switch (value) { |
| 347 case '++': return INC; | 361 case '++': return INC; |
| 348 case '--': return DEC; | 362 case '--': return DEC; |
| 349 default: return null; | 363 default: return null; |
| 350 } | 364 } |
| 351 } | 365 } |
| 352 } | 366 } |
| OLD | NEW |