mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-20 07:15:31 +00:00
8015693: reduce NodeLiteralNode to NullLiteralNode
Reviewed-by: jlaskey, lagergren
This commit is contained in:
parent
91a299799e
commit
8bcbbe70de
@ -28,7 +28,6 @@ package jdk.nashorn.internal.ir;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||
@ -242,8 +241,8 @@ public abstract class LiteralNode<T> extends Node implements PropertyKey {
|
||||
*
|
||||
* @return the new literal node
|
||||
*/
|
||||
public static LiteralNode<Node> newInstance(final long token, final int finish) {
|
||||
return new NodeLiteralNode(token, finish);
|
||||
public static LiteralNode<Object> newInstance(final long token, final int finish) {
|
||||
return new NullLiteralNode(token, finish);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,8 +252,8 @@ public abstract class LiteralNode<T> extends Node implements PropertyKey {
|
||||
*
|
||||
* @return the new literal node
|
||||
*/
|
||||
public static LiteralNode<?> newInstance(final Node parent) {
|
||||
return new NodeLiteralNode(parent.getToken(), parent.getFinish());
|
||||
public static LiteralNode<Object> newInstance(final Node parent) {
|
||||
return new NullLiteralNode(parent.getToken(), parent.getFinish());
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@ -496,33 +495,15 @@ public abstract class LiteralNode<T> extends Node implements PropertyKey {
|
||||
return new LexerTokenLiteralNode(parent.getToken(), parent.getFinish(), value);
|
||||
}
|
||||
|
||||
private static final class NodeLiteralNode extends LiteralNode<Node> {
|
||||
private static final class NullLiteralNode extends LiteralNode<Object> {
|
||||
|
||||
private NodeLiteralNode(final long token, final int finish) {
|
||||
this(token, finish, null);
|
||||
}
|
||||
|
||||
private NodeLiteralNode(final long token, final int finish, final Node value) {
|
||||
super(Token.recast(token, TokenType.OBJECT), finish, value);
|
||||
}
|
||||
|
||||
private NodeLiteralNode(final LiteralNode<Node> literalNode) {
|
||||
super(literalNode);
|
||||
}
|
||||
|
||||
private NodeLiteralNode(final LiteralNode<Node> literalNode, final Node value) {
|
||||
super(literalNode, value);
|
||||
private NullLiteralNode(final long token, final int finish) {
|
||||
super(Token.recast(token, TokenType.OBJECT), finish, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
|
||||
if (visitor.enterLiteralNode(this)) {
|
||||
if (value != null) {
|
||||
final Node newValue = value.accept(visitor);
|
||||
if(value != newValue) {
|
||||
return visitor.leaveLiteralNode(new NodeLiteralNode(this, newValue));
|
||||
}
|
||||
}
|
||||
return visitor.leaveLiteralNode(this);
|
||||
}
|
||||
|
||||
@ -531,38 +512,13 @@ public abstract class LiteralNode<T> extends Node implements PropertyKey {
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return value == null ? Type.OBJECT : super.getType();
|
||||
return Type.OBJECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getWidestOperationType() {
|
||||
return value == null ? Type.OBJECT : value.getWidestOperationType();
|
||||
return Type.OBJECT;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Create a new node literal for an arbitrary node
|
||||
*
|
||||
* @param token token
|
||||
* @param finish finish
|
||||
* @param value the literal value node
|
||||
*
|
||||
* @return the new literal node
|
||||
*/
|
||||
public static LiteralNode<Node> newInstance(final long token, final int finish, final Node value) {
|
||||
return new NodeLiteralNode(token, finish, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new node literal based on a parent node (source, token, finish)
|
||||
*
|
||||
* @param parent parent node
|
||||
* @param value node value
|
||||
*
|
||||
* @return the new literal node
|
||||
*/
|
||||
public static LiteralNode<?> newInstance(final Node parent, final Node value) {
|
||||
return new NodeLiteralNode(parent.getToken(), parent.getFinish(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user