Search in sources :

Example 16 with PrefixExpression

use of com.google.devtools.j2objc.ast.PrefixExpression 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 17 with PrefixExpression

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

the class Autoboxer method endVisit.

@Override
public void endVisit(PrefixExpression node) {
    PrefixExpression.Operator op = node.getOperator();
    Expression operand = node.getOperand();
    if (op == PrefixExpression.Operator.INCREMENT) {
        rewriteBoxedPrefixOrPostfix(node, operand, "PreIncr");
    } else if (op == PrefixExpression.Operator.DECREMENT) {
        rewriteBoxedPrefixOrPostfix(node, operand, "PreDecr");
    } else if (!operand.getTypeMirror().getKind().isPrimitive()) {
        unbox(operand);
    }
}
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) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression)

Example 18 with PrefixExpression

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

the class UnsequencedExpressionRewriter method isUnsequenced.

private boolean isUnsequenced(VariableAccess modification, Set<TreeNode> modificationAncestors, VariableAccess access) {
    TreeNode commonAncestor = currentTopNode;
    TreeNode node = access.expression;
    while (node != currentTopNode) {
        if (modificationAncestors.contains(node)) {
            commonAncestor = node;
            break;
        }
        node = node.getParent();
    }
    // contain the other access, then they are not unsequenced.
    if (isWithinConditionalBranch(modification.expression, commonAncestor) || isWithinConditionalBranch(access.expression, commonAncestor)) {
        return false;
    } else if (commonAncestor instanceof CommaExpression) {
        return false;
    } else if (commonAncestor instanceof Assignment && modification.expression == commonAncestor) {
        // "i = 1 + i++;" is unsequenced (according to clang).
        return access.expression instanceof PrefixExpression || access.expression instanceof PostfixExpression;
    }
    return true;
}
Also used : Assignment(com.google.devtools.j2objc.ast.Assignment) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) TreeNode(com.google.devtools.j2objc.ast.TreeNode) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression)

Aggregations

PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)18 PointerType (com.google.devtools.j2objc.types.PointerType)12 TypeMirror (javax.lang.model.type.TypeMirror)12 Expression (com.google.devtools.j2objc.ast.Expression)11 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)9 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)9 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)8 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)7 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)6 VariableElement (javax.lang.model.element.VariableElement)6 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)5 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)4 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)4 SimpleName (com.google.devtools.j2objc.ast.SimpleName)4 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)4 CastExpression (com.google.devtools.j2objc.ast.CastExpression)3 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)3 TreeNode (com.google.devtools.j2objc.ast.TreeNode)3 Assignment (com.google.devtools.j2objc.ast.Assignment)2 Block (com.google.devtools.j2objc.ast.Block)2