Search in sources :

Example 86 with BinaryExpression

use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.

the class BinaryExpressionMultiTypeDispatcher method isAssignmentToArray.

private static boolean isAssignmentToArray(BinaryExpression binExp) {
    Expression leftExpression = binExp.getLeftExpression();
    if (!(leftExpression instanceof BinaryExpression))
        return false;
    BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
    if (leftBinExpr.getOperation().getType() != LEFT_SQUARE_BRACKET)
        return false;
    return true;
}
Also used : BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) Expression(org.codehaus.groovy.ast.expr.Expression)

Example 87 with BinaryExpression

use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.

the class BinaryExpressionMultiTypeDispatcher method doAssignmentToLocalVariable.

private boolean doAssignmentToLocalVariable(String method, BinaryExpression binExp) {
    Expression left = binExp.getLeftExpression();
    if (left instanceof VariableExpression) {
        VariableExpression ve = (VariableExpression) left;
        Variable v = ve.getAccessedVariable();
        if (v instanceof DynamicVariable)
            return false;
        if (v instanceof PropertyExpression)
            return false;
    /* field and declaration we don't return false */
    } else {
        return false;
    }
    evaluateBinaryExpression(method, binExp);
    getController().getOperandStack().dup();
    getController().getCompileStack().pushLHS(true);
    binExp.getLeftExpression().visit(getController().getAcg());
    getController().getCompileStack().popLHS();
    return true;
}
Also used : Variable(org.codehaus.groovy.ast.Variable) DynamicVariable(org.codehaus.groovy.ast.DynamicVariable) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) Expression(org.codehaus.groovy.ast.expr.Expression) DynamicVariable(org.codehaus.groovy.ast.DynamicVariable) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression)

Example 88 with BinaryExpression

use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.

the class BinaryExpressionMultiTypeDispatcher method doPrimitiveCompare.

protected boolean doPrimitiveCompare(ClassNode leftType, ClassNode rightType, BinaryExpression binExp) {
    Expression leftExp = binExp.getLeftExpression();
    Expression rightExp = binExp.getRightExpression();
    int operation = binExp.getOperation().getType();
    int operationType = getOperandConversionType(leftType, rightType);
    BinaryExpressionWriter bew = binExpWriter[operationType];
    if (!bew.write(operation, true))
        return false;
    AsmClassGenerator acg = getController().getAcg();
    OperandStack os = getController().getOperandStack();
    leftExp.visit(acg);
    os.doGroovyCast(bew.getNormalOpResultType());
    rightExp.visit(acg);
    os.doGroovyCast(bew.getNormalOpResultType());
    bew.write(operation, false);
    return true;
}
Also used : PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) Expression(org.codehaus.groovy.ast.expr.Expression) AsmClassGenerator(org.codehaus.groovy.classgen.AsmClassGenerator)

Example 89 with BinaryExpression

use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.

the class EqualsAndHashCodeASTTransformation method bothSelfRecursivePropertyX.

private static BinaryExpression bothSelfRecursivePropertyX(PropertyNode pNode, Expression other) {
    String getterName = getGetterName(pNode);
    Expression selfGetter = callThisX(getterName);
    Expression otherGetter = callX(other, getterName);
    return andX(sameX(selfGetter, varX("this")), sameX(otherGetter, other));
}
Also used : Expression(org.codehaus.groovy.ast.expr.Expression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) CastExpression(org.codehaus.groovy.ast.expr.CastExpression)

Example 90 with BinaryExpression

use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.

the class EqualsAndHashCodeASTTransformation method differentSelfRecursivePropertyX.

private static BinaryExpression differentSelfRecursivePropertyX(PropertyNode pNode, Expression other) {
    String getterName = getGetterName(pNode);
    Expression selfGetter = callThisX(getterName);
    Expression otherGetter = callX(other, getterName);
    return orX(andX(sameX(selfGetter, varX("this")), notX(sameX(otherGetter, other))), andX(notX(sameX(selfGetter, varX("this"))), sameX(otherGetter, other)));
}
Also used : Expression(org.codehaus.groovy.ast.expr.Expression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) CastExpression(org.codehaus.groovy.ast.expr.CastExpression)

Aggregations

BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)94 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)83 Expression (org.codehaus.groovy.ast.expr.Expression)71 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)57 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)51 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)49 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)48 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)39 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)35 BooleanExpression (org.codehaus.groovy.ast.expr.BooleanExpression)33 ClassNode (org.codehaus.groovy.ast.ClassNode)31 TernaryExpression (org.codehaus.groovy.ast.expr.TernaryExpression)29 EmptyExpression (org.codehaus.groovy.ast.expr.EmptyExpression)28 FieldExpression (org.codehaus.groovy.ast.expr.FieldExpression)28 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)26 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)24 CastExpression (org.codehaus.groovy.ast.expr.CastExpression)21 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)21 ArrayExpression (org.codehaus.groovy.ast.expr.ArrayExpression)20 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)20