瀏覽代碼

Check for multi-path conditions: if a node can be reached from multiple
places, all paths must be followed, and all should equal the same
result, or else the match is disregarded

Yentl Van Tendeloo 7 年之前
父節點
當前提交
95b5acb43f
共有 2 個文件被更改,包括 23 次插入9 次删除
  1. 22 8
      kernel/rules/to_python.alc
  2. 1 1
      wrappers/modelverse_SCCD.py

+ 22 - 8
kernel/rules/to_python.alc

@@ -1,6 +1,7 @@
 include "primitives.alh"
 include "modelling.alh"
 include "object_operations.alh"
+include "random.alh"
 
 Boolean function main(model : Element):
 	String result
@@ -16,7 +17,9 @@ Boolean function main(model : Element):
 	Element rules
 	String rule
 	String value
+	Element explored
 
+	explored = set_create()
 	result = "root, = yield [('RR', [])]\n"
 	nodes = allInstances(model, "Rules/Root")
 	while (set_len(nodes) > 0):
@@ -41,16 +44,27 @@ Boolean function main(model : Element):
 					// Is a match node, so fetch the value on the edge
 					name = read_attribute(model, edge, "value")
 					destination = string_replace(new_node, "/", "_")
-					result = result + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+					if (set_in(explored, destination)):
+						// Already visited this one in another way, so try to merge!
+						String rand
+						rand = random_string(10)
+						result = result + rand + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+						result = result + "if " + rand + " != " + destination + ":\n"
+						// If the values don't agree, this is not a correct match, and we say that this element remains unmatched (i.e., assign None)
+						result = result + "\t" + destination + " = None\n"
+					else:
+						// First visit to this element, so just assign
+						result = result + destination + ", = yield [('RD', [" + source + ", " + name + "])]\n"
+						set_add(explored, destination)
 
-					String value
-					value = read_attribute(model, new_node, "value")
-					if (element_neq(value, read_root())):
-						// Match node has a value we should compare as well!
-						// Read out the value from the Modelverse
-						result = result + destination + "_V, = yield [('RV', [" + destination + "])]\n"
+						String value
+						value = read_attribute(model, new_node, "value")
+						if (element_neq(value, read_root())):
+							// Match node has a value we should compare as well!
+							// Read out the value from the Modelverse
+							result = result + destination + "_V, = yield [('RV', [" + destination + "])]\n"
 
-					set_add(to_explore, new_node)
+						set_add(to_explore, new_node)
 
 	rules = allInstances(model, "Rules/Rule")
 	while (set_len(rules) > 0):

+ 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)
 
-Date:   Fri Nov 24 12:23:17 2017
+Date:   Fri Nov 24 12:36:49 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server