mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
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:
parent
dce6419b4f
commit
14e5b78d94
1 changed files with 18 additions and 3 deletions
|
@ -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 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':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue