| 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/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/ast/visitor.dart'; | 12 import 'package:analyzer/dart/ast/visitor.dart'; |
| 13 import 'package:analyzer/dart/constant/value.dart'; | 13 import 'package:analyzer/dart/constant/value.dart'; |
| 14 import 'package:analyzer/dart/element/element.dart'; | 14 import 'package:analyzer/dart/element/element.dart'; |
| 15 import 'package:analyzer/dart/element/type.dart'; | 15 import 'package:analyzer/dart/element/type.dart'; |
| 16 import 'package:analyzer/src/dart/constant/utilities.dart'; | 16 import 'package:analyzer/src/dart/constant/utilities.dart'; |
| 17 import 'package:analyzer/src/dart/constant/value.dart'; | 17 import 'package:analyzer/src/dart/constant/value.dart'; |
| 18 import 'package:analyzer/src/dart/element/element.dart'; | 18 import 'package:analyzer/src/dart/element/element.dart'; |
| 19 import 'package:analyzer/src/dart/element/member.dart'; | 19 import 'package:analyzer/src/dart/element/member.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart' | 21 import 'package:analyzer/src/generated/engine.dart' |
| 22 show AnalysisEngine, RecordingErrorListener; | 22 show AnalysisEngine, RecordingErrorListener; |
| 23 import 'package:analyzer/src/generated/error.dart'; | 23 import 'package:analyzer/src/generated/error.dart'; |
| 24 import 'package:analyzer/src/generated/java_core.dart'; | 24 import 'package:analyzer/src/generated/java_core.dart'; |
| 25 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 25 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 26 import 'package:analyzer/src/generated/source.dart' show Source; | |
| 27 import 'package:analyzer/src/generated/type_system.dart' | 26 import 'package:analyzer/src/generated/type_system.dart' |
| 28 show TypeSystem, TypeSystemImpl; | 27 show TypeSystem, TypeSystemImpl; |
| 29 import 'package:analyzer/src/generated/utilities_collection.dart'; | 28 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 30 import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind; | 29 import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind; |
| 31 import 'package:analyzer/src/task/dart.dart'; | 30 import 'package:analyzer/src/task/dart.dart'; |
| 32 | 31 |
| 33 /** | 32 /** |
| 34 * Helper class encapsulating the methods for evaluating constants and | 33 * Helper class encapsulating the methods for evaluating constants and |
| 35 * constant instance creation expressions. | 34 * constant instance creation expressions. |
| 36 */ | 35 */ |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 */ | 922 */ |
| 924 HashSet<ConstantEvaluationTarget> _constantsToCompute = | 923 HashSet<ConstantEvaluationTarget> _constantsToCompute = |
| 925 new HashSet<ConstantEvaluationTarget>(); | 924 new HashSet<ConstantEvaluationTarget>(); |
| 926 | 925 |
| 927 /** | 926 /** |
| 928 * The evaluation engine that does the work of evaluating instance creation | 927 * The evaluation engine that does the work of evaluating instance creation |
| 929 * expressions. | 928 * expressions. |
| 930 */ | 929 */ |
| 931 final ConstantEvaluationEngine evaluationEngine; | 930 final ConstantEvaluationEngine evaluationEngine; |
| 932 | 931 |
| 933 final AnalysisContext _context; | |
| 934 | |
| 935 /** | 932 /** |
| 936 * Initialize a newly created constant value computer. The [typeProvider] is | 933 * Initialize a newly created constant value computer. The [typeProvider] is |
| 937 * the type provider used to access known types. The [declaredVariables] is | 934 * the type provider used to access known types. The [declaredVariables] is |
| 938 * the set of variables declared on the command line using '-D'. | 935 * the set of variables declared on the command line using '-D'. |
| 939 */ | 936 */ |
| 940 ConstantValueComputer(this._context, TypeProvider typeProvider, | 937 ConstantValueComputer( |
| 941 DeclaredVariables declaredVariables, | 938 TypeProvider typeProvider, DeclaredVariables declaredVariables, |
| 942 [ConstantEvaluationValidator validator, TypeSystem typeSystem]) | 939 [ConstantEvaluationValidator validator, TypeSystem typeSystem]) |
| 943 : evaluationEngine = new ConstantEvaluationEngine( | 940 : evaluationEngine = new ConstantEvaluationEngine( |
| 944 typeProvider, declaredVariables, | 941 typeProvider, declaredVariables, |
| 945 validator: validator, typeSystem: typeSystem); | 942 validator: validator, typeSystem: typeSystem); |
| 946 | 943 |
| 947 /** | 944 /** |
| 948 * Add the constants in the given compilation [unit] to the list of constants | 945 * Add the constants in the given compilation [unit] to the list of constants |
| 949 * whose value needs to be computed. | 946 * whose value needs to be computed. |
| 950 */ | 947 */ |
| 951 void add(CompilationUnit unit, Source source, Source librarySource) { | 948 void add(CompilationUnit unit) { |
| 952 ConstantFinder constantFinder = | 949 ConstantFinder constantFinder = new ConstantFinder(); |
| 953 new ConstantFinder(_context, source, librarySource); | |
| 954 unit.accept(constantFinder); | 950 unit.accept(constantFinder); |
| 955 _constantsToCompute.addAll(constantFinder.constantsToCompute); | 951 _constantsToCompute.addAll(constantFinder.constantsToCompute); |
| 956 } | 952 } |
| 957 | 953 |
| 958 /** | 954 /** |
| 959 * Compute values for all of the constants in the compilation units that were | 955 * Compute values for all of the constants in the compilation units that were |
| 960 * added. | 956 * added. |
| 961 */ | 957 */ |
| 962 void computeValues() { | 958 void computeValues() { |
| 963 for (ConstantEvaluationTarget constant in _constantsToCompute) { | 959 for (ConstantEvaluationTarget constant in _constantsToCompute) { |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 } | 1984 } |
| 1989 | 1985 |
| 1990 @override | 1986 @override |
| 1991 String toString() { | 1987 String toString() { |
| 1992 if (value == null) { | 1988 if (value == null) { |
| 1993 return "error"; | 1989 return "error"; |
| 1994 } | 1990 } |
| 1995 return value.toString(); | 1991 return value.toString(); |
| 1996 } | 1992 } |
| 1997 } | 1993 } |
| OLD | NEW |