author | attila |
Wed, 28 Jan 2015 17:58:08 +0100 | |
changeset 28690 | 78317797ab62 |
parent 27204 | 06ec78f29a56 |
child 29407 | 3fd4ede1581e |
permissions | -rw-r--r-- |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
1 |
/* |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
4 |
* |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
10 |
* |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
15 |
* accompanied this code). |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
16 |
* |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
20 |
* |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
23 |
* questions. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
24 |
*/ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
25 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
26 |
package jdk.nashorn.internal.ir; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
27 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
28 |
import java.util.List; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
29 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
30 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
31 |
/** |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
32 |
* Represents a block used as a statement. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
33 |
*/ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
34 |
public class BlockStatement extends Statement { |
27204 | 35 |
private static final long serialVersionUID = 1L; |
36 |
||
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
37 |
/** Block to execute. */ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
38 |
private final Block block; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
39 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
40 |
/** |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
41 |
* Constructor |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
42 |
* |
28690 | 43 |
* @param block the block to execute |
44 |
*/ |
|
45 |
public BlockStatement(final Block block) { |
|
46 |
this(block.getFirstStatementLineNumber(), block); |
|
47 |
} |
|
48 |
||
49 |
/** |
|
50 |
* Constructor |
|
51 |
* |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
52 |
* @param lineNumber line number |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
53 |
* @param block the block to execute |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
54 |
*/ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
55 |
public BlockStatement(final int lineNumber, final Block block) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
56 |
super(lineNumber, block.getToken(), block.getFinish()); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
57 |
this.block = block; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
58 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
59 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
60 |
private BlockStatement(final BlockStatement blockStatement, final Block block) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
61 |
super(blockStatement); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
62 |
this.block = block; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
63 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
64 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
65 |
/** |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
66 |
* Use this method to create a block statement meant to replace a single statement. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
67 |
* @param stmt the statement to replace |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
68 |
* @param newStmts the statements for the new block statement |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
69 |
* @return a block statement with the new statements. It will have the line number, token, and finish of the |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
70 |
* original statement. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
71 |
*/ |
24719 | 72 |
public static BlockStatement createReplacement(final Statement stmt, final List<Statement> newStmts) { |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
73 |
return createReplacement(stmt, stmt.getFinish(), newStmts); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
74 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
75 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
76 |
/** |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
77 |
* Use this method to create a block statement meant to replace a single statement. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
78 |
* @param stmt the statement to replace |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
79 |
* @param finish the new finish for the block |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
80 |
* @param newStmts the statements for the new block statement |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
81 |
* @return a block statement with the new statements. It will have the line number, and token of the |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
82 |
* original statement. |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
83 |
*/ |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24719
diff
changeset
|
84 |
public static BlockStatement createReplacement(final Statement stmt, final int finish, final List<Statement> newStmts) { |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
85 |
return new BlockStatement(stmt.getLineNumber(), new Block(stmt.getToken(), finish, newStmts)); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
86 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
87 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
88 |
@Override |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
89 |
public boolean isTerminal() { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
90 |
return block.isTerminal(); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
91 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
92 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
93 |
@Override |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
94 |
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
95 |
if (visitor.enterBlockStatement(this)) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
96 |
return visitor.leaveBlockStatement(setBlock((Block)block.accept(visitor))); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
97 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
98 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
99 |
return this; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
100 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
101 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
102 |
@Override |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24719
diff
changeset
|
103 |
public void toString(final StringBuilder sb, final boolean printType) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24719
diff
changeset
|
104 |
block.toString(sb, printType); |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
105 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
106 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
107 |
/** |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
108 |
* Return the block to be executed |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
109 |
* @return the block |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
110 |
*/ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
111 |
public Block getBlock() { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
112 |
return block; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
113 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
114 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
115 |
/** |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
116 |
* Reset the block to be executed |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
117 |
* @param block the block |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
118 |
* @return new or same execute node |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
119 |
*/ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
120 |
public BlockStatement setBlock(final Block block) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
121 |
if (this.block == block) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
122 |
return this; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
123 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
124 |
return new BlockStatement(this, block); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
125 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
diff
changeset
|
126 |
} |