author | hannesw |
Wed, 20 Dec 2017 21:40:11 +0100 | |
changeset 48380 | 597f69e5f1e3 |
parent 47216 | 71c04702a3d5 |
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.Collections; |
|
29 |
import java.util.List; |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
30 |
import java.util.RandomAccess; |
24751 | 31 |
import jdk.nashorn.internal.codegen.types.Type; |
48380
597f69e5f1e3
8193508: Expressions in split literals must never be optimistic
hannesw
parents:
47216
diff
changeset
|
32 |
import jdk.nashorn.internal.ir.annotations.Ignore; |
17233 | 33 |
import jdk.nashorn.internal.ir.annotations.Immutable; |
16147 | 34 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
35 |
||
36 |
/** |
|
37 |
* IR representation of an object literal. |
|
38 |
*/ |
|
17233 | 39 |
@Immutable |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
40 |
public final class ObjectNode extends Expression implements LexicalContextNode, Splittable { |
27204 | 41 |
private static final long serialVersionUID = 1L; |
16147 | 42 |
|
43 |
/** Literal elements. */ |
|
17981
9b8e085aa1fe
8015955: ObjectNode.elements should be stronger typed
attila
parents:
17769
diff
changeset
|
44 |
private final List<PropertyNode> elements; |
16147 | 45 |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
46 |
/** Ranges for splitting large literals over multiple compile units in codegen. */ |
48380
597f69e5f1e3
8193508: Expressions in split literals must never be optimistic
hannesw
parents:
47216
diff
changeset
|
47 |
@Ignore |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
48 |
private final List<Splittable.SplitRange> splitRanges; |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
49 |
|
16147 | 50 |
/** |
51 |
* Constructor |
|
52 |
* |
|
53 |
* @param token token |
|
54 |
* @param finish finish |
|
55 |
* @param elements the elements used to initialize this ObjectNode |
|
56 |
*/ |
|
17981
9b8e085aa1fe
8015955: ObjectNode.elements should be stronger typed
attila
parents:
17769
diff
changeset
|
57 |
public ObjectNode(final long token, final int finish, final List<PropertyNode> elements) { |
17523
cb4a7c901e0d
8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents:
17233
diff
changeset
|
58 |
super(token, finish); |
16147 | 59 |
this.elements = elements; |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
60 |
this.splitRanges = null; |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
61 |
assert elements instanceof RandomAccess : "Splitting requires random access lists"; |
16147 | 62 |
} |
63 |
||
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
64 |
private ObjectNode(final ObjectNode objectNode, final List<PropertyNode> elements, |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
65 |
final List<Splittable.SplitRange> splitRanges ) { |
16147 | 66 |
super(objectNode); |
17233 | 67 |
this.elements = elements; |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
68 |
this.splitRanges = splitRanges; |
16147 | 69 |
} |
70 |
||
71 |
@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
|
72 |
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
73 |
return Acceptor.accept(this, visitor); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
74 |
} |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
75 |
|
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
76 |
@Override |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
77 |
public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { |
17233 | 78 |
if (visitor.enterObjectNode(this)) { |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
79 |
return visitor.leaveObjectNode(setElements(lc, Node.accept(visitor, elements))); |
16147 | 80 |
} |
81 |
return this; |
|
82 |
} |
|
83 |
||
84 |
@Override |
|
28130
433d6755c5f8
8067774: Use a stack of types when calculating local variable types
attila
parents:
27204
diff
changeset
|
85 |
public Type getType() { |
24751 | 86 |
return Type.OBJECT; |
87 |
} |
|
88 |
||
89 |
@Override |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
90 |
public void toString(final StringBuilder sb, final boolean printType) { |
16147 | 91 |
sb.append('{'); |
92 |
||
93 |
if (!elements.isEmpty()) { |
|
94 |
sb.append(' '); |
|
95 |
||
96 |
boolean first = true; |
|
97 |
for (final Node element : elements) { |
|
98 |
if (!first) { |
|
99 |
sb.append(", "); |
|
100 |
} |
|
101 |
first = false; |
|
102 |
||
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
103 |
element.toString(sb, printType); |
16147 | 104 |
} |
105 |
sb.append(' '); |
|
106 |
} |
|
107 |
||
108 |
sb.append('}'); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Get the elements of this literal node |
|
113 |
* @return a list of elements |
|
114 |
*/ |
|
17981
9b8e085aa1fe
8015955: ObjectNode.elements should be stronger typed
attila
parents:
17769
diff
changeset
|
115 |
public List<PropertyNode> getElements() { |
16147 | 116 |
return Collections.unmodifiableList(elements); |
117 |
} |
|
17233 | 118 |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
119 |
private ObjectNode setElements(final LexicalContext lc, final List<PropertyNode> elements) { |
17233 | 120 |
if (this.elements == elements) { |
121 |
return this; |
|
122 |
} |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
123 |
return Node.replaceInLexicalContext(lc, this, new ObjectNode(this, elements, this.splitRanges)); |
17233 | 124 |
} |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
125 |
|
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
126 |
/** |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
127 |
* Set the split ranges for this ObjectNode |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
128 |
* @see Splittable.SplitRange |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
129 |
* @param lc the lexical context |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
130 |
* @param splitRanges list of split ranges |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
131 |
* @return new or changed object node |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
132 |
*/ |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
133 |
public ObjectNode setSplitRanges(final LexicalContext lc, final List<Splittable.SplitRange> splitRanges) { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
134 |
if (this.splitRanges == splitRanges) { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
135 |
return this; |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
136 |
} |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
137 |
return Node.replaceInLexicalContext(lc, this, new ObjectNode(this, elements, splitRanges)); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
138 |
} |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
139 |
|
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
140 |
/** |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
141 |
* Get the split ranges for this ObjectNode, or null if the object is not split. |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
142 |
* @see Splittable.SplitRange |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
143 |
* @return list of split ranges |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
144 |
*/ |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
145 |
@Override |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
146 |
public List<Splittable.SplitRange> getSplitRanges() { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
147 |
return splitRanges == null ? null : Collections.unmodifiableList(splitRanges); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
148 |
} |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
28130
diff
changeset
|
149 |
|
16147 | 150 |
} |