fsa_toRuntime.alc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. String function map_D2P(model : Element, name : String):
  5. Element destinations
  6. String pick
  7. destinations = allAssociationDestinations(model, name, "D2P_state")
  8. pick = name
  9. while (pick == name):
  10. pick = set_pop(destinations)
  11. return pick!
  12. Boolean function main(model : Element):
  13. Element all_states
  14. String element_name
  15. String new_element_name
  16. String mm_type_name
  17. Element all_links
  18. all_states = allInstances(model, "Design/State")
  19. while (set_len(all_states) > 0):
  20. element_name = set_pop(all_states)
  21. mm_type_name = "PartialRuntime/" + cast_string(list_read(string_split(read_type(model, element_name), "/"), 1))
  22. if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_state")) == 0):
  23. // New design element, so create in partial runtime model as well
  24. new_element_name = instantiate_node(model, mm_type_name, "")
  25. instantiate_link(model, "D2P_state", "", element_name, new_element_name)
  26. // Always update the value of attributes of PartialRuntime
  27. new_element_name = map_D2P(model, element_name)
  28. instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name"))
  29. instantiate_attribute(model, new_element_name, "initial", read_attribute(model, element_name, "initial"))
  30. log("Copied state initial: " + cast_value(new_element_name) + ", initial: " + cast_value(read_attribute(model, element_name, "initial")))
  31. all_states = allInstances(model, "PartialRuntime/State")
  32. while (set_len(all_states) > 0):
  33. element_name = set_pop(all_states)
  34. if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_state")) == 0):
  35. // Old partial runtime element, so remove
  36. model_delete_element(model, element_name)
  37. // Delete all existing transitions
  38. all_links = allInstances(model, "PartialRuntime/Transition")
  39. while (set_len(all_links) > 0):
  40. model_delete_element(model, set_pop(all_links))
  41. // Recreate all transitions
  42. all_links = allInstances(model, "Design/Transition")
  43. while (set_len(all_links) > 0):
  44. element_name = set_pop(all_links)
  45. new_element_name = instantiate_link(model, "PartialRuntime/Transition", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  46. instantiate_attribute(model, new_element_name, "trigger", read_attribute(model, element_name, "trigger"))
  47. instantiate_attribute(model, new_element_name, "raise", read_attribute(model, element_name, "raise"))
  48. return True!