| 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'; |
| 11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 11 import 'package:analyzer/dart/ast/token.dart'; | 12 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/ast/visitor.dart'; | 13 import 'package:analyzer/dart/ast/visitor.dart'; |
| 13 import 'package:analyzer/dart/constant/value.dart'; | 14 import 'package:analyzer/dart/constant/value.dart'; |
| 14 import 'package:analyzer/dart/element/element.dart'; | 15 import 'package:analyzer/dart/element/element.dart'; |
| 15 import 'package:analyzer/dart/element/type.dart'; | 16 import 'package:analyzer/dart/element/type.dart'; |
| 16 import 'package:analyzer/error/error.dart'; | 17 import 'package:analyzer/error/error.dart'; |
| 17 import 'package:analyzer/error/listener.dart'; | 18 import 'package:analyzer/error/listener.dart'; |
| 18 import 'package:analyzer/src/dart/constant/utilities.dart'; | 19 import 'package:analyzer/src/dart/constant/utilities.dart'; |
| 19 import 'package:analyzer/src/dart/constant/value.dart'; | 20 import 'package:analyzer/src/dart/constant/value.dart'; |
| 20 import 'package:analyzer/src/dart/element/element.dart'; | 21 import 'package:analyzer/src/dart/element/element.dart'; |
| 21 import 'package:analyzer/src/dart/element/member.dart'; | 22 import 'package:analyzer/src/dart/element/member.dart'; |
| 22 import 'package:analyzer/src/error/codes.dart'; | 23 import 'package:analyzer/src/error/codes.dart'; |
| 23 import 'package:analyzer/src/generated/engine.dart'; | 24 import 'package:analyzer/src/generated/engine.dart'; |
| 24 import 'package:analyzer/src/generated/engine.dart' | 25 import 'package:analyzer/src/generated/engine.dart' |
| 25 show AnalysisEngine, RecordingErrorListener; | 26 show AnalysisEngine, RecordingErrorListener; |
| 26 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 27 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 27 import 'package:analyzer/src/generated/type_system.dart' | 28 import 'package:analyzer/src/generated/type_system.dart' |
| 28 show TypeSystem, TypeSystemImpl; | 29 show TypeSystem, TypeSystemImpl; |
| 29 import 'package:analyzer/src/generated/utilities_collection.dart'; | 30 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 30 import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind; | 31 import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind; |
| 31 import 'package:analyzer/src/task/dart.dart'; | 32 import 'package:analyzer/src/task/dart.dart'; |
| 32 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Helper class encapsulating the methods for evaluating constants and | 35 * Helper class encapsulating the methods for evaluating constants and |
| 36 * constant instance creation expressions. | 36 * constant instance creation expressions. |
| 37 */ | 37 */ |
| 38 class ConstantEvaluationEngine { | 38 class ConstantEvaluationEngine { |
| 39 /** | 39 /** |
| 40 * Parameter to "fromEnvironment" methods that denotes the default value. | 40 * Parameter to "fromEnvironment" methods that denotes the default value. |
| 41 */ | 41 */ |
| 42 static String _DEFAULT_VALUE_PARAM = "defaultValue"; | 42 static String _DEFAULT_VALUE_PARAM = "defaultValue"; |
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 if (conditionResult == null) { | 1285 if (conditionResult == null) { |
| 1286 return conditionResult; | 1286 return conditionResult; |
| 1287 } | 1287 } |
| 1288 if (conditionResult.toBoolValue() == true) { | 1288 if (conditionResult.toBoolValue() == true) { |
| 1289 return thenResult; | 1289 return thenResult; |
| 1290 } else if (conditionResult.toBoolValue() == false) { | 1290 } else if (conditionResult.toBoolValue() == false) { |
| 1291 return elseResult; | 1291 return elseResult; |
| 1292 } | 1292 } |
| 1293 ParameterizedType thenType = thenResult.type; | 1293 ParameterizedType thenType = thenResult.type; |
| 1294 ParameterizedType elseType = elseResult.type; | 1294 ParameterizedType elseType = elseResult.type; |
| 1295 return new DartObjectImpl.validWithUnknownValue( | 1295 return new DartObjectImpl.validWithUnknownValue(_typeSystem |
| 1296 _typeSystem.getLeastUpperBound(thenType, elseType) as InterfaceType); | 1296 .getLeastUpperBound(thenType, elseType) as ParameterizedType); |
| 1297 } | 1297 } |
| 1298 | 1298 |
| 1299 @override | 1299 @override |
| 1300 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => | 1300 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => |
| 1301 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value)); | 1301 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value)); |
| 1302 | 1302 |
| 1303 @override | 1303 @override |
| 1304 DartObjectImpl visitInstanceCreationExpression( | 1304 DartObjectImpl visitInstanceCreationExpression( |
| 1305 InstanceCreationExpression node) { | 1305 InstanceCreationExpression node) { |
| 1306 if (!node.isConst) { | 1306 if (!node.isConst) { |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 } | 2080 } |
| 2081 | 2081 |
| 2082 @override | 2082 @override |
| 2083 String toString() { | 2083 String toString() { |
| 2084 if (value == null) { | 2084 if (value == null) { |
| 2085 return "error"; | 2085 return "error"; |
| 2086 } | 2086 } |
| 2087 return value.toString(); | 2087 return value.toString(); |
| 2088 } | 2088 } |
| 2089 } | 2089 } |
| OLD | NEW |