| OLD | NEW |
| 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 library engine.constant; | 3 library engine.constant; |
| 4 import 'java_core.dart'; | 4 import 'java_core.dart'; |
| 5 import 'source.dart' show Source; | 5 import 'source.dart' show Source; |
| 6 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; | 6 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; |
| 7 import 'scanner.dart' show TokenType; | 7 import 'scanner.dart' show TokenType; |
| 8 import 'ast.dart'; | 8 import 'ast.dart'; |
| 9 import 'element.dart'; | 9 import 'element.dart'; |
| 10 import 'engine.dart' show AnalysisEngine; | 10 import 'engine.dart' show AnalysisEngine; |
| 11 /** | 11 /** |
| 12 * Instances of the class `ConstantEvaluator` evaluate constant expressions to p
roduce their | 12 * 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 | 13 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant |
| 14 * expression is one of the following: | 14 * expression is one of the following: |
| 15 * | 15 * |
| 16 * * A literal number. | 16 * * A literal number. |
| 17 * * A literal boolean. | 17 * * A literal boolean. |
| 18 * * A literal string where any interpolated expression is a compile-time consta
nt that evaluates | 18 * * 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`. | 19 * to a numeric, string or boolean value or to `null`. |
| 20 * * `null`. | 20 * * `null`. |
| 21 * * A reference to a static constant variable. | 21 * * A reference to a static constant variable. |
| 22 * * An identifier expression that denotes a constant variable, a class or a typ
e variable. | 22 * * An identifier expression that denotes a constant variable, a class or a typ
e parameter. |
| 23 * * A constant constructor invocation. | 23 * * A constant constructor invocation. |
| 24 * * A constant list literal. | 24 * * A constant list literal. |
| 25 * * A constant map literal. | 25 * * A constant map literal. |
| 26 * * A simple or qualified identifier denoting a top-level function or a static
method. | 26 * * A simple or qualified identifier denoting a top-level function or a static
method. |
| 27 * * A parenthesized expression `(e)` where `e` is a constant expression. | 27 * * A parenthesized expression `(e)` where `e` is a constant expression. |
| 28 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`, | 28 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`, |
| 29 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a | 29 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a |
| 30 * numeric, string or boolean value or to `null`. | 30 * numeric, string or boolean value or to `null`. |
| 31 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where | 31 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where |
| 32 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean value
or | 32 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean value
or |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 * Instances of the class `ConstantVisitor` evaluate constant expressions to pro
duce their | 263 * 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 | 264 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant |
| 265 * expression is one of the following: | 265 * expression is one of the following: |
| 266 * | 266 * |
| 267 * * A literal number. | 267 * * A literal number. |
| 268 * * A literal boolean. | 268 * * A literal boolean. |
| 269 * * A literal string where any interpolated expression is a compile-time consta
nt that evaluates | 269 * * 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`. | 270 * to a numeric, string or boolean value or to `null`. |
| 271 * * `null`. | 271 * * `null`. |
| 272 * * A reference to a static constant variable. | 272 * * A reference to a static constant variable. |
| 273 * * An identifier expression that denotes a constant variable, a class or a typ
e variable. | 273 * * An identifier expression that denotes a constant variable, a class or a typ
e parameter. |
| 274 * * A constant constructor invocation. | 274 * * A constant constructor invocation. |
| 275 * * A constant list literal. | 275 * * A constant list literal. |
| 276 * * A constant map literal. | 276 * * A constant map literal. |
| 277 * * A simple or qualified identifier denoting a top-level function or a static
method. | 277 * * A simple or qualified identifier denoting a top-level function or a static
method. |
| 278 * * A parenthesized expression `(e)` where `e` is a constant expression. | 278 * * A parenthesized expression `(e)` where `e` is a constant expression. |
| 279 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`, | 279 * * An expression of one of the forms `identical(e1, e2)`, `e1 == e2`, |
| 280 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a | 280 * `e1 != e2` where `e1` and `e2` are constant expressions that evaluate to a |
| 281 * numeric, string or boolean value or to `null`. | 281 * numeric, string or boolean value or to `null`. |
| 282 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where | 282 * * An expression of one of the forms `!e`, `e1 && e2` or `e1 || e2`, where |
| 283 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean value
or | 283 * `e`, `e1` and `e2` are constant expressions that evaluate to a boolean value
or |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } else if (operatorType == TokenType.SLASH) { | 351 } else if (operatorType == TokenType.SLASH) { |
| 352 return leftResult.divide(node, rightResult); | 352 return leftResult.divide(node, rightResult); |
| 353 } else if (operatorType == TokenType.TILDE_SLASH) { | 353 } else if (operatorType == TokenType.TILDE_SLASH) { |
| 354 return leftResult.integerDivide(node, rightResult); | 354 return leftResult.integerDivide(node, rightResult); |
| 355 } | 355 } |
| 356 break; | 356 break; |
| 357 } | 357 } |
| 358 return error(node, null); | 358 return error(node, null); |
| 359 } | 359 } |
| 360 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => node.value ?
ValidResult.RESULT_TRUE : ValidResult.RESULT_FALSE; | 360 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => node.value ?
ValidResult.RESULT_TRUE : ValidResult.RESULT_FALSE; |
| 361 EvaluationResultImpl visitConditionalExpression(ConditionalExpression node) { |
| 362 Expression condition = node.condition; |
| 363 EvaluationResultImpl conditionResult = condition.accept(this); |
| 364 conditionResult = conditionResult.applyBooleanConversion(condition); |
| 365 if (conditionResult is ErrorResult) { |
| 366 return conditionResult; |
| 367 } |
| 368 EvaluationResultImpl thenResult = node.thenExpression.accept(this); |
| 369 if (thenResult is ErrorResult) { |
| 370 return thenResult; |
| 371 } |
| 372 EvaluationResultImpl elseResult = node.elseExpression.accept(this); |
| 373 if (elseResult is ErrorResult) { |
| 374 return elseResult; |
| 375 } |
| 376 return (identical(conditionResult, ValidResult.RESULT_TRUE)) ? thenResult :
elseResult; |
| 377 } |
| 361 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => new ValidResult
(node.value); | 378 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => new ValidResult
(node.value); |
| 362 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio
n node) { | 379 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio
n node) { |
| 363 if (!node.isConst) { | 380 if (!node.isConst) { |
| 364 return error(node, null); | 381 return error(node, null); |
| 365 } | 382 } |
| 366 ConstructorElement constructor = node.staticElement; | 383 ConstructorElement constructor = node.staticElement; |
| 367 if (constructor != null && constructor.isConst) { | 384 if (constructor != null && constructor.isConst) { |
| 368 node.argumentList.accept(this); | 385 node.argumentList.accept(this); |
| 369 return ValidResult.RESULT_OBJECT; | 386 return ValidResult.RESULT_OBJECT; |
| 370 } | 387 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 * objects. | 729 * objects. |
| 713 * | 730 * |
| 714 * @param firstResult the first set of results being merged | 731 * @param firstResult the first set of results being merged |
| 715 * @param secondResult the second set of results being merged | 732 * @param secondResult the second set of results being merged |
| 716 */ | 733 */ |
| 717 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) { | 734 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) { |
| 718 errorData.addAll(firstResult.errorData); | 735 errorData.addAll(firstResult.errorData); |
| 719 errorData.addAll(secondResult.errorData); | 736 errorData.addAll(secondResult.errorData); |
| 720 } | 737 } |
| 721 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToError(node, this); | 738 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToError(node, this); |
| 739 EvaluationResultImpl applyBooleanConversion(ASTNode node) => this; |
| 722 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndError(node, this); | 740 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndError(node, this); |
| 723 EvaluationResultImpl bitNot(Expression node) => this; | 741 EvaluationResultImpl bitNot(Expression node) => this; |
| 724 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.bitOrError(node, this); | 742 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.bitOrError(node, this); |
| 725 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitXorError(node, this); | 743 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitXorError(node, this); |
| 726 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand) => rightOperand.concatenateError(node, this); | 744 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand) => rightOperand.concatenateError(node, this); |
| 727 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.divideError(node, this); | 745 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.divideError(node, this); |
| 728 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe
rand) => rightOperand.equalEqualError(node, this); | 746 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe
rand) => rightOperand.equalEqualError(node, this); |
| 729 bool equalValues(EvaluationResultImpl result) => false; | 747 bool equalValues(EvaluationResultImpl result) => false; |
| 730 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r
ightOperand) => rightOperand.greaterThanError(node, this); | 748 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r
ightOperand) => rightOperand.greaterThanError(node, this); |
| 731 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul
tImpl rightOperand) => rightOperand.greaterThanOrEqualError(node, this); | 749 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul
tImpl rightOperand) => rightOperand.greaterThanOrEqualError(node, this); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 this.node = node; | 825 this.node = node; |
| 808 this.errorCode = errorCode; | 826 this.errorCode = errorCode; |
| 809 } | 827 } |
| 810 } | 828 } |
| 811 /** | 829 /** |
| 812 * Instances of the class `InternalResult` represent the result of attempting to
evaluate a | 830 * Instances of the class `InternalResult` represent the result of attempting to
evaluate a |
| 813 * expression. | 831 * expression. |
| 814 */ | 832 */ |
| 815 abstract class EvaluationResultImpl { | 833 abstract class EvaluationResultImpl { |
| 816 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and); | 834 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and); |
| 835 |
| 836 /** |
| 837 * Return the result of applying boolean conversion to this result. |
| 838 * |
| 839 * @param node the node against which errors should be reported |
| 840 * @return the result of applying boolean conversion to the given value |
| 841 */ |
| 842 EvaluationResultImpl applyBooleanConversion(ASTNode node); |
| 817 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand); | 843 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand); |
| 818 EvaluationResultImpl bitNot(Expression node); | 844 EvaluationResultImpl bitNot(Expression node); |
| 819 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand); | 845 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand); |
| 820 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand); | 846 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand); |
| 821 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand); | 847 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand); |
| 822 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand); | 848 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand); |
| 823 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe
rand); | 849 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe
rand); |
| 824 bool equalValues(EvaluationResultImpl result); | 850 bool equalValues(EvaluationResultImpl result); |
| 825 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r
ightOperand); | 851 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r
ightOperand); |
| 826 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul
tImpl rightOperand); | 852 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul
tImpl rightOperand); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 | 1012 |
| 987 /** | 1013 /** |
| 988 * Initialize a newly created result to represent the given value. | 1014 * Initialize a newly created result to represent the given value. |
| 989 * | 1015 * |
| 990 * @param value the value of the expression | 1016 * @param value the value of the expression |
| 991 */ | 1017 */ |
| 992 ValidResult(Object value) { | 1018 ValidResult(Object value) { |
| 993 this.value = value; | 1019 this.value = value; |
| 994 } | 1020 } |
| 995 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToValid(node, this); | 1021 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToValid(node, this); |
| 1022 |
| 1023 /** |
| 1024 * Return the result of applying boolean conversion to this result. |
| 1025 * |
| 1026 * @param node the node against which errors should be reported |
| 1027 * @return the result of applying boolean conversion to the given value |
| 1028 */ |
| 1029 EvaluationResultImpl applyBooleanConversion(ASTNode node) => booleanConversion
(node, value); |
| 996 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndValid(node, this); | 1030 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndValid(node, this); |
| 997 EvaluationResultImpl bitNot(Expression node) { | 1031 EvaluationResultImpl bitNot(Expression node) { |
| 998 if (isSomeInt) { | 1032 if (isSomeInt) { |
| 999 return RESULT_INT; | 1033 return RESULT_INT; |
| 1000 } | 1034 } |
| 1001 if (value == null) { | 1035 if (value == null) { |
| 1002 return error(node); | 1036 return error(node); |
| 1003 } else if (value is int) { | 1037 } else if (value is int) { |
| 1004 return valueOf(~((value as int))); | 1038 return valueOf(~((value as int))); |
| 1005 } | 1039 } |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 ValidResult valueOf3(double value) => new ValidResult(value); | 1737 ValidResult valueOf3(double value) => new ValidResult(value); |
| 1704 | 1738 |
| 1705 /** | 1739 /** |
| 1706 * Return a result object representing the given value. | 1740 * Return a result object representing the given value. |
| 1707 * | 1741 * |
| 1708 * @param value the value to be represented as a result object | 1742 * @param value the value to be represented as a result object |
| 1709 * @return a result object representing the given value | 1743 * @return a result object representing the given value |
| 1710 */ | 1744 */ |
| 1711 ValidResult valueOf4(String value) => new ValidResult(value); | 1745 ValidResult valueOf4(String value) => new ValidResult(value); |
| 1712 } | 1746 } |
| OLD | NEW |