Refine 2.7 dead code test ..

in a hacky way. Will probalby have to expand this in the future or
better do dead code analysis
This commit is contained in:
rocky
2018-02-19 07:06:04 -05:00
parent 08c7966ef9
commit f4b7e54313
3 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
# Bug found in 2.7 test_itertools.py
# Bug was erroneously using reduction to unconditional_true
# A proper fix would be to use unconditional_true only when we
# can determine there is or was dead code.
from itertools import izip_longest
for args in [['abc', range(6)]]:
target = [tuple([arg[i] if i < len(arg) else None for arg in args])
for i in range(max(map(len, args)))]
assert list(izip_longest(*args)) == target

View File

@@ -77,7 +77,6 @@ case $PYVERSION in
[test_grammar.py]=1 # Too many stmts. Handle large stmts
[test_io.py]=1 # Test takes too long to run
[test_ioctl.py]=1 # Test takes too long to run
[test_itertools.py]=1 # Syntax error - look at!
[test_memoryio.py]=1 # FIX
[test_multiprocessing.py]=1 # On uncompyle2, taks 24 secs
[test_pep352.py]=1 # ?

View File

@@ -102,7 +102,9 @@ class Python27Parser(Python2Parser):
# conditional_true are for conditions which always evaluate true
# There is dead or non-optional remnants of the condition code though,
# and we use that to match on to reconstruct the source more accurately
# and we use that to match on to reconstruct the source more accurately.
# FIXME: we should do analysis and reduce *only* if there is dead code
expr ::= conditional_true
conditional_true ::= expr JUMP_FORWARD expr COME_FROM
@@ -167,6 +169,7 @@ class Python27Parser(Python2Parser):
""")
super(Python27Parser, self).customize_grammar_rules(tokens, customize)
self.check_reduce['and'] = 'AST'
self.check_reduce['conditional_true'] = 'AST'
return
def reduce_is_invalid(self, rule, ast, tokens, first, last):
@@ -182,6 +185,15 @@ class Python27Parser(Python2Parser):
jmp_target = jmp_false.offset + jmp_false.attr + 3
return not (jmp_target == tokens[last].offset or
tokens[last].pattr == jmp_false.pattr)
elif rule[0] == ('conditional_true'):
# FIXME: the below is a hack. script is probably never used in a boolean
# What we really need is to look for precence of dead code.
if ast[0] == 'expr':
a = ast[0]
else:
a = ast
return a[0] == 'subscript'
return False