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

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

Issue 1329743005: Abstract over the type system. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments 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
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 "(?!${ConstantValueComputer._RESERVED_WORD_RE}\\b(?!\\\$))[a-zA-Z\$][\\w\$ ]*"; 207 "(?!${ConstantValueComputer._RESERVED_WORD_RE}\\b(?!\\\$))[a-zA-Z\$][\\w\$ ]*";
208 208
209 /** 209 /**
210 * RegExp that validates a non-empty non-private symbol. 210 * RegExp that validates a non-empty non-private symbol.
211 * From sdk/lib/internal/symbol.dart. 211 * From sdk/lib/internal/symbol.dart.
212 */ 212 */
213 static RegExp _PUBLIC_SYMBOL_PATTERN = new RegExp( 213 static RegExp _PUBLIC_SYMBOL_PATTERN = new RegExp(
214 "^(?:${ConstantValueComputer._OPERATOR_RE}\$|$_PUBLIC_IDENTIFIER_RE(?:=?\$ |[.](?!\$)))+?\$"); 214 "^(?:${ConstantValueComputer._OPERATOR_RE}\$|$_PUBLIC_IDENTIFIER_RE(?:=?\$ |[.](?!\$)))+?\$");
215 215
216 /** 216 /**
217 * The type provider used to access the known types.
218 */
219 final TypeProvider typeProvider;
220
221 /**
217 * The type system. This is used to gues the types of constants when their 222 * The type system. This is used to gues the types of constants when their
218 * exact value is unknown. 223 * exact value is unknown.
219 */ 224 */
220 final TypeSystem typeSystem; 225 final TypeSystem typeSystem;
221 226
222 /** 227 /**
223 * The set of variables declared on the command line using '-D'. 228 * The set of variables declared on the command line using '-D'.
224 */ 229 */
225 final DeclaredVariables _declaredVariables; 230 final DeclaredVariables _declaredVariables;
226 231
227 /** 232 /**
228 * Validator used to verify correct dependency analysis when running unit 233 * Validator used to verify correct dependency analysis when running unit
229 * tests. 234 * tests.
230 */ 235 */
231 final ConstantEvaluationValidator validator; 236 final ConstantEvaluationValidator validator;
232 237
233 /** 238 /**
234 * Initialize a newly created [ConstantEvaluationEngine]. The [typeProvider] 239 * Initialize a newly created [ConstantEvaluationEngine]. The [typeProvider]
235 * is used to access known types. [_declaredVariables] is the set of 240 * is used to access known types. [_declaredVariables] is the set of
236 * variables declared on the command line using '-D'. The [validator], if 241 * variables declared on the command line using '-D'. The [validator], if
237 * given, is used to verify correct dependency analysis when running unit 242 * given, is used to verify correct dependency analysis when running unit
238 * tests. 243 * tests.
239 */ 244 */
240 ConstantEvaluationEngine(TypeProvider typeProvider, this._declaredVariables, 245 ConstantEvaluationEngine(
246 this.typeProvider, this.typeSystem, this._declaredVariables,
241 {ConstantEvaluationValidator validator}) 247 {ConstantEvaluationValidator validator})
242 : validator = validator != null 248 : validator = validator != null
243 ? validator 249 ? validator
244 : new ConstantEvaluationValidator_ForProduction(), 250 : new ConstantEvaluationValidator_ForProduction();
245 typeSystem = new TypeSystemImpl(typeProvider);
246
247 /**
248 * The type provider used to access the known types.
249 */
250 TypeProvider get typeProvider => typeSystem.typeProvider;
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 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 * The source containing the expression(s) that will be evaluated. 1143 * The source containing the expression(s) that will be evaluated.
1144 */ 1144 */
1145 final Source _source; 1145 final Source _source;
1146 1146
1147 /** 1147 /**
1148 * The type provider used to access the known types. 1148 * The type provider used to access the known types.
1149 */ 1149 */
1150 final TypeProvider _typeProvider; 1150 final TypeProvider _typeProvider;
1151 1151
1152 /** 1152 /**
1153 * The type system primitives.
1154 */
1155 final TypeSystem _typeSystem;
1156
1157 /**
1153 * Initialize a newly created evaluator to evaluate expressions in the given 1158 * Initialize a newly created evaluator to evaluate expressions in the given
1154 * [source]. The [typeProvider] is the type provider used to access known 1159 * [source]. The [typeProvider] is the type provider used to access known
1155 * types. 1160 * types.
1156 */ 1161 */
1157 ConstantEvaluator(this._source, this._typeProvider); 1162 ConstantEvaluator(this._source, this._typeProvider, this._typeSystem);
1158 1163
1159 EvaluationResult evaluate(Expression expression) { 1164 EvaluationResult evaluate(Expression expression) {
1160 RecordingErrorListener errorListener = new RecordingErrorListener(); 1165 RecordingErrorListener errorListener = new RecordingErrorListener();
1161 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source); 1166 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
1162 DartObjectImpl result = expression.accept(new ConstantVisitor( 1167 DartObjectImpl result = expression.accept(new ConstantVisitor(
1163 new ConstantEvaluationEngine(_typeProvider, new DeclaredVariables()), 1168 new ConstantEvaluationEngine(
1169 _typeProvider, _typeSystem, new DeclaredVariables()),
1164 errorReporter)); 1170 errorReporter));
1165 if (result != null) { 1171 if (result != null) {
1166 return EvaluationResult.forValue(result); 1172 return EvaluationResult.forValue(result);
1167 } 1173 }
1168 return EvaluationResult.forErrors(errorListener.errors); 1174 return EvaluationResult.forErrors(errorListener.errors);
1169 } 1175 }
1170 } 1176 }
1171 1177
1172 /** 1178 /**
1173 * A visitor used to traverse the AST structures of all of the compilation units 1179 * 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
1296 final ConstantEvaluationEngine evaluationEngine; 1302 final ConstantEvaluationEngine evaluationEngine;
1297 1303
1298 final AnalysisContext _context; 1304 final AnalysisContext _context;
1299 1305
1300 /** 1306 /**
1301 * Initialize a newly created constant value computer. The [typeProvider] is 1307 * Initialize a newly created constant value computer. The [typeProvider] is
1302 * the type provider used to access known types. The [declaredVariables] is 1308 * the type provider used to access known types. The [declaredVariables] is
1303 * the set of variables declared on the command line using '-D'. 1309 * the set of variables declared on the command line using '-D'.
1304 */ 1310 */
1305 ConstantValueComputer(this._context, TypeProvider typeProvider, 1311 ConstantValueComputer(this._context, TypeProvider typeProvider,
1306 DeclaredVariables declaredVariables, 1312 TypeSystem typeSystem, DeclaredVariables declaredVariables,
1307 [ConstantEvaluationValidator validator]) 1313 [ConstantEvaluationValidator validator])
1308 : evaluationEngine = new ConstantEvaluationEngine( 1314 : evaluationEngine = new ConstantEvaluationEngine(
1309 typeProvider, declaredVariables, 1315 typeProvider, typeSystem, declaredVariables,
1310 validator: validator); 1316 validator: validator);
1311 1317
1312 /** 1318 /**
1313 * Add the constants in the given compilation [unit] to the list of constants 1319 * Add the constants in the given compilation [unit] to the list of constants
1314 * whose value needs to be computed. 1320 * whose value needs to be computed.
1315 */ 1321 */
1316 void add(CompilationUnit unit, Source source, Source librarySource) { 1322 void add(CompilationUnit unit, Source source, Source librarySource) {
1317 ConstantFinder constantFinder = 1323 ConstantFinder constantFinder =
1318 new ConstantFinder(_context, source, librarySource); 1324 new ConstantFinder(_context, source, librarySource);
1319 unit.accept(constantFinder); 1325 unit.accept(constantFinder);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 return conditionResult; 1576 return conditionResult;
1571 } 1577 }
1572 if (conditionResult.isTrue) { 1578 if (conditionResult.isTrue) {
1573 return thenResult; 1579 return thenResult;
1574 } else if (conditionResult.isFalse) { 1580 } else if (conditionResult.isFalse) {
1575 return elseResult; 1581 return elseResult;
1576 } 1582 }
1577 ParameterizedType thenType = thenResult.type; 1583 ParameterizedType thenType = thenResult.type;
1578 ParameterizedType elseType = elseResult.type; 1584 ParameterizedType elseType = elseResult.type;
1579 return new DartObjectImpl.validWithUnknownValue( 1585 return new DartObjectImpl.validWithUnknownValue(
1580 _typeSystem.getLeastUpperBound(thenType, elseType) as InterfaceType); 1586 _typeSystem.getLeastUpperBound(_typeProvider, thenType, elseType)
1587 as InterfaceType);
1581 } 1588 }
1582 1589
1583 @override 1590 @override
1584 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => 1591 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) =>
1585 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value)); 1592 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value));
1586 1593
1587 @override 1594 @override
1588 DartObjectImpl visitInstanceCreationExpression( 1595 DartObjectImpl visitInstanceCreationExpression(
1589 InstanceCreationExpression node) { 1596 InstanceCreationExpression node) {
1590 if (!node.isConst) { 1597 if (!node.isConst) {
(...skipping 3702 matching lines...) Expand 10 before | Expand all | Expand 10 after
5293 return BoolState.from(_element == rightElement); 5300 return BoolState.from(_element == rightElement);
5294 } else if (rightOperand is DynamicState) { 5301 } else if (rightOperand is DynamicState) {
5295 return BoolState.UNKNOWN_VALUE; 5302 return BoolState.UNKNOWN_VALUE;
5296 } 5303 }
5297 return BoolState.FALSE_STATE; 5304 return BoolState.FALSE_STATE;
5298 } 5305 }
5299 5306
5300 @override 5307 @override
5301 String toString() => _element == null ? "-unknown-" : _element.name; 5308 String toString() => _element == null ? "-unknown-" : _element.name;
5302 } 5309 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698