Browse Source

Revert "Fully replace the old typing with the new explicit model"

This reverts commit c2e5fae4d40db5ac9fd1e2aae3dced9397cd87f7.
Yentl Van Tendeloo 8 years ago
parent
commit
dc67b0197f

+ 10 - 10
bootstrap/99_core.mvc

@@ -91,43 +91,43 @@ CF core {
 
                 TypeMapping TM_SimpleClassDiagrams {
                     name = "type mappings/formalisms/SimpleClassDiagrams"
-                    location = "models/SimpleClassDiagrams/type_mapping"
+                    location = "models/SimpleClassDiagrams/types"
                     permissions = "221"
                 }
 
                 TypeMapping TM_TypeMapping {
                     name = "type mappings/formalisms/TypeMapping"
-                    location = "models/TypeMapping/type_mapping"
+                    location = "models/TypeMapping/types"
                     permissions = "221"
                 }
 
                 TypeMapping TM_Tracability{
                     name = "type mappings/formalisms/Tracability"
-                    location = "models/Tracability/type_mapping"
+                    location = "models/Tracability/types"
                     permissions = "221"
                 }
 
                 TypeMapping TM_ProcessModel {
                     name = "type mappings/formalisms/ProcessModel"
-                    location = "models/ProcessModel/type_mapping"
+                    location = "models/ProcessModel/types"
                     permissions = "221"
                 }
 
                 TypeMapping TM_ActionLanguage {
                     name = "type mappings/formalisms/ActionLanguage"
-                    location = "models/ActionLanguage/type_mapping"
+                    location = "models/ActionLanguage/types"
                     permissions = "221"
                 }
 
                 TypeMapping TM_ManualOperation {
                     name = "type mappings/formalisms/ManualOperation"
-                    location = "models/ManualOperation/type_mapping"
+                    location = "models/ManualOperation/types"
                     permissions = "221"
                 }
 
                 TypeMapping TM_Bottom {
                     name = "type mappings/formalisms/Bottom"
-                    location = "models/Bottom/type_mapping"
+                    location = "models/Bottom/types"
                     permissions = "221"
                 }
 
@@ -139,7 +139,7 @@ CF core {
 
                 TypeMapping TM_conformance_mv {
                     name = "type mappings/models/conformance_mv"
-                    location = "models/Conformance_MV/type_mapping"
+                    location = "models/Conformance_MV/types"
                     permissions = "221"
                 }
             }
@@ -150,13 +150,13 @@ CF core {
 
                 TypeMapping TM_Core {
                     name = "type mappings/administration/core"
-                    location = "models/core/type_mapping"
+                    location = "models/core/types"
                     permissions = "220"
                 }
 
                 TypeMapping TM_CoreFormalism {
                     name = "type mappings/administration/CoreFormalism"
-                    location = "models/CoreFormalism/type_mapping"
+                    location = "models/CoreFormalism/types"
                     permissions = "221"
                 }
             }

+ 5 - 9
bootstrap/metamodels.alt

@@ -3,6 +3,7 @@ include "object_operations.alh"
 include "library.alh"
 include "conformance_scd.alh"
 include "modelling.alh"
+include "typing.alh"
 
 String function constraint_Natural(model : Element, name : String):
 	Element self
@@ -139,16 +140,9 @@ Element function initialize_SCD(location : String):
 	instantiate_node(scd, "Class", "GlobalConstraint")
 	model_define_attribute(scd, "GlobalConstraint", "global_constraint", False, "ActionLanguage")
 
-	return scd!
-
-Void function create_metamodels():
-	String location_SCD
-	String location_PN
-
-	location_SCD = "models/SimpleClassDiagrams"
-	location_PN = "models/PetriNets"
+	dict_overwrite(scd, "types", get_type_mapping(scd))
 
-	return!
+	return scd!
 
 Void function initialize_AL(scd_location : String, export_location : String):
 	// TODO this should be written in a file-based model and not created like this in the bootstrap
@@ -304,5 +298,7 @@ Void function initialize_AL(scd_location : String, export_location : String):
 	instantiate_attribute(model, "call_params", "target_upper_cardinality", 1)
 	instantiate_attribute(model, "call_last_param", "target_upper_cardinality", 1)
 
+	dict_overwrite(model, "types", get_type_mapping(model))
+
 	export_node(export_location, model)
 	return !

+ 58 - 84
bootstrap/typing.alc

@@ -2,120 +2,94 @@ include "primitives.alh"
 include "utils.alh"
 
 Element function get_type_mapping(model : Element):
-	return model["type_mapping"]!
-
-Void function set_type_mapping(model : Element, type_mapping : Element):
-	dict_overwrite(model, "type_mapping", type_mapping)
-	return!
-
-Element function get_type_mapping_as_dict(model : Element):
-	Float start
-	start = time()
+	// Deserialize dictionary as model
+	Element tm_model
+	tm_model = dict_create()
 
-	Element dict
+	Element m
+	Element mm
+	Element edge
 	Element keys
 	String key
 
-	dict = dict_create()
 	keys = dict_keys(model["type_mapping"])
 
+	while (set_len(keys) > 0):
+		key = set_pop(keys)
+		m = model["model"][key]
+		mm = model["metamodel"]["model"][model["type_mapping"][key]]
+		edge = create_edge(m, mm)
+
+		dict_add_fast(tm_model, cast_id2s(m), m)
+		dict_add_fast(tm_model, cast_id2s(mm), mm)
+		dict_add_fast(tm_model, cast_id2s(edge), edge)
+
+	return tm_model!
+
+Void function set_type_mapping(model : Element, type_mapping_model : Element):
+	// Serialize model to dictionary
+	Element type_mapping
 	Element rev_model
 	Element rev_metamodel
+	Element keys
+	String key
+
+	type_mapping = dict_create()
+	keys = dict_keys(type_mapping_model)
 	rev_model = make_reverse_dictionary(model["model"])
 	rev_metamodel = make_reverse_dictionary(model["metamodel"]["model"])
 
 	while (set_len(keys) > 0):
 		key = set_pop(keys)
-		if (bool_not(bool_or(dict_in_node(rev_model, model["type_mapping"][key]), dict_in_node(rev_metamodel, model["type_mapping"][key])))):
+		if (bool_not(bool_or(dict_in(rev_model, cast_id2s(type_mapping_model[key])), dict_in(rev_metamodel, cast_id2s(type_mapping_model[key]))))):
 			// Element is in neither model or metamodel
 			// Must be a typing link!
 			// So add it
-			dict_add_fast(dict, rev_model[cast_id2s(read_edge_src(model["type_mapping"][key]))], rev_metamodel[cast_id2s(read_edge_dst(model["type_mapping"][key]))])
-
-	log("get_type_mapping_as_dict : 0.0 : " + cast_v2s(time() - start))
-	return dict!
+			dict_add_fast(type_mapping, rev_model[cast_id2s(read_edge_src(type_mapping_model[key]))], rev_metamodel[cast_id2s(read_edge_dst(type_mapping_model[key]))])
 
-String function read_type(model : Element, name : String):
-	Float start
-	start = time()
+	dict_overwrite(model, "type_mapping", type_mapping)
+	return!
 
-	Element m_element
-	Element link
-	Integer nr
-	Element mm_element
+Element function elements_typed_by(model : Element, type_name : String):
 	Element result
+	result = reverseKeyLookupMulti(get_type_mapping_as_dict(model), type_name)
+	return result!
+
+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)):
-		m_element = model["model"][name]
-		nr = read_nr_out(m_element) - 1
-		while (nr >= 0):
-			link = read_out(m_element, nr)
-			if (dict_in(model["type_mapping"], cast_id2s(link))):
-				// Link is in our mapping, so we probably found it...
-				// But ONLY if it is NOT in the model itself
-				if (reverseKeyLookup(model["model"], link) == ""):
-					// It is not, so we actually got it!
-					// Now follow the edge to the type
-					mm_element = read_edge_dst(link)
-
-					result = reverseKeyLookup(model["metamodel"]["model"], mm_element)
-					log("read_type : 0.0 : " + cast_v2s(time() - start))
-					return result!
-			nr = nr - 1
-
-	// Nothing found, so it must not be typed at all
-	log("read_type : 0.0 : " + cast_v2s(time() - start))
-	return ""!
+		if (dict_in(model["type_mapping"], name)):
+			result = model["type_mapping"][name]
+			if (dict_in(model["metamodel"]["model"], result)):
+				return result!
+			else:
+				return ""!
+		else:
+			return ""!
+	else:
+		return ""!
 
 Void function retype(model : Element, element : String, type : String):
-	// Remove previous type
-	Float start
-	start = time()
-	remove_type(model, element)
-
-	// Add element of the model
-	dict_add_fast(model["type_mapping"], cast_id2s(model["model"][element]), model["model"][element])
-
-	// Add element of metamodel if not yet there
-	Element type_entry
-	type_entry = model["metamodel"]["model"][type]
-	if (bool_not(dict_in(model["type_mapping"], cast_id2s(type_entry)))):
-		dict_add_fast(model["type_mapping"], cast_id2s(type_entry), type_entry)
-
-	// Draw a link between them: the typing link
-	Element new_edge
-	new_edge = create_edge(model["model"][element], type_entry)
-	dict_add_fast(model["type_mapping"], cast_id2s(new_edge), new_edge)
-	
-	log("retype : 0.0 : " + cast_v2s(time() - start))
+	// 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!
 
 Void function new_type_mapping(model : Element):
 	if (dict_in(model, "type_mapping")):
 		dict_delete(model, "type_mapping")
-
 	dict_add_fast(model, "type_mapping", dict_create())
-
 	return !
 
 Void function remove_type(model : Element, name : String):
-	Float start
-	start = time()
-	String elem
-
-	elem = cast_id2s(model["model"][name])
-	if (dict_in(model["type_mapping"], elem)):
-		dict_delete(model["type_mapping"], elem)
-
-	log("remove_type : 0.0 : " + cast_v2s(time() - start))
+	dict_delete(model["type_mapping"], name)
 	return !
-
-Element function elements_typed_by(model : Element, type_name : String):
-	Float start
-	Element result
-	start = time()
-
-	result = reverseKeyLookupMulti(get_type_mapping_as_dict(model), type_name)
-
-	log("elements_typed_by : 0.0 : " + cast_v2s(time() - start))
-	return result!

+ 1 - 0
interface/HUTN/hutn_compiler/model_bootstrap_visitor.py

@@ -29,6 +29,7 @@ class ModelBootstrapVisitor(Visitor):
     def visit_start(self, tree):
         for t in tree.get_tail():
             self.visit(t)
+        self.code += '\tdict_overwrite(%s, "types", get_type_mapping(%s))\n' % (self.current_model, self.current_model)
 
     def visit_include_files(self, tree):
         self.includes.append('include %s' % tree.get_children("STRVALUE")[0].get_text())