Search in sources :

Example 1 with Sort

use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.

the class AnalyzerCaster method promoteNumeric.

public static Type promoteNumeric(Type from0, Type from1, boolean decimal) {
    final Sort sort0 = from0.sort;
    final Sort sort1 = from1.sort;
    if (sort0 == Sort.DEF || sort1 == Sort.DEF) {
        return DEF_TYPE;
    }
    if (decimal) {
        if (sort0 == Sort.DOUBLE || sort1 == Sort.DOUBLE) {
            return DOUBLE_TYPE;
        } else if (sort0 == Sort.FLOAT || sort1 == Sort.FLOAT) {
            return FLOAT_TYPE;
        }
    }
    if (sort0 == Sort.LONG || sort1 == Sort.LONG) {
        return LONG_TYPE;
    } else if (sort0 == Sort.INT || sort1 == Sort.INT || sort0 == Sort.CHAR || sort1 == Sort.CHAR || sort0 == Sort.SHORT || sort1 == Sort.SHORT || sort0 == Sort.BYTE || sort1 == Sort.BYTE) {
        return INT_TYPE;
    }
    return null;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 2 with Sort

use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.

the class AnalyzerCaster method promoteEquality.

public static Type promoteEquality(final Type from0, final Type from1) {
    final Sort sort0 = from0.sort;
    final Sort sort1 = from1.sort;
    if (sort0 == Sort.DEF || sort1 == Sort.DEF) {
        return DEF_TYPE;
    }
    if (sort0.primitive && sort1.primitive) {
        if (sort0.bool && sort1.bool) {
            return BOOLEAN_TYPE;
        }
        if (sort0.numeric && sort1.numeric) {
            return promoteNumeric(from0, from1, true);
        }
    }
    return OBJECT_TYPE;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 3 with Sort

use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.

the class AnalyzerCaster method promoteXor.

public static Type promoteXor(final Type from0, final Type from1) {
    final Sort sort0 = from0.sort;
    final Sort sort1 = from1.sort;
    if (sort0 == Sort.DEF || sort1 == Sort.DEF) {
        return DEF_TYPE;
    }
    if (sort0.bool || sort1.bool) {
        return BOOLEAN_TYPE;
    }
    return promoteNumeric(from0, from1, false);
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 4 with Sort

use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.

the class EBinary method analyzeDiv.

private void analyzeDiv(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promote = AnalyzerCaster.promoteNumeric(left.actual, right.actual, true);
    if (promote == null) {
        throw createError(new ClassCastException("Cannot apply divide [/] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
    }
    actual = promote;
    if (promote.sort == Sort.DEF) {
        left.expected = left.actual;
        right.expected = right.actual;
        if (expected != null) {
            actual = expected;
        }
    } else {
        left.expected = promote;
        right.expected = promote;
    }
    left = left.cast(variables);
    right = right.cast(variables);
    if (left.constant != null && right.constant != null) {
        Sort sort = promote.sort;
        try {
            if (sort == Sort.INT) {
                constant = (int) left.constant / (int) right.constant;
            } else if (sort == Sort.LONG) {
                constant = (long) left.constant / (long) right.constant;
            } else if (sort == Sort.FLOAT) {
                constant = (float) left.constant / (float) right.constant;
            } else if (sort == Sort.DOUBLE) {
                constant = (double) left.constant / (double) right.constant;
            } else {
                throw createError(new IllegalStateException("Illegal tree structure."));
            }
        } catch (ArithmeticException exception) {
            throw createError(exception);
        }
    }
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 5 with Sort

use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.

the class EBinary method analyzeBWOr.

private void analyzeBWOr(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promote = AnalyzerCaster.promoteNumeric(left.actual, right.actual, false);
    if (promote == null) {
        throw createError(new ClassCastException("Cannot apply or [|] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
    }
    actual = promote;
    if (promote.sort == Sort.DEF) {
        left.expected = left.actual;
        right.expected = right.actual;
        if (expected != null) {
            actual = expected;
        }
    } else {
        left.expected = promote;
        right.expected = promote;
    }
    left = left.cast(variables);
    right = right.cast(variables);
    if (left.constant != null && right.constant != null) {
        Sort sort = promote.sort;
        if (sort == Sort.INT) {
            constant = (int) left.constant | (int) right.constant;
        } else if (sort == Sort.LONG) {
            constant = (long) left.constant | (long) right.constant;
        } else {
            throw createError(new IllegalStateException("Illegal tree structure."));
        }
    }
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Aggregations

Sort (org.elasticsearch.painless.Definition.Sort)32 Type (org.elasticsearch.painless.Definition.Type)4 List (java.util.List)2 Map (java.util.Map)1 Definition (org.elasticsearch.painless.Definition)1 Field (org.elasticsearch.painless.Definition.Field)1 Method (org.elasticsearch.painless.Definition.Method)1 Struct (org.elasticsearch.painless.Definition.Struct)1 Label (org.objectweb.asm.Label)1