| 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.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 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 @override | 905 @override |
| 906 Object visitFunctionExpression(FunctionExpression node) { | 906 Object visitFunctionExpression(FunctionExpression node) { |
| 907 super.visitFunctionExpression(node); | 907 super.visitFunctionExpression(node); |
| 908 _validateDefaultValues(node.parameters); | 908 _validateDefaultValues(node.parameters); |
| 909 return null; | 909 return null; |
| 910 } | 910 } |
| 911 | 911 |
| 912 @override | 912 @override |
| 913 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 913 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 914 if (node.isConst) { | 914 if (node.isConst) { |
| 915 EvaluationResultImpl evaluationResult = node.evaluationResult; | 915 // We need to evaluate the constant to see if any errors occur during its |
| 916 // Note: evaluationResult might be null if there are circular references | 916 // evaluation. |
| 917 // among constants. | 917 ConstructorElement constructor = node.staticElement; |
| 918 if (evaluationResult != null) { | 918 if (constructor != null) { |
| 919 _reportErrors(evaluationResult.errors, null); | 919 ConstantEvaluationEngine evaluationEngine = |
| 920 new ConstantEvaluationEngine(_typeProvider, declaredVariables); |
| 921 ConstantVisitor constantVisitor = |
| 922 new ConstantVisitor(evaluationEngine, _errorReporter); |
| 923 evaluationEngine.evaluateConstructorCall(node, |
| 924 node.argumentList.arguments, constructor, constantVisitor, |
| 925 _errorReporter); |
| 920 } | 926 } |
| 921 } | 927 } |
| 922 _validateInstanceCreationArguments(node); | 928 _validateInstanceCreationArguments(node); |
| 923 return super.visitInstanceCreationExpression(node); | 929 return super.visitInstanceCreationExpression(node); |
| 924 } | 930 } |
| 925 | 931 |
| 926 @override | 932 @override |
| 927 Object visitListLiteral(ListLiteral node) { | 933 Object visitListLiteral(ListLiteral node) { |
| 928 super.visitListLiteral(node); | 934 super.visitListLiteral(node); |
| 929 if (node.constKeyword != null) { | 935 if (node.constKeyword != null) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 if (!foundError) { | 1051 if (!foundError) { |
| 1046 _checkForCaseExpressionTypeImplementsEquals(node, firstType); | 1052 _checkForCaseExpressionTypeImplementsEquals(node, firstType); |
| 1047 } | 1053 } |
| 1048 return super.visitSwitchStatement(node); | 1054 return super.visitSwitchStatement(node); |
| 1049 } | 1055 } |
| 1050 | 1056 |
| 1051 @override | 1057 @override |
| 1052 Object visitVariableDeclaration(VariableDeclaration node) { | 1058 Object visitVariableDeclaration(VariableDeclaration node) { |
| 1053 super.visitVariableDeclaration(node); | 1059 super.visitVariableDeclaration(node); |
| 1054 Expression initializer = node.initializer; | 1060 Expression initializer = node.initializer; |
| 1055 if (initializer != null && node.isConst) { | 1061 if (initializer != null && (node.isConst || node.isFinal)) { |
| 1056 VariableElementImpl element = node.element as VariableElementImpl; | 1062 VariableElementImpl element = node.element as VariableElementImpl; |
| 1057 EvaluationResultImpl result = element.evaluationResult; | 1063 EvaluationResultImpl result = element.evaluationResult; |
| 1058 if (result == null) { | 1064 if (result == null) { |
| 1059 // | 1065 // Variables marked "const" should have had their values computed by |
| 1060 // Normally we don't need to visit const variable declarations because | 1066 // ConstantValueComputer. Other variables will only have had their |
| 1061 // we have already computed their values. But if we missed it for some | 1067 // values computed if the value was needed (e.g. final variables in a |
| 1062 // reason, this gives us a second chance. | 1068 // class containing const constructors). |
| 1063 // | 1069 assert(!node.isConst); |
| 1064 result = new EvaluationResultImpl.con1(_validate(initializer, | |
| 1065 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE)); | |
| 1066 element.evaluationResult = result; | |
| 1067 return null; | 1070 return null; |
| 1068 } | 1071 } |
| 1069 _reportErrors(result.errors, | 1072 _reportErrors(result.errors, |
| 1070 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); | 1073 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); |
| 1071 _reportErrorIfFromDeferredLibrary(initializer, | 1074 _reportErrorIfFromDeferredLibrary(initializer, |
| 1072 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DE
FERRED_LIBRARY); | 1075 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DE
FERRED_LIBRARY); |
| 1073 } | 1076 } |
| 1074 return null; | 1077 return null; |
| 1075 } | 1078 } |
| 1076 | 1079 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 ErrorCode dataErrorCode = data.errorCode; | 1155 ErrorCode dataErrorCode = data.errorCode; |
| 1153 if (identical(dataErrorCode, | 1156 if (identical(dataErrorCode, |
| 1154 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) || | 1157 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) || |
| 1155 identical( | 1158 identical( |
| 1156 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || | 1159 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || |
| 1157 identical(dataErrorCode, | 1160 identical(dataErrorCode, |
| 1158 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || | 1161 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || |
| 1159 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || | 1162 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || |
| 1160 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || | 1163 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || |
| 1161 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || | 1164 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || |
| 1165 identical(dataErrorCode, CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_C
ONSTANT) || |
| 1162 identical(dataErrorCode, | 1166 identical(dataErrorCode, |
| 1163 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA
TCH) || | 1167 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMA
TCH) || |
| 1164 identical(dataErrorCode, | 1168 identical(dataErrorCode, |
| 1165 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA
TCH) || | 1169 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA
TCH) || |
| 1166 identical(dataErrorCode, | 1170 identical(dataErrorCode, |
| 1167 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH)) { | 1171 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH)) { |
| 1168 _errorReporter.reportError(data); | 1172 _errorReporter.reportError(data); |
| 1169 } else if (errorCode != null) { | 1173 } else if (errorCode != null) { |
| 1170 _errorReporter.reportError(new AnalysisError.con2( | 1174 _errorReporter.reportError(new AnalysisError.con2( |
| 1171 data.source, data.offset, data.length, errorCode)); | 1175 data.source, data.offset, data.length, errorCode)); |
| (...skipping 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2855 //of this parameter. | 2859 //of this parameter. |
| 2856 // | 2860 // |
| 2857 ElementHolder holder = new ElementHolder(); | 2861 ElementHolder holder = new ElementHolder(); |
| 2858 _visitChildren(holder, node); | 2862 _visitChildren(holder, node); |
| 2859 (node.element as ParameterElementImpl).parameters = holder.parameters; | 2863 (node.element as ParameterElementImpl).parameters = holder.parameters; |
| 2860 holder.validate(); | 2864 holder.validate(); |
| 2861 return null; | 2865 return null; |
| 2862 } | 2866 } |
| 2863 | 2867 |
| 2864 @override | 2868 @override |
| 2865 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 2866 if (node.isConst) { | |
| 2867 node.constantHandle = new ConstantInstanceCreationHandle(); | |
| 2868 } | |
| 2869 return super.visitInstanceCreationExpression(node); | |
| 2870 } | |
| 2871 | |
| 2872 @override | |
| 2873 Object visitLabeledStatement(LabeledStatement node) { | 2869 Object visitLabeledStatement(LabeledStatement node) { |
| 2874 bool onSwitchStatement = node.statement is SwitchStatement; | 2870 bool onSwitchStatement = node.statement is SwitchStatement; |
| 2875 for (Label label in node.labels) { | 2871 for (Label label in node.labels) { |
| 2876 SimpleIdentifier labelName = label.label; | 2872 SimpleIdentifier labelName = label.label; |
| 2877 LabelElementImpl element = | 2873 LabelElementImpl element = |
| 2878 new LabelElementImpl(labelName, onSwitchStatement, false); | 2874 new LabelElementImpl(labelName, onSwitchStatement, false); |
| 2879 _currentHolder.addLabel(element); | 2875 _currentHolder.addLabel(element); |
| 2880 labelName.staticElement = element; | 2876 labelName.staticElement = element; |
| 2881 } | 2877 } |
| 2882 return super.visitLabeledStatement(node); | 2878 return super.visitLabeledStatement(node); |
| (...skipping 12555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15438 nonFields.add(node); | 15434 nonFields.add(node); |
| 15439 return null; | 15435 return null; |
| 15440 } | 15436 } |
| 15441 | 15437 |
| 15442 @override | 15438 @override |
| 15443 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15439 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15444 | 15440 |
| 15445 @override | 15441 @override |
| 15446 Object visitWithClause(WithClause node) => null; | 15442 Object visitWithClause(WithClause node) => null; |
| 15447 } | 15443 } |
| OLD | NEW |