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

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

Issue 68233003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3
3 library engine.constant; 4 library engine.constant;
5
4 import 'java_core.dart'; 6 import 'java_core.dart';
5 import 'source.dart' show Source; 7 import 'source.dart' show Source;
6 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; 8 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode;
7 import 'scanner.dart' show TokenType; 9 import 'scanner.dart' show TokenType;
8 import 'ast.dart'; 10 import 'ast.dart';
9 import 'element.dart'; 11 import 'element.dart';
10 import 'engine.dart' show AnalysisEngine; 12 import 'engine.dart' show AnalysisEngine;
13
11 /** 14 /**
12 * Instances of the class `ConstantEvaluator` evaluate constant expressions to p roduce their 15 * Instances of the class `ConstantEvaluator` evaluate constant expressions to p roduce their
13 * compile-time value. According to the Dart Language Specification: <blockquote > A constant 16 * compile-time value. According to the Dart Language Specification: <blockquote > A constant
14 * expression is one of the following: 17 * expression is one of the following:
15 * 18 *
16 * * A literal number. 19 * * A literal number.
17 * * A literal boolean. 20 * * A literal boolean.
18 * * A literal string where any interpolated expression is a compile-time consta nt that evaluates 21 * * A literal string where any interpolated expression is a compile-time consta nt that evaluates
19 * to a numeric, string or boolean value or to `null`. 22 * to a numeric, string or boolean value or to `null`.
20 * * `null`. 23 * * `null`.
(...skipping 20 matching lines...) Expand all
41 * 44 *
42 * </blockquote> The values returned by instances of this class are therefore `n ull` and 45 * </blockquote> The values returned by instances of this class are therefore `n ull` and
43 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and 46 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and
44 * `DartObject`. 47 * `DartObject`.
45 * 48 *
46 * In addition, this class defines several values that can be returned to indica te various 49 * In addition, this class defines several values that can be returned to indica te various
47 * conditions encountered during evaluation. These are documented with the stati c field that define 50 * conditions encountered during evaluation. These are documented with the stati c field that define
48 * those values. 51 * those values.
49 */ 52 */
50 class ConstantEvaluator { 53 class ConstantEvaluator {
51
52 /** 54 /**
53 * The source containing the expression(s) that will be evaluated. 55 * The source containing the expression(s) that will be evaluated.
54 */ 56 */
55 Source _source; 57 Source _source;
56 58
57 /** 59 /**
58 * Initialize a newly created evaluator to evaluate expressions in the given s ource. 60 * Initialize a newly created evaluator to evaluate expressions in the given s ource.
59 * 61 *
60 * @param source the source containing the expression(s) that will be evaluate d 62 * @param source the source containing the expression(s) that will be evaluate d
61 */ 63 */
62 ConstantEvaluator(Source source) { 64 ConstantEvaluator(Source source) {
63 this._source = source; 65 this._source = source;
64 } 66 }
67
65 EvaluationResult evaluate(Expression expression) { 68 EvaluationResult evaluate(Expression expression) {
66 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); 69 EvaluationResultImpl result = expression.accept(new ConstantVisitor());
67 if (result is ValidResult) { 70 if (result is ValidResult) {
68 return EvaluationResult.forValue(((result as ValidResult)).value); 71 return EvaluationResult.forValue((result as ValidResult).value);
69 } 72 }
70 List<AnalysisError> errors = new List<AnalysisError>(); 73 List<AnalysisError> errors = new List<AnalysisError>();
71 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { 74 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) {
72 ASTNode node = data.node; 75 ASTNode node = data.node;
73 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, [])); 76 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, []));
74 } 77 }
75 return EvaluationResult.forErrors(new List.from(errors)); 78 return EvaluationResult.forErrors(new List.from(errors));
76 } 79 }
77 } 80 }
81
78 /** 82 /**
79 * Instances of the class `EvaluationResult` represent the result of attempting to evaluate an 83 * Instances of the class `EvaluationResult` represent the result of attempting to evaluate an
80 * expression. 84 * expression.
81 */ 85 */
82 class EvaluationResult { 86 class EvaluationResult {
83
84 /** 87 /**
85 * Return an evaluation result representing the result of evaluating an expres sion that is not a 88 * Return an evaluation result representing the result of evaluating an expres sion that is not a
86 * compile-time constant because of the given errors. 89 * compile-time constant because of the given errors.
87 * 90 *
88 * @param errors the errors that should be reported for the expression(s) that were evaluated 91 * @param errors the errors that should be reported for the expression(s) that were evaluated
89 * @return the result of evaluating an expression that is not a compile-time c onstant 92 * @return the result of evaluating an expression that is not a compile-time c onstant
90 */ 93 */
91 static EvaluationResult forErrors(List<AnalysisError> errors) => new Evaluatio nResult(null, errors); 94 static EvaluationResult forErrors(List<AnalysisError> errors) => new Evaluatio nResult(null, errors);
92 95
93 /** 96 /**
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS : _errors; 133 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS : _errors;
131 134
132 /** 135 /**
133 * Return `true` if the expression is a compile-time constant expression that would not 136 * Return `true` if the expression is a compile-time constant expression that would not
134 * throw an exception when evaluated. 137 * throw an exception when evaluated.
135 * 138 *
136 * @return `true` if the expression is a valid compile-time constant expressio n 139 * @return `true` if the expression is a valid compile-time constant expressio n
137 */ 140 */
138 bool get isValid => _errors == null; 141 bool get isValid => _errors == null;
139 } 142 }
143
140 /** 144 /**
141 * Instances of the class `ConstantFinder` are used to traverse the AST structur es of all of 145 * Instances of the class `ConstantFinder` are used to traverse the AST structur es of all of
142 * the compilation units being resolved and build a table mapping constant varia ble elements to the 146 * the compilation units being resolved and build a table mapping constant varia ble elements to the
143 * declarations of those variables. 147 * declarations of those variables.
144 */ 148 */
145 class ConstantFinder extends RecursiveASTVisitor<Object> { 149 class ConstantFinder extends RecursiveASTVisitor<Object> {
146
147 /** 150 /**
148 * A table mapping constant variable elements to the declarations of those var iables. 151 * A table mapping constant variable elements to the declarations of those var iables.
149 */ 152 */
150 final Map<VariableElement, VariableDeclaration> variableMap = new Map<Variable Element, VariableDeclaration>(); 153 final Map<VariableElement, VariableDeclaration> variableMap = new Map<Variable Element, VariableDeclaration>();
154
151 Object visitVariableDeclaration(VariableDeclaration node) { 155 Object visitVariableDeclaration(VariableDeclaration node) {
152 super.visitVariableDeclaration(node); 156 super.visitVariableDeclaration(node);
153 Expression initializer = node.initializer; 157 Expression initializer = node.initializer;
154 if (initializer != null && node.isConst) { 158 if (initializer != null && node.isConst) {
155 VariableElement element = node.element; 159 VariableElement element = node.element;
156 if (element != null) { 160 if (element != null) {
157 variableMap[element] = node; 161 variableMap[element] = node;
158 } 162 }
159 } 163 }
160 return null; 164 return null;
161 } 165 }
162 } 166 }
167
163 /** 168 /**
164 * Instances of the class `ConstantValueComputer` compute the values of constant variables in 169 * Instances of the class `ConstantValueComputer` compute the values of constant variables in
165 * one or more compilation units. The expected usage pattern is for the compilat ion units to be 170 * one or more compilation units. The expected usage pattern is for the compilat ion units to be
166 * added to this computer using the method [add] and then for the method 171 * added to this computer using the method [add] and then for the method
167 * [computeValues] to invoked exactly once. Any use of an instance after invokin g the 172 * [computeValues] to invoked exactly once. Any use of an instance after invokin g the
168 * method [computeValues] will result in unpredictable behavior. 173 * method [computeValues] will result in unpredictable behavior.
169 */ 174 */
170 class ConstantValueComputer { 175 class ConstantValueComputer {
171
172 /** 176 /**
173 * The object used to find constant variables in the compilation units that we re added. 177 * The object used to find constant variables in the compilation units that we re added.
174 */ 178 */
175 ConstantFinder _constantFinder = new ConstantFinder(); 179 ConstantFinder _constantFinder = new ConstantFinder();
176 180
177 /** 181 /**
178 * A graph in which the nodes are the constant variables and the edges are fro m each variable to 182 * A graph in which the nodes are the constant variables and the edges are fro m each variable to
179 * the other constant variables that are referenced in the head's initializer. 183 * the other constant variables that are referenced in the head's initializer.
180 */ 184 */
181 DirectedGraph<VariableElement> _referenceGraph = new DirectedGraph<VariableEle ment>(); 185 DirectedGraph<VariableElement> _referenceGraph = new DirectedGraph<VariableEle ment>();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 * Compute a value for the given variable. 234 * Compute a value for the given variable.
231 * 235 *
232 * @param variable the variable for which a value is to be computed 236 * @param variable the variable for which a value is to be computed
233 */ 237 */
234 void computeValueFor(VariableElement variable) { 238 void computeValueFor(VariableElement variable) {
235 VariableDeclaration declaration = _declarationMap[variable]; 239 VariableDeclaration declaration = _declarationMap[variable];
236 if (declaration == null) { 240 if (declaration == null) {
237 return; 241 return;
238 } 242 }
239 EvaluationResultImpl result = declaration.initializer.accept(new ConstantVis itor()); 243 EvaluationResultImpl result = declaration.initializer.accept(new ConstantVis itor());
240 ((variable as VariableElementImpl)).evaluationResult = result; 244 (variable as VariableElementImpl).evaluationResult = result;
241 if (result is ErrorResult) { 245 if (result is ErrorResult) {
242 List<AnalysisError> errors = new List<AnalysisError>(); 246 List<AnalysisError> errors = new List<AnalysisError>();
243 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { 247 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) {
244 ASTNode node = data.node; 248 ASTNode node = data.node;
245 Source source = variable.getAncestor(CompilationUnitElement).source; 249 Source source = variable.getAncestor(CompilationUnitElement).source;
246 errors.add(new AnalysisError.con2(source, node.offset, node.length, data .errorCode, [])); 250 errors.add(new AnalysisError.con2(source, node.offset, node.length, data .errorCode, []));
247 } 251 }
248 } 252 }
249 } 253 }
250 254
251 /** 255 /**
252 * Generate an error indicating that the given variable is not a valid compile -time constant 256 * Generate an error indicating that the given variable is not a valid compile -time constant
253 * because it references at least one of the variables in the given cycle, eac h of which directly 257 * because it references at least one of the variables in the given cycle, eac h of which directly
254 * or indirectly references the variable. 258 * or indirectly references the variable.
255 * 259 *
256 * @param variablesInCycle the variables in the cycle that includes the given variable 260 * @param variablesInCycle the variables in the cycle that includes the given variable
257 * @param variable the variable that is not a valid compile-time constant 261 * @param variable the variable that is not a valid compile-time constant
258 */ 262 */
259 void generateCycleError(List<VariableElement> variablesInCycle, VariableElemen t variable) { 263 void generateCycleError(List<VariableElement> variablesInCycle, VariableElemen t variable) {
260 } 264 }
261 } 265 }
266
262 /** 267 /**
263 * Instances of the class `ConstantVisitor` evaluate constant expressions to pro duce their 268 * Instances of the class `ConstantVisitor` evaluate constant expressions to pro duce their
264 * compile-time value. According to the Dart Language Specification: <blockquote > A constant 269 * compile-time value. According to the Dart Language Specification: <blockquote > A constant
265 * expression is one of the following: 270 * expression is one of the following:
266 * 271 *
267 * * A literal number. 272 * * A literal number.
268 * * A literal boolean. 273 * * A literal boolean.
269 * * A literal string where any interpolated expression is a compile-time consta nt that evaluates 274 * * A literal string where any interpolated expression is a compile-time consta nt that evaluates
270 * to a numeric, string or boolean value or to `null`. 275 * to a numeric, string or boolean value or to `null`.
271 * * `null`. 276 * * `null`.
(...skipping 25 matching lines...) Expand all
297 EvaluationResultImpl result = null; 302 EvaluationResultImpl result = null;
298 for (StringLiteral string in node.strings) { 303 for (StringLiteral string in node.strings) {
299 if (result == null) { 304 if (result == null) {
300 result = string.accept(this); 305 result = string.accept(this);
301 } else { 306 } else {
302 result = result.concatenate(node, string.accept(this)); 307 result = result.concatenate(node, string.accept(this));
303 } 308 }
304 } 309 }
305 return result; 310 return result;
306 } 311 }
312
307 EvaluationResultImpl visitBinaryExpression(BinaryExpression node) { 313 EvaluationResultImpl visitBinaryExpression(BinaryExpression node) {
308 EvaluationResultImpl leftResult = node.leftOperand.accept(this); 314 EvaluationResultImpl leftResult = node.leftOperand.accept(this);
309 EvaluationResultImpl rightResult = node.rightOperand.accept(this); 315 EvaluationResultImpl rightResult = node.rightOperand.accept(this);
310 TokenType operatorType = node.operator.type; 316 TokenType operatorType = node.operator.type;
311 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) { 317 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) {
312 if (leftResult is ValidResult && ((leftResult as ValidResult)).isNull || r ightResult is ValidResult && ((rightResult as ValidResult)).isNull) { 318 if (leftResult is ValidResult && (leftResult as ValidResult).isNull || rig htResult is ValidResult && (rightResult as ValidResult).isNull) {
313 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); 319 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
314 } 320 }
315 } 321 }
316 while (true) { 322 while (true) {
317 if (operatorType == TokenType.AMPERSAND) { 323 if (operatorType == TokenType.AMPERSAND) {
318 return leftResult.bitAnd(node, rightResult); 324 return leftResult.bitAnd(node, rightResult);
319 } else if (operatorType == TokenType.AMPERSAND_AMPERSAND) { 325 } else if (operatorType == TokenType.AMPERSAND_AMPERSAND) {
320 return leftResult.logicalAnd(node, rightResult); 326 return leftResult.logicalAnd(node, rightResult);
321 } else if (operatorType == TokenType.BANG_EQ) { 327 } else if (operatorType == TokenType.BANG_EQ) {
322 return leftResult.notEqual(node, rightResult); 328 return leftResult.notEqual(node, rightResult);
(...skipping 27 matching lines...) Expand all
350 return leftResult.times(node, rightResult); 356 return leftResult.times(node, rightResult);
351 } else if (operatorType == TokenType.SLASH) { 357 } else if (operatorType == TokenType.SLASH) {
352 return leftResult.divide(node, rightResult); 358 return leftResult.divide(node, rightResult);
353 } else if (operatorType == TokenType.TILDE_SLASH) { 359 } else if (operatorType == TokenType.TILDE_SLASH) {
354 return leftResult.integerDivide(node, rightResult); 360 return leftResult.integerDivide(node, rightResult);
355 } 361 }
356 break; 362 break;
357 } 363 }
358 return error(node, null); 364 return error(node, null);
359 } 365 }
366
360 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => node.value ? ValidResult.RESULT_TRUE : ValidResult.RESULT_FALSE; 367 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => node.value ? ValidResult.RESULT_TRUE : ValidResult.RESULT_FALSE;
368
361 EvaluationResultImpl visitConditionalExpression(ConditionalExpression node) { 369 EvaluationResultImpl visitConditionalExpression(ConditionalExpression node) {
362 Expression condition = node.condition; 370 Expression condition = node.condition;
363 EvaluationResultImpl conditionResult = condition.accept(this); 371 EvaluationResultImpl conditionResult = condition.accept(this);
364 conditionResult = conditionResult.applyBooleanConversion(condition); 372 conditionResult = conditionResult.applyBooleanConversion(condition);
365 if (conditionResult is ErrorResult) { 373 if (conditionResult is ErrorResult) {
366 return conditionResult; 374 return conditionResult;
367 } 375 }
368 EvaluationResultImpl thenResult = node.thenExpression.accept(this); 376 EvaluationResultImpl thenResult = node.thenExpression.accept(this);
369 if (thenResult is ErrorResult) { 377 if (thenResult is ErrorResult) {
370 return thenResult; 378 return thenResult;
371 } 379 }
372 EvaluationResultImpl elseResult = node.elseExpression.accept(this); 380 EvaluationResultImpl elseResult = node.elseExpression.accept(this);
373 if (elseResult is ErrorResult) { 381 if (elseResult is ErrorResult) {
374 return elseResult; 382 return elseResult;
375 } 383 }
376 return (identical(conditionResult, ValidResult.RESULT_TRUE)) ? thenResult : elseResult; 384 return (identical(conditionResult, ValidResult.RESULT_TRUE)) ? thenResult : elseResult;
377 } 385 }
386
378 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => new ValidResult (node.value); 387 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => new ValidResult (node.value);
388
379 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio n node) { 389 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio n node) {
380 if (!node.isConst) { 390 if (!node.isConst) {
381 return error(node, null); 391 return error(node, null);
382 } 392 }
383 ConstructorElement constructor = node.staticElement; 393 ConstructorElement constructor = node.staticElement;
384 if (constructor != null && constructor.isConst) { 394 if (constructor != null && constructor.isConst) {
385 node.argumentList.accept(this); 395 node.argumentList.accept(this);
386 return ValidResult.RESULT_OBJECT; 396 return ValidResult.RESULT_OBJECT;
387 } 397 }
388 return error(node, null); 398 return error(node, null);
389 } 399 }
400
390 EvaluationResultImpl visitIntegerLiteral(IntegerLiteral node) => new ValidResu lt(node.value); 401 EvaluationResultImpl visitIntegerLiteral(IntegerLiteral node) => new ValidResu lt(node.value);
402
391 EvaluationResultImpl visitInterpolationExpression(InterpolationExpression node ) { 403 EvaluationResultImpl visitInterpolationExpression(InterpolationExpression node ) {
392 EvaluationResultImpl result = node.expression.accept(this); 404 EvaluationResultImpl result = node.expression.accept(this);
393 return result.performToString(node); 405 return result.performToString(node);
394 } 406 }
407
395 EvaluationResultImpl visitInterpolationString(InterpolationString node) => new ValidResult(node.value); 408 EvaluationResultImpl visitInterpolationString(InterpolationString node) => new ValidResult(node.value);
409
396 EvaluationResultImpl visitListLiteral(ListLiteral node) { 410 EvaluationResultImpl visitListLiteral(ListLiteral node) {
397 if (node.constKeyword == null) { 411 if (node.constKeyword == null) {
398 return new ErrorResult.con1(node, CompileTimeErrorCode.MISSING_CONST_IN_LI ST_LITERAL); 412 return new ErrorResult.con1(node, CompileTimeErrorCode.MISSING_CONST_IN_LI ST_LITERAL);
399 } 413 }
400 ErrorResult result = null; 414 ErrorResult result = null;
401 for (Expression element in node.elements) { 415 for (Expression element in node.elements) {
402 result = union(result, element.accept(this)); 416 result = union(result, element.accept(this));
403 } 417 }
404 if (result != null) { 418 if (result != null) {
405 return result; 419 return result;
406 } 420 }
407 return ValidResult.RESULT_OBJECT; 421 return ValidResult.RESULT_OBJECT;
408 } 422 }
423
409 EvaluationResultImpl visitMapLiteral(MapLiteral node) { 424 EvaluationResultImpl visitMapLiteral(MapLiteral node) {
410 if (node.constKeyword == null) { 425 if (node.constKeyword == null) {
411 return new ErrorResult.con1(node, CompileTimeErrorCode.MISSING_CONST_IN_MA P_LITERAL); 426 return new ErrorResult.con1(node, CompileTimeErrorCode.MISSING_CONST_IN_MA P_LITERAL);
412 } 427 }
413 ErrorResult result = null; 428 ErrorResult result = null;
414 for (MapLiteralEntry entry in node.entries) { 429 for (MapLiteralEntry entry in node.entries) {
415 result = union(result, entry.key.accept(this)); 430 result = union(result, entry.key.accept(this));
416 result = union(result, entry.value.accept(this)); 431 result = union(result, entry.value.accept(this));
417 } 432 }
418 if (result != null) { 433 if (result != null) {
419 return result; 434 return result;
420 } 435 }
421 return ValidResult.RESULT_OBJECT; 436 return ValidResult.RESULT_OBJECT;
422 } 437 }
438
423 EvaluationResultImpl visitMethodInvocation(MethodInvocation node) { 439 EvaluationResultImpl visitMethodInvocation(MethodInvocation node) {
424 Element element = node.methodName.staticElement; 440 Element element = node.methodName.staticElement;
425 if (element is FunctionElement) { 441 if (element is FunctionElement) {
426 FunctionElement function = element as FunctionElement; 442 FunctionElement function = element as FunctionElement;
427 if (function.name == "identical") { 443 if (function.name == "identical") {
428 NodeList<Expression> arguments = node.argumentList.arguments; 444 NodeList<Expression> arguments = node.argumentList.arguments;
429 if (arguments.length == 2) { 445 if (arguments.length == 2) {
430 Element enclosingElement = function.enclosingElement; 446 Element enclosingElement = function.enclosingElement;
431 if (enclosingElement is CompilationUnitElement) { 447 if (enclosingElement is CompilationUnitElement) {
432 LibraryElement library = ((enclosingElement as CompilationUnitElemen t)).library; 448 LibraryElement library = (enclosingElement as CompilationUnitElement ).library;
433 if (library.isDartCore) { 449 if (library.isDartCore) {
434 EvaluationResultImpl leftArgument = arguments[0].accept(this); 450 EvaluationResultImpl leftArgument = arguments[0].accept(this);
435 EvaluationResultImpl rightArgument = arguments[1].accept(this); 451 EvaluationResultImpl rightArgument = arguments[1].accept(this);
436 return leftArgument.equalEqual(node, rightArgument); 452 return leftArgument.equalEqual(node, rightArgument);
437 } 453 }
438 } 454 }
439 } 455 }
440 } 456 }
441 } 457 }
442 return error(node, null); 458 return error(node, null);
443 } 459 }
460
444 EvaluationResultImpl visitNamedExpression(NamedExpression node) => node.expres sion.accept(this); 461 EvaluationResultImpl visitNamedExpression(NamedExpression node) => node.expres sion.accept(this);
462
445 EvaluationResultImpl visitNode(ASTNode node) => error(node, null); 463 EvaluationResultImpl visitNode(ASTNode node) => error(node, null);
464
446 EvaluationResultImpl visitNullLiteral(NullLiteral node) => ValidResult.RESULT_ NULL; 465 EvaluationResultImpl visitNullLiteral(NullLiteral node) => ValidResult.RESULT_ NULL;
466
447 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node ) => node.expression.accept(this); 467 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node ) => node.expression.accept(this);
468
448 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) { 469 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
449 SimpleIdentifier prefixNode = node.prefix; 470 SimpleIdentifier prefixNode = node.prefix;
450 Element prefixElement = prefixNode.staticElement; 471 Element prefixElement = prefixNode.staticElement;
451 if (prefixElement is! PrefixElement) { 472 if (prefixElement is! PrefixElement) {
452 EvaluationResultImpl prefixResult = prefixNode.accept(this); 473 EvaluationResultImpl prefixResult = prefixNode.accept(this);
453 if (prefixResult is! ValidResult) { 474 if (prefixResult is! ValidResult) {
454 return error(node, null); 475 return error(node, null);
455 } 476 }
456 } 477 }
457 return getConstantValue(node, node.staticElement); 478 return getConstantValue(node, node.staticElement);
458 } 479 }
480
459 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) { 481 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) {
460 EvaluationResultImpl operand = node.operand.accept(this); 482 EvaluationResultImpl operand = node.operand.accept(this);
461 if (operand is ValidResult && ((operand as ValidResult)).isNull) { 483 if (operand is ValidResult && (operand as ValidResult).isNull) {
462 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); 484 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
463 } 485 }
464 while (true) { 486 while (true) {
465 if (node.operator.type == TokenType.BANG) { 487 if (node.operator.type == TokenType.BANG) {
466 return operand.logicalNot(node); 488 return operand.logicalNot(node);
467 } else if (node.operator.type == TokenType.TILDE) { 489 } else if (node.operator.type == TokenType.TILDE) {
468 return operand.bitNot(node); 490 return operand.bitNot(node);
469 } else if (node.operator.type == TokenType.MINUS) { 491 } else if (node.operator.type == TokenType.MINUS) {
470 return operand.negated(node); 492 return operand.negated(node);
471 } 493 }
472 break; 494 break;
473 } 495 }
474 return error(node, null); 496 return error(node, null);
475 } 497 }
498
476 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => getConstantVa lue(node, node.propertyName.staticElement); 499 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => getConstantVa lue(node, node.propertyName.staticElement);
500
477 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) => getConsta ntValue(node, node.staticElement); 501 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) => getConsta ntValue(node, node.staticElement);
502
478 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new ValidResult(node.value); 503 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new ValidResult(node.value);
504
479 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) { 505 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) {
480 EvaluationResultImpl result = null; 506 EvaluationResultImpl result = null;
481 for (InterpolationElement element in node.elements) { 507 for (InterpolationElement element in node.elements) {
482 if (result == null) { 508 if (result == null) {
483 result = element.accept(this); 509 result = element.accept(this);
484 } else { 510 } else {
485 result = result.concatenate(node, element.accept(this)); 511 result = result.concatenate(node, element.accept(this));
486 } 512 }
487 } 513 }
488 return result; 514 return result;
489 } 515 }
516
490 EvaluationResultImpl visitSymbolLiteral(SymbolLiteral node) => ValidResult.RES ULT_SYMBOL; 517 EvaluationResultImpl visitSymbolLiteral(SymbolLiteral node) => ValidResult.RES ULT_SYMBOL;
491 518
492 /** 519 /**
493 * Return a result object representing an error associated with the given node . 520 * Return a result object representing an error associated with the given node .
494 * 521 *
495 * @param node the AST node associated with the error 522 * @param node the AST node associated with the error
496 * @param code the error code indicating the nature of the error 523 * @param code the error code indicating the nature of the error
497 * @return a result object representing an error associated with the given nod e 524 * @return a result object representing an error associated with the given nod e
498 */ 525 */
499 ErrorResult error(ASTNode node, ErrorCode code) => new ErrorResult.con1(node, code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code); 526 ErrorResult error(ASTNode node, ErrorCode code) => new ErrorResult.con1(node, code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code);
500 527
501 /** 528 /**
502 * Return the constant value of the static constant represented by the given e lement. 529 * Return the constant value of the static constant represented by the given e lement.
503 * 530 *
504 * @param node the node to be used if an error needs to be reported 531 * @param node the node to be used if an error needs to be reported
505 * @param element the element whose value is to be returned 532 * @param element the element whose value is to be returned
506 * @return the constant value of the static constant 533 * @return the constant value of the static constant
507 */ 534 */
508 EvaluationResultImpl getConstantValue(ASTNode node, Element element) { 535 EvaluationResultImpl getConstantValue(ASTNode node, Element element) {
509 if (element is PropertyAccessorElement) { 536 if (element is PropertyAccessorElement) {
510 element = ((element as PropertyAccessorElement)).variable; 537 element = (element as PropertyAccessorElement).variable;
511 } 538 }
512 if (element is VariableElementImpl) { 539 if (element is VariableElementImpl) {
513 VariableElementImpl variableElementImpl = element as VariableElementImpl; 540 VariableElementImpl variableElementImpl = element as VariableElementImpl;
514 EvaluationResultImpl value = variableElementImpl.evaluationResult; 541 EvaluationResultImpl value = variableElementImpl.evaluationResult;
515 if (variableElementImpl.isConst && value != null) { 542 if (variableElementImpl.isConst && value != null) {
516 return value; 543 return value;
517 } 544 }
518 } else if (element is ExecutableElement) { 545 } else if (element is ExecutableElement) {
519 if (((element as ExecutableElement)).isStatic) { 546 if ((element as ExecutableElement).isStatic) {
520 return new ValidResult(element); 547 return new ValidResult(element);
521 } 548 }
522 } else if (element is ClassElement) { 549 } else if (element is ClassElement || element is FunctionTypeAliasElement) {
523 return ValidResult.RESULT_OBJECT; 550 return ValidResult.RESULT_OBJECT;
524 } 551 }
525 return error(node, null); 552 return error(node, null);
526 } 553 }
527 554
528 /** 555 /**
529 * Return the union of the errors encoded in the given results. 556 * Return the union of the errors encoded in the given results.
530 * 557 *
531 * @param leftResult the first set of errors, or `null` if there was no previo us collection 558 * @param leftResult the first set of errors, or `null` if there was no previo us collection
532 * of errors 559 * of errors
533 * @param rightResult the errors to be added to the collection, or a valid res ult if there are no 560 * @param rightResult the errors to be added to the collection, or a valid res ult if there are no
534 * errors to be added 561 * errors to be added
535 * @return the union of the errors encoded in the given results 562 * @return the union of the errors encoded in the given results
536 */ 563 */
537 ErrorResult union(ErrorResult leftResult, EvaluationResultImpl rightResult) { 564 ErrorResult union(ErrorResult leftResult, EvaluationResultImpl rightResult) {
538 if (rightResult is ErrorResult) { 565 if (rightResult is ErrorResult) {
539 if (leftResult != null) { 566 if (leftResult != null) {
540 return new ErrorResult.con2(leftResult, rightResult as ErrorResult); 567 return new ErrorResult.con2(leftResult, rightResult as ErrorResult);
541 } else { 568 } else {
542 return rightResult as ErrorResult; 569 return rightResult as ErrorResult;
543 } 570 }
544 } 571 }
545 return leftResult; 572 return leftResult;
546 } 573 }
547 } 574 }
575
548 /** 576 /**
549 * Instances of the class `DirectedGraph` implement a directed graph in which th e nodes are 577 * Instances of the class `DirectedGraph` implement a directed graph in which th e nodes are
550 * arbitrary (client provided) objects and edges are represented implicitly. The graph will allow an 578 * arbitrary (client provided) objects and edges are represented implicitly. The graph will allow an
551 * edge from any node to any other node, including itself, but will not represen t multiple edges 579 * edge from any node to any other node, including itself, but will not represen t multiple edges
552 * between the same pair of nodes. 580 * between the same pair of nodes.
553 * 581 *
554 * @param N the type of the nodes in the graph 582 * @param N the type of the nodes in the graph
555 */ 583 */
556 class DirectedGraph<N> { 584 class DirectedGraph<N> {
557
558 /** 585 /**
559 * The table encoding the edges in the graph. An edge is represented by an ent ry mapping the head 586 * The table encoding the edges in the graph. An edge is represented by an ent ry mapping the head
560 * to a set of tails. Nodes that are not the head of any edge are represented by an entry mapping 587 * to a set of tails. Nodes that are not the head of any edge are represented by an entry mapping
561 * the node to an empty set of tails. 588 * the node to an empty set of tails.
562 */ 589 */
563 Map<N, Set<N>> _edges = new Map<N, Set<N>>(); 590 Map<N, Set<N>> _edges = new Map<N, Set<N>>();
564 591
565 /** 592 /**
566 * Add an edge from the given head node to the given tail node. Both nodes wil l be a part of the 593 * Add an edge from the given head node to the given tail node. Both nodes wil l be a part of the
567 * graph after this method is invoked, whether or not they were before. 594 * graph after this method is invoked, whether or not they were before.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 * 723 *
697 * @return a sink node 724 * @return a sink node
698 */ 725 */
699 N findSink() { 726 N findSink() {
700 for (N key in _edges.keys) { 727 for (N key in _edges.keys) {
701 if (_edges[key].isEmpty) return key; 728 if (_edges[key].isEmpty) return key;
702 } 729 }
703 return null; 730 return null;
704 } 731 }
705 } 732 }
733
706 /** 734 /**
707 * Instances of the class `ErrorResult` represent the result of evaluating an ex pression that 735 * Instances of the class `ErrorResult` represent the result of evaluating an ex pression that
708 * is not a valid compile time constant. 736 * is not a valid compile time constant.
709 */ 737 */
710 class ErrorResult extends EvaluationResultImpl { 738 class ErrorResult extends EvaluationResultImpl {
711
712 /** 739 /**
713 * The errors that prevent the expression from being a valid compile time cons tant. 740 * The errors that prevent the expression from being a valid compile time cons tant.
714 */ 741 */
715 final List<ErrorResult_ErrorData> errorData = new List<ErrorResult_ErrorData>( ); 742 final List<ErrorResult_ErrorData> errorData = new List<ErrorResult_ErrorData>( );
716 743
717 /** 744 /**
718 * Initialize a newly created result representing the error with the given cod e reported against 745 * Initialize a newly created result representing the error with the given cod e reported against
719 * the given node. 746 * the given node.
720 * 747 *
721 * @param node the node against which the error should be reported 748 * @param node the node against which the error should be reported
722 * @param errorCode the error code for the error to be generated 749 * @param errorCode the error code for the error to be generated
723 */ 750 */
724 ErrorResult.con1(ASTNode node, ErrorCode errorCode) { 751 ErrorResult.con1(ASTNode node, ErrorCode errorCode) {
725 errorData.add(new ErrorResult_ErrorData(node, errorCode)); 752 errorData.add(new ErrorResult_ErrorData(node, errorCode));
726 } 753 }
727 754
728 /** 755 /**
729 * Initialize a newly created result to represent the union of the errors in t he given result 756 * Initialize a newly created result to represent the union of the errors in t he given result
730 * objects. 757 * objects.
731 * 758 *
732 * @param firstResult the first set of results being merged 759 * @param firstResult the first set of results being merged
733 * @param secondResult the second set of results being merged 760 * @param secondResult the second set of results being merged
734 */ 761 */
735 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) { 762 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) {
736 errorData.addAll(firstResult.errorData); 763 errorData.addAll(firstResult.errorData);
737 errorData.addAll(secondResult.errorData); 764 errorData.addAll(secondResult.errorData);
738 } 765 }
766
739 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper and) => rightOperand.addToError(node, this); 767 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper and) => rightOperand.addToError(node, this);
768
740 EvaluationResultImpl applyBooleanConversion(ASTNode node) => this; 769 EvaluationResultImpl applyBooleanConversion(ASTNode node) => this;
770
741 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitAndError(node, this); 771 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitAndError(node, this);
772
742 EvaluationResultImpl bitNot(Expression node) => this; 773 EvaluationResultImpl bitNot(Expression node) => this;
774
743 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.bitOrError(node, this); 775 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.bitOrError(node, this);
776
744 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitXorError(node, this); 777 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitXorError(node, this);
778
745 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp erand) => rightOperand.concatenateError(node, this); 779 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp erand) => rightOperand.concatenateError(node, this);
780
746 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.divideError(node, this); 781 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.divideError(node, this);
782
747 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe rand) => rightOperand.equalEqualError(node, this); 783 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe rand) => rightOperand.equalEqualError(node, this);
784
748 bool equalValues(EvaluationResultImpl result) => false; 785 bool equalValues(EvaluationResultImpl result) => false;
786
749 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r ightOperand) => rightOperand.greaterThanError(node, this); 787 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r ightOperand) => rightOperand.greaterThanError(node, this);
788
750 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul tImpl rightOperand) => rightOperand.greaterThanOrEqualError(node, this); 789 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul tImpl rightOperand) => rightOperand.greaterThanOrEqualError(node, this);
790
751 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideError(node, this); 791 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideError(node, this);
792
752 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef tOperand) => this; 793 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef tOperand) => this;
794
753 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.lessThanError(node, this); 795 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.lessThanError(node, this);
796
754 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm pl rightOperand) => rightOperand.lessThanOrEqualError(node, this); 797 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm pl rightOperand) => rightOperand.lessThanOrEqualError(node, this);
798
755 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.logicalAndError(node, this); 799 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.logicalAndError(node, this);
800
756 EvaluationResultImpl logicalNot(Expression node) => this; 801 EvaluationResultImpl logicalNot(Expression node) => this;
802
757 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.logicalOrError(node, this); 803 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.logicalOrError(node, this);
804
758 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.minusError(node, this); 805 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.minusError(node, this);
806
759 EvaluationResultImpl negated(Expression node) => this; 807 EvaluationResultImpl negated(Expression node) => this;
808
760 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.notEqualError(node, this); 809 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.notEqualError(node, this);
810
761 EvaluationResultImpl performToString(ASTNode node) => this; 811 EvaluationResultImpl performToString(ASTNode node) => this;
812
762 EvaluationResultImpl remainder(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.remainderError(node, this); 813 EvaluationResultImpl remainder(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.remainderError(node, this);
814
763 EvaluationResultImpl shiftLeft(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.shiftLeftError(node, this); 815 EvaluationResultImpl shiftLeft(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.shiftLeftError(node, this);
816
764 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.shiftRightError(node, this); 817 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.shiftRightError(node, this);
818
765 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.timesError(node, this); 819 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.timesError(node, this);
820
766 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand); 821 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
822
767 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand ) => this; 823 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand ) => this;
824
768 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand); 825 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
826
769 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan d) => this; 827 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan d) => this;
828
770 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand); 829 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
830
771 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand ) => this; 831 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand ) => this;
832
772 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand); 833 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
834
773 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan d) => this; 835 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan d) => this;
836
774 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand); 837 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
838
775 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand ) => this; 839 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand ) => this;
840
776 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand); 841 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
842
777 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan d) => this; 843 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan d) => this;
844
778 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => new ErrorResult.con2(this, leftOperand); 845 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => new ErrorResult.con2(this, leftOperand);
846
779 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand) => this; 847 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand) => this;
848
780 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => new ErrorResult.con2(this, leftOperand); 849 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => new ErrorResult.con2(this, leftOperand);
850
781 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => new ErrorResult.con2(this, leftOperand); 851 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => new ErrorResult.con2(this, leftOperand);
852
782 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul t leftOperand) => this; 853 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul t leftOperand) => this;
854
783 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO perand) => this; 855 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO perand) => this;
856
784 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => new ErrorResult.con2(this, leftOperand); 857 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => new ErrorResult.con2(this, leftOperand);
858
785 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand); 859 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
860
786 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => new ErrorResult.con2(this, leftOperand); 861 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => new ErrorResult.con2(this, leftOperand);
862
787 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l eftOperand) => this; 863 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l eftOperand) => this;
864
788 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper and) => this; 865 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper and) => this;
866
789 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand); 867 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
868
790 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp erand) => this; 869 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp erand) => this;
870
791 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand); 871 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
872
792 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe rand) => this; 873 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe rand) => this;
874
793 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand); 875 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
876
794 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand ) => this; 877 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand ) => this;
878
795 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand); 879 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
880
796 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper and) => this; 881 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper and) => this;
882
797 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand); 883 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
884
798 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe rand) => this; 885 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe rand) => this;
886
799 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand); 887 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
888
800 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe rand) => this; 889 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe rand) => this;
890
801 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand); 891 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
892
802 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp erand) => this; 893 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp erand) => this;
894
803 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand); 895 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
896
804 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand ) => this; 897 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand ) => this;
805 } 898 }
899
806 class ErrorResult_ErrorData { 900 class ErrorResult_ErrorData {
807
808 /** 901 /**
809 * The node against which the error should be reported. 902 * The node against which the error should be reported.
810 */ 903 */
811 ASTNode node; 904 ASTNode node;
812 905
813 /** 906 /**
814 * The error code for the error to be generated. 907 * The error code for the error to be generated.
815 */ 908 */
816 ErrorCode errorCode; 909 ErrorCode errorCode;
817 910
818 /** 911 /**
819 * Initialize a newly created data holder to represent the error with the give n code reported 912 * Initialize a newly created data holder to represent the error with the give n code reported
820 * against the given node. 913 * against the given node.
821 * 914 *
822 * @param node the node against which the error should be reported 915 * @param node the node against which the error should be reported
823 * @param errorCode the error code for the error to be generated 916 * @param errorCode the error code for the error to be generated
824 */ 917 */
825 ErrorResult_ErrorData(ASTNode node, ErrorCode errorCode) { 918 ErrorResult_ErrorData(ASTNode node, ErrorCode errorCode) {
826 this.node = node; 919 this.node = node;
827 this.errorCode = errorCode; 920 this.errorCode = errorCode;
828 } 921 }
829 } 922 }
923
830 /** 924 /**
831 * Instances of the class `InternalResult` represent the result of attempting to evaluate a 925 * Instances of the class `InternalResult` represent the result of attempting to evaluate a
832 * expression. 926 * expression.
833 */ 927 */
834 abstract class EvaluationResultImpl { 928 abstract class EvaluationResultImpl {
835 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper and); 929 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper and);
836 930
837 /** 931 /**
838 * Return the result of applying boolean conversion to this result. 932 * Return the result of applying boolean conversion to this result.
839 * 933 *
840 * @param node the node against which errors should be reported 934 * @param node the node against which errors should be reported
841 * @return the result of applying boolean conversion to the given value 935 * @return the result of applying boolean conversion to the given value
842 */ 936 */
843 EvaluationResultImpl applyBooleanConversion(ASTNode node); 937 EvaluationResultImpl applyBooleanConversion(ASTNode node);
938
844 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO perand); 939 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO perand);
940
845 EvaluationResultImpl bitNot(Expression node); 941 EvaluationResultImpl bitNot(Expression node);
942
846 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp erand); 943 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp erand);
944
847 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO perand); 945 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO perand);
946
848 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp erand); 947 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp erand);
948
849 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO perand); 949 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO perand);
950
850 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe rand); 951 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe rand);
952
851 bool equalValues(EvaluationResultImpl result); 953 bool equalValues(EvaluationResultImpl result);
954
852 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r ightOperand); 955 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r ightOperand);
956
853 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul tImpl rightOperand); 957 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul tImpl rightOperand);
958
854 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl rightOperand); 959 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl rightOperand);
960
855 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ tOperand); 961 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ tOperand);
962
856 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm pl rightOperand); 963 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm pl rightOperand);
964
857 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri ghtOperand); 965 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri ghtOperand);
966
858 EvaluationResultImpl logicalNot(Expression node); 967 EvaluationResultImpl logicalNot(Expression node);
968
859 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig htOperand); 969 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig htOperand);
970
860 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp erand); 971 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp erand);
972
861 EvaluationResultImpl negated(Expression node); 973 EvaluationResultImpl negated(Expression node);
974
862 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ tOperand); 975 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ tOperand);
976
863 EvaluationResultImpl performToString(ASTNode node); 977 EvaluationResultImpl performToString(ASTNode node);
978
864 EvaluationResultImpl remainder(BinaryExpression node, EvaluationResultImpl rig htOperand); 979 EvaluationResultImpl remainder(BinaryExpression node, EvaluationResultImpl rig htOperand);
980
865 EvaluationResultImpl shiftLeft(BinaryExpression node, EvaluationResultImpl rig htOperand); 981 EvaluationResultImpl shiftLeft(BinaryExpression node, EvaluationResultImpl rig htOperand);
982
866 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri ghtOperand); 983 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri ghtOperand);
984
867 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp erand); 985 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp erand);
986
868 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ); 987 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand );
988
869 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand ); 989 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand );
990
870 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d); 991 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d);
992
871 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan d); 993 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan d);
994
872 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ); 995 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand );
996
873 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand ); 997 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand );
998
874 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d); 999 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d);
1000
875 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan d); 1001 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan d);
1002
876 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ); 1003 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand );
1004
877 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand ); 1005 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand );
1006
878 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d); 1007 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d);
1008
879 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan d); 1009 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan d);
1010
880 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) ; 1011 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) ;
1012
881 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand) ; 1013 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand) ;
1014
882 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand); 1015 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand);
1016
883 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand); 1017 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand);
1018
884 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul t leftOperand); 1019 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul t leftOperand);
1020
885 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO perand); 1021 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO perand);
1022
886 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand); 1023 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand);
1024
887 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef tOperand); 1025 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef tOperand);
1026
888 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and); 1027 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and);
1028
889 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand); 1029 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand);
1030
890 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l eftOperand); 1031 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l eftOperand);
1032
891 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper and); 1033 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper and);
1034
892 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand); 1035 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand);
1036
893 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp erand); 1037 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp erand);
1038
894 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand); 1039 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand);
1040
895 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe rand); 1041 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe rand);
1042
896 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ); 1043 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand );
1044
897 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand ); 1045 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand );
1046
898 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and); 1047 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and);
1048
899 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper and); 1049 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper and);
1050
900 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand); 1051 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand);
1052
901 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe rand); 1053 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe rand);
1054
902 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand); 1055 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand);
1056
903 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe rand); 1057 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe rand);
1058
904 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand); 1059 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand);
1060
905 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp erand); 1061 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp erand);
1062
906 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ); 1063 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand );
1064
907 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand ); 1065 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand );
908 } 1066 }
1067
909 /** 1068 /**
910 * Instances of the class `ReferenceFinder` add reference information for a give n variable to 1069 * Instances of the class `ReferenceFinder` add reference information for a give n variable to
911 * the bi-directional mapping used to order the evaluation of constants. 1070 * the bi-directional mapping used to order the evaluation of constants.
912 */ 1071 */
913 class ReferenceFinder extends RecursiveASTVisitor<Object> { 1072 class ReferenceFinder extends RecursiveASTVisitor<Object> {
914
915 /** 1073 /**
916 * The element representing the variable whose initializer will be visited. 1074 * The element representing the variable whose initializer will be visited.
917 */ 1075 */
918 VariableElement _source; 1076 VariableElement _source;
919 1077
920 /** 1078 /**
921 * A graph in which the nodes are the constant variables and the edges are fro m each variable to 1079 * A graph in which the nodes are the constant variables and the edges are fro m each variable to
922 * the other constant variables that are referenced in the head's initializer. 1080 * the other constant variables that are referenced in the head's initializer.
923 */ 1081 */
924 DirectedGraph<VariableElement> _referenceGraph; 1082 DirectedGraph<VariableElement> _referenceGraph;
925 1083
926 /** 1084 /**
927 * Initialize a newly created reference finder to find references from the giv en variable to other 1085 * Initialize a newly created reference finder to find references from the giv en variable to other
928 * variables and to add those references to the given graph. 1086 * variables and to add those references to the given graph.
929 * 1087 *
930 * @param source the element representing the variable whose initializer will be visited 1088 * @param source the element representing the variable whose initializer will be visited
931 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables 1089 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables
932 * (tails) in their initializers 1090 * (tails) in their initializers
933 */ 1091 */
934 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen ceGraph) { 1092 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen ceGraph) {
935 this._source = source; 1093 this._source = source;
936 this._referenceGraph = referenceGraph; 1094 this._referenceGraph = referenceGraph;
937 } 1095 }
1096
938 Object visitSimpleIdentifier(SimpleIdentifier node) { 1097 Object visitSimpleIdentifier(SimpleIdentifier node) {
939 Element element = node.staticElement; 1098 Element element = node.staticElement;
940 if (element is PropertyAccessorElement) { 1099 if (element is PropertyAccessorElement) {
941 element = ((element as PropertyAccessorElement)).variable; 1100 element = (element as PropertyAccessorElement).variable;
942 } 1101 }
943 if (element is VariableElement) { 1102 if (element is VariableElement) {
944 VariableElement variable = element as VariableElement; 1103 VariableElement variable = element as VariableElement;
945 if (variable.isConst) { 1104 if (variable.isConst) {
946 _referenceGraph.addEdge(_source, variable); 1105 _referenceGraph.addEdge(_source, variable);
947 } 1106 }
948 } 1107 }
949 return null; 1108 return null;
950 } 1109 }
951 } 1110 }
1111
952 /** 1112 /**
953 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid 1113 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid
954 * compile time constant expression. 1114 * compile time constant expression.
955 */ 1115 */
956 class ValidResult extends EvaluationResultImpl { 1116 class ValidResult extends EvaluationResultImpl {
957
958 /** 1117 /**
959 * A result object representing the value 'false'. 1118 * A result object representing the value 'false'.
960 */ 1119 */
961 static ValidResult RESULT_FALSE = new ValidResult(false); 1120 static ValidResult RESULT_FALSE = new ValidResult(false);
962 1121
963 /** 1122 /**
964 * A result object representing the an object without specific type on which n o further operations 1123 * A result object representing the an object without specific type on which n o further operations
965 * can be performed. 1124 * can be performed.
966 */ 1125 */
967 static ValidResult RESULT_DYNAMIC = new ValidResult(null); 1126 static ValidResult RESULT_DYNAMIC = new ValidResult(null);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 Object value; 1177 Object value;
1019 1178
1020 /** 1179 /**
1021 * Initialize a newly created result to represent the given value. 1180 * Initialize a newly created result to represent the given value.
1022 * 1181 *
1023 * @param value the value of the expression 1182 * @param value the value of the expression
1024 */ 1183 */
1025 ValidResult(Object value) { 1184 ValidResult(Object value) {
1026 this.value = value; 1185 this.value = value;
1027 } 1186 }
1187
1028 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper and) => rightOperand.addToValid(node, this); 1188 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper and) => rightOperand.addToValid(node, this);
1029 1189
1030 /** 1190 /**
1031 * Return the result of applying boolean conversion to this result. 1191 * Return the result of applying boolean conversion to this result.
1032 * 1192 *
1033 * @param node the node against which errors should be reported 1193 * @param node the node against which errors should be reported
1034 * @return the result of applying boolean conversion to the given value 1194 * @return the result of applying boolean conversion to the given value
1035 */ 1195 */
1036 EvaluationResultImpl applyBooleanConversion(ASTNode node) => booleanConversion (node, value); 1196 EvaluationResultImpl applyBooleanConversion(ASTNode node) => booleanConversion (node, value);
1197
1037 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitAndValid(node, this); 1198 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitAndValid(node, this);
1199
1038 EvaluationResultImpl bitNot(Expression node) { 1200 EvaluationResultImpl bitNot(Expression node) {
1039 if (isSomeInt) { 1201 if (isSomeInt) {
1040 return RESULT_INT; 1202 return RESULT_INT;
1041 } 1203 }
1042 if (value == null) { 1204 if (value == null) {
1043 return error(node); 1205 return error(node);
1044 } else if (value is int) { 1206 } else if (value is int) {
1045 return valueOf(~((value as int))); 1207 return valueOf(~(value as int));
1046 } 1208 }
1047 return error(node); 1209 return error(node);
1048 } 1210 }
1211
1049 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.bitOrValid(node, this); 1212 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.bitOrValid(node, this);
1213
1050 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitXorValid(node, this); 1214 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.bitXorValid(node, this);
1215
1051 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp erand) => rightOperand.concatenateValid(node, this); 1216 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp erand) => rightOperand.concatenateValid(node, this);
1217
1052 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.divideValid(node, this); 1218 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO perand) => rightOperand.divideValid(node, this);
1219
1053 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe rand) => rightOperand.equalEqualValid(node, this); 1220 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe rand) => rightOperand.equalEqualValid(node, this);
1221
1054 bool equalValues(EvaluationResultImpl result) => identical(equalEqual(null, re sult), RESULT_TRUE); 1222 bool equalValues(EvaluationResultImpl result) => identical(equalEqual(null, re sult), RESULT_TRUE);
1223
1055 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r ightOperand) => rightOperand.greaterThanValid(node, this); 1224 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r ightOperand) => rightOperand.greaterThanValid(node, this);
1225
1056 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul tImpl rightOperand) => rightOperand.greaterThanOrEqualValid(node, this); 1226 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul tImpl rightOperand) => rightOperand.greaterThanOrEqualValid(node, this);
1227
1057 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideValid(node, this); 1228 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideValid(node, this);
1229
1058 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.lessThanValid(node, this); 1230 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.lessThanValid(node, this);
1231
1059 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm pl rightOperand) => rightOperand.lessThanOrEqualValid(node, this); 1232 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm pl rightOperand) => rightOperand.lessThanOrEqualValid(node, this);
1233
1060 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.logicalAndValid(node, this); 1234 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.logicalAndValid(node, this);
1235
1061 EvaluationResultImpl logicalNot(Expression node) { 1236 EvaluationResultImpl logicalNot(Expression node) {
1062 if (isSomeBool) { 1237 if (isSomeBool) {
1063 return RESULT_BOOL; 1238 return RESULT_BOOL;
1064 } 1239 }
1065 if (value == null) { 1240 if (value == null) {
1066 return RESULT_TRUE; 1241 return RESULT_TRUE;
1067 } else if (value is bool) { 1242 } else if (value is bool) {
1068 return ((value as bool)) ? RESULT_FALSE : RESULT_TRUE; 1243 return (value as bool) ? RESULT_FALSE : RESULT_TRUE;
1069 } 1244 }
1070 return error(node); 1245 return error(node);
1071 } 1246 }
1247
1072 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.logicalOrValid(node, this); 1248 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.logicalOrValid(node, this);
1249
1073 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.minusValid(node, this); 1250 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.minusValid(node, this);
1251
1074 EvaluationResultImpl negated(Expression node) { 1252 EvaluationResultImpl negated(Expression node) {
1075 if (isSomeNum) { 1253 if (isSomeNum) {
1076 return RESULT_INT; 1254 return RESULT_INT;
1077 } 1255 }
1078 if (value == null) { 1256 if (value == null) {
1079 return error(node); 1257 return error(node);
1080 } else if (value is int) { 1258 } else if (value is int) {
1081 return valueOf(-((value as int))); 1259 return valueOf(-(value as int));
1082 } else if (value is double) { 1260 } else if (value is double) {
1083 return valueOf3(-((value as double))); 1261 return valueOf3(-(value as double));
1084 } 1262 }
1085 return error(node); 1263 return error(node);
1086 } 1264 }
1265
1087 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.notEqualValid(node, this); 1266 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ tOperand) => rightOperand.notEqualValid(node, this);
1267
1088 EvaluationResultImpl performToString(ASTNode node) { 1268 EvaluationResultImpl performToString(ASTNode node) {
1089 if (value == null) { 1269 if (value == null) {
1090 return valueOf4("null"); 1270 return valueOf4("null");
1091 } else if (value is bool) { 1271 } else if (value is bool) {
1092 return valueOf4(((value as bool)).toString()); 1272 return valueOf4((value as bool).toString());
1093 } else if (value is int) { 1273 } else if (value is int) {
1094 return valueOf4(((value as int)).toString()); 1274 return valueOf4((value as int).toString());
1095 } else if (value is double) { 1275 } else if (value is double) {
1096 return valueOf4(((value as double)).toString()); 1276 return valueOf4((value as double).toString());
1097 } else if (value is String) { 1277 } else if (value is String) {
1098 return this; 1278 return this;
1099 } else if (isSomeBool) { 1279 } else if (isSomeBool) {
1100 return valueOf4("<some bool>"); 1280 return valueOf4("<some bool>");
1101 } else if (isSomeInt) { 1281 } else if (isSomeInt) {
1102 return valueOf4("<some int>"); 1282 return valueOf4("<some int>");
1103 } else if (isSomeNum) { 1283 } else if (isSomeNum) {
1104 return valueOf4("<some num>"); 1284 return valueOf4("<some num>");
1105 } 1285 }
1106 return error(node); 1286 return error(node);
1107 } 1287 }
1288
1108 EvaluationResultImpl remainder(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.remainderValid(node, this); 1289 EvaluationResultImpl remainder(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.remainderValid(node, this);
1290
1109 EvaluationResultImpl shiftLeft(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.shiftLeftValid(node, this); 1291 EvaluationResultImpl shiftLeft(BinaryExpression node, EvaluationResultImpl rig htOperand) => rightOperand.shiftLeftValid(node, this);
1292
1110 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.shiftRightValid(node, this); 1293 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri ghtOperand) => rightOperand.shiftRightValid(node, this);
1294
1111 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.timesValid(node, this); 1295 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp erand) => rightOperand.timesValid(node, this);
1296
1112 String toString() { 1297 String toString() {
1113 if (value == null) { 1298 if (value == null) {
1114 return "null"; 1299 return "null";
1115 } 1300 }
1116 return value.toString(); 1301 return value.toString();
1117 } 1302 }
1303
1118 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand; 1304 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1305
1119 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand ) { 1306 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand ) {
1120 if (!isAnyNum || !leftOperand.isAnyNum) { 1307 if (!isAnyNum || !leftOperand.isAnyNum) {
1121 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1308 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1122 } 1309 }
1123 if (isSomeInt || leftOperand.isSomeInt) { 1310 if (isSomeInt || leftOperand.isSomeInt) {
1124 return RESULT_INT; 1311 return RESULT_INT;
1125 } else if (isSomeNum || leftOperand.isSomeNum) { 1312 } else if (isSomeNum || leftOperand.isSomeNum) {
1126 return RESULT_NUM; 1313 return RESULT_NUM;
1127 } 1314 }
1128 Object leftValue = leftOperand.value; 1315 Object leftValue = leftOperand.value;
1129 if (leftValue == null) { 1316 if (leftValue == null) {
1130 return error(node.leftOperand); 1317 return error(node.leftOperand);
1131 } else if (value == null) { 1318 } else if (value == null) {
1132 return error(node.rightOperand); 1319 return error(node.rightOperand);
1133 } else if (leftValue is int) { 1320 } else if (leftValue is int) {
1134 if (value is int) { 1321 if (value is int) {
1135 return valueOf(((leftValue as int)) + (value as int)); 1322 return valueOf((leftValue as int) + (value as int));
1136 } else if (value is double) { 1323 } else if (value is double) {
1137 return valueOf3(((leftValue as int)).toDouble() + ((value as double))); 1324 return valueOf3((leftValue as int).toDouble() + (value as double));
1138 } 1325 }
1139 } else if (leftValue is double) { 1326 } else if (leftValue is double) {
1140 if (value is int) { 1327 if (value is int) {
1141 return valueOf3(((leftValue as double)) + ((value as int)).toDouble()); 1328 return valueOf3((leftValue as double) + (value as int).toDouble());
1142 } else if (value is double) { 1329 } else if (value is double) {
1143 return valueOf3(((leftValue as double)) + ((value as double))); 1330 return valueOf3((leftValue as double) + (value as double));
1144 } 1331 }
1145 } else if (leftValue is String) { 1332 } else if (leftValue is String) {
1146 if (value is String) { 1333 if (value is String) {
1147 return valueOf4("${((leftValue as String))}${((value as String))}"); 1334 return valueOf4("${(leftValue as String)}${(value as String)}");
1148 } 1335 }
1149 } 1336 }
1150 return error(node); 1337 return error(node);
1151 } 1338 }
1339
1152 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand; 1340 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
1341
1153 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan d) { 1342 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan d) {
1154 if (!isAnyInt || !leftOperand.isAnyInt) { 1343 if (!isAnyInt || !leftOperand.isAnyInt) {
1155 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); 1344 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT);
1156 } 1345 }
1157 if (isSomeInt || leftOperand.isSomeInt) { 1346 if (isSomeInt || leftOperand.isSomeInt) {
1158 return RESULT_INT; 1347 return RESULT_INT;
1159 } 1348 }
1160 Object leftValue = leftOperand.value; 1349 Object leftValue = leftOperand.value;
1161 if (leftValue == null) { 1350 if (leftValue == null) {
1162 return error(node.leftOperand); 1351 return error(node.leftOperand);
1163 } else if (value == null) { 1352 } else if (value == null) {
1164 return error(node.rightOperand); 1353 return error(node.rightOperand);
1165 } else if (leftValue is int) { 1354 } else if (leftValue is int) {
1166 if (value is int) { 1355 if (value is int) {
1167 return valueOf(((leftValue as int)) & (value as int)); 1356 return valueOf((leftValue as int) & (value as int));
1168 } 1357 }
1169 return error(node.leftOperand); 1358 return error(node.leftOperand);
1170 } 1359 }
1171 if (value is int) { 1360 if (value is int) {
1172 return error(node.rightOperand); 1361 return error(node.rightOperand);
1173 } 1362 }
1174 return union(error(node.leftOperand), error(node.rightOperand)); 1363 return union(error(node.leftOperand), error(node.rightOperand));
1175 } 1364 }
1365
1176 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand; 1366 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1367
1177 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand ) { 1368 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand ) {
1178 if (!isAnyInt || !leftOperand.isAnyInt) { 1369 if (!isAnyInt || !leftOperand.isAnyInt) {
1179 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); 1370 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT);
1180 } 1371 }
1181 if (isSomeInt || leftOperand.isSomeInt) { 1372 if (isSomeInt || leftOperand.isSomeInt) {
1182 return RESULT_INT; 1373 return RESULT_INT;
1183 } 1374 }
1184 Object leftValue = leftOperand.value; 1375 Object leftValue = leftOperand.value;
1185 if (leftValue == null) { 1376 if (leftValue == null) {
1186 return error(node.leftOperand); 1377 return error(node.leftOperand);
1187 } else if (value == null) { 1378 } else if (value == null) {
1188 return error(node.rightOperand); 1379 return error(node.rightOperand);
1189 } else if (leftValue is int) { 1380 } else if (leftValue is int) {
1190 if (value is int) { 1381 if (value is int) {
1191 return valueOf(((leftValue as int)) | (value as int)); 1382 return valueOf((leftValue as int) | (value as int));
1192 } 1383 }
1193 return error(node.leftOperand); 1384 return error(node.leftOperand);
1194 } 1385 }
1195 if (value is int) { 1386 if (value is int) {
1196 return error(node.rightOperand); 1387 return error(node.rightOperand);
1197 } 1388 }
1198 return union(error(node.leftOperand), error(node.rightOperand)); 1389 return union(error(node.leftOperand), error(node.rightOperand));
1199 } 1390 }
1391
1200 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand; 1392 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
1393
1201 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan d) { 1394 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan d) {
1202 if (!isAnyInt || !leftOperand.isAnyInt) { 1395 if (!isAnyInt || !leftOperand.isAnyInt) {
1203 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); 1396 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT);
1204 } 1397 }
1205 if (isSomeInt || leftOperand.isSomeInt) { 1398 if (isSomeInt || leftOperand.isSomeInt) {
1206 return RESULT_INT; 1399 return RESULT_INT;
1207 } 1400 }
1208 Object leftValue = leftOperand.value; 1401 Object leftValue = leftOperand.value;
1209 if (leftValue == null) { 1402 if (leftValue == null) {
1210 return error(node.leftOperand); 1403 return error(node.leftOperand);
1211 } else if (value == null) { 1404 } else if (value == null) {
1212 return error(node.rightOperand); 1405 return error(node.rightOperand);
1213 } else if (leftValue is int) { 1406 } else if (leftValue is int) {
1214 if (value is int) { 1407 if (value is int) {
1215 return valueOf(((leftValue as int)) ^ (value as int)); 1408 return valueOf((leftValue as int) ^ (value as int));
1216 } 1409 }
1217 return error(node.leftOperand); 1410 return error(node.leftOperand);
1218 } 1411 }
1219 if (value is int) { 1412 if (value is int) {
1220 return error(node.rightOperand); 1413 return error(node.rightOperand);
1221 } 1414 }
1222 return union(error(node.leftOperand), error(node.rightOperand)); 1415 return union(error(node.leftOperand), error(node.rightOperand));
1223 } 1416 }
1417
1224 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => leftOperand; 1418 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => leftOperand;
1419
1225 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand ) { 1420 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand ) {
1226 Object leftValue = leftOperand.value; 1421 Object leftValue = leftOperand.value;
1227 if (leftValue is String && value is String) { 1422 if (leftValue is String && value is String) {
1228 return valueOf4("${((leftValue as String))}${((value as String))}"); 1423 return valueOf4("${(leftValue as String)}${(value as String)}");
1229 } 1424 }
1230 return error(node); 1425 return error(node);
1231 } 1426 }
1427
1232 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand; 1428 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
1429
1233 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan d) { 1430 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan d) {
1234 if (!isAnyNum || !leftOperand.isAnyNum) { 1431 if (!isAnyNum || !leftOperand.isAnyNum) {
1235 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1432 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1236 } 1433 }
1237 if (isSomeNum || leftOperand.isSomeNum) { 1434 if (isSomeNum || leftOperand.isSomeNum) {
1238 return RESULT_NUM; 1435 return RESULT_NUM;
1239 } 1436 }
1240 Object leftValue = leftOperand.value; 1437 Object leftValue = leftOperand.value;
1241 if (leftValue == null) { 1438 if (leftValue == null) {
1242 return error(node.leftOperand); 1439 return error(node.leftOperand);
1243 } else if (value == null) { 1440 } else if (value == null) {
1244 return error(node.rightOperand); 1441 return error(node.rightOperand);
1245 } else if (leftValue is int) { 1442 } else if (leftValue is int) {
1246 if (value is int) { 1443 if (value is int) {
1247 if (((value as int)) == 0) { 1444 if ((value as int) == 0) {
1248 return valueOf3(((leftValue as int)).toDouble() / ((value as int)).toD ouble()); 1445 return valueOf3((leftValue as int).toDouble() / (value as int).toDoubl e());
1249 } 1446 }
1250 return valueOf(((leftValue as int)) ~/ (value as int)); 1447 return valueOf((leftValue as int) ~/ (value as int));
1251 } else if (value is double) { 1448 } else if (value is double) {
1252 return valueOf3(((leftValue as int)).toDouble() / ((value as double))); 1449 return valueOf3((leftValue as int).toDouble() / (value as double));
1253 } 1450 }
1254 } else if (leftValue is double) { 1451 } else if (leftValue is double) {
1255 if (value is int) { 1452 if (value is int) {
1256 return valueOf3(((leftValue as double)) / ((value as int)).toDouble()); 1453 return valueOf3((leftValue as double) / (value as int).toDouble());
1257 } else if (value is double) { 1454 } else if (value is double) {
1258 return valueOf3(((leftValue as double)) / ((value as double))); 1455 return valueOf3((leftValue as double) / (value as double));
1259 } 1456 }
1260 } 1457 }
1261 return error(node); 1458 return error(node);
1262 } 1459 }
1460
1263 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => leftOperand; 1461 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => leftOperand;
1462
1264 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand) { 1463 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand) {
1265 if (node is BinaryExpression) { 1464 if (node is BinaryExpression) {
1266 if (!isAnyNullBoolNumString || !leftOperand.isAnyNullBoolNumString) { 1465 if (!isAnyNullBoolNumString || !leftOperand.isAnyNullBoolNumString) {
1267 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING ); 1466 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING );
1268 } 1467 }
1269 } 1468 }
1270 Object leftValue = leftOperand.value; 1469 Object leftValue = leftOperand.value;
1271 if (leftValue == null) { 1470 if (leftValue == null) {
1272 return valueOf2(value == null); 1471 return valueOf2(value == null);
1273 } else if (leftValue is bool) {
1274 if (value is bool) {
1275 return valueOf2(identical(leftValue as bool, value as bool));
1276 }
1277 return RESULT_FALSE;
1278 } else if (leftValue is int) { 1472 } else if (leftValue is int) {
1279 if (value is int) { 1473 if (value is int) {
1280 return valueOf2(((leftValue as int)) == value); 1474 return valueOf2((leftValue as int) == value);
1281 } else if (value is double) { 1475 } else if (value is double) {
1282 return valueOf2(toDouble(leftValue as int) == value); 1476 return valueOf2(toDouble(leftValue as int) == value);
1283 } 1477 }
1284 return RESULT_FALSE; 1478 return RESULT_FALSE;
1285 } else if (leftValue is double) { 1479 } else if (leftValue is double) {
1286 if (value is int) { 1480 if (value is int) {
1287 return valueOf2(((leftValue as double)) == toDouble(value as int)); 1481 return valueOf2((leftValue as double) == toDouble(value as int));
1288 } else if (value is double) { 1482 } else if (value is double) {
1289 return valueOf2(((leftValue as double)) == value); 1483 return valueOf2((leftValue as double) == value);
1290 } 1484 }
1291 return RESULT_FALSE; 1485 return RESULT_FALSE;
1292 } else if (leftValue is String) { 1486 } else {
1293 if (value is String) { 1487 return valueOf2(leftValue == value);
1294 return valueOf2(((leftValue as String)) == value);
1295 }
1296 return RESULT_FALSE;
1297 } 1488 }
1298 return RESULT_FALSE;
1299 } 1489 }
1490
1300 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => leftOperand; 1491 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => leftOperand;
1492
1301 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => leftOperand; 1493 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => leftOperand;
1494
1302 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul t leftOperand) { 1495 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul t leftOperand) {
1303 if (!isAnyNum || !leftOperand.isAnyNum) { 1496 if (!isAnyNum || !leftOperand.isAnyNum) {
1304 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1497 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1305 } 1498 }
1306 if (isSomeNum || leftOperand.isSomeNum) { 1499 if (isSomeNum || leftOperand.isSomeNum) {
1307 return RESULT_BOOL; 1500 return RESULT_BOOL;
1308 } 1501 }
1309 Object leftValue = leftOperand.value; 1502 Object leftValue = leftOperand.value;
1310 if (leftValue == null) { 1503 if (leftValue == null) {
1311 return error(node.leftOperand); 1504 return error(node.leftOperand);
1312 } else if (value == null) { 1505 } else if (value == null) {
1313 return error(node.rightOperand); 1506 return error(node.rightOperand);
1314 } else if (leftValue is int) { 1507 } else if (leftValue is int) {
1315 if (value is int) { 1508 if (value is int) {
1316 return valueOf2(((leftValue as int)).compareTo(value as int) >= 0); 1509 return valueOf2((leftValue as int).compareTo(value as int) >= 0);
1317 } else if (value is double) { 1510 } else if (value is double) {
1318 return valueOf2(((leftValue as int)).toDouble() >= ((value as double))); 1511 return valueOf2((leftValue as int).toDouble() >= (value as double));
1319 } 1512 }
1320 } else if (leftValue is double) { 1513 } else if (leftValue is double) {
1321 if (value is int) { 1514 if (value is int) {
1322 return valueOf2(((leftValue as double)) >= ((value as int)).toDouble()); 1515 return valueOf2((leftValue as double) >= (value as int).toDouble());
1323 } else if (value is double) { 1516 } else if (value is double) {
1324 return valueOf2(((leftValue as double)) >= ((value as double))); 1517 return valueOf2((leftValue as double) >= (value as double));
1325 } 1518 }
1326 } 1519 }
1327 return error(node); 1520 return error(node);
1328 } 1521 }
1522
1329 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO perand) { 1523 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO perand) {
1330 if (!isAnyNum || !leftOperand.isAnyNum) { 1524 if (!isAnyNum || !leftOperand.isAnyNum) {
1331 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1525 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1332 } 1526 }
1333 if (isSomeNum || leftOperand.isSomeNum) { 1527 if (isSomeNum || leftOperand.isSomeNum) {
1334 return RESULT_BOOL; 1528 return RESULT_BOOL;
1335 } 1529 }
1336 Object leftValue = leftOperand.value; 1530 Object leftValue = leftOperand.value;
1337 if (leftValue == null) { 1531 if (leftValue == null) {
1338 return error(node.leftOperand); 1532 return error(node.leftOperand);
1339 } else if (value == null) { 1533 } else if (value == null) {
1340 return error(node.rightOperand); 1534 return error(node.rightOperand);
1341 } else if (leftValue is int) { 1535 } else if (leftValue is int) {
1342 if (value is int) { 1536 if (value is int) {
1343 return valueOf2(((leftValue as int)).compareTo(value as int) > 0); 1537 return valueOf2((leftValue as int).compareTo(value as int) > 0);
1344 } else if (value is double) { 1538 } else if (value is double) {
1345 return valueOf2(((leftValue as int)).toDouble() > ((value as double))); 1539 return valueOf2((leftValue as int).toDouble() > (value as double));
1346 } 1540 }
1347 } else if (leftValue is double) { 1541 } else if (leftValue is double) {
1348 if (value is int) { 1542 if (value is int) {
1349 return valueOf2(((leftValue as double)) > ((value as int)).toDouble()); 1543 return valueOf2((leftValue as double) > (value as int).toDouble());
1350 } else if (value is double) { 1544 } else if (value is double) {
1351 return valueOf2(((leftValue as double)) > ((value as double))); 1545 return valueOf2((leftValue as double) > (value as double));
1352 } 1546 }
1353 } 1547 }
1354 return error(node); 1548 return error(node);
1355 } 1549 }
1550
1356 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => leftOperand; 1551 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => leftOperand;
1552
1357 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef tOperand) { 1553 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef tOperand) {
1358 if (!isAnyNum || !leftOperand.isAnyNum) { 1554 if (!isAnyNum || !leftOperand.isAnyNum) {
1359 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1555 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1360 } 1556 }
1361 if (isSomeNum || leftOperand.isSomeNum) { 1557 if (isSomeNum || leftOperand.isSomeNum) {
1362 return RESULT_INT; 1558 return RESULT_INT;
1363 } 1559 }
1364 Object leftValue = leftOperand.value; 1560 Object leftValue = leftOperand.value;
1365 if (leftValue == null) { 1561 if (leftValue == null) {
1366 return error(node.leftOperand); 1562 return error(node.leftOperand);
1367 } else if (value == null) { 1563 } else if (value == null) {
1368 return error(node.rightOperand); 1564 return error(node.rightOperand);
1369 } else if (leftValue is int) { 1565 } else if (leftValue is int) {
1370 if (value is int) { 1566 if (value is int) {
1371 if (((value as int)) == 0) { 1567 if ((value as int) == 0) {
1372 return error2(node, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE); 1568 return error2(node, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE);
1373 } 1569 }
1374 return valueOf(((leftValue as int)) ~/ (value as int)); 1570 return valueOf((leftValue as int) ~/ (value as int));
1375 } else if (value is double) { 1571 } else if (value is double) {
1376 double result = ((leftValue as int)).toDouble() / ((value as double)); 1572 double result = (leftValue as int).toDouble() / (value as double);
1377 return valueOf(result.toInt()); 1573 return valueOf(result.toInt());
1378 } 1574 }
1379 } else if (leftValue is double) { 1575 } else if (leftValue is double) {
1380 if (value is int) { 1576 if (value is int) {
1381 double result = ((leftValue as double)) / ((value as int)).toDouble(); 1577 double result = (leftValue as double) / (value as int).toDouble();
1382 return valueOf(result.toInt()); 1578 return valueOf(result.toInt());
1383 } else if (value is double) { 1579 } else if (value is double) {
1384 double result = ((leftValue as double)) / ((value as double)); 1580 double result = (leftValue as double) / (value as double);
1385 return valueOf(result.toInt()); 1581 return valueOf(result.toInt());
1386 } 1582 }
1387 } 1583 }
1388 return error(node); 1584 return error(node);
1389 } 1585 }
1586
1390 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => leftOperand; 1587 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
1588
1391 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => leftOperand; 1589 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => leftOperand;
1590
1392 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l eftOperand) { 1591 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l eftOperand) {
1393 if (!isAnyNum || !leftOperand.isAnyNum) { 1592 if (!isAnyNum || !leftOperand.isAnyNum) {
1394 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1593 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1395 } 1594 }
1396 if (isSomeNum || leftOperand.isSomeNum) { 1595 if (isSomeNum || leftOperand.isSomeNum) {
1397 return RESULT_BOOL; 1596 return RESULT_BOOL;
1398 } 1597 }
1399 Object leftValue = leftOperand.value; 1598 Object leftValue = leftOperand.value;
1400 if (leftValue == null) { 1599 if (leftValue == null) {
1401 return error(node.leftOperand); 1600 return error(node.leftOperand);
1402 } else if (value == null) { 1601 } else if (value == null) {
1403 return error(node.rightOperand); 1602 return error(node.rightOperand);
1404 } else if (leftValue is int) { 1603 } else if (leftValue is int) {
1405 if (value is int) { 1604 if (value is int) {
1406 return valueOf2(((leftValue as int)).compareTo(value as int) <= 0); 1605 return valueOf2((leftValue as int).compareTo(value as int) <= 0);
1407 } else if (value is double) { 1606 } else if (value is double) {
1408 return valueOf2(((leftValue as int)).toDouble() <= ((value as double))); 1607 return valueOf2((leftValue as int).toDouble() <= (value as double));
1409 } 1608 }
1410 } else if (leftValue is double) { 1609 } else if (leftValue is double) {
1411 if (value is int) { 1610 if (value is int) {
1412 return valueOf2(((leftValue as double)) <= ((value as int)).toDouble()); 1611 return valueOf2((leftValue as double) <= (value as int).toDouble());
1413 } else if (value is double) { 1612 } else if (value is double) {
1414 return valueOf2(((leftValue as double)) <= ((value as double))); 1613 return valueOf2((leftValue as double) <= (value as double));
1415 } 1614 }
1416 } 1615 }
1417 return error(node); 1616 return error(node);
1418 } 1617 }
1618
1419 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper and) { 1619 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper and) {
1420 if (!isAnyNum || !leftOperand.isAnyNum) { 1620 if (!isAnyNum || !leftOperand.isAnyNum) {
1421 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1621 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1422 } 1622 }
1423 if (isSomeNum || leftOperand.isSomeNum) { 1623 if (isSomeNum || leftOperand.isSomeNum) {
1424 return RESULT_BOOL; 1624 return RESULT_BOOL;
1425 } 1625 }
1426 Object leftValue = leftOperand.value; 1626 Object leftValue = leftOperand.value;
1427 if (leftValue == null) { 1627 if (leftValue == null) {
1428 return error(node.leftOperand); 1628 return error(node.leftOperand);
1429 } else if (value == null) { 1629 } else if (value == null) {
1430 return error(node.rightOperand); 1630 return error(node.rightOperand);
1431 } else if (leftValue is int) { 1631 } else if (leftValue is int) {
1432 if (value is int) { 1632 if (value is int) {
1433 return valueOf2(((leftValue as int)).compareTo(value as int) < 0); 1633 return valueOf2((leftValue as int).compareTo(value as int) < 0);
1434 } else if (value is double) { 1634 } else if (value is double) {
1435 return valueOf2(((leftValue as int)).toDouble() < ((value as double))); 1635 return valueOf2((leftValue as int).toDouble() < (value as double));
1436 } 1636 }
1437 } else if (leftValue is double) { 1637 } else if (leftValue is double) {
1438 if (value is int) { 1638 if (value is int) {
1439 return valueOf2(((leftValue as double)) < ((value as int)).toDouble()); 1639 return valueOf2((leftValue as double) < (value as int).toDouble());
1440 } else if (value is double) { 1640 } else if (value is double) {
1441 return valueOf2(((leftValue as double)) < ((value as double))); 1641 return valueOf2((leftValue as double) < (value as double));
1442 } 1642 }
1443 } 1643 }
1444 return error(node); 1644 return error(node);
1445 } 1645 }
1646
1446 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand; 1647 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
1648
1447 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp erand) { 1649 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp erand) {
1448 if (!isAnyBool || !leftOperand.isAnyBool) { 1650 if (!isAnyBool || !leftOperand.isAnyBool) {
1449 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL); 1651 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL);
1450 } 1652 }
1451 if (isSomeBool || leftOperand.isSomeBool) { 1653 if (isSomeBool || leftOperand.isSomeBool) {
1452 return RESULT_BOOL; 1654 return RESULT_BOOL;
1453 } 1655 }
1454 Object leftValue = leftOperand.value; 1656 Object leftValue = leftOperand.value;
1455 if (leftValue is bool) { 1657 if (leftValue is bool) {
1456 if (leftValue as bool) { 1658 if (leftValue as bool) {
1457 return booleanConversion(node.rightOperand, value); 1659 return booleanConversion(node.rightOperand, value);
1458 } 1660 }
1459 return RESULT_FALSE; 1661 return RESULT_FALSE;
1460 } 1662 }
1461 return error(node); 1663 return error(node);
1462 } 1664 }
1665
1463 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand; 1666 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
1667
1464 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe rand) { 1668 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe rand) {
1465 if (!isAnyBool || !leftOperand.isAnyBool) { 1669 if (!isAnyBool || !leftOperand.isAnyBool) {
1466 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL); 1670 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL);
1467 } 1671 }
1468 if (isSomeBool || leftOperand.isSomeBool) { 1672 if (isSomeBool || leftOperand.isSomeBool) {
1469 return RESULT_BOOL; 1673 return RESULT_BOOL;
1470 } 1674 }
1471 Object leftValue = leftOperand.value; 1675 Object leftValue = leftOperand.value;
1472 if (leftValue is bool && ((leftValue as bool))) { 1676 if (leftValue is bool && (leftValue as bool)) {
1473 return RESULT_TRUE; 1677 return RESULT_TRUE;
1474 } 1678 }
1475 return booleanConversion(node.rightOperand, value); 1679 return booleanConversion(node.rightOperand, value);
1476 } 1680 }
1681
1477 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand; 1682 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1683
1478 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand ) { 1684 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand ) {
1479 if (!isAnyNum || !leftOperand.isAnyNum) { 1685 if (!isAnyNum || !leftOperand.isAnyNum) {
1480 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1686 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1481 } 1687 }
1482 if (isSomeInt || leftOperand.isSomeInt) { 1688 if (isSomeInt || leftOperand.isSomeInt) {
1483 return RESULT_INT; 1689 return RESULT_INT;
1484 } else if (isSomeNum || leftOperand.isSomeNum) { 1690 } else if (isSomeNum || leftOperand.isSomeNum) {
1485 return RESULT_NUM; 1691 return RESULT_NUM;
1486 } 1692 }
1487 Object leftValue = leftOperand.value; 1693 Object leftValue = leftOperand.value;
1488 if (leftValue == null) { 1694 if (leftValue == null) {
1489 return error(node.leftOperand); 1695 return error(node.leftOperand);
1490 } else if (value == null) { 1696 } else if (value == null) {
1491 return error(node.rightOperand); 1697 return error(node.rightOperand);
1492 } else if (leftValue is int) { 1698 } else if (leftValue is int) {
1493 if (value is int) { 1699 if (value is int) {
1494 return valueOf(((leftValue as int)) - (value as int)); 1700 return valueOf((leftValue as int) - (value as int));
1495 } else if (value is double) { 1701 } else if (value is double) {
1496 return valueOf3(((leftValue as int)).toDouble() - ((value as double))); 1702 return valueOf3((leftValue as int).toDouble() - (value as double));
1497 } 1703 }
1498 } else if (leftValue is double) { 1704 } else if (leftValue is double) {
1499 if (value is int) { 1705 if (value is int) {
1500 return valueOf3(((leftValue as double)) - ((value as int)).toDouble()); 1706 return valueOf3((leftValue as double) - (value as int).toDouble());
1501 } else if (value is double) { 1707 } else if (value is double) {
1502 return valueOf3(((leftValue as double)) - ((value as double))); 1708 return valueOf3((leftValue as double) - (value as double));
1503 } 1709 }
1504 } 1710 }
1505 return error(node); 1711 return error(node);
1506 } 1712 }
1713
1507 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => leftOperand; 1714 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
1715
1508 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper and) { 1716 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper and) {
1509 if (!isAnyNullBoolNumString || !leftOperand.isAnyNullBoolNumString) { 1717 if (!isAnyNullBoolNumString || !leftOperand.isAnyNullBoolNumString) {
1510 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); 1718 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING);
1511 } 1719 }
1512 Object leftValue = leftOperand.value; 1720 Object leftValue = leftOperand.value;
1513 if (leftValue == null) { 1721 if (leftValue == null) {
1514 return valueOf2(value != null); 1722 return valueOf2(value != null);
1515 } else if (leftValue is bool) { 1723 } else if (leftValue is bool) {
1516 if (value is bool) { 1724 if (value is bool) {
1517 return valueOf2(((leftValue as bool)) != ((value as bool))); 1725 return valueOf2((leftValue as bool) != (value as bool));
1518 } 1726 }
1519 return RESULT_TRUE; 1727 return RESULT_TRUE;
1520 } else if (leftValue is int) { 1728 } else if (leftValue is int) {
1521 if (value is int) { 1729 if (value is int) {
1522 return valueOf2(((leftValue as int)) != value); 1730 return valueOf2((leftValue as int) != value);
1523 } else if (value is double) { 1731 } else if (value is double) {
1524 return valueOf2(toDouble(leftValue as int) != value); 1732 return valueOf2(toDouble(leftValue as int) != value);
1525 } 1733 }
1526 return RESULT_TRUE; 1734 return RESULT_TRUE;
1527 } else if (leftValue is double) { 1735 } else if (leftValue is double) {
1528 if (value is int) { 1736 if (value is int) {
1529 return valueOf2(((leftValue as double)) != toDouble(value as int)); 1737 return valueOf2((leftValue as double) != toDouble(value as int));
1530 } else if (value is double) { 1738 } else if (value is double) {
1531 return valueOf2(((leftValue as double)) != value); 1739 return valueOf2((leftValue as double) != value);
1532 } 1740 }
1533 return RESULT_TRUE; 1741 return RESULT_TRUE;
1534 } else if (leftValue is String) { 1742 } else if (leftValue is String) {
1535 if (value is String) { 1743 if (value is String) {
1536 return valueOf2(((leftValue as String)) != value); 1744 return valueOf2((leftValue as String) != value);
1537 } 1745 }
1538 return RESULT_TRUE; 1746 return RESULT_TRUE;
1539 } 1747 }
1540 return RESULT_TRUE; 1748 return RESULT_TRUE;
1541 } 1749 }
1750
1542 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand; 1751 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
1752
1543 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe rand) { 1753 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe rand) {
1544 if (!isAnyNum || !leftOperand.isAnyNum) { 1754 if (!isAnyNum || !leftOperand.isAnyNum) {
1545 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1755 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1546 } 1756 }
1547 if (isSomeInt || leftOperand.isSomeInt) { 1757 if (isSomeInt || leftOperand.isSomeInt) {
1548 return RESULT_INT; 1758 return RESULT_INT;
1549 } else if (isSomeNum || leftOperand.isSomeNum) { 1759 } else if (isSomeNum || leftOperand.isSomeNum) {
1550 return RESULT_NUM; 1760 return RESULT_NUM;
1551 } 1761 }
1552 Object leftValue = leftOperand.value; 1762 Object leftValue = leftOperand.value;
1553 if (leftValue == null) { 1763 if (leftValue == null) {
1554 return error(node.leftOperand); 1764 return error(node.leftOperand);
1555 } else if (value == null) { 1765 } else if (value == null) {
1556 return error(node.rightOperand); 1766 return error(node.rightOperand);
1557 } else if (leftValue is int) { 1767 } else if (leftValue is int) {
1558 if (value is int) { 1768 if (value is int) {
1559 if (((value as int)) == 0) { 1769 if ((value as int) == 0) {
1560 return valueOf3(((leftValue as int)).toDouble() % ((value as int)).toD ouble()); 1770 return valueOf3((leftValue as int).toDouble() % (value as int).toDoubl e());
1561 } 1771 }
1562 return valueOf(((leftValue as int)).remainder(value as int)); 1772 return valueOf((leftValue as int).remainder(value as int));
1563 } else if (value is double) { 1773 } else if (value is double) {
1564 return valueOf3(((leftValue as int)).toDouble() % ((value as double))); 1774 return valueOf3((leftValue as int).toDouble() % (value as double));
1565 } 1775 }
1566 } else if (leftValue is double) { 1776 } else if (leftValue is double) {
1567 if (value is int) { 1777 if (value is int) {
1568 return valueOf3(((leftValue as double)) % ((value as int)).toDouble()); 1778 return valueOf3((leftValue as double) % (value as int).toDouble());
1569 } else if (value is double) { 1779 } else if (value is double) {
1570 return valueOf3(((leftValue as double)) % ((value as double))); 1780 return valueOf3((leftValue as double) % (value as double));
1571 } 1781 }
1572 } 1782 }
1573 return error(node); 1783 return error(node);
1574 } 1784 }
1785
1575 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand; 1786 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
1787
1576 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe rand) { 1788 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe rand) {
1577 if (!isAnyInt || !leftOperand.isAnyInt) { 1789 if (!isAnyInt || !leftOperand.isAnyInt) {
1578 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); 1790 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT);
1579 } 1791 }
1580 if (isSomeInt || leftOperand.isSomeInt) { 1792 if (isSomeInt || leftOperand.isSomeInt) {
1581 return RESULT_INT; 1793 return RESULT_INT;
1582 } 1794 }
1583 Object leftValue = leftOperand.value; 1795 Object leftValue = leftOperand.value;
1584 if (leftValue == null) { 1796 if (leftValue == null) {
1585 return error(node.leftOperand); 1797 return error(node.leftOperand);
1586 } else if (value == null) { 1798 } else if (value == null) {
1587 return error(node.rightOperand); 1799 return error(node.rightOperand);
1588 } else if (leftValue is int) { 1800 } else if (leftValue is int) {
1589 if (value is int) { 1801 if (value is int) {
1590 return RESULT_INT; 1802 return RESULT_INT;
1591 } 1803 }
1592 return error(node.rightOperand); 1804 return error(node.rightOperand);
1593 } 1805 }
1594 if (value is int) { 1806 if (value is int) {
1595 return error(node.leftOperand); 1807 return error(node.leftOperand);
1596 } 1808 }
1597 return union(error(node.leftOperand), error(node.rightOperand)); 1809 return union(error(node.leftOperand), error(node.rightOperand));
1598 } 1810 }
1811
1599 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand; 1812 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
1813
1600 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp erand) { 1814 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp erand) {
1601 if (!isAnyInt || !leftOperand.isAnyInt) { 1815 if (!isAnyInt || !leftOperand.isAnyInt) {
1602 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); 1816 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT);
1603 } 1817 }
1604 if (isSomeInt || leftOperand.isSomeInt) { 1818 if (isSomeInt || leftOperand.isSomeInt) {
1605 return RESULT_INT; 1819 return RESULT_INT;
1606 } 1820 }
1607 Object leftValue = leftOperand.value; 1821 Object leftValue = leftOperand.value;
1608 if (leftValue == null) { 1822 if (leftValue == null) {
1609 return error(node.leftOperand); 1823 return error(node.leftOperand);
1610 } else if (value == null) { 1824 } else if (value == null) {
1611 return error(node.rightOperand); 1825 return error(node.rightOperand);
1612 } else if (leftValue is int) { 1826 } else if (leftValue is int) {
1613 if (value is int) { 1827 if (value is int) {
1614 return valueOf(((leftValue as int)) >> ((value as int))); 1828 return valueOf((leftValue as int) >> (value as int));
1615 } 1829 }
1616 return error(node.rightOperand); 1830 return error(node.rightOperand);
1617 } 1831 }
1618 if (value is int) { 1832 if (value is int) {
1619 return error(node.leftOperand); 1833 return error(node.leftOperand);
1620 } 1834 }
1621 return union(error(node.leftOperand), error(node.rightOperand)); 1835 return union(error(node.leftOperand), error(node.rightOperand));
1622 } 1836 }
1837
1623 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand; 1838 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1839
1624 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand ) { 1840 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand ) {
1625 if (!isAnyNum || !leftOperand.isAnyNum) { 1841 if (!isAnyNum || !leftOperand.isAnyNum) {
1626 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); 1842 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM);
1627 } 1843 }
1628 if (isSomeInt || leftOperand.isSomeInt) { 1844 if (isSomeInt || leftOperand.isSomeInt) {
1629 return RESULT_INT; 1845 return RESULT_INT;
1630 } else if (isSomeNum || leftOperand.isSomeNum) { 1846 } else if (isSomeNum || leftOperand.isSomeNum) {
1631 return RESULT_NUM; 1847 return RESULT_NUM;
1632 } 1848 }
1633 Object leftValue = leftOperand.value; 1849 Object leftValue = leftOperand.value;
1634 if (leftValue == null) { 1850 if (leftValue == null) {
1635 return error(node.leftOperand); 1851 return error(node.leftOperand);
1636 } else if (value == null) { 1852 } else if (value == null) {
1637 return error(node.rightOperand); 1853 return error(node.rightOperand);
1638 } else if (leftValue is int) { 1854 } else if (leftValue is int) {
1639 if (value is int) { 1855 if (value is int) {
1640 return valueOf(((leftValue as int)) * (value as int)); 1856 return valueOf((leftValue as int) * (value as int));
1641 } else if (value is double) { 1857 } else if (value is double) {
1642 return valueOf3(((leftValue as int)).toDouble() * ((value as double))); 1858 return valueOf3((leftValue as int).toDouble() * (value as double));
1643 } 1859 }
1644 } else if (leftValue is double) { 1860 } else if (leftValue is double) {
1645 if (value is int) { 1861 if (value is int) {
1646 return valueOf3(((leftValue as double)) * ((value as int)).toDouble()); 1862 return valueOf3((leftValue as double) * (value as int).toDouble());
1647 } else if (value is double) { 1863 } else if (value is double) {
1648 return valueOf3(((leftValue as double)) * ((value as double))); 1864 return valueOf3((leftValue as double) * (value as double));
1649 } 1865 }
1650 } 1866 }
1651 return error(node); 1867 return error(node);
1652 } 1868 }
1869
1653 bool get isNull => identical(this, RESULT_NULL); 1870 bool get isNull => identical(this, RESULT_NULL);
1654 1871
1655 /** 1872 /**
1656 * Return the result of applying boolean conversion to the given value. 1873 * Return the result of applying boolean conversion to the given value.
1657 * 1874 *
1658 * @param node the node against which errors should be reported 1875 * @param node the node against which errors should be reported
1659 * @param value the value to be converted to a boolean 1876 * @param value the value to be converted to a boolean
1660 * @return the result of applying boolean conversion to the given value 1877 * @return the result of applying boolean conversion to the given value
1661 */ 1878 */
1662 EvaluationResultImpl booleanConversion(ASTNode node, Object value) { 1879 EvaluationResultImpl booleanConversion(ASTNode node, Object value) {
1663 if (value is bool) { 1880 if (value is bool) {
1664 if (value as bool) { 1881 if (value as bool) {
1665 return RESULT_TRUE; 1882 return RESULT_TRUE;
1666 } else { 1883 } else {
1667 return RESULT_FALSE; 1884 return RESULT_FALSE;
1668 } 1885 }
1669 } 1886 }
1670 return error(node); 1887 return error(node);
1671 } 1888 }
1889
1672 ErrorResult error(ASTNode node) => error2(node, CompileTimeErrorCode.INVALID_C ONSTANT); 1890 ErrorResult error(ASTNode node) => error2(node, CompileTimeErrorCode.INVALID_C ONSTANT);
1673 1891
1674 /** 1892 /**
1675 * Return a result object representing an error associated with the given node . 1893 * Return a result object representing an error associated with the given node .
1676 * 1894 *
1677 * @param node the AST node associated with the error 1895 * @param node the AST node associated with the error
1678 * @param code the error code indicating the nature of the error 1896 * @param code the error code indicating the nature of the error
1679 * @return a result object representing an error associated with the given nod e 1897 * @return a result object representing an error associated with the given nod e
1680 */ 1898 */
1681 ErrorResult error2(ASTNode node, ErrorCode code) => new ErrorResult.con1(node, code); 1899 ErrorResult error2(ASTNode node, ErrorCode code) => new ErrorResult.con1(node, code);
(...skipping 25 matching lines...) Expand all
1707 1925
1708 /** 1926 /**
1709 * Checks if this result has type "int", exact value of which we don't know. 1927 * Checks if this result has type "int", exact value of which we don't know.
1710 */ 1928 */
1711 bool get isSomeInt => identical(this, RESULT_INT); 1929 bool get isSomeInt => identical(this, RESULT_INT);
1712 1930
1713 /** 1931 /**
1714 * Checks if this result has type "num" (or "int"), exact value of which we do n't know. 1932 * Checks if this result has type "num" (or "int"), exact value of which we do n't know.
1715 */ 1933 */
1716 bool get isSomeNum => identical(this, RESULT_DYNAMIC) || identical(this, RESUL T_INT) || identical(this, RESULT_NUM); 1934 bool get isSomeNum => identical(this, RESULT_DYNAMIC) || identical(this, RESUL T_INT) || identical(this, RESULT_NUM);
1935
1717 double toDouble(int value) => value.toDouble(); 1936 double toDouble(int value) => value.toDouble();
1718 1937
1719 /** 1938 /**
1720 * Return an error result that is the union of the two given error results. 1939 * Return an error result that is the union of the two given error results.
1721 * 1940 *
1722 * @param firstError the first error to be combined 1941 * @param firstError the first error to be combined
1723 * @param secondError the second error to be combined 1942 * @param secondError the second error to be combined
1724 * @return an error result that is the union of the two given error results 1943 * @return an error result that is the union of the two given error results
1725 */ 1944 */
1726 ErrorResult union(ErrorResult firstError, ErrorResult secondError) => new Erro rResult.con2(firstError, secondError); 1945 ErrorResult union(ErrorResult firstError, ErrorResult secondError) => new Erro rResult.con2(firstError, secondError);
(...skipping 23 matching lines...) Expand all
1750 ValidResult valueOf3(double value) => new ValidResult(value); 1969 ValidResult valueOf3(double value) => new ValidResult(value);
1751 1970
1752 /** 1971 /**
1753 * Return a result object representing the given value. 1972 * Return a result object representing the given value.
1754 * 1973 *
1755 * @param value the value to be represented as a result object 1974 * @param value the value to be represented as a result object
1756 * @return a result object representing the given value 1975 * @return a result object representing the given value
1757 */ 1976 */
1758 ValidResult valueOf4(String value) => new ValidResult(value); 1977 ValidResult valueOf4(String value) => new ValidResult(value);
1759 } 1978 }
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