123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- include "primitives.alh"
- include "object_operations.alh"
- include "library.alh"
- include "conformance_scd.alh"
- include "modelling.alh"
- String function constraint_Natural(model : Element, name : String):
- Element self
- self = model["model"][name]
- if (is_physical_int(self)):
- if (integer_gte(self, 0)):
- return "OK"!
- else:
- return "Natural number not larger than or equal to zero"!
- else:
- return "Natural number not larger than or equal to zero"!
- Element function constraint_String(model : Element, name : String):
- Element self
- self = model["model"][name]
- if (is_physical_string(self)):
- return "OK"!
- else:
- return "String has non-string instance"!
- Element function constraint_Boolean(model : Element, name : String):
- Element self
- self = model["model"][name]
- if (is_physical_boolean(self)):
- return "OK"!
- else:
- return "Boolean has non-boolean instance"!
- Element function constraint_Location(model : Element, name : String):
- Element self
- self = model["model"][name]
- if (is_physical_string(self)):
- if (element_neq(import_node(self), read_root())):
- return "OK"!
- else:
- return "Location references non-existing element!"!
- else:
- return "Location has non-string instance"!
- Element function constraint_ActionLanguage(model : Element, name : String):
- Element self
- self = model["model"][name]
- if (is_physical_string(self)):
- if (element_neq(import_node(self), read_root())):
- return "OK"!
- else:
- return "ActionLanguage references non-existing element!"!
- else:
- return "ActionLanguage has non-string value!"!
- Element function initialize_SCD(location : String):
- if (element_neq(import_node(location), read_root())):
- return import_node(location)!
- Element scd
- String al_location
- al_location = "models/ActionLanguage"
- scd = instantiate_bottom()
- model_add_node(scd, "Element")
- model_add_node(scd, "Class")
- model_add_node(scd, "Attribute")
- model_add_node(scd, "SimpleAttribute")
- model_add_node(scd, "String")
- model_add_value(scd, "name_value", "name")
- model_add_edge(scd, "Association", "Class", "Class")
- model_add_edge(scd, "Inheritance", "Element", "Element")
- model_add_edge(scd, "AttributeLink", "Element", "Attribute")
- model_add_edge(scd, "attr_name", "AttributeLink", "String")
- model_add_edge(scd, "attr_name_name", "attr_name", "name_value")
- model_add_edge(scd, "class_inh_element", "Class", "Element")
- model_add_edge(scd, "attribute_inh_element", "Attribute", "Element")
- model_add_edge(scd, "simple_inh_attribute", "SimpleAttribute", "Attribute")
- model_add_edge(scd, "association_inh_element", "Association", "Element")
- model_add_edge(scd, "attributelink_inh_element", "AttributeLink", "Element")
- // Retype to self
- retype_model(scd, scd)
- retype(scd, "Element", "Class")
- retype(scd, "Class", "Class")
- retype(scd, "Attribute", "Class")
- retype(scd, "SimpleAttribute", "Class")
- retype(scd, "String", "SimpleAttribute")
- retype(scd, "name_value", "String")
- retype(scd, "Association", "Association")
- retype(scd, "Inheritance", "Association")
- retype(scd, "AttributeLink", "Association")
- retype(scd, "attr_name", "AttributeLink")
- retype(scd, "attr_name_name", "attr_name")
- retype(scd, "class_inh_element", "Inheritance")
- retype(scd, "attribute_inh_element", "Inheritance")
- retype(scd, "simple_inh_attribute", "Inheritance")
- retype(scd, "association_inh_element", "Inheritance")
- retype(scd, "attributelink_inh_element", "Inheritance")
- // Add some attributes, now that it is an ordinary model
- instantiate_node(scd, "SimpleAttribute", "Location")
- instantiate_node(scd, "SimpleAttribute", "Natural")
- instantiate_node(scd, "SimpleAttribute", "Boolean")
- instantiate_link(scd, "AttributeLink", "attr_optional", "AttributeLink", "Boolean")
- instantiate_attribute(scd, "attr_optional", "name", "optional")
- instantiate_attribute(scd, "attr_optional", "optional", False)
- instantiate_attribute(scd, "attr_name", "optional", False)
- instantiate_node(scd, "Class", "ComplexAttribute")
- instantiate_link(scd, "Inheritance", "", "ComplexAttribute", "Attribute")
- model_define_attribute(scd, "Class", "lower_cardinality", True, "Natural")
- model_define_attribute(scd, "Class", "upper_cardinality", True, "Natural")
- model_define_attribute(scd, "Association", "source_lower_cardinality", True, "Natural")
- model_define_attribute(scd, "Association", "target_lower_cardinality", True, "Natural")
- model_define_attribute(scd, "Association", "source_upper_cardinality", True, "Natural")
- model_define_attribute(scd, "Association", "target_upper_cardinality", True, "Natural")
- model_define_attribute(scd, "ComplexAttribute", "type", False, "Location")
- // Export already, to allow AL to pick it up
- export_node(location, scd)
- // Add in the Action Language metamodel
- initialize_AL(location, al_location)
- // Define additional attributes that define functions
- instantiate_node(scd, "ComplexAttribute", "ActionLanguage")
- instantiate_attribute(scd, "ActionLanguage", "type", al_location)
- model_define_attribute(scd, "Element", "constraint", True, "ActionLanguage")
- // Define some constraints
- instantiate_attribute_code(scd, "Natural", "constraint", constraint_Natural)
- instantiate_attribute_code(scd, "String", "constraint", constraint_String)
- instantiate_attribute_code(scd, "Boolean", "constraint", constraint_Boolean)
- instantiate_attribute_code(scd, "Location", "constraint", constraint_Location)
- instantiate_attribute_code(scd, "ActionLanguage", "constraint", constraint_ActionLanguage)
- instantiate_node(scd, "Class", "GlobalConstraint")
- model_define_attribute(scd, "GlobalConstraint", "global_constraint", False, "ActionLanguage")
- return scd!
- Element function initialize_PN(location_SCD : String, location_PN : String):
- Element pn
- Element scd
- scd = import_node(location_SCD)
- pn = instantiate_model(scd)
- instantiate_node(pn, "Class", "Place")
- instantiate_node(pn, "Class", "Transition")
- instantiate_node(pn, "SimpleAttribute", "Natural")
- instantiate_link(pn, "Association", "P2T", "Place", "Transition")
- instantiate_link(pn, "Association", "T2P", "Transition", "Place")
- model_define_attribute(pn, "Place", "tokens", False, "Natural")
- model_define_attribute(pn, "P2T", "weight", False, "Natural")
- model_define_attribute(pn, "T2P", "weight", False, "Natural")
- // Add constraint on the Natural
- instantiate_attribute_code(pn, "Natural", "constraint", constraint_Natural)
- export_node(location_PN, pn)
- return pn!
- Element function initialize_bottom(location_bottom : String):
- Element ltm_bottom
- ltm_bottom = instantiate_bottom()
- model_add_node(ltm_bottom, "Node")
- model_add_edge(ltm_bottom, "Edge", "Node", "Node")
- model_add_edge(ltm_bottom, "inheritance", "Node", "Node")
- model_add_edge(ltm_bottom, "__inh", "Edge", "Node")
- retype_model(ltm_bottom, ltm_bottom)
- retype(ltm_bottom, "Node", "Node")
- retype(ltm_bottom, "Edge", "Edge")
- retype(ltm_bottom, "inheritance", "Edge")
- retype(ltm_bottom, "__inh", "inheritance")
- export_node(location_bottom, ltm_bottom)
- return ltm_bottom!
- Element function create_metamodels():
- String location_SCD
- String location_PN
- String location_bottom
- location_SCD = "models/SimpleClassDiagrams"
- location_PN = "models/PetriNets"
- location_bottom = "models/LTM_bottom"
- if (bool_not(dict_in(dict_read(dict_read(read_root(), "__hierarchy"), "models"), "SimpleClassDiagrams"))):
- initialize_SCD(location_SCD)
- if (bool_not(dict_in(dict_read(dict_read(read_root(), "__hierarchy"), "models"), "PetriNets"))):
- initialize_PN(location_SCD, location_PN)
- if (bool_not(dict_in(dict_read(dict_read(read_root(), "__hierarchy"), "models"), "LTM_bottom"))):
- initialize_bottom(location_bottom)
- return dict_read(dict_read(read_root(), "__hierarchy"), "models")!
- Void function initialize_AL(scd_location : String, export_location : String):
- Element model
- Element scd_model
- if (element_neq(import_node(export_location), read_root())):
- return!
- scd_model = import_node(scd_location)
- model = instantiate_model(scd_model)
- instantiate_node(model, "Class", "Element")
- instantiate_node(model, "Class", "Action")
- instantiate_node(model, "Class", "Statement")
- instantiate_node(model, "Class", "Expression")
- instantiate_node(model, "Class", "funcdef")
- instantiate_node(model, "Class", "param")
- instantiate_node(model, "Class", "if")
- instantiate_node(model, "Class", "break")
- instantiate_node(model, "Class", "while")
- instantiate_node(model, "Class", "continue")
- instantiate_node(model, "Class", "assign")
- instantiate_node(model, "Class", "return")
- instantiate_node(model, "Class", "output")
- instantiate_node(model, "Class", "declare")
- instantiate_node(model, "Class", "global")
- instantiate_node(model, "Class", "access")
- instantiate_node(model, "Class", "constant")
- instantiate_node(model, "Class", "input")
- instantiate_node(model, "Class", "resolve")
- instantiate_node(model, "Class", "call")
- instantiate_node(model, "Class", "String")
- instantiate_node(model, "SimpleAttribute", "StringAttr")
- instantiate_node(model, "Class", "Initial")
- instantiate_attribute(model, "Initial", "lower_cardinality", 1)
- instantiate_attribute(model, "Initial", "upper_cardinality", 1)
- instantiate_link(model, "Association", "initial_funcdef", "Initial", "Action")
- instantiate_attribute(model, "initial_funcdef", "target_lower_cardinality", 1)
- instantiate_attribute(model, "initial_funcdef", "target_upper_cardinality", 1)
- 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", "", "declare", "Statement")
- instantiate_link(model, "Inheritance", "", "call", "Expression")
- instantiate_link(model, "Inheritance", "", "access", "Expression")
- instantiate_link(model, "Inheritance", "", "constant", "Expression")
- instantiate_link(model, "Inheritance", "", "input", "Expression")
- instantiate_link(model, "Inheritance", "", "String", "Element")
- instantiate_link(model, "Association", "dict_link", "Action", "Element")
- model_define_attribute(model, "dict_link", "name", False, "StringAttr")
- instantiate_attribute(model, "dict_link", "target_upper_cardinality", 1)
- instantiate_link(model, "Association", "Statement_next", "Statement", "Statement")
- instantiate_link(model, "Association", "if_cond", "if", "Expression")
- instantiate_link(model, "Association", "if_then", "if", "Statement")
- instantiate_link(model, "Association", "if_else", "if", "Statement")
- instantiate_link(model, "Association", "while_cond", "while", "Expression")
- instantiate_link(model, "Association", "while_body", "while", "Statement")
- instantiate_link(model, "Association", "assign_var", "assign", "resolve")
- instantiate_link(model, "Association", "assign_value", "assign", "Expression")
- instantiate_link(model, "Association", "break_while", "break", "while")
- instantiate_link(model, "Association", "continue_while", "continue", "while")
- instantiate_link(model, "Association", "return_value", "return", "Expression")
- instantiate_link(model, "Association", "resolve_var", "resolve", "Element")
- instantiate_link(model, "Association", "access_var", "access", "resolve")
- instantiate_link(model, "Association", "constant_node", "constant", "Element")
- instantiate_link(model, "Association", "output_node", "output", "Expression")
- instantiate_link(model, "Association", "global_var", "global", "String")
- instantiate_link(model, "Association", "param_name", "param", "String")
- instantiate_link(model, "Association", "param_value", "param", "Expression")
- instantiate_link(model, "Association", "param_next_param", "param", "param")
- instantiate_link(model, "Association", "funcdef_body", "funcdef", "Statement")
- instantiate_link(model, "Association", "call_func", "call", "Expression")
- instantiate_link(model, "Association", "call_params", "call", "param")
- instantiate_link(model, "Association", "call_last_param", "call", "param")
- instantiate_link(model, "Inheritance", "", "Statement_next", "dict_link")
- instantiate_link(model, "Inheritance", "", "if_cond", "dict_link")
- instantiate_link(model, "Inheritance", "", "if_then", "dict_link")
- instantiate_link(model, "Inheritance", "", "if_else", "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")
- instantiate_attribute(model, "if_else", "target_lower_cardinality", 1)
- instantiate_attribute(model, "return_value", "target_lower_cardinality", 1)
- instantiate_attribute(model, "param_next_param", "target_lower_cardinality", 1)
- instantiate_attribute(model, "call_params", "target_lower_cardinality", 1)
- instantiate_attribute(model, "call_last_param", "target_lower_cardinality", 1)
- export_node(export_location, model)
- return !
|