mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Add optimization of declarations.
integer a = 0; -> integer a; float f; -> float f = 0; vector v; -> vector v = <0,0,0>; rotation r -> rotation r = <0,0,0,1>;
This commit is contained in:
parent
6ec39aa745
commit
2cbed52bf7
1 changed files with 12 additions and 4 deletions
|
@ -521,13 +521,21 @@ class optimizer(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt == 'DECL':
|
if nt == 'DECL':
|
||||||
# The expression code is elsewhere.
|
|
||||||
if child:
|
if child:
|
||||||
self.FoldTree(child, 0)
|
self.FoldTree(child, 0)
|
||||||
# TODO: Remove assignment if integer zero.
|
# Remove assignment if integer zero.
|
||||||
|
if node['t'] == 'integer' and child[0]['nt'] == 'CONST' \
|
||||||
|
and not child[0]['value']:
|
||||||
|
del node['ch']
|
||||||
|
child = None
|
||||||
else:
|
else:
|
||||||
# TODO: Add assignment if vector, rotation or float.
|
# Add assignment if vector, rotation or float.
|
||||||
pass
|
if node['t'] in ('float', 'vector', 'rotation'):
|
||||||
|
typ = node['t']
|
||||||
|
node['ch'] = [{'nt':'CONST', 't':typ, 'value':
|
||||||
|
0.0 if typ == 'float' else
|
||||||
|
lslfuncs.ZERO_VECTOR if typ == 'vector' else
|
||||||
|
lslfuncs.ZERO_ROTATION}]
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt in self.ignored_stmts:
|
if nt in self.ignored_stmts:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue