Search in sources :

Example 1 with MessageContainer

use of com.oracle.truffle.dsl.processor.model.MessageContainer 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 2 with MessageContainer

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

the class AbstractParser method redirectMessages.

private void redirectMessages(Set<MessageContainer> visitedSinks, MessageContainer model, MessageContainer baseContainer) {
    List<Message> messages = model.getMessages();
    for (int i = messages.size() - 1; i >= 0; i--) {
        Message message = messages.get(i);
        if (!ElementUtils.isEnclosedIn(baseContainer.getMessageElement(), message.getOriginalContainer().getMessageElement())) {
            // redirect message
            MessageContainer original = message.getOriginalContainer();
            String text = wrapText(original.getMessageElement(), original.getMessageAnnotation(), message.getText());
            Message redirectedMessage = new Message(null, null, baseContainer, text, message.getKind());
            model.getMessages().remove(i);
            baseContainer.getMessages().add(redirectedMessage);
        }
    }
    for (MessageContainer childContainer : model) {
        if (visitedSinks.contains(childContainer)) {
            continue;
        }
        visitedSinks.add(childContainer);
        MessageContainer newBase = baseContainer;
        if (childContainer.getBaseContainer() != null) {
            newBase = childContainer.getBaseContainer();
        }
        redirectMessages(visitedSinks, childContainer, newBase);
    }
}
Also used : Message(com.oracle.truffle.dsl.processor.model.MessageContainer.Message) MessageContainer(com.oracle.truffle.dsl.processor.model.MessageContainer)

Aggregations

MessageContainer (com.oracle.truffle.dsl.processor.model.MessageContainer)2 CompileErrorException (com.oracle.truffle.dsl.processor.CompileErrorException)1 Message (com.oracle.truffle.dsl.processor.model.MessageContainer.Message)1 NodeData (com.oracle.truffle.dsl.processor.model.NodeData)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1