fsa_merge.alc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. include "conformance_scd.alh"
  5. include "utils.alh"
  6. include "typing.alh"
  7. include "mini_modify.alh"
  8. String function map_P2F(model : Element, name : String):
  9. Element destinations
  10. String pick
  11. destinations = allAssociationDestinations(model, name, "P2F_state")
  12. pick = name
  13. while (pick == name):
  14. pick = set_pop(destinations)
  15. return pick!
  16. Boolean function main(model : Element):
  17. Element all_states
  18. String element_name
  19. Boolean found_current
  20. found_current = False
  21. all_states = allInstances(model, "PartialRuntime/State")
  22. while (set_len(all_states) > 0):
  23. element_name = set_pop(all_states)
  24. if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_state")) > 0):
  25. // Element already exists in full, so copy existing attributes
  26. instantiate_attribute(model, element_name, "current", read_attribute(model, map_P2F(model, element_name), "current"))
  27. if (read_attribute(model, map_P2F(model, element_name), "current")):
  28. found_current = True
  29. else:
  30. // New state, so assume that it is not current
  31. instantiate_attribute(model, element_name, "current", False)
  32. instantiate_link(model, "P2F_state", "", element_name, element_name)
  33. Element all_elements
  34. String elem
  35. all_elements = dict_keys(model["model"])
  36. while (set_len(all_elements) > 0):
  37. elem = set_pop(all_elements)
  38. if (string_startswith(read_type(model, elem), "PartialRuntime/")):
  39. retype(model, elem, "NewFullRuntime/" + cast_string(list_read(string_split_nr(read_type(model, elem), "/", 1), 1)))
  40. String new_state
  41. if (found_current == False):
  42. if (False):
  43. // Prompt for new state
  44. output("FIX_NEW_STATE")
  45. new_state = input()
  46. all_states = allInstances(model, "PartialRuntime/State")
  47. while (set_len(all_states) > 0):
  48. element_name = set_pop(all_states)
  49. if (value_eq(read_attribute(model, element_name, "name"), new_state)):
  50. instantiate_attribute(model, element_name, "current", True)
  51. break!
  52. else:
  53. // Reset to initial
  54. all_states = allInstances(model, "PartialRuntime/State")
  55. while (set_len(all_states) > 0):
  56. element_name = set_pop(all_states)
  57. if (value_eq(read_attribute(model, element_name, "initial"), True)):
  58. instantiate_attribute(model, element_name, "current", True)
  59. break!
  60. return True!