typing.alc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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()!