瀏覽代碼

Working entry/exit actions

Yentl Van Tendeloo 8 年之前
父節點
當前提交
08aa35e9e2
共有 2 個文件被更改,包括 29 次插入5 次删除
  1. 20 0
      integration/code/minimal_SCCD.mvc
  2. 9 5
      models/SCCD_execute.alc

+ 20 - 0
integration/code/minimal_SCCD.mvc

@@ -37,10 +37,30 @@ CompositeState main_statechart {
             {composite_children} BasicState x_a {
                 name = "xa"
                 isInitial = True
+                onEntryScript = $
+                        Void function entry(attributes : Element):
+                            log("ENTRY xa")
+                            return!
+                    $
+                onExitScript = $
+                        Void function exit(attributes : Element):
+                            log("EXIT xa")
+                            return!
+                    $
             }
             {composite_children} BasicState x_b {
                 name = "xb"
                 isInitial = False
+                onEntryScript = $
+                        Void function entry(attributes : Element):
+                            log("ENTRY xb")
+                            return!
+                    $
+                onExitScript = $
+                        Void function exit(attributes : Element):
+                            log("EXIT xb")
+                            return!
+                    $
             }
             {composite_children} BasicState x_c {
                 name = "xc"

+ 9 - 5
models/SCCD_execute.alc

@@ -208,13 +208,15 @@ Element function execute_transition(model : Element, data : Element, class : Str
 	source_states = expand_current_state(model, readAssociationSource(model, transition), data["classes"][class]["states"])
 	target_states = expand_initial_state(model, readAssociationDestination(model, transition))
 
+	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 = get_func_AL_model(import_node(action))
 		action(data["attributes"])
 
 	return target_states!
@@ -384,8 +386,10 @@ Element function get_actions_to_execute(model : Element, source_states : Element
 				break!
 
 		// i-th element equal for all hierarchies, so go to next element
-		i = i + 1
+		if (bool_not(finished)):
+			i = i + 1
 
+	log("Found difference at i = " + cast_v2s(i))
 	// Found the first differing element at position i
 
 	// All elements remaining in hierarchy_source are to be traversed in REVERSE order for the exit actions
@@ -414,10 +418,10 @@ Element function get_actions_to_execute(model : Element, source_states : Element
 				// Prepend, instead of append, as we want to do these operations in reverse order!
 
 				// First check if there is any exit action at all
-				action = read_attribute(model, state, "exit_action")
+				action = read_attribute(model, state, "onExitScript")
 				if (element_neq(action, read_root())):
 					// An exit action is found!
-					list_insert(result, 0, get_func_AL_model(import_node(action)))
+					list_insert(result, get_func_AL_model(import_node(action)), 0)
 
 				// Add this state as visited, even though there might not have been an associated action
 				set_add(visited, state)
@@ -439,7 +443,7 @@ Element function get_actions_to_execute(model : Element, source_states : Element
 				// Append, instead of prepend, as we want to do these operations in normal order!
 
 				// First check if there is any entry action at all
-				action = read_attribute(model, state, "entry_action")
+				action = read_attribute(model, state, "onEntryScript")
 				if (element_neq(action, read_root())):
 					// An entry action is found!
 					list_append(result, get_func_AL_model(import_node(action)))