diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index 204362e..ac01e99 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -2628,6 +2628,9 @@ list lazy_list_set(list L, integer i, list v) # # Allow referencing undefined functions inside function definitions. # self.allowundeffn = 'allowundeffn' in options + # Prettify a source file + self.prettify = 'prettify' 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 @@ -2650,6 +2653,16 @@ list lazy_list_set(list L, integer i, list v) self.symtab[0][-1] = None self.scopeindex = 0 + if self.prettify: + # Add the constants as symbol table variables... + for i in self.constants: + self.symtab[0][i] = {'Kind':'v', 'Scope':0, + 'Type':lslcommon.PythonType2LSL[type(self.constants[i])]} + # ... and remove them as constants. + self.constants = {} + # Remove TRUE and FALSE from keywords + self.keywords -= set(('TRUE', 'FALSE')) + # Last preprocessor __FILE__. means the current file. self.lastFILE = '' diff --git a/main.py b/main.py index 2238b21..a33e8b1 100755 --- a/main.py +++ b/main.py @@ -217,6 +217,7 @@ Usage: {progname} [--avname=] * specify name of avatar saving the script [--assetid=] * specify the asset UUID of the script [--shortname=] * specify the script's short file name + [--prettify] Prettify source file. Disables all -O options. filename input file Options marked with * are used to define the preprocessor macros __AGENTID__, @@ -359,6 +360,7 @@ validoptions = frozenset(('extendedglobalexpr','breakcont','extendedtypecast', # undocumented 'lso','expr','rsrclimit', # 'clear' is handled as a special case + # 'prettify' is internal, as it's a user flag )) def main(argv): @@ -382,7 +384,7 @@ def main(argv): try: opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTyb:L:', ('optimizer-options=', 'help', 'version', 'output=', 'header', - 'timestamp','python-exceptions', + 'timestamp', 'python-exceptions', 'prettify', 'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow', 'avid=', 'avname=', 'assetid=', 'shortname=', 'builtins=' 'libdata=')) @@ -404,6 +406,7 @@ def main(argv): mcpp_mode = False preshow = False raise_exception = False + prettify = False builtins = None libdata = None @@ -525,8 +528,15 @@ def main(argv): elif opt == '--shortname': shortname = arg + + elif opt == '--prettify': + prettify = True del opts + if prettify: + options &= set(('rsrclimit',)) + options.add('prettify') + try: if 'rsrclimit' in options: