diff options
Diffstat (limited to 'src/jdk/nashorn/internal/ir/CaseNode.java')
-rw-r--r-- | src/jdk/nashorn/internal/ir/CaseNode.java | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/src/jdk/nashorn/internal/ir/CaseNode.java b/src/jdk/nashorn/internal/ir/CaseNode.java index c809058a..48f96184 100644 --- a/src/jdk/nashorn/internal/ir/CaseNode.java +++ b/src/jdk/nashorn/internal/ir/CaseNode.java @@ -25,6 +25,8 @@ package jdk.nashorn.internal.ir; +import java.util.Collections; +import java.util.List; import jdk.nashorn.internal.codegen.Label; import jdk.nashorn.internal.ir.annotations.Immutable; import jdk.nashorn.internal.ir.visitor.NodeVisitor; @@ -34,7 +36,9 @@ import jdk.nashorn.internal.ir.visitor.NodeVisitor; * Case nodes are not BreakableNodes, but the SwitchNode is */ @Immutable -public final class CaseNode extends Node { +public final class CaseNode extends Node implements JoinPredecessor, Labels, Terminal { + private static final long serialVersionUID = 1L; + /** Test expression. */ private final Expression test; @@ -45,6 +49,11 @@ public final class CaseNode extends Node { private final Label entry; /** + * @see JoinPredecessor + */ + private final LocalVariableConversion conversion; + + /** * Constructors * * @param token token @@ -58,16 +67,23 @@ public final class CaseNode extends Node { this.test = test; this.body = body; this.entry = new Label("entry"); + this.conversion = null; } - CaseNode(final CaseNode caseNode, final Expression test, final Block body) { + CaseNode(final CaseNode caseNode, final Expression test, final Block body, final LocalVariableConversion conversion) { super(caseNode); this.test = test; this.body = body; this.entry = new Label(caseNode.entry); + this.conversion = conversion; } + /** + * Is this a terminal case node, i.e. does it end control flow like having a throw or return? + * + * @return true if this node statement is terminal + */ @Override public boolean isTerminal() { return body.isTerminal(); @@ -90,10 +106,10 @@ public final class CaseNode extends Node { } @Override - public void toString(final StringBuilder sb) { + public void toString(final StringBuilder sb, final boolean printTypes) { if (test != null) { sb.append("case "); - test.toString(sb); + test.toString(sb, printTypes); sb.append(':'); } else { sb.append("default:"); @@ -133,13 +149,31 @@ public final class CaseNode extends Node { if (this.test == test) { return this; } - return new CaseNode(this, test, body); + return new CaseNode(this, test, body, conversion); + } + + @Override + public JoinPredecessor setLocalVariableConversion(final LexicalContext lc, final LocalVariableConversion conversion) { + if(this.conversion == conversion) { + return this; + } + return new CaseNode(this, test, body, conversion); + } + + @Override + public LocalVariableConversion getLocalVariableConversion() { + return conversion; } private CaseNode setBody(final Block body) { if (this.body == body) { return this; } - return new CaseNode(this, test, body); + return new CaseNode(this, test, body, conversion); + } + + @Override + public List<Label> getLabels() { + return Collections.unmodifiableList(Collections.singletonList(entry)); } } |