Remove empty statements. Optimize out 'else ;' and 'else {}'.

Without empty statement removal, {;} would trick the optimizer into believing the statement was not empty. E.g. if(x) ; else {;} would not remove the else.
This commit is contained in:
Sei Lisa 2014-08-02 10:40:59 +02:00
parent dce6419b4f
commit 14e5b78d94

View file

@ -447,12 +447,23 @@ class optimizer(renamer, deadcode):
parent[index] = {'nt':'CONST', 't':node['t'], 'value':value}
return
if nt in ('{}', 'FNDEF', 'STDEF'):
if nt == 'STDEF':
for idx in xrange(len(child)):
self.FoldTree(child, idx)
return
if nt in ('{}', 'FNDEF'):
idx = 0
while idx < len(child):
self.FoldTree(child, idx)
self.FoldStmt(child, idx)
if 'StSw' in child[idx]:
node['StSw'] = True
if child[idx]['nt'] == ';' \
or nt == '{}' and child[idx]['nt'] == '{}' and not child[idx]['ch']:
del child[idx]
else:
if 'StSw' in child[idx]:
node['StSw'] = True
idx += 1
return
if nt == 'IF':
@ -484,6 +495,10 @@ class optimizer(renamer, deadcode):
if len(child) > 2:
self.FoldTree(child, 2)
self.FoldStmt(child, 2)
if child[2]['nt'] == ';' \
or child[2]['nt'] == '{}' and not child[2]['ch']:
# no point in "... else ;" - remove else branch
del child[2]
return
if nt == 'WHILE':