|
@@ -50,6 +50,7 @@ Void function set_type_mapping(model : Element, type_mapping_model : Element):
|
|
|
dict_add_fast(type_mapping, rev_model[cast_id2s(read_edge_src(type_mapping_model[key]))], rev_metamodel[cast_id2s(read_edge_dst(type_mapping_model[key]))])
|
|
|
|
|
|
dict_overwrite(model, "type_mapping", type_mapping)
|
|
|
+ dict_overwrite(model, "type_mapping_model", type_mapping_model)
|
|
|
return!
|
|
|
|
|
|
Element function elements_typed_by(model : Element, type_name : String):
|
|
@@ -81,17 +82,45 @@ String function read_type(model : Element, name : String):
|
|
|
Void function retype(model : Element, element : String, type : String):
|
|
|
// Retype a model, deleting any previous type the element had
|
|
|
// The type string is evaluated in the metamodel previously specified
|
|
|
- if (dict_in(model["type_mapping"], element)):
|
|
|
- dict_delete(model["type_mapping"], element)
|
|
|
- dict_add_fast(model["type_mapping"], element, type)
|
|
|
+ dict_overwrite(model["type_mapping"], element, type)
|
|
|
+
|
|
|
+ // TODO this is a serious problem, which we now want to avoid...
|
|
|
+ if (cast_id2s(model["model"][element]) == "0"):
|
|
|
+ return!
|
|
|
+
|
|
|
+ // Remove previous type
|
|
|
+ String elem
|
|
|
+ elem = cast_id2s(model["model"][element])
|
|
|
+ if (dict_in(model["type_mapping_model"], elem)):
|
|
|
+ dict_delete(model["type_mapping_model"], elem)
|
|
|
+
|
|
|
+ // Add element of the model
|
|
|
+ dict_add_fast(model["type_mapping_model"], cast_id2s(model["model"][element]), model["model"][element])
|
|
|
+
|
|
|
+ // Add element of metamodel if not yet there
|
|
|
+ Element type_entry
|
|
|
+ type_entry = model["metamodel"]["model"][type]
|
|
|
+ if (bool_not(dict_in(model["type_mapping_model"], cast_id2s(type_entry)))):
|
|
|
+ dict_add_fast(model["type_mapping_model"], cast_id2s(type_entry), type_entry)
|
|
|
+
|
|
|
+ // Draw a link between them: the typing link
|
|
|
+ Element new_edge
|
|
|
+ new_edge = create_edge(model["model"][element], type_entry)
|
|
|
+ dict_add_fast(model["type_mapping_model"], cast_id2s(new_edge), new_edge)
|
|
|
+
|
|
|
return!
|
|
|
|
|
|
Void function new_type_mapping(model : Element):
|
|
|
- if (dict_in(model, "type_mapping")):
|
|
|
- dict_delete(model, "type_mapping")
|
|
|
- dict_add_fast(model, "type_mapping", dict_create())
|
|
|
+ dict_overwrite(model, "type_mapping", dict_create())
|
|
|
+ dict_overwrite(model["type_mapping_model"], "model", dict_create())
|
|
|
return !
|
|
|
|
|
|
Void function remove_type(model : Element, name : String):
|
|
|
dict_delete(model["type_mapping"], name)
|
|
|
+
|
|
|
+ String elem
|
|
|
+ elem = cast_id2s(model["model"][name])
|
|
|
+ if (dict_in(model["type_mapping"], elem)):
|
|
|
+ dict_delete(model["type_mapping"], elem)
|
|
|
+
|
|
|
return !
|