include "primitives.alh" include "object_operations.alh" include "library.alh" include "conformance_scd.alh" include "modelling.alh" Element function constraint_natural(model : Element, name : String): if (is_physical_int(model["model"][name])): if (integer_gte(model["model"][name], 0)): return "OK"! else: return "Natural number not larger than or equal to zero"! else: return "Natural has non-integer instance"! Element function constraint_string(model : Element, name : String): if (is_physical_string(model["model"][name])): return "OK"! else: return "String has non-string instance"! Element function constraint_boolean(model : Element, name : String): if (is_physical_boolean(model["model"][name])): return "OK"! else: return "Boolean has non-boolean instance"! Element function constraint_if(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "if"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_while(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "while"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_break(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "break"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_continue(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "continue"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_assign(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "assign"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_return(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "return"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_output(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "output"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_input(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "input"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_declare(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "declare"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_global(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "global"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_access(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "access"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_constant(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "constant"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_resolve(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "resolve"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function constraint_call(model : Element, name : String): if (is_physical_action(model["model"][name])): if (cast_a2s(model["model"][name]) == "call"): return "OK"! else: return "Got wrong action primitive: " + cast_a2s(model["model"][name])! else: return "Expected physical action value"! Element function initialize_SCD(location : String): if (element_neq(import_node(location), read_root())): return import_node(location)! Element scd scd = instantiate_bottom() model_add_node(scd, "Element") model_add_node(scd, "Class") model_add_node(scd, "AttributeValue") 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, "Attribute", "Element", "AttributeValue") model_add_edge(scd, "attr_name", "Attribute", "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, "attributevalue_inh_element", "AttributeValue", "Element") model_add_edge(scd, "association_inh_class", "Association", "Class") model_add_edge(scd, "attribute_inh_attributevalue", "Attribute", "AttributeValue") // Retype to self retype_model(scd, scd) retype(scd, "Element", "Class") retype(scd, "Class", "Class") retype(scd, "AttributeValue", "Class") retype(scd, "String", "AttributeValue") retype(scd, "name_value", "String") retype(scd, "Association", "Association") retype(scd, "Inheritance", "Association") retype(scd, "Attribute", "Association") retype(scd, "attr_name", "Attribute") retype(scd, "attr_name_name", "attr_name") retype(scd, "class_inh_element", "Inheritance") retype(scd, "attributevalue_inh_element", "Inheritance") retype(scd, "association_inh_class", "Inheritance") retype(scd, "attribute_inh_attributevalue", "Inheritance") // Add some attributes, now that it is an ordinary model instantiate_node(scd, "AttributeValue", "Natural") instantiate_node(scd, "AttributeValue", "Boolean") instantiate_link(scd, "Attribute", "attr_optional", "Attribute", "Boolean") instantiate_attribute(scd, "attr_optional", "name", "optional") instantiate_attribute(scd, "attr_optional", "optional", False) instantiate_attribute(scd, "attr_name", "optional", False) 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") // Make all primitives inherit from primitive type instantiate_node(scd, "AttributeValue", "PrimitiveType") instantiate_link(scd, "Inheritance", "", "Natural", "PrimitiveType") instantiate_link(scd, "Inheritance", "", "String", "PrimitiveType") instantiate_link(scd, "Inheritance", "", "Boolean", "PrimitiveType") // Add in the Action Language metamodel add_AL_to_MM(scd) // Define additional attributes that define functions model_define_attribute(scd, "Element", "constraint", True, "funcdef") model_define_attribute(scd, "AttributeValue", "to_string", True, "funcdef") // Define some constraints instantiate_attribute(scd, "Natural", "constraint", constraint_natural) instantiate_attribute(scd, "String", "constraint", constraint_string) instantiate_attribute(scd, "Boolean", "constraint", constraint_boolean) // Add constraints to all primitive classes // TODO this is much too slow right now //add_constraint(scd, "if", constraint_if) //add_constraint(scd, "while", constraint_while) //add_constraint(scd, "break", constraint_break) //add_constraint(scd, "continue", constraint_continue) //add_constraint(scd, "assign", constraint_assign) //add_constraint(scd, "return", constraint_return) //add_constraint(scd, "output", constraint_output) //add_constraint(scd, "input", constraint_input) //add_constraint(scd, "declare", constraint_declare) //add_constraint(scd, "global", constraint_global) //add_constraint(scd, "access", constraint_access) //add_constraint(scd, "constant", constraint_constant) //add_constraint(scd, "resolve", constraint_resolve) //add_constraint(scd, "call", constraint_call) // Finally done, so export! export_node(location, scd) 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, "AttributeValue", "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(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 add_AL_to_MM(model : Element): instantiate_node(model, "AttributeValue", "Action") instantiate_link(model, "Inheritance", "", "Action", "PrimitiveType") instantiate_node(model, "AttributeValue", "Statement") instantiate_node(model, "AttributeValue", "Expression") instantiate_node(model, "AttributeValue", "funcdef") instantiate_node(model, "AttributeValue", "param") instantiate_node(model, "AttributeValue", "if") instantiate_node(model, "AttributeValue", "break") instantiate_node(model, "AttributeValue", "while") instantiate_node(model, "AttributeValue", "continue") instantiate_node(model, "AttributeValue", "assign") instantiate_node(model, "AttributeValue", "return") instantiate_node(model, "AttributeValue", "output") instantiate_node(model, "AttributeValue", "declare") instantiate_node(model, "AttributeValue", "global") instantiate_node(model, "AttributeValue", "access") instantiate_node(model, "AttributeValue", "constant") instantiate_node(model, "AttributeValue", "input") instantiate_node(model, "AttributeValue", "resolve") instantiate_node(model, "AttributeValue", "call") instantiate_link(model, "Attribute", "dict_link", "Action", "PrimitiveType") instantiate_attribute(model, "dict_link", "name", "dictionary_link") instantiate_attribute(model, "dict_link", "optional", True) model_define_attribute(model, "dict_link", "name", False, "String") model_define_attribute(model, "Statement", "next", True, "Statement") model_define_attribute(model, "if", "cond", False, "Expression") model_define_attribute(model, "if", "true", False, "Statement") model_define_attribute(model, "if", "false", True, "Statement") model_define_attribute(model, "while", "cond", False, "Expression") model_define_attribute(model, "while", "body", False, "Statement") model_define_attribute(model, "assign", "var", False, "resolve") model_define_attribute(model, "assign", "value", False, "Expression") model_define_attribute(model, "break", "while", False, "while") model_define_attribute(model, "continue", "while", False, "while") model_define_attribute(model, "return", "value", True, "Expression") model_define_attribute(model, "resolve", "var", False, "String") model_define_attribute(model, "access", "var", False, "resolve") model_define_attribute(model, "constant", "node", False, "PrimitiveType") model_define_attribute(model, "output", "node", False, "Expression") model_define_attribute(model, "global", "var", False, "String") model_define_attribute(model, "param", "name", False, "String") model_define_attribute(model, "param", "value", False, "Expression") model_define_attribute(model, "param", "next_param", True, "param") model_define_attribute(model, "funcdef", "body", False, "Statement") model_define_attribute(model, "call", "func", False, "Statement") model_define_attribute(model, "call", "params", True, "param") model_define_attribute(model, "call", "last_param", True, "param") instantiate_link(model, "Inheritance", "", "statement_next", "dict_link") instantiate_link(model, "Inheritance", "", "if_cond", "dict_link") instantiate_link(model, "Inheritance", "", "if_true", "dict_link") instantiate_link(model, "Inheritance", "", "if_false", "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") return !