com.sun.tools.javac.tree.JCTree.JCAssignOp Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCAssignOp. 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: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Make an attributed assignop expression.
 *  @param optag    The operators tree tag.
 *  @param lhs      The operator's left argument.
 *  @param rhs      The operator's right argument.
 */
JCAssignOp makeAssignop(JCTree.Tag optag, JCTree lhs, JCTree rhs) {
    JCAssignOp tree = make.Assignop(optag, lhs, rhs);
    tree.operator = operators.resolveBinary(tree, tree.getTag().noAssignOp(), lhs.type, rhs.type);
    tree.type = lhs.type;
    return tree;
}
 
Example #2
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitAssignop(JCAssignOp tree) {
    if (TreeInfo.symbol(tree.lhs) == sym) {
        dependencyFound = true;
        return;
    }
    super.visitAssignop(tree);
}
 
Example #3
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
/** Convert compound assigment. */
private BinaryExpression convertAssignment(JCAssignOp expression) {
  return BinaryExpression.newBuilder()
      .setLeftOperand(convertExpression(expression.getVariable()))
      .setOperator(JavaEnvironment.getBinaryOperator(expression.getKind()))
      .setRightOperand(convertExpression(expression.getExpression()))
      .build();
}
 
Example #4
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #5
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitAssignop(JCAssignOp tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.lhs));
    sr.mergeWith(csp(tree.rhs));
    result = sr;
}
 
Example #6
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitAssignop(JCAssignOp node) {
    node.operator = null;
    super.visitAssignop(node);
}
 
Example #7
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitAssignop(JCAssignOp tree) {
    tree.lhs = translate(tree.lhs, null);
    tree.rhs = translate(tree.rhs, tree.operator.type.getParameterTypes().tail.head);
    tree.type = erasure(tree.type);
    result = tree;
}
 
Example #8
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitAssignop(JCAssignOp tree) {
    scanExpr(tree.lhs);
    scanExpr(tree.rhs);
    letInit(tree.lhs);
}
 
Example #9
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitAssignop(JCAssignOp tree) {
    scan(tree.lhs);
    scan(tree.rhs);
    letInit(tree.lhs);
}
 
Example #10
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Construct definition of an access method.
     *  @param pos        The source code position of the definition.
     *  @param vsym       The private or protected symbol.
     *  @param accessor   The access method for the symbol.
     *  @param acode      The access code.
     */
    JCTree accessDef(int pos, Symbol vsym, MethodSymbol accessor, int acode) {
//      System.err.println("access " + vsym + " with " + accessor);//DEBUG
        currentClass = vsym.owner.enclClass();
        make.at(pos);
        JCMethodDecl md = make.MethodDef(accessor, null);

        // Find actual symbol
        Symbol sym = actualSymbols.get(vsym);
        if (sym == null) sym = vsym;

        JCExpression ref;           // The tree referencing the private symbol.
        List<JCExpression> args;    // Any additional arguments to be passed along.
        if ((sym.flags() & STATIC) != 0) {
            ref = make.Ident(sym);
            args = make.Idents(md.params);
        } else {
            JCExpression site = make.Ident(md.params.head);
            if (acode % 2 != 0) {
                //odd access codes represent qualified super accesses - need to
                //emit reference to the direct superclass, even if the refered
                //member is from an indirect superclass (JLS 13.1)
                site.setType(types.erasure(types.supertype(vsym.owner.enclClass().type)));
            }
            ref = make.Select(site, sym);
            args = make.Idents(md.params.tail);
        }
        JCStatement stat;          // The statement accessing the private symbol.
        if (sym.kind == VAR) {
            // Normalize out all odd access codes by taking floor modulo 2:
            int acode1 = acode - (acode & 1);

            JCExpression expr;      // The access method's return value.
            AccessCode aCode = AccessCode.getFromCode(acode1);
            switch (aCode) {
            case DEREF:
                expr = ref;
                break;
            case ASSIGN:
                expr = make.Assign(ref, args.head);
                break;
            case PREINC: case POSTINC: case PREDEC: case POSTDEC:
                expr = makeUnary(aCode.tag, ref);
                break;
            default:
                expr = make.Assignop(
                    treeTag(binaryAccessOperator(acode1, JCTree.Tag.NO_TAG)), ref, args.head);
                ((JCAssignOp) expr).operator = binaryAccessOperator(acode1, JCTree.Tag.NO_TAG);
            }
            stat = make.Return(expr.setType(sym.type));
        } else {
            stat = make.Call(make.App(ref, args));
        }
        md.body = make.Block(0, List.of(stat));

        // Make sure all parameters, result types and thrown exceptions
        // are accessible.
        for (List<JCVariableDecl> l = md.params; l.nonEmpty(); l = l.tail)
            l.head.vartype = access(l.head.vartype);
        md.restype = access(md.restype);
        for (List<JCExpression> l = md.thrown; l.nonEmpty(); l = l.tail)
            l.head = access(l.head);

        return md;
    }
 
Example #11
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
AssignopDependencyScanner(JCAssignOp tree) {
    this.sym = TreeInfo.symbol(tree.lhs);
}
 
Example #12
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitUnary(JCUnary tree) {
    boolean isUpdateOperator = tree.getTag().isIncOrDecUnaryOp();
    if (isUpdateOperator && !tree.arg.type.isPrimitive()) {
        switch(tree.getTag()) {
        case PREINC:            // ++ e
                // translate to e += 1
        case PREDEC:            // -- e
                // translate to e -= 1
            {
                JCTree.Tag opcode = (tree.hasTag(PREINC))
                    ? PLUS_ASG : MINUS_ASG;
                JCAssignOp newTree = makeAssignop(opcode,
                                                tree.arg,
                                                make.Literal(1));
                result = translate(newTree, tree.type);
                return;
            }
        case POSTINC:           // e ++
        case POSTDEC:           // e --
            {
                result = translate(lowerBoxedPostop(tree), tree.type);
                return;
            }
        }
        throw new AssertionError(tree);
    }

    tree.arg = boxIfNeeded(translate(tree.arg, tree), tree.type);

    if (tree.hasTag(NOT) && tree.arg.type.constValue() != null) {
        tree.type = cfolder.fold1(bool_not, tree.arg.type);
    }

    // If translated left hand side is an Apply, we are
    // seeing an access method invocation. In this case, return
    // that access method invocation as result.
    if (isUpdateOperator && tree.arg.hasTag(APPLY)) {
        result = tree.arg;
    } else {
        result = tree;
    }
}
 
Example #13
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCAssignOp Assignop(TreeTag opcode, JCTree lhs, JCTree rhs) {
	return invoke(Assignop, opcode.value, lhs, rhs);
}
 
Example #14
Source File: ExpressionTemplate.java    From Refaster with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
  }
}
 
Example #15
Source File: UAssignOp.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public JCAssignOp inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().Assignop(
      TAG.get(getKind()), getVariable().inline(inliner), getExpression().inline(inliner));
}