Add 'nofoldtabs' option to disable warning when a function generates tabs

When a function folds to a string that contains a tab, e.g. llUnescapeURL("%09"), or to a list that contains a string that contains a tab, a warning is emitted unless the foldtabs option (which forces the optimization) is used. This option allows to quiet the warning without forcing the optimization.
This commit is contained in:
Sei Lisa 2016-04-01 20:48:33 +02:00
parent 5804a9a610
commit dc98e477d7
3 changed files with 10 additions and 10 deletions

View file

@ -945,16 +945,13 @@ class foldconst(object):
else: else:
value = fn(*tuple(arg['value'] for arg in child)) value = fn(*tuple(arg['value'] for arg in child))
if not self.foldtabs: if not self.foldtabs:
generatesTabs = ( isinstance(value, unicode) if not self.nofoldtabs:
and '\t' in value generatesTabs = (
or type(value) == list isinstance(value, unicode) and '\t' in value
and any(isinstance(x, unicode) or type(value) == list and any(isinstance(x, unicode) and '\t' in x for x in value)
and '\t' in x )
for x in value if generatesTabs:
) warning("Can't optimize call to %s because it would generate a tab character (you can force the optimization with the foldtabs option, or disable this warning with the nofoldtabs option)." % node['name'])
)
if generatesTabs:
warning("Can't optimize call to %s because it would generate a tab character (you can force the optimization with the foldtabs option)." % node['name'])
return return
parent[index] = {'nt':'CONST', 't':node['t'], 'value':value} parent[index] = {'nt':'CONST', 't':node['t'], 'value':value}
except lslfuncs.ELSLCantCompute: except lslfuncs.ELSLCantCompute:

View file

@ -68,6 +68,7 @@ class optimizer(foldconst, renamer, deadcode):
self.addstrings = 'addstrings' in options self.addstrings = 'addstrings' in options
self.foldtabs = 'foldtabs' in options self.foldtabs = 'foldtabs' in options
self.nofoldtabs = 'nofoldtabs' in options
self.shrinknames = 'shrinknames' in options self.shrinknames = 'shrinknames' in options

View file

@ -277,6 +277,8 @@ Optimizer options (+ means active by default, - means inactive by default):
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.
nofoldtabs - Suppress warning when a function can't be optimized
because it generates a string or list with a tab.
skippreproc + Skip preprocessor directives in the source as if they skippreproc + Skip preprocessor directives in the source as if they
were comments. Not useful unless the script is itself were comments. Not useful unless the script is itself
the output of a preprocessor like GNU cpp, which inserts the output of a preprocessor like GNU cpp, which inserts