mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Fix bug where 1 + (2 + function) was folded as 4 + function
After folding, our cached values changed under us. Re-cache them.
This commit is contained in:
parent
2740306b6c
commit
18d19b4653
1 changed files with 19 additions and 7 deletions
|
@ -973,20 +973,32 @@ class foldconst(object):
|
|||
return self.FoldTree(parent, index)
|
||||
|
||||
while lnt == 'CONST' and rnt == 'NEG' and rval.ch[0].nt == '~':
|
||||
child[0].value += 1
|
||||
rval = child[1] = rval.ch[0].ch[0]
|
||||
rnt = rval.nt
|
||||
lval.value += 1
|
||||
child[1] = rval.ch[0].ch[0]
|
||||
# rtype doesn't change
|
||||
assert rval.t == 'integer'
|
||||
assert child[1].t == 'integer'
|
||||
self.FoldTree(parent, index)
|
||||
node = parent[index]
|
||||
nt, child = node.nt, node.ch
|
||||
if nt != '+':
|
||||
return
|
||||
lval, rval = child[0], child[1]
|
||||
lnt, rnt = lval.nt, rval.nt
|
||||
ltype, rtype = lval.t, rval.t
|
||||
|
||||
while lnt == 'CONST' and rnt == '~' and rval.ch[0].nt == 'NEG':
|
||||
lval.value -= 1
|
||||
rval = child[1] = rval.ch[0].ch[0]
|
||||
rnt = rval.nt
|
||||
child[1] = rval.ch[0].ch[0]
|
||||
# rtype doesn't change
|
||||
assert rval.t == 'integer'
|
||||
assert child[1].t == 'integer'
|
||||
self.FoldTree(parent, index)
|
||||
node = parent[index]
|
||||
nt, child = node.nt, node.ch
|
||||
if nt != '+':
|
||||
return
|
||||
lval, rval = child[0], child[1]
|
||||
lnt, rnt = lval.nt, rval.nt
|
||||
ltype, rtype = lval.t, rval.t
|
||||
|
||||
if lnt != 'CONST':
|
||||
# Neither is const.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue