| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.constants.expressions; | 5 library dart2js.constants.expressions; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../core_types.dart'; | 9 import '../core_types.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 /// Substitute free variables using arguments. | 73 /// Substitute free variables using arguments. |
| 74 ConstantExpression apply(NormalizedArguments arguments) => this; | 74 ConstantExpression apply(NormalizedArguments arguments) => this; |
| 75 | 75 |
| 76 /// Compute the [ConstantValue] for this expression using the [environment] | 76 /// Compute the [ConstantValue] for this expression using the [environment] |
| 77 /// and the [constantSystem]. | 77 /// and the [constantSystem]. |
| 78 ConstantValue evaluate( | 78 ConstantValue evaluate( |
| 79 Environment environment, ConstantSystem constantSystem); | 79 Environment environment, ConstantSystem constantSystem); |
| 80 | 80 |
| 81 /// Returns the type of this constant expression, if it is independent of the | 81 /// Returns the type of this constant expression, if it is independent of the |
| 82 /// environment values. | 82 /// environment values. |
| 83 DartType getKnownType(CoreTypes coreTypes) => null; | 83 DartType getKnownType(CommonElements commonElements) => null; |
| 84 | 84 |
| 85 /// Returns a text string resembling the Dart code creating this constant. | 85 /// Returns a text string resembling the Dart code creating this constant. |
| 86 String toDartText() { | 86 String toDartText() { |
| 87 ConstExpPrinter printer = new ConstExpPrinter(); | 87 ConstExpPrinter printer = new ConstExpPrinter(); |
| 88 accept(printer); | 88 accept(printer); |
| 89 return printer.toString(); | 89 return printer.toString(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 /// Returns a text string showing the structure of this constant. | 92 /// Returns a text string showing the structure of this constant. |
| 93 String toStructuredText() { | 93 String toStructuredText() { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 @override | 230 @override |
| 231 int _computeHashCode() => 13 * primitiveValue.hashCode; | 231 int _computeHashCode() => 13 * primitiveValue.hashCode; |
| 232 | 232 |
| 233 @override | 233 @override |
| 234 bool _equals(BoolConstantExpression other) { | 234 bool _equals(BoolConstantExpression other) { |
| 235 return primitiveValue == other.primitiveValue; | 235 return primitiveValue == other.primitiveValue; |
| 236 } | 236 } |
| 237 | 237 |
| 238 @override | 238 @override |
| 239 DartType getKnownType(CoreTypes coreTypes) => coreTypes.boolType; | 239 DartType getKnownType(CommonElements commonElements) => |
| 240 commonElements.boolType; |
| 240 } | 241 } |
| 241 | 242 |
| 242 /// Integer literal constant. | 243 /// Integer literal constant. |
| 243 class IntConstantExpression extends PrimitiveConstantExpression { | 244 class IntConstantExpression extends PrimitiveConstantExpression { |
| 244 final int primitiveValue; | 245 final int primitiveValue; |
| 245 | 246 |
| 246 IntConstantExpression(this.primitiveValue); | 247 IntConstantExpression(this.primitiveValue); |
| 247 | 248 |
| 248 ConstantExpressionKind get kind => ConstantExpressionKind.INT; | 249 ConstantExpressionKind get kind => ConstantExpressionKind.INT; |
| 249 | 250 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 264 | 265 |
| 265 @override | 266 @override |
| 266 int _computeHashCode() => 17 * primitiveValue.hashCode; | 267 int _computeHashCode() => 17 * primitiveValue.hashCode; |
| 267 | 268 |
| 268 @override | 269 @override |
| 269 bool _equals(IntConstantExpression other) { | 270 bool _equals(IntConstantExpression other) { |
| 270 return primitiveValue == other.primitiveValue; | 271 return primitiveValue == other.primitiveValue; |
| 271 } | 272 } |
| 272 | 273 |
| 273 @override | 274 @override |
| 274 DartType getKnownType(CoreTypes coreTypes) => coreTypes.intType; | 275 DartType getKnownType(CommonElements commonElements) => |
| 276 commonElements.intType; |
| 275 } | 277 } |
| 276 | 278 |
| 277 /// Double literal constant. | 279 /// Double literal constant. |
| 278 class DoubleConstantExpression extends PrimitiveConstantExpression { | 280 class DoubleConstantExpression extends PrimitiveConstantExpression { |
| 279 final double primitiveValue; | 281 final double primitiveValue; |
| 280 | 282 |
| 281 DoubleConstantExpression(this.primitiveValue); | 283 DoubleConstantExpression(this.primitiveValue); |
| 282 | 284 |
| 283 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; | 285 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; |
| 284 | 286 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 299 | 301 |
| 300 @override | 302 @override |
| 301 int _computeHashCode() => 19 * primitiveValue.hashCode; | 303 int _computeHashCode() => 19 * primitiveValue.hashCode; |
| 302 | 304 |
| 303 @override | 305 @override |
| 304 bool _equals(DoubleConstantExpression other) { | 306 bool _equals(DoubleConstantExpression other) { |
| 305 return primitiveValue == other.primitiveValue; | 307 return primitiveValue == other.primitiveValue; |
| 306 } | 308 } |
| 307 | 309 |
| 308 @override | 310 @override |
| 309 DartType getKnownType(CoreTypes coreTypes) => coreTypes.doubleType; | 311 DartType getKnownType(CommonElements commonElements) => |
| 312 commonElements.doubleType; |
| 310 } | 313 } |
| 311 | 314 |
| 312 /// String literal constant. | 315 /// String literal constant. |
| 313 class StringConstantExpression extends PrimitiveConstantExpression { | 316 class StringConstantExpression extends PrimitiveConstantExpression { |
| 314 final String primitiveValue; | 317 final String primitiveValue; |
| 315 | 318 |
| 316 StringConstantExpression(this.primitiveValue); | 319 StringConstantExpression(this.primitiveValue); |
| 317 | 320 |
| 318 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; | 321 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; |
| 319 | 322 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 334 | 337 |
| 335 @override | 338 @override |
| 336 int _computeHashCode() => 23 * primitiveValue.hashCode; | 339 int _computeHashCode() => 23 * primitiveValue.hashCode; |
| 337 | 340 |
| 338 @override | 341 @override |
| 339 bool _equals(StringConstantExpression other) { | 342 bool _equals(StringConstantExpression other) { |
| 340 return primitiveValue == other.primitiveValue; | 343 return primitiveValue == other.primitiveValue; |
| 341 } | 344 } |
| 342 | 345 |
| 343 @override | 346 @override |
| 344 DartType getKnownType(CoreTypes coreTypes) => coreTypes.stringType; | 347 DartType getKnownType(CommonElements commonElements) => |
| 348 commonElements.stringType; |
| 345 } | 349 } |
| 346 | 350 |
| 347 /// Null literal constant. | 351 /// Null literal constant. |
| 348 class NullConstantExpression extends PrimitiveConstantExpression { | 352 class NullConstantExpression extends PrimitiveConstantExpression { |
| 349 NullConstantExpression(); | 353 NullConstantExpression(); |
| 350 | 354 |
| 351 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; | 355 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; |
| 352 | 356 |
| 353 accept(ConstantExpressionVisitor visitor, [context]) { | 357 accept(ConstantExpressionVisitor visitor, [context]) { |
| 354 return visitor.visitNull(this, context); | 358 return visitor.visitNull(this, context); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 367 | 371 |
| 368 get primitiveValue => null; | 372 get primitiveValue => null; |
| 369 | 373 |
| 370 @override | 374 @override |
| 371 int _computeHashCode() => 29; | 375 int _computeHashCode() => 29; |
| 372 | 376 |
| 373 @override | 377 @override |
| 374 bool _equals(NullConstantExpression other) => true; | 378 bool _equals(NullConstantExpression other) => true; |
| 375 | 379 |
| 376 @override | 380 @override |
| 377 DartType getKnownType(CoreTypes coreTypes) => coreTypes.nullType; | 381 DartType getKnownType(CommonElements commonElements) => |
| 382 commonElements.nullType; |
| 378 } | 383 } |
| 379 | 384 |
| 380 /// Literal list constant. | 385 /// Literal list constant. |
| 381 class ListConstantExpression extends ConstantExpression { | 386 class ListConstantExpression extends ConstantExpression { |
| 382 final InterfaceType type; | 387 final InterfaceType type; |
| 383 final List<ConstantExpression> values; | 388 final List<ConstantExpression> values; |
| 384 | 389 |
| 385 ListConstantExpression(this.type, this.values); | 390 ListConstantExpression(this.type, this.values); |
| 386 | 391 |
| 387 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; | 392 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 bool _equals(ListConstantExpression other) { | 432 bool _equals(ListConstantExpression other) { |
| 428 if (type != other.type) return false; | 433 if (type != other.type) return false; |
| 429 if (values.length != other.values.length) return false; | 434 if (values.length != other.values.length) return false; |
| 430 for (int i = 0; i < values.length; i++) { | 435 for (int i = 0; i < values.length; i++) { |
| 431 if (values[i] != other.values[i]) return false; | 436 if (values[i] != other.values[i]) return false; |
| 432 } | 437 } |
| 433 return true; | 438 return true; |
| 434 } | 439 } |
| 435 | 440 |
| 436 @override | 441 @override |
| 437 DartType getKnownType(CoreTypes coreTypes) => type; | 442 DartType getKnownType(CommonElements commonElements) => type; |
| 438 | 443 |
| 439 @override | 444 @override |
| 440 bool get isImplicit => false; | 445 bool get isImplicit => false; |
| 441 | 446 |
| 442 @override | 447 @override |
| 443 bool get isPotential => values.any((e) => e.isPotential); | 448 bool get isPotential => values.any((e) => e.isPotential); |
| 444 } | 449 } |
| 445 | 450 |
| 446 /// Literal map constant. | 451 /// Literal map constant. |
| 447 class MapConstantExpression extends ConstantExpression { | 452 class MapConstantExpression extends ConstantExpression { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 if (type != other.type) return false; | 511 if (type != other.type) return false; |
| 507 if (values.length != other.values.length) return false; | 512 if (values.length != other.values.length) return false; |
| 508 for (int i = 0; i < values.length; i++) { | 513 for (int i = 0; i < values.length; i++) { |
| 509 if (keys[i] != other.keys[i]) return false; | 514 if (keys[i] != other.keys[i]) return false; |
| 510 if (values[i] != other.values[i]) return false; | 515 if (values[i] != other.values[i]) return false; |
| 511 } | 516 } |
| 512 return true; | 517 return true; |
| 513 } | 518 } |
| 514 | 519 |
| 515 @override | 520 @override |
| 516 DartType getKnownType(CoreTypes coreTypes) => type; | 521 DartType getKnownType(CommonElements commonElements) => type; |
| 517 | 522 |
| 518 @override | 523 @override |
| 519 bool get isImplicit => false; | 524 bool get isImplicit => false; |
| 520 | 525 |
| 521 @override | 526 @override |
| 522 bool get isPotential { | 527 bool get isPotential { |
| 523 return keys.any((e) => e.isPotential) || values.any((e) => e.isPotential); | 528 return keys.any((e) => e.isPotential) || values.any((e) => e.isPotential); |
| 524 } | 529 } |
| 525 } | 530 } |
| 526 | 531 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 @override | 688 @override |
| 684 bool _equals(ConcatenateConstantExpression other) { | 689 bool _equals(ConcatenateConstantExpression other) { |
| 685 if (expressions.length != other.expressions.length) return false; | 690 if (expressions.length != other.expressions.length) return false; |
| 686 for (int i = 0; i < expressions.length; i++) { | 691 for (int i = 0; i < expressions.length; i++) { |
| 687 if (expressions[i] != other.expressions[i]) return false; | 692 if (expressions[i] != other.expressions[i]) return false; |
| 688 } | 693 } |
| 689 return true; | 694 return true; |
| 690 } | 695 } |
| 691 | 696 |
| 692 @override | 697 @override |
| 693 DartType getKnownType(CoreTypes coreTypes) => coreTypes.stringType; | 698 DartType getKnownType(CommonElements commonElements) => |
| 699 commonElements.stringType; |
| 694 | 700 |
| 695 @override | 701 @override |
| 696 bool get isPotential { | 702 bool get isPotential { |
| 697 return expressions.any((e) => e.isPotential); | 703 return expressions.any((e) => e.isPotential); |
| 698 } | 704 } |
| 699 } | 705 } |
| 700 | 706 |
| 701 /// Symbol literal. | 707 /// Symbol literal. |
| 702 class SymbolConstantExpression extends ConstantExpression { | 708 class SymbolConstantExpression extends ConstantExpression { |
| 703 final String name; | 709 final String name; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 723 return name == other.name; | 729 return name == other.name; |
| 724 } | 730 } |
| 725 | 731 |
| 726 @override | 732 @override |
| 727 ConstantValue evaluate( | 733 ConstantValue evaluate( |
| 728 Environment environment, ConstantSystem constantSystem) { | 734 Environment environment, ConstantSystem constantSystem) { |
| 729 return constantSystem.createSymbol(environment.compiler, name); | 735 return constantSystem.createSymbol(environment.compiler, name); |
| 730 } | 736 } |
| 731 | 737 |
| 732 @override | 738 @override |
| 733 DartType getKnownType(CoreTypes coreTypes) => coreTypes.symbolType; | 739 DartType getKnownType(CommonElements commonElements) => |
| 740 commonElements.symbolType; |
| 734 } | 741 } |
| 735 | 742 |
| 736 /// Type literal. | 743 /// Type literal. |
| 737 class TypeConstantExpression extends ConstantExpression { | 744 class TypeConstantExpression extends ConstantExpression { |
| 738 /// Either [DynamicType] or a raw [GenericType]. | 745 /// Either [DynamicType] or a raw [GenericType]. |
| 739 final DartType type; | 746 final DartType type; |
| 740 | 747 |
| 741 TypeConstantExpression(this.type) { | 748 TypeConstantExpression(this.type) { |
| 742 assert(type is GenericType || type is DynamicType); | 749 assert(type is GenericType || type is DynamicType); |
| 743 } | 750 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 761 | 768 |
| 762 @override | 769 @override |
| 763 int _computeHashCode() => 13 * type.hashCode; | 770 int _computeHashCode() => 13 * type.hashCode; |
| 764 | 771 |
| 765 @override | 772 @override |
| 766 bool _equals(TypeConstantExpression other) { | 773 bool _equals(TypeConstantExpression other) { |
| 767 return type == other.type; | 774 return type == other.type; |
| 768 } | 775 } |
| 769 | 776 |
| 770 @override | 777 @override |
| 771 DartType getKnownType(CoreTypes coreTypes) => coreTypes.typeType; | 778 DartType getKnownType(CommonElements commonElements) => |
| 779 commonElements.typeType; |
| 772 } | 780 } |
| 773 | 781 |
| 774 /// Reference to a constant local, top-level, or static variable. | 782 /// Reference to a constant local, top-level, or static variable. |
| 775 class VariableConstantExpression extends ConstantExpression { | 783 class VariableConstantExpression extends ConstantExpression { |
| 776 final VariableElement element; | 784 final VariableElement element; |
| 777 | 785 |
| 778 VariableConstantExpression(this.element); | 786 VariableConstantExpression(this.element); |
| 779 | 787 |
| 780 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; | 788 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; |
| 781 | 789 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 | 836 |
| 829 @override | 837 @override |
| 830 int _computeHashCode() => 13 * element.hashCode; | 838 int _computeHashCode() => 13 * element.hashCode; |
| 831 | 839 |
| 832 @override | 840 @override |
| 833 bool _equals(FunctionConstantExpression other) { | 841 bool _equals(FunctionConstantExpression other) { |
| 834 return element == other.element; | 842 return element == other.element; |
| 835 } | 843 } |
| 836 | 844 |
| 837 @override | 845 @override |
| 838 DartType getKnownType(CoreTypes coreTypes) => coreTypes.functionType; | 846 DartType getKnownType(CommonElements commonElements) => |
| 847 commonElements.functionType; |
| 839 } | 848 } |
| 840 | 849 |
| 841 /// A constant binary expression like `a * b`. | 850 /// A constant binary expression like `a * b`. |
| 842 class BinaryConstantExpression extends ConstantExpression { | 851 class BinaryConstantExpression extends ConstantExpression { |
| 843 final ConstantExpression left; | 852 final ConstantExpression left; |
| 844 final BinaryOperator operator; | 853 final BinaryOperator operator; |
| 845 final ConstantExpression right; | 854 final ConstantExpression right; |
| 846 | 855 |
| 847 BinaryConstantExpression(this.left, this.operator, this.right) { | 856 BinaryConstantExpression(this.left, this.operator, this.right) { |
| 848 assert(PRECEDENCE_MAP[operator.kind] != null); | 857 assert(PRECEDENCE_MAP[operator.kind] != null); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 878 .lookupBinary(operator) | 887 .lookupBinary(operator) |
| 879 .fold(leftValue, rightValue); | 888 .fold(leftValue, rightValue); |
| 880 } | 889 } |
| 881 } | 890 } |
| 882 | 891 |
| 883 ConstantExpression apply(NormalizedArguments arguments) { | 892 ConstantExpression apply(NormalizedArguments arguments) { |
| 884 return new BinaryConstantExpression( | 893 return new BinaryConstantExpression( |
| 885 left.apply(arguments), operator, right.apply(arguments)); | 894 left.apply(arguments), operator, right.apply(arguments)); |
| 886 } | 895 } |
| 887 | 896 |
| 888 DartType getKnownType(CoreTypes coreTypes) { | 897 DartType getKnownType(CommonElements commonElements) { |
| 889 DartType knownLeftType = left.getKnownType(coreTypes); | 898 DartType knownLeftType = left.getKnownType(commonElements); |
| 890 DartType knownRightType = right.getKnownType(coreTypes); | 899 DartType knownRightType = right.getKnownType(commonElements); |
| 891 switch (operator.kind) { | 900 switch (operator.kind) { |
| 892 case BinaryOperatorKind.EQ: | 901 case BinaryOperatorKind.EQ: |
| 893 case BinaryOperatorKind.NOT_EQ: | 902 case BinaryOperatorKind.NOT_EQ: |
| 894 case BinaryOperatorKind.LOGICAL_AND: | 903 case BinaryOperatorKind.LOGICAL_AND: |
| 895 case BinaryOperatorKind.LOGICAL_OR: | 904 case BinaryOperatorKind.LOGICAL_OR: |
| 896 case BinaryOperatorKind.GT: | 905 case BinaryOperatorKind.GT: |
| 897 case BinaryOperatorKind.LT: | 906 case BinaryOperatorKind.LT: |
| 898 case BinaryOperatorKind.GTEQ: | 907 case BinaryOperatorKind.GTEQ: |
| 899 case BinaryOperatorKind.LTEQ: | 908 case BinaryOperatorKind.LTEQ: |
| 900 return coreTypes.boolType; | 909 return commonElements.boolType; |
| 901 case BinaryOperatorKind.ADD: | 910 case BinaryOperatorKind.ADD: |
| 902 if (knownLeftType == coreTypes.stringType) { | 911 if (knownLeftType == commonElements.stringType) { |
| 903 assert(knownRightType == coreTypes.stringType); | 912 assert(knownRightType == commonElements.stringType); |
| 904 return coreTypes.stringType; | 913 return commonElements.stringType; |
| 905 } else if (knownLeftType == coreTypes.intType && | 914 } else if (knownLeftType == commonElements.intType && |
| 906 knownRightType == coreTypes.intType) { | 915 knownRightType == commonElements.intType) { |
| 907 return coreTypes.intType; | 916 return commonElements.intType; |
| 908 } | 917 } |
| 909 assert(knownLeftType == coreTypes.doubleType || | 918 assert(knownLeftType == commonElements.doubleType || |
| 910 knownRightType == coreTypes.doubleType); | 919 knownRightType == commonElements.doubleType); |
| 911 return coreTypes.doubleType; | 920 return commonElements.doubleType; |
| 912 case BinaryOperatorKind.SUB: | 921 case BinaryOperatorKind.SUB: |
| 913 case BinaryOperatorKind.MUL: | 922 case BinaryOperatorKind.MUL: |
| 914 case BinaryOperatorKind.MOD: | 923 case BinaryOperatorKind.MOD: |
| 915 if (knownLeftType == coreTypes.intType && | 924 if (knownLeftType == commonElements.intType && |
| 916 knownRightType == coreTypes.intType) { | 925 knownRightType == commonElements.intType) { |
| 917 return coreTypes.intType; | 926 return commonElements.intType; |
| 918 } | 927 } |
| 919 assert(knownLeftType == coreTypes.doubleType || | 928 assert(knownLeftType == commonElements.doubleType || |
| 920 knownRightType == coreTypes.doubleType); | 929 knownRightType == commonElements.doubleType); |
| 921 return coreTypes.doubleType; | 930 return commonElements.doubleType; |
| 922 case BinaryOperatorKind.DIV: | 931 case BinaryOperatorKind.DIV: |
| 923 return coreTypes.doubleType; | 932 return commonElements.doubleType; |
| 924 case BinaryOperatorKind.IDIV: | 933 case BinaryOperatorKind.IDIV: |
| 925 return coreTypes.intType; | 934 return commonElements.intType; |
| 926 case BinaryOperatorKind.AND: | 935 case BinaryOperatorKind.AND: |
| 927 case BinaryOperatorKind.OR: | 936 case BinaryOperatorKind.OR: |
| 928 case BinaryOperatorKind.XOR: | 937 case BinaryOperatorKind.XOR: |
| 929 case BinaryOperatorKind.SHR: | 938 case BinaryOperatorKind.SHR: |
| 930 case BinaryOperatorKind.SHL: | 939 case BinaryOperatorKind.SHL: |
| 931 return coreTypes.intType; | 940 return commonElements.intType; |
| 932 case BinaryOperatorKind.IF_NULL: | 941 case BinaryOperatorKind.IF_NULL: |
| 933 case BinaryOperatorKind.INDEX: | 942 case BinaryOperatorKind.INDEX: |
| 934 throw new UnsupportedError( | 943 throw new UnsupportedError( |
| 935 'Unexpected constant binary operator: $operator'); | 944 'Unexpected constant binary operator: $operator'); |
| 936 } | 945 } |
| 937 } | 946 } |
| 938 | 947 |
| 939 int get precedence => PRECEDENCE_MAP[operator.kind]; | 948 int get precedence => PRECEDENCE_MAP[operator.kind]; |
| 940 | 949 |
| 941 @override | 950 @override |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 int _computeHashCode() { | 1029 int _computeHashCode() { |
| 1021 return 17 * left.hashCode + 19 * right.hashCode; | 1030 return 17 * left.hashCode + 19 * right.hashCode; |
| 1022 } | 1031 } |
| 1023 | 1032 |
| 1024 @override | 1033 @override |
| 1025 bool _equals(IdenticalConstantExpression other) { | 1034 bool _equals(IdenticalConstantExpression other) { |
| 1026 return left == other.left && right == other.right; | 1035 return left == other.left && right == other.right; |
| 1027 } | 1036 } |
| 1028 | 1037 |
| 1029 @override | 1038 @override |
| 1030 DartType getKnownType(CoreTypes coreTypes) => coreTypes.boolType; | 1039 DartType getKnownType(CommonElements commonElements) => |
| 1040 commonElements.boolType; |
| 1031 | 1041 |
| 1032 @override | 1042 @override |
| 1033 bool get isPotential { | 1043 bool get isPotential { |
| 1034 return left.isPotential || right.isPotential; | 1044 return left.isPotential || right.isPotential; |
| 1035 } | 1045 } |
| 1036 } | 1046 } |
| 1037 | 1047 |
| 1038 /// A unary constant expression like `-a`. | 1048 /// A unary constant expression like `-a`. |
| 1039 class UnaryConstantExpression extends ConstantExpression { | 1049 class UnaryConstantExpression extends ConstantExpression { |
| 1040 final UnaryOperator operator; | 1050 final UnaryOperator operator; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 int _computeHashCode() { | 1085 int _computeHashCode() { |
| 1076 return 13 * operator.hashCode + 17 * expression.hashCode; | 1086 return 13 * operator.hashCode + 17 * expression.hashCode; |
| 1077 } | 1087 } |
| 1078 | 1088 |
| 1079 @override | 1089 @override |
| 1080 bool _equals(UnaryConstantExpression other) { | 1090 bool _equals(UnaryConstantExpression other) { |
| 1081 return operator == other.operator && expression == other.expression; | 1091 return operator == other.operator && expression == other.expression; |
| 1082 } | 1092 } |
| 1083 | 1093 |
| 1084 @override | 1094 @override |
| 1085 DartType getKnownType(CoreTypes coreTypes) { | 1095 DartType getKnownType(CommonElements commonElements) { |
| 1086 return expression.getKnownType(coreTypes); | 1096 return expression.getKnownType(commonElements); |
| 1087 } | 1097 } |
| 1088 | 1098 |
| 1089 @override | 1099 @override |
| 1090 bool get isPotential { | 1100 bool get isPotential { |
| 1091 return expression.isPotential; | 1101 return expression.isPotential; |
| 1092 } | 1102 } |
| 1093 | 1103 |
| 1094 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { | 1104 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { |
| 1095 UnaryOperatorKind.NOT: 14, | 1105 UnaryOperatorKind.NOT: 14, |
| 1096 UnaryOperatorKind.COMPLEMENT: 14, | 1106 UnaryOperatorKind.COMPLEMENT: 14, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 int _computeHashCode() { | 1148 int _computeHashCode() { |
| 1139 return 23 * expression.hashCode; | 1149 return 23 * expression.hashCode; |
| 1140 } | 1150 } |
| 1141 | 1151 |
| 1142 @override | 1152 @override |
| 1143 bool _equals(StringLengthConstantExpression other) { | 1153 bool _equals(StringLengthConstantExpression other) { |
| 1144 return expression == other.expression; | 1154 return expression == other.expression; |
| 1145 } | 1155 } |
| 1146 | 1156 |
| 1147 @override | 1157 @override |
| 1148 DartType getKnownType(CoreTypes coreTypes) => coreTypes.intType; | 1158 DartType getKnownType(CommonElements commonElements) => |
| 1159 commonElements.intType; |
| 1149 | 1160 |
| 1150 @override | 1161 @override |
| 1151 bool get isPotential { | 1162 bool get isPotential { |
| 1152 return expression.isPotential; | 1163 return expression.isPotential; |
| 1153 } | 1164 } |
| 1154 } | 1165 } |
| 1155 | 1166 |
| 1156 /// A constant conditional expression like `a ? b : c`. | 1167 /// A constant conditional expression like `a ? b : c`. |
| 1157 class ConditionalConstantExpression extends ConstantExpression { | 1168 class ConditionalConstantExpression extends ConstantExpression { |
| 1158 final ConstantExpression condition; | 1169 final ConstantExpression condition; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 if (conditionValue.isTrue) { | 1220 if (conditionValue.isTrue) { |
| 1210 return trueValue; | 1221 return trueValue; |
| 1211 } else if (conditionValue.isFalse) { | 1222 } else if (conditionValue.isFalse) { |
| 1212 return falseValue; | 1223 return falseValue; |
| 1213 } else { | 1224 } else { |
| 1214 return new NonConstantValue(); | 1225 return new NonConstantValue(); |
| 1215 } | 1226 } |
| 1216 } | 1227 } |
| 1217 | 1228 |
| 1218 @override | 1229 @override |
| 1219 DartType getKnownType(CoreTypes coreTypes) { | 1230 DartType getKnownType(CommonElements commonElements) { |
| 1220 DartType trueType = trueExp.getKnownType(coreTypes); | 1231 DartType trueType = trueExp.getKnownType(commonElements); |
| 1221 DartType falseType = falseExp.getKnownType(coreTypes); | 1232 DartType falseType = falseExp.getKnownType(commonElements); |
| 1222 if (trueType == falseType) { | 1233 if (trueType == falseType) { |
| 1223 return trueType; | 1234 return trueType; |
| 1224 } | 1235 } |
| 1225 return null; | 1236 return null; |
| 1226 } | 1237 } |
| 1227 | 1238 |
| 1228 @override | 1239 @override |
| 1229 bool get isPotential { | 1240 bool get isPotential { |
| 1230 return condition.isPotential || trueExp.isPotential || falseExp.isPotential; | 1241 return condition.isPotential || trueExp.isPotential || falseExp.isPotential; |
| 1231 } | 1242 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 return defaultConstantValue; | 1401 return defaultConstantValue; |
| 1391 } | 1402 } |
| 1392 } | 1403 } |
| 1393 | 1404 |
| 1394 ConstantExpression apply(NormalizedArguments arguments) { | 1405 ConstantExpression apply(NormalizedArguments arguments) { |
| 1395 return new BoolFromEnvironmentConstantExpression(name.apply(arguments), | 1406 return new BoolFromEnvironmentConstantExpression(name.apply(arguments), |
| 1396 defaultValue != null ? defaultValue.apply(arguments) : null); | 1407 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1397 } | 1408 } |
| 1398 | 1409 |
| 1399 @override | 1410 @override |
| 1400 DartType getKnownType(CoreTypes coreTypes) => coreTypes.boolType; | 1411 DartType getKnownType(CommonElements commonElements) => |
| 1412 commonElements.boolType; |
| 1401 } | 1413 } |
| 1402 | 1414 |
| 1403 /// A `const int.fromEnvironment` constant. | 1415 /// A `const int.fromEnvironment` constant. |
| 1404 class IntFromEnvironmentConstantExpression | 1416 class IntFromEnvironmentConstantExpression |
| 1405 extends FromEnvironmentConstantExpression { | 1417 extends FromEnvironmentConstantExpression { |
| 1406 IntFromEnvironmentConstantExpression( | 1418 IntFromEnvironmentConstantExpression( |
| 1407 ConstantExpression name, ConstantExpression defaultValue) | 1419 ConstantExpression name, ConstantExpression defaultValue) |
| 1408 : super(name, defaultValue); | 1420 : super(name, defaultValue); |
| 1409 | 1421 |
| 1410 ConstantExpressionKind get kind { | 1422 ConstantExpressionKind get kind { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 return constantSystem.createInt(value); | 1467 return constantSystem.createInt(value); |
| 1456 } | 1468 } |
| 1457 } | 1469 } |
| 1458 | 1470 |
| 1459 ConstantExpression apply(NormalizedArguments arguments) { | 1471 ConstantExpression apply(NormalizedArguments arguments) { |
| 1460 return new IntFromEnvironmentConstantExpression(name.apply(arguments), | 1472 return new IntFromEnvironmentConstantExpression(name.apply(arguments), |
| 1461 defaultValue != null ? defaultValue.apply(arguments) : null); | 1473 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1462 } | 1474 } |
| 1463 | 1475 |
| 1464 @override | 1476 @override |
| 1465 DartType getKnownType(CoreTypes coreTypes) => coreTypes.intType; | 1477 DartType getKnownType(CommonElements commonElements) => |
| 1478 commonElements.intType; |
| 1466 } | 1479 } |
| 1467 | 1480 |
| 1468 /// A `const String.fromEnvironment` constant. | 1481 /// A `const String.fromEnvironment` constant. |
| 1469 class StringFromEnvironmentConstantExpression | 1482 class StringFromEnvironmentConstantExpression |
| 1470 extends FromEnvironmentConstantExpression { | 1483 extends FromEnvironmentConstantExpression { |
| 1471 StringFromEnvironmentConstantExpression( | 1484 StringFromEnvironmentConstantExpression( |
| 1472 ConstantExpression name, ConstantExpression defaultValue) | 1485 ConstantExpression name, ConstantExpression defaultValue) |
| 1473 : super(name, defaultValue); | 1486 : super(name, defaultValue); |
| 1474 | 1487 |
| 1475 ConstantExpressionKind get kind { | 1488 ConstantExpressionKind get kind { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 return constantSystem.createString(new DartString.literal(text)); | 1529 return constantSystem.createString(new DartString.literal(text)); |
| 1517 } | 1530 } |
| 1518 } | 1531 } |
| 1519 | 1532 |
| 1520 ConstantExpression apply(NormalizedArguments arguments) { | 1533 ConstantExpression apply(NormalizedArguments arguments) { |
| 1521 return new StringFromEnvironmentConstantExpression(name.apply(arguments), | 1534 return new StringFromEnvironmentConstantExpression(name.apply(arguments), |
| 1522 defaultValue != null ? defaultValue.apply(arguments) : null); | 1535 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1523 } | 1536 } |
| 1524 | 1537 |
| 1525 @override | 1538 @override |
| 1526 DartType getKnownType(CoreTypes coreTypes) => coreTypes.stringType; | 1539 DartType getKnownType(CommonElements commonElements) => |
| 1540 commonElements.stringType; |
| 1527 } | 1541 } |
| 1528 | 1542 |
| 1529 /// A constant expression referenced with a deferred prefix. | 1543 /// A constant expression referenced with a deferred prefix. |
| 1530 /// For example `lib.C`. | 1544 /// For example `lib.C`. |
| 1531 class DeferredConstantExpression extends ConstantExpression { | 1545 class DeferredConstantExpression extends ConstantExpression { |
| 1532 final ConstantExpression expression; | 1546 final ConstantExpression expression; |
| 1533 final PrefixElement prefix; | 1547 final PrefixElement prefix; |
| 1534 | 1548 |
| 1535 DeferredConstantExpression(this.expression, this.prefix); | 1549 DeferredConstantExpression(this.expression, this.prefix); |
| 1536 | 1550 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 visit(exp.name); | 1888 visit(exp.name); |
| 1875 if (exp.defaultValue != null) { | 1889 if (exp.defaultValue != null) { |
| 1876 sb.write(', defaultValue: '); | 1890 sb.write(', defaultValue: '); |
| 1877 visit(exp.defaultValue); | 1891 visit(exp.defaultValue); |
| 1878 } | 1892 } |
| 1879 sb.write(')'); | 1893 sb.write(')'); |
| 1880 } | 1894 } |
| 1881 | 1895 |
| 1882 String toString() => sb.toString(); | 1896 String toString() => sb.toString(); |
| 1883 } | 1897 } |
| OLD | NEW |