Search in sources :

Example 11 with Expression

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

the class UnsequencedExpressionRewriter method visit.

@Override
public boolean visit(ForStatement node) {
    List<Expression> initializers = node.getInitializers();
    // expression or a list of initializer expressions.
    if (initializers.size() == 1 && initializers.get(0) instanceof VariableDeclarationExpression) {
        VariableDeclarationExpression decl = (VariableDeclarationExpression) initializers.get(0);
        extractVariableDeclarationFragments(decl.getFragments(), TreeUtil.asStatementList(node).subList(0, 0));
    } else {
        extractExpressionList(initializers, TreeUtil.asStatementList(node).subList(0, 0), false);
    }
    Expression expr = node.getExpression();
    if (expr != null) {
        newExpression(expr);
        expr.accept(this);
        List<VariableAccess> toExtract = getUnsequencedAccesses();
        if (!toExtract.isEmpty()) {
            // Convert "if (;cond;)" into "if (;;) { if (!(cond)) break; ...}".
            List<Statement> stmtList = TreeUtil.asStatementList(node.getBody()).subList(0, 0);
            extractOrderedAccesses(stmtList, currentTopNode, toExtract);
            stmtList.add(createLoopTermination(node.getExpression()));
            node.setExpression(null);
        }
    }
    extractExpressionList(node.getUpdaters(), TreeUtil.asStatementList(node.getBody()), true);
    node.getBody().accept(this);
    return false;
}
Also used : PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) CommaExpression(com.google.devtools.j2objc.ast.CommaExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) AssertStatement(com.google.devtools.j2objc.ast.AssertStatement) ForStatement(com.google.devtools.j2objc.ast.ForStatement) SynchronizedStatement(com.google.devtools.j2objc.ast.SynchronizedStatement) DoStatement(com.google.devtools.j2objc.ast.DoStatement) EnhancedForStatement(com.google.devtools.j2objc.ast.EnhancedForStatement) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) WhileStatement(com.google.devtools.j2objc.ast.WhileStatement) BreakStatement(com.google.devtools.j2objc.ast.BreakStatement) IfStatement(com.google.devtools.j2objc.ast.IfStatement) Statement(com.google.devtools.j2objc.ast.Statement) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) ThrowStatement(com.google.devtools.j2objc.ast.ThrowStatement) SwitchStatement(com.google.devtools.j2objc.ast.SwitchStatement) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression)

Example 12 with Expression

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

the class NilCheckResolver method visit.

@Override
public boolean visit(ClassInstanceCreation node) {
    Expression outerTarget = node.getExpression();
    if (outerTarget != null) {
        outerTarget.accept(this);
        addNilCheck(outerTarget);
    }
    Expression superOuterArg = node.getSuperOuterArg();
    if (superOuterArg != null) {
        superOuterArg.accept(this);
        addNilCheck(superOuterArg);
    }
    for (Expression arg : node.getArguments()) {
        arg.accept(this);
    }
    // Don't need to visit AnonymousClassDeclaration child because it's removed by
    // AnonymousClassConverter.
    removeNonFinalFields();
    handleThrows();
    return false;
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) 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)

Example 13 with Expression

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

the class NilCheckResolver method visit.

@Override
public boolean visit(ForStatement node) {
    for (Expression initializer : node.getInitializers()) {
        initializer.accept(this);
    }
    pushLoopOrSwitchScope(getStatementLabel(node));
    for (int i = 0; i < 2; i++) {
        Expression expr = node.getExpression();
        if (expr != null) {
            expr.accept(this);
            // Merge loop exit
            scope.mergeInto(scope.next, getSafeVarsFalse(expr));
            addSafeVars(getSafeVarsTrue(expr));
        }
        pushScope();
        node.getBody().accept(this);
        popAndMerge();
        for (Expression updater : node.getUpdaters()) {
            updater.accept(this);
        }
    }
    popWithoutMerge();
    return false;
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) 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)

Example 14 with Expression

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

the class NilCheckResolver method visit.

@Override
public boolean visit(SuperConstructorInvocation node) {
    Expression outerTarget = node.getExpression();
    if (outerTarget != null) {
        outerTarget.accept(this);
        addNilCheck(outerTarget);
    }
    for (Expression arg : node.getArguments()) {
        arg.accept(this);
    }
    removeNonFinalFields();
    handleThrows();
    return false;
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) 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)

Example 15 with Expression

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

the class NilCheckResolver method visit.

@Override
public boolean visit(DoStatement node) {
    pushLoopOrSwitchScope(getStatementLabel(node));
    for (int i = 0; i < 2; i++) {
        pushScope();
        node.getBody().accept(this);
        popAndMerge();
        Expression expr = node.getExpression();
        expr.accept(this);
        // Merge loop exit
        scope.mergeInto(scope.next, getSafeVarsFalse(expr));
        addSafeVars(getSafeVarsTrue(expr));
    }
    popWithoutMerge();
    return false;
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) 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)

Aggregations

Expression (com.google.devtools.j2objc.ast.Expression)106 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)80 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)68 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)60 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)57 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)50 CastExpression (com.google.devtools.j2objc.ast.CastExpression)46 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)45 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)42 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)32 TypeMirror (javax.lang.model.type.TypeMirror)32 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)30 VariableElement (javax.lang.model.element.VariableElement)30 LambdaExpression (com.google.devtools.j2objc.ast.LambdaExpression)26 SimpleName (com.google.devtools.j2objc.ast.SimpleName)25 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)19 NativeExpression (com.google.devtools.j2objc.ast.NativeExpression)19 FunctionalExpression (com.google.devtools.j2objc.ast.FunctionalExpression)15 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)14 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)14