Browse Source

Implemented allInstances in an easier (and more correct) way, that also
takes into account subclasses

Yentl Van Tendeloo 9 years ago
parent
commit
7e98ac964e
1 changed files with 7 additions and 16 deletions
  1. 7 16
      bootstrap/object_operations.alc

+ 7 - 16
bootstrap/object_operations.alc

@@ -7,24 +7,15 @@ Element function allInstances(model : Element, type_name : String):
 	Element result
 	Element type
 
-	type = model["metamodel"]["model"][type_name]
-	type_mapping = model["type_mapping"]
-	result = create_node()
-
-	Integer counter
-	counter = 0
+	String key
+	Element keys
 
-	Integer length
-	length = read_nr_out(type_mapping)
+	keys = dict_keys(model["model"])
+	while (0 < list_len(keys)):
+		key = set_pop(keys)
+		if (is_nominal_instance(model, key, type_name)):
+			set_add(result, key)
 
-	Element edge
-	while (counter < length):
-		edge = read_out(type_mapping, counter)
-		if (element_eq(read_edge_dst(edge), type)):
-			// Found an element of the specified type
-			set_add(result, getName(model, read_edge_dst(read_out(edge, 0))))
-		counter = counter + 1
-	
 	return result
 
 Element function selectPossibleIncoming(model : Element, target : String, limit_set : Element):