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)! // Temporarily disable during tests return create_node()! Element scd 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, "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", "Attribute") retype(scd, "name_value", "String") retype(scd, "Association", "Association") retype(scd, "Inheritance", "Association") retype(scd, "AttributeLink", "Association") retype(scd, "attr_name", "Attribute") retype(scd, "attr_name_name", "attr_name") retype(scd, "class_inh_element", "Inheritance") retype(scd, "attribute_inh_element", "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", "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") // 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 //instantiate_attribute_code(scd, "if", "constraint", constraint_if) //instantiate_attribute_code(scd, "while", "constraint", constraint_while) //instantiate_attribute_code(scd, "break", "constraint", constraint_break) //instantiate_attribute_code(scd, "continue", "constraint", constraint_continue) //instantiate_attribute_code(scd, "assign", "constraint", constraint_assign) //instantiate_attribute_code(scd, "return", "constraint", constraint_return) //instantiate_attribute_code(scd, "output", "constraint", constraint_output) //instantiate_attribute_code(scd, "input", "constraint", constraint_input) //instantiate_attribute_code(scd, "declare", "constraint", constraint_declare) //instantiate_attribute_code(scd, "global", "constraint", constraint_global) //instantiate_attribute_code(scd, "access", "constraint", constraint_access) //instantiate_attribute_code(scd, "constant", "constraint", constraint_constant) //instantiate_attribute_code(scd, "resolve", "constraint", constraint_resolve) //instantiate_attribute_code(scd, "call", "constraint", 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", "PrimitiveType") instantiate_node(model, "AttributeValue", "Action") instantiate_node(model, "AttributeValue", "String") instantiate_node(model, "AttributeValue", "Natural") instantiate_link(model, "Inheritance", "", "Natural", "PrimitiveType") instantiate_link(model, "Inheritance", "", "String", "PrimitiveType") instantiate_link(model, "Inheritance", "", "Action", "PrimitiveType") instantiate_link(model, "Inheritance", "", "Boolean", "PrimitiveType") instantiate_attribute(model, "Natural", "constraint", constraint_natural) instantiate_attribute(model, "String", "constraint", constraint_string) instantiate_attribute(model, "Boolean", "constraint", constraint_boolean) instantiate_node(model, "AttributeValue", "Boolean") 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, "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", "", "declare", "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", "", "access", "Expression") instantiate_link(model, "Inheritance", "", "constant", "Expression") instantiate_link(model, "Inheritance", "", "input", "Expression") model_define_attribute(model, "Statement", "next", True, "Statement") model_define_attribute(model, "if", "cond", False, "Expression") model_define_attribute(model, "if", "then", False, "Statement") model_define_attribute(model, "if", "else", 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, "PrimitiveType") 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") model_define_attribute(model, "Statement_next", "name", False, "String") model_define_attribute(model, "if_cond", "name", False, "String") model_define_attribute(model, "if_then", "name", False, "String") model_define_attribute(model, "if_else", "name", False, "String") model_define_attribute(model, "while_cond", "name", False, "String") model_define_attribute(model, "while_body", "name", False, "String") model_define_attribute(model, "assign_var", "name", False, "String") model_define_attribute(model, "assign_value", "name", False, "String") model_define_attribute(model, "break_while", "name", False, "String") model_define_attribute(model, "continue_while", "name", False, "String") model_define_attribute(model, "return_value", "name", False, "String") model_define_attribute(model, "resolve_var", "name", False, "String") model_define_attribute(model, "access_var", "name", False, "String") model_define_attribute(model, "constant_node", "name", False, "String") model_define_attribute(model, "output_node", "name", False, "String") model_define_attribute(model, "global_var", "name", False, "String") model_define_attribute(model, "param_name", "name", False, "String") model_define_attribute(model, "param_value", "name", False, "String") model_define_attribute(model, "param_next_param", "name", False, "String") model_define_attribute(model, "funcdef_body", "name", False, "String") model_define_attribute(model, "call_func", "name", False, "String") model_define_attribute(model, "call_params", "name", False, "String") model_define_attribute(model, "call_last_param", "name", False, "String") return !