Search in sources :

Example 16 with CodeTree

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

the class AbstractCodeWriter method visitVariable.

@Override
public Void visitVariable(VariableElement f, Void p) {
    Element parent = f.getEnclosingElement();
    for (AnnotationMirror annotation : f.getAnnotationMirrors()) {
        visitAnnotation(f, annotation);
        write(" ");
    }
    CodeTree init = null;
    if (f instanceof CodeVariableElement) {
        init = ((CodeVariableElement) f).getInit();
    }
    if (parent != null && parent.getKind() == ElementKind.ENUM && f.getModifiers().contains(Modifier.STATIC)) {
        write(f.getSimpleName());
        if (init != null) {
            write("(");
            visitTree(init, p, f);
            write(")");
        }
    } else {
        writeModifiers(f.getModifiers(), true);
        boolean varArgs = false;
        if (parent != null && parent.getKind() == ElementKind.METHOD) {
            ExecutableElement method = (ExecutableElement) parent;
            if (method.isVarArgs() && method.getParameters().indexOf(f) == method.getParameters().size() - 1) {
                varArgs = true;
            }
        }
        TypeMirror varType = f.asType();
        if (varArgs) {
            if (varType.getKind() == TypeKind.ARRAY) {
                varType = ((ArrayType) varType).getComponentType();
            }
            write(useImport(f, varType));
            write("...");
        } else {
            write(useImport(f, varType));
        }
        write(" ");
        write(f.getSimpleName());
        if (init != null) {
            write(" = ");
            visitTree(init, p, f);
        }
    }
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeParameterElement(javax.lang.model.element.TypeParameterElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)

Example 17 with CodeTree

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

the class DSLExpressionGenerator method visitBinary.

public void visitBinary(Binary binary) {
    CodeTree right = stack.pop();
    CodeTree left = stack.pop();
    stack.push(combine(left, string(" " + binary.getOperator() + " "), right));
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree)

Example 18 with CodeTree

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

the class DSLExpressionGenerator method visitVariable.

public void visitVariable(Variable variable) {
    VariableElement resolvedVariable = variable.getResolvedVariable();
    CodeTree tree;
    if (variable.getResolvedType().getKind() == TypeKind.NULL) {
        tree = CodeTreeBuilder.singleString("null");
    } else if (variable.getReceiver() == null) {
        if (isStatic(resolvedVariable)) {
            tree = staticReference(resolvedVariable);
        } else {
            tree = bindings.get(variable);
            boolean bound = true;
            if (tree == null) {
                tree = string(resolvedVariable.getSimpleName().toString());
                bound = false;
            }
            if (root != null && !bound) {
                tree = combine(root, string("."), tree);
            }
        }
    } else {
        if (isStatic(resolvedVariable)) {
            throw new AssertionError("Static variables cannot have receivers.");
        }
        tree = combine(pop(), string("."), string(resolvedVariable.getSimpleName().toString()));
    }
    push(tree);
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) VariableElement(javax.lang.model.element.VariableElement)

Example 19 with CodeTree

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

the class FlatNodeGenFactory method createCallSingleChildExecute.

private ChildExecutionResult createCallSingleChildExecute(NodeExecutionData execution, LocalVariable target, FrameState frameState, ExecutableTypeData executableType) {
    CodeTree execute = callChildExecuteMethod(execution, executableType, frameState);
    TypeMirror sourceType = executableType.getReturnType();
    TypeMirror targetType = target.getTypeMirror();
    CodeTree result = expect(sourceType, targetType, execute);
    return new ChildExecutionResult(result, executableType.hasUnexpectedValue(context) || needsCastTo(sourceType, targetType));
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror)

Example 20 with CodeTree

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

the class FlatNodeGenFactory method createExecuteAndSpecialize.

private CodeExecutableElement createExecuteAndSpecialize() {
    if (!node.needsRewrites(context)) {
        return null;
    }
    final FrameState frameState = FrameState.load(this);
    String frame = null;
    if (needsFrameToExecute(reachableSpecializations)) {
        frame = FRAME_VALUE;
    }
    TypeMirror returnType = executeAndSpecializeType.getReturnType();
    CodeExecutableElement method = frameState.createMethod(modifiers(PRIVATE), returnType, "executeAndSpecialize", frame);
    final CodeTreeBuilder builder = method.createBuilder();
    builder.declaration(context.getType(Lock.class), "lock", "getLock()");
    builder.declaration(context.getType(boolean.class), "hasLock", "true");
    builder.statement("lock.lock()");
    builder.tree(state.createLoad(frameState));
    if (requiresExclude()) {
        builder.tree(exclude.createLoad(frameState));
    }
    if (shouldReportPolymorphism(node, reachableSpecializations)) {
        generateSaveOldPolymorphismState(builder, frameState);
    }
    builder.startTryBlock();
    FrameState originalFrameState = frameState.copy();
    SpecializationGroup group = createSpecializationGroups();
    CodeTree execution = visitSpecializationGroup(builder, group, executeAndSpecializeType, frameState, null, NodeExecutionMode.SLOW_PATH);
    builder.tree(execution);
    if (group.hasFallthrough()) {
        builder.tree(createTransferToInterpreterAndInvalidate());
        builder.tree(createThrowUnsupported(builder, originalFrameState));
    }
    builder.end().startFinallyBlock();
    if (shouldReportPolymorphism(node, reachableSpecializations)) {
        generateCheckNewPolymorphismState(builder);
    }
    builder.startIf().string("hasLock").end().startBlock();
    builder.statement("lock.unlock()");
    builder.end();
    builder.end();
    return method;
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) SpecializationGroup(com.oracle.truffle.dsl.processor.parser.SpecializationGroup) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) Lock(java.util.concurrent.locks.Lock)

Aggregations

CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)34 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)21 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)14 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)14 TypeMirror (javax.lang.model.type.TypeMirror)14 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)13 ArrayList (java.util.ArrayList)13 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)6 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)6 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)5 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)5 VariableElement (javax.lang.model.element.VariableElement)5 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)4 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)3 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)3 SpecializationGroup (com.oracle.truffle.dsl.processor.parser.SpecializationGroup)3 TypeGuard (com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)2 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)2