浏览代码

Fixed concrete syntax front-end for tracability

Yentl Van Tendeloo 8 年之前
父节点
当前提交
ac1d35482e

+ 3 - 53
bootstrap/core_algorithm.alc

@@ -9,6 +9,7 @@ include "ramify.alh"
 include "conformance_scd.alh"
 include "transform.alh"
 include "metamodels.alh"
+include "utils.alh"
 
 Element core = ?
 
@@ -18,59 +19,6 @@ String admin_password = "admin"
 String core_location = "models/CoreFormalism"
 String core_model_location = "core"
 
-String function JSON_print(model : Element):
-	String result
-	Element keys_m
-	String v_m
-	String type
-	String attr_key
-	Element attr_keys
-	Boolean first
-	Element attr_value
-
-	result = "["
-	keys_m = dict_keys(model["model"])
-	first = True
-
-	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")):
-			if (bool_not(first)):
-				result = result + ","
-			else:
-				first = False
-
-			result = result + "{"
-			result = (((result + "\"id\": \"") + v_m) + "\"")
-			result = (((result + ",") + "\"type\": \"") + read_type(model, v_m)) + "\""
-			if (type == "Association"):
-				result = (((result + ", \"__source\": \"") + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + "\"")
-				result = (((result + ", \"__target\": \"") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m]))) + "\"")
-
-			// Has attributes
-			attr_keys = dict_keys(getAttributeList(model, v_m))
-			while (0 < read_nr_out(attr_keys)):
-				attr_key = set_pop(attr_keys)
-				attr_value = read_attribute(model, v_m, attr_key)
-				if (element_eq(attr_value, read_root())):
-					result = (((result + ", \"") + attr_key) + "\": null")
-				else:
-					if (is_physical_boolean(attr_value)):
-						if (attr_value):
-							result = ((result + ", \"") + attr_key) + "\": true"
-						else:
-							result = ((result + ", \"") + attr_key) + "\": false"
-					else:
-						result = ((((result + ", \"") + attr_key) + "\": ") + cast_v2s(attr_value))
-
-			result = result + "}"
-
-	result = result + "]"
-
-	return result!
-
 Void function initialize_core():
 	// Initialize the Core Formalism
 	String core_model
@@ -952,6 +900,8 @@ String function cmd_model_render(user_id : String, model_name : String, mapper_n
 					// Overwrite the previous rendered model
 					model_overwrite(result["rendered"], get_model_id(rendered_name))
 					model_overwrite(result["abstract"], get_model_id(model_name))
+					log("Overwrite model at " + model_name)
+					log("Entries: " + set_to_string(dict_keys(result["abstract"]["model"])))
 
 					// Tracability updated in-place
 					model_overwrite(tracability_model, get_model_id(tracability_name))

+ 1 - 0
bootstrap/initial_code_task.alc

@@ -17,5 +17,6 @@ Void mutable function __main():
 	exec(root["bootstrap/transform.alc"]["initializers"])
 	exec(root["bootstrap/conformance_scd.alc"]["initializers"])
 	exec(root["bootstrap/random.alc"]["initializers"])
+	exec(root["bootstrap/utils.alc"]["initializers"])
 	new_task()
 	return!

+ 6 - 7
bootstrap/model_management.alc

@@ -180,14 +180,14 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 				src = cast_id2s(read_edge_src(model["model"][key]))
 				dst = cast_id2s(read_edge_dst(model["model"][key]))
 				if (bool_and(dict_in(elem_map, src), dict_in(elem_map, dst))):
-					new_name = instantiate_link(new_model, retyping_key + type, key, elem_map[src], elem_map[dst])
+					new_name = instantiate_link(new_model, retyping_key + type, "", elem_map[src], elem_map[dst])
 				else:
 					set_add(second_keys, key)
 					new_name = ""
 			elif (has_value(model["model"][key])):
-				new_name = instantiate_value(new_model, retyping_key + type, key, model["model"][key])
+				new_name = instantiate_value(new_model, retyping_key + type, "", model["model"][key])
 			else:
-				new_name = instantiate_node(new_model, retyping_key + type, key)
+				new_name = instantiate_node(new_model, retyping_key + type, "")
 
 			if (new_name != ""):
 				// Add the new name to a map which registers the mapping to the new name
@@ -286,7 +286,6 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 				src_name = list_read(string_split(read_type(merged_model, src), "/"), 0)
 				dst_name = list_read(string_split(read_type(merged_model, dst), "/"), 0)
 
-
 				// Check if we actually keep both models around, as otherwise it is useless anyway
 				if (bool_and(dict_in(result, src_name), dict_in(result, dst_name))):
 					if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
@@ -321,7 +320,7 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 						// Though we first check the model to which it was mapped, as this should be the same as we have now
 						if (bool_and(dict_in(result[retyping_key]["model"], mapping[src]), dict_in(result[retyping_key]["model"], mapping[dst]))):
 							// The matching worked fine
-							dict_add_fast(mapping, key, instantiate_link(result[retyping_key], original_type, "", mapping[src], mapping[dst]))
+							dict_add_fast(mapping, key, instantiate_link(result[retyping_key], original_type, key, mapping[src], mapping[dst]))
 						else:
 							log("ERROR mapping: source/target mapped to model, but not found in expected model; ignoring")
 					else:
@@ -330,11 +329,11 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 
 				elif (has_value(elem)):
 					// Has a value, so copy that as well
-					dict_add_fast(mapping, key, instantiate_value(result[retyping_key], original_type, "", elem))
+					dict_add_fast(mapping, key, instantiate_value(result[retyping_key], original_type, key, elem))
 
 				else:
 					// Is a node
-					dict_add_fast(mapping, key, instantiate_node(result[retyping_key], original_type, ""))
+					dict_add_fast(mapping, key, instantiate_node(result[retyping_key], original_type, key))
 
 		if (read_nr_out(keys) == 0):
 			keys = second_keys

+ 55 - 0
bootstrap/utils.alc

@@ -0,0 +1,55 @@
+include "modelling.alh"
+include "primitives.alh"
+include "object_operations.alh"
+include "model_management.alh"
+
+String function JSON_print(model : Element):
+	String result
+	Element keys_m
+	String v_m
+	String type
+	String attr_key
+	Element attr_keys
+	Boolean first
+	Element attr_value
+
+	result = "["
+	keys_m = dict_keys(model["model"])
+	first = True
+
+	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")):
+			if (bool_not(first)):
+				result = result + ","
+			else:
+				first = False
+
+			result = result + "{"
+			result = (((result + "\"id\": \"") + v_m) + "\"")
+			result = (((result + ",") + "\"type\": \"") + read_type(model, v_m)) + "\""
+			if (type == "Association"):
+				result = (((result + ", \"__source\": \"") + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + "\"")
+				result = (((result + ", \"__target\": \"") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m]))) + "\"")
+
+			// Has attributes
+			attr_keys = dict_keys(getAttributeList(model, v_m))
+			while (0 < read_nr_out(attr_keys)):
+				attr_key = set_pop(attr_keys)
+				attr_value = read_attribute(model, v_m, attr_key)
+				if (element_eq(attr_value, read_root())):
+					result = (((result + ", \"") + attr_key) + "\": null")
+				else:
+					if (is_physical_boolean(attr_value)):
+						if (attr_value):
+							result = ((result + ", \"") + attr_key) + "\": true"
+						else:
+							result = ((result + ", \"") + attr_key) + "\": false"
+					else:
+						result = ((((result + ", \"") + attr_key) + "\": ") + cast_v2s(attr_value))
+
+			result = result + "}"
+	result = result + "]"
+	return result!

+ 1 - 0
interface/HUTN/includes/utils.alh

@@ -0,0 +1 @@
+String function JSON_print(model : Element)

+ 2 - 0
wrappers/modelverse.py

@@ -752,6 +752,8 @@ def read_attrs(model_name, ID):
     # raises UnknownIdentifier
     _goto_mode(MODE_MODIFY, model_name)
 
+    print("Read attrs on model named " + str(model_name))
+
     _input(["read", ID])
     output = _handle_output("Success: ", split=" ")
     v = output.split("\n")