浏览代码

Make it start up

Yentl Van Tendeloo 8 年之前
父节点
当前提交
a85f3b6217
共有 2 个文件被更改,包括 45 次插入3 次删除
  1. 二进制
      bootstrap/bootstrap.m.gz
  2. 45 3
      bootstrap/model_management.alc

二进制
bootstrap/bootstrap.m.gz


+ 45 - 3
bootstrap/model_management.alc

@@ -165,7 +165,49 @@ Void function model_join(dst_model : Element, src_model : Element, retyping_key
 
 	return!
 	
-Element function model_split(source_model : Element, target_metamodel : Element, retyping_key : String):
-	Element model
+Element function model_split(src_model : Element, target_metamodel : Element, retyping_key : String):
+	Element dst_model
 
-	return model!
+	dst_model = instantiate_model(target_metamodel)
+
+	Element queue
+	Element mapping
+	String name
+	String type
+	String src
+	String dst
+	Integer length
+
+	queue = set_to_list(dict_keys(src_model["model"]))
+	mapping = create_node()
+	length = string_len(retyping_key)
+
+	while (read_nr_out(queue) > 0):
+		name = list_pop(queue, 0)
+
+		if (is_edge(src_model["model"][name])):
+			// Is an edge, so potentially queue it
+			String src
+			String dst
+
+			src = reverseKeyLookup(src_model["model"], read_edge_src(src_model["model"][name]))
+			dst = reverseKeyLookup(src_model["model"], read_edge_dst(src_model["model"][name]))
+			type = reverseKeyLookup(src_model["metamodel"]["model"], dict_read_node(src_model["type_mapping"], src_model["model"][name]))
+
+			if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
+				// All present, so create the link between them
+				dict_add(mapping, name, instantiate_link(dst_model, string_substr(type, length, string_len(type)), "", mapping[src], mapping[dst]))
+			else:
+				list_append(queue, name)
+
+		elif (has_value(src_model["model"][name])):
+			// Has a value, so copy that as well
+			type = reverseKeyLookup(src_model["metamodel"]["model"], dict_read_node(src_model["type_mapping"], src_model["model"][name]))
+			dict_add(mapping, name, instantiate_value(dst_model, string_substr(type, length, string_len(type)), "", src_model["model"][name]))
+
+		else:
+			// Is a node
+			type = reverseKeyLookup(src_model["metamodel"]["model"], dict_read_node(src_model["type_mapping"], src_model["model"][name]))
+			dict_add(mapping, name, instantiate_node(dst_model, string_substr(type, length, string_len(type)), ""))
+
+	return dst_model!