mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-03 00:18:20 +00:00
Restart numbering at every parameter table. Saves many identifiers.
This commit is contained in:
parent
de4d6f8857
commit
649de92ebd
1 changed files with 10 additions and 3 deletions
|
@ -59,7 +59,8 @@ class renamer(object):
|
||||||
elif kind == 'v':
|
elif kind == 'v':
|
||||||
globalvars.append(name)
|
globalvars.append(name)
|
||||||
else:
|
else:
|
||||||
assert False, 'Invalid kind at this scope: ' + kind # pragma: no cover
|
assert False, 'Invalid kind at this scope: ' \
|
||||||
|
+ kind # pragma: no cover
|
||||||
|
|
||||||
# We make three passes, one for states, then functions, then globals,
|
# We make three passes, one for states, then functions, then globals,
|
||||||
# in that order.
|
# in that order.
|
||||||
|
@ -112,11 +113,13 @@ class renamer(object):
|
||||||
# Do the same for function and event parameter names. Pure locals get
|
# Do the same for function and event parameter names. Pure locals get
|
||||||
# long distinct names.
|
# long distinct names.
|
||||||
First = True
|
First = True
|
||||||
|
restart = self.WordFirstChar
|
||||||
for table in self.symtab:
|
for table in self.symtab:
|
||||||
if First:
|
if First:
|
||||||
First = False
|
First = False
|
||||||
# Skip globals
|
# Skip globals
|
||||||
continue
|
continue
|
||||||
|
InParams = False
|
||||||
for name,sym in table.iteritems():
|
for name,sym in table.iteritems():
|
||||||
if name == -1: continue
|
if name == -1: continue
|
||||||
if sym['Kind'] != 'v':
|
if sym['Kind'] != 'v':
|
||||||
|
@ -124,10 +127,14 @@ class renamer(object):
|
||||||
name = name # trick the optimizer
|
name = name # trick the optimizer
|
||||||
continue
|
continue
|
||||||
if 'Param' in sym:
|
if 'Param' in sym:
|
||||||
|
if not InParams:
|
||||||
|
# Restart at every new parameter table.
|
||||||
|
# Parameter tables are isolated from each other.
|
||||||
|
InParams = True
|
||||||
|
self.WordFirstChar = restart
|
||||||
# Same procedure as for global vars
|
# Same procedure as for global vars
|
||||||
# Not the best strategy (using locally unique names would
|
# Not the best strategy (using locally unique names would
|
||||||
# do a better job) but hey. At the time of writing there's
|
# do a better job) but hey.
|
||||||
# no reference analysis. TODO: Implement.
|
|
||||||
if ReusableNames:
|
if ReusableNames:
|
||||||
short = ReusableNames.pop()
|
short = ReusableNames.pop()
|
||||||
self.UsedNames.add(short)
|
self.UsedNames.add(short)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue