8134502: introduce abstraction for basic NodeVisitor usage

Reviewed-by: lagergren, sundar
This commit is contained in:
Attila Szegedi 2015-09-28 08:40:39 +02:00
parent 96f1486b0a
commit b6c3667ca0
19 changed files with 93 additions and 83 deletions

View File

@ -47,7 +47,6 @@ import jdk.nashorn.internal.ir.IdentNode;
import jdk.nashorn.internal.ir.IfNode;
import jdk.nashorn.internal.ir.IndexNode;
import jdk.nashorn.internal.ir.LabelNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.ObjectNode;
@ -64,7 +63,7 @@ import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.parser.Lexer;
import jdk.nashorn.internal.parser.TokenType;
@ -72,10 +71,9 @@ import jdk.nashorn.internal.parser.TokenType;
* This class translates from nashorn IR Node objects
* to nashorn parser API Tree objects.
*/
final class IRTranslator extends NodeVisitor<LexicalContext> {
final class IRTranslator extends SimpleNodeVisitor {
public IRTranslator() {
super(new LexicalContext());
}
// currently translated Statement

View File

@ -41,9 +41,8 @@ import jdk.nashorn.internal.ir.CallNode;
import jdk.nashorn.internal.ir.Expression;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.IdentNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.logging.DebugLogger;
@ -81,7 +80,7 @@ import jdk.nashorn.internal.runtime.options.Options;
*/
@Logger(name="apply2call")
public final class ApplySpecialization extends NodeVisitor<LexicalContext> implements Loggable {
public final class ApplySpecialization extends SimpleNodeVisitor implements Loggable {
private static final boolean USE_APPLY2CALL = Options.getBooleanProperty("nashorn.apply2call", true);
@ -105,7 +104,6 @@ public final class ApplySpecialization extends NodeVisitor<LexicalContext> imple
* @param compiler compiler
*/
public ApplySpecialization(final Compiler compiler) {
super(new LexicalContext());
this.compiler = compiler;
this.log = initLogger(compiler.getContext());
}
@ -138,7 +136,7 @@ public final class ApplySpecialization extends NodeVisitor<LexicalContext> imple
private boolean hasApplies(final FunctionNode functionNode) {
try {
functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
functionNode.accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode fn) {
return fn == functionNode;
@ -172,7 +170,7 @@ public final class ApplySpecialization extends NodeVisitor<LexicalContext> imple
final Deque<Set<Expression>> stack = new ArrayDeque<>();
//ensure that arguments is only passed as arg to apply
functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
functionNode.accept(new SimpleNodeVisitor() {
private boolean isCurrentArg(final Expression expr) {
return !stack.isEmpty() && stack.peek().contains(expr); //args to current apply call

View File

@ -67,7 +67,6 @@ import jdk.nashorn.internal.ir.ForNode;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.IdentNode;
import jdk.nashorn.internal.ir.IndexNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LexicalContextNode;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.Node;
@ -81,7 +80,7 @@ import jdk.nashorn.internal.ir.TryNode;
import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.parser.TokenType;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.ECMAErrors;
@ -102,7 +101,7 @@ import jdk.nashorn.internal.runtime.logging.Logger;
* visitor.
*/
@Logger(name="symbols")
final class AssignSymbols extends NodeVisitor<LexicalContext> implements Loggable {
final class AssignSymbols extends SimpleNodeVisitor implements Loggable {
private final DebugLogger log;
private final boolean debug;
@ -150,7 +149,6 @@ final class AssignSymbols extends NodeVisitor<LexicalContext> implements Loggabl
private final boolean isOnDemand;
public AssignSymbols(final Compiler compiler) {
super(new LexicalContext());
this.compiler = compiler;
this.log = initLogger(compiler.getContext());
this.debug = log.isEnabled();
@ -187,7 +185,7 @@ final class AssignSymbols extends NodeVisitor<LexicalContext> implements Loggabl
*/
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
// This visitor will assign symbol to all declared variables.
body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
body.accept(new SimpleNodeVisitor() {
@Override
protected boolean enterDefault(final Node node) {
// Don't bother visiting expressions; var is a statement, it can't be inside an expression.

View File

@ -29,19 +29,17 @@ import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.Statement;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
class CacheAst extends NodeVisitor<LexicalContext> {
class CacheAst extends SimpleNodeVisitor {
private final Deque<RecompilableScriptFunctionData> dataStack = new ArrayDeque<>();
private final Compiler compiler;
CacheAst(final Compiler compiler) {
super(new LexicalContext());
this.compiler = compiler;
assert !compiler.isOnDemandCompilation();
}

View File

@ -129,7 +129,7 @@ import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.parser.Lexer.RegexToken;
import jdk.nashorn.internal.parser.TokenType;
@ -1433,8 +1433,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
final Block currentBlock = lc.getCurrentBlock();
final CodeGeneratorLexicalContext codegenLexicalContext = lc;
function.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
function.accept(new SimpleNodeVisitor() {
private MethodEmitter sharedScopeCall(final IdentNode identNode, final int flags) {
final Symbol symbol = identNode.getSymbol();
final boolean isFastScope = isFastScope(symbol);
@ -2461,7 +2460,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
@Override
public Boolean get() {
value.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
value.accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
return false;
@ -2799,7 +2798,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
boolean contains;
@Override
public Boolean get() {
rootExpr.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
rootExpr.accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
return false;
@ -4347,7 +4346,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
* on the stack throughout the store and used at the end to execute it
*/
target.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
target.accept(new SimpleNodeVisitor() {
@Override
public boolean enterIdentNode(final IdentNode node) {
if (node.getSymbol().isScope()) {
@ -4446,7 +4445,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
* need to do a conversion on non-equivalent types exists, but is
* very rare. See for example test/script/basic/access-specializer.js
*/
target.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
target.accept(new SimpleNodeVisitor() {
@Override
protected boolean enterDefault(final Node node) {
throw new AssertionError("Unexpected node " + node + " in store epilogue");

View File

@ -36,13 +36,13 @@ import java.util.Set;
import jdk.nashorn.internal.codegen.Compiler.CompilationPhases;
import jdk.nashorn.internal.ir.Block;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.Symbol;
import jdk.nashorn.internal.ir.debug.ASTWriter;
import jdk.nashorn.internal.ir.debug.PrintVisitor;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.runtime.CodeInstaller;
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
import jdk.nashorn.internal.runtime.ScriptEnvironment;
@ -118,7 +118,7 @@ abstract class CompilationPhase {
FunctionNode newFunctionNode;
//ensure elementTypes, postsets and presets exist for splitter and arraynodes
newFunctionNode = transformFunction(fn, new NodeVisitor<LexicalContext>(new LexicalContext()) {
newFunctionNode = transformFunction(fn, new SimpleNodeVisitor() {
@Override
public LiteralNode<?> leaveLiteralNode(final LiteralNode<?> literalNode) {
return literalNode.initialize(lc);
@ -222,7 +222,7 @@ abstract class CompilationPhase {
// correctness, it's just an optimization -- runtime type calculation is not used when the compilation
// is not an on-demand optimistic compilation, so we can skip locals marking then.
if (compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
fn.getBody().accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
fn.getBody().accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
// OTOH, we must not declare symbols from nested functions to be locals. As we're doing on-demand

View File

@ -39,7 +39,7 @@ import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.Symbol;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
import jdk.nashorn.internal.runtime.logging.DebugLogger;
@ -53,7 +53,7 @@ import jdk.nashorn.internal.runtime.logging.Logger;
* FunctionNode being compiled
*/
@Logger(name="scopedepths")
final class FindScopeDepths extends NodeVisitor<LexicalContext> implements Loggable {
final class FindScopeDepths extends SimpleNodeVisitor implements Loggable {
private final Compiler compiler;
private final Map<Integer, Map<Integer, RecompilableScriptFunctionData>> fnIdToNestedFunctions = new HashMap<>();
@ -66,7 +66,6 @@ final class FindScopeDepths extends NodeVisitor<LexicalContext> implements Logga
private int dynamicScopeCount;
FindScopeDepths(final Compiler compiler) {
super(new LexicalContext());
this.compiler = compiler;
this.log = initLogger(compiler.getContext());
}
@ -273,7 +272,7 @@ final class FindScopeDepths extends NodeVisitor<LexicalContext> implements Logga
//get all symbols that are referenced inside this function body
final Set<Symbol> symbols = new HashSet<>();
block.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
block.accept(new SimpleNodeVisitor() {
@Override
public boolean enterIdentNode(final IdentNode identNode) {
final Symbol symbol = identNode.getSymbol();

View File

@ -38,7 +38,6 @@ import jdk.nashorn.internal.ir.EmptyNode;
import jdk.nashorn.internal.ir.Expression;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.IfNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
import jdk.nashorn.internal.ir.Node;
@ -47,7 +46,7 @@ import jdk.nashorn.internal.ir.SwitchNode;
import jdk.nashorn.internal.ir.TernaryNode;
import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.ScriptRuntime;
@ -59,12 +58,11 @@ import jdk.nashorn.internal.runtime.logging.Logger;
* Simple constant folding pass, executed before IR is starting to be lowered.
*/
@Logger(name="fold")
final class FoldConstants extends NodeVisitor<LexicalContext> implements Loggable {
final class FoldConstants extends SimpleNodeVisitor implements Loggable {
private final DebugLogger log;
FoldConstants(final Compiler compiler) {
super(new LexicalContext());
this.log = initLogger(compiler.getContext());
}
@ -194,7 +192,7 @@ final class FoldConstants extends NodeVisitor<LexicalContext> implements Loggabl
* initializers removed.
*/
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
deadCodeRoot.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
deadCodeRoot.accept(new SimpleNodeVisitor() {
@Override
public boolean enterVarNode(final VarNode varNode) {
statements.add(varNode.setInit(null));

View File

@ -87,6 +87,7 @@ import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.parser.TokenType;
/**
@ -105,7 +106,7 @@ import jdk.nashorn.internal.parser.TokenType;
* instances of the calculator to be run on nested functions (when not lazy compiling).
*
*/
final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
final class LocalVariableTypesCalculator extends SimpleNodeVisitor {
private static class JumpOrigin {
final JoinPredecessor node;
@ -425,7 +426,6 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
private final Deque<Label> catchLabels = new ArrayDeque<>();
LocalVariableTypesCalculator(final Compiler compiler) {
super(new LexicalContext());
this.compiler = compiler;
}
@ -1330,7 +1330,7 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
// Sets the return type of the function and also performs the bottom-up pass of applying type and conversion
// information to nodes as well as doing the calculation on nested functions as required.
FunctionNode newFunction = functionNode;
final NodeVisitor<LexicalContext> applyChangesVisitor = new NodeVisitor<LexicalContext>(new LexicalContext()) {
final SimpleNodeVisitor applyChangesVisitor = new SimpleNodeVisitor() {
private boolean inOuterFunction = true;
private final Deque<JoinPredecessor> joinPredecessors = new ArrayDeque<>();

View File

@ -74,7 +74,7 @@ import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.parser.Token;
import jdk.nashorn.internal.parser.TokenType;
import jdk.nashorn.internal.runtime.Context;
@ -331,7 +331,7 @@ final class Lower extends NodeOperatorVisitor<BlockLexicalContext> implements Lo
@SuppressWarnings("unchecked")
private static <T extends Node> T ensureUniqueNamesIn(final T node) {
return (T)node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
return (T)node.accept(new SimpleNodeVisitor() {
@Override
public Node leaveFunctionNode(final FunctionNode functionNode) {
final String name = functionNode.getName();
@ -396,7 +396,7 @@ final class Lower extends NodeOperatorVisitor<BlockLexicalContext> implements Lo
final Block finallyBlock = createFinallyBlock(finallyBody);
final ArrayList<Block> inlinedFinallies = new ArrayList<>();
final FunctionNode fn = lc.getCurrentFunction();
final TryNode newTryNode = (TryNode)tryNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
final TryNode newTryNode = (TryNode)tryNode.accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
@ -539,7 +539,7 @@ final class Lower extends NodeOperatorVisitor<BlockLexicalContext> implements Lo
final Block catchAll = catchAllBlock(tryNode);
final List<ThrowNode> rethrows = new ArrayList<>(1);
catchAll.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
catchAll.accept(new SimpleNodeVisitor() {
@Override
public boolean enterThrowNode(final ThrowNode throwNode) {
rethrows.add(throwNode);
@ -686,7 +686,7 @@ final class Lower extends NodeOperatorVisitor<BlockLexicalContext> implements Lo
private static boolean controlFlowEscapes(final LexicalContext lex, final Block loopBody) {
final List<Node> escapes = new ArrayList<>();
loopBody.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
loopBody.accept(new SimpleNodeVisitor() {
@Override
public Node leaveBreakNode(final BreakNode node) {
escapes.add(node);

View File

@ -42,7 +42,6 @@ import jdk.nashorn.internal.ir.IdentNode;
import jdk.nashorn.internal.ir.IfNode;
import jdk.nashorn.internal.ir.IndexNode;
import jdk.nashorn.internal.ir.JoinPredecessorExpression;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LoopNode;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.Optimistic;
@ -52,7 +51,7 @@ import jdk.nashorn.internal.ir.TernaryNode;
import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.parser.TokenType;
import jdk.nashorn.internal.runtime.ScriptObject;
@ -61,7 +60,7 @@ import jdk.nashorn.internal.runtime.ScriptObject;
* must not ever be marked as optimistic, assigning narrowest non-invalidated types to program points from the
* compilation environment, as well as initializing optimistic types of global properties for scripts.
*/
final class OptimisticTypesCalculator extends NodeVisitor<LexicalContext> {
final class OptimisticTypesCalculator extends SimpleNodeVisitor {
final Compiler compiler;
@ -69,7 +68,6 @@ final class OptimisticTypesCalculator extends NodeVisitor<LexicalContext> {
final Deque<BitSet> neverOptimistic = new ArrayDeque<>();
OptimisticTypesCalculator(final Compiler compiler) {
super(new LexicalContext());
this.compiler = compiler;
}

View File

@ -37,25 +37,20 @@ import jdk.nashorn.internal.ir.Expression;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.IdentNode;
import jdk.nashorn.internal.ir.IndexNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.Optimistic;
import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
/**
* Find program points in the code that are needed for optimistic assumptions
*/
class ProgramPoints extends NodeVisitor<LexicalContext> {
class ProgramPoints extends SimpleNodeVisitor {
private final IntDeque nextProgramPoint = new IntDeque();
private final Set<Node> noProgramPoint = new HashSet<>();
ProgramPoints() {
super(new LexicalContext());
}
private int next() {
final int next = nextProgramPoint.getAndIncrement();
if(next > MAX_PROGRAM_POINT_VALUE) {

View File

@ -27,24 +27,19 @@ package jdk.nashorn.internal.codegen;
import java.util.ArrayList;
import java.util.List;
import jdk.nashorn.internal.ir.CompileUnitHolder;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.ObjectNode;
import jdk.nashorn.internal.ir.Splittable;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
/**
* Base class for a node visitor that replaces {@link CompileUnit}s in {@link CompileUnitHolder}s.
*/
abstract class ReplaceCompileUnits extends NodeVisitor<LexicalContext> {
ReplaceCompileUnits() {
super(new LexicalContext());
}
abstract class ReplaceCompileUnits extends SimpleNodeVisitor {
/**
* Override to provide a replacement for an old compile unit.

View File

@ -33,7 +33,6 @@ import java.util.List;
import java.util.Map;
import jdk.nashorn.internal.ir.Block;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
import jdk.nashorn.internal.ir.Node;
@ -42,7 +41,7 @@ import jdk.nashorn.internal.ir.PropertyNode;
import jdk.nashorn.internal.ir.SplitNode;
import jdk.nashorn.internal.ir.Splittable;
import jdk.nashorn.internal.ir.Statement;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.logging.DebugLogger;
import jdk.nashorn.internal.runtime.logging.Loggable;
@ -53,7 +52,7 @@ import jdk.nashorn.internal.runtime.options.Options;
* Split the IR into smaller compile units.
*/
@Logger(name="splitter")
final class Splitter extends NodeVisitor<LexicalContext> implements Loggable {
final class Splitter extends SimpleNodeVisitor implements Loggable {
/** Current compiler. */
private final Compiler compiler;
@ -79,7 +78,6 @@ final class Splitter extends NodeVisitor<LexicalContext> implements Loggable {
* @param outermostCompileUnit compile unit for outermost function, if non-lazy this is the script's compile unit
*/
public Splitter(final Compiler compiler, final FunctionNode functionNode, final CompileUnit outermostCompileUnit) {
super(new LexicalContext());
this.compiler = compiler;
this.outermost = functionNode;
this.outermostCompileUnit = outermostCompileUnit;
@ -142,7 +140,7 @@ final class Splitter extends NodeVisitor<LexicalContext> implements Loggable {
final Block body = functionNode.getBody();
final List<FunctionNode> dc = directChildren(functionNode);
final Block newBody = (Block)body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
final Block newBody = (Block)body.accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode nestedFunction) {
return dc.contains(nestedFunction);
@ -164,7 +162,7 @@ final class Splitter extends NodeVisitor<LexicalContext> implements Loggable {
private static List<FunctionNode> directChildren(final FunctionNode functionNode) {
final List<FunctionNode> dc = new ArrayList<>();
functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
functionNode.accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode child) {
if (child == functionNode) {

View File

@ -49,7 +49,6 @@ import jdk.nashorn.internal.ir.IfNode;
import jdk.nashorn.internal.ir.IndexNode;
import jdk.nashorn.internal.ir.JoinPredecessorExpression;
import jdk.nashorn.internal.ir.LabelNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LiteralNode;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.ObjectNode;
@ -66,7 +65,7 @@ import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.parser.JSONParser;
import jdk.nashorn.internal.parser.Lexer.RegexToken;
import jdk.nashorn.internal.parser.Parser;
@ -78,7 +77,7 @@ import jdk.nashorn.internal.runtime.Source;
/**
* This IR writer produces a JSON string that represents AST as a JSON string.
*/
public final class JSONWriter extends NodeVisitor<LexicalContext> {
public final class JSONWriter extends SimpleNodeVisitor {
/**
* Returns AST as JSON compatible string.
@ -945,7 +944,6 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
// Internals below
private JSONWriter(final boolean includeLocation) {
super(new LexicalContext());
this.buf = new StringBuilder();
this.includeLocation = includeLocation;
}

View File

@ -41,7 +41,6 @@ import jdk.nashorn.internal.ir.IfNode;
import jdk.nashorn.internal.ir.JoinPredecessor;
import jdk.nashorn.internal.ir.JoinPredecessorExpression;
import jdk.nashorn.internal.ir.LabelNode;
import jdk.nashorn.internal.ir.LexicalContext;
import jdk.nashorn.internal.ir.LocalVariableConversion;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.SplitNode;
@ -53,7 +52,7 @@ import jdk.nashorn.internal.ir.UnaryNode;
import jdk.nashorn.internal.ir.VarNode;
import jdk.nashorn.internal.ir.WhileNode;
import jdk.nashorn.internal.ir.WithNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
/**
* Print out the AST as human readable source code.
@ -61,7 +60,7 @@ import jdk.nashorn.internal.ir.visitor.NodeVisitor;
*
* see the flags --print-parse and --print-lower-parse
*/
public final class PrintVisitor extends NodeVisitor<LexicalContext> {
public final class PrintVisitor extends SimpleNodeVisitor {
/** Tab width */
private static final int TABWIDTH = 4;
@ -96,7 +95,6 @@ public final class PrintVisitor extends NodeVisitor<LexicalContext> {
* @param printTypes should we print optimistic and inferred types?
*/
public PrintVisitor(final boolean printLineNumbers, final boolean printTypes) {
super(new LexicalContext());
this.EOLN = System.lineSeparator();
this.sb = new StringBuilder();
this.printLineNumbers = printLineNumbers;

View File

@ -34,7 +34,7 @@ import jdk.nashorn.internal.ir.UnaryNode;
* Like NodeVisitor but navigating further into operators.
* @param <T> Lexical context class for this NodeOperatorVisitor
*/
public class NodeOperatorVisitor<T extends LexicalContext> extends NodeVisitor<T> {
public abstract class NodeOperatorVisitor<T extends LexicalContext> extends NodeVisitor<T> {
/**
* Constructor
*

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.nashorn.internal.ir.visitor;
import jdk.nashorn.internal.ir.LexicalContext;
/**
* Convenience base class for a {@link NodeVisitor} with a plain {@link LexicalContext}.
*/
public abstract class SimpleNodeVisitor extends NodeVisitor<LexicalContext> {
/**
* Creates a new simple node visitor.
*/
public SimpleNodeVisitor() {
super(new LexicalContext());
}
}

View File

@ -62,7 +62,7 @@ import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.SwitchNode;
import jdk.nashorn.internal.ir.Symbol;
import jdk.nashorn.internal.ir.TryNode;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor;
import jdk.nashorn.internal.objects.Global;
import jdk.nashorn.internal.parser.Parser;
import jdk.nashorn.internal.parser.Token;
@ -518,8 +518,7 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
// don't cache non-split functions from the eager pass); those already cached, or those not split
// don't need this step.
final Set<Symbol> blockDefinedSymbols = fn.isSplit() && !cached ? Collections.newSetFromMap(new IdentityHashMap<>()) : null;
FunctionNode newFn = (FunctionNode)fn.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
FunctionNode newFn = (FunctionNode)fn.accept(new SimpleNodeVisitor() {
private Symbol getReplacement(final Symbol original) {
if (original == null) {
return null;
@ -757,7 +756,7 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
private FunctionNode extractFunctionFromScript(final FunctionNode script) {
final Set<FunctionNode> fns = new HashSet<>();
script.getBody().accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
script.getBody().accept(new SimpleNodeVisitor() {
@Override
public boolean enterFunctionNode(final FunctionNode fn) {
fns.add(fn);