Просмотр исходного кода

Add nicer info in pretty_print

Yentl Van Tendeloo 8 лет назад
Родитель
Сommit
27ede3db7d
2 измененных файлов с 26 добавлено и 2 удалено
  1. 20 0
      bootstrap/mini_modify.alc
  2. 6 2
      bootstrap/object_operations.alc

+ 20 - 0
bootstrap/mini_modify.alc

@@ -19,6 +19,8 @@ String function pretty_print(model : Element):
 	Element attr_keys
 	String attr_key
 	String result
+	Element lst
+	String assoc
 
 	result = ""
 	keys_m = dict_keys(model["model"])
@@ -34,7 +36,24 @@ String function pretty_print(model : Element):
 				result = result + ((("    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + " --> ") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])))
 				result = result + "\n"
 
+			// Print all incoming associations
+			result = result + "    Incoming associations:\n"
+			lst = allIncomingAssociationInstances(model, v_m, "")
+			while (set_len(lst) > 0):
+				assoc = set_pop(lst)
+				if (read_type(model["metamodel"], read_type(model, assoc)) == "Association"):
+					result = result + "      " + readAssociationSource(model, assoc) + " ---(" + assoc + ")--> \n"
+
+			// Print all outgoing associations
+			result = result + "    Outgoing associations:\n"
+			lst = allOutgoingAssociationInstances(model, v_m, "")
+			while (set_len(lst) > 0):
+				assoc = set_pop(lst)
+				if (read_type(model["metamodel"], read_type(model, assoc)) == "Association"):
+					result = result + "      ---(" + assoc + ")--> " + readAssociationDestination(model, assoc) + "\n"
+
 			// Defines attributes
+			result = result + "    Defines attributes:\n"
 			attr_list = getInstantiatableAttributes(model, v_m)
 			attr_keys = dict_keys(attr_list)
 			while (set_len(attr_keys) > 0):
@@ -43,6 +62,7 @@ String function pretty_print(model : Element):
 				result = result + "\n"
 
 			// Has attributes
+			result = result + "    Has attributes:\n"
 			attr_list = getAttributeList(model, v_m)
 			attr_keys = dict_keys(attr_list)
 			while (set_len(attr_keys) > 0):

+ 6 - 2
bootstrap/object_operations.alc

@@ -77,7 +77,9 @@ Element function allOutgoingAssociationInstances(model : Element, source_name :
 	i = 0
 	while (i < all_out):
 		option = reverseKeyLookup(model["model"], read_out(source, i))
-		if (is_nominal_instance(model, option, assoc_name)):
+		if (assoc_name == ""):
+			set_add(result, option)
+		elif (is_nominal_instance(model, option, assoc_name)):
 			set_add(result, option)
 		i = i + 1
 
@@ -97,7 +99,9 @@ Element function allIncomingAssociationInstances(model : Element, target_name :
 	i = 0
 	while (i < all_out):
 		option = reverseKeyLookup(model["model"], read_in(source, i))
-		if (is_nominal_instance(model, option, assoc_name)):
+		if (assoc_name == ""):
+			set_add(result, option)
+		elif (is_nominal_instance(model, option, assoc_name)):
 			set_add(result, option)
 		i = i + 1