protected int diffAssignop(JCAssignOp oldT, JCAssignOp newT, int[] bounds) { int localPointer = bounds[0]; // lhs int[] lhsBounds = getBounds(oldT.lhs); copyTo(localPointer, lhsBounds[0]); localPointer = diffTree(oldT.lhs, newT.lhs, lhsBounds); if (oldT.getTag() != newT.getTag()) { // todo (#pf): operatorName() does not work copyTo(localPointer, oldT.pos); printer.print(getAssignementOperator(newT)); localPointer = oldT.pos + getAssignementOperator(oldT).length(); } // rhs int[] rhsBounds = getBounds(oldT.rhs); copyTo(localPointer, rhsBounds[0]); localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds); copyTo(localPointer, bounds[1]); return bounds[1]; }
public void visitAssignop(JCAssignOp tree) { // Attribute arguments. Type owntype = attribTree(tree.lhs, env, VAR, Type.noType); Type operand = attribExpr(tree.rhs, env); // Find operator. Symbol operator = tree.operator = rs.resolveBinaryOperator( tree.pos(), tree.getTag() - JCTree.ASGOffset, env, owntype, operand); if (operator.kind == MTH && !owntype.isErroneous() && !operand.isErroneous()) { chk.checkOperator(tree.pos(), (OperatorSymbol)operator, tree.getTag() - JCTree.ASGOffset, owntype, operand); chk.checkDivZero(tree.rhs.pos(), operator, operand); chk.checkCastable(tree.rhs.pos(), operator.type.getReturnType(), owntype); } result = check(tree, owntype, VAL, pkind, pt); }
public void visitAssignop(JCAssignOp that) { try { print("JCAssignOp:"); } catch (Exception e) { } super.visitAssignop(that); }
public void visitAssignop(JCAssignOp tree) { try { open(prec, TreeInfo.assignopPrec); printExpr(tree.lhs, TreeInfo.assignopPrec + 1); String opname = operatorName(treeTag(tree)); print(" " + opname + " "); printExpr(tree.rhs, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public void visitAssignop(JCAssignOp tree) { printNode(tree); child("lhs", tree.lhs); property("(operator)", operatorName(getTag(tree) - JCTree.ASGOffset) + "="); child("rhs", tree.rhs); indent--; }
@Override public void visitAssignop(JCAssignOp node) { BinaryExpression expr = new BinaryExpression(); expr.rawRight(toTree(node.getExpression())); expr.rawLeft(toTree(node.getVariable())); expr.astOperator(JcTreeBuilder.BINARY_OPERATORS.inverse().get(getTag(node))); set(node, expr); }
@Override public Choice<State<JCAssignOp>> visitCompoundAssignment( final CompoundAssignmentTree node, State<?> state) { return chooseSubtrees( state, s -> unifyExpression(node.getVariable(), s), s -> unifyExpression(node.getExpression(), s), (var, expr) -> maker().Assignop(((JCAssignOp) node).getTag(), var, expr)) .condition(assignOp -> !(assignOp.result().getVariable() instanceof PlaceholderParamIdent)); }
@Override public JCAssignOp inline(Inliner inliner) throws CouldNotResolveImportException { return inliner .maker() .Assignop( TAG.get(getKind()), getVariable().inline(inliner), getExpression().inline(inliner)); }
public void visitAssignop(JCAssignOp tree) { try { open(prec, TreeInfo.assignopPrec); printExpr(tree.lhs, TreeInfo.assignopPrec + 1); print(" " + operatorName(tree.getTag() - JCTree.ASGOffset) + "= "); printExpr(tree.rhs, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec); } catch (IOException e) { throw new UncheckedIOException(e); } }
public void visitAssignop(JCAssignOp tree) { try { open(prec, TreeInfo.assignopPrec); printExpr(tree.lhs, TreeInfo.assignopPrec + 1); print(" " + operatorName(getTag(tree) - JCTree.ASGOffset) + "= "); printExpr(tree.rhs, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec); } catch (IOException e) { throw new UncheckedIOException(e); } }
private boolean matchAssignop(JCAssignOp t1, JCAssignOp t2) { return t1.operator == t2.operator && treesMatch(t1.lhs, t2.lhs) && treesMatch(t1.rhs, t2.rhs); }
public JCAssignOp Assignop(TreeTag opcode, JCTree lhs, JCTree rhs) { return invoke(Assignop, opcode.value, lhs, rhs); }
@Override public void visitAssignop(JCAssignOp tree) { print(tree.lhs); String opname = operator(treeTag(tree)); print(" " + opname + " "); print(tree.rhs); }
public AJCAssignOp(JCAssignOp ltree) { super(ltree.getTag(), ltree.lhs, ltree.rhs, ltree.operator); }
public AJCAssignOp(JCAssignOp ltree, String lcomment) { this(ltree); setComment(lcomment); }
/** * Returns the precedence level appropriate for unambiguously printing * leaf as a subexpression of its parent. */ private static int getPrecedence(JCTree leaf, Context context) { JCCompilationUnit comp = context.get(JCCompilationUnit.class); JCTree parent = TreeInfo.pathFor(leaf, comp).get(1); // In general, this should match the logic in com.sun.tools.javac.tree.Pretty. // // TODO(mdempsky): There are probably cases where we could omit parentheses // by tweaking the returned precedence, but they need careful review. // For example, consider a template to replace "add(a, b)" with "a + b", // which applied to "x + add(y, z)" would result in "x + (y + z)". // In most cases, we'd likely prefer "x + y + z" instead, but those aren't // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due // to integer promotion rules. if (parent instanceof JCConditional) { // This intentionally differs from Pretty, because Pretty appears buggy: // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html JCConditional conditional = (JCConditional) parent; return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0); } else if (parent instanceof JCAssign) { JCAssign assign = (JCAssign) parent; return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0); } else if (parent instanceof JCAssignOp) { JCAssignOp assignOp = (JCAssignOp) parent; return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0); } else if (parent instanceof JCUnary) { return TreeInfo.opPrec(parent.getTag()); } else if (parent instanceof JCBinary) { JCBinary binary = (JCBinary) parent; return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0); } else if (parent instanceof JCTypeCast) { JCTypeCast typeCast = (JCTypeCast) parent; return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec; } else if (parent instanceof JCInstanceOf) { JCInstanceOf instanceOf = (JCInstanceOf) parent; return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0); } else if (parent instanceof JCArrayAccess) { JCArrayAccess arrayAccess = (JCArrayAccess) parent; return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec; } else if (parent instanceof JCFieldAccess) { JCFieldAccess fieldAccess = (JCFieldAccess) parent; return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec; } else { return TreeInfo.noPrec; } }
@Override public JCAssignOp inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().Assignop( TAG.get(getKind()), getVariable().inline(inliner), getExpression().inline(inliner)); }
/** * Returns the precedence level appropriate for unambiguously printing leaf as a subexpression of * its parent. */ private static int getPrecedence(JCTree leaf, Context context) { JCCompilationUnit comp = context.get(JCCompilationUnit.class); JCTree parent = TreeInfo.pathFor(leaf, comp).get(1); // In general, this should match the logic in com.sun.tools.javac.tree.Pretty. // // TODO(mdempsky): There are probably cases where we could omit parentheses // by tweaking the returned precedence, but they need careful review. // For example, consider a template to replace "add(a, b)" with "a + b", // which applied to "x + add(y, z)" would result in "x + (y + z)". // In most cases, we'd likely prefer "x + y + z" instead, but those aren't // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due // to integer promotion rules. if (parent instanceof JCConditional) { // This intentionally differs from Pretty, because Pretty appears buggy: // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html JCConditional conditional = (JCConditional) parent; return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0); } else if (parent instanceof JCAssign) { JCAssign assign = (JCAssign) parent; return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0); } else if (parent instanceof JCAssignOp) { JCAssignOp assignOp = (JCAssignOp) parent; return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0); } else if (parent instanceof JCUnary) { return TreeInfo.opPrec(parent.getTag()); } else if (parent instanceof JCBinary) { JCBinary binary = (JCBinary) parent; return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0); } else if (parent instanceof JCTypeCast) { JCTypeCast typeCast = (JCTypeCast) parent; return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec; } else if (parent instanceof JCInstanceOf) { JCInstanceOf instanceOf = (JCInstanceOf) parent; return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0); } else if (parent instanceof JCArrayAccess) { JCArrayAccess arrayAccess = (JCArrayAccess) parent; return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec; } else if (parent instanceof JCFieldAccess) { JCFieldAccess fieldAccess = (JCFieldAccess) parent; return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec; } else { return TreeInfo.noPrec; } }
@Override public void visitAssignop(JCAssignOp that) { if (that.operator == null) that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); super.visitAssignop(that); }
/** * @return identifier which is being incremented by constant one. Returns null if no such * identifier is found. */ private IdentifierTree getIncrementedIdentifer(JCStatement statement) { if (statement == null) { return null; } if (statement.getKind() == Kind.EXPRESSION_STATEMENT) { Tree.Kind kind = ((JCExpressionStatement) statement).getExpression().getKind(); if (kind == Kind.PREFIX_INCREMENT || kind == Kind.POSTFIX_INCREMENT) { JCUnary unary = (JCUnary) ((JCExpressionStatement) statement).getExpression(); if (unary.arg.getKind() == Kind.IDENTIFIER) { return (IdentifierTree) unary.arg; } return null; } else if (kind == Kind.PLUS_ASSIGNMENT) { JCAssignOp assignOp = (JCAssignOp) ((JCExpressionStatement) statement).getExpression(); if (assignOp.lhs.getKind() == Kind.IDENTIFIER && (isConstantOne(assignOp.rhs))) { return (IdentifierTree) assignOp.lhs; } } else if (kind == Kind.ASSIGNMENT) { JCAssign assign = (JCAssign) ((JCExpressionStatement) statement).getExpression(); if (assign.lhs.getKind() == Kind.IDENTIFIER && assign.rhs.getKind() == Kind.PLUS) { JCBinary binary = (JCBinary) assign.rhs; if (binary.lhs.getKind() == Kind.IDENTIFIER) { if (((JCIdent) assign.lhs).sym == ((JCIdent) binary.lhs).sym) { if (isConstantOne(binary.rhs)) { return (IdentifierTree) binary.lhs; } } } if (binary.rhs.getKind() == Kind.IDENTIFIER) { if (((JCIdent) assign.lhs).sym == ((JCIdent) binary.rhs).sym) { if (isConstantOne(binary.lhs)) { return (IdentifierTree) binary.rhs; } } } } } } return null; }