Search in sources :

Example 1 with MethodSpec

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

the class NodeParser method createGenericSpecialization.

private SpecializationData createGenericSpecialization(final NodeData node) {
    FallbackParser parser = new FallbackParser(context, node);
    MethodSpec specification = parser.createDefaultMethodSpec(node.getSpecializations().iterator().next().getMethod(), null, true, null);
    List<VariableElement> parameterTypes = new ArrayList<>();
    int signatureIndex = 1;
    for (ParameterSpec spec : specification.getRequired()) {
        parameterTypes.add(new CodeVariableElement(createGenericType(node, spec), "arg" + signatureIndex));
        if (spec.isSignature()) {
            signatureIndex++;
        }
    }
    TypeMirror returnType = createGenericType(node, specification.getReturnType());
    SpecializationData generic = parser.create("Generic", TemplateMethod.NO_NATURAL_ORDER, null, null, returnType, parameterTypes);
    if (generic == null) {
        throw new RuntimeException("Unable to create generic signature for node " + node.getNodeId() + " with " + parameterTypes + ". Specification " + specification + ".");
    }
    return generic;
}
Also used : MethodSpec(com.oracle.truffle.dsl.processor.model.MethodSpec) ParameterSpec(com.oracle.truffle.dsl.processor.model.ParameterSpec) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) ArrayList(java.util.ArrayList) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) VariableElement(javax.lang.model.element.VariableElement)

Example 2 with MethodSpec

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

the class SpecializationMethodParser method createSpecification.

@Override
public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) {
    MethodSpec spec = createDefaultMethodSpec(method, mirror, true, null);
    spec.getAnnotations().add(new CachedParameterSpec(getContext().getDeclaredType(Cached.class)));
    return spec;
}
Also used : CachedParameterSpec(com.oracle.truffle.dsl.processor.model.CachedParameterSpec) MethodSpec(com.oracle.truffle.dsl.processor.model.MethodSpec)

Example 3 with MethodSpec

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

the class TemplateMethodParser method parse.

private E parse(int naturalOrder, ExecutableElement method, AnnotationMirror annotation) {
    MethodSpec methodSpecification = createSpecification(method, annotation);
    if (methodSpecification == null) {
        return null;
    }
    TemplateMethod templateMethod = parser.parse(methodSpecification, method, annotation, naturalOrder);
    if (templateMethod != null) {
        return create(templateMethod, templateMethod.hasErrors());
    }
    return null;
}
Also used : TemplateMethod(com.oracle.truffle.dsl.processor.model.TemplateMethod) MethodSpec(com.oracle.truffle.dsl.processor.model.MethodSpec)

Example 4 with MethodSpec

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

the class TypeCastParser method createSpecification.

@Override
public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) {
    TypeMirror targetTypeMirror = ElementUtils.getAnnotationValue(TypeMirror.class, mirror, "value");
    ParameterSpec returnTypeSpec = new ParameterSpec("returnType", targetTypeMirror);
    returnTypeSpec.setAllowSubclasses(false);
    MethodSpec spec = new MethodSpec(returnTypeSpec);
    spec.addRequired(new ParameterSpec("value", getContext().getType(Object.class)));
    return spec;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ParameterSpec(com.oracle.truffle.dsl.processor.model.ParameterSpec) MethodSpec(com.oracle.truffle.dsl.processor.model.MethodSpec)

Example 5 with MethodSpec

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

the class CreateCastParser method createSpecification.

@Override
public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) {
    List<String> childNames = ElementUtils.getAnnotationValueList(String.class, mirror, "value");
    NodeChildData foundChild = null;
    for (String childName : childNames) {
        foundChild = getNode().findChild(childName);
        if (foundChild != null) {
            break;
        }
    }
    TypeMirror baseType = getContext().getTruffleTypes().getNode();
    if (foundChild != null) {
        baseType = foundChild.getOriginalType();
    }
    MethodSpec spec = new MethodSpec(new ParameterSpec("child", baseType));
    addDefaultFieldMethodSpec(spec);
    ParameterSpec childSpec = new ParameterSpec("castedChild", baseType);
    childSpec.setSignature(true);
    spec.addRequired(childSpec);
    return spec;
}
Also used : NodeChildData(com.oracle.truffle.dsl.processor.model.NodeChildData) TypeMirror(javax.lang.model.type.TypeMirror) MethodSpec(com.oracle.truffle.dsl.processor.model.MethodSpec) ParameterSpec(com.oracle.truffle.dsl.processor.model.ParameterSpec)

Aggregations

MethodSpec (com.oracle.truffle.dsl.processor.model.MethodSpec)8 ParameterSpec (com.oracle.truffle.dsl.processor.model.ParameterSpec)5 TypeMirror (javax.lang.model.type.TypeMirror)3 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1 CachedParameterSpec (com.oracle.truffle.dsl.processor.model.CachedParameterSpec)1 NodeChildData (com.oracle.truffle.dsl.processor.model.NodeChildData)1 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)1 TemplateMethod (com.oracle.truffle.dsl.processor.model.TemplateMethod)1 ArrayList (java.util.ArrayList)1 VariableElement (javax.lang.model.element.VariableElement)1