OLD | NEW |
1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
3 | 3 |
4 library engine.constant; | 4 library engine.constant; |
5 | 5 |
6 import 'java_core.dart'; | 6 import 'java_core.dart'; |
7 import 'source.dart' show Source; | 7 import 'source.dart' show Source; |
8 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; | 8 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; |
9 import 'scanner.dart' show TokenType; | 9 import 'scanner.dart' show TokenType; |
10 import 'ast.dart'; | 10 import 'ast.dart'; |
11 import 'element.dart'; | 11 import 'element.dart'; |
12 import 'engine.dart' show AnalysisEngine; | 12 import 'engine.dart' show AnalysisEngine; |
13 | 13 |
| 14 |
14 /** | 15 /** |
15 * Instances of the class {@code ConstantEvaluator} evaluate constant expression
s to produce their | 16 * Instances of the class {@code ConstantEvaluator} evaluate constant expression
s to produce their |
16 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant | 17 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant |
17 * expression is one of the following: | 18 * expression is one of the following: |
18 * <ul> | 19 * <ul> |
19 * <li>A literal number.</li> | 20 * <li>A literal number.</li> |
20 * <li>A literal boolean.</li> | 21 * <li>A literal boolean.</li> |
21 * <li>A literal string where any interpolated expression is a compile-time cons
tant that evaluates | 22 * <li>A literal string where any interpolated expression is a compile-time cons
tant that evaluates |
22 * to a numeric, string or boolean value or to {@code null}.</li> | 23 * to a numeric, string or boolean value or to {@code null}.</li> |
23 * <li>{@code null}.</li> | 24 * <li>{@code null}.</li> |
(...skipping 12 matching lines...) Expand all Loading... |
36 * <li>An expression of one of the forms {@code -e}, {@code e1 + e2}, {@code e1
- e2},{@code e1 * e2}, {@code e1 / e2}, {@code e1 ~/ e2}, {@code e1 > e2}, {@cod
e e1 < e2},{@code e1 >= e2}, {@code e1 <= e2} or {@code e1 % e2}, where {@code e
}, {@code e1} and {@code e2}are constant expressions that evaluate to a numeric
value or to {@code null}.</li> | 37 * <li>An expression of one of the forms {@code -e}, {@code e1 + e2}, {@code e1
- e2},{@code e1 * e2}, {@code e1 / e2}, {@code e1 ~/ e2}, {@code e1 > e2}, {@cod
e e1 < e2},{@code e1 >= e2}, {@code e1 <= e2} or {@code e1 % e2}, where {@code e
}, {@code e1} and {@code e2}are constant expressions that evaluate to a numeric
value or to {@code null}.</li> |
37 * </ul> | 38 * </ul> |
38 * </blockquote> The values returned by instances of this class are therefore {@
code null} and | 39 * </blockquote> The values returned by instances of this class are therefore {@
code null} and |
39 * instances of the classes {@code Boolean}, {@code BigInteger}, {@code Double},
{@code String}, and{@code DartObject}. | 40 * instances of the classes {@code Boolean}, {@code BigInteger}, {@code Double},
{@code String}, and{@code DartObject}. |
40 * <p> | 41 * <p> |
41 * In addition, this class defines several values that can be returned to indica
te various | 42 * In addition, this class defines several values that can be returned to indica
te various |
42 * conditions encountered during evaluation. These are documented with the stati
c field that define | 43 * conditions encountered during evaluation. These are documented with the stati
c field that define |
43 * those values. | 44 * those values. |
44 */ | 45 */ |
45 class ConstantEvaluator { | 46 class ConstantEvaluator { |
| 47 |
46 /** | 48 /** |
47 * The source containing the expression(s) that will be evaluated. | 49 * The source containing the expression(s) that will be evaluated. |
48 */ | 50 */ |
49 Source _source; | 51 Source _source; |
| 52 |
50 /** | 53 /** |
51 * Initialize a newly created evaluator to evaluate expressions in the given s
ource. | 54 * Initialize a newly created evaluator to evaluate expressions in the given s
ource. |
52 * @param source the source containing the expression(s) that will be evaluate
d | 55 * @param source the source containing the expression(s) that will be evaluate
d |
53 */ | 56 */ |
54 ConstantEvaluator(Source source) { | 57 ConstantEvaluator(Source source) { |
55 this._source = source; | 58 this._source = source; |
56 } | 59 } |
57 EvaluationResult evaluate(Expression expression) { | 60 EvaluationResult evaluate(Expression expression) { |
58 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); | 61 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); |
59 if (result is ValidResult) { | 62 if (result is ValidResult) { |
60 return EvaluationResult.forValue(((result as ValidResult)).value); | 63 return EvaluationResult.forValue(((result as ValidResult)).value); |
61 } | 64 } |
62 List<AnalysisError> errors = new List<AnalysisError>(); | 65 List<AnalysisError> errors = new List<AnalysisError>(); |
63 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 66 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
64 ASTNode node2 = data.node; | 67 ASTNode node2 = data.node; |
65 errors.add(new AnalysisError.con2(_source, node2.offset, node2.length, dat
a.errorCode, [])); | 68 errors.add(new AnalysisError.con2(_source, node2.offset, node2.length, dat
a.errorCode, [])); |
66 } | 69 } |
67 return EvaluationResult.forErrors(new List.from(errors)); | 70 return EvaluationResult.forErrors(new List.from(errors)); |
68 } | 71 } |
69 } | 72 } |
| 73 |
70 /** | 74 /** |
71 * Instances of the class {@code EvaluationResult} represent the result of attem
pting to evaluate an | 75 * Instances of the class {@code EvaluationResult} represent the result of attem
pting to evaluate an |
72 * expression. | 76 * expression. |
73 */ | 77 */ |
74 class EvaluationResult { | 78 class EvaluationResult { |
| 79 |
75 /** | 80 /** |
76 * Return an evaluation result representing the result of evaluating an expres
sion that is not a | 81 * Return an evaluation result representing the result of evaluating an expres
sion that is not a |
77 * compile-time constant because of the given errors. | 82 * compile-time constant because of the given errors. |
78 * @param errors the errors that should be reported for the expression(s) that
were evaluated | 83 * @param errors the errors that should be reported for the expression(s) that
were evaluated |
79 * @return the result of evaluating an expression that is not a compile-time c
onstant | 84 * @return the result of evaluating an expression that is not a compile-time c
onstant |
80 */ | 85 */ |
81 static EvaluationResult forErrors(List<AnalysisError> errors) => new Evaluatio
nResult(null, errors); | 86 static EvaluationResult forErrors(List<AnalysisError> errors) => new Evaluatio
nResult(null, errors); |
| 87 |
82 /** | 88 /** |
83 * Return an evaluation result representing the result of evaluating an expres
sion that is a | 89 * Return an evaluation result representing the result of evaluating an expres
sion that is a |
84 * compile-time constant that evaluates to the given value. | 90 * compile-time constant that evaluates to the given value. |
85 * @param value the value of the expression | 91 * @param value the value of the expression |
86 * @return the result of evaluating an expression that is a compile-time const
ant | 92 * @return the result of evaluating an expression that is a compile-time const
ant |
87 */ | 93 */ |
88 static EvaluationResult forValue(Object value) => new EvaluationResult(value,
null); | 94 static EvaluationResult forValue(Object value) => new EvaluationResult(value,
null); |
| 95 |
89 /** | 96 /** |
90 * The value of the expression. | 97 * The value of the expression. |
91 */ | 98 */ |
92 Object _value; | 99 Object _value; |
| 100 |
93 /** | 101 /** |
94 * The errors that should be reported for the expression(s) that were evaluate
d. | 102 * The errors that should be reported for the expression(s) that were evaluate
d. |
95 */ | 103 */ |
96 List<AnalysisError> _errors; | 104 List<AnalysisError> _errors; |
| 105 |
97 /** | 106 /** |
98 * Initialize a newly created result object with the given state. Clients shou
ld use one of the | 107 * Initialize a newly created result object with the given state. Clients shou
ld use one of the |
99 * factory methods: {@link #forErrors(AnalysisError\[\])} and {@link #forValue
(Object)}. | 108 * factory methods: {@link #forErrors(AnalysisError\[\])} and {@link #forValue
(Object)}. |
100 * @param value the value of the expression | 109 * @param value the value of the expression |
101 * @param errors the errors that should be reported for the expression(s) that
were evaluated | 110 * @param errors the errors that should be reported for the expression(s) that
were evaluated |
102 */ | 111 */ |
103 EvaluationResult(Object value, List<AnalysisError> errors) { | 112 EvaluationResult(Object value, List<AnalysisError> errors) { |
104 this._value = value; | 113 this._value = value; |
105 this._errors = errors; | 114 this._errors = errors; |
106 } | 115 } |
| 116 |
107 /** | 117 /** |
108 * Return an array containing the errors that should be reported for the expre
ssion(s) that were | 118 * Return an array containing the errors that should be reported for the expre
ssion(s) that were |
109 * evaluated. If there are no such errors, the array will be empty. The array
can be empty even if | 119 * evaluated. If there are no such errors, the array will be empty. The array
can be empty even if |
110 * the expression is not a valid compile time constant if the errors would hav
e been reported by | 120 * the expression is not a valid compile time constant if the errors would hav
e been reported by |
111 * other parts of the analysis engine. | 121 * other parts of the analysis engine. |
112 */ | 122 */ |
113 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS :
_errors; | 123 List<AnalysisError> get errors => _errors == null ? AnalysisError.NO_ERRORS :
_errors; |
| 124 |
114 /** | 125 /** |
115 * Return the value of the expression, or {@code null} if the expression evalu
ated to {@code null}or if the expression could not be evaluated, either because
it was not a compile-time constant | 126 * Return the value of the expression, or {@code null} if the expression evalu
ated to {@code null}or if the expression could not be evaluated, either because
it was not a compile-time constant |
116 * expression or because it would throw an exception when evaluated. | 127 * expression or because it would throw an exception when evaluated. |
117 * @return the value of the expression | 128 * @return the value of the expression |
118 */ | 129 */ |
119 Object get value => _value; | 130 Object get value => _value; |
| 131 |
120 /** | 132 /** |
121 * Return {@code true} if the expression is a compile-time constant expression
that would not | 133 * Return {@code true} if the expression is a compile-time constant expression
that would not |
122 * throw an exception when evaluated. | 134 * throw an exception when evaluated. |
123 * @return {@code true} if the expression is a valid compile-time constant exp
ression | 135 * @return {@code true} if the expression is a valid compile-time constant exp
ression |
124 */ | 136 */ |
125 bool isValid() => _errors == null; | 137 bool isValid() => _errors == null; |
126 } | 138 } |
| 139 |
127 /** | 140 /** |
128 * Instances of the class {@code ConstantFinder} are used to traverse the AST st
ructures of all of | 141 * Instances of the class {@code ConstantFinder} are used to traverse the AST st
ructures of all of |
129 * the compilation units being resolved and build a table mapping constant varia
ble elements to the | 142 * the compilation units being resolved and build a table mapping constant varia
ble elements to the |
130 * declarations of those variables. | 143 * declarations of those variables. |
131 */ | 144 */ |
132 class ConstantFinder extends RecursiveASTVisitor<Object> { | 145 class ConstantFinder extends RecursiveASTVisitor<Object> { |
| 146 |
133 /** | 147 /** |
134 * A table mapping constant variable elements to the declarations of those var
iables. | 148 * A table mapping constant variable elements to the declarations of those var
iables. |
135 */ | 149 */ |
136 Map<VariableElement, VariableDeclaration> _variableMap = new Map<VariableEleme
nt, VariableDeclaration>(); | 150 Map<VariableElement, VariableDeclaration> _variableMap = new Map<VariableEleme
nt, VariableDeclaration>(); |
137 /** | 151 |
138 * Initialize a newly created constant finder. | |
139 */ | |
140 ConstantFinder() : super() { | |
141 } | |
142 /** | 152 /** |
143 * Return a table mapping constant variable elements to the declarations of th
ose variables. | 153 * Return a table mapping constant variable elements to the declarations of th
ose variables. |
144 * @return a table mapping constant variable elements to the declarations of t
hose variables | 154 * @return a table mapping constant variable elements to the declarations of t
hose variables |
145 */ | 155 */ |
146 Map<VariableElement, VariableDeclaration> get variableMap => _variableMap; | 156 Map<VariableElement, VariableDeclaration> get variableMap => _variableMap; |
147 Object visitVariableDeclaration(VariableDeclaration node) { | 157 Object visitVariableDeclaration(VariableDeclaration node) { |
148 super.visitVariableDeclaration(node); | 158 super.visitVariableDeclaration(node); |
149 Expression initializer2 = node.initializer; | 159 Expression initializer2 = node.initializer; |
150 if (initializer2 != null && node.isConst()) { | 160 if (initializer2 != null && node.isConst()) { |
151 VariableElement element2 = node.element; | 161 VariableElement element2 = node.element; |
152 if (element2 != null) { | 162 if (element2 != null) { |
153 _variableMap[element2] = node; | 163 _variableMap[element2] = node; |
154 } | 164 } |
155 } | 165 } |
156 return null; | 166 return null; |
157 } | 167 } |
158 } | 168 } |
| 169 |
159 /** | 170 /** |
160 * Instances of the class {@code ConstantValueComputer} compute the values of co
nstant variables in | 171 * Instances of the class {@code ConstantValueComputer} compute the values of co
nstant variables in |
161 * one or more compilation units. The expected usage pattern is for the compilat
ion units to be | 172 * one or more compilation units. The expected usage pattern is for the compilat
ion units to be |
162 * added to this computer using the method {@link #add(CompilationUnit)} and the
n for the method{@link #computeValues()} to invoked exactly once. Any use of an
instance after invoking the | 173 * added to this computer using the method {@link #add(CompilationUnit)} and the
n for the method{@link #computeValues()} to invoked exactly once. Any use of an
instance after invoking the |
163 * method {@link #computeValues()} will result in unpredictable behavior. | 174 * method {@link #computeValues()} will result in unpredictable behavior. |
164 */ | 175 */ |
165 class ConstantValueComputer { | 176 class ConstantValueComputer { |
| 177 |
166 /** | 178 /** |
167 * The object used to find constant variables in the compilation units that we
re added. | 179 * The object used to find constant variables in the compilation units that we
re added. |
168 */ | 180 */ |
169 ConstantFinder _constantFinder = new ConstantFinder(); | 181 ConstantFinder _constantFinder = new ConstantFinder(); |
| 182 |
170 /** | 183 /** |
171 * A graph in which the nodes are the constant variables and the edges are fro
m each variable to | 184 * A graph in which the nodes are the constant variables and the edges are fro
m each variable to |
172 * the other constant variables that are referenced in the head's initializer. | 185 * the other constant variables that are referenced in the head's initializer. |
173 */ | 186 */ |
174 DirectedGraph<VariableElement> _referenceGraph = new DirectedGraph<VariableEle
ment>(); | 187 DirectedGraph<VariableElement> _referenceGraph = new DirectedGraph<VariableEle
ment>(); |
| 188 |
175 /** | 189 /** |
176 * A table mapping constant variables to the declarations of those variables. | 190 * A table mapping constant variables to the declarations of those variables. |
177 */ | 191 */ |
178 Map<VariableElement, VariableDeclaration> _declarationMap; | 192 Map<VariableElement, VariableDeclaration> _declarationMap; |
179 /** | 193 |
180 * Initialize a newly created constant value computer. | |
181 */ | |
182 ConstantValueComputer() : super() { | |
183 } | |
184 /** | 194 /** |
185 * Add the constant variables in the given compilation unit to the list of con
stant variables | 195 * Add the constant variables in the given compilation unit to the list of con
stant variables |
186 * whose value needs to be computed. | 196 * whose value needs to be computed. |
187 * @param unit the compilation unit defining the constant variables to be adde
d | 197 * @param unit the compilation unit defining the constant variables to be adde
d |
188 */ | 198 */ |
189 void add(CompilationUnit unit) { | 199 void add(CompilationUnit unit) { |
190 unit.accept(_constantFinder); | 200 unit.accept(_constantFinder); |
191 } | 201 } |
| 202 |
192 /** | 203 /** |
193 * Compute values for all of the constant variables in the compilation units t
hat were added. | 204 * Compute values for all of the constant variables in the compilation units t
hat were added. |
194 */ | 205 */ |
195 void computeValues() { | 206 void computeValues() { |
196 _declarationMap = _constantFinder.variableMap; | 207 _declarationMap = _constantFinder.variableMap; |
197 for (MapEntry<VariableElement, VariableDeclaration> entry in getMapEntrySet(
_declarationMap)) { | 208 for (MapEntry<VariableElement, VariableDeclaration> entry in getMapEntrySet(
_declarationMap)) { |
198 VariableElement element = entry.getKey(); | 209 VariableElement element = entry.getKey(); |
199 ReferenceFinder referenceFinder = new ReferenceFinder(element, _referenceG
raph); | 210 ReferenceFinder referenceFinder = new ReferenceFinder(element, _referenceG
raph); |
200 _referenceGraph.addNode(element); | 211 _referenceGraph.addNode(element); |
201 entry.getValue().initializer.accept(referenceFinder); | 212 entry.getValue().initializer.accept(referenceFinder); |
(...skipping 10 matching lines...) Expand all Loading... |
212 AnalysisEngine.instance.logger.logError("Exiting constant value comput
er with ${_referenceGraph.nodeCount} variables that are neither sinks no in a cy
cle"); | 223 AnalysisEngine.instance.logger.logError("Exiting constant value comput
er with ${_referenceGraph.nodeCount} variables that are neither sinks no in a cy
cle"); |
213 return; | 224 return; |
214 } | 225 } |
215 for (VariableElement variable in variablesInCycle) { | 226 for (VariableElement variable in variablesInCycle) { |
216 generateCycleError(variablesInCycle, variable); | 227 generateCycleError(variablesInCycle, variable); |
217 } | 228 } |
218 _referenceGraph.removeAllNodes(variablesInCycle); | 229 _referenceGraph.removeAllNodes(variablesInCycle); |
219 } | 230 } |
220 } | 231 } |
221 } | 232 } |
| 233 |
222 /** | 234 /** |
223 * Compute a value for the given variable. | 235 * Compute a value for the given variable. |
224 * @param variable the variable for which a value is to be computed | 236 * @param variable the variable for which a value is to be computed |
225 */ | 237 */ |
226 void computeValueFor(VariableElement variable) { | 238 void computeValueFor(VariableElement variable) { |
227 VariableDeclaration declaration = _declarationMap[variable]; | 239 VariableDeclaration declaration = _declarationMap[variable]; |
228 if (declaration == null) { | 240 if (declaration == null) { |
229 return; | 241 return; |
230 } | 242 } |
231 EvaluationResultImpl result = declaration.initializer.accept(new ConstantVis
itor()); | 243 EvaluationResultImpl result = declaration.initializer.accept(new ConstantVis
itor()); |
232 ((variable as VariableElementImpl)).evaluationResult = result; | 244 ((variable as VariableElementImpl)).evaluationResult = result; |
233 if (result is ErrorResult) { | 245 if (result is ErrorResult) { |
234 List<AnalysisError> errors = new List<AnalysisError>(); | 246 List<AnalysisError> errors = new List<AnalysisError>(); |
235 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 247 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
236 ASTNode node2 = data.node; | 248 ASTNode node2 = data.node; |
237 Source source2 = variable.getAncestor(CompilationUnitElement).source; | 249 Source source2 = variable.getAncestor(CompilationUnitElement).source; |
238 errors.add(new AnalysisError.con2(source2, node2.offset, node2.length, d
ata.errorCode, [])); | 250 errors.add(new AnalysisError.con2(source2, node2.offset, node2.length, d
ata.errorCode, [])); |
239 } | 251 } |
240 } | 252 } |
241 } | 253 } |
| 254 |
242 /** | 255 /** |
243 * Generate an error indicating that the given variable is not a valid compile
-time constant | 256 * Generate an error indicating that the given variable is not a valid compile
-time constant |
244 * because it references at least one of the variables in the given cycle, eac
h of which directly | 257 * because it references at least one of the variables in the given cycle, eac
h of which directly |
245 * or indirectly references the variable. | 258 * or indirectly references the variable. |
246 * @param variablesInCycle the variables in the cycle that includes the given
variable | 259 * @param variablesInCycle the variables in the cycle that includes the given
variable |
247 * @param variable the variable that is not a valid compile-time constant | 260 * @param variable the variable that is not a valid compile-time constant |
248 */ | 261 */ |
249 void generateCycleError(List<VariableElement> variablesInCycle, VariableElemen
t variable) { | 262 void generateCycleError(List<VariableElement> variablesInCycle, VariableElemen
t variable) { |
250 } | 263 } |
251 } | 264 } |
| 265 |
252 /** | 266 /** |
253 * Instances of the class {@code ConstantVisitor} evaluate constant expressions
to produce their | 267 * Instances of the class {@code ConstantVisitor} evaluate constant expressions
to produce their |
254 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant | 268 * compile-time value. According to the Dart Language Specification: <blockquote
> A constant |
255 * expression is one of the following: | 269 * expression is one of the following: |
256 * <ul> | 270 * <ul> |
257 * <li>A literal number.</li> | 271 * <li>A literal number.</li> |
258 * <li>A literal boolean.</li> | 272 * <li>A literal boolean.</li> |
259 * <li>A literal string where any interpolated expression is a compile-time cons
tant that evaluates | 273 * <li>A literal string where any interpolated expression is a compile-time cons
tant that evaluates |
260 * to a numeric, string or boolean value or to {@code null}.</li> | 274 * to a numeric, string or boolean value or to {@code null}.</li> |
261 * <li>{@code null}.</li> | 275 * <li>{@code null}.</li> |
262 * <li>A reference to a static constant variable.</li> | 276 * <li>A reference to a static constant variable.</li> |
263 * <li>An identifier expression that denotes a constant variable, a class or a t
ype variable.</li> | 277 * <li>An identifier expression that denotes a constant variable, a class or a t
ype variable.</li> |
264 * <li>A constant constructor invocation.</li> | 278 * <li>A constant constructor invocation.</li> |
265 * <li>A constant list literal.</li> | 279 * <li>A constant list literal.</li> |
266 * <li>A constant map literal.</li> | 280 * <li>A constant map literal.</li> |
267 * <li>A simple or qualified identifier denoting a top-level function or a stati
c method.</li> | 281 * <li>A simple or qualified identifier denoting a top-level function or a stati
c method.</li> |
268 * <li>A parenthesized expression {@code (e)} where {@code e} is a constant expr
ession.</li> | 282 * <li>A parenthesized expression {@code (e)} where {@code e} is a constant expr
ession.</li> |
269 * <li>An expression of one of the forms {@code identical(e1, e2)}, {@code e1 ==
e2},{@code e1 != e2} where {@code e1} and {@code e2} are constant expressions t
hat evaluate to a | 283 * <li>An expression of one of the forms {@code identical(e1, e2)}, {@code e1 ==
e2},{@code e1 != e2} where {@code e1} and {@code e2} are constant expressions t
hat evaluate to a |
270 * numeric, string or boolean value or to {@code null}.</li> | 284 * numeric, string or boolean value or to {@code null}.</li> |
271 * <li>An expression of one of the forms {@code !e}, {@code e1 && e2} or {@code
e1 || e2}, where{@code e}, {@code e1} and {@code e2} are constant expressions th
at evaluate to a boolean value or | 285 * <li>An expression of one of the forms {@code !e}, {@code e1 && e2} or {@code
e1 || e2}, where{@code e}, {@code e1} and {@code e2} are constant expressions th
at evaluate to a boolean value or |
272 * to {@code null}.</li> | 286 * to {@code null}.</li> |
273 * <li>An expression of one of the forms {@code ~e}, {@code e1 ^ e2}, {@code e1
& e2},{@code e1 | e2}, {@code e1 >> e2} or {@code e1 << e2}, where {@code e}, {@
code e1} and {@code e2}are constant expressions that evaluate to an integer valu
e or to {@code null}.</li> | 287 * <li>An expression of one of the forms {@code ~e}, {@code e1 ^ e2}, {@code e1
& e2},{@code e1 | e2}, {@code e1 >> e2} or {@code e1 << e2}, where {@code e}, {@
code e1} and {@code e2}are constant expressions that evaluate to an integer valu
e or to {@code null}.</li> |
274 * <li>An expression of one of the forms {@code -e}, {@code e1 + e2}, {@code e1
- e2},{@code e1 * e2}, {@code e1 / e2}, {@code e1 ~/ e2}, {@code e1 > e2}, {@cod
e e1 < e2},{@code e1 >= e2}, {@code e1 <= e2} or {@code e1 % e2}, where {@code e
}, {@code e1} and {@code e2}are constant expressions that evaluate to a numeric
value or to {@code null}.</li> | 288 * <li>An expression of one of the forms {@code -e}, {@code e1 + e2}, {@code e1
- e2},{@code e1 * e2}, {@code e1 / e2}, {@code e1 ~/ e2}, {@code e1 > e2}, {@cod
e e1 < e2},{@code e1 >= e2}, {@code e1 <= e2} or {@code e1 % e2}, where {@code e
}, {@code e1} and {@code e2}are constant expressions that evaluate to a numeric
value or to {@code null}.</li> |
275 * </ul> | 289 * </ul> |
276 * </blockquote> | 290 * </blockquote> |
277 */ | 291 */ |
278 class ConstantVisitor extends GeneralizingASTVisitor<EvaluationResultImpl> { | 292 class ConstantVisitor extends GeneralizingASTVisitor<EvaluationResultImpl> { |
279 /** | |
280 * Initialize a newly created constant visitor. | |
281 */ | |
282 ConstantVisitor() : super() { | |
283 } | |
284 EvaluationResultImpl visitAdjacentStrings(AdjacentStrings node) { | 293 EvaluationResultImpl visitAdjacentStrings(AdjacentStrings node) { |
285 EvaluationResultImpl result = null; | 294 EvaluationResultImpl result = null; |
286 for (StringLiteral string in node.strings) { | 295 for (StringLiteral string in node.strings) { |
287 if (result == null) { | 296 if (result == null) { |
288 result = string.accept(this); | 297 result = string.accept(this); |
289 } else { | 298 } else { |
290 result = result.concatenate(node, string.accept(this)); | 299 result = result.concatenate(node, string.accept(this)); |
291 } | 300 } |
292 } | 301 } |
293 return result; | 302 return result; |
294 } | 303 } |
295 EvaluationResultImpl visitBinaryExpression(BinaryExpression node) { | 304 EvaluationResultImpl visitBinaryExpression(BinaryExpression node) { |
296 EvaluationResultImpl leftResult = node.leftOperand.accept(this); | 305 EvaluationResultImpl leftResult = node.leftOperand.accept(this); |
297 EvaluationResultImpl rightResult = node.rightOperand.accept(this); | 306 EvaluationResultImpl rightResult = node.rightOperand.accept(this); |
| 307 TokenType operatorType = node.operator.type; |
| 308 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) { |
| 309 if (leftResult is ValidResult && ((leftResult as ValidResult)).isNull() ||
rightResult is ValidResult && ((rightResult as ValidResult)).isNull()) { |
| 310 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); |
| 311 } |
| 312 } |
298 while (true) { | 313 while (true) { |
299 if (node.operator.type == TokenType.AMPERSAND) { | 314 if (operatorType == TokenType.AMPERSAND) { |
300 return leftResult.bitAnd(node, rightResult); | 315 return leftResult.bitAnd(node, rightResult); |
301 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) { | 316 } else if (operatorType == TokenType.AMPERSAND_AMPERSAND) { |
302 return leftResult.logicalAnd(node, rightResult); | 317 return leftResult.logicalAnd(node, rightResult); |
303 } else if (node.operator.type == TokenType.BANG_EQ) { | 318 } else if (operatorType == TokenType.BANG_EQ) { |
304 return leftResult.notEqual(node, rightResult); | 319 return leftResult.notEqual(node, rightResult); |
305 } else if (node.operator.type == TokenType.BAR) { | 320 } else if (operatorType == TokenType.BAR) { |
306 return leftResult.bitOr(node, rightResult); | 321 return leftResult.bitOr(node, rightResult); |
307 } else if (node.operator.type == TokenType.BAR_BAR) { | 322 } else if (operatorType == TokenType.BAR_BAR) { |
308 return leftResult.logicalOr(node, rightResult); | 323 return leftResult.logicalOr(node, rightResult); |
309 } else if (node.operator.type == TokenType.CARET) { | 324 } else if (operatorType == TokenType.CARET) { |
310 return leftResult.bitXor(node, rightResult); | 325 return leftResult.bitXor(node, rightResult); |
311 } else if (node.operator.type == TokenType.EQ_EQ) { | 326 } else if (operatorType == TokenType.EQ_EQ) { |
312 return leftResult.equalEqual(node, rightResult); | 327 return leftResult.equalEqual(node, rightResult); |
313 } else if (node.operator.type == TokenType.GT) { | 328 } else if (operatorType == TokenType.GT) { |
314 return leftResult.greaterThan(node, rightResult); | 329 return leftResult.greaterThan(node, rightResult); |
315 } else if (node.operator.type == TokenType.GT_EQ) { | 330 } else if (operatorType == TokenType.GT_EQ) { |
316 return leftResult.greaterThanOrEqual(node, rightResult); | 331 return leftResult.greaterThanOrEqual(node, rightResult); |
317 } else if (node.operator.type == TokenType.GT_GT) { | 332 } else if (operatorType == TokenType.GT_GT) { |
318 return leftResult.shiftRight(node, rightResult); | 333 return leftResult.shiftRight(node, rightResult); |
319 } else if (node.operator.type == TokenType.LT) { | 334 } else if (operatorType == TokenType.LT) { |
320 return leftResult.lessThan(node, rightResult); | 335 return leftResult.lessThan(node, rightResult); |
321 } else if (node.operator.type == TokenType.LT_EQ) { | 336 } else if (operatorType == TokenType.LT_EQ) { |
322 return leftResult.lessThanOrEqual(node, rightResult); | 337 return leftResult.lessThanOrEqual(node, rightResult); |
323 } else if (node.operator.type == TokenType.LT_LT) { | 338 } else if (operatorType == TokenType.LT_LT) { |
324 return leftResult.shiftLeft(node, rightResult); | 339 return leftResult.shiftLeft(node, rightResult); |
325 } else if (node.operator.type == TokenType.MINUS) { | 340 } else if (operatorType == TokenType.MINUS) { |
326 return leftResult.minus(node, rightResult); | 341 return leftResult.minus(node, rightResult); |
327 } else if (node.operator.type == TokenType.PERCENT) { | 342 } else if (operatorType == TokenType.PERCENT) { |
328 return leftResult.remainder(node, rightResult); | 343 return leftResult.remainder(node, rightResult); |
329 } else if (node.operator.type == TokenType.PLUS) { | 344 } else if (operatorType == TokenType.PLUS) { |
330 return leftResult.add(node, rightResult); | 345 return leftResult.add(node, rightResult); |
331 } else if (node.operator.type == TokenType.STAR) { | 346 } else if (operatorType == TokenType.STAR) { |
332 return leftResult.times(node, rightResult); | 347 return leftResult.times(node, rightResult); |
333 } else if (node.operator.type == TokenType.SLASH) { | 348 } else if (operatorType == TokenType.SLASH) { |
334 return leftResult.divide(node, rightResult); | 349 return leftResult.divide(node, rightResult); |
335 } else if (node.operator.type == TokenType.TILDE_SLASH) { | 350 } else if (operatorType == TokenType.TILDE_SLASH) { |
336 return leftResult.integerDivide(node, rightResult); | 351 return leftResult.integerDivide(node, rightResult); |
337 } | 352 } |
338 break; | 353 break; |
339 } | 354 } |
340 return error(node, null); | 355 return error(node, null); |
341 } | 356 } |
342 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => node.value ?
ValidResult.RESULT_TRUE : ValidResult.RESULT_FALSE; | 357 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => node.value ?
ValidResult.RESULT_TRUE : ValidResult.RESULT_FALSE; |
343 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => new ValidResult
(node.value); | 358 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => new ValidResult
(node.value); |
344 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio
n node) { | 359 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio
n node) { |
345 ConstructorElement constructor = node.element; | 360 ConstructorElement constructor = node.element; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 EvaluationResultImpl rightArgument = arguments2[1].accept(this); | 406 EvaluationResultImpl rightArgument = arguments2[1].accept(this); |
392 return leftArgument.equalEqual(node, rightArgument); | 407 return leftArgument.equalEqual(node, rightArgument); |
393 } | 408 } |
394 } | 409 } |
395 } | 410 } |
396 } | 411 } |
397 } | 412 } |
398 return error(node, null); | 413 return error(node, null); |
399 } | 414 } |
400 EvaluationResultImpl visitNode(ASTNode node) => error(node, null); | 415 EvaluationResultImpl visitNode(ASTNode node) => error(node, null); |
401 EvaluationResultImpl visitNullLiteral(NullLiteral node) => new ValidResult(nul
l); | 416 EvaluationResultImpl visitNullLiteral(NullLiteral node) => ValidResult.RESULT_
NULL; |
402 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node
) => node.expression.accept(this); | 417 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node
) => node.expression.accept(this); |
403 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) => getCo
nstantValue(node, node.element); | 418 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) => getCo
nstantValue(node, node.element); |
404 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) { | 419 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) { |
405 EvaluationResultImpl operand2 = node.operand.accept(this); | 420 EvaluationResultImpl operand2 = node.operand.accept(this); |
| 421 if (operand2 is ValidResult && ((operand2 as ValidResult)).isNull()) { |
| 422 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); |
| 423 } |
406 while (true) { | 424 while (true) { |
407 if (node.operator.type == TokenType.BANG) { | 425 if (node.operator.type == TokenType.BANG) { |
408 return operand2.logicalNot(node); | 426 return operand2.logicalNot(node); |
409 } else if (node.operator.type == TokenType.TILDE) { | 427 } else if (node.operator.type == TokenType.TILDE) { |
410 return operand2.bitNot(node); | 428 return operand2.bitNot(node); |
411 } else if (node.operator.type == TokenType.MINUS) { | 429 } else if (node.operator.type == TokenType.MINUS) { |
412 return operand2.negated(node); | 430 return operand2.negated(node); |
413 } | 431 } |
414 break; | 432 break; |
415 } | 433 } |
416 return error(node, null); | 434 return error(node, null); |
417 } | 435 } |
418 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => getConstantVa
lue(node, node.propertyName.element); | 436 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => getConstantVa
lue(node, node.propertyName.element); |
419 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) => getConsta
ntValue(node, node.element); | 437 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) => getConsta
ntValue(node, node.element); |
420 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new
ValidResult(node.value); | 438 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new
ValidResult(node.value); |
421 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) { | 439 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) { |
422 EvaluationResultImpl result = null; | 440 EvaluationResultImpl result = null; |
423 for (InterpolationElement element in node.elements) { | 441 for (InterpolationElement element in node.elements) { |
424 if (result == null) { | 442 if (result == null) { |
425 result = element.accept(this); | 443 result = element.accept(this); |
426 } else { | 444 } else { |
427 result = result.concatenate(node, element.accept(this)); | 445 result = result.concatenate(node, element.accept(this)); |
428 } | 446 } |
429 } | 447 } |
430 return result; | 448 return result; |
431 } | 449 } |
| 450 |
432 /** | 451 /** |
433 * Return a result object representing an error associated with the given node
. | 452 * Return a result object representing an error associated with the given node
. |
434 * @param node the AST node associated with the error | 453 * @param node the AST node associated with the error |
435 * @param code the error code indicating the nature of the error | 454 * @param code the error code indicating the nature of the error |
436 * @return a result object representing an error associated with the given nod
e | 455 * @return a result object representing an error associated with the given nod
e |
437 */ | 456 */ |
438 ErrorResult error(ASTNode node, ErrorCode code) => new ErrorResult.con1(node,
code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code); | 457 ErrorResult error(ASTNode node, ErrorCode code) => new ErrorResult.con1(node,
code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code); |
| 458 |
439 /** | 459 /** |
440 * Return the constant value of the static constant represented by the given e
lement. | 460 * Return the constant value of the static constant represented by the given e
lement. |
441 * @param node the node to be used if an error needs to be reported | 461 * @param node the node to be used if an error needs to be reported |
442 * @param element the element whose value is to be returned | 462 * @param element the element whose value is to be returned |
443 * @return the constant value of the static constant | 463 * @return the constant value of the static constant |
444 */ | 464 */ |
445 EvaluationResultImpl getConstantValue(ASTNode node, Element element) { | 465 EvaluationResultImpl getConstantValue(ASTNode node, Element element) { |
446 if (element is PropertyAccessorElement) { | 466 if (element is PropertyAccessorElement) { |
447 element = ((element as PropertyAccessorElement)).variable; | 467 element = ((element as PropertyAccessorElement)).variable; |
448 } | 468 } |
449 if (element is VariableElementImpl) { | 469 if (element is VariableElementImpl) { |
450 EvaluationResultImpl value = ((element as VariableElementImpl)).evaluation
Result; | 470 EvaluationResultImpl value = ((element as VariableElementImpl)).evaluation
Result; |
451 if (value != null) { | 471 if (value != null) { |
452 return value; | 472 return value; |
453 } | 473 } |
454 } else if (element is ExecutableElement) { | 474 } else if (element is ExecutableElement) { |
455 return new ValidResult(element); | 475 return new ValidResult(element); |
| 476 } else if (element is ClassElement) { |
| 477 return ValidResult.RESULT_OBJECT; |
456 } | 478 } |
457 return error(node, null); | 479 return error(node, null); |
458 } | 480 } |
| 481 |
459 /** | 482 /** |
460 * Return the union of the errors encoded in the given results. | 483 * Return the union of the errors encoded in the given results. |
461 * @param leftResult the first set of errors, or {@code null} if there was no
previous collection | 484 * @param leftResult the first set of errors, or {@code null} if there was no
previous collection |
462 * of errors | 485 * of errors |
463 * @param rightResult the errors to be added to the collection, or a valid res
ult if there are no | 486 * @param rightResult the errors to be added to the collection, or a valid res
ult if there are no |
464 * errors to be added | 487 * errors to be added |
465 * @return the union of the errors encoded in the given results | 488 * @return the union of the errors encoded in the given results |
466 */ | 489 */ |
467 ErrorResult union(ErrorResult leftResult, EvaluationResultImpl rightResult) { | 490 ErrorResult union(ErrorResult leftResult, EvaluationResultImpl rightResult) { |
468 if (rightResult is ErrorResult) { | 491 if (rightResult is ErrorResult) { |
469 if (leftResult != null) { | 492 if (leftResult != null) { |
470 return new ErrorResult.con2(leftResult, (rightResult as ErrorResult)); | 493 return new ErrorResult.con2(leftResult, (rightResult as ErrorResult)); |
471 } else { | 494 } else { |
472 return rightResult as ErrorResult; | 495 return rightResult as ErrorResult; |
473 } | 496 } |
474 } | 497 } |
475 return leftResult; | 498 return leftResult; |
476 } | 499 } |
477 } | 500 } |
| 501 |
478 /** | 502 /** |
479 * Instances of the class {@code DirectedGraph} implement a directed graph in wh
ich the nodes are | 503 * Instances of the class {@code DirectedGraph} implement a directed graph in wh
ich the nodes are |
480 * arbitrary (client provided) objects and edges are represented implicitly. The
graph will allow an | 504 * arbitrary (client provided) objects and edges are represented implicitly. The
graph will allow an |
481 * edge from any node to any other node, including itself, but will not represen
t multiple edges | 505 * edge from any node to any other node, including itself, but will not represen
t multiple edges |
482 * between the same pair of nodes. | 506 * between the same pair of nodes. |
483 * @param N the type of the nodes in the graph | 507 * @param N the type of the nodes in the graph |
484 */ | 508 */ |
485 class DirectedGraph<N> { | 509 class DirectedGraph<N> { |
| 510 |
486 /** | 511 /** |
487 * The table encoding the edges in the graph. An edge is represented by an ent
ry mapping the head | 512 * The table encoding the edges in the graph. An edge is represented by an ent
ry mapping the head |
488 * to a set of tails. Nodes that are not the head of any edge are represented
by an entry mapping | 513 * to a set of tails. Nodes that are not the head of any edge are represented
by an entry mapping |
489 * the node to an empty set of tails. | 514 * the node to an empty set of tails. |
490 */ | 515 */ |
491 Map<N, Set<N>> _edges = new Map<N, Set<N>>(); | 516 Map<N, Set<N>> _edges = new Map<N, Set<N>>(); |
492 /** | 517 |
493 * Initialize a newly create directed graph to be empty. | |
494 */ | |
495 DirectedGraph() : super() { | |
496 } | |
497 /** | 518 /** |
498 * Add an edge from the given head node to the given tail node. Both nodes wil
l be a part of the | 519 * Add an edge from the given head node to the given tail node. Both nodes wil
l be a part of the |
499 * graph after this method is invoked, whether or not they were before. | 520 * graph after this method is invoked, whether or not they were before. |
500 * @param head the node at the head of the edge | 521 * @param head the node at the head of the edge |
501 * @param tail the node at the tail of the edge | 522 * @param tail the node at the tail of the edge |
502 */ | 523 */ |
503 void addEdge(N head, N tail) { | 524 void addEdge(N head, N tail) { |
504 Set<N> tails = _edges[tail]; | 525 Set<N> tails = _edges[tail]; |
505 if (tails == null) { | 526 if (tails == null) { |
506 _edges[tail] = new Set<N>(); | 527 _edges[tail] = new Set<N>(); |
507 } | 528 } |
508 tails = _edges[head]; | 529 tails = _edges[head]; |
509 if (tails == null) { | 530 if (tails == null) { |
510 tails = new Set<N>(); | 531 tails = new Set<N>(); |
511 _edges[head] = tails; | 532 _edges[head] = tails; |
512 } | 533 } |
513 javaSetAdd(tails, tail); | 534 javaSetAdd(tails, tail); |
514 } | 535 } |
| 536 |
515 /** | 537 /** |
516 * Add the given node to the set of nodes in the graph. | 538 * Add the given node to the set of nodes in the graph. |
517 * @param node the node to be added | 539 * @param node the node to be added |
518 */ | 540 */ |
519 void addNode(N node) { | 541 void addNode(N node) { |
520 Set<N> tails = _edges[node]; | 542 Set<N> tails = _edges[node]; |
521 if (tails == null) { | 543 if (tails == null) { |
522 _edges[node] = new Set<N>(); | 544 _edges[node] = new Set<N>(); |
523 } | 545 } |
524 } | 546 } |
| 547 |
525 /** | 548 /** |
526 * Return a list of nodes that form a cycle, or {@code null} if there are no c
ycles in this graph. | 549 * Return a list of nodes that form a cycle, or {@code null} if there are no c
ycles in this graph. |
527 * @return a list of nodes that form a cycle | 550 * @return a list of nodes that form a cycle |
528 */ | 551 */ |
529 List<N> findCycle() => null; | 552 List<N> findCycle() => null; |
| 553 |
530 /** | 554 /** |
531 * Return the number of nodes in this graph. | 555 * Return the number of nodes in this graph. |
532 * @return the number of nodes in this graph | 556 * @return the number of nodes in this graph |
533 */ | 557 */ |
534 int get nodeCount => _edges.length; | 558 int get nodeCount => _edges.length; |
| 559 |
535 /** | 560 /** |
536 * Return a set containing the tails of edges that have the given node as thei
r head. The set will | 561 * Return a set containing the tails of edges that have the given node as thei
r head. The set will |
537 * be empty if there are no such edges or if the node is not part of the graph
. Clients must not | 562 * be empty if there are no such edges or if the node is not part of the graph
. Clients must not |
538 * modify the returned set. | 563 * modify the returned set. |
539 * @param head the node at the head of all of the edges whose tails are to be
returned | 564 * @param head the node at the head of all of the edges whose tails are to be
returned |
540 * @return a set containing the tails of edges that have the given node as the
ir head | 565 * @return a set containing the tails of edges that have the given node as the
ir head |
541 */ | 566 */ |
542 Set<N> getTails(N head) { | 567 Set<N> getTails(N head) { |
543 Set<N> tails = _edges[head]; | 568 Set<N> tails = _edges[head]; |
544 if (tails == null) { | 569 if (tails == null) { |
545 return new Set<N>(); | 570 return new Set<N>(); |
546 } | 571 } |
547 return tails; | 572 return tails; |
548 } | 573 } |
| 574 |
549 /** | 575 /** |
550 * Return {@code true} if this graph is empty. | 576 * Return {@code true} if this graph is empty. |
551 * @return {@code true} if this graph is empty | 577 * @return {@code true} if this graph is empty |
552 */ | 578 */ |
553 bool isEmpty() => _edges.isEmpty; | 579 bool isEmpty() => _edges.isEmpty; |
| 580 |
554 /** | 581 /** |
555 * Remove all of the given nodes from this graph. As a consequence, any edges
for which those | 582 * Remove all of the given nodes from this graph. As a consequence, any edges
for which those |
556 * nodes were either a head or a tail will also be removed. | 583 * nodes were either a head or a tail will also be removed. |
557 * @param nodes the nodes to be removed | 584 * @param nodes the nodes to be removed |
558 */ | 585 */ |
559 void removeAllNodes(List<N> nodes) { | 586 void removeAllNodes(List<N> nodes) { |
560 for (N node in nodes) { | 587 for (N node in nodes) { |
561 removeNode(node); | 588 removeNode(node); |
562 } | 589 } |
563 } | 590 } |
| 591 |
564 /** | 592 /** |
565 * Remove the edge from the given head node to the given tail node. If there w
as no such edge then | 593 * Remove the edge from the given head node to the given tail node. If there w
as no such edge then |
566 * the graph will be unmodified: the number of edges will be the same and the
set of nodes will be | 594 * the graph will be unmodified: the number of edges will be the same and the
set of nodes will be |
567 * the same (neither node will either be added or removed). | 595 * the same (neither node will either be added or removed). |
568 * @param head the node at the head of the edge | 596 * @param head the node at the head of the edge |
569 * @param tail the node at the tail of the edge | 597 * @param tail the node at the tail of the edge |
570 * @return {@code true} if the graph was modified as a result of this operatio
n | 598 * @return {@code true} if the graph was modified as a result of this operatio
n |
571 */ | 599 */ |
572 void removeEdge(N head, N tail) { | 600 void removeEdge(N head, N tail) { |
573 Set<N> tails = _edges[head]; | 601 Set<N> tails = _edges[head]; |
574 if (tails != null) { | 602 if (tails != null) { |
575 tails.remove(tail); | 603 tails.remove(tail); |
576 } | 604 } |
577 } | 605 } |
| 606 |
578 /** | 607 /** |
579 * Remove the given node from this graph. As a consequence, any edges for whic
h that node was | 608 * Remove the given node from this graph. As a consequence, any edges for whic
h that node was |
580 * either a head or a tail will also be removed. | 609 * either a head or a tail will also be removed. |
581 * @param node the node to be removed | 610 * @param node the node to be removed |
582 */ | 611 */ |
583 void removeNode(N node) { | 612 void removeNode(N node) { |
584 _edges.remove(node); | 613 _edges.remove(node); |
585 for (Set<N> tails in _edges.values) { | 614 for (Set<N> tails in _edges.values) { |
586 tails.remove(node); | 615 tails.remove(node); |
587 } | 616 } |
588 } | 617 } |
| 618 |
589 /** | 619 /** |
590 * Find one node (referred to as a sink node) that has no outgoing edges (that
is, for which there | 620 * Find one node (referred to as a sink node) that has no outgoing edges (that
is, for which there |
591 * are no edges that have that node as the head of the edge) and remove it fro
m this graph. Return | 621 * are no edges that have that node as the head of the edge) and remove it fro
m this graph. Return |
592 * the node that was removed, or {@code null} if there are no such nodes eithe
r because the graph | 622 * the node that was removed, or {@code null} if there are no such nodes eithe
r because the graph |
593 * is empty or because every node in the graph has at least one outgoing edge.
As a consequence of | 623 * is empty or because every node in the graph has at least one outgoing edge.
As a consequence of |
594 * removing the node from the graph any edges for which that node was a tail w
ill also be removed. | 624 * removing the node from the graph any edges for which that node was a tail w
ill also be removed. |
595 * @return the sink node that was removed | 625 * @return the sink node that was removed |
596 */ | 626 */ |
597 N removeSink() { | 627 N removeSink() { |
598 N sink = findSink(); | 628 N sink = findSink(); |
599 if (sink == null) { | 629 if (sink == null) { |
600 return null; | 630 return null; |
601 } | 631 } |
602 removeNode(sink); | 632 removeNode(sink); |
603 return sink; | 633 return sink; |
604 } | 634 } |
| 635 |
605 /** | 636 /** |
606 * Return one node that has no outgoing edges (that is, for which there are no
edges that have | 637 * Return one node that has no outgoing edges (that is, for which there are no
edges that have |
607 * that node as the head of the edge), or {@code null} if there are no such no
des. | 638 * that node as the head of the edge), or {@code null} if there are no such no
des. |
608 * @return a sink node | 639 * @return a sink node |
609 */ | 640 */ |
610 N findSink() { | 641 N findSink() { |
611 for (MapEntry<N, Set<N>> entry in getMapEntrySet(_edges)) { | 642 for (MapEntry<N, Set<N>> entry in getMapEntrySet(_edges)) { |
612 if (entry.getValue().isEmpty) { | 643 if (entry.getValue().isEmpty) { |
613 return entry.getKey(); | 644 return entry.getKey(); |
614 } | 645 } |
615 } | 646 } |
616 return null; | 647 return null; |
617 } | 648 } |
618 } | 649 } |
| 650 |
619 /** | 651 /** |
620 * Instances of the class {@code ErrorResult} represent the result of evaluating
an expression that | 652 * Instances of the class {@code ErrorResult} represent the result of evaluating
an expression that |
621 * is not a valid compile time constant. | 653 * is not a valid compile time constant. |
622 */ | 654 */ |
623 class ErrorResult extends EvaluationResultImpl { | 655 class ErrorResult extends EvaluationResultImpl { |
| 656 |
624 /** | 657 /** |
625 * The errors that prevent the expression from being a valid compile time cons
tant. | 658 * The errors that prevent the expression from being a valid compile time cons
tant. |
626 */ | 659 */ |
627 List<ErrorResult_ErrorData> _errors = new List<ErrorResult_ErrorData>(); | 660 List<ErrorResult_ErrorData> _errors = new List<ErrorResult_ErrorData>(); |
| 661 |
628 /** | 662 /** |
629 * Initialize a newly created result representing the error with the given cod
e reported against | 663 * Initialize a newly created result representing the error with the given cod
e reported against |
630 * the given node. | 664 * the given node. |
631 * @param node the node against which the error should be reported | 665 * @param node the node against which the error should be reported |
632 * @param errorCode the error code for the error to be generated | 666 * @param errorCode the error code for the error to be generated |
633 */ | 667 */ |
634 ErrorResult.con1(ASTNode node, ErrorCode errorCode) { | 668 ErrorResult.con1(ASTNode node, ErrorCode errorCode) { |
635 _jtd_constructor_168_impl(node, errorCode); | 669 _jtd_constructor_171_impl(node, errorCode); |
636 } | 670 } |
637 _jtd_constructor_168_impl(ASTNode node, ErrorCode errorCode) { | 671 _jtd_constructor_171_impl(ASTNode node, ErrorCode errorCode) { |
638 _errors.add(new ErrorResult_ErrorData(node, errorCode)); | 672 _errors.add(new ErrorResult_ErrorData(node, errorCode)); |
639 } | 673 } |
| 674 |
640 /** | 675 /** |
641 * Initialize a newly created result to represent the union of the errors in t
he given result | 676 * Initialize a newly created result to represent the union of the errors in t
he given result |
642 * objects. | 677 * objects. |
643 * @param firstResult the first set of results being merged | 678 * @param firstResult the first set of results being merged |
644 * @param secondResult the second set of results being merged | 679 * @param secondResult the second set of results being merged |
645 */ | 680 */ |
646 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) { | 681 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) { |
647 _jtd_constructor_169_impl(firstResult, secondResult); | 682 _jtd_constructor_172_impl(firstResult, secondResult); |
648 } | 683 } |
649 _jtd_constructor_169_impl(ErrorResult firstResult, ErrorResult secondResult) { | 684 _jtd_constructor_172_impl(ErrorResult firstResult, ErrorResult secondResult) { |
650 _errors.addAll(firstResult._errors); | 685 _errors.addAll(firstResult._errors); |
651 _errors.addAll(secondResult._errors); | 686 _errors.addAll(secondResult._errors); |
652 } | 687 } |
653 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToError(node, this); | 688 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToError(node, this); |
654 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndError(node, this); | 689 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndError(node, this); |
655 EvaluationResultImpl bitNot(Expression node) => this; | 690 EvaluationResultImpl bitNot(Expression node) => this; |
656 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.bitOrError(node, this); | 691 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.bitOrError(node, this); |
657 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitXorError(node, this); | 692 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitXorError(node, this); |
658 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand) => rightOperand.concatenateError(node, this); | 693 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand) => rightOperand.concatenateError(node, this); |
659 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.divideError(node, this); | 694 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.divideError(node, this); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe
rand) => new ErrorResult.con2(this, leftOperand); | 745 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe
rand) => new ErrorResult.con2(this, leftOperand); |
711 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe
rand) => this; | 746 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe
rand) => this; |
712 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe
rand) => new ErrorResult.con2(this, leftOperand); | 747 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe
rand) => new ErrorResult.con2(this, leftOperand); |
713 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe
rand) => this; | 748 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe
rand) => this; |
714 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp
erand) => new ErrorResult.con2(this, leftOperand); | 749 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp
erand) => new ErrorResult.con2(this, leftOperand); |
715 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp
erand) => this; | 750 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp
erand) => this; |
716 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand
) => new ErrorResult.con2(this, leftOperand); | 751 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand
) => new ErrorResult.con2(this, leftOperand); |
717 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand
) => this; | 752 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand
) => this; |
718 } | 753 } |
719 class ErrorResult_ErrorData { | 754 class ErrorResult_ErrorData { |
| 755 |
720 /** | 756 /** |
721 * The node against which the error should be reported. | 757 * The node against which the error should be reported. |
722 */ | 758 */ |
723 ASTNode _node; | 759 ASTNode _node; |
| 760 |
724 /** | 761 /** |
725 * The error code for the error to be generated. | 762 * The error code for the error to be generated. |
726 */ | 763 */ |
727 ErrorCode _errorCode; | 764 ErrorCode _errorCode; |
| 765 |
728 /** | 766 /** |
729 * Initialize a newly created data holder to represent the error with the give
n code reported | 767 * Initialize a newly created data holder to represent the error with the give
n code reported |
730 * against the given node. | 768 * against the given node. |
731 * @param node the node against which the error should be reported | 769 * @param node the node against which the error should be reported |
732 * @param errorCode the error code for the error to be generated | 770 * @param errorCode the error code for the error to be generated |
733 */ | 771 */ |
734 ErrorResult_ErrorData(ASTNode node, ErrorCode errorCode) { | 772 ErrorResult_ErrorData(ASTNode node, ErrorCode errorCode) { |
735 this._node = node; | 773 this._node = node; |
736 this._errorCode = errorCode; | 774 this._errorCode = errorCode; |
737 } | 775 } |
| 776 |
738 /** | 777 /** |
739 * Return the error code for the error to be generated. | 778 * Return the error code for the error to be generated. |
740 * @return the error code for the error to be generated | 779 * @return the error code for the error to be generated |
741 */ | 780 */ |
742 ErrorCode get errorCode => _errorCode; | 781 ErrorCode get errorCode => _errorCode; |
| 782 |
743 /** | 783 /** |
744 * Return the node against which the error should be reported. | 784 * Return the node against which the error should be reported. |
745 * @return the node against which the error should be reported | 785 * @return the node against which the error should be reported |
746 */ | 786 */ |
747 ASTNode get node => _node; | 787 ASTNode get node => _node; |
748 } | 788 } |
| 789 |
749 /** | 790 /** |
750 * Instances of the class {@code InternalResult} represent the result of attempt
ing to evaluate a | 791 * Instances of the class {@code InternalResult} represent the result of attempt
ing to evaluate a |
751 * expression. | 792 * expression. |
752 */ | 793 */ |
753 abstract class EvaluationResultImpl { | 794 abstract class EvaluationResultImpl { |
754 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and); | 795 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and); |
755 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand); | 796 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand); |
756 EvaluationResultImpl bitNot(Expression node); | 797 EvaluationResultImpl bitNot(Expression node); |
757 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand); | 798 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand); |
758 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand); | 799 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper
and); | 850 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper
and); |
810 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe
rand); | 851 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe
rand); |
811 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe
rand); | 852 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe
rand); |
812 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe
rand); | 853 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe
rand); |
813 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe
rand); | 854 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe
rand); |
814 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp
erand); | 855 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp
erand); |
815 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp
erand); | 856 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp
erand); |
816 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand
); | 857 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand
); |
817 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand
); | 858 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand
); |
818 } | 859 } |
| 860 |
819 /** | 861 /** |
820 * Instances of the class {@code ReferenceFinder} add reference information for
a given variable to | 862 * Instances of the class {@code ReferenceFinder} add reference information for
a given variable to |
821 * the bi-directional mapping used to order the evaluation of constants. | 863 * the bi-directional mapping used to order the evaluation of constants. |
822 */ | 864 */ |
823 class ReferenceFinder extends RecursiveASTVisitor<Object> { | 865 class ReferenceFinder extends RecursiveASTVisitor<Object> { |
| 866 |
824 /** | 867 /** |
825 * The element representing the variable whose initializer will be visited. | 868 * The element representing the variable whose initializer will be visited. |
826 */ | 869 */ |
827 VariableElement _source; | 870 VariableElement _source; |
| 871 |
828 /** | 872 /** |
829 * A graph in which the nodes are the constant variables and the edges are fro
m each variable to | 873 * A graph in which the nodes are the constant variables and the edges are fro
m each variable to |
830 * the other constant variables that are referenced in the head's initializer. | 874 * the other constant variables that are referenced in the head's initializer. |
831 */ | 875 */ |
832 DirectedGraph<VariableElement> _referenceGraph; | 876 DirectedGraph<VariableElement> _referenceGraph; |
| 877 |
833 /** | 878 /** |
834 * Initialize a newly created reference finder to find references from the giv
en variable to other | 879 * Initialize a newly created reference finder to find references from the giv
en variable to other |
835 * variables and to add those references to the given graph. | 880 * variables and to add those references to the given graph. |
836 * @param source the element representing the variable whose initializer will
be visited | 881 * @param source the element representing the variable whose initializer will
be visited |
837 * @param referenceGraph a graph recording which variables (heads) reference w
hich other variables | 882 * @param referenceGraph a graph recording which variables (heads) reference w
hich other variables |
838 * (tails) in their initializers | 883 * (tails) in their initializers |
839 */ | 884 */ |
840 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen
ceGraph) { | 885 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen
ceGraph) { |
841 this._source = source; | 886 this._source = source; |
842 this._referenceGraph = referenceGraph; | 887 this._referenceGraph = referenceGraph; |
843 } | 888 } |
844 Object visitSimpleIdentifier(SimpleIdentifier node) { | 889 Object visitSimpleIdentifier(SimpleIdentifier node) { |
845 Element element2 = node.element; | 890 Element element2 = node.element; |
846 if (element2 is PropertyAccessorElement) { | 891 if (element2 is PropertyAccessorElement) { |
847 element2 = ((element2 as PropertyAccessorElement)).variable; | 892 element2 = ((element2 as PropertyAccessorElement)).variable; |
848 } | 893 } |
849 if (element2 is VariableElement) { | 894 if (element2 is VariableElement) { |
850 VariableElement variable = element2 as VariableElement; | 895 VariableElement variable = element2 as VariableElement; |
851 if (variable.isConst()) { | 896 if (variable.isConst()) { |
852 _referenceGraph.addEdge(_source, variable); | 897 _referenceGraph.addEdge(_source, variable); |
853 } | 898 } |
854 } | 899 } |
855 return null; | 900 return null; |
856 } | 901 } |
857 } | 902 } |
| 903 |
858 /** | 904 /** |
859 * Instances of the class {@code ValidResult} represent the result of attempting
to evaluate a valid | 905 * Instances of the class {@code ValidResult} represent the result of attempting
to evaluate a valid |
860 * compile time constant expression. | 906 * compile time constant expression. |
861 */ | 907 */ |
862 class ValidResult extends EvaluationResultImpl { | 908 class ValidResult extends EvaluationResultImpl { |
| 909 |
863 /** | 910 /** |
864 * A result object representing the value 'false'. | 911 * A result object representing the value 'false'. |
865 */ | 912 */ |
866 static ValidResult RESULT_FALSE = new ValidResult(false); | 913 static ValidResult RESULT_FALSE = new ValidResult(false); |
| 914 |
| 915 /** |
| 916 * A result object representing the an object without specific type on which n
o further operations |
| 917 * can be performed. |
| 918 */ |
| 919 static ValidResult RESULT_DYNAMIC = new ValidResult(null); |
| 920 |
| 921 /** |
| 922 * A result object representing the an arbitrary integer on which no further o
perations can be |
| 923 * performed. |
| 924 */ |
| 925 static ValidResult RESULT_INT = new ValidResult(null); |
| 926 |
| 927 /** |
| 928 * A result object representing the {@code null} value. |
| 929 */ |
| 930 static ValidResult RESULT_NULL = new ValidResult(null); |
| 931 |
| 932 /** |
| 933 * A result object representing the an arbitrary numeric on which no further o
perations can be |
| 934 * performed. |
| 935 */ |
| 936 static ValidResult RESULT_NUM = new ValidResult(null); |
| 937 |
| 938 /** |
| 939 * A result object representing the an arbitrary boolean on which no further o
perations can be |
| 940 * performed. |
| 941 */ |
| 942 static ValidResult RESULT_BOOL = new ValidResult(null); |
| 943 |
867 /** | 944 /** |
868 * A result object representing the an arbitrary object on which no further op
erations can be | 945 * A result object representing the an arbitrary object on which no further op
erations can be |
869 * performed. | 946 * performed. |
870 */ | 947 */ |
871 static ValidResult RESULT_OBJECT = new ValidResult(new Object()); | 948 static ValidResult RESULT_OBJECT = new ValidResult(new Object()); |
| 949 |
| 950 /** |
| 951 * A result object representing the an arbitrary string on which no further op
erations can be |
| 952 * performed. |
| 953 */ |
| 954 static ValidResult RESULT_STRING = new ValidResult("<string>"); |
| 955 |
872 /** | 956 /** |
873 * A result object representing the value 'true'. | 957 * A result object representing the value 'true'. |
874 */ | 958 */ |
875 static ValidResult RESULT_TRUE = new ValidResult(true); | 959 static ValidResult RESULT_TRUE = new ValidResult(true); |
| 960 |
876 /** | 961 /** |
877 * The value of the expression. | 962 * The value of the expression. |
878 */ | 963 */ |
879 Object _value; | 964 Object _value; |
| 965 |
880 /** | 966 /** |
881 * Initialize a newly created result to represent the given value. | 967 * Initialize a newly created result to represent the given value. |
882 * @param value the value of the expression | 968 * @param value the value of the expression |
883 */ | 969 */ |
884 ValidResult(Object value) { | 970 ValidResult(Object value) { |
885 this._value = value; | 971 this._value = value; |
886 } | 972 } |
887 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToValid(node, this); | 973 EvaluationResultImpl add(BinaryExpression node, EvaluationResultImpl rightOper
and) => rightOperand.addToValid(node, this); |
888 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndValid(node, this); | 974 EvaluationResultImpl bitAnd(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitAndValid(node, this); |
889 EvaluationResultImpl bitNot(Expression node) { | 975 EvaluationResultImpl bitNot(Expression node) { |
| 976 if (isSomeInt()) { |
| 977 return RESULT_INT; |
| 978 } |
890 if (_value == null) { | 979 if (_value == null) { |
891 return error(node); | 980 return error(node); |
892 } else if (_value is int) { | 981 } else if (_value is int) { |
893 return valueOf(~((_value as int))); | 982 return valueOf(~((_value as int))); |
894 } | 983 } |
895 return error(node); | 984 return error(node); |
896 } | 985 } |
897 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.bitOrValid(node, this); | 986 EvaluationResultImpl bitOr(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.bitOrValid(node, this); |
898 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitXorValid(node, this); | 987 EvaluationResultImpl bitXor(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.bitXorValid(node, this); |
899 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand) => rightOperand.concatenateValid(node, this); | 988 EvaluationResultImpl concatenate(Expression node, EvaluationResultImpl rightOp
erand) => rightOperand.concatenateValid(node, this); |
900 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.divideValid(node, this); | 989 EvaluationResultImpl divide(BinaryExpression node, EvaluationResultImpl rightO
perand) => rightOperand.divideValid(node, this); |
901 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe
rand) => rightOperand.equalEqualValid(node, this); | 990 EvaluationResultImpl equalEqual(Expression node, EvaluationResultImpl rightOpe
rand) => rightOperand.equalEqualValid(node, this); |
902 Object get value => _value; | 991 Object get value => _value; |
903 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r
ightOperand) => rightOperand.greaterThanValid(node, this); | 992 EvaluationResultImpl greaterThan(BinaryExpression node, EvaluationResultImpl r
ightOperand) => rightOperand.greaterThanValid(node, this); |
904 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul
tImpl rightOperand) => rightOperand.greaterThanOrEqualValid(node, this); | 993 EvaluationResultImpl greaterThanOrEqual(BinaryExpression node, EvaluationResul
tImpl rightOperand) => rightOperand.greaterThanOrEqualValid(node, this); |
905 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl
rightOperand) => rightOperand.integerDivideValid(node, this); | 994 EvaluationResultImpl integerDivide(BinaryExpression node, EvaluationResultImpl
rightOperand) => rightOperand.integerDivideValid(node, this); |
906 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ
tOperand) => rightOperand.lessThanValid(node, this); | 995 EvaluationResultImpl lessThan(BinaryExpression node, EvaluationResultImpl righ
tOperand) => rightOperand.lessThanValid(node, this); |
907 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm
pl rightOperand) => rightOperand.lessThanOrEqualValid(node, this); | 996 EvaluationResultImpl lessThanOrEqual(BinaryExpression node, EvaluationResultIm
pl rightOperand) => rightOperand.lessThanOrEqualValid(node, this); |
908 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri
ghtOperand) => rightOperand.logicalAndValid(node, this); | 997 EvaluationResultImpl logicalAnd(BinaryExpression node, EvaluationResultImpl ri
ghtOperand) => rightOperand.logicalAndValid(node, this); |
909 EvaluationResultImpl logicalNot(Expression node) { | 998 EvaluationResultImpl logicalNot(Expression node) { |
| 999 if (isSomeBool()) { |
| 1000 return RESULT_BOOL; |
| 1001 } |
910 if (_value == null) { | 1002 if (_value == null) { |
911 return RESULT_TRUE; | 1003 return RESULT_TRUE; |
912 } else if (_value is bool) { | 1004 } else if (_value is bool) { |
913 return ((_value as bool)) ? RESULT_FALSE : RESULT_TRUE; | 1005 return ((_value as bool)) ? RESULT_FALSE : RESULT_TRUE; |
914 } | 1006 } |
915 return error(node); | 1007 return error(node); |
916 } | 1008 } |
917 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig
htOperand) => rightOperand.logicalOrValid(node, this); | 1009 EvaluationResultImpl logicalOr(BinaryExpression node, EvaluationResultImpl rig
htOperand) => rightOperand.logicalOrValid(node, this); |
918 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.minusValid(node, this); | 1010 EvaluationResultImpl minus(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.minusValid(node, this); |
919 EvaluationResultImpl negated(Expression node) { | 1011 EvaluationResultImpl negated(Expression node) { |
| 1012 if (isSomeNum()) { |
| 1013 return RESULT_INT; |
| 1014 } |
920 if (_value == null) { | 1015 if (_value == null) { |
921 return error(node); | 1016 return error(node); |
922 } else if (_value is int) { | 1017 } else if (_value is int) { |
923 return valueOf(-((_value as int))); | 1018 return valueOf(-((_value as int))); |
924 } else if (_value is double) { | 1019 } else if (_value is double) { |
925 return valueOf3(-((_value as double))); | 1020 return valueOf3(-((_value as double))); |
926 } | 1021 } |
927 return error(node); | 1022 return error(node); |
928 } | 1023 } |
929 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ
tOperand) => rightOperand.notEqualValid(node, this); | 1024 EvaluationResultImpl notEqual(BinaryExpression node, EvaluationResultImpl righ
tOperand) => rightOperand.notEqualValid(node, this); |
(...skipping 16 matching lines...) Expand all Loading... |
946 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri
ghtOperand) => rightOperand.shiftRightValid(node, this); | 1041 EvaluationResultImpl shiftRight(BinaryExpression node, EvaluationResultImpl ri
ghtOperand) => rightOperand.shiftRightValid(node, this); |
947 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.timesValid(node, this); | 1042 EvaluationResultImpl times(BinaryExpression node, EvaluationResultImpl rightOp
erand) => rightOperand.timesValid(node, this); |
948 String toString() { | 1043 String toString() { |
949 if (_value == null) { | 1044 if (_value == null) { |
950 return "null"; | 1045 return "null"; |
951 } | 1046 } |
952 return _value.toString(); | 1047 return _value.toString(); |
953 } | 1048 } |
954 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; | 1049 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; |
955 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand
2) { | 1050 EvaluationResultImpl addToValid(BinaryExpression node, ValidResult leftOperand
2) { |
| 1051 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1052 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1053 return RESULT_NUM; |
| 1054 } |
| 1055 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1056 } |
956 Object leftValue = leftOperand2.value; | 1057 Object leftValue = leftOperand2.value; |
957 if (leftValue == null) { | 1058 if (leftValue == null) { |
958 return error(node.leftOperand); | 1059 return error(node.leftOperand); |
959 } else if (_value == null) { | 1060 } else if (_value == null) { |
960 return error(node.rightOperand); | 1061 return error(node.rightOperand); |
961 } else if (leftValue is int) { | 1062 } else if (leftValue is int) { |
962 if (_value is int) { | 1063 if (_value is int) { |
963 return valueOf(((leftValue as int)) + (_value as int)); | 1064 return valueOf(((leftValue as int)) + (_value as int)); |
964 } else if (_value is double) { | 1065 } else if (_value is double) { |
965 return valueOf3(((leftValue as int)).toDouble() + ((_value as double))); | 1066 return valueOf3(((leftValue as int)).toDouble() + ((_value as double))); |
966 } | 1067 } |
967 } else if (leftValue is double) { | 1068 } else if (leftValue is double) { |
968 if (_value is int) { | 1069 if (_value is int) { |
969 return valueOf3(((leftValue as double)) + ((_value as int)).toDouble()); | 1070 return valueOf3(((leftValue as double)) + ((_value as int)).toDouble()); |
970 } else if (_value is double) { | 1071 } else if (_value is double) { |
971 return valueOf3(((leftValue as double)) + ((_value as double))); | 1072 return valueOf3(((leftValue as double)) + ((_value as double))); |
972 } | 1073 } |
973 } else if (leftValue is String) { | 1074 } else if (leftValue is String) { |
974 if (_value is String) { | 1075 if (_value is String) { |
975 return valueOf4("${((leftValue as String))}${((_value as String))}"); | 1076 return valueOf4("${((leftValue as String))}${((_value as String))}"); |
976 } | 1077 } |
977 } | 1078 } |
978 return error(node); | 1079 return error(node); |
979 } | 1080 } |
980 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan
d) => leftOperand; | 1081 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan
d) => leftOperand; |
981 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan
d2) { | 1082 EvaluationResultImpl bitAndValid(BinaryExpression node, ValidResult leftOperan
d2) { |
| 1083 if (isSomeInt() || leftOperand2.isSomeInt()) { |
| 1084 if (isAnyInt() && leftOperand2.isAnyInt()) { |
| 1085 return RESULT_INT; |
| 1086 } |
| 1087 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); |
| 1088 } |
982 Object leftValue = leftOperand2.value; | 1089 Object leftValue = leftOperand2.value; |
983 if (leftValue == null) { | 1090 if (leftValue == null) { |
984 return error(node.leftOperand); | 1091 return error(node.leftOperand); |
985 } else if (_value == null) { | 1092 } else if (_value == null) { |
986 return error(node.rightOperand); | 1093 return error(node.rightOperand); |
987 } else if (leftValue is int) { | 1094 } else if (leftValue is int) { |
988 if (_value is int) { | 1095 if (_value is int) { |
989 return valueOf(((leftValue as int)) & (_value as int)); | 1096 return valueOf(((leftValue as int)) & (_value as int)); |
990 } | 1097 } |
991 return error(node.leftOperand); | 1098 return error(node.leftOperand); |
992 } | 1099 } |
993 if (_value is int) { | 1100 if (_value is int) { |
994 return error(node.rightOperand); | 1101 return error(node.rightOperand); |
995 } | 1102 } |
996 return union(error(node.leftOperand), error(node.rightOperand)); | 1103 return union(error(node.leftOperand), error(node.rightOperand)); |
997 } | 1104 } |
998 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; | 1105 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; |
999 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand
2) { | 1106 EvaluationResultImpl bitOrValid(BinaryExpression node, ValidResult leftOperand
2) { |
| 1107 if (isSomeInt() || leftOperand2.isSomeInt()) { |
| 1108 if (isAnyInt() && leftOperand2.isAnyInt()) { |
| 1109 return RESULT_INT; |
| 1110 } |
| 1111 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); |
| 1112 } |
1000 Object leftValue = leftOperand2.value; | 1113 Object leftValue = leftOperand2.value; |
1001 if (leftValue == null) { | 1114 if (leftValue == null) { |
1002 return error(node.leftOperand); | 1115 return error(node.leftOperand); |
1003 } else if (_value == null) { | 1116 } else if (_value == null) { |
1004 return error(node.rightOperand); | 1117 return error(node.rightOperand); |
1005 } else if (leftValue is int) { | 1118 } else if (leftValue is int) { |
1006 if (_value is int) { | 1119 if (_value is int) { |
1007 return valueOf(((leftValue as int)) | (_value as int)); | 1120 return valueOf(((leftValue as int)) | (_value as int)); |
1008 } | 1121 } |
1009 return error(node.leftOperand); | 1122 return error(node.leftOperand); |
1010 } | 1123 } |
1011 if (_value is int) { | 1124 if (_value is int) { |
1012 return error(node.rightOperand); | 1125 return error(node.rightOperand); |
1013 } | 1126 } |
1014 return union(error(node.leftOperand), error(node.rightOperand)); | 1127 return union(error(node.leftOperand), error(node.rightOperand)); |
1015 } | 1128 } |
1016 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan
d) => leftOperand; | 1129 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan
d) => leftOperand; |
1017 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan
d2) { | 1130 EvaluationResultImpl bitXorValid(BinaryExpression node, ValidResult leftOperan
d2) { |
| 1131 if (isSomeInt() || leftOperand2.isSomeInt()) { |
| 1132 if (isAnyInt() && leftOperand2.isAnyInt()) { |
| 1133 return RESULT_INT; |
| 1134 } |
| 1135 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); |
| 1136 } |
1018 Object leftValue = leftOperand2.value; | 1137 Object leftValue = leftOperand2.value; |
1019 if (leftValue == null) { | 1138 if (leftValue == null) { |
1020 return error(node.leftOperand); | 1139 return error(node.leftOperand); |
1021 } else if (_value == null) { | 1140 } else if (_value == null) { |
1022 return error(node.rightOperand); | 1141 return error(node.rightOperand); |
1023 } else if (leftValue is int) { | 1142 } else if (leftValue is int) { |
1024 if (_value is int) { | 1143 if (_value is int) { |
1025 return valueOf(((leftValue as int)) ^ (_value as int)); | 1144 return valueOf(((leftValue as int)) ^ (_value as int)); |
1026 } | 1145 } |
1027 return error(node.leftOperand); | 1146 return error(node.leftOperand); |
1028 } | 1147 } |
1029 if (_value is int) { | 1148 if (_value is int) { |
1030 return error(node.rightOperand); | 1149 return error(node.rightOperand); |
1031 } | 1150 } |
1032 return union(error(node.leftOperand), error(node.rightOperand)); | 1151 return union(error(node.leftOperand), error(node.rightOperand)); |
1033 } | 1152 } |
1034 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand
) => leftOperand; | 1153 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand
) => leftOperand; |
1035 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand
) { | 1154 EvaluationResultImpl concatenateValid(Expression node, ValidResult leftOperand
) { |
1036 Object leftValue = leftOperand.value; | 1155 Object leftValue = leftOperand.value; |
1037 if (leftValue is String && _value is String) { | 1156 if (leftValue is String && _value is String) { |
1038 return valueOf4("${((leftValue as String))}${((_value as String))}"); | 1157 return valueOf4("${((leftValue as String))}${((_value as String))}"); |
1039 } | 1158 } |
1040 return error(node); | 1159 return error(node); |
1041 } | 1160 } |
1042 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan
d) => leftOperand; | 1161 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan
d) => leftOperand; |
1043 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan
d2) { | 1162 EvaluationResultImpl divideValid(BinaryExpression node, ValidResult leftOperan
d2) { |
| 1163 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1164 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1165 return RESULT_NUM; |
| 1166 } |
| 1167 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1168 } |
1044 Object leftValue = leftOperand2.value; | 1169 Object leftValue = leftOperand2.value; |
1045 if (leftValue == null) { | 1170 if (leftValue == null) { |
1046 return error(node.leftOperand); | 1171 return error(node.leftOperand); |
1047 } else if (_value == null) { | 1172 } else if (_value == null) { |
1048 return error(node.rightOperand); | 1173 return error(node.rightOperand); |
1049 } else if (leftValue is int) { | 1174 } else if (leftValue is int) { |
1050 if (_value is int) { | 1175 if (_value is int) { |
1051 if (((_value as int)) == 0) { | 1176 if (((_value as int)) == 0) { |
1052 return valueOf3(((leftValue as int)).toDouble() / ((_value as int)).to
Double()); | 1177 return valueOf3(((leftValue as int)).toDouble() / ((_value as int)).to
Double()); |
1053 } | 1178 } |
1054 return valueOf(((leftValue as int)) ~/ (_value as int)); | 1179 return valueOf(((leftValue as int)) ~/ (_value as int)); |
1055 } else if (_value is double) { | 1180 } else if (_value is double) { |
1056 return valueOf3(((leftValue as int)).toDouble() / ((_value as double))); | 1181 return valueOf3(((leftValue as int)).toDouble() / ((_value as double))); |
1057 } | 1182 } |
1058 } else if (leftValue is double) { | 1183 } else if (leftValue is double) { |
1059 if (_value is int) { | 1184 if (_value is int) { |
1060 return valueOf3(((leftValue as double)) / ((_value as int)).toDouble()); | 1185 return valueOf3(((leftValue as double)) / ((_value as int)).toDouble()); |
1061 } else if (_value is double) { | 1186 } else if (_value is double) { |
1062 return valueOf3(((leftValue as double)) / ((_value as double))); | 1187 return valueOf3(((leftValue as double)) / ((_value as double))); |
1063 } | 1188 } |
1064 } | 1189 } |
1065 return error(node); | 1190 return error(node); |
1066 } | 1191 } |
1067 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand)
=> leftOperand; | 1192 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand)
=> leftOperand; |
1068 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand)
{ | 1193 EvaluationResultImpl equalEqualValid(Expression node, ValidResult leftOperand)
{ |
| 1194 if (node is BinaryExpression) { |
| 1195 if (!isAnyNullBoolNumString() || !leftOperand.isAnyNullBoolNumString()) { |
| 1196 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING
); |
| 1197 } |
| 1198 } |
1069 Object leftValue = leftOperand.value; | 1199 Object leftValue = leftOperand.value; |
1070 if (leftValue == null) { | 1200 if (leftValue == null) { |
1071 return valueOf2(_value == null); | 1201 return valueOf2(_value == null); |
1072 } else if (leftValue is bool) { | 1202 } else if (leftValue is bool) { |
1073 if (_value is bool) { | 1203 if (_value is bool) { |
1074 return valueOf2(identical(((leftValue as bool)), ((_value as bool)))); | 1204 return valueOf2(identical(((leftValue as bool)), ((_value as bool)))); |
1075 } | 1205 } |
1076 return RESULT_FALSE; | 1206 return RESULT_FALSE; |
1077 } else if (leftValue is int) { | 1207 } else if (leftValue is int) { |
1078 if (_value is int) { | 1208 if (_value is int) { |
(...skipping 13 matching lines...) Expand all Loading... |
1092 if (_value is String) { | 1222 if (_value is String) { |
1093 return valueOf2(((leftValue as String)) == _value); | 1223 return valueOf2(((leftValue as String)) == _value); |
1094 } | 1224 } |
1095 return RESULT_FALSE; | 1225 return RESULT_FALSE; |
1096 } | 1226 } |
1097 return RESULT_FALSE; | 1227 return RESULT_FALSE; |
1098 } | 1228 } |
1099 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO
perand) => leftOperand; | 1229 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO
perand) => leftOperand; |
1100 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul
t leftOperand) => leftOperand; | 1230 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul
t leftOperand) => leftOperand; |
1101 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul
t leftOperand2) { | 1231 EvaluationResultImpl greaterThanOrEqualValid(BinaryExpression node, ValidResul
t leftOperand2) { |
| 1232 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1233 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1234 return RESULT_BOOL; |
| 1235 } |
| 1236 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1237 } |
1102 Object leftValue = leftOperand2.value; | 1238 Object leftValue = leftOperand2.value; |
1103 if (leftValue == null) { | 1239 if (leftValue == null) { |
1104 return error(node.leftOperand); | 1240 return error(node.leftOperand); |
1105 } else if (_value == null) { | 1241 } else if (_value == null) { |
1106 return error(node.rightOperand); | 1242 return error(node.rightOperand); |
1107 } else if (leftValue is int) { | 1243 } else if (leftValue is int) { |
1108 if (_value is int) { | 1244 if (_value is int) { |
1109 return valueOf2(((leftValue as int)).compareTo((_value as int)) >= 0); | 1245 return valueOf2(((leftValue as int)).compareTo((_value as int)) >= 0); |
1110 } else if (_value is double) { | 1246 } else if (_value is double) { |
1111 return valueOf2(((leftValue as int)).toDouble() >= ((_value as double)))
; | 1247 return valueOf2(((leftValue as int)).toDouble() >= ((_value as double)))
; |
1112 } | 1248 } |
1113 } else if (leftValue is double) { | 1249 } else if (leftValue is double) { |
1114 if (_value is int) { | 1250 if (_value is int) { |
1115 return valueOf2(((leftValue as double)) >= ((_value as int)).toDouble())
; | 1251 return valueOf2(((leftValue as double)) >= ((_value as int)).toDouble())
; |
1116 } else if (_value is double) { | 1252 } else if (_value is double) { |
1117 return valueOf2(((leftValue as double)) >= ((_value as double))); | 1253 return valueOf2(((leftValue as double)) >= ((_value as double))); |
1118 } | 1254 } |
1119 } | 1255 } |
1120 return error(node); | 1256 return error(node); |
1121 } | 1257 } |
1122 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO
perand2) { | 1258 EvaluationResultImpl greaterThanValid(BinaryExpression node, ValidResult leftO
perand2) { |
| 1259 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1260 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1261 return RESULT_BOOL; |
| 1262 } |
| 1263 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1264 } |
1123 Object leftValue = leftOperand2.value; | 1265 Object leftValue = leftOperand2.value; |
1124 if (leftValue == null) { | 1266 if (leftValue == null) { |
1125 return error(node.leftOperand); | 1267 return error(node.leftOperand); |
1126 } else if (_value == null) { | 1268 } else if (_value == null) { |
1127 return error(node.rightOperand); | 1269 return error(node.rightOperand); |
1128 } else if (leftValue is int) { | 1270 } else if (leftValue is int) { |
1129 if (_value is int) { | 1271 if (_value is int) { |
1130 return valueOf2(((leftValue as int)).compareTo((_value as int)) > 0); | 1272 return valueOf2(((leftValue as int)).compareTo((_value as int)) > 0); |
1131 } else if (_value is double) { | 1273 } else if (_value is double) { |
1132 return valueOf2(((leftValue as int)).toDouble() > ((_value as double))); | 1274 return valueOf2(((leftValue as int)).toDouble() > ((_value as double))); |
1133 } | 1275 } |
1134 } else if (leftValue is double) { | 1276 } else if (leftValue is double) { |
1135 if (_value is int) { | 1277 if (_value is int) { |
1136 return valueOf2(((leftValue as double)) > ((_value as int)).toDouble()); | 1278 return valueOf2(((leftValue as double)) > ((_value as int)).toDouble()); |
1137 } else if (_value is double) { | 1279 } else if (_value is double) { |
1138 return valueOf2(((leftValue as double)) > ((_value as double))); | 1280 return valueOf2(((leftValue as double)) > ((_value as double))); |
1139 } | 1281 } |
1140 } | 1282 } |
1141 return error(node); | 1283 return error(node); |
1142 } | 1284 } |
1143 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef
tOperand) => leftOperand; | 1285 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef
tOperand) => leftOperand; |
1144 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef
tOperand2) { | 1286 EvaluationResultImpl integerDivideValid(BinaryExpression node, ValidResult lef
tOperand2) { |
| 1287 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1288 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1289 return RESULT_INT; |
| 1290 } |
| 1291 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1292 } |
1145 Object leftValue = leftOperand2.value; | 1293 Object leftValue = leftOperand2.value; |
1146 if (leftValue == null) { | 1294 if (leftValue == null) { |
1147 return error(node.leftOperand); | 1295 return error(node.leftOperand); |
1148 } else if (_value == null) { | 1296 } else if (_value == null) { |
1149 return error(node.rightOperand); | 1297 return error(node.rightOperand); |
1150 } else if (leftValue is int) { | 1298 } else if (leftValue is int) { |
1151 if (_value is int) { | 1299 if (_value is int) { |
1152 if (((_value as int)) == 0) { | 1300 if (((_value as int)) == 0) { |
1153 return valueOf3(((leftValue as int)).toDouble() / ((_value as int)).to
Double()); | 1301 return valueOf3(((leftValue as int)).toDouble() / ((_value as int)).to
Double()); |
1154 } | 1302 } |
1155 return valueOf(((leftValue as int)) ~/ (_value as int)); | 1303 return valueOf(((leftValue as int)) ~/ (_value as int)); |
1156 } else if (_value is double) { | 1304 } else if (_value is double) { |
1157 double result = ((leftValue as int)).toDouble() / ((_value as double)); | 1305 double result = ((leftValue as int)).toDouble() / ((_value as double)); |
1158 return valueOf((result as int)); | 1306 return valueOf((result as int)); |
1159 } | 1307 } |
1160 } else if (leftValue is double) { | 1308 } else if (leftValue is double) { |
1161 if (_value is int) { | 1309 if (_value is int) { |
1162 double result = ((leftValue as double)) / ((_value as int)).toDouble(); | 1310 double result = ((leftValue as double)) / ((_value as int)).toDouble(); |
1163 return valueOf((result as int)); | 1311 return valueOf((result as int)); |
1164 } else if (_value is double) { | 1312 } else if (_value is double) { |
1165 double result = ((leftValue as double)) / ((_value as double)); | 1313 double result = ((leftValue as double)) / ((_value as double)); |
1166 return valueOf((result as int)); | 1314 return valueOf((result as int)); |
1167 } | 1315 } |
1168 } | 1316 } |
1169 return error(node); | 1317 return error(node); |
1170 } | 1318 } |
1171 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper
and) => leftOperand; | 1319 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper
and) => leftOperand; |
1172 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l
eftOperand) => leftOperand; | 1320 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l
eftOperand) => leftOperand; |
1173 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l
eftOperand2) { | 1321 EvaluationResultImpl lessThanOrEqualValid(BinaryExpression node, ValidResult l
eftOperand2) { |
| 1322 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1323 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1324 return RESULT_BOOL; |
| 1325 } |
| 1326 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1327 } |
1174 Object leftValue = leftOperand2.value; | 1328 Object leftValue = leftOperand2.value; |
1175 if (leftValue == null) { | 1329 if (leftValue == null) { |
1176 return error(node.leftOperand); | 1330 return error(node.leftOperand); |
1177 } else if (_value == null) { | 1331 } else if (_value == null) { |
1178 return error(node.rightOperand); | 1332 return error(node.rightOperand); |
1179 } else if (leftValue is int) { | 1333 } else if (leftValue is int) { |
1180 if (_value is int) { | 1334 if (_value is int) { |
1181 return valueOf2(((leftValue as int)).compareTo((_value as int)) <= 0); | 1335 return valueOf2(((leftValue as int)).compareTo((_value as int)) <= 0); |
1182 } else if (_value is double) { | 1336 } else if (_value is double) { |
1183 return valueOf2(((leftValue as int)).toDouble() <= ((_value as double)))
; | 1337 return valueOf2(((leftValue as int)).toDouble() <= ((_value as double)))
; |
1184 } | 1338 } |
1185 } else if (leftValue is double) { | 1339 } else if (leftValue is double) { |
1186 if (_value is int) { | 1340 if (_value is int) { |
1187 return valueOf2(((leftValue as double)) <= ((_value as int)).toDouble())
; | 1341 return valueOf2(((leftValue as double)) <= ((_value as int)).toDouble())
; |
1188 } else if (_value is double) { | 1342 } else if (_value is double) { |
1189 return valueOf2(((leftValue as double)) <= ((_value as double))); | 1343 return valueOf2(((leftValue as double)) <= ((_value as double))); |
1190 } | 1344 } |
1191 } | 1345 } |
1192 return error(node); | 1346 return error(node); |
1193 } | 1347 } |
1194 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper
and2) { | 1348 EvaluationResultImpl lessThanValid(BinaryExpression node, ValidResult leftOper
and2) { |
| 1349 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1350 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1351 return RESULT_BOOL; |
| 1352 } |
| 1353 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1354 } |
1195 Object leftValue = leftOperand2.value; | 1355 Object leftValue = leftOperand2.value; |
1196 if (leftValue == null) { | 1356 if (leftValue == null) { |
1197 return error(node.leftOperand); | 1357 return error(node.leftOperand); |
1198 } else if (_value == null) { | 1358 } else if (_value == null) { |
1199 return error(node.rightOperand); | 1359 return error(node.rightOperand); |
1200 } else if (leftValue is int) { | 1360 } else if (leftValue is int) { |
1201 if (_value is int) { | 1361 if (_value is int) { |
1202 return valueOf2(((leftValue as int)).compareTo((_value as int)) < 0); | 1362 return valueOf2(((leftValue as int)).compareTo((_value as int)) < 0); |
1203 } else if (_value is double) { | 1363 } else if (_value is double) { |
1204 return valueOf2(((leftValue as int)).toDouble() < ((_value as double))); | 1364 return valueOf2(((leftValue as int)).toDouble() < ((_value as double))); |
1205 } | 1365 } |
1206 } else if (leftValue is double) { | 1366 } else if (leftValue is double) { |
1207 if (_value is int) { | 1367 if (_value is int) { |
1208 return valueOf2(((leftValue as double)) < ((_value as int)).toDouble()); | 1368 return valueOf2(((leftValue as double)) < ((_value as int)).toDouble()); |
1209 } else if (_value is double) { | 1369 } else if (_value is double) { |
1210 return valueOf2(((leftValue as double)) < ((_value as double))); | 1370 return valueOf2(((leftValue as double)) < ((_value as double))); |
1211 } | 1371 } |
1212 } | 1372 } |
1213 return error(node); | 1373 return error(node); |
1214 } | 1374 } |
1215 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp
erand) => leftOperand; | 1375 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp
erand) => leftOperand; |
1216 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp
erand) { | 1376 EvaluationResultImpl logicalAndValid(BinaryExpression node, ValidResult leftOp
erand) { |
| 1377 if (isSomeBool() || leftOperand.isSomeBool()) { |
| 1378 if (isAnyBool() && leftOperand.isAnyBool()) { |
| 1379 return RESULT_BOOL; |
| 1380 } |
| 1381 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL); |
| 1382 } |
1217 Object leftValue = leftOperand.value; | 1383 Object leftValue = leftOperand.value; |
1218 if (leftValue is bool && ((leftValue as bool))) { | 1384 if (leftValue is bool) { |
1219 return booleanConversion(node.rightOperand, _value); | 1385 if (((leftValue as bool))) { |
| 1386 return booleanConversion(node.rightOperand, _value); |
| 1387 } |
| 1388 return RESULT_FALSE; |
1220 } | 1389 } |
1221 return RESULT_FALSE; | 1390 return error(node); |
1222 } | 1391 } |
1223 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe
rand) => leftOperand; | 1392 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe
rand) => leftOperand; |
1224 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe
rand) { | 1393 EvaluationResultImpl logicalOrValid(BinaryExpression node, ValidResult leftOpe
rand) { |
| 1394 if (isSomeBool() || leftOperand.isSomeBool()) { |
| 1395 if (isAnyBool() && leftOperand.isAnyBool()) { |
| 1396 return RESULT_BOOL; |
| 1397 } |
| 1398 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL); |
| 1399 } |
1225 Object leftValue = leftOperand.value; | 1400 Object leftValue = leftOperand.value; |
1226 if (leftValue is bool && ((leftValue as bool))) { | 1401 if (leftValue is bool && ((leftValue as bool))) { |
1227 return RESULT_TRUE; | 1402 return RESULT_TRUE; |
1228 } | 1403 } |
1229 return booleanConversion(node.rightOperand, _value); | 1404 return booleanConversion(node.rightOperand, _value); |
1230 } | 1405 } |
1231 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; | 1406 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; |
1232 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand
2) { | 1407 EvaluationResultImpl minusValid(BinaryExpression node, ValidResult leftOperand
2) { |
| 1408 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1409 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1410 return RESULT_NUM; |
| 1411 } |
| 1412 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1413 } |
1233 Object leftValue = leftOperand2.value; | 1414 Object leftValue = leftOperand2.value; |
1234 if (leftValue == null) { | 1415 if (leftValue == null) { |
1235 return error(node.leftOperand); | 1416 return error(node.leftOperand); |
1236 } else if (_value == null) { | 1417 } else if (_value == null) { |
1237 return error(node.rightOperand); | 1418 return error(node.rightOperand); |
1238 } else if (leftValue is int) { | 1419 } else if (leftValue is int) { |
1239 if (_value is int) { | 1420 if (_value is int) { |
1240 return valueOf(((leftValue as int)) - (_value as int)); | 1421 return valueOf(((leftValue as int)) - (_value as int)); |
1241 } else if (_value is double) { | 1422 } else if (_value is double) { |
1242 return valueOf3(((leftValue as int)).toDouble() - ((_value as double))); | 1423 return valueOf3(((leftValue as int)).toDouble() - ((_value as double))); |
1243 } | 1424 } |
1244 } else if (leftValue is double) { | 1425 } else if (leftValue is double) { |
1245 if (_value is int) { | 1426 if (_value is int) { |
1246 return valueOf3(((leftValue as double)) - ((_value as int)).toDouble()); | 1427 return valueOf3(((leftValue as double)) - ((_value as int)).toDouble()); |
1247 } else if (_value is double) { | 1428 } else if (_value is double) { |
1248 return valueOf3(((leftValue as double)) - ((_value as double))); | 1429 return valueOf3(((leftValue as double)) - ((_value as double))); |
1249 } | 1430 } |
1250 } | 1431 } |
1251 return error(node); | 1432 return error(node); |
1252 } | 1433 } |
1253 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper
and) => leftOperand; | 1434 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper
and) => leftOperand; |
1254 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper
and) { | 1435 EvaluationResultImpl notEqualValid(BinaryExpression node, ValidResult leftOper
and) { |
| 1436 if (!isAnyNullBoolNumString() || !leftOperand.isAnyNullBoolNumString()) { |
| 1437 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); |
| 1438 } |
1255 Object leftValue = leftOperand.value; | 1439 Object leftValue = leftOperand.value; |
1256 if (leftValue == null) { | 1440 if (leftValue == null) { |
1257 return valueOf2(_value != null); | 1441 return valueOf2(_value != null); |
1258 } else if (leftValue is bool) { | 1442 } else if (leftValue is bool) { |
1259 if (_value is bool) { | 1443 if (_value is bool) { |
1260 return valueOf2(((leftValue as bool)) != ((_value as bool))); | 1444 return valueOf2(((leftValue as bool)) != ((_value as bool))); |
1261 } | 1445 } |
1262 return RESULT_TRUE; | 1446 return RESULT_TRUE; |
1263 } else if (leftValue is int) { | 1447 } else if (leftValue is int) { |
1264 if (_value is int) { | 1448 if (_value is int) { |
(...skipping 12 matching lines...) Expand all Loading... |
1277 } else if (leftValue is String) { | 1461 } else if (leftValue is String) { |
1278 if (_value is String) { | 1462 if (_value is String) { |
1279 return valueOf2(((leftValue as String)) != _value); | 1463 return valueOf2(((leftValue as String)) != _value); |
1280 } | 1464 } |
1281 return RESULT_TRUE; | 1465 return RESULT_TRUE; |
1282 } | 1466 } |
1283 return RESULT_TRUE; | 1467 return RESULT_TRUE; |
1284 } | 1468 } |
1285 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe
rand) => leftOperand; | 1469 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe
rand) => leftOperand; |
1286 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe
rand2) { | 1470 EvaluationResultImpl remainderValid(BinaryExpression node, ValidResult leftOpe
rand2) { |
| 1471 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1472 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1473 return RESULT_NUM; |
| 1474 } |
| 1475 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1476 } |
1287 Object leftValue = leftOperand2.value; | 1477 Object leftValue = leftOperand2.value; |
1288 if (leftValue == null) { | 1478 if (leftValue == null) { |
1289 return error(node.leftOperand); | 1479 return error(node.leftOperand); |
1290 } else if (_value == null) { | 1480 } else if (_value == null) { |
1291 return error(node.rightOperand); | 1481 return error(node.rightOperand); |
1292 } else if (leftValue is int) { | 1482 } else if (leftValue is int) { |
1293 if (_value is int) { | 1483 if (_value is int) { |
1294 if (((_value as int)) == 0) { | 1484 if (((_value as int)) == 0) { |
1295 return valueOf3(((leftValue as int)).toDouble() % ((_value as int)).to
Double()); | 1485 return valueOf3(((leftValue as int)).toDouble() % ((_value as int)).to
Double()); |
1296 } | 1486 } |
1297 return valueOf(((leftValue as int)).remainder((_value as int))); | 1487 return valueOf(((leftValue as int)).remainder((_value as int))); |
1298 } else if (_value is double) { | 1488 } else if (_value is double) { |
1299 return valueOf3(((leftValue as int)).toDouble() % ((_value as double))); | 1489 return valueOf3(((leftValue as int)).toDouble() % ((_value as double))); |
1300 } | 1490 } |
1301 } else if (leftValue is double) { | 1491 } else if (leftValue is double) { |
1302 if (_value is int) { | 1492 if (_value is int) { |
1303 return valueOf3(((leftValue as double)) % ((_value as int)).toDouble()); | 1493 return valueOf3(((leftValue as double)) % ((_value as int)).toDouble()); |
1304 } else if (_value is double) { | 1494 } else if (_value is double) { |
1305 return valueOf3(((leftValue as double)) % ((_value as double))); | 1495 return valueOf3(((leftValue as double)) % ((_value as double))); |
1306 } | 1496 } |
1307 } | 1497 } |
1308 return error(node); | 1498 return error(node); |
1309 } | 1499 } |
1310 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe
rand) => leftOperand; | 1500 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe
rand) => leftOperand; |
1311 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe
rand2) { | 1501 EvaluationResultImpl shiftLeftValid(BinaryExpression node, ValidResult leftOpe
rand2) { |
| 1502 if (isSomeInt() || leftOperand2.isSomeInt()) { |
| 1503 if (isAnyInt() && leftOperand2.isAnyInt()) { |
| 1504 return RESULT_INT; |
| 1505 } |
| 1506 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); |
| 1507 } |
1312 Object leftValue = leftOperand2.value; | 1508 Object leftValue = leftOperand2.value; |
1313 if (leftValue == null) { | 1509 if (leftValue == null) { |
1314 return error(node.leftOperand); | 1510 return error(node.leftOperand); |
1315 } else if (_value == null) { | 1511 } else if (_value == null) { |
1316 return error(node.rightOperand); | 1512 return error(node.rightOperand); |
1317 } else if (leftValue is int) { | 1513 } else if (leftValue is int) { |
1318 if (_value is int) { | 1514 if (_value is int) { |
1319 return valueOf(((leftValue as int)) << ((_value as int))); | 1515 return valueOf(((leftValue as int)) << ((_value as int))); |
1320 } | 1516 } |
1321 return error(node.rightOperand); | 1517 return error(node.rightOperand); |
1322 } | 1518 } |
1323 if (_value is int) { | 1519 if (_value is int) { |
1324 return error(node.leftOperand); | 1520 return error(node.leftOperand); |
1325 } | 1521 } |
1326 return union(error(node.leftOperand), error(node.rightOperand)); | 1522 return union(error(node.leftOperand), error(node.rightOperand)); |
1327 } | 1523 } |
1328 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp
erand) => leftOperand; | 1524 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp
erand) => leftOperand; |
1329 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp
erand2) { | 1525 EvaluationResultImpl shiftRightValid(BinaryExpression node, ValidResult leftOp
erand2) { |
| 1526 if (isSomeInt() || leftOperand2.isSomeInt()) { |
| 1527 if (isAnyInt() && leftOperand2.isAnyInt()) { |
| 1528 return RESULT_INT; |
| 1529 } |
| 1530 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_INT); |
| 1531 } |
1330 Object leftValue = leftOperand2.value; | 1532 Object leftValue = leftOperand2.value; |
1331 if (leftValue == null) { | 1533 if (leftValue == null) { |
1332 return error(node.leftOperand); | 1534 return error(node.leftOperand); |
1333 } else if (_value == null) { | 1535 } else if (_value == null) { |
1334 return error(node.rightOperand); | 1536 return error(node.rightOperand); |
1335 } else if (leftValue is int) { | 1537 } else if (leftValue is int) { |
1336 if (_value is int) { | 1538 if (_value is int) { |
1337 return valueOf(((leftValue as int)) >> ((_value as int))); | 1539 return valueOf(((leftValue as int)) >> ((_value as int))); |
1338 } | 1540 } |
1339 return error(node.rightOperand); | 1541 return error(node.rightOperand); |
1340 } | 1542 } |
1341 if (_value is int) { | 1543 if (_value is int) { |
1342 return error(node.leftOperand); | 1544 return error(node.leftOperand); |
1343 } | 1545 } |
1344 return union(error(node.leftOperand), error(node.rightOperand)); | 1546 return union(error(node.leftOperand), error(node.rightOperand)); |
1345 } | 1547 } |
1346 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; | 1548 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand
) => leftOperand; |
1347 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand
2) { | 1549 EvaluationResultImpl timesValid(BinaryExpression node, ValidResult leftOperand
2) { |
| 1550 if (isSomeNum() || leftOperand2.isSomeNum()) { |
| 1551 if (isAnyNum() && leftOperand2.isAnyNum()) { |
| 1552 return RESULT_NUM; |
| 1553 } |
| 1554 return error2(node, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM); |
| 1555 } |
1348 Object leftValue = leftOperand2.value; | 1556 Object leftValue = leftOperand2.value; |
1349 if (leftValue == null) { | 1557 if (leftValue == null) { |
1350 return error(node.leftOperand); | 1558 return error(node.leftOperand); |
1351 } else if (_value == null) { | 1559 } else if (_value == null) { |
1352 return error(node.rightOperand); | 1560 return error(node.rightOperand); |
1353 } else if (leftValue is int) { | 1561 } else if (leftValue is int) { |
1354 if (_value is int) { | 1562 if (_value is int) { |
1355 return valueOf(((leftValue as int)) * (_value as int)); | 1563 return valueOf(((leftValue as int)) * (_value as int)); |
1356 } else if (_value is double) { | 1564 } else if (_value is double) { |
1357 return valueOf3(((leftValue as int)).toDouble() * ((_value as double))); | 1565 return valueOf3(((leftValue as int)).toDouble() * ((_value as double))); |
1358 } | 1566 } |
1359 } else if (leftValue is double) { | 1567 } else if (leftValue is double) { |
1360 if (_value is int) { | 1568 if (_value is int) { |
1361 return valueOf3(((leftValue as double)) * ((_value as int)).toDouble()); | 1569 return valueOf3(((leftValue as double)) * ((_value as int)).toDouble()); |
1362 } else if (_value is double) { | 1570 } else if (_value is double) { |
1363 return valueOf3(((leftValue as double)) * ((_value as double))); | 1571 return valueOf3(((leftValue as double)) * ((_value as double))); |
1364 } | 1572 } |
1365 } | 1573 } |
1366 return error(node); | 1574 return error(node); |
1367 } | 1575 } |
| 1576 bool isNull() => identical(this, RESULT_NULL); |
| 1577 |
1368 /** | 1578 /** |
1369 * Return the result of applying boolean conversion to the given value. | 1579 * Return the result of applying boolean conversion to the given value. |
1370 * @param node the node against which errors should be reported | 1580 * @param node the node against which errors should be reported |
1371 * @param value the value to be converted to a boolean | 1581 * @param value the value to be converted to a boolean |
1372 * @return the result of applying boolean conversion to the given value | 1582 * @return the result of applying boolean conversion to the given value |
1373 */ | 1583 */ |
1374 EvaluationResultImpl booleanConversion(ASTNode node, Object value) { | 1584 EvaluationResultImpl booleanConversion(ASTNode node, Object value) { |
1375 if (value == null) { | 1585 if (value is bool) { |
1376 return error(node); | 1586 if (((value as bool))) { |
1377 } else if (value is bool && ((value as bool))) { | 1587 return RESULT_TRUE; |
1378 return RESULT_TRUE; | 1588 } else { |
| 1589 return RESULT_FALSE; |
| 1590 } |
1379 } | 1591 } |
1380 return RESULT_FALSE; | 1592 return error(node); |
1381 } | 1593 } |
1382 ErrorResult error(ASTNode node) => error2(node, CompileTimeErrorCode.INVALID_C
ONSTANT); | 1594 ErrorResult error(ASTNode node) => error2(node, CompileTimeErrorCode.INVALID_C
ONSTANT); |
| 1595 |
1383 /** | 1596 /** |
1384 * Return a result object representing an error associated with the given node
. | 1597 * Return a result object representing an error associated with the given node
. |
1385 * @param node the AST node associated with the error | 1598 * @param node the AST node associated with the error |
1386 * @param code the error code indicating the nature of the error | 1599 * @param code the error code indicating the nature of the error |
1387 * @return a result object representing an error associated with the given nod
e | 1600 * @return a result object representing an error associated with the given nod
e |
1388 */ | 1601 */ |
1389 ErrorResult error2(ASTNode node, ErrorCode code) => new ErrorResult.con1(node,
code); | 1602 ErrorResult error2(ASTNode node, ErrorCode code) => new ErrorResult.con1(node,
code); |
| 1603 |
| 1604 /** |
| 1605 * Checks if this result has type "bool", with known or unknown value. |
| 1606 */ |
| 1607 bool isAnyBool() => isSomeBool() || identical(this, RESULT_TRUE) || identical(
this, RESULT_FALSE); |
| 1608 |
| 1609 /** |
| 1610 * Checks if this result has type "int", with known or unknown value. |
| 1611 */ |
| 1612 bool isAnyInt() => identical(this, RESULT_INT) || _value is int; |
| 1613 |
| 1614 /** |
| 1615 * Checks if this result has one of the types - "bool", "num" or "string"; or
may be {@code null}. |
| 1616 */ |
| 1617 bool isAnyNullBoolNumString() => isNull() || isAnyBool() || isAnyNum() || _val
ue is String; |
| 1618 |
| 1619 /** |
| 1620 * Checks if this result has type "num", with known or unknown value. |
| 1621 */ |
| 1622 bool isAnyNum() => isSomeNum() || _value is num; |
| 1623 |
| 1624 /** |
| 1625 * Checks if this result has type "bool", exact value of which we don't know. |
| 1626 */ |
| 1627 bool isSomeBool() => identical(this, RESULT_BOOL); |
| 1628 |
| 1629 /** |
| 1630 * Checks if this result has type "int", exact value of which we don't know. |
| 1631 */ |
| 1632 bool isSomeInt() => identical(this, RESULT_INT); |
| 1633 |
| 1634 /** |
| 1635 * Checks if this result has type "num" (or "int"), exact value of which we do
n't know. |
| 1636 */ |
| 1637 bool isSomeNum() => identical(this, RESULT_DYNAMIC) || identical(this, RESULT_
INT) || identical(this, RESULT_NUM); |
1390 double toDouble(int value) => value.toDouble(); | 1638 double toDouble(int value) => value.toDouble(); |
| 1639 |
1391 /** | 1640 /** |
1392 * Return an error result that is the union of the two given error results. | 1641 * Return an error result that is the union of the two given error results. |
1393 * @param firstError the first error to be combined | 1642 * @param firstError the first error to be combined |
1394 * @param secondError the second error to be combined | 1643 * @param secondError the second error to be combined |
1395 * @return an error result that is the union of the two given error results | 1644 * @return an error result that is the union of the two given error results |
1396 */ | 1645 */ |
1397 ErrorResult union(ErrorResult firstError, ErrorResult secondError) => new Erro
rResult.con2(firstError, secondError); | 1646 ErrorResult union(ErrorResult firstError, ErrorResult secondError) => new Erro
rResult.con2(firstError, secondError); |
| 1647 |
1398 /** | 1648 /** |
1399 * Return a result object representing the given value. | 1649 * Return a result object representing the given value. |
1400 * @param value the value to be represented as a result object | 1650 * @param value the value to be represented as a result object |
1401 * @return a result object representing the given value | 1651 * @return a result object representing the given value |
1402 */ | 1652 */ |
1403 ValidResult valueOf(int value) => new ValidResult(value); | 1653 ValidResult valueOf(int value) => new ValidResult(value); |
| 1654 |
1404 /** | 1655 /** |
1405 * Return a result object representing the given value. | 1656 * Return a result object representing the given value. |
1406 * @param value the value to be represented as a result object | 1657 * @param value the value to be represented as a result object |
1407 * @return a result object representing the given value | 1658 * @return a result object representing the given value |
1408 */ | 1659 */ |
1409 ValidResult valueOf2(bool value) => value ? RESULT_TRUE : RESULT_FALSE; | 1660 ValidResult valueOf2(bool value) => value ? RESULT_TRUE : RESULT_FALSE; |
| 1661 |
1410 /** | 1662 /** |
1411 * Return a result object representing the given value. | 1663 * Return a result object representing the given value. |
1412 * @param value the value to be represented as a result object | 1664 * @param value the value to be represented as a result object |
1413 * @return a result object representing the given value | 1665 * @return a result object representing the given value |
1414 */ | 1666 */ |
1415 ValidResult valueOf3(double value) => new ValidResult(value); | 1667 ValidResult valueOf3(double value) => new ValidResult(value); |
| 1668 |
1416 /** | 1669 /** |
1417 * Return a result object representing the given value. | 1670 * Return a result object representing the given value. |
1418 * @param value the value to be represented as a result object | 1671 * @param value the value to be represented as a result object |
1419 * @return a result object representing the given value | 1672 * @return a result object representing the given value |
1420 */ | 1673 */ |
1421 ValidResult valueOf4(String value) => new ValidResult(value); | 1674 ValidResult valueOf4(String value) => new ValidResult(value); |
1422 } | 1675 } |
OLD | NEW |