Browse Source

Added simple ForAll scheduling block

Yentl Van Tendeloo 8 years ago
parent
commit
85c84389c5
2 changed files with 46 additions and 0 deletions
  1. 20 0
      bootstrap/ramify.alc
  2. 26 0
      bootstrap/transform.alc

+ 20 - 0
bootstrap/ramify.alc

@@ -260,6 +260,26 @@ Element function ramify(model : Element):
 	instantiate_attribute(new_model, "QueryLHS", "target_lower_cardinality", 1)
 	instantiate_attribute(new_model, "QueryLHS", "target_upper_cardinality", 1)
 
+	// 	Class ForAll : Rule {}
+	instantiate_node(new_model, "Class", "ForAll")
+	instantiate_link(new_model, "Inheritance", "", "Atomic", "ForAll")
+
+	//	Association ForAllLHS (ForAll, LHS) {
+	//		target_lower_cardinality = 1
+	//		target_upper_cardinality = 1
+	//	}
+	instantiate_link(new_model, "Association", "ForAllLHS", "ForAll", "LHS")
+	instantiate_attribute(new_model, "ForAllLHS", "target_lower_cardinality", 1)
+	instantiate_attribute(new_model, "ForAllLHS", "target_upper_cardinality", 1)
+
+	//	Association ForAllRHS (ForAll, RHS) {
+	//		target_lower_cardinality = 1
+	//		target_upper_cardinality = 1
+	//	}
+	instantiate_link(new_model, "Association", "ForAllRHS", "ForAll", "RHS")
+	instantiate_attribute(new_model, "ForAllRHS", "target_lower_cardinality", 1)
+	instantiate_attribute(new_model, "ForAllRHS", "target_upper_cardinality", 1)
+
 	//	Class Atomic : Rule {}
 	instantiate_node(new_model, "Class", "Atomic")
 	instantiate_link(new_model, "Inheritance", "", "Atomic", "Rule")

+ 26 - 0
bootstrap/transform.alc

@@ -341,6 +341,8 @@ Boolean function transform_composite(host_model : Element, schedule_model : Elem
 			result = transform_query(host_model, schedule_model, current)
 		elif (typename == "Composite"):
 			result = transform_composite(host_model, schedule_model, current)
+		elif (typename == "ForAll"):
+			result = transform_forall(host_model, schedule_model, current)
 
 		if (result):
 			current = set_pop(allAssociationDestinations(schedule_model, current, "OnSuccess"))
@@ -371,6 +373,30 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 	else:
 		return False!
 
+Boolean function transform_forall(host_model : Element, schedule_model : Element, current : String):
+	// Execute the atomic transformation
+	Element mappings
+	String LHS
+	String RHS
+	Element mapping
+	Boolean result
+
+	LHS = set_pop(allAssociationDestinations(schedule_model, current, "AtomicLHS"))
+	mappings = match(host_model, schedule_model, LHS)
+
+	if (read_nr_out(mappings) > 0):
+		result = True
+	else:
+		result = False
+
+	while (read_nr_out(mappings) > 0):
+		mapping = set_pop(mappings)
+		// TODO check if there are actually no deletions happening in the meantime of other matched elements...
+		RHS = set_pop(allAssociationDestinations(schedule_model, current, "AtomicRHS"))
+		rewrite(host_model, schedule_model, RHS, mapping)
+
+	return result!
+
 Boolean function transform_query(host_model : Element, schedule_model : Element, current : String):
 	// Execute the transformation
 	String LHS