Java Code Examples for jdk.nashorn.internal.ir.BinaryNode#lhs()
The following examples show how to use
jdk.nashorn.internal.ir.BinaryNode#lhs() .
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: OptimisticTypesCalculator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public boolean enterBinaryNode(final BinaryNode binaryNode) { if(binaryNode.isAssignment()) { final Expression lhs = binaryNode.lhs(); if(!binaryNode.isSelfModifying()) { tagNeverOptimistic(lhs); } if(lhs instanceof IdentNode) { final Symbol symbol = ((IdentNode)lhs).getSymbol(); // Assignment to internal symbols is never optimistic, except for self-assignment expressions if(symbol.isInternal() && !binaryNode.rhs().isSelfModifying()) { tagNeverOptimistic(binaryNode.rhs()); } } } else if(binaryNode.isTokenType(TokenType.INSTANCEOF)) { tagNeverOptimistic(binaryNode.lhs()); tagNeverOptimistic(binaryNode.rhs()); } return true; }
Example 2
Source File: CodeGenerator.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public boolean enterADD(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); final Type type = binaryNode.getType(); if (type.isNumeric()) { enterNumericAdd(lhs, rhs, type, binaryNode.getSymbol()); } else { loadBinaryOperands(binaryNode); method.add(); method.store(binaryNode.getSymbol()); } return false; }
Example 3
Source File: Attr.java From nashorn with GNU General Public License v2.0 | 6 votes |
/** * This is a helper called before an assignment. * @param binaryNode assignment node */ private boolean enterAssignmentNode(final BinaryNode binaryNode) { start(binaryNode); final Node lhs = binaryNode.lhs(); if (lhs instanceof IdentNode) { final Block block = lc.getCurrentBlock(); final IdentNode ident = (IdentNode)lhs; final String name = ident.getName(); Symbol symbol = findSymbol(block, name); if (symbol == null) { symbol = defineSymbol(block, name, IS_GLOBAL); } else { maybeForceScope(symbol); } addLocalDef(name); } return true; }
Example 4
Source File: OptimisticTypesCalculator.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public boolean enterBinaryNode(final BinaryNode binaryNode) { if(binaryNode.isAssignment()) { final Expression lhs = binaryNode.lhs(); if(!binaryNode.isSelfModifying()) { tagNeverOptimistic(lhs); } if(lhs instanceof IdentNode) { final Symbol symbol = ((IdentNode)lhs).getSymbol(); // Assignment to internal symbols is never optimistic, except for self-assignment expressions if(symbol.isInternal() && !binaryNode.rhs().isSelfModifying()) { tagNeverOptimistic(binaryNode.rhs()); } } } else if(binaryNode.isTokenType(TokenType.INSTANCEOF)) { tagNeverOptimistic(binaryNode.lhs()); tagNeverOptimistic(binaryNode.rhs()); } return true; }
Example 5
Source File: Attr.java From nashorn with GNU General Public License v2.0 | 6 votes |
/** * This assign helper is called after an assignment, when all children of * the assign has been processed. It fixes the types and recursively makes * sure that everyhing has slots that should have them in the chain. * * @param binaryNode assignment node */ private Node leaveAssignmentNode(final BinaryNode binaryNode) { BinaryNode newBinaryNode = binaryNode; final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); final Type type; if (rhs.getType().isNumeric()) { type = Type.widest(binaryNode.lhs().getType(), binaryNode.rhs().getType()); } else { type = Type.OBJECT; //force lhs to be an object if not numeric assignment, e.g. strings too. } newType(lhs.getSymbol(), type); return end(ensureSymbol(type, newBinaryNode)); }
Example 6
Source File: LocalVariableTypesCalculator.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override public boolean enterBinaryNode(final BinaryNode binaryNode) { // NOTE: regardless of operator's lexical associativity, lhs is always evaluated first. final Expression lhs = binaryNode.lhs(); final LvarType lhsType; if (!(lhs instanceof IdentNode && binaryNode.isTokenType(TokenType.ASSIGN))) { lhsType = visitExpression(lhs); } else { // Can't visit IdentNode on LHS of a simple assignment, as visits imply use, and this is def. // The type is irrelevant, as only RHS is used to determine the type anyway. lhsType = LvarType.UNDEFINED; } final boolean isLogical = binaryNode.isLogical(); final Label joinLabel = isLogical ? new Label("") : null; if(isLogical) { jumpToLabel((JoinPredecessor)lhs, joinLabel); } final Expression rhs = binaryNode.rhs(); final LvarType rhsType = visitExpression(rhs); if(isLogical) { jumpToLabel((JoinPredecessor)rhs, joinLabel); } joinOnLabel(joinLabel); final LvarType type = toLvarType(binaryNode.setOperands(lhsType.typeExpression, rhsType.typeExpression).getType()); if(binaryNode.isAssignment() && lhs instanceof IdentNode) { if(binaryNode.isSelfModifying()) { onSelfAssignment((IdentNode)lhs, type); } else { onAssignment((IdentNode)lhs, type); } } typeStack.push(type); return false; }
Example 7
Source File: Attr.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * This assign helper is called after an assignment, when all children of * the assign has been processed. It fixes the types and recursively makes * sure that everyhing has slots that should have them in the chain. * * @param binaryNode assignment node */ private Node leaveAssignmentNode(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); final Type type; if (lhs instanceof IdentNode) { final Block block = lc.getCurrentBlock(); final IdentNode ident = (IdentNode)lhs; final String name = ident.getName(); final Symbol symbol = findSymbol(block, name); if (symbol == null) { defineSymbol(block, name, IS_GLOBAL); } else { maybeForceScope(symbol); } addLocalDef(name); } if (rhs.getType().isNumeric()) { type = Type.widest(lhs.getType(), rhs.getType()); } else { type = Type.OBJECT; //force lhs to be an object if not numeric assignment, e.g. strings too. } newType(lhs.getSymbol(), type); return end(ensureSymbol(type, binaryNode)); }
Example 8
Source File: LocalVariableTypesCalculator.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public boolean enterBinaryNode(final BinaryNode binaryNode) { // NOTE: regardless of operator's lexical associativity, lhs is always evaluated first. final Expression lhs = binaryNode.lhs(); final LvarType lhsType; if (!(lhs instanceof IdentNode && binaryNode.isTokenType(TokenType.ASSIGN))) { lhsType = visitExpression(lhs); } else { // Can't visit IdentNode on LHS of a simple assignment, as visits imply use, and this is def. // The type is irrelevant, as only RHS is used to determine the type anyway. lhsType = LvarType.UNDEFINED; } final boolean isLogical = binaryNode.isLogical(); final Label joinLabel = isLogical ? new Label("") : null; if(isLogical) { jumpToLabel((JoinPredecessor)lhs, joinLabel); } final Expression rhs = binaryNode.rhs(); final LvarType rhsType = visitExpression(rhs); if(isLogical) { jumpToLabel((JoinPredecessor)rhs, joinLabel); } joinOnLabel(joinLabel); final LvarType type = toLvarType(binaryNode.setOperands(lhsType.typeExpression, rhsType.typeExpression).getType()); if(binaryNode.isAssignment() && lhs instanceof IdentNode) { if(binaryNode.isSelfModifying()) { onSelfAssignment((IdentNode)lhs, type); } else { onAssignment((IdentNode)lhs, type); } } typeStack.push(type); return false; }
Example 9
Source File: CodeGenerator.java From nashorn with GNU General Public License v2.0 | 5 votes |
private boolean enterComma(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); load(lhs); load(rhs); method.store(binaryNode.getSymbol()); return false; }
Example 10
Source File: AssignSymbols.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private Node leaveASSIGN(final BinaryNode binaryNode) { // If we're assigning a property of the this object ("this.foo = ..."), record it. final Expression lhs = binaryNode.lhs(); if (lhs instanceof AccessNode) { final AccessNode accessNode = (AccessNode) lhs; final Expression base = accessNode.getBase(); if (base instanceof IdentNode) { final Symbol symbol = ((IdentNode)base).getSymbol(); if(symbol.isThis()) { thisProperties.peek().add(accessNode.getProperty()); } } } return binaryNode; }
Example 11
Source File: Attr.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * Add is a special binary, as it works not only on arithmetic, but for * strings etc as well. */ @Override public Node leaveADD(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); ensureTypeNotUnknown(lhs); ensureTypeNotUnknown(rhs); //even if we are adding two known types, this can overflow. i.e. //int and number -> number. //int and int are also number though. //something and object is object return end(ensureSymbol(Type.widest(arithType(), Type.widest(lhs.getType(), rhs.getType())), binaryNode)); }
Example 12
Source File: AssignSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private Node leaveASSIGN(final BinaryNode binaryNode) { // If we're assigning a property of the this object ("this.foo = ..."), record it. final Expression lhs = binaryNode.lhs(); if (lhs instanceof AccessNode) { final AccessNode accessNode = (AccessNode) lhs; final Expression base = accessNode.getBase(); if (base instanceof IdentNode) { final Symbol symbol = ((IdentNode)base).getSymbol(); if(symbol.isThis()) { thisProperties.peek().add(accessNode.getProperty()); } } } return binaryNode; }
Example 13
Source File: Lower.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public boolean enterASSIGN(BinaryNode binaryNode) { if (es6 && (binaryNode.lhs() instanceof ObjectNode || binaryNode.lhs() instanceof ArrayLiteralNode)) { throwNotImplementedYet("es6.destructuring", binaryNode); } return super.enterASSIGN(binaryNode); }
Example 14
Source File: Attr.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public Node leaveASSIGN_ADD(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); final Type widest = Type.widest(lhs.getType(), rhs.getType()); //Type.NUMBER if we can't prove that the add doesn't overflow. todo return leaveSelfModifyingAssignmentNode(binaryNode, widest.isNumeric() ? Type.NUMBER : Type.OBJECT); }
Example 15
Source File: RangeAnalyzer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Check for a loop counter. This is currently quite conservative, in that it only handles * x <= counter and x < counter. * * @param node loop node to check * @return */ private static Symbol findLoopCounter(final LoopNode node) { final Expression test = node.getTest(); if (test != null && test.isComparison()) { final BinaryNode binaryNode = (BinaryNode)test; final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); //detect ident cmp int_literal if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) { final Symbol symbol = lhs.getSymbol(); final int margin = ((LiteralNode<?>)rhs).getInt32(); final TokenType op = test.tokenType(); switch (op) { case LT: case LE: symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin))); return symbol; case GT: case GE: //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin)); //return symbol; default: break; } } } return null; }
Example 16
Source File: RangeAnalyzer.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * Check for a loop counter. This is currently quite conservative, in that it only handles * x <= counter and x < counter. * * @param node loop node to check * @return */ private static Symbol findLoopCounter(final LoopNode node) { final Expression test = node.getTest(); if (test != null && test.isComparison()) { final BinaryNode binaryNode = (BinaryNode)test; final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); //detect ident cmp int_literal if (lhs instanceof IdentNode && rhs instanceof LiteralNode && ((LiteralNode<?>)rhs).getType().isInteger()) { final Symbol symbol = lhs.getSymbol(); final int margin = ((LiteralNode<?>)rhs).getInt32(); final TokenType op = test.tokenType(); switch (op) { case LT: case LE: symbol.setRange(RANGE.join(symbol.getRange(), Range.createRange(op == TokenType.LT ? margin - 1 : margin))); return symbol; case GT: case GE: //setRange(lhs, Range.createRange(op == TokenType.GT ? margin + 1 : margin)); //return symbol; default: break; } } } return null; }
Example 17
Source File: LocalVariableTypesCalculator.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public boolean enterBinaryNode(final BinaryNode binaryNode) { // NOTE: regardless of operator's lexical associativity, lhs is always evaluated first. final Expression lhs = binaryNode.lhs(); final LvarType lhsType; if (!(lhs instanceof IdentNode && binaryNode.isTokenType(TokenType.ASSIGN))) { lhsType = visitExpression(lhs); } else { // Can't visit IdentNode on LHS of a simple assignment, as visits imply use, and this is def. // The type is irrelevant, as only RHS is used to determine the type anyway. lhsType = LvarType.UNDEFINED; } final boolean isLogical = binaryNode.isLogical(); final Label joinLabel = isLogical ? new Label("") : null; if(isLogical) { jumpToLabel((JoinPredecessor)lhs, joinLabel); } final Expression rhs = binaryNode.rhs(); final LvarType rhsType = visitExpression(rhs); if(isLogical) { jumpToLabel((JoinPredecessor)rhs, joinLabel); } joinOnLabel(joinLabel); final LvarType type = toLvarType(binaryNode.setOperands(lhsType.typeExpression, rhsType.typeExpression).getType()); if(binaryNode.isAssignment() && lhs instanceof IdentNode) { if(binaryNode.isSelfModifying()) { onSelfAssignment((IdentNode)lhs, type); } else { onAssignment((IdentNode)lhs, type); } } typeStack.push(type); return false; }
Example 18
Source File: Attr.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private Node leaveSelfModifyingAssignmentNode(final BinaryNode binaryNode, final Type destType) { //e.g. for -=, Number, no wider, destType (binaryNode.getWidestOperationType()) is the coerce type final Expression lhs = binaryNode.lhs(); newType(lhs.getSymbol(), destType); //may not narrow if dest is already wider than destType return end(ensureSymbol(destType, binaryNode)); }
Example 19
Source File: CodeGenerator.java From nashorn with GNU General Public License v2.0 | 2 votes |
/** * Constructor * * @param opType type of the computation - overriding the type of the node * @param node the assign op node */ AssignOp(final Type opType, final BinaryNode node) { super(node, node.lhs()); this.opType = opType; }
Example 20
Source File: CodeGenerator.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Constructor * * @param opType type of the computation - overriding the type of the node * @param node the assign op node */ AssignOp(final Type opType, final BinaryNode node) { super(node, node.lhs()); this.opType = opType; }