Search in sources :

Example 1 with BinaryOperatorExpression

use of com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression in project j2objc by google.

the class MethodTranslator method visitBinaryOperatorExpression.

@Override
public TreeNode visitBinaryOperatorExpression(BinaryOperatorExpression node, Void data) {
    Expression leftExpr = (Expression) node.getLeft().acceptVisitor(this, null);
    Expression rightExpr = (Expression) node.getRight().acceptVisitor(this, null);
    InfixExpression binaryExpr = new InfixExpression().addOperand(leftExpr).addOperand(rightExpr);
    switch(node.getOperator()) {
        case BITWISE_AND:
            binaryExpr.setOperator(InfixExpression.Operator.AND).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case BITWISE_OR:
            binaryExpr.setOperator(InfixExpression.Operator.OR).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case EXCLUSIVE_OR:
            binaryExpr.setOperator(InfixExpression.Operator.XOR).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case LOGICAL_AND:
            binaryExpr.setOperator(InfixExpression.Operator.CONDITIONAL_AND).setTypeMirror(typeUtil.getBoolean());
            break;
        case LOGICAL_OR:
            binaryExpr.setOperator(InfixExpression.Operator.CONDITIONAL_OR).setTypeMirror(typeUtil.getBoolean());
            break;
        case GREATER_THAN:
            binaryExpr.setOperator(InfixExpression.Operator.GREATER).setTypeMirror(typeUtil.getBoolean());
            break;
        case GREATER_THAN_OR_EQUAL:
            binaryExpr.setOperator(InfixExpression.Operator.GREATER_EQUALS).setTypeMirror(typeUtil.getBoolean());
            break;
        case LESS_THAN:
            binaryExpr.setOperator(InfixExpression.Operator.LESS).setTypeMirror(typeUtil.getBoolean());
            break;
        case LESS_THAN_OR_EQUAL:
            binaryExpr.setOperator(InfixExpression.Operator.LESS_EQUALS).setTypeMirror(typeUtil.getBoolean());
            break;
        case EQUALITY:
            binaryExpr.setOperator(InfixExpression.Operator.EQUALS).setTypeMirror(typeUtil.getBoolean());
            break;
        case INEQUALITY:
            binaryExpr.setOperator(InfixExpression.Operator.NOT_EQUALS).setTypeMirror(typeUtil.getBoolean());
            break;
        case ADD:
            binaryExpr.setOperator(InfixExpression.Operator.PLUS).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case SUBTRACT:
            binaryExpr.setOperator(InfixExpression.Operator.MINUS).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case MULTIPLY:
            binaryExpr.setOperator(InfixExpression.Operator.TIMES).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case DIVIDE:
            binaryExpr.setOperator(InfixExpression.Operator.DIVIDE).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case MODULUS:
            binaryExpr.setOperator(InfixExpression.Operator.REMAINDER).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
            break;
        case SHIFT_LEFT:
            binaryExpr.setOperator(InfixExpression.Operator.LEFT_SHIFT).setTypeMirror(typeUtil.unaryNumericPromotion(leftExpr.getTypeMirror()));
            break;
        case SHIFT_RIGHT:
            binaryExpr.setOperator(InfixExpression.Operator.RIGHT_SHIFT_SIGNED).setTypeMirror(typeUtil.unaryNumericPromotion(leftExpr.getTypeMirror()));
            break;
        case UNSIGNED_SHIFT_RIGHT:
            binaryExpr.setOperator(InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED).setTypeMirror(typeUtil.unaryNumericPromotion(leftExpr.getTypeMirror()));
            break;
        default:
            throw new AssertionError("Unsupported infix operator: " + node.getOperator());
    }
    return binaryExpr;
}
Also used : SuperReferenceExpression(com.strobel.decompiler.languages.java.ast.SuperReferenceExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) AnonymousObjectCreationExpression(com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression) Expression(com.google.devtools.j2objc.ast.Expression) TypeReferenceExpression(com.strobel.decompiler.languages.java.ast.TypeReferenceExpression) UnaryOperatorExpression(com.strobel.decompiler.languages.java.ast.UnaryOperatorExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) BinaryOperatorExpression(com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression) ClassOfExpression(com.strobel.decompiler.languages.java.ast.ClassOfExpression) ThisReferenceExpression(com.strobel.decompiler.languages.java.ast.ThisReferenceExpression) AssignmentExpression(com.strobel.decompiler.languages.java.ast.AssignmentExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) PrimitiveExpression(com.strobel.decompiler.languages.java.ast.PrimitiveExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) MemberReferenceExpression(com.strobel.decompiler.languages.java.ast.MemberReferenceExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ObjectCreationExpression(com.strobel.decompiler.languages.java.ast.ObjectCreationExpression) InvocationExpression(com.strobel.decompiler.languages.java.ast.InvocationExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) ArrayCreationExpression(com.strobel.decompiler.languages.java.ast.ArrayCreationExpression) MethodGroupExpression(com.strobel.decompiler.languages.java.ast.MethodGroupExpression) IdentifierExpression(com.strobel.decompiler.languages.java.ast.IdentifierExpression) IndexerExpression(com.strobel.decompiler.languages.java.ast.IndexerExpression) NullReferenceExpression(com.strobel.decompiler.languages.java.ast.NullReferenceExpression) ArrayInitializerExpression(com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression)

Aggregations

ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)1 Expression (com.google.devtools.j2objc.ast.Expression)1 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)1 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)1 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)1 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)1 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)1 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)1 AnonymousObjectCreationExpression (com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression)1 ArrayCreationExpression (com.strobel.decompiler.languages.java.ast.ArrayCreationExpression)1 ArrayInitializerExpression (com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression)1 AssignmentExpression (com.strobel.decompiler.languages.java.ast.AssignmentExpression)1 BinaryOperatorExpression (com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression)1 ClassOfExpression (com.strobel.decompiler.languages.java.ast.ClassOfExpression)1 IdentifierExpression (com.strobel.decompiler.languages.java.ast.IdentifierExpression)1 IndexerExpression (com.strobel.decompiler.languages.java.ast.IndexerExpression)1 InvocationExpression (com.strobel.decompiler.languages.java.ast.InvocationExpression)1 MemberReferenceExpression (com.strobel.decompiler.languages.java.ast.MemberReferenceExpression)1 MethodGroupExpression (com.strobel.decompiler.languages.java.ast.MethodGroupExpression)1 NullReferenceExpression (com.strobel.decompiler.languages.java.ast.NullReferenceExpression)1