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 engine.constant; | 5 library engine.constant; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/utilities_general.dart'; | 10 import 'package:analyzer/src/generated/utilities_general.dart'; |
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 } | 1526 } |
1527 return result; | 1527 return result; |
1528 } | 1528 } |
1529 | 1529 |
1530 @override | 1530 @override |
1531 DartObjectImpl visitBinaryExpression(BinaryExpression node) { | 1531 DartObjectImpl visitBinaryExpression(BinaryExpression node) { |
1532 DartObjectImpl leftResult = node.leftOperand.accept(this); | 1532 DartObjectImpl leftResult = node.leftOperand.accept(this); |
1533 DartObjectImpl rightResult = node.rightOperand.accept(this); | 1533 DartObjectImpl rightResult = node.rightOperand.accept(this); |
1534 TokenType operatorType = node.operator.type; | 1534 TokenType operatorType = node.operator.type; |
1535 // 'null' is almost never good operand | 1535 // 'null' is almost never good operand |
1536 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) { | 1536 if (operatorType != TokenType.BANG_EQ && |
| 1537 operatorType != TokenType.EQ_EQ && |
| 1538 operatorType != TokenType.QUESTION_QUESTION) { |
1537 if (leftResult != null && leftResult.isNull || | 1539 if (leftResult != null && leftResult.isNull || |
1538 rightResult != null && rightResult.isNull) { | 1540 rightResult != null && rightResult.isNull) { |
1539 _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); | 1541 _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); |
1540 return null; | 1542 return null; |
1541 } | 1543 } |
1542 } | 1544 } |
1543 // evaluate operator | 1545 // evaluate operator |
1544 while (true) { | 1546 while (true) { |
1545 if (operatorType == TokenType.AMPERSAND) { | 1547 if (operatorType == TokenType.AMPERSAND) { |
1546 return _dartObjectComputer.bitAnd(node, leftResult, rightResult); | 1548 return _dartObjectComputer.bitAnd(node, leftResult, rightResult); |
(...skipping 28 matching lines...) Expand all Loading... |
1575 } else if (operatorType == TokenType.PERCENT) { | 1577 } else if (operatorType == TokenType.PERCENT) { |
1576 return _dartObjectComputer.remainder(node, leftResult, rightResult); | 1578 return _dartObjectComputer.remainder(node, leftResult, rightResult); |
1577 } else if (operatorType == TokenType.PLUS) { | 1579 } else if (operatorType == TokenType.PLUS) { |
1578 return _dartObjectComputer.add(node, leftResult, rightResult); | 1580 return _dartObjectComputer.add(node, leftResult, rightResult); |
1579 } else if (operatorType == TokenType.STAR) { | 1581 } else if (operatorType == TokenType.STAR) { |
1580 return _dartObjectComputer.times(node, leftResult, rightResult); | 1582 return _dartObjectComputer.times(node, leftResult, rightResult); |
1581 } else if (operatorType == TokenType.SLASH) { | 1583 } else if (operatorType == TokenType.SLASH) { |
1582 return _dartObjectComputer.divide(node, leftResult, rightResult); | 1584 return _dartObjectComputer.divide(node, leftResult, rightResult); |
1583 } else if (operatorType == TokenType.TILDE_SLASH) { | 1585 } else if (operatorType == TokenType.TILDE_SLASH) { |
1584 return _dartObjectComputer.integerDivide(node, leftResult, rightResult); | 1586 return _dartObjectComputer.integerDivide(node, leftResult, rightResult); |
| 1587 } else if (operatorType == TokenType.QUESTION_QUESTION) { |
| 1588 return _dartObjectComputer.questionQuestion( |
| 1589 node, leftResult, rightResult); |
1585 } else { | 1590 } else { |
1586 // TODO(brianwilkerson) Figure out which error to report. | 1591 // TODO(brianwilkerson) Figure out which error to report. |
1587 _error(node, null); | 1592 _error(node, null); |
1588 return null; | 1593 return null; |
1589 } | 1594 } |
1590 break; | 1595 break; |
1591 } | 1596 } |
1592 } | 1597 } |
1593 | 1598 |
1594 @override | 1599 @override |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2288 if (leftOperand != null && rightOperand != null) { | 2293 if (leftOperand != null && rightOperand != null) { |
2289 try { | 2294 try { |
2290 return leftOperand.equalEqual(_typeProvider, rightOperand); | 2295 return leftOperand.equalEqual(_typeProvider, rightOperand); |
2291 } on EvaluationException catch (exception) { | 2296 } on EvaluationException catch (exception) { |
2292 _errorReporter.reportErrorForNode(exception.errorCode, node); | 2297 _errorReporter.reportErrorForNode(exception.errorCode, node); |
2293 } | 2298 } |
2294 } | 2299 } |
2295 return null; | 2300 return null; |
2296 } | 2301 } |
2297 | 2302 |
| 2303 DartObjectImpl questionQuestion(Expression node, DartObjectImpl leftOperand, |
| 2304 DartObjectImpl rightOperand) { |
| 2305 if (leftOperand != null && rightOperand != null) { |
| 2306 if (leftOperand.isNull) return rightOperand; |
| 2307 return leftOperand; |
| 2308 } |
| 2309 return null; |
| 2310 } |
| 2311 |
2298 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand, | 2312 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand, |
2299 DartObjectImpl rightOperand) { | 2313 DartObjectImpl rightOperand) { |
2300 if (leftOperand != null && rightOperand != null) { | 2314 if (leftOperand != null && rightOperand != null) { |
2301 try { | 2315 try { |
2302 return leftOperand.greaterThan(_typeProvider, rightOperand); | 2316 return leftOperand.greaterThan(_typeProvider, rightOperand); |
2303 } on EvaluationException catch (exception) { | 2317 } on EvaluationException catch (exception) { |
2304 _errorReporter.reportErrorForNode(exception.errorCode, node); | 2318 _errorReporter.reportErrorForNode(exception.errorCode, node); |
2305 } | 2319 } |
2306 } | 2320 } |
2307 return null; | 2321 return null; |
(...skipping 3252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5560 return BoolState.from(_element == rightElement); | 5574 return BoolState.from(_element == rightElement); |
5561 } else if (rightOperand is DynamicState) { | 5575 } else if (rightOperand is DynamicState) { |
5562 return BoolState.UNKNOWN_VALUE; | 5576 return BoolState.UNKNOWN_VALUE; |
5563 } | 5577 } |
5564 return BoolState.FALSE_STATE; | 5578 return BoolState.FALSE_STATE; |
5565 } | 5579 } |
5566 | 5580 |
5567 @override | 5581 @override |
5568 String toString() => _element == null ? "-unknown-" : _element.name; | 5582 String toString() => _element == null ? "-unknown-" : _element.name; |
5569 } | 5583 } |
OLD | NEW |