Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java @ 22536:21f48bc8a535
GraphPrintVisitor API cleanup
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Thu, 07 Jan 2016 15:37:19 +0100 |
parents | 23d2b5513c83 |
children |
comparison
equal
deleted
inserted
replaced
22535:9b9301abe3ff | 22536:21f48bc8a535 |
---|---|
433 } else { | 433 } else { |
434 return nextId(); | 434 return nextId(); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 /** | 438 final NodeElement getElementByObject(Object obj) { |
439 * @deprecated to be removed | |
440 */ | |
441 @Deprecated | |
442 protected Object getElementByObject(Object obj) { | |
443 return getElementByObjectImpl(obj); | |
444 } | |
445 | |
446 final NodeElement getElementByObjectImpl(Object obj) { | |
447 return nodeMap.get(obj); | 439 return nodeMap.get(obj); |
448 } | 440 } |
449 | 441 |
450 /** | 442 final void createElementForNode(Object node) { |
451 * @deprecated to be removed | |
452 */ | |
453 @Deprecated | |
454 protected void createElementForNode(Object node) { | |
455 boolean exists = nodeMap.containsKey(node); | 443 boolean exists = nodeMap.containsKey(node); |
456 if (!exists) { | 444 if (!exists) { |
457 int nodeId = !exists ? oldOrNextId(node) : nextId(); | 445 int nodeId = !exists ? oldOrNextId(node) : nextId(); |
458 nodeMap.put(node, new NodeElement(nodeId)); | 446 nodeMap.put(node, new NodeElement(nodeId)); |
459 | 447 |
460 setNodePropertyImpl(node, "name", node.getClass().getSimpleName().replaceFirst("Node$", "")); | 448 setNodeProperty(node, "name", node.getClass().getSimpleName().replaceFirst("Node$", "")); |
461 NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); | 449 NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); |
462 if (nodeInfo != null) { | 450 if (nodeInfo != null) { |
463 setNodePropertyImpl(node, "cost", nodeInfo.cost()); | 451 setNodeProperty(node, "cost", nodeInfo.cost()); |
464 if (!nodeInfo.shortName().isEmpty()) { | 452 if (!nodeInfo.shortName().isEmpty()) { |
465 setNodePropertyImpl(node, "shortName", nodeInfo.shortName()); | 453 setNodeProperty(node, "shortName", nodeInfo.shortName()); |
466 } | 454 } |
467 } | 455 } |
468 setNodePropertyImpl(node, "class", node.getClass().getSimpleName()); | 456 setNodeProperty(node, "class", node.getClass().getSimpleName()); |
469 if (node instanceof Node) { | 457 if (node instanceof Node) { |
470 readNodeProperties((Node) node); | 458 readNodeProperties((Node) node); |
471 copyDebugProperties((Node) node); | 459 copyDebugProperties((Node) node); |
472 } | 460 } |
473 } | 461 } |
474 } | 462 } |
475 | 463 |
476 /** | 464 final void setNodeProperty(Object node, String propertyName, Object value) { |
477 * @deprecated to be removed | 465 NodeElement nodeElem = getElementByObject(node); |
478 */ | |
479 @Deprecated | |
480 protected void setNodeProperty(Object node, String propertyName, Object value) { | |
481 setNodePropertyImpl(node, propertyName, value); | |
482 } | |
483 | |
484 final void setNodePropertyImpl(Object node, String propertyName, Object value) { | |
485 NodeElement nodeElem = getElementByObjectImpl(node); | |
486 nodeElem.getProperties().put(propertyName, value); | 466 nodeElem.getProperties().put(propertyName, value); |
487 } | 467 } |
488 | 468 |
489 private void copyDebugProperties(Node node) { | 469 private void copyDebugProperties(Node node) { |
490 Map<String, Object> debugProperties = node.getDebugProperties(); | 470 Map<String, Object> debugProperties = node.getDebugProperties(); |
491 for (Map.Entry<String, Object> property : debugProperties.entrySet()) { | 471 for (Map.Entry<String, Object> property : debugProperties.entrySet()) { |
492 setNodePropertyImpl(node, property.getKey(), property.getValue()); | 472 setNodeProperty(node, property.getKey(), property.getValue()); |
493 } | 473 } |
494 } | 474 } |
495 | 475 |
496 private void readNodeProperties(Node node) { | 476 private void readNodeProperties(Node node) { |
497 NodeFieldAccessor[] fields = NodeClass.get(node).getFields(); | 477 NodeFieldAccessor[] fields = NodeClass.get(node).getFields(); |
498 for (NodeFieldAccessor field : fields) { | 478 for (NodeFieldAccessor field : fields) { |
499 if (field.getKind() == NodeFieldKind.DATA) { | 479 if (field.getKind() == NodeFieldKind.DATA) { |
500 String key = field.getName(); | 480 String key = field.getName(); |
501 if (!getElementByObjectImpl(node).getProperties().containsKey(key)) { | 481 if (!getElementByObject(node).getProperties().containsKey(key)) { |
502 Object value = field.loadValue(node); | 482 Object value = field.loadValue(node); |
503 setNodePropertyImpl(node, key, value); | 483 setNodeProperty(node, key, value); |
504 } | 484 } |
505 } | 485 } |
506 } | 486 } |
507 } | 487 } |
508 | 488 |
509 /** | 489 final void connectNodes(Object a, Object b, String label) { |
510 * @deprecated to be removed | 490 NodeElement fromNode = getElementByObject(a); |
511 */ | 491 NodeElement toNode = getElementByObject(b); |
512 @Deprecated | |
513 protected void connectNodes(Object a, Object b, String label) { | |
514 connectNodesImpl(a, b, label); | |
515 } | |
516 | |
517 final void connectNodesImpl(Object a, Object b, String label) { | |
518 NodeElement fromNode = getElementByObjectImpl(a); | |
519 NodeElement toNode = getElementByObjectImpl(b); | |
520 if (fromNode == null || toNode == null) { | 492 if (fromNode == null || toNode == null) { |
521 return; | 493 return; |
522 } | 494 } |
523 | 495 |
524 // count existing to-edges | 496 // count existing to-edges |
536 if (openGraphCount == 0) { | 508 if (openGraphCount == 0) { |
537 beginGraph(DEFAULT_GRAPH_NAME); | 509 beginGraph(DEFAULT_GRAPH_NAME); |
538 } | 510 } |
539 | 511 |
540 // if node is visited once again, skip | 512 // if node is visited once again, skip |
541 if (getElementByObjectImpl(node) != null) { | 513 if (getElementByObject(node) != null) { |
542 return this; | 514 return this; |
543 } | 515 } |
544 | 516 |
545 // respect node's custom handler | 517 // respect node's custom handler |
546 if (!TruffleOptions.AOT && NodeUtil.findAnnotation(node.getClass(), CustomGraphPrintHandler.class) != null) { | 518 if (!TruffleOptions.AOT && NodeUtil.findAnnotation(node.getClass(), CustomGraphPrintHandler.class) != null) { |
619 public void visit(Object node, GraphPrintHandler handler) { | 591 public void visit(Object node, GraphPrintHandler handler) { |
620 GraphPrintVisitor.this.visit(node, handler); | 592 GraphPrintVisitor.this.visit(node, handler); |
621 } | 593 } |
622 | 594 |
623 public void connectNodes(Object node, Object child) { | 595 public void connectNodes(Object node, Object child) { |
624 GraphPrintVisitor.this.connectNodesImpl(node, child, null); | 596 GraphPrintVisitor.this.connectNodes(node, child, null); |
625 } | 597 } |
626 | 598 |
627 public void connectNodes(Object node, Object child, String label) { | 599 public void connectNodes(Object node, Object child, String label) { |
628 GraphPrintVisitor.this.connectNodesImpl(node, child, label); | 600 GraphPrintVisitor.this.connectNodes(node, child, label); |
629 } | 601 } |
630 | 602 |
631 public void setNodeProperty(Object node, String propertyName, Object value) { | 603 public void setNodeProperty(Object node, String propertyName, Object value) { |
632 GraphPrintVisitor.this.setNodePropertyImpl(node, propertyName, value); | 604 GraphPrintVisitor.this.setNodeProperty(node, propertyName, value); |
633 } | 605 } |
634 | 606 |
635 public boolean visited(Object node) { | 607 public boolean visited(Object node) { |
636 return GraphPrintVisitor.this.getElementByObjectImpl(node) != null; | 608 return GraphPrintVisitor.this.getElementByObject(node) != null; |
637 } | 609 } |
638 } | 610 } |
639 | 611 |
640 public interface GraphPrintHandler { | 612 public interface GraphPrintHandler { |
641 | 613 |