Search in sources :

Example 16 with Type

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

the class SDeclaration method analyze.

@Override
void analyze(Locals locals) {
    final Type type;
    try {
        type = Definition.getType(this.type);
    } catch (IllegalArgumentException exception) {
        throw createError(new IllegalArgumentException("Not a type [" + this.type + "]."));
    }
    if (expression != null) {
        expression.expected = type;
        expression.analyze(locals);
        expression = expression.cast(locals);
    }
    variable = locals.addVariable(location, type, name, false);
}
Also used : Type(org.elasticsearch.painless.Definition.Type)

Example 17 with Type

use of org.elasticsearch.painless.Definition.Type 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."));
        }
    }
}
Also used : Type(org.elasticsearch.painless.Definition.Type) Sort(org.elasticsearch.painless.Definition.Sort)

Example 18 with Type

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

the class EConditional method analyze.

@Override
void analyze(Locals locals) {
    condition.expected = Definition.BOOLEAN_TYPE;
    condition.analyze(locals);
    condition = condition.cast(locals);
    if (condition.constant != null) {
        throw createError(new IllegalArgumentException("Extraneous conditional statement."));
    }
    left.expected = expected;
    left.explicit = explicit;
    left.internal = internal;
    right.expected = expected;
    right.explicit = explicit;
    right.internal = internal;
    actual = expected;
    left.analyze(locals);
    right.analyze(locals);
    if (expected == null) {
        final Type promote = AnalyzerCaster.promoteConditional(left.actual, right.actual, left.constant, right.constant);
        left.expected = promote;
        right.expected = promote;
        actual = promote;
    }
    left = left.cast(locals);
    right = right.cast(locals);
}
Also used : Type(org.elasticsearch.painless.Definition.Type)

Aggregations

Type (org.elasticsearch.painless.Definition.Type)18 Method (org.elasticsearch.painless.Definition.Method)3 Sort (org.elasticsearch.painless.Definition.Sort)3 ArrayList (java.util.ArrayList)2 Struct (org.elasticsearch.painless.Definition.Struct)2 Variable (org.elasticsearch.painless.Locals.Variable)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 MethodType (java.lang.invoke.MethodType)1 Modifier (java.lang.reflect.Modifier)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 Comparator (java.util.Comparator)1 Comparator.comparing (java.util.Comparator.comparing)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1