mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +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
|
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):
|
def main(argv):
|
||||||
"""Main executable."""
|
"""Main executable."""
|
||||||
|
|
||||||
|
@ -313,6 +322,10 @@ def main(argv):
|
||||||
'optsigns','optfloats','constfold','dcr','errmissingdefault',
|
'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:
|
try:
|
||||||
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HT',
|
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HT',
|
||||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||||
|
@ -346,18 +359,27 @@ def main(argv):
|
||||||
if opt in ('-O', '--optimizer-options'):
|
if opt in ('-O', '--optimizer-options'):
|
||||||
optchanges = arg.lower().split(',')
|
optchanges = arg.lower().split(',')
|
||||||
for chg in optchanges:
|
for chg in optchanges:
|
||||||
|
if not chg:
|
||||||
|
continue
|
||||||
if chg in ('clear', '+clear'):
|
if chg in ('clear', '+clear'):
|
||||||
options = set()
|
options = set()
|
||||||
continue
|
continue
|
||||||
if chg == '-clear':
|
if chg == '-clear':
|
||||||
# ignore
|
# ignore
|
||||||
continue
|
continue
|
||||||
if chg[0:1] not in ('+', '-'):
|
chgfix = chg
|
||||||
chg = '+' + chg
|
if chgfix[0] not in ('+', '-'):
|
||||||
if chg[0] == '-':
|
chgfix = '+' + chgfix
|
||||||
options.discard(chg[1:])
|
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:
|
else:
|
||||||
options.add(chg[1:])
|
options.add(chgfix[1:])
|
||||||
|
del chgfix
|
||||||
|
|
||||||
elif opt in ('-h', '--help'):
|
elif opt in ('-h', '--help'):
|
||||||
Usage(argv[0])
|
Usage(argv[0])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue