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

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

Issue 1121313004: Move validation logic for constant evaluation into its own class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
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 engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ UALS, 968 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ UALS,
969 key, [type.displayName]); 969 key, [type.displayName]);
970 } 970 }
971 } 971 }
972 } else { 972 } else {
973 // Note: we throw the errors away because this isn't actually a const. 973 // Note: we throw the errors away because this isn't actually a const.
974 AnalysisErrorListener errorListener = 974 AnalysisErrorListener errorListener =
975 AnalysisErrorListener.NULL_LISTENER; 975 AnalysisErrorListener.NULL_LISTENER;
976 ErrorReporter subErrorReporter = 976 ErrorReporter subErrorReporter =
977 new ErrorReporter(errorListener, _errorReporter.source); 977 new ErrorReporter(errorListener, _errorReporter.source);
978 DartObjectImpl result = key 978 DartObjectImpl result =
979 .accept(new ConstantVisitor.con1(_typeProvider, subErrorReporter)); 979 key.accept(new ConstantVisitor(_typeProvider, subErrorReporter));
980 if (result != null) { 980 if (result != null) {
981 if (keys.contains(result)) { 981 if (keys.contains(result)) {
982 invalidKeys.add(key); 982 invalidKeys.add(key);
983 } else { 983 } else {
984 keys.add(result); 984 keys.add(result);
985 } 985 }
986 } else { 986 } else {
987 reportEqualKeys = false; 987 reportEqualKeys = false;
988 } 988 }
989 } 989 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 * time constant, or `null` if the expression is not a compile time constant. 1172 * time constant, or `null` if the expression is not a compile time constant.
1173 * 1173 *
1174 * @param expression the expression to be validated 1174 * @param expression the expression to be validated
1175 * @param errorCode the error code to be used if the expression is not a compi le time constant 1175 * @param errorCode the error code to be used if the expression is not a compi le time constant
1176 * @return the value of the compile time constant 1176 * @return the value of the compile time constant
1177 */ 1177 */
1178 DartObjectImpl _validate(Expression expression, ErrorCode errorCode) { 1178 DartObjectImpl _validate(Expression expression, ErrorCode errorCode) {
1179 RecordingErrorListener errorListener = new RecordingErrorListener(); 1179 RecordingErrorListener errorListener = new RecordingErrorListener();
1180 ErrorReporter subErrorReporter = 1180 ErrorReporter subErrorReporter =
1181 new ErrorReporter(errorListener, _errorReporter.source); 1181 new ErrorReporter(errorListener, _errorReporter.source);
1182 DartObjectImpl result = expression 1182 DartObjectImpl result =
1183 .accept(new ConstantVisitor.con1(_typeProvider, subErrorReporter)); 1183 expression.accept(new ConstantVisitor(_typeProvider, subErrorReporter));
1184 _reportErrors(errorListener.errors, errorCode); 1184 _reportErrors(errorListener.errors, errorCode);
1185 return result; 1185 return result;
1186 } 1186 }
1187 1187
1188 /** 1188 /**
1189 * Validate that if the passed arguments are constant expressions. 1189 * Validate that if the passed arguments are constant expressions.
1190 * 1190 *
1191 * @param argumentList the argument list to evaluate 1191 * @param argumentList the argument list to evaluate
1192 */ 1192 */
1193 void _validateConstantArguments(ArgumentList argumentList) { 1193 void _validateConstantArguments(ArgumentList argumentList) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 for (VariableDeclaration variableDeclaration 1279 for (VariableDeclaration variableDeclaration
1280 in fieldDeclaration.fields.variables) { 1280 in fieldDeclaration.fields.variables) {
1281 Expression initializer = variableDeclaration.initializer; 1281 Expression initializer = variableDeclaration.initializer;
1282 if (initializer != null) { 1282 if (initializer != null) {
1283 // Ignore any errors produced during validation--if the constant 1283 // Ignore any errors produced during validation--if the constant
1284 // can't be eavluated we'll just report a single error. 1284 // can't be eavluated we'll just report a single error.
1285 AnalysisErrorListener errorListener = 1285 AnalysisErrorListener errorListener =
1286 AnalysisErrorListener.NULL_LISTENER; 1286 AnalysisErrorListener.NULL_LISTENER;
1287 ErrorReporter subErrorReporter = 1287 ErrorReporter subErrorReporter =
1288 new ErrorReporter(errorListener, _errorReporter.source); 1288 new ErrorReporter(errorListener, _errorReporter.source);
1289 DartObjectImpl result = initializer.accept( 1289 DartObjectImpl result = initializer
1290 new ConstantVisitor.con1(_typeProvider, subErrorReporter)); 1290 .accept(new ConstantVisitor(_typeProvider, subErrorReporter));
1291 if (result == null) { 1291 if (result == null) {
1292 _errorReporter.reportErrorForNode( 1292 _errorReporter.reportErrorForNode(
1293 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE D_BY_NON_CONST, 1293 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE D_BY_NON_CONST,
1294 errorSite, [variableDeclaration.name.name]); 1294 errorSite, [variableDeclaration.name.name]);
1295 } 1295 }
1296 } 1296 }
1297 } 1297 }
1298 } 1298 }
1299 } 1299 }
1300 } 1300 }
(...skipping 13968 matching lines...) Expand 10 before | Expand all | Expand 10 after
15269 } 15269 }
15270 } 15270 }
15271 15271
15272 class _ConstantVerifier_validateInitializerExpression extends ConstantVisitor { 15272 class _ConstantVerifier_validateInitializerExpression extends ConstantVisitor {
15273 final ConstantVerifier verifier; 15273 final ConstantVerifier verifier;
15274 15274
15275 List<ParameterElement> parameterElements; 15275 List<ParameterElement> parameterElements;
15276 15276
15277 _ConstantVerifier_validateInitializerExpression(TypeProvider arg0, 15277 _ConstantVerifier_validateInitializerExpression(TypeProvider arg0,
15278 ErrorReporter arg1, this.verifier, this.parameterElements) 15278 ErrorReporter arg1, this.verifier, this.parameterElements)
15279 : super.con1(arg0, arg1); 15279 : super(arg0, arg1);
15280 15280
15281 @override 15281 @override
15282 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { 15282 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) {
15283 Element element = node.staticElement; 15283 Element element = node.staticElement;
15284 for (ParameterElement parameterElement in parameterElements) { 15284 for (ParameterElement parameterElement in parameterElements) {
15285 if (identical(parameterElement, element) && parameterElement != null) { 15285 if (identical(parameterElement, element) && parameterElement != null) {
15286 DartType type = parameterElement.type; 15286 DartType type = parameterElement.type;
15287 if (type != null) { 15287 if (type != null) {
15288 if (type.isDynamic) { 15288 if (type.isDynamic) {
15289 return new DartObjectImpl( 15289 return new DartObjectImpl(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
15426 nonFields.add(node); 15426 nonFields.add(node);
15427 return null; 15427 return null;
15428 } 15428 }
15429 15429
15430 @override 15430 @override
15431 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15431 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15432 15432
15433 @override 15433 @override
15434 Object visitWithClause(WithClause node) => null; 15434 Object visitWithClause(WithClause node) => null;
15435 } 15435 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698