123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- include "primitives.alh"
- include "utils.alh"
- Element function get_type_mapping_as_dict(model : Element):
- //NEW_get_type_mapping_as_dict(model)
- return OLD_get_type_mapping_as_dict(model)!
- String function read_type(model : Element, name : String):
- NEW_read_type(model, name)
- return OLD_read_type(model, name)!
- Void function retype(model : Element, element : String, type : String):
- //NEW_retype(model, element, type)
- OLD_retype(model, element, type)
- return!
- Void function new_type_mapping(model : Element):
- NEW_new_type_mapping(model)
- OLD_new_type_mapping(model)
- return!
- Void function remove_type(model : Element, name : String):
- OLD_remove_type(model, name)
- return!
- Element function get_type_mapping(model : Element):
- return model["type_mapping"]!
- Void function set_type_mapping(model : Element, type_mapping : Element):
- dict_overwrite(model, "type_mapping", type_mapping)
- return!
- Element function NEW_get_type_mapping_as_dict(model : Element):
- Element dict
- Element keys
- String key
- dict = dict_create()
- keys = dict_keys(model["type_mapping"])
- Element rev_model
- Element rev_metamodel
- rev_model = make_reverse_dictionary(model["model"])
- rev_metamodel = make_reverse_dictionary(model["metamodel"]["model"])
- while (set_len(keys) > 0):
- key = set_pop(key)
- if (bool_not(bool_or(dict_in_node(rev_model, model["type_mapping"][key]), dict_in_node(rev_metamodel, model["type_mapping"][key])))):
- // Element is in neither model or metamodel
- // Must be a typing link!
- // So add it
- dict_add_fast(dict, rev_model[model["type_mapping"][key]], rev_metamodel[model["type_mapping"][key]])
- return dict!
- String function NEW_read_type(model : Element, name : String):
- Element m_element
- Element link
- Integer nr
- Element mm_element
- if (dict_in(model["model"], name)):
- m_element = model["model"][name]
- nr = read_nr_out(m_element) - 1
- while (nr >= 0):
- link = read_out(m_element, nr)
- if (dict_in(model["type_mapping"], cast_id2s(link))):
- // Link is in our mapping, so we probably found it...
- // But ONLY if it is NOT in the model itself
- if (reverseKeyLookup(model["model"], link) == ""):
- // It is not, so we actually got it!
- // Now follow the edge to the type
- mm_element = read_edge_dst(link)
- return reverseKeyLookup(model["metamodel"]["model"], mm_element)!
- nr = nr - 1
- // Nothing found, so it must not be typed at all
- return ""!
- Void function NEW_retype(model : Element, element : String, type : String):
- // Remove previous type
- NEW_remove_type(model, element)
- // Add element of the model
- dict_add_fast(model["type_mapping"], cast_id2s(model["model"][element]), model["model"][element])
- // Add element of metamodel if not yet there
- Element type_entry
- type_entry = model["metamodel"]["model"][type]
- if (bool_not(dict_in(model["type_mapping"], cast_id2s(type_entry)))):
- dict_add_fast(model["type_mapping"], cast_id2s(type_entry), type_entry)
- // Draw a link between them: the typing link
- Element new_edge
- new_edge = create_edge(model["model"][element], type_entry)
- dict_add_fast(model["type_mapping"], cast_id2s(new_edge), new_edge)
- return!
- Void function NEW_new_type_mapping(model : Element):
- if (dict_in(model, "type_mapping")):
- dict_delete(model, "type_mapping")
- dict_add_fast(model, "type_mapping", dict_create())
- return !
- Void function NEW_remove_type(model : Element, name : String):
- String elem
- elem = cast_id2s(model["model"][name])
- if (dict_in(model["type_mapping"], elem)):
- dict_delete(model["type_mapping"], elem)
- return !
- Element function OLD_get_type_mapping_as_dict(model : Element):
- return model["type_mapping"][""]!
- Element function OLD_get_elements_typed_by(model : Element, type : String):
- return reverseKeyLookupMulti(model["type_mapping"][""], type)!
- String function OLD_read_type(model : Element, name : String):
- String result
- Element tm
- if (dict_in(model["model"], name)):
- if (dict_in(model["type_mapping"][""], name)):
- result = model["type_mapping"][""][name]
- if (dict_in(model["metamodel"]["model"], result)):
- return result!
- else:
- return ""!
- else:
- return ""!
- else:
- return ""!
- Void function OLD_retype(model : Element, element : String, type : String):
- // Retype a model, deleting any previous type the element had
- // The type string is evaluated in the metamodel previously specified
- if (dict_in(model["type_mapping"][""], element)):
- dict_delete(model["type_mapping"][""], element)
- dict_add_fast(model["type_mapping"][""], element, type)
- return!
- Void function OLD_new_type_mapping(model : Element):
- if (dict_in(model, "type_mapping")):
- dict_delete(model, "type_mapping")
- dict_add_fast(model, "type_mapping", dict_create())
- dict_add_fast(model["type_mapping"], "", dict_create())
- return !
- Void function OLD_remove_type(model : Element, name : String):
- dict_delete(model["type_mapping"][""], name)
- return !
|