Browse Source

NAC matching finishes when only a single match is required

Yentl Van Tendeloo 8 years ago
parent
commit
90df0749ea
1 changed files with 11 additions and 8 deletions
  1. 11 8
      bootstrap/transform.alc

+ 11 - 8
bootstrap/transform.alc

@@ -44,7 +44,7 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 			if (bool_not(set_in(schedule, next))):
 				if (set_in(full_all_elements, next)):
 					if (bool_not(set_in(ignore, read_attribute(schedule_model, next, "label")))):
-						list_append(schedule, next)
+						list_insert(schedule, next, 0)
 					else:
 						required_size = required_size - 1
 
@@ -210,7 +210,7 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 	options = filtered_options
 	return options!
 
-Element function full_match(host_model : Element, schedule_model : Element, current : String):
+Element function full_match(host_model : Element, schedule_model : Element, current : String, single_ok : Boolean):
 	Element NACs
 	String LHS
 	String NAC
@@ -247,6 +247,9 @@ Element function full_match(host_model : Element, schedule_model : Element, curr
 		if (allowed):
 			set_add(final_mappings, mapping)
 
+		if (single_ok):
+			break!
+
 	return final_mappings!
 
 Element function match(host_model : Element, schedule_model : Element, LHS : String, initial_mapping : Element):
@@ -268,7 +271,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	mappings = create_node()
 	set_add(mappings, initial_mapping)
 	while (read_nr_out(schedule) > 0):
-		current_element = list_pop(schedule, 0)
+		current_element = list_pop(schedule, read_nr_out(schedule) - 1)
 		log("Binding element with label " + cast_v2s(read_attribute(schedule_model, current_element, "label")))
 		new_mappings = create_node()
 
@@ -355,7 +358,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 
 	while (read_nr_out(labels_to_add) > 0):
 		// Add the elements linked to these labels
-		label = list_pop(labels_to_add, 0)
+		label = list_pop(labels_to_add, read_nr_out(labels_to_add) - 1)
 		if (is_edge(schedule_model["model"][RHS_map[label]])):
 			// Edge
 			src = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_src(schedule_model["model"][RHS_map[label]])), "label")
@@ -369,7 +372,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 				dict_add(new_mapping, label, new_name)
 			else:
 				// Delay this a bit, until all are bound
-				list_append(labels_to_add, label)
+				list_insert(labels_to_add, label, 0)
 		else:
 			// Node
 			// Create the node and add it
@@ -489,7 +492,7 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 	// Execute the atomic transformation
 	Element mappings
 	Element mapping
-	mappings = full_match(host_model, schedule_model, current)
+	mappings = full_match(host_model, schedule_model, current, True)
 
 	if (read_nr_out(mappings) > 0):
 		// Pick one!
@@ -508,7 +511,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	Element mapping
 	Boolean result
 
-	mappings = full_match(host_model, schedule_model, current)
+	mappings = full_match(host_model, schedule_model, current, False)
 
 	if (read_nr_out(mappings) > 0):
 		result = True
@@ -528,7 +531,7 @@ Boolean function transform_query(host_model : Element, schedule_model : Element,
 	// Execute the transformation
 	Element mappings
 	Element mapping
-	mappings = full_match(host_model, schedule_model, current)
+	mappings = full_match(host_model, schedule_model, current, True)
 
 	if (read_nr_out(mappings) > 0):
 		return True!