소스 검색

Split of model_management operations to their own file

Yentl Van Tendeloo 8 년 전
부모
커밋
deb21c0c91
6개의 변경된 파일127개의 추가작업 그리고 118개의 파일을 삭제
  1. 122 0
      bootstrap/model_management.alc
  2. 0 115
      bootstrap/modelling.alc
  3. 1 0
      bootstrap/ramify.alc
  4. 1 0
      bootstrap/transform.alc
  5. 3 0
      interface/HUTN/includes/model_management.alh
  6. 0 3
      interface/HUTN/includes/modelling.alh

+ 122 - 0
bootstrap/model_management.alc

@@ -0,0 +1,122 @@
+include "primitives.alh"
+include "io.alh"
+include "object_operations.alh"
+include "constructors.alh"
+include "metamodels.alh"
+include "library.alh"
+include "modelling.alh"
+
+Element function model_fuse(models : Element):
+	Element new_model
+	Element tagged_model
+	String model_name
+	Element model
+	Element keys
+	String key
+	Element selected_MM
+	String type
+
+	// Read out some data first
+	tagged_model = set_pop(models)
+	set_add(models, tagged_model)
+	model = list_read(tagged_model, 1)
+	selected_MM = model["metamodel"]
+	new_model = instantiate_model(selected_MM)
+
+	models = set_copy(models)
+	while (read_nr_out(models)):
+		tagged_model = set_pop(models)
+		model_name = list_read(tagged_model, 0)
+		model = list_read(tagged_model, 1)
+
+		// Add all elements from 'model', but prepend it with the 'model_name'
+		keys = set_to_list(dict_keys(model["model"]))
+		while (read_nr_out(keys) > 0):
+			key = list_pop(keys, 0)
+			type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][key]))
+
+			if (is_edge(model["model"][key])):
+				String src
+				String dst
+				src = (model_name + "/") + reverseKeyLookup(model["model"], read_edge_src(model["model"][key]))
+				dst = (model_name + "/") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][key]))
+				if (bool_and(dict_in(new_model["model"], src), dict_in(new_model["model"], dst))):
+					instantiate_link(new_model, type, (model_name + "/") + key, (model_name + "/") + src, (model_name + "/") + dst)
+				else:
+					list_append(keys, key)
+			elif (has_value(model["model"][key])):
+				instantiate_value(new_model, type, (model_name + "/") + key, model["model"][key])
+			else:
+				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
+	String type
+
+	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
+			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(dst_model["model"], src), dict_in(dst_model["model"], dst))):
+				// All present, so create the link between them
+				instantiate_link(dst_model, type, name, src, 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]))
+			instantiate_value(dst_model, type, name, 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]))
+			instantiate_node(dst_model, type, name)
+
+	return dst_model!
+
+Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String):
+	String key
+	String type
+	Element keys
+	Integer length
+
+	keys = dict_keys(model["model"])
+	length = string_len(name)
+
+	while (read_nr_out(keys) > 0):
+		key = set_pop(keys)
+		type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][key]))
+
+		if (operation == "+"):
+			// Keep all, but augment typename
+			dict_delete_node(model["type_mapping"], model["model"][key])
+			dict_add(model["type_mapping"], model["model"][key], model["metamodel"]["model"][name + type])
+		elif (operation == "-"):
+			// Keep only if typename beginning matches and remove from typename
+			if (string_startswith(type, name)):
+				dict_delete_node(model["type_mapping"], model["model"][key])
+				dict_add(model["type_mapping"], model["model"][key], model["metamodel"]["model"][string_substr(type, length, string_len(type))])
+			else:
+				model_delete_element(model, key)
+
+	return model!

+ 0 - 115
bootstrap/modelling.alc

@@ -512,118 +512,3 @@ Void function construct_model():
 				dict_add(global_models, input(), m)
 		else:
 			log("Modelling error: did not understand command " + command)
-
-Element function model_fuse(models : Element):
-	Element new_model
-	Element tagged_model
-	String model_name
-	Element model
-	Element keys
-	String key
-	Element selected_MM
-	String type
-
-	// Read out some data first
-	tagged_model = set_pop(models)
-	set_add(models, tagged_model)
-	model = list_read(tagged_model, 1)
-	selected_MM = model["metamodel"]
-	new_model = instantiate_model(selected_MM)
-
-	models = set_copy(models)
-	while (read_nr_out(models)):
-		tagged_model = set_pop(models)
-		model_name = list_read(tagged_model, 0)
-		model = list_read(tagged_model, 1)
-
-		// Add all elements from 'model', but prepend it with the 'model_name'
-		keys = set_to_list(dict_keys(model["model"]))
-		while (read_nr_out(keys) > 0):
-			key = list_pop(keys, 0)
-			type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][key]))
-
-			if (is_edge(model["model"][key])):
-				String src
-				String dst
-				src = (model_name + "/") + reverseKeyLookup(model["model"], read_edge_src(model["model"][key]))
-				dst = (model_name + "/") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][key]))
-				if (bool_and(dict_in(new_model["model"], src), dict_in(new_model["model"], dst))):
-					instantiate_link(new_model, type, (model_name + "/") + key, (model_name + "/") + src, (model_name + "/") + dst)
-				else:
-					list_append(keys, key)
-			elif (has_value(model["model"][key])):
-				instantiate_value(new_model, type, (model_name + "/") + key, model["model"][key])
-			else:
-				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
-	String type
-
-	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
-			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(dst_model["model"], src), dict_in(dst_model["model"], dst))):
-				// All present, so create the link between them
-				instantiate_link(dst_model, type, name, src, 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]))
-			instantiate_value(dst_model, type, name, 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]))
-			instantiate_node(dst_model, type, name)
-
-	return dst_model!
-
-Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String):
-	String key
-	String type
-	Element keys
-	Integer length
-
-	keys = dict_keys(model["model"])
-	length = string_len(name)
-
-	while (read_nr_out(keys) > 0):
-		key = set_pop(keys)
-		type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][key]))
-
-		if (operation == "+"):
-			// Keep all, but augment typename
-			dict_delete_node(model["type_mapping"], model["model"][key])
-			dict_add(model["type_mapping"], model["model"][key], model["metamodel"]["model"][name + type])
-		elif (operation == "-"):
-			// Keep only if typename beginning matches and remove from typename
-			if (string_startswith(type, name)):
-				dict_delete_node(model["type_mapping"], model["model"][key])
-				dict_add(model["type_mapping"], model["model"][key], model["metamodel"]["model"][string_substr(type, length, string_len(type))])
-			else:
-				model_delete_element(model, key)
-
-	return model!

+ 1 - 0
bootstrap/ramify.alc

@@ -2,6 +2,7 @@ include "primitives.alh"
 include "object_operations.alh"
 include "modelling.alh"
 include "metamodels.alh"
+include "model_management.alh"
 
 Element function create_outplace_transformation_language(source : Element, target : Element):
 	log("Create outplace model!")

+ 1 - 0
bootstrap/transform.alc

@@ -3,6 +3,7 @@ include "object_operations.alh"
 include "modelling.alh"
 include "random.alh"
 include "conformance_scd.alh"
+include "model_management.alh"
 
 Element function make_matching_schedule(schedule_model : Element, LHS : Element):
 	Element schedule

+ 3 - 0
interface/HUTN/includes/model_management.alh

@@ -0,0 +1,3 @@
+Element function model_fuse(models : Element)
+Element function model_copy(model : Element)
+Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String)

+ 0 - 3
interface/HUTN/includes/modelling.alh

@@ -22,6 +22,3 @@ Element function read_attribute(model : Element, elem : String, name : String)
 Void function model_delete_element(model : Element, name : String)
 Void function add_constraint(model : Element, name : String, constraint : Action)
 String function model_define_attribute(model : Element, elem : String, name : String, type : String)
-Element function model_fuse(models : Element)
-Element function model_copy(model : Element)
-Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String)