Search in sources :

Example 11 with Sort

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

the class EComp method analyzeGT.

private void analyzeGT(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promotedType = AnalyzerCaster.promoteNumeric(left.actual, right.actual, true);
    if (promotedType == null) {
        throw createError(new ClassCastException("Cannot apply greater than [>] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
    }
    if (promotedType.sort == Sort.DEF) {
        left.expected = left.actual;
        right.expected = right.actual;
    } else {
        left.expected = promotedType;
        right.expected = promotedType;
    }
    left = left.cast(variables);
    right = right.cast(variables);
    if (left.constant != null && right.constant != null) {
        Sort sort = promotedType.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 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."));
        }
    }
    actual = Definition.BOOLEAN_TYPE;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 12 with Sort

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

the class EComp method analyzeLTE.

private void analyzeLTE(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promotedType = AnalyzerCaster.promoteNumeric(left.actual, right.actual, true);
    if (promotedType == null) {
        throw createError(new ClassCastException("Cannot apply less than or equals [<=] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
    }
    if (promotedType.sort == Sort.DEF) {
        left.expected = left.actual;
        right.expected = right.actual;
    } else {
        left.expected = promotedType;
        right.expected = promotedType;
    }
    left = left.cast(variables);
    right = right.cast(variables);
    if (left.constant != null && right.constant != null) {
        Sort sort = promotedType.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 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."));
        }
    }
    actual = Definition.BOOLEAN_TYPE;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 13 with Sort

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

the class EComp method analyzeEqR.

private void analyzeEqR(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promotedType = AnalyzerCaster.promoteEquality(left.actual, right.actual);
    if (promotedType == null) {
        throw createError(new ClassCastException("Cannot apply reference equals [===] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
    }
    left.expected = promotedType;
    right.expected = promotedType;
    left = left.cast(variables);
    right = right.cast(variables);
    if (left.isNull && right.isNull) {
        throw createError(new IllegalArgumentException("Extraneous comparison of null constants."));
    }
    if ((left.constant != null || left.isNull) && (right.constant != null || right.isNull)) {
        Sort sort = promotedType.sort;
        if (sort == Sort.BOOL) {
            constant = (boolean) left.constant == (boolean) right.constant;
        } else 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 {
            constant = left.constant == right.constant;
        }
    }
    actual = Definition.BOOLEAN_TYPE;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 14 with Sort

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

the class EComp method analyzeGTE.

private void analyzeGTE(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promotedType = AnalyzerCaster.promoteNumeric(left.actual, right.actual, true);
    if (promotedType == null) {
        throw createError(new ClassCastException("Cannot apply greater than or equals [>=] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
    }
    if (promotedType.sort == Sort.DEF) {
        left.expected = left.actual;
        right.expected = right.actual;
    } else {
        left.expected = promotedType;
        right.expected = promotedType;
    }
    left = left.cast(variables);
    right = right.cast(variables);
    if (left.constant != null && right.constant != null) {
        Sort sort = promotedType.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 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."));
        }
    }
    actual = Definition.BOOLEAN_TYPE;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 15 with Sort

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

the class EUnary method analyzerAdd.

void analyzerAdd(Locals variables) {
    child.analyze(variables);
    promote = AnalyzerCaster.promoteNumeric(child.actual, true);
    if (promote == null) {
        throw createError(new ClassCastException("Cannot apply positive [+] to type [" + child.actual.name + "]."));
    }
    child.expected = promote;
    child = child.cast(variables);
    if (child.constant != null) {
        Sort sort = promote.sort;
        if (sort == Sort.INT) {
            constant = +(int) child.constant;
        } else if (sort == Sort.LONG) {
            constant = +(long) child.constant;
        } else if (sort == Sort.FLOAT) {
            constant = +(float) child.constant;
        } else if (sort == Sort.DOUBLE) {
            constant = +(double) child.constant;
        } else {
            throw createError(new IllegalStateException("Illegal tree structure."));
        }
    }
    if (promote.sort == Sort.DEF && expected != null) {
        actual = expected;
    } else {
        actual = promote;
    }
}
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