Browse Source

Allow nicer split for in-place and out-place transformations

Yentl Van Tendeloo 8 years ago
parent
commit
a5c8c160e7

BIN
bootstrap/bootstrap.m.gz


+ 1 - 1
bootstrap/conformance_scd.alc

@@ -112,7 +112,7 @@ String function conformance_scd(model : Element):
 			model_name = set_pop(keys)
 			element = model["model"][model_name]
 			type_name = reverseKeyLookup(metamodel["model"], dict_read_node(typing, element))
-			log((("Check " + model_name) + " : ") + type_name)
+			//log((("Check " + model_name) + " : ") + type_name)
 
 			if (bool_not(dict_in_node(typing, element))):
 				return "Model has no type specified: " + model_info(model, model_name)!

+ 28 - 18
bootstrap/ramify.alc

@@ -3,36 +3,46 @@ include "object_operations.alh"
 include "modelling.alh"
 include "metamodels.alh"
 
-Element function create_transformation_language(root : Element, source : String, target : String):
+Element function create_outplace_transformation_language(source : Element, target : Element):
+	log("Create outplace model!")
 	Element ramified
 	Element fused
 	Element tagged_model
 	Element model_list
 
-	if (source == target):
-		// in-place transformation, so no need to alter meta-model any further
-		ramified = ramify(root[source])
-	else:
-		// out-place transformation, so modify meta-model a bit and add further information
-		model_list = create_node()
-		tagged_model = create_node()
-		list_append(tagged_model, source)
-		list_append(tagged_model, root[source])
-		list_append(model_list, tagged_model)
-		tagged_model = create_node()
-		list_append(tagged_model, target)
-		list_append(tagged_model, root[target])
-		list_append(model_list, tagged_model)
-
-		fused = model_fuse(model_list)
-		ramified = ramify(fused)
+	// out-place transformation, so modify meta-model a bit and add further information
+	model_list = create_node()
+	tagged_model = create_node()
+	list_append(tagged_model, "SOURCE")
+	list_append(tagged_model, source)
+	list_append(model_list, tagged_model)
+	tagged_model = create_node()
+	list_append(tagged_model, "TARGET")
+	list_append(tagged_model, target)
+	list_append(model_list, tagged_model)
+
+	fused = model_fuse(model_list)
+	ramified = ramify(fused)
 
 	// Augment with information about the source and target
+	dict_add(ramified, "inplace", False)
 	dict_add(ramified, "source", source)
 	dict_add(ramified, "target", target)
 
 	return ramified!
 
+Element function create_inplace_transformation_language(model : Element):
+	log("Create inplace model!")
+	Element ramified
+
+	ramified = ramify(model)
+
+	dict_add(ramified, "inplace", True)
+	dict_add(ramified, "source", model)
+	dict_add(ramified, "target", model)
+
+	return ramified!
+
 Element function ramify(model : Element):
 	// Create new model structure
 	Element new_model

+ 30 - 2
bootstrap/transform.alc

@@ -270,12 +270,23 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 
 	return!
 
-Boolean function transform(host_model : Element, schedule_model : Element):
+Element function transform(host_model : Element, schedule_model : Element):
 	// Find initial model
 	Element all_composites
 	String composite
 	String current
 
+	if (bool_not(schedule_model["metamodel"]["inplace"])):
+		// Do some preliminary changes if it is deemed out-place!
+		// Need to make sure that:
+		//		1) a fused language is created of source and target
+		// 		2) the host_model conforms to the fused language
+		// TODO
+		log("Out place transformation!")
+		log("Schedule model has: " + cast_v2s(schedule_model["inplace"]))
+		return read_root()!
+
+	// Now start transforming for real
 	all_composites = allInstances(schedule_model, "Composite")
 	if (read_nr_out(all_composites) == 1):
 		// Only one, so it is easy
@@ -288,7 +299,24 @@ Boolean function transform(host_model : Element, schedule_model : Element):
 				// Isn't contained in any, so this is the root model!
 				current = composite
 
-	return transform_composite(host_model, schedule_model, current)!
+	if (transform_composite(host_model, schedule_model, current)):
+		// Success, so return True if it is in-place, or the new model if it is out-place
+		if (schedule_model["inplace"]):
+			log("Transform success!")
+			return True!
+		else:
+			// Prepare the model before sending it back
+			// 	1) Strip the host model of all "SOURCE" elements
+			// 	2) Retype the model to the "TARGET" elements
+			// TODO
+			return read_root()!
+	else:
+		// Failure, so return False if it is in-place, or the root node if it is out-place
+		if (schedule_model["inplace"]):
+			log("Transform failed!")
+			return False!
+		else:
+			return read_root()!
 
 Boolean function transform_composite(host_model : Element, schedule_model : Element, composite : String):
 	String current

+ 29 - 13
integration/code/pn_interface.alc

@@ -387,25 +387,40 @@ Element function main():
 		elif (command == "ramify"):
 			Element result
 			String old_name
-			output("Name of the new RAMified metamodel")
+			output("Name of the RAMified metamodel to create")
 			name = input()
 			if (dict_in(root, name)):
 				output("Already exists; aborting")
 			else:
-				output("Source language?")
-				String source
-				String target
-				source = input()
-				if (dict_in(root, source)):
-					output("Target language?")
-					target = input()
-					if (dict_in(root, target)):
-						result = create_transformation_language(root, source, target)
+				String type
+				output("In-place (in) or Out-place (out)?")
+				type = input()
+				if (type == "in"):
+					output("Source language?")
+					String source
+					source = input()
+					if (dict_in(root, source)):
+						result = create_inplace_transformation_language(root[source])
 						dict_add(root, name, result)
 					else:
-						output("Unknown target language; aborting")
+						output("Unknown source language; aborting")
+				elif (type == "out"):
+					output("Source language?")
+					String source
+					String target
+					source = input()
+					if (dict_in(root, source)):
+						output("Target language?")
+						target = input()
+						if (dict_in(root, target)):
+							result = create_outplace_transformation_language(root[source], root[target])
+							dict_add(root, name, result)
+						else:
+							output("Unknown target language; aborting")
+					else:
+						output("Unknown source language; aborting")
 				else:
-					output("Unknown source language; aborting")
+					output("Unknown type of model transformation!")
 		elif (command == "transform"):
 			Element result
 			String schedule
@@ -415,7 +430,8 @@ Element function main():
 				output("Which schedule do you want to execute?")
 				schedule = input()
 				if (dict_in(root, schedule)):
-					output("Transformation result: " + cast_v2s(transform(root[name], root[schedule])))
+					result = transform(root[name], root[schedule])
+					output("Transformation result: " + cast_e2s(result))
 				else:
 					output("Unknown transformation selected!")
 			else:

+ 2 - 2
integration/test_pn_interface.py

@@ -705,7 +705,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
                 "instantiate", "P2T", "p2t2", "p2", "t1",
                 "attr_add", "p2t2", "weight", 1,
                 "exit",
-             "ramify", "PetriNets_Runtime",
+             "ramify", "PetriNets_Runtime_SCHEDULE", "in", "PetriNets_Runtime",
              "new", "PetriNets_Runtime_SCHEDULE", "pn_simulate",
                 # Rule 1: mark transition to execute
                 # LHS
@@ -1150,7 +1150,7 @@ Void function action(host_model : Element, name : String, mapping : Element):
         self.assertTrue(run_file(all_files,
             get_model_constructor(PN_runtime) + \
                 get_model_constructor(PN_model) + [
-                "ramify", "PetriNets_Runtime_SCHEDULE", "PetriNets_Runtime", "PetriNets_Runtime",
+                "ramify", "PetriNets_Runtime_SCHEDULE", "in", "PetriNets_Runtime",
                 ] + get_model_constructor(schedule_model) + [
                 "transform", "pn", "pn_simulate",
                 "load", "pn",

+ 2 - 1
interface/HUTN/includes/ramify.alh

@@ -1,2 +1,3 @@
-Element function create_transformation_language(root : Element, source : String, target : String)
+Element function create_inplace_transformation_language(model : Element)
+Element function create_outplace_transformation_language(source : Element, target : Element)
 Element function ramify(model : Element)