mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Remove handling of corner cases that we decided to not support
There was some remaining code trying to deal with labels in the single statement part of IFs and FORs.
This commit is contained in:
parent
b329b2b28e
commit
6f32b4710a
1 changed files with 3 additions and 25 deletions
|
@ -1781,11 +1781,7 @@ class foldconst(object):
|
||||||
# If type(X) != Key, then:
|
# If type(X) != Key, then:
|
||||||
# if (X) ; else {stuff} -> if (!X) {stuff}
|
# if (X) ; else {stuff} -> if (!X) {stuff}
|
||||||
# (being careful with labels again)
|
# (being careful with labels again)
|
||||||
if (child[0].t != 'key'
|
if child[0].t != 'key':
|
||||||
and (child[2].nt != 'IF'
|
|
||||||
or len(child[2].ch) == 3
|
|
||||||
or child[2].ch[1].nt != '@')
|
|
||||||
):
|
|
||||||
# We've already converted all other types to equivalent
|
# We've already converted all other types to equivalent
|
||||||
# comparisons
|
# comparisons
|
||||||
assert child[0].t == 'integer'
|
assert child[0].t == 'integer'
|
||||||
|
@ -1859,18 +1855,12 @@ class foldconst(object):
|
||||||
self.FoldStmt(child, 3)
|
self.FoldStmt(child, 3)
|
||||||
self.FoldAndRemoveEmptyStmts(child[2].ch)
|
self.FoldAndRemoveEmptyStmts(child[2].ch)
|
||||||
else:
|
else:
|
||||||
|
# Loop never executes.
|
||||||
# Convert expression list to code block.
|
# Convert expression list to code block.
|
||||||
exprlist = []
|
exprlist = []
|
||||||
for expr in child[0].ch:
|
for expr in child[0].ch:
|
||||||
# Fold into expression statements.
|
# Fold into expression statements.
|
||||||
exprlist.append(nr(nt='EXPR', t=expr.t, ch=[expr]))
|
exprlist.append(nr(nt='EXPR', t=expr.t, ch=[expr]))
|
||||||
if (exprlist or child[2].ch) and child[3].nt == '@':
|
|
||||||
# Corner case. We can't optimize this to one single
|
|
||||||
# statement, so we leave it as-is.
|
|
||||||
self.FoldTree(child, 3)
|
|
||||||
self.FoldStmt(child, 3)
|
|
||||||
self.FoldAndRemoveEmptyStmts(child[2].ch)
|
|
||||||
return
|
|
||||||
|
|
||||||
# returns type None, as FOR does
|
# returns type None, as FOR does
|
||||||
if exprlist:
|
if exprlist:
|
||||||
|
@ -1879,19 +1869,7 @@ class foldconst(object):
|
||||||
# removed earlier) so don't mark this node as SEF.
|
# removed earlier) so don't mark this node as SEF.
|
||||||
parent[index] = nr(nt='{}', t=None, ch=exprlist)
|
parent[index] = nr(nt='{}', t=None, ch=exprlist)
|
||||||
else:
|
else:
|
||||||
if child[3].nt == '@':
|
parent[index] = nr(nt=';', t=None, SEF=True)
|
||||||
# Corner case. The label is in the same scope as
|
|
||||||
# this statement, so it must be preserved. Also,
|
|
||||||
# jumping inside the loop would execute the
|
|
||||||
# iterator, so we fold it.
|
|
||||||
self.FoldAndRemoveEmptyStmts(child[2].ch)
|
|
||||||
if not child[2].ch:
|
|
||||||
# if there's something in the 2nd list,
|
|
||||||
# preserve the whole statement, otherwise
|
|
||||||
# replace it with the label
|
|
||||||
parent[index] = child[3]
|
|
||||||
else:
|
|
||||||
parent[index] = nr(nt=';', t=None, SEF=True)
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.FoldTree(child, 3)
|
self.FoldTree(child, 3)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue