| 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 // 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 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // [ErrorVerifier.checkForRecursiveFactoryRedirect()]). | 828 // [ErrorVerifier.checkForRecursiveFactoryRedirect()]). |
| 829 break; | 829 break; |
| 830 } | 830 } |
| 831 } | 831 } |
| 832 constructor = redirectedConstructor; | 832 constructor = redirectedConstructor; |
| 833 } | 833 } |
| 834 return constructor; | 834 return constructor; |
| 835 } | 835 } |
| 836 | 836 |
| 837 /** | 837 /** |
| 838 * Generate an error indicating that the given [constant] is not a valid |
| 839 * compile-time constant because it references at least one of the constants |
| 840 * in the given [cycle], each of which directly or indirectly references the |
| 841 * constant. |
| 842 */ |
| 843 void generateCycleError(Iterable<ConstantEvaluationTarget> cycle, |
| 844 ConstantEvaluationTarget constant) { |
| 845 if (constant is VariableElement) { |
| 846 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 847 ErrorReporter errorReporter = |
| 848 new ErrorReporter(errorListener, constant.source); |
| 849 // TODO(paulberry): It would be really nice if we could extract enough |
| 850 // information from the 'cycle' argument to provide the user with a |
| 851 // description of the cycle. |
| 852 errorReporter.reportErrorForElement( |
| 853 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, constant, []); |
| 854 (constant as VariableElementImpl).evaluationResult = |
| 855 new EvaluationResultImpl(null, errorListener.errors); |
| 856 } else if (constant is ConstructorElement) { |
| 857 // We don't report cycle errors on constructor declarations since there |
| 858 // is nowhere to put the error information. |
| 859 } else { |
| 860 // Should not happen. Formal parameter defaults and annotations should |
| 861 // never appear as part of a cycle because they can't be referred to. |
| 862 assert(false); |
| 863 AnalysisEngine.instance.logger.logError( |
| 864 "Constant value computer trying to report a cycle error for a node of
type ${constant.runtimeType}"); |
| 865 } |
| 866 } |
| 867 |
| 868 /** |
| 838 * If [constructor] redirects to another const constructor, return the | 869 * If [constructor] redirects to another const constructor, return the |
| 839 * const constructor it redirects to. Otherwise return `null`. | 870 * const constructor it redirects to. Otherwise return `null`. |
| 840 */ | 871 */ |
| 841 ConstructorElement getConstRedirectedConstructor( | 872 ConstructorElement getConstRedirectedConstructor( |
| 842 ConstructorElement constructor) { | 873 ConstructorElement constructor) { |
| 843 if (!constructor.isFactory) { | 874 if (!constructor.isFactory) { |
| 844 return null; | 875 return null; |
| 845 } | 876 } |
| 846 if (identical(constructor.enclosingElement.type, typeProvider.symbolType)) { | 877 if (identical(constructor.enclosingElement.type, typeProvider.symbolType)) { |
| 847 // The dart:core.Symbol has a const factory constructor that redirects | 878 // The dart:core.Symbol has a const factory constructor that redirects |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 referenceGraph.addEdge(constant, dependency); | 1269 referenceGraph.addEdge(constant, dependency); |
| 1239 }); | 1270 }); |
| 1240 } | 1271 } |
| 1241 List<List<ConstantEvaluationTarget>> topologicalSort = | 1272 List<List<ConstantEvaluationTarget>> topologicalSort = |
| 1242 referenceGraph.computeTopologicalSort(); | 1273 referenceGraph.computeTopologicalSort(); |
| 1243 for (List<ConstantEvaluationTarget> constantsInCycle in topologicalSort) { | 1274 for (List<ConstantEvaluationTarget> constantsInCycle in topologicalSort) { |
| 1244 if (constantsInCycle.length == 1) { | 1275 if (constantsInCycle.length == 1) { |
| 1245 _computeValueFor(constantsInCycle[0]); | 1276 _computeValueFor(constantsInCycle[0]); |
| 1246 } else { | 1277 } else { |
| 1247 for (ConstantEvaluationTarget constant in constantsInCycle) { | 1278 for (ConstantEvaluationTarget constant in constantsInCycle) { |
| 1248 _generateCycleError(constantsInCycle, constant); | 1279 evaluationEngine.generateCycleError(constantsInCycle, constant); |
| 1249 } | 1280 } |
| 1250 } | 1281 } |
| 1251 } | 1282 } |
| 1252 } | 1283 } |
| 1253 | 1284 |
| 1254 /** | 1285 /** |
| 1255 * Compute a value for the given [constant]. | 1286 * Compute a value for the given [constant]. |
| 1256 */ | 1287 */ |
| 1257 void _computeValueFor(ConstantEvaluationTarget constant) { | 1288 void _computeValueFor(ConstantEvaluationTarget constant) { |
| 1258 if (!_constantsToCompute.contains(constant)) { | 1289 if (!_constantsToCompute.contains(constant)) { |
| 1259 // Element is in the dependency graph but should have been computed by | 1290 // Element is in the dependency graph but should have been computed by |
| 1260 // a previous stage of analysis. | 1291 // a previous stage of analysis. |
| 1261 // TODO(paulberry): once we have moved over to the new task model, this | 1292 // TODO(paulberry): once we have moved over to the new task model, this |
| 1262 // should only occur for constants associated with enum members. Once | 1293 // should only occur for constants associated with enum members. Once |
| 1263 // that happens we should add an assertion to verify that it doesn't | 1294 // that happens we should add an assertion to verify that it doesn't |
| 1264 // occur in any other cases. | 1295 // occur in any other cases. |
| 1265 return; | 1296 return; |
| 1266 } | 1297 } |
| 1267 evaluationEngine.computeConstantValue(constant); | 1298 evaluationEngine.computeConstantValue(constant); |
| 1268 } | 1299 } |
| 1269 | |
| 1270 /** | |
| 1271 * Generate an error indicating that the given [constant] is not a valid | |
| 1272 * compile-time constant because it references at least one of the constants | |
| 1273 * in the given [cycle], each of which directly or indirectly references the | |
| 1274 * constant. | |
| 1275 */ | |
| 1276 void _generateCycleError( | |
| 1277 List<ConstantEvaluationTarget> cycle, ConstantEvaluationTarget constant) { | |
| 1278 if (constant is VariableElement) { | |
| 1279 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 1280 ErrorReporter errorReporter = | |
| 1281 new ErrorReporter(errorListener, constant.source); | |
| 1282 // TODO(paulberry): It would be really nice if we could extract enough | |
| 1283 // information from the 'cycle' argument to provide the user with a | |
| 1284 // description of the cycle. | |
| 1285 errorReporter.reportErrorForElement( | |
| 1286 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, constant, []); | |
| 1287 (constant as VariableElementImpl).evaluationResult = | |
| 1288 new EvaluationResultImpl(null, errorListener.errors); | |
| 1289 } else if (constant is ConstructorElement) { | |
| 1290 // We don't report cycle errors on constructor declarations since there | |
| 1291 // is nowhere to put the error information. | |
| 1292 } else { | |
| 1293 // Should not happen. Formal parameter defaults and annotations should | |
| 1294 // never appear as part of a cycle because they can't be referred to. | |
| 1295 assert(false); | |
| 1296 AnalysisEngine.instance.logger.logError( | |
| 1297 "Constant value computer trying to report a cycle error for a node of
type ${constant.runtimeType}"); | |
| 1298 } | |
| 1299 } | |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 /** | 1302 /** |
| 1303 * A visitor used to evaluate constant expressions to produce their compile-time | 1303 * A visitor used to evaluate constant expressions to produce their compile-time |
| 1304 * value. According to the Dart Language Specification: <blockquote> A constant | 1304 * value. According to the Dart Language Specification: <blockquote> A constant |
| 1305 * expression is one of the following: | 1305 * expression is one of the following: |
| 1306 * | 1306 * |
| 1307 * * A literal number. | 1307 * * A literal number. |
| 1308 * * A literal boolean. | 1308 * * A literal boolean. |
| 1309 * * A literal string where any interpolated expression is a compile-time | 1309 * * A literal string where any interpolated expression is a compile-time |
| (...skipping 3905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5215 return BoolState.from(_element == rightElement); | 5215 return BoolState.from(_element == rightElement); |
| 5216 } else if (rightOperand is DynamicState) { | 5216 } else if (rightOperand is DynamicState) { |
| 5217 return BoolState.UNKNOWN_VALUE; | 5217 return BoolState.UNKNOWN_VALUE; |
| 5218 } | 5218 } |
| 5219 return BoolState.FALSE_STATE; | 5219 return BoolState.FALSE_STATE; |
| 5220 } | 5220 } |
| 5221 | 5221 |
| 5222 @override | 5222 @override |
| 5223 String toString() => _element == null ? "-unknown-" : _element.name; | 5223 String toString() => _element == null ? "-unknown-" : _element.name; |
| 5224 } | 5224 } |
| OLD | NEW |