/// <summary> /// Visit every node in tree t and trigger an action for each node /// before/after having visited all of its children. /// Execute both actions even if t has no children. /// If a child visit yields a new child, it can update its /// parent's child list or just return the new child. The /// child update code works even if the child visit alters its parent /// and returns the new tree. /// /// Return result of applying post action to this node. /// </summary> public object Visit(object t, ITreeVisitorAction action) { bool isNil = adaptor.IsNil(t); if (action != null && !isNil) { t = action.Pre(t); // if rewritten, walk children of new t } int n = adaptor.GetChildCount(t); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(t, i); object visitResult = Visit(child, action); object childAfterVisit = adaptor.GetChild(t, i); if (visitResult != childAfterVisit) // result & child differ? { adaptor.SetChild(t, i, visitResult); } } if (action != null && !isNil) { t = action.Post(t); } return(t); }
/** <summary> * Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. Bottom up walk. * Execute both actions even if t has no children. Ignore return * results from transforming children since they will have altered * the child list of this node (their parent). Return result of * applying post action to this node. * </summary> */ public object Visit(object t, ITreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); bool isNil = adaptor.IsNil(t); if (action != null && !isNil) { t = action.Pre(t); // if rewritten, walk children of new t } for (int i = 0; i < adaptor.GetChildCount(t); i++) { object child = adaptor.GetChild(t, i); Visit(child, action); } if (action != null && !isNil) t = action.Post(t); return t; }
/// <summary> /// Visit every node in tree t and trigger an action for each node /// before/after having visited all of its children. /// Execute both actions even if t has no children. /// If a child visit yields a new child, it can update its /// parent's child list or just return the new child. The /// child update code works even if the child visit alters its parent /// and returns the new tree. /// /// Return result of applying post action to this node. /// </summary> public object Visit(object t, ITreeVisitorAction action) { bool isNil = adaptor.IsNil(t); if ( action!=null && !isNil ) { t = action.Pre(t); // if rewritten, walk children of new t } int n = adaptor.GetChildCount(t); for (int i=0; i<n; i++) { object child = adaptor.GetChild(t, i); object visitResult = Visit(child, action); object childAfterVisit = adaptor.GetChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.SetChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.Post(t); return t; }
public object Visit(object t, ITreeVisitorAction action) { bool flag = this.adaptor.IsNil(t); if (action != null && !flag) { t = action.Pre(t); } for (int i = 0; i < this.adaptor.GetChildCount(t); ++i) { this.Visit(this.adaptor.GetChild(t, i), action); } if (action != null && !flag) { t = action.Post(t); } return(t); }
public object Visit(object t, ITreeVisitorAction action) { bool flag = this.adaptor.IsNil(t); if ((action != null) && !flag) { t = action.Pre(t); } for (int i = 0; i < this.adaptor.GetChildCount(t); i++) { object child = this.adaptor.GetChild(t, i); this.Visit(child, action); } if ((action != null) && !flag) { t = action.Post(t); } return t; }
/** <summary> * Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. Bottom up walk. * Execute both actions even if t has no children. Ignore return * results from transforming children since they will have altered * the child list of this node (their parent). Return result of * applying post action to this node. * </summary> */ public object Visit(object t, ITreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); bool isNil = adaptor.IsNil(t); if (action != null && !isNil) { t = action.Pre(t); // if rewritten, walk children of new t } for (int i = 0; i < adaptor.GetChildCount(t); i++) { object child = adaptor.GetChild(t, i); Visit(child, action); } if (action != null && !isNil) { t = action.Post(t); } return(t); }
public object Visit(object t, ITreeVisitorAction action) { // Do pre-visit action // if (action != null && !adaptor.IsNil(t)) { t = action.Pre(t); // if rewritten, walk children of new t } // // We snarf a copy of the children to walk so that the walking may modify // it in place // int n = adaptor.GetChildCount(t); if (n > 0) { ArrayList ourChildren = new ArrayList(n); for (int i = 0; i < n; i++) { ourChildren.Add(adaptor.GetChild(t, i)); } // // Recurse! // foreach (object child in ourChildren) { Visit(child, action); } } // // Do post-visit action // if (action != null && !adaptor.IsNil(t)) t = action.Post(t); // return t; }
public void Visit(object t, ITreeVisitorAction action) { // Do pre-visit action // if (action != null && !adaptor.IsNil(t)) { action.Pre(t); } // int n = adaptor.GetChildCount(t); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(t, i); Visit(child, action); } // // Do post-visit action // if (action != null && !adaptor.IsNil(t)) action.Post(t); }