Browse Source

Fixed some more bugs related to the new type_mapping

Yentl Van Tendeloo 8 years ago
parent
commit
135689558b

BIN
bootstrap/bootstrap.m.gz


+ 3 - 8
bootstrap/conformance_scd.alc

@@ -110,6 +110,7 @@ String function conformance_scd(model : Element):
 		while (0 < list_len(keys)):
 			model_name = set_pop(keys)
 			type_name = read_type(model, model_name)
+			element = model["model"][model_name]
 
 			log("Check " + model_name)
 			log("   : " + type_name)
@@ -123,8 +124,8 @@ String function conformance_scd(model : Element):
 			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(model["model"][typing[model_name]]))
-				dst_metamodel = reverseKeyLookup(metamodel["model"], read_edge_dst(model["model"][typing[model_name]]))
+				src_metamodel = reverseKeyLookup(metamodel["model"], read_edge_src(metamodel["model"][typing[model_name]]))
+				dst_metamodel = reverseKeyLookup(metamodel["model"], read_edge_dst(metamodel["model"][typing[model_name]]))
 
 				if (bool_not(is_nominal_instance(model, src_model, src_metamodel))):
 					return "Source of model edge not typed by source of type: " + model_info(model, model_name)!
@@ -141,9 +142,7 @@ String function conformance_scd(model : Element):
 			if (bool_not(dict_in(spo_cache, type_name))):
 				dict_add(spo_cache, type_name, selectPossibleOutgoing(metamodel, type_name, dict_keys(cardinalities)))
 
-			log("Set copy")
 			check_list = set_copy(spo_cache[type_name])
-			log("Done: " + cast_v2s(read_nr_out(check_list)))
 			while (0 < list_len(check_list)):
 				check_type = set_pop(check_list)
 				if (dict_in(cardinalities, check_type)):
@@ -162,15 +161,12 @@ String function conformance_scd(model : Element):
 								String error
 								error = (("Upper cardinality violation for outgoing edge of type " + check_type) + " at ") + model_info(model, model_name)
 								return error!
-			log("List iter OK")
 
 			// Identical, but for outgoing, and thus for A in the figure
 			if (bool_not(dict_in(spi_cache, type_name))):
 				dict_add(spi_cache, type_name, selectPossibleIncoming(metamodel, type_name, dict_keys(cardinalities)))
 
-			log("Set copy 2")
 			check_list = set_copy(spi_cache[type_name])
-			log("Done 2")
 			while (0 < list_len(check_list)):
 				check_type = set_pop(check_list)
 				if (dict_in(cardinalities, check_type)):
@@ -189,7 +185,6 @@ String function conformance_scd(model : Element):
 								String error
 								error = (("Upper cardinality violation for incoming edge of type " + check_type) + " at ") + model_info(model, model_name)
 								return error!
-			log("List iter OK 2")
 
 			constraint_function = read_attribute(metamodel, typing[model_name], "constraint")
 			if (element_neq(constraint_function, read_root())):

+ 6 - 10
bootstrap/modelling.alc

@@ -317,9 +317,10 @@ Element function read_attribute(model : Element, element : String, attribute : S
 	Integer i
 	Integer count
 	Element edge
-	String edge_type
+	String edge_type_name
 	Element elem
 	Element typing
+	Element name
 
 	elem = model["model"][element]
 	typing = model["type_mapping"]
@@ -328,9 +329,10 @@ Element function read_attribute(model : Element, element : String, attribute : S
 	i = 0
 	while (i < count):
 		edge = read_out(elem, i)
-		if (dict_in(typing, reverseKeyLookup(model["model"], edge))):
-			edge_type = typing[reverseKeyLookup(model["model"], edge)]
-			if (edge_type == reverseKeyLookup(model["model"], dict_read_edge(read_edge_src(model["model"][edge_type]), attribute))):
+		name = reverseKeyLookup(model["model"], edge)
+		if (dict_in(typing, name)):
+			edge_type_name = typing[name]
+			if (edge_type_name == reverseKeyLookup(model["metamodel"]["model"], dict_read_edge(read_edge_src(model["metamodel"]["model"][edge_type_name]), attribute))):
 				return read_edge_dst(edge)!
 		i = i + 1
 
@@ -486,13 +488,10 @@ Void function add_constraint(model : Element, element : String, constraint : Act
 Void function construct_model():
 	String command
 
-	log("Initialize SCD")
 	initialize_SCD("models/SimpleClassDiagrams")
-	log("Initialized!")
 
 	while (True):
 		command = input()
-		log(command)
 		if (command == "instantiate_bottom"):
 			Element m
 			m = instantiate_bottom()
@@ -584,15 +583,12 @@ Element function construct_model_raw(metamodel : Element):
 			input()
 			add_constraint(model, input(), construct_function())
 		elif (command == "import_node"):
-			log("Dropping import_node as not allowed")
 			input()
 			input()
 		elif (command == "export_node"):
-			log("Dropping export_node as not allowed")
 			input()
 			input()
 		elif (command == "instantiate_model"):
-			log("Dropping instantiate_model as not allowed")
 			input()
 			input()
 		else:

+ 1 - 0
core/core_algorithm.alc

@@ -635,6 +635,7 @@ Void function user_function_skip_init(user_id : String):
 			models = allInstances(core, "Model")
 			while (read_nr_out(models) > 0):
 				m = set_pop(models)
+				log("Read attribute name of " + cast_e2s(m))
 				output(string_join((string_join("  ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name")))
 
 		elif (cmd == "model_list_full"):

+ 16 - 19
kernel/modelverse_kernel/compiled.py

@@ -152,8 +152,8 @@ def add_AL(a, b, **remainder):
         }
 
     # Already add some often used types to the type cache, so we don't have to check for their presence
-    to_str, string = yield [("RD", [metamodel_dict, "to_str"]),
-                            ("RD", [metamodel_dict, "String"])]
+    to_str, string = yield [("CNV", ["to_str"]),
+                            ("CNV", ["String"])]
 
     type_cache = {"to_str": to_str,
                   "String": string}
@@ -178,16 +178,13 @@ def add_AL(a, b, **remainder):
 
         # Fill the cache
         if expected_type not in type_cache:
-            type_cache[expected_type], = yield [("RD", [metamodel_dict, expected_type])]
+            type_cache[expected_type], = yield [("CNV", [expected_type])]
 
         # Need to add it now
-        yield [("CD", [model_dict, "__%s" % worknode, worknode])]
+        nodename = "__%s" % worknode
+        yield [("CD", [model_dict, nodename, worknode])]
         added.add(worknode)
-        # NOTE can't just use CD here, as the key is a node and not a value
-        t1, = yield [("CE", [type_map, type_cache[expected_type]])]
-        t2, = yield [("CE", [t1, worknode])]
-        if t1 is None or t2 is None:
-            raise Exception("ERROR")
+        _, =        yield [("CD", [type_map, nodename, type_cache[expected_type]])]
 
         # Now add all its outgoing links, depending on the type we actually saw
         links = type_links.get(expected_type, [])
@@ -206,25 +203,25 @@ def add_AL(a, b, **remainder):
                 # Now add: edge, edge_outlink, edge_name
 
                 # Add 'edge'
-                yield [("CD", [model_dict, "__%s" % edge, edge])]
+                edgename = "__%s" % edge
+                yield [("CD", [model_dict, edgename, edge])]
                 added.add(edge)
                 link_type = "%s_%s" % (expected_type, link_name)
                 if link_type not in type_cache:
-                    type_cache[link_type], = yield [("RD", [metamodel_dict, link_type])]
-                t, = yield [("CE", [type_map, type_cache[link_type]])]
-                yield [("CE", [t, edge])]
+                    type_cache[link_type], = yield [("CNV", [link_type])]
+                _, = yield [("CD", [type_map, edge_name, type_cache[link_type]])]
 
                 # Add 'edge_outlink'
-                yield [("CD", [model_dict, "__%s" % edge_outlink, edge_outlink])]
+                edgename = "__%s" % edge_outlink
+                yield [("CD", [model_dict, edgename, edge_outlink])]
                 added.add(edge_outlink)
-                t, = yield [("CE", [type_map, type_cache["to_str"]])]
-                yield [("CE", [t, edge_outlink])]
+                _, = yield [("CD", [type_map, edgename, type_cache["to_str"]])]
 
                 # Add 'edge_name' (if not present)
                 if edge_name not in added:
-                    yield [("CD", [model_dict, "__%s" % edge_name, edge_name])]
-                    t, = yield [("CE", [type_map, type_cache["String"]])]
-                    yield [("CE", [t, edge_name])]
+                    edgename = "__%s" % edge_name
+                    yield [("CD", [model_dict, edgename, edge_name])]
+                    _, = yield [("CD", [type_map, edgename, type_cache["String"]])]
                     added.add(edge_name)
 
                 # Add the destination to the worklist