From 6ef4c039944e06247a79c7ad85e7f24ce07076c4 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 1 Apr 2018 20:05:35 +0200 Subject: [PATCH] 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). --- lslopt/lslfoldconst.py | 1 + lslopt/lslparse.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index ebbffe0..4ef13f8 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -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): diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index e83a255..7459f6a 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -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