Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1355773002: Make type system changes backwards compatible (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 engine.constant; 5 library engine.constant;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/utilities_general.dart'; 10 import 'package:analyzer/src/generated/utilities_general.dart';
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 */ 235 */
236 final ConstantEvaluationValidator validator; 236 final ConstantEvaluationValidator validator;
237 237
238 /** 238 /**
239 * Initialize a newly created [ConstantEvaluationEngine]. The [typeProvider] 239 * Initialize a newly created [ConstantEvaluationEngine]. The [typeProvider]
240 * is used to access known types. [_declaredVariables] is the set of 240 * is used to access known types. [_declaredVariables] is the set of
241 * variables declared on the command line using '-D'. The [validator], if 241 * variables declared on the command line using '-D'. The [validator], if
242 * given, is used to verify correct dependency analysis when running unit 242 * given, is used to verify correct dependency analysis when running unit
243 * tests. 243 * tests.
244 */ 244 */
245 ConstantEvaluationEngine( 245 ConstantEvaluationEngine(this.typeProvider, this._declaredVariables,
246 this.typeProvider, this.typeSystem, this._declaredVariables, 246 {ConstantEvaluationValidator validator, TypeSystem typeSystem})
247 {ConstantEvaluationValidator validator})
248 : validator = validator != null 247 : validator = validator != null
249 ? validator 248 ? validator
250 : new ConstantEvaluationValidator_ForProduction(); 249 : new ConstantEvaluationValidator_ForProduction(),
250 typeSystem = typeSystem != null ? typeSystem : new TypeSystemImpl();
251 251
252 /** 252 /**
253 * Check that the arguments to a call to fromEnvironment() are correct. The 253 * Check that the arguments to a call to fromEnvironment() are correct. The
254 * [arguments] are the AST nodes of the arguments. The [argumentValues] are 254 * [arguments] are the AST nodes of the arguments. The [argumentValues] are
255 * the values of the unnamed arguments. The [namedArgumentValues] are the 255 * the values of the unnamed arguments. The [namedArgumentValues] are the
256 * values of the named arguments. The [expectedDefaultValueType] is the 256 * values of the named arguments. The [expectedDefaultValueType] is the
257 * allowed type of the "defaultValue" parameter (if present). Note: 257 * allowed type of the "defaultValue" parameter (if present). Note:
258 * "defaultValue" is always allowed to be null. Return `true` if the arguments 258 * "defaultValue" is always allowed to be null. Return `true` if the arguments
259 * are correct, `false` if there is an error. 259 * are correct, `false` if there is an error.
260 */ 260 */
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 /** 1152 /**
1153 * The type system primitives. 1153 * The type system primitives.
1154 */ 1154 */
1155 final TypeSystem _typeSystem; 1155 final TypeSystem _typeSystem;
1156 1156
1157 /** 1157 /**
1158 * Initialize a newly created evaluator to evaluate expressions in the given 1158 * Initialize a newly created evaluator to evaluate expressions in the given
1159 * [source]. The [typeProvider] is the type provider used to access known 1159 * [source]. The [typeProvider] is the type provider used to access known
1160 * types. 1160 * types.
1161 */ 1161 */
1162 ConstantEvaluator(this._source, this._typeProvider, this._typeSystem); 1162 ConstantEvaluator(this._source, this._typeProvider, {TypeSystem typeSystem})
1163 : _typeSystem = typeSystem != null ? typeSystem : new TypeSystemImpl();
1163 1164
1164 EvaluationResult evaluate(Expression expression) { 1165 EvaluationResult evaluate(Expression expression) {
1165 RecordingErrorListener errorListener = new RecordingErrorListener(); 1166 RecordingErrorListener errorListener = new RecordingErrorListener();
1166 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source); 1167 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
1167 DartObjectImpl result = expression.accept(new ConstantVisitor( 1168 DartObjectImpl result = expression.accept(new ConstantVisitor(
1168 new ConstantEvaluationEngine( 1169 new ConstantEvaluationEngine(_typeProvider, new DeclaredVariables(),
1169 _typeProvider, _typeSystem, new DeclaredVariables()), 1170 typeSystem: _typeSystem),
1170 errorReporter)); 1171 errorReporter));
1171 if (result != null) { 1172 if (result != null) {
1172 return EvaluationResult.forValue(result); 1173 return EvaluationResult.forValue(result);
1173 } 1174 }
1174 return EvaluationResult.forErrors(errorListener.errors); 1175 return EvaluationResult.forErrors(errorListener.errors);
1175 } 1176 }
1176 } 1177 }
1177 1178
1178 /** 1179 /**
1179 * A visitor used to traverse the AST structures of all of the compilation units 1180 * A visitor used to traverse the AST structures of all of the compilation units
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 final ConstantEvaluationEngine evaluationEngine; 1303 final ConstantEvaluationEngine evaluationEngine;
1303 1304
1304 final AnalysisContext _context; 1305 final AnalysisContext _context;
1305 1306
1306 /** 1307 /**
1307 * Initialize a newly created constant value computer. The [typeProvider] is 1308 * Initialize a newly created constant value computer. The [typeProvider] is
1308 * the type provider used to access known types. The [declaredVariables] is 1309 * the type provider used to access known types. The [declaredVariables] is
1309 * the set of variables declared on the command line using '-D'. 1310 * the set of variables declared on the command line using '-D'.
1310 */ 1311 */
1311 ConstantValueComputer(this._context, TypeProvider typeProvider, 1312 ConstantValueComputer(this._context, TypeProvider typeProvider,
1312 TypeSystem typeSystem, DeclaredVariables declaredVariables, 1313 DeclaredVariables declaredVariables,
1313 [ConstantEvaluationValidator validator]) 1314 [ConstantEvaluationValidator validator, TypeSystem typeSystem])
1314 : evaluationEngine = new ConstantEvaluationEngine( 1315 : evaluationEngine = new ConstantEvaluationEngine(
1315 typeProvider, typeSystem, declaredVariables, 1316 typeProvider, declaredVariables,
1316 validator: validator); 1317 validator: validator, typeSystem: typeSystem);
1317 1318
1318 /** 1319 /**
1319 * Add the constants in the given compilation [unit] to the list of constants 1320 * Add the constants in the given compilation [unit] to the list of constants
1320 * whose value needs to be computed. 1321 * whose value needs to be computed.
1321 */ 1322 */
1322 void add(CompilationUnit unit, Source source, Source librarySource) { 1323 void add(CompilationUnit unit, Source source, Source librarySource) {
1323 ConstantFinder constantFinder = 1324 ConstantFinder constantFinder =
1324 new ConstantFinder(_context, source, librarySource); 1325 new ConstantFinder(_context, source, librarySource);
1325 unit.accept(constantFinder); 1326 unit.accept(constantFinder);
1326 _constantsToCompute.addAll(constantFinder.constantsToCompute); 1327 _constantsToCompute.addAll(constantFinder.constantsToCompute);
(...skipping 3973 matching lines...) Expand 10 before | Expand all | Expand 10 after
5300 return BoolState.from(_element == rightElement); 5301 return BoolState.from(_element == rightElement);
5301 } else if (rightOperand is DynamicState) { 5302 } else if (rightOperand is DynamicState) {
5302 return BoolState.UNKNOWN_VALUE; 5303 return BoolState.UNKNOWN_VALUE;
5303 } 5304 }
5304 return BoolState.FALSE_STATE; 5305 return BoolState.FALSE_STATE;
5305 } 5306 }
5306 5307
5307 @override 5308 @override
5308 String toString() => _element == null ? "-unknown-" : _element.name; 5309 String toString() => _element == null ? "-unknown-" : _element.name;
5309 } 5310 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/engine.dart » ('j') | pkg/analyzer/lib/src/generated/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698