Search in sources :

Example 31 with Sort

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

the class EComp method analyzeEq.

private void analyzeEq(Locals variables) {
    left.analyze(variables);
    right.analyze(variables);
    promotedType = AnalyzerCaster.promoteEquality(left.actual, right.actual);
    if (promotedType == null) {
        throw createError(new ClassCastException("Cannot apply 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.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 if (!left.isNull) {
            constant = left.constant.equals(right.constant);
        } else if (!right.isNull) {
            constant = right.constant.equals(null);
        } else {
            throw createError(new IllegalStateException("Illegal tree structure."));
        }
    }
    actual = Definition.BOOLEAN_TYPE;
}
Also used : Sort(org.elasticsearch.painless.Definition.Sort)

Example 32 with Sort

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

the class EComp method analyzeNER.

private void analyzeNER(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 not 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)

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