mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Refine the places where void expressions are allowed
To prevent passing down a value in every call, the flag is a member. Yes, ugly.
This commit is contained in:
parent
660dcff65b
commit
7bb07ecf38
1 changed files with 22 additions and 3 deletions
|
@ -876,6 +876,8 @@ class parser(object):
|
||||||
return nr(nt=CONST, t='integer', value=1 if tok0 == 'TRUE' else 0)
|
return nr(nt=CONST, t='integer', value=1 if tok0 == 'TRUE' else 0)
|
||||||
if tok0 == '<':
|
if tok0 == '<':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
saveAllowVoid = self.allowVoid
|
||||||
|
self.allowVoid = False
|
||||||
val = [self.autocastcheck(self.Parse_expression(), 'float')]
|
val = [self.autocastcheck(self.Parse_expression(), 'float')]
|
||||||
self.expect(',')
|
self.expect(',')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
@ -908,6 +910,7 @@ class parser(object):
|
||||||
|
|
||||||
# We defer it to a separate function.
|
# We defer it to a separate function.
|
||||||
val += self.Parse_vector_rotation_tail()
|
val += self.Parse_vector_rotation_tail()
|
||||||
|
self.allowVoid = saveAllowVoid
|
||||||
|
|
||||||
if len(val) == 3:
|
if len(val) == 3:
|
||||||
return nr(nt='VECTOR', t='vector', ch=val)
|
return nr(nt='VECTOR', t='vector', ch=val)
|
||||||
|
@ -923,7 +926,10 @@ class parser(object):
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
self.expect('(')
|
self.expect('(')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
saveAllowVoid = self.allowVoid
|
||||||
|
self.allowVoid = True
|
||||||
expr = self.Parse_expression()
|
expr = self.Parse_expression()
|
||||||
|
self.allowVoid = saveAllowVoid
|
||||||
if expr.t not in types:
|
if expr.t not in types:
|
||||||
raise (EParseTypeMismatch(self) if expr.t is None
|
raise (EParseTypeMismatch(self) if expr.t is None
|
||||||
else EParseUndefined(self))
|
else EParseUndefined(self))
|
||||||
|
@ -989,11 +995,14 @@ class parser(object):
|
||||||
raise EParseTypeMismatch(self)
|
raise EParseTypeMismatch(self)
|
||||||
idxexpr = idxexpr[0]
|
idxexpr = idxexpr[0]
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
saveAllowVoid = self.allowVoid
|
||||||
|
self.allowVoid = True
|
||||||
expr = self.Parse_expression()
|
expr = self.Parse_expression()
|
||||||
|
self.allowVoid = saveAllowVoid
|
||||||
rtyp = expr.t
|
rtyp = expr.t
|
||||||
# Define aux function if it doesn't exist
|
# Define aux function if it doesn't exist
|
||||||
# (leaves users room for writing their own replacement, e.g.
|
# (leaves users room for writing their own replacement, e.g.
|
||||||
# one that fills with something other than zeros)
|
# one that uses something other than integer zero as filler)
|
||||||
if 'lazy_list_set' not in self.symtab[0]:
|
if 'lazy_list_set' not in self.symtab[0]:
|
||||||
self.PushScope()
|
self.PushScope()
|
||||||
paramscope = self.scopeindex
|
paramscope = self.scopeindex
|
||||||
|
@ -1158,8 +1167,6 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
expr = self.Parse_expression()
|
expr = self.Parse_expression()
|
||||||
rtyp = expr.t
|
rtyp = expr.t
|
||||||
if rtyp not in types:
|
|
||||||
raise EParseTypeMismatch(self)
|
|
||||||
if typ in ('integer', 'float'):
|
if typ in ('integer', 'float'):
|
||||||
# LSL admits integer *= float (go figger).
|
# LSL admits integer *= float (go figger).
|
||||||
# It acts like: lhs = (integer)((float)lhs * rhs)
|
# It acts like: lhs = (integer)((float)lhs * rhs)
|
||||||
|
@ -1614,6 +1621,9 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
raise EParseTypeMismatch(self)
|
raise EParseTypeMismatch(self)
|
||||||
expression = nr(nt=op, t='integer', ch=[expression, rexpr])
|
expression = nr(nt=op, t='integer', ch=[expression, rexpr])
|
||||||
|
|
||||||
|
if not self.allowVoid and expression.t not in types:
|
||||||
|
raise EParseTypeMismatch(self)
|
||||||
|
|
||||||
return expression
|
return expression
|
||||||
|
|
||||||
def Parse_optional_expression_list(self, expected_types = None):
|
def Parse_optional_expression_list(self, expected_types = None):
|
||||||
|
@ -1635,7 +1645,10 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
idx = 0
|
idx = 0
|
||||||
if self.tok[0] not in (']', ')', ';'):
|
if self.tok[0] not in (']', ')', ';'):
|
||||||
while True:
|
while True:
|
||||||
|
saveAllowVoid = self.allowVoid
|
||||||
|
self.allowVoid = True
|
||||||
expr = self.Parse_expression()
|
expr = self.Parse_expression()
|
||||||
|
self.allowVoid = saveAllowVoid
|
||||||
if expr.nt == 'SUBIDX' and expr.t is None:
|
if expr.nt == 'SUBIDX' and expr.t is None:
|
||||||
# Don't accept an untyped lazy list in expression lists
|
# Don't accept an untyped lazy list in expression lists
|
||||||
raise EParseTypeMismatch(self)
|
raise EParseTypeMismatch(self)
|
||||||
|
@ -2196,7 +2209,10 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
return decl
|
return decl
|
||||||
|
|
||||||
# If none of the above, it must be an expression.
|
# If none of the above, it must be an expression.
|
||||||
|
saveAllowVoid = self.allowVoid
|
||||||
|
self.allowVoid = True
|
||||||
value = self.Parse_expression()
|
value = self.Parse_expression()
|
||||||
|
self.allowVoid = saveAllowVoid
|
||||||
self.expect(';')
|
self.expect(';')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
return nr(nt='EXPR', t=value.t, ch=[value])
|
return nr(nt='EXPR', t=value.t, ch=[value])
|
||||||
|
@ -2880,6 +2896,9 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
# globals are allowed; if true, only already seen globals are permitted.
|
# globals are allowed; if true, only already seen globals are permitted.
|
||||||
self.disallowglobalvars = False
|
self.disallowglobalvars = False
|
||||||
|
|
||||||
|
# Another hack to determine where to allow void expressions.
|
||||||
|
self.allowVoid = 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