|
@@ -233,42 +233,109 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
|
|
|
|
|
|
return
|
|
|
|
|
|
-Void function recursive_add_AL(model : Element, element : Element):
|
|
|
- // TODO
|
|
|
- String name
|
|
|
-
|
|
|
- name = "__" + cast_id2s(element)
|
|
|
- if (dict_in(model["model"], name)):
|
|
|
+Void function add_AL_links(model : Element, list : Element, element : Element, linkname : String, expected_type : String):
|
|
|
+ if (bool_not(dict_in(element, linkname))):
|
|
|
return
|
|
|
- else:
|
|
|
- // Add this element and call it for all its outgoing links
|
|
|
- dict_add(model["model"], name, element)
|
|
|
- if (is_physical_action(element)):
|
|
|
- dict_add(model["type_mapping"], element, model["metamodel"][cast_a2s(element)])
|
|
|
- else:
|
|
|
- // Either dealing with a param, a funcdef, or just some other kind of node that we have no clue about
|
|
|
- // TODO add this code
|
|
|
- return
|
|
|
|
|
|
- // Add all its outgoing links
|
|
|
- Integer counter
|
|
|
- Integer i
|
|
|
- Element elem
|
|
|
+ Element link
|
|
|
+ link = dict_read_edge(element, linkname)
|
|
|
|
|
|
- counter = read_nr_out(element)
|
|
|
- i = 0
|
|
|
- while (i < counter):
|
|
|
- elem = read_out(element, i)
|
|
|
- // TODO add the link and all its attributes
|
|
|
+ // The link
|
|
|
+ dict_add(model["model"], "__" + cast_id2s(link), link)
|
|
|
+ dict_add(model["type_mapping"], link, model["metamodel"]["model"]["dict_link"])
|
|
|
|
|
|
- recursive_add_AL(model, elem)
|
|
|
- i = i + 1
|
|
|
+ // The name link
|
|
|
+ link = read_out(link, 0)
|
|
|
+ dict_add(model["model"], "__" + cast_id2s(link), link)
|
|
|
+ dict_add(model["type_mapping"], link, model["metamodel"]["model"]["to_str"])
|
|
|
|
|
|
- return
|
|
|
+ // The name node
|
|
|
+ link = read_edge_dst(link)
|
|
|
+ dict_add(model["model"], "__" + cast_id2s(link), link)
|
|
|
+ dict_add(model["type_mapping"], link, model["metamodel"]["model"]["String"])
|
|
|
+
|
|
|
+ // Now add the destination to the worker list
|
|
|
+ Element node
|
|
|
+ node = create_node()
|
|
|
+ list_append(node, element[linkname])
|
|
|
+ list_append(node, expected_type)
|
|
|
+ set_add(list, node)
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+String function add_AL(model : Element, element : Element):
|
|
|
+ Element todo
|
|
|
+ Element node
|
|
|
+ Element work_node
|
|
|
+ Element elem
|
|
|
+ String type
|
|
|
+
|
|
|
+ todo = create_node()
|
|
|
+ node = create_node()
|
|
|
+ list_append(node, element)
|
|
|
+ list_append(node, "Funcdef")
|
|
|
+ set_add(todo, node)
|
|
|
+
|
|
|
+ while (0 < dict_len(todo)):
|
|
|
+ work_node = set_pop(todo)
|
|
|
+ elem = list_read(work_node, 0)
|
|
|
+ type = list_read(work_node, 1)
|
|
|
+
|
|
|
+ // Determine the type if we don't know it
|
|
|
+ if (type == ""):
|
|
|
+ if (is_physical_action(elem)):
|
|
|
+ type = cast_a2s(elem)
|
|
|
+ else:
|
|
|
+ type = "Any"
|
|
|
+
|
|
|
+ // Add the node itself
|
|
|
+ dict_add(model["model"], "__" + cast_id2s(elem), elem)
|
|
|
+ dict_add(model["type_mapping"], elem, model["metamodel"]["model"][type])
|
|
|
+
|
|
|
+ // Now add its edges
|
|
|
+ if (type == "if"):
|
|
|
+ add_AL_links(model, todo, elem, "cond", "")
|
|
|
+ add_AL_links(model, todo, elem, "true", "")
|
|
|
+ add_AL_links(model, todo, elem, "false", "")
|
|
|
+ add_AL_links(model, todo, elem, "next", "")
|
|
|
+ elif (type == "while"):
|
|
|
+ add_AL_links(model, todo, elem, "cond", "")
|
|
|
+ add_AL_links(model, todo, elem, "body", "")
|
|
|
+ add_AL_links(model, todo, elem, "next", "")
|
|
|
+ elif (type == "assign"):
|
|
|
+ add_AL_links(model, todo, elem, "var", "")
|
|
|
+ add_AL_links(model, todo, elem, "value", "")
|
|
|
+ add_AL_links(model, todo, elem, "next", "")
|
|
|
+ elif (type == "break"):
|
|
|
+ add_AL_links(model, todo, elem, "while", "While")
|
|
|
+ elif (type == "continue"):
|
|
|
+ add_AL_links(model, todo, elem, "while", "While")
|
|
|
+ elif (type == "return"):
|
|
|
+ add_AL_links(model, todo, elem, "value", "")
|
|
|
+ elif (type == "resolve"):
|
|
|
+ add_AL_links(model, todo, elem, "var", "")
|
|
|
+ elif (type == "access"):
|
|
|
+ add_AL_links(model, todo, elem, "var", "")
|
|
|
+ elif (type == "constant"):
|
|
|
+ add_AL_links(model, todo, elem, "node", "")
|
|
|
+ elif (type == "output"):
|
|
|
+ add_AL_links(model, todo, elem, "node", "")
|
|
|
+ elif (type == "global"):
|
|
|
+ add_AL_links(model, todo, elem, "var", "String")
|
|
|
+ elif (type == "param"):
|
|
|
+ add_AL_links(model, todo, elem, "name", "String")
|
|
|
+ add_AL_links(model, todo, elem, "value", "")
|
|
|
+ add_AL_links(model, todo, elem, "next_param", "Param")
|
|
|
+ elif (type == "funcdef"):
|
|
|
+ add_AL_links(model, todo, elem, "body", "")
|
|
|
+ elif (type == "call"):
|
|
|
+ add_AL_links(model, todo, elem, "func", "")
|
|
|
+ add_AL_links(model, todo, elem, "params", "Param")
|
|
|
+ add_AL_links(model, todo, elem, "last_param", "Param")
|
|
|
+ else:
|
|
|
+ log("Unknown type found in AL parser: " + type)
|
|
|
|
|
|
-String function type_action_code(model : Element, constraint : Action):
|
|
|
- recursive_add_AL(model, constraint)
|
|
|
- return reverseKeyLookup(model["model"], constraint)
|
|
|
+ return reverseKeyLookup(model["model"], element)
|
|
|
|
|
|
Void function add_constraint(model : Element, element : String):
|
|
|
// Add local constraints to an element
|
|
@@ -279,7 +346,7 @@ Void function add_constraint(model : Element, element : String):
|
|
|
|
|
|
constraint = construct_function()
|
|
|
attr_type = find_attribute_type(model, element, "constraint")
|
|
|
- constraint_name = type_action_code(model, constraint)
|
|
|
+ constraint_name = add_AL(model, constraint)
|
|
|
link_name = instantiate_link(model, attr_type, "", model["model"][element], constraint_name)
|
|
|
|
|
|
return
|