Преглед изворни кода

Check whether we need to do the cardinalities check, before fetching the instances

Yentl Van Tendeloo пре 9 година
родитељ
комит
10c0ae42ae

+ 22 - 30
bootstrap/conformance_scd.alc

@@ -18,7 +18,7 @@ Boolean function is_nominal_instance(model : Element, instance : String, type :
 		return False
 
 	if (bool_not(dict_in_node(model["type_mapping"], model["model"][instance]))):
-		// Doesn't even have a type
+		// doesn't even have a type
 		return False
 
 	return is_nominal_subtype(model["metamodel"], reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][instance])), type)
@@ -109,30 +109,24 @@ String function conformance_scd(model : Element):
 			log("Check " + model_name)
 			element = model["model"][model_name]
 
-			log("1")
 			if (bool_not(dict_in_node(typing, element))):
 				return "Model has no type specified: " + model_name
 
-			log("2")
 			if (bool_not(set_in_node(metamodel["model"], dict_read_node(typing, element)))):
 				return "Type of element not in specified metamodel: " + model_name
 
-			log("3")
 			if (bool_not(is_nominal_instance(model, model_name, reverseKeyLookup(metamodel["model"], dict_read_node(typing, element))))):
 				return "Element is not an instance of its specified type: " + model_name
 
-			log("4")
 			if (is_edge(element)):
 				src_model = reverseKeyLookup(model["model"], read_edge_src(element))
 				dst_model = reverseKeyLookup(model["model"], read_edge_dst(element))
 				src_metamodel = reverseKeyLookup(metamodel["model"], read_edge_src(dict_read_node(typing, element)))
 				dst_metamodel = reverseKeyLookup(metamodel["model"], read_edge_dst(dict_read_node(typing, element)))
 
-				log("5")
 				if (bool_not(is_nominal_instance(model, src_model, src_metamodel))):
 					return "Source of model edge not typed by source of type: " + model_name
 
-				log("6")
 				if (bool_not(is_nominal_instance(model, dst_model, dst_metamodel))):
 					return "Destination of model edge not typed by source of type: " + model_name
 
@@ -142,41 +136,39 @@ String function conformance_scd(model : Element):
 			//   A  ---------------------> B
 			//
 			// First the incoming, so we are at B in the above figure
-			log("7")
 			check_list = selectPossibleOutgoing(model, model_name, dict_keys(cardinalities))
 			while (0 < list_len(check_list)):
 				check_type = set_pop(check_list)
 				if (dict_in(cardinalities, check_type)):
 					// Cardinalities defined for this association, so check them
-					instances = list_len(allOutgoingAssociationInstances(model, model_name, check_type))
-					if (dict_in(cardinalities[check_type], "tlc")):
-						// A lower cardinality was defined at the target
-						if (integer_gt(cardinalities[check_type]["tlc"], instances)):
-							return "Lower cardinality violation for outgoing edge at " + model_name
-					if (dict_in(cardinalities[check_type], "tuc")):
-						// An upper cardinality was defined at the target
-						if (integer_lt(cardinalities[check_type]["tuc"], instances)):
-							return "Upper cardinality violation for outgoing edge at " + model_name
+					if (bool_or(dict_in(cardinalities[check_type], "tlc"), dict_in(cardinalities[check_type], "tuc"))):
+						instances = list_len(allOutgoingAssociationInstances(model, model_name, check_type))
+						if (dict_in(cardinalities[check_type], "tlc")):
+							// A lower cardinality was defined at the target
+							if (integer_gt(cardinalities[check_type]["tlc"], instances)):
+								return "Lower cardinality violation for outgoing edge at " + model_name
+						if (dict_in(cardinalities[check_type], "tuc")):
+							// An upper cardinality was defined at the target
+							if (integer_lt(cardinalities[check_type]["tuc"], instances)):
+								return "Upper cardinality violation for outgoing edge at " + model_name
 
 			// Identical, but for outgoing, and thus for A in the figure
-			log("8")
 			check_list = selectPossibleIncoming(model, model_name, dict_keys(cardinalities))
 			while (0 < list_len(check_list)):
-				log("LOOP")
 				check_type = set_pop(check_list)
 				if (dict_in(cardinalities, check_type)):
 					// Cardinalities defined for this association, so check them
-					instances = list_len(allIncomingAssociationInstances(model, model_name, check_type))
-					if (dict_in(cardinalities[check_type], "slc")):
-						// A lower cardinality was defined at the source
-						if (integer_gt(cardinalities[check_type]["slc"], instances)):
-							return "Lower cardinality violation for incoming edge at " + model_name
-					if (dict_in(cardinalities[check_type], "suc")):
-						// An upper cardinality was defined at the source
-						if (integer_lt(cardinalities[check_type]["suc"], instances)):
-							return "Upper cardinality violation for incoming edge at " + model_name
-
-			log("10")
+					if (bool_or(dict_in(cardinalities[check_type], "slc"), dict_in(cardinalities[check_type], "suc"))):
+						instances = list_len(allIncomingAssociationInstances(model, model_name, check_type))
+						if (dict_in(cardinalities[check_type], "slc")):
+							// A lower cardinality was defined at the source
+							if (integer_gt(cardinalities[check_type]["slc"], instances)):
+								return "Lower cardinality violation for incoming edge at " + model_name
+						if (dict_in(cardinalities[check_type], "suc")):
+							// An upper cardinality was defined at the source
+							if (integer_lt(cardinalities[check_type]["suc"], instances)):
+								return "Upper cardinality violation for incoming edge at " + model_name
+
 			Element constraint_function
 			constraint_function = read_attribute(metamodel, reverseKeyLookup(metamodel["model"], dict_read_node(typing, element)), "constraint")
 			if (element_neq(constraint_function, read_root())):

+ 4 - 2
bootstrap/modelling.alc

@@ -209,15 +209,17 @@ Element function read_attribute(model : Element, element : String, attribute : S
 	Element edge
 	Element edge_type
 	Element elem
+	Element typing
 
 	elem = model["model"][element]
+	typing = model["type_mapping"]
 	count = read_nr_out(elem)
 
 	i = 0
 	while (i < count):
 		edge = read_out(elem, i)
-		if (dict_in_node(model["type_mapping"], edge)):
-			edge_type = dict_read_node(model["type_mapping"], edge)
+		if (dict_in_node(typing, edge)):
+			edge_type = dict_read_node(typing, edge)
 			if (element_eq(edge_type, dict_read_edge(read_edge_src(edge_type), attribute))):
 				return read_edge_dst(edge)
 		i = i + 1

+ 20 - 27
bootstrap/object_operations.alc

@@ -71,43 +71,36 @@ Element function selectPossibleOutgoing(model : Element, source : String, limit_
 Element function allOutgoingAssociationInstances(model : Element, source_name : String, assoc_name : String):
 	// Read out all outgoing edges of the model and select those that are typed by the specified association
 	// TODO for some reason this crashes if allInstances is used!
-
-	Integer nr_out
-	Integer i
-	Element out
-	String out_name
+	Element assocs
+	String assoc
 	Element result
+	Element source
+
+	assocs = allInstances(model, assoc_name)
+	source = model["model"][source_name]
 
 	result = create_node()
-	nr_out = read_nr_out(model["model"][source_name])
-	i = 0
-	while (i < nr_out):
-		out = read_out(model["model"][source_name], i)
-		if (set_in_node(model["model"], out)):
-			out_name = reverseKeyLookup(model["model"], out)
-			if (is_nominal_instance(model, out_name, assoc_name)):
-				set_add(result, out_name)
-		i = i + 1
+	while (0 < list_len(assocs)):
+		assoc = set_pop(assocs)
+		if (element_eq(source, read_edge_src(model["model"][assoc]))):
+			set_add(result, assoc)
 	return result
 
 Element function allIncomingAssociationInstances(model : Element, target_name : String, assoc_name : String):
 	// Read out all outgoing edges of the model and select those that are typed by the specified association
-	Integer nr_in
-	Integer i
-	Element in
-	String in_name
+	Element assocs
+	String assoc
 	Element result
+	Element target
+
+	assocs = allInstances(model, assoc_name)
+	target = model["model"][target_name]
 
 	result = create_node()
-	nr_in = read_nr_in(model["model"][target_name])
-	i = 0
-	while (i < nr_in):
-		in = read_in(model["model"][target_name], i)
-		if (set_in_node(model["model"], in)):
-			in_name = reverseKeyLookup(model["model"], in)
-			if (is_nominal_instance(model, in_name, assoc_name)):
-				set_add(result, in_name)
-		i = i + 1
+	while (0 < list_len(assocs)):
+		assoc = set_pop(assocs)
+		if (element_eq(target, read_edge_dst(model["model"][assoc]))):
+			set_add(result, assoc)
 	return result
 
 Element function getAttributeList(model : Element, element : String):

+ 0 - 1
interface/HUTN/includes/conformance_scd.alh

@@ -1,6 +1,5 @@
 Boolean function is_direct_instance(model: Element, instance: String, type: String)
 Boolean function is_nominal_instance(model: Element, instance: String, type: String)
-Boolean function is_structural_subtype(subtype: Element, supertype: Element)
 Element function conformance_scd(model: Element)
 Element function set_model_constraints(model: Element, func: Element)
 Element function generate_bottom_type_mapping(model: Element)