use of com.oracle.truffle.dsl.processor.model.AssumptionExpression in project graal by oracle.
the class NodeParser method initializeAssumptions.
private void initializeAssumptions(SpecializationData specialization, DSLExpressionResolver resolver) {
final DeclaredType assumptionType = context.getDeclaredType(Assumption.class);
final TypeMirror assumptionArrayType = new ArrayCodeTypeMirror(assumptionType);
final List<String> assumptionDefinitions = ElementUtils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "assumptions");
List<AssumptionExpression> assumptionExpressions = new ArrayList<>();
int assumptionId = 0;
for (String assumption : assumptionDefinitions) {
AssumptionExpression assumptionExpression;
DSLExpression expression = null;
try {
expression = DSLExpression.parse(assumption);
expression.accept(resolver);
assumptionExpression = new AssumptionExpression(specialization, expression, "assumption" + assumptionId);
if (!ElementUtils.isAssignable(expression.getResolvedType(), assumptionType) && !ElementUtils.isAssignable(expression.getResolvedType(), assumptionArrayType)) {
assumptionExpression.addError("Incompatible return type %s. Assumptions must be assignable to %s or %s.", ElementUtils.getSimpleName(expression.getResolvedType()), ElementUtils.getSimpleName(assumptionType), ElementUtils.getSimpleName(assumptionArrayType));
}
if (specialization.isDynamicParameterBound(expression)) {
specialization.addError("Assumption expressions must not bind dynamic parameter values.");
}
} catch (InvalidExpressionException e) {
assumptionExpression = new AssumptionExpression(specialization, null, "assumption" + assumptionId);
assumptionExpression.addError("Error parsing expression '%s': %s", assumption, e.getMessage());
}
assumptionExpressions.add(assumptionExpression);
assumptionId++;
}
specialization.setAssumptionExpressions(assumptionExpressions);
}
Aggregations