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") 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, "Attribute", "statement_next", "Statement", "Statement") instantiate_link(model, "Attribute", "if_cond", "if", "Expression") instantiate_link(model, "Attribute", "if_then", "if", "Statement") instantiate_link(model, "Attribute", "if_else", "if", "Statement") instantiate_link(model, "Attribute", "while_cond", "while", "Expression") instantiate_link(model, "Attribute", "while_body", "while", "Statement") instantiate_link(model, "Attribute", "assign_var", "assign", "Element") instantiate_link(model, "Attribute", "assign_value", "assign", "Expression") instantiate_link(model, "Attribute", "break_while", "break", "while") instantiate_link(model, "Attribute", "continue_while", "continue", "while") instantiate_link(model, "Attribute", "return_value", "return", "Expression") instantiate_link(model, "Attribute", "resolve_var", "resolve", "Element") instantiate_link(model, "Attribute", "access_var", "access", "Element") instantiate_link(model, "Attribute", "constant_node", "constant", "Element") instantiate_link(model, "Attribute", "output_node", "output", "Expression") instantiate_link(model, "Attribute", "global_var", "global", "String") instantiate_link(model, "Attribute", "param_name", "param", "String") instantiate_link(model, "Attribute", "param_value", "param", "Expression") instantiate_link(model, "Attribute", "param_next_param", "param", "param") instantiate_link(model, "Attribute", "funcdef_body", "funcdef", "Statement") instantiate_link(model, "Attribute", "call_func", "call", "Expression") instantiate_link(model, "Attribute", "call_params", "call", "param") instantiate_link(model, "Attribute", "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") // Add cardinalities on how many connections are allowed: one of each // instantiate_attribute(model, "statement_next", "target_upper_cardinality", 1) // instantiate_attribute(model, "if_cond", "target_lower_cardinality", 1) // instantiate_attribute(model, "if_cond", "target_upper_cardinality", 1) // instantiate_attribute(model, "if_then", "target_lower_cardinality", 1) // instantiate_attribute(model, "if_then", "target_upper_cardinality", 1) // instantiate_attribute(model, "if_else", "target_upper_cardinality", 1) // instantiate_attribute(model, "while_cond", "target_lower_cardinality", 1) // instantiate_attribute(model, "while_cond", "target_upper_cardinality", 1) // instantiate_attribute(model, "while_body", "target_lower_cardinality", 1) // instantiate_attribute(model, "while_body", "target_upper_cardinality", 1) // instantiate_attribute(model, "assign_var", "target_lower_cardinality", 1) // instantiate_attribute(model, "assign_var", "target_upper_cardinality", 1) // instantiate_attribute(model, "assign_value", "target_lower_cardinality", 1) // instantiate_attribute(model, "assign_value", "target_upper_cardinality", 1) // instantiate_attribute(model, "break_while", "target_lower_cardinality", 1) // instantiate_attribute(model, "break_while", "target_upper_cardinality", 1) // instantiate_attribute(model, "continue_while", "target_lower_cardinality", 1) // instantiate_attribute(model, "continue_while", "target_upper_cardinality", 1) // instantiate_attribute(model, "return_value", "target_upper_cardinality", 1) // instantiate_attribute(model, "resolve_var", "target_lower_cardinality", 1) // instantiate_attribute(model, "resolve_var", "target_upper_cardinality", 1) // instantiate_attribute(model, "access_var", "target_lower_cardinality", 1) // instantiate_attribute(model, "access_var", "target_upper_cardinality", 1) // instantiate_attribute(model, "constant_node", "target_lower_cardinality", 1) // instantiate_attribute(model, "constant_node", "target_upper_cardinality", 1) // instantiate_attribute(model, "output_node", "target_lower_cardinality", 1) // instantiate_attribute(model, "output_node", "target_upper_cardinality", 1) // instantiate_attribute(model, "global_var", "target_lower_cardinality", 1) // instantiate_attribute(model, "global_var", "target_upper_cardinality", 1) // instantiate_attribute(model, "param_name", "target_lower_cardinality", 1) // instantiate_attribute(model, "param_name", "target_upper_cardinality", 1) // instantiate_attribute(model, "param_value", "target_lower_cardinality", 1) // instantiate_attribute(model, "param_value", "target_upper_cardinality", 1) // instantiate_attribute(model, "param_next_param", "target_upper_cardinality", 1) // instantiate_attribute(model, "funcdef_body", "target_lower_cardinality", 1) // instantiate_attribute(model, "funcdef_body", "target_upper_cardinality", 1) // instantiate_attribute(model, "call_func", "target_lower_cardinality", 1) // instantiate_attribute(model, "call_func", "target_upper_cardinality", 1) // instantiate_attribute(model, "call_params", "target_upper_cardinality", 1) // instantiate_attribute(model, "call_last_param", "target_upper_cardinality", 1) return !