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