/** <summary>^(A B C): emit create A, create B, add child, ...</summary> */ protected virtual void SimulateTreeConstruction(object t) { dbg.CreateNode(t); int n = adaptor.GetChildCount(t); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(t, i); SimulateTreeConstruction(child); dbg.AddChild(t, child); } }
protected void ToDOTDefineEdges(object tree, ITreeAdaptor adaptor, StringTemplate treeST) { if (tree == null) { return; } int n = adaptor.GetChildCount(tree); if (n == 0) { // must have already dumped as child from previous // invocation; do nothing return; } string parentName = "n" + GetNodeNumber(tree); // for each child, do a parent -> child edge using unique node names string parentText = adaptor.GetNodeText(tree); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(tree, i); string childText = adaptor.GetNodeText(child); string childName = "n" + GetNodeNumber(child); StringTemplate edgeST = _edgeST.GetInstanceOf(); edgeST.SetAttribute("parent", parentName); edgeST.SetAttribute("child", childName); edgeST.SetAttribute("parentText", parentText); edgeST.SetAttribute("childText", childText); treeST.SetAttribute("edges", edgeST); ToDOTDefineEdges(child, adaptor, treeST); } }
protected void ToDOTDefineNodes(object tree, ITreeAdaptor adaptor, StringTemplate treeST) { if (tree == null) { return; } int n = adaptor.GetChildCount(tree); if (n == 0) { // must have already dumped as child from previous // invocation; do nothing return; } // define parent node StringTemplate parentNodeST = GetNodeST(adaptor, tree); treeST.SetAttribute("nodes", parentNodeST); // for each child, do a "<unique-name> [label=text]" node def for (int i = 0; i < n; i++) { object child = adaptor.GetChild(tree, i); StringTemplate nodeST = GetNodeST(adaptor, child); treeST.SetAttribute("nodes", nodeST); ToDOTDefineNodes(child, adaptor, treeST); } }
protected void ToDOTDefineNodes(object tree, ITreeAdaptor adaptor, StringTemplate treeST) { if ( tree == null ) { return; } int n = adaptor.GetChildCount(tree); if ( n == 0 ) { // must have already dumped as child from previous // invocation; do nothing return; } // define parent node StringTemplate parentNodeST = GetNodeST(adaptor, tree); treeST.SetAttribute("nodes", parentNodeST); // for each child, do a "<unique-name> [label=text]" node def for (int i = 0; i < n; i++) { object child = adaptor.GetChild(tree, i); StringTemplate nodeST = GetNodeST(adaptor, child); treeST.SetAttribute("nodes", nodeST); ToDOTDefineNodes(child, adaptor, treeST); } }
protected void ToDOTDefineEdges(object tree, ITreeAdaptor adaptor, StringTemplate treeST) { if ( tree == null ) { return; } int n = adaptor.GetChildCount(tree); if ( n == 0 ) { // must have already dumped as child from previous // invocation; do nothing return; } string parentName = "n" + GetNodeNumber(tree); // for each child, do a parent -> child edge using unique node names string parentText = adaptor.GetNodeText(tree); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(tree, i); string childText = adaptor.GetNodeText(child); string childName = "n" + GetNodeNumber(child); StringTemplate edgeST = _edgeST.GetInstanceOf(); edgeST.SetAttribute("parent", parentName); edgeST.SetAttribute("child", childName); edgeST.SetAttribute("parentText", parentText); edgeST.SetAttribute("childText", childText); treeST.SetAttribute("edges", edgeST); ToDOTDefineEdges(child, adaptor, treeST); } }