| 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 analyzer.src.dart.constant.evaluation; | 5 library analyzer.src.dart.constant.evaluation; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/context/declared_variables.dart'; | 9 import 'package:analyzer/context/declared_variables.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 String name = baseParameter.name; | 699 String name = baseParameter.name; |
| 700 parameterMap[name] = argumentValue; | 700 parameterMap[name] = argumentValue; |
| 701 } | 701 } |
| 702 } | 702 } |
| 703 ConstantVisitor initializerVisitor = new ConstantVisitor( | 703 ConstantVisitor initializerVisitor = new ConstantVisitor( |
| 704 this, externalErrorReporter, | 704 this, externalErrorReporter, |
| 705 lexicalEnvironment: parameterMap); | 705 lexicalEnvironment: parameterMap); |
| 706 String superName = null; | 706 String superName = null; |
| 707 NodeList<Expression> superArguments = null; | 707 NodeList<Expression> superArguments = null; |
| 708 for (ConstructorInitializer initializer in initializers) { | 708 for (ConstructorInitializer initializer in initializers) { |
| 709 if (initializer is ConstructorFieldInitializer) { | 709 if (initializer is AssertInitializer) { |
| 710 Expression condition = initializer.condition; |
| 711 DartObjectImpl conditionResult = condition?.accept(initializerVisitor); |
| 712 if (conditionResult != null) { |
| 713 if (conditionResult.isBool) { |
| 714 if (!conditionResult.toBoolValue()) { |
| 715 errorReporter.reportErrorForNode( |
| 716 CompileTimeErrorCode.CONST_EVAL_THROWS_ASSERT_FALSE, node); |
| 717 } |
| 718 } else { |
| 719 errorReporter.reportErrorForNode( |
| 720 CompileTimeErrorCode.CONST_EVAL_THROWS_ASSERT_NOT_BOOL, node); |
| 721 } |
| 722 } else { |
| 723 errorReporter.reportErrorForNode( |
| 724 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); |
| 725 } |
| 726 } else if (initializer is ConstructorFieldInitializer) { |
| 710 Expression initializerExpression = initializer.expression; | 727 Expression initializerExpression = initializer.expression; |
| 711 DartObjectImpl evaluationResult = | 728 DartObjectImpl evaluationResult = |
| 712 initializerExpression?.accept(initializerVisitor); | 729 initializerExpression?.accept(initializerVisitor); |
| 713 if (evaluationResult != null) { | 730 if (evaluationResult != null) { |
| 714 String fieldName = initializer.fieldName.name; | 731 String fieldName = initializer.fieldName.name; |
| 715 if (fieldMap.containsKey(fieldName)) { | 732 if (fieldMap.containsKey(fieldName)) { |
| 716 errorReporter.reportErrorForNode( | 733 errorReporter.reportErrorForNode( |
| 717 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); | 734 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); |
| 718 } | 735 } |
| 719 fieldMap[fieldName] = evaluationResult; | 736 fieldMap[fieldName] = evaluationResult; |
| (...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 } | 2150 } |
| 2134 | 2151 |
| 2135 @override | 2152 @override |
| 2136 String toString() { | 2153 String toString() { |
| 2137 if (value == null) { | 2154 if (value == null) { |
| 2138 return "error"; | 2155 return "error"; |
| 2139 } | 2156 } |
| 2140 return value.toString(); | 2157 return value.toString(); |
| 2141 } | 2158 } |
| 2142 } | 2159 } |
| OLD | NEW |