Narrow the 2.7 unconditional_true reduction

This commit is contained in:
rocky
2018-02-19 17:06:18 -05:00
parent deb9903a97
commit 8864034966

View File

@@ -103,7 +103,8 @@ 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.
# FIXME: we should do analysis and reduce *only* if there is dead code
# FIXME: we should do analysis and reduce *only* if there is dead code?
# right now we check that expr is "or". Any other nodes types?
expr ::= conditional_true
conditional_true ::= expr JUMP_FORWARD expr COME_FROM
@@ -186,14 +187,10 @@ class Python27Parser(Python2Parser):
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: "subscript" was probably never used
# in a boolean which got eliminated. 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'
# FIXME: the below is a hack: we check expr for
# nodes that could have possibly been a been a Boolean.
# We should also look for the presence of dead code.
return ast[0] == 'expr' and ast[0] == 'or'
return False