瀏覽代碼

Use shorter variable names now that scopes exist

Yentl Van Tendeloo 9 年之前
父節點
當前提交
f909fdb654
共有 1 個文件被更改,包括 179 次插入179 次删除
  1. 179 179
      bootstrap/conformance_scd.alc

+ 179 - 179
bootstrap/conformance_scd.alc

@@ -5,90 +5,90 @@ include "constructors.alh"
 
 Element function set_copy(elem_to_copy : Element):
 	Element result
-	Integer counter_copy
+	Integer i
 	Integer max
 
 	result = create_node()
 
 	// Expand the provided list by including all elements that need to be checked
-	counter_copy = 0
+	i = 0
 	max = read_nr_out(elem_to_copy)
-	while (counter_copy < max):
-		set_add(result, read_edge_dst(read_out(elem_to_copy, counter_copy)))
-		counter_copy = counter_copy + 1
+	while (i < max):
+		set_add(result, read_edge_dst(read_out(elem_to_copy, i)))
+		i = i + 1
 
 	return result
 
-Boolean function is_direct_instance(model_idi : Element, instance_idi : Element, type_idi : 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(dict_read(model_idi, "type_mapping"), instance_idi) == type_idi
+	return dict_read_node(dict_read(model, "type_mapping"), instance) == type
 
-Boolean function is_nominal_instance(model_ini : Element, instance_ini : Element, type_ini : Element):
-	return is_nominal_subtype(type_ini, dict_read_node(dict_read(model_ini, "type_mapping"), instance_ini), dict_read(dict_read(model_ini, "metamodel"), "type_mapping"), dict_read(model_ini, "inheritance"))
+Boolean function is_nominal_instance(model : Element, instance : Element, type : Element):
+	return is_nominal_subtype(type, dict_read_node(dict_read(model, "type_mapping"), instance), dict_read(dict_read(model, "metamodel"), "type_mapping"), dict_read(model, "inheritance"))
 
 Boolean function is_nominal_subtype(superclass : Element, subclass : Element, types : Element, inheritance_link : Element):
-	Integer counter_iso
-	Integer i_iso
-	Element edge_iso
-	Element destination_iso
+	Integer counter
+	Integer i
+	Element edge
+	Element destination
 
 	// End of recursion
 	if (superclass == subclass):
 		return True
 
 	// Iterate over all superclasses of the found class
-	counter_iso = read_nr_out(subclass)
-	i_iso = 0
-	while (i_iso < counter_iso):
-		edge_iso = read_out(subclass, i_iso)
+	counter = read_nr_out(subclass)
+	i = 0
+	while (i < counter):
+		edge = read_out(subclass, i)
 		// Check if it even has a type (to prevent errors)
-		if (dict_in_node(types, edge_iso)):
+		if (dict_in_node(types, edge)):
 			// Check whether it is an inheritance edge, as there is no other distinction between them
-			if (dict_read_node(types, edge_iso) == inheritance_link):
+			if (dict_read_node(types, edge) == inheritance_link):
 				// It is an inheritance edge, so follow it to its destination
-				destination_iso = read_edge_dst(edge_iso)
+				destination = read_edge_dst(edge)
 				// Found a new superclass to test
-				if (is_nominal_subtype(superclass, destination_iso, types, inheritance_link)):
+				if (is_nominal_subtype(superclass, destination, types, inheritance_link)):
 					return True
-		i_iso = i_iso + 1
+		i = i + 1
 	
 	// No link seems to have been found, so it is False
 	return False
 
-Boolean function is_structural_instance(model_isi : Element, instance_isi : Element, type_isi : Element):
-	return is_structural_subtype(dict_read_node(dict_read(model_isi, "type_mapping"), instance_isi), type_isi)
+Boolean function is_structural_instance(model : Element, instance : Element, type : Element):
+	return is_structural_subtype(dict_read_node(dict_read(model, "type_mapping"), instance), type)
 	
-Boolean function is_structural_subtype(subtype_isi : Element, supertype_isi : Element):
+Boolean function is_structural_subtype(subtype : Element, supertype : Element):
 	// Determine whether it is just the exact type or not
-	if (subtype_isi == supertype_isi):
+	if (subtype == supertype):
 		return True
 
 	// Find all links that are required (name and type) from the specified type
-	Element required_keys_isi
-	required_keys_isi = dict_keys(supertype_isi)
-	Integer required_keys_len_isi
-	required_keys_len_isi = dict_len(required_keys_isi)
+	Element required_keys
+	required_keys = dict_keys(supertype)
+	Integer required_keys_len
+	required_keys_len = dict_len(required_keys)
 
-	String key_isi
-	Element equivalent_isi
-	Integer i_isi
-	i_isi = 0
+	String key
+	Element equivalent
+	Integer i
+	i = 0
 
 	// Go over all keys that we require
-	while (i_isi < required_keys_len_isi):
-		key_isi = set_pop(required_keys_isi)
+	while (i < required_keys_len):
+		key = set_pop(required_keys)
 		// Check whether they exist in the instance
-		if (dict_in(subtype_isi, key_isi)):
+		if (dict_in(subtype, key)):
 			// Normally, we should still check whether they don't violate the constraints imposed on the class (i.e., are actually present)
 			// For now, we ignore this and simply require that it is always there in the metamodel (not necessarily in the instance)
 			// TODO
 
 			// Still check whether the types match
-			if (bool_not(is_structural_subtype(dict_read(subtype_isi, key_isi), dict_read(supertype_isi, key_isi)))):
+			if (bool_not(is_structural_subtype(dict_read(subtype, key), dict_read(supertype, key)))):
 				return False
 
 			// All clear, so pass on to the next attribute
-			i_isi = i_isi + 1
+			i = i + 1
 		else:
 			return False
 
@@ -97,7 +97,7 @@ Boolean function is_structural_subtype(subtype_isi : Element, supertype_isi : El
 
 String function conformance_scd(model : Element):
 	// Initialization
-	Element work_conf
+	Element work_node
 	Element model_src
 	Element metamodel_src
 	Element model_dst
@@ -116,33 +116,33 @@ String function conformance_scd(model : Element):
 
 	// Iterate over all model elements and check if they are typed (in "typing") and their type is in the metamodel
 	while (dict_len(models) > 0):
-		work_conf = set_pop(models)
+		work_node = set_pop(models)
 		// Basic check: does the element have a type
-		if (bool_not(dict_in_node(typing, work_conf))):
-			return "Model has no type specified: " + getName(model, work_conf)
+		if (bool_not(dict_in_node(typing, work_node))):
+			return "Model has no type specified: " + getName(model, work_node)
 
 		// Basic check: is the type of the element part of the metamodel
-		if (bool_not(set_in_node(metamodels, dict_read_node(typing, work_conf)))):
-			return "Type of element not in specified metamodel: " + getName(model, work_conf)
+		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_conf), typeof(work_conf)))):
-			return "Primitive type does not agree with actual type: " + getName(model, work_conf)
+		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_conf)):
-			model_src = read_edge_src(work_conf)
-			metamodel_src = read_edge_src(dict_read_node(typing, work_conf))
+		if (is_edge(work_node)):
+			model_src = read_edge_src(work_node)
+			metamodel_src = read_edge_src(dict_read_node(typing, work_node))
 			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_conf)
+				return "Source of model edge not typed by source of type: " + getName(model, work_node)
 
 		// For edges only: check whether the destination is typed according to the metamodel
-		if (is_edge(work_conf)):
-			model_dst = read_edge_dst(work_conf)
-			metamodel_dst = read_edge_dst(dict_read_node(typing, work_conf))
+		if (is_edge(work_node)):
+			model_dst = read_edge_dst(work_node)
+			metamodel_dst = read_edge_dst(dict_read_node(typing, work_node))
 			if (bool_not(is_nominal_instance(model, model_dst, metamodel_dst))):
-				return "Destination of model edge not typed by destination of type: " + getName(model, work_conf)
+				return "Destination of model edge not typed by destination of type: " + getName(model, work_node)
 
 	// Structure seems fine, now do static semantics
 	if (dict_in(dict_read(model, "metamodel"), "constraints")):
@@ -152,164 +152,164 @@ String function conformance_scd(model : Element):
 	else:
 		return "OK"
 
-Element function retype(model_rt : Element, metamodel_rt : Element, inheritance_rt : Element, mapping_rt : Element):
-	if (dict_in(model_rt, "type_mapping")):
+Element function retype(model : Element, metamodel : Element, inheritance : Element, mapping : Element):
+	if (dict_in(model, "type_mapping")):
 		// Remove previous type mappings
-		dict_delete(model_rt, "type_mapping")
-	if (dict_in(model_rt, "metamodel")):
+		dict_delete(model, "type_mapping")
+	if (dict_in(model, "metamodel")):
 		// Remove the previous metamodel too, as this might change too
-		dict_delete(model_rt, "metamodel")
-	if (dict_in(model_rt, "inheritance")):
+		dict_delete(model, "metamodel")
+	if (dict_in(model, "inheritance")):
 		// Remove the inheritance link too, as, yet again, this can vary
-		dict_delete(model_rt, "inheritance")
+		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_rt, "metamodel", metamodel_rt)
-	dict_add(model_rt, "inheritance", inheritance_rt)
-	dict_add(model_rt, "type_mapping", mapping_rt)
+	dict_add(model, "metamodel", metamodel)
+	dict_add(model, "inheritance", inheritance)
+	dict_add(model, "type_mapping", mapping)
 
-	return model_rt
+	return model
 
-Element function add_to_model(model_atm : Element, name_atm : String, element_atm : Element):
-	if (name_atm == ""):
+Element function add_to_model(model : Element, name : String, element : Element):
+	if (name == ""):
 		// No name desired
-		dict_add(dict_read(model_atm, "model"), "__" + cast_id2s(element_atm), element_atm)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(element), element)
 	else:
-		dict_add(dict_read(model_atm, "model"), name_atm, element_atm)
-	return element_atm
-
-Element function instantiate_bottom_node(model_bn : Element, name_bn : String):
-	Element new_element_bn
-	new_element_bn = create_node()
-	return add_to_model(model_bn, name_bn, new_element_bn)
-
-Element function instantiate_bottom_value(model_bv : Element, name_bv : String, value_bv : Element):
-	Element new_element_bv
-	new_element_bv = create_value(value_bv)
-	return add_to_model(model_bv, name_bv, new_element_bv)
-
-Element function instantiate_bottom_edge(model_be : Element, name_be : String, source_be : Element, target_be : Element):
-	Element new_element_be
-	new_element_be = create_edge(source_be, target_be)
-	return add_to_model(model_be, name_be, new_element_be)
-
-Element function set_model_constraints(model_con : Element, func_con : Element):
-	if (dict_in(model_con, "constraints")):
-		dict_delete(model_con, "constraints")
-	dict_add(model_con, "constraints", func_con)
-	return model_con
-
-Element function instantiate_model_lib(model_mo : Element, type_mo : Element, name_mo : String, optionals : Element, attribute_types : Element, attribute_instances : Element):
-	Element new_element_mo
-	if (is_edge(type_mo)):
+		dict_add(dict_read(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_mo = instantiate_bottom_edge(model_mo, name_mo, list_read(optionals, 0), list_read(optionals, 1))
+		new_element = instantiate_bottom_edge(model, name, list_read(optionals, 0), list_read(optionals, 1))
 	else:
-		if (typeof(type_mo) == Type):
-			new_element_mo = instantiate_bottom_value(model_mo, name_mo, list_read(optionals, 0))
+		if (typeof(type) == Type):
+			new_element = instantiate_bottom_value(model, name, list_read(optionals, 0))
 		else:
-			new_element_mo = instantiate_bottom_node(model_mo, name_mo)
+			new_element = instantiate_bottom_node(model, name)
 
 	// Add it to the type mapping
-	dict_add(dict_read(model_mo, "type_mapping"), new_element_mo, type_mo)
+	dict_add(dict_read(model, "type_mapping"), new_element, type)
 
 	// Add all attribute types at this level
-	Integer counter_mo
-	Integer max_mo
-	Element keys_mo
-	keys_mo = dict_keys(attribute_types)
-	counter_mo = 0
-	max_mo = list_len(keys_mo)
-
-	Element attr_name_mo
-	Element attr_type_mo
-	Element created_attr_mo
-	Element created_edge_mo
-	Element metamodel_mo
-	metamodel_mo = dict_read(dict_read(model_mo, "metamodel"), "model")
+	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 = dict_read(dict_read(model, "metamodel"), "model")
 
 	// For all new attributes
-	while (counter_mo < max_mo):
-		attr_name_mo = set_pop(keys_mo)
-		attr_type_mo = dict_read(attribute_types, attr_name_mo)
+	while (counter < max):
+		attr_name = set_pop(keys)
+		attr_type = dict_read(attribute_types, attr_name)
 
-		created_attr_mo = create_edge(new_element_mo, attr_type_mo)
-		created_edge_mo = create_edge(created_attr_mo, attr_name_mo)
+		created_attr = create_edge(new_element, attr_type)
+		created_edge = create_edge(created_attr, attr_name)
 		
 		// Add it to the model
-		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_name_mo), attr_name_mo)
-		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_type_mo), attr_type_mo)
-		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(created_attr_mo), created_attr_mo)
-		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(created_edge_mo), created_edge_mo)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_name), attr_name)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_type), attr_type)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(created_attr), created_attr)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(created_edge), created_edge)
 
 		// And add the typing
-		dict_add(dict_read(model_mo, "type_mapping"), attr_name_mo, dict_read(metamodel_mo, "__String"))
-		dict_add(dict_read(model_mo, "type_mapping"), attr_type_mo, dict_read(metamodel_mo, "Type"))
-		dict_add(dict_read(model_mo, "type_mapping"), created_attr_mo, dict_read(metamodel_mo, "Attribute"))
-		dict_add(dict_read(model_mo, "type_mapping"), created_edge_mo, dict_read(metamodel_mo, "__Name"))
+		dict_add(dict_read(model, "type_mapping"), attr_name, dict_read(metamodel, "__String"))
+		dict_add(dict_read(model, "type_mapping"), attr_type, dict_read(metamodel, "Type"))
+		dict_add(dict_read(model, "type_mapping"), created_attr, dict_read(metamodel, "Attribute"))
+		dict_add(dict_read(model, "type_mapping"), created_edge, dict_read(metamodel, "__Name"))
 
 		// Increase while loop counter
-		counter_mo = counter_mo + 1
+		counter = counter + 1
 
 	// Similarly for instantiated attributes
-	counter_mo = 0
-	keys_mo = dict_keys(attribute_instances)
-	max_mo = list_len(keys_mo)
-	Element attr_definer_class_mo
-	Element attr_type_edge_mo
-	Element attr_value_mo
-	Element attr_edge_mo
-
-	while (counter_mo < max_mo):
+	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_mo = set_pop(keys_mo)
-		attr_value_mo = dict_read(attribute_instances, attr_name_mo)
-		attr_definer_class_mo = find_attribute(type_mo, attr_name_mo, dict_read(dict_read(model_mo, "metamodel"), "type_mapping"), dict_read(model_mo, "inheritance"))
-		attr_type_mo = dict_read(attr_definer_class_mo, attr_name_mo)
-		attr_type_edge_mo = dict_read_edge(attr_definer_class_mo, attr_name_mo)
-		attr_edge_mo = create_edge(new_element_mo, attr_value_mo)
+		attr_name = set_pop(keys)
+		attr_value = dict_read(attribute_instances, attr_name)
+		attr_definer_class = find_attribute(type, attr_name, dict_read(dict_read(model, "metamodel"), "type_mapping"), dict_read(model, "inheritance"))
+		attr_type = dict_read(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(dict_read(model_mo, "model"), "__" + cast_id2s(attr_value_mo), attr_value_mo)
-		dict_add(dict_read(model_mo, "model"), "__" + cast_id2s(attr_edge_mo), attr_edge_mo)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_value), attr_value)
+		dict_add(dict_read(model, "model"), "__" + cast_id2s(attr_edge), attr_edge)
 
 		// Type the new elements
-		dict_add(dict_read(model_mo, "type_mapping"), attr_value_mo, attr_type_mo)
-		dict_add(dict_read(model_mo, "type_mapping"), attr_edge_mo, attr_type_edge_mo)
-
-		counter_mo = counter_mo + 1
-
-	return new_element_mo
-
-Element function instantiate_new_model(metamodel_inm : Element, inheritance_inm : Element):
-	Element model_inm
-	model_inm = create_node()
-	dict_add(model_inm, "model", create_node())
-	dict_add(model_inm, "type_mapping", create_node())
-	dict_add(model_inm, "metamodel", metamodel_inm)
-	dict_add(model_inm, "inheritance", inheritance_inm)
-	return model_inm
-
-Element function generate_bottom_type_mapping(model_tm : Element):
-	Element mm_tm
-	mm_tm = dict_read(dict_read(model_tm, "metamodel"), "model")
-	dict_delete(model_tm, "type_mapping")
-	Element tm_tm
-	tm_tm = create_node()
-	dict_add(model_tm, "type_mapping", tm_tm)
+		dict_add(dict_read(model, "type_mapping"), attr_value, attr_type)
+		dict_add(dict_read(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 = dict_read(dict_read(model, "metamodel"), "model")
+	dict_delete(model, "type_mapping")
+	Element tm
+	tm = create_node()
+	dict_add(model, "type_mapping", tm)
 	
 	// Iterate over every element
-	Element elem_keys_tm
-	Element elem_tm
-	elem_keys_tm = dict_keys(dict_read(model_tm, "model"))
-	while (0 < read_nr_out(elem_keys_tm)):
-		elem_tm = dict_read(dict_read(model_tm, "model"), set_pop(elem_keys_tm))
-		if (is_edge(elem_tm)):
-			dict_add(tm_tm, elem_tm, dict_read(mm_tm, "Edge"))
+	Element elem_keys
+	Element elem
+	elem_keys = dict_keys(dict_read(model, "model"))
+	while (0 < read_nr_out(elem_keys)):
+		elem = dict_read(dict_read(model, "model"), set_pop(elem_keys))
+		if (is_edge(elem)):
+			dict_add(tm, elem, dict_read(mm, "Edge"))
 		else:
-			if (cast_v2s(elem_tm) != "None"):
-				dict_add(tm_tm, elem_tm, dict_read(mm_tm, cast_v2s(typeof(elem_tm))))
+			if (cast_v2s(elem) != "None"):
+				dict_add(tm, elem, dict_read(mm, cast_v2s(typeof(elem))))
 			else:
-				dict_add(tm_tm, elem_tm, dict_read(mm_tm, "Node"))
+				dict_add(tm, elem, dict_read(mm, "Node"))
 
-	return model_tm
+	return model