use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EBinary method analyzeLSH.
private void analyzeLSH(Locals variables) {
left.analyze(variables);
right.analyze(variables);
Type lhspromote = AnalyzerCaster.promoteNumeric(left.actual, false);
Type rhspromote = AnalyzerCaster.promoteNumeric(right.actual, false);
if (lhspromote == null || rhspromote == null) {
throw createError(new ClassCastException("Cannot apply left shift [<<] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
actual = promote = lhspromote;
shiftDistance = rhspromote;
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 analyzeAdd.
private void analyzeAdd(Locals variables) {
left.analyze(variables);
right.analyze(variables);
promote = AnalyzerCaster.promoteAdd(left.actual, right.actual);
if (promote == null) {
throw createError(new ClassCastException("Cannot apply add [+] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
Sort sort = promote.sort;
actual = promote;
if (sort == Sort.STRING) {
left.expected = left.actual;
if (left instanceof EBinary && ((EBinary) left).operation == Operation.ADD && left.actual.sort == Sort.STRING) {
((EBinary) left).cat = true;
}
right.expected = right.actual;
if (right instanceof EBinary && ((EBinary) right).operation == Operation.ADD && right.actual.sort == Sort.STRING) {
((EBinary) right).cat = true;
}
} else if (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) {
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 (sort == Sort.STRING) {
constant = "" + left.constant + 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 analyzeRem.
private void analyzeRem(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 remainder [%] 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);
}
}
}
use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EBinary method analyzeBWAnd.
private void analyzeBWAnd(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 and [&] 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."));
}
}
}
use of org.elasticsearch.painless.Definition.Sort in project elasticsearch by elastic.
the class EBinary method analyzeRSH.
private void analyzeRSH(Locals variables) {
left.analyze(variables);
right.analyze(variables);
Type lhspromote = AnalyzerCaster.promoteNumeric(left.actual, false);
Type rhspromote = AnalyzerCaster.promoteNumeric(right.actual, false);
if (lhspromote == null || rhspromote == null) {
throw createError(new ClassCastException("Cannot apply right shift [>>] to types " + "[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
actual = promote = lhspromote;
shiftDistance = rhspromote;
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."));
}
}
}
Aggregations