|
@@ -51,7 +51,7 @@ bottom = [
|
|
|
"instantiate_attribute", "1", "attr_name", "optional", False,
|
|
|
|
|
|
"instantiate_node", "1", "Class", "ComplexAttribute",
|
|
|
- "instantiate_link", "1", "", "Inheritance", "ComplexAttribute", "Attribute",
|
|
|
+ "instantiate_link", "1", "Inheritance", "", "ComplexAttribute", "Attribute",
|
|
|
|
|
|
"model_define_attribute", "1", "Class", "lower_cardinality", True, "Natural",
|
|
|
"model_define_attribute", "1", "Class", "upper_cardinality", True, "Natural",
|
|
@@ -68,7 +68,7 @@ bottom = [
|
|
|
bottom_link_al = [
|
|
|
"model",
|
|
|
"instantiate_node", "1", "ComplexAttribute", "ActionLanguage",
|
|
|
- "instantiate_attribute", "1", "ActionLanguage", "type", "/models/ActionLanguage",
|
|
|
+ "instantiate_attribute", "1", "ActionLanguage", "type", "models/ActionLanguage",
|
|
|
|
|
|
"model_define_attribute", "1", "Element", "constraint", True, "ActionLanguage",
|
|
|
"exit",
|
|
@@ -97,9 +97,15 @@ action_language = [
|
|
|
"instantiate_node", "2", "Class", "input",
|
|
|
"instantiate_node", "2", "Class", "resolve",
|
|
|
"instantiate_node", "2", "Class", "call",
|
|
|
- "instantiate_node", "2", "Class", "Natural",
|
|
|
"instantiate_node", "2", "Class", "String",
|
|
|
- "instantiate_node", "2", "Class", "Boolean",
|
|
|
+ "instantiate_node", "2", "SimpleAttribute", "StringAttr",
|
|
|
+
|
|
|
+ "instantiate_node", "2", "Class", "Initial",
|
|
|
+ "instantiate_attribute", "2", "Initial", "lower_cardinality", 1,
|
|
|
+ "instantiate_attribute", "2", "Initial", "upper_cardinality", 1,
|
|
|
+ "instantiate_link", "2", "Association", "initial_funcdef", "Initial", "Action",
|
|
|
+ "instantiate_attribute", "2", "initial_funcdef", "target_lower_cardinality", 1,
|
|
|
+ "instantiate_attribute", "2", "initial_funcdef", "target_upper_cardinality", 1,
|
|
|
|
|
|
"instantiate_link", "2", "Inheritance", "", "Action", "Element",
|
|
|
"instantiate_link", "2", "Inheritance", "", "funcdef", "Action",
|
|
@@ -120,12 +126,10 @@ action_language = [
|
|
|
"instantiate_link", "2", "Inheritance", "", "access", "Expression",
|
|
|
"instantiate_link", "2", "Inheritance", "", "constant", "Expression",
|
|
|
"instantiate_link", "2", "Inheritance", "", "input", "Expression",
|
|
|
- "instantiate_link", "2", "Inheritance", "", "Natural", "Element",
|
|
|
"instantiate_link", "2", "Inheritance", "", "String", "Element",
|
|
|
- "instantiate_link", "2", "Inheritance", "", "Boolean", "Element",
|
|
|
|
|
|
"instantiate_link", "2", "Association", "dict_link", "Action", "Element",
|
|
|
- "model_define_attribute", "2", "dict_link", "name", False, "String",
|
|
|
+ "model_define_attribute", "2", "dict_link", "name", False, "StringAttr",
|
|
|
"instantiate_attribute", "2", "dict_link", "target_upper_cardinality", 1,
|
|
|
|
|
|
"instantiate_link", "2", "Association", "Statement_next", "Statement", "Statement",
|
|
@@ -192,7 +196,7 @@ def add_constraint(model, element, code):
|
|
|
print(locals())
|
|
|
return [
|
|
|
"model",
|
|
|
- "add_code_model", "AL", location,
|
|
|
+ "add_code_model", "2", location,
|
|
|
] + get_constructor(code) + [
|
|
|
"instantiate_attribute", model, element, "constraint", location,
|
|
|
"exit",
|
|
@@ -299,9 +303,9 @@ def conformance_check(node):
|
|
|
code_natural = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
- String function constraint(model : Element, name : String):
|
|
|
+ String function constraint(params : Element):
|
|
|
Element self
|
|
|
- self = model["model"][name]
|
|
|
+ self = params["model"]["model"][params["name"]]
|
|
|
if (is_physical_int(self)):
|
|
|
if (integer_gte(self, 0)):
|
|
|
return "OK"!
|
|
@@ -314,8 +318,11 @@ code_natural = \
|
|
|
code_string = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
- Element function constraint(model : Element, name : String):
|
|
|
- if (is_physical_string(model["model"][name])):
|
|
|
+ Element function constraint(params : Element):
|
|
|
+ Element self
|
|
|
+ self = params["model"]["model"][params["name"]]
|
|
|
+ log("In constraint")
|
|
|
+ if (is_physical_string(self)):
|
|
|
return "OK"!
|
|
|
else:
|
|
|
return "String has non-string instance"!
|
|
@@ -324,8 +331,10 @@ code_string = \
|
|
|
code_boolean = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
- Element function constraint(model : Element, name : String):
|
|
|
- if (is_physical_boolean(model["model"][name])):
|
|
|
+ Element function constraint(params : Element):
|
|
|
+ Element self
|
|
|
+ self = params["model"]["model"][params["name"]]
|
|
|
+ if (is_physical_boolean(self)):
|
|
|
return "OK"!
|
|
|
else:
|
|
|
return "Boolean has non-boolean instance"!
|
|
@@ -335,9 +344,11 @@ code_location = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "library.alh"
|
|
|
- Element function constraint(model : Element, name : String):
|
|
|
- if (is_physical_string(model["model"][name])):
|
|
|
- if (element_neq(import_node(model["model"][name]), read_root())):
|
|
|
+ Element function constraint(params : Element):
|
|
|
+ Element self
|
|
|
+ self = params["model"]["model"][params["name"]]
|
|
|
+ if (is_physical_string(self)):
|
|
|
+ if (element_neq(import_node(self), read_root())):
|
|
|
return "OK"!
|
|
|
else:
|
|
|
return "Location references non-existing element!"!
|
|
@@ -349,14 +360,16 @@ code_complex_attribute = \
|
|
|
"""
|
|
|
include "primitives.alh"
|
|
|
include "library.alh"
|
|
|
- Element function constraint(model : Element, name : String):
|
|
|
- if (is_physical_string(model["model"][name])):
|
|
|
- if (element_neq(import_node(model["model"][name]), read_root())):
|
|
|
+ Element function constraint(params : Element):
|
|
|
+ Element self
|
|
|
+ self = params["model"]["model"][params["name"]]
|
|
|
+ if (is_physical_string(self)):
|
|
|
+ if (element_neq(import_node(self), read_root())):
|
|
|
return "OK"!
|
|
|
else:
|
|
|
return "Complex Attribute references non-existing element!"!
|
|
|
else:
|
|
|
- return "Complex Attribute has non-string value"!
|
|
|
+ return ("Complex Attribute has non-string value: " + cast_e2s(self))!
|
|
|
"""
|
|
|
|
|
|
class TestConstructorsModels(unittest.TestCase):
|
|
@@ -365,29 +378,37 @@ class TestConstructorsModels(unittest.TestCase):
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_action_language(self):
|
|
|
- commands = bottom + action_language + bottom_link_al + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
+ commands = bottom + action_language + bottom_link_al + \
|
|
|
+ add_constraint("2", "String", code_string) + \
|
|
|
+ add_constraint("2", "StringAttr", code_string) + \
|
|
|
+ conformance_check("models/ActionLanguage") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_constraints_scd(self):
|
|
|
commands = bottom + action_language + bottom_link_al + \
|
|
|
+ add_constraint("2", "String", code_string) + \
|
|
|
+ add_constraint("2", "StringAttr", code_string) + \
|
|
|
add_constraint("1", "Natural", code_natural) + \
|
|
|
add_constraint("1", "String", code_string) + \
|
|
|
add_constraint("1", "Location", code_location) + \
|
|
|
add_constraint("1", "Boolean", code_boolean) + \
|
|
|
- add_constraint("1", "ComplexAttribute", code_complex_attribute) + \
|
|
|
+ add_constraint("1", "ActionLanguage", code_complex_attribute) + \
|
|
|
conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_constraints_pn(self):
|
|
|
commands = bottom + action_language + bottom_link_al + \
|
|
|
+ add_constraint("2", "String", code_string) + \
|
|
|
+ add_constraint("2", "StringAttr", code_string) + \
|
|
|
add_constraint("1", "Natural", code_natural) + \
|
|
|
add_constraint("1", "String", code_string) + \
|
|
|
add_constraint("1", "Location", code_location) + \
|
|
|
add_constraint("1", "Boolean", code_boolean) + \
|
|
|
- add_constraint("1", "ComplexAttribute", code_complex_attribute) + \
|
|
|
+ add_constraint("1", "ActionLanguage", code_complex_attribute) + \
|
|
|
instantiate_scd + \
|
|
|
- instantiate_pn + \
|
|
|
add_constraint("3", "Natural", code_natural) + \
|
|
|
+ conformance_check("models/PetriNets_new") + \
|
|
|
+ instantiate_pn + \
|
|
|
conformance_check("models/PN_instance") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|