Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/AbstractParser.java @ 16755:bd28da642eea
Truffle-DSL: Several new features implemented:
Implementation of a new code generation layout which shares code between generated nodes.
Declaration order of specializations is now used as specialization order.
Specializations do no longer perform fallthrough on respecialization, they now always respecialize from the first specialization.
Implemented support for contains relations between specializations.
Improved reachability error messages.
Preliminary support for @Implies.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:05 +0200 |
parents | 4830676526e3 |
children |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/AbstractParser.java Mon Aug 11 15:53:05 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/AbstractParser.java Mon Aug 11 15:53:05 2014 +0200 @@ -30,6 +30,7 @@ import javax.tools.Diagnostic.Kind; import com.oracle.truffle.dsl.processor.template.*; +import com.oracle.truffle.dsl.processor.template.MessageContainer.*; /** * THIS IS NOT PUBLIC API. @@ -42,10 +43,10 @@ protected final Log log; - public AbstractParser(ProcessorContext c) { - this.context = c; - this.processingEnv = c.getEnvironment(); - this.log = c.getLog(); + public AbstractParser() { + this.context = ProcessorContext.getInstance(); + this.processingEnv = context.getEnvironment(); + this.log = context.getLog(); } public final M parse(RoundEnvironment env, Element element) { @@ -65,7 +66,8 @@ return null; } - model.emitMessages(context, (TypeElement) element, log); + redirectMessages(new HashSet<MessageContainer>(), model, model); + model.emitMessages(context, log); 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()); @@ -75,6 +77,51 @@ } } + 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 (!Utils.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, 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); + } + } + + private static String wrapText(Element element, AnnotationMirror mirror, String text) { + StringBuilder b = new StringBuilder(); + if (element != null) { + b.append("Element " + element.toString()); + } + if (mirror != null) { + b.append(" at annotation @" + Utils.getSimpleName(mirror.getAnnotationType())); + } + + if (b.length() > 0) { + b.append(" is erroneous: ").append(text); + return b.toString(); + } else { + return text; + } + } + protected M filterErrorElements(M model) { return model.hasErrors() ? null : model; }