diff options
Diffstat (limited to 'src/jdk/nashorn/internal/ir/CatchNode.java')
-rw-r--r-- | src/jdk/nashorn/internal/ir/CatchNode.java | 87 |
1 files changed, 40 insertions, 47 deletions
diff --git a/src/jdk/nashorn/internal/ir/CatchNode.java b/src/jdk/nashorn/internal/ir/CatchNode.java index 005ffa8e..5e1b4111 100644 --- a/src/jdk/nashorn/internal/ir/CatchNode.java +++ b/src/jdk/nashorn/internal/ir/CatchNode.java @@ -25,26 +25,23 @@ package jdk.nashorn.internal.ir; +import jdk.nashorn.internal.ir.annotations.Immutable; import jdk.nashorn.internal.ir.visitor.NodeVisitor; import jdk.nashorn.internal.runtime.Source; /** * IR representation of a catch clause. - * */ -public class CatchNode extends Node { +@Immutable +public final class CatchNode extends Node { /** Exception identifier. */ - private IdentNode exception; + private final IdentNode exception; /** Exception condition. */ - private Node exceptionCondition; + private final Node exceptionCondition; /** Catch body. */ - private Block body; - - /** Is rethrow - e.g. synthetic catch block for e.g. finallies, the parser case where - * there has to be at least on catch for syntactic validity */ - private boolean isSyntheticRethrow; + private final Block body; /** * Constructors @@ -64,18 +61,12 @@ public class CatchNode extends Node { this.body = body; } - private CatchNode(final CatchNode catchNode, final CopyState cs) { + private CatchNode(final CatchNode catchNode, final IdentNode exception, final Node exceptionCondition, final Block body) { super(catchNode); - this.exception = (IdentNode)cs.existingOrCopy(catchNode.exception); - this.exceptionCondition = cs.existingOrCopy(catchNode.exceptionCondition); - this.body = (Block)cs.existingOrCopy(catchNode.body); - this.isSyntheticRethrow = catchNode.isSyntheticRethrow; - } - - @Override - protected Node copy(final CopyState cs) { - return new CatchNode(this, cs); + this.exception = exception; + this.exceptionCondition = exceptionCondition; + this.body = body; } /** @@ -84,21 +75,22 @@ public class CatchNode extends Node { */ @Override public Node accept(final NodeVisitor visitor) { - if (visitor.enterCatchNode(this) != null) { - exception = (IdentNode)exception.accept(visitor); - - if (exceptionCondition != null) { - exceptionCondition = exceptionCondition.accept(visitor); - } - - body = (Block)body.accept(visitor); - return visitor.leaveCatchNode(this); + if (visitor.enterCatchNode(this)) { + return visitor.leaveCatchNode( + setException((IdentNode)exception.accept(visitor)). + setExceptionCondition(exceptionCondition == null ? null : exceptionCondition.accept(visitor)). + setBody((Block)body.accept(visitor))); } return this; } @Override + public boolean isTerminal() { + return body.isTerminal(); + } + + @Override public void toString(final StringBuilder sb) { sb.append(" catch ("); exception.toString(sb); @@ -111,23 +103,6 @@ public class CatchNode extends Node { } /** - * Check if this catch is a synthetic rethrow - * @return true if this is a synthetic rethrow - */ - public boolean isSyntheticRethrow() { - return isSyntheticRethrow; - } - - /** - * Flag this as deliberatly generated catch all that rethrows the - * caught exception. This is used for example for generating finally - * expressions - */ - public void setIsSyntheticRethrow() { - this.isSyntheticRethrow = true; - } - - /** * Get the identifier representing the exception thrown * @return the exception identifier */ @@ -146,9 +121,13 @@ public class CatchNode extends Node { /** * Reset the exception condition for this catch block * @param exceptionCondition the new exception condition + * @return new or same CatchNode */ - public void setExceptionCondition(final Node exceptionCondition) { - this.exceptionCondition = exceptionCondition; + public CatchNode setExceptionCondition(final Node exceptionCondition) { + if (this.exceptionCondition == exceptionCondition) { + return this; + } + return new CatchNode(this, exception, exceptionCondition, body); } /** @@ -158,4 +137,18 @@ public class CatchNode extends Node { public Block getBody() { return body; } + + private CatchNode setException(final IdentNode exception) { + if (this.exception == exception) { + return this; + } + return new CatchNode(this, exception, exceptionCondition, body); + } + + private CatchNode setBody(final Block body) { + if (this.body == body) { + return this; + } + return new CatchNode(this, exception, exceptionCondition, body); + } } |