Java Code Examples for org.codehaus.groovy.syntax.Types#COMPARE_EQUAL

The following examples show how to use org.codehaus.groovy.syntax.Types#COMPARE_EQUAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryExpressionTransformer.java    From groovy with Apache License 2.0 6 votes vote down vote up
private static BinaryExpression tryOptimizeCharComparison(final Expression left, final Expression right, final BinaryExpression bin) {
    int op = bin.getOperation().getType();
    if (StaticTypeCheckingSupport.isCompareToBoolean(op) || op == Types.COMPARE_EQUAL || op == Types.COMPARE_NOT_EQUAL) {
        Character cLeft = tryCharConstant(left);
        Character cRight = tryCharConstant(right);
        if (cLeft != null || cRight != null) {
            Expression oLeft = (cLeft == null ? left : constX(cLeft, true));
            oLeft.setSourcePosition(left);
            Expression oRight = (cRight == null ? right : constX(cRight, true));
            oRight.setSourcePosition(right);
            bin.setLeftExpression(oLeft);
            bin.setRightExpression(oRight);
            return bin;
        }
    }
    return null;
}
 
Example 2
Source File: SqlWhereVisitor.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected String tokenAsSql(Token token) {
    switch (token.getType()) {
        case Types.COMPARE_EQUAL:
            return "=";
        case Types.LOGICAL_AND:
            return "and";
        case Types.LOGICAL_OR:
            return "or";
        default:
            return token.getText();
    }
}
 
Example 3
Source File: OptimizingStatementWriter.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
public void visitBinaryExpression(final BinaryExpression expression) {
    if (expression.getNodeMetaData(StatementMeta.class) != null) return;
    super.visitBinaryExpression(expression);

    ClassNode leftType = typeChooser.resolveType(expression.getLeftExpression(), node);
    ClassNode rightType = typeChooser.resolveType(expression.getRightExpression(), node);
    ClassNode resultType = null;
    int operation = expression.getOperation().getType();

    if (operation == Types.LEFT_SQUARE_BRACKET && leftType.isArray()) {
        opt.chainShouldOptimize(true);
        resultType = leftType.getComponentType();
    } else {
        switch (operation) {
            case Types.COMPARE_EQUAL:
            case Types.COMPARE_LESS_THAN:
            case Types.COMPARE_LESS_THAN_EQUAL:
            case Types.COMPARE_GREATER_THAN:
            case Types.COMPARE_GREATER_THAN_EQUAL:
            case Types.COMPARE_NOT_EQUAL:
                if (isIntCategory(leftType) && isIntCategory(rightType)) {
                    opt.chainShouldOptimize(true);
                } else if (isLongCategory(leftType) && isLongCategory(rightType)) {
                    opt.chainShouldOptimize(true);
                } else if (isDoubleCategory(leftType) && isDoubleCategory(rightType)) {
                    opt.chainShouldOptimize(true);
                } else {
                    opt.chainCanOptimize(true);
                }
                resultType = boolean_TYPE;
                break;
            case Types.LOGICAL_AND:
            case Types.LOGICAL_AND_EQUAL:
            case Types.LOGICAL_OR:
            case Types.LOGICAL_OR_EQUAL:
                if (boolean_TYPE.equals(leftType) && boolean_TYPE.equals(rightType)) {
                    opt.chainShouldOptimize(true);
                } else {
                    opt.chainCanOptimize(true);
                }
                expression.setType(boolean_TYPE);
                resultType = boolean_TYPE;
                break;
            case Types.DIVIDE:
            case Types.DIVIDE_EQUAL:
                if (isLongCategory(leftType) && isLongCategory(rightType)) {
                    resultType = BigDecimal_TYPE;
                    opt.chainShouldOptimize(true);
                } else if (isBigDecCategory(leftType) && isBigDecCategory(rightType)) {
                    // no optimization for BigDecimal yet
                    //resultType = BigDecimal_TYPE;
                } else if (isDoubleCategory(leftType) && isDoubleCategory(rightType)) {
                    resultType = double_TYPE;
                    opt.chainShouldOptimize(true);
                }
                break;
            case Types.POWER:
            case Types.POWER_EQUAL:
                // TODO: implement
                break;
            case Types.ASSIGN:
                resultType = optimizeDivWithIntOrLongTarget(expression.getRightExpression(), leftType);
                opt.chainCanOptimize(true);
                break;
            default:
                if (isIntCategory(leftType) && isIntCategory(rightType)) {
                    resultType = int_TYPE;
                    opt.chainShouldOptimize(true);
                } else if (isLongCategory(leftType) && isLongCategory(rightType)) {
                    resultType = long_TYPE;
                    opt.chainShouldOptimize(true);
                } else if (isBigDecCategory(leftType) && isBigDecCategory(rightType)) {
                    // no optimization for BigDecimal yet
                    //resultType = BigDecimal_TYPE;
                } else if (isDoubleCategory(leftType) && isDoubleCategory(rightType)) {
                    resultType = double_TYPE;
                    opt.chainShouldOptimize(true);
                }
        }
    }

    if (resultType != null) {
        addMeta(expression).type = resultType;
        opt.chainInvolvedType(resultType);
        opt.chainInvolvedType(rightType);
        opt.chainInvolvedType(leftType);
    }
}