internal static List <AbstractNode> GetChildren(AbstractNode root, Type type) { List <AbstractNode> ChildrenList = new List <AbstractNode>(); AbstractNode child = root.Child; while (child != null) { // If the child is what we want, add it to the list if (child.GetType() == type) { ChildrenList.Add(child); // If a list is represnted by chaining identical nodes together go down this path while (child.Child != null && child.Child.GetType() == type) { child = child.Child; ChildrenList.Add(child); } } // If I have myself as a child, consider that an equal state to this, and explore that path else if (child.GetType() == root.GetType()) { ChildrenList.AddRange(Utilities.GetChildren(child, type)); } // Look at sibling child = child.Sib; } return(ChildrenList); }
internal static List <AbstractNode> GetMethodBodyChildren(AbstractNode node, CodeGenVisitor c) { // return children that are Assignment Expressions and also ones that are Method Calls List <AbstractNode> retVal = new List <AbstractNode>(); AbstractNode an; an = node.Child; while (an != null) { if (an.GetType() == typeof(AssignmentExpr) || an.GetType() == typeof(MethodCall) || an.GetType() == typeof(SelectionStmt) || an.GetType() == typeof(Stmt)) { retVal.Add(an); } if (an.GetType() == node.GetType()) { retVal.AddRange(GetMethodBodyChildren(an, c)); } if (an.Sib != an) { an = an.Sib; } } return(retVal); }