Add Pop to the list of idents that GetNextShortest can't generate

It's unlikely to hit this one (requires more than 10,000 identifiers to trigger) but it's a bug nevertheless.

While touching the file, try to explain the situation better in the first comment.
This commit is contained in:
Sei Lisa 2021-01-05 23:27:49 +01:00
parent 81906475ff
commit da05d1e1c2

View file

@ -15,11 +15,12 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>. # along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
# This module renames all kinds of variables. Globals and function/event # This module renames all kinds of variables. Global variables, user functions,
# parameters take memory space, so shrinking the identifiers as much as # state names, event names and function/event parameters all take memory space,
# possible ensures their memory usage will be minimized. It also reuses some # so shrinking the identifiers as much as possible, when possible (i.e. not for
# preexisting names when possible. Locals are renamed also so that they don't # events or the default state), ensures their memory usage will be minimized.
# stand in the way of globals. # It also reuses some preexisting names. Locals are renamed also so that they
# don't stand in the way of globals.
# #
# A side effect of this change is that the script becomes unreadable gibberish. # A side effect of this change is that the script becomes unreadable gibberish.
@ -28,8 +29,11 @@ from strutil import xrange
class renamer(object): class renamer(object):
CharSet1 = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' CharSet1 = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
CharSet2 = '0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' CharSet2 = '0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
# As a special case, 'Pop' is not a keyword, but it's one of the predefined
# identifiers, therefore it must not be generated by GetNextShortest
# because it's already in the list of identifiers available from the start.
Kws = frozenset({'do', 'if', 'PI', Kws = frozenset({'do', 'if', 'PI',
'for', 'key', 'EOF', 'for', 'key', 'EOF', 'Pop',
'jump', 'else', 'list', 'TRUE', 'LOOP', 'case' 'jump', 'else', 'list', 'TRUE', 'LOOP', 'case'
}) })
def GetNextShortest(self): def GetNextShortest(self):