Browse Source

Fix entry action for initial state of class

Yentl Van Tendeloo 8 years ago
parent
commit
7bb670eeb9
2 changed files with 31 additions and 19 deletions
  1. 5 0
      integration/code/minimal_SCCD.mvc
  2. 26 19
      models/SCCD_execute.alc

+ 5 - 0
integration/code/minimal_SCCD.mvc

@@ -27,6 +27,11 @@ CompositeState main_statechart {
     {composite_children} BasicState init {
         name = "initial"
         isInitial = True
+        onEntryScript = $
+            Void function entry(attributes : Element):
+                log("ENTRY initial")
+                return!
+            $
     }
 
     {composite_children} ParallelState main_parallel {

+ 26 - 19
models/SCCD_execute.alc

@@ -136,6 +136,14 @@ Void function start_class(model : Element, data : Element, class : String):
 		dict_add(attributes, read_attribute(model, set_pop(attrs), "name"), read_root())
 	dict_add(class_handle, "attributes", attributes)
 
+	// Execute all entry actions
+	Element init
+	init = create_node()
+	set_add(init, "")
+	// Initial state before initialization is the set with an empty hierarchy
+	// Empty set would not find any difference between the source and target
+	execute_actions(model, init, set_copy(class_handle["states"]), attributes)
+
 	dict_add(data["classes"], class_handle["ID"], class_handle)
 
 	return!
@@ -186,6 +194,15 @@ Element function get_enabled_transitions(model : Element, state : String, data :
 
 	return result!
 
+Void function execute_actions(model : Element, source_states : Element, target_states : Element, attributes : Element):
+	Element actions
+	actions = get_actions_to_execute(model, source_states, target_states)
+	while (read_nr_out(actions) > 0):
+		Element action
+		action = list_pop(actions, 0)
+		action(attributes)
+	return!
+
 Element function execute_transition(model : Element, data : Element, class : String, transition : String):
 	// Execute the script (if any)
 	Element script
@@ -210,14 +227,7 @@ Element function execute_transition(model : Element, data : Element, class : Str
 
 	log("Source state expanded to: " + set_to_string(source_states))
 	log("Target state expanded to: " + set_to_string(target_states))
-
-	// Do all required operations 
-	Element actions
-	actions = get_actions_to_execute(model, source_states, target_states)
-	while (read_nr_out(actions) > 0):
-		Element action
-		action = list_pop(actions, 0)
-		action(data["attributes"])
+	execute_actions(model, source_states, target_states, data["classes"][class]["attributes"])
 
 	return target_states!
 
@@ -315,20 +325,17 @@ String function get_parent(model : Element, state : String):
 		return ""!
 
 Element function find_hierarchy(model : Element, state : String):
-	Element result
-	String parent
-
-	parent = get_parent(model, state)
-	if (parent == ""):
-		// Are at the topmost element, so empty hierarchy for us
-		result = create_node()
+	if (state == ""):
+		return create_node()!
 	else:
+		Element result
+		String parent
+
+		parent = get_parent(model, state)
 		// We have a parent, so take the parent list first
 		result = find_hierarchy(model, parent)
-
-	// Now append ourself
-	list_append(result, state)
-	return result!
+		list_append(result, state)
+		return result!
 
 Element function get_actions_to_execute(model : Element, source_states : Element, target_states : Element):
 	Element result