|
@@ -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!
|