| 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 '../dart2jslib.dart' show assertDebugMode; | 7 import '../dart2jslib.dart' show assertDebugMode; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart' show | 9 import '../elements/elements.dart' show |
| 10 ConstructorElement, | 10 ConstructorElement, |
| 11 Element, | 11 Element, |
| 12 FunctionElement, | 12 FunctionElement, |
| 13 PrefixElement, |
| 13 VariableElement; | 14 VariableElement; |
| 14 import '../resolution/operators.dart'; | 15 import '../resolution/operators.dart'; |
| 15 import '../universe/universe.dart' show CallStructure; | 16 import '../universe/universe.dart' show CallStructure; |
| 16 import 'values.dart'; | 17 import 'values.dart'; |
| 17 | 18 |
| 18 enum ConstantExpressionKind { | 19 enum ConstantExpressionKind { |
| 19 BINARY, | 20 BINARY, |
| 20 BOOL, | 21 BOOL, |
| 21 CONCATENATE, | 22 CONCATENATE, |
| 22 CONDITIONAL, | 23 CONDITIONAL, |
| 23 CONSTRUCTED, | 24 CONSTRUCTED, |
| 25 DEFERRED, |
| 24 DOUBLE, | 26 DOUBLE, |
| 25 ERRONEOUS, | 27 ERRONEOUS, |
| 26 FUNCTION, | 28 FUNCTION, |
| 27 IDENTICAL, | 29 IDENTICAL, |
| 28 INT, | 30 INT, |
| 29 LIST, | 31 LIST, |
| 30 MAP, | 32 MAP, |
| 31 NULL, | 33 NULL, |
| 32 STRING, | 34 STRING, |
| 33 SYMBOL, | 35 SYMBOL, |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } | 601 } |
| 600 | 602 |
| 601 @override | 603 @override |
| 602 bool _equals(ConditionalConstantExpression other) { | 604 bool _equals(ConditionalConstantExpression other) { |
| 603 return condition == other.condition && | 605 return condition == other.condition && |
| 604 trueExp == other.trueExp && | 606 trueExp == other.trueExp && |
| 605 falseExp == other.falseExp; | 607 falseExp == other.falseExp; |
| 606 } | 608 } |
| 607 } | 609 } |
| 608 | 610 |
| 611 /// A constant expression referenced with a deferred prefix. |
| 612 /// For example `lib.C`. |
| 613 class DeferredConstantExpression extends ConstantExpression { |
| 614 final ConstantValue value; |
| 615 final ConstantExpression expression; |
| 616 final PrefixElement prefix; |
| 617 |
| 618 DeferredConstantExpression(this.value, this.expression, this.prefix); |
| 619 |
| 620 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED; |
| 621 |
| 622 @override |
| 623 int _computeHashCode() { |
| 624 return 13 * expression.hashCode; |
| 625 } |
| 626 |
| 627 @override |
| 628 bool _equals(DeferredConstantExpression other) { |
| 629 return expression == other.expression; |
| 630 } |
| 631 |
| 632 @override |
| 633 accept(ConstantExpressionVisitor visitor, [context]) { |
| 634 return visitor.visitDeferred(this, context); |
| 635 } |
| 636 } |
| 637 |
| 609 abstract class ConstantExpressionVisitor<C, R> { | 638 abstract class ConstantExpressionVisitor<C, R> { |
| 610 const ConstantExpressionVisitor(); | 639 const ConstantExpressionVisitor(); |
| 611 | 640 |
| 612 R visit(ConstantExpression constant, C context) { | 641 R visit(ConstantExpression constant, C context) { |
| 613 return constant.accept(this, context); | 642 return constant.accept(this, context); |
| 614 } | 643 } |
| 615 | 644 |
| 616 R visitPrimitive(PrimitiveConstantExpression exp, C context); | 645 R visitPrimitive(PrimitiveConstantExpression exp, C context); |
| 617 R visitList(ListConstantExpression exp, C context); | 646 R visitList(ListConstantExpression exp, C context); |
| 618 R visitMap(MapConstantExpression exp, C context); | 647 R visitMap(MapConstantExpression exp, C context); |
| 619 R visitConstructed(ConstructedConstantExpression exp, C context); | 648 R visitConstructed(ConstructedConstantExpression exp, C context); |
| 620 R visitConcatenate(ConcatenateConstantExpression exp, C context); | 649 R visitConcatenate(ConcatenateConstantExpression exp, C context); |
| 621 R visitSymbol(SymbolConstantExpression exp, C context); | 650 R visitSymbol(SymbolConstantExpression exp, C context); |
| 622 R visitType(TypeConstantExpression exp, C context); | 651 R visitType(TypeConstantExpression exp, C context); |
| 623 R visitVariable(VariableConstantExpression exp, C context); | 652 R visitVariable(VariableConstantExpression exp, C context); |
| 624 R visitFunction(FunctionConstantExpression exp, C context); | 653 R visitFunction(FunctionConstantExpression exp, C context); |
| 625 R visitBinary(BinaryConstantExpression exp, C context); | 654 R visitBinary(BinaryConstantExpression exp, C context); |
| 626 R visitIdentical(IdenticalConstantExpression exp, C context); | 655 R visitIdentical(IdenticalConstantExpression exp, C context); |
| 627 R visitUnary(UnaryConstantExpression exp, C context); | 656 R visitUnary(UnaryConstantExpression exp, C context); |
| 628 R visitConditional(ConditionalConstantExpression exp, C context); | 657 R visitConditional(ConditionalConstantExpression exp, C context); |
| 658 R visitDeferred(DeferredConstantExpression exp, C context); |
| 629 } | 659 } |
| 630 | 660 |
| 631 /// Represents the declaration of a constant [element] with value [expression]. | 661 /// Represents the declaration of a constant [element] with value [expression]. |
| 632 // TODO(johnniwinther): Where does this class belong? | 662 // TODO(johnniwinther): Where does this class belong? |
| 633 class ConstDeclaration { | 663 class ConstDeclaration { |
| 634 final VariableElement element; | 664 final VariableElement element; |
| 635 final ConstantExpression expression; | 665 final ConstantExpression expression; |
| 636 | 666 |
| 637 ConstDeclaration(this.element, this.expression); | 667 ConstDeclaration(this.element, this.expression); |
| 638 } | 668 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 | 831 |
| 802 @override | 832 @override |
| 803 void visitConditional(ConditionalConstantExpression exp, [_]) { | 833 void visitConditional(ConditionalConstantExpression exp, [_]) { |
| 804 write(exp, exp.condition, leftAssociative: false); | 834 write(exp, exp.condition, leftAssociative: false); |
| 805 sb.write(' ? '); | 835 sb.write(' ? '); |
| 806 write(exp, exp.trueExp); | 836 write(exp, exp.trueExp); |
| 807 sb.write(' : '); | 837 sb.write(' : '); |
| 808 write(exp, exp.falseExp); | 838 write(exp, exp.falseExp); |
| 809 } | 839 } |
| 810 | 840 |
| 841 @override |
| 842 visitDeferred(DeferredConstantExpression exp, context) { |
| 843 sb.write(exp.prefix.deferredImport.prefix.source); |
| 844 sb.write('.'); |
| 845 write(exp, exp.expression); |
| 846 } |
| 847 |
| 811 String toString() => sb.toString(); | 848 String toString() => sb.toString(); |
| 812 } | 849 } |
| OLD | NEW |