Try to do better with the propagation of FoldCond.

Negation, specifically, didn't propagate to children. This might be redundant, though.
This commit is contained in:
Sei Lisa 2017-08-15 13:07:30 +02:00
parent c5b5a8303c
commit 2e29cc9131

View file

@ -130,14 +130,18 @@ class foldconst(object):
return # Nothing to do if it's already simplified. return # Nothing to do if it's already simplified.
child = node['ch'] if 'ch' in node else None child = node['ch'] if 'ch' in node else None
if nt == '!' and child[0]['nt'] == '!': if nt == '!':
# bool(!!a) equals bool(a) self.FoldCond(child, 0, True)
parent[index] = child[0]['ch'][0]
return if child[0]['nt'] == '!':
# bool(!!a) equals bool(a)
parent[index] = child[0]['ch'][0]
return
if nt == 'NEG': if nt == 'NEG':
# bool(-a) equals bool(a) # bool(-a) equals bool(a)
parent[index] = child[0] parent[index] = child[0]
self.FoldCond(parent, index, ParentIsNegation)
return return
if nt in self.binary_ops and child[0]['t'] == child[1]['t'] == 'integer': if nt in self.binary_ops and child[0]['t'] == child[1]['t'] == 'integer':