Fri, 31 May 2013 12:56:56 +0200
8015693: reduce NodeLiteralNode to NullLiteralNode
Reviewed-by: jlaskey, lagergren
src/jdk/nashorn/internal/ir/LiteralNode.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/ir/LiteralNode.java Thu May 30 16:49:46 2013 +0530 1.2 +++ b/src/jdk/nashorn/internal/ir/LiteralNode.java Fri May 31 12:56:56 2013 +0200 1.3 @@ -28,7 +28,6 @@ 1.4 import java.util.Arrays; 1.5 import java.util.Collections; 1.6 import java.util.List; 1.7 - 1.8 import jdk.nashorn.internal.codegen.CompileUnit; 1.9 import jdk.nashorn.internal.codegen.types.Type; 1.10 import jdk.nashorn.internal.ir.annotations.Immutable; 1.11 @@ -242,8 +241,8 @@ 1.12 * 1.13 * @return the new literal node 1.14 */ 1.15 - public static LiteralNode<Node> newInstance(final long token, final int finish) { 1.16 - return new NodeLiteralNode(token, finish); 1.17 + public static LiteralNode<Object> newInstance(final long token, final int finish) { 1.18 + return new NullLiteralNode(token, finish); 1.19 } 1.20 1.21 /** 1.22 @@ -253,8 +252,8 @@ 1.23 * 1.24 * @return the new literal node 1.25 */ 1.26 - public static LiteralNode<?> newInstance(final Node parent) { 1.27 - return new NodeLiteralNode(parent.getToken(), parent.getFinish()); 1.28 + public static LiteralNode<Object> newInstance(final Node parent) { 1.29 + return new NullLiteralNode(parent.getToken(), parent.getFinish()); 1.30 } 1.31 1.32 @Immutable 1.33 @@ -496,33 +495,15 @@ 1.34 return new LexerTokenLiteralNode(parent.getToken(), parent.getFinish(), value); 1.35 } 1.36 1.37 - private static final class NodeLiteralNode extends LiteralNode<Node> { 1.38 + private static final class NullLiteralNode extends LiteralNode<Object> { 1.39 1.40 - private NodeLiteralNode(final long token, final int finish) { 1.41 - this(token, finish, null); 1.42 - } 1.43 - 1.44 - private NodeLiteralNode(final long token, final int finish, final Node value) { 1.45 - super(Token.recast(token, TokenType.OBJECT), finish, value); 1.46 - } 1.47 - 1.48 - private NodeLiteralNode(final LiteralNode<Node> literalNode) { 1.49 - super(literalNode); 1.50 - } 1.51 - 1.52 - private NodeLiteralNode(final LiteralNode<Node> literalNode, final Node value) { 1.53 - super(literalNode, value); 1.54 + private NullLiteralNode(final long token, final int finish) { 1.55 + super(Token.recast(token, TokenType.OBJECT), finish, null); 1.56 } 1.57 1.58 @Override 1.59 public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { 1.60 if (visitor.enterLiteralNode(this)) { 1.61 - if (value != null) { 1.62 - final Node newValue = value.accept(visitor); 1.63 - if(value != newValue) { 1.64 - return visitor.leaveLiteralNode(new NodeLiteralNode(this, newValue)); 1.65 - } 1.66 - } 1.67 return visitor.leaveLiteralNode(this); 1.68 } 1.69 1.70 @@ -531,38 +512,13 @@ 1.71 1.72 @Override 1.73 public Type getType() { 1.74 - return value == null ? Type.OBJECT : super.getType(); 1.75 + return Type.OBJECT; 1.76 } 1.77 1.78 @Override 1.79 public Type getWidestOperationType() { 1.80 - return value == null ? Type.OBJECT : value.getWidestOperationType(); 1.81 + return Type.OBJECT; 1.82 } 1.83 - 1.84 - } 1.85 - /** 1.86 - * Create a new node literal for an arbitrary node 1.87 - * 1.88 - * @param token token 1.89 - * @param finish finish 1.90 - * @param value the literal value node 1.91 - * 1.92 - * @return the new literal node 1.93 - */ 1.94 - public static LiteralNode<Node> newInstance(final long token, final int finish, final Node value) { 1.95 - return new NodeLiteralNode(token, finish, value); 1.96 - } 1.97 - 1.98 - /** 1.99 - * Create a new node literal based on a parent node (source, token, finish) 1.100 - * 1.101 - * @param parent parent node 1.102 - * @param value node value 1.103 - * 1.104 - * @return the new literal node 1.105 - */ 1.106 - public static LiteralNode<?> newInstance(final Node parent, final Node value) { 1.107 - return new NodeLiteralNode(parent.getToken(), parent.getFinish(), value); 1.108 } 1.109 1.110 /**