瀏覽代碼

Safer way of finding an association destination and origin

Yentl Van Tendeloo 7 年之前
父節點
當前提交
bd071b8d7e

+ 9 - 9
bootstrap/core_algorithm.alc

@@ -101,7 +101,7 @@ Element function get_full_model(model_id : String, metamodel_id : String):
 	dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
 	dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
 
 
 	// TODO for now this is restricted to the fixed semantics
 	// TODO for now this is restricted to the fixed semantics
-	// dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
+	// dict_add(m, "semantics", anAssociationDestination(core, choice, "semantics"))
 	dict_add(m, "semantics", get_entry_id("models/conformance_mv"))
 	dict_add(m, "semantics", get_entry_id("models/conformance_mv"))
 
 
 	if (metamodel_id == model_id):
 	if (metamodel_id == model_id):
@@ -144,7 +144,7 @@ Integer function get_relation_to_model(user_id : String, model_id : String):
 		return 0!
 		return 0!
 	else:
 	else:
 		String group_id
 		String group_id
-		group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
+		group_id = anAssociationDestination(core, model_id, "group")
 		if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
 		if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
 			// We are in the owning group
 			// We are in the owning group
 			return 1!
 			return 1!
@@ -1023,9 +1023,9 @@ Void function enact_PM(pm : Element, mapping : Element):
 						if (read_type(pm, next) == "Decision"):
 						if (read_type(pm, next) == "Decision"):
 							// Got decision node, so expand immediately
 							// Got decision node, so expand immediately
 							if (result):
 							if (result):
-								list_append(worklist, set_pop(allAssociationDestinations(pm, next, "Then")))
+								list_append(worklist, anAssociationDestination(pm, next, "Then"))
 							else:
 							else:
-								list_append(worklist, set_pop(allAssociationDestinations(pm, next, "Else")))
+								list_append(worklist, anAssociationDestination(pm, next, "Else"))
 						else:
 						else:
 							// Other node, so just append for further processing
 							// Other node, so just append for further processing
 							list_append(worklist, next)
 							list_append(worklist, next)
@@ -1608,7 +1608,7 @@ String function cmd_model_overwrite(model_name : String, metamodel_name : String
 	model_id = get_entry_id(model_name)
 	model_id = get_entry_id(model_name)
 	if (model_id != ""):
 	if (model_id != ""):
 		if (allow_write(current_user_id, model_id)):
 		if (allow_write(current_user_id, model_id)):
-			type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
+			type_id = anAssociationDestination(core, model_id, "instanceOf")
 			if (allow_read(current_user_id, type_id)):
 			if (allow_read(current_user_id, type_id)):
 				Element mm
 				Element mm
 				mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("formalisms/SimpleClassDiagrams"))
 				mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("formalisms/SimpleClassDiagrams"))
@@ -1639,7 +1639,7 @@ String function cmd_model_modify(model_name : String, metamodel_name : String):
 
 
 	if (model_id != ""):
 	if (model_id != ""):
 		if (allow_read(current_user_id, model_id)):
 		if (allow_read(current_user_id, model_id)):
-			type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
+			type_id = anAssociationDestination(core, model_id, "instanceOf")
 			if (allow_read(current_user_id, type_id)):
 			if (allow_read(current_user_id, type_id)):
 				Element new_model
 				Element new_model
 				new_model = get_full_model(model_id, get_entry_id(metamodel_name))
 				new_model = get_full_model(model_id, get_entry_id(metamodel_name))
@@ -1726,8 +1726,8 @@ String function cmd_model_list_full(location : String):
 			while (set_len(models) > 0):
 			while (set_len(models) > 0):
 				m = set_pop(models)
 				m = set_pop(models)
 				permissions = read_attribute(core, m, "permissions")
 				permissions = read_attribute(core, m, "permissions")
-				owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
-				group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
+				owner = read_attribute(core, anAssociationDestination(core, m, "owner"), "name")
+				group = read_attribute(core, anAssociationDestination(core, m, "group"), "name")
 				if (is_nominal_instance(core, m, "Folder")):
 				if (is_nominal_instance(core, m, "Folder")):
 					name = get_filename(read_attribute(core, m, "name")) + "/"
 					name = get_filename(read_attribute(core, m, "name")) + "/"
 				else:
 				else:
@@ -2354,7 +2354,7 @@ String function cmd_model_types(model_name : String):
 		types = allOutgoingAssociationInstances(core, model_id, "instanceOf")
 		types = allOutgoingAssociationInstances(core, model_id, "instanceOf")
 		while (set_len(types) > 0):
 		while (set_len(types) > 0):
 			type_link = set_pop(types)
 			type_link = set_pop(types)
-			result = result + full_name(readAssociationDestination(core, type_link)) + ", " + full_name(set_pop(allAssociationDestinations(core, type_link, "typing"))) + ", " + full_name(set_pop(allAssociationDestinations(core, type_link, "semantics")))+ "\n"
+			result = result + cast_string(full_name(readAssociationDestination(core, type_link))) + ", " + cast_string(full_name(anAssociationDestination(core, type_link, "typing"))) + ", " + cast_string(full_name(anAssociationDestination(core, type_link, "semantics"))) + "\n"
 
 
 		return result!
 		return result!
 	else:
 	else:

+ 30 - 0
bootstrap/object_operations.alc

@@ -200,6 +200,21 @@ String function readAssociationSource(model : Element, name : String):
 String function readAssociationDestination(model : Element, name : String):
 String function readAssociationDestination(model : Element, name : String):
 	return reverseKeyLookup(model["model"], read_edge_dst(model["model"][name]))!
 	return reverseKeyLookup(model["model"], read_edge_dst(model["model"][name]))!
 
 
+String function anAssociationDestination(model : Element, name : String, association_type : String):
+	Element tmp
+	Element result
+	String val
+
+	result = set_create()
+	tmp = allOutgoingAssociationInstances(model, name, association_type)
+
+	while (set_len(tmp) > 0):
+		val = readAssociationDestination(model, set_pop(tmp))
+		if (val != ""):
+			return val!
+
+	return ""!
+
 Element function allAssociationDestinations(model : Element, name : String, association_type : String):
 Element function allAssociationDestinations(model : Element, name : String, association_type : String):
 	Element tmp
 	Element tmp
 	Element result
 	Element result
@@ -215,6 +230,21 @@ Element function allAssociationDestinations(model : Element, name : String, asso
 
 
 	return result!
 	return result!
 
 
+String function anAssociationOrigin(model : Element, name : String, association_type : String):
+	Element tmp
+	Element result
+	String val
+
+	result = set_create()
+	tmp = allIncomingAssociationInstances(model, name, association_type)
+
+	while (set_len(tmp) > 0):
+		val = readAssociationSource(model, set_pop(tmp))
+		if (val != ""):
+			return val!
+
+	return ""!
+
 Element function allAssociationOrigins(model : Element, name : String, association_type : String):
 Element function allAssociationOrigins(model : Element, name : String, association_type : String):
 	Element tmp
 	Element tmp
 	Element result
 	Element result

+ 2 - 0
interface/HUTN/includes/object_operations.alh

@@ -12,3 +12,5 @@ String function readAssociationDestination(model : Element, name : String)
 Element function allAssociationDestinations(model : Element, name : String, association_type : String)
 Element function allAssociationDestinations(model : Element, name : String, association_type : String)
 Element function allAssociationOrigins(model : Element, name : String, association_type : String)
 Element function allAssociationOrigins(model : Element, name : String, association_type : String)
 Element function allowedAssociationsBetween(model : Element, src : String, dst : String)
 Element function allowedAssociationsBetween(model : Element, src : String, dst : String)
+String function anAssociationDestination(model : Element, name : String, association_type : String)
+String function anAssociationOrigin(model : Element, name : String, association_type : String)

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Wed May 30 08:07:46 2018
+Date:   Wed May 30 10:05:28 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server