Search in sources :

Example 6 with OptimisationStrategy

use of com.redhat.ceylon.compiler.java.codegen.Operators.OptimisationStrategy in project ceylon-compiler by ceylon.

the class ExpressionTransformer method transformOverridableBinaryOperator.

private JCExpression transformOverridableBinaryOperator(Tree.BinaryOperatorExpression op, Type leftType, Type rightType) {
    OperatorTranslation operator = Operators.getOperator(op.getClass());
    if (operator == null) {
        return makeErroneous(op, "compiler bug: " + op.getClass() + " is an unhandled operator");
    }
    OptimisationStrategy optimisationStrategy = operator.getBinOpOptimisationStrategy(op, op.getLeftTerm(), leftType, op.getRightTerm(), rightType, this);
    at(op);
    JCExpression left = transformExpression(op.getLeftTerm(), optimisationStrategy.getBoxingStrategy(), leftType, EXPR_WIDEN_PRIM);
    JCExpression right = transformExpression(op.getRightTerm(), optimisationStrategy.getBoxingStrategy(), rightType, EXPR_WIDEN_PRIM);
    return transformOverridableBinaryOperator(operator, optimisationStrategy, left, right, op.getLeftTerm(), op.getRightTerm(), op.getTypeModel());
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) OptimisationStrategy(com.redhat.ceylon.compiler.java.codegen.Operators.OptimisationStrategy) AssignmentOperatorTranslation(com.redhat.ceylon.compiler.java.codegen.Operators.AssignmentOperatorTranslation) OperatorTranslation(com.redhat.ceylon.compiler.java.codegen.Operators.OperatorTranslation)

Example 7 with OptimisationStrategy

use of com.redhat.ceylon.compiler.java.codegen.Operators.OptimisationStrategy in project ceylon-compiler by ceylon.

the class ExpressionTransformer method transform.

// Comparison operators
public JCExpression transform(Tree.IdenticalOp op) {
    // The only thing which might be unboxed is boolean, and we can follow the rules of == for optimising it,
    // which are simple and require that both types be booleans to be unboxed, otherwise they must be boxed
    OptimisationStrategy optimisationStrategy = OperatorTranslation.BINARY_EQUAL.getBinOpOptimisationStrategy(op, op.getLeftTerm(), op.getRightTerm(), this);
    JCExpression left = transformExpression(op.getLeftTerm(), optimisationStrategy.getBoxingStrategy(), null);
    JCExpression right = transformExpression(op.getRightTerm(), optimisationStrategy.getBoxingStrategy(), null);
    return at(op).Binary(JCTree.EQ, left, right);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) OptimisationStrategy(com.redhat.ceylon.compiler.java.codegen.Operators.OptimisationStrategy)

Aggregations

OptimisationStrategy (com.redhat.ceylon.compiler.java.codegen.Operators.OptimisationStrategy)7 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)7 AssignmentOperatorTranslation (com.redhat.ceylon.compiler.java.codegen.Operators.AssignmentOperatorTranslation)6 OperatorTranslation (com.redhat.ceylon.compiler.java.codegen.Operators.OperatorTranslation)6 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)4 Term (com.redhat.ceylon.compiler.typechecker.tree.Tree.Term)4 Type (com.redhat.ceylon.model.typechecker.model.Type)4 JCTree (com.sun.tools.javac.tree.JCTree)4 SyntheticName (com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName)2 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)2 Interface (com.redhat.ceylon.model.typechecker.model.Interface)2 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)2 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)1 Name (com.sun.tools.javac.util.Name)1