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

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

Issue 940853002: Issue 22409. Restore recognizing string concatenation in const expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.constant; 8 library engine.constant;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
11 11
12 import 'package:analyzer/src/generated/utilities_general.dart';
13
12 import 'ast.dart'; 14 import 'ast.dart';
13 import 'element.dart'; 15 import 'element.dart';
14 import 'engine.dart' show AnalysisEngine, RecordingErrorListener; 16 import 'engine.dart' show AnalysisEngine, RecordingErrorListener;
15 import 'error.dart'; 17 import 'error.dart';
16 import 'java_core.dart'; 18 import 'java_core.dart';
17 import 'resolver.dart' show TypeProvider; 19 import 'resolver.dart' show TypeProvider;
18 import 'scanner.dart' show Token, TokenType; 20 import 'scanner.dart' show Token, TokenType;
19 import 'source.dart' show Source; 21 import 'source.dart' show Source;
20 import 'utilities_collection.dart'; 22 import 'utilities_collection.dart';
21 import 'utilities_dart.dart' show ParameterKind; 23 import 'utilities_dart.dart' show ParameterKind;
22 import 'package:analyzer/src/generated/utilities_general.dart';
23 24
24 /** 25 /**
25 * Instances of the class `BoolState` represent the state of an object represent ing a boolean 26 * Instances of the class `BoolState` represent the state of an object represent ing a boolean
26 * value. 27 * value.
27 */ 28 */
28 class BoolState extends InstanceState { 29 class BoolState extends InstanceState {
29 /** 30 /**
30 * An instance representing the boolean value 'false'. 31 * An instance representing the boolean value 'false'.
31 */ 32 */
32 static BoolState FALSE_STATE = new BoolState(false); 33 static BoolState FALSE_STATE = new BoolState(false);
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 return _nullObject; 1259 return _nullObject;
1259 } 1260 }
1260 1261
1261 /** 1262 /**
1262 * This method is called just before retrieving an evaluation result from an A ST node. Unit tests 1263 * This method is called just before retrieving an evaluation result from an A ST node. Unit tests
1263 * will override it to introduce additional error checking. 1264 * will override it to introduce additional error checking.
1264 */ 1265 */
1265 void beforeGetEvaluationResult(AstNode node) { 1266 void beforeGetEvaluationResult(AstNode node) {
1266 } 1267 }
1267 1268
1269 /**
1270 * Return `true` if the given [element] represents the `length` getter in
1271 * class [String].
1272 */
1273 bool isStringLength(Element element) {
1274 if (element is PropertyAccessorElement) {
1275 if (element.isGetter && element.name == 'length') {
1276 return element.enclosingElement == _typeProvider.stringType.element;
1277 }
1278 }
1279 return false;
1280 }
1281
1268 @override 1282 @override
1269 DartObjectImpl visitAdjacentStrings(AdjacentStrings node) { 1283 DartObjectImpl visitAdjacentStrings(AdjacentStrings node) {
1270 DartObjectImpl result = null; 1284 DartObjectImpl result = null;
1271 for (StringLiteral string in node.strings) { 1285 for (StringLiteral string in node.strings) {
1272 if (result == null) { 1286 if (result == null) {
1273 result = string.accept(this); 1287 result = string.accept(this);
1274 } else { 1288 } else {
1275 result = 1289 result =
1276 _dartObjectComputer.concatenate(node, result, string.accept(this)); 1290 _dartObjectComputer.concatenate(node, result, string.accept(this));
1277 } 1291 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1554
1541 @override 1555 @override
1542 DartObjectImpl visitNullLiteral(NullLiteral node) => null2; 1556 DartObjectImpl visitNullLiteral(NullLiteral node) => null2;
1543 1557
1544 @override 1558 @override
1545 DartObjectImpl visitParenthesizedExpression(ParenthesizedExpression node) => 1559 DartObjectImpl visitParenthesizedExpression(ParenthesizedExpression node) =>
1546 node.expression.accept(this); 1560 node.expression.accept(this);
1547 1561
1548 @override 1562 @override
1549 DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) { 1563 DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
1550 // TODO(brianwilkerson) Uncomment the lines below when the new constant 1564 // String.length
1551 // support can be added. 1565 {
1552 // Element element = node.getStaticElement(); 1566 Element element = node.staticElement;
1553 // if (isStringLength(element)) { 1567 if (isStringLength(element)) {
1554 // EvaluationResultImpl target = node.getPrefix().accept(this); 1568 DartObjectImpl prefixResult = node.prefix.accept(this);
1555 // return target.stringLength(typeProvider, node); 1569 return prefixResult.stringLength(_typeProvider);
1556 // } 1570 }
1571 }
1572 // importPrefix.CONST
1557 SimpleIdentifier prefixNode = node.prefix; 1573 SimpleIdentifier prefixNode = node.prefix;
1558 Element prefixElement = prefixNode.staticElement; 1574 Element prefixElement = prefixNode.staticElement;
1559 if (prefixElement is! PrefixElement) { 1575 if (prefixElement is! PrefixElement) {
1560 DartObjectImpl prefixResult = prefixNode.accept(this); 1576 DartObjectImpl prefixResult = prefixNode.accept(this);
1561 if (prefixResult == null) { 1577 if (prefixResult == null) {
1562 // The error has already been reported. 1578 // The error has already been reported.
1563 return null; 1579 return null;
1564 } 1580 }
1565 } 1581 }
1566 // validate prefixed identifier 1582 // validate prefixed identifier
(...skipping 19 matching lines...) Expand all
1586 _error(node, null); 1602 _error(node, null);
1587 return null; 1603 return null;
1588 } 1604 }
1589 break; 1605 break;
1590 } 1606 }
1591 } 1607 }
1592 1608
1593 @override 1609 @override
1594 DartObjectImpl visitPropertyAccess(PropertyAccess node) { 1610 DartObjectImpl visitPropertyAccess(PropertyAccess node) {
1595 Element element = node.propertyName.staticElement; 1611 Element element = node.propertyName.staticElement;
1596 // TODO(brianwilkerson) Uncomment the lines below when the new constant 1612 if (isStringLength(element)) {
1597 // support can be added. 1613 DartObjectImpl prefixResult = node.realTarget.accept(this);
1598 // if (isStringLength(element)) { 1614 return prefixResult.stringLength(_typeProvider);
1599 // EvaluationResultImpl target = node.getRealTarget().accept(this); 1615 }
1600 // return target.stringLength(typeProvider, node);
1601 // }
1602 return _getConstantValue(node, element); 1616 return _getConstantValue(node, element);
1603 } 1617 }
1604 1618
1605 @override 1619 @override
1606 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { 1620 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) {
1607 if (_lexicalEnvironment != null && 1621 if (_lexicalEnvironment != null &&
1608 _lexicalEnvironment.containsKey(node.name)) { 1622 _lexicalEnvironment.containsKey(node.name)) {
1609 return _lexicalEnvironment[node.name]; 1623 return _lexicalEnvironment[node.name];
1610 } 1624 }
1611 return _getConstantValue(node, node.staticElement); 1625 return _getConstantValue(node, node.staticElement);
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
3590 bool first = true; 3604 bool first = true;
3591 for (String fieldName in fieldNames) { 3605 for (String fieldName in fieldNames) {
3592 if (first) { 3606 if (first) {
3593 first = false; 3607 first = false;
3594 } else { 3608 } else {
3595 buffer.write('; '); 3609 buffer.write('; ');
3596 } 3610 }
3597 buffer.write(fieldName); 3611 buffer.write(fieldName);
3598 buffer.write(' = '); 3612 buffer.write(' = ');
3599 buffer.write(_fieldMap[fieldName]); 3613 buffer.write(_fieldMap[fieldName]);
3600 }; 3614 }
3601 return buffer.toString(); 3615 return buffer.toString();
3602 } 3616 }
3603 } 3617 }
3604 3618
3605 /** 3619 /**
3606 * The class `InstanceState` defines the behavior of objects representing the st ate of a Dart 3620 * The class `InstanceState` defines the behavior of objects representing the st ate of a Dart
3607 * object. 3621 * object.
3608 */ 3622 */
3609 abstract class InstanceState { 3623 abstract class InstanceState {
3610 /** 3624 /**
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 Object get value => null; 3671 Object get value => null;
3658 3672
3659 /** 3673 /**
3660 * Return the result of invoking the '+' operator on this object with the give n argument. 3674 * Return the result of invoking the '+' operator on this object with the give n argument.
3661 * 3675 *
3662 * @param rightOperand the right-hand operand of the operation 3676 * @param rightOperand the right-hand operand of the operation
3663 * @return the result of invoking the '+' operator on this object with the giv en argument 3677 * @return the result of invoking the '+' operator on this object with the giv en argument
3664 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 3678 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3665 */ 3679 */
3666 InstanceState add(InstanceState rightOperand) { 3680 InstanceState add(InstanceState rightOperand) {
3667 // TODO(brianwilkerson) Uncomment the code below when the new constant 3681 if (this is StringState && rightOperand is StringState) {
3668 // support can be added. 3682 return concatenate(rightOperand);
3669 // if (this instanceof StringState || rightOperand instanceof StringState) { 3683 }
3670 // return concatenate(rightOperand);
3671 // }
3672 assertNumOrNull(this); 3684 assertNumOrNull(this);
3673 assertNumOrNull(rightOperand); 3685 assertNumOrNull(rightOperand);
3674 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT); 3686 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT);
3675 } 3687 }
3676 3688
3677 /** 3689 /**
3678 * Throw an exception if the given state does not represent a boolean value. 3690 * Throw an exception if the given state does not represent a boolean value.
3679 * 3691 *
3680 * @param state the state being tested 3692 * @param state the state being tested
3681 * @throws EvaluationException if the given state does not represent a boolean value 3693 * @throws EvaluationException if the given state does not represent a boolean value
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
5241 return BoolState.from(_element == rightElement); 5253 return BoolState.from(_element == rightElement);
5242 } else if (rightOperand is DynamicState) { 5254 } else if (rightOperand is DynamicState) {
5243 return BoolState.UNKNOWN_VALUE; 5255 return BoolState.UNKNOWN_VALUE;
5244 } 5256 }
5245 return BoolState.FALSE_STATE; 5257 return BoolState.FALSE_STATE;
5246 } 5258 }
5247 5259
5248 @override 5260 @override
5249 String toString() => _element == null ? "-unknown-" : _element.name; 5261 String toString() => _element == null ? "-unknown-" : _element.name;
5250 } 5262 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698