Przeglądaj źródła

Added instantiation of own metamodel as well

Yentl Van Tendeloo 9 lat temu
rodzic
commit
a8114d3929
2 zmienionych plików z 35 dodań i 8 usunięć
  1. 8 5
      bootstrap/modelling.alc
  2. 27 3
      integration/test_constructors_models.py

+ 8 - 5
bootstrap/modelling.alc

@@ -143,12 +143,15 @@ Element function find_attribute_definer(model : Element, elem : Element, name :
 		// Return the de facto error-value
 		return read_root()
 
-Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : String):
+Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : Element):
 	// Instantiate an attribute of something that needs to be instantiated
 	// Actually a bit more difficult than all the rest, as we need to find the attribute to instantiate
-	Element attr_type
+	String attr_type
+	String attr_name
 
 	attr_type = find_attribute_type(model, element, attribute_name)
+	attr_name = model_add_value(model, "", value)
+	retype(attr_name, getName(model["metamodel"], read_edge_dst(model["metamodel"]["model"][attr_type])))
 	instantiate_link(model, attr_type, "", element, value)
 
 	return
@@ -168,9 +171,9 @@ Void function instantiate_named(model : Element, type : String, name : String, s
 	String name_name
 
 	link_name = instantiate_link(model, type, "", source, destination)
-	name_name = model_add_value(model, "", name)
-	retype(model, name_name, "String")
-	instantiate_attribute(model, link_name, "name", name_name)
+	//name_name = model_add_value(model, "", name)
+	//retype(model, name_name, "String")
+	instantiate_attribute(model, link_name, "name", name)
 
 	return
 

+ 27 - 3
integration/test_constructors_models.py

@@ -58,7 +58,7 @@ retype = [
         '"exit"',
     ]
 
-instantiate_pn = [
+instantiate_scd = [
         '"model"',
         '"instantiate_model"', 1, 2,
         '"define_inheritance"', 2, '"l3"',
@@ -73,6 +73,26 @@ instantiate_pn = [
         '"exit"',
     ]
 
+instantiate_pn = [
+        '"model"',
+        '"instantiate_model"', 2, 3,
+        '"instantiate_node"', 3, '"Place"', '"p1"',
+        '"instantiate_node"', 3, '"Place"', '"p2"',
+        '"instantiate_node"', 3, '"Transition"', '"t1"',
+        '"instantiate_node"', 3, '"Transition"', '"t2"',
+        '"instantiate_link"', 3, '"P2T"', '"p1_t1"', '"p1"', '"t1"',
+        '"instantiate_link"', 3, '"T2P"', '"t1_p2"', '"t1"', '"p2"',
+        '"instantiate_link"', 3, '"P2T"', '"p2_t2"', '"p2"', '"t2"',
+        '"instantiate_link"', 3, '"T2P"', '"t2_p1"', '"t2"', '"p1"',
+        '"instantiate_attribute"', 3, '"p1_t1"', '"weight"', '1',
+        '"instantiate_attribute"', 3, '"t1_p2"', '"weight"', '2',
+        '"instantiate_attribute"', 3, '"p2_t2"', '"weight"', '3',
+        '"instantiate_attribute"', 3, '"t2_p1"', '"weight"', '4',
+        '"instantiate_attribute"', 3, '"p1"', '"tokens"', '5',
+        '"instantiate_attribute"', 3, '"p2"', '"tokens"', '6',
+        '"exit"',
+    ]
+
 def conformance_check(node):
     return [
             '"output"',
@@ -91,8 +111,12 @@ class TestConstructorsModels(unittest.TestCase):
         commands = bottom + retype + conformance_check(1)
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
-    def test_constructors_instantiate_petrinet(self):
-        commands = bottom + retype + instantiate_pn + conformance_check(2)
+    def test_constructors_instantiate_scd(self):
+        commands = bottom + retype + instantiate_scd + conformance_check(2)
+        self.assertTrue(run_barebone(commands, ["OK"], 1))
+
+    def test_constructors_instantiate_pn(self):
+        commands = bottom + retype + instantiate_scd + instantiate_pn + conformance_check(3)
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
     """