mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Improve llStringLength detection, to catch more cases.
For example, if (llStringLength(s) > 0) -> if (!(s == ""))
This commit is contained in:
parent
4c8227bae5
commit
3bb5102f06
1 changed files with 17 additions and 11 deletions
|
@ -267,6 +267,22 @@ class foldconst(object):
|
||||||
return # Nothing to do if it's already simplified.
|
return # Nothing to do if it's already simplified.
|
||||||
child = node['ch'] if 'ch' in node else None
|
child = node['ch'] if 'ch' in node else None
|
||||||
|
|
||||||
|
if nt == 'FNCALL' and node['name'] == 'llStringLength':
|
||||||
|
# llStringLength(expr) -> !(expr == "")
|
||||||
|
node = {'nt':'==', 't':'integer',
|
||||||
|
'ch':[child[0],
|
||||||
|
{'nt':'CONST', 't':'string',
|
||||||
|
'value':u''}]}
|
||||||
|
node = {'nt':'!', 't':'integer', 'ch':[node]}
|
||||||
|
# new node is SEF if the argument to llStringLength is
|
||||||
|
if 'SEF' in child[0]:
|
||||||
|
node['SEF'] = True
|
||||||
|
node['ch'][0]['SEF'] = True
|
||||||
|
parent[index] = node
|
||||||
|
nt = '!'
|
||||||
|
child = node['ch']
|
||||||
|
# fall through to keep optimizing if necessary
|
||||||
|
|
||||||
if nt == '!':
|
if nt == '!':
|
||||||
self.FoldCond(child, 0, True)
|
self.FoldCond(child, 0, True)
|
||||||
|
|
||||||
|
@ -281,7 +297,6 @@ class foldconst(object):
|
||||||
self.FoldCond(parent, index, ParentIsNegation)
|
self.FoldCond(parent, index, ParentIsNegation)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if nt in self.binary_ops and child[0]['t'] == child[1]['t'] == 'integer':
|
if nt in self.binary_ops and child[0]['t'] == child[1]['t'] == 'integer':
|
||||||
if nt == '!=':
|
if nt == '!=':
|
||||||
if child[0]['nt'] == 'CONST' and child[0]['value'] == 1 \
|
if child[0]['nt'] == 'CONST' and child[0]['value'] == 1 \
|
||||||
|
@ -645,16 +660,6 @@ class foldconst(object):
|
||||||
subexpr = child[0]
|
subexpr = child[0]
|
||||||
snt = subexpr['nt']
|
snt = subexpr['nt']
|
||||||
|
|
||||||
if snt == 'FNCALL' and subexpr['name'] == 'llStringLength':
|
|
||||||
# !llStringLength(expr) -> expr == ""
|
|
||||||
parent[index] = {'nt':'==', 't':'integer',
|
|
||||||
'ch':[subexpr['ch'][0],
|
|
||||||
{'nt':'CONST', 't':'string',
|
|
||||||
'value':u""}]}
|
|
||||||
# new node is SEF if the argument to llStringLength is
|
|
||||||
if 'SEF' in subexpr['ch'][0]:
|
|
||||||
parent[index]['SEF'] = True
|
|
||||||
return
|
|
||||||
if 'SEF' in subexpr:
|
if 'SEF' in subexpr:
|
||||||
node['SEF'] = True
|
node['SEF'] = True
|
||||||
if subexpr['nt'] == 'CONST':
|
if subexpr['nt'] == 'CONST':
|
||||||
|
@ -1419,6 +1424,7 @@ class foldconst(object):
|
||||||
fn = sym['Fn']
|
fn = sym['Fn']
|
||||||
args = [arg['value'] for arg in child]
|
args = [arg['value'] for arg in child]
|
||||||
assert len(args) == len(sym['ParamTypes'])
|
assert len(args) == len(sym['ParamTypes'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# May raise ELSLCantCompute
|
# May raise ELSLCantCompute
|
||||||
if name[:10] == 'llDetected':
|
if name[:10] == 'llDetected':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue