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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations