Search in sources :

Example 1 with Message

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

Example 2 with Message

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

the class NodeCodeGenerator method generateErrorNode.

private static void generateErrorNode(ProcessorContext context, NodeData node, CodeTypeElement type) {
    for (ExecutableElement superConstructor : GeneratorUtils.findUserConstructors(node.getTemplateType().asType())) {
        CodeExecutableElement constructor = GeneratorUtils.createConstructorUsingFields(modifiers(), type, superConstructor);
        ElementUtils.setVisibility(constructor.getModifiers(), ElementUtils.getVisibility(superConstructor.getModifiers()));
        List<CodeVariableElement> childParameters = new ArrayList<>();
        for (NodeChildData child : node.getChildren()) {
            childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName()));
        }
        constructor.getParameters().addAll(superConstructor.getParameters().size(), childParameters);
        type.add(constructor);
    }
    for (ExecutableElement method : ElementFilter.methodsIn(context.getEnvironment().getElementUtils().getAllMembers(node.getTemplateType()))) {
        if (method.getModifiers().contains(Modifier.ABSTRACT) && ElementUtils.getVisibility(method.getModifiers()) != Modifier.PRIVATE) {
            CodeExecutableElement overrideMethod = CodeExecutableElement.clone(context.getEnvironment(), method);
            overrideMethod.getModifiers().remove(Modifier.ABSTRACT);
            List<Message> messages = node.collectMessages();
            String message = messages.toString();
            message = message.replaceAll("\"", "\\\\\"");
            message = message.replaceAll("\n", "\\\\n");
            overrideMethod.createBuilder().startThrow().startNew(context.getType(RuntimeException.class)).doubleQuote("Truffle DSL compiler errors: " + message).end().end();
            type.add(overrideMethod);
        }
    }
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) NodeChildData(com.oracle.truffle.dsl.processor.model.NodeChildData) Message(com.oracle.truffle.dsl.processor.model.MessageContainer.Message) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)

Aggregations

Message (com.oracle.truffle.dsl.processor.model.MessageContainer.Message)2 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1 MessageContainer (com.oracle.truffle.dsl.processor.model.MessageContainer)1 NodeChildData (com.oracle.truffle.dsl.processor.model.NodeChildData)1 ArrayList (java.util.ArrayList)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1