Quellcode durchsuchen

Fixed similar problems of == and element_eq mix-ups

Yentl Van Tendeloo vor 9 Jahren
Ursprung
Commit
ac988bb2d0
1 geänderte Dateien mit 4 neuen und 148 gelöschten Zeilen
  1. 4 148
      bootstrap/conformance_scd.alc

+ 4 - 148
bootstrap/conformance_scd.alc

@@ -21,7 +21,7 @@ Element function set_copy(elem_to_copy : Element):
 
 Boolean function is_direct_instance(model : Element, instance : Element, type : Element):
 	// Just check whether or not the type mapping specifies the type as the type of the instance
-	return dict_read_node(model["type_mapping"], instance) == type
+	return element_eq(dict_read_node(model["type_mapping"], instance), type)
 
 Boolean function is_nominal_instance(model : Element, instance : Element, type : Element):
 	return is_nominal_subtype(type, dict_read_node(model["type_mapping"], instance), model["metamodel"]["type_mapping"], model["inheritance"])
@@ -60,7 +60,7 @@ Boolean function is_structural_instance(model : Element, instance : Element, typ
 	
 Boolean function is_structural_subtype(subtype : Element, supertype : Element):
 	// Determine whether it is just the exact type or not
-	if (subtype == supertype):
+	if (element_eq(subtype, supertype)):
 		return True
 
 	// Find all links that are required (name and type) from the specified type
@@ -125,15 +125,11 @@ String function conformance_scd(model : Element):
 		if (bool_not(set_in_node(metamodels, dict_read_node(typing, work_node)))):
 			return "Type of element not in specified metamodel: " + getName(model, work_node)
 
-		// Basic check: type of the value agrees with the actual type
-		// this is always checked, as it falls back to a sane default for non-values
-		if (bool_not(type_eq(dict_read_node(typing, work_node), typeof(work_node)))):
-			return "Primitive type does not agree with actual type: " + getName(model, work_node)
-
 		// For edges only: check whether the source is typed according to the metamodel
 		if (is_edge(work_node)):
 			model_src = read_edge_src(work_node)
 			metamodel_src = read_edge_src(dict_read_node(typing, work_node))
+			log((getName(model, model_src) + " : ") + getName(model["metamodel"], metamodel_src))
 			if (bool_not(is_nominal_instance(model, model_src, metamodel_src))):
 				return "Source of model edge not typed by source of type: " + getName(model, work_node)
 
@@ -152,149 +148,12 @@ String function conformance_scd(model : Element):
 	else:
 		return "OK"
 
-Element function retype(model : Element, metamodel : Element, inheritance : Element, mapping : Element):
-	if (dict_in(model, "type_mapping")):
-		// Remove previous type mappings
-		dict_delete(model, "type_mapping")
-	if (dict_in(model, "metamodel")):
-		// Remove the previous metamodel too, as this might change too
-		dict_delete(model, "metamodel")
-	if (dict_in(model, "inheritance")):
-		// Remove the inheritance link too, as, yet again, this can vary
-		dict_delete(model, "inheritance")
-	
-	// Start the new configuration of the metamodel and inheritance link, as well as set the new mapping relation
-	dict_add(model, "metamodel", metamodel)
-	dict_add(model, "inheritance", inheritance)
-	dict_add(model, "type_mapping", mapping)
-
-	return model
-
-Element function add_to_model(model : Element, name : String, element : Element):
-	if (name == ""):
-		// No name desired
-		dict_add(model["model"], "__" + cast_id2s(element), element)
-	else:
-		dict_add(model["model"], name, element)
-	return element
-
-Element function instantiate_bottom_node(model : Element, name : String):
-	Element new_element
-	new_element = create_node()
-	return add_to_model(model, name, new_element)
-
-Element function instantiate_bottom_value(model : Element, name : String, value : Element):
-	Element new_element
-	new_element = create_value(value)
-	return add_to_model(model, name, new_element)
-
-Element function instantiate_bottom_edge(model : Element, name : String, source : Element, target : Element):
-	Element new_element
-	new_element = create_edge(source, target)
-	return add_to_model(model, name, new_element)
-
 Element function set_model_constraints(model : Element, func : Element):
 	if (dict_in(model, "constraints")):
 		dict_delete(model, "constraints")
 	dict_add(model, "constraints", func)
 	return model
 
-Element function instantiate_model_lib(model : Element, type : Element, name : String, optionals : Element, attribute_types : Element, attribute_instances : Element):
-	Element new_element
-	if (is_edge(type)):
-		// Create a new edge from "optionals[0]" to "optionals[1]"
-		new_element = instantiate_bottom_edge(model, name, list_read(optionals, 0), list_read(optionals, 1))
-	else:
-		if (typeof(type) == Type):
-			new_element = instantiate_bottom_value(model, name, list_read(optionals, 0))
-		else:
-			new_element = instantiate_bottom_node(model, name)
-
-	// Add it to the type mapping
-	dict_add(model["type_mapping"], new_element, type)
-
-	// Add all attribute types at this level
-	Integer counter
-	Integer max
-	Element keys
-	keys = dict_keys(attribute_types)
-	counter = 0
-	max = list_len(keys)
-
-	Element attr_name
-	Element attr_type
-	Element created_attr
-	Element created_edge
-	Element metamodel
-	metamodel = model["metamodel"]["model"]
-
-	// For all new attributes
-	while (counter < max):
-		attr_name = set_pop(keys)
-		attr_type = attribute_types[attr_name]
-
-		created_attr = create_edge(new_element, attr_type)
-		created_edge = create_edge(created_attr, attr_name)
-		
-		Element m
-		Element tm
-		m = model["model"]
-		tm = model["type_mapping"]
-
-		// Add it to the model
-		dict_add(m, "__" + cast_id2s(attr_name), attr_name)
-		dict_add(m, "__" + cast_id2s(attr_type), attr_type)
-		dict_add(m, "__" + cast_id2s(created_attr), created_attr)
-		dict_add(m, "__" + cast_id2s(created_edge), created_edge)
-
-		// And add the typing
-		dict_add(tm, attr_name, metamodel["__String"])
-		dict_add(tm, attr_type, metamodel["Type"])
-		dict_add(tm, created_attr, metamodel["Attribute"])
-		dict_add(tm, created_edge, metamodel["__Name"])
-
-		// Increase while loop counter
-		counter = counter + 1
-
-	// Similarly for instantiated attributes
-	counter = 0
-	keys = dict_keys(attribute_instances)
-	max = list_len(keys)
-	Element attr_definer_class
-	Element attr_type_edge
-	Element attr_value
-	Element attr_edge
-
-	while (counter < max):
-		// Look it up
-		attr_name = set_pop(keys)
-		attr_value = attribute_instances[attr_name]
-		attr_definer_class = find_attribute(type, attr_name, model["metamodel"]["type_mapping"], model["inheritance"])
-		attr_type = attr_definer_class[attr_name]
-		attr_type_edge = dict_read_edge(attr_definer_class, attr_name)
-		attr_edge = create_edge(new_element, attr_value)
-
-		// Add to model
-		dict_add(model["model"], "__" + cast_id2s(attr_value), attr_value)
-		dict_add(model["model"], "__" + cast_id2s(attr_edge), attr_edge)
-
-		// Type the new elements
-		dict_add(model["type_mapping"], attr_value, attr_type)
-		dict_add(model["type_mapping"], attr_edge, attr_type_edge)
-
-		counter = counter + 1
-
-	return new_element
-
-Element function instantiate_new_model(metamodel : Element, inheritance : Element):
-	Element model
-	model = create_node()
-	dict_add(model, "model", create_node())
-	dict_add(model, "type_mapping", create_node())
-	dict_add(model, "metamodel", metamodel)
-	dict_add(model, "inheritance", inheritance)
-	return model
-
 Element function generate_bottom_type_mapping(model : Element):
 	Element mm
 	mm = model["metamodel"]["model"]
@@ -312,9 +171,6 @@ Element function generate_bottom_type_mapping(model : Element):
 		if (is_edge(elem)):
 			dict_add(tm, elem, mm["Edge"])
 		else:
-			if (cast_v2s(elem) != "None"):
-				dict_add(tm, elem, mm[cast_v2s(typeof(elem))])
-			else:
-				dict_add(tm, elem, mm["Node"])
+			dict_add(tm, elem, mm["Node"])
 
 	return model