Browse Source

Fixed problematic attribute deletion

Yentl Van Tendeloo 9 years ago
parent
commit
b352c26cb7

+ 5 - 1
bootstrap/modelling.alc

@@ -195,6 +195,8 @@ Void function define_inheritance(model : Element, inheritance_name : String):
 Void function model_delete_element(model : Element, name : String):
 	// Remove the link
 	// 1) from the type mapping
+	log("Delete element with name " + name)
+	log("  ==> " + cast_e2s(model["model"][name]))
 	dict_delete(model["type_mapping"], model["model"][name])
 
 	// 2) from the model
@@ -234,7 +236,9 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
 
 	while (list_len(attr_links) > 0):
 		attr_link = set_pop(attr_links)
-		model_delete_element(model, attr_link)
+		dict_delete(model["type_mapping"], read_edge_dst(model["model"][attr_link]))
+		dict_delete(model["type_mapping"], model["model"][attr_link])
+		delete_element(read_edge_dst(model["model"][attr_link]))
 
 	return
 

+ 1 - 1
integration/code/pn_interface.alc

@@ -226,12 +226,12 @@ Element function model_loaded(model : Element):
 			if (dict_in(model["model"], model_name)):
 				Element attrs
 				attrs = getAttributeList(model, model_name)
-				output(print_dict(attrs))
 				String attr_name
 				output("Which attribute do you want to delete?")
 				attr_name = input()
 				if (set_in(dict_keys(attrs), attr_name)):
 					unset_attribute(model, model_name, attr_name)
+					output("Attribute deleted!")
 				else:
 					output("No such attribute!")
 			else:

+ 25 - 0
integration/test_pn_interface.py

@@ -89,6 +89,10 @@ attr_add =          ["Which model do you want to assign an attribute to?",
                      "Which attribute do you wish to assign?",
                      "Value of attribute?",
                      "Added attribute!"]
+attr_del =          ["Which model do you want to remove an attribute of?",
+                     "Which attribute do you want to delete?",
+                     "Attribute deleted!",
+                    ]
 
 help_root =         ["Currently no model is loaded, so your operations are limited to:",
                      "  new    -- Create a new model and save it for future use"
@@ -356,3 +360,24 @@ class TestPetrinetInterface(unittest.TestCase):
             did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge at p1"] + prompt,
             mode))
 
+    def test_po_pn_interface_verify_natural(self):
+        self.pn_interface_verify_natural("PO")
+
+    def test_co_pn_interface_verify_natural(self):
+        self.pn_interface_verify_natural("CO")
+
+    def pn_interface_verify_natural(self, mode):
+        self.assertTrue(run_file(all_files,
+            ["new", "PetriNets", "abc",
+            "instantiate", "Place", "p1",
+            "attr_add", "p1", "tokens", -5,
+            "attr_del", "p1", "tokens",
+            "attr_add", "p1", "tokens", 4,
+            "verify"],
+            init + new + loaded + \
+            instantiate_node + prompt + \
+            attr_add + prompt + \
+            attr_del + prompt + \
+            attr_add + prompt + \
+            ["OK"] + prompt,
+            mode))

+ 3 - 0
kernel/modelverse_kernel/primitives.py

@@ -264,6 +264,7 @@ def dict_delete(a, b, **remainder):
         b_value = yield [("RV", [b])]
         edge = yield [("RDE", [a, b_value])]
     yield [("DE", [edge])]
+    print("DELETE " + str(edge))
     raise PrimitiveFinished(a)
 
 def dict_read(a, b, **remainder):
@@ -385,10 +386,12 @@ def delete_element(a, **remainder):
     if edge[0] is None:
         # Not an edge:
         yield [("DN", [a])]
+        print("DELETE ELEMENT NODE " + str(a))
         result = yield [("CNV", [False])]
         raise PrimitiveFinished(result)
     else:
         yield [("DE", [a])]
+        print("DELETE ELEMENT EDGE " + str(a))
         result = yield [("CNV", [True])]
         raise PrimitiveFinished(result)