# HG changeset patch # User Andreas Woess # Date 1374506988 -7200 # Node ID e9248ebb1d79340442ed18c0be2ee4a3356c588b # Parent 3cf5f371dc9f9d2caef0210322519f148fa5a706 Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring. diff -r 3cf5f371dc9f -r e9248ebb1d79 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java --- 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 childFields = new ArrayList<>(); String sep = ""; @@ -704,4 +710,7 @@ } } + private static String nodeName(Node node) { + return node.getClass().getSimpleName(); + } }