Search in sources :

Example 6 with PointerType

use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.

the class ArrayRewriter method newArrayAccess.

private Expression newArrayAccess(ArrayAccess arrayAccessNode, TypeMirror componentType, TypeElement iosArrayElement, boolean assignable) {
    String funcName = ElementUtil.getName(iosArrayElement) + "_Get";
    TypeMirror returnType = componentType;
    TypeMirror declaredReturnType = componentType.getKind().isPrimitive() ? componentType : TypeUtil.ID_TYPE;
    if (assignable) {
        funcName += "Ref";
        returnType = declaredReturnType = new PointerType(componentType);
    }
    FunctionElement element = new FunctionElement(funcName, declaredReturnType, iosArrayElement).addParameters(iosArrayElement.asType(), typeUtil.getInt());
    FunctionInvocation invocation = new FunctionInvocation(element, returnType);
    invocation.addArgument(arrayAccessNode.getArray().copy());
    invocation.addArgument(arrayAccessNode.getIndex().copy());
    if (assignable) {
        return new PrefixExpression(componentType, PrefixExpression.Operator.DEREFERENCE, invocation);
    }
    return 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 7 with PointerType

use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.

the class ArrayRewriter method newInitializedArrayInvocation.

private MethodInvocation newInitializedArrayInvocation(ArrayType arrayType, List<Expression> elements, boolean retainedResult) {
    TypeMirror componentType = arrayType.getComponentType();
    TypeElement iosArrayElement = typeUtil.getIosArray(componentType);
    GeneratedExecutableElement methodElement = GeneratedExecutableElement.newMethodWithSelector(getInitializeSelector(componentType, retainedResult), iosArrayElement.asType(), iosArrayElement).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
    methodElement.addParameter(GeneratedVariableElement.newParameter("values", new PointerType(componentType), methodElement));
    methodElement.addParameter(GeneratedVariableElement.newParameter("count", typeUtil.getInt(), methodElement));
    if (!componentType.getKind().isPrimitive()) {
        methodElement.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), methodElement));
    }
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));
    // Create the array initializer and add it as the first parameter.
    ArrayInitializer arrayInit = new ArrayInitializer(arrayType);
    for (Expression element : elements) {
        arrayInit.addExpression(element.copy());
    }
    invocation.addArgument(arrayInit);
    // Add the array size parameter.
    invocation.addArgument(NumberLiteral.newIntLiteral(arrayInit.getExpressions().size(), typeUtil));
    // Add the type argument for object arrays.
    if (!componentType.getKind().isPrimitive()) {
        invocation.addArgument(new TypeLiteral(componentType, typeUtil));
    }
    return invocation;
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) TypeMirror(javax.lang.model.type.TypeMirror) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) TypeElement(javax.lang.model.element.TypeElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) PointerType(com.google.devtools.j2objc.types.PointerType) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 8 with PointerType

use of com.google.devtools.j2objc.types.PointerType 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 9 with PointerType

use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.

the class JavaCloneWriter method createVolatileCloneStatement.

private Statement createVolatileCloneStatement(VariableElement var, VariableElement originalVar, boolean isWeak) {
    TypeMirror voidType = typeUtil.getVoid();
    TypeMirror pointerType = new PointerType(var.asType());
    String funcName = "JreCloneVolatile" + (isWeak ? "" : "Strong");
    FunctionElement element = new FunctionElement(funcName, voidType, null).addParameters(pointerType, pointerType);
    FunctionInvocation invocation = new FunctionInvocation(element, voidType);
    invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, new SimpleName(var)));
    invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, new FieldAccess(var, new SimpleName(originalVar))));
    return new ExpressionStatement(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) SimpleName(com.google.devtools.j2objc.ast.SimpleName) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) PointerType(com.google.devtools.j2objc.types.PointerType) FieldAccess(com.google.devtools.j2objc.ast.FieldAccess)

Example 10 with PointerType

use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.

the class StaticVarRewriter method visit.

@Override
public boolean visit(FieldAccess node) {
    VariableElement var = node.getVariableElement();
    if (ElementUtil.isInstanceVar(var)) {
        node.getExpression().accept(this);
        return false;
    }
    Expression expr = TreeUtil.remove(node.getExpression());
    Expression varNode = TreeUtil.remove(node.getName());
    if (!TranslationUtil.hasSideEffect(expr)) {
        node.replaceWith(varNode);
        varNode.accept(this);
        return false;
    }
    CommaExpression commaExpr = new CommaExpression(expr);
    if (TranslationUtil.isAssigned(node)) {
        commaExpr.addExpression(new PrefixExpression(new PointerType(var.asType()), PrefixExpression.Operator.ADDRESS_OF, varNode));
        node.replaceWith(new PrefixExpression(var.asType(), PrefixExpression.Operator.DEREFERENCE, commaExpr));
    } else {
        commaExpr.addExpression(varNode);
        node.replaceWith(commaExpr);
    }
    commaExpr.accept(this);
    return false;
}
Also used : CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) PointerType(com.google.devtools.j2objc.types.PointerType) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

PointerType (com.google.devtools.j2objc.types.PointerType)14 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)13 TypeMirror (javax.lang.model.type.TypeMirror)13 Expression (com.google.devtools.j2objc.ast.Expression)9 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)9 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)9 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)5 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)5 VariableElement (javax.lang.model.element.VariableElement)5 SimpleName (com.google.devtools.j2objc.ast.SimpleName)4 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)4 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)3 TypeElement (javax.lang.model.element.TypeElement)3 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)2 FieldAccess (com.google.devtools.j2objc.ast.FieldAccess)2 NativeExpression (com.google.devtools.j2objc.ast.NativeExpression)2 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)2 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)2 ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)1 Block (com.google.devtools.j2objc.ast.Block)1