Selaa lähdekoodia

Added an RPGame model

Yentl Van Tendeloo 9 vuotta sitten
vanhempi
commit
24116c1542
3 muutettua tiedostoa jossa 87 lisäystä ja 47 poistoa
  1. 22 23
      bootstrap/conformance_scd.alc
  2. 14 8
      integration/code/pn_interface.alc
  3. 51 16
      integration/test_pn_interface.py

+ 22 - 23
bootstrap/conformance_scd.alc

@@ -129,14 +129,14 @@ String function conformance_scd(model : Element):
 			log((("Check " + model_name) + " : ") + type_name)
 
 			if (bool_not(dict_in_node(typing, element))):
-				return "Model has no type specified: " + model_name
+				return "Model has no type specified: " + model_info(model, model_name)
 
 			if (bool_not(set_in_node(metamodel["model"], dict_read_node(typing, element)))):
-				return "Type of element not in specified metamodel: " + model_name
+				return "Type of element not in specified metamodel: " + model_info(model, model_name)
 
 			// This is true by definition of is_nominal_instance
 			//if (bool_not(is_nominal_instance(model, model_name, type_name))):
-			//	return "Element is not an instance of its specified type: " + model_name
+			//	return "Element is not an instance of its specified type: " + model_info(model, model_name)
 
 			if (is_edge(element)):
 				src_model = reverseKeyLookup(model["model"], read_edge_src(element))
@@ -145,10 +145,10 @@ String function conformance_scd(model : Element):
 				dst_metamodel = reverseKeyLookup(metamodel["model"], read_edge_dst(dict_read_node(typing, element)))
 
 				if (bool_not(is_nominal_instance(model, src_model, src_metamodel))):
-					return "Source of model edge not typed by source of type: " + model_name
+					return "Source of model edge not typed by source of type: " + model_info(model, model_name)
 
 				if (bool_not(is_nominal_instance(model, dst_model, dst_metamodel))):
-					return "Destination of model edge not typed by source of type: " + model_name
+					return "Destination of model edge not typed by source of type: " + model_info(model, model_name)
 
 			// Check cardinality for all of our edges
 			//
@@ -157,9 +157,7 @@ String function conformance_scd(model : Element):
 			//
 			// First the incoming, so we are at B in the above figure
 			if (bool_not(dict_in(spo_cache, type_name))):
-				log("Fill SPO cache")
 				dict_add(spo_cache, type_name, selectPossibleOutgoing(metamodel, type_name, dict_keys(cardinalities)))
-				log("Filled SPO cache")
 
 			check_list = set_copy(spo_cache[type_name])
 			while (0 < list_len(check_list)):
@@ -171,23 +169,18 @@ String function conformance_scd(model : Element):
 						if (dict_in(cardinalities[check_type], "tlc")):
 							// A lower cardinality was defined at the target
 							if (integer_gt(cardinalities[check_type]["tlc"], instances)):
-								log("Instances: " + cast_i2s(instances))
-								log("Cardinalities: " + cast_i2s(cardinalities[check_type]["tuc"]))
-								log("Type: " + check_type)
-								return "Lower cardinality violation for outgoing edge at " + model_name
+								return "Lower cardinality violation for outgoing edge at " + model_info(model, model_name)
 						if (dict_in(cardinalities[check_type], "tuc")):
 							// An upper cardinality was defined at the target
 							if (integer_lt(cardinalities[check_type]["tuc"], instances)):
 								log("Instances: " + cast_i2s(instances))
 								log("Cardinalities: " + cast_i2s(cardinalities[check_type]["tuc"]))
 								log("Type: " + check_type)
-								return "Upper cardinality violation for outgoing edge at " + model_name
+								return "Upper cardinality violation for outgoing edge at " + model_info(model, model_name)
 
 			// Identical, but for outgoing, and thus for A in the figure
 			if (bool_not(dict_in(spi_cache, type_name))):
-				log("Fill SPI cache")
 				dict_add(spi_cache, type_name, selectPossibleIncoming(metamodel, type_name, dict_keys(cardinalities)))
-				log("Filled SPI cache")
 
 			check_list = set_copy(spi_cache[type_name])
 			while (0 < list_len(check_list)):
@@ -199,17 +192,11 @@ String function conformance_scd(model : Element):
 						if (dict_in(cardinalities[check_type], "slc")):
 							// A lower cardinality was defined at the source
 							if (integer_gt(cardinalities[check_type]["slc"], instances)):
-								log("Instances: " + cast_i2s(instances))
-								log("Cardinalities: " + cast_i2s(cardinalities[check_type]["tuc"]))
-								log("Type: " + check_type)
-								return "Lower cardinality violation for incoming edge at " + model_name
+								return "Lower cardinality violation for incoming edge at " + model_info(model, model_name)
 						if (dict_in(cardinalities[check_type], "suc")):
 							// An upper cardinality was defined at the source
 							if (integer_lt(cardinalities[check_type]["suc"], instances)):
-								log("Instances: " + cast_i2s(instances))
-								log("Cardinalities: " + cast_i2s(cardinalities[check_type]["tuc"]))
-								log("Type: " + check_type)
-								return "Upper cardinality violation for incoming edge at " + model_name
+								return "Upper cardinality violation for incoming edge at " + model_info(model, model_name)
 
 			Element constraint_function
 			constraint_function = read_attribute(metamodel, reverseKeyLookup(metamodel["model"], dict_read_node(typing, element)), "constraint")
@@ -217,7 +204,7 @@ String function conformance_scd(model : Element):
 				String result
 				result = constraint_function(model, model_name)
 				if (result != "OK"):
-					return result
+					return result + model_info(model, model_name)
 
 	// Check multiplicities, if they are defined (optional)
 	Element metamodel_keys
@@ -276,3 +263,15 @@ Element function generate_bottom_type_mapping(model : Element):
 			dict_add(tm, elem, mm["Node"])
 
 	return model
+
+String function model_info(model : Element, name : String):
+	return name
+	// For more detailed information
+	String result
+	result = ""
+	result = (result + "\nModel name: ") + name
+	result = (result + "\nType: ") + cast_v2s(reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][name])))
+	result = (result + "\nValue: ") + cast_v2s(model["model"][name])
+	result = (result + "\nSource: ") + cast_v2s(reverseKeyLookup(model["model"], read_edge_src(model["model"][name])))
+	result = (result + "\nDestination: ") + cast_v2s(reverseKeyLookup(model["model"], read_edge_dst(model["model"][name])))
+	return result

+ 14 - 8
integration/code/pn_interface.alc

@@ -167,22 +167,28 @@ Element function model_loaded(model : Element):
 							dst_name = input()
 							if (dict_in(model["model"], dst_name)):
 								instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
-								if (dict_in(model["model"], element_name)):
-									output("Instantiation successful!")
-								else:
-									output("Instantiation error!")
+								output("Instantiation successful!")
 							else:
 								output("Unknown destination; aborting")
 						else:
 							output("Unknown source; aborting")
 					else:
 						instantiate_node(model, mm_type_name, element_name)
-						if (dict_in(model["model"], element_name)):
-							output("Instantiation successful!")
-						else:
-							output("Instantiation error!")
+						output("Instantiation successful!")
 			else:
 				output("Unknown type specified; aborting")
+		elif (cmd == "set_inheritance"):
+			String inh_name
+
+			output("Which link in the metamodel is the inheritance link?")
+			inh_name = input()
+
+			if (dict_in(model["metamodel"]["model"], inh_name)):
+				dict_add(model, "inheritance", model["metamodel"]["model"][inh_name])
+				output("Set inheritance link!")
+			else:
+				output("Element not found in metamodel; aborting")
+
 		elif (cmd == "constrain"):
 			output("Element to constrain (empty for global)?")
 			String model_name

+ 51 - 16
integration/test_pn_interface.py

@@ -2,6 +2,11 @@ import unittest
 
 from utils import run_file, get_constructor
 
+set_inheritance = [
+        "Which link in the metamodel is the inheritance link?",
+        "Set inheritance link!",
+    ]
+
 do_instantiate_simple = [
             '"new"', '"PetriNets"', '"abc"',
             '"instantiate"', '"Transition"', '"t1"',
@@ -408,10 +413,6 @@ include "primitives.alh"
 include "object_operations.alh"
 
 Element function constraint(model : Element, name : String):
-\treturn "OK"
-            """
-
-        """
 \tElement associations
 \tElement back_associations
 \tElement association
@@ -419,30 +420,31 @@ Element function constraint(model : Element, name : String):
 \tassociations = allOutgoingAssociationInstances(model, name, "tile_left")
 \twhile (0 < list_len(associations)):
 \t\tassociation = set_pop(associations)
-\t\tdestination = reverseKeyLookup(model["model"], read_edge_dst(association))
+\t\tdestination = reverseKeyLookup(model["model"], read_edge_dst(model["model"][association]))
 \t\tback_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
 \t\tif (list_len(back_associations) < 1):
-\t\t\treturn "Left link does not have a right link back"
+\t\t\treturn "Left link does not have a right link back at "
 \t\telse:
-\t\t\tassociation = list_read(back_associations, 0)
-\t\t\tdestination = reverseKeyLookup(model["model"], read_edge_dst(association))
+\t\t\tassociation = set_pop(back_associations)
+\t\t\tdestination = reverseKeyLookup(model["model"], read_edge_dst(model["model"][association]))
 \t\t\tif (destination != name):
-\t\t\t\treturn "Left link does not have a right link back to the same node"
-        """
+\t\t\t\treturn "Left link does not have a right link back to the same node at "
+\tlog("All OK for " + name)
+\treturn "OK"
+            """
 
         constructors = get_constructor(constraint_code)
         print(constructors)
 
         self.assertTrue(run_file(all_files,
             ['"new"', '"SimpleClassDiagrams"', '"RPGame"',
+                '"set_inheritance"', '"Inheritance"',
                 '"instantiate"', '"Class"', '"Scene"',
                 '"instantiate"', '"Class"', '"Tile"',
                 '"instantiate"', '"Class"', '"Item"',
                 '"instantiate"', '"Class"', '"Goal"',
                 '"instantiate"', '"Class"', '"Character"',
                 '"instantiate"', '"Class"', '"Hero"',
-                '"instantiate"', '"Class"', '"String"',
-                '"instantiate"', '"Association"', '"scene_name"', '"Scene"', '"String"',
                 '"instantiate"', '"Association"', '"scene_has_tiles"', '"Scene"', '"Tile"',
                 '"instantiate"', '"Association"', '"tile_left"', '"Tile"', '"Tile"',
                 '"instantiate"', '"Association"', '"tile_right"', '"Tile"', '"Tile"',
@@ -458,8 +460,6 @@ Element function constraint(model : Element, name : String):
                 '"attr_add"', '"scene_has_tiles"', '"source_lower_cardinality"', '1',
                 '"attr_add"', '"scene_has_tiles"', '"source_upper_cardinality"', '1',
                 '"attr_add"', '"scene_has_tiles"', '"target_lower_cardinality"', '1',
-                '"attr_add"', '"scene_name"', '"target_lower_cardinality"', '1',
-                '"attr_add"', '"scene_name"', '"target_upper_cardinality"', '1',
                 '"attr_add"', '"item_on"', '"target_lower_cardinality"', '1',
                 '"attr_add"', '"item_on"', '"target_upper_cardinality"', '1',
                 '"attr_add"', '"item_on"', '"source_upper_cardinality"', '1',
@@ -475,8 +475,43 @@ Element function constraint(model : Element, name : String):
                 '"attr_add"', '"tile_bottom"', '"source_upper_cardinality"', '1',
                 '"attr_add"', '"tile_bottom"', '"target_upper_cardinality"', '1',
                 '"constrain"', '"Tile"',
-            ] + constructors + [
+            ] + constructors + ['"verify"'] + ['"exit"'] + [
+                '"new"', '"RPGame"', '"my_game"',
+                '"instantiate"', '"Scene"', '"scene"',
+                '"instantiate"', '"Hero"', '"Link"',
+                '"instantiate"', '"Goal"', '"goal"',
+                '"instantiate"', '"Tile"', '"tile_00"',
+                '"instantiate"', '"Tile"', '"tile_01"',
+                '"instantiate"', '"Tile"', '"tile_10"',
+                '"instantiate"', '"Tile"', '"tile_11"',
+                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_00"',
+                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_01"',
+                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_10"',
+                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_11"',
+                '"instantiate"', '"character_on"', '""',  '"Link"', '"tile_00"',
+                '"instantiate"', '"item_on"', '""', '"goal"', '"tile_11"',
+                '"instantiate"', '"tile_left"', '""', '"tile_01"', '"tile_00"',
+                '"instantiate"', '"tile_left"', '""', '"tile_11"', '"tile_10"',
+                '"instantiate"', '"tile_right"', '""', '"tile_00"', '"tile_01"',
+                '"instantiate"', '"tile_right"', '""', '"tile_10"', '"tile_11"',
+                '"instantiate"', '"tile_top"', '""', '"tile_10"', '"tile_00"',
+                '"instantiate"', '"tile_top"', '""', '"tile_11"', '"tile_01"',
+                '"instantiate"', '"tile_bottom"', '""', '"tile_00"', '"tile_10"',
+                '"instantiate"', '"tile_bottom"', '""', '"tile_01"', '"tile_11"',
                 '"verify"',
             ],
-            init + new + loaded + (instantiate_node + prompt) * 7 + (instantiate_edge + prompt) * 10 + (attr_add + prompt) * 22 + ["Element to constrain (empty for global)?", "Give input to function constructors for LOCAL constraint!", "Added constraint to model!"] + prompt + ["OK"] + prompt,
+            init + new + loaded + \
+                set_inheritance + prompt + \
+                (instantiate_node + prompt) * 6 + \
+                (instantiate_edge + prompt) * 9 + \
+                (attr_add + prompt) * 20 + \
+                ["Element to constrain (empty for global)?",
+                 "Give input to function constructors for LOCAL constraint!",
+                 "Added constraint to model!"] + \
+                prompt + \
+                ["OK"] + \
+                prompt + prompt + new + loaded + \
+                (instantiate_node + prompt) * 7 + \
+                (instantiate_edge + prompt) * 14 + \
+                ["OK"],
             mode))