| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 return false; | 301 return false; |
| 302 } | 302 } |
| 303 if (!identical(argumentValues[0].type, typeProvider.stringType)) { | 303 if (!identical(argumentValues[0].type, typeProvider.stringType)) { |
| 304 return false; | 304 return false; |
| 305 } | 305 } |
| 306 String name = argumentValues[0].stringValue; | 306 String name = argumentValues[0].stringValue; |
| 307 return isValidPublicSymbol(name); | 307 return isValidPublicSymbol(name); |
| 308 } | 308 } |
| 309 | 309 |
| 310 /** | 310 /** |
| 311 * Compute the constant value associated with the given [element]. |
| 312 */ |
| 313 void computeConstantValue(Element element) { |
| 314 validator.beforeComputeValue(element); |
| 315 if (element is ParameterElement) { |
| 316 if (element.initializer != null) { |
| 317 Expression defaultValue = |
| 318 (element as PotentiallyConstVariableElement).constantInitializer; |
| 319 if (defaultValue != null) { |
| 320 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 321 ErrorReporter errorReporter = |
| 322 new ErrorReporter(errorListener, element.source); |
| 323 DartObjectImpl dartObject = |
| 324 defaultValue.accept(new ConstantVisitor(this, errorReporter)); |
| 325 (element as ParameterElementImpl).evaluationResult = |
| 326 new EvaluationResultImpl.con2(dartObject, errorListener.errors); |
| 327 } |
| 328 } |
| 329 } else if (element is VariableElement) { |
| 330 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 331 ErrorReporter errorReporter = |
| 332 new ErrorReporter(errorListener, element.source); |
| 333 DartObjectImpl dartObject = |
| 334 (element as PotentiallyConstVariableElement).constantInitializer |
| 335 .accept(new ConstantVisitor(this, errorReporter)); |
| 336 // Only check the type for truly const declarations (don't check final |
| 337 // fields with initializers, since their types may be generic. The type |
| 338 // of the final field will be checked later, when the constructor is |
| 339 // invoked). |
| 340 if (dartObject != null && element.isConst) { |
| 341 if (!runtimeTypeMatch(dartObject, element.type)) { |
| 342 errorReporter.reportErrorForElement( |
| 343 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, element, [ |
| 344 dartObject.type, |
| 345 element.type |
| 346 ]); |
| 347 } |
| 348 } |
| 349 (element as VariableElementImpl).evaluationResult = |
| 350 new EvaluationResultImpl.con2(dartObject, errorListener.errors); |
| 351 } else if (element is ConstructorElement) { |
| 352 // No evaluation needs to be done; constructor declarations are only in |
| 353 // the dependency graph to ensure that any constants referred to in |
| 354 // initializer lists and parameter defaults are evaluated before |
| 355 // invocations of the constructor. However we do need to annotate the |
| 356 // element as being free of constant evaluation cycles so that later code |
| 357 // will know that it is safe to evaluate. |
| 358 (element as ConstructorElementImpl).isCycleFree = true; |
| 359 } else { |
| 360 // Should not happen. |
| 361 assert(false); |
| 362 AnalysisEngine.instance.logger.logError( |
| 363 "Constant value computer trying to compute the value of a node of type
${element.runtimeType}"); |
| 364 return; |
| 365 } |
| 366 } |
| 367 |
| 368 /** |
| 311 * Determine which constant elements need to have their values computed | 369 * Determine which constant elements need to have their values computed |
| 312 * prior to computing the value of [element], and report them using | 370 * prior to computing the value of [element], and report them using |
| 313 * [callback]. | 371 * [callback]. |
| 314 */ | 372 */ |
| 315 void computeDependencies(Element element, ReferenceFinderCallback callback) { | 373 void computeDependencies(Element element, ReferenceFinderCallback callback) { |
| 316 ReferenceFinder referenceFinder = new ReferenceFinder(callback); | 374 ReferenceFinder referenceFinder = new ReferenceFinder(callback); |
| 317 if (element is ParameterElement) { | 375 if (element is ParameterElement) { |
| 318 if (element.initializer != null) { | 376 if (element.initializer != null) { |
| 319 Expression defaultValue = | 377 Expression defaultValue = |
| 320 (element as ConstVariableElement).constantInitializer; | 378 (element as ConstVariableElement).constantInitializer; |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 | 1161 |
| 1104 /** | 1162 /** |
| 1105 * Compute a value for the given [element]. | 1163 * Compute a value for the given [element]. |
| 1106 */ | 1164 */ |
| 1107 void _computeValueFor(Element element) { | 1165 void _computeValueFor(Element element) { |
| 1108 if (!_constantsToCompute.contains(element)) { | 1166 if (!_constantsToCompute.contains(element)) { |
| 1109 // Element is in the dependency graph but should have been computed by | 1167 // Element is in the dependency graph but should have been computed by |
| 1110 // a previous stage of analysis. | 1168 // a previous stage of analysis. |
| 1111 return; | 1169 return; |
| 1112 } | 1170 } |
| 1113 evaluationEngine.validator.beforeComputeValue(element); | 1171 evaluationEngine.computeConstantValue(element); |
| 1114 if (element is ParameterElement) { | |
| 1115 if (element.initializer != null) { | |
| 1116 Expression defaultValue = | |
| 1117 (element as PotentiallyConstVariableElement).constantInitializer; | |
| 1118 if (defaultValue != null) { | |
| 1119 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 1120 ErrorReporter errorReporter = | |
| 1121 new ErrorReporter(errorListener, element.source); | |
| 1122 DartObjectImpl dartObject = defaultValue | |
| 1123 .accept(new ConstantVisitor(evaluationEngine, errorReporter)); | |
| 1124 (element as ParameterElementImpl).evaluationResult = | |
| 1125 new EvaluationResultImpl.con2(dartObject, errorListener.errors); | |
| 1126 } | |
| 1127 } | |
| 1128 } else if (element is VariableElement) { | |
| 1129 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 1130 ErrorReporter errorReporter = | |
| 1131 new ErrorReporter(errorListener, element.source); | |
| 1132 DartObjectImpl dartObject = | |
| 1133 (element as PotentiallyConstVariableElement).constantInitializer | |
| 1134 .accept(new ConstantVisitor(evaluationEngine, errorReporter)); | |
| 1135 // Only check the type for truly const declarations (don't check final | |
| 1136 // fields with initializers, since their types may be generic. The type | |
| 1137 // of the final field will be checked later, when the constructor is | |
| 1138 // invoked). | |
| 1139 if (dartObject != null && element.isConst) { | |
| 1140 if (!evaluationEngine.runtimeTypeMatch(dartObject, element.type)) { | |
| 1141 errorReporter.reportErrorForElement( | |
| 1142 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, element, [ | |
| 1143 dartObject.type, | |
| 1144 element.type | |
| 1145 ]); | |
| 1146 } | |
| 1147 } | |
| 1148 (element as VariableElementImpl).evaluationResult = | |
| 1149 new EvaluationResultImpl.con2(dartObject, errorListener.errors); | |
| 1150 } else if (element is ConstructorElement) { | |
| 1151 // No evaluation needs to be done; constructor declarations are only in | |
| 1152 // the dependency graph to ensure that any constants referred to in | |
| 1153 // initializer lists and parameter defaults are evaluated before | |
| 1154 // invocations of the constructor. However we do need to annotate the | |
| 1155 // element as being free of constant evaluation cycles so that later code | |
| 1156 // will know that it is safe to evaluate. | |
| 1157 (element as ConstructorElementImpl).isCycleFree = true; | |
| 1158 } else { | |
| 1159 // Should not happen. | |
| 1160 assert(false); | |
| 1161 AnalysisEngine.instance.logger.logError( | |
| 1162 "Constant value computer trying to compute the value of a node of type
${element.runtimeType}"); | |
| 1163 return; | |
| 1164 } | |
| 1165 } | 1172 } |
| 1166 | 1173 |
| 1167 /** | 1174 /** |
| 1168 * Compute a value for the given annotation. | 1175 * Compute a value for the given annotation. |
| 1169 */ | 1176 */ |
| 1170 void _computeValueForAnnotation(Annotation constNode) { | 1177 void _computeValueForAnnotation(Annotation constNode) { |
| 1171 ElementAnnotationImpl elementAnnotation = constNode.elementAnnotation; | 1178 ElementAnnotationImpl elementAnnotation = constNode.elementAnnotation; |
| 1172 // elementAnnotation is null if the annotation couldn't be resolved, in | 1179 // elementAnnotation is null if the annotation couldn't be resolved, in |
| 1173 // which case we skip it. | 1180 // which case we skip it. |
| 1174 if (elementAnnotation != null) { | 1181 if (elementAnnotation != null) { |
| (...skipping 3970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5145 return BoolState.from(_element == rightElement); | 5152 return BoolState.from(_element == rightElement); |
| 5146 } else if (rightOperand is DynamicState) { | 5153 } else if (rightOperand is DynamicState) { |
| 5147 return BoolState.UNKNOWN_VALUE; | 5154 return BoolState.UNKNOWN_VALUE; |
| 5148 } | 5155 } |
| 5149 return BoolState.FALSE_STATE; | 5156 return BoolState.FALSE_STATE; |
| 5150 } | 5157 } |
| 5151 | 5158 |
| 5152 @override | 5159 @override |
| 5153 String toString() => _element == null ? "-unknown-" : _element.name; | 5160 String toString() => _element == null ? "-unknown-" : _element.name; |
| 5154 } | 5161 } |
| OLD | NEW |