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;
}
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;
}
Aggregations