123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- include "primitives.alh"
- include "conformance_scd.alh"
- include "constructors.alh"
- Element function allInstances(model : Element, type_name : String):
- Element type_mapping
- Element result
- Element type
- String key
- Element keys
- keys = dict_keys(model["model"])
- type = model["metamodel"]["model"][type_name]
- result = create_node()
- while (0 < list_len(keys)):
- key = set_pop(keys)
- if (is_nominal_instance(model, model["model"][key], type)):
- set_add(result, key)
- return result
- Element function selectPossibleIncoming(model : Element, target : String, limit_set : Element):
- // Find all possible incoming link types for the target model
- // Should also include those specified on the superclass(es)
- String type
- Element metamodel_dict
- Element elem
- Element result
- Element target_element
- result = create_node()
- metamodel_dict = model["metamodel"]["model"]
- target_element = model["model"][target]
- while (0 < list_len(limit_set)):
- type = set_pop(limit_set)
- elem = metamodel_dict[type]
- if (is_edge(elem)):
- if (is_nominal_instance(model, target_element, read_edge_dst(elem))):
- set_add(result, type)
-
- return result
- Element function selectPossibleOutgoing(model : Element, source : String, limit_set : Element):
- // Find all possible outgoing link types for the source model
- // Should also include those specified on the superclass(es)
- String type
- Element metamodel_dict
- Element elem
- Element result
- Element source_element
- result = create_node()
- metamodel_dict = model["metamodel"]["model"]
- source_element = model["model"][source]
-
- while (0 < list_len(limit_set)):
- type = set_pop(limit_set)
- elem = metamodel_dict[type]
- if (is_edge(elem)):
- if (is_nominal_instance(model, source_element, read_edge_src(elem))):
- set_add(result, type)
-
- return result
- Element function allOutgoingAssociationInstances(model : Element, source_name : String, assoc_name : String):
- // Read out all outgoing edges of the model and select those that are typed by the specified association
- // TODO for some reason this crashes if allInstances is used!
- Integer nr_out
- Integer i
- Element out
- String out_name
- Element result
- result = create_node()
- nr_out = read_nr_out(model["model"][source_name])
- i = 0
- while (i < nr_out):
- out = read_out(model["model"][source_name], i)
- if (set_in_node(model["model"], out)):
- out_name = reverseKeyLookup(model["model"], out)
- if (is_nominal_instance(model, out, model["metamodel"]["model"][assoc_name])):
- set_add(result, out_name)
- i = i + 1
- return result
- Element function allIncomingAssociationInstances(model : Element, target_name : String, assoc_name : String):
- // Read out all outgoing edges of the model and select those that are typed by the specified association
- Integer nr_in
- Integer i
- Element in
- String in_name
- Element result
- result = create_node()
- nr_in = read_nr_in(model["model"][target_name])
- i = 0
- while (i < nr_in):
- in = read_in(model["model"][target_name], i)
- if (set_in_node(model["model"], in)):
- in_name = reverseKeyLookup(model["model"], in)
- if (is_nominal_instance(model, in, model["metamodel"]["model"][assoc_name])):
- set_add(result, in_name)
- i = i + 1
- return result
- Element function getAttributeList(model : Element, element : String):
- Element result
- Element keys
- Element type
- Element attr_name
- String attr_type
- result = create_node()
- type = dict_read_node(model["type_mapping"], model["model"][element])
- keys = dict_keys(type)
- // Add our own attributes
- while (0 < list_len(keys)):
- attr_name = set_pop(keys)
- if (is_physical_string(attr_name)):
- attr_type = reverseKeyLookup(model["metamodel"]["model"], type[attr_name])
- dict_add(result, attr_name, attr_type)
- // Go on to the metalevel
- // TODO
- return result
- Element function getInstantiatableAttributes(model : Element, element : String):
- Element result
- result = create_node()
- // Get all outgoing "dictionary" links
- Element set_own
- Element elem
- elem = model["model"][element]
- set_own = dict_keys(element)
- // Filter them
- Element e
- while (0 < read_nr_out(set_own)):
- e = set_pop(set_own)
- if (is_physical_string(e)):
- dict_add(result, e, reverseKeyLookup(model["model"], element[e]))
- return result
- // TODO Utility functions!
- String function reverseKeyLookup(dict : Element, element : Element):
- return dict_reverse(dict, element)
- // TODO this code makes everything very inefficient; wait to enable this for once the compilation is implemented
- Element elements
- String name
- elements = dict_keys(dict)
- while (0 < list_len(elements)):
- name = set_pop(elements)
- if (element_eq(dict[name], element)):
- return name
- return string_join(string_join("(unknown: ", cast_e2s(element)), " )")
- String function print_dict(dict : Element):
- Element keys
- Element key
- String result
- keys = dict_keys(dict)
- result = ""
- while (0 < list_len(keys)):
- key = set_pop(keys)
- result = result + cast_v2s(key)
- result = result + ": "
- result = result + cast_v2s(dict[key])
- result = result + "\n"
- return result
- String function getName(model : Element, element : Element):
- return reverseKeyLookup(model["model"], element)
|