فهرست منبع

First model_copy

Yentl Van Tendeloo 8 سال پیش
والد
کامیت
b8a0918755
2فایلهای تغییر یافته به همراه36 افزوده شده و 7 حذف شده
  1. 22 0
      bootstrap/modelling.alc
  2. 14 7
      bootstrap/transform.alc

+ 22 - 0
bootstrap/modelling.alc

@@ -557,3 +557,25 @@ Element function model_fuse(models : Element):
 				instantiate_node(new_model, type, (model_name + "/") + key)
 
 	return new_model!
+
+Element function model_copy(src_model : Element):
+	Element dst_model
+	Element queue
+	Element name
+
+	dst_model = instantiate_model(src_model["metamodel"])
+	dict_add(dst_model, "inheritance", src_model["inheritance"])
+	dict_add(dst_model, "model", create_node())
+	dict_add(dst_model, "type_mapping", create_node())
+
+	queue = set_to_list(dict_keys(src_model["model"]))
+
+	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
+		elif (has_value(src_model["model"][name])):
+			// Has a value, so copy that as well
+		else:
+			// Is a node

+ 14 - 7
bootstrap/transform.alc

@@ -275,16 +275,23 @@ Element function transform(host_model : Element, schedule_model : Element):
 	Element all_composites
 	String composite
 	String current
+	Element merged
+	Element original_mm
 
 	if (bool_not(schedule_model["metamodel"]["inplace"])):
 		// Do some preliminary changes if it is deemed out-place!
 		// Need to make sure that:
 		//		1) a fused language is created of source and target
 		// 		2) the host_model conforms to the fused language
-		// TODO
-		log("Out place transformation!")
-		log("Schedule model has: " + cast_v2s(schedule_model["inplace"]))
-		return read_root()!
+
+		// 1) Merge the languages
+		merged = model_fuse(schedule_model["metamodel"]["source"], schedule_model["metamodel"]["target"])
+
+		// 2a) Copy host_model, as we will change its typing information and content out-place
+		host_model = model_copy(host_model)
+		
+		// 2b) Retype all elements of host_model in the merged language
+		model_retype_on_name(host_model, merged, "+", "SOURCE/")
 
 	// Now start transforming for real
 	all_composites = allInstances(schedule_model, "Composite")
@@ -306,9 +313,9 @@ Element function transform(host_model : Element, schedule_model : Element):
 			return True!
 		else:
 			// Prepare the model before sending it back
-			// 	1) Strip the host model of all "SOURCE" elements
-			// 	2) Retype the model to the "TARGET" elements
-			// TODO
+			// Only keep elements with TARGET types and retype them to original
+			model_retype_on_name(host_model, original_mm, "-", "TARGET/")
+
 			return read_root()!
 	else:
 		// Failure, so return False if it is in-place, or the root node if it is out-place