Selaa lähdekoodia

Updated model_render to compile nicely

Yentl Van Tendeloo 8 vuotta sitten
vanhempi
commit
eccefa0513
3 muutettua tiedostoa jossa 55 lisäystä ja 36 poistoa
  1. 14 1
      core/core_algorithm.alc
  2. 40 35
      core/mini_modify.alc
  3. 1 0
      core/mini_modify.alh

+ 14 - 1
core/core_algorithm.alc

@@ -847,6 +847,13 @@ Void function user_function_skip_init(user_id : String):
 			String mapper_name
 			String mapper_ID
 			String rendered_name
+			String tracability_name
+			String type_ID
+			Element inputs
+			Element outputs
+			Element rendered_model
+			Element tracability_model
+			Element result
 
 			output("Model to render?")
 			model_name = input()
@@ -890,7 +897,13 @@ Void function user_function_skip_init(user_id : String):
 								tracability_model = get_full_model(get_model_id(tracability_name))
 
 							// Do the operation itself!
-							execute_operation(mapper_ID, inputs, outputs, tracability_model)
+							result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
+
+							// Overwrite the previous rendered model; tracability updated in-place
+							model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
+
+							// Also output the resulting model
+							output(pretty_print(rendered_name))
 
 						else:
 							output("Permission denied")

+ 40 - 35
core/mini_modify.alc

@@ -8,6 +8,45 @@ include "metamodels.alh"
 include "modelling.alh"
 include "compilation_manager.alh"
 
+String function pretty_print(model : Element):
+	Element keys_m
+	String type
+	String v_m
+	Element attr_list
+	Element attr_keys
+	String attr_key
+	String result
+
+	result = ""
+	keys_m = dict_keys(model["model"])
+
+	while (read_nr_out(keys_m) > 0):
+		v_m = set_pop(keys_m)
+		type = read_type(model["metamodel"], read_type(model, v_m))
+
+		if (bool_or(type == "Class", type == "Association")):
+			result = result + ((("  " + v_m) + " : ") + read_type(model, v_m))
+			if (type == "Association"):
+				result = result + ((("    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + " --> ") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])))
+
+			// Defines attributes
+			attr_list = getInstantiatableAttributes(model, v_m)
+			attr_keys = dict_keys(attr_list)
+			while (0 < read_nr_out(attr_keys)):
+				attr_key = set_pop(attr_keys)
+				result = result + (((("      " + attr_key) + " : ") + cast_v2s(attr_list[attr_key])))
+
+			// Has attributes
+			attr_list = getAttributeList(model, v_m)
+			attr_keys = dict_keys(attr_list)
+			while (0 < read_nr_out(attr_keys)):
+				attr_key = set_pop(attr_keys)
+				if (element_eq(read_attribute(model, v_m, attr_key), read_root())):
+					result = result + (((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = (undefined)")
+				else:
+					result = result + ((((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = ") + cast_v2s(read_attribute(model, v_m, attr_key)))
+	return result!
+
 Element function modify(model : Element, write : Boolean):
 	String cmd
 
@@ -191,41 +230,7 @@ Element function modify(model : Element, write : Boolean):
 				output("Permission denied")
 
 		elif (cmd == "nice_list"):
-			Element keys_m
-			String type
-			String v_m
-			Element attr_list
-			Element attr_keys
-			String attr_key
-
-			// TODO change log to output
-			keys_m = dict_keys(model["model"])
-
-			while (read_nr_out(keys_m) > 0):
-				v_m = set_pop(keys_m)
-				type = read_type(model["metamodel"], read_type(model, v_m))
-
-				if (bool_or(type == "Class", type == "Association")):
-					log((("  " + v_m) + " : ") + read_type(model, v_m))
-					if (type == "Association"):
-						log((("    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + " --> ") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])))
-
-					// Defines attributes
-					attr_list = getInstantiatableAttributes(model, v_m)
-					attr_keys = dict_keys(attr_list)
-					while (0 < read_nr_out(attr_keys)):
-						attr_key = set_pop(attr_keys)
-						log(((("      " + attr_key) + " : ") + cast_v2s(attr_list[attr_key])))
-
-					// Has attributes
-					attr_list = getAttributeList(model, v_m)
-					attr_keys = dict_keys(attr_list)
-					while (0 < read_nr_out(attr_keys)):
-						attr_key = set_pop(attr_keys)
-						if (element_eq(read_attribute(model, v_m, attr_key), read_root())):
-							log(((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = (undefined)")
-						else:
-							log((((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = ") + cast_v2s(read_attribute(model, v_m, attr_key)))
+			pretty_print(model)
 
 		elif (cmd == "list"):
 			Element keys_m

+ 1 - 0
core/mini_modify.alh

@@ -1 +1,2 @@
 Element function modify(model : Element, write : Boolean)
+String function pretty_print(model : Element)