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

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

Issue 1036723002: Move "null2" getter from ConstantVisitor to TypeProvider. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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/lib/src/generated/resolver.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';
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 new HashMap<String, DartObjectImpl>(); 750 new HashMap<String, DartObjectImpl>();
751 HashMap<String, NamedExpression> namedArgumentNodes = 751 HashMap<String, NamedExpression> namedArgumentNodes =
752 new HashMap<String, NamedExpression>(); 752 new HashMap<String, NamedExpression>();
753 for (int i = 0; i < argumentCount; i++) { 753 for (int i = 0; i < argumentCount; i++) {
754 Expression argument = arguments[i]; 754 Expression argument = arguments[i];
755 if (argument is NamedExpression) { 755 if (argument is NamedExpression) {
756 String name = argument.name.label.name; 756 String name = argument.name.label.name;
757 namedArgumentValues[name] = 757 namedArgumentValues[name] =
758 constantVisitor._valueOf(argument.expression); 758 constantVisitor._valueOf(argument.expression);
759 namedArgumentNodes[name] = argument; 759 namedArgumentNodes[name] = argument;
760 argumentValues[i] = constantVisitor.null2; 760 argumentValues[i] = typeProvider.nullObject;
761 } else { 761 } else {
762 argumentValues[i] = constantVisitor._valueOf(argument); 762 argumentValues[i] = constantVisitor._valueOf(argument);
763 argumentNodes[i] = argument; 763 argumentNodes[i] = argument;
764 } 764 }
765 } 765 }
766 constructor = _followConstantRedirectionChain(constructor); 766 constructor = _followConstantRedirectionChain(constructor);
767 InterfaceType definingClass = constructor.returnType as InterfaceType; 767 InterfaceType definingClass = constructor.returnType as InterfaceType;
768 if (constructor.isFactory) { 768 if (constructor.isFactory) {
769 // We couldn't find a non-factory constructor. 769 // We couldn't find a non-factory constructor.
770 // See if it's because we reached an external const factory constructor 770 // See if it's because we reached an external const factory constructor
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 // direct error messages to the constructor call. 861 // direct error messages to the constructor call.
862 errorTarget = node; 862 errorTarget = node;
863 } 863 }
864 if (argumentValue == null && baseParameter is ParameterElementImpl) { 864 if (argumentValue == null && baseParameter is ParameterElementImpl) {
865 // The parameter is an optional positional parameter for which no value 865 // The parameter is an optional positional parameter for which no value
866 // was provided, so use the default value. 866 // was provided, so use the default value.
867 beforeGetParameterDefault(baseParameter); 867 beforeGetParameterDefault(baseParameter);
868 EvaluationResultImpl evaluationResult = baseParameter.evaluationResult; 868 EvaluationResultImpl evaluationResult = baseParameter.evaluationResult;
869 if (evaluationResult == null) { 869 if (evaluationResult == null) {
870 // No default was provided, so the default value is null. 870 // No default was provided, so the default value is null.
871 argumentValue = constantVisitor.null2; 871 argumentValue = typeProvider.nullObject;
872 } else if (evaluationResult.value != null) { 872 } else if (evaluationResult.value != null) {
873 argumentValue = evaluationResult.value; 873 argumentValue = evaluationResult.value;
874 } 874 }
875 } 875 }
876 if (argumentValue != null) { 876 if (argumentValue != null) {
877 if (!_runtimeTypeMatch(argumentValue, parameter.type)) { 877 if (!_runtimeTypeMatch(argumentValue, parameter.type)) {
878 errorReporter.reportErrorForNode( 878 errorReporter.reportErrorForNode(
879 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA TCH, 879 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA TCH,
880 errorTarget, [argumentValue.type, parameter.type]); 880 errorTarget, [argumentValue.type, parameter.type]);
881 } 881 }
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 * <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i> 1158 * <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i>
1159 * evaluates to a boolean value. 1159 * evaluates to a boolean value.
1160 * </blockquote> 1160 * </blockquote>
1161 */ 1161 */
1162 class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> { 1162 class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
1163 /** 1163 /**
1164 * The type provider used to access the known types. 1164 * The type provider used to access the known types.
1165 */ 1165 */
1166 final TypeProvider _typeProvider; 1166 final TypeProvider _typeProvider;
1167 1167
1168 /**
1169 * An shared object representing the value 'null'.
1170 */
1171 DartObjectImpl _nullObject;
1172
1173 HashMap<String, DartObjectImpl> _lexicalEnvironment; 1168 HashMap<String, DartObjectImpl> _lexicalEnvironment;
1174 1169
1175 /** 1170 /**
1176 * Error reporter that we use to report errors accumulated while computing the 1171 * Error reporter that we use to report errors accumulated while computing the
1177 * constant. 1172 * constant.
1178 */ 1173 */
1179 final ErrorReporter _errorReporter; 1174 final ErrorReporter _errorReporter;
1180 1175
1181 /** 1176 /**
1182 * Helper class used to compute constant values. 1177 * Helper class used to compute constant values.
(...skipping 19 matching lines...) Expand all
1202 * found during evaluation. 1197 * found during evaluation.
1203 */ 1198 */
1204 ConstantVisitor.con2(this._typeProvider, 1199 ConstantVisitor.con2(this._typeProvider,
1205 HashMap<String, DartObjectImpl> lexicalEnvironment, this._errorReporter) { 1200 HashMap<String, DartObjectImpl> lexicalEnvironment, this._errorReporter) {
1206 this._lexicalEnvironment = lexicalEnvironment; 1201 this._lexicalEnvironment = lexicalEnvironment;
1207 this._dartObjectComputer = 1202 this._dartObjectComputer =
1208 new DartObjectComputer(_errorReporter, _typeProvider); 1203 new DartObjectComputer(_errorReporter, _typeProvider);
1209 } 1204 }
1210 1205
1211 /** 1206 /**
1212 * Return an object representing the value 'null'.
1213 */
1214 DartObjectImpl get null2 {
1215 if (_nullObject == null) {
1216 _nullObject =
1217 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE);
1218 }
1219 return _nullObject;
1220 }
1221
1222 /**
1223 * This method is called just before retrieving an evaluation result from an 1207 * This method is called just before retrieving an evaluation result from an
1224 * AST node. Unit tests will override it to introduce additional error 1208 * AST node. Unit tests will override it to introduce additional error
1225 * checking. 1209 * checking.
1226 */ 1210 */
1227 void beforeGetEvaluationResult(AstNode node) {} 1211 void beforeGetEvaluationResult(AstNode node) {}
1228 1212
1229 /** 1213 /**
1230 * Return `true` if the given [element] represents the `length` getter in 1214 * Return `true` if the given [element] represents the `length` getter in
1231 * class 'String'. 1215 * class 'String'.
1232 */ 1216 */
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 node.expression.accept(this); 1481 node.expression.accept(this);
1498 1482
1499 @override 1483 @override
1500 DartObjectImpl visitNode(AstNode node) { 1484 DartObjectImpl visitNode(AstNode node) {
1501 // TODO(brianwilkerson) Figure out which error to report. 1485 // TODO(brianwilkerson) Figure out which error to report.
1502 _error(node, null); 1486 _error(node, null);
1503 return null; 1487 return null;
1504 } 1488 }
1505 1489
1506 @override 1490 @override
1507 DartObjectImpl visitNullLiteral(NullLiteral node) => null2; 1491 DartObjectImpl visitNullLiteral(NullLiteral node) => _typeProvider.nullObject;
1508 1492
1509 @override 1493 @override
1510 DartObjectImpl visitParenthesizedExpression(ParenthesizedExpression node) => 1494 DartObjectImpl visitParenthesizedExpression(ParenthesizedExpression node) =>
1511 node.expression.accept(this); 1495 node.expression.accept(this);
1512 1496
1513 @override 1497 @override
1514 DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) { 1498 DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
1515 // String.length 1499 // String.length
1516 { 1500 {
1517 Element element = node.staticElement; 1501 Element element = node.staticElement;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 1654
1671 /** 1655 /**
1672 * Return the value of the given [expression], or a representation of 'null' 1656 * Return the value of the given [expression], or a representation of 'null'
1673 * if the expression cannot be evaluated. 1657 * if the expression cannot be evaluated.
1674 */ 1658 */
1675 DartObjectImpl _valueOf(Expression expression) { 1659 DartObjectImpl _valueOf(Expression expression) {
1676 DartObjectImpl expressionValue = expression.accept(this); 1660 DartObjectImpl expressionValue = expression.accept(this);
1677 if (expressionValue != null) { 1661 if (expressionValue != null) {
1678 return expressionValue; 1662 return expressionValue;
1679 } 1663 }
1680 return null2; 1664 return _typeProvider.nullObject;
1681 } 1665 }
1682 } 1666 }
1683 1667
1684 /** 1668 /**
1685 * The state of a Dart object. 1669 * The state of a Dart object.
1686 */ 1670 */
1687 abstract class DartObject { 1671 abstract class DartObject {
1688 /** 1672 /**
1689 * Return the boolean value of this object, or `null` if either the value of 1673 * Return the boolean value of this object, or `null` if either the value of
1690 * this object is not known or this object is not of type 'bool'. 1674 * this object is not known or this object is not of type 'bool'.
(...skipping 3382 matching lines...) Expand 10 before | Expand all | Expand 10 after
5073 return BoolState.from(_element == rightElement); 5057 return BoolState.from(_element == rightElement);
5074 } else if (rightOperand is DynamicState) { 5058 } else if (rightOperand is DynamicState) {
5075 return BoolState.UNKNOWN_VALUE; 5059 return BoolState.UNKNOWN_VALUE;
5076 } 5060 }
5077 return BoolState.FALSE_STATE; 5061 return BoolState.FALSE_STATE;
5078 } 5062 }
5079 5063
5080 @override 5064 @override
5081 String toString() => _element == null ? "-unknown-" : _element.name; 5065 String toString() => _element == null ? "-unknown-" : _element.name;
5082 } 5066 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698