typing.alc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // log("Could not find " + result)
  17. return ""!
  18. else:
  19. // log("Untyped " + name)
  20. return ""!
  21. else:
  22. // log("Couldn't find type of " + name)
  23. return ""!
  24. Void function retype(model : Element, element : String, type : String):
  25. // Retype a model, deleting any previous type the element had
  26. // The type string is evaluated in the metamodel previously specified
  27. if (dict_in(model["type_mapping"], element)):
  28. dict_delete(model["type_mapping"], element)
  29. dict_add_fast(model["type_mapping"], element, type)
  30. return!
  31. Element function new_type_mapping():
  32. return dict_create()!
  33. Void function remove_type(model : Element, name : String):
  34. dict_delete(model["type_mapping"], name)
  35. return !