AToMPM.alc 2.8 KB

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