Search in sources :

Example 1 with TemplateMethod

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

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

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

the class NodeParser method initializeUninitialized.

private static void initializeUninitialized(final NodeData node) {
    SpecializationData generic = node.getGenericSpecialization();
    if (generic == null) {
        return;
    }
    TemplateMethod uninializedMethod = new TemplateMethod("Uninitialized", -1, node, generic.getSpecification(), null, null, generic.getReturnType(), generic.getParameters());
    // should not use messages from generic specialization
    uninializedMethod.getMessages().clear();
    node.getSpecializations().add(new SpecializationData(node, uninializedMethod, SpecializationKind.UNINITIALIZED));
}
Also used : TemplateMethod(com.oracle.truffle.dsl.processor.model.TemplateMethod) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData)

Aggregations

TemplateMethod (com.oracle.truffle.dsl.processor.model.TemplateMethod)3 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1 MethodSpec (com.oracle.truffle.dsl.processor.model.MethodSpec)1 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)1 ParameterSpec (com.oracle.truffle.dsl.processor.model.ParameterSpec)1 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)1