author | hannesw |
Fri, 25 Oct 2013 10:20:49 +0200 | |
changeset 21457 | 381acbd07fe5 |
parent 20933 | 89748612fd1d |
child 24719 | f726e9d67629 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.ir; |
|
27 |
||
28 |
import java.util.Arrays; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.List; |
|
20928
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
31 |
|
16147 | 32 |
import jdk.nashorn.internal.codegen.CompileUnit; |
20928
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
33 |
import jdk.nashorn.internal.codegen.types.ArrayType; |
16147 | 34 |
import jdk.nashorn.internal.codegen.types.Type; |
17233 | 35 |
import jdk.nashorn.internal.ir.annotations.Immutable; |
16147 | 36 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
20928
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
37 |
import jdk.nashorn.internal.objects.NativeArray; |
16147 | 38 |
import jdk.nashorn.internal.parser.Lexer.LexerToken; |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
39 |
import jdk.nashorn.internal.parser.Token; |
16147 | 40 |
import jdk.nashorn.internal.parser.TokenType; |
41 |
import jdk.nashorn.internal.runtime.JSType; |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
42 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
16147 | 43 |
import jdk.nashorn.internal.runtime.Undefined; |
44 |
||
45 |
/** |
|
46 |
* Literal nodes represent JavaScript values. |
|
47 |
* |
|
48 |
* @param <T> the literal type |
|
49 |
*/ |
|
17233 | 50 |
@Immutable |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
51 |
public abstract class LiteralNode<T> extends Expression implements PropertyKey { |
16147 | 52 |
/** Literal value */ |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
53 |
protected final T value; |
16147 | 54 |
|
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
55 |
/** Marker for values that must be computed at runtime */ |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
56 |
public static final Object POSTSET_MARKER = new Object(); |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
57 |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
58 |
/** |
16147 | 59 |
* Constructor |
60 |
* |
|
61 |
* @param token token |
|
62 |
* @param finish finish |
|
63 |
* @param value the value of the literal |
|
64 |
*/ |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
65 |
protected LiteralNode(final long token, final int finish, final T value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
66 |
super(token, finish); |
16147 | 67 |
this.value = value; |
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Copy constructor |
|
72 |
* |
|
73 |
* @param literalNode source node |
|
74 |
*/ |
|
75 |
protected LiteralNode(final LiteralNode<T> literalNode) { |
|
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
76 |
this(literalNode, literalNode.value); |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
77 |
} |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
78 |
|
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
79 |
/** |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
80 |
* A copy constructor with value change. |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
81 |
* @param literalNode the original literal node |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
82 |
* @param newValue new value for this node |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
83 |
*/ |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
84 |
protected LiteralNode(final LiteralNode<T> literalNode, final T newValue) { |
16147 | 85 |
super(literalNode); |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
86 |
this.value = newValue; |
16147 | 87 |
} |
88 |
||
89 |
@Override |
|
90 |
public boolean isAtom() { |
|
91 |
return true; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Check if the literal value is null |
|
96 |
* @return true if literal value is null |
|
97 |
*/ |
|
98 |
public boolean isNull() { |
|
99 |
return value == null; |
|
100 |
} |
|
101 |
||
102 |
@Override |
|
103 |
public Type getType() { |
|
104 |
return Type.typeFor(value.getClass()); |
|
105 |
} |
|
106 |
||
107 |
@Override |
|
108 |
public String getPropertyName() { |
|
109 |
return JSType.toString(getObject()); |
|
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Fetch boolean value of node. |
|
114 |
* |
|
115 |
* @return boolean value of node. |
|
116 |
*/ |
|
117 |
public boolean getBoolean() { |
|
118 |
return JSType.toBoolean(value); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Fetch int32 value of node. |
|
123 |
* |
|
124 |
* @return Int32 value of node. |
|
125 |
*/ |
|
126 |
public int getInt32() { |
|
127 |
return JSType.toInt32(value); |
|
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* Fetch uint32 value of node. |
|
132 |
* |
|
133 |
* @return uint32 value of node. |
|
134 |
*/ |
|
135 |
public long getUint32() { |
|
136 |
return JSType.toUint32(value); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Fetch long value of node |
|
141 |
* |
|
142 |
* @return long value of node |
|
143 |
*/ |
|
144 |
public long getLong() { |
|
145 |
return JSType.toLong(value); |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Fetch double value of node. |
|
150 |
* |
|
151 |
* @return double value of node. |
|
152 |
*/ |
|
153 |
public double getNumber() { |
|
154 |
return JSType.toNumber(value); |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Get the array value of the node |
|
159 |
* |
|
160 |
* @return the array value |
|
161 |
*/ |
|
162 |
public Node[] getArray() { |
|
163 |
assert false : "not an array node"; |
|
164 |
return null; |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Fetch String value of node. |
|
169 |
* |
|
170 |
* @return String value of node. |
|
171 |
*/ |
|
172 |
public String getString() { |
|
173 |
return JSType.toString(value); |
|
174 |
} |
|
175 |
||
176 |
/** |
|
177 |
* Fetch Object value of node. |
|
178 |
* |
|
179 |
* @return Object value of node. |
|
180 |
*/ |
|
181 |
public Object getObject() { |
|
182 |
return value; |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Test if the value is a string. |
|
187 |
* |
|
188 |
* @return True if value is a string. |
|
189 |
*/ |
|
190 |
public boolean isString() { |
|
191 |
return value instanceof String; |
|
192 |
} |
|
193 |
||
194 |
/** |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
195 |
* Test if tha value is a number |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
196 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
197 |
* @return True if value is a number |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
198 |
*/ |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
199 |
public boolean isNumeric() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
200 |
return value instanceof Number; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
201 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
202 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
203 |
/** |
16147 | 204 |
* Assist in IR navigation. |
205 |
* |
|
206 |
* @param visitor IR navigating visitor. |
|
207 |
*/ |
|
208 |
@Override |
|
17769
14ea7feaf658
8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
17523
diff
changeset
|
209 |
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
17233 | 210 |
if (visitor.enterLiteralNode(this)) { |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
211 |
return visitor.leaveLiteralNode(this); |
16147 | 212 |
} |
213 |
||
214 |
return this; |
|
215 |
} |
|
216 |
||
217 |
@Override |
|
218 |
public void toString(final StringBuilder sb) { |
|
219 |
if (value == null) { |
|
220 |
sb.append("null"); |
|
221 |
} else { |
|
222 |
sb.append(value.toString()); |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
/** |
|
227 |
* Get the literal node value |
|
228 |
* @return the value |
|
229 |
*/ |
|
230 |
public T getValue() { |
|
231 |
return value; |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Create a new null literal |
|
236 |
* |
|
237 |
* @param token token |
|
238 |
* @param finish finish |
|
239 |
* |
|
240 |
* @return the new literal node |
|
241 |
*/ |
|
17967
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
242 |
public static LiteralNode<Object> newInstance(final long token, final int finish) { |
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
243 |
return new NullLiteralNode(token, finish); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
244 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
245 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
246 |
/** |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
247 |
* Create a new null literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
248 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
249 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
250 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
251 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
252 |
*/ |
17967
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
253 |
public static LiteralNode<Object> newInstance(final Node parent) { |
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
254 |
return new NullLiteralNode(parent.getToken(), parent.getFinish()); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
255 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
256 |
|
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
257 |
/** |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
258 |
* Super class for primitive (side-effect free) literals. |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
259 |
* |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
260 |
* @param <T> the literal type |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
261 |
*/ |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
262 |
public static class PrimitiveLiteralNode<T> extends LiteralNode<T> { |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
263 |
private PrimitiveLiteralNode(final long token, final int finish, final T value) { |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
264 |
super(token, finish, value); |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
265 |
} |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
266 |
|
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
267 |
private PrimitiveLiteralNode(final PrimitiveLiteralNode<T> literalNode) { |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
268 |
super(literalNode); |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
269 |
} |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
270 |
|
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
271 |
/** |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
272 |
* Check if the literal value is boolean true |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
273 |
* @return true if literal value is boolean true |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
274 |
*/ |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
275 |
public boolean isTrue() { |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
276 |
return JSType.toBoolean(value); |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
277 |
} |
21457
381acbd07fe5
8027042: Evaluation order for binary operators can be improved
hannesw
parents:
20933
diff
changeset
|
278 |
|
381acbd07fe5
8027042: Evaluation order for binary operators can be improved
hannesw
parents:
20933
diff
changeset
|
279 |
@Override |
381acbd07fe5
8027042: Evaluation order for binary operators can be improved
hannesw
parents:
20933
diff
changeset
|
280 |
public boolean isLocal() { |
381acbd07fe5
8027042: Evaluation order for binary operators can be improved
hannesw
parents:
20933
diff
changeset
|
281 |
return true; |
381acbd07fe5
8027042: Evaluation order for binary operators can be improved
hannesw
parents:
20933
diff
changeset
|
282 |
} |
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
283 |
} |
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
284 |
|
17233 | 285 |
@Immutable |
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
286 |
private static final class BooleanLiteralNode extends PrimitiveLiteralNode<Boolean> { |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
287 |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
288 |
private BooleanLiteralNode(final long token, final int finish, final boolean value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
289 |
super(Token.recast(token, value ? TokenType.TRUE : TokenType.FALSE), finish, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
290 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
291 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
292 |
private BooleanLiteralNode(final BooleanLiteralNode literalNode) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
293 |
super(literalNode); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
294 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
295 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
296 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
297 |
public boolean isTrue() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
298 |
return value; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
299 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
300 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
301 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
302 |
public Type getType() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
303 |
return Type.BOOLEAN; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
304 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
305 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
306 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
307 |
public Type getWidestOperationType() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
308 |
return Type.BOOLEAN; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
309 |
} |
16147 | 310 |
} |
311 |
||
312 |
/** |
|
313 |
* Create a new boolean literal |
|
314 |
* |
|
315 |
* @param token token |
|
316 |
* @param finish finish |
|
317 |
* @param value true or false |
|
318 |
* |
|
319 |
* @return the new literal node |
|
320 |
*/ |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
321 |
public static LiteralNode<Boolean> newInstance(final long token, final int finish, final boolean value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
322 |
return new BooleanLiteralNode(token, finish, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
323 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
324 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
325 |
/** |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
326 |
* Create a new boolean literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
327 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
328 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
329 |
* @param value true or false |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
330 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
331 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
332 |
*/ |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
333 |
public static LiteralNode<?> newInstance(final Node parent, final boolean value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
334 |
return new BooleanLiteralNode(parent.getToken(), parent.getFinish(), value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
335 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
336 |
|
17233 | 337 |
@Immutable |
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
338 |
private static final class NumberLiteralNode extends PrimitiveLiteralNode<Number> { |
16147 | 339 |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
340 |
private final Type type = numberGetType(value); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
341 |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
342 |
private NumberLiteralNode(final long token, final int finish, final Number value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
343 |
super(Token.recast(token, TokenType.DECIMAL), finish, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
344 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
345 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
346 |
private NumberLiteralNode(final NumberLiteralNode literalNode) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
347 |
super(literalNode); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
348 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
349 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
350 |
private static Type numberGetType(final Number number) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
351 |
if (number instanceof Integer) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
352 |
return Type.INT; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
353 |
} else if (number instanceof Long) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
354 |
return Type.LONG; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
355 |
} else if (number instanceof Double) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
356 |
return Type.NUMBER; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
357 |
} else { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
358 |
assert false; |
16147 | 359 |
} |
360 |
||
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
361 |
return null; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
362 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
363 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
364 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
365 |
public Type getType() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
366 |
return type; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
367 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
368 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
369 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
370 |
public Type getWidestOperationType() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
371 |
return getType(); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
372 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
373 |
|
16147 | 374 |
} |
375 |
/** |
|
376 |
* Create a new number literal |
|
377 |
* |
|
378 |
* @param token token |
|
379 |
* @param finish finish |
|
380 |
* @param value literal value |
|
381 |
* |
|
382 |
* @return the new literal node |
|
383 |
*/ |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
384 |
public static LiteralNode<Number> newInstance(final long token, final int finish, final Number value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
385 |
return new NumberLiteralNode(token, finish, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
386 |
} |
16147 | 387 |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
388 |
/** |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
389 |
* Create a new number literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
390 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
391 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
392 |
* @param value literal value |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
393 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
394 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
395 |
*/ |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
396 |
public static LiteralNode<?> newInstance(final Node parent, final Number value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
397 |
return new NumberLiteralNode(parent.getToken(), parent.getFinish(), value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
398 |
} |
16147 | 399 |
|
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
400 |
private static class UndefinedLiteralNode extends PrimitiveLiteralNode<Undefined> { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
401 |
private UndefinedLiteralNode(final long token, final int finish) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
402 |
super(Token.recast(token, TokenType.OBJECT), finish, ScriptRuntime.UNDEFINED); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
403 |
} |
16147 | 404 |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
405 |
private UndefinedLiteralNode(final UndefinedLiteralNode literalNode) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
406 |
super(literalNode); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
407 |
} |
16147 | 408 |
} |
409 |
||
410 |
/** |
|
411 |
* Create a new undefined literal |
|
412 |
* |
|
413 |
* @param token token |
|
414 |
* @param finish finish |
|
415 |
* @param value undefined value, passed only for polymorphisism discrimination |
|
416 |
* |
|
417 |
* @return the new literal node |
|
418 |
*/ |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
419 |
public static LiteralNode<Undefined> newInstance(final long token, final int finish, final Undefined value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
420 |
return new UndefinedLiteralNode(token, finish); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
421 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
422 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
423 |
/** |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
424 |
* Create a new null literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
425 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
426 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
427 |
* @param value undefined value |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
428 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
429 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
430 |
*/ |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
431 |
public static LiteralNode<?> newInstance(final Node parent, final Undefined value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
432 |
return new UndefinedLiteralNode(parent.getToken(), parent.getFinish()); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
433 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
434 |
|
17233 | 435 |
@Immutable |
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
436 |
private static class StringLiteralNode extends PrimitiveLiteralNode<String> { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
437 |
private StringLiteralNode(final long token, final int finish, final String value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
438 |
super(Token.recast(token, TokenType.STRING), finish, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
439 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
440 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
441 |
private StringLiteralNode(final StringLiteralNode literalNode) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
442 |
super(literalNode); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
443 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
444 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
445 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
446 |
public void toString(final StringBuilder sb) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
447 |
sb.append('\"'); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
448 |
sb.append(value); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
449 |
sb.append('\"'); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
450 |
} |
16147 | 451 |
} |
452 |
||
453 |
/** |
|
454 |
* Create a new string literal |
|
455 |
* |
|
456 |
* @param token token |
|
457 |
* @param finish finish |
|
458 |
* @param value string value |
|
459 |
* |
|
460 |
* @return the new literal node |
|
461 |
*/ |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
462 |
public static LiteralNode<String> newInstance(final long token, final int finish, final String value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
463 |
return new StringLiteralNode(token, finish, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
464 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
465 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
466 |
/** |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
467 |
* Create a new String literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
468 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
469 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
470 |
* @param value string value |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
471 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
472 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
473 |
*/ |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
474 |
public static LiteralNode<?> newInstance(final Node parent, final String value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
475 |
return new StringLiteralNode(parent.getToken(), parent.getFinish(), value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
476 |
} |
16147 | 477 |
|
17233 | 478 |
@Immutable |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
479 |
private static class LexerTokenLiteralNode extends LiteralNode<LexerToken> { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
480 |
private LexerTokenLiteralNode(final long token, final int finish, final LexerToken value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
481 |
super(Token.recast(token, TokenType.STRING), finish, value); //TODO is string the correct token type here? |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
482 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
483 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
484 |
private LexerTokenLiteralNode(final LexerTokenLiteralNode literalNode) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
485 |
super(literalNode); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
486 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
487 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
488 |
@Override |
16215
92f00bfd6059
8007523: VerifyError on script that uses regular expression literals with ternary operator
sundar
parents:
16201
diff
changeset
|
489 |
public Type getType() { |
92f00bfd6059
8007523: VerifyError on script that uses regular expression literals with ternary operator
sundar
parents:
16201
diff
changeset
|
490 |
return Type.OBJECT; |
92f00bfd6059
8007523: VerifyError on script that uses regular expression literals with ternary operator
sundar
parents:
16201
diff
changeset
|
491 |
} |
92f00bfd6059
8007523: VerifyError on script that uses regular expression literals with ternary operator
sundar
parents:
16201
diff
changeset
|
492 |
|
92f00bfd6059
8007523: VerifyError on script that uses regular expression literals with ternary operator
sundar
parents:
16201
diff
changeset
|
493 |
@Override |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
494 |
public void toString(final StringBuilder sb) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
495 |
sb.append(value.toString()); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
496 |
} |
16147 | 497 |
} |
498 |
||
499 |
/** |
|
500 |
* Create a new literal node for a lexer token |
|
501 |
* |
|
502 |
* @param token token |
|
503 |
* @param finish finish |
|
504 |
* @param value lexer token value |
|
505 |
* |
|
506 |
* @return the new literal node |
|
507 |
*/ |
|
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
508 |
public static LiteralNode<LexerToken> newInstance(final long token, final int finish, final LexerToken value) { |
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
509 |
return new LexerTokenLiteralNode(token, finish, value); |
16147 | 510 |
} |
511 |
||
512 |
/** |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
513 |
* Create a new lexer token literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
514 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
515 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
516 |
* @param value lexer token |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
517 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
518 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
519 |
*/ |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
520 |
public static LiteralNode<?> newInstance(final Node parent, final LexerToken value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
521 |
return new LexerTokenLiteralNode(parent.getToken(), parent.getFinish(), value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
522 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
523 |
|
18852
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
524 |
/** |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
525 |
* Get the constant value for an object, or {@link #POSTSET_MARKER} if the value can't be statically computed. |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
526 |
* |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
527 |
* @param object a node or value object |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
528 |
* @return the constant value or {@code POSTSET_MARKER} |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
529 |
*/ |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
530 |
public static Object objectAsConstant(final Object object) { |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
531 |
if (object == null) { |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
532 |
return null; |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
533 |
} else if (object instanceof Number || object instanceof String || object instanceof Boolean) { |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
534 |
return object; |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
535 |
} else if (object instanceof LiteralNode) { |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
536 |
return objectAsConstant(((LiteralNode<?>)object).getValue()); |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
537 |
} |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
538 |
|
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
539 |
return POSTSET_MARKER; |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
540 |
} |
604c1d681b6f
8017084: Use spill properties for large object literals
hannesw
parents:
18633
diff
changeset
|
541 |
|
20572
7bceef30eefa
8026042: FoldConstants need to guard against ArrayLiteralNode
hannesw
parents:
18867
diff
changeset
|
542 |
private static final class NullLiteralNode extends PrimitiveLiteralNode<Object> { |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
543 |
|
17967
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
544 |
private NullLiteralNode(final long token, final int finish) { |
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
545 |
super(Token.recast(token, TokenType.OBJECT), finish, null); |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
546 |
} |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
547 |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
548 |
@Override |
17769
14ea7feaf658
8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
17523
diff
changeset
|
549 |
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
17233 | 550 |
if (visitor.enterLiteralNode(this)) { |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16215
diff
changeset
|
551 |
return visitor.leaveLiteralNode(this); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
552 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
553 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
554 |
return this; |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
555 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
556 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
557 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
558 |
public Type getType() { |
17967
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
559 |
return Type.OBJECT; |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
560 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
561 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
562 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
563 |
public Type getWidestOperationType() { |
17967
0ac7d2a303b9
8015693: reduce NodeLiteralNode to NullLiteralNode
attila
parents:
17769
diff
changeset
|
564 |
return Type.OBJECT; |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
565 |
} |
16147 | 566 |
} |
567 |
||
568 |
/** |
|
569 |
* Array literal node class. |
|
570 |
*/ |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
571 |
public static final class ArrayLiteralNode extends LiteralNode<Expression[]> { |
16147 | 572 |
|
573 |
/** Array element type. */ |
|
574 |
private Type elementType; |
|
575 |
||
576 |
/** Preset constant array. */ |
|
577 |
private Object presets; |
|
578 |
||
579 |
/** Indices of array elements requiring computed post sets. */ |
|
580 |
private int[] postsets; |
|
581 |
||
582 |
private List<ArrayUnit> units; |
|
583 |
||
584 |
/** |
|
585 |
* An ArrayUnit is a range in an ArrayLiteral. ArrayLiterals can |
|
586 |
* be split if they are too large, for bytecode generation reasons |
|
587 |
*/ |
|
588 |
public static class ArrayUnit { |
|
589 |
/** Compile unit associated with the postsets range. */ |
|
590 |
private final CompileUnit compileUnit; |
|
591 |
||
592 |
/** postsets range associated with the unit (hi not inclusive). */ |
|
593 |
private final int lo, hi; |
|
594 |
||
595 |
/** |
|
596 |
* Constructor |
|
597 |
* @param compileUnit compile unit |
|
598 |
* @param lo lowest array index in unit |
|
599 |
* @param hi highest array index in unit + 1 |
|
600 |
*/ |
|
601 |
public ArrayUnit(final CompileUnit compileUnit, final int lo, final int hi) { |
|
602 |
this.compileUnit = compileUnit; |
|
603 |
this.lo = lo; |
|
604 |
this.hi = hi; |
|
605 |
} |
|
606 |
||
607 |
/** |
|
608 |
* Get the high index position of the ArrayUnit (non inclusive) |
|
609 |
* @return high index position |
|
610 |
*/ |
|
611 |
public int getHi() { |
|
612 |
return hi; |
|
613 |
} |
|
614 |
||
615 |
/** |
|
616 |
* Get the low index position of the ArrayUnit (inclusive) |
|
617 |
* @return low index position |
|
618 |
*/ |
|
619 |
public int getLo() { |
|
620 |
return lo; |
|
621 |
} |
|
622 |
||
623 |
/** |
|
624 |
* The array compile unit |
|
625 |
* @return array compile unit |
|
626 |
*/ |
|
627 |
public CompileUnit getCompileUnit() { |
|
628 |
return compileUnit; |
|
629 |
} |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Constructor |
|
634 |
* |
|
635 |
* @param token token |
|
636 |
* @param finish finish |
|
637 |
* @param value array literal value, a Node array |
|
638 |
*/ |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
639 |
protected ArrayLiteralNode(final long token, final int finish, final Expression[] value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
640 |
super(Token.recast(token, TokenType.ARRAY), finish, value); |
16147 | 641 |
this.elementType = Type.UNKNOWN; |
642 |
} |
|
643 |
||
644 |
/** |
|
645 |
* Copy constructor |
|
646 |
* @param node source array literal node |
|
647 |
*/ |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
648 |
private ArrayLiteralNode(final ArrayLiteralNode node, final Expression[] value) { |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
649 |
super(node, value); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
650 |
this.elementType = node.elementType; |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
651 |
this.presets = node.presets; |
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
652 |
this.postsets = node.postsets; |
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
653 |
this.units = node.units; |
16147 | 654 |
} |
655 |
||
656 |
/** |
|
657 |
* Compute things like widest element type needed. Internal use from compiler only |
|
658 |
*/ |
|
659 |
public void analyze() { |
|
660 |
elementType = Type.INT; |
|
661 |
analyzeElements(); |
|
662 |
||
18633
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
663 |
if (elementType.isInteger()) { |
16147 | 664 |
presetIntArray(); |
18633
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
665 |
} else if (elementType.isLong()) { |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
666 |
presetLongArray(); |
16147 | 667 |
} else if (elementType.isNumeric()) { |
668 |
presetNumberArray(); |
|
669 |
} else { |
|
670 |
presetObjectArray(); |
|
671 |
} |
|
672 |
} |
|
673 |
||
674 |
private void presetIntArray() { |
|
675 |
final int[] array = new int[value.length]; |
|
676 |
final int[] computed = new int[value.length]; |
|
677 |
int nComputed = 0; |
|
678 |
||
679 |
for (int i = 0; i < value.length; i++) { |
|
680 |
final Object element = objectAsConstant(value[i]); |
|
681 |
||
682 |
if (element instanceof Number) { |
|
683 |
array[i] = ((Number)element).intValue(); |
|
684 |
} else { |
|
685 |
computed[nComputed++] = i; |
|
686 |
} |
|
687 |
} |
|
688 |
||
689 |
presets = array; |
|
690 |
postsets = Arrays.copyOf(computed, nComputed); |
|
691 |
} |
|
692 |
||
18633
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
693 |
private void presetLongArray() { |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
694 |
final long[] array = new long[value.length]; |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
695 |
final int[] computed = new int[value.length]; |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
696 |
int nComputed = 0; |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
697 |
|
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
698 |
for (int i = 0; i < value.length; i++) { |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
699 |
final Object element = objectAsConstant(value[i]); |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
700 |
|
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
701 |
if (element instanceof Number) { |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
702 |
array[i] = ((Number)element).longValue(); |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
703 |
} else { |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
704 |
computed[nComputed++] = i; |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
705 |
} |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
706 |
} |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
707 |
|
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
708 |
presets = array; |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
709 |
postsets = Arrays.copyOf(computed, nComputed); |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
710 |
} |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
711 |
|
16147 | 712 |
private void presetNumberArray() { |
713 |
final double[] array = new double[value.length]; |
|
714 |
final int[] computed = new int[value.length]; |
|
715 |
int nComputed = 0; |
|
716 |
||
717 |
for (int i = 0; i < value.length; i++) { |
|
718 |
final Object element = objectAsConstant(value[i]); |
|
719 |
||
720 |
if (element instanceof Number) { |
|
721 |
array[i] = ((Number)element).doubleValue(); |
|
722 |
} else { |
|
723 |
computed[nComputed++] = i; |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
presets = array; |
|
728 |
postsets = Arrays.copyOf(computed, nComputed); |
|
729 |
} |
|
730 |
||
731 |
private void presetObjectArray() { |
|
732 |
final Object[] array = new Object[value.length]; |
|
733 |
final int[] computed = new int[value.length]; |
|
734 |
int nComputed = 0; |
|
735 |
||
736 |
for (int i = 0; i < value.length; i++) { |
|
737 |
final Node node = value[i]; |
|
738 |
||
739 |
if (node == null) { |
|
740 |
computed[nComputed++] = i; |
|
741 |
} else { |
|
742 |
final Object element = objectAsConstant(node); |
|
743 |
||
744 |
if (element != POSTSET_MARKER) { |
|
745 |
array[i] = element; |
|
746 |
} else { |
|
747 |
computed[nComputed++] = i; |
|
748 |
} |
|
749 |
} |
|
750 |
} |
|
751 |
||
752 |
presets = array; |
|
753 |
postsets = Arrays.copyOf(computed, nComputed); |
|
754 |
} |
|
755 |
||
756 |
private void analyzeElements() { |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
757 |
for (final Expression node : value) { |
16147 | 758 |
if (node == null) { |
759 |
elementType = elementType.widest(Type.OBJECT); //no way to represent undefined as number |
|
760 |
break; |
|
761 |
} |
|
762 |
||
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
763 |
assert node.getSymbol() != null; //don't run this on unresolved nodes or you are in trouble |
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
764 |
Type symbolType = node.getSymbol().getSymbolType(); |
16147 | 765 |
if (symbolType.isUnknown()) { |
766 |
symbolType = Type.OBJECT; |
|
767 |
} |
|
768 |
||
769 |
if (symbolType.isBoolean()) { |
|
770 |
elementType = elementType.widest(Type.OBJECT); |
|
771 |
break; |
|
772 |
} |
|
773 |
||
774 |
elementType = elementType.widest(symbolType); |
|
775 |
||
776 |
if (elementType.isObject()) { |
|
777 |
break; |
|
778 |
} |
|
779 |
} |
|
780 |
} |
|
781 |
||
782 |
@Override |
|
783 |
public Node[] getArray() { |
|
784 |
return value; |
|
785 |
} |
|
786 |
||
20933
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20928
diff
changeset
|
787 |
/** |
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20928
diff
changeset
|
788 |
* Get the array element type as Java format, e.g. [I |
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20928
diff
changeset
|
789 |
* @return array element type |
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20928
diff
changeset
|
790 |
*/ |
20928
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
791 |
public ArrayType getArrayType() { |
16147 | 792 |
if (elementType.isInteger()) { |
793 |
return Type.INT_ARRAY; |
|
18633
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
794 |
} else if (elementType.isLong()) { |
c2138d47b2c6
8017082: Long array literals were slightly broken
lagergren
parents:
17967
diff
changeset
|
795 |
return Type.LONG_ARRAY; |
16147 | 796 |
} else if (elementType.isNumeric()) { |
797 |
return Type.NUMBER_ARRAY; |
|
798 |
} else { |
|
799 |
return Type.OBJECT_ARRAY; |
|
800 |
} |
|
801 |
} |
|
802 |
||
20928
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
803 |
@Override |
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
804 |
public Type getType() { |
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
805 |
return Type.typeFor(NativeArray.class); |
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
806 |
} |
3ff39d5c8c08
8026137: Fix Issues with Binary Evaluation Order
lagergren
parents:
20572
diff
changeset
|
807 |
|
16147 | 808 |
/** |
809 |
* Get the element type of this array literal |
|
810 |
* @return element type |
|
811 |
*/ |
|
812 |
public Type getElementType() { |
|
813 |
return elementType; |
|
814 |
} |
|
815 |
||
816 |
/** |
|
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
817 |
* Get indices of arrays containing computed post sets. post sets |
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
818 |
* are things like non literals e.g. "x+y" instead of i or 17 |
16147 | 819 |
* @return post set indices |
820 |
*/ |
|
821 |
public int[] getPostsets() { |
|
822 |
return postsets; |
|
823 |
} |
|
824 |
||
825 |
/** |
|
826 |
* Get presets constant array |
|
827 |
* @return presets array, always returns an array type |
|
828 |
*/ |
|
829 |
public Object getPresets() { |
|
830 |
return presets; |
|
831 |
} |
|
832 |
||
833 |
/** |
|
834 |
* Get the array units that make up this ArrayLiteral |
|
835 |
* @see ArrayUnit |
|
836 |
* @return list of array units |
|
837 |
*/ |
|
838 |
public List<ArrayUnit> getUnits() { |
|
839 |
return units == null ? null : Collections.unmodifiableList(units); |
|
840 |
} |
|
841 |
||
842 |
/** |
|
843 |
* Set the ArrayUnits that make up this ArrayLiteral |
|
844 |
* @see ArrayUnit |
|
845 |
* @param units list of array units |
|
846 |
*/ |
|
847 |
public void setUnits(final List<ArrayUnit> units) { |
|
848 |
this.units = units; |
|
849 |
} |
|
850 |
||
851 |
@Override |
|
17769
14ea7feaf658
8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
17523
diff
changeset
|
852 |
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
17233 | 853 |
if (visitor.enterLiteralNode(this)) { |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
854 |
final List<Expression> oldValue = Arrays.asList(value); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
855 |
final List<Expression> newValue = Node.accept(visitor, Expression.class, oldValue); |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
856 |
return visitor.leaveLiteralNode(oldValue != newValue ? setValue(newValue) : this); |
16147 | 857 |
} |
858 |
return this; |
|
859 |
} |
|
860 |
||
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
861 |
private ArrayLiteralNode setValue(final List<Expression> value) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
862 |
return new ArrayLiteralNode(this, value.toArray(new Expression[value.size()])); |
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
863 |
} |
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
17233
diff
changeset
|
864 |
|
16147 | 865 |
@Override |
866 |
public void toString(final StringBuilder sb) { |
|
867 |
sb.append('['); |
|
868 |
boolean first = true; |
|
869 |
for (final Node node : value) { |
|
870 |
if (!first) { |
|
871 |
sb.append(','); |
|
872 |
sb.append(' '); |
|
873 |
} |
|
874 |
if (node == null) { |
|
875 |
sb.append("undefined"); |
|
876 |
} else { |
|
877 |
node.toString(sb); |
|
878 |
} |
|
879 |
first = false; |
|
880 |
} |
|
881 |
sb.append(']'); |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
/** |
|
886 |
* Create a new array literal of Nodes from a list of Node values |
|
887 |
* |
|
888 |
* @param token token |
|
889 |
* @param finish finish |
|
890 |
* @param value literal value list |
|
891 |
* |
|
892 |
* @return the new literal node |
|
893 |
*/ |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
894 |
public static LiteralNode<Expression[]> newInstance(final long token, final int finish, final List<Expression> value) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
895 |
return new ArrayLiteralNode(token, finish, value.toArray(new Expression[value.size()])); |
16147 | 896 |
} |
897 |
||
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
898 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
899 |
/** |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
900 |
* Create a new array literal based on a parent node (source, token, finish) |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
901 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
902 |
* @param parent parent node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
903 |
* @param value literal value list |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
904 |
* |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
905 |
* @return the new literal node |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
906 |
*/ |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
907 |
public static LiteralNode<?> newInstance(final Node parent, final List<Expression> value) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
908 |
return new ArrayLiteralNode(parent.getToken(), parent.getFinish(), value.toArray(new Expression[value.size()])); |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
909 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16151
diff
changeset
|
910 |
|
16147 | 911 |
/** |
912 |
* Create a new array literal of Nodes |
|
913 |
* |
|
914 |
* @param token token |
|
915 |
* @param finish finish |
|
916 |
* @param value literal value array |
|
917 |
* |
|
918 |
* @return the new literal node |
|
919 |
*/ |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
18852
diff
changeset
|
920 |
public static LiteralNode<Expression[]> newInstance(final long token, final int finish, final Expression[] value) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17518
diff
changeset
|
921 |
return new ArrayLiteralNode(token, finish, value); |
16147 | 922 |
} |
923 |
} |