Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 10704:84b944726df2
Truffle: introduce NodeUtil.countNodes
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Thu, 11 Jul 2013 12:22:51 +0200 |
parents | 98b004bf3985 |
children | 99789440ce28 |
comparison
equal
deleted
inserted
replaced
10703:7cdd4708b1aa | 10704:84b944726df2 |
---|---|
506 } | 506 } |
507 }); | 507 }); |
508 return nodeList; | 508 return nodeList; |
509 } | 509 } |
510 | 510 |
511 public static int countNodes(Node root) { | |
512 NodeCountVisitor nodeCount = new NodeCountVisitor(); | |
513 root.accept(nodeCount); | |
514 return nodeCount.nodeCount; | |
515 } | |
516 | |
517 private static class NodeCountVisitor implements NodeVisitor { | |
518 | |
519 int nodeCount; | |
520 | |
521 @Override | |
522 public boolean visit(Node node) { | |
523 if (node instanceof RootNode && nodeCount > 0) { | |
524 return false; | |
525 } | |
526 nodeCount++; | |
527 return true; | |
528 } | |
529 } | |
530 | |
511 public static String printCompactTreeToString(Node node) { | 531 public static String printCompactTreeToString(Node node) { |
512 StringWriter out = new StringWriter(); | 532 StringWriter out = new StringWriter(); |
513 printCompactTree(new PrintWriter(out), null, node, 1); | 533 printCompactTree(new PrintWriter(out), null, node, 1); |
514 return out.toString(); | 534 return out.toString(); |
515 } | 535 } |