浏览代码

Finally make transformations on textual model work!

Yentl Van Tendeloo 8 年之前
父节点
当前提交
f7659b824a

二进制
bootstrap/bootstrap.m.gz


+ 14 - 4
bootstrap/modelling.alc

@@ -161,13 +161,23 @@ Element function get_superclasses(model : Element, name : String):
 
 String function find_attribute_definer(model : Element, elem_name : String, name : String):
 	Element superclasses
-	Element current
+	String current
+	Integer nr_out
+	Element out
+	String name_attr
 
 	superclasses = get_superclasses(model, elem_name)
 	while (list_len(superclasses) > 0):
 		current = set_pop(superclasses)
-		if (dict_in(model["model"][current], name)):
-			return current!
+		
+		nr_out = read_nr_out(model["model"][current])
+		while (nr_out > 0):
+			nr_out = nr_out - 1
+			out = read_out(model["model"][current], nr_out)
+			name_attr = read_attribute(model, reverseKeyLookup(model["model"], out), "name")
+			if (name_attr == name):
+				return current!
+
 	return ""!
 
 Void function instantiate_attribute(model : Element, element : String, attribute_name : String, value : Element):
@@ -475,7 +485,7 @@ Void function construct_model():
 		elif (command == "instantiate_attribute_ref"):
 			instantiate_attribute_ref(global_models[input()], input(), input(), input())
 		elif (command == "instantiate_attribute_code"):
-			instantiate_attribute_code(global_models[input()], input(), input(), input())
+			instantiate_attribute_code(global_models[input()], input(), input(), construct_function())
 		elif (command == "instantiate_link"):
 			instantiate_link(global_models[input()], input(), input(), input(), input())
 		elif (command == "define_inheritance"):

+ 0 - 6
bootstrap/object_operations.alc

@@ -216,9 +216,7 @@ Element function allowedAssociationsBetween(model : Element, src : String, dst :
 
 	result = create_node()
 	type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][src]))
-	log("Computing all types")
 	all_types = get_superclasses(model["metamodel"], type)
-	log("Got types: " + set_to_string(all_types))
 
 	while (read_nr_out(all_types) > 0):
 		type = set_pop(all_types)
@@ -231,13 +229,9 @@ Element function allowedAssociationsBetween(model : Element, src : String, dst :
 				// Find destination
 				dst_name = reverseKeyLookup(model["metamodel"]["model"], read_edge_dst(edge))
 				edge_name = reverseKeyLookup(model["metamodel"]["model"], edge)
-				log("Got destination: " + log(dst_name))
-				log("  with name: " + edge_name)
-				log("Is instance: " + dst)
 
 				if (is_nominal_instance(model, dst, dst_name)):
 					// Find out whether our dst is an instance of the found destination type
-					log("Adding edge: " + edge_name)
 					set_add(result, edge_name)
 
 			i = i + 1

+ 39 - 24
integration/test_pn_interface.py

@@ -906,9 +906,22 @@ Void function action(host_model : Element, name : String, mapping : Element):
                     tokens = 2
                     executed = False
                 }
+                Place p3 {
+                    tokens = 3
+                    executed = False
+                }
                 Transition t1 {
                     executing = False
                 }
+                P2T (p1, t1) {
+                    weight = 1
+                }
+                P2T (p2, t1) {
+                    weight = 1
+                }
+                T2P (t1, p3) {
+                    weight = 2
+                }
             }
 
             export pn to models/pn
@@ -960,7 +973,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                     }
                     {Contains} Atomic consume {
                         LHS {
-                            Pre_Transition {
+                            Pre_Transition lhs_consume_t{
                                 label = "0"
                                 constraint = $
                                     include "primitives.alh"
@@ -970,7 +983,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                         return value_eq(read_attribute(host_model, name, "executing"), True)!
                                     $
                             }
-                            Pre_Place {
+                            Pre_Place lhs_consume_p{
                                 label = "1"
                                 constraint = $
                                     include "primitives.alh"
@@ -980,15 +993,15 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                         return value_eq(read_attribute(host_model, name, "executed"), False)!
                                     $
                             }
-                            Pre_P2T {
+                            Pre_P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
                                 label = "2"
                             }
                         }
                         RHS {
-                            Post_Transition {
+                            Post_Transition rhs_consume_t {
                                 label = "0"
                             }
-                            Post_Place {
+                            Post_Place rhs_consume_p {
                                 label = "1"
                                 action = $
                                     include "primitives.alh"
@@ -1005,14 +1018,14 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                         return!
                                     $
                             }
-                            Post_P2T {
+                            Post_P2T (rhs_consume_p, rhs_consume_t){
                                 label = "2"
                             }
                         }
                     }
                     {Contains} Atomic produce {
                         LHS {
-                            Pre_Transition {
+                            Pre_Transition lhs_produce_t{
                                 label = "0"
                                 constraint = $
                                     include "primitives.alh"
@@ -1022,7 +1035,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                         return value_eq(read_attribute(host_model, name, "executing"), True)!
                                     $
                             }
-                            Pre_Place {
+                            Pre_Place lhs_produce_p{
                                 label = "1"
                                 constraint = $
                                     include "primitives.alh"
@@ -1032,15 +1045,15 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                         return value_eq(read_attribute(host_model, name, "executed"), False)!
                                     $
                             }
-                            Pre_T2P {
+                            Pre_T2P (lhs_produce_t, lhs_produce_p){
                                 label = "2"
                             }
                         }
                         RHS {
-                            Post_Transition {
+                            Post_Transition rhs_produce_t{
                                 label = "0"
                             }
-                            Post_Place {
+                            Post_Place rhs_produce_p{
                                 label = "1"
                                 action = $
                                     include "primitives.alh"
@@ -1057,7 +1070,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                         return!
                                     $
                             }
-                            Post_T2P {
+                            Post_T2P (rhs_produce_t, rhs_produce_p){
                                 label = "2"
                             }
                         }
@@ -1082,7 +1095,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                                     include "primitives.alh"
                                     include "modelling.alh"
                                     Void function action(host_model : Element, name : String, mapping : Element):
-                                        unset_attribute(host_model, name, "executingd")
+                                        unset_attribute(host_model, name, "executing")
                                         instantiate_attribute(host_model, name, "executing", False)
                                         return!
                                     $
@@ -1116,18 +1129,19 @@ Void function action(host_model : Element, name : String, mapping : Element):
                             }
                         }
                     }
-                    {Contains} OnSuccess (mark, consume) {}
-                    {Contains} OnFailure (mark, failure) {}
-                    {Contains} OnSuccess (consume, consume) {}
-                    {Contains} OnFailure (consume, produce) {}
-                    {Contains} OnSuccess (produce, produce) {}
-                    {Contains} OnFailure (produce, unmark_transition) {}
-                    {Contains} OnSuccess (unmark_transition, unmark_place) {}
-                    {Contains} OnFailure (unmark_transition, failure) {}
-                    {Contains} OnSuccess (unmark_place, unmark_place) {}
-                    {Contains} OnFailure (unmark_place, success) {}
-                    initial = !mark
+
                 }
+                OnSuccess (mark, consume) {}
+                OnFailure (mark, failure) {}
+                OnSuccess (consume, consume) {}
+                OnFailure (consume, produce) {}
+                OnSuccess (produce, produce) {}
+                OnFailure (produce, unmark_transition) {}
+                OnSuccess (unmark_transition, unmark_place) {}
+                OnFailure (unmark_transition, failure) {}
+                OnSuccess (unmark_place, unmark_place) {}
+                OnFailure (unmark_place, success) {}
+                Initial (schedule, mark) {}
             }
 
             export s to models/pn_simulate
@@ -1145,6 +1159,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                     "read", "t1",
                     "read", "p1",
                     "read", "p2",
+                    "read", "p3",
                     "exit",
             ],
           None, "PO"))

+ 1 - 2
interface/HUTN/grammars/modelling.g

@@ -17,8 +17,7 @@ grammar{
                     | (NEWLINE? DOLLAR ANYTHING_EXCEPT_DOLLAR DOLLAR NEWLINE?);
 
     model_attr_instance: (MODEL_ID ASSIGN value NEWLINE?)
-                       | (MODEL_ID ASSIGN NEWLINE? DOLLAR ANYTHING_EXCEPT_DOLLAR DOLLAR NEWLINE?)
-                       | (MODEL_ID ASSIGN EXCLAMATION MODEL_ID NEWLINE?);
+                       | (MODEL_ID ASSIGN NEWLINE? DOLLAR ANYTHING_EXCEPT_DOLLAR DOLLAR NEWLINE?);
 
     value
         : DEC_NUMBER

+ 0 - 7
interface/HUTN/hutn_compiler/model_visitor.py

@@ -46,12 +46,8 @@ class ModelVisitor(Visitor):
         model_type = children[0].get_text()
         model_name = children[-1].get_text()
         self.constructors.extend(["instantiate_model", model_type, model_name])
-        print("CHECK for inheritance")
         if tree.get_children("LPAR"):
-            print("ADD")
             self.constructors.extend(["define_inheritance", model_name, tree.get_children("MODEL_ID")[1].get_text()])
-        else:
-            print("NO!")
         self.current_model = model_name
         for element in tree.get_children("model_element"):
             self.visit(element)
@@ -176,6 +172,3 @@ class ModelVisitor(Visitor):
             # Coded attribute
             self.constructors.extend(["instantiate_attribute_code", self.current_model, self.current_element[-1], attr_name])
             self.constructors.extend(constructors_compile(tree.get_children("ANYTHING_EXCEPT_DOLLAR")[0].get_text()))
-        else:
-            # Assign direct reference
-            self.constructors.extend(["instantiate_attribute_ref", self.current_model, self.current_element[-1], attr_name, tree.get_children("MODEL_ID")[1].get_text()])