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);
}
}
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);
}
}
}
Aggregations