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(node, leftResult, rightResul t); | |
floitsch
2015/12/02 20:59:26
long line
Lasse Reichstein Nielsen
2015/12/04 12:11:46
Done.
| |
1585 } else { | 1589 } else { |
1586 // TODO(brianwilkerson) Figure out which error to report. | 1590 // TODO(brianwilkerson) Figure out which error to report. |
1587 _error(node, null); | 1591 _error(node, null); |
1588 return null; | 1592 return null; |
1589 } | 1593 } |
1590 break; | 1594 break; |
1591 } | 1595 } |
1592 } | 1596 } |
1593 | 1597 |
1594 @override | 1598 @override |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2288 if (leftOperand != null && rightOperand != null) { | 2292 if (leftOperand != null && rightOperand != null) { |
2289 try { | 2293 try { |
2290 return leftOperand.equalEqual(_typeProvider, rightOperand); | 2294 return leftOperand.equalEqual(_typeProvider, rightOperand); |
2291 } on EvaluationException catch (exception) { | 2295 } on EvaluationException catch (exception) { |
2292 _errorReporter.reportErrorForNode(exception.errorCode, node); | 2296 _errorReporter.reportErrorForNode(exception.errorCode, node); |
2293 } | 2297 } |
2294 } | 2298 } |
2295 return null; | 2299 return null; |
2296 } | 2300 } |
2297 | 2301 |
2302 DartObjectImpl questionQuestion(Expression node, DartObjectImpl leftOperand, | |
2303 DartObjectImpl rightOperand) { | |
2304 if (leftOperand != null && rightOperand != null) { | |
2305 if (leftOperand.isNull) return rightOperand; | |
2306 return leftOperand; | |
2307 } | |
2308 return null; | |
2309 } | |
2310 | |
2298 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand, | 2311 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand, |
2299 DartObjectImpl rightOperand) { | 2312 DartObjectImpl rightOperand) { |
2300 if (leftOperand != null && rightOperand != null) { | 2313 if (leftOperand != null && rightOperand != null) { |
2301 try { | 2314 try { |
2302 return leftOperand.greaterThan(_typeProvider, rightOperand); | 2315 return leftOperand.greaterThan(_typeProvider, rightOperand); |
2303 } on EvaluationException catch (exception) { | 2316 } on EvaluationException catch (exception) { |
2304 _errorReporter.reportErrorForNode(exception.errorCode, node); | 2317 _errorReporter.reportErrorForNode(exception.errorCode, node); |
2305 } | 2318 } |
2306 } | 2319 } |
2307 return null; | 2320 return null; |
(...skipping 3252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5560 return BoolState.from(_element == rightElement); | 5573 return BoolState.from(_element == rightElement); |
5561 } else if (rightOperand is DynamicState) { | 5574 } else if (rightOperand is DynamicState) { |
5562 return BoolState.UNKNOWN_VALUE; | 5575 return BoolState.UNKNOWN_VALUE; |
5563 } | 5576 } |
5564 return BoolState.FALSE_STATE; | 5577 return BoolState.FALSE_STATE; |
5565 } | 5578 } |
5566 | 5579 |
5567 @override | 5580 @override |
5568 String toString() => _element == null ? "-unknown-" : _element.name; | 5581 String toString() => _element == null ? "-unknown-" : _element.name; |
5569 } | 5582 } |
OLD | NEW |