mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Make DoesSomething apply to labels optionally.
Allows detection of empty events, for example, even if they have labels. Also, it is OK if there's a label inserted in a nested {}; that case wasn't contemplated.
This commit is contained in:
parent
f2a6243695
commit
e13f210695
1 changed files with 9 additions and 6 deletions
|
@ -131,17 +131,20 @@ class foldconst(object):
|
||||||
else:
|
else:
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
def DoesSomething(self, node):
|
def DoesSomething(self, node, labels = True):
|
||||||
"""Tell if a subtree does something or is just empty statements
|
"""Tell if a subtree does something or is just empty statements
|
||||||
(a pure combination of ';' and '{}')
|
(a pure combination of ';' and '{}'). Labels are the top level are
|
||||||
|
considered to do something if labels is True, and vice versa.
|
||||||
|
|
||||||
Not to be confused with lslparse.does_something which includes labels,
|
Not to be confused with lslparse.does_something which always includes
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
if node['nt'] != ';':
|
maybe_label = ';' if labels else '@'
|
||||||
|
if maybe_label != node['nt'] != ';':
|
||||||
if node['nt'] == '{}':
|
if node['nt'] == '{}':
|
||||||
for subnode in node['ch']:
|
for subnode in node['ch']:
|
||||||
if self.DoesSomething(subnode):
|
# Labels embedded in {} are not reachable. They do nothing.
|
||||||
|
if self.DoesSomething(subnode, labels = False):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue