Chromium Code Reviews| 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.compile_time_constant_evaluator; | 5 library dart2js.compile_time_constant_evaluator; |
| 6 | 6 |
| 7 import 'constant_system_dart.dart'; | 7 import 'constant_system_dart.dart'; |
| 8 import 'constants/constant_system.dart'; | 8 import 'constants/constant_system.dart'; |
| 9 import 'constants/expressions.dart'; | 9 import 'constants/expressions.dart'; |
| 10 import 'constants/values.dart'; | 10 import 'constants/values.dart'; |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 AstConstant left = evaluate(send.receiver); | 585 AstConstant left = evaluate(send.receiver); |
| 586 AstConstant right = evaluate(send.argumentsNode.nodes.head); | 586 AstConstant right = evaluate(send.argumentsNode.nodes.head); |
| 587 if (left == null || right == null) { | 587 if (left == null || right == null) { |
| 588 return null; | 588 return null; |
| 589 } | 589 } |
| 590 ConstantValue leftValue = left.value; | 590 ConstantValue leftValue = left.value; |
| 591 ConstantValue rightValue = right.value; | 591 ConstantValue rightValue = right.value; |
| 592 Operator node = send.selector.asOperator(); | 592 Operator node = send.selector.asOperator(); |
| 593 BinaryOperator operator = BinaryOperator.parse(node.source); | 593 BinaryOperator operator = BinaryOperator.parse(node.source); |
| 594 ConstantValue folded = null; | 594 ConstantValue folded = null; |
| 595 switch (operator.kind) { | 595 // operator is null when `node=="is"` |
| 596 case BinaryOperatorKind.EQ: | 596 if (operator != null) { |
| 597 if (leftValue.isPrimitive && rightValue.isPrimitive) { | 597 switch (operator.kind) { |
|
Siggi Cherem (dart-lang)
2015/04/17 19:19:23
FYI - no changes below besides indentation
Johnni Winther
2015/04/17 20:31:15
Thanks. I think `node=="as"` also ends here.
| |
| 598 folded = constantSystem.equal.fold(leftValue, rightValue); | 598 case BinaryOperatorKind.EQ: |
| 599 } | 599 if (leftValue.isPrimitive && rightValue.isPrimitive) { |
| 600 break; | 600 folded = constantSystem.equal.fold(leftValue, rightValue); |
| 601 case BinaryOperatorKind.NOT_EQ: | |
| 602 if (leftValue.isPrimitive && rightValue.isPrimitive) { | |
| 603 BoolConstantValue areEquals = | |
| 604 constantSystem.equal.fold(leftValue, rightValue); | |
| 605 if (areEquals == null) { | |
| 606 folded = null; | |
| 607 } else { | |
| 608 folded = areEquals.negate(); | |
| 609 } | 601 } |
| 610 } | 602 break; |
| 611 break; | 603 case BinaryOperatorKind.NOT_EQ: |
| 612 default: | 604 if (leftValue.isPrimitive && rightValue.isPrimitive) { |
| 613 BinaryOperation operation = constantSystem.lookupBinary(operator); | 605 BoolConstantValue areEquals = |
| 614 if (operation != null) { | 606 constantSystem.equal.fold(leftValue, rightValue); |
| 615 folded = operation.fold(leftValue, rightValue); | 607 if (areEquals == null) { |
| 616 } | 608 folded = null; |
| 609 } else { | |
| 610 folded = areEquals.negate(); | |
| 611 } | |
| 612 } | |
| 613 break; | |
| 614 default: | |
| 615 BinaryOperation operation = constantSystem.lookupBinary(operator); | |
| 616 if (operation != null) { | |
| 617 folded = operation.fold(leftValue, rightValue); | |
| 618 } | |
| 619 } | |
| 617 } | 620 } |
| 618 if (folded == null) { | 621 if (folded == null) { |
| 619 return signalNotCompileTimeConstant(send); | 622 return signalNotCompileTimeConstant(send); |
| 620 } | 623 } |
| 621 return new AstConstant( | 624 return new AstConstant( |
| 622 context, send, new BinaryConstantExpression(folded, | 625 context, send, new BinaryConstantExpression(folded, |
| 623 left.expression, operator, right.expression)); | 626 left.expression, operator, right.expression)); |
| 624 } | 627 } |
| 625 return signalNotCompileTimeConstant(send); | 628 return signalNotCompileTimeConstant(send); |
| 626 } | 629 } |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 ConstantValue get value => expression.value; | 1138 ConstantValue get value => expression.value; |
| 1136 | 1139 |
| 1137 String toString() => expression.toString(); | 1140 String toString() => expression.toString(); |
| 1138 } | 1141 } |
| 1139 | 1142 |
| 1140 /// A synthetic constant used to recover from errors. | 1143 /// A synthetic constant used to recover from errors. |
| 1141 class ErroneousAstConstant extends AstConstant { | 1144 class ErroneousAstConstant extends AstConstant { |
| 1142 ErroneousAstConstant(Element element, Node node) | 1145 ErroneousAstConstant(Element element, Node node) |
| 1143 : super(element, node, new ErroneousConstantExpression()); | 1146 : super(element, node, new ErroneousConstantExpression()); |
| 1144 } | 1147 } |
| OLD | NEW |