summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-02-10 00:14:42 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:02 +0200
commite293546eabf2cac650b764c16a04fd737db7bdac (patch)
tree776b70628cfe783707ed2dbb36bc7738ab3fffe0
parent4204f59b524a447b49dc067d142600e347cc7d88 (diff)
Improve monkey.fix.postprocess
-rwxr-xr-xmonkey/monkey.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/monkey/monkey.py b/monkey/monkey.py
index 080b317..7155c23 100755
--- a/monkey/monkey.py
+++ b/monkey/monkey.py
@@ -107,18 +107,23 @@ def fix(name, code, edits, program_lines, aux_code='', timeout=30, debug=False):
# - check if any lines can be removed from the program
def postprocess(steps):
new_steps = []
- i = 0
- while i < len(steps):
- # Check for successive edits on the same line.
- if i < len(steps)-1 and \
- steps[i][0] in ('add_rule', 'add_subgoal', 'change_line') and \
- steps[i+1][0] == 'change_line' and \
- steps[i][1] == steps[i+1][1] and steps[i][2][1] == steps[i+1][2][0]:
- new_steps.append(('change_line', steps[i][1], (steps[i][2][0], steps[i+1][2][1])))
- i += 1
- else:
- new_steps.append(steps[i])
- i += 1
+ for step in steps:
+ if new_steps:
+ prev = new_steps[-1]
+
+ if prev[1] == step[1] and \
+ prev[0] in ('add_rule', 'add_subgoal', 'change_line') and \
+ step[0] == 'change_line' and \
+ normalized(prev[2][1]) == normalized(step[2][0]):
+ new_steps[-1] = (prev[0], prev[1], (prev[2][0], step[2][1]))
+ continue
+
+ if prev[0] == 'add_subgoal' and step[0] == 'remove_line' and \
+ prev[1]+1 == step[1]:
+ new_steps[-1] = ('change_line', prev[1], (step[2][0], prev[2][1]))
+ continue
+
+ new_steps.append(step)
return new_steps
# Main loop: best-first search through generated programs.