Search in sources :

Example 21 with FunctionInvocation

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

the class ArrayRewriter method newArrayAssignment.

private FunctionInvocation newArrayAssignment(Assignment assignmentNode, ArrayAccess arrayAccessNode, TypeMirror componentType) {
    Assignment.Operator op = assignmentNode.getOperator();
    assert !componentType.getKind().isPrimitive();
    assert op == Assignment.Operator.ASSIGN;
    Expression value = TreeUtil.remove(assignmentNode.getRightHandSide());
    Expression retainedValue = TranslationUtil.retainResult(value);
    String funcName = "IOSObjectArray_Set";
    if (retainedValue != null) {
        funcName = "IOSObjectArray_SetAndConsume";
        value = retainedValue;
    }
    TypeElement objArrayType = TypeUtil.IOS_OBJECT_ARRAY;
    TypeMirror idType = TypeUtil.ID_TYPE;
    FunctionElement element = new FunctionElement(funcName, idType, objArrayType).addParameters(objArrayType.asType(), typeUtil.getInt(), idType);
    FunctionInvocation invocation = new FunctionInvocation(element, componentType);
    List<Expression> args = invocation.getArguments();
    args.add(TreeUtil.remove(arrayAccessNode.getArray()));
    args.add(TreeUtil.remove(arrayAccessNode.getIndex()));
    args.add(value);
    return invocation;
}
Also used : Assignment(com.google.devtools.j2objc.ast.Assignment) FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement)

Example 22 with FunctionInvocation

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

the class StatementGenerator method visit.

@Override
public boolean visit(ExpressionStatement node) {
    Expression expression = node.getExpression();
    TypeMirror type = expression.getTypeMirror();
    if (!type.getKind().isPrimitive() && !type.getKind().equals(TypeKind.VOID) && options.useARC() && (expression instanceof MethodInvocation || expression instanceof SuperMethodInvocation || expression instanceof FunctionInvocation)) {
        // Avoid clang warning that the return value is unused.
        buffer.append("(void) ");
    }
    expression.accept(this);
    buffer.append(";\n");
    return false;
}
Also used : FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) TypeMirror(javax.lang.model.type.TypeMirror) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 23 with FunctionInvocation

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

the class Autoboxer method rewriteBoxedPrefixOrPostfix.

private void rewriteBoxedPrefixOrPostfix(TreeNode node, Expression operand, String funcName) {
    TypeMirror type = operand.getTypeMirror();
    TypeMirror primitiveType = typeUtil.unboxedType(type);
    if (primitiveType == null) {
        return;
    }
    TypeMirror pointerType = new PointerType(type);
    funcName = "JreBoxed" + funcName + translationUtil.getOperatorFunctionModifier(operand) + NameTable.capitalize(primitiveType.toString());
    FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type)).addParameters(pointerType);
    FunctionInvocation invocation = new FunctionInvocation(element, type);
    invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(operand)));
    node.replaceWith(invocation);
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) TypeMirror(javax.lang.model.type.TypeMirror) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) PointerType(com.google.devtools.j2objc.types.PointerType)

Example 24 with FunctionInvocation

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

the class OperatorRewriter method rewriteVolatileLoad.

private void rewriteVolatileLoad(Expression node) {
    VariableElement var = TreeUtil.getVariableElement(node);
    if (var != null && ElementUtil.isVolatile(var) && !TranslationUtil.isAssigned(node)) {
        TypeMirror type = node.getTypeMirror();
        TypeMirror declaredType = type.getKind().isPrimitive() ? type : TypeUtil.ID_TYPE;
        String funcName = "JreLoadVolatile" + NameTable.capitalize(declaredType.toString());
        FunctionElement element = new FunctionElement(funcName, declaredType, null).addParameters(TypeUtil.ID_PTR_TYPE);
        FunctionInvocation invocation = new FunctionInvocation(element, type);
        node.replaceWith(invocation);
        invocation.addArgument(new PrefixExpression(new PointerType(type), PrefixExpression.Operator.ADDRESS_OF, node));
    }
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) TypeMirror(javax.lang.model.type.TypeMirror) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) PointerType(com.google.devtools.j2objc.types.PointerType) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) VariableElement(javax.lang.model.element.VariableElement)

Example 25 with FunctionInvocation

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

the class OperatorRewriter method rewriteRetainedLocal.

private void rewriteRetainedLocal(Expression expr) {
    if (expr.getKind() == TreeNode.Kind.STRING_LITERAL || expr.getKind() == TreeNode.Kind.FUNCTION_INVOCATION) {
        return;
    }
    FunctionElement element = new FunctionElement("JreRetainedLocalValue", TypeUtil.ID_TYPE, null);
    FunctionInvocation invocation = new FunctionInvocation(element, expr.getTypeMirror());
    expr.replaceWith(invocation);
    invocation.addArgument(expr);
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation)

Aggregations

FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)36 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)26 TypeMirror (javax.lang.model.type.TypeMirror)23 Expression (com.google.devtools.j2objc.ast.Expression)21 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)14 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)13 ExecutableElement (javax.lang.model.element.ExecutableElement)11 TypeElement (javax.lang.model.element.TypeElement)11 CastExpression (com.google.devtools.j2objc.ast.CastExpression)10 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)10 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)10 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)9 SimpleName (com.google.devtools.j2objc.ast.SimpleName)9 PointerType (com.google.devtools.j2objc.types.PointerType)9 VariableElement (javax.lang.model.element.VariableElement)9 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)8 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)8 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)6 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)5 NativeExpression (com.google.devtools.j2objc.ast.NativeExpression)5