mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-03 00:18:20 +00:00
Remove empty SEF events.
If the state becomes empty, add an empty timer() event. timer() is the parameter-less event with the shortest name.
This commit is contained in:
parent
e13f210695
commit
ed49170d87
1 changed files with 16 additions and 1 deletions
|
@ -1497,6 +1497,15 @@ class foldconst(object):
|
||||||
# event definition
|
# event definition
|
||||||
self.CurEvent = node['name']
|
self.CurEvent = node['name']
|
||||||
self.FoldTree(child, 0)
|
self.FoldTree(child, 0)
|
||||||
|
|
||||||
|
# Test if the event is empty and SEF, and remove it if so.
|
||||||
|
if ('scope' not in node and not self.DoesSomething(child[0],
|
||||||
|
labels = False) and 'SEF' in self.events[node['name']]
|
||||||
|
):
|
||||||
|
# Delete ourselves.
|
||||||
|
del parent[index]
|
||||||
|
return
|
||||||
|
|
||||||
# TODO: This works, but analysis of code paths is DCR's thing
|
# TODO: This works, but analysis of code paths is DCR's thing
|
||||||
# and this is incomplete, e.g. x(){{return;}} is not detected.
|
# and this is incomplete, e.g. x(){{return;}} is not detected.
|
||||||
while 'ch' in child[0] and child[0]['ch']:
|
while 'ch' in child[0] and child[0]['ch']:
|
||||||
|
@ -1534,8 +1543,14 @@ class foldconst(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt == 'STDEF':
|
if nt == 'STDEF':
|
||||||
for idx in xrange(len(child)):
|
for idx in xrange(len(child) - 1, -1, -1):
|
||||||
self.FoldTree(child, idx)
|
self.FoldTree(child, idx)
|
||||||
|
if not child:
|
||||||
|
# All events removed - add a dummy timer()
|
||||||
|
child.append({'nt':'FNDEF', 't':None, 'name':'timer',
|
||||||
|
'pscope':0, 'ptypes':[], 'pnames':[],
|
||||||
|
'ch':[{'nt':'{}', 't':None, 'ch':[]}]
|
||||||
|
})
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt == '{}':
|
if nt == '{}':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue