Search in sources :

Example 16 with FunctionInvocation

use of com.google.devtools.j2objc.ast.FunctionInvocation 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 (!typeUtil.isSameType(castType, 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) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) 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 17 with FunctionInvocation

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

the class ArrayRewriter method visit.

// We must handle object array assignment before its children because if the
// rhs is an array creation, we can optimize with "SetAndConsume".
@Override
public boolean visit(Assignment node) {
    Expression lhs = node.getLeftHandSide();
    TypeMirror lhsType = lhs.getTypeMirror();
    if (lhs instanceof ArrayAccess && !lhsType.getKind().isPrimitive()) {
        FunctionInvocation newAssignment = newArrayAssignment(node, (ArrayAccess) lhs, lhsType);
        node.replaceWith(newAssignment);
        newAssignment.accept(this);
        return false;
    }
    return true;
}
Also used : ArrayAccess(com.google.devtools.j2objc.ast.ArrayAccess) 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)

Example 18 with FunctionInvocation

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

the class StatementGenerator method needsParenthesesForMacro.

private boolean needsParenthesesForMacro(Expression expr) {
    boolean[] hasComma = { false };
    expr.accept(new TreeVisitor() {

        @Override
        public boolean visit(ArrayInitializer node) {
            hasComma[0] = true;
            return false;
        }

        @Override
        public boolean visit(CommaExpression node) {
            // Adds parentheses around children.
            return false;
        }

        @Override
        public boolean visit(FunctionInvocation node) {
            // Adds parentheses around children.
            return false;
        }

        @Override
        public boolean visit(StringLiteral node) {
            if (!UnicodeUtils.hasValidCppCharacters(node.getLiteralValue())) {
                // LiteralGenerator will emit the string using [NSString stringWithCharacters:].
                hasComma[0] = true;
                return false;
            }
            return true;
        }
    });
    return hasComma[0];
}
Also used : TreeVisitor(com.google.devtools.j2objc.ast.TreeVisitor) UnitTreeVisitor(com.google.devtools.j2objc.ast.UnitTreeVisitor) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) StringLiteral(com.google.devtools.j2objc.ast.StringLiteral) CStringLiteral(com.google.devtools.j2objc.ast.CStringLiteral) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 19 with FunctionInvocation

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

the class Functionizer method endVisit.

@Override
public void endVisit(MethodInvocation node) {
    ExecutableElement element = node.getExecutableElement();
    if (!ElementUtil.isStatic(element) && !functionizableMethods.contains(element)) {
        return;
    }
    FunctionInvocation functionInvocation = new FunctionInvocation(newFunctionElement(element), node.getTypeMirror());
    List<Expression> args = functionInvocation.getArguments();
    TreeUtil.moveList(node.getArguments(), args);
    if (!ElementUtil.isStatic(element)) {
        Expression expr = node.getExpression();
        if (expr == null) {
            expr = new ThisExpression(TreeUtil.getEnclosingTypeElement(node).asType());
        }
        args.add(0, TreeUtil.remove(expr));
    }
    node.replaceWith(functionInvocation);
}
Also used : ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) Expression(com.google.devtools.j2objc.ast.Expression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 20 with FunctionInvocation

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

the class OperatorRewriter method handleRetainedLocal.

private void handleRetainedLocal(VariableElement var, Expression rhs) {
    if (ElementUtil.isLocalVariable(var) && ElementUtil.hasAnnotation(var, RetainedLocalRef.class) && options.useReferenceCounting()) {
        FunctionElement element = new FunctionElement("JreRetainedLocalValue", TypeUtil.ID_TYPE, null);
        FunctionInvocation invocation = new FunctionInvocation(element, rhs.getTypeMirror());
        rhs.replaceWith(invocation);
        invocation.addArgument(rhs);
    }
}
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