Browse Source

Rust: all priority tests pass

Joeri Exelmans 4 years ago
parent
commit
de767d54b3
1 changed files with 17 additions and 4 deletions
  1. 17 4
      src/sccd/statechart/codegen/rust.py

+ 17 - 4
src/sccd/statechart/codegen/rust.py

@@ -53,6 +53,10 @@ def compile_actions(actions: List[Action], w: IndentingWriter):
 
 def compile_statechart(sc: Statechart, globals: Globals, w: IndentingWriter):
 
+    # TODO: Do not create a StatechartInstance just to check if priorities are valid:
+    from sccd.statechart.dynamic.statechart_instance import StatechartInstance
+    StatechartInstance(sc, None, None, None, None) # may raise error if priorities are invalid
+
     tree = sc.tree
 
     # Note: The reason for the
@@ -397,10 +401,19 @@ def compile_statechart(sc: Statechart, globals: Globals, w: IndentingWriter):
                     w.dedent()
                     w.writeln("}")
 
-        # TODO: This is where parent/child-first semantic variability should be implemented
-        #       For now, it's always "parent first"
-        parent()
-        child()
+
+        if sc.semantics.hierarchical_priority == HierarchicalPriority.SOURCE_PARENT:
+            parent()
+            child()
+        elif sc.semantics.hierarchical_priority == HierarchicalPriority.SOURCE_CHILD:
+            child()
+            parent()
+        elif sc.semantics.hierarchical_priority == HierarchicalPriority.NONE:
+            # We're free to pick any semantics here, but let's not go too wild
+            parent()
+            child()
+        else:
+            raise Exception("Unsupported option %s" % sc.semantics.hierarchical_priority)
 
     write_transitions(tree.root)