Mercurial > hg > truffle
changeset 10845:e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Mon, 22 Jul 2013 17:29:48 +0200 |
parents | 3cf5f371dc9f |
children | e87d56a51047 |
files | graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java |
diffstat | 1 files changed, 17 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Mon Jul 22 16:20:43 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Mon Jul 22 17:29:48 2013 +0200 @@ -344,7 +344,11 @@ for (long fieldOffset : nodeClass.childrenOffsets) { Node[] children = (Node[]) unsafe.getObject(node, fieldOffset); if (children != null) { - nodes.addAll(Arrays.asList(children)); + for (Node child : children) { + if (child != null) { + nodes.add(child); + } + } } } @@ -545,23 +549,25 @@ } public static int countNodes(Node root, Class<?> clazz) { - NodeCountVisitor nodeCount = new NodeCountVisitor(clazz); + NodeCountVisitor nodeCount = new NodeCountVisitor(root, clazz); root.accept(nodeCount); return nodeCount.nodeCount; } private static final class NodeCountVisitor implements NodeVisitor { + int nodeCount; + private final Node root; private final Class<?> clazz; - int nodeCount; - private NodeCountVisitor(Class<?> clazz) { + private NodeCountVisitor(Node root, Class<?> clazz) { + this.root = root; this.clazz = clazz; } @Override public boolean visit(Node node) { - if (node instanceof RootNode && nodeCount > 0) { + if (node instanceof RootNode && node != root) { return false; } if (clazz == null || clazz.isInstance(node)) { @@ -589,7 +595,7 @@ p.print(" "); } if (parent == null) { - p.println(node.getClass().getSimpleName()); + p.println(nodeName(node)); } else { String fieldName = "unknownField"; NodeField[] fields = NodeClass.get(parent.getClass()).fields; @@ -611,7 +617,7 @@ } p.print(fieldName); p.print(" = "); - p.println(node.getClass().getSimpleName()); + p.println(nodeName(node)); } for (Node child : node.getChildren()) { @@ -649,7 +655,7 @@ return; } - p.print(node.getClass().getSimpleName()); + p.print(nodeName(node)); ArrayList<NodeField> childFields = new ArrayList<>(); String sep = ""; @@ -704,4 +710,7 @@ } } + private static String nodeName(Node node) { + return node.getClass().getSimpleName(); + } }