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

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

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