浏览代码

Minor optimizations

Yentl Van Tendeloo 7 年之前
父节点
当前提交
4054a58f14
共有 2 个文件被更改,包括 42 次插入8 次删除
  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 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"])
 
 	while (set_len(keys) > 0):
 		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)
 
 		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)
 		if (bool_not(dict_in(tm_model, mm_name))):
 			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_destination_name
 	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()
 	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):
 		key = set_pop(keys)
 		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 = ""
 			while (set_len(lookups) > 0):
 				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_", "")
 					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 = ""
 			while (set_len(lookups) > 0):
 				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_", "")
 					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
 				// Must be a typing link!
 				// So add it
@@ -77,12 +109,14 @@ Element function elements_typed_by(model : Element, type_name : String):
 	Element result
 	Element temp_result
 	String temp
+	Element m_model
 
+	m_model = model["model"]
 	result = set_create()
 	temp_result = reverseKeyLookupMultiValue(get_type_mapping_as_dict(model), type_name)
 	while (set_len(temp_result) > 0):
 		temp = set_pop(temp_result)
-		if (dict_in(model["model"], temp)):
+		if (dict_in(m_model, temp)):
 			set_add(result, temp)
 	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)
 
-Date:   Fri May 25 10:59:57 2018
+Date:   Fri May 25 12:42:46 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server