Search in sources :

Example 6 with AssumptionExpression

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);
}
Also used : ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) InvalidExpressionException(com.oracle.truffle.dsl.processor.expression.InvalidExpressionException) ArrayList(java.util.ArrayList) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression) DeclaredType(javax.lang.model.type.DeclaredType) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression)

Aggregations

AssumptionExpression (com.oracle.truffle.dsl.processor.model.AssumptionExpression)6 ArrayList (java.util.ArrayList)5 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)4 DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)2 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)2 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)2 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)2 TypeMirror (javax.lang.model.type.TypeMirror)2 Assumption (com.oracle.truffle.api.Assumption)1 Cached (com.oracle.truffle.api.dsl.Cached)1 Node (com.oracle.truffle.api.nodes.Node)1 Child (com.oracle.truffle.api.nodes.Node.Child)1 NodeCost (com.oracle.truffle.api.nodes.NodeCost)1 NodeInterface (com.oracle.truffle.api.nodes.NodeInterface)1 InvalidExpressionException (com.oracle.truffle.dsl.processor.expression.InvalidExpressionException)1 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)1 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)1 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)1 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1