Browse Source

Split up type mapping and all operations on it

Yentl Van Tendeloo 8 years ago
parent
commit
93c60c93b9

+ 10 - 24
bootstrap/90_core_formalism.mvc

@@ -53,26 +53,6 @@ SimpleClassDiagrams CoreFormalism {
             $
     }
 
-    SimpleAttribute TypeMapping {
-        constraint = $
-            String function constraint(model : Element, name : String):
-                Element self
-                self = model["model"][name]
-                if (has_value(self)):
-                    return "TypeMapping cannot have a value for root node!"!
-                Element keys
-                String key
-                keys = dict_keys(self)
-                while (read_nr_out(keys) > 0):
-                    key = set_pop(keys)
-                    if (bool_not(is_physical_string(key))):
-                        return ("Key on type mapping is not a string: " + cast_e2s(key))!
-                    elif (bool_not(is_physical_string(self[key]))):
-                        return ("Value on type mapping is not a string for key " + cast_e2s(key))!
-                return "OK"!
-            $
-    }
-
     Class User {
         name : String
         password : String
@@ -92,8 +72,9 @@ SimpleClassDiagrams CoreFormalism {
         permissions : Permissions
     }
 
+    Class TypeMapping : Model {}
+
     Association instanceOf (Model, Model) {
-        typing_location : String
     }
 
     Association owner (Model, User) {
@@ -112,8 +93,6 @@ SimpleClassDiagrams CoreFormalism {
 
     Class ActionLanguage : Transformation {}
 
-    Class ExternalTool : Transformation {}
-
     Class ManualOperation : Transformation {}
 
     Association transformInput (Model, Transformation) {
@@ -127,7 +106,14 @@ SimpleClassDiagrams CoreFormalism {
         type : String
     }
 
-    Association semantics (instanceOf, ActionLanguage) {}
+    Association semantics (instanceOf, ActionLanguage) {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
+    Association typing (instanceOf, TypeMapping) {
+        target_lower_cardinality = 1
+        target_upper_cardinality = 1
+    }
 
     Class Service {
         name : String

+ 151 - 26
bootstrap/99_core.mvc

@@ -23,49 +23,127 @@ CF core {
         location = "models/SimpleClassDiagrams/model"
         permissions = "221"
     }
+
     group (SimpleClassDiagrams, admin_group) {}
     owner (SimpleClassDiagrams, admin_user) {}
 
+    TypeMapping TM_SimpleClassDiagrams {
+        name = "TM_SimpleClassDiagrams"
+        location = "models/SimpleClassDiagrams/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_SimpleClassDiagrams, admin_group) {}
+    owner (TM_SimpleClassDiagrams, admin_user) {}
+
+    Model TypeMapping {
+        name = "TypeMapping"
+        location = "models/TypeMapping/model"
+        permissions = "221"
+    }
+
+    group (TypeMapping, admin_group) {}
+    owner (TypeMapping, admin_user) {}
+
+    TypeMapping TM_TypeMapping {
+        name = "TM_TypeMapping"
+        location = "models/TypeMapping/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_TypeMapping, admin_group) {}
+    owner (TM_TypeMapping, admin_user) {}
+
     Model Tracability {
         name = "Tracability"
         location = "models/Tracability/model"
         permissions = "221"
     }
+
     group (Tracability, admin_group) {}
     owner (Tracability, admin_user) {}
 
+    TypeMapping TM_Tracability{
+        name = "TM_Tracability"
+        location = "models/Tracability/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_Tracability, admin_group) {}
+    owner (TM_Tracability, admin_user) {}
+
     Model ProcessModel {
         name = "ProcessModel"
         location = "models/ProcessModel/model"
         permissions = "221"
     }
+
     group (ProcessModel, admin_group) {}
     owner (ProcessModel, admin_user) {}
 
+    TypeMapping TM_ProcessModel {
+        name = "TM_ProcessModel"
+        location = "models/ProcessModel/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_ProcessModel, admin_group) {}
+    owner (TM_ProcessModel, admin_user) {}
+
     Model ActionLanguage {
         name = "ActionLanguage"
         location = "models/ActionLanguage/model"
         permissions = "221"
     }
+
     group (ActionLanguage, admin_group) {}
     owner (ActionLanguage, admin_user) {}
 
+    TypeMapping TM_ActionLanguage {
+        name = "TM_ActionLanguage"
+        location = "models/ActionLanguage/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_ActionLanguage, admin_group) {}
+    owner (TM_ActionLanguage, admin_user) {}
+
     Model ManualOperation {
         name = "ManualOperation"
         location = "models/ManualOperation/model"
         permissions = "221"
     }
+
     group (ManualOperation, admin_group) {}
     owner (ManualOperation, admin_user) {}
 
+    TypeMapping TM_ManualOperation {
+        name = "TM_ManualOperation"
+        location = "models/ManualOperation/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_ManualOperation, admin_group) {}
+    owner (TM_ManualOperation, admin_user) {}
+
     ActionLanguage conformance_mv {
         name = "conformance_mv"
         location = "models/Conformance_MV/model"
         permissions = "221"
     }
+
     group (conformance_mv, admin_group) {}
     owner (conformance_mv, admin_user) {}
 
+    TypeMapping TM_conformance_mv {
+        name = "TM_conformance_mv"
+        location = "models/Conformance_MV/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_conformance_mv, admin_group) {}
+    owner (TM_conformance_mv, admin_user) {}
+
     transformInput (conformance_mv, SimpleClassDiagrams) {
         name = "model"
     }
@@ -78,54 +156,90 @@ CF core {
         location = "models/CoreFormalism/model"
         permissions = "221"
     }
+
     group (CoreFormalism, admin_group) {}
     owner (CoreFormalism, admin_user) {}
 
+    TypeMapping TM_CoreFormalism {
+        name = "TM_CoreFormalism"
+        location = "models/CoreFormalism/type_mapping"
+        permissions = "221"
+    }
+
+    group (TM_CoreFormalism, admin_group) {}
+    owner (TM_CoreFormalism, admin_user) {}
+
     Model Core {
         name = "core"
         location = "models/core/model"
         permissions = "220"
     }
+
     group (Core, admin_group) {}
     owner (Core, admin_user) {}
 
+    TypeMapping TM_Core {
+        name = "TM_core"
+        location = "models/core/type_mapping"
+        permissions = "220"
+    }
+
+    group (TM_Core, admin_group) {}
+    owner (TM_Core, admin_user) {}
+
     Model bottom {
         name = "bottom"
         location = "models/bottom/model"
         permissions = "221"
     }
+
     group (bottom, admin_group) {}
     owner (bottom, admin_user) {}
 
-    instanceOf inst_SCD (SimpleClassDiagrams, SimpleClassDiagrams) {
-        typing_location = "models/SimpleClassDiagrams/type_mapping"
-    }
-    instanceOf inst_trace (Tracability, SimpleClassDiagrams) {
-        typing_location = "models/Tracability/type_mapping"
-    }
-    instanceOf inst_pm (ProcessModel, SimpleClassDiagrams) {
-        typing_location = "models/ProcessModel/type_mapping"
-    }
-    instanceOf inst_al (ActionLanguage, SimpleClassDiagrams) {
-        typing_location = "models/ActionLanguage/type_mapping"
-    }
-    instanceOf inst_man (ManualOperation, SimpleClassDiagrams) {
-        typing_location = "models/ManualOperation/type_mapping"
-    }
-    instanceOf inst_conf (conformance_mv, ActionLanguage) {
-        typing_location = "models/Conformance_MV/type_mapping"
-    }
-    instanceOf inst_cf (CoreFormalism, SimpleClassDiagrams) {
-        typing_location = "models/CoreFormalism/type_mapping"
-    }
-    instanceOf inst_core (Core, CoreFormalism) {
-        typing_location = "models/core/type_mapping"
-    }
-    instanceOf inst_bottom (bottom, SimpleClassDiagrams) {
-        typing_location = "models/bottom/type_mapping"
+    TypeMapping TM_bottom {
+        name = "TM_bottom"
+        location = "models/bottom/type_mapping"
+        permissions = "221"
     }
 
+    group (TM_bottom, admin_group) {}
+    owner (TM_bottom, admin_user) {}
+
+    instanceOf inst_SCD (SimpleClassDiagrams, SimpleClassDiagrams) {}
+    instanceOf inst_TM (TypeMapping, SimpleClassDiagrams) {}
+    instanceOf inst_trace (Tracability, SimpleClassDiagrams) {}
+    instanceOf inst_pm (ProcessModel, SimpleClassDiagrams) {}
+    instanceOf inst_al (ActionLanguage, SimpleClassDiagrams) {}
+    instanceOf inst_man (ManualOperation, SimpleClassDiagrams) {}
+    instanceOf inst_conf (conformance_mv, ActionLanguage) {}
+    instanceOf inst_cf (CoreFormalism, SimpleClassDiagrams) {}
+    instanceOf inst_core (Core, CoreFormalism) {}
+    instanceOf inst_bottom (bottom, SimpleClassDiagrams) {}
+
+    instanceOf TM_inst_SCD (TM_SimpleClassDiagrams, TypeMapping) {}
+    instanceOf TM_inst_TM (TM_TypeMapping, TypeMapping) {}
+    instanceOf TM_inst_trace (TM_Tracability, TypeMapping) {}
+    instanceOf TM_inst_pm (TM_ProcessModel, TypeMapping) {}
+    instanceOf TM_inst_al (TM_ActionLanguage, TypeMapping) {}
+    instanceOf TM_inst_man (TM_ManualOperation, TypeMapping) {}
+    instanceOf TM_inst_conf (TM_conformance_mv, TypeMapping) {}
+    instanceOf TM_inst_cf (TM_CoreFormalism, TypeMapping) {}
+    instanceOf TM_inst_core (TM_Core, TypeMapping) {}
+    instanceOf TM_inst_bottom (TM_bottom, TypeMapping) {}
+
+    typing (inst_SCD, TM_SimpleClassDiagrams) {}
+    typing (inst_TM, TM_TypeMapping) {}
+    typing (inst_trace, TM_Tracability) {}
+    typing (inst_pm, TM_ProcessModel) {}
+    typing (inst_al, TM_ActionLanguage) {}
+    typing (inst_man, TM_ManualOperation) {}
+    typing (inst_conf, TM_conformance_mv) {}
+    typing (inst_cf, TM_CoreFormalism) {}
+    typing (inst_core, TM_Core) {}
+    typing (inst_bottom, TM_bottom) {}
+
     semantics (inst_SCD, conformance_mv) {}
+    semantics (inst_TM, conformance_mv) {}
     semantics (inst_trace, conformance_mv) {}
     semantics (inst_pm, conformance_mv) {}
     semantics (inst_al, conformance_mv) {}
@@ -134,6 +248,17 @@ CF core {
     semantics (inst_cf, conformance_mv) {}
     semantics (inst_core, conformance_mv) {}
     semantics (inst_bottom, conformance_mv) {}
+
+    semantics (TM_inst_SCD, conformance_mv) {}
+    semantics (TM_inst_TM, conformance_mv) {}
+    semantics (TM_inst_trace, conformance_mv) {}
+    semantics (TM_inst_pm, conformance_mv) {}
+    semantics (TM_inst_al, conformance_mv) {}
+    semantics (TM_inst_man, conformance_mv) {}
+    semantics (TM_inst_conf, conformance_mv) {}
+    semantics (TM_inst_cf, conformance_mv) {}
+    semantics (TM_inst_core, conformance_mv) {}
+    semantics (TM_inst_bottom, conformance_mv) {}
 }
 
 export core to models/core

+ 45 - 0
bootstrap/conformance_finding.alc

@@ -0,0 +1,45 @@
+include "primitives.alh"
+include "object_operations.alh"
+include "typing.alh"
+
+Element function find_type_mapping(model : Element, metamodel : Element):
+	// Takes as input a model dictionary and fully specified metamodel
+	// No other entries are required, and the type mapping is returned
+
+	// TODO for now, this only returns something for a simple case, where the MM has one edge, and one node
+	//      and it makes the assumption that SCD is the M3 level...
+
+	// First find the name of the edge and node elements
+	Element result
+	Element elems
+	String elem
+
+	String node_element
+	String edge_element
+
+	elems = dict_keys(metamodel["model"])
+	while (set_len(elems) > 0):
+		elem = set_pop(elems)
+
+		if (bool_not(is_edge(elem))):
+			node_element = elem
+		else:
+			// Is an edge, but might be the inheritance link...
+			if (read_type(metamodel, elem) != "Inheritance"):
+				// Is not the inheritance link
+				edge_element = elem
+
+	// Now we have bot an edge_element and node_element of the metamodel
+	// Now just trivially bind all elements!
+	result = create_node()
+
+	elems = dict_keys(model)
+	while (set_len(elems) > 0):
+		elem = set_pop(elems)
+
+		if (is_edge(elem)):
+			dict_add(result, elem, edge_element)
+		else:
+			dict_add(result, elem, node_element)
+	
+	return result!

+ 8 - 28
bootstrap/conformance_scd.alc

@@ -3,6 +3,7 @@ include "library.alh"
 include "object_operations.alh"
 include "constructors.alh"
 include "modelling.alh"
+include "typing.alh"
 
 Boolean function wrap_conformance(model : Element):
 	String result
@@ -15,9 +16,12 @@ Boolean function wrap_conformance(model : Element):
 
 Boolean function is_direct_instance(model : Element, instance : String, type : String):
 	// Just check whether or not the type mapping specifies the type as the type of the instance
-	return value_eq(model["type_mapping"][instance], type)!
+	return (read_type(model, instance) == type)!
 
 Boolean function is_nominal_instance(model : Element, instance : String, type : String):
+	if (read_type(model, instance) == type):
+		return True!
+
 	if (bool_not(dict_in(model["metamodel"]["model"], type))):
 		// type is not even in the specified metamodel, so this will never work
 		return False!
@@ -26,14 +30,11 @@ Boolean function is_nominal_instance(model : Element, instance : String, type :
 		// type is an edge, but we aren't
 		return False!
 
-	if (bool_not(dict_in(model["type_mapping"], instance))):
+	if (element_eq(read_type(model, instance), read_root())):
 		// doesn't even have a type
 		return False!
 
-	if (value_eq(model["type_mapping"][instance], type)):
-		return True!
-
-	return is_nominal_subtype(model["metamodel"], model["type_mapping"][instance], type)!
+	return is_nominal_subtype(model["metamodel"], read_type(model, instance), type)!
 
 Boolean function is_nominal_subtype(metamodel : Element, subclass : String, superclass : String):
 	if (element_eq(metamodel["model"][subclass], metamodel["model"][superclass])):
@@ -135,7 +136,7 @@ String function conformance_scd(model : Element):
 	// Load in variables
 	scd = import_node("models/SimpleClassDiagrams")
 	metamodel = model["metamodel"]
-	typing = model["type_mapping"]
+	typing = get_type_mapping_as_dict(model)
 
 	// Create dictionary with all associations and allowed cardinalities
 	if (dict_len(model["model"]) > 0):
@@ -318,24 +319,3 @@ Element function set_model_constraints(model : Element, func : Element):
 
 String function model_info(model : Element, name : String):
 	return name!
-
-Element function generate_bottom_type_mapping(model_dict : Element):
-	// The model is only a dictionary of elements, being the usual model["model"] value.
-	// This function returns the type mapping dictionary
-	// There are only two concepts that we can link to: "Node" and "Edge".
-
-	// Iterate over each element in the model
-	Element result
-	Element elements
-	String element
-
-	elements = dict_keys(model_dict)
-	result = dict_create()
-
-	while (set_len(elements) > 0):
-		element = set_pop(elements)
-		if (is_edge(model_dict[element])):
-			dict_add_fast(result, element, "Edge")
-		else:
-			dict_add_fast(result, element, "Node")
-	return result!

+ 35 - 6
bootstrap/core_algorithm.alc

@@ -10,6 +10,8 @@ include "conformance_scd.alh"
 include "transform.alh"
 include "metamodels.alh"
 include "utils.alh"
+include "conformance_finding.alh"
+include "typing.alh"
 
 Element core = ?
 
@@ -56,7 +58,7 @@ Element function get_full_model(model_id : String, metamodel_id : String):
 
 	m = dict_create()
 	dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
-	dict_add(m, "type_mapping", import_node(read_attribute(core, choice, "typing_location")))
+	dict_add(m, "type_mapping", import_node(read_attribute(core, set_pop(allAssociationDestinations(core, choice, "typing")), "location")))
 	dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
 
 	if (readAssociationDestination(core, choice) == model_id):
@@ -247,10 +249,10 @@ Void function model_create(model : Element, name : String, user_id : String, typ
 	String model_id
 	String instance_of
 
+	// Create model itself
 	location = "models/" + cast_id2s(model)
 	export_node(location, model["model"])
 
-	// Manage meta-info
 	model_id = instantiate_node(core, kind, "")
 	instantiate_attribute(core, model_id, "name", name)
 	instantiate_attribute(core, model_id, "location", location)
@@ -258,10 +260,20 @@ Void function model_create(model : Element, name : String, user_id : String, typ
 	instantiate_link(core, "owner", "", model_id, user_id)
 	instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
 	instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
+	instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
 
+	// Create type mapping model
 	location = "models/" + cast_id2s(model["type_mapping"])
 	export_node(location, model["type_mapping"])
-	instantiate_attribute(core, instance_of, "typing_location", location)
+
+	model_id = instantiate_node(core, "TypeMapping", "")
+	instantiate_link(core, "typing", "", instance_of, model_id)
+	instantiate_attribute(core, model_id, "name", "TM_" + name)
+	instantiate_attribute(core, model_id, "location", location)
+	instantiate_attribute(core, model_id, "permissions", "200")
+	instantiate_link(core, "owner", "", model_id, user_id)
+	instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
+	instance_of = instantiate_link(core, "instanceOf", "", model_id, get_model_id("TypeMapping"))
 	instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
 
 	return!
@@ -281,11 +293,14 @@ Void function model_overwrite(model : Element, model_id : String, metamodel_id :
 
 	// Update the instanceOf relation of the context in which we are working
 	// TODO This needs to be fixed: all previous connections should be cleared probably
-	instanceOf_link = get_instanceOf_link(model_id, metamodel_id)
-	unset_attribute(core, instanceOf_link, "typing_location")
+	String choice
+	String typing_model_id
+	choice = get_instanceOf_link(model_id, metamodel_id)
+	typing_model_id = set_pop(allAssociationDestinations(core, choice, "typing"))
+
 	location = "models/" + cast_id2s(model["type_mapping"])
 	export_node(location, model["type_mapping"])
-	instantiate_attribute(core, instanceOf_link, "typing_location", location)
+	instantiate_attribute(core, typing_model_id, "location", location)
 
 	return!
 
@@ -980,6 +995,8 @@ String function cmd_model_modify(user_id : String, model_name : String, metamode
 			if (allow_read(user_id, type_id)):
 				output("Success")
 				Element new_model
+				log("Getting full model for " + model_name)
+				log("Metamodel:  " + metamodel_name)
 				new_model = get_full_model(model_id, get_model_id(metamodel_name))
 				modify(new_model, allow_write(user_id, model_id))
 				if (allow_write(user_id, model_id)):
@@ -1753,6 +1770,18 @@ Void function user_function_skip_init(user_id : String):
 			// Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
 			// as the current user will have been deleted
 			return !
+		elif (cmd == "add_conformance"):
+			// TODO
+			cmd = "FAIL"
+		elif (cmd == "remove_conformance"):
+			// TODO
+			cmd = "FAIL"
+		elif (cmd == "user_name"):
+			// TODO
+			cmd = "FAIL"
+		elif (cmd == "service_poll"):
+			// TODO
+			cmd = "FAIL"
 		else:
 			output("Unknown command: " + cmd)
 

+ 1 - 0
bootstrap/initial_code_manager.alc

@@ -16,5 +16,6 @@ Void function __main():
 	exec(root["bootstrap/core_algorithm.alc"]["initializers"])
 	exec(root["bootstrap/utils.alc"]["initializers"])
 	exec(root["bootstrap/io.alc"]["initializers"])
+	exec(root["bootstrap/typing.alc"]["initializers"])
 	task_management()
 	return!

+ 2 - 0
bootstrap/initial_code_task.alc

@@ -21,5 +21,7 @@ Void mutable function __main():
 	exec(root["bootstrap/utils.alc"]["initializers"])
 	exec(root["bootstrap/services.alc"]["initializers"])
 	exec(root["bootstrap/io.alc"]["initializers"])
+	exec(root["bootstrap/conformance_finding.alc"]["initializers"])
+	exec(root["bootstrap/typing.alc"]["initializers"])
 	new_task()
 	return!

+ 35 - 0
bootstrap/mini_modify.alc

@@ -129,6 +129,24 @@ String function cmd_instantiate_edge(write : Boolean, model : Element, mm_type_n
 	else:
 		return "Permission denied to write"!
 
+String function cmd_define_attribute(write : Boolean, model : Element, element_name : String, attr_name : String, type : String):
+	if (write):
+		if (dict_in(model["model"], element_name)):
+			if (dict_in(model["model"], type)):
+				Element attrs
+				attrs = getAttributeList(model, element_name)
+				if (bool_not(set_in(dict_keys(attrs), attr_name))):
+					model_define_attribute(model, element_name, attr_name, False, type)
+					return "Success"!
+				else:
+					return "Attribute already defined: " + attr_name!
+			else:
+				return "Element not found: " + type!
+		else:
+			return "Element not found: " + element_name!
+	else:
+		return "Permission denied to write"!
+
 String function cmd_attr_add(write : Boolean, model : Element, element_name : String, attr_name : String, value : Element):
 	if (write):
 		if (dict_in(model["model"], element_name)):
@@ -335,6 +353,19 @@ String function cmd_read_association_destination(write : Boolean, model : Elemen
 	else:
 		return "Element not found: " + element_name!
 
+String function cmd_all_instances(model : Element, type : String):
+	String result
+	Element elems
+
+	if (dict_in(model["metamodel"]["model"], type)):
+		result = "Success: "
+		elems = allInstances(model, type)
+		while (set_len(elems) > 0):
+			result = string_join(result, set_pop(elems)) + "\n"
+		return result!
+	else:
+		return "Element not found: " + type!
+
 Element function modify(model : Element, write : Boolean):
 	String cmd
 
@@ -384,6 +415,10 @@ Element function modify(model : Element, write : Boolean):
 			output(cmd_read_association_destination(write, model, single_input("Name?")))
 		elif (cmd == "connections_between"):
 			output(cmd_connections_between(model, single_input("Source element?"), single_input("Target element?")))
+		elif (cmd == "all_instances"):
+			output(cmd_all_instances(model, single_input("Type?")))
+		elif (cmd == "define_attribute"):
+			output(cmd_define_attribute(write, model, single_input("On which element?"), single_input("Attribute name?"), single_input("Type?")))
 		else:
 			output("Unknown command while modelling: " + cast_v2s(cmd))
 			output("Use command 'help' to get a list of available commands")

+ 0 - 32
bootstrap/model_management.alc

@@ -111,38 +111,6 @@ Element function model_copy(src_model : Element):
 
 	return dst_model!
 
-Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String):
-	String key
-	String type
-	Element keys
-	Integer length
-
-	keys = dict_keys(model["model"])
-	length = string_len(name)
-
-	while (set_len(keys) > 0):
-		key = set_pop(keys)
-		if (dict_in(model["model"], key)):
-			// Check if the element is still there, as a delete of a node might remove all attached links automatically
-			type = read_type(model, key)
-
-			if (operation == "+"):
-				// Keep all, but augment typename
-				dict_delete(model["type_mapping"], key)
-				dict_add_fast(model["type_mapping"], key, name + type)
-			elif (operation == "-"):
-				// Keep only if typename beginning matches and remove from typename
-				if (string_startswith(type, name)):
-					dict_delete(model["type_mapping"], key)
-					dict_add_fast(model["type_mapping"], key, string_substr(type, length, string_len(type)))
-				else:
-					model_delete_element(model, key)
-
-	dict_delete(model, "metamodel")
-	dict_add_fast(model, "metamodel", new_MM)
-
-	return model!
-
 Element function model_join(models : Element, metamodel : Element, tracability_model : Element):
 	Element new_model
 	Element tagged_model

+ 26 - 50
bootstrap/modelling.alc

@@ -4,6 +4,7 @@ include "object_operations.alh"
 include "constructors.alh"
 include "metamodels.alh"
 include "library.alh"
+include "typing.alh"
 
 Element global_models = ?
 
@@ -23,7 +24,6 @@ Element function instantiate_bottom():
 
 	// Add an empty model and empty type mapping
 	dict_add_fast(new_model, "model", dict_create())
-	dict_add_fast(new_model, "type_mapping", dict_create())
 
 	// Return the created model
 	return new_model!
@@ -74,20 +74,11 @@ String function model_add_edge(model : Element, name : String, source : String,
 
 Void function retype_model(model : Element, metamodel : Element):
 	// Remove the type mapping and add a new one for the specified metamodel
-	dict_delete(model, "type_mapping")
-	dict_add_fast(model, "type_mapping", dict_create())
-	dict_add_fast(model, "metamodel", metamodel)
-	return!
-
-Void function retype(model : Element, element : String, type : String):
-	// Retype a model, deleting any previous type the element had
-	// The type string is evaluated in the metamodel previously specified
-
-	if (dict_in(model["type_mapping"], element)):
-		dict_delete(model["type_mapping"], element)
-
-	dict_add_fast(model["type_mapping"], element, type)
+	if (dict_in(model, "type_mapping")):
+		dict_delete(model, "type_mapping")
 
+	dict_add_fast(model, "type_mapping", new_type_mapping())
+	dict_add_fast(model, "metamodel", metamodel)
 	return!
 
 Element function instantiate_model(metamodel : Element):
@@ -108,7 +99,7 @@ String function reuse_element(model : Element, type_name : String, instance_name
 
 	actual_name = instantiated_name(element, instance_name)
 	dict_add(model["model"], actual_name, element)
-	dict_add_fast(model["type_mapping"], actual_name, type_name)
+	retype(model, actual_name, type_name)
 
 	return actual_name!
 
@@ -125,7 +116,7 @@ String function instantiate_node(model : Element, type_name : String, instance_n
 
 	actual_name = instantiated_name(value, instance_name)
 	dict_add_fast(model["model"], actual_name, value)
-	dict_add_fast(model["type_mapping"], actual_name, type_name)
+	retype(model, actual_name, type_name)
 	return actual_name!
 
 String function instantiate_value(model : Element, type_name : String, instance_name : String, value : Element):
@@ -138,7 +129,7 @@ String function instantiate_value(model : Element, type_name : String, instance_
 	
 	actual_name = instantiated_name(value, instance_name)
 	dict_add_fast(model["model"], actual_name, value)
-	dict_add_fast(model["type_mapping"], actual_name, type_name)
+	retype(model, actual_name, type_name)
 	return actual_name!
 
 String function find_attribute_type(model : Element, elem : String, name : String):
@@ -184,8 +175,9 @@ Element function get_subclasses(model : Element, name : String):
 			j = 0
 			while (j < num_edges):
 				edge = read_in(model["model"][elem], j)
-				if (value_eq(model["type_mapping"][reverseKeyLookup(model["model"], edge)], "Inheritance")):
-					set_add(nodes, reverseKeyLookup(model["model"], read_edge_src(edge)))
+				if (dict_in(model["model"], reverseKeyLookup(model["model"], edge))):
+					if (read_type(model, reverseKeyLookup(model["model"], edge)) == "Inheritance"):
+						set_add(nodes, reverseKeyLookup(model["model"], read_edge_src(edge)))
 				j = j + 1
 	return result!
 
@@ -212,8 +204,9 @@ Element function get_superclasses(model : Element, name : String):
 			j = 0
 			while (j < num_edges):
 				edge = read_out(model["model"][elem], j)
-				if (value_eq(model["type_mapping"][reverseKeyLookup(model["model"], edge)], "Inheritance")):
-					set_add(nodes, reverseKeyLookup(model["model"], read_edge_dst(edge)))
+				if (dict_in(model["model"], reverseKeyLookup(model["model"], edge))):
+					if (read_type(model, reverseKeyLookup(model["model"], edge)) == "Inheritance"):
+						set_add(nodes, reverseKeyLookup(model["model"], read_edge_dst(edge)))
 				j = j + 1
 
 	return result!
@@ -360,17 +353,11 @@ String function instantiate_link(model : Element, type : String, name : String,
 	v = create_edge(model["model"][source], model["model"][destination])
 	actual_name = instantiated_name(v, name)
 	dict_add_fast(model["model"], actual_name, v)
-	dict_add_fast(model["type_mapping"], actual_name, type)
+	retype(model, actual_name, type)
 	return actual_name!
 
 Void function model_delete_element(model : Element, name : String):
-	// Remove the link
-	// 1) from the type mapping
-	dict_delete(model["type_mapping"], name)
-
-	// 2) from the model
 	delete_element(model["model"][name])
-
 	return!
 
 String function model_define_attribute(model : Element, elem : String, name : String, optional : Boolean, type : String):
@@ -396,21 +383,18 @@ Element function read_attribute(model : Element, element : String, attribute : S
 		Element edge
 		Element edge_type
 		Element elem
-		Element typing
 		Element name
 
 		elem = model["model"][element]
-		typing = model["type_mapping"]
 		count = read_nr_out(elem)
 
 		i = 0
 		while (i < count):
 			edge = read_out(elem, i)
 			name = reverseKeyLookup(model["model"], edge)
-			if (dict_in(typing, name)):
-				edge_type = model["metamodel"]["model"][typing[name]]
-				if (element_eq(edge_type, dict_read_edge(read_edge_src(edge_type), attribute))):
-					return read_edge_dst(edge)!
+			edge_type = model["metamodel"]["model"][read_type(model, name)]
+			if (element_eq(edge_type, dict_read_edge(read_edge_src(edge_type), attribute))):
+				return read_edge_dst(edge)!
 			i = i + 1
 
 	else:
@@ -430,8 +414,6 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
 
 	while (set_len(attr_links) > 0):
 		attr_link = set_pop(attr_links)
-		dict_delete(model["type_mapping"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
-		dict_delete(model["type_mapping"], attr_link)
 		dict_delete(model["model"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
 		delete_element(model["model"][attr_link])
 
@@ -442,29 +424,24 @@ Void function add_AL_links(model : Element, list : Element, element : Element, t
 		return!
 
 	Element link
-	String link_name
-
 	link = dict_read_edge(element, linkname)
-	link_name = "__" + cast_id2s(link)
 
 	// The link
-	dict_add_fast(model["model"], link_name, link)
-	dict_add_fast(model["type_mapping"], link_name, (type + "_") + linkname)
+	if (linkname == "next"):
+		type = "Statement"
+	reuse_element(model, (type + "_") + linkname, "", link)
 
 	// The name link
 	link = read_out(link, 0)
-	link_name = "__" + cast_id2s(link)
-
-	dict_add_fast(model["model"], link_name, link)
-	dict_add_fast(model["type_mapping"], link_name, "dict_link_name")
+	reuse_element(model, "dict_link_name", "", link)
 	
 	// The name node
+	String link_name
 	link = read_edge_dst(link)
 	link_name = "__" + cast_id2s(link)
 
-	if (bool_not(set_in(model["model"], link_name))):
-		dict_add_fast(model["model"], link_name, link)
-		dict_add_fast(model["type_mapping"], link_name, "StringAttr")
+	if (bool_not(dict_in(model["model"], link_name))):
+		reuse_element(model, "StringAttr", link_name, link)
 
 	// Now add the destination to the worker list
 	set_add_node(list, create_tuple(element[linkname], expected_type))
@@ -497,8 +474,7 @@ String function add_AL(model : Element, element : Element):
 					type = "Element"
 
 			// Add the node itself
-			dict_add_fast(model["model"], elem_name, elem)
-			dict_add_fast(model["type_mapping"], elem_name, type)
+			reuse_element(model, type, elem_name, elem)
 
 			// Now add its edges
 			if (type == "if"):

+ 2 - 23
bootstrap/object_operations.alc

@@ -2,6 +2,7 @@ include "primitives.alh"
 include "conformance_scd.alh"
 include "constructors.alh"
 include "modelling.alh"
+include "typing.alh"
 
 Element function allInstances(model : Element, type_name : String):
 	if (dict_in(model["metamodel"]["model"], type_name)):
@@ -18,8 +19,7 @@ Element function allInstances(model : Element, type_name : String):
 
 		while (set_len(accepted) > 0):
 			class = set_pop(accepted)
-			results = reverseKeyLookupMulti(model["type_mapping"], class)
-			set_merge(result, results)
+			set_merge(result, get_elements_typed_by(model, class))
 		return result!
 	else:
 		log("No such type in the metamodel: " + type_name)
@@ -226,24 +226,3 @@ Element function allowedAssociationsBetween(model : Element, src : String, dst :
 			i = i + 1
 
 	return result!
-
-String function read_type(model : Element, name : String):
-	String result
-
-	Element tm
-
-	if (dict_in(model["model"], name)):
-		if (dict_in(model["type_mapping"], name)):
-			result = model["type_mapping"][name]
-			
-			if (dict_in(model["metamodel"]["model"], result)):
-				return result!
-			else:
-				log("Could not find " + result)
-				return ""!
-		else:
-			log("Untyped " + name)
-			return ""!
-	else:
-		log("Couldn't find type of " + name)
-		return ""!

+ 1 - 7
bootstrap/ramify.alc

@@ -8,13 +8,7 @@ include "conformance_scd.alh"
 Element function ramify(model : Element):
 	// Create new model structure
 	Element new_model
-	new_model = dict_create()
-	dict_add_fast(new_model, "model", dict_create())
-	dict_add_fast(new_model, "type_mapping", dict_create())
-	dict_add_fast(new_model, "metamodel", model["metamodel"])
-
-	dict_add_fast(new_model, "source", model)
-	dict_add_fast(new_model, "target", model)
+	new_model = instantiate_model(model["metamodel"])
 
 	// Get local variables for parts
 	Element old_m

+ 3 - 0
bootstrap/semi_primitives.alc

@@ -253,12 +253,15 @@ Element function set_overlap(sa : Element, sb : Element):
 
 	if (set_len(sa) > set_len(sb)):
 		// Pick the smallest set to iterate over, so switch if sa is not the smallest
+		log("Switch order")
 		result = sa
 		sa = sb
 		sb = result
 
 	result = set_create()
 	sa = set_copy(sa)
+	log("SA: " + set_to_string(sa))
+	log("SB: " + set_to_string(sb))
 
 	// Iterate over each element of sa and only add it to the result if it is also in sb
 	while (set_len(sa) > 0):

+ 40 - 0
bootstrap/typing.alc

@@ -0,0 +1,40 @@
+include "primitives.alh"
+include "utils.alh"
+
+Element function get_type_mapping_as_dict(model : Element):
+	return model["type_mapping"]!
+
+Element function get_elements_typed_by(model : Element, type : String):
+	return reverseKeyLookupMulti(model["type_mapping"], type)!
+
+String function read_type(model : Element, name : String):
+	String result
+	Element tm
+	if (dict_in(model["model"], name)):
+		if (dict_in(model["type_mapping"], name)):
+			result = model["type_mapping"][name]
+
+			if (dict_in(model["metamodel"]["model"], result)):
+				return result!
+			else:
+				// log("Could not find " + result)
+				return ""!
+		else:
+			// log("Untyped " + name)
+			return ""!
+	else:
+		// log("Couldn't find type of " + name)
+		return ""!
+
+Void function retype(model : Element, element : String, type : String):
+	// Retype a model, deleting any previous type the element had
+	// The type string is evaluated in the metamodel previously specified
+
+	if (dict_in(model["type_mapping"], element)):
+		dict_delete(model["type_mapping"], element)
+
+	dict_add_fast(model["type_mapping"], element, type)
+	return!
+
+Element function new_type_mapping():
+	return dict_create()!

+ 0 - 1
bootstrap/utils.alc

@@ -99,5 +99,4 @@ Void function set_difference(set1 : Element, set2 : Element):
 	return!
 
 String function get_taskname():
-	log("Taskname is: " + reverseKeyLookup(read_root(), read_taskroot()))
 	return reverseKeyLookup(read_root(), read_taskroot())!

+ 52 - 16
integration/test_mvc.py

@@ -14,7 +14,19 @@ expected_model_list = set([("SimpleClassDiagrams", "SimpleClassDiagrams"),
                            ("Tracability", "SimpleClassDiagrams"),
                            ("conformance_mv", "ActionLanguage"),
                            ("bottom", "SimpleClassDiagrams"),
-                           ("core", "CoreFormalism")])
+                           ("core", "CoreFormalism"),
+                           ('TypeMapping', 'SimpleClassDiagrams'),
+                           ('TM_SimpleClassDiagrams', 'TypeMapping'),
+                           ('TM_TypeMapping', 'TypeMapping'),
+                           ('TM_Tracability', 'TypeMapping'),
+                           ('TM_ProcessModel', 'TypeMapping'),
+                           ('TM_ActionLanguage', 'TypeMapping'),
+                           ('TM_ManualOperation', 'TypeMapping'),
+                           ('TM_conformance_mv', 'TypeMapping'),
+                           ('TM_CoreFormalism', 'TypeMapping'),
+                           ('TM_core', 'TypeMapping'),
+                           ('TM_bottom', 'TypeMapping'),
+                          ])
 
 expected_model_full_list = set([("SimpleClassDiagrams", "SimpleClassDiagrams", "admin", "admin", "221"),
                                 ("CoreFormalism", "SimpleClassDiagrams", "admin", "admin", "221"),
@@ -24,7 +36,19 @@ expected_model_full_list = set([("SimpleClassDiagrams", "SimpleClassDiagrams", "
                                 ("Tracability", "SimpleClassDiagrams", "admin", "admin", "221"),
                                 ("bottom", "SimpleClassDiagrams", "admin", "admin", "221"),
                                 ("conformance_mv", "ActionLanguage", "admin", "admin", "221"),
-                                ("core", "CoreFormalism", "admin", "admin", "220")])
+                                ("core", "CoreFormalism", "admin", "admin", "220"),
+                                ('TypeMapping', 'SimpleClassDiagrams', "admin", "admin", "221"),
+                                ('TM_SimpleClassDiagrams', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_TypeMapping', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_Tracability', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_ProcessModel', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_ActionLanguage', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_ManualOperation', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_conformance_mv', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_CoreFormalism', 'TypeMapping', "admin", "admin", "221"),
+                                ('TM_core', 'TypeMapping', "admin", "admin", "220"),
+                                ('TM_bottom', 'TypeMapping', "admin", "admin", "221"),
+                                ])
 
 expected_transformation_list = set([("ActionLanguage", "conformance_mv")])
 
@@ -48,44 +72,48 @@ class TestModelverseCore(unittest.TestCase):
 
     def test_model_add_empty(self):
         model_add("Empty", "SimpleClassDiagrams")
-        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams")])
-        assert model_list_full() == set(list(expected_model_full_list) + [("Empty", "SimpleClassDiagrams", "admin", "nobody", "200")])
+        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams"), ("TM_Empty", "TypeMapping")])
+        assert model_list_full() == set(list(expected_model_full_list) + [("Empty", "SimpleClassDiagrams", "admin", "nobody", "200"),
+                                                                          ("TM_Empty", "TypeMapping", "admin", "nobody", "200"),
+                                                                         ])
 
     def test_model_verify(self):
         assert verify("SimpleClassDiagrams", "SimpleClassDiagrams") == "OK"
 
     def test_model_empty_instantiate(self):
         model_add("Empty", "SimpleClassDiagrams")
-        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams")])
-        assert model_list_full() == set(list(expected_model_full_list) + [("Empty", "SimpleClassDiagrams", "admin", "nobody", "200")])
+        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams"), ("TM_Empty", "TypeMapping")])
         assert element_list("Empty") == set([])
         instantiate("Empty", "Class", ID="A")
         assert element_list("Empty") == set([("A", "Class")])
-        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams")])
-        assert model_list_full() == set(list(expected_model_full_list) + [("Empty", "SimpleClassDiagrams", "admin", "nobody", "200")])
+        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams"), ("TM_Empty", "TypeMapping")])
 
     def test_model_overwrite(self):
         model_add("Empty", "SimpleClassDiagrams")
-        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams")])
-        assert model_list_full() == set(list(expected_model_full_list) + [("Empty", "SimpleClassDiagrams", "admin", "nobody", "200")])
+        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams"), ("TM_Empty", "TypeMapping")])
         assert element_list("Empty") == set([])
         instantiate("Empty", "Class", ID="A")
         assert element_list("Empty") == set([("A", "Class")])
         model_overwrite("Empty")
         assert element_list("Empty") == set([])
-        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams")])
-        assert model_list_full() == set(list(expected_model_full_list) + [("Empty", "SimpleClassDiagrams", "admin", "nobody", "200")])
+        assert model_list() == set(list(expected_model_list) + [("Empty", "SimpleClassDiagrams"), ("TM_Empty", "TypeMapping")])
         instantiate("Empty", "Class", ID="B")
         assert element_list("Empty") == set([("B", "Class")])
 
     def test_transform_add_MT(self):
         model_add("PetriNet", "SimpleClassDiagrams", open("integration/code/petrinets.mvc", "r").read())
-        assert model_list() == set(list(expected_model_list) + [("PetriNet", "SimpleClassDiagrams")])
+        assert model_list() == set(list(expected_model_list) + [("PetriNet", "SimpleClassDiagrams"),
+                                                                ("TM_PetriNet", "TypeMapping"),
+                                                               ])
         transformation_add_MT({"PetriNet": "PetriNet"}, {}, "print_pn", open("integration/code/pn_print.mvc").read())
         assert model_list() == set(list(expected_model_list) + [("PetriNet", "SimpleClassDiagrams"),
+                                                                ("TM_PetriNet", "TypeMapping"),
                                                                 ("__RAM_print_pn", "SimpleClassDiagrams"),
+                                                                ("TM___RAM_print_pn", "TypeMapping"),
                                                                 ("__merged_print_pn", "SimpleClassDiagrams"),
-                                                                ("print_pn", "__RAM_print_pn")])
+                                                                ("TM___merged_print_pn", "TypeMapping"),
+                                                                ("print_pn", "__RAM_print_pn"),
+                                                                ("TM_print_pn", "TypeMapping")])
         assert transformation_list() == set(list(expected_transformation_list) + [("ModelTransformation", "print_pn")])
 
     def test_transform_add_MT_pn_print_exec(self):
@@ -97,13 +125,21 @@ class TestModelverseCore(unittest.TestCase):
         model_add("PetriNet", "SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
         model_add("my_pn", "PetriNet", open("integration/code/pn_runtime_model.mvc", "r").read())
         assert model_list() == set(list(expected_model_list) + [("PetriNet", "SimpleClassDiagrams"),
-                                                                ("my_pn", "PetriNet")])
+                                                                ("TM_PetriNet", "TypeMapping"),
+                                                                ("my_pn", "PetriNet"),
+                                                                ("TM_my_pn", "TypeMapping"),
+                                                               ])
         transformation_add_MT({"PetriNet": "PetriNet"}, {}, "print_pn", open("integration/code/pn_print.mvc").read())
         assert model_list() == set(list(expected_model_list) + [("PetriNet", "SimpleClassDiagrams"),
+                                                                ("TM_PetriNet", "TypeMapping"),
                                                                 ("my_pn", "PetriNet"),
+                                                                ("TM_my_pn", "TypeMapping"),
                                                                 ("__RAM_print_pn", "SimpleClassDiagrams"),
+                                                                ("TM___RAM_print_pn", "TypeMapping"),
                                                                 ("__merged_print_pn", "SimpleClassDiagrams"),
-                                                                ("print_pn", "__RAM_print_pn")])
+                                                                ("TM___merged_print_pn", "TypeMapping"),
+                                                                ("print_pn", "__RAM_print_pn"),
+                                                                ("TM_print_pn", "TypeMapping")])
         assert transformation_list() == set(list(expected_transformation_list) + [("ModelTransformation", "print_pn")])
         assert transformation_execute_MT("print_pn", {"PetriNet": "my_pn"}, {}, callback) == True
 

+ 1 - 0
interface/HUTN/includes/conformance_finding.alh

@@ -0,0 +1 @@
+Element function find_type_mapping(model : Element, metamodel : Element)

+ 0 - 1
interface/HUTN/includes/model_management.alh

@@ -1,5 +1,4 @@
 Element function model_fuse(models : Element)
 Element function model_copy(model : Element)
-Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String)
 Element function model_join(models : Element, metamodel : Element, tracability : Element)
 Element function model_split(merged_model : Element, models : Element, tracability : Boolean)

+ 1 - 0
interface/HUTN/includes/modelling.alh

@@ -25,3 +25,4 @@ String function model_define_attribute(model : Element, elem : String, name : St
 Element function construct_model_raw(metamodel : Element)
 Element function get_func_AL_model(model : Element)
 Void function add_code_model(model : Element, export_name : String, code : Element)
+String function read_type(model : Element, name : String)

+ 0 - 1
interface/HUTN/includes/object_operations.alh

@@ -11,4 +11,3 @@ String function readAssociationDestination(model : Element, name : String)
 Element function allAssociationDestinations(model : Element, name : String, association_type : String)
 Element function allAssociationOrigins(model : Element, name : String, association_type : String)
 Element function allowedAssociationsBetween(model : Element, src : String, dst : String)
-String function read_type(model : Element, name : String)

+ 5 - 0
interface/HUTN/includes/typing.alh

@@ -0,0 +1,5 @@
+Element function get_type_mapping_as_dict(model : Element)
+Element function get_elements_typed_by(model : Element, type : String)
+String function read_type(model : Element, name : String)
+Void function retype(model : Element, element : String, type : String)
+Element function new_type_mapping()

+ 4 - 6
models/merge_EPN.alc

@@ -1,17 +1,15 @@
 include "primitives.alh"
+include "modelling.alh"
 
 Boolean function main(model : Element):
 	Element keys
 	String key
 	Element split
-	Element tm
 
-	tm = model["type_mapping"]
-
-	keys = dict_keys(tm)
+	keys = dict_keys(model["model"])
 	while (set_len(keys) > 0):
 		key = set_pop(keys)
-		split = string_split(tm[key], "/")
-		dict_overwrite(tm, key, string_join("Encapsulated_PetriNet/", split[1]))
+		split = string_split(read_type(model, key), "/")
+		retype(model, key, string_join("Encapsulated_PetriNet/", split[1]))
 
 	return True!

+ 14 - 4
wrappers/modelverse.py

@@ -947,11 +947,21 @@ def connections_between(model_name, source_element, target_element):
 
 def define_attribute(model_name, node, attr_name, attr_type):
     """Create a new attribute, which can be instantiated one meta-level below."""
-    raise NotImplementedError()
+    _goto_mode(MODE_MODIFY, model_name)
+
+    _input(["define_attribute", node, attr_name, attr_type])
+    return _handle_output("Success: ", split=" ")
 
 def all_instances(model_name, type_name):
     """Returns a list of all elements of a specific type."""
-    raise NotImplementedError()
+    _goto_mode(MODE_MODIFY, model_name)
+
+    _input(["all_instances", type_name])
+    output = _handle_output("Success: ", split=" ")
+    if output == "":
+        return set([])
+    else:
+        return set(output.split("\n"))
 
 def service_poll(port):
     """Checks whether or not the Modelverse side has any input ready to be processed."""
@@ -961,10 +971,10 @@ def user_name(user, username):
     """Change a user's name."""
     raise NotImplementedError()
 
-def remove_metamodel(model_name, metamodel_name):
+def remove_conformance(model_name, metamodel_name):
     """Remove a metamodel for a model."""
     raise NotImplementedError()
 
-def add_metamodel(model_name, metamodel_name, partial_type_mapping=None):
+def add_conformance(model_name, metamodel_name, partial_type_mapping=None):
     """Add a metamodel for a model."""
     raise NotImplementedError()