|
25 | 25 | import org.elasticsearch.painless.ir.ClassNode;
|
26 | 26 | import org.elasticsearch.painless.ir.ExpressionNode;
|
27 | 27 | import org.elasticsearch.painless.lookup.PainlessCast;
|
28 |
| -import org.elasticsearch.painless.lookup.PainlessLookupUtility; |
29 | 28 | import org.elasticsearch.painless.symbol.ScriptRoot;
|
30 | 29 |
|
31 | 30 | import java.util.Objects;
|
@@ -84,14 +83,6 @@ public abstract class AExpression extends ANode {
|
84 | 83 | */
|
85 | 84 | boolean internal = false;
|
86 | 85 |
|
87 |
| - /** |
88 |
| - * Set to the value of the constant this expression node represents if |
89 |
| - * and only if the node represents a constant. If this is not null |
90 |
| - * this node will be replaced by an {@link EConstant} during casting |
91 |
| - * if it's not already one. |
92 |
| - */ |
93 |
| - Object constant = null; |
94 |
| - |
95 | 86 | /**
|
96 | 87 | * Set to true by {@link ENull} to represent a null value.
|
97 | 88 | */
|
@@ -134,97 +125,14 @@ AExpression cast(ScriptRoot scriptRoot, Scope scope) {
|
134 | 125 | PainlessCast cast = AnalyzerCaster.getLegalCast(location, actual, expected, explicit, internal);
|
135 | 126 |
|
136 | 127 | if (cast == null) {
|
137 |
| - if (constant == null || this instanceof EConstant) { |
138 |
| - // For the case where a cast is not required and a constant is not set |
139 |
| - // or the node is already an EConstant no changes are required to the tree. |
140 |
| - |
141 |
| - return this; |
142 |
| - } else { |
143 |
| - // For the case where a cast is not required but a |
144 |
| - // constant is set, an EConstant replaces this node |
145 |
| - // with the constant copied from this node. Note that |
146 |
| - // for constants output data does not need to be copied |
147 |
| - // from this node because the output data for the EConstant |
148 |
| - // will already be the same. |
149 |
| - |
150 |
| - EConstant econstant = new EConstant(location, constant); |
151 |
| - econstant.analyze(scriptRoot, scope); |
152 |
| - |
153 |
| - if (!expected.equals(econstant.actual)) { |
154 |
| - throw createError(new IllegalStateException("Illegal tree structure.")); |
155 |
| - } |
156 |
| - |
157 |
| - return econstant; |
158 |
| - } |
| 128 | + return this; |
159 | 129 | } else {
|
160 |
| - if (constant == null) { |
161 |
| - // For the case where a cast is required and a constant is not set. |
162 |
| - // Modify the tree to add an ECast between this node and its parent. |
163 |
| - // The output data from this node is copied to the ECast for |
164 |
| - // further reads done by the parent. |
165 |
| - |
166 |
| - ECast ecast = new ECast(location, this, cast); |
167 |
| - ecast.statement = statement; |
168 |
| - ecast.actual = expected; |
169 |
| - ecast.isNull = isNull; |
170 |
| - |
171 |
| - return ecast; |
172 |
| - } else { |
173 |
| - if (PainlessLookupUtility.isConstantType(expected)) { |
174 |
| - // For the case where a cast is required, a constant is set, |
175 |
| - // and the constant can be immediately cast to the expected type. |
176 |
| - // An EConstant replaces this node with the constant cast appropriately |
177 |
| - // from the constant value defined by this node. Note that |
178 |
| - // for constants output data does not need to be copied |
179 |
| - // from this node because the output data for the EConstant |
180 |
| - // will already be the same. |
181 |
| - |
182 |
| - constant = AnalyzerCaster.constCast(location, constant, cast); |
183 |
| - |
184 |
| - EConstant econstant = new EConstant(location, constant); |
185 |
| - econstant.analyze(scriptRoot, scope); |
186 |
| - |
187 |
| - if (!expected.equals(econstant.actual)) { |
188 |
| - throw createError(new IllegalStateException("Illegal tree structure.")); |
189 |
| - } |
190 |
| - |
191 |
| - return econstant; |
192 |
| - } else if (this instanceof EConstant) { |
193 |
| - // For the case where a cast is required, a constant is set, |
194 |
| - // the constant cannot be immediately cast to the expected type, |
195 |
| - // and this node is already an EConstant. Modify the tree to add |
196 |
| - // an ECast between this node and its parent. Note that |
197 |
| - // for constants output data does not need to be copied |
198 |
| - // from this node because the output data for the EConstant |
199 |
| - // will already be the same. |
200 |
| - |
201 |
| - ECast ecast = new ECast(location, this, cast); |
202 |
| - ecast.actual = expected; |
203 |
| - |
204 |
| - return ecast; |
205 |
| - } else { |
206 |
| - // For the case where a cast is required, a constant is set, |
207 |
| - // the constant cannot be immediately cast to the expected type, |
208 |
| - // and this node is not an EConstant. Replace this node with |
209 |
| - // an Econstant node copying the constant from this node. |
210 |
| - // Modify the tree to add an ECast between the EConstant node |
211 |
| - // and its parent. Note that for constants output data does not |
212 |
| - // need to be copied from this node because the output data for |
213 |
| - // the EConstant will already be the same. |
214 |
| - |
215 |
| - EConstant econstant = new EConstant(location, constant); |
216 |
| - econstant.analyze(scriptRoot, scope); |
217 |
| - |
218 |
| - if (!actual.equals(econstant.actual)) { |
219 |
| - throw createError(new IllegalStateException("Illegal tree structure.")); |
220 |
| - } |
221 |
| - |
222 |
| - ECast ecast = new ECast(location, econstant, cast); |
223 |
| - ecast.actual = expected; |
224 |
| - |
225 |
| - return ecast; |
226 |
| - } |
227 |
| - } |
| 130 | + ECast ecast = new ECast(location, this, cast); |
| 131 | + ecast.statement = statement; |
| 132 | + ecast.actual = expected; |
| 133 | + ecast.isNull = isNull; |
| 134 | + |
| 135 | + return ecast; |
228 | 136 | }
|
229 | 137 | }
|
230 | 138 | }
|
0 commit comments