Bläddra i källkod

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 8 år sedan
förälder
incheckning
ad887d9880
2 ändrade filer med 23 tillägg och 9 borttagningar
  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 "primitives.alh"
 include "modelling.alh"
 include "modelling.alh"
 include "object_operations.alh"
 include "object_operations.alh"
+include "random.alh"
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
 	String result
 	String result
@@ -16,7 +17,9 @@ Boolean function main(model : Element):
 	Element rules
 	Element rules
 	String rule
 	String rule
 	String value
 	String value
+	Element explored
 
 
+	explored = set_create()
 	result = "root, = yield [('RR', [])]\n"
 	result = "root, = yield [('RR', [])]\n"
 	nodes = allInstances(model, "Rules/Root")
 	nodes = allInstances(model, "Rules/Root")
 	while (set_len(nodes) > 0):
 	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
 					// Is a match node, so fetch the value on the edge
 					name = read_attribute(model, edge, "value")
 					name = read_attribute(model, edge, "value")
 					destination = string_replace(new_node, "/", "_")
 					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")
 	rules = allInstances(model, "Rules/Rule")
 	while (set_len(rules) > 0):
 	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)
 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 author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server