Browse Source

Consistency between if_true and if_then, and if_false and if_else

Yentl Van Tendeloo 9 years ago
parent
commit
071c2dbde0
3 changed files with 20 additions and 15 deletions
  1. 8 6
      bootstrap/metamodels.alc
  2. 8 5
      bootstrap/modelling.alc
  3. 4 4
      integration/test_constructors_models.py

+ 8 - 6
bootstrap/metamodels.alc

@@ -236,8 +236,8 @@ Element function initialize_SCD(location : String):
 	instantiate_link(scd, "Inheritance", "", "input", "Expression")
 	instantiate_link(scd, "Association", "statement_next", "Statement", "Statement")
 	instantiate_link(scd, "Association", "if_cond", "if", "Expression")
-	instantiate_link(scd, "Association", "if_true", "if", "Statement")
-	instantiate_link(scd, "Association", "if_false", "if", "Statement")
+	instantiate_link(scd, "Association", "if_then", "if", "Statement")
+	instantiate_link(scd, "Association", "if_else", "if", "Statement")
 	instantiate_link(scd, "Association", "while_cond", "while", "Expression")
 	instantiate_link(scd, "Association", "while_body", "while", "Statement")
 	instantiate_link(scd, "Association", "assign_var", "assign", "Any")
@@ -259,8 +259,8 @@ Element function initialize_SCD(location : String):
 	instantiate_link(scd, "Association", "call_last_param", "call", "param")
 	instantiate_link(scd, "Inheritance", "", "statement_next", "dict_link")
 	instantiate_link(scd, "Inheritance", "", "if_cond", "dict_link")
-	instantiate_link(scd, "Inheritance", "", "if_true", "dict_link")
-	instantiate_link(scd, "Inheritance", "", "if_false", "dict_link")
+	instantiate_link(scd, "Inheritance", "", "if_then", "dict_link")
+	instantiate_link(scd, "Inheritance", "", "if_else", "dict_link")
 	instantiate_link(scd, "Inheritance", "", "while_cond", "dict_link")
 	instantiate_link(scd, "Inheritance", "", "while_body", "dict_link")
 	instantiate_link(scd, "Inheritance", "", "assign_var", "dict_link")
@@ -285,8 +285,8 @@ Element function initialize_SCD(location : String):
 	instantiate_attribute(scd, "statement_next", "target_upper_cardinality", 1)
 	instantiate_attribute(scd, "if_cond", "target_lower_cardinality", 1)
 	instantiate_attribute(scd, "if_cond", "target_upper_cardinality", 1)
-	instantiate_attribute(scd, "if_true", "target_lower_cardinality", 1)
-	instantiate_attribute(scd, "if_true", "target_upper_cardinality", 1)
+	instantiate_attribute(scd, "if_then", "target_lower_cardinality", 1)
+	instantiate_attribute(scd, "if_else", "target_upper_cardinality", 1)
 	instantiate_attribute(scd, "if_false", "target_upper_cardinality", 1)
 	instantiate_attribute(scd, "while_cond", "target_lower_cardinality", 1)
 	instantiate_attribute(scd, "while_cond", "target_upper_cardinality", 1)
@@ -344,7 +344,9 @@ Element function initialize_SCD(location : String):
 	instantiate_attribute(scd, "constraint", "name", "constraint")
 
 	// And add some, to enforce correct physical types
+	log("Add Natural constraint")
 	add_constraint(scd, "Natural", constraint_natural)
+	log("Add String constraint")
 	add_constraint(scd, "String", constraint_string)
 
 	// Finally done, so export!

+ 8 - 5
bootstrap/modelling.alc

@@ -244,11 +244,10 @@ 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):
-	if (bool_not(dict_in(element, linkname))):
-		return
-
 	Element link
 	link = dict_read_edge(element, linkname)
+	if (bool_not(dict_in(element, linkname))):
+		return
 
 	// The link
 	dict_add(model["model"], "__" + cast_id2s(link), link)
@@ -275,6 +274,7 @@ Void function add_AL_links(model : Element, list : Element, element : Element, t
 	return
 
 String function add_AL(model : Element, element : Element):
+	log("Adding constraint: " + cast_e2s(element))
 	Element todo
 	Element node
 	Element work_node
@@ -293,6 +293,7 @@ String function add_AL(model : Element, element : Element):
 		type = list_read(work_node, 1)
 
 		if (bool_not(set_in_node(model["model"], elem))):
+			log("Adding")
 			// Determine the type if we don't know it
 			if (type == ""):
 				if (is_physical_action(elem)):
@@ -307,8 +308,8 @@ String function add_AL(model : Element, element : Element):
 			// Now add its edges
 			if (type == "if"):
 				add_AL_links(model, todo, elem, type, "cond", "")
-				add_AL_links(model, todo, elem, type, "true", "")
-				add_AL_links(model, todo, elem, type, "false", "")
+				add_AL_links(model, todo, elem, type, "then", "")
+				add_AL_links(model, todo, elem, type, "else", "")
 				add_AL_links(model, todo, elem, type, "next", "")
 			elif (type == "while"):
 				add_AL_links(model, todo, elem, type, "cond", "")
@@ -348,6 +349,8 @@ String function add_AL(model : Element, element : Element):
 				add_AL_links(model, todo, elem, type, "params", "param")
 				add_AL_links(model, todo, elem, type, "last_param", "param")
 				add_AL_links(model, todo, elem, type, "next", "")
+		else:
+			log("Already in there")
 
 	return reverseKeyLookup(model["model"], element)
 

+ 4 - 4
integration/test_constructors_models.py

@@ -90,10 +90,10 @@ action_language = [
         '"instantiate_attribute"', 1, '"statement_next"', '"name"', '"next"',
         '"instantiate_link"', 1, '"Association"', '"if_cond"', '"if"', '"Expression"',
         '"instantiate_attribute"', 1, '"if_cond"', '"name"', '"cond"',
-        '"instantiate_link"', 1, '"Association"', '"if_true"', '"if"', '"Statement"',
-        '"instantiate_attribute"', 1, '"if_true"', '"name"', '"true"',
-        '"instantiate_link"', 1, '"Association"', '"if_false"', '"if"', '"Statement"',
-        '"instantiate_attribute"', 1, '"if_false"', '"name"', '"false"',
+        '"instantiate_link"', 1, '"Association"', '"if_then"', '"if"', '"Statement"',
+        '"instantiate_attribute"', 1, '"if_then"', '"name"', '"true"',
+        '"instantiate_link"', 1, '"Association"', '"if_else"', '"if"', '"Statement"',
+        '"instantiate_attribute"', 1, '"if_else"', '"name"', '"false"',
         '"instantiate_link"', 1, '"Association"', '"while_cond"', '"while"', '"Expression"',
         '"instantiate_attribute"', 1, '"while_cond"', '"name"', '"cond"',
         '"instantiate_link"', 1, '"Association"', '"while_body"', '"while"', '"Statement"',