| 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 '../elements/resolution_types.dart'; | 10 import '../elements/resolution_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(CommonElements commonElements) => null; | 83 ResolutionDartType 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(CommonElements commonElements) => | 239 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 240 commonElements.boolType; | 240 commonElements.boolType; |
| 241 } | 241 } |
| 242 | 242 |
| 243 /// Integer literal constant. | 243 /// Integer literal constant. |
| 244 class IntConstantExpression extends PrimitiveConstantExpression { | 244 class IntConstantExpression extends PrimitiveConstantExpression { |
| 245 final int primitiveValue; | 245 final int primitiveValue; |
| 246 | 246 |
| 247 IntConstantExpression(this.primitiveValue); | 247 IntConstantExpression(this.primitiveValue); |
| 248 | 248 |
| 249 ConstantExpressionKind get kind => ConstantExpressionKind.INT; | 249 ConstantExpressionKind get kind => ConstantExpressionKind.INT; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 265 | 265 |
| 266 @override | 266 @override |
| 267 int _computeHashCode() => 17 * primitiveValue.hashCode; | 267 int _computeHashCode() => 17 * primitiveValue.hashCode; |
| 268 | 268 |
| 269 @override | 269 @override |
| 270 bool _equals(IntConstantExpression other) { | 270 bool _equals(IntConstantExpression other) { |
| 271 return primitiveValue == other.primitiveValue; | 271 return primitiveValue == other.primitiveValue; |
| 272 } | 272 } |
| 273 | 273 |
| 274 @override | 274 @override |
| 275 DartType getKnownType(CommonElements commonElements) => | 275 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 276 commonElements.intType; | 276 commonElements.intType; |
| 277 } | 277 } |
| 278 | 278 |
| 279 /// Double literal constant. | 279 /// Double literal constant. |
| 280 class DoubleConstantExpression extends PrimitiveConstantExpression { | 280 class DoubleConstantExpression extends PrimitiveConstantExpression { |
| 281 final double primitiveValue; | 281 final double primitiveValue; |
| 282 | 282 |
| 283 DoubleConstantExpression(this.primitiveValue); | 283 DoubleConstantExpression(this.primitiveValue); |
| 284 | 284 |
| 285 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; | 285 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 301 | 301 |
| 302 @override | 302 @override |
| 303 int _computeHashCode() => 19 * primitiveValue.hashCode; | 303 int _computeHashCode() => 19 * primitiveValue.hashCode; |
| 304 | 304 |
| 305 @override | 305 @override |
| 306 bool _equals(DoubleConstantExpression other) { | 306 bool _equals(DoubleConstantExpression other) { |
| 307 return primitiveValue == other.primitiveValue; | 307 return primitiveValue == other.primitiveValue; |
| 308 } | 308 } |
| 309 | 309 |
| 310 @override | 310 @override |
| 311 DartType getKnownType(CommonElements commonElements) => | 311 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 312 commonElements.doubleType; | 312 commonElements.doubleType; |
| 313 } | 313 } |
| 314 | 314 |
| 315 /// String literal constant. | 315 /// String literal constant. |
| 316 class StringConstantExpression extends PrimitiveConstantExpression { | 316 class StringConstantExpression extends PrimitiveConstantExpression { |
| 317 final String primitiveValue; | 317 final String primitiveValue; |
| 318 | 318 |
| 319 StringConstantExpression(this.primitiveValue); | 319 StringConstantExpression(this.primitiveValue); |
| 320 | 320 |
| 321 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; | 321 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 337 | 337 |
| 338 @override | 338 @override |
| 339 int _computeHashCode() => 23 * primitiveValue.hashCode; | 339 int _computeHashCode() => 23 * primitiveValue.hashCode; |
| 340 | 340 |
| 341 @override | 341 @override |
| 342 bool _equals(StringConstantExpression other) { | 342 bool _equals(StringConstantExpression other) { |
| 343 return primitiveValue == other.primitiveValue; | 343 return primitiveValue == other.primitiveValue; |
| 344 } | 344 } |
| 345 | 345 |
| 346 @override | 346 @override |
| 347 DartType getKnownType(CommonElements commonElements) => | 347 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 348 commonElements.stringType; | 348 commonElements.stringType; |
| 349 } | 349 } |
| 350 | 350 |
| 351 /// Null literal constant. | 351 /// Null literal constant. |
| 352 class NullConstantExpression extends PrimitiveConstantExpression { | 352 class NullConstantExpression extends PrimitiveConstantExpression { |
| 353 NullConstantExpression(); | 353 NullConstantExpression(); |
| 354 | 354 |
| 355 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; | 355 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; |
| 356 | 356 |
| 357 accept(ConstantExpressionVisitor visitor, [context]) { | 357 accept(ConstantExpressionVisitor visitor, [context]) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 371 | 371 |
| 372 get primitiveValue => null; | 372 get primitiveValue => null; |
| 373 | 373 |
| 374 @override | 374 @override |
| 375 int _computeHashCode() => 29; | 375 int _computeHashCode() => 29; |
| 376 | 376 |
| 377 @override | 377 @override |
| 378 bool _equals(NullConstantExpression other) => true; | 378 bool _equals(NullConstantExpression other) => true; |
| 379 | 379 |
| 380 @override | 380 @override |
| 381 DartType getKnownType(CommonElements commonElements) => | 381 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 382 commonElements.nullType; | 382 commonElements.nullType; |
| 383 } | 383 } |
| 384 | 384 |
| 385 /// Literal list constant. | 385 /// Literal list constant. |
| 386 class ListConstantExpression extends ConstantExpression { | 386 class ListConstantExpression extends ConstantExpression { |
| 387 final InterfaceType type; | 387 final ResolutionInterfaceType type; |
| 388 final List<ConstantExpression> values; | 388 final List<ConstantExpression> values; |
| 389 | 389 |
| 390 ListConstantExpression(this.type, this.values); | 390 ListConstantExpression(this.type, this.values); |
| 391 | 391 |
| 392 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; | 392 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; |
| 393 | 393 |
| 394 accept(ConstantExpressionVisitor visitor, [context]) { | 394 accept(ConstantExpressionVisitor visitor, [context]) { |
| 395 return visitor.visitList(this, context); | 395 return visitor.visitList(this, context); |
| 396 } | 396 } |
| 397 | 397 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 bool _equals(ListConstantExpression other) { | 432 bool _equals(ListConstantExpression other) { |
| 433 if (type != other.type) return false; | 433 if (type != other.type) return false; |
| 434 if (values.length != other.values.length) return false; | 434 if (values.length != other.values.length) return false; |
| 435 for (int i = 0; i < values.length; i++) { | 435 for (int i = 0; i < values.length; i++) { |
| 436 if (values[i] != other.values[i]) return false; | 436 if (values[i] != other.values[i]) return false; |
| 437 } | 437 } |
| 438 return true; | 438 return true; |
| 439 } | 439 } |
| 440 | 440 |
| 441 @override | 441 @override |
| 442 DartType getKnownType(CommonElements commonElements) => type; | 442 ResolutionDartType getKnownType(CommonElements commonElements) => type; |
| 443 | 443 |
| 444 @override | 444 @override |
| 445 bool get isImplicit => false; | 445 bool get isImplicit => false; |
| 446 | 446 |
| 447 @override | 447 @override |
| 448 bool get isPotential => values.any((e) => e.isPotential); | 448 bool get isPotential => values.any((e) => e.isPotential); |
| 449 } | 449 } |
| 450 | 450 |
| 451 /// Literal map constant. | 451 /// Literal map constant. |
| 452 class MapConstantExpression extends ConstantExpression { | 452 class MapConstantExpression extends ConstantExpression { |
| 453 final InterfaceType type; | 453 final ResolutionInterfaceType type; |
| 454 final List<ConstantExpression> keys; | 454 final List<ConstantExpression> keys; |
| 455 final List<ConstantExpression> values; | 455 final List<ConstantExpression> values; |
| 456 | 456 |
| 457 MapConstantExpression(this.type, this.keys, this.values); | 457 MapConstantExpression(this.type, this.keys, this.values); |
| 458 | 458 |
| 459 ConstantExpressionKind get kind => ConstantExpressionKind.MAP; | 459 ConstantExpressionKind get kind => ConstantExpressionKind.MAP; |
| 460 | 460 |
| 461 accept(ConstantExpressionVisitor visitor, [context]) { | 461 accept(ConstantExpressionVisitor visitor, [context]) { |
| 462 return visitor.visitMap(this, context); | 462 return visitor.visitMap(this, context); |
| 463 } | 463 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 if (type != other.type) return false; | 511 if (type != other.type) return false; |
| 512 if (values.length != other.values.length) return false; | 512 if (values.length != other.values.length) return false; |
| 513 for (int i = 0; i < values.length; i++) { | 513 for (int i = 0; i < values.length; i++) { |
| 514 if (keys[i] != other.keys[i]) return false; | 514 if (keys[i] != other.keys[i]) return false; |
| 515 if (values[i] != other.values[i]) return false; | 515 if (values[i] != other.values[i]) return false; |
| 516 } | 516 } |
| 517 return true; | 517 return true; |
| 518 } | 518 } |
| 519 | 519 |
| 520 @override | 520 @override |
| 521 DartType getKnownType(CommonElements commonElements) => type; | 521 ResolutionDartType getKnownType(CommonElements commonElements) => type; |
| 522 | 522 |
| 523 @override | 523 @override |
| 524 bool get isImplicit => false; | 524 bool get isImplicit => false; |
| 525 | 525 |
| 526 @override | 526 @override |
| 527 bool get isPotential { | 527 bool get isPotential { |
| 528 return keys.any((e) => e.isPotential) || values.any((e) => e.isPotential); | 528 return keys.any((e) => e.isPotential) || values.any((e) => e.isPotential); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 /// Invocation of a const constructor. | 532 /// Invocation of a const constructor. |
| 533 class ConstructedConstantExpression extends ConstantExpression { | 533 class ConstructedConstantExpression extends ConstantExpression { |
| 534 final InterfaceType type; | 534 final ResolutionInterfaceType type; |
| 535 final ConstructorElement target; | 535 final ConstructorElement target; |
| 536 final CallStructure callStructure; | 536 final CallStructure callStructure; |
| 537 final List<ConstantExpression> arguments; | 537 final List<ConstantExpression> arguments; |
| 538 | 538 |
| 539 ConstructedConstantExpression( | 539 ConstructedConstantExpression( |
| 540 this.type, this.target, this.callStructure, this.arguments) { | 540 this.type, this.target, this.callStructure, this.arguments) { |
| 541 assert(type.element == target.enclosingClass); | 541 assert(type.element == target.enclosingClass); |
| 542 assert(!arguments.contains(null)); | 542 assert(!arguments.contains(null)); |
| 543 } | 543 } |
| 544 | 544 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 561 sb.write('])'); | 561 sb.write('])'); |
| 562 } | 562 } |
| 563 | 563 |
| 564 Map<FieldElement, ConstantExpression> computeInstanceFields() { | 564 Map<FieldElement, ConstantExpression> computeInstanceFields() { |
| 565 assert(invariant(target, target.constantConstructor != null, | 565 assert(invariant(target, target.constantConstructor != null, |
| 566 message: "No constant constructor computed for $target.")); | 566 message: "No constant constructor computed for $target.")); |
| 567 return target.constantConstructor | 567 return target.constantConstructor |
| 568 .computeInstanceFields(arguments, callStructure); | 568 .computeInstanceFields(arguments, callStructure); |
| 569 } | 569 } |
| 570 | 570 |
| 571 InterfaceType computeInstanceType() { | 571 ResolutionInterfaceType computeInstanceType() { |
| 572 return target.constantConstructor.computeInstanceType(type); | 572 return target.constantConstructor.computeInstanceType(type); |
| 573 } | 573 } |
| 574 | 574 |
| 575 ConstructedConstantExpression apply(NormalizedArguments arguments) { | 575 ConstructedConstantExpression apply(NormalizedArguments arguments) { |
| 576 return new ConstructedConstantExpression(type, target, callStructure, | 576 return new ConstructedConstantExpression(type, target, callStructure, |
| 577 this.arguments.map((a) => a.apply(arguments)).toList()); | 577 this.arguments.map((a) => a.apply(arguments)).toList()); |
| 578 } | 578 } |
| 579 | 579 |
| 580 @override | 580 @override |
| 581 ConstantValue evaluate( | 581 ConstantValue evaluate( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 @override | 688 @override |
| 689 bool _equals(ConcatenateConstantExpression other) { | 689 bool _equals(ConcatenateConstantExpression other) { |
| 690 if (expressions.length != other.expressions.length) return false; | 690 if (expressions.length != other.expressions.length) return false; |
| 691 for (int i = 0; i < expressions.length; i++) { | 691 for (int i = 0; i < expressions.length; i++) { |
| 692 if (expressions[i] != other.expressions[i]) return false; | 692 if (expressions[i] != other.expressions[i]) return false; |
| 693 } | 693 } |
| 694 return true; | 694 return true; |
| 695 } | 695 } |
| 696 | 696 |
| 697 @override | 697 @override |
| 698 DartType getKnownType(CommonElements commonElements) => | 698 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 699 commonElements.stringType; | 699 commonElements.stringType; |
| 700 | 700 |
| 701 @override | 701 @override |
| 702 bool get isPotential { | 702 bool get isPotential { |
| 703 return expressions.any((e) => e.isPotential); | 703 return expressions.any((e) => e.isPotential); |
| 704 } | 704 } |
| 705 } | 705 } |
| 706 | 706 |
| 707 /// Symbol literal. | 707 /// Symbol literal. |
| 708 class SymbolConstantExpression extends ConstantExpression { | 708 class SymbolConstantExpression extends ConstantExpression { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 729 return name == other.name; | 729 return name == other.name; |
| 730 } | 730 } |
| 731 | 731 |
| 732 @override | 732 @override |
| 733 ConstantValue evaluate( | 733 ConstantValue evaluate( |
| 734 Environment environment, ConstantSystem constantSystem) { | 734 Environment environment, ConstantSystem constantSystem) { |
| 735 return constantSystem.createSymbol(environment.compiler, name); | 735 return constantSystem.createSymbol(environment.compiler, name); |
| 736 } | 736 } |
| 737 | 737 |
| 738 @override | 738 @override |
| 739 DartType getKnownType(CommonElements commonElements) => | 739 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 740 commonElements.symbolType; | 740 commonElements.symbolType; |
| 741 } | 741 } |
| 742 | 742 |
| 743 /// Type literal. | 743 /// Type literal. |
| 744 class TypeConstantExpression extends ConstantExpression { | 744 class TypeConstantExpression extends ConstantExpression { |
| 745 /// Either [DynamicType] or a raw [GenericType]. | 745 /// Either [ResolutionDynamicType] or a raw [GenericType]. |
| 746 final DartType type; | 746 final ResolutionDartType type; |
| 747 | 747 |
| 748 TypeConstantExpression(this.type) { | 748 TypeConstantExpression(this.type) { |
| 749 assert(type is GenericType || type is DynamicType); | 749 assert(type is GenericType || type is ResolutionDynamicType); |
| 750 } | 750 } |
| 751 | 751 |
| 752 ConstantExpressionKind get kind => ConstantExpressionKind.TYPE; | 752 ConstantExpressionKind get kind => ConstantExpressionKind.TYPE; |
| 753 | 753 |
| 754 accept(ConstantExpressionVisitor visitor, [context]) { | 754 accept(ConstantExpressionVisitor visitor, [context]) { |
| 755 return visitor.visitType(this, context); | 755 return visitor.visitType(this, context); |
| 756 } | 756 } |
| 757 | 757 |
| 758 @override | 758 @override |
| 759 void _createStructuredText(StringBuffer sb) { | 759 void _createStructuredText(StringBuffer sb) { |
| 760 sb.write('Type(type=$type)'); | 760 sb.write('Type(type=$type)'); |
| 761 } | 761 } |
| 762 | 762 |
| 763 @override | 763 @override |
| 764 ConstantValue evaluate( | 764 ConstantValue evaluate( |
| 765 Environment environment, ConstantSystem constantSystem) { | 765 Environment environment, ConstantSystem constantSystem) { |
| 766 return constantSystem.createType(environment.compiler, type); | 766 return constantSystem.createType(environment.compiler, type); |
| 767 } | 767 } |
| 768 | 768 |
| 769 @override | 769 @override |
| 770 int _computeHashCode() => 13 * type.hashCode; | 770 int _computeHashCode() => 13 * type.hashCode; |
| 771 | 771 |
| 772 @override | 772 @override |
| 773 bool _equals(TypeConstantExpression other) { | 773 bool _equals(TypeConstantExpression other) { |
| 774 return type == other.type; | 774 return type == other.type; |
| 775 } | 775 } |
| 776 | 776 |
| 777 @override | 777 @override |
| 778 DartType getKnownType(CommonElements commonElements) => | 778 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 779 commonElements.typeType; | 779 commonElements.typeType; |
| 780 } | 780 } |
| 781 | 781 |
| 782 /// Reference to a constant local, top-level, or static variable. | 782 /// Reference to a constant local, top-level, or static variable. |
| 783 class VariableConstantExpression extends ConstantExpression { | 783 class VariableConstantExpression extends ConstantExpression { |
| 784 final VariableElement element; | 784 final VariableElement element; |
| 785 | 785 |
| 786 VariableConstantExpression(this.element); | 786 VariableConstantExpression(this.element); |
| 787 | 787 |
| 788 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; | 788 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 | 836 |
| 837 @override | 837 @override |
| 838 int _computeHashCode() => 13 * element.hashCode; | 838 int _computeHashCode() => 13 * element.hashCode; |
| 839 | 839 |
| 840 @override | 840 @override |
| 841 bool _equals(FunctionConstantExpression other) { | 841 bool _equals(FunctionConstantExpression other) { |
| 842 return element == other.element; | 842 return element == other.element; |
| 843 } | 843 } |
| 844 | 844 |
| 845 @override | 845 @override |
| 846 DartType getKnownType(CommonElements commonElements) => | 846 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 847 commonElements.functionType; | 847 commonElements.functionType; |
| 848 } | 848 } |
| 849 | 849 |
| 850 /// A constant binary expression like `a * b`. | 850 /// A constant binary expression like `a * b`. |
| 851 class BinaryConstantExpression extends ConstantExpression { | 851 class BinaryConstantExpression extends ConstantExpression { |
| 852 final ConstantExpression left; | 852 final ConstantExpression left; |
| 853 final BinaryOperator operator; | 853 final BinaryOperator operator; |
| 854 final ConstantExpression right; | 854 final ConstantExpression right; |
| 855 | 855 |
| 856 BinaryConstantExpression(this.left, this.operator, this.right) { | 856 BinaryConstantExpression(this.left, this.operator, this.right) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 887 .lookupBinary(operator) | 887 .lookupBinary(operator) |
| 888 .fold(leftValue, rightValue); | 888 .fold(leftValue, rightValue); |
| 889 } | 889 } |
| 890 } | 890 } |
| 891 | 891 |
| 892 ConstantExpression apply(NormalizedArguments arguments) { | 892 ConstantExpression apply(NormalizedArguments arguments) { |
| 893 return new BinaryConstantExpression( | 893 return new BinaryConstantExpression( |
| 894 left.apply(arguments), operator, right.apply(arguments)); | 894 left.apply(arguments), operator, right.apply(arguments)); |
| 895 } | 895 } |
| 896 | 896 |
| 897 DartType getKnownType(CommonElements commonElements) { | 897 ResolutionDartType getKnownType(CommonElements commonElements) { |
| 898 DartType knownLeftType = left.getKnownType(commonElements); | 898 ResolutionDartType knownLeftType = left.getKnownType(commonElements); |
| 899 DartType knownRightType = right.getKnownType(commonElements); | 899 ResolutionDartType knownRightType = right.getKnownType(commonElements); |
| 900 switch (operator.kind) { | 900 switch (operator.kind) { |
| 901 case BinaryOperatorKind.EQ: | 901 case BinaryOperatorKind.EQ: |
| 902 case BinaryOperatorKind.NOT_EQ: | 902 case BinaryOperatorKind.NOT_EQ: |
| 903 case BinaryOperatorKind.LOGICAL_AND: | 903 case BinaryOperatorKind.LOGICAL_AND: |
| 904 case BinaryOperatorKind.LOGICAL_OR: | 904 case BinaryOperatorKind.LOGICAL_OR: |
| 905 case BinaryOperatorKind.GT: | 905 case BinaryOperatorKind.GT: |
| 906 case BinaryOperatorKind.LT: | 906 case BinaryOperatorKind.LT: |
| 907 case BinaryOperatorKind.GTEQ: | 907 case BinaryOperatorKind.GTEQ: |
| 908 case BinaryOperatorKind.LTEQ: | 908 case BinaryOperatorKind.LTEQ: |
| 909 return commonElements.boolType; | 909 return commonElements.boolType; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 int _computeHashCode() { | 1029 int _computeHashCode() { |
| 1030 return 17 * left.hashCode + 19 * right.hashCode; | 1030 return 17 * left.hashCode + 19 * right.hashCode; |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 @override | 1033 @override |
| 1034 bool _equals(IdenticalConstantExpression other) { | 1034 bool _equals(IdenticalConstantExpression other) { |
| 1035 return left == other.left && right == other.right; | 1035 return left == other.left && right == other.right; |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 @override | 1038 @override |
| 1039 DartType getKnownType(CommonElements commonElements) => | 1039 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 1040 commonElements.boolType; | 1040 commonElements.boolType; |
| 1041 | 1041 |
| 1042 @override | 1042 @override |
| 1043 bool get isPotential { | 1043 bool get isPotential { |
| 1044 return left.isPotential || right.isPotential; | 1044 return left.isPotential || right.isPotential; |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 /// A unary constant expression like `-a`. | 1048 /// A unary constant expression like `-a`. |
| 1049 class UnaryConstantExpression extends ConstantExpression { | 1049 class UnaryConstantExpression extends ConstantExpression { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 int _computeHashCode() { | 1085 int _computeHashCode() { |
| 1086 return 13 * operator.hashCode + 17 * expression.hashCode; | 1086 return 13 * operator.hashCode + 17 * expression.hashCode; |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 @override | 1089 @override |
| 1090 bool _equals(UnaryConstantExpression other) { | 1090 bool _equals(UnaryConstantExpression other) { |
| 1091 return operator == other.operator && expression == other.expression; | 1091 return operator == other.operator && expression == other.expression; |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 @override | 1094 @override |
| 1095 DartType getKnownType(CommonElements commonElements) { | 1095 ResolutionDartType getKnownType(CommonElements commonElements) { |
| 1096 return expression.getKnownType(commonElements); | 1096 return expression.getKnownType(commonElements); |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 @override | 1099 @override |
| 1100 bool get isPotential { | 1100 bool get isPotential { |
| 1101 return expression.isPotential; | 1101 return expression.isPotential; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { | 1104 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { |
| 1105 UnaryOperatorKind.NOT: 14, | 1105 UnaryOperatorKind.NOT: 14, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 int _computeHashCode() { | 1148 int _computeHashCode() { |
| 1149 return 23 * expression.hashCode; | 1149 return 23 * expression.hashCode; |
| 1150 } | 1150 } |
| 1151 | 1151 |
| 1152 @override | 1152 @override |
| 1153 bool _equals(StringLengthConstantExpression other) { | 1153 bool _equals(StringLengthConstantExpression other) { |
| 1154 return expression == other.expression; | 1154 return expression == other.expression; |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 @override | 1157 @override |
| 1158 DartType getKnownType(CommonElements commonElements) => | 1158 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 1159 commonElements.intType; | 1159 commonElements.intType; |
| 1160 | 1160 |
| 1161 @override | 1161 @override |
| 1162 bool get isPotential { | 1162 bool get isPotential { |
| 1163 return expression.isPotential; | 1163 return expression.isPotential; |
| 1164 } | 1164 } |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 /// A constant conditional expression like `a ? b : c`. | 1167 /// A constant conditional expression like `a ? b : c`. |
| 1168 class ConditionalConstantExpression extends ConstantExpression { | 1168 class ConditionalConstantExpression extends ConstantExpression { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 if (conditionValue.isTrue) { | 1220 if (conditionValue.isTrue) { |
| 1221 return trueValue; | 1221 return trueValue; |
| 1222 } else if (conditionValue.isFalse) { | 1222 } else if (conditionValue.isFalse) { |
| 1223 return falseValue; | 1223 return falseValue; |
| 1224 } else { | 1224 } else { |
| 1225 return new NonConstantValue(); | 1225 return new NonConstantValue(); |
| 1226 } | 1226 } |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 @override | 1229 @override |
| 1230 DartType getKnownType(CommonElements commonElements) { | 1230 ResolutionDartType getKnownType(CommonElements commonElements) { |
| 1231 DartType trueType = trueExp.getKnownType(commonElements); | 1231 ResolutionDartType trueType = trueExp.getKnownType(commonElements); |
| 1232 DartType falseType = falseExp.getKnownType(commonElements); | 1232 ResolutionDartType falseType = falseExp.getKnownType(commonElements); |
| 1233 if (trueType == falseType) { | 1233 if (trueType == falseType) { |
| 1234 return trueType; | 1234 return trueType; |
| 1235 } | 1235 } |
| 1236 return null; | 1236 return null; |
| 1237 } | 1237 } |
| 1238 | 1238 |
| 1239 @override | 1239 @override |
| 1240 bool get isPotential { | 1240 bool get isPotential { |
| 1241 return condition.isPotential || trueExp.isPotential || falseExp.isPotential; | 1241 return condition.isPotential || trueExp.isPotential || falseExp.isPotential; |
| 1242 } | 1242 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 return defaultConstantValue; | 1401 return defaultConstantValue; |
| 1402 } | 1402 } |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 ConstantExpression apply(NormalizedArguments arguments) { | 1405 ConstantExpression apply(NormalizedArguments arguments) { |
| 1406 return new BoolFromEnvironmentConstantExpression(name.apply(arguments), | 1406 return new BoolFromEnvironmentConstantExpression(name.apply(arguments), |
| 1407 defaultValue != null ? defaultValue.apply(arguments) : null); | 1407 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 @override | 1410 @override |
| 1411 DartType getKnownType(CommonElements commonElements) => | 1411 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 1412 commonElements.boolType; | 1412 commonElements.boolType; |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 /// A `const int.fromEnvironment` constant. | 1415 /// A `const int.fromEnvironment` constant. |
| 1416 class IntFromEnvironmentConstantExpression | 1416 class IntFromEnvironmentConstantExpression |
| 1417 extends FromEnvironmentConstantExpression { | 1417 extends FromEnvironmentConstantExpression { |
| 1418 IntFromEnvironmentConstantExpression( | 1418 IntFromEnvironmentConstantExpression( |
| 1419 ConstantExpression name, ConstantExpression defaultValue) | 1419 ConstantExpression name, ConstantExpression defaultValue) |
| 1420 : super(name, defaultValue); | 1420 : super(name, defaultValue); |
| 1421 | 1421 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 return constantSystem.createInt(value); | 1467 return constantSystem.createInt(value); |
| 1468 } | 1468 } |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 ConstantExpression apply(NormalizedArguments arguments) { | 1471 ConstantExpression apply(NormalizedArguments arguments) { |
| 1472 return new IntFromEnvironmentConstantExpression(name.apply(arguments), | 1472 return new IntFromEnvironmentConstantExpression(name.apply(arguments), |
| 1473 defaultValue != null ? defaultValue.apply(arguments) : null); | 1473 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1474 } | 1474 } |
| 1475 | 1475 |
| 1476 @override | 1476 @override |
| 1477 DartType getKnownType(CommonElements commonElements) => | 1477 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 1478 commonElements.intType; | 1478 commonElements.intType; |
| 1479 } | 1479 } |
| 1480 | 1480 |
| 1481 /// A `const String.fromEnvironment` constant. | 1481 /// A `const String.fromEnvironment` constant. |
| 1482 class StringFromEnvironmentConstantExpression | 1482 class StringFromEnvironmentConstantExpression |
| 1483 extends FromEnvironmentConstantExpression { | 1483 extends FromEnvironmentConstantExpression { |
| 1484 StringFromEnvironmentConstantExpression( | 1484 StringFromEnvironmentConstantExpression( |
| 1485 ConstantExpression name, ConstantExpression defaultValue) | 1485 ConstantExpression name, ConstantExpression defaultValue) |
| 1486 : super(name, defaultValue); | 1486 : super(name, defaultValue); |
| 1487 | 1487 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 return constantSystem.createString(new DartString.literal(text)); | 1529 return constantSystem.createString(new DartString.literal(text)); |
| 1530 } | 1530 } |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 ConstantExpression apply(NormalizedArguments arguments) { | 1533 ConstantExpression apply(NormalizedArguments arguments) { |
| 1534 return new StringFromEnvironmentConstantExpression(name.apply(arguments), | 1534 return new StringFromEnvironmentConstantExpression(name.apply(arguments), |
| 1535 defaultValue != null ? defaultValue.apply(arguments) : null); | 1535 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 @override | 1538 @override |
| 1539 DartType getKnownType(CommonElements commonElements) => | 1539 ResolutionDartType getKnownType(CommonElements commonElements) => |
| 1540 commonElements.stringType; | 1540 commonElements.stringType; |
| 1541 } | 1541 } |
| 1542 | 1542 |
| 1543 /// A constant expression referenced with a deferred prefix. | 1543 /// A constant expression referenced with a deferred prefix. |
| 1544 /// For example `lib.C`. | 1544 /// For example `lib.C`. |
| 1545 class DeferredConstantExpression extends ConstantExpression { | 1545 class DeferredConstantExpression extends ConstantExpression { |
| 1546 final ConstantExpression expression; | 1546 final ConstantExpression expression; |
| 1547 final PrefixElement prefix; | 1547 final PrefixElement prefix; |
| 1548 | 1548 |
| 1549 DeferredConstantExpression(this.expression, this.prefix); | 1549 DeferredConstantExpression(this.expression, this.prefix); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 if (child.precedence < parent.precedence || | 1634 if (child.precedence < parent.precedence || |
| 1635 !leftAssociative && child.precedence == parent.precedence) { | 1635 !leftAssociative && child.precedence == parent.precedence) { |
| 1636 sb.write('('); | 1636 sb.write('('); |
| 1637 child.accept(this); | 1637 child.accept(this); |
| 1638 sb.write(')'); | 1638 sb.write(')'); |
| 1639 } else { | 1639 } else { |
| 1640 child.accept(this); | 1640 child.accept(this); |
| 1641 } | 1641 } |
| 1642 } | 1642 } |
| 1643 | 1643 |
| 1644 void writeTypeArguments(InterfaceType type) { | 1644 void writeTypeArguments(ResolutionInterfaceType type) { |
| 1645 if (type.treatAsRaw) return; | 1645 if (type.treatAsRaw) return; |
| 1646 sb.write('<'); | 1646 sb.write('<'); |
| 1647 bool needsComma = false; | 1647 bool needsComma = false; |
| 1648 for (DartType value in type.typeArguments) { | 1648 for (ResolutionDartType value in type.typeArguments) { |
| 1649 if (needsComma) { | 1649 if (needsComma) { |
| 1650 sb.write(', '); | 1650 sb.write(', '); |
| 1651 } | 1651 } |
| 1652 sb.write(value); | 1652 sb.write(value); |
| 1653 needsComma = true; | 1653 needsComma = true; |
| 1654 } | 1654 } |
| 1655 sb.write('>'); | 1655 sb.write('>'); |
| 1656 } | 1656 } |
| 1657 | 1657 |
| 1658 @override | 1658 @override |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 visit(exp.name); | 1888 visit(exp.name); |
| 1889 if (exp.defaultValue != null) { | 1889 if (exp.defaultValue != null) { |
| 1890 sb.write(', defaultValue: '); | 1890 sb.write(', defaultValue: '); |
| 1891 visit(exp.defaultValue); | 1891 visit(exp.defaultValue); |
| 1892 } | 1892 } |
| 1893 sb.write(')'); | 1893 sb.write(')'); |
| 1894 } | 1894 } |
| 1895 | 1895 |
| 1896 String toString() => sb.toString(); | 1896 String toString() => sb.toString(); |
| 1897 } | 1897 } |
| OLD | NEW |