Change while (cond) /*empty*/; into do /*empty*/; while (cond);

This commit is contained in:
Sei Lisa 2018-05-17 06:19:35 +02:00
parent 8f93386108
commit caf50c4e14

View file

@ -116,7 +116,7 @@ class foldconst(object):
labels, and applies to a block's statement list, not to a node.
"""
maybe_label = ';' if labels else '@'
if maybe_label != node.nt != ';':
if maybe_label != node.nt != ';' and not node.SEF:
if node.nt == '{}':
for subnode in node.ch:
# Labels embedded in {} are not reachable. They do nothing.
@ -1675,6 +1675,8 @@ class foldconst(object):
# out anyway. Otherwise we just don't know if it may be infinite,
# even if every component is SEF.
if self.DoesSomething(child[1]):
self.ExpandCondition(child, 0)
self.FoldTree(child, 0)
self.FoldCond(child, 0)
@ -1688,6 +1690,12 @@ class foldconst(object):
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':
self.FoldTree(child, 0) # This one is always executed.
self.FoldStmt(child, 0)