typing.alc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. include "primitives.alh"
  2. include "utils.alh"
  3. Element function get_type_mapping_as_dict(model : Element):
  4. return model["type_mapping"]!
  5. Element function get_elements_typed_by(model : Element, type : String):
  6. return reverseKeyLookupMulti(model["type_mapping"], type)!
  7. String function read_type(model : Element, name : String):
  8. String result
  9. Element tm
  10. if (dict_in(model["model"], name)):
  11. if (dict_in(model["type_mapping"], name)):
  12. result = model["type_mapping"][name]
  13. if (dict_in(model["metamodel"]["model"], result)):
  14. return result!
  15. else:
  16. return ""!
  17. else:
  18. return ""!
  19. else:
  20. return ""!
  21. Void function retype(model : Element, element : String, type : String):
  22. // Retype a model, deleting any previous type the element had
  23. // The type string is evaluated in the metamodel previously specified
  24. if (dict_in(model["type_mapping"], element)):
  25. dict_delete(model["type_mapping"], element)
  26. dict_add_fast(model["type_mapping"], element, type)
  27. return!
  28. Void function new_type_mapping(model : Element):
  29. if (dict_in(model, "type_mapping")):
  30. dict_delete(model, "type_mapping")
  31. dict_add_fast(model, "type_mapping", dict_create())
  32. return !
  33. Void function remove_type(model : Element, name : String):
  34. dict_delete(model["type_mapping"], name)
  35. return !
  36. Void function set_type_mapping(model : Element, type_mapping : Element):
  37. dict_overwrite(model, "type_mapping", type_mapping)
  38. return!
  39. Element function get_type_mapping(model : Element):
  40. return model["type_mapping"]!