Make the -O options case-insensitive.

This commit is contained in:
Sei Lisa 2016-06-28 03:45:39 +02:00
parent 0c3ad9b938
commit 980adff9c8

52
main.py
View file

@ -205,25 +205,27 @@ make the output readable by the optimizer. This option is active by default.
if about == 'optimizer-options': if about == 'optimizer-options':
sys.stderr.write( sys.stderr.write(
r''' r'''
Optimizer options (+ means active by default, - means inactive by default): Optimizer control options.
+ means active by default, - means inactive by default.
Case insensitive.
Syntax extensions options: Syntax extensions options:
extendedglobalexpr + Enables arbitrary expressions in globals (as opposed to ExtendedGlobalExpr + Enables arbitrary expressions in globals (as opposed to
dull simple expressions allowed by regular LSL). Needs dull simple expressions allowed by regular LSL). Needs
constant folding active for the result to be compilable. constant folding active for the result to be compilable.
breakcont - Allow break/continue statements for loops. Note that BreakCont - Allow break/continue statements for loops. Note that
when active, 'break' and 'continue' become reserved when active, 'break' and 'continue' become reserved
words, but when inactive they can be used as variables. words, but when inactive they can be used as variables.
extendedtypecast + Allows extended typecast syntax e.g. (string)(integer)a ExtendedTypeCast + Allows extended typecast syntax e.g. (string)(integer)a
is valid with this option. is valid with this option.
extendedassignment + Enables &=, |=, ^=, <<=, >>= assignment operators. ExtendedAssignment + Enables &=, |=, ^=, <<=, >>= assignment operators.
allowkeyconcat + Allow string + key and key + string (both return string) AllowKeyConcat + Allow string + key and key + string (both return string)
allowmultistrings + Allow C-like string juxtaposition, e.g. "ab" "cd" means AllowMultiStrings + Allow C-like string juxtaposition, e.g. "ab" "cd" means
"abcd", no concatenation involved. Very useful when used "abcd", no concatenation involved. Very useful when used
with a preprocessor. Similar to addstrings, but this one with a preprocessor. Similar to addstrings, but this one
is not an optimization, it introduces new syntax. is not an optimization, it introduces new syntax.
duplabels - Normally, a duplicate label within a function is allowed DupLabels - Normally, a duplicate label within a function is allowed
by the syntax by using {} blocks; however, the server by the syntax by using {} blocks; however, the server
will just refuse to save the script (under Mono) or do will just refuse to save the script (under Mono) or do
something completely unexpected (under LSO: all jumps something completely unexpected (under LSO: all jumps
@ -233,39 +235,39 @@ Optimizer options (+ means active by default, - means inactive by default):
Deprecated / compatibility syntax extensions options: Deprecated / compatibility syntax extensions options:
lazylists - Support syntax like mylist[index] = 5; rather than using LazyLists - Support syntax like mylist[index] = 5; rather than using
llListReplaceList. Only assignment supported. The list llListReplaceList. Only assignment supported. The list
is extended when the argument is greater than the list is extended when the argument is greater than the list
length, by inserting integer zeros. This is implemented length, by inserting integer zeros. This is implemented
for compatibility with Firestorm, but its use is not for compatibility with Firestorm, but its use is not
recommended, as it adds a new function, wasting memory recommended, as it adds a new function, wasting memory
against the very spirit of this program. against the very spirit of this program.
enableswitch - Support C-like switch() syntax, with some limitations. EnableSwitch - Support C-like switch() syntax, with some limitations.
Like lazylists, it's implemented for compatibility with Like lazylists, it's implemented for compatibility with
Firestorm, but not recommended. Note that the operand to Firestorm, but not recommended. Note that the operand to
switch() may be evaluated more than once. switch() may be evaluated more than once.
errmissingdefault + Throw an error in case the 'default:' label of a switch ErrMissingDefault + Throw an error in case the 'default:' label of a switch
statement is missing. statement is missing.
funcoverride - Allow duplicate function definitions to override the FuncOverride - Allow duplicate function definitions to override the
previous definition. For compatibility with Firestorm's previous definition. For compatibility with Firestorm's
optimizer. optimizer.
Optimization options Optimization options
optimize + Runs the optimizer. Optimize + Runs the optimizer.
optsigns + Optimize signs in float and integer constants. OptSigns + Optimize signs in float and integer constants.
optfloats + Optimize floats that represent an integral value. OptFloats + Optimize floats that represent an integral value.
constfold + Fold constant expressions to their values, and simplify ConstFold + Fold constant expressions to their values, and simplify
some expressions and statements. some expressions and statements.
dcr + Dead code removal. This option removes several instances DCR + Dead code removal. This option removes several instances
of code that will never execute, and performs other of code that will never execute, and performs other
optimizations like removal of unused variables, optimizations like removal of unused variables,
functions or expressions. functions or expressions.
shrinknames - Reduces script memory by shrinking identifiers. In the ShrinkNames - Reduces script memory by shrinking identifiers. In the
process, it turns the script into unreadable gibberish, process, it turns the script into unreadable gibberish,
hard to debug, but this gets big savings for complex hard to debug, but this gets big savings for complex
scripts. scripts.
addstrings - Concatenate strings together when possible. Note that AddStrings - Concatenate strings together when possible. Note that
such an optimization can be counter-productive in some such an optimization can be counter-productive in some
cases, that's why it's disabled by default. For example: cases, that's why it's disabled by default. For example:
string a="a"+"longstring"; string b="b"+"longstring"; string a="a"+"longstring"; string b="b"+"longstring";
@ -275,21 +277,21 @@ Optimizer options (+ means active by default, - means inactive by default):
Miscellaneous options Miscellaneous options
foldtabs - Tabs can't be copy-pasted, so expressions that produce FoldTabs - Tabs can't be copy-pasted, so expressions that produce
tabs, e.g. llUnescapeURL("%09"), aren't optimized by tabs, e.g. llUnescapeURL("%09"), aren't optimized by
default. This option overrides that check, enabling default. This option overrides that check, enabling
expansion of functions that produce strings with tabs. expansion of functions that produce strings with tabs.
The resulting source isn't guaranteed to be The resulting source isn't guaranteed to be
copy-paste-able to the viewer. copy-paste-able to the viewer.
warntabs + Suppress warning when a function can't be optimized WarnTabs + Suppress warning when a function can't be optimized
because it generates a string or list with a tab, or because it generates a string or list with a tab, or
when a string contains a tab. when a string contains a tab.
processpre + Process some preprocessor directives in the source. This ProcessPre + Process some preprocessor directives in the source. This
enables usage of #pragma/#line preprocessor directives, enables usage of #pragma/#line preprocessor directives,
and is probably necessary if the script is itself the and is probably necessary if the script is itself the
output of a preprocessor. Note that this option does not output of a preprocessor. Note that this option does not
make the optimizer process macros. make the optimizer process macros.
explicitcast - Add explicit casts where they are implicit. This option ExplicitCast - Add explicit casts where they are implicit. This option
is useless with 'optimize' and 'optsigns', and is of is useless with 'optimize' and 'optsigns', and is of
basically no use in general, other than to see where basically no use in general, other than to see where
automatic casts happen. automatic casts happen.
@ -348,9 +350,9 @@ def main():
if chg[0:1] not in ('+', '-'): if chg[0:1] not in ('+', '-'):
chg = '+' + chg chg = '+' + chg
if chg[0] == '-': if chg[0] == '-':
options.discard(chg[1:]) options.discard(chg[1:].lower())
else: else:
options.add(chg[1:]) options.add(chg[1:].lower())
elif opt in ('-h', '--help'): elif opt in ('-h', '--help'):
Usage() Usage()