MetaDepth.alc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "modelling.alh"
  4. include "library.alh"
  5. Boolean function main(model : Element):
  6. // Contains three types of models: model, metamodel, and type_mapping.
  7. // Each with the obvious meanings.
  8. // Note that this is only a placeholder that serves as a proof of concept.
  9. // Thus only the check for multiple inheritance is being done, which checks for attributes.
  10. // A full example is given in the Modelverse's internal conformance relation.
  11. // Find all instances of classes
  12. // First, find the class types
  13. Element classes
  14. classes = allInstances(model, "metamodel/Class")
  15. Element links
  16. String link
  17. Element type_mapping
  18. type_mapping = dict_create()
  19. Element instances
  20. String instance
  21. instances = allInstances(model, "type_mapping/Instance")
  22. while (set_len(instances) > 0):
  23. instance = set_pop(instances)
  24. dict_add(type_mapping, "model/" + string_replace(instance, "type_mapping/instance_", ""), "metamodel/" + string_replace(set_pop(allAssociationDestinations(model, instance, "type_mapping/TypeLink")), "type_mapping/type_", ""))
  25. // Check if each attribute is there, and satisfies the constraints
  26. instances = dict_keys(type_mapping)
  27. while (set_len(instances) > 0):
  28. instance = set_pop(instances)
  29. if (read_type(model, type_mapping[instance]) == "metamodel/Class"):
  30. // Got an instance of a Class
  31. String type
  32. Element inherits_from
  33. type = type_mapping[instance]
  34. Element outgoing_links
  35. String outgoing_link
  36. Element attrs
  37. outgoing_links = allOutgoingAssociationInstances(model, instance, "")
  38. attrs = dict_create()
  39. while (set_len(outgoing_links) > 0):
  40. outgoing_link = set_pop(outgoing_links)
  41. String name
  42. if (dict_in(type_mapping, outgoing_link)):
  43. name = read_attribute(model, type_mapping[outgoing_link], "name")
  44. dict_add(attrs, name, model["model"][readAssociationDestination(model, outgoing_link)])
  45. // Fetch a list of attributes that should be defined
  46. inherits_from = allAssociationDestinations(model, type, "metamodel/Inheritance")
  47. String superclass
  48. Element defining_attributes
  49. Element last_found
  50. Element inherits_mapping
  51. inherits_mapping = dict_create()
  52. String key
  53. while (set_len(inherits_from) > 0):
  54. key = set_pop(inherits_from)
  55. dict_add(inherits_mapping, read_attribute(model, key, "name"), key)
  56. Element sorted_inherits
  57. sorted_inherits = list_sort(set_to_list(dict_keys(inherits_mapping)))
  58. inherits_from = list_create()
  59. while (list_len(sorted_inherits) > 0):
  60. list_append(inherits_from, inherits_mapping[list_pop(sorted_inherits, 0)])
  61. last_found = dict_create()
  62. while (list_len(inherits_from) > 0):
  63. superclass = list_pop_final(inherits_from)
  64. defining_attributes = getInstantiatableAttributes(model, superclass, "metamodel/AttributeLink")
  65. dict_update(last_found, defining_attributes)
  66. Element keys
  67. String attr
  68. Element constraint
  69. String result
  70. keys = dict_keys(attrs)
  71. while (set_len(keys) > 0):
  72. attr = set_pop(keys)
  73. constraint = get_func_AL_model(import_node(read_attribute(model, last_found[attr], "constraint")))
  74. result = constraint(attrs[attr])
  75. if (result != "OK"):
  76. log("Conformance not OK: " + result)
  77. return False!
  78. log("Conformance OK")
  79. return True!