Search in sources :

Example 56 with CodeTreeBuilder

use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.

the class NodeFactoryFactory method createCreateGetExecutionSignature.

private CodeExecutableElement createCreateGetExecutionSignature() {
    TypeMirror returnValue = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(List.class)));
    CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnValue, "getExecutionSignature");
    CodeTreeBuilder builder = method.createBuilder();
    builder.startReturn();
    builder.startStaticCall(context.getType(Arrays.class), "asList");
    for (NodeExecutionData execution : node.getChildExecutions()) {
        builder.typeLiteral(execution.getNodeType());
    }
    builder.end();
    builder.end();
    return method;
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) NodeExecutionData(com.oracle.truffle.dsl.processor.model.NodeExecutionData) TypeMirror(javax.lang.model.type.TypeMirror) Arrays(java.util.Arrays) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 57 with CodeTreeBuilder

use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.

the class NodeFactoryFactory method createCreateMethod.

private CodeExecutableElement createCreateMethod(ExecutableElement constructor) {
    CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), constructor);
    method.setSimpleName(CodeNames.of("create"));
    method.getModifiers().clear();
    method.getModifiers().add(Modifier.PUBLIC);
    method.getModifiers().add(Modifier.STATIC);
    method.setReturnType(node.getNodeType());
    CodeTreeBuilder body = method.createBuilder();
    body.startReturn();
    if (node.getSpecializations().isEmpty()) {
        body.nullLiteral();
    } else {
        body.startNew(NodeCodeGenerator.nodeType(node));
        for (VariableElement var : method.getParameters()) {
            body.string(var.getSimpleName().toString());
        }
        body.end();
    }
    body.end();
    return method;
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) VariableElement(javax.lang.model.element.VariableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 58 with CodeTreeBuilder

use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.

the class TypeSystemCodeGenerator method check.

static CodeTree check(TypeSystemData typeSystem, TypeMirror type, CodeTree content) {
    if (ElementUtils.isObject(type)) {
        return content;
    }
    CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
    TypeCheckData check = typeSystem.getCheck(type);
    if (check == null) {
        builder.instanceOf(content, ElementUtils.boxType(typeSystem.getContext(), type));
    } else {
        builder.startStaticCall(typeSystem.getTemplateType().asType(), check.getMethodName()).tree(content).end();
    }
    return builder.build();
}
Also used : TypeCheckData(com.oracle.truffle.dsl.processor.model.TypeCheckData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 59 with CodeTreeBuilder

use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.

the class TypeSystemCodeGenerator method callImplictMethodFlat.

private static CodeTree callImplictMethodFlat(TypeSystemData typeSystem, TypeMirror type, String methodName, CodeTree value, CodeTree state) {
    if (ElementUtils.isObject(type)) {
        return value;
    }
    CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
    builder.startStaticCall(createTypeSystemGen(typeSystem), methodName);
    if (state != null) {
        builder.tree(state);
    }
    builder.tree(value);
    builder.end();
    return builder.build();
}
Also used : CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 60 with CodeTreeBuilder

use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.

the class TypeSystemCodeGenerator method invokeImplicitCast.

static CodeTree invokeImplicitCast(TypeSystemData typeSystem, ImplicitCastData cast, CodeTree expression) {
    CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
    builder.startStaticCall(createTypeSystemGen(typeSystem), cast.getMethodName()).tree(expression);
    builder.end();
    return builder.build();
}
Also used : CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Aggregations

CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)64 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)23 TypeMirror (javax.lang.model.type.TypeMirror)23 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)21 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)20 ArrayList (java.util.ArrayList)18 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)17 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)16 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)13 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)12 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)8 VariableElement (javax.lang.model.element.VariableElement)8 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)7 ExecutableElement (javax.lang.model.element.ExecutableElement)7 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)5 ExecutableTypeData (com.oracle.truffle.dsl.processor.model.ExecutableTypeData)5 Arrays (java.util.Arrays)5 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)4 AssumptionExpression (com.oracle.truffle.dsl.processor.model.AssumptionExpression)4 SpecializationGroup (com.oracle.truffle.dsl.processor.parser.SpecializationGroup)4