mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Change while (cond) /*empty*/; into do /*empty*/; while (cond);
This commit is contained in:
parent
8f93386108
commit
caf50c4e14
1 changed files with 21 additions and 13 deletions
|
@ -116,7 +116,7 @@ class foldconst(object):
|
||||||
labels, and applies to a block's statement list, not to a node.
|
labels, and applies to a block's statement list, not to a node.
|
||||||
"""
|
"""
|
||||||
maybe_label = ';' if labels else '@'
|
maybe_label = ';' if labels else '@'
|
||||||
if maybe_label != node.nt != ';':
|
if maybe_label != node.nt != ';' and not node.SEF:
|
||||||
if node.nt == '{}':
|
if node.nt == '{}':
|
||||||
for subnode in node.ch:
|
for subnode in node.ch:
|
||||||
# Labels embedded in {} are not reachable. They do nothing.
|
# Labels embedded in {} are not reachable. They do nothing.
|
||||||
|
@ -1675,18 +1675,26 @@ class foldconst(object):
|
||||||
# out anyway. Otherwise we just don't know if it may be infinite,
|
# out anyway. Otherwise we just don't know if it may be infinite,
|
||||||
# even if every component is SEF.
|
# even if every component is SEF.
|
||||||
|
|
||||||
self.ExpandCondition(child, 0)
|
if self.DoesSomething(child[1]):
|
||||||
self.FoldTree(child, 0)
|
|
||||||
self.FoldCond(child, 0)
|
self.ExpandCondition(child, 0)
|
||||||
if child[0].nt == 'CONST':
|
self.FoldTree(child, 0)
|
||||||
# See if the whole WHILE can be eliminated.
|
self.FoldCond(child, 0)
|
||||||
if not lslfuncs.cond(child[0].value):
|
if child[0].nt == 'CONST':
|
||||||
# Whole statement can be removed.
|
# See if the whole WHILE can be eliminated.
|
||||||
parent[index] = nr(nt=';', t=None, SEF=True)
|
if not lslfuncs.cond(child[0].value):
|
||||||
return
|
# Whole statement can be removed.
|
||||||
self.FoldTree(child, 1)
|
parent[index] = nr(nt=';', t=None, SEF=True)
|
||||||
self.FoldStmt(child, 1)
|
return
|
||||||
return
|
self.FoldTree(child, 1)
|
||||||
|
self.FoldStmt(child, 1)
|
||||||
|
return
|
||||||
|
|
||||||
|
# It does nothing - Turn it into a do..while
|
||||||
|
nt = node.nt = 'DO'
|
||||||
|
child[0], child[1] = child[1], child[0]
|
||||||
|
|
||||||
|
# Fall through to optimize as DO..WHILE
|
||||||
|
|
||||||
if nt == 'DO':
|
if nt == 'DO':
|
||||||
self.FoldTree(child, 0) # This one is always executed.
|
self.FoldTree(child, 0) # This one is always executed.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue