use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EBinary method analyzeXor.
private void analyzeXor(Locals variables) {
left.analyze(variables);
right.analyze(variables);
promote = AnalyzerCaster.promoteXor(left.actual, right.actual);
if (promote == null) {
throw createError(new ClassCastException("Cannot apply xor [^] 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.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 {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
}
use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EBinary method analyzeUSH.
private void analyzeUSH(Locals variables) {
left.analyze(variables);
right.analyze(variables);
Type lhspromote = AnalyzerCaster.promoteNumeric(left.actual, false);
Type rhspromote = AnalyzerCaster.promoteNumeric(right.actual, false);
actual = promote = lhspromote;
shiftDistance = rhspromote;
if (lhspromote == null || rhspromote == null) {
throw createError(new ClassCastException("Cannot apply unsigned shift [>>>] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (lhspromote.sort == Sort.DEF || rhspromote.sort == Sort.DEF) {
left.expected = left.actual;
right.expected = right.actual;
if (expected != null) {
actual = expected;
}
} else {
left.expected = lhspromote;
if (rhspromote.sort == Sort.LONG) {
right.expected = Definition.INT_TYPE;
right.explicit = true;
} else {
right.expected = rhspromote;
}
}
left = left.cast(variables);
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = lhspromote.sort;
if (sort == Sort.INT) {
constant = (int) left.constant >>> (int) right.constant;
} else if (sort == Sort.LONG) {
constant = (long) left.constant >>> (int) right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
}
use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EBinary method analyzeSub.
private void analyzeSub(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 subtract [-] 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 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."));
}
}
}
use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EComp method analyzeNE.
private void analyzeNE(Locals variables) {
left.analyze(variables);
right.analyze(variables);
promotedType = AnalyzerCaster.promoteEquality(left.actual, right.actual);
if (promotedType == null) {
throw createError(new ClassCastException("Cannot apply not 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 analyzeLT.
private void analyzeLT(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 [>=] 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;
}
Aggregations