Search in sources :

Example 1 with FunctionInvocation

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

the class Functionizer method endVisit.

@Override
public void endVisit(SuperMethodInvocation node) {
    ExecutableElement element = node.getExecutableElement();
    // Yes, super method invocations can be static.
    if (!ElementUtil.isStatic(element)) {
        return;
    }
    FunctionInvocation functionInvocation = new FunctionInvocation(newFunctionElement(element), node.getTypeMirror());
    TreeUtil.moveList(node.getArguments(), functionInvocation.getArguments());
    node.replaceWith(functionInvocation);
}
Also used : FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 2 with FunctionInvocation

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

the class OperatorRewriter method rewriteStringConcatenation.

private void rewriteStringConcatenation(InfixExpression node) {
    List<Expression> childOperands = node.getOperands();
    List<Expression> operands = Lists.newArrayListWithCapacity(childOperands.size());
    TreeUtil.moveList(childOperands, operands);
    operands = coalesceStringLiterals(operands);
    if (operands.size() == 1 && typeUtil.isString(operands.get(0).getTypeMirror())) {
        node.replaceWith(operands.get(0));
        return;
    }
    TypeMirror stringType = typeUtil.getJavaString().asType();
    FunctionElement element = new FunctionElement("JreStrcat", stringType, null).addParameters(TypeUtil.NATIVE_CHAR_PTR).setIsVarargs(true);
    FunctionInvocation invocation = new FunctionInvocation(element, stringType);
    List<Expression> args = invocation.getArguments();
    args.add(getStrcatTypesCString(operands));
    args.addAll(operands);
    node.replaceWith(invocation);
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) TypeMirror(javax.lang.model.type.TypeMirror)

Example 3 with FunctionInvocation

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

the class OperatorRewriter method rewriteRegularAssignment.

private void rewriteRegularAssignment(Assignment node) {
    VariableElement var = TreeUtil.getVariableElement(node.getLeftHandSide());
    if (var == null) {
        return;
    }
    handleRetainedLocal(var, node.getRightHandSide());
    boolean isRetainedWith = ElementUtil.isRetainedWithField(var);
    String funcName = getAssignmentFunctionName(node, var, isRetainedWith);
    if (funcName == null) {
        return;
    }
    TypeMirror type = node.getTypeMirror();
    TypeMirror idType = TypeUtil.ID_TYPE;
    TypeMirror declaredType = type.getKind().isPrimitive() ? type : idType;
    Expression lhs = node.getLeftHandSide();
    FunctionElement element = new FunctionElement(funcName, declaredType, null);
    FunctionInvocation invocation = new FunctionInvocation(element, type);
    List<Expression> args = invocation.getArguments();
    if (isRetainedWith) {
        element.addParameters(idType);
        args.add(getRetainedWithTarget(node, var));
    }
    element.addParameters(TypeUtil.ID_PTR_TYPE, idType);
    args.add(new PrefixExpression(new PointerType(lhs.getTypeMirror()), PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
    args.add(TreeUtil.remove(node.getRightHandSide()));
    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) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) 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 4 with FunctionInvocation

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

the class OperatorRewriter method rewriteStringAppend.

private void rewriteStringAppend(Assignment node) {
    List<Expression> operands = getStringAppendOperands(node);
    Expression lhs = node.getLeftHandSide();
    TypeMirror lhsType = lhs.getTypeMirror();
    String funcName = "JreStrAppend" + translationUtil.getOperatorFunctionModifier(lhs);
    FunctionElement element = new FunctionElement(funcName, TypeUtil.ID_TYPE, null).addParameters(TypeUtil.ID_PTR_TYPE, TypeUtil.NATIVE_CHAR_PTR).setIsVarargs(true);
    FunctionInvocation invocation = new FunctionInvocation(element, lhsType);
    List<Expression> args = invocation.getArguments();
    args.add(new PrefixExpression(new PointerType(lhsType), PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
    args.add(getStrcatTypesCString(operands));
    args.addAll(operands);
    node.replaceWith(invocation);
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) TypeMirror(javax.lang.model.type.TypeMirror) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) PointerType(com.google.devtools.j2objc.types.PointerType)

Example 5 with FunctionInvocation

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

the class OperatorRewriter method endVisit.

@Override
public void endVisit(InfixExpression node) {
    InfixExpression.Operator op = node.getOperator();
    TypeMirror nodeType = node.getTypeMirror();
    String funcName = getInfixFunction(node);
    if (funcName != null) {
        Iterator<Expression> operandIter = node.getOperands().iterator();
        Expression leftOperand = operandIter.next();
        operandIter.remove();
        // translated here are all left-associative.
        while (operandIter.hasNext()) {
            Expression rightOperand = operandIter.next();
            operandIter.remove();
            FunctionElement element = new FunctionElement(funcName, nodeType, null).addParameters(leftOperand.getTypeMirror(), rightOperand.getTypeMirror());
            FunctionInvocation invocation = new FunctionInvocation(element, nodeType);
            List<Expression> args = invocation.getArguments();
            args.add(leftOperand);
            args.add(rightOperand);
            leftOperand = invocation;
        }
        // so NOT_EQUALS operators are negated here.
        if (op == InfixExpression.Operator.NOT_EQUALS) {
            leftOperand = new PrefixExpression(leftOperand.getTypeMirror(), PrefixExpression.Operator.NOT, leftOperand);
        }
        node.replaceWith(leftOperand);
    } else if (op == InfixExpression.Operator.PLUS && typeUtil.isString(nodeType) && !isStringAppend(node.getParent())) {
        rewriteStringConcatenation(node);
    }
}
Also used : FunctionElement(com.google.devtools.j2objc.types.FunctionElement) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) TypeMirror(javax.lang.model.type.TypeMirror) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression)

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