瀏覽代碼

Merged in NEW type mapping without causing crashes

Yentl Van Tendeloo 8 年之前
父節點
當前提交
45079ad665
共有 4 個文件被更改,包括 27 次插入20 次删除
  1. 17 13
      bootstrap/modelling.alc
  2. 2 2
      bootstrap/transform.alc
  3. 5 5
      bootstrap/typing.alc
  4. 3 0
      state/modelverse_state/main.py

+ 17 - 13
bootstrap/modelling.alc

@@ -142,7 +142,7 @@ String function find_attribute_type(model : Element, elem : String, name : Strin
 	
 	mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
 
-	if (value_eq(mm_elem, "")):
+	if (mm_elem == ""):
 		// Couldn't find element, so is not allowed!
 		return ""!
 	else:
@@ -186,6 +186,7 @@ Element function get_superclasses(model : Element, name : String):
 	Element edge
 	String elem
 	Element nodes
+	String edge_name
 
 	nodes = set_create()
 	set_add(nodes, name)
@@ -202,8 +203,9 @@ Element function get_superclasses(model : Element, name : String):
 			j = 0
 			while (j < num_edges):
 				edge = read_out(model["model"][elem], j)
-				if (dict_in(model["model"], reverseKeyLookup(model["model"], edge))):
-					if (read_type(model, reverseKeyLookup(model["model"], edge)) == "Inheritance"):
+				edge_name = reverseKeyLookup(model["model"], edge)
+				if (edge_name != ""):
+					if (read_type(model, edge_name) == "Inheritance"):
 						set_add(nodes, reverseKeyLookup(model["model"], read_edge_dst(edge)))
 				j = j + 1
 
@@ -215,18 +217,22 @@ String function find_attribute_definer(model : Element, elem_name : String, name
 	Integer nr_out
 	Element out
 	String name_attr
+	String elem
 
 	superclasses = get_superclasses(model, elem_name)
 	while (set_len(superclasses) > 0):
 		current = set_pop(superclasses)
 		
+		// TODO is it possible to use allOutgoingAssociationInstances here?
 		nr_out = read_nr_out(model["model"][current])
 		while (nr_out > 0):
 			nr_out = nr_out - 1
 			out = read_out(model["model"][current], nr_out)
-			name_attr = read_attribute(model, reverseKeyLookup(model["model"], out), "name")
-			if (name_attr == name):
-				return current!
+			elem = reverseKeyLookup(model["model"], out)
+			if (elem != ""):
+				name_attr = read_attribute(model, elem, "name")
+				if (name_attr == name):
+					return current!
 
 	return ""!
 
@@ -242,9 +248,6 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 	attr_type = find_attribute_type(model, element, attribute_name)
 
 	if (attr_type == ""):
-		log("Could not find attribute " + cast_v2s(attribute_name))
-		log("For element " + element)
-		log("Type: " + read_type(model, element))
 		return!
 
 	if (has_value(value)):
@@ -384,7 +387,7 @@ Element function read_attribute(model : Element, element : String, attribute : S
 		Element edge
 		Element edge_type
 		Element elem
-		Element name
+		String name
 
 		elem = model["model"][element]
 		count = read_nr_out(elem)
@@ -393,9 +396,10 @@ Element function read_attribute(model : Element, element : String, attribute : S
 		while (i < count):
 			edge = read_out(elem, i)
 			name = reverseKeyLookup(model["model"], 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)!
+			if (name != ""):
+				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:

+ 2 - 2
bootstrap/transform.alc

@@ -355,8 +355,8 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	String new_name
 	Element RHS_map
 	String tmp
-	Element value
-	Element action
+	String value
+	String action
 	Element original_RHS_labels
 
 	Element reverse

+ 5 - 5
bootstrap/typing.alc

@@ -2,7 +2,7 @@ include "primitives.alh"
 include "utils.alh"
 
 Element function get_type_mapping_as_dict(model : Element):
-	//NEW_get_type_mapping_as_dict(model)
+	NEW_get_type_mapping_as_dict(model)
 	return OLD_get_type_mapping_as_dict(model)!
 
 String function read_type(model : Element, name : String):
@@ -10,7 +10,7 @@ String function read_type(model : Element, name : String):
 	return OLD_read_type(model, name)!
 
 Void function retype(model : Element, element : String, type : String):
-	//NEW_retype(model, element, type)
+	NEW_retype(model, element, type)
 	OLD_retype(model, element, type)
 	return!
 
@@ -44,12 +44,12 @@ Element function NEW_get_type_mapping_as_dict(model : Element):
 	rev_metamodel = make_reverse_dictionary(model["metamodel"]["model"])
 
 	while (set_len(keys) > 0):
-		key = set_pop(key)
+		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])))):
 			// Element is in neither model or metamodel
 			// Must be a typing link!
 			// So add it
-			dict_add_fast(dict, rev_model[model["type_mapping"][key]], rev_metamodel[model["type_mapping"][key]])
+			dict_add_fast(dict, dict_read_node(rev_model, read_edge_src(model["type_mapping"][key])), dict_read_node(rev_metamodel, read_edge_dst(model["type_mapping"][key])))
 
 	return dict!
 
@@ -80,7 +80,7 @@ String function NEW_read_type(model : Element, name : String):
 
 Void function NEW_retype(model : Element, element : String, type : String):
 	// Remove previous type
-	NEW_remove_type(model, element)
+	//NEW_remove_type(model, element)
 
 	// Add element of the model
 	dict_add_fast(model["type_mapping"], cast_id2s(model["model"][element]), model["model"][element])

+ 3 - 0
state/modelverse_state/main.py

@@ -222,6 +222,9 @@ class ModelverseState(object):
         except KeyError:
             # Didn't exist
             pass
+        except:
+            print(locals())
+            raise
         return None
 
     def read_dict_keys(self, node):