mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Remove support for labels as immediate children of IF/ELSE/WHILE/FOR/DO.
This extremely uncommon coding pattern was becoming a hell to support. It has caused many bugs in past that need them being treated as special cases. Getting rid of the possibility entirely seems like the best approach. It's still supported if the code is not to be optimized (e.g. with --pretty).
This commit is contained in:
parent
27698a92ef
commit
6ef4c03994
2 changed files with 16 additions and 0 deletions
|
@ -24,6 +24,7 @@ from lslfuncs import ZERO_VECTOR, ZERO_ROTATION
|
|||
import math
|
||||
from lslfuncopt import OptimizeFunc, OptimizeArgs, FuncOptSetup
|
||||
|
||||
# TODO: Remove special handling of @ within IF,WHILE,FOR,DO
|
||||
|
||||
class foldconst(object):
|
||||
|
||||
|
|
|
@ -193,6 +193,13 @@ class EParseInvalidBackslash(EParse):
|
|||
u"Preprocessor directive can't end in backslash."
|
||||
u" Activate the preprocessor or put everything in the same line.")
|
||||
|
||||
class EParseInvalidLabelOpt(EParse):
|
||||
def __init__(self, parser):
|
||||
super(EParseInvalidLabelOpt, self).__init__(parser,
|
||||
u"When optimization is active, a label can't be the immediate"
|
||||
u" child of a 'for', 'if', 'while' or 'do'. Disable optimization"
|
||||
u" or rewrite the code in some other way.")
|
||||
|
||||
class EInternal(Exception):
|
||||
"""This exception is a construct to allow a different function to cause an
|
||||
immediate return of EOF from parser.GetToken().
|
||||
|
@ -1688,6 +1695,8 @@ list lazy_list_set(list L, integer i, list v)
|
|||
return nr(nt=';', t=None)
|
||||
|
||||
if tok0 == '@':
|
||||
if not AllowDecl and self.forbidlabels:
|
||||
raise EParseInvalidLabelOpt(self)
|
||||
self.NextToken()
|
||||
self.expect('IDENT')
|
||||
name = self.tok[1]
|
||||
|
@ -2762,6 +2771,12 @@ list lazy_list_set(list L, integer i, list v)
|
|||
# Prettify a source file
|
||||
self.prettify = 'prettify' in options
|
||||
|
||||
# We've decided to ditch support for optimization when the code
|
||||
# includes a label as the immediate child of FOR, IF, DO or WHILE.
|
||||
# If optimization is on, such a label will raise an error. That
|
||||
# coding pattern is normally easy to work around anyway.
|
||||
self.forbidlabels = 'optimize' in options
|
||||
|
||||
# Symbol table:
|
||||
# This is a list of all local and global symbol tables.
|
||||
# The first element (0) is the global scope. Each symbol table is a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue