Search in sources :

Example 1 with MatchableNode

use of org.graalvm.compiler.core.match.MatchableNode in project graal by oracle.

the class MatchProcessor method processMatchableNode.

/**
 * Build up the type table to be used during parsing of the MatchRule.
 */
private void processMatchableNode(Element element) {
    if (!processedMatchableNode.contains(element)) {
        try {
            processedMatchableNode.add(element);
            AnnotationMirror mirror = findAnnotationMirror(element, matchableNodesTypeMirror);
            if (mirror == null) {
                mirror = findAnnotationMirror(element, matchableNodeTypeMirror);
            }
            if (mirror == null) {
                return;
            }
            TypeElement topDeclaringType = topDeclaringType(element);
            List<AnnotationMirror> mirrors = null;
            if (typeUtils().isSameType(mirror.getAnnotationType(), matchableNodesTypeMirror)) {
                // Unpack the mirrors for a repeatable annotation
                mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value");
            }
            int i = 0;
            for (MatchableNode matchableNode : element.getAnnotationsByType(MatchableNode.class)) {
                processMatchableNode(element, topDeclaringType, matchableNode, mirrors != null ? mirrors.get(i++) : mirror);
            }
        } catch (Throwable t) {
            reportExceptionThrow(element, t);
        }
    }
}
Also used : MatchableNode(org.graalvm.compiler.core.match.MatchableNode) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement)

Example 2 with MatchableNode

use of org.graalvm.compiler.core.match.MatchableNode in project graal by oracle.

the class MatchProcessor method processMatchableNode.

private void processMatchableNode(Element element, TypeElement topDeclaringType, MatchableNode matchable, AnnotationMirror mirror) throws GraalError {
    logMessage("processMatchableNode %s %s %s\n", topDeclaringType, element, matchable);
    String nodeClass;
    String nodePackage;
    TypeMirror nodeClassMirror = null;
    try {
        matchable.nodeClass();
    } catch (MirroredTypeException e) {
        nodeClassMirror = e.getTypeMirror();
    }
    if (nodeClassMirror == null) {
        throw new GraalError("Can't get mirror for node class %s", element);
    }
    if (nodeClassMirror.toString().equals(MatchableNode.class.getName())) {
        nodeClass = topDeclaringType.getQualifiedName().toString();
    } else {
        nodeClass = nodeClassMirror.toString();
    }
    TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(nodeClass);
    if (typeElement == null) {
        errorMessage(element, mirror, "Class \"%s\" cannot be resolved to a type", nodeClass);
        return;
    }
    nodePackage = findPackage(typeElement);
    assert nodeClass.startsWith(nodePackage);
    nodeClass = nodeClass.substring(nodePackage.length() + 1);
    assert nodeClass.endsWith("Node");
    String shortName = nodeClass.substring(0, nodeClass.length() - 4);
    Types typeUtils = processingEnv.getTypeUtils();
    TypeElement nodeClassElement = (TypeElement) typeUtils.asElement(nodeClassMirror);
    for (String input : matchable.inputs()) {
        boolean ok = false;
        TypeElement current = nodeClassElement;
        while (!ok && current != null) {
            for (Element fieldElement : ElementFilter.fieldsIn(current.getEnclosedElements())) {
                if (fieldElement.getSimpleName().toString().equals(input)) {
                    ok = true;
                    break;
                }
            }
            TypeMirror theSuper = current.getSuperclass();
            current = (TypeElement) typeUtils.asElement(theSuper);
        }
        if (!ok) {
            errorMessage(element, mirror, "Input named \"%s\" doesn't exist in %s", input, nodeClassElement.getSimpleName());
        }
    }
    declareType(nodeClassMirror, shortName, nodeClass, nodePackage, matchable.inputs(), matchable.commutative(), matchable.shareable(), element);
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) MatchableNode(org.graalvm.compiler.core.match.MatchableNode) SupportedAnnotationTypes(javax.annotation.processing.SupportedAnnotationTypes) Types(javax.lang.model.util.Types) GraalError(org.graalvm.compiler.debug.GraalError) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement)

Aggregations

TypeElement (javax.lang.model.element.TypeElement)2 MatchableNode (org.graalvm.compiler.core.match.MatchableNode)2 SupportedAnnotationTypes (javax.annotation.processing.SupportedAnnotationTypes)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 PackageElement (javax.lang.model.element.PackageElement)1 VariableElement (javax.lang.model.element.VariableElement)1 MirroredTypeException (javax.lang.model.type.MirroredTypeException)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Types (javax.lang.model.util.Types)1 GraalError (org.graalvm.compiler.debug.GraalError)1