Search in sources :

Example 1 with OperatorSymbol

use of com.sun.tools.javac.code.Symbol.OperatorSymbol in project ceylon-compiler by ceylon.

the class Attr method visitUnary.

public void visitUnary(JCUnary tree) {
    // Attribute arguments.
    Type argtype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC) ? attribTree(tree.arg, env, VAR, Type.noType) : chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env));
    // Find operator.
    Symbol operator = tree.operator = rs.resolveUnaryOperator(tree.pos(), tree.getTag(), env, argtype);
    Type owntype = types.createErrorType(tree.type);
    if (operator.kind == MTH && !argtype.isErroneous()) {
        owntype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC) ? tree.arg.type : operator.type.getReturnType();
        int opc = ((OperatorSymbol) operator).opcode;
        // If the argument is constant, fold it.
        if (argtype.constValue() != null) {
            Type ctype = cfolder.fold1(opc, argtype);
            if (ctype != null) {
                owntype = cfolder.coerce(ctype, owntype);
                // operands are constant identifiers.
                if (tree.arg.type.tsym == syms.stringType.tsym) {
                    tree.arg.type = syms.stringType;
                }
            }
        }
    }
    result = check(tree, owntype, VAL, pkind, pt);
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol) Lint(com.sun.tools.javac.code.Lint)

Example 2 with OperatorSymbol

use of com.sun.tools.javac.code.Symbol.OperatorSymbol in project ceylon-compiler by ceylon.

the class Attr method visitBinary.

public void visitBinary(JCBinary tree) {
    // Attribute arguments.
    Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env));
    Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env));
    // Find operator.
    Symbol operator = tree.operator = rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right);
    Type owntype = types.createErrorType(tree.type);
    if (operator.kind == MTH && !left.isErroneous() && !right.isErroneous()) {
        owntype = operator.type.getReturnType();
        int opc = chk.checkOperator(tree.lhs.pos(), (OperatorSymbol) operator, tree.getTag(), left, right);
        // If both arguments are constants, fold them.
        if (left.constValue() != null && right.constValue() != null) {
            Type ctype = cfolder.fold2(opc, left, right);
            if (ctype != null) {
                owntype = cfolder.coerce(ctype, owntype);
                // operands are constant identifiers.
                if (tree.lhs.type.tsym == syms.stringType.tsym) {
                    tree.lhs.type = syms.stringType;
                }
                if (tree.rhs.type.tsym == syms.stringType.tsym) {
                    tree.rhs.type = syms.stringType;
                }
            }
        }
        // castable to each other, (JLS???).
        if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) {
            if (!types.isCastable(left, right, new Warner(tree.pos()))) {
                log.error(tree.pos(), "incomparable.types", left, right);
            }
        }
        chk.checkDivZero(tree.rhs.pos(), operator, right);
    }
    result = check(tree, owntype, VAL, pkind, pt);
}
Also used : Warner(com.sun.tools.javac.util.Warner) ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol) Lint(com.sun.tools.javac.code.Lint)

Example 3 with OperatorSymbol

use of com.sun.tools.javac.code.Symbol.OperatorSymbol in project ceylon-compiler by ceylon.

the class Attr method visitAssignop.

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);
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)3 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)3 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)3 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)3 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)3 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)3 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)3 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)3 Type (com.sun.tools.javac.code.Type)3 ArrayType (com.sun.tools.javac.code.Type.ArrayType)3 ClassType (com.sun.tools.javac.code.Type.ClassType)3 MethodType (com.sun.tools.javac.code.Type.MethodType)3 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)3 WildcardType (com.sun.tools.javac.code.Type.WildcardType)3 Lint (com.sun.tools.javac.code.Lint)2 Warner (com.sun.tools.javac.util.Warner)1