Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1577293002: Implement (partially) ?? being compile-time constant in analyzer. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/language/language_analyzer2.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 analyzer.src.generated.constant; 5 library analyzer.src.generated.constant;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 } 1609 }
1610 return result; 1610 return result;
1611 } 1611 }
1612 1612
1613 @override 1613 @override
1614 DartObjectImpl visitBinaryExpression(BinaryExpression node) { 1614 DartObjectImpl visitBinaryExpression(BinaryExpression node) {
1615 DartObjectImpl leftResult = node.leftOperand.accept(this); 1615 DartObjectImpl leftResult = node.leftOperand.accept(this);
1616 DartObjectImpl rightResult = node.rightOperand.accept(this); 1616 DartObjectImpl rightResult = node.rightOperand.accept(this);
1617 TokenType operatorType = node.operator.type; 1617 TokenType operatorType = node.operator.type;
1618 // 'null' is almost never good operand 1618 // 'null' is almost never good operand
1619 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) { 1619 if (operatorType != TokenType.BANG_EQ &&
1620 operatorType != TokenType.EQ_EQ &&
1621 operatorType != TokenType.QUESTION_QUESTION) {
1620 if (leftResult != null && leftResult.isNull || 1622 if (leftResult != null && leftResult.isNull ||
1621 rightResult != null && rightResult.isNull) { 1623 rightResult != null && rightResult.isNull) {
1622 _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); 1624 _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
1623 return null; 1625 return null;
1624 } 1626 }
1625 } 1627 }
1626 // evaluate operator 1628 // evaluate operator
1627 while (true) { 1629 while (true) {
1628 if (operatorType == TokenType.AMPERSAND) { 1630 if (operatorType == TokenType.AMPERSAND) {
1629 return _dartObjectComputer.bitAnd(node, leftResult, rightResult); 1631 return _dartObjectComputer.bitAnd(node, leftResult, rightResult);
(...skipping 28 matching lines...) Expand all
1658 } else if (operatorType == TokenType.PERCENT) { 1660 } else if (operatorType == TokenType.PERCENT) {
1659 return _dartObjectComputer.remainder(node, leftResult, rightResult); 1661 return _dartObjectComputer.remainder(node, leftResult, rightResult);
1660 } else if (operatorType == TokenType.PLUS) { 1662 } else if (operatorType == TokenType.PLUS) {
1661 return _dartObjectComputer.add(node, leftResult, rightResult); 1663 return _dartObjectComputer.add(node, leftResult, rightResult);
1662 } else if (operatorType == TokenType.STAR) { 1664 } else if (operatorType == TokenType.STAR) {
1663 return _dartObjectComputer.times(node, leftResult, rightResult); 1665 return _dartObjectComputer.times(node, leftResult, rightResult);
1664 } else if (operatorType == TokenType.SLASH) { 1666 } else if (operatorType == TokenType.SLASH) {
1665 return _dartObjectComputer.divide(node, leftResult, rightResult); 1667 return _dartObjectComputer.divide(node, leftResult, rightResult);
1666 } else if (operatorType == TokenType.TILDE_SLASH) { 1668 } else if (operatorType == TokenType.TILDE_SLASH) {
1667 return _dartObjectComputer.integerDivide(node, leftResult, rightResult); 1669 return _dartObjectComputer.integerDivide(node, leftResult, rightResult);
1670 } else if (operatorType == TokenType.QUESTION_QUESTION) {
1671 return _dartObjectComputer.questionQuestion(
1672 node, leftResult, rightResult);
1668 } else { 1673 } else {
1669 // TODO(brianwilkerson) Figure out which error to report. 1674 // TODO(brianwilkerson) Figure out which error to report.
1670 _error(node, null); 1675 _error(node, null);
1671 return null; 1676 return null;
1672 } 1677 }
1673 break; 1678 break;
1674 } 1679 }
1675 } 1680 }
1676 1681
1677 @override 1682 @override
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
2300 if (leftOperand != null && rightOperand != null) { 2305 if (leftOperand != null && rightOperand != null) {
2301 try { 2306 try {
2302 return leftOperand.equalEqual(_typeProvider, rightOperand); 2307 return leftOperand.equalEqual(_typeProvider, rightOperand);
2303 } on EvaluationException catch (exception) { 2308 } on EvaluationException catch (exception) {
2304 _errorReporter.reportErrorForNode(exception.errorCode, node); 2309 _errorReporter.reportErrorForNode(exception.errorCode, node);
2305 } 2310 }
2306 } 2311 }
2307 return null; 2312 return null;
2308 } 2313 }
2309 2314
2315 DartObjectImpl questionQuestion(Expression node, DartObjectImpl leftOperand,
2316 DartObjectImpl rightOperand) {
2317 if (leftOperand != null && rightOperand != null) {
2318 if (leftOperand.isNull) {
2319 return rightOperand;
2320 }
2321 return leftOperand;
2322 }
2323 return null;
2324 }
2325
2310 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand, 2326 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand,
2311 DartObjectImpl rightOperand) { 2327 DartObjectImpl rightOperand) {
2312 if (leftOperand != null && rightOperand != null) { 2328 if (leftOperand != null && rightOperand != null) {
2313 try { 2329 try {
2314 return leftOperand.greaterThan(_typeProvider, rightOperand); 2330 return leftOperand.greaterThan(_typeProvider, rightOperand);
2315 } on EvaluationException catch (exception) { 2331 } on EvaluationException catch (exception) {
2316 _errorReporter.reportErrorForNode(exception.errorCode, node); 2332 _errorReporter.reportErrorForNode(exception.errorCode, node);
2317 } 2333 }
2318 } 2334 }
2319 return null; 2335 return null;
(...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after
5450 return BoolState.from(_element == rightElement); 5466 return BoolState.from(_element == rightElement);
5451 } else if (rightOperand is DynamicState) { 5467 } else if (rightOperand is DynamicState) {
5452 return BoolState.UNKNOWN_VALUE; 5468 return BoolState.UNKNOWN_VALUE;
5453 } 5469 }
5454 return BoolState.FALSE_STATE; 5470 return BoolState.FALSE_STATE;
5455 } 5471 }
5456 5472
5457 @override 5473 @override
5458 String toString() => _element == null ? "-unknown-" : _element.name; 5474 String toString() => _element == null ? "-unknown-" : _element.name;
5459 } 5475 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698