Переглянути джерело

Fixed most AL MM problems

Yentl Van Tendeloo 8 роки тому
батько
коміт
5c15328b57

BIN
bootstrap/bootstrap.m.gz


+ 43 - 32
bootstrap/metamodels.alc

@@ -209,7 +209,6 @@ Element function initialize_SCD(location : String):
 	instantiate_link(scd, "Inheritance", "", "Natural", "PrimitiveType")
 	instantiate_link(scd, "Inheritance", "", "String", "PrimitiveType")
 	instantiate_link(scd, "Inheritance", "", "Boolean", "PrimitiveType")
-	instantiate_link(scd, "Inheritance", "", "Action", "PrimitiveType")
 
 	// Add in the Action Language metamodel
 	add_AL_to_MM(scd)
@@ -223,7 +222,6 @@ Element function initialize_SCD(location : String):
 	instantiate_attribute(scd, "String", "constraint", constraint_string)
 	instantiate_attribute(scd, "Boolean", "constraint", constraint_boolean)
 
-
 	// Add constraints to all primitive classes
 	// TODO this is much too slow right now
 	//instantiate_attribute_code(scd, "if", "constraint", constraint_if)
@@ -326,15 +324,28 @@ Void function add_AL_to_MM(model : Element):
 	instantiate_node(model, "AttributeValue", "resolve")
 	instantiate_node(model, "AttributeValue", "call")
 
-	instantiate_link(model, "Attribute", "dict_link", "Action", "PrimitiveType")
-	instantiate_attribute(model, "dict_link", "name", "dictionary_link")
-	instantiate_attribute(model, "dict_link", "optional", True)
-	model_define_attribute(model, "dict_link", "name", False, "String")
+	instantiate_link(model, "Inheritance", "", "Action", "Element")
+	instantiate_link(model, "Inheritance", "", "funcdef", "Action")
+	instantiate_link(model, "Inheritance", "", "param", "Action")
+	instantiate_link(model, "Inheritance", "", "Statement", "Action")
+	instantiate_link(model, "Inheritance", "", "Expression", "Action")
+	instantiate_link(model, "Inheritance", "", "resolve", "Statement")
+	instantiate_link(model, "Inheritance", "", "if", "Statement")
+	instantiate_link(model, "Inheritance", "", "break", "Statement")
+	instantiate_link(model, "Inheritance", "", "continue", "Statement")
+	instantiate_link(model, "Inheritance", "", "global", "Statement")
+	instantiate_link(model, "Inheritance", "", "while", "Statement")
+	instantiate_link(model, "Inheritance", "", "assign", "Statement")
+	instantiate_link(model, "Inheritance", "", "return", "Statement")
+	instantiate_link(model, "Inheritance", "", "call", "Statement")
+	instantiate_link(model, "Inheritance", "", "access", "Expression")
+	instantiate_link(model, "Inheritance", "", "constant", "Expression")
+	instantiate_link(model, "Inheritance", "", "input", "Expression")
 
 	model_define_attribute(model, "Statement", "next", True, "Statement")
 	model_define_attribute(model, "if", "cond", False, "Expression")
-	model_define_attribute(model, "if", "true", False, "Statement")
-	model_define_attribute(model, "if", "false", True, "Statement")
+	model_define_attribute(model, "if", "then", False, "Statement")
+	model_define_attribute(model, "if", "else", True, "Statement")
 	model_define_attribute(model, "while", "cond", False, "Expression")
 	model_define_attribute(model, "while", "body", False, "Statement")
 	model_define_attribute(model, "assign", "var", False, "resolve")
@@ -342,7 +353,7 @@ Void function add_AL_to_MM(model : Element):
 	model_define_attribute(model, "break", "while", False, "while")
 	model_define_attribute(model, "continue", "while", False, "while")
 	model_define_attribute(model, "return", "value", True, "Expression")
-	model_define_attribute(model, "resolve", "var", False, "String")
+	model_define_attribute(model, "resolve", "var", False, "PrimitiveType")
 	model_define_attribute(model, "access", "var", False, "resolve")
 	model_define_attribute(model, "constant", "node", False, "PrimitiveType")
 	model_define_attribute(model, "output", "node", False, "Expression")
@@ -355,28 +366,28 @@ Void function add_AL_to_MM(model : Element):
 	model_define_attribute(model, "call", "params", True, "param")
 	model_define_attribute(model, "call", "last_param", True, "param")
 
-	instantiate_link(model, "Inheritance", "", "statement_next", "dict_link")
-	instantiate_link(model, "Inheritance", "", "if_cond", "dict_link")
-	instantiate_link(model, "Inheritance", "", "if_true", "dict_link")
-	instantiate_link(model, "Inheritance", "", "if_false", "dict_link")
-	instantiate_link(model, "Inheritance", "", "while_cond", "dict_link")
-	instantiate_link(model, "Inheritance", "", "while_body", "dict_link")
-	instantiate_link(model, "Inheritance", "", "assign_var", "dict_link")
-	instantiate_link(model, "Inheritance", "", "assign_value", "dict_link")
-	instantiate_link(model, "Inheritance", "", "break_while", "dict_link")
-	instantiate_link(model, "Inheritance", "", "continue_while", "dict_link")
-	instantiate_link(model, "Inheritance", "", "return_value", "dict_link")
-	instantiate_link(model, "Inheritance", "", "resolve_var", "dict_link")
-	instantiate_link(model, "Inheritance", "", "access_var", "dict_link")
-	instantiate_link(model, "Inheritance", "", "constant_node", "dict_link")
-	instantiate_link(model, "Inheritance", "", "output_node", "dict_link")
-	instantiate_link(model, "Inheritance", "", "global_var", "dict_link")
-	instantiate_link(model, "Inheritance", "", "param_name", "dict_link")
-	instantiate_link(model, "Inheritance", "", "param_value", "dict_link")
-	instantiate_link(model, "Inheritance", "", "param_next_param", "dict_link")
-	instantiate_link(model, "Inheritance", "", "funcdef_body", "dict_link")
-	instantiate_link(model, "Inheritance", "", "call_func", "dict_link")
-	instantiate_link(model, "Inheritance", "", "call_params", "dict_link")
-	instantiate_link(model, "Inheritance", "", "call_last_param", "dict_link")
+	model_define_attribute(model, "Statement_next", "name", False, "String")
+	model_define_attribute(model, "if_cond", "name", False, "String")
+	model_define_attribute(model, "if_then", "name", False, "String")
+	model_define_attribute(model, "if_else", "name", False, "String")
+	model_define_attribute(model, "while_cond", "name", False, "String")
+	model_define_attribute(model, "while_body", "name", False, "String")
+	model_define_attribute(model, "assign_var", "name", False, "String")
+	model_define_attribute(model, "assign_value", "name", False, "String")
+	model_define_attribute(model, "break_while", "name", False, "String")
+	model_define_attribute(model, "continue_while", "name", False, "String")
+	model_define_attribute(model, "return_value", "name", False, "String")
+	model_define_attribute(model, "resolve_var", "name", False, "String")
+	model_define_attribute(model, "access_var", "name", False, "String")
+	model_define_attribute(model, "constant_node", "name", False, "String")
+	model_define_attribute(model, "output_node", "name", False, "String")
+	model_define_attribute(model, "global_var", "name", False, "String")
+	model_define_attribute(model, "param_name", "name", False, "String")
+	model_define_attribute(model, "param_value", "name", False, "String")
+	model_define_attribute(model, "param_next_param", "name", False, "String")
+	model_define_attribute(model, "funcdef_body", "name", False, "String")
+	model_define_attribute(model, "call_func", "name", False, "String")
+	model_define_attribute(model, "call_params", "name", False, "String")
+	model_define_attribute(model, "call_last_param", "name", False, "String")
 
 	return !

+ 46 - 1
bootstrap/modelling.alc

@@ -364,7 +364,7 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
 
 	return!
 
-Void function add_AL_links(model : Element, list : Element, element : Element, type: String, linkname : String, expected_type : String):
+Void function add_AL_links_old(model : Element, list : Element, element : Element, type: String, linkname : String, expected_type : String):
 	if (bool_not(dict_in(element, linkname))):
 		return!
 
@@ -402,6 +402,51 @@ Void function add_AL_links(model : Element, list : Element, element : Element, t
 
 	return!
 
+Void function add_AL_links(model : Element, list : Element, element : Element, type: String, linkname : String, expected_type : String):
+	if (bool_not(dict_in(element, linkname))):
+		log("FINISH")
+		return!
+
+	Element link
+	String link_name
+
+	link = dict_read_edge(element, linkname)
+	link_name = "__" + cast_id2s(link)
+
+	// The link
+	dict_add(model["model"], link_name, link)
+	dict_add(model["type_mapping"], link_name, (type + "_") + linkname)
+	log("Added " + link_name)
+	log((("  as " + type) + "_") + linkname)
+
+	// The name link
+	link = read_out(link, 0)
+	link_name = "__" + cast_id2s(link)
+
+	dict_add(model["model"], link_name, link)
+	dict_add(model["type_mapping"], link_name, ((type + "_") + linkname) + "_name")
+	
+	log("Add name " + link_name)
+	log(((("  As " + type) + "_") + linkname) + "_name")
+
+	// The name node
+	link = read_edge_dst(link)
+	link_name = "__" + cast_id2s(link)
+
+	if (bool_not(set_in_node(model["model"], link))):
+		log("TRUE")
+		dict_add(model["model"], link_name, link)
+		dict_add(model["type_mapping"], link_name, "String")
+		log("Added string " + link_name)
+		log("  with value " + cast_e2s(link))
+	else:
+		log("FALSE")
+
+	// Now add the destination to the worker list
+	set_add(list, create_tuple(element[linkname], expected_type))
+
+	return!
+
 String function add_AL(model : Element, element : Element):
 	Element todo
 	Element node

+ 40 - 48
integration/test_constructors_models.py

@@ -83,11 +83,6 @@ action_language = [
         "instantiate_node", "1", "AttributeValue", "resolve",
         "instantiate_node", "1", "AttributeValue", "call",
 
-        "instantiate_link", "1", "Attribute", "dict_link", "Action", "PrimitiveType",
-        "instantiate_attribute", "1", "dict_link", "name", "dictionary_link",
-        "instantiate_attribute", "1", "dict_link", "optional", True,
-        "model_define_attribute", "1", "dict_link", "name", False, "String",
-
         "instantiate_link", "1", "Inheritance", "", "Action", "Element",
         "instantiate_link", "1", "Inheritance", "", "funcdef", "Action",
         "instantiate_link", "1", "Inheritance", "", "param", "Action",
@@ -110,8 +105,8 @@ action_language = [
 
         "model_define_attribute", "1", "Statement", "next", True, "Statement",
         "model_define_attribute", "1", "if", "cond", False, "Expression",
-        "model_define_attribute", "1", "if", "true", False, "Statement",
-        "model_define_attribute", "1", "if", "false", True, "Statement",
+        "model_define_attribute", "1", "if", "then", False, "Statement",
+        "model_define_attribute", "1", "if", "else", True, "Statement",
         "model_define_attribute", "1", "while", "cond", False, "Expression",
         "model_define_attribute", "1", "while", "body", False, "Statement",
         "model_define_attribute", "1", "assign", "var", False, "resolve",
@@ -119,7 +114,7 @@ action_language = [
         "model_define_attribute", "1", "break", "while", False, "while",
         "model_define_attribute", "1", "continue", "while", False, "while",
         "model_define_attribute", "1", "return", "value", True, "Expression",
-        "model_define_attribute", "1", "resolve", "var", False, "String",
+        "model_define_attribute", "1", "resolve", "var", False, "PrimitiveType",
         "model_define_attribute", "1", "access", "var", False, "resolve",
         "model_define_attribute", "1", "constant", "node", False, "PrimitiveType",
         "model_define_attribute", "1", "output", "node", False, "Expression",
@@ -132,36 +127,33 @@ action_language = [
         "model_define_attribute", "1", "call", "params", True, "param",
         "model_define_attribute", "1", "call", "last_param", True, "param",
 
-        "instantiate_link", "1", "Inheritance", "", "Statement_next", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "if_cond", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "if_true", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "if_false", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "while_cond", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "while_body", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "assign_var", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "assign_value", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "break_while", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "continue_while", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "return_value", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "resolve_var", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "access_var", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "constant_node", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "output_node", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "global_var", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "param_name", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "param_value", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "param_next_param", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "funcdef_body", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "call_func", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "call_params", "dict_link",
-        "instantiate_link", "1", "Inheritance", "", "call_last_param", "dict_link",
+        # TODO these Strings are actually supposed to be more restricted!
+        "model_define_attribute", "1", "Statement_next", "name", False, "String",
+        "model_define_attribute", "1", "if_cond", "name", False, "String",
+        "model_define_attribute", "1", "if_then", "name", False, "String",
+        "model_define_attribute", "1", "if_else", "name", False, "String",
+        "model_define_attribute", "1", "while_cond", "name", False, "String",
+        "model_define_attribute", "1", "while_body", "name", False, "String",
+        "model_define_attribute", "1", "assign_var", "name", False, "String",
+        "model_define_attribute", "1", "assign_value", "name", False, "String",
+        "model_define_attribute", "1", "break_while", "name", False, "String",
+        "model_define_attribute", "1", "continue_while", "name", False, "String",
+        "model_define_attribute", "1", "return_value", "name", False, "String",
+        "model_define_attribute", "1", "resolve_var", "name", False, "String",
+        "model_define_attribute", "1", "access_var", "name", False, "String",
+        "model_define_attribute", "1", "constant_node", "name", False, "String",
+        "model_define_attribute", "1", "output_node", "name", False, "String",
+        "model_define_attribute", "1", "global_var", "name", False, "String",
+        "model_define_attribute", "1", "param_name", "name", False, "String",
+        "model_define_attribute", "1", "param_value", "name", False, "String",
+        "model_define_attribute", "1", "param_next_param", "name", False, "String",
+        "model_define_attribute", "1", "funcdef_body", "name", False, "String",
+        "model_define_attribute", "1", "call_func", "name", False, "String",
+        "model_define_attribute", "1", "call_params", "name", False, "String",
+        "model_define_attribute", "1", "call_last_param", "name", False, "String",
 
-        "model_define_attribute", "1", "Class", "constraint", True, "funcdef",
-        "exit",
-    ]
-
-bottom_attributes = [
-        "model",
+        "model_define_attribute", "1", "Element", "constraint", True, "funcdef",
+        "model_define_attribute", "1", "AttributeValue", "to_string", True, "funcdef",
         "exit",
     ]
 
@@ -311,42 +303,42 @@ def conformance_check(node):
 
 class TestConstructorsModels(unittest.TestCase):
     def test_constructors_instantiate_bottom(self):
-        commands = bottom + bottom_attributes + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
+        commands = bottom + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
     def test_constructors_action_language(self):
-        commands = bottom + action_language + bottom_attributes + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
+        commands = bottom + action_language + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
-    def test_constructors_constraints(self):
-        commands = bottom + action_language + bottom_attributes + add_constraints(1) + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
+    def test_constructors_constraints_scd(self):
+        commands = bottom + action_language + add_constraints(1) + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
-    def test_constructors_constraints_executed(self):
-        commands = bottom + action_language + bottom_attributes + add_constraints(1) + instantiate_scd + add_constraints(2) + instantiate_pn + conformance_check("models/PN_instance") + ["return", False]
+    def test_constructors_constraints_pn(self):
+        commands = bottom + action_language + add_constraints(1) + instantiate_scd + add_constraints(2) + instantiate_pn + conformance_check("models/PN_instance") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
     def test_constructors_instantiate_scd(self):
-        commands = bottom + bottom_attributes + instantiate_scd + conformance_check("models/PetriNets_new") + ["return", False]
+        commands = bottom + instantiate_scd + conformance_check("models/PetriNets_new") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
     def test_constructors_instantiate_pn(self):
-        commands = bottom + bottom_attributes + instantiate_scd + instantiate_pn + conformance_check("models/PN_instance") + ["return", False]
+        commands = bottom + instantiate_scd + instantiate_pn + conformance_check("models/PN_instance") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK"], 1))
 
     def test_constructors_instantiate_example(self):
-        commands = bottom + bottom_attributes + instantiate_example + conformance_check("models/example_MM") + conformance_check("models/example_M") + ["return", False]
+        commands = bottom + instantiate_example + conformance_check("models/example_MM") + conformance_check("models/example_M") + ["return", False]
         self.assertTrue(run_barebone(commands, ["OK", "OK"], 1))
 
     def test_constructors_is_direct_instance(self):
-        commands = bottom + bottom_attributes + instantiate_example + is_direct_instance + ["return", False]
+        commands = bottom + instantiate_example + is_direct_instance + ["return", False]
         expected = [True, False, False,
                     False, True, False,
                     False, False, True]
         self.assertTrue(run_barebone(commands, expected, 1))
 
     def test_constructors_is_nominal_instance(self):
-        commands = bottom + bottom_attributes + instantiate_example + is_nominal_instance + ["return", False]
+        commands = bottom + instantiate_example + is_nominal_instance + ["return", False]
         expected = [True, True, False,
                     False, True, False,
                     False, False, True]