jdk.nashorn.internal.ir.visitor.NodeVisitor Java Examples
The following examples show how to use
jdk.nashorn.internal.ir.visitor.NodeVisitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VarNode.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Assist in IR navigation. * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterVarNode(this)) { // var is right associative, so visit init before name final Expression newInit = init == null ? null : (Expression)init.accept(visitor); final IdentNode newName = (IdentNode)name.accept(visitor); final VarNode newThis; if (name != newName || init != newInit) { newThis = new VarNode(this, newName, newInit, flags); } else { newThis = this; } return visitor.leaveVarNode(newThis); } return this; }
Example #2
Source File: TryNode.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Assist in IR navigation. * @param visitor IR navigating visitor. */ @Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterTryNode(this)) { // Need to do finallybody first for termination analysis. TODO still necessary? final Block newFinallyBody = finallyBody == null ? null : (Block)finallyBody.accept(visitor); final Block newBody = (Block)body.accept(visitor); return visitor.leaveTryNode( setBody(lc, newBody). setFinallyBody(lc, newFinallyBody). setCatchBlocks(lc, Node.accept(visitor, catchBlocks)). setInlinedFinallies(lc, Node.accept(visitor, inlinedFinallies))); } return this; }
Example #3
Source File: CallNode.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Assist in IR navigation. * * @param visitor IR navigating visitor. * * @return node or replacement */ @Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterCallNode(this)) { final CallNode newCallNode = (CallNode)visitor.leaveCallNode( setFunction((Expression)function.accept(visitor)). setArgs(Node.accept(visitor, args)). setEvalArgs(evalArgs == null ? null : evalArgs.setArgs(Node.accept(visitor, evalArgs.getArgs())))); // Theoretically, we'd need to instead pass lc to every setter and do a replacement on each. In practice, // setType from TypeOverride can't accept a lc, and we don't necessarily want to go there now. if (this != newCallNode) { return Node.replaceInLexicalContext(lc, this, newCallNode); } } return this; }
Example #4
Source File: CallNode.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Assist in IR navigation. * * @param visitor IR navigating visitor. * * @return node or replacement */ @Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterCallNode(this)) { final CallNode newCallNode = (CallNode)visitor.leaveCallNode( setFunction((Expression)function.accept(visitor)). setArgs(Node.accept(visitor, args)). setEvalArgs(evalArgs == null ? null : evalArgs.setArgs(Node.accept(visitor, evalArgs.getArgs())))); // Theoretically, we'd need to instead pass lc to every setter and do a replacement on each. In practice, // setType from TypeOverride can't accept a lc, and we don't necessarily want to go there now. if (this != newCallNode) { return Node.replaceInLexicalContext(lc, this, newCallNode); } } return this; }
Example #5
Source File: CallNode.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Assist in IR navigation. * * @param visitor IR navigating visitor. * * @return node or replacement */ @Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterCallNode(this)) { final CallNode newCallNode = (CallNode)visitor.leaveCallNode( setFunction((Expression)function.accept(visitor)). setArgs(Node.accept(visitor, Expression.class, args)). setFlags(flags). setEvalArgs(evalArgs == null ? null : evalArgs.setCode((Expression)evalArgs.getCode().accept(visitor)). setThis((IdentNode)evalArgs.getThis().accept(visitor)))); // Theoretically, we'd need to instead pass lc to every setter and do a replacement on each. In practice, // setType from TypeOverride can't accept a lc, and we don't necessarily want to go there now. if(this != newCallNode) { return Node.replaceInLexicalContext(lc, this, newCallNode); } } return this; }
Example #6
Source File: IdentNode.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterIdentNode(this)) { return visitor.leaveIdentNode(this); } return this; }
Example #7
Source File: IdentNode.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterIdentNode(this)) { return visitor.leaveIdentNode(this); } return this; }
Example #8
Source File: FunctionNode.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterFunctionNode(this)) { return visitor.leaveFunctionNode(setBody(lc, (Block)body.accept(visitor))); } return this; }
Example #9
Source File: LiteralNode.java From nashorn with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterLiteralNode(this)) { final List<Expression> oldValue = Arrays.asList(value); final List<Expression> newValue = Node.accept(visitor, Expression.class, oldValue); return visitor.leaveLiteralNode(oldValue != newValue ? setValue(newValue) : this); } return this; }
Example #10
Source File: AccessNode.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterAccessNode(this)) { return visitor.leaveAccessNode( setBase((Expression)base.accept(visitor))); } return this; }
Example #11
Source File: UnaryNode.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterUnaryNode(this)) { return visitor.leaveUnaryNode(setExpression((Expression)expression.accept(visitor))); } return this; }
Example #12
Source File: ReturnNode.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterReturnNode(this)) { if (expression != null) { return visitor.leaveReturnNode(setExpression((Expression)expression.accept(visitor))); } return visitor.leaveReturnNode(this); } return this; }
Example #13
Source File: Node.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
static <T extends Node> List<T> accept(final NodeVisitor<? extends LexicalContext> visitor, final List<T> list) { final int size = list.size(); if (size == 0) { return list; } List<T> newList = null; for (int i = 0; i < size; i++) { final T node = list.get(i); @SuppressWarnings("unchecked") final T newNode = node == null ? null : (T)node.accept(visitor); if (newNode != node) { if (newList == null) { newList = new ArrayList<>(size); for (int j = 0; j < i; j++) { newList.add(list.get(j)); } } newList.add(newNode); } else { if (newList != null) { newList.add(node); } } } return newList == null ? list : newList; }
Example #14
Source File: ClassNode.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterClassNode(this)) { return visitor.leaveClassNode(this); } return this; }
Example #15
Source File: ForNode.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterForNode(this)) { return visitor.leaveForNode( setInit(lc, init == null ? null : (Expression)init.accept(visitor)). setTest(lc, test == null ? null : (JoinPredecessorExpression)test.accept(visitor)). setModify(lc, modify == null ? null : (JoinPredecessorExpression)modify.accept(visitor)). setBody(lc, (Block)body.accept(visitor))); } return this; }
Example #16
Source File: ContinueNode.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterContinueNode(this)) { return visitor.leaveContinueNode(this); } return this; }
Example #17
Source File: TernaryNode.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterTernaryNode(this)) { final Expression newTest = (Expression)getTest().accept(visitor); final JoinPredecessorExpression newTrueExpr = (JoinPredecessorExpression)trueExpr.accept(visitor); final JoinPredecessorExpression newFalseExpr = (JoinPredecessorExpression)falseExpr.accept(visitor); return visitor.leaveTernaryNode(setTest(newTest).setTrueExpression(newTrueExpr).setFalseExpression(newFalseExpr)); } return this; }
Example #18
Source File: WithNode.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * * @param visitor IR navigating visitor. */ @Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterWithNode(this)) { return visitor.leaveWithNode( setExpression(lc, (Expression)expression.accept(visitor)). setBody(lc, (Block)body.accept(visitor))); } return this; }
Example #19
Source File: IndexNode.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterIndexNode(this)) { return visitor.leaveIndexNode( setBase((Expression)base.accept(visitor)). setIndex((Expression)index.accept(visitor))); } return this; }
Example #20
Source File: ExpressionStatement.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterExpressionStatement(this)) { return visitor.leaveExpressionStatement(setExpression((Expression)expression.accept(visitor))); } return this; }
Example #21
Source File: UnaryNode.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterUnaryNode(this)) { return visitor.leaveUnaryNode(setRHS((Expression)rhs.accept(visitor))); } return this; }
Example #22
Source File: CaseNode.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Assist in IR navigation. * @param visitor IR navigating visitor. */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterCaseNode(this)) { final Expression newTest = test == null ? null : (Expression)test.accept(visitor); final Block newBody = body == null ? null : (Block)body.accept(visitor); return visitor.leaveCaseNode(setTest(newTest).setBody(newBody)); } return this; }
Example #23
Source File: FinalizeTypes.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * A symbol (and {@link jdk.nashorn.internal.runtime.Property}) can be tagged as "may be primitive". * This is used a hint for dual fields that it is even worth it to try representing this * field as something other than java.lang.Object. * * @param node node in which to tag symbols as primitive * @param to which primitive type to use for tagging */ private static void setCanBePrimitive(final Node node, final Type to) { final HashSet<Node> exclude = new HashSet<>(); node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { private void setCanBePrimitive(final Symbol symbol) { LOG.info("*** can be primitive symbol ", symbol, " ", Debug.id(symbol)); symbol.setCanBePrimitive(to); } @Override public boolean enterIdentNode(final IdentNode identNode) { if (!exclude.contains(identNode)) { setCanBePrimitive(identNode.getSymbol()); } return false; } @Override public boolean enterAccessNode(final AccessNode accessNode) { setCanBePrimitive(accessNode.getProperty().getSymbol()); return false; } @Override public boolean enterIndexNode(final IndexNode indexNode) { exclude.add(indexNode.getBase()); //prevent array base node to be flagged as primitive, but k in a[k++] is fine return true; } }); }
Example #24
Source File: ReturnNode.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterReturnNode(this)) { if (expression != null) { return visitor.leaveReturnNode(setExpression((Expression)expression.accept(visitor))); } return visitor.leaveReturnNode(this); } return this; }
Example #25
Source File: FunctionNode.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterFunctionNode(this)) { return visitor.leaveFunctionNode(setBody(lc, (Block)body.accept(visitor))); } return this; }
Example #26
Source File: ObjectNode.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterObjectNode(this)) { return visitor.leaveObjectNode(setElements(lc, Node.accept(visitor, elements))); } return this; }
Example #27
Source File: ContinueNode.java From nashorn with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterContinueNode(this)) { return visitor.leaveContinueNode(this); } return this; }
Example #28
Source File: ContinueNode.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterContinueNode(this)) { return visitor.leaveContinueNode(this); } return this; }
Example #29
Source File: BreakNode.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterBreakNode(this)) { return visitor.leaveBreakNode(this); } return this; }
Example #30
Source File: Node.java From hottub with GNU General Public License v2.0 | 5 votes |
static <T extends Node> List<T> accept(final NodeVisitor<? extends LexicalContext> visitor, final List<T> list) { final int size = list.size(); if (size == 0) { return list; } List<T> newList = null; for (int i = 0; i < size; i++) { final T node = list.get(i); @SuppressWarnings("unchecked") final T newNode = node == null ? null : (T)node.accept(visitor); if (newNode != node) { if (newList == null) { newList = new ArrayList<>(size); for (int j = 0; j < i; j++) { newList.add(list.get(j)); } } newList.add(newNode); } else { if (newList != null) { newList.add(node); } } } return newList == null ? list : newList; }