Search in sources :

Example 1 with ParameterSpec

use of com.oracle.truffle.dsl.processor.model.ParameterSpec 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 ParameterSpec

use of com.oracle.truffle.dsl.processor.model.ParameterSpec 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 3 with ParameterSpec

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

the class MethodSpecParser method parseImpl.

public TemplateMethod parseImpl(MethodSpec methodSpecification, int naturalOrder, String id, ExecutableElement method, AnnotationMirror annotation, TypeMirror returnType, List<? extends VariableElement> parameterTypes) {
    ParameterSpec returnTypeSpec = methodSpecification.getReturnType();
    Parameter returnTypeMirror = matchParameter(returnTypeSpec, new CodeVariableElement(returnType, "returnType"), -1, -1);
    if (returnTypeMirror == null) {
        if (isEmitErrors() && method != null) {
            TemplateMethod invalidMethod = new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<Parameter>emptyList());
            String expectedReturnType = returnTypeSpec.toSignatureString(true);
            String actualReturnType = ElementUtils.getSimpleName(returnType);
            String message = String.format("The provided return type \"%s\" does not match expected return type \"%s\".\nExpected signature: \n %s", actualReturnType, expectedReturnType, methodSpecification.toSignatureString(method.getSimpleName().toString()));
            invalidMethod.addError(message);
            return invalidMethod;
        } else {
            return null;
        }
    }
    List<Parameter> parameters = parseParameters(methodSpecification, parameterTypes, isUseVarArgs() && method != null ? method.isVarArgs() : false);
    if (parameters == null) {
        if (isEmitErrors() && method != null) {
            TemplateMethod invalidMethod = new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<Parameter>emptyList());
            String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(method), methodSpecification.toSignatureString(method.getSimpleName().toString()));
            invalidMethod.addError(message);
            return invalidMethod;
        } else {
            return null;
        }
    }
    return new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, parameters);
}
Also used : TemplateMethod(com.oracle.truffle.dsl.processor.model.TemplateMethod) ParameterSpec(com.oracle.truffle.dsl.processor.model.ParameterSpec) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)

Example 4 with ParameterSpec

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

the class NodeMethodParser method createReturnParameterSpec.

protected ParameterSpec createReturnParameterSpec() {
    ParameterSpec returnValue = new ParameterSpec("returnValue", getPossibleReturnTypes());
    returnValue.setExecution(getNode().getThisExecution());
    return returnValue;
}
Also used : ParameterSpec(com.oracle.truffle.dsl.processor.model.ParameterSpec)

Example 5 with ParameterSpec

use of com.oracle.truffle.dsl.processor.model.ParameterSpec 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

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