|
@@ -19,14 +19,14 @@ Void function print_states(model : Element, data : Element):
|
|
|
|
|
|
log("Current states:")
|
|
log("Current states:")
|
|
classes = set_copy(data["classes"])
|
|
classes = set_copy(data["classes"])
|
|
- while (read_nr_out(classes) > 0):
|
|
|
|
|
|
+ while (set_len(classes) > 0):
|
|
class = set_pop(classes)
|
|
class = set_pop(classes)
|
|
log(string_join(string_join(string_join(" ", class["ID"]), " : "), read_attribute(model, class["type"], "name")))
|
|
log(string_join(string_join(string_join(" ", class["ID"]), " : "), read_attribute(model, class["type"], "name")))
|
|
log(" Attributes: " + dict_to_string(class["attributes"]))
|
|
log(" Attributes: " + dict_to_string(class["attributes"]))
|
|
|
|
|
|
states = set_copy(class["states"])
|
|
states = set_copy(class["states"])
|
|
log(" States:")
|
|
log(" States:")
|
|
- while (read_nr_out(states) > 0):
|
|
|
|
|
|
+ while (set_len(states) > 0):
|
|
state = set_pop(states)
|
|
state = set_pop(states)
|
|
log(string_join(" ", read_attribute(model, state, "name")))
|
|
log(string_join(" ", read_attribute(model, state, "name")))
|
|
|
|
|
|
@@ -38,7 +38,7 @@ Element function filter(model : Element, set : Element, attribute_name : String,
|
|
Element result
|
|
Element result
|
|
|
|
|
|
result = create_node()
|
|
result = create_node()
|
|
- while (read_nr_out(set) > 0):
|
|
|
|
|
|
+ while (set_len(set) > 0):
|
|
key = set_pop(set)
|
|
key = set_pop(set)
|
|
if (value_eq(read_attribute(model, key, attribute_name), attribute_value)):
|
|
if (value_eq(read_attribute(model, key, attribute_name), attribute_value)):
|
|
set_add(result, key)
|
|
set_add(result, key)
|
|
@@ -51,7 +51,7 @@ Element function filter_exists(model : Element, set : Element, attribute_name :
|
|
Element result
|
|
Element result
|
|
|
|
|
|
result = create_node()
|
|
result = create_node()
|
|
- while (read_nr_out(set) > 0):
|
|
|
|
|
|
+ while (set_len(set) > 0):
|
|
key = set_pop(set)
|
|
key = set_pop(set)
|
|
if (element_neq(read_attribute(model, key, attribute_name), read_root())):
|
|
if (element_neq(read_attribute(model, key, attribute_name), read_root())):
|
|
set_add(result, key)
|
|
set_add(result, key)
|
|
@@ -67,7 +67,7 @@ Element function expand_current_state(model : Element, state : String, data : El
|
|
|
|
|
|
Element hierarchy
|
|
Element hierarchy
|
|
String deep_state
|
|
String deep_state
|
|
- while (read_nr_out(current_states) > 0):
|
|
|
|
|
|
+ while (set_len(current_states) > 0):
|
|
deep_state = set_pop(current_states)
|
|
deep_state = set_pop(current_states)
|
|
hierarchy = find_hierarchy(model, deep_state, data)
|
|
hierarchy = find_hierarchy(model, deep_state, data)
|
|
// Got the hierarchy of one of the states
|
|
// Got the hierarchy of one of the states
|
|
@@ -117,7 +117,7 @@ Element function expand_parallel_state(model : Element, parallel_state : String,
|
|
children = allAssociationDestinations(model, parallel_state, "SCCD/parallel_children")
|
|
children = allAssociationDestinations(model, parallel_state, "SCCD/parallel_children")
|
|
result = create_node()
|
|
result = create_node()
|
|
|
|
|
|
- while (read_nr_out(children) > 0):
|
|
|
|
|
|
+ while (set_len(children) > 0):
|
|
set_merge(result, expand_initial_state(model, set_pop(children), data))
|
|
set_merge(result, expand_initial_state(model, set_pop(children), data))
|
|
|
|
|
|
return result!
|
|
return result!
|
|
@@ -158,7 +158,7 @@ Void function start_class(model : Element, data : Element, class : String, ident
|
|
history = create_node()
|
|
history = create_node()
|
|
dict_add(class_handle, "history", history)
|
|
dict_add(class_handle, "history", history)
|
|
cstates = allInstances(model, "SCCD/CompositeState")
|
|
cstates = allInstances(model, "SCCD/CompositeState")
|
|
- while (read_nr_out(cstates) > 0):
|
|
|
|
|
|
+ while (set_len(cstates) > 0):
|
|
cstate = set_pop(cstates)
|
|
cstate = set_pop(cstates)
|
|
dict_add(history, cstate, expand_initial_state(model, cstate, class_handle))
|
|
dict_add(history, cstate, expand_initial_state(model, cstate, class_handle))
|
|
|
|
|
|
@@ -167,7 +167,7 @@ Void function start_class(model : Element, data : Element, class : String, ident
|
|
attributes = create_node()
|
|
attributes = create_node()
|
|
Element attrs
|
|
Element attrs
|
|
attrs = allAssociationDestinations(model, class, "SCCD/class_attributes")
|
|
attrs = allAssociationDestinations(model, class, "SCCD/class_attributes")
|
|
- while (read_nr_out(attrs) > 0):
|
|
|
|
|
|
+ while (set_len(attrs) > 0):
|
|
dict_add(attributes, read_attribute(model, set_pop(attrs), "name"), read_root())
|
|
dict_add(attributes, read_attribute(model, set_pop(attrs), "name"), read_root())
|
|
dict_add(class_handle, "attributes", attributes)
|
|
dict_add(class_handle, "attributes", attributes)
|
|
|
|
|
|
@@ -212,7 +212,7 @@ Element function get_enabled_transitions(model : Element, state : String, data :
|
|
event_names = create_node()
|
|
event_names = create_node()
|
|
event_parameters = create_node()
|
|
event_parameters = create_node()
|
|
events = set_copy(data["current_class_handle"]["events"])
|
|
events = set_copy(data["current_class_handle"]["events"])
|
|
- while (read_nr_out(events) > 0):
|
|
|
|
|
|
+ while (set_len(events) > 0):
|
|
evt = set_pop(events)
|
|
evt = set_pop(events)
|
|
evt_name = list_read(evt, 0)
|
|
evt_name = list_read(evt, 0)
|
|
|
|
|
|
@@ -223,7 +223,7 @@ Element function get_enabled_transitions(model : Element, state : String, data :
|
|
// Add event parameters
|
|
// Add event parameters
|
|
set_add(event_parameters[evt_name], list_read(evt, 1))
|
|
set_add(event_parameters[evt_name], list_read(evt, 1))
|
|
|
|
|
|
- while (read_nr_out(to_filter) > 0):
|
|
|
|
|
|
+ while (set_len(to_filter) > 0):
|
|
transition = set_pop(to_filter)
|
|
transition = set_pop(to_filter)
|
|
|
|
|
|
// Check event
|
|
// Check event
|
|
@@ -255,7 +255,7 @@ Element function get_enabled_transitions(model : Element, state : String, data :
|
|
Element params
|
|
Element params
|
|
Element param
|
|
Element param
|
|
params = set_copy(event_parameters[attr])
|
|
params = set_copy(event_parameters[attr])
|
|
- while (read_nr_out(params) > 0):
|
|
|
|
|
|
+ while (set_len(params) > 0):
|
|
param = set_pop(params)
|
|
param = set_pop(params)
|
|
if (element_neq(cond, read_root())):
|
|
if (element_neq(cond, read_root())):
|
|
// Got a condition to check first
|
|
// Got a condition to check first
|
|
@@ -308,7 +308,7 @@ Void function process_raised_event(model : Element, event : Element, parameter_a
|
|
// Send to all classes
|
|
// Send to all classes
|
|
Element classes
|
|
Element classes
|
|
classes = dict_keys(data["classes"])
|
|
classes = dict_keys(data["classes"])
|
|
- while(read_nr_out(classes) > 0):
|
|
|
|
|
|
+ while(set_len(classes) > 0):
|
|
set_add_node(data["classes"][set_pop(classes)]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
|
|
set_add_node(data["classes"][set_pop(classes)]["new_events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
|
|
elif (scope == "narrow"):
|
|
elif (scope == "narrow"):
|
|
// Send to the specified class only
|
|
// Send to the specified class only
|
|
@@ -337,7 +337,7 @@ Element function execute_transition(model : Element, data : Element, transition_
|
|
Element events
|
|
Element events
|
|
String event
|
|
String event
|
|
events = allAssociationDestinations(model, transition, "SCCD/transition_raises")
|
|
events = allAssociationDestinations(model, transition, "SCCD/transition_raises")
|
|
- while (read_nr_out(events) > 0):
|
|
|
|
|
|
+ while (set_len(events) > 0):
|
|
event = set_pop(events)
|
|
event = set_pop(events)
|
|
|
|
|
|
Element parameter_action
|
|
Element parameter_action
|
|
@@ -385,17 +385,17 @@ Boolean function step_class(model : Element, data : Element, class : String):
|
|
new_states = create_node()
|
|
new_states = create_node()
|
|
transitioned = False
|
|
transitioned = False
|
|
|
|
|
|
- while (read_nr_out(states) > 0):
|
|
|
|
|
|
+ while (set_len(states) > 0):
|
|
state = set_pop(states)
|
|
state = set_pop(states)
|
|
found = False
|
|
found = False
|
|
|
|
|
|
// Loop over the hierarchy of this state and try to apply transitions
|
|
// Loop over the hierarchy of this state and try to apply transitions
|
|
hierarchy = find_hierarchy(model, state, data)
|
|
hierarchy = find_hierarchy(model, state, data)
|
|
- while (read_nr_out(hierarchy) > 0):
|
|
|
|
|
|
+ while (list_len(hierarchy) > 0):
|
|
current_state = list_pop(hierarchy, 0)
|
|
current_state = list_pop(hierarchy, 0)
|
|
transitions = get_enabled_transitions(model, current_state, data)
|
|
transitions = get_enabled_transitions(model, current_state, data)
|
|
|
|
|
|
- if (read_nr_out(transitions) > 0):
|
|
|
|
|
|
+ if (set_len(transitions) > 0):
|
|
// Found an enabled transition, so store that one
|
|
// Found an enabled transition, so store that one
|
|
transition = random_choice(set_to_list(transitions))
|
|
transition = random_choice(set_to_list(transitions))
|
|
|
|
|
|
@@ -424,7 +424,7 @@ String function get_parent(model : Element, state : String):
|
|
Element tmp_set
|
|
Element tmp_set
|
|
tmp_set = allAssociationOrigins(model, state, "SCCD/composite_children")
|
|
tmp_set = allAssociationOrigins(model, state, "SCCD/composite_children")
|
|
set_merge(tmp_set, allAssociationOrigins(model, state, "SCCD/parallel_children"))
|
|
set_merge(tmp_set, allAssociationOrigins(model, state, "SCCD/parallel_children"))
|
|
- if (read_nr_out(tmp_set) > 0):
|
|
|
|
|
|
+ if (set_len(tmp_set) > 0):
|
|
return set_pop(tmp_set)!
|
|
return set_pop(tmp_set)!
|
|
else:
|
|
else:
|
|
return ""!
|
|
return ""!
|
|
@@ -462,11 +462,11 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
Element all_hierarchies
|
|
Element all_hierarchies
|
|
|
|
|
|
hierarchy_sources = create_node()
|
|
hierarchy_sources = create_node()
|
|
- while (read_nr_out(source_states) > 0):
|
|
|
|
|
|
+ while (set_len(source_states) > 0):
|
|
set_add(hierarchy_sources, find_hierarchy(model, set_pop(source_states), data))
|
|
set_add(hierarchy_sources, find_hierarchy(model, set_pop(source_states), data))
|
|
|
|
|
|
hierarchy_targets = create_node()
|
|
hierarchy_targets = create_node()
|
|
- while (read_nr_out(target_states) > 0):
|
|
|
|
|
|
+ while (set_len(target_states) > 0):
|
|
set_add(hierarchy_targets, find_hierarchy(model, set_pop(target_states), data))
|
|
set_add(hierarchy_targets, find_hierarchy(model, set_pop(target_states), data))
|
|
|
|
|
|
all_hierarchies = set_copy(hierarchy_sources)
|
|
all_hierarchies = set_copy(hierarchy_sources)
|
|
@@ -492,7 +492,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
// Check the i-th element in both and see if they are equal
|
|
// Check the i-th element in both and see if they are equal
|
|
current = ""
|
|
current = ""
|
|
iter_hierarchies = set_copy(all_hierarchies)
|
|
iter_hierarchies = set_copy(all_hierarchies)
|
|
- while (read_nr_out(iter_hierarchies) > 0):
|
|
|
|
|
|
+ while (set_len(iter_hierarchies) > 0):
|
|
hierarchy = set_pop(iter_hierarchies)
|
|
hierarchy = set_pop(iter_hierarchies)
|
|
|
|
|
|
// Exhausted one of the lists
|
|
// Exhausted one of the lists
|
|
@@ -541,7 +541,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
Element hierarchy_source
|
|
Element hierarchy_source
|
|
Element hierarchy_target
|
|
Element hierarchy_target
|
|
visited = create_node()
|
|
visited = create_node()
|
|
- while (read_nr_out(hierarchy_sources) > 0):
|
|
|
|
|
|
+ while (set_len(hierarchy_sources) > 0):
|
|
// Get one of these hierarchies
|
|
// Get one of these hierarchies
|
|
hierarchy_source = set_pop(hierarchy_sources)
|
|
hierarchy_source = set_pop(hierarchy_sources)
|
|
spliced_hierarchy = list_splice(hierarchy_source, i, list_len(hierarchy_source))
|
|
spliced_hierarchy = list_splice(hierarchy_source, i, list_len(hierarchy_source))
|
|
@@ -561,7 +561,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
// Add hierarchy_targets actions
|
|
// Add hierarchy_targets actions
|
|
// Clear visited, just to be safe, though it should not matter
|
|
// Clear visited, just to be safe, though it should not matter
|
|
visited = create_node()
|
|
visited = create_node()
|
|
- while (read_nr_out(hierarchy_targets) > 0):
|
|
|
|
|
|
+ while (set_len(hierarchy_targets) > 0):
|
|
// Get one of these hierarchies
|
|
// Get one of these hierarchies
|
|
hierarchy_target = set_pop(hierarchy_targets)
|
|
hierarchy_target = set_pop(hierarchy_targets)
|
|
spliced_hierarchy = list_splice(hierarchy_target, i, list_len(hierarchy_target))
|
|
spliced_hierarchy = list_splice(hierarchy_target, i, list_len(hierarchy_target))
|
|
@@ -584,7 +584,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
Element events
|
|
Element events
|
|
String event
|
|
String event
|
|
// First do exit actions
|
|
// First do exit actions
|
|
- while (read_nr_out(exit) > 0):
|
|
|
|
|
|
+ while (list_len(exit) > 0):
|
|
state = list_pop(exit, 0)
|
|
state = list_pop(exit, 0)
|
|
|
|
|
|
// Set history when leaving
|
|
// Set history when leaving
|
|
@@ -600,7 +600,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
|
|
|
|
// Raise events
|
|
// Raise events
|
|
events = allAssociationDestinations(model, state, "SCCD/onExitRaise")
|
|
events = allAssociationDestinations(model, state, "SCCD/onExitRaise")
|
|
- while (read_nr_out(events) > 0):
|
|
|
|
|
|
+ while (set_len(events) > 0):
|
|
event = set_pop(events)
|
|
event = set_pop(events)
|
|
|
|
|
|
Element parameter_action
|
|
Element parameter_action
|
|
@@ -615,11 +615,11 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
// Unschedule after events
|
|
// Unschedule after events
|
|
Element timed_transitions
|
|
Element timed_transitions
|
|
timed_transitions = filter_exists(model, allOutgoingAssociationInstances(model, state, "SCCD/transition"), "after")
|
|
timed_transitions = filter_exists(model, allOutgoingAssociationInstances(model, state, "SCCD/transition"), "after")
|
|
- while (read_nr_out(timed_transitions) > 0):
|
|
|
|
|
|
+ while (set_len(timed_transitions) > 0):
|
|
dict_delete(data["current_class_handle"]["timers"], set_pop(timed_transitions))
|
|
dict_delete(data["current_class_handle"]["timers"], set_pop(timed_transitions))
|
|
|
|
|
|
// Then do entry actions
|
|
// Then do entry actions
|
|
- while (read_nr_out(entry) > 0):
|
|
|
|
|
|
+ while (list_len(entry) > 0):
|
|
state = list_pop(entry, 0)
|
|
state = list_pop(entry, 0)
|
|
|
|
|
|
// Do entry actions
|
|
// Do entry actions
|
|
@@ -631,7 +631,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
|
|
|
|
// Raise events
|
|
// Raise events
|
|
events = allAssociationDestinations(model, state, "SCCD/onEntryRaise")
|
|
events = allAssociationDestinations(model, state, "SCCD/onEntryRaise")
|
|
- while (read_nr_out(events) > 0):
|
|
|
|
|
|
+ while (set_len(events) > 0):
|
|
event = set_pop(events)
|
|
event = set_pop(events)
|
|
|
|
|
|
Element parameter_action
|
|
Element parameter_action
|
|
@@ -648,7 +648,7 @@ Void function execute_actions(model : Element, source_states : Element, target_s
|
|
String transition
|
|
String transition
|
|
Element after
|
|
Element after
|
|
timed_transitions = filter_exists(model, allOutgoingAssociationInstances(model, state, "SCCD/transition"), "after")
|
|
timed_transitions = filter_exists(model, allOutgoingAssociationInstances(model, state, "SCCD/transition"), "after")
|
|
- while (read_nr_out(timed_transitions) > 0):
|
|
|
|
|
|
+ while (set_len(timed_transitions) > 0):
|
|
transition = set_pop(timed_transitions)
|
|
transition = set_pop(timed_transitions)
|
|
after = resolve_function(read_attribute(model, transition, "after"), data)
|
|
after = resolve_function(read_attribute(model, transition, "after"), data)
|
|
dict_add(data["current_class_handle"]["timers"], transition, float_addition(data["time_sim"], after(data["current_class_handle"]["attributes"])))
|
|
dict_add(data["current_class_handle"]["timers"], transition, float_addition(data["time_sim"], after(data["current_class_handle"]["attributes"])))
|
|
@@ -669,7 +669,7 @@ Float function step(model : Element, data : Element):
|
|
classes = dict_keys(data["classes"])
|
|
classes = dict_keys(data["classes"])
|
|
|
|
|
|
transitioned = False
|
|
transitioned = False
|
|
- while (read_nr_out(classes) > 0):
|
|
|
|
|
|
+ while (set_len(classes) > 0):
|
|
class = set_pop(classes)
|
|
class = set_pop(classes)
|
|
if (step_class(model, data, class)):
|
|
if (step_class(model, data, class)):
|
|
transitioned = True
|
|
transitioned = True
|
|
@@ -677,7 +677,7 @@ Float function step(model : Element, data : Element):
|
|
if (bool_not(transitioned)):
|
|
if (bool_not(transitioned)):
|
|
// Find minimum timer for this class, and store that
|
|
// Find minimum timer for this class, and store that
|
|
keys = dict_keys(data["classes"][class]["timers"])
|
|
keys = dict_keys(data["classes"][class]["timers"])
|
|
- while (read_nr_out(keys) > 0):
|
|
|
|
|
|
+ while (set_len(keys) > 0):
|
|
key = set_pop(keys)
|
|
key = set_pop(keys)
|
|
t_current = data["classes"][class]["timers"][key]
|
|
t_current = data["classes"][class]["timers"][key]
|
|
if (t_current < t_min):
|
|
if (t_current < t_min):
|
|
@@ -735,7 +735,7 @@ Boolean function main(model : Element):
|
|
dict_overwrite(data, "new_events", create_node())
|
|
dict_overwrite(data, "new_events", create_node())
|
|
Element classes
|
|
Element classes
|
|
classes = dict_keys(data["classes"])
|
|
classes = dict_keys(data["classes"])
|
|
- while(read_nr_out(classes) > 0):
|
|
|
|
|
|
+ while(set_len(classes) > 0):
|
|
String class
|
|
String class
|
|
class = set_pop(classes)
|
|
class = set_pop(classes)
|
|
dict_overwrite(data["classes"][class], "events", data["classes"][class]["new_events"])
|
|
dict_overwrite(data["classes"][class], "events", data["classes"][class]["new_events"])
|
|
@@ -753,7 +753,7 @@ Boolean function main(model : Element):
|
|
if (float_gt(time_sim, data["time_sim"])):
|
|
if (float_gt(time_sim, data["time_sim"])):
|
|
print_states(model, data)
|
|
print_states(model, data)
|
|
|
|
|
|
- if (read_nr_out(data["classes"]) == 0):
|
|
|
|
|
|
+ if (dict_len(data["classes"]) == 0):
|
|
// No more active classes left: terminate!
|
|
// No more active classes left: terminate!
|
|
log("Finished SCCD execution")
|
|
log("Finished SCCD execution")
|
|
break!
|
|
break!
|