author | attila |
Wed, 28 Jan 2015 17:58:08 +0100 | |
changeset 28690 | 78317797ab62 |
parent 25865 | d38d876f1654 |
child 32888 | 24f99be3d5ab |
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.debug; |
|
27 |
||
28 |
import java.util.List; |
|
17233 | 29 |
import jdk.nashorn.internal.ir.BinaryNode; |
16147 | 30 |
import jdk.nashorn.internal.ir.Block; |
21868
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
31 |
import jdk.nashorn.internal.ir.BlockStatement; |
24751 | 32 |
import jdk.nashorn.internal.ir.BreakNode; |
16147 | 33 |
import jdk.nashorn.internal.ir.CaseNode; |
34 |
import jdk.nashorn.internal.ir.CatchNode; |
|
24751 | 35 |
import jdk.nashorn.internal.ir.ContinueNode; |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
36 |
import jdk.nashorn.internal.ir.ExpressionStatement; |
16147 | 37 |
import jdk.nashorn.internal.ir.ForNode; |
38 |
import jdk.nashorn.internal.ir.FunctionNode; |
|
24751 | 39 |
import jdk.nashorn.internal.ir.IdentNode; |
16147 | 40 |
import jdk.nashorn.internal.ir.IfNode; |
24751 | 41 |
import jdk.nashorn.internal.ir.JoinPredecessor; |
42 |
import jdk.nashorn.internal.ir.JoinPredecessorExpression; |
|
16147 | 43 |
import jdk.nashorn.internal.ir.LabelNode; |
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:
17524
diff
changeset
|
44 |
import jdk.nashorn.internal.ir.LexicalContext; |
24751 | 45 |
import jdk.nashorn.internal.ir.LocalVariableConversion; |
16147 | 46 |
import jdk.nashorn.internal.ir.Node; |
47 |
import jdk.nashorn.internal.ir.SplitNode; |
|
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
48 |
import jdk.nashorn.internal.ir.Statement; |
16147 | 49 |
import jdk.nashorn.internal.ir.SwitchNode; |
24751 | 50 |
import jdk.nashorn.internal.ir.ThrowNode; |
16147 | 51 |
import jdk.nashorn.internal.ir.TryNode; |
18869
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
52 |
import jdk.nashorn.internal.ir.UnaryNode; |
16147 | 53 |
import jdk.nashorn.internal.ir.VarNode; |
54 |
import jdk.nashorn.internal.ir.WhileNode; |
|
55 |
import jdk.nashorn.internal.ir.WithNode; |
|
56 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
|
57 |
||
58 |
/** |
|
59 |
* Print out the AST as human readable source code. |
|
60 |
* This works both on lowered and unlowered ASTs |
|
61 |
* |
|
62 |
* see the flags --print-parse and --print-lower-parse |
|
63 |
*/ |
|
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:
17524
diff
changeset
|
64 |
public final class PrintVisitor extends NodeVisitor<LexicalContext> { |
16147 | 65 |
/** Tab width */ |
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
66 |
private static final int TABWIDTH = 4; |
16147 | 67 |
|
68 |
/** Composing buffer. */ |
|
69 |
private final StringBuilder sb; |
|
70 |
||
71 |
/** Indentation factor. */ |
|
72 |
private int indent; |
|
73 |
||
74 |
/** Line separator. */ |
|
75 |
private final String EOLN; |
|
76 |
||
77 |
/** Print line numbers */ |
|
78 |
private final boolean printLineNumbers; |
|
79 |
||
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
80 |
/** Print inferred and optimistic types */ |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
81 |
private final boolean printTypes; |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
82 |
|
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
83 |
private int lastLineNumber = -1; |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
84 |
|
16147 | 85 |
/** |
86 |
* Constructor. |
|
87 |
*/ |
|
88 |
public PrintVisitor() { |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
89 |
this(true, true); |
16147 | 90 |
} |
91 |
||
92 |
/** |
|
93 |
* Constructor |
|
94 |
* |
|
95 |
* @param printLineNumbers should line number nodes be included in the output? |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
96 |
* @param printTypes should we print optimistic and inferred types? |
16147 | 97 |
*/ |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
98 |
public PrintVisitor(final boolean printLineNumbers, final boolean printTypes) { |
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:
17524
diff
changeset
|
99 |
super(new LexicalContext()); |
16147 | 100 |
this.EOLN = System.lineSeparator(); |
101 |
this.sb = new StringBuilder(); |
|
102 |
this.printLineNumbers = printLineNumbers; |
|
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 |
this.printTypes = printTypes; |
16147 | 104 |
} |
105 |
||
106 |
/** |
|
107 |
* Constructor |
|
108 |
* |
|
109 |
* @param root a node from which to start printing code |
|
110 |
*/ |
|
111 |
public PrintVisitor(final Node root) { |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
112 |
this(root, true, true); |
16147 | 113 |
} |
114 |
||
115 |
/** |
|
116 |
* Constructor |
|
117 |
* |
|
118 |
* @param root a node from which to start printing code |
|
119 |
* @param printLineNumbers should line numbers nodes be included in the output? |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
120 |
* @param printTypes should we print optimistic and inferred types? |
16147 | 121 |
*/ |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
122 |
public PrintVisitor(final Node root, final boolean printLineNumbers, final boolean printTypes) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
123 |
this(printLineNumbers, printTypes); |
16147 | 124 |
visit(root); |
125 |
} |
|
126 |
||
127 |
private void visit(final Node root) { |
|
128 |
root.accept(this); |
|
129 |
} |
|
130 |
||
131 |
@Override |
|
132 |
public String toString() { |
|
133 |
return sb.append(EOLN).toString(); |
|
134 |
} |
|
135 |
||
136 |
/** |
|
137 |
* Insert spaces before a statement. |
|
138 |
*/ |
|
139 |
private void indent() { |
|
140 |
for (int i = indent; i > 0; i--) { |
|
141 |
sb.append(' '); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
/* |
|
146 |
* Visits. |
|
147 |
*/ |
|
17233 | 148 |
|
16147 | 149 |
@Override |
17233 | 150 |
public boolean enterDefault(final Node node) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
151 |
node.toString(sb, printTypes); |
17233 | 152 |
return false; |
16147 | 153 |
} |
154 |
||
155 |
@Override |
|
24751 | 156 |
public boolean enterContinueNode(final ContinueNode node) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
157 |
node.toString(sb, printTypes); |
24751 | 158 |
printLocalVariableConversion(node); |
159 |
return false; |
|
160 |
} |
|
161 |
||
162 |
@Override |
|
163 |
public boolean enterBreakNode(final BreakNode node) { |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
164 |
node.toString(sb, printTypes); |
24751 | 165 |
printLocalVariableConversion(node); |
166 |
return false; |
|
167 |
} |
|
168 |
||
169 |
@Override |
|
170 |
public boolean enterThrowNode(final ThrowNode node) { |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
171 |
node.toString(sb, printTypes); |
24751 | 172 |
printLocalVariableConversion(node); |
173 |
return false; |
|
174 |
} |
|
175 |
||
176 |
@Override |
|
17233 | 177 |
public boolean enterBlock(final Block block) { |
16147 | 178 |
sb.append(' '); |
179 |
sb.append('{'); |
|
180 |
||
181 |
indent += TABWIDTH; |
|
182 |
||
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
183 |
final List<Statement> statements = block.getStatements(); |
16147 | 184 |
|
25244
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
185 |
for (final Statement statement : statements) { |
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
186 |
if (printLineNumbers) { |
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
187 |
final int lineNumber = statement.getLineNumber(); |
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
188 |
sb.append('\n'); |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
189 |
if (lineNumber != lastLineNumber) { |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
190 |
indent(); |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
191 |
sb.append("[|").append(lineNumber).append("|];").append('\n'); |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
192 |
} |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
193 |
lastLineNumber = lineNumber; |
16147 | 194 |
} |
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
195 |
indent(); |
16147 | 196 |
|
17233 | 197 |
statement.accept(this); |
16147 | 198 |
|
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
199 |
int lastIndex = sb.length() - 1; |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
200 |
char lastChar = sb.charAt(lastIndex); |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
201 |
while (Character.isWhitespace(lastChar) && lastIndex >= 0) { |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
202 |
lastChar = sb.charAt(--lastIndex); |
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
203 |
} |
16147 | 204 |
|
205 |
if (lastChar != '}' && lastChar != ';') { |
|
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
206 |
sb.append(';'); |
16147 | 207 |
} |
208 |
||
209 |
if (statement.hasGoto()) { |
|
210 |
sb.append(" [GOTO]"); |
|
211 |
} |
|
212 |
||
213 |
if (statement.isTerminal()) { |
|
214 |
sb.append(" [TERMINAL]"); |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
indent -= TABWIDTH; |
|
219 |
||
220 |
sb.append(EOLN); |
|
221 |
indent(); |
|
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
222 |
sb.append('}'); |
24751 | 223 |
printLocalVariableConversion(block); |
21868
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
224 |
|
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
225 |
return false; |
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
226 |
} |
16147 | 227 |
|
21868
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
228 |
@Override |
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
229 |
public boolean enterBlockStatement(final BlockStatement statement) { |
f3cd4fa7f8b9
8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents:
18869
diff
changeset
|
230 |
statement.getBlock().accept(this); |
17233 | 231 |
return false; |
16147 | 232 |
} |
233 |
||
234 |
@Override |
|
17233 | 235 |
public boolean enterBinaryNode(final BinaryNode binaryNode) { |
236 |
binaryNode.lhs().accept(this); |
|
237 |
sb.append(' '); |
|
238 |
sb.append(binaryNode.tokenType()); |
|
239 |
sb.append(' '); |
|
240 |
binaryNode.rhs().accept(this); |
|
241 |
return false; |
|
16147 | 242 |
} |
243 |
||
244 |
@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
|
245 |
public boolean enterJoinPredecessorExpression(final JoinPredecessorExpression expr) { |
24751 | 246 |
expr.getExpression().accept(this); |
247 |
printLocalVariableConversion(expr); |
|
248 |
return false; |
|
249 |
} |
|
250 |
||
251 |
@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
|
252 |
public boolean enterIdentNode(final IdentNode identNode) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
253 |
identNode.toString(sb, printTypes); |
24751 | 254 |
printLocalVariableConversion(identNode); |
255 |
return true; |
|
256 |
} |
|
257 |
||
258 |
private void printLocalVariableConversion(final JoinPredecessor joinPredecessor) { |
|
259 |
LocalVariableConversion.toString(joinPredecessor.getLocalVariableConversion(), sb); |
|
260 |
} |
|
261 |
||
262 |
@Override |
|
18869
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
263 |
public boolean enterUnaryNode(final UnaryNode unaryNode) { |
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
264 |
unaryNode.toString(sb, new Runnable() { |
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
265 |
@Override |
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
266 |
public void run() { |
24719 | 267 |
unaryNode.getExpression().accept(PrintVisitor.this); |
18869
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
268 |
} |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
269 |
}, printTypes); |
18869
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
270 |
return false; |
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
271 |
} |
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
272 |
|
b8ddb7296bae
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents:
18867
diff
changeset
|
273 |
@Override |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
274 |
public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
275 |
expressionStatement.getExpression().accept(this); |
17233 | 276 |
return false; |
16147 | 277 |
} |
278 |
||
279 |
@Override |
|
17233 | 280 |
public boolean enterForNode(final ForNode forNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
281 |
forNode.toString(sb, printTypes); |
17233 | 282 |
forNode.getBody().accept(this); |
283 |
return false; |
|
16147 | 284 |
} |
285 |
||
286 |
@Override |
|
17233 | 287 |
public boolean enterFunctionNode(final FunctionNode functionNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
288 |
functionNode.toString(sb, printTypes); |
17233 | 289 |
enterBlock(functionNode.getBody()); |
290 |
return false; |
|
16147 | 291 |
} |
292 |
||
293 |
@Override |
|
17233 | 294 |
public boolean enterIfNode(final IfNode ifNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
295 |
ifNode.toString(sb, printTypes); |
16147 | 296 |
ifNode.getPass().accept(this); |
297 |
||
298 |
final Block fail = ifNode.getFail(); |
|
299 |
||
300 |
if (fail != null) { |
|
301 |
sb.append(" else "); |
|
302 |
fail.accept(this); |
|
303 |
} |
|
24751 | 304 |
if(ifNode.getLocalVariableConversion() != null) { |
305 |
assert fail == null; |
|
306 |
sb.append(" else "); |
|
307 |
printLocalVariableConversion(ifNode); |
|
308 |
sb.append(";"); |
|
309 |
} |
|
17233 | 310 |
return false; |
16147 | 311 |
} |
312 |
||
313 |
@Override |
|
17233 | 314 |
public boolean enterLabelNode(final LabelNode labeledNode) { |
16147 | 315 |
indent -= TABWIDTH; |
316 |
indent(); |
|
317 |
indent += TABWIDTH; |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
318 |
labeledNode.toString(sb, printTypes); |
16147 | 319 |
labeledNode.getBody().accept(this); |
24751 | 320 |
printLocalVariableConversion(labeledNode); |
17233 | 321 |
return false; |
16147 | 322 |
} |
323 |
||
324 |
@Override |
|
17233 | 325 |
public boolean enterSplitNode(final SplitNode splitNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
326 |
splitNode.toString(sb, printTypes); |
16147 | 327 |
sb.append(EOLN); |
328 |
indent += TABWIDTH; |
|
329 |
indent(); |
|
17233 | 330 |
return true; |
16147 | 331 |
} |
332 |
||
333 |
@Override |
|
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16151
diff
changeset
|
334 |
public Node leaveSplitNode(final SplitNode splitNode) { |
16147 | 335 |
sb.append("</split>"); |
336 |
sb.append(EOLN); |
|
337 |
indent -= TABWIDTH; |
|
338 |
indent(); |
|
339 |
return splitNode; |
|
340 |
} |
|
341 |
||
342 |
@Override |
|
17233 | 343 |
public boolean enterSwitchNode(final SwitchNode switchNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
344 |
switchNode.toString(sb, printTypes); |
16147 | 345 |
sb.append(" {"); |
346 |
||
347 |
final List<CaseNode> cases = switchNode.getCases(); |
|
348 |
||
349 |
for (final CaseNode caseNode : cases) { |
|
350 |
sb.append(EOLN); |
|
351 |
indent(); |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
352 |
caseNode.toString(sb, printTypes); |
24751 | 353 |
printLocalVariableConversion(caseNode); |
16147 | 354 |
indent += TABWIDTH; |
355 |
caseNode.getBody().accept(this); |
|
356 |
indent -= TABWIDTH; |
|
357 |
sb.append(EOLN); |
|
358 |
} |
|
24751 | 359 |
if(switchNode.getLocalVariableConversion() != null) { |
360 |
sb.append(EOLN); |
|
361 |
indent(); |
|
362 |
sb.append("default: "); |
|
363 |
printLocalVariableConversion(switchNode); |
|
364 |
sb.append("{}"); |
|
365 |
} |
|
16147 | 366 |
sb.append(EOLN); |
367 |
indent(); |
|
368 |
sb.append("}"); |
|
369 |
||
17233 | 370 |
return false; |
16147 | 371 |
} |
372 |
||
373 |
@Override |
|
17233 | 374 |
public boolean enterTryNode(final TryNode tryNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
375 |
tryNode.toString(sb, printTypes); |
24751 | 376 |
printLocalVariableConversion(tryNode); |
16147 | 377 |
tryNode.getBody().accept(this); |
378 |
||
379 |
final List<Block> catchBlocks = tryNode.getCatchBlocks(); |
|
380 |
||
381 |
for (final Block catchBlock : catchBlocks) { |
|
17233 | 382 |
final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0); |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
383 |
catchNode.toString(sb, printTypes); |
16147 | 384 |
catchNode.getBody().accept(this); |
385 |
} |
|
386 |
||
387 |
final Block finallyBody = tryNode.getFinallyBody(); |
|
388 |
||
389 |
if (finallyBody != null) { |
|
390 |
sb.append(" finally "); |
|
391 |
finallyBody.accept(this); |
|
392 |
} |
|
393 |
||
28690 | 394 |
for (final Block inlinedFinally : tryNode.getInlinedFinallies()) { |
395 |
inlinedFinally.accept(this); |
|
396 |
} |
|
17233 | 397 |
return false; |
16147 | 398 |
} |
399 |
||
400 |
@Override |
|
17233 | 401 |
public boolean enterVarNode(final VarNode varNode) { |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16151
diff
changeset
|
402 |
sb.append("var "); |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
403 |
varNode.getName().toString(sb, printTypes); |
24751 | 404 |
printLocalVariableConversion(varNode.getName()); |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16151
diff
changeset
|
405 |
final Node init = varNode.getInit(); |
17233 | 406 |
if (init != null) { |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16151
diff
changeset
|
407 |
sb.append(" = "); |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16151
diff
changeset
|
408 |
init.accept(this); |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16151
diff
changeset
|
409 |
} |
17524
703643aeb0d6
8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents:
17233
diff
changeset
|
410 |
|
17233 | 411 |
return false; |
16147 | 412 |
} |
413 |
||
414 |
@Override |
|
17233 | 415 |
public boolean enterWhileNode(final WhileNode whileNode) { |
24751 | 416 |
printLocalVariableConversion(whileNode); |
17233 | 417 |
if (whileNode.isDoWhile()) { |
418 |
sb.append("do"); |
|
419 |
whileNode.getBody().accept(this); |
|
420 |
sb.append(' '); |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
421 |
whileNode.toString(sb, printTypes); |
17233 | 422 |
} else { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
423 |
whileNode.toString(sb, printTypes); |
17233 | 424 |
whileNode.getBody().accept(this); |
425 |
} |
|
16147 | 426 |
|
17233 | 427 |
return false; |
16147 | 428 |
} |
429 |
||
430 |
@Override |
|
17233 | 431 |
public boolean enterWithNode(final WithNode withNode) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
432 |
withNode.toString(sb, printTypes); |
16147 | 433 |
withNode.getBody().accept(this); |
434 |
||
17233 | 435 |
return false; |
16147 | 436 |
} |
437 |
||
438 |
} |