Browse Source

First code for the concrete syntax renderer

Yentl Van Tendeloo 8 years ago
parent
commit
ab3bbddc49
2 changed files with 64 additions and 9 deletions
  1. 64 7
      core/core_algorithm.alc
  2. 0 2
      core/core_formalism.mvc

+ 64 - 7
core/core_algorithm.alc

@@ -753,6 +753,7 @@ Void function user_function_skip_init(user_id : String):
 			output("    model_list                      -- List all models")
 			output("    model_list_full                 -- List all models with full info")
 			output("    model_overwrite                 -- Overwrites a model with an uploaded model, leaving all metadata")
+			output("    model_render                    -- Render a given model with a specified mapper")
 			output("    verify                          -- Check whether a model conforms to its metamodel")
 			output("")
 			output("Transformation-specific operations")
@@ -839,6 +840,66 @@ Void function user_function_skip_init(user_id : String):
 					output("Permission denied")
 			else:
 				output("No such model")
+
+		elif (cmd == "model_render"):
+			String model_name
+			String model_ID
+			String mapper_name
+			String mapper_ID
+			String rendered_name
+
+			output("Model to render?")
+			model_name = input()
+			model_ID = get_model_id(model_name)
+
+			if (model_ID != ""):
+				output("Mapper to use?")
+				mapper_name = input()
+				mapper_ID = get_model_id(mapper_name)
+
+				if (allow_read(user_id, model_ID)):
+					if (mapper_ID != ""):
+						if (allow_read(user_id, mapper_ID)):
+							// Everything is fine; start the actual operation
+							// Find metamodel to render to
+							rendered_name = (("__RENDERED_" + model_name) + "__") + mapper_name
+							tracability_name = (("__TRACABILITY_" + model_name) + "__") + mapper_name
+
+							// Take the abstract syntax model and the previously rendered model
+							inputs = create_node()
+							set_add(inputs, model_name)
+							set_add(inputs, rendered_name)
+
+							// Generate a new rendered model only (no write to original model!)
+							outputs = create_node()
+							type_ID = followAssociation(core, mapper_ID, "transformOutput")
+							set_add(outputs, read_attribute(core, type_ID, "name"))
+
+							// Rendered model doesn't exist yet, so create first
+							if (get_model_id(rendered_name) == ""):
+								// Rendered model doesn't exist yet, so create first!
+								rendered_model = instantiate_model(get_full_model(type_ID))
+								model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
+								
+								// Tracability model won't exist either
+								tracability_model = instantiate_model(get_full_model(get_model_id("Tracability")))
+								model_create(tracability_model, tracability_name, user_id, get_model_id("Tracability"), "Model")
+
+							else:
+								// Read out tracability model
+								tracability_model = get_full_model(get_model_id(tracability_name))
+
+							// Do the operation itself!
+							execute_operation(mapper_ID, inputs, outputs, tracability_model)
+
+						else:
+							output("Permission denied")
+					else:
+						output("No such mapper")
+				else:
+					output("Permission denied")
+			else:
+				output("No such model")
 			
 		elif (cmd == "transformation_execute"):
 			// Execute a transformation, whatever type it is
@@ -897,16 +958,16 @@ Void function user_function_skip_init(user_id : String):
 						outputs = create_node()
 						while (read_nr_out(targets) > 0):
 							target = set_pop(targets)
-							output(string_join("Which model to create for target type ", read_attribute(core, target, "name")))
+							output(string_join("Which model to create for target type ", read_attribute(core, readAssociationDestination(core, target), "name")))
 							target_model_name = input()
 
 							if (get_model_id(target_model_name) == ""):
 								// Doesn't exist yet, so we can easily create
-								dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
+								dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
 							else:
 								// Already exists, so we need to check for write access
 								if (allow_write(user_id, get_model_id(target_model_name))):
-									dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
+									dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
 								else:
 									output("Permission denied; try again")
 									set_add(targets, target)
@@ -1254,12 +1315,10 @@ Void function user_function_skip_init(user_id : String):
 				while (read_nr_out(source) > 0):
 					dst = set_pop(source)
 					link = instantiate_link(core, "transformInput", "", model_id, dst)
-					instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
 
 				while (read_nr_out(target) > 0):
 					dst = set_pop(target)
 					link = instantiate_link(core, "transformOutput", "", model_id, dst)
-					instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
 			else:
 				output("Model already exists")
 
@@ -1352,12 +1411,10 @@ Void function user_function_skip_init(user_id : String):
 						while (read_nr_out(source) > 0):
 							dst = set_pop(source)
 							link = instantiate_link(core, "transformInput", "", model_id, dst)
-							instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
 
 						while (read_nr_out(target) > 0):
 							dst = set_pop(target)
 							link = instantiate_link(core, "transformOutput", "", model_id, dst)
-							instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
 					else:
 						output("Model already exists")
 				else:

+ 0 - 2
core/core_formalism.mvc

@@ -117,10 +117,8 @@ SimpleClassDiagrams CoreFormalism {
     Class ManualOperation : Transformation {}
 
     Association transformInput (Model, Transformation) {
-        name : String
     }
     Association transformOutput (Transformation, Model) {
-        name : String
     }
 
     Association tracability (Model, Model) {