Search in sources :

Example 41 with Expression

use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.

the class Autoboxer method endVisit.

@Override
public void endVisit(ReturnStatement node) {
    Expression expr = node.getExpression();
    if (expr != null) {
        boolean returnsPrimitive = TreeUtil.getOwningReturnType(node).getKind().isPrimitive();
        boolean exprIsPrimitive = expr.getTypeMirror().getKind().isPrimitive();
        if (returnsPrimitive && !exprIsPrimitive) {
            unbox(expr);
        }
        if (!returnsPrimitive && exprIsPrimitive) {
            box(expr);
        }
    }
}
Also used : CastExpression(com.google.devtools.j2objc.ast.CastExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression)

Example 42 with Expression

use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.

the class Autoboxer method rewriteBoxedAssignment.

private void rewriteBoxedAssignment(Assignment node) {
    Expression lhs = node.getLeftHandSide();
    Expression rhs = node.getRightHandSide();
    TypeMirror type = lhs.getTypeMirror();
    TypeMirror primitiveType = typeUtil.unboxedType(type);
    if (primitiveType == null) {
        return;
    }
    TypeMirror pointerType = new PointerType(type);
    String funcName = "JreBoxed" + getAssignFunctionName(node.getOperator()) + translationUtil.getOperatorFunctionModifier(lhs) + NameTable.capitalize(primitiveType.toString());
    FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type)).addParameters(pointerType, primitiveType);
    FunctionInvocation invocation = new FunctionInvocation(element, type);
    invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
    invocation.addArgument(TreeUtil.remove(rhs));
    unbox(rhs);
    node.replaceWith(invocation);
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) CastExpression(com.google.devtools.j2objc.ast.CastExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) TypeMirror(javax.lang.model.type.TypeMirror) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) PointerType(com.google.devtools.j2objc.types.PointerType)

Example 43 with Expression

use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.

the class CastResolver method rewriteFloatToIntegralCast.

private Expression rewriteFloatToIntegralCast(TypeMirror castType, Expression expr, String funcName, TypeMirror funcReturnType) {
    FunctionElement element = new FunctionElement(funcName, funcReturnType, null).addParameters(typeUtil.getDouble());
    FunctionInvocation invocation = new FunctionInvocation(element, funcReturnType);
    invocation.addArgument(TreeUtil.remove(expr));
    Expression newExpr = invocation;
    if (!castType.equals(funcReturnType)) {
        newExpr = new CastExpression(castType, newExpr);
    }
    return newExpr;
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) CastExpression(com.google.devtools.j2objc.ast.CastExpression) Expression(com.google.devtools.j2objc.ast.Expression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression)

Example 44 with Expression

use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.

the class TreeConverter method convertPrefixExpression.

private static TreeNode convertPrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression node) {
    PrefixExpression newNode = new PrefixExpression();
    convertExpression(node, newNode);
    return newNode.setOperator(PrefixExpression.Operator.parse(node.getOperator().toString())).setOperand((Expression) TreeConverter.convert(node.getOperand())).setTypeMirror(BindingConverter.getType(node.resolveTypeBinding()));
}
Also used : PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression)

Example 45 with Expression

use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.

the class ArrayRewriter method createInvocation.

private MethodInvocation createInvocation(ArrayCreation node) {
    ArrayType arrayType = node.getTypeMirror();
    boolean retainedResult = node.hasRetainedResult() || options.useARC();
    ArrayInitializer initializer = node.getInitializer();
    if (initializer != null) {
        return newInitializedArrayInvocation(arrayType, initializer.getExpressions(), retainedResult);
    } else {
        List<Expression> dimensions = node.getDimensions();
        if (dimensions.size() == 1) {
            return newSingleDimensionArrayInvocation(arrayType, dimensions.get(0), retainedResult);
        } else {
            return newMultiDimensionArrayInvocation(arrayType, dimensions, retainedResult);
        }
    }
}
Also used : ArrayType(javax.lang.model.type.ArrayType) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Aggregations

Expression (com.google.devtools.j2objc.ast.Expression)106 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)80 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)68 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)60 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)57 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)50 CastExpression (com.google.devtools.j2objc.ast.CastExpression)46 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)45 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)42 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)32 TypeMirror (javax.lang.model.type.TypeMirror)32 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)30 VariableElement (javax.lang.model.element.VariableElement)30 LambdaExpression (com.google.devtools.j2objc.ast.LambdaExpression)26 SimpleName (com.google.devtools.j2objc.ast.SimpleName)25 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)19 NativeExpression (com.google.devtools.j2objc.ast.NativeExpression)19 FunctionalExpression (com.google.devtools.j2objc.ast.FunctionalExpression)15 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)14 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)14