Mercurial > hg > graal-jvmci-8
changeset 4397:403330cfd3da
Added Formattable interface to node base class in order to allow custom handling of formatter specifiers for the node class.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 28 Jan 2012 23:52:45 +0100 |
parents | 4023bae16d02 |
children | 292fbdb2dd20 |
files | graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java |
diffstat | 1 files changed, 65 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Sat Jan 28 23:14:46 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Sat Jan 28 23:52:45 2012 +0100 @@ -25,6 +25,8 @@ import java.lang.annotation.*; import java.util.*; +import com.oracle.max.graal.graph.NodeClass.*; + /** * This class is the base class for all nodes, it represent a node which can be inserted in a {@link Graph}.<br> @@ -45,7 +47,7 @@ * * */ -public abstract class Node implements Cloneable { +public abstract class Node implements Cloneable, Formattable { static final int DELETED_ID_START = -1000000000; static final int INITIAL_ID = -1; @@ -490,4 +492,66 @@ throw new RuntimeException("unknown verbosity: " + verbosity); } } + + @Override + public void formatTo(Formatter formatter, int flags, int width, int precision) { + if ((flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE) { + formatter.format(toString(Verbosity.Id)); + } else if ((flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE) { + formatter.format(toString(Verbosity.Long)); + } else { + formatter.format(toString(Verbosity.Short)); + } + + boolean neighborsAlternate = ((flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY); + int neighborsFlags = (neighborsAlternate ? FormattableFlags.ALTERNATE | FormattableFlags.LEFT_JUSTIFY : 0); + if (width > 0) { + if (this.predecessor != null) { + formatter.format(" pred={"); + this.predecessor.formatTo(formatter, neighborsFlags, width - 1, 0); + formatter.format("}"); + } + + NodeClassIterator inputIter = inputs().iterator(); + while (inputIter.hasNext()) { + Position position = inputIter.nextPosition(); + Node input = getNodeClass().get(this, position); + if (input != null) { + formatter.format(" "); + formatter.format(getNodeClass().getName(position)); + formatter.format("={"); + input.formatTo(formatter, neighborsFlags, width - 1, 0); + formatter.format("}"); + } + } + } + + if (precision > 0) { + if (this.usages.size() > 0) { + formatter.format(" usages={"); + int z = 0; + for (Node usage : this.usages) { + if (z != 0) { + formatter.format(", "); + } + usage.formatTo(formatter, neighborsFlags, 0, precision - 1); + ++z; + } + formatter.format("}"); + } + + NodeClassIterator succIter = successors().iterator(); + while (succIter.hasNext()) { + Position position = succIter.nextPosition(); + Node successor = getNodeClass().get(this, position); + if (successor != null) { + formatter.format(" "); + formatter.format(getNodeClass().getName(position)); + formatter.format("={"); + successor.formatTo(formatter, neighborsFlags, 0, precision - 1); + formatter.format("}"); + } + } + } + } }