author | hannesw |
Sat, 19 Sep 2015 16:04:28 +0200 | |
changeset 32781 | d8f34ffbbc7a |
parent 32692 | 8f60bd284bf4 |
child 32888 | 24f99be3d5ab |
permissions | -rw-r--r-- |
27206 | 1 |
/* |
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
|
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.codegen; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
30 |
|
27206 | 31 |
import jdk.nashorn.internal.ir.CompileUnitHolder; |
32 |
import jdk.nashorn.internal.ir.FunctionNode; |
|
33 |
import jdk.nashorn.internal.ir.LexicalContext; |
|
34 |
import jdk.nashorn.internal.ir.LiteralNode; |
|
35 |
import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; |
|
36 |
import jdk.nashorn.internal.ir.Node; |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
37 |
import jdk.nashorn.internal.ir.ObjectNode; |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
38 |
import jdk.nashorn.internal.ir.Splittable; |
27206 | 39 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
40 |
||
41 |
/** |
|
42 |
* Base class for a node visitor that replaces {@link CompileUnit}s in {@link CompileUnitHolder}s. |
|
43 |
*/ |
|
44 |
abstract class ReplaceCompileUnits extends NodeVisitor<LexicalContext> { |
|
45 |
ReplaceCompileUnits() { |
|
46 |
super(new LexicalContext()); |
|
47 |
} |
|
48 |
||
49 |
/** |
|
50 |
* Override to provide a replacement for an old compile unit. |
|
51 |
* @param oldUnit the old compile unit to replace |
|
52 |
* @return the compile unit's replacement. |
|
53 |
*/ |
|
54 |
abstract CompileUnit getReplacement(final CompileUnit oldUnit); |
|
55 |
||
56 |
CompileUnit getExistingReplacement(final CompileUnitHolder node) { |
|
57 |
final CompileUnit oldUnit = node.getCompileUnit(); |
|
58 |
assert oldUnit != null; |
|
59 |
||
60 |
final CompileUnit newUnit = getReplacement(oldUnit); |
|
61 |
assert newUnit != null; |
|
62 |
||
63 |
return newUnit; |
|
64 |
} |
|
65 |
||
66 |
@Override |
|
67 |
public Node leaveFunctionNode(final FunctionNode node) { |
|
32692
8f60bd284bf4
8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes
sundar
parents:
27206
diff
changeset
|
68 |
return node.setCompileUnit(lc, getExistingReplacement(node)); |
27206 | 69 |
} |
70 |
||
71 |
@Override |
|
72 |
public Node leaveLiteralNode(final LiteralNode<?> node) { |
|
73 |
if (node instanceof ArrayLiteralNode) { |
|
74 |
final ArrayLiteralNode aln = (ArrayLiteralNode)node; |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
75 |
if (aln.getSplitRanges() == null) { |
27206 | 76 |
return node; |
77 |
} |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
78 |
final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>(); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
79 |
for (final Splittable.SplitRange au : aln.getSplitRanges()) { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
80 |
newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh())); |
27206 | 81 |
} |
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
82 |
return aln.setSplitRanges(lc, newArrayUnits); |
27206 | 83 |
} |
84 |
return node; |
|
85 |
} |
|
32781
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
86 |
|
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
87 |
@Override |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
88 |
public Node leaveObjectNode(final ObjectNode objectNode) { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
89 |
final List<Splittable.SplitRange> ranges = objectNode.getSplitRanges(); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
90 |
if (ranges != null) { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
91 |
final List<Splittable.SplitRange> newRanges = new ArrayList<>(); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
92 |
for (final Splittable.SplitRange range : ranges) { |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
93 |
newRanges.add(new Splittable.SplitRange(getExistingReplacement(range), range.getLow(), range.getHigh())); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
94 |
} |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
95 |
return objectNode.setSplitRanges(lc, newRanges); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
96 |
} |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
97 |
return super.leaveObjectNode(objectNode); |
d8f34ffbbc7a
8135190: Method code too large in Babel browser.js script
hannesw
parents:
32692
diff
changeset
|
98 |
} |
27206 | 99 |
} |