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

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

Issue 221483002: Fix for translation of \!= to \!identical(), but use == and \!= for Enum. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/lib/src/generated/element.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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.constant; 8 library engine.constant;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * expressions that evaluate to a numeric value or to <b>null</b>. 59 * expressions that evaluate to a numeric value or to <b>null</b>.
60 * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub>< /i> where 60 * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub>< /i> where
61 * <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and <i>e<sub>3</sub></i> are const ant expressions, and 61 * <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and <i>e<sub>3</sub></i> are const ant expressions, and
62 * <i>e<sub>1</sub></i> evaluates to a boolean value. 62 * <i>e<sub>1</sub></i> evaluates to a boolean value.
63 * </blockquote> 63 * </blockquote>
64 */ 64 */
65 class ConstantEvaluator { 65 class ConstantEvaluator {
66 /** 66 /**
67 * The source containing the expression(s) that will be evaluated. 67 * The source containing the expression(s) that will be evaluated.
68 */ 68 */
69 Source _source; 69 final Source _source;
70 70
71 /** 71 /**
72 * The type provider used to access the known types. 72 * The type provider used to access the known types.
73 */ 73 */
74 TypeProvider _typeProvider; 74 final TypeProvider _typeProvider;
75 75
76 /** 76 /**
77 * Initialize a newly created evaluator to evaluate expressions in the given s ource. 77 * Initialize a newly created evaluator to evaluate expressions in the given s ource.
78 * 78 *
79 * @param source the source containing the expression(s) that will be evaluate d 79 * @param source the source containing the expression(s) that will be evaluate d
80 * @param typeProvider the type provider used to access known types 80 * @param typeProvider the type provider used to access known types
81 */ 81 */
82 ConstantEvaluator(Source source, TypeProvider typeProvider) { 82 ConstantEvaluator(this._source, this._typeProvider);
83 this._source = source;
84 this._typeProvider = typeProvider;
85 }
86 83
87 EvaluationResult evaluate(Expression expression) { 84 EvaluationResult evaluate(Expression expression) {
88 EvaluationResultImpl result = expression.accept(new ConstantVisitor(_typePro vider)); 85 EvaluationResultImpl result = expression.accept(new ConstantVisitor(_typePro vider));
89 if (result is ValidResult) { 86 if (result is ValidResult) {
90 return EvaluationResult.forValue(result.value); 87 return EvaluationResult.forValue(result.value);
91 } 88 }
92 List<AnalysisError> errors = new List<AnalysisError>(); 89 List<AnalysisError> errors = new List<AnalysisError>();
93 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) { 90 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) {
94 AstNode node = data.node; 91 AstNode node = data.node;
95 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, [])); 92 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, []));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 * compile-time constant that evaluates to the given value. 196 * compile-time constant that evaluates to the given value.
200 * 197 *
201 * @param value the value of the expression 198 * @param value the value of the expression
202 * @return the result of evaluating an expression that is a compile-time const ant 199 * @return the result of evaluating an expression that is a compile-time const ant
203 */ 200 */
204 static EvaluationResult forValue(DartObject value) => new EvaluationResult(val ue, null); 201 static EvaluationResult forValue(DartObject value) => new EvaluationResult(val ue, null);
205 202
206 /** 203 /**
207 * The value of the expression. 204 * The value of the expression.
208 */ 205 */
209 DartObject value; 206 final DartObject value;
210 207
211 /** 208 /**
212 * The errors that should be reported for the expression(s) that were evaluate d. 209 * The errors that should be reported for the expression(s) that were evaluate d.
213 */ 210 */
214 List<AnalysisError> _errors; 211 final List<AnalysisError> _errors;
215 212
216 /** 213 /**
217 * Initialize a newly created result object with the given state. Clients shou ld use one of the 214 * Initialize a newly created result object with the given state. Clients shou ld use one of the
218 * factory methods: [forErrors] and [forValue]. 215 * factory methods: [forErrors] and [forValue].
219 * 216 *
220 * @param value the value of the expression 217 * @param value the value of the expression
221 * @param errors the errors that should be reported for the expression(s) that were evaluated 218 * @param errors the errors that should be reported for the expression(s) that were evaluated
222 */ 219 */
223 EvaluationResult(DartObject value, List<AnalysisError> errors) { 220 EvaluationResult(this.value, this._errors);
224 this.value = value;
225 this._errors = errors;
226 }
227 221
228 /** 222 /**
229 * Return an array containing the errors that should be reported for the expre ssion(s) that were 223 * Return an array containing the errors that should be reported for the expre ssion(s) that were
230 * evaluated. If there are no such errors, the array will be empty. The array can be empty even if 224 * evaluated. If there are no such errors, the array will be empty. The array can be empty even if
231 * the expression is not a valid compile time constant if the errors would hav e been reported by 225 * the expression is not a valid compile time constant if the errors would hav e been reported by
232 * other parts of the analysis engine. 226 * other parts of the analysis engine.
233 */ 227 */
234 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS : _errors; 228 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS : _errors;
235 229
236 /** 230 /**
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 * Instances of the class `ConstantValueComputer` compute the values of constant variables in 265 * Instances of the class `ConstantValueComputer` compute the values of constant variables in
272 * one or more compilation units. The expected usage pattern is for the compilat ion units to be 266 * one or more compilation units. The expected usage pattern is for the compilat ion units to be
273 * added to this computer using the method [add] and then for the method 267 * added to this computer using the method [add] and then for the method
274 * [computeValues] to be invoked exactly once. Any use of an instance after invo king the 268 * [computeValues] to be invoked exactly once. Any use of an instance after invo king the
275 * method [computeValues] will result in unpredictable behavior. 269 * method [computeValues] will result in unpredictable behavior.
276 */ 270 */
277 class ConstantValueComputer { 271 class ConstantValueComputer {
278 /** 272 /**
279 * The type provider used to access the known types. 273 * The type provider used to access the known types.
280 */ 274 */
281 TypeProvider _typeProvider; 275 final TypeProvider _typeProvider;
282 276
283 /** 277 /**
284 * The object used to find constant variables in the compilation units that we re added. 278 * The object used to find constant variables in the compilation units that we re added.
285 */ 279 */
286 ConstantFinder _constantFinder = new ConstantFinder(); 280 ConstantFinder _constantFinder = new ConstantFinder();
287 281
288 /** 282 /**
289 * A graph in which the nodes are the constant variables and the edges are fro m each variable to 283 * A graph in which the nodes are the constant variables and the edges are fro m each variable to
290 * the other constant variables that are referenced in the head's initializer. 284 * the other constant variables that are referenced in the head's initializer.
291 */ 285 */
292 DirectedGraph<VariableElement> _referenceGraph = new DirectedGraph<VariableEle ment>(); 286 DirectedGraph<VariableElement> _referenceGraph = new DirectedGraph<VariableEle ment>();
293 287
294 /** 288 /**
295 * A table mapping constant variables to the declarations of those variables. 289 * A table mapping constant variables to the declarations of those variables.
296 */ 290 */
297 Map<VariableElement, VariableDeclaration> _declarationMap; 291 Map<VariableElement, VariableDeclaration> _declarationMap;
298 292
299 /** 293 /**
300 * Initialize a newly created constant value computer. 294 * Initialize a newly created constant value computer.
301 * 295 *
302 * @param typeProvider the type provider used to access known types 296 * @param typeProvider the type provider used to access known types
303 */ 297 */
304 ConstantValueComputer(TypeProvider typeProvider) { 298 ConstantValueComputer(this._typeProvider);
305 this._typeProvider = typeProvider;
306 }
307 299
308 /** 300 /**
309 * Add the constant variables in the given compilation unit to the list of con stant variables 301 * Add the constant variables in the given compilation unit to the list of con stant variables
310 * whose value needs to be computed. 302 * whose value needs to be computed.
311 * 303 *
312 * @param unit the compilation unit defining the constant variables to be adde d 304 * @param unit the compilation unit defining the constant variables to be adde d
313 */ 305 */
314 void add(CompilationUnit unit) { 306 void add(CompilationUnit unit) {
315 unit.accept(_constantFinder); 307 unit.accept(_constantFinder);
316 } 308 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 * expressions that evaluate to a numeric value or to <b>null</b>. 423 * expressions that evaluate to a numeric value or to <b>null</b>.
432 * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub>< /i> where 424 * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub>< /i> where
433 * <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and <i>e<sub>3</sub></i> are const ant expressions, and 425 * <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and <i>e<sub>3</sub></i> are const ant expressions, and
434 * <i>e<sub>1</sub></i> evaluates to a boolean value. 426 * <i>e<sub>1</sub></i> evaluates to a boolean value.
435 * </blockquote> 427 * </blockquote>
436 */ 428 */
437 class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> { 429 class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> {
438 /** 430 /**
439 * The type provider used to access the known types. 431 * The type provider used to access the known types.
440 */ 432 */
441 TypeProvider _typeProvider; 433 final TypeProvider _typeProvider;
442 434
443 /** 435 /**
444 * An shared object representing the value 'null'. 436 * An shared object representing the value 'null'.
445 */ 437 */
446 DartObjectImpl _nullObject; 438 DartObjectImpl _nullObject;
447 439
448 /** 440 /**
449 * Initialize a newly created constant visitor. 441 * Initialize a newly created constant visitor.
450 * 442 *
451 * @param typeProvider the type provider used to access known types 443 * @param typeProvider the type provider used to access known types
452 */ 444 */
453 ConstantVisitor(TypeProvider typeProvider) { 445 ConstantVisitor(this._typeProvider);
454 this._typeProvider = typeProvider;
455 }
456 446
457 @override 447 @override
458 EvaluationResultImpl visitAdjacentStrings(AdjacentStrings node) { 448 EvaluationResultImpl visitAdjacentStrings(AdjacentStrings node) {
459 EvaluationResultImpl result = null; 449 EvaluationResultImpl result = null;
460 for (StringLiteral string in node.strings) { 450 for (StringLiteral string in node.strings) {
461 if (result == null) { 451 if (result == null) {
462 result = string.accept(this); 452 result = string.accept(this);
463 } else { 453 } else {
464 result = result.concatenate(_typeProvider, node, string.accept(this)); 454 result = result.concatenate(_typeProvider, node, string.accept(this));
465 } 455 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 return _valid(definingClass, new SymbolState(argumentValue)); 584 return _valid(definingClass, new SymbolState(argumentValue));
595 } 585 }
596 } 586 }
597 } 587 }
598 Map<String, DartObjectImpl> fieldMap = new Map<String, DartObjectImpl>(); 588 Map<String, DartObjectImpl> fieldMap = new Map<String, DartObjectImpl>();
599 List<ParameterElement> parameters = constructor.parameters; 589 List<ParameterElement> parameters = constructor.parameters;
600 int parameterCount = parameters.length; 590 int parameterCount = parameters.length;
601 for (int i = 0; i < parameterCount; i++) { 591 for (int i = 0; i < parameterCount; i++) {
602 ParameterElement parameter = parameters[i]; 592 ParameterElement parameter = parameters[i];
603 if (parameter.isInitializingFormal) { 593 if (parameter.isInitializingFormal) {
604 String fieldName = (parameter as FieldFormalParameterElement).field.na me; 594 FieldElement field = (parameter as FieldFormalParameterElement).field;
605 if (identical(parameter.parameterKind, ParameterKind.NAMED)) { 595 if (field != null) {
606 DartObjectImpl argumentValue = namedArgumentValues[parameter.name]; 596 String fieldName = field.name;
607 if (argumentValue != null) { 597 if (parameter.parameterKind == ParameterKind.NAMED) {
608 fieldMap[fieldName] = argumentValue; 598 DartObjectImpl argumentValue = namedArgumentValues[parameter.name] ;
599 if (argumentValue != null) {
600 fieldMap[fieldName] = argumentValue;
601 }
602 } else if (i < argumentCount) {
603 fieldMap[fieldName] = argumentValues[i];
609 } 604 }
610 } else if (i < argumentCount) {
611 fieldMap[fieldName] = argumentValues[i];
612 } 605 }
613 } 606 }
614 } 607 }
615 // TODO(brianwilkerson) This doesn't handle fields initialized in an initi alizer. We should be 608 // TODO(brianwilkerson) This doesn't handle fields initialized in an initi alizer. We should be
616 // able to handle fields initialized by the superclass' constructor fairly easily, but other 609 // able to handle fields initialized by the superclass' constructor fairly easily, but other
617 // initializers will be harder. 610 // initializers will be harder.
618 return _valid(definingClass, new GenericState(fieldMap)); 611 return _valid(definingClass, new GenericState(fieldMap));
619 } 612 }
620 // TODO(brianwilkerson) Figure out which error to report. 613 // TODO(brianwilkerson) Figure out which error to report.
621 return _error(node, null); 614 return _error(node, null);
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand); 1113 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
1121 1114
1122 @override 1115 @override
1123 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this; 1116 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
1124 } 1117 }
1125 1118
1126 class ErrorResult_ErrorData { 1119 class ErrorResult_ErrorData {
1127 /** 1120 /**
1128 * The node against which the error should be reported. 1121 * The node against which the error should be reported.
1129 */ 1122 */
1130 AstNode node; 1123 final AstNode node;
1131 1124
1132 /** 1125 /**
1133 * The error code for the error to be generated. 1126 * The error code for the error to be generated.
1134 */ 1127 */
1135 ErrorCode errorCode; 1128 final ErrorCode errorCode;
1136 1129
1137 /** 1130 /**
1138 * Initialize a newly created data holder to represent the error with the give n code reported 1131 * Initialize a newly created data holder to represent the error with the give n code reported
1139 * against the given node. 1132 * against the given node.
1140 * 1133 *
1141 * @param node the node against which the error should be reported 1134 * @param node the node against which the error should be reported
1142 * @param errorCode the error code for the error to be generated 1135 * @param errorCode the error code for the error to be generated
1143 */ 1136 */
1144 ErrorResult_ErrorData(AstNode node, ErrorCode errorCode) { 1137 ErrorResult_ErrorData(this.node, this.errorCode);
1145 this.node = node;
1146 this.errorCode = errorCode;
1147 }
1148 } 1138 }
1149 1139
1150 /** 1140 /**
1151 * Instances of the class `InternalResult` represent the result of attempting to evaluate a 1141 * Instances of the class `InternalResult` represent the result of attempting to evaluate a
1152 * expression. 1142 * expression.
1153 */ 1143 */
1154 abstract class EvaluationResultImpl { 1144 abstract class EvaluationResultImpl {
1155 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand); 1145 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand);
1156 1146
1157 /** 1147 /**
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 } 1283 }
1294 1284
1295 /** 1285 /**
1296 * Instances of the class `ReferenceFinder` add reference information for a give n variable to 1286 * Instances of the class `ReferenceFinder` add reference information for a give n variable to
1297 * the bi-directional mapping used to order the evaluation of constants. 1287 * the bi-directional mapping used to order the evaluation of constants.
1298 */ 1288 */
1299 class ReferenceFinder extends RecursiveAstVisitor<Object> { 1289 class ReferenceFinder extends RecursiveAstVisitor<Object> {
1300 /** 1290 /**
1301 * The element representing the variable whose initializer will be visited. 1291 * The element representing the variable whose initializer will be visited.
1302 */ 1292 */
1303 VariableElement _source; 1293 final VariableElement _source;
1304 1294
1305 /** 1295 /**
1306 * A graph in which the nodes are the constant variables and the edges are fro m each variable to 1296 * A graph in which the nodes are the constant variables and the edges are fro m each variable to
1307 * the other constant variables that are referenced in the head's initializer. 1297 * the other constant variables that are referenced in the head's initializer.
1308 */ 1298 */
1309 DirectedGraph<VariableElement> _referenceGraph; 1299 final DirectedGraph<VariableElement> _referenceGraph;
1310 1300
1311 /** 1301 /**
1312 * Initialize a newly created reference finder to find references from the giv en variable to other 1302 * Initialize a newly created reference finder to find references from the giv en variable to other
1313 * variables and to add those references to the given graph. 1303 * variables and to add those references to the given graph.
1314 * 1304 *
1315 * @param source the element representing the variable whose initializer will be visited 1305 * @param source the element representing the variable whose initializer will be visited
1316 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables 1306 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables
1317 * (tails) in their initializers 1307 * (tails) in their initializers
1318 */ 1308 */
1319 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen ceGraph) { 1309 ReferenceFinder(this._source, this._referenceGraph);
1320 this._source = source;
1321 this._referenceGraph = referenceGraph;
1322 }
1323 1310
1324 @override 1311 @override
1325 Object visitSimpleIdentifier(SimpleIdentifier node) { 1312 Object visitSimpleIdentifier(SimpleIdentifier node) {
1326 Element element = node.staticElement; 1313 Element element = node.staticElement;
1327 if (element is PropertyAccessorElement) { 1314 if (element is PropertyAccessorElement) {
1328 element = (element as PropertyAccessorElement).variable; 1315 element = (element as PropertyAccessorElement).variable;
1329 } 1316 }
1330 if (element is VariableElement) { 1317 if (element is VariableElement) {
1331 VariableElement variable = element as VariableElement; 1318 VariableElement variable = element as VariableElement;
1332 if (variable.isConst) { 1319 if (variable.isConst) {
1333 _referenceGraph.addEdge(_source, variable); 1320 _referenceGraph.addEdge(_source, variable);
1334 } 1321 }
1335 } 1322 }
1336 return null; 1323 return null;
1337 } 1324 }
1338 } 1325 }
1339 1326
1340 /** 1327 /**
1341 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid 1328 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid
1342 * compile time constant expression. 1329 * compile time constant expression.
1343 */ 1330 */
1344 class ValidResult extends EvaluationResultImpl { 1331 class ValidResult extends EvaluationResultImpl {
1345 /** 1332 /**
1346 * The value of the expression. 1333 * The value of the expression.
1347 */ 1334 */
1348 DartObjectImpl value; 1335 final DartObjectImpl value;
1349 1336
1350 /** 1337 /**
1351 * Initialize a newly created result to represent the given value. 1338 * Initialize a newly created result to represent the given value.
1352 * 1339 *
1353 * @param value the value of the expression 1340 * @param value the value of the expression
1354 */ 1341 */
1355 ValidResult(DartObjectImpl value) { 1342 ValidResult(this.value);
1356 this.value = value;
1357 }
1358 1343
1359 @override 1344 @override
1360 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToValid(typeProvider, node, t his); 1345 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToValid(typeProvider, node, t his);
1361 1346
1362 /** 1347 /**
1363 * Return the result of applying boolean conversion to this result. 1348 * Return the result of applying boolean conversion to this result.
1364 * 1349 *
1365 * @param node the node against which errors should be reported 1350 * @param node the node against which errors should be reported
1366 * @return the result of applying boolean conversion to the given value 1351 * @return the result of applying boolean conversion to the given value
1367 */ 1352 */
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 } 1770 }
1786 1771
1787 /** 1772 /**
1788 * Instances of the class `BoolState` represent the state of an object represent ing a boolean 1773 * Instances of the class `BoolState` represent the state of an object represent ing a boolean
1789 * value. 1774 * value.
1790 */ 1775 */
1791 class BoolState extends InstanceState { 1776 class BoolState extends InstanceState {
1792 /** 1777 /**
1793 * The value of this instance. 1778 * The value of this instance.
1794 */ 1779 */
1795 bool value = false; 1780 final bool value;
1796 1781
1797 /** 1782 /**
1798 * An instance representing the boolean value 'false'. 1783 * An instance representing the boolean value 'false'.
1799 */ 1784 */
1800 static BoolState FALSE_STATE = new BoolState(false); 1785 static BoolState FALSE_STATE = new BoolState(false);
1801 1786
1802 /** 1787 /**
1803 * An instance representing the boolean value 'true'. 1788 * An instance representing the boolean value 'true'.
1804 */ 1789 */
1805 static BoolState TRUE_STATE = new BoolState(true); 1790 static BoolState TRUE_STATE = new BoolState(true);
1806 1791
1807 /** 1792 /**
1808 * A state that can be used to represent a boolean whose value is not known. 1793 * A state that can be used to represent a boolean whose value is not known.
1809 */ 1794 */
1810 static BoolState UNKNOWN_VALUE = new BoolState(null); 1795 static BoolState UNKNOWN_VALUE = new BoolState(null);
1811 1796
1812 /** 1797 /**
1813 * Return the boolean state representing the given boolean value. 1798 * Return the boolean state representing the given boolean value.
1814 * 1799 *
1815 * @param value the value to be represented 1800 * @param value the value to be represented
1816 * @return the boolean state representing the given boolean value 1801 * @return the boolean state representing the given boolean value
1817 */ 1802 */
1818 static BoolState from(bool value) => value ? BoolState.TRUE_STATE : BoolState. FALSE_STATE; 1803 static BoolState from(bool value) => value ? BoolState.TRUE_STATE : BoolState. FALSE_STATE;
1819 1804
1820 /** 1805 /**
1821 * Initialize a newly created state to represent the given value. 1806 * Initialize a newly created state to represent the given value.
1822 * 1807 *
1823 * @param value the value of this instance 1808 * @param value the value of this instance
1824 */ 1809 */
1825 BoolState(bool value) { 1810 BoolState(this.value);
1826 this.value = value;
1827 }
1828 1811
1829 @override 1812 @override
1830 BoolState convertToBool() => this; 1813 BoolState convertToBool() => this;
1831 1814
1832 @override 1815 @override
1833 StringState convertToString() { 1816 StringState convertToString() {
1834 if (value == null) { 1817 if (value == null) {
1835 return StringState.UNKNOWN_VALUE; 1818 return StringState.UNKNOWN_VALUE;
1836 } 1819 }
1837 return new StringState(value ? "true" : "false"); 1820 return new StringState(value ? "true" : "false");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 String toString() => value == null ? "-unknown-" : (value ? "true" : "false"); 1891 String toString() => value == null ? "-unknown-" : (value ? "true" : "false");
1909 } 1892 }
1910 1893
1911 /** 1894 /**
1912 * Instances of the class `DartObjectImpl` represent an instance of a Dart class . 1895 * Instances of the class `DartObjectImpl` represent an instance of a Dart class .
1913 */ 1896 */
1914 class DartObjectImpl implements DartObject { 1897 class DartObjectImpl implements DartObject {
1915 /** 1898 /**
1916 * The run-time type of this object. 1899 * The run-time type of this object.
1917 */ 1900 */
1918 InterfaceType type; 1901 final InterfaceType type;
1919 1902
1920 /** 1903 /**
1921 * The state of the object. 1904 * The state of the object.
1922 */ 1905 */
1923 InstanceState _state; 1906 final InstanceState _state;
1924 1907
1925 /** 1908 /**
1926 * Initialize a newly created object to have the given type and state. 1909 * Initialize a newly created object to have the given type and state.
1927 * 1910 *
1928 * @param type the run-time type of this object 1911 * @param type the run-time type of this object
1929 * @param state the state of the object 1912 * @param state the state of the object
1930 */ 1913 */
1931 DartObjectImpl(InterfaceType type, InstanceState state) { 1914 DartObjectImpl(this.type, this._state);
1932 this.type = type;
1933 this._state = state;
1934 }
1935 1915
1936 /** 1916 /**
1937 * Return the result of invoking the '+' operator on this object with the give n argument. 1917 * Return the result of invoking the '+' operator on this object with the give n argument.
1938 * 1918 *
1939 * @param typeProvider the type provider used to find known types 1919 * @param typeProvider the type provider used to find known types
1940 * @param rightOperand the right-hand operand of the operation 1920 * @param rightOperand the right-hand operand of the operation
1941 * @return the result of invoking the '+' operator on this object with the giv en argument 1921 * @return the result of invoking the '+' operator on this object with the giv en argument
1942 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 1922 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
1943 */ 1923 */
1944 DartObjectImpl add(TypeProvider typeProvider, DartObjectImpl rightOperand) { 1924 DartObjectImpl add(TypeProvider typeProvider, DartObjectImpl rightOperand) {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 } 2338 }
2359 2339
2360 /** 2340 /**
2361 * Instances of the class `DoubleState` represent the state of an object represe nting a 2341 * Instances of the class `DoubleState` represent the state of an object represe nting a
2362 * double. 2342 * double.
2363 */ 2343 */
2364 class DoubleState extends NumState { 2344 class DoubleState extends NumState {
2365 /** 2345 /**
2366 * The value of this instance. 2346 * The value of this instance.
2367 */ 2347 */
2368 double value = 0.0; 2348 final double value;
2369 2349
2370 /** 2350 /**
2371 * A state that can be used to represent a double whose value is not known. 2351 * A state that can be used to represent a double whose value is not known.
2372 */ 2352 */
2373 static DoubleState UNKNOWN_VALUE = new DoubleState(null); 2353 static DoubleState UNKNOWN_VALUE = new DoubleState(null);
2374 2354
2375 /** 2355 /**
2376 * Initialize a newly created state to represent a double with the given value . 2356 * Initialize a newly created state to represent a double with the given value .
2377 * 2357 *
2378 * @param value the value of this instance 2358 * @param value the value of this instance
2379 */ 2359 */
2380 DoubleState(double value) { 2360 DoubleState(this.value);
2381 this.value = value;
2382 }
2383 2361
2384 @override 2362 @override
2385 NumState add(InstanceState rightOperand) { 2363 NumState add(InstanceState rightOperand) {
2386 assertNumOrNull(rightOperand); 2364 assertNumOrNull(rightOperand);
2387 if (value == null) { 2365 if (value == null) {
2388 return UNKNOWN_VALUE; 2366 return UNKNOWN_VALUE;
2389 } 2367 }
2390 if (rightOperand is IntState) { 2368 if (rightOperand is IntState) {
2391 int rightValue = rightOperand.value; 2369 int rightValue = rightOperand.value;
2392 if (rightValue == null) { 2370 if (rightValue == null) {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 } 2826 }
2849 2827
2850 /** 2828 /**
2851 * Instances of the class `EvaluationException` represent a run-time exception t hat would be 2829 * Instances of the class `EvaluationException` represent a run-time exception t hat would be
2852 * thrown during the evaluation of Dart code. 2830 * thrown during the evaluation of Dart code.
2853 */ 2831 */
2854 class EvaluationException extends JavaException { 2832 class EvaluationException extends JavaException {
2855 /** 2833 /**
2856 * The error code associated with the exception. 2834 * The error code associated with the exception.
2857 */ 2835 */
2858 ErrorCode errorCode; 2836 final ErrorCode errorCode;
2859 2837
2860 /** 2838 /**
2861 * Initialize a newly created exception to have the given error code. 2839 * Initialize a newly created exception to have the given error code.
2862 * 2840 *
2863 * @param errorCode the error code associated with the exception 2841 * @param errorCode the error code associated with the exception
2864 */ 2842 */
2865 EvaluationException(ErrorCode errorCode) { 2843 EvaluationException(this.errorCode);
2866 this.errorCode = errorCode;
2867 }
2868 } 2844 }
2869 2845
2870 /** 2846 /**
2871 * Instances of the class `FunctionState` represent the state of an object repre senting a 2847 * Instances of the class `FunctionState` represent the state of an object repre senting a
2872 * function. 2848 * function.
2873 */ 2849 */
2874 class FunctionState extends InstanceState { 2850 class FunctionState extends InstanceState {
2875 /** 2851 /**
2876 * The element representing the function being modeled. 2852 * The element representing the function being modeled.
2877 */ 2853 */
2878 ExecutableElement _element; 2854 final ExecutableElement _element;
2879 2855
2880 /** 2856 /**
2881 * Initialize a newly created state to represent the given function. 2857 * Initialize a newly created state to represent the given function.
2882 * 2858 *
2883 * @param element the element representing the function being modeled 2859 * @param element the element representing the function being modeled
2884 */ 2860 */
2885 FunctionState(ExecutableElement element) { 2861 FunctionState(this._element);
2886 this._element = element;
2887 }
2888 2862
2889 @override 2863 @override
2890 StringState convertToString() { 2864 StringState convertToString() {
2891 if (_element == null) { 2865 if (_element == null) {
2892 return StringState.UNKNOWN_VALUE; 2866 return StringState.UNKNOWN_VALUE;
2893 } 2867 }
2894 return new StringState(_element.name); 2868 return new StringState(_element.name);
2895 } 2869 }
2896 2870
2897 @override 2871 @override
(...skipping 27 matching lines...) Expand all
2925 } 2899 }
2926 2900
2927 /** 2901 /**
2928 * Instances of the class `GenericState` represent the state of an object repres enting a Dart 2902 * Instances of the class `GenericState` represent the state of an object repres enting a Dart
2929 * object for which there is no more specific state. 2903 * object for which there is no more specific state.
2930 */ 2904 */
2931 class GenericState extends InstanceState { 2905 class GenericState extends InstanceState {
2932 /** 2906 /**
2933 * The values of the fields of this instance. 2907 * The values of the fields of this instance.
2934 */ 2908 */
2935 Map<String, DartObjectImpl> _fieldMap = new Map<String, DartObjectImpl>(); 2909 final Map<String, DartObjectImpl> _fieldMap;
2936 2910
2937 /** 2911 /**
2938 * A state that can be used to represent an object whose state is not known. 2912 * A state that can be used to represent an object whose state is not known.
2939 */ 2913 */
2940 static GenericState UNKNOWN_VALUE = new GenericState(new Map<String, DartObjec tImpl>()); 2914 static GenericState UNKNOWN_VALUE = new GenericState(new Map<String, DartObjec tImpl>());
2941 2915
2942 /** 2916 /**
2943 * Initialize a newly created state to represent a newly created object. 2917 * Initialize a newly created state to represent a newly created object.
2944 * 2918 *
2945 * @param fieldMap the values of the fields of this instance 2919 * @param fieldMap the values of the fields of this instance
2946 */ 2920 */
2947 GenericState(Map<String, DartObjectImpl> fieldMap) { 2921 GenericState(this._fieldMap);
2948 this._fieldMap = fieldMap;
2949 }
2950 2922
2951 @override 2923 @override
2952 StringState convertToString() => StringState.UNKNOWN_VALUE; 2924 StringState convertToString() => StringState.UNKNOWN_VALUE;
2953 2925
2954 @override 2926 @override
2955 bool operator ==(Object object) { 2927 bool operator ==(Object object) {
2956 if (object is! GenericState) { 2928 if (object is! GenericState) {
2957 return false; 2929 return false;
2958 } 2930 }
2959 GenericState state = object as GenericState; 2931 GenericState state = object as GenericState;
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 } 3365 }
3394 } 3366 }
3395 3367
3396 /** 3368 /**
3397 * Instances of the class `IntState` represent the state of an object representi ng an int. 3369 * Instances of the class `IntState` represent the state of an object representi ng an int.
3398 */ 3370 */
3399 class IntState extends NumState { 3371 class IntState extends NumState {
3400 /** 3372 /**
3401 * The value of this instance. 3373 * The value of this instance.
3402 */ 3374 */
3403 int value = 0; 3375 final int value;
3404 3376
3405 /** 3377 /**
3406 * A state that can be used to represent an int whose value is not known. 3378 * A state that can be used to represent an int whose value is not known.
3407 */ 3379 */
3408 static IntState UNKNOWN_VALUE = new IntState(null); 3380 static IntState UNKNOWN_VALUE = new IntState(null);
3409 3381
3410 /** 3382 /**
3411 * Initialize a newly created state to represent an int with the given value. 3383 * Initialize a newly created state to represent an int with the given value.
3412 * 3384 *
3413 * @param value the value of this instance 3385 * @param value the value of this instance
3414 */ 3386 */
3415 IntState(int value) { 3387 IntState(this.value);
3416 this.value = value;
3417 }
3418 3388
3419 @override 3389 @override
3420 NumState add(InstanceState rightOperand) { 3390 NumState add(InstanceState rightOperand) {
3421 assertNumOrNull(rightOperand); 3391 assertNumOrNull(rightOperand);
3422 if (value == null) { 3392 if (value == null) {
3423 if (rightOperand is DoubleState) { 3393 if (rightOperand is DoubleState) {
3424 return DoubleState.UNKNOWN_VALUE; 3394 return DoubleState.UNKNOWN_VALUE;
3425 } 3395 }
3426 return UNKNOWN_VALUE; 3396 return UNKNOWN_VALUE;
3427 } 3397 }
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
3840 } 3810 }
3841 3811
3842 /** 3812 /**
3843 * The unique instance of the class `ListState` represents the state of an objec t representing 3813 * The unique instance of the class `ListState` represents the state of an objec t representing
3844 * a list. 3814 * a list.
3845 */ 3815 */
3846 class ListState extends InstanceState { 3816 class ListState extends InstanceState {
3847 /** 3817 /**
3848 * The elements of the list. 3818 * The elements of the list.
3849 */ 3819 */
3850 List<DartObjectImpl> _elements; 3820 final List<DartObjectImpl> _elements;
3851 3821
3852 /** 3822 /**
3853 * Initialize a newly created state to represent a list with the given element s. 3823 * Initialize a newly created state to represent a list with the given element s.
3854 * 3824 *
3855 * @param elements the elements of the list 3825 * @param elements the elements of the list
3856 */ 3826 */
3857 ListState(List<DartObjectImpl> elements) { 3827 ListState(this._elements);
3858 this._elements = elements;
3859 }
3860 3828
3861 @override 3829 @override
3862 StringState convertToString() => StringState.UNKNOWN_VALUE; 3830 StringState convertToString() => StringState.UNKNOWN_VALUE;
3863 3831
3864 @override 3832 @override
3865 BoolState equalEqual(InstanceState rightOperand) { 3833 BoolState equalEqual(InstanceState rightOperand) {
3866 assertBoolNumStringOrNull(rightOperand); 3834 assertBoolNumStringOrNull(rightOperand);
3867 if (rightOperand is DynamicState) { 3835 if (rightOperand is DynamicState) {
3868 return BoolState.UNKNOWN_VALUE; 3836 return BoolState.UNKNOWN_VALUE;
3869 } 3837 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3930 } 3898 }
3931 3899
3932 /** 3900 /**
3933 * The unique instance of the class `ListState` represents the state of an objec t representing 3901 * The unique instance of the class `ListState` represents the state of an objec t representing
3934 * a map. 3902 * a map.
3935 */ 3903 */
3936 class MapState extends InstanceState { 3904 class MapState extends InstanceState {
3937 /** 3905 /**
3938 * The entries in the map. 3906 * The entries in the map.
3939 */ 3907 */
3940 Map<DartObjectImpl, DartObjectImpl> _entries; 3908 final Map<DartObjectImpl, DartObjectImpl> _entries;
3941 3909
3942 /** 3910 /**
3943 * Initialize a newly created state to represent a map with the given entries. 3911 * Initialize a newly created state to represent a map with the given entries.
3944 * 3912 *
3945 * @param entries the entries in the map 3913 * @param entries the entries in the map
3946 */ 3914 */
3947 MapState(Map<DartObjectImpl, DartObjectImpl> entries) { 3915 MapState(this._entries);
3948 this._entries = entries;
3949 }
3950 3916
3951 @override 3917 @override
3952 StringState convertToString() => StringState.UNKNOWN_VALUE; 3918 StringState convertToString() => StringState.UNKNOWN_VALUE;
3953 3919
3954 @override 3920 @override
3955 BoolState equalEqual(InstanceState rightOperand) { 3921 BoolState equalEqual(InstanceState rightOperand) {
3956 assertBoolNumStringOrNull(rightOperand); 3922 assertBoolNumStringOrNull(rightOperand);
3957 if (rightOperand is DynamicState) { 3923 if (rightOperand is DynamicState) {
3958 return BoolState.UNKNOWN_VALUE; 3924 return BoolState.UNKNOWN_VALUE;
3959 } 3925 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
4179 } 4145 }
4180 4146
4181 /** 4147 /**
4182 * Instances of the class `StringState` represent the state of an object represe nting a 4148 * Instances of the class `StringState` represent the state of an object represe nting a
4183 * string. 4149 * string.
4184 */ 4150 */
4185 class StringState extends InstanceState { 4151 class StringState extends InstanceState {
4186 /** 4152 /**
4187 * The value of this instance. 4153 * The value of this instance.
4188 */ 4154 */
4189 String value; 4155 final String value;
4190 4156
4191 /** 4157 /**
4192 * A state that can be used to represent a double whose value is not known. 4158 * A state that can be used to represent a double whose value is not known.
4193 */ 4159 */
4194 static StringState UNKNOWN_VALUE = new StringState(null); 4160 static StringState UNKNOWN_VALUE = new StringState(null);
4195 4161
4196 /** 4162 /**
4197 * Initialize a newly created state to represent the given value. 4163 * Initialize a newly created state to represent the given value.
4198 * 4164 *
4199 * @param value the value of this instance 4165 * @param value the value of this instance
4200 */ 4166 */
4201 StringState(String value) { 4167 StringState(this.value);
4202 this.value = value;
4203 }
4204 4168
4205 @override 4169 @override
4206 StringState concatenate(InstanceState rightOperand) { 4170 StringState concatenate(InstanceState rightOperand) {
4207 if (value == null) { 4171 if (value == null) {
4208 return UNKNOWN_VALUE; 4172 return UNKNOWN_VALUE;
4209 } 4173 }
4210 if (rightOperand is StringState) { 4174 if (rightOperand is StringState) {
4211 String rightValue = rightOperand.value; 4175 String rightValue = rightOperand.value;
4212 if (rightValue == null) { 4176 if (rightValue == null) {
4213 return UNKNOWN_VALUE; 4177 return UNKNOWN_VALUE;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4260 } 4224 }
4261 4225
4262 /** 4226 /**
4263 * Instances of the class `StringState` represent the state of an object represe nting a 4227 * Instances of the class `StringState` represent the state of an object represe nting a
4264 * symbol. 4228 * symbol.
4265 */ 4229 */
4266 class SymbolState extends InstanceState { 4230 class SymbolState extends InstanceState {
4267 /** 4231 /**
4268 * The value of this instance. 4232 * The value of this instance.
4269 */ 4233 */
4270 String value; 4234 final String value;
4271 4235
4272 /** 4236 /**
4273 * Initialize a newly created state to represent the given value. 4237 * Initialize a newly created state to represent the given value.
4274 * 4238 *
4275 * @param value the value of this instance 4239 * @param value the value of this instance
4276 */ 4240 */
4277 SymbolState(String value) { 4241 SymbolState(this.value);
4278 this.value = value;
4279 }
4280 4242
4281 @override 4243 @override
4282 StringState convertToString() { 4244 StringState convertToString() {
4283 if (value == null) { 4245 if (value == null) {
4284 return StringState.UNKNOWN_VALUE; 4246 return StringState.UNKNOWN_VALUE;
4285 } 4247 }
4286 return new StringState(value); 4248 return new StringState(value);
4287 } 4249 }
4288 4250
4289 @override 4251 @override
(...skipping 30 matching lines...) Expand all
4320 String toString() => value == null ? "-unknown-" : "#${value}"; 4282 String toString() => value == null ? "-unknown-" : "#${value}";
4321 } 4283 }
4322 4284
4323 /** 4285 /**
4324 * Instances of the class `TypeState` represent the state of an object represent ing a type. 4286 * Instances of the class `TypeState` represent the state of an object represent ing a type.
4325 */ 4287 */
4326 class TypeState extends InstanceState { 4288 class TypeState extends InstanceState {
4327 /** 4289 /**
4328 * The element representing the type being modeled. 4290 * The element representing the type being modeled.
4329 */ 4291 */
4330 Element _element; 4292 final Element _element;
4331 4293
4332 /** 4294 /**
4333 * Initialize a newly created state to represent the given value. 4295 * Initialize a newly created state to represent the given value.
4334 * 4296 *
4335 * @param element the element representing the type being modeled 4297 * @param element the element representing the type being modeled
4336 */ 4298 */
4337 TypeState(Element element) { 4299 TypeState(this._element);
4338 this._element = element;
4339 }
4340 4300
4341 @override 4301 @override
4342 StringState convertToString() { 4302 StringState convertToString() {
4343 if (_element == null) { 4303 if (_element == null) {
4344 return StringState.UNKNOWN_VALUE; 4304 return StringState.UNKNOWN_VALUE;
4345 } 4305 }
4346 return new StringState(_element.name); 4306 return new StringState(_element.name);
4347 } 4307 }
4348 4308
4349 @override 4309 @override
(...skipping 19 matching lines...) Expand all
4369 4329
4370 @override 4330 @override
4371 String get typeName => "Type"; 4331 String get typeName => "Type";
4372 4332
4373 @override 4333 @override
4374 int get hashCode => _element == null ? 0 : _element.hashCode; 4334 int get hashCode => _element == null ? 0 : _element.hashCode;
4375 4335
4376 @override 4336 @override
4377 String toString() => _element == null ? "-unknown-" : _element.name; 4337 String toString() => _element == null ? "-unknown-" : _element.name;
4378 } 4338 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698