Joeri Exelmans 5 лет назад
Родитель
Сommit
fda4631e29

+ 5 - 5
src/sccd/statechart/static/priority.py

@@ -23,7 +23,7 @@ def explicit_ortho(tree: StateTree) -> EdgeList:
         transitions = []
         def visit_state(s: State, _=None):
             transitions.extend(s.transitions)
-        visit_tree(s, lambda s: s.children, before_children=[visit_state])
+        visit_tree(s, lambda s: s.children, parent_first=[visit_state])
         return transitions
     # create edges between transitions in one region to another
     def visit_parallel_state(s: State, _=None):
@@ -40,7 +40,7 @@ def explicit_ortho(tree: StateTree) -> EdgeList:
                         edges.extend((connector, t) for t in curr)
                     prev = curr
     visit_tree(tree.root, lambda s: s.children,
-        before_children=[visit_parallel_state])
+        parent_first=[visit_parallel_state])
     return edges
 
 # explicit ordering of outgoing transitions of the same state
@@ -54,7 +54,7 @@ def explicit_same_state(tree: StateTree) -> EdgeList:
                 edges.append((prev, t))
             prev = t
     visit_tree(tree.root, lambda s: s.children,
-        before_children=[visit_state])
+        parent_first=[visit_state])
     return edges
 
 # hierarchical Source-Parent ordering
@@ -65,7 +65,7 @@ def source_parent(tree: StateTree) -> EdgeList:
             edges.extend(itertools.product(parent_transitions, s.transitions))
             return s.transitions
         return parent_transitions
-    visit_tree(tree.root, lambda s: s.children, before_children=[visit_state])
+    visit_tree(tree.root, lambda s: s.children, parent_first=[visit_state])
     return edges
 
 # hierarchical Source-Child ordering
@@ -78,7 +78,7 @@ def source_child(tree: StateTree) -> EdgeList:
             return s.transitions
         else:
             return children_transitions
-    visit_tree(tree.root, lambda s: s.children, after_children=[visit_state])
+    visit_tree(tree.root, lambda s: s.children, child_first=[visit_state])
     return edges
 
 # hierarchical Arena-Parent ordering

+ 3 - 3
src/sccd/statechart/static/tree.py

@@ -323,7 +323,7 @@ class StateTree(Freezable):
                 state.opt.freeze()
 
             visit_tree(root, lambda s: s.children,
-                before_children=[
+                parent_first=[
                     assign_state_id(),
                     assign_full_name,
                     assign_depth,
@@ -331,7 +331,7 @@ class StateTree(Freezable):
                     visit_transitions,
                     set_ancestors,
                 ],
-                after_children=[
+                child_first=[
                     set_descendants,
                     calculate_effective_targets,
                 ])
@@ -339,7 +339,7 @@ class StateTree(Freezable):
             self.initial_states = root.opt.effective_targets
 
             visit_tree(root, lambda s: s.children,
-                after_children=[
+                child_first=[
                     deal_with_history,
                     freeze,
                 ])

+ 8 - 8
src/sccd/util/visit_tree.py

@@ -1,23 +1,23 @@
 import functools
 import itertools
 
-# A generic depth-first tree-visit function that can let multiple visitor functions do their thing in only a single pass.
+# A generic depth-first tree-visit function that can let multiple visitor functions do "their thing" in only a single pass.
 # It accepts 2 lists of visitor functions:
-# 'before_children' is a list of callbacks that will be called with 1 or 2 parameters (and therefore the 2nd parameter of the callback should have a default value): 1) the current element and 2) the value of the callback returned by the parent element if the current element is not the root element.
-# 'after_children' is a list of callbacks that will be called with 2 parameters: 2) the current element and 2) An empty list for all the leaf elements or a list with the responses of the children of that element for the callback.
-def visit_tree(node, get_children, before_children=[], after_children=[], parent_values=None):
+# 'parent_first' is a list of callbacks that will be called with 1 or 2 parameters (and therefore the 2nd parameter of the callback should have a default value): 1) the current element and 2) the value of the callback returned by the parent element if the current element is not the root element.
+# 'child_first' is a list of callbacks that will be called with 2 parameters: 2) the current element and 2) An empty list for all the leaf elements or a list with the responses of the children of that element for the callback.
+def visit_tree(node, get_children, parent_first=[], child_first=[], parent_values=None):
     # Most parameters unchanged for recursive calls
     def visit(node, parent_values):
         if parent_values is None:
-            parent_values = [f(node) for f in before_children]
+            parent_values = [f(node) for f in parent_first]
         else:
-            parent_values = [f(node, p) for f,p in zip(before_children, parent_values)]
+            parent_values = [f(node, p) for f,p in zip(parent_first, parent_values)]
 
         # child_responses is a list of len(children)-many lists C, where for every child of node, C is the 'to_parent' value returned by every child
         child_responses = [visit(node=c, parent_values=parent_values) for c in get_children(node)]
 
-        to_parent = [f(node, [cs[i] for cs in child_responses]) for i,f in enumerate(after_children)]
-        # 'to_parent' is the mapping from our after_children-functions to those functions called on the responses we got from our children
+        to_parent = [f(node, [cs[i] for cs in child_responses]) for i,f in enumerate(child_first)]
+        # 'to_parent' is the mapping from our child_first-functions to those functions called on the responses we got from our children
 
         return to_parent