Browse Source

Added code for creation and deletion of classes

Yentl Van Tendeloo 8 years ago
parent
commit
902d79108a
3 changed files with 60 additions and 3 deletions
  1. 25 2
      integration/code/minimal_SCCD.mvc
  2. 1 0
      models/SCCD.mvc
  3. 34 1
      models/SCCD_execute.alc

+ 25 - 2
integration/code/minimal_SCCD.mvc

@@ -8,6 +8,12 @@ Diagram my_SCCD {
 Class main {
     name = "Main"
     default = True
+    constructor_body = $
+            Void function const(attributes : Element, parameters : Element):
+                dict_overwrite(attributes, "a", 0)
+                dict_overwrite(attributes, "id", 0)
+                return !
+        $
 }
 
 Attribute attr_a {
@@ -15,7 +21,7 @@ Attribute attr_a {
 }
 
 Attribute attr_b {
-    name = "b"
+    name = "id"
 }
 
 class_attributes (main, attr_a) {}
@@ -130,11 +136,28 @@ transition (x_b, x_c) {
         $
 }
 
-transition (y_a, y_b) {
+transition transition_y (y_a, y_b) {
     name = "Y"
     event = "Y"
 }
 
+Raise create_new_class {
+    scope = "cd"
+    event = "create_instance"
+    parameter = $
+            Element function func(attributes : Element, parameters : Element):
+                Element result
+                log("Executing create_instance!")
+                result = create_node()
+                list_append(result, "Main")
+                list_append(result, attributes["id"])
+                list_append(result, read_root())
+                dict_overwrite(attributes, "id", integer_addition(attributes["id"], 1))
+        $
+}
+
+transition_raises (transition_y, create_new_class) {}
+
 transition (init, main_parallel) {
     name = "init"
     event = "init"

+ 1 - 0
models/SCCD.mvc

@@ -22,6 +22,7 @@ Class Class{
     default : Boolean
     external : Boolean
 }
+
 Association diagram_classes(Diagram, Class){
     target_lower_cardinality = 1
 }

+ 34 - 1
models/SCCD_execute.alc

@@ -111,6 +111,10 @@ Element function expand_parallel_state(model : Element, parallel_state : String)
 
 	return result!
 
+Void function delete_class(model : Element, data : Element, identifier : String):
+	// Stop a specific class instance, with attached statechart, from executing
+	dict_delete(data["classes"], identifier)
+
 Void function start_class(model : Element, data : Element, class : String, identifier : String, parameters : Element):
 	// Start up the class and assign its initial state to it
 
@@ -277,7 +281,36 @@ Element function execute_transition(model : Element, data : Element, class : Str
 			parameter_action = get_func_AL_model(import_node(parameter_action))
 			parameter_action = parameter_action(data["classes"][class]["attributes"], event_parameter)
 
-		set_add(data["events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
+		String scope
+		scope = read_attribute(model, event, "scope")
+		if (scope == "cd"):
+			// Is an event for us internally, so don't append
+			// Instead, we process it directly
+			String operation
+			operation = read_attribute(model, event, "event")
+			if (operation == "create_instance"):
+				log("Creating new instance")
+				// Start up a new class of the desired type
+
+				// Parameters of this call:
+				// class -- type of the class to instantiate
+				// identifier -- name of this instance, for future reference
+				// parameters -- parameters for constructor
+				String class
+				String identifier
+				Element parameters
+				class = set_pop(filter(model, allInstances(model, "SCCD/Class"), "name", list_read(parameter_action, 0)))
+				identifier = list_read(parameter_action, 1)
+				parameters = list_read(parameter_action, 2)
+				start_class(model, data, class, identifier, parameters)
+
+			elif (operation == "delete_instance"):
+				// Delete the requested class
+				String identifier
+				identifier = list_read(parameter_action, 0)
+				delete_class(model, data, identifier)
+		else:
+			set_add(data["events"], create_tuple(read_attribute(model, event, "event"), parameter_action))
 
 	// Find new set of states
 	Element target_states