瀏覽代碼

Changed the implementation of all{Outgoing/Incoming}AssociationInstances back to use allInstances, which will later be implemented more efficiently

Yentl Van Tendeloo 9 年之前
父節點
當前提交
b8ed448b2e
共有 1 個文件被更改,包括 21 次插入35 次删除
  1. 21 35
      bootstrap/object_operations.alc

+ 21 - 35
bootstrap/object_operations.alc

@@ -66,50 +66,36 @@ Element function selectPossibleOutgoing(model : Element, source : String, limit_
 
 Element function allOutgoingAssociationInstances(model : Element, source_name : String, assoc_name : String):
 	// Read out all outgoing edges of the model and select those that are typed by the specified association
-	Integer nr_out
-	Integer i
-	Element out
-	String out_name
+	Element assocs
+	String assoc
 	Element result
+	Element source
 
-	result = create_node()
-	nr_out = read_nr_out(model["model"][source_name])
-	i = 0
-
-	log("Searching for instances of " + assoc_name)
-	log("  starting from " + source_name)
-	while (i < nr_out):
-		out = read_out(model["model"][source_name], i)
-		if (set_in_node(model["model"], out)):
-			out_name = reverseKeyLookup(model["model"], out)
-			log("     checking " + out_name)
-			log("        typed by: " + reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], out)))
-			if (is_nominal_instance(model, out_name, assoc_name)):
-				set_add(result, out_name)
-		else:
-			log("     skipping link typed by: " + reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], out)))
-		i = i + 1
+	assocs = allInstances(model, assoc_name)
+	source = model["model"][source_name]
 
+	result = create_node()
+	while (0 < list_len(assocs)):
+		assoc = set_pop(assocs)
+		if (element_eq(source, read_edge_src(model["model"][assoc]))):
+			set_add(result, assoc)
 	return result
 
 Element function allIncomingAssociationInstances(model : Element, target_name : String, assoc_name : String):
 	// Read out all outgoing edges of the model and select those that are typed by the specified association
-	Integer nr_in
-	Integer i
-	Element in
-	String in_name
+	Element assocs
+	String assoc
 	Element result
-	result = create_node()
-	nr_in = read_nr_in(model["model"][target_name])
-	i = 0
-	while (i < nr_in):
-		in = read_in(model["model"][target_name], i)
-		if (set_in_node(model["model"], in)):
-			in_name = reverseKeyLookup(model["model"], in)
-			if (is_nominal_instance(model, in_name, assoc_name)):
-				set_add(result, in_name)
-		i = i + 1
+	Element target
 
+	assocs = allInstances(model, assoc_name)
+	target = model["model"][target_name]
+
+	result = create_node()
+	while (0 < list_len(assocs)):
+		assoc = set_pop(assocs)
+		if (element_eq(target, read_edge_dst(model["model"][assoc]))):
+			set_add(result, assoc)
 	return result
 
 Element function getAttributeList(model : Element, element : String):