include "primitives.alh" include "modelling.alh" include "object_operations.alh" include "conformance_scd.alh" include "utils.alh" include "typing.alh" include "mini_modify.alh" String function map_P2F(model : Element, name : String): Element destinations String pick destinations = allAssociationDestinations(model, name, "P2F_state") pick = name while (pick == name): pick = set_pop(destinations) return pick! Boolean function main(model : Element): Element all_states String element_name Boolean found_current found_current = False all_states = allInstances(model, "PartialRuntime/State") while (set_len(all_states) > 0): element_name = set_pop(all_states) if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_state")) > 0): // Element already exists in full, so copy existing attributes instantiate_attribute(model, element_name, "current", read_attribute(model, map_P2F(model, element_name), "current")) if (read_attribute(model, map_P2F(model, element_name), "current")): found_current = True else: // New state, so assume that it is not current instantiate_attribute(model, element_name, "current", False) instantiate_link(model, "P2F_state", "", element_name, element_name) Element all_elements String elem all_elements = dict_keys(model["model"]) while (set_len(all_elements) > 0): elem = set_pop(all_elements) if (string_startswith(read_type(model, elem), "PartialRuntime/")): retype(model, elem, "NewFullRuntime/" + cast_string(list_read(string_split_nr(read_type(model, elem), "/", 1), 1))) String new_state if (found_current == False): if (False): // Prompt for new state output("FIX_NEW_STATE") new_state = input() all_states = allInstances(model, "PartialRuntime/State") while (set_len(all_states) > 0): element_name = set_pop(all_states) if (value_eq(read_attribute(model, element_name, "name"), new_state)): instantiate_attribute(model, element_name, "current", True) break! else: // Reset to initial all_states = allInstances(model, "PartialRuntime/State") while (set_len(all_states) > 0): element_name = set_pop(all_states) if (value_eq(read_attribute(model, element_name, "initial"), True)): instantiate_attribute(model, element_name, "current", True) break! return True!