Search in sources :

Example 6 with Type

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

the class ENewObj 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 + "]."));
    }
    Struct struct = type.struct;
    constructor = struct.constructors.get(new Definition.MethodKey("<init>", arguments.size()));
    if (constructor != null) {
        Type[] types = new Type[constructor.arguments.size()];
        constructor.arguments.toArray(types);
        if (constructor.arguments.size() != arguments.size()) {
            throw createError(new IllegalArgumentException("When calling constructor on type [" + struct.name + "]" + " expected [" + constructor.arguments.size() + "] arguments, but found [" + arguments.size() + "]."));
        }
        for (int argument = 0; argument < arguments.size(); ++argument) {
            AExpression expression = arguments.get(argument);
            expression.expected = types[argument];
            expression.internal = true;
            expression.analyze(locals);
            arguments.set(argument, expression.cast(locals));
        }
        statement = true;
        actual = type;
    } else {
        throw createError(new IllegalArgumentException("Unknown new call on type [" + struct.name + "]."));
    }
}
Also used : Type(org.elasticsearch.painless.Definition.Type) Struct(org.elasticsearch.painless.Definition.Struct)

Example 7 with Type

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

the class SCatch 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 (!Exception.class.isAssignableFrom(type.clazz)) {
        throw createError(new ClassCastException("Not an exception type [" + this.type + "]."));
    }
    variable = locals.addVariable(location, type, name, true);
    if (block != null) {
        block.lastSource = lastSource;
        block.inLoop = inLoop;
        block.lastLoop = lastLoop;
        block.analyze(locals);
        methodEscape = block.methodEscape;
        loopEscape = block.loopEscape;
        allEscape = block.allEscape;
        anyContinue = block.anyContinue;
        anyBreak = block.anyBreak;
        statementCount = block.statementCount;
    }
}
Also used : Type(org.elasticsearch.painless.Definition.Type)

Example 8 with Type

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

the class SExpression method analyze.

@Override
void analyze(Locals locals) {
    Type rtnType = locals.getReturnType();
    boolean isVoid = rtnType.sort == Sort.VOID;
    expression.read = lastSource && !isVoid;
    expression.analyze(locals);
    if (!lastSource && !expression.statement) {
        throw createError(new IllegalArgumentException("Not a statement."));
    }
    boolean rtn = lastSource && !isVoid && expression.actual.sort != Sort.VOID;
    expression.expected = rtn ? rtnType : expression.actual;
    expression.internal = rtn;
    expression = expression.cast(locals);
    methodEscape = rtn;
    loopEscape = rtn;
    allEscape = rtn;
    statementCount = 1;
}
Also used : Type(org.elasticsearch.painless.Definition.Type)

Example 9 with Type

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

the class PainlessDocGenerator method emitJavadocLink.

/**
     * Emit an external link to Javadoc for a {@link Method}.
     *
     * @param root name of the root uri variable
     */
private static void emitJavadocLink(PrintStream stream, String root, Method method) {
    stream.print("link:{");
    stream.print(root);
    stream.print("-javadoc}/");
    stream.print((method.augmentation ? Augmentation.class : method.owner.clazz).getName().replace('.', '/'));
    stream.print(".html#");
    stream.print(methodName(method));
    stream.print("%2D");
    boolean first = true;
    if (method.augmentation) {
        first = false;
        stream.print(method.owner.clazz.getName());
    }
    for (Type arg : method.arguments) {
        if (first) {
            first = false;
        } else {
            stream.print("%2D");
        }
        stream.print(arg.struct.clazz.getName());
        if (arg.dimensions > 0) {
            stream.print(":A");
        }
    }
    stream.print("%2D");
}
Also used : Type(org.elasticsearch.painless.Definition.Type)

Example 10 with Type

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

the class SEach method analyze.

@Override
void analyze(Locals locals) {
    expression.analyze(locals);
    expression.expected = expression.actual;
    expression = expression.cast(locals);
    final Type type;
    try {
        type = Definition.getType(this.type);
    } catch (IllegalArgumentException exception) {
        throw createError(new IllegalArgumentException("Not a type [" + this.type + "]."));
    }
    locals = Locals.newLocalScope(locals);
    Variable variable = locals.addVariable(location, type, name, true);
    if (expression.actual.sort == Sort.ARRAY) {
        sub = new SSubEachArray(location, variable, expression, block);
    } else if (expression.actual.sort == Sort.DEF || Iterable.class.isAssignableFrom(expression.actual.clazz)) {
        sub = new SSubEachIterable(location, variable, expression, block);
    } else {
        throw createError(new IllegalArgumentException("Illegal for each type [" + expression.actual.name + "]."));
    }
    sub.analyze(locals);
    if (block == null) {
        throw createError(new IllegalArgumentException("Extraneous for each loop."));
    }
    block.beginLoop = true;
    block.inLoop = true;
    block.analyze(locals);
    block.statementCount = Math.max(1, block.statementCount);
    if (block.loopEscape && !block.anyContinue) {
        throw createError(new IllegalArgumentException("Extraneous for loop."));
    }
    statementCount = 1;
    if (locals.hasVariable(Locals.LOOP)) {
        sub.loopCounter = locals.getVariable(location, Locals.LOOP);
    }
}
Also used : Type(org.elasticsearch.painless.Definition.Type) Variable(org.elasticsearch.painless.Locals.Variable)

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