Search in sources :

Example 1 with CompileErrorException

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

the class ElementUtils method getTypeId.

public static String getTypeId(TypeMirror mirror) {
    switch(mirror.getKind()) {
        case BOOLEAN:
            return "Boolean";
        case BYTE:
            return "Byte";
        case CHAR:
            return "Char";
        case DOUBLE:
            return "Double";
        case FLOAT:
            return "Float";
        case SHORT:
            return "Short";
        case INT:
            return "Int";
        case LONG:
            return "Long";
        case DECLARED:
            return fixECJBinaryNameIssue(((DeclaredType) mirror).asElement().getSimpleName().toString());
        case ARRAY:
            return getTypeId(((ArrayType) mirror).getComponentType()) + "Array";
        case VOID:
            return "Void";
        case NULL:
            return "Null";
        case WILDCARD:
            StringBuilder b = new StringBuilder();
            WildcardType type = (WildcardType) mirror;
            if (type.getExtendsBound() != null) {
                b.append("Extends").append(getTypeId(type.getExtendsBound()));
            } else if (type.getSuperBound() != null) {
                b.append("Super").append(getTypeId(type.getExtendsBound()));
            }
            return b.toString();
        case TYPEVAR:
            return "Any";
        case ERROR:
            throw new CompileErrorException("Type error " + mirror);
        default:
            throw new RuntimeException("Unknown type specified " + mirror.getKind() + " mirror: " + mirror);
    }
}
Also used : ArrayType(javax.lang.model.type.ArrayType) WildcardType(javax.lang.model.type.WildcardType) CompileErrorException(com.oracle.truffle.dsl.processor.CompileErrorException)

Example 2 with CompileErrorException

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

the class AbstractParser method parse.

public final M parse(Element element) {
    M model = null;
    try {
        AnnotationMirror mirror = null;
        if (getAnnotationType() != null) {
            mirror = ElementUtils.findAnnotationMirror(processingEnv, element.getAnnotationMirrors(), getAnnotationType());
        }
        if (!context.getTruffleTypes().verify(context, element, mirror)) {
            return null;
        }
        model = parse(element, mirror);
        if (model == null) {
            return null;
        }
        redirectMessages(new HashSet<MessageContainer>(), model, model);
        model.emitMessages(context, log);
        if (model instanceof NodeData) {
            return model;
        } else {
            return filterErrorElements(model);
        }
    } catch (CompileErrorException e) {
        log.message(Kind.WARNING, element, null, null, "The truffle processor could not parse class due to error: %s", e.getMessage());
        return null;
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) MessageContainer(com.oracle.truffle.dsl.processor.model.MessageContainer) NodeData(com.oracle.truffle.dsl.processor.model.NodeData) CompileErrorException(com.oracle.truffle.dsl.processor.CompileErrorException)

Example 3 with CompileErrorException

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

the class NodeParser method parseRootType.

private NodeData parseRootType(TypeElement rootType) {
    List<NodeData> enclosedNodes = new ArrayList<>();
    for (TypeElement enclosedType : ElementFilter.typesIn(rootType.getEnclosedElements())) {
        NodeData enclosedChild = parseRootType(enclosedType);
        if (enclosedChild != null) {
            enclosedNodes.add(enclosedChild);
        }
    }
    NodeData node;
    try {
        node = parseNode(rootType);
    } catch (CompileErrorException e) {
        throw e;
    } catch (Throwable e) {
        RuntimeException e2 = new RuntimeException(String.format("Parsing of Node %s failed.", ElementUtils.getQualifiedName(rootType)));
        e2.addSuppressed(e);
        throw e2;
    }
    if (node == null && !enclosedNodes.isEmpty()) {
        node = new NodeData(context, rootType);
    }
    if (node != null) {
        for (NodeData enclosedNode : enclosedNodes) {
            node.addEnclosedNode(enclosedNode);
        }
    }
    return node;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) NodeData(com.oracle.truffle.dsl.processor.model.NodeData) CompileErrorException(com.oracle.truffle.dsl.processor.CompileErrorException)

Aggregations

CompileErrorException (com.oracle.truffle.dsl.processor.CompileErrorException)3 NodeData (com.oracle.truffle.dsl.processor.model.NodeData)2 MessageContainer (com.oracle.truffle.dsl.processor.model.MessageContainer)1 ArrayList (java.util.ArrayList)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 TypeElement (javax.lang.model.element.TypeElement)1 ArrayType (javax.lang.model.type.ArrayType)1 WildcardType (javax.lang.model.type.WildcardType)1