AToMPM.alc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 = cast_string(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. // TODO
  50. inherits_from = allAssociationDestinations(model, type, "metamodel/Inheritance")
  51. String superclass
  52. Element defining_attributes
  53. Element last_found
  54. last_found = dict_create()
  55. while (set_len(inherits_from) > 0):
  56. superclass = set_pop(inherits_from)
  57. defining_attributes = getInstantiatableAttributes(model, superclass, "metamodel/AttributeLink")
  58. dict_update(last_found, defining_attributes)
  59. Element keys
  60. String attr
  61. Element constraint
  62. String result
  63. keys = dict_keys(attrs)
  64. while (set_len(keys) > 0):
  65. attr = set_pop(keys)
  66. constraint = get_func_AL_model(import_node(read_attribute(model, last_found[attr], "constraint")))
  67. result = constraint(attrs[attr])
  68. if (result != "OK"):
  69. log("Conformance not OK: " + result)
  70. return False!
  71. log("Conformance OK")
  72. return True!