mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix an infinite recursion by disallowing forward globals in global var defs.
This commit is contained in:
parent
716374eb83
commit
f3339b0906
2 changed files with 11 additions and 3 deletions
|
@ -165,9 +165,8 @@ class optimizer(object):
|
||||||
if self.globalmode:
|
if self.globalmode:
|
||||||
val = self.symtab[code[3]][code[2]][2]
|
val = self.symtab[code[3]][code[2]][2]
|
||||||
if val is not None:
|
if val is not None:
|
||||||
# WARNING: Possible reference loop here
|
# Infinite recursion is prevented at the parser level, by
|
||||||
# TODO: Break reference loop by only accepting globals in order
|
# not allowing forward globals in global var definitions.
|
||||||
# of definition during parsing.
|
|
||||||
self.FoldTree(val)
|
self.FoldTree(val)
|
||||||
if code[1] != 'key' and val is not None:
|
if code[1] != 'key' and val is not None:
|
||||||
code[:] = [CONSTANT, code[1], val]
|
code[:] = [CONSTANT, code[1], val]
|
||||||
|
|
|
@ -186,6 +186,8 @@ class parser(object):
|
||||||
# return (symtab[symbol][1], symtab[symbol][3])
|
# return (symtab[symbol][1], symtab[symbol][3])
|
||||||
return symtab[symbol][1]
|
return symtab[symbol][1]
|
||||||
scope = symtab[-1]
|
scope = symtab[-1]
|
||||||
|
if self.globalmode and symbol not in self.symtab[0]:
|
||||||
|
return None # Disallow forwards in global var mode
|
||||||
if symbol not in self.globals:
|
if symbol not in self.globals:
|
||||||
return None
|
return None
|
||||||
return self.globals[symbol]
|
return self.globals[symbol]
|
||||||
|
@ -1464,7 +1466,9 @@ class parser(object):
|
||||||
if self.tok[0] == '=':
|
if self.tok[0] == '=':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
if self.extendedglobalexpr:
|
if self.extendedglobalexpr:
|
||||||
|
self.globalmode = True # Var def. Disallow forward globals.
|
||||||
value = tuple(self.Parse_expression()) # Use advanced expression evaluation.
|
value = tuple(self.Parse_expression()) # Use advanced expression evaluation.
|
||||||
|
self.globalmode = False # Allow forward globals again.
|
||||||
else:
|
else:
|
||||||
value = self.Parse_simple_expr() # Use LSL's dull global expression.
|
value = self.Parse_simple_expr() # Use LSL's dull global expression.
|
||||||
self.expect(';')
|
self.expect(';')
|
||||||
|
@ -1713,6 +1717,11 @@ class parser(object):
|
||||||
|
|
||||||
self.dictorder = 0
|
self.dictorder = 0
|
||||||
|
|
||||||
|
# This is a small hack to prevent circular definitions in globals when
|
||||||
|
# extended expressions are enabled. When false (default), forward
|
||||||
|
# globals are allowed; if true, only already seen globals are permitted.
|
||||||
|
self.globalmode = False
|
||||||
|
|
||||||
# Globals and labels can be referenced before they are defined. That
|
# Globals and labels can be referenced before they are defined. That
|
||||||
# includes states.
|
# includes states.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue