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

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCUnary. 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: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitUnary(JCUnary tree) {
    switch (tree.getTag()) {
    case NOT:
        scanCond(tree.arg);
        final Bits t = new Bits(initsWhenFalse);
        initsWhenFalse.assign(initsWhenTrue);
        initsWhenTrue.assign(t);
        t.assign(uninitsWhenFalse);
        uninitsWhenFalse.assign(uninitsWhenTrue);
        uninitsWhenTrue.assign(t);
        break;
    case PREINC: case POSTINC:
    case PREDEC: case POSTDEC:
        scanExpr(tree.arg);
        letInit(tree.arg);
        break;
    default:
        scanExpr(tree.arg);
    }
}
 
Example #2
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Lower a tree of the form e++ or e-- where e is an object type */
JCExpression lowerBoxedPostop(final JCUnary tree) {
    // translate to tmp1=lval(e); tmp2=tmp1; tmp1 OP 1; tmp2
    // or
    // translate to tmp1=lval(e); tmp2=tmp1; (typeof tree)tmp1 OP 1; tmp2
    // where OP is += or -=
    final boolean cast = TreeInfo.skipParens(tree.arg).hasTag(TYPECAST);
    return abstractLval(tree.arg, tmp1 -> abstractRval(tmp1, tree.arg.type, tmp2 -> {
        Tag opcode = (tree.hasTag(POSTINC))
            ? PLUS_ASG : MINUS_ASG;
        //"tmp1" and "tmp2" may refer to the same instance
        //(for e.g. <Class>.super.<ident>). But further processing may
        //change the components of the tree in place (see visitSelect),
        //so cloning the tree to avoid interference between the two uses:
        JCExpression lhs = (JCExpression)tmp1.clone();
        lhs = cast
            ? make.TypeCast(tree.arg.type, lhs)
            : lhs;
        JCExpression update = makeAssignop(opcode,
                                     lhs,
                                     make.Literal(1));
        return makeComma(update, tmp2);
    }));
}
 
Example #3
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void visitUnary(JCUnary tree) {
	try {
		int ownprec = isOwnPrec(tree);
		String opname = operatorName(treeTag(tree));
		open(prec, ownprec);
		if (isPrefixUnary(tree)) {
			print(opname);
			printExpr(tree.arg, ownprec);
		} else {
			printExpr(tree.arg, ownprec);
			print(opname);
		}
		close(prec, ownprec);
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #4
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitUnary(JCUnary tree) {
    switch (tree.getTag()) {
        case PREINC: case POSTINC:
        case PREDEC: case POSTDEC:
            scan(tree.arg);
            letInit(tree.arg);
            break;
        default:
            scan(tree.arg);
    }
}
 
Example #5
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 unary expression.
 *  @param optag    The operators tree tag.
 *  @param arg      The operator's argument.
 */
JCUnary makeUnary(JCTree.Tag optag, JCExpression arg) {
    JCUnary tree = make.Unary(optag, arg);
    tree.operator = operators.resolveUnary(tree, optag, arg.type);
    tree.type = tree.operator.type.getReturnType();
    return tree;
}
 
Example #6
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 visitUnary(JCUnary tree) {
    if (TreeInfo.symbol(tree.arg) == sym) {
        dependencyFound = true;
        return;
    }
    super.visitUnary(tree);
}
 
Example #7
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public JCTree visitNewClass(NewClassTree node, Void aVoid) {
    JCNewClass oldNewClazz = (JCNewClass)node;
    JCNewClass newNewClazz = (JCNewClass)super.visitNewClass(node, aVoid);
    if (!oldNewClazz.args.isEmpty() && oldNewClazz.args.head.hasTag(NULLCHK)) {
        //workaround to Attr generating trees
        newNewClazz.encl = ((JCUnary)newNewClazz.args.head).arg;
        newNewClazz.args = newNewClazz.args.tail;
    }
    return newNewClazz;
}
 
Example #8
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitUnary(JCUnary that) {
    if (!ALLOWED_OPERATORS.contains(that.getTag())) {
        result = false;
        return ;
    }
    that.arg.accept(this);
}
 
Example #9
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 #10
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 #11
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 4 votes vote down vote up
private boolean isPrefixUnary(JCUnary tree) {
	return treeTag(tree).isPrefixUnaryOp();
}
 
Example #12
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCUnary Unary(TreeTag opcode, JCExpression arg) {
	return invoke(Unary, opcode.value, arg);
}
 
Example #13
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private UnaryExpression convertPrefixUnary(JCUnary expression) {
  return PrefixExpression.newBuilder()
      .setOperand(convertExpression(expression.getExpression()))
      .setOperator(JavaEnvironment.getPrefixOperator(expression.getKind()))
      .build();
}
 
Example #14
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private UnaryExpression convertPostfixUnary(JCUnary expression) {
  return PostfixExpression.newBuilder()
      .setOperand(convertExpression(expression.getExpression()))
      .setOperator(JavaEnvironment.getPostfixOperator(expression.getKind()))
      .build();
}
 
Example #15
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitUnary(JCUnary tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.arg));
    result = sr;
}
 
Example #16
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitUnary(JCUnary tree) {
    tree.arg = translate(tree.arg, (tree.getTag() == Tag.NULLCHK)
        ? tree.type
        : tree.operator.type.getParameterTypes().head);
    result = tree;
}
 
Example #17
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitUnary(JCUnary node) {
    node.operator = null;
    super.visitUnary(node);
}