Browse Source

Minor optimizations

Yentl Van Tendeloo 7 years ago
parent
commit
4054a58f14
2 changed files with 42 additions and 8 deletions
  1. 41 7
      bootstrap/typing.alc
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 41 - 7
bootstrap/typing.alc

@@ -14,16 +14,23 @@ Element function get_type_mapping(model : Element):
 	String m_name
 	String m_name
 	String mm_name
 	String mm_name
 
 
+	Element m_model
+	Element mm_model
+	Element tm
+	m_model = model["model"]
+	mm_model = model["metamodel"]["model"]
+	tm = model["type_mapping"]
+
 	keys = dict_keys(model["type_mapping"])
 	keys = dict_keys(model["type_mapping"])
 
 
 	while (set_len(keys) > 0):
 	while (set_len(keys) > 0):
 		key = set_pop(keys)
 		key = set_pop(keys)
-		m = model["model"][key]
-		mm = model["metamodel"]["model"][model["type_mapping"][key]]
+		m = m_model[key]
+		mm = mm_model[tm[key]]
 		edge = create_edge(m, mm)
 		edge = create_edge(m, mm)
 
 
 		m_name = "instance_" + key
 		m_name = "instance_" + key
-		mm_name = "type_" + cast_string(model["type_mapping"][key])
+		mm_name = "type_" + cast_string(tm[key])
 		dict_add_fast(tm_model, m_name, m)
 		dict_add_fast(tm_model, m_name, m)
 		if (bool_not(dict_in(tm_model, mm_name))):
 		if (bool_not(dict_in(tm_model, mm_name))):
 			dict_add_fast(tm_model, mm_name, mm)
 			dict_add_fast(tm_model, mm_name, mm)
@@ -41,14 +48,36 @@ Void function set_type_mapping(model : Element, type_mapping_model : Element):
 	String tmp_source_name
 	String tmp_source_name
 	String tmp_destination_name
 	String tmp_destination_name
 	Element lookups
 	Element lookups
+	String value
+	String src_id
+	String dst_id
+	Element mm_model
+	Element m_model
+	m_model = model["model"]
+	mm_model = model["metamodel"]["model"]
 
 
 	type_mapping = dict_create()
 	type_mapping = dict_create()
 	keys = dict_keys(type_mapping_model)
 	keys = dict_keys(type_mapping_model)
 
 
+	Element reverse_mapping
+	reverse_mapping = dict_create()
+
+	while (set_len(keys) > 0):
+		key = set_pop(keys)
+		value = cast_id(type_mapping_model[key])
+
+		if (bool_not(dict_in(reverse_mapping, value))):
+			dict_add(reverse_mapping, value, set_create())
+		set_add(reverse_mapping[value], key)
+
+	keys = dict_keys(type_mapping_model)
 	while (set_len(keys) > 0):
 	while (set_len(keys) > 0):
 		key = set_pop(keys)
 		key = set_pop(keys)
 		if (is_edge(type_mapping_model[key])):
 		if (is_edge(type_mapping_model[key])):
-			lookups = reverseKeyLookupMultiID(type_mapping_model, read_edge_src(type_mapping_model[key]))
+			src_id = cast_id(read_edge_src(type_mapping_model[key]))
+			if (bool_not(dict_in(reverse_mapping, src_id))):
+				continue!
+			lookups = set_copy(reverse_mapping[src_id])
 			source_name = ""
 			source_name = ""
 			while (set_len(lookups) > 0):
 			while (set_len(lookups) > 0):
 				tmp_source_name = set_pop(lookups)
 				tmp_source_name = set_pop(lookups)
@@ -56,7 +85,10 @@ Void function set_type_mapping(model : Element, type_mapping_model : Element):
 					source_name = string_replace(tmp_source_name, "instance_", "")
 					source_name = string_replace(tmp_source_name, "instance_", "")
 					break!
 					break!
 
 
-			lookups = reverseKeyLookupMultiID(type_mapping_model, read_edge_dst(type_mapping_model[key]))
+			dst_id = cast_id(read_edge_dst(type_mapping_model[key]))
+			if (bool_not(dict_in(reverse_mapping, dst_id))):
+				continue!
+			lookups = set_copy(reverse_mapping[dst_id])
 			destination_name = ""
 			destination_name = ""
 			while (set_len(lookups) > 0):
 			while (set_len(lookups) > 0):
 				tmp_destination_name = set_pop(lookups)
 				tmp_destination_name = set_pop(lookups)
@@ -64,7 +96,7 @@ Void function set_type_mapping(model : Element, type_mapping_model : Element):
 					destination_name = string_replace(tmp_destination_name, "type_", "")
 					destination_name = string_replace(tmp_destination_name, "type_", "")
 					break!
 					break!
 
 
-			if (bool_and(dict_in(model["model"], source_name), dict_in(model["metamodel"]["model"], destination_name))):
+			if (bool_and(dict_in(m_model, source_name), dict_in(mm_model, destination_name))):
 				// Element is in neither model or metamodel
 				// Element is in neither model or metamodel
 				// Must be a typing link!
 				// Must be a typing link!
 				// So add it
 				// So add it
@@ -77,12 +109,14 @@ Element function elements_typed_by(model : Element, type_name : String):
 	Element result
 	Element result
 	Element temp_result
 	Element temp_result
 	String temp
 	String temp
+	Element m_model
 
 
+	m_model = model["model"]
 	result = set_create()
 	result = set_create()
 	temp_result = reverseKeyLookupMultiValue(get_type_mapping_as_dict(model), type_name)
 	temp_result = reverseKeyLookupMultiValue(get_type_mapping_as_dict(model), type_name)
 	while (set_len(temp_result) > 0):
 	while (set_len(temp_result) > 0):
 		temp = set_pop(temp_result)
 		temp = set_pop(temp_result)
-		if (dict_in(model["model"], temp)):
+		if (dict_in(m_model, temp)):
 			set_add(result, temp)
 			set_add(result, temp)
 	return result!
 	return result!
 
 

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Fri May 25 10:59:57 2018
+Date:   Fri May 25 12:42:46 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server