Browse Source

RAMification is mostly working, with many bugs fixed, but attribute resolution crashes

Yentl Van Tendeloo 8 years ago
parent
commit
2637ebe692
4 changed files with 54 additions and 26 deletions
  1. BIN
      bootstrap/bootstrap.m.gz
  2. 2 1
      bootstrap/metamodels.alc
  3. 19 12
      bootstrap/object_operations.alc
  4. 33 13
      bootstrap/ramify.alc

BIN
bootstrap/bootstrap.m.gz


+ 2 - 1
bootstrap/metamodels.alc

@@ -230,7 +230,8 @@ Element function initialize_PN(location_SCD : String, location_PN : String):
 	instantiate_attribute(pn, "T2P_weight", "target_upper_cardinality", 1)
 
 	// Add constraint on the Natural
-	add_constraint(pn, "Natural", constraint_natural)
+	//TODO temporarily done for RAMification to test
+	//add_constraint(pn, "Natural", constraint_natural)
 
 	// Add global constraints
 	//set_model_constraints(pn, petrinet_constraints)

+ 19 - 12
bootstrap/object_operations.alc

@@ -124,18 +124,25 @@ Element function getAttributeList(model : Element, element : String):
 Element function getInstantiatableAttributes(model : Element, element : String):
 	Element result
 	result = create_node()
-	// Get all outgoing "dictionary" links
-	Element set_own
-	Element elem
-	elem = model["model"][element]
-	set_own = dict_keys(element)
-
-	// Filter them
-	Element e
-	while (0 < read_nr_out(set_own)):
-		e = set_pop(set_own)
-		if (is_physical_string(e)):
-			dict_add(result, e, reverseKeyLookup(model["model"], element[e]))
+
+	Element types
+	types = get_superclasses(model, element)
+
+	while (read_nr_out(types) > 0):
+		element = set_pop(types)
+
+		// Get all outgoing "dictionary" links
+		Element set_own
+		Element elem
+		elem = model["model"][element]
+		set_own = dict_keys(element)
+
+		// Filter them
+		Element e
+		while (0 < read_nr_out(set_own)):
+			e = set_pop(set_own)
+			if (is_physical_string(e)):
+				dict_add(result, e, reverseKeyLookup(model["model"], element[e]))
 
 	return result!
 

+ 33 - 13
bootstrap/ramify.alc

@@ -8,6 +8,7 @@ Element function ramify_func(model : Element, prepost : String):
 	Element new_model
 	new_model = create_node()
 	dict_add(new_model, "model", create_node())
+	dict_add(new_model, "type_mapping", create_node())
 	dict_add(new_model, "metamodel", model["metamodel"])
 	dict_add(new_model, "inheritance", model["inheritance"])
 	log("Copied basic data")
@@ -18,11 +19,11 @@ Element function ramify_func(model : Element, prepost : String):
 	Element mm
 	String inheritor
 	new_m = new_model["model"]
-	old_m = new_model["model"]
+	old_m = model["model"]
 	mm = new_model["metamodel"]["model"]
 
 	Boolean is_pre
-	is_pre = prepost == "pre"
+	is_pre = (prepost == "pre")
 
 	// Add in Natural and String
 	log("Adding Natural and String")
@@ -46,6 +47,7 @@ Element function ramify_func(model : Element, prepost : String):
 		//		upper_cardinality = 1
 		//		lower_cardinality = 1
 		//	}
+		log("LHS")
 		instantiate_node(new_model, "Class", "LHS")
 		instantiate_attribute(new_model, "LHS", "lower_cardinality", 1)
 		instantiate_attribute(new_model, "LHS", "upper_cardinality", 1)
@@ -97,6 +99,7 @@ Element function ramify_func(model : Element, prepost : String):
 		//		upper_cardinality = 1
 		//		lower_cardinality = 1
 		//	}
+		log("RHS")
 		instantiate_node(new_model, "Class", "RHS")
 		instantiate_attribute(new_model, "RHS", "lower_cardinality", 1)
 		instantiate_attribute(new_model, "RHS", "upper_cardinality", 1)
@@ -147,16 +150,23 @@ Element function ramify_func(model : Element, prepost : String):
 	String old_source
 	String old_target
 	log("Iterate!")
+	Element to_link
+	to_link = create_node()
+
 	while (read_nr_out(keys) > 0):
 		key = set_pop(keys)
 		entry = old_m[key]
 		log("Try " + key)
 
 		type_name = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], entry))
+		log("Type Name: " + cast_e2s(type_name))
 		if (type_name == "Class"):
 			log("Class")
 			instantiate_node(new_model, type_name, append + key)
 
+			// Also make it inherit from the "root element"
+			instantiate_link(new_model, "Inheritance", "", append + key, inheritor)
+
 		elif (type_name == "Association"):
 			log("Association")
 			old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
@@ -174,15 +184,25 @@ Element function ramify_func(model : Element, prepost : String):
 
 		elif (bool_not(has_value(entry))):
 			log("Attribute")
-			// Primitive values themselves are not copied, so skip that here
-
-			// An instance link, so just copy over (don't make element of Root Element), and don't even copy if it is lower cardinality
-			// It is probably an attribute at the meta-language level, so check which one it is
-			String name
-			name = cast_v2s(read_attribute(model["metamodel"], type_name, "name"))
-			if (bool_not(bool_or(bool_or(name == "lower_cardinality", name == "source_lower_cardinality"), name == "target_lower_cardinality"))):
-				// Not a lower cardinality, so copy
-				old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
+			create_edge(to_link, entry)
+
+	while (read_nr_out(to_link) > 0):
+		entry = set_pop(to_link)
+		type_name = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], entry))
+		// Primitive values themselves are not copied, so skip that here
+
+		// An instance link, so just copy over (don't make element of Root Element), and don't even copy if it is lower cardinality
+		// It is probably an attribute at the meta-language level, so check which one it is
+		String name
+		name = read_attribute(model["metamodel"], type_name, "name")
+		if (bool_not(bool_or(bool_or(name == "lower_cardinality", name == "source_lower_cardinality"), bool_or(name == "constraint", name == "target_lower_cardinality")))):
+			// Not a lower cardinality or constraint, so copy
+			old_source = reverseKeyLookup(model["model"], read_edge_src(entry))
+			if (bool_or(bool_or(name == "name", name == "upper_cardinality"), bool_or(name == "source_upper_cardinality", name == "target_upper_cardinality"))):
+				// Keep the old name for the physical attributes!
+				instantiate_attribute(new_model, append + old_source, name, read_edge_dst(entry))
+			else:
+				// Rename the attributes as well
 				instantiate_attribute(new_model, append + old_source, append + name, read_edge_dst(entry))
 
 	log("Finished")
@@ -194,11 +214,11 @@ Element function ramify(model : Element):
 
 	// Create Pre part
 	log("PRE")
-	dict_add(rv, "pre", ramify_func(model, "Pre"))
+	dict_add(rv, "pre", ramify_func(model, "pre"))
 
 	// Create Post part
 	log("POST")
-	dict_add(rv, "post", ramify_func(model, "Post"))
+	dict_add(rv, "post", ramify_func(model, "post"))
 
 	log("FINISHED")
 	return rv!