mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Create a list of valid optimizer options and check against it.
Validating the input options was badly needed.
This commit is contained in:
parent
e2ad14ee1b
commit
e3632d8a64
1 changed files with 27 additions and 5 deletions
32
main.py
32
main.py
|
@ -300,6 +300,15 @@ Case insensitive.
|
|||
""")
|
||||
return
|
||||
|
||||
validoptions = frozenset(('extendedglobalexpr','breakcont','extendedtypecast',
|
||||
'extendedassignment','allowkeyconcat','allowmultistrings','duplabels',
|
||||
'lazylists','enableswitch','errmissingdefault','funcoverride','optimize',
|
||||
'optsigns','optfloats','constfold','dcr','shrinknames','addstrings',
|
||||
'foldtabs','warntabs','processpre','explicitcast',
|
||||
'help'
|
||||
# 'clear' is handled as a special case
|
||||
))
|
||||
|
||||
def main(argv):
|
||||
"""Main executable."""
|
||||
|
||||
|
@ -313,6 +322,10 @@ def main(argv):
|
|||
'optsigns','optfloats','constfold','dcr','errmissingdefault',
|
||||
))
|
||||
|
||||
assert not (options - validoptions), (u"Default options not present in"
|
||||
u" validoptions: '%s'"
|
||||
% (b"', '".join(options - validoptions)).decode('utf8'))
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HT',
|
||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||
|
@ -346,18 +359,27 @@ def main(argv):
|
|||
if opt in ('-O', '--optimizer-options'):
|
||||
optchanges = arg.lower().split(',')
|
||||
for chg in optchanges:
|
||||
if not chg:
|
||||
continue
|
||||
if chg in ('clear', '+clear'):
|
||||
options = set()
|
||||
continue
|
||||
if chg == '-clear':
|
||||
# ignore
|
||||
continue
|
||||
if chg[0:1] not in ('+', '-'):
|
||||
chg = '+' + chg
|
||||
if chg[0] == '-':
|
||||
options.discard(chg[1:])
|
||||
chgfix = chg
|
||||
if chgfix[0] not in ('+', '-'):
|
||||
chgfix = '+' + chgfix
|
||||
if chgfix[1:] not in validoptions:
|
||||
Usage(argv[0], 'optimizer-options')
|
||||
sys.stderr.write(u"\nError: Unrecognized"
|
||||
u" optimizer option: %s\n" % chg)
|
||||
return 1
|
||||
if chgfix[0] == '-':
|
||||
options.discard(chgfix[1:])
|
||||
else:
|
||||
options.add(chg[1:])
|
||||
options.add(chgfix[1:])
|
||||
del chgfix
|
||||
|
||||
elif opt in ('-h', '--help'):
|
||||
Usage(argv[0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue