typegraph/scripts/graph/replaceLink.gml

27 lines
794 B
Plaintext

///replaceLink(from, toOld, toNew)
/**
* replaceLink :: TypeConLink -> TypeConLink -> TypeConLink -> ()
*
* Replaces an edge between one type con and another with a new target.
*
* @param from the source of the edge
* @param toOld the current target of the edge
* @param toNew the new target of the edge
*/
var from = argument0;
var toOld = argument1;
var toNew = argument2;
assertInstanceof(from, TypeConLink);
assertInstanceof(toOld, TypeConLink);
assertInstanceof(toNew, TypeConLink);
assert(toOld != toNew, "Replacing link from "+getInstObjName(from)+" to "+getInstObjName(toOld)+" by itself.");
ds_list_replace(from.to, ds_list_find_index(from.to, toOld), toNew);
if (ds_list_find_index(from.to, toOld) == -1)
ds_set_delete(toOld.from, from);
ds_set_add(toNew.from, from);