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

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

Issue 259773005: New analyzer snapshot. Sorted unit members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.constant; 8 library engine.constant;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
11 import 'java_engine.dart' show ObjectUtilities; 11 import 'java_engine.dart' show ObjectUtilities;
12 import 'source.dart' show Source; 12 import 'source.dart' show Source;
13 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; 13 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode;
14 import 'scanner.dart' show Token, TokenType; 14 import 'scanner.dart' show Token, TokenType;
15 import 'ast.dart'; 15 import 'ast.dart';
16 import 'element.dart'; 16 import 'element.dart';
17 import 'resolver.dart' show TypeProvider; 17 import 'resolver.dart' show TypeProvider;
18 import 'engine.dart' show AnalysisEngine; 18 import 'engine.dart' show AnalysisEngine;
19 import 'utilities_dart.dart' show ParameterKind; 19 import 'utilities_dart.dart' show ParameterKind;
20 import 'utilities_collection.dart'; 20 import 'utilities_collection.dart';
21 21
22 /** 22 /**
23 * Instances of the class `BoolState` represent the state of an object represent ing a boolean
24 * value.
25 */
26 class BoolState extends InstanceState {
27 /**
28 * The value of this instance.
29 */
30 final bool value;
31
32 /**
33 * An instance representing the boolean value 'false'.
34 */
35 static BoolState FALSE_STATE = new BoolState(false);
36
37 /**
38 * An instance representing the boolean value 'true'.
39 */
40 static BoolState TRUE_STATE = new BoolState(true);
41
42 /**
43 * A state that can be used to represent a boolean whose value is not known.
44 */
45 static BoolState UNKNOWN_VALUE = new BoolState(null);
46
47 /**
48 * Return the boolean state representing the given boolean value.
49 *
50 * @param value the value to be represented
51 * @return the boolean state representing the given boolean value
52 */
53 static BoolState from(bool value) => value ? BoolState.TRUE_STATE : BoolState. FALSE_STATE;
54
55 /**
56 * Initialize a newly created state to represent the given value.
57 *
58 * @param value the value of this instance
59 */
60 BoolState(this.value);
61
62 @override
63 BoolState convertToBool() => this;
64
65 @override
66 StringState convertToString() {
67 if (value == null) {
68 return StringState.UNKNOWN_VALUE;
69 }
70 return new StringState(value ? "true" : "false");
71 }
72
73 @override
74 BoolState equalEqual(InstanceState rightOperand) {
75 assertBoolNumStringOrNull(rightOperand);
76 if (value == null) {
77 return UNKNOWN_VALUE;
78 }
79 if (rightOperand is BoolState) {
80 bool rightValue = rightOperand.value;
81 if (rightValue == null) {
82 return UNKNOWN_VALUE;
83 }
84 return BoolState.from(identical(value, rightValue));
85 } else if (rightOperand is DynamicState) {
86 return UNKNOWN_VALUE;
87 }
88 return FALSE_STATE;
89 }
90
91 @override
92 bool operator ==(Object object) => object is BoolState && identical(value, obj ect.value);
93
94 @override
95 String get typeName => "bool";
96
97 @override
98 bool get hasExactValue => true;
99
100 @override
101 int get hashCode => value == null ? 0 : (value ? 2 : 3);
102
103 /**
104 * Return `true` if this object represents an object whose type is 'bool'.
105 *
106 * @return `true` if this object represents a boolean value
107 */
108 @override
109 bool get isBool => true;
110
111 @override
112 bool get isBoolNumStringOrNull => true;
113
114 @override
115 BoolState logicalAnd(InstanceState rightOperand) {
116 assertBool(rightOperand);
117 if (value == null) {
118 return UNKNOWN_VALUE;
119 }
120 return value ? rightOperand.convertToBool() : FALSE_STATE;
121 }
122
123 @override
124 BoolState logicalNot() {
125 if (value == null) {
126 return UNKNOWN_VALUE;
127 }
128 return value ? FALSE_STATE : TRUE_STATE;
129 }
130
131 @override
132 BoolState logicalOr(InstanceState rightOperand) {
133 assertBool(rightOperand);
134 if (value == null) {
135 return UNKNOWN_VALUE;
136 }
137 return value ? TRUE_STATE : rightOperand.convertToBool();
138 }
139
140 @override
141 String toString() => value == null ? "-unknown-" : (value ? "true" : "false");
142 }
143
144 /**
23 * Instances of the class `ConstantEvaluator` evaluate constant expressions to p roduce their 145 * Instances of the class `ConstantEvaluator` evaluate constant expressions to p roduce their
24 * compile-time value. According to the Dart Language Specification: <blockquote > A constant 146 * compile-time value. According to the Dart Language Specification: <blockquote > A constant
25 * expression is one of the following: 147 * expression is one of the following:
26 * * A literal number. 148 * * A literal number.
27 * * A literal boolean. 149 * * A literal boolean.
28 * * A literal string where any interpolated expression is a compile-time consta nt that evaluates 150 * * A literal string where any interpolated expression is a compile-time consta nt that evaluates
29 * to a numeric, string or boolean value or to <b>null</b>. 151 * to a numeric, string or boolean value or to <b>null</b>.
30 * * A literal symbol. 152 * * A literal symbol.
31 * * <b>null</b>. 153 * * <b>null</b>.
32 * * A qualified reference to a static constant variable. 154 * * A qualified reference to a static constant variable.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 List<AnalysisError> errors = new List<AnalysisError>(); 211 List<AnalysisError> errors = new List<AnalysisError>();
90 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) { 212 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) {
91 AstNode node = data.node; 213 AstNode node = data.node;
92 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, [])); 214 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, []));
93 } 215 }
94 return EvaluationResult.forErrors(new List.from(errors)); 216 return EvaluationResult.forErrors(new List.from(errors));
95 } 217 }
96 } 218 }
97 219
98 /** 220 /**
99 * The interface `DartObject` defines the behavior of objects that represent the state of a
100 * Dart object.
101 */
102 abstract class DartObject {
103 /**
104 * Return the boolean value of this object, or `null` if either the value of t his object is
105 * not known or this object is not of type 'bool'.
106 *
107 * @return the boolean value of this object
108 */
109 bool get boolValue;
110
111 /**
112 * Return the floating point value of this object, or `null` if either the val ue of this
113 * object is not known or this object is not of type 'double'.
114 *
115 * @return the floating point value of this object
116 */
117 double get doubleValue;
118
119 /**
120 * Return the integer value of this object, or `null` if either the value of t his object is
121 * not known or this object is not of type 'int'.
122 *
123 * @return the integer value of this object
124 */
125 int get intValue;
126
127 /**
128 * Return the string value of this object, or `null` if either the value of th is object is
129 * not known or this object is not of type 'String'.
130 *
131 * @return the string value of this object
132 */
133 String get stringValue;
134
135 /**
136 * Return the run-time type of this object.
137 *
138 * @return the run-time type of this object
139 */
140 InterfaceType get type;
141
142 /**
143 * Return this object's value if it can be represented exactly, or `null` if e ither the
144 * value cannot be represented exactly or if the value is `null`. Clients shou ld use
145 * [hasExactValue] to distinguish between these two cases.
146 *
147 * @return this object's value
148 */
149 Object get value;
150
151 /**
152 * Return `true` if this object's value can be represented exactly.
153 *
154 * @return `true` if this object's value can be represented exactly
155 */
156 bool get hasExactValue;
157
158 /**
159 * Return `true` if this object represents the value 'false'.
160 *
161 * @return `true` if this object represents the value 'false'
162 */
163 bool get isFalse;
164
165 /**
166 * Return `true` if this object represents the value 'null'.
167 *
168 * @return `true` if this object represents the value 'null'
169 */
170 bool get isNull;
171
172 /**
173 * Return `true` if this object represents the value 'true'.
174 *
175 * @return `true` if this object represents the value 'true'
176 */
177 bool get isTrue;
178 }
179
180 /**
181 * Instances of the class `EvaluationResult` represent the result of attempting to evaluate an
182 * expression.
183 */
184 class EvaluationResult {
185 /**
186 * Return an evaluation result representing the result of evaluating an expres sion that is not a
187 * compile-time constant because of the given errors.
188 *
189 * @param errors the errors that should be reported for the expression(s) that were evaluated
190 * @return the result of evaluating an expression that is not a compile-time c onstant
191 */
192 static EvaluationResult forErrors(List<AnalysisError> errors) => new Evaluatio nResult(null, errors);
193
194 /**
195 * Return an evaluation result representing the result of evaluating an expres sion that is a
196 * compile-time constant that evaluates to the given value.
197 *
198 * @param value the value of the expression
199 * @return the result of evaluating an expression that is a compile-time const ant
200 */
201 static EvaluationResult forValue(DartObject value) => new EvaluationResult(val ue, null);
202
203 /**
204 * The value of the expression.
205 */
206 final DartObject value;
207
208 /**
209 * The errors that should be reported for the expression(s) that were evaluate d.
210 */
211 final List<AnalysisError> _errors;
212
213 /**
214 * Initialize a newly created result object with the given state. Clients shou ld use one of the
215 * factory methods: [forErrors] and [forValue].
216 *
217 * @param value the value of the expression
218 * @param errors the errors that should be reported for the expression(s) that were evaluated
219 */
220 EvaluationResult(this.value, this._errors);
221
222 /**
223 * Return an array containing the errors that should be reported for the expre ssion(s) that were
224 * evaluated. If there are no such errors, the array will be empty. The array can be empty even if
225 * the expression is not a valid compile time constant if the errors would hav e been reported by
226 * other parts of the analysis engine.
227 */
228 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS : _errors;
229
230 /**
231 * Return `true` if the expression is a compile-time constant expression that would not
232 * throw an exception when evaluated.
233 *
234 * @return `true` if the expression is a valid compile-time constant expressio n
235 */
236 bool get isValid => _errors == null;
237 }
238
239 /**
240 * Instances of the class `ConstantFinder` are used to traverse the AST structur es of all of 221 * Instances of the class `ConstantFinder` are used to traverse the AST structur es of all of
241 * the compilation units being resolved and build a table mapping constant varia ble elements to the 222 * the compilation units being resolved and build a table mapping constant varia ble elements to the
242 * declarations of those variables. 223 * declarations of those variables.
243 */ 224 */
244 class ConstantFinder extends RecursiveAstVisitor<Object> { 225 class ConstantFinder extends RecursiveAstVisitor<Object> {
245 /** 226 /**
246 * A table mapping constant variable elements to the declarations of those var iables. 227 * A table mapping constant variable elements to the declarations of those var iables.
247 */ 228 */
248 final Map<VariableElement, VariableDeclaration> variableMap = new Map<Variable Element, VariableDeclaration>(); 229 final Map<VariableElement, VariableDeclaration> variableMap = new Map<Variable Element, VariableDeclaration>();
249 230
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 DartObjectImpl _valueOf(Expression expression) { 857 DartObjectImpl _valueOf(Expression expression) {
877 EvaluationResultImpl expressionValue = expression.accept(this); 858 EvaluationResultImpl expressionValue = expression.accept(this);
878 if (expressionValue is ValidResult) { 859 if (expressionValue is ValidResult) {
879 return expressionValue.value; 860 return expressionValue.value;
880 } 861 }
881 return null2; 862 return null2;
882 } 863 }
883 } 864 }
884 865
885 /** 866 /**
886 * Instances of the class `ErrorResult` represent the result of evaluating an ex pression that 867 * The interface `DartObject` defines the behavior of objects that represent the state of a
887 * is not a valid compile time constant. 868 * Dart object.
888 */ 869 */
889 class ErrorResult extends EvaluationResultImpl { 870 abstract class DartObject {
890 /** 871 /**
891 * The errors that prevent the expression from being a valid compile time cons tant. 872 * Return the boolean value of this object, or `null` if either the value of t his object is
892 */ 873 * not known or this object is not of type 'bool'.
893 List<ErrorResult_ErrorData> _errors = new List<ErrorResult_ErrorData>(); 874 *
894 875 * @return the boolean value of this object
895 /** 876 */
896 * Initialize a newly created result representing the error with the given cod e reported against 877 bool get boolValue;
897 * the given node. 878
898 * 879 /**
899 * @param node the node against which the error should be reported 880 * Return the floating point value of this object, or `null` if either the val ue of this
900 * @param errorCode the error code for the error to be generated 881 * object is not known or this object is not of type 'double'.
901 */ 882 *
902 ErrorResult.con1(AstNode node, ErrorCode errorCode) { 883 * @return the floating point value of this object
903 _errors.add(new ErrorResult_ErrorData(node, errorCode)); 884 */
904 } 885 double get doubleValue;
905 886
906 /** 887 /**
907 * Initialize a newly created result to represent the union of the errors in t he given result 888 * Return the integer value of this object, or `null` if either the value of t his object is
908 * objects. 889 * not known or this object is not of type 'int'.
909 * 890 *
910 * @param firstResult the first set of results being merged 891 * @return the integer value of this object
911 * @param secondResult the second set of results being merged 892 */
912 */ 893 int get intValue;
913 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) { 894
914 _errors.addAll(firstResult._errors); 895 /**
915 _errors.addAll(secondResult._errors); 896 * Return the string value of this object, or `null` if either the value of th is object is
916 } 897 * not known or this object is not of type 'String'.
917 898 *
918 @override 899 * @return the string value of this object
919 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToError(node, this); 900 */
920 901 String get stringValue;
921 @override 902
922 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node) => this; 903 /**
923 904 * Return the run-time type of this object.
924 @override 905 *
925 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitAndError(node, this); 906 * @return the run-time type of this object
926 907 */
927 @override 908 InterfaceType get type;
928 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node) => thi s; 909
929 910 /**
930 @override 911 * Return this object's value if it can be represented exactly, or `null` if e ither the
931 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.bitOrError(node, this); 912 * value cannot be represented exactly or if the value is `null`. Clients shou ld use
932 913 * [hasExactValue] to distinguish between these two cases.
933 @override 914 *
934 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitXorError(node, this); 915 * @return this object's value
935 916 */
936 @override 917 Object get value;
937 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand) => rightOperand.concatenateError(node, this); 918
938 919 /**
939 @override 920 * Return `true` if this object's value can be represented exactly.
940 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.divideError(node, this); 921 *
941 922 * @return `true` if this object's value can be represented exactly
942 @override 923 */
943 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand) => rightOperand.equalEqualError(node, this); 924 bool get hasExactValue;
944 925
945 @override 926 /**
946 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) => fa lse; 927 * Return `true` if this object represents the value 'false'.
947 928 *
948 List<ErrorResult_ErrorData> get errorData => _errors; 929 * @return `true` if this object represents the value 'false'
949 930 */
950 @override 931 bool get isFalse;
951 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand) => rightOperand.greaterThanError(node, t his); 932
952 933 /**
953 @override 934 * Return `true` if this object represents the value 'null'.
954 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand) => rightOperand.greaterThanOrEqua lError(node, this); 935 *
955 936 * @return `true` if this object represents the value 'null'
956 @override 937 */
957 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideError(nod e, this); 938 bool get isNull;
958 939
959 @override 940 /**
960 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand) => this; 941 * Return `true` if this object represents the value 'true'.
961 942 *
962 @override 943 * @return `true` if this object represents the value 'true'
963 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.lessThanError(node, this); 944 */
964 945 bool get isTrue;
965 @override
966 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand) => rightOperand.lessThanOrEqualError (node, this);
967
968 @override
969 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.logicalAndError(node, thi s);
970
971 @override
972 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node) => this;
973
974 @override
975 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.logicalOrError(node, this) ;
976
977 @override
978 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.minusError(node, this);
979
980 @override
981 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node) => th is;
982
983 @override
984 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.notEqualError(node, this);
985
986 @override
987 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node) => this;
988
989 @override
990 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.remainderError(node, this) ;
991
992 @override
993 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.shiftLeftError(node, this) ;
994
995 @override
996 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.shiftRightError(node, thi s);
997
998 @override
999 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.timesError(node, this);
1000
1001 @override
1002 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
1003
1004 @override
1005 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
1006
1007 @override
1008 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
1009
1010 @override
1011 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
1012
1013 @override
1014 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
1015
1016 @override
1017 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
1018
1019 @override
1020 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
1021
1022 @override
1023 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
1024
1025 @override
1026 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
1027
1028 @override
1029 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand) => this;
1030
1031 @override
1032 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
1033
1034 @override
1035 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
1036
1037 @override
1038 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => new ErrorResult.con2(this, leftOperand);
1039
1040 @override
1041 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand) => this;
1042
1043 @override
1044 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => new ErrorResult.con2(this, leftOperand);
1045
1046 @override
1047 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => new ErrorResult.con2(this, leftOperand);
1048
1049 @override
1050 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand) => this;
1051
1052 @override
1053 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand) => this;
1054
1055 @override
1056 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => new ErrorResult.con2(this, leftOperand);
1057
1058 @override
1059 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
1060
1061 @override
1062 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => new ErrorResult.con2(this, leftOperand);
1063
1064 @override
1065 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand) => this;
1066
1067 @override
1068 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) => this;
1069
1070 @override
1071 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
1072
1073 @override
1074 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) => this;
1075
1076 @override
1077 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
1078
1079 @override
1080 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
1081
1082 @override
1083 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
1084
1085 @override
1086 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
1087
1088 @override
1089 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
1090
1091 @override
1092 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) => this;
1093
1094 @override
1095 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
1096
1097 @override
1098 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
1099
1100 @override
1101 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
1102
1103 @override
1104 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
1105
1106 @override
1107 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
1108
1109 @override
1110 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) => this;
1111
1112 @override
1113 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
1114
1115 @override
1116 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
1117 }
1118
1119 class ErrorResult_ErrorData {
1120 /**
1121 * The node against which the error should be reported.
1122 */
1123 final AstNode node;
1124
1125 /**
1126 * The error code for the error to be generated.
1127 */
1128 final ErrorCode errorCode;
1129
1130 /**
1131 * Initialize a newly created data holder to represent the error with the give n code reported
1132 * against the given node.
1133 *
1134 * @param node the node against which the error should be reported
1135 * @param errorCode the error code for the error to be generated
1136 */
1137 ErrorResult_ErrorData(this.node, this.errorCode);
1138 }
1139
1140 /**
1141 * Instances of the class `InternalResult` represent the result of attempting to evaluate a
1142 * expression.
1143 */
1144 abstract class EvaluationResultImpl {
1145 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand);
1146
1147 /**
1148 * Return the result of applying boolean conversion to this result.
1149 *
1150 * @param typeProvider the type provider used to access known types
1151 * @param node the node against which errors should be reported
1152 * @return the result of applying boolean conversion to the given value
1153 */
1154 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node);
1155
1156 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
1157
1158 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node);
1159
1160 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
1161
1162 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
1163
1164 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand);
1165
1166 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
1167
1168 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand);
1169
1170 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result);
1171
1172 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand);
1173
1174 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand);
1175
1176 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
1177
1178 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand);
1179
1180 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand);
1181
1182 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand);
1183
1184 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node);
1185
1186 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
1187
1188 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
1189
1190 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node);
1191
1192 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand);
1193
1194 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node);
1195
1196 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
1197
1198 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
1199
1200 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand);
1201
1202 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
1203
1204 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand );
1205
1206 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
1207
1208 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d);
1209
1210 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
1211
1212 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand );
1213
1214 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
1215
1216 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d);
1217
1218 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
1219
1220 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand );
1221
1222 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand);
1223
1224 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d);
1225
1226 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
1227
1228 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) ;
1229
1230 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand);
1231
1232 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand);
1233
1234 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand);
1235
1236 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand);
1237
1238 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand);
1239
1240 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand);
1241
1242 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand);
1243
1244 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and);
1245
1246 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand);
1247
1248 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand);
1249
1250 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand);
1251
1252 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand);
1253
1254 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand);
1255
1256 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand);
1257
1258 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
1259
1260 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand );
1261
1262 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
1263
1264 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and);
1265
1266 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand);
1267
1268 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand);
1269
1270 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
1271
1272 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand);
1273
1274 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
1275
1276 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand);
1277
1278 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand);
1279
1280 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand );
1281
1282 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
1283 }
1284
1285 /**
1286 * Instances of the class `ReferenceFinder` add reference information for a give n variable to
1287 * the bi-directional mapping used to order the evaluation of constants.
1288 */
1289 class ReferenceFinder extends RecursiveAstVisitor<Object> {
1290 /**
1291 * The element representing the variable whose initializer will be visited.
1292 */
1293 final VariableElement _source;
1294
1295 /**
1296 * A graph in which the nodes are the constant variables and the edges are fro m each variable to
1297 * the other constant variables that are referenced in the head's initializer.
1298 */
1299 final DirectedGraph<VariableElement> _referenceGraph;
1300
1301 /**
1302 * Initialize a newly created reference finder to find references from the giv en variable to other
1303 * variables and to add those references to the given graph.
1304 *
1305 * @param source the element representing the variable whose initializer will be visited
1306 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables
1307 * (tails) in their initializers
1308 */
1309 ReferenceFinder(this._source, this._referenceGraph);
1310
1311 @override
1312 Object visitSimpleIdentifier(SimpleIdentifier node) {
1313 Element element = node.staticElement;
1314 if (element is PropertyAccessorElement) {
1315 element = (element as PropertyAccessorElement).variable;
1316 }
1317 if (element is VariableElement) {
1318 VariableElement variable = element as VariableElement;
1319 if (variable.isConst) {
1320 _referenceGraph.addEdge(_source, variable);
1321 }
1322 }
1323 return null;
1324 }
1325 }
1326
1327 /**
1328 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid
1329 * compile time constant expression.
1330 */
1331 class ValidResult extends EvaluationResultImpl {
1332 /**
1333 * The value of the expression.
1334 */
1335 final DartObjectImpl value;
1336
1337 /**
1338 * Initialize a newly created result to represent the given value.
1339 *
1340 * @param value the value of the expression
1341 */
1342 ValidResult(this.value);
1343
1344 @override
1345 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToValid(typeProvider, node, t his);
1346
1347 /**
1348 * Return the result of applying boolean conversion to this result.
1349 *
1350 * @param node the node against which errors should be reported
1351 * @return the result of applying boolean conversion to the given value
1352 */
1353 @override
1354 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node) {
1355 try {
1356 return _valueOf(value.convertToBool(typeProvider));
1357 } on EvaluationException catch (exception) {
1358 return _error(node, exception.errorCode);
1359 }
1360 }
1361
1362 @override
1363 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitAndValid(typeProvider, nod e, this);
1364
1365 @override
1366 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node) {
1367 try {
1368 return _valueOf(value.bitNot(typeProvider));
1369 } on EvaluationException catch (exception) {
1370 return _error(node, exception.errorCode);
1371 }
1372 }
1373
1374 @override
1375 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.bitOrValid(typeProvider, node, this);
1376
1377 @override
1378 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitXorValid(typeProvider, nod e, this);
1379
1380 @override
1381 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand) => rightOperand.concatenateValid(typeProvider, node, this);
1382
1383 @override
1384 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.divideValid(typeProvider, nod e, this);
1385
1386 @override
1387 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand) => rightOperand.equalEqualValid(typeProvider, n ode, this);
1388
1389 @override
1390 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) {
1391 if (result is! ValidResult) {
1392 return false;
1393 }
1394 return value == (result as ValidResult).value;
1395 }
1396
1397 @override
1398 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand) => rightOperand.greaterThanValid(typePro vider, node, this);
1399
1400 @override
1401 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand) => rightOperand.greaterThanOrEqua lValid(typeProvider, node, this);
1402
1403 @override
1404 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideValid(typ eProvider, node, this);
1405
1406 /**
1407 * Return `true` if this object represents an object whose type is 'bool'.
1408 *
1409 * @return `true` if this object represents a boolean value
1410 */
1411 bool get isBool => value.isBool;
1412
1413 /**
1414 * Return `true` if this object represents an object whose type is either 'boo l', 'num',
1415 * 'String', or 'Null'.
1416 *
1417 * @return `true` if this object represents either a boolean, numeric, string or null value
1418 */
1419 bool get isBoolNumStringOrNull => value.isBoolNumStringOrNull;
1420
1421 /**
1422 * Return `true` if this result represents the value 'false'.
1423 *
1424 * @return `true` if this result represents the value 'false'
1425 */
1426 bool get isFalse => value.isFalse;
1427
1428 /**
1429 * Return `true` if this result represents the value 'null'.
1430 *
1431 * @return `true` if this result represents the value 'null'
1432 */
1433 bool get isNull => value.isNull;
1434
1435 /**
1436 * Return `true` if this result represents the value 'true'.
1437 *
1438 * @return `true` if this result represents the value 'true'
1439 */
1440 bool get isTrue => value.isTrue;
1441
1442 /**
1443 * Return `true` if this object represents an instance of a user-defined class .
1444 *
1445 * @return `true` if this object represents an instance of a user-defined clas s
1446 */
1447 bool get isUserDefinedObject => value.isUserDefinedObject;
1448
1449 @override
1450 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.lessThanValid(typeProvider, node, this);
1451
1452 @override
1453 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand) => rightOperand.lessThanOrEqualValid (typeProvider, node, this);
1454
1455 @override
1456 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.logicalAndValid(typeProvi der, node, this);
1457
1458 @override
1459 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node) {
1460 try {
1461 return _valueOf(value.logicalNot(typeProvider));
1462 } on EvaluationException catch (exception) {
1463 return _error(node, exception.errorCode);
1464 }
1465 }
1466
1467 @override
1468 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.logicalOrValid(typeProvide r, node, this);
1469
1470 @override
1471 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.minusValid(typeProvider, node, this);
1472
1473 @override
1474 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node) {
1475 try {
1476 return _valueOf(value.negated(typeProvider));
1477 } on EvaluationException catch (exception) {
1478 return _error(node, exception.errorCode);
1479 }
1480 }
1481
1482 @override
1483 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.notEqualValid(typeProvider, node, this);
1484
1485 @override
1486 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node) {
1487 try {
1488 return _valueOf(value.performToString(typeProvider));
1489 } on EvaluationException catch (exception) {
1490 return _error(node, exception.errorCode);
1491 }
1492 }
1493
1494 @override
1495 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.remainderValid(typeProvide r, node, this);
1496
1497 @override
1498 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.shiftLeftValid(typeProvide r, node, this);
1499
1500 @override
1501 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.shiftRightValid(typeProvi der, node, this);
1502
1503 @override
1504 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.timesValid(typeProvider, node, this);
1505
1506 @override
1507 String toString() {
1508 if (value == null) {
1509 return "null";
1510 }
1511 return value.toString();
1512 }
1513
1514 @override
1515 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1516
1517 @override
1518 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
1519 try {
1520 return _valueOf(leftOperand.value.add(typeProvider, value));
1521 } on EvaluationException catch (exception) {
1522 return _error(node, exception.errorCode);
1523 }
1524 }
1525
1526 @override
1527 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
1528
1529 @override
1530 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
1531 try {
1532 return _valueOf(leftOperand.value.bitAnd(typeProvider, value));
1533 } on EvaluationException catch (exception) {
1534 return _error(node, exception.errorCode);
1535 }
1536 }
1537
1538 @override
1539 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1540
1541 @override
1542 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
1543 try {
1544 return _valueOf(leftOperand.value.bitOr(typeProvider, value));
1545 } on EvaluationException catch (exception) {
1546 return _error(node, exception.errorCode);
1547 }
1548 }
1549
1550 @override
1551 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
1552
1553 @override
1554 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
1555 try {
1556 return _valueOf(leftOperand.value.bitXor(typeProvider, value));
1557 } on EvaluationException catch (exception) {
1558 return _error(node, exception.errorCode);
1559 }
1560 }
1561
1562 @override
1563 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => leftOperand;
1564
1565 @override
1566 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand) {
1567 try {
1568 return _valueOf(leftOperand.value.concatenate(typeProvider, value));
1569 } on EvaluationException catch (exception) {
1570 return _error(node, exception.errorCode);
1571 }
1572 }
1573
1574 @override
1575 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
1576
1577 @override
1578 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
1579 try {
1580 return _valueOf(leftOperand.value.divide(typeProvider, value));
1581 } on EvaluationException catch (exception) {
1582 return _error(node, exception.errorCode);
1583 }
1584 }
1585
1586 @override
1587 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => leftOperand;
1588
1589 @override
1590 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand) {
1591 try {
1592 return _valueOf(leftOperand.value.equalEqual(typeProvider, value));
1593 } on EvaluationException catch (exception) {
1594 return _error(node, exception.errorCode);
1595 }
1596 }
1597
1598 @override
1599 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => leftOperand;
1600
1601 @override
1602 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => leftOperand;
1603
1604 @override
1605 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand) {
1606 try {
1607 return _valueOf(leftOperand.value.greaterThanOrEqual(typeProvider, value)) ;
1608 } on EvaluationException catch (exception) {
1609 return _error(node, exception.errorCode);
1610 }
1611 }
1612
1613 @override
1614 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand) {
1615 try {
1616 return _valueOf(leftOperand.value.greaterThan(typeProvider, value));
1617 } on EvaluationException catch (exception) {
1618 return _error(node, exception.errorCode);
1619 }
1620 }
1621
1622 @override
1623 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => leftOperand;
1624
1625 @override
1626 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand) {
1627 try {
1628 return _valueOf(leftOperand.value.integerDivide(typeProvider, value));
1629 } on EvaluationException catch (exception) {
1630 return _error(node, exception.errorCode);
1631 }
1632 }
1633
1634 @override
1635 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
1636
1637 @override
1638 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => leftOperand;
1639
1640 @override
1641 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand) {
1642 try {
1643 return _valueOf(leftOperand.value.lessThanOrEqual(typeProvider, value));
1644 } on EvaluationException catch (exception) {
1645 return _error(node, exception.errorCode);
1646 }
1647 }
1648
1649 @override
1650 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) {
1651 try {
1652 return _valueOf(leftOperand.value.lessThan(typeProvider, value));
1653 } on EvaluationException catch (exception) {
1654 return _error(node, exception.errorCode);
1655 }
1656 }
1657
1658 @override
1659 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
1660
1661 @override
1662 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) {
1663 try {
1664 return _valueOf(leftOperand.value.logicalAnd(typeProvider, value));
1665 } on EvaluationException catch (exception) {
1666 return _error(node, exception.errorCode);
1667 }
1668 }
1669
1670 @override
1671 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
1672
1673 @override
1674 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
1675 try {
1676 return _valueOf(leftOperand.value.logicalOr(typeProvider, value));
1677 } on EvaluationException catch (exception) {
1678 return _error(node, exception.errorCode);
1679 }
1680 }
1681
1682 @override
1683 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1684
1685 @override
1686 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
1687 try {
1688 return _valueOf(leftOperand.value.minus(typeProvider, value));
1689 } on EvaluationException catch (exception) {
1690 return _error(node, exception.errorCode);
1691 }
1692 }
1693
1694 @override
1695 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
1696
1697 @override
1698 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) {
1699 try {
1700 return _valueOf(leftOperand.value.notEqual(typeProvider, value));
1701 } on EvaluationException catch (exception) {
1702 return _error(node, exception.errorCode);
1703 }
1704 }
1705
1706 @override
1707 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
1708
1709 @override
1710 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
1711 try {
1712 return _valueOf(leftOperand.value.remainder(typeProvider, value));
1713 } on EvaluationException catch (exception) {
1714 return _error(node, exception.errorCode);
1715 }
1716 }
1717
1718 @override
1719 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
1720
1721 @override
1722 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
1723 try {
1724 return _valueOf(leftOperand.value.shiftLeft(typeProvider, value));
1725 } on EvaluationException catch (exception) {
1726 return _error(node, exception.errorCode);
1727 }
1728 }
1729
1730 @override
1731 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
1732
1733 @override
1734 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) {
1735 try {
1736 return _valueOf(leftOperand.value.shiftRight(typeProvider, value));
1737 } on EvaluationException catch (exception) {
1738 return _error(node, exception.errorCode);
1739 }
1740 }
1741
1742 @override
1743 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
1744
1745 @override
1746 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
1747 try {
1748 return _valueOf(leftOperand.value.times(typeProvider, value));
1749 } on EvaluationException catch (exception) {
1750 return _error(node, exception.errorCode);
1751 }
1752 }
1753
1754 /**
1755 * Return a result object representing an error associated with the given node .
1756 *
1757 * @param node the AST node associated with the error
1758 * @param code the error code indicating the nature of the error
1759 * @return a result object representing an error associated with the given nod e
1760 */
1761 ErrorResult _error(AstNode node, ErrorCode code) => new ErrorResult.con1(node, code);
1762
1763 /**
1764 * Return a result object representing the given value.
1765 *
1766 * @param value the value to be represented as a result object
1767 * @return a result object representing the given value
1768 */
1769 ValidResult _valueOf(DartObjectImpl value) => new ValidResult(value);
1770 }
1771
1772 /**
1773 * Instances of the class `BoolState` represent the state of an object represent ing a boolean
1774 * value.
1775 */
1776 class BoolState extends InstanceState {
1777 /**
1778 * The value of this instance.
1779 */
1780 final bool value;
1781
1782 /**
1783 * An instance representing the boolean value 'false'.
1784 */
1785 static BoolState FALSE_STATE = new BoolState(false);
1786
1787 /**
1788 * An instance representing the boolean value 'true'.
1789 */
1790 static BoolState TRUE_STATE = new BoolState(true);
1791
1792 /**
1793 * A state that can be used to represent a boolean whose value is not known.
1794 */
1795 static BoolState UNKNOWN_VALUE = new BoolState(null);
1796
1797 /**
1798 * Return the boolean state representing the given boolean value.
1799 *
1800 * @param value the value to be represented
1801 * @return the boolean state representing the given boolean value
1802 */
1803 static BoolState from(bool value) => value ? BoolState.TRUE_STATE : BoolState. FALSE_STATE;
1804
1805 /**
1806 * Initialize a newly created state to represent the given value.
1807 *
1808 * @param value the value of this instance
1809 */
1810 BoolState(this.value);
1811
1812 @override
1813 BoolState convertToBool() => this;
1814
1815 @override
1816 StringState convertToString() {
1817 if (value == null) {
1818 return StringState.UNKNOWN_VALUE;
1819 }
1820 return new StringState(value ? "true" : "false");
1821 }
1822
1823 @override
1824 BoolState equalEqual(InstanceState rightOperand) {
1825 assertBoolNumStringOrNull(rightOperand);
1826 if (value == null) {
1827 return UNKNOWN_VALUE;
1828 }
1829 if (rightOperand is BoolState) {
1830 bool rightValue = rightOperand.value;
1831 if (rightValue == null) {
1832 return UNKNOWN_VALUE;
1833 }
1834 return BoolState.from(identical(value, rightValue));
1835 } else if (rightOperand is DynamicState) {
1836 return UNKNOWN_VALUE;
1837 }
1838 return FALSE_STATE;
1839 }
1840
1841 @override
1842 bool operator ==(Object object) => object is BoolState && identical(value, obj ect.value);
1843
1844 @override
1845 String get typeName => "bool";
1846
1847 @override
1848 bool get hasExactValue => true;
1849
1850 @override
1851 int get hashCode => value == null ? 0 : (value ? 2 : 3);
1852
1853 /**
1854 * Return `true` if this object represents an object whose type is 'bool'.
1855 *
1856 * @return `true` if this object represents a boolean value
1857 */
1858 @override
1859 bool get isBool => true;
1860
1861 @override
1862 bool get isBoolNumStringOrNull => true;
1863
1864 @override
1865 BoolState logicalAnd(InstanceState rightOperand) {
1866 assertBool(rightOperand);
1867 if (value == null) {
1868 return UNKNOWN_VALUE;
1869 }
1870 return value ? rightOperand.convertToBool() : FALSE_STATE;
1871 }
1872
1873 @override
1874 BoolState logicalNot() {
1875 if (value == null) {
1876 return UNKNOWN_VALUE;
1877 }
1878 return value ? FALSE_STATE : TRUE_STATE;
1879 }
1880
1881 @override
1882 BoolState logicalOr(InstanceState rightOperand) {
1883 assertBool(rightOperand);
1884 if (value == null) {
1885 return UNKNOWN_VALUE;
1886 }
1887 return value ? TRUE_STATE : rightOperand.convertToBool();
1888 }
1889
1890 @override
1891 String toString() => value == null ? "-unknown-" : (value ? "true" : "false");
1892 } 946 }
1893 947
1894 /** 948 /**
1895 * Instances of the class `DartObjectImpl` represent an instance of a Dart class . 949 * Instances of the class `DartObjectImpl` represent an instance of a Dart class .
1896 */ 950 */
1897 class DartObjectImpl implements DartObject { 951 class DartObjectImpl implements DartObject {
1898 /** 952 /**
1899 * The run-time type of this object. 953 * The run-time type of this object.
1900 */ 954 */
1901 final InterfaceType type; 955 final InterfaceType type;
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
2819 if (rightOperand is IntState) { 1873 if (rightOperand is IntState) {
2820 return IntState.UNKNOWN_VALUE; 1874 return IntState.UNKNOWN_VALUE;
2821 } else if (rightOperand is DoubleState) { 1875 } else if (rightOperand is DoubleState) {
2822 return DoubleState.UNKNOWN_VALUE; 1876 return DoubleState.UNKNOWN_VALUE;
2823 } 1877 }
2824 return NumState.UNKNOWN_VALUE; 1878 return NumState.UNKNOWN_VALUE;
2825 } 1879 }
2826 } 1880 }
2827 1881
2828 /** 1882 /**
1883 * Instances of the class `ErrorResult` represent the result of evaluating an ex pression that
1884 * is not a valid compile time constant.
1885 */
1886 class ErrorResult extends EvaluationResultImpl {
1887 /**
1888 * The errors that prevent the expression from being a valid compile time cons tant.
1889 */
1890 List<ErrorResult_ErrorData> _errors = new List<ErrorResult_ErrorData>();
1891
1892 /**
1893 * Initialize a newly created result representing the error with the given cod e reported against
1894 * the given node.
1895 *
1896 * @param node the node against which the error should be reported
1897 * @param errorCode the error code for the error to be generated
1898 */
1899 ErrorResult.con1(AstNode node, ErrorCode errorCode) {
1900 _errors.add(new ErrorResult_ErrorData(node, errorCode));
1901 }
1902
1903 /**
1904 * Initialize a newly created result to represent the union of the errors in t he given result
1905 * objects.
1906 *
1907 * @param firstResult the first set of results being merged
1908 * @param secondResult the second set of results being merged
1909 */
1910 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) {
1911 _errors.addAll(firstResult._errors);
1912 _errors.addAll(secondResult._errors);
1913 }
1914
1915 @override
1916 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToError(node, this);
1917
1918 @override
1919 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node) => this;
1920
1921 @override
1922 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitAndError(node, this);
1923
1924 @override
1925 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node) => thi s;
1926
1927 @override
1928 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.bitOrError(node, this);
1929
1930 @override
1931 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitXorError(node, this);
1932
1933 @override
1934 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand) => rightOperand.concatenateError(node, this);
1935
1936 @override
1937 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.divideError(node, this);
1938
1939 @override
1940 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand) => rightOperand.equalEqualError(node, this);
1941
1942 @override
1943 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) => fa lse;
1944
1945 List<ErrorResult_ErrorData> get errorData => _errors;
1946
1947 @override
1948 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand) => rightOperand.greaterThanError(node, t his);
1949
1950 @override
1951 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand) => rightOperand.greaterThanOrEqua lError(node, this);
1952
1953 @override
1954 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideError(nod e, this);
1955
1956 @override
1957 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand) => this;
1958
1959 @override
1960 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.lessThanError(node, this);
1961
1962 @override
1963 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand) => rightOperand.lessThanOrEqualError (node, this);
1964
1965 @override
1966 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.logicalAndError(node, thi s);
1967
1968 @override
1969 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node) => this;
1970
1971 @override
1972 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.logicalOrError(node, this) ;
1973
1974 @override
1975 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.minusError(node, this);
1976
1977 @override
1978 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node) => th is;
1979
1980 @override
1981 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.notEqualError(node, this);
1982
1983 @override
1984 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node) => this;
1985
1986 @override
1987 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.remainderError(node, this) ;
1988
1989 @override
1990 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.shiftLeftError(node, this) ;
1991
1992 @override
1993 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.shiftRightError(node, thi s);
1994
1995 @override
1996 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.timesError(node, this);
1997
1998 @override
1999 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2000
2001 @override
2002 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2003
2004 @override
2005 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
2006
2007 @override
2008 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
2009
2010 @override
2011 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2012
2013 @override
2014 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2015
2016 @override
2017 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
2018
2019 @override
2020 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
2021
2022 @override
2023 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2024
2025 @override
2026 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand) => this;
2027
2028 @override
2029 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
2030
2031 @override
2032 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
2033
2034 @override
2035 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => new ErrorResult.con2(this, leftOperand);
2036
2037 @override
2038 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand) => this;
2039
2040 @override
2041 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => new ErrorResult.con2(this, leftOperand);
2042
2043 @override
2044 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => new ErrorResult.con2(this, leftOperand);
2045
2046 @override
2047 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand) => this;
2048
2049 @override
2050 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand) => this;
2051
2052 @override
2053 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => new ErrorResult.con2(this, leftOperand);
2054
2055 @override
2056 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
2057
2058 @override
2059 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => new ErrorResult.con2(this, leftOperand);
2060
2061 @override
2062 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand) => this;
2063
2064 @override
2065 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) => this;
2066
2067 @override
2068 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
2069
2070 @override
2071 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) => this;
2072
2073 @override
2074 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
2075
2076 @override
2077 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
2078
2079 @override
2080 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2081
2082 @override
2083 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2084
2085 @override
2086 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
2087
2088 @override
2089 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) => this;
2090
2091 @override
2092 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
2093
2094 @override
2095 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
2096
2097 @override
2098 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
2099
2100 @override
2101 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
2102
2103 @override
2104 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
2105
2106 @override
2107 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) => this;
2108
2109 @override
2110 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2111
2112 @override
2113 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2114 }
2115
2116 class ErrorResult_ErrorData {
2117 /**
2118 * The node against which the error should be reported.
2119 */
2120 final AstNode node;
2121
2122 /**
2123 * The error code for the error to be generated.
2124 */
2125 final ErrorCode errorCode;
2126
2127 /**
2128 * Initialize a newly created data holder to represent the error with the give n code reported
2129 * against the given node.
2130 *
2131 * @param node the node against which the error should be reported
2132 * @param errorCode the error code for the error to be generated
2133 */
2134 ErrorResult_ErrorData(this.node, this.errorCode);
2135 }
2136
2137 /**
2829 * Instances of the class `EvaluationException` represent a run-time exception t hat would be 2138 * Instances of the class `EvaluationException` represent a run-time exception t hat would be
2830 * thrown during the evaluation of Dart code. 2139 * thrown during the evaluation of Dart code.
2831 */ 2140 */
2832 class EvaluationException extends JavaException { 2141 class EvaluationException extends JavaException {
2833 /** 2142 /**
2834 * The error code associated with the exception. 2143 * The error code associated with the exception.
2835 */ 2144 */
2836 final ErrorCode errorCode; 2145 final ErrorCode errorCode;
2837 2146
2838 /** 2147 /**
2839 * Initialize a newly created exception to have the given error code. 2148 * Initialize a newly created exception to have the given error code.
2840 * 2149 *
2841 * @param errorCode the error code associated with the exception 2150 * @param errorCode the error code associated with the exception
2842 */ 2151 */
2843 EvaluationException(this.errorCode); 2152 EvaluationException(this.errorCode);
2844 } 2153 }
2845 2154
2846 /** 2155 /**
2156 * Instances of the class `EvaluationResult` represent the result of attempting to evaluate an
2157 * expression.
2158 */
2159 class EvaluationResult {
2160 /**
2161 * Return an evaluation result representing the result of evaluating an expres sion that is not a
2162 * compile-time constant because of the given errors.
2163 *
2164 * @param errors the errors that should be reported for the expression(s) that were evaluated
2165 * @return the result of evaluating an expression that is not a compile-time c onstant
2166 */
2167 static EvaluationResult forErrors(List<AnalysisError> errors) => new Evaluatio nResult(null, errors);
2168
2169 /**
2170 * Return an evaluation result representing the result of evaluating an expres sion that is a
2171 * compile-time constant that evaluates to the given value.
2172 *
2173 * @param value the value of the expression
2174 * @return the result of evaluating an expression that is a compile-time const ant
2175 */
2176 static EvaluationResult forValue(DartObject value) => new EvaluationResult(val ue, null);
2177
2178 /**
2179 * The value of the expression.
2180 */
2181 final DartObject value;
2182
2183 /**
2184 * The errors that should be reported for the expression(s) that were evaluate d.
2185 */
2186 final List<AnalysisError> _errors;
2187
2188 /**
2189 * Initialize a newly created result object with the given state. Clients shou ld use one of the
2190 * factory methods: [forErrors] and [forValue].
2191 *
2192 * @param value the value of the expression
2193 * @param errors the errors that should be reported for the expression(s) that were evaluated
2194 */
2195 EvaluationResult(this.value, this._errors);
2196
2197 /**
2198 * Return an array containing the errors that should be reported for the expre ssion(s) that were
2199 * evaluated. If there are no such errors, the array will be empty. The array can be empty even if
2200 * the expression is not a valid compile time constant if the errors would hav e been reported by
2201 * other parts of the analysis engine.
2202 */
2203 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS : _errors;
2204
2205 /**
2206 * Return `true` if the expression is a compile-time constant expression that would not
2207 * throw an exception when evaluated.
2208 *
2209 * @return `true` if the expression is a valid compile-time constant expressio n
2210 */
2211 bool get isValid => _errors == null;
2212 }
2213
2214 /**
2215 * Instances of the class `InternalResult` represent the result of attempting to evaluate a
2216 * expression.
2217 */
2218 abstract class EvaluationResultImpl {
2219 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand);
2220
2221 /**
2222 * Return the result of applying boolean conversion to this result.
2223 *
2224 * @param typeProvider the type provider used to access known types
2225 * @param node the node against which errors should be reported
2226 * @return the result of applying boolean conversion to the given value
2227 */
2228 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node);
2229
2230 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
2231
2232 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node);
2233
2234 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
2235
2236 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
2237
2238 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand);
2239
2240 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
2241
2242 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand);
2243
2244 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result);
2245
2246 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand);
2247
2248 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand);
2249
2250 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand);
2251
2252 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand);
2253
2254 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand);
2255
2256 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand);
2257
2258 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node);
2259
2260 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
2261
2262 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
2263
2264 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node);
2265
2266 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand);
2267
2268 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node);
2269
2270 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
2271
2272 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
2273
2274 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand);
2275
2276 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
2277
2278 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand );
2279
2280 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2281
2282 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d);
2283
2284 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
2285
2286 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand );
2287
2288 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2289
2290 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d);
2291
2292 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
2293
2294 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand );
2295
2296 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand);
2297
2298 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d);
2299
2300 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
2301
2302 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) ;
2303
2304 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand);
2305
2306 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand);
2307
2308 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand);
2309
2310 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand);
2311
2312 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand);
2313
2314 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand);
2315
2316 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand);
2317
2318 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and);
2319
2320 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand);
2321
2322 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand);
2323
2324 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand);
2325
2326 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand);
2327
2328 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand);
2329
2330 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand);
2331
2332 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
2333
2334 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand );
2335
2336 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2337
2338 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and);
2339
2340 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand);
2341
2342 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand);
2343
2344 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
2345
2346 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand);
2347
2348 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
2349
2350 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand);
2351
2352 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand);
2353
2354 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand );
2355
2356 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2357 }
2358
2359 /**
2847 * Instances of the class `FunctionState` represent the state of an object repre senting a 2360 * Instances of the class `FunctionState` represent the state of an object repre senting a
2848 * function. 2361 * function.
2849 */ 2362 */
2850 class FunctionState extends InstanceState { 2363 class FunctionState extends InstanceState {
2851 /** 2364 /**
2852 * The element representing the function being modeled. 2365 * The element representing the function being modeled.
2853 */ 2366 */
2854 final ExecutableElement _element; 2367 final ExecutableElement _element;
2855 2368
2856 /** 2369 /**
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
3617 } 3130 }
3618 double result = value.toDouble() / rightValue; 3131 double result = value.toDouble() / rightValue;
3619 return new IntState(result.toInt()); 3132 return new IntState(result.toInt());
3620 } else if (rightOperand is DynamicState || rightOperand is NumState) { 3133 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3621 return UNKNOWN_VALUE; 3134 return UNKNOWN_VALUE;
3622 } 3135 }
3623 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON); 3136 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3624 } 3137 }
3625 3138
3626 @override 3139 @override
3140 bool get isBoolNumStringOrNull => true;
3141
3142 @override
3143 BoolState lessThan(InstanceState rightOperand) {
3144 assertNumOrNull(rightOperand);
3145 if (value == null) {
3146 return BoolState.UNKNOWN_VALUE;
3147 }
3148 if (rightOperand is IntState) {
3149 int rightValue = rightOperand.value;
3150 if (rightValue == null) {
3151 return BoolState.UNKNOWN_VALUE;
3152 }
3153 return BoolState.from(value.compareTo(rightValue) < 0);
3154 } else if (rightOperand is DoubleState) {
3155 double rightValue = rightOperand.value;
3156 if (rightValue == null) {
3157 return BoolState.UNKNOWN_VALUE;
3158 }
3159 return BoolState.from(value.toDouble() < rightValue);
3160 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3161 return BoolState.UNKNOWN_VALUE;
3162 }
3163 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3164 }
3165
3166 @override
3167 BoolState lessThanOrEqual(InstanceState rightOperand) {
3168 assertNumOrNull(rightOperand);
3169 if (value == null) {
3170 return BoolState.UNKNOWN_VALUE;
3171 }
3172 if (rightOperand is IntState) {
3173 int rightValue = rightOperand.value;
3174 if (rightValue == null) {
3175 return BoolState.UNKNOWN_VALUE;
3176 }
3177 return BoolState.from(value.compareTo(rightValue) <= 0);
3178 } else if (rightOperand is DoubleState) {
3179 double rightValue = rightOperand.value;
3180 if (rightValue == null) {
3181 return BoolState.UNKNOWN_VALUE;
3182 }
3183 return BoolState.from(value.toDouble() <= rightValue);
3184 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3185 return BoolState.UNKNOWN_VALUE;
3186 }
3187 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3188 }
3189
3190 @override
3191 NumState minus(InstanceState rightOperand) {
3192 assertNumOrNull(rightOperand);
3193 if (value == null) {
3194 if (rightOperand is DoubleState) {
3195 return DoubleState.UNKNOWN_VALUE;
3196 }
3197 return UNKNOWN_VALUE;
3198 }
3199 if (rightOperand is IntState) {
3200 int rightValue = rightOperand.value;
3201 if (rightValue == null) {
3202 return UNKNOWN_VALUE;
3203 }
3204 return new IntState(value - rightValue);
3205 } else if (rightOperand is DoubleState) {
3206 double rightValue = rightOperand.value;
3207 if (rightValue == null) {
3208 return DoubleState.UNKNOWN_VALUE;
3209 }
3210 return new DoubleState(value.toDouble() - rightValue);
3211 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3212 return UNKNOWN_VALUE;
3213 }
3214 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3215 }
3216
3217 @override
3218 NumState negated() {
3219 if (value == null) {
3220 return UNKNOWN_VALUE;
3221 }
3222 return new IntState(-value);
3223 }
3224
3225 @override
3226 NumState remainder(InstanceState rightOperand) {
3227 assertNumOrNull(rightOperand);
3228 if (value == null) {
3229 if (rightOperand is DoubleState) {
3230 return DoubleState.UNKNOWN_VALUE;
3231 }
3232 return UNKNOWN_VALUE;
3233 }
3234 if (rightOperand is IntState) {
3235 int rightValue = rightOperand.value;
3236 if (rightValue == null) {
3237 return UNKNOWN_VALUE;
3238 } else if (rightValue == 0) {
3239 return new DoubleState(value.toDouble() % rightValue.toDouble());
3240 }
3241 return new IntState(value.remainder(rightValue));
3242 } else if (rightOperand is DoubleState) {
3243 double rightValue = rightOperand.value;
3244 if (rightValue == null) {
3245 return DoubleState.UNKNOWN_VALUE;
3246 }
3247 return new DoubleState(value.toDouble() % rightValue);
3248 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3249 return UNKNOWN_VALUE;
3250 }
3251 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3252 }
3253
3254 @override
3255 IntState shiftLeft(InstanceState rightOperand) {
3256 assertIntOrNull(rightOperand);
3257 if (value == null) {
3258 return UNKNOWN_VALUE;
3259 }
3260 if (rightOperand is IntState) {
3261 int rightValue = rightOperand.value;
3262 if (rightValue == null) {
3263 return UNKNOWN_VALUE;
3264 } else if (rightValue.bitLength > 31) {
3265 return UNKNOWN_VALUE;
3266 }
3267 return new IntState(value << rightValue);
3268 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3269 return UNKNOWN_VALUE;
3270 }
3271 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3272 }
3273
3274 @override
3275 IntState shiftRight(InstanceState rightOperand) {
3276 assertIntOrNull(rightOperand);
3277 if (value == null) {
3278 return UNKNOWN_VALUE;
3279 }
3280 if (rightOperand is IntState) {
3281 int rightValue = rightOperand.value;
3282 if (rightValue == null) {
3283 return UNKNOWN_VALUE;
3284 } else if (rightValue.bitLength > 31) {
3285 return UNKNOWN_VALUE;
3286 }
3287 return new IntState(value >> rightValue);
3288 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3289 return UNKNOWN_VALUE;
3290 }
3291 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3292 }
3293
3294 @override
3295 NumState times(InstanceState rightOperand) {
3296 assertNumOrNull(rightOperand);
3297 if (value == null) {
3298 if (rightOperand is DoubleState) {
3299 return DoubleState.UNKNOWN_VALUE;
3300 }
3301 return UNKNOWN_VALUE;
3302 }
3303 if (rightOperand is IntState) {
3304 int rightValue = rightOperand.value;
3305 if (rightValue == null) {
3306 return UNKNOWN_VALUE;
3307 }
3308 return new IntState(value * rightValue);
3309 } else if (rightOperand is DoubleState) {
3310 double rightValue = rightOperand.value;
3311 if (rightValue == null) {
3312 return DoubleState.UNKNOWN_VALUE;
3313 }
3314 return new DoubleState(value.toDouble() * rightValue);
3315 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3316 return UNKNOWN_VALUE;
3317 }
3318 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3319 }
3320
3321 @override
3322 String toString() => value == null ? "-unknown-" : value.toString();
3323 }
3324
3325 /**
3326 * The unique instance of the class `ListState` represents the state of an objec t representing
3327 * a list.
3328 */
3329 class ListState extends InstanceState {
3330 /**
3331 * The elements of the list.
3332 */
3333 final List<DartObjectImpl> _elements;
3334
3335 /**
3336 * Initialize a newly created state to represent a list with the given element s.
3337 *
3338 * @param elements the elements of the list
3339 */
3340 ListState(this._elements);
3341
3342 @override
3343 StringState convertToString() => StringState.UNKNOWN_VALUE;
3344
3345 @override
3346 BoolState equalEqual(InstanceState rightOperand) {
3347 assertBoolNumStringOrNull(rightOperand);
3348 if (rightOperand is DynamicState) {
3349 return BoolState.UNKNOWN_VALUE;
3350 }
3351 return BoolState.from(this == rightOperand);
3352 }
3353
3354 @override
3355 bool operator ==(Object object) {
3356 if (object is! ListState) {
3357 return false;
3358 }
3359 List<DartObjectImpl> otherElements = (object as ListState)._elements;
3360 int count = _elements.length;
3361 if (otherElements.length != count) {
3362 return false;
3363 } else if (count == 0) {
3364 return true;
3365 }
3366 for (int i = 0; i < count; i++) {
3367 if (_elements[i] != otherElements[i]) {
3368 return false;
3369 }
3370 }
3371 return true;
3372 }
3373
3374 @override
3375 String get typeName => "List";
3376
3377 @override
3378 List<Object> get value {
3379 int count = _elements.length;
3380 List<Object> result = new List<Object>(count);
3381 for (int i = 0; i < count; i++) {
3382 DartObjectImpl element = _elements[i];
3383 if (!element.hasExactValue) {
3384 return null;
3385 }
3386 result[i] = element.value;
3387 }
3388 return result;
3389 }
3390
3391 @override
3392 bool get hasExactValue {
3393 int count = _elements.length;
3394 for (int i = 0; i < count; i++) {
3395 if (!_elements[i].hasExactValue) {
3396 return false;
3397 }
3398 }
3399 return true;
3400 }
3401
3402 @override
3403 int get hashCode {
3404 int value = 0;
3405 int count = _elements.length;
3406 for (int i = 0; i < count; i++) {
3407 value = (value << 3) ^ _elements[i].hashCode;
3408 }
3409 return value;
3410 }
3411 }
3412
3413 /**
3414 * The unique instance of the class `ListState` represents the state of an objec t representing
3415 * a map.
3416 */
3417 class MapState extends InstanceState {
3418 /**
3419 * The entries in the map.
3420 */
3421 final Map<DartObjectImpl, DartObjectImpl> _entries;
3422
3423 /**
3424 * Initialize a newly created state to represent a map with the given entries.
3425 *
3426 * @param entries the entries in the map
3427 */
3428 MapState(this._entries);
3429
3430 @override
3431 StringState convertToString() => StringState.UNKNOWN_VALUE;
3432
3433 @override
3434 BoolState equalEqual(InstanceState rightOperand) {
3435 assertBoolNumStringOrNull(rightOperand);
3436 if (rightOperand is DynamicState) {
3437 return BoolState.UNKNOWN_VALUE;
3438 }
3439 return BoolState.from(this == rightOperand);
3440 }
3441
3442 @override
3443 bool operator ==(Object object) {
3444 if (object is! MapState) {
3445 return false;
3446 }
3447 Map<DartObjectImpl, DartObjectImpl> otherElements = (object as MapState)._en tries;
3448 int count = _entries.length;
3449 if (otherElements.length != count) {
3450 return false;
3451 } else if (count == 0) {
3452 return true;
3453 }
3454 for (MapEntry<DartObjectImpl, DartObjectImpl> entry in getMapEntrySet(_entri es)) {
3455 DartObjectImpl key = entry.getKey();
3456 DartObjectImpl value = entry.getValue();
3457 DartObjectImpl otherValue = otherElements[key];
3458 if (value != otherValue) {
3459 return false;
3460 }
3461 }
3462 return true;
3463 }
3464
3465 @override
3466 String get typeName => "Map";
3467
3468 @override
3469 Map<Object, Object> get value {
3470 Map<Object, Object> result = new Map<Object, Object>();
3471 for (MapEntry<DartObjectImpl, DartObjectImpl> entry in getMapEntrySet(_entri es)) {
3472 DartObjectImpl key = entry.getKey();
3473 DartObjectImpl value = entry.getValue();
3474 if (!key.hasExactValue || !value.hasExactValue) {
3475 return null;
3476 }
3477 result[key.value] = value.value;
3478 }
3479 return result;
3480 }
3481
3482 @override
3483 bool get hasExactValue {
3484 for (MapEntry<DartObjectImpl, DartObjectImpl> entry in getMapEntrySet(_entri es)) {
3485 if (!entry.getKey().hasExactValue || !entry.getValue().hasExactValue) {
3486 return false;
3487 }
3488 }
3489 return true;
3490 }
3491
3492 @override
3493 int get hashCode {
3494 int value = 0;
3495 for (DartObjectImpl key in _entries.keys.toSet()) {
3496 value = (value << 3) ^ key.hashCode;
3497 }
3498 return value;
3499 }
3500 }
3501
3502 /**
3503 * The unique instance of the class `NullState` represents the state of the valu e 'null'.
3504 */
3505 class NullState extends InstanceState {
3506 /**
3507 * An instance representing the boolean value 'true'.
3508 */
3509 static NullState NULL_STATE = new NullState();
3510
3511 @override
3512 BoolState convertToBool() {
3513 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3514 }
3515
3516 @override
3517 StringState convertToString() => new StringState("null");
3518
3519 @override
3520 BoolState equalEqual(InstanceState rightOperand) {
3521 assertBoolNumStringOrNull(rightOperand);
3522 if (rightOperand is DynamicState) {
3523 return BoolState.UNKNOWN_VALUE;
3524 }
3525 return BoolState.from(rightOperand is NullState);
3526 }
3527
3528 @override
3529 bool operator ==(Object object) => object is NullState;
3530
3531 @override
3532 String get typeName => "Null";
3533
3534 @override
3535 bool get hasExactValue => true;
3536
3537 @override
3538 int get hashCode => 0;
3539
3540 @override
3541 bool get isBoolNumStringOrNull => true;
3542
3543 @override
3544 BoolState logicalNot() {
3545 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3546 }
3547
3548 @override
3549 String toString() => "null";
3550 }
3551
3552 /**
3553 * Instances of the class `NumState` represent the state of an object representi ng a number of
3554 * an unknown type (a 'num').
3555 */
3556 class NumState extends InstanceState {
3557 /**
3558 * A state that can be used to represent a number whose value is not known.
3559 */
3560 static NumState UNKNOWN_VALUE = new NumState();
3561
3562 @override
3563 NumState add(InstanceState rightOperand) {
3564 assertNumOrNull(rightOperand);
3565 return UNKNOWN_VALUE;
3566 }
3567
3568 @override
3569 StringState convertToString() => StringState.UNKNOWN_VALUE;
3570
3571 @override
3572 NumState divide(InstanceState rightOperand) {
3573 assertNumOrNull(rightOperand);
3574 return UNKNOWN_VALUE;
3575 }
3576
3577 @override
3578 bool operator ==(Object object) => object is NumState;
3579
3580 @override
3581 BoolState equalEqual(InstanceState rightOperand) {
3582 assertBoolNumStringOrNull(rightOperand);
3583 return BoolState.UNKNOWN_VALUE;
3584 }
3585
3586 @override
3587 String get typeName => "num";
3588
3589 @override
3590 BoolState greaterThan(InstanceState rightOperand) {
3591 assertNumOrNull(rightOperand);
3592 return BoolState.UNKNOWN_VALUE;
3593 }
3594
3595 @override
3596 BoolState greaterThanOrEqual(InstanceState rightOperand) {
3597 assertNumOrNull(rightOperand);
3598 return BoolState.UNKNOWN_VALUE;
3599 }
3600
3601 @override
3602 int get hashCode => 7;
3603
3604 @override
3605 IntState integerDivide(InstanceState rightOperand) {
3606 assertNumOrNull(rightOperand);
3607 if (rightOperand is IntState) {
3608 int rightValue = rightOperand.value;
3609 if (rightValue == null) {
3610 return IntState.UNKNOWN_VALUE;
3611 } else if (rightValue == 0) {
3612 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_IDB ZE);
3613 }
3614 } else if (rightOperand is DynamicState) {
3615 return IntState.UNKNOWN_VALUE;
3616 }
3617 return IntState.UNKNOWN_VALUE;
3618 }
3619
3620 @override
3627 bool get isBoolNumStringOrNull => true; 3621 bool get isBoolNumStringOrNull => true;
3628 3622
3629 @override 3623 @override
3630 BoolState lessThan(InstanceState rightOperand) { 3624 BoolState lessThan(InstanceState rightOperand) {
3631 assertNumOrNull(rightOperand); 3625 assertNumOrNull(rightOperand);
3632 if (value == null) {
3633 return BoolState.UNKNOWN_VALUE;
3634 }
3635 if (rightOperand is IntState) {
3636 int rightValue = rightOperand.value;
3637 if (rightValue == null) {
3638 return BoolState.UNKNOWN_VALUE;
3639 }
3640 return BoolState.from(value.compareTo(rightValue) < 0);
3641 } else if (rightOperand is DoubleState) {
3642 double rightValue = rightOperand.value;
3643 if (rightValue == null) {
3644 return BoolState.UNKNOWN_VALUE;
3645 }
3646 return BoolState.from(value.toDouble() < rightValue);
3647 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3648 return BoolState.UNKNOWN_VALUE;
3649 }
3650 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3651 }
3652
3653 @override
3654 BoolState lessThanOrEqual(InstanceState rightOperand) {
3655 assertNumOrNull(rightOperand);
3656 if (value == null) {
3657 return BoolState.UNKNOWN_VALUE;
3658 }
3659 if (rightOperand is IntState) {
3660 int rightValue = rightOperand.value;
3661 if (rightValue == null) {
3662 return BoolState.UNKNOWN_VALUE;
3663 }
3664 return BoolState.from(value.compareTo(rightValue) <= 0);
3665 } else if (rightOperand is DoubleState) {
3666 double rightValue = rightOperand.value;
3667 if (rightValue == null) {
3668 return BoolState.UNKNOWN_VALUE;
3669 }
3670 return BoolState.from(value.toDouble() <= rightValue);
3671 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3672 return BoolState.UNKNOWN_VALUE;
3673 }
3674 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3675 }
3676
3677 @override
3678 NumState minus(InstanceState rightOperand) {
3679 assertNumOrNull(rightOperand);
3680 if (value == null) {
3681 if (rightOperand is DoubleState) {
3682 return DoubleState.UNKNOWN_VALUE;
3683 }
3684 return UNKNOWN_VALUE;
3685 }
3686 if (rightOperand is IntState) {
3687 int rightValue = rightOperand.value;
3688 if (rightValue == null) {
3689 return UNKNOWN_VALUE;
3690 }
3691 return new IntState(value - rightValue);
3692 } else if (rightOperand is DoubleState) {
3693 double rightValue = rightOperand.value;
3694 if (rightValue == null) {
3695 return DoubleState.UNKNOWN_VALUE;
3696 }
3697 return new DoubleState(value.toDouble() - rightValue);
3698 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3699 return UNKNOWN_VALUE;
3700 }
3701 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3702 }
3703
3704 @override
3705 NumState negated() {
3706 if (value == null) {
3707 return UNKNOWN_VALUE;
3708 }
3709 return new IntState(-value);
3710 }
3711
3712 @override
3713 NumState remainder(InstanceState rightOperand) {
3714 assertNumOrNull(rightOperand);
3715 if (value == null) {
3716 if (rightOperand is DoubleState) {
3717 return DoubleState.UNKNOWN_VALUE;
3718 }
3719 return UNKNOWN_VALUE;
3720 }
3721 if (rightOperand is IntState) {
3722 int rightValue = rightOperand.value;
3723 if (rightValue == null) {
3724 return UNKNOWN_VALUE;
3725 } else if (rightValue == 0) {
3726 return new DoubleState(value.toDouble() % rightValue.toDouble());
3727 }
3728 return new IntState(value.remainder(rightValue));
3729 } else if (rightOperand is DoubleState) {
3730 double rightValue = rightOperand.value;
3731 if (rightValue == null) {
3732 return DoubleState.UNKNOWN_VALUE;
3733 }
3734 return new DoubleState(value.toDouble() % rightValue);
3735 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3736 return UNKNOWN_VALUE;
3737 }
3738 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3739 }
3740
3741 @override
3742 IntState shiftLeft(InstanceState rightOperand) {
3743 assertIntOrNull(rightOperand);
3744 if (value == null) {
3745 return UNKNOWN_VALUE;
3746 }
3747 if (rightOperand is IntState) {
3748 int rightValue = rightOperand.value;
3749 if (rightValue == null) {
3750 return UNKNOWN_VALUE;
3751 } else if (rightValue.bitLength > 31) {
3752 return UNKNOWN_VALUE;
3753 }
3754 return new IntState(value << rightValue);
3755 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3756 return UNKNOWN_VALUE;
3757 }
3758 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3759 }
3760
3761 @override
3762 IntState shiftRight(InstanceState rightOperand) {
3763 assertIntOrNull(rightOperand);
3764 if (value == null) {
3765 return UNKNOWN_VALUE;
3766 }
3767 if (rightOperand is IntState) {
3768 int rightValue = rightOperand.value;
3769 if (rightValue == null) {
3770 return UNKNOWN_VALUE;
3771 } else if (rightValue.bitLength > 31) {
3772 return UNKNOWN_VALUE;
3773 }
3774 return new IntState(value >> rightValue);
3775 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3776 return UNKNOWN_VALUE;
3777 }
3778 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3779 }
3780
3781 @override
3782 NumState times(InstanceState rightOperand) {
3783 assertNumOrNull(rightOperand);
3784 if (value == null) {
3785 if (rightOperand is DoubleState) {
3786 return DoubleState.UNKNOWN_VALUE;
3787 }
3788 return UNKNOWN_VALUE;
3789 }
3790 if (rightOperand is IntState) {
3791 int rightValue = rightOperand.value;
3792 if (rightValue == null) {
3793 return UNKNOWN_VALUE;
3794 }
3795 return new IntState(value * rightValue);
3796 } else if (rightOperand is DoubleState) {
3797 double rightValue = rightOperand.value;
3798 if (rightValue == null) {
3799 return DoubleState.UNKNOWN_VALUE;
3800 }
3801 return new DoubleState(value.toDouble() * rightValue);
3802 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3803 return UNKNOWN_VALUE;
3804 }
3805 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3806 }
3807
3808 @override
3809 String toString() => value == null ? "-unknown-" : value.toString();
3810 }
3811
3812 /**
3813 * The unique instance of the class `ListState` represents the state of an objec t representing
3814 * a list.
3815 */
3816 class ListState extends InstanceState {
3817 /**
3818 * The elements of the list.
3819 */
3820 final List<DartObjectImpl> _elements;
3821
3822 /**
3823 * Initialize a newly created state to represent a list with the given element s.
3824 *
3825 * @param elements the elements of the list
3826 */
3827 ListState(this._elements);
3828
3829 @override
3830 StringState convertToString() => StringState.UNKNOWN_VALUE;
3831
3832 @override
3833 BoolState equalEqual(InstanceState rightOperand) {
3834 assertBoolNumStringOrNull(rightOperand);
3835 if (rightOperand is DynamicState) {
3836 return BoolState.UNKNOWN_VALUE;
3837 }
3838 return BoolState.from(this == rightOperand);
3839 }
3840
3841 @override
3842 bool operator ==(Object object) {
3843 if (object is! ListState) {
3844 return false;
3845 }
3846 List<DartObjectImpl> otherElements = (object as ListState)._elements;
3847 int count = _elements.length;
3848 if (otherElements.length != count) {
3849 return false;
3850 } else if (count == 0) {
3851 return true;
3852 }
3853 for (int i = 0; i < count; i++) {
3854 if (_elements[i] != otherElements[i]) {
3855 return false;
3856 }
3857 }
3858 return true;
3859 }
3860
3861 @override
3862 String get typeName => "List";
3863
3864 @override
3865 List<Object> get value {
3866 int count = _elements.length;
3867 List<Object> result = new List<Object>(count);
3868 for (int i = 0; i < count; i++) {
3869 DartObjectImpl element = _elements[i];
3870 if (!element.hasExactValue) {
3871 return null;
3872 }
3873 result[i] = element.value;
3874 }
3875 return result;
3876 }
3877
3878 @override
3879 bool get hasExactValue {
3880 int count = _elements.length;
3881 for (int i = 0; i < count; i++) {
3882 if (!_elements[i].hasExactValue) {
3883 return false;
3884 }
3885 }
3886 return true;
3887 }
3888
3889 @override
3890 int get hashCode {
3891 int value = 0;
3892 int count = _elements.length;
3893 for (int i = 0; i < count; i++) {
3894 value = (value << 3) ^ _elements[i].hashCode;
3895 }
3896 return value;
3897 }
3898 }
3899
3900 /**
3901 * The unique instance of the class `ListState` represents the state of an objec t representing
3902 * a map.
3903 */
3904 class MapState extends InstanceState {
3905 /**
3906 * The entries in the map.
3907 */
3908 final Map<DartObjectImpl, DartObjectImpl> _entries;
3909
3910 /**
3911 * Initialize a newly created state to represent a map with the given entries.
3912 *
3913 * @param entries the entries in the map
3914 */
3915 MapState(this._entries);
3916
3917 @override
3918 StringState convertToString() => StringState.UNKNOWN_VALUE;
3919
3920 @override
3921 BoolState equalEqual(InstanceState rightOperand) {
3922 assertBoolNumStringOrNull(rightOperand);
3923 if (rightOperand is DynamicState) {
3924 return BoolState.UNKNOWN_VALUE;
3925 }
3926 return BoolState.from(this == rightOperand);
3927 }
3928
3929 @override
3930 bool operator ==(Object object) {
3931 if (object is! MapState) {
3932 return false;
3933 }
3934 Map<DartObjectImpl, DartObjectImpl> otherElements = (object as MapState)._en tries;
3935 int count = _entries.length;
3936 if (otherElements.length != count) {
3937 return false;
3938 } else if (count == 0) {
3939 return true;
3940 }
3941 for (MapEntry<DartObjectImpl, DartObjectImpl> entry in getMapEntrySet(_entri es)) {
3942 DartObjectImpl key = entry.getKey();
3943 DartObjectImpl value = entry.getValue();
3944 DartObjectImpl otherValue = otherElements[key];
3945 if (value != otherValue) {
3946 return false;
3947 }
3948 }
3949 return true;
3950 }
3951
3952 @override
3953 String get typeName => "Map";
3954
3955 @override
3956 Map<Object, Object> get value {
3957 Map<Object, Object> result = new Map<Object, Object>();
3958 for (MapEntry<DartObjectImpl, DartObjectImpl> entry in getMapEntrySet(_entri es)) {
3959 DartObjectImpl key = entry.getKey();
3960 DartObjectImpl value = entry.getValue();
3961 if (!key.hasExactValue || !value.hasExactValue) {
3962 return null;
3963 }
3964 result[key.value] = value.value;
3965 }
3966 return result;
3967 }
3968
3969 @override
3970 bool get hasExactValue {
3971 for (MapEntry<DartObjectImpl, DartObjectImpl> entry in getMapEntrySet(_entri es)) {
3972 if (!entry.getKey().hasExactValue || !entry.getValue().hasExactValue) {
3973 return false;
3974 }
3975 }
3976 return true;
3977 }
3978
3979 @override
3980 int get hashCode {
3981 int value = 0;
3982 for (DartObjectImpl key in _entries.keys.toSet()) {
3983 value = (value << 3) ^ key.hashCode;
3984 }
3985 return value;
3986 }
3987 }
3988
3989 /**
3990 * The unique instance of the class `NullState` represents the state of the valu e 'null'.
3991 */
3992 class NullState extends InstanceState {
3993 /**
3994 * An instance representing the boolean value 'true'.
3995 */
3996 static NullState NULL_STATE = new NullState();
3997
3998 @override
3999 BoolState convertToBool() {
4000 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
4001 }
4002
4003 @override
4004 StringState convertToString() => new StringState("null");
4005
4006 @override
4007 BoolState equalEqual(InstanceState rightOperand) {
4008 assertBoolNumStringOrNull(rightOperand);
4009 if (rightOperand is DynamicState) {
4010 return BoolState.UNKNOWN_VALUE;
4011 }
4012 return BoolState.from(rightOperand is NullState);
4013 }
4014
4015 @override
4016 bool operator ==(Object object) => object is NullState;
4017
4018 @override
4019 String get typeName => "Null";
4020
4021 @override
4022 bool get hasExactValue => true;
4023
4024 @override
4025 int get hashCode => 0;
4026
4027 @override
4028 bool get isBoolNumStringOrNull => true;
4029
4030 @override
4031 BoolState logicalNot() {
4032 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
4033 }
4034
4035 @override
4036 String toString() => "null";
4037 }
4038
4039 /**
4040 * Instances of the class `NumState` represent the state of an object representi ng a number of
4041 * an unknown type (a 'num').
4042 */
4043 class NumState extends InstanceState {
4044 /**
4045 * A state that can be used to represent a number whose value is not known.
4046 */
4047 static NumState UNKNOWN_VALUE = new NumState();
4048
4049 @override
4050 NumState add(InstanceState rightOperand) {
4051 assertNumOrNull(rightOperand);
4052 return UNKNOWN_VALUE;
4053 }
4054
4055 @override
4056 StringState convertToString() => StringState.UNKNOWN_VALUE;
4057
4058 @override
4059 NumState divide(InstanceState rightOperand) {
4060 assertNumOrNull(rightOperand);
4061 return UNKNOWN_VALUE;
4062 }
4063
4064 @override
4065 bool operator ==(Object object) => object is NumState;
4066
4067 @override
4068 BoolState equalEqual(InstanceState rightOperand) {
4069 assertBoolNumStringOrNull(rightOperand);
4070 return BoolState.UNKNOWN_VALUE;
4071 }
4072
4073 @override
4074 String get typeName => "num";
4075
4076 @override
4077 BoolState greaterThan(InstanceState rightOperand) {
4078 assertNumOrNull(rightOperand);
4079 return BoolState.UNKNOWN_VALUE;
4080 }
4081
4082 @override
4083 BoolState greaterThanOrEqual(InstanceState rightOperand) {
4084 assertNumOrNull(rightOperand);
4085 return BoolState.UNKNOWN_VALUE;
4086 }
4087
4088 @override
4089 int get hashCode => 7;
4090
4091 @override
4092 IntState integerDivide(InstanceState rightOperand) {
4093 assertNumOrNull(rightOperand);
4094 if (rightOperand is IntState) {
4095 int rightValue = rightOperand.value;
4096 if (rightValue == null) {
4097 return IntState.UNKNOWN_VALUE;
4098 } else if (rightValue == 0) {
4099 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_IDB ZE);
4100 }
4101 } else if (rightOperand is DynamicState) {
4102 return IntState.UNKNOWN_VALUE;
4103 }
4104 return IntState.UNKNOWN_VALUE;
4105 }
4106
4107 @override
4108 bool get isBoolNumStringOrNull => true;
4109
4110 @override
4111 BoolState lessThan(InstanceState rightOperand) {
4112 assertNumOrNull(rightOperand);
4113 return BoolState.UNKNOWN_VALUE; 3626 return BoolState.UNKNOWN_VALUE;
4114 } 3627 }
4115 3628
4116 @override 3629 @override
4117 BoolState lessThanOrEqual(InstanceState rightOperand) { 3630 BoolState lessThanOrEqual(InstanceState rightOperand) {
4118 assertNumOrNull(rightOperand); 3631 assertNumOrNull(rightOperand);
4119 return BoolState.UNKNOWN_VALUE; 3632 return BoolState.UNKNOWN_VALUE;
4120 } 3633 }
4121 3634
4122 @override 3635 @override
(...skipping 15 matching lines...) Expand all
4138 NumState times(InstanceState rightOperand) { 3651 NumState times(InstanceState rightOperand) {
4139 assertNumOrNull(rightOperand); 3652 assertNumOrNull(rightOperand);
4140 return UNKNOWN_VALUE; 3653 return UNKNOWN_VALUE;
4141 } 3654 }
4142 3655
4143 @override 3656 @override
4144 String toString() => "-unknown-"; 3657 String toString() => "-unknown-";
4145 } 3658 }
4146 3659
4147 /** 3660 /**
3661 * Instances of the class `ReferenceFinder` add reference information for a give n variable to
3662 * the bi-directional mapping used to order the evaluation of constants.
3663 */
3664 class ReferenceFinder extends RecursiveAstVisitor<Object> {
3665 /**
3666 * The element representing the variable whose initializer will be visited.
3667 */
3668 final VariableElement _source;
3669
3670 /**
3671 * A graph in which the nodes are the constant variables and the edges are fro m each variable to
3672 * the other constant variables that are referenced in the head's initializer.
3673 */
3674 final DirectedGraph<VariableElement> _referenceGraph;
3675
3676 /**
3677 * Initialize a newly created reference finder to find references from the giv en variable to other
3678 * variables and to add those references to the given graph.
3679 *
3680 * @param source the element representing the variable whose initializer will be visited
3681 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables
3682 * (tails) in their initializers
3683 */
3684 ReferenceFinder(this._source, this._referenceGraph);
3685
3686 @override
3687 Object visitSimpleIdentifier(SimpleIdentifier node) {
3688 Element element = node.staticElement;
3689 if (element is PropertyAccessorElement) {
3690 element = (element as PropertyAccessorElement).variable;
3691 }
3692 if (element is VariableElement) {
3693 VariableElement variable = element as VariableElement;
3694 if (variable.isConst) {
3695 _referenceGraph.addEdge(_source, variable);
3696 }
3697 }
3698 return null;
3699 }
3700 }
3701
3702 /**
4148 * Instances of the class `StringState` represent the state of an object represe nting a 3703 * Instances of the class `StringState` represent the state of an object represe nting a
4149 * string. 3704 * string.
4150 */ 3705 */
4151 class StringState extends InstanceState { 3706 class StringState extends InstanceState {
4152 /** 3707 /**
4153 * The value of this instance. 3708 * The value of this instance.
4154 */ 3709 */
4155 final String value; 3710 final String value;
4156 3711
4157 /** 3712 /**
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4328 } 3883 }
4329 3884
4330 @override 3885 @override
4331 String get typeName => "Type"; 3886 String get typeName => "Type";
4332 3887
4333 @override 3888 @override
4334 int get hashCode => _element == null ? 0 : _element.hashCode; 3889 int get hashCode => _element == null ? 0 : _element.hashCode;
4335 3890
4336 @override 3891 @override
4337 String toString() => _element == null ? "-unknown-" : _element.name; 3892 String toString() => _element == null ? "-unknown-" : _element.name;
3893 }
3894
3895 /**
3896 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid
3897 * compile time constant expression.
3898 */
3899 class ValidResult extends EvaluationResultImpl {
3900 /**
3901 * The value of the expression.
3902 */
3903 final DartObjectImpl value;
3904
3905 /**
3906 * Initialize a newly created result to represent the given value.
3907 *
3908 * @param value the value of the expression
3909 */
3910 ValidResult(this.value);
3911
3912 @override
3913 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToValid(typeProvider, node, t his);
3914
3915 /**
3916 * Return the result of applying boolean conversion to this result.
3917 *
3918 * @param node the node against which errors should be reported
3919 * @return the result of applying boolean conversion to the given value
3920 */
3921 @override
3922 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node) {
3923 try {
3924 return _valueOf(value.convertToBool(typeProvider));
3925 } on EvaluationException catch (exception) {
3926 return _error(node, exception.errorCode);
3927 }
3928 }
3929
3930 @override
3931 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitAndValid(typeProvider, nod e, this);
3932
3933 @override
3934 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node) {
3935 try {
3936 return _valueOf(value.bitNot(typeProvider));
3937 } on EvaluationException catch (exception) {
3938 return _error(node, exception.errorCode);
3939 }
3940 }
3941
3942 @override
3943 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.bitOrValid(typeProvider, node, this);
3944
3945 @override
3946 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitXorValid(typeProvider, nod e, this);
3947
3948 @override
3949 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand) => rightOperand.concatenateValid(typeProvider, node, this);
3950
3951 @override
3952 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.divideValid(typeProvider, nod e, this);
3953
3954 @override
3955 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand) => rightOperand.equalEqualValid(typeProvider, n ode, this);
3956
3957 @override
3958 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) {
3959 if (result is! ValidResult) {
3960 return false;
3961 }
3962 return value == (result as ValidResult).value;
3963 }
3964
3965 @override
3966 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand) => rightOperand.greaterThanValid(typePro vider, node, this);
3967
3968 @override
3969 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand) => rightOperand.greaterThanOrEqua lValid(typeProvider, node, this);
3970
3971 @override
3972 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideValid(typ eProvider, node, this);
3973
3974 /**
3975 * Return `true` if this object represents an object whose type is 'bool'.
3976 *
3977 * @return `true` if this object represents a boolean value
3978 */
3979 bool get isBool => value.isBool;
3980
3981 /**
3982 * Return `true` if this object represents an object whose type is either 'boo l', 'num',
3983 * 'String', or 'Null'.
3984 *
3985 * @return `true` if this object represents either a boolean, numeric, string or null value
3986 */
3987 bool get isBoolNumStringOrNull => value.isBoolNumStringOrNull;
3988
3989 /**
3990 * Return `true` if this result represents the value 'false'.
3991 *
3992 * @return `true` if this result represents the value 'false'
3993 */
3994 bool get isFalse => value.isFalse;
3995
3996 /**
3997 * Return `true` if this result represents the value 'null'.
3998 *
3999 * @return `true` if this result represents the value 'null'
4000 */
4001 bool get isNull => value.isNull;
4002
4003 /**
4004 * Return `true` if this result represents the value 'true'.
4005 *
4006 * @return `true` if this result represents the value 'true'
4007 */
4008 bool get isTrue => value.isTrue;
4009
4010 /**
4011 * Return `true` if this object represents an instance of a user-defined class .
4012 *
4013 * @return `true` if this object represents an instance of a user-defined clas s
4014 */
4015 bool get isUserDefinedObject => value.isUserDefinedObject;
4016
4017 @override
4018 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.lessThanValid(typeProvider, node, this);
4019
4020 @override
4021 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand) => rightOperand.lessThanOrEqualValid (typeProvider, node, this);
4022
4023 @override
4024 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.logicalAndValid(typeProvi der, node, this);
4025
4026 @override
4027 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node) {
4028 try {
4029 return _valueOf(value.logicalNot(typeProvider));
4030 } on EvaluationException catch (exception) {
4031 return _error(node, exception.errorCode);
4032 }
4033 }
4034
4035 @override
4036 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.logicalOrValid(typeProvide r, node, this);
4037
4038 @override
4039 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.minusValid(typeProvider, node, this);
4040
4041 @override
4042 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node) {
4043 try {
4044 return _valueOf(value.negated(typeProvider));
4045 } on EvaluationException catch (exception) {
4046 return _error(node, exception.errorCode);
4047 }
4048 }
4049
4050 @override
4051 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.notEqualValid(typeProvider, node, this);
4052
4053 @override
4054 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node) {
4055 try {
4056 return _valueOf(value.performToString(typeProvider));
4057 } on EvaluationException catch (exception) {
4058 return _error(node, exception.errorCode);
4059 }
4060 }
4061
4062 @override
4063 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.remainderValid(typeProvide r, node, this);
4064
4065 @override
4066 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.shiftLeftValid(typeProvide r, node, this);
4067
4068 @override
4069 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.shiftRightValid(typeProvi der, node, this);
4070
4071 @override
4072 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.timesValid(typeProvider, node, this);
4073
4074 @override
4075 String toString() {
4076 if (value == null) {
4077 return "null";
4078 }
4079 return value.toString();
4080 }
4081
4082 @override
4083 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4084
4085 @override
4086 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4087 try {
4088 return _valueOf(leftOperand.value.add(typeProvider, value));
4089 } on EvaluationException catch (exception) {
4090 return _error(node, exception.errorCode);
4091 }
4092 }
4093
4094 @override
4095 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
4096
4097 @override
4098 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
4099 try {
4100 return _valueOf(leftOperand.value.bitAnd(typeProvider, value));
4101 } on EvaluationException catch (exception) {
4102 return _error(node, exception.errorCode);
4103 }
4104 }
4105
4106 @override
4107 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4108
4109 @override
4110 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4111 try {
4112 return _valueOf(leftOperand.value.bitOr(typeProvider, value));
4113 } on EvaluationException catch (exception) {
4114 return _error(node, exception.errorCode);
4115 }
4116 }
4117
4118 @override
4119 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
4120
4121 @override
4122 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
4123 try {
4124 return _valueOf(leftOperand.value.bitXor(typeProvider, value));
4125 } on EvaluationException catch (exception) {
4126 return _error(node, exception.errorCode);
4127 }
4128 }
4129
4130 @override
4131 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => leftOperand;
4132
4133 @override
4134 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand) {
4135 try {
4136 return _valueOf(leftOperand.value.concatenate(typeProvider, value));
4137 } on EvaluationException catch (exception) {
4138 return _error(node, exception.errorCode);
4139 }
4140 }
4141
4142 @override
4143 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
4144
4145 @override
4146 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
4147 try {
4148 return _valueOf(leftOperand.value.divide(typeProvider, value));
4149 } on EvaluationException catch (exception) {
4150 return _error(node, exception.errorCode);
4151 }
4152 }
4153
4154 @override
4155 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => leftOperand;
4156
4157 @override
4158 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand) {
4159 try {
4160 return _valueOf(leftOperand.value.equalEqual(typeProvider, value));
4161 } on EvaluationException catch (exception) {
4162 return _error(node, exception.errorCode);
4163 }
4164 }
4165
4166 @override
4167 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => leftOperand;
4168
4169 @override
4170 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => leftOperand;
4171
4172 @override
4173 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand) {
4174 try {
4175 return _valueOf(leftOperand.value.greaterThanOrEqual(typeProvider, value)) ;
4176 } on EvaluationException catch (exception) {
4177 return _error(node, exception.errorCode);
4178 }
4179 }
4180
4181 @override
4182 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand) {
4183 try {
4184 return _valueOf(leftOperand.value.greaterThan(typeProvider, value));
4185 } on EvaluationException catch (exception) {
4186 return _error(node, exception.errorCode);
4187 }
4188 }
4189
4190 @override
4191 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => leftOperand;
4192
4193 @override
4194 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand) {
4195 try {
4196 return _valueOf(leftOperand.value.integerDivide(typeProvider, value));
4197 } on EvaluationException catch (exception) {
4198 return _error(node, exception.errorCode);
4199 }
4200 }
4201
4202 @override
4203 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
4204
4205 @override
4206 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => leftOperand;
4207
4208 @override
4209 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand) {
4210 try {
4211 return _valueOf(leftOperand.value.lessThanOrEqual(typeProvider, value));
4212 } on EvaluationException catch (exception) {
4213 return _error(node, exception.errorCode);
4214 }
4215 }
4216
4217 @override
4218 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) {
4219 try {
4220 return _valueOf(leftOperand.value.lessThan(typeProvider, value));
4221 } on EvaluationException catch (exception) {
4222 return _error(node, exception.errorCode);
4223 }
4224 }
4225
4226 @override
4227 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
4228
4229 @override
4230 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) {
4231 try {
4232 return _valueOf(leftOperand.value.logicalAnd(typeProvider, value));
4233 } on EvaluationException catch (exception) {
4234 return _error(node, exception.errorCode);
4235 }
4236 }
4237
4238 @override
4239 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
4240
4241 @override
4242 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
4243 try {
4244 return _valueOf(leftOperand.value.logicalOr(typeProvider, value));
4245 } on EvaluationException catch (exception) {
4246 return _error(node, exception.errorCode);
4247 }
4248 }
4249
4250 @override
4251 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4252
4253 @override
4254 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4255 try {
4256 return _valueOf(leftOperand.value.minus(typeProvider, value));
4257 } on EvaluationException catch (exception) {
4258 return _error(node, exception.errorCode);
4259 }
4260 }
4261
4262 @override
4263 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
4264
4265 @override
4266 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) {
4267 try {
4268 return _valueOf(leftOperand.value.notEqual(typeProvider, value));
4269 } on EvaluationException catch (exception) {
4270 return _error(node, exception.errorCode);
4271 }
4272 }
4273
4274 @override
4275 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
4276
4277 @override
4278 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
4279 try {
4280 return _valueOf(leftOperand.value.remainder(typeProvider, value));
4281 } on EvaluationException catch (exception) {
4282 return _error(node, exception.errorCode);
4283 }
4284 }
4285
4286 @override
4287 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
4288
4289 @override
4290 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
4291 try {
4292 return _valueOf(leftOperand.value.shiftLeft(typeProvider, value));
4293 } on EvaluationException catch (exception) {
4294 return _error(node, exception.errorCode);
4295 }
4296 }
4297
4298 @override
4299 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
4300
4301 @override
4302 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) {
4303 try {
4304 return _valueOf(leftOperand.value.shiftRight(typeProvider, value));
4305 } on EvaluationException catch (exception) {
4306 return _error(node, exception.errorCode);
4307 }
4308 }
4309
4310 @override
4311 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4312
4313 @override
4314 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4315 try {
4316 return _valueOf(leftOperand.value.times(typeProvider, value));
4317 } on EvaluationException catch (exception) {
4318 return _error(node, exception.errorCode);
4319 }
4320 }
4321
4322 /**
4323 * Return a result object representing an error associated with the given node .
4324 *
4325 * @param node the AST node associated with the error
4326 * @param code the error code indicating the nature of the error
4327 * @return a result object representing an error associated with the given nod e
4328 */
4329 ErrorResult _error(AstNode node, ErrorCode code) => new ErrorResult.con1(node, code);
4330
4331 /**
4332 * Return a result object representing the given value.
4333 *
4334 * @param value the value to be represented as a result object
4335 * @return a result object representing the given value
4336 */
4337 ValidResult _valueOf(DartObjectImpl value) => new ValidResult(value);
4338 } 4338 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698