diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index 79caf74..f4acebf 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -1674,10 +1674,15 @@ list lazy_list_set(list L, integer i, list v) ]}) if switchcasedefault is None: - switchcasedefault = brk - self.breakstack[-1][2] = True - prelude.append({'nt':'JUMP', 't':None, 'name':switchcasedefault, - 'scope':blkscope}) + warning("No 'default:' label in switch statement") + if self.brokennodefault: + warning("Broken behaviour active - falling through") + if not self.brokennodefault: + switchcasedefault = brk + self.breakstack[-1][2] = True + if switchcasedefault is not None: + prelude.append({'nt':'JUMP', 't':None, 'name':switchcasedefault, + 'scope':blkscope}) last = self.breakstack.pop() if last[2]: blk.append({'nt':'@', 'name':brk, 'scope':blkscope}) @@ -2311,6 +2316,9 @@ list lazy_list_set(list L, integer i, list v) if self.enableswitch: self.keywords |= frozenset(('switch', 'case', 'break')) + # Broken behaviour in the absence of a default: label in a switch stmt. + self.brokennodefault = 'brokennodefault' in options + # Allow brackets for assignment of list elements e.g. mylist[5]=4 self.lazylists = 'lazylists' in options diff --git a/main.py b/main.py index c1ba024..88deec2 100755 --- a/main.py +++ b/main.py @@ -228,6 +228,11 @@ Optimizer options (+ means active by default, - means inactive by default): will go to the last label with that name). This flag works around that limitation by replacing the names of the labels in the output with unique ones. + brokennodefault + Mimic Firestorm's legacy broken behaviour when the + 'default' label in a switch statement is absent. Rather + than jumping to the end of the switch in that case + (which is how it behaves when this option is not set), + it falls through and executes the first 'case' label. Deprecated / compatibility syntax extensions options: @@ -300,7 +305,7 @@ def main(): # Default options options = set(('extendedglobalexpr','extendedtypecast','extendedassignment', 'allowkeyconcat','allowmultistrings','skippreproc','optimize', - 'optsigns','optfloats','constfold','dcr' + 'optsigns','optfloats','constfold','dcr', 'brokennodefault', )) try: