OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.constant_system.dart; | 5 library dart2js.constant_system.dart; |
6 | 6 |
7 import 'compiler.dart' show | 7 import 'compiler.dart' show |
8 Compiler; | 8 Compiler; |
9 import 'constants/constant_system.dart'; | 9 import 'constants/constant_system.dart'; |
10 import 'constants/values.dart'; | 10 import 'constants/values.dart'; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 BoolConstantValue fold(ConstantValue left, ConstantValue right) { | 325 BoolConstantValue fold(ConstantValue left, ConstantValue right) { |
326 // In order to preserve runtime semantics which says that NaN !== NaN don't | 326 // In order to preserve runtime semantics which says that NaN !== NaN don't |
327 // constant fold NaN === NaN. Otherwise the output depends on inlined | 327 // constant fold NaN === NaN. Otherwise the output depends on inlined |
328 // variables and other optimizations. | 328 // variables and other optimizations. |
329 if (left.isNaN && right.isNaN) return null; | 329 if (left.isNaN && right.isNaN) return null; |
330 return DART_CONSTANT_SYSTEM.createBool(left == right); | 330 return DART_CONSTANT_SYSTEM.createBool(left == right); |
331 } | 331 } |
332 apply(left, right) => identical(left, right); | 332 apply(left, right) => identical(left, right); |
333 } | 333 } |
334 | 334 |
| 335 class IfNullOperation implements BinaryOperation { |
| 336 final String name = '??'; |
| 337 const IfNullOperation(); |
| 338 ConstantValue fold(ConstantValue left, ConstantValue right) { |
| 339 if (left.isNull) return right; |
| 340 return left; |
| 341 } |
| 342 apply(left, right) => left ?? right; |
| 343 } |
| 344 |
335 abstract class CodeUnitAtOperation implements BinaryOperation { | 345 abstract class CodeUnitAtOperation implements BinaryOperation { |
336 final String name = 'charCodeAt'; | 346 final String name = 'charCodeAt'; |
337 const CodeUnitAtOperation(); | 347 const CodeUnitAtOperation(); |
338 apply(left, right) => left.codeUnitAt(right); | 348 apply(left, right) => left.codeUnitAt(right); |
339 } | 349 } |
340 | 350 |
341 class CodeUnitAtConstantOperation extends CodeUnitAtOperation { | 351 class CodeUnitAtConstantOperation extends CodeUnitAtOperation { |
342 const CodeUnitAtConstantOperation(); | 352 const CodeUnitAtConstantOperation(); |
343 ConstantValue fold(ConstantValue left, ConstantValue right) { | 353 ConstantValue fold(ConstantValue left, ConstantValue right) { |
344 // 'a'.codeUnitAt(0) is not a constant expression. | 354 // 'a'.codeUnitAt(0) is not a constant expression. |
(...skipping 30 matching lines...) Expand all Loading... |
375 final bitNot = const BitNotOperation(); | 385 final bitNot = const BitNotOperation(); |
376 final bitOr = const BitOrOperation(); | 386 final bitOr = const BitOrOperation(); |
377 final bitXor = const BitXorOperation(); | 387 final bitXor = const BitXorOperation(); |
378 final booleanAnd = const BooleanAndOperation(); | 388 final booleanAnd = const BooleanAndOperation(); |
379 final booleanOr = const BooleanOrOperation(); | 389 final booleanOr = const BooleanOrOperation(); |
380 final divide = const DivideOperation(); | 390 final divide = const DivideOperation(); |
381 final equal = const EqualsOperation(); | 391 final equal = const EqualsOperation(); |
382 final greaterEqual = const GreaterEqualOperation(); | 392 final greaterEqual = const GreaterEqualOperation(); |
383 final greater = const GreaterOperation(); | 393 final greater = const GreaterOperation(); |
384 final identity = const IdentityOperation(); | 394 final identity = const IdentityOperation(); |
| 395 final ifNull = const IfNullOperation(); |
385 final lessEqual = const LessEqualOperation(); | 396 final lessEqual = const LessEqualOperation(); |
386 final less = const LessOperation(); | 397 final less = const LessOperation(); |
387 final modulo = const ModuloOperation(); | 398 final modulo = const ModuloOperation(); |
388 final multiply = const MultiplyOperation(); | 399 final multiply = const MultiplyOperation(); |
389 final negate = const NegateOperation(); | 400 final negate = const NegateOperation(); |
390 final not = const NotOperation(); | 401 final not = const NotOperation(); |
391 final shiftLeft = const ShiftLeftOperation(); | 402 final shiftLeft = const ShiftLeftOperation(); |
392 final shiftRight = const ShiftRightOperation(); | 403 final shiftRight = const ShiftRightOperation(); |
393 final subtract = const SubtractOperation(); | 404 final subtract = const SubtractOperation(); |
394 final truncatingDivide = const TruncatingDivideOperation(); | 405 final truncatingDivide = const TruncatingDivideOperation(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 bool isInt(ConstantValue constant) => constant.isInt; | 451 bool isInt(ConstantValue constant) => constant.isInt; |
441 bool isDouble(ConstantValue constant) => constant.isDouble; | 452 bool isDouble(ConstantValue constant) => constant.isDouble; |
442 bool isString(ConstantValue constant) => constant.isString; | 453 bool isString(ConstantValue constant) => constant.isString; |
443 bool isBool(ConstantValue constant) => constant.isBool; | 454 bool isBool(ConstantValue constant) => constant.isBool; |
444 bool isNull(ConstantValue constant) => constant.isNull; | 455 bool isNull(ConstantValue constant) => constant.isNull; |
445 | 456 |
446 bool isSubtype(DartTypes types, DartType s, DartType t) { | 457 bool isSubtype(DartTypes types, DartType s, DartType t) { |
447 return types.isSubtype(s, t); | 458 return types.isSubtype(s, t); |
448 } | 459 } |
449 } | 460 } |
OLD | NEW |