MetaDepth.alc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 type_mapping
  16. Element instances
  17. String instance
  18. type_mapping = model["model"][set_pop(allInstances(model, "type_mapping/Root"))]
  19. Element new_type_mapping
  20. Element keys
  21. String key
  22. new_type_mapping = dict_create()
  23. keys = dict_keys(type_mapping)
  24. while (set_len(keys) > 0):
  25. key = set_pop(keys)
  26. dict_add(new_type_mapping, "model/" + key, "metamodel/" + cast_string(type_mapping[key]))
  27. type_mapping = new_type_mapping
  28. // Check if each attribute is there, and satisfies the constraints
  29. instances = dict_keys(type_mapping)
  30. while (set_len(instances) > 0):
  31. instance = set_pop(instances)
  32. if (read_type(model, type_mapping[instance]) == "metamodel/Class"):
  33. // Got an instance of a Class
  34. String type
  35. Element inherits_from
  36. type = type_mapping[instance]
  37. Element outgoing_links
  38. String outgoing_link
  39. Element attrs
  40. outgoing_links = allOutgoingAssociationInstances(model, instance, "")
  41. attrs = dict_create()
  42. while (set_len(outgoing_links) > 0):
  43. outgoing_link = set_pop(outgoing_links)
  44. String name
  45. if (dict_in(type_mapping, outgoing_link)):
  46. name = read_attribute(model, type_mapping[outgoing_link], "name")
  47. dict_add(attrs, name, model["model"][readAssociationDestination(model, outgoing_link)])
  48. // Fetch a list of attributes that should be defined
  49. inherits_from = allAssociationDestinations(model, type, "metamodel/Inheritance")
  50. String superclass
  51. Element defining_attributes
  52. Element last_found
  53. Element inherits_mapping
  54. inherits_mapping = dict_create()
  55. String key
  56. while (set_len(inherits_from) > 0):
  57. key = set_pop(inherits_from)
  58. dict_add(inherits_mapping, read_attribute(model, key, "name"), key)
  59. Element sorted_inherits
  60. sorted_inherits = list_sort(set_to_list(dict_keys(inherits_mapping)))
  61. inherits_from = list_create()
  62. while (list_len(sorted_inherits) > 0):
  63. list_append(inherits_from, inherits_mapping[list_pop(sorted_inherits, 0)])
  64. last_found = dict_create()
  65. while (list_len(inherits_from) > 0):
  66. superclass = list_pop_final(inherits_from)
  67. defining_attributes = getInstantiatableAttributes(model, superclass, "metamodel/AttributeLink")
  68. dict_update(last_found, defining_attributes)
  69. Element keys
  70. String attr
  71. Element constraint
  72. String result
  73. keys = dict_keys(attrs)
  74. while (set_len(keys) > 0):
  75. attr = set_pop(keys)
  76. constraint = get_func_AL_model(import_node(read_attribute(model, last_found[attr], "constraint")))
  77. result = constraint(attrs[attr])
  78. if (result != "OK"):
  79. log("Conformance not OK: " + result)
  80. return False!
  81. log("Conformance OK")
  82. return True!