浏览代码

First branching based on determined rules

Yentl Van Tendeloo 7 年之前
父节点
当前提交
c3f0808f6a
共有 3 个文件被更改,包括 42 次插入4 次删除
  1. 3 1
      kernel/rules/MvK_rules_MM.mvc
  2. 38 2
      kernel/rules/to_python.alc
  3. 1 1
      wrappers/modelverse_SCCD.py

+ 3 - 1
kernel/rules/MvK_rules_MM.mvc

@@ -14,7 +14,9 @@ Class Match : Node {
 }
 }
 Class Create : Node {}
 Class Create : Node {}
 Class Delete : Match {}
 Class Delete : Match {}
-Class NAC : Node {}
+Class NAC : Node {
+    match : Boolean
+}
 Class Root : Node {}
 Class Root : Node {}
 
 
 Association contains (Rule, Node) {}
 Association contains (Rule, Node) {}

+ 38 - 2
kernel/rules/to_python.alc

@@ -13,7 +13,9 @@ Boolean function main(model : Element):
 	String destination
 	String destination
 	String name
 	String name
 	Element to_explore
 	Element to_explore
-	Element explored
+	Element rules
+	String rule
+	String value
 
 
 	result = "root, = yield [('RR', [])]\n"
 	result = "root, = yield [('RR', [])]\n"
 	nodes = allInstances(model, "Rules/Root")
 	nodes = allInstances(model, "Rules/Root")
@@ -24,7 +26,6 @@ Boolean function main(model : Element):
 
 
 		// Keep following outgoing edges to find matching nodes
 		// Keep following outgoing edges to find matching nodes
 		to_explore = set_create()
 		to_explore = set_create()
-		explored = set_create()
 		set_add(to_explore, node)
 		set_add(to_explore, node)
 
 
 		while (set_len(to_explore) > 0):
 		while (set_len(to_explore) > 0):
@@ -51,6 +52,41 @@ Boolean function main(model : Element):
 
 
 					set_add(to_explore, new_node)
 					set_add(to_explore, new_node)
 
 
+	rules = allInstances(model, "Rules/Rule")
+	while (set_len(rules) > 0):
+		// Check if this rule is applicable
+		rule = set_pop(rules)
+
+		// Fetch all elements with a "match" label and check that they are not None (and possibly, that they have a value)
+		result = result + "if (True "
+		nodes = allAssociationDestinations(model, rule, "Rules/contains")
+		while (set_len(nodes) > 0):
+			node = set_pop(nodes)
+			if (value_eq(read_attribute(model, node, "match"), True)):
+				// We should match on this node:
+				value = read_attribute(model, node, "value")
+				if (bool_and(read_type(model, node) == "Rules/NAC", element_eq(value, read_root()))):
+					result = result + " and " + string_replace(node, "/", "_") + " is None "
+				else:
+					result = result + " and " + string_replace(node, "/", "_") + " is not None "
+
+				if (element_neq(value, read_root())):
+					// Got a value, so match that as well
+					// But check if it is an action element (first character == !)
+					String sign
+
+					if (read_type(model, node) == "Rules/NAC"):
+						sign = "!="
+					else:
+						sign = "=="
+
+					if (string_get(value, 0) == "!"):
+						result = result + " and " + string_replace(node, "/", "_") + "_V['value'] " + sign + " '" + string_replace(value, "!", "") + "'"
+					else:
+						result = result + " and " + string_replace(node, "/", "_") + "_V " + sign + " " + value
+
+		result = result + "): pass # Execute rule " + string_replace(rule, "/", "_") + "\n"
+
 	log("Got result:")
 	log("Got result:")
 	log(result)
 	log(result)
 	return True!
 	return True!

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Fri Nov 24 11:09:50 2017
+Date:   Fri Nov 24 12:23:17 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server