mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-03 00:18:20 +00:00
Do -(b + -c) -> -b+c. Also when a-b is transformed to a+-b, fold -b.
This commit is contained in:
parent
a859b3e8e4
commit
be86216124
1 changed files with 14 additions and 1 deletions
|
@ -299,8 +299,20 @@ class foldconst(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt == 'NEG':
|
if nt == 'NEG':
|
||||||
# TODO: -(b + -c) -> -b+c, -(-b + c) -> b + -c
|
|
||||||
self.FoldTree(child, 0)
|
self.FoldTree(child, 0)
|
||||||
|
|
||||||
|
if child[0]['nt'] == '+' and (child[0]['ch'][0]['nt'] == 'NEG'
|
||||||
|
or child[0]['ch'][1]['nt'] == 'NEG'):
|
||||||
|
node = parent[index] = child[0]
|
||||||
|
child = node['ch']
|
||||||
|
for a in (0, 1):
|
||||||
|
if child[a]['nt'] == 'NEG':
|
||||||
|
child[a] = child[a]['ch'][0]
|
||||||
|
else:
|
||||||
|
child[a] = {'nt':'NEG','t':child[a]['t'],'ch':[child[a]]}
|
||||||
|
self.FoldTree(child, a)
|
||||||
|
return
|
||||||
|
|
||||||
if child[0]['nt'] == 'NEG':
|
if child[0]['nt'] == 'NEG':
|
||||||
# Double negation: - - expr -> expr
|
# Double negation: - - expr -> expr
|
||||||
node = parent[index] = child[0]['ch'][0]
|
node = parent[index] = child[0]['ch'][0]
|
||||||
|
@ -469,6 +481,7 @@ class foldconst(object):
|
||||||
rnt = 'NEG'
|
rnt = 'NEG'
|
||||||
RSEF = 'SEF' in rval
|
RSEF = 'SEF' in rval
|
||||||
rval = child[1] = {'nt':rnt, 't':rval['t'], 'ch':[rval]}
|
rval = child[1] = {'nt':rnt, 't':rval['t'], 'ch':[rval]}
|
||||||
|
self.FoldTree(child, 1)
|
||||||
if RSEF:
|
if RSEF:
|
||||||
rval['SEF'] = True
|
rval['SEF'] = True
|
||||||
# rtype unchanged
|
# rtype unchanged
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue