Преглед на файлове

Fixed constructors_compiled as well

Yentl Van Tendeloo преди 8 години
родител
ревизия
779bf0b32e

+ 14 - 9
bootstrap/metamodels.alc

@@ -17,6 +17,8 @@ String function constraint_Natural(params : Element):
 
 Element function constraint_String(params : Element):
 	Element self
+	log("Invoked!")
+	log("params: " + dict_to_string(params))
 	self = params["model"]["model"][params["name"]]
 	if (is_physical_string(self)):
 		return "OK"!
@@ -76,7 +78,7 @@ Element function initialize_SCD(location : String):
 	model_add_edge(scd, "attr_name_name", "attr_name", "name_value")
 	model_add_edge(scd, "class_inh_element", "Class", "Element")
 	model_add_edge(scd, "attribute_inh_element", "Attribute", "Element")
-	model_add_edge(scd, "simple_inh_element", "SimpleAttribute", "Element")
+	model_add_edge(scd, "simple_inh_attribute", "SimpleAttribute", "Attribute")
 	model_add_edge(scd, "association_inh_element", "Association", "Element")
 	model_add_edge(scd, "attributelink_inh_element", "AttributeLink", "Element")
 
@@ -95,7 +97,7 @@ Element function initialize_SCD(location : String):
 	retype(scd, "attr_name_name", "attr_name")
 	retype(scd, "class_inh_element", "Inheritance")
 	retype(scd, "attribute_inh_element", "Inheritance")
-	retype(scd, "simple_inh_element", "Inheritance")
+	retype(scd, "simple_inh_attribute", "Inheritance")
 	retype(scd, "association_inh_element", "Inheritance")
 	retype(scd, "attributelink_inh_element", "Inheritance")
 
@@ -130,11 +132,11 @@ Element function initialize_SCD(location : String):
 	model_define_attribute(scd, "Element", "constraint", True, "ActionLanguage")
 
 	// Define some constraints
-	instantiate_attribute(scd, "Natural", "constraint", constraint_Natural)
-	instantiate_attribute(scd, "String", "constraint", constraint_String)
-	instantiate_attribute(scd, "Boolean", "constraint", constraint_Boolean)
-	instantiate_attribute(scd, "Location", "constraint", constraint_Location)
-	instantiate_attribute(scd, "ActionLanguage", "constraint", constraint_ActionLanguage)
+	instantiate_attribute_code(scd, "Natural", "constraint", constraint_Natural)
+	instantiate_attribute_code(scd, "String", "constraint", constraint_String)
+	instantiate_attribute_code(scd, "Boolean", "constraint", constraint_Boolean)
+	instantiate_attribute_code(scd, "Location", "constraint", constraint_Location)
+	instantiate_attribute_code(scd, "ActionLanguage", "constraint", constraint_ActionLanguage)
 
 	return scd!
 
@@ -147,7 +149,7 @@ Element function initialize_PN(location_SCD : String, location_PN : String):
 	pn = instantiate_model(scd)
 	instantiate_node(pn, "Class", "Place")
 	instantiate_node(pn, "Class", "Transition")
-	instantiate_node(pn, "AttributeValue", "Natural")
+	instantiate_node(pn, "SimpleAttribute", "Natural")
 	instantiate_link(pn, "Association", "P2T", "Place", "Transition")
 	instantiate_link(pn, "Association", "T2P", "Transition", "Place")
 	model_define_attribute(pn, "Place", "tokens", False, "Natural")
@@ -155,7 +157,7 @@ Element function initialize_PN(location_SCD : String, location_PN : String):
 	model_define_attribute(pn, "T2P", "weight", False, "Natural")
 
 	// Add constraint on the Natural
-	instantiate_attribute(pn, "Natural", "constraint", constraint_Natural)
+	instantiate_attribute_code(pn, "Natural", "constraint", constraint_Natural)
 
 	export_node(location_PN, pn)
 
@@ -201,6 +203,9 @@ Void function initialize_AL(scd_location : String, export_location : String):
 	Element model
 	Element scd_model
 
+	if (element_neq(import_node(export_location), read_root())):
+		return!
+
 	scd_model = import_node(scd_location)
 	model = instantiate_model(scd_model)
 

+ 8 - 3
bootstrap/modelling.alc

@@ -258,9 +258,14 @@ Void function add_code_model(model : Element, export_name : String, code : Eleme
 	return !
 
 Void function instantiate_attribute_code(model : Element, element : String, attribute_name : String, code : Element):
-	String ref
-	ref = add_AL(model, code)
-	instantiate_existing_attribute(model, element, attribute_name, ref)
+	// First create a new model for the AL part
+	String location
+	location = "code/" + cast_id2s(code)
+
+	add_code_model(import_node("models/ActionLanguage"), location, code)
+
+	// Now link it with a complex attribute
+	instantiate_attribute(model, element, attribute_name, location)
 
 	return!
 

+ 16 - 9
integration/code/my_petrinet_with_MM_and_constraints.mvc

@@ -2,15 +2,22 @@ import models/SimpleClassDiagrams as SCD
 include "primitives.alh"
 
 SCD PetriNets{
-    AttributeValue Natural {
-        $
-            if (bool_not(is_physical_int(self))):
-                return "Natural has no integer value"!
-            elif (integer_lt(self, 0)):
-                return "Natural does not have a positive or zero value"!
-            else:
-                return "OK"!
-         $
+    SimpleAttribute Natural {
+        constraint =
+            $
+            include "primitives.alh"
+
+            String function constraint_Natural(params : Element):
+                Element self
+                self = params["model"]["model"][params["name"]]
+                if (is_physical_int(self)):
+                    if (integer_gte(self, 0)):
+                        return "OK"!
+                    else:
+                        return "Natural number not larger than or equal to zero"!
+                else:
+                    return "Natural number not larger than or equal to zero"!
+            $
     }
     Class Place{
         tokens : Natural

+ 2 - 1
integration/code/petrinets.mvc

@@ -1,7 +1,8 @@
 import models/SimpleClassDiagrams as SimpleClassDiagrams
 
 SimpleClassDiagrams PetriNets{
-    AttributeValue Natural {}
+    SimpleAttribute Natural {}
+
     Class Place{
         tokens : Natural
     }

+ 20 - 9
integration/code/petrinets_constraints.mvc

@@ -2,23 +2,34 @@ import models/SimpleClassDiagrams as SCD
 include "primitives.alh"
 
 SCD PetriNets{
-    AttributeValue Natural {
-        $
-            if (bool_not(is_physical_int(self))):
-                return "Natural has no integer value"!
-            elif (integer_lt(self, 0)):
-                return "Natural does not have a positive or zero value"!
-            else:
-                return "OK"!
-         $
+    SimpleAttribute Natural {
+        constraint =
+            $
+            include "primitives.alh"
+
+            String function constraint_Natural(params : Element):
+                Element self
+                self = params["model"]["model"][params["name"]]
+                if (is_physical_int(self)):
+                    if (integer_gte(self, 0)):
+                        return "OK"!
+                    else:
+                        return "Natural number not larger than or equal to zero"!
+                else:
+                    return "Natural number not larger than or equal to zero"!
+            $
     }
+
     Class Place{
         tokens : Natural
     }
+
     Class Transition{}
+
     Association P2T (Place, Transition) {
         weight : Natural
     }
+
     Association T2P (Transition, Place) {
         weight : Natural
     }

+ 2 - 2
integration/code/pn_design.mvc

@@ -1,8 +1,8 @@
 import models/SimpleClassDiagrams as SimpleClassDiagrams
 
 SimpleClassDiagrams PetriNets_Design{
-    AttributeValue Natural {}
-    AttributeValue String {}
+    SimpleAttribute Natural {}
+    SimpleAttribute String {}
 
     Class Place {
         tokens : Natural

+ 0 - 27
integration/code/pn_print_MR.mvc

@@ -1,27 +0,0 @@
-RAM_PN_R print {
-    Composite schedule {
-        {Contains} Success success {}
-        {Contains} ForAll print_tokens {
-            LHS {
-                Pre_PetriNets_Place {
-                    label = "0"
-                }
-            }
-            RHS {
-                Post_PetriNets_Place {
-                    label = "0"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            output((cast_v2s(read_attribute(host_model, name, "name")) + " --> ") + cast_v2s(read_attribute(host_model, name, "tokens")))
-                            return!
-                        $
-                }
-            }
-        }
-    }
-    OnSuccess (print_tokens, success) {}
-    OnFailure (print_tokens, success) {}
-    Initial (schedule, print_tokens) {}
-}

+ 3 - 3
integration/code/pn_runtime.mvc

@@ -1,9 +1,9 @@
 import models/SimpleClassDiagrams as SimpleClassDiagrams
 
 SimpleClassDiagrams PetriNets_Runtime{
-    AttributeValue Natural {}
-    AttributeValue Boolean {}
-    AttributeValue String {}
+    SimpleAttribute Natural {}
+    SimpleAttribute Boolean {}
+    SimpleAttribute String {}
 
     Class Place {
         tokens : Natural

+ 0 - 19
integration/code/pn_runtime_MR.mvc

@@ -1,19 +0,0 @@
-SimpleClassDiagrams PetriNets_Runtime{
-    AttributeValue Natural {}
-    AttributeValue Boolean {}
-    AttributeValue String {}
-
-    Class Place {
-        tokens : Natural
-        name : String
-    }
-    Class Transition {
-        executing : Boolean
-    }
-    Association P2T (Place, Transition) {
-        weight : Natural
-    }
-    Association T2P (Transition, Place) {
-        weight : Natural
-    }
-}

+ 0 - 26
integration/code/pn_runtime_model_MR.mvc

@@ -1,26 +0,0 @@
-PetriNets_Runtime pn {
-	Place p1 {
-		tokens = 1
-        name = "p1"
-	}
-	Place p2 {
-		tokens = 2
-        name = "p2"
-	}
-	Place p3 {
-		tokens = 3
-        name = "p3"
-	}
-	Transition t1 {
-		executing = False
-	}
-	P2T (p1, t1) {
-		weight = 1
-	}
-	P2T (p2, t1) {
-		weight = 1
-	}
-	T2P (t1, p3) {
-		weight = 2
-	}
-}

+ 17 - 9
integration/code/several_petrinets.mvc

@@ -2,16 +2,24 @@ import models/SimpleClassDiagrams as SCD
 include "primitives.alh"
 
 SCD PetriNets{
-    AttributeValue Natural {
-        $
-            if (bool_not(is_physical_int(self))):
-                return "Natural has no integer value at " + name!
-            elif (integer_lt(self, 0)):
-                return "Natural does not have a positive or zero value at " + name!
-            else:
-                return "OK"!
-         $
+    SimpleAttribute Natural {
+        constraint =
+            $
+            include "primitives.alh"
+
+            String function constraint_Natural(params : Element):
+                Element self
+                self = params["model"]["model"][params["name"]]
+                if (is_physical_int(self)):
+                    if (integer_gte(self, 0)):
+                        return "OK"!
+                    else:
+                        return string_join("Natural does not have a positive or zero value at ", params["name"])!
+                else:
+                    return string_join("Natural has no integer value at ", params["name"])!
+            $
     }
+
     Class Place{
         tokens : Natural
     }

+ 3 - 3
integration/code/simpleclassdiagrams.mvc

@@ -1,9 +1,9 @@
 import /formalisms/SimpleClassDiagrams as SCD
 
 SCD SimpleClassDiagrams{
-    AttributeValue Natural {}
-    AttributeValue String {}
-    AttributeValue Boolean {}
+    SimpleAttribute Natural {}
+    SimpleAttribute String {}
+    SimpleAttribute Boolean {}
 
     Class Element {}
     Class Class{