mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix bug where types of expressions in vectors/rotations were not checked
E.g. this was a valid vector literal: <"",0,0> Parse_simple_expr didn't have that problem, though.
This commit is contained in:
parent
075d3aba0c
commit
8289c14c81
1 changed files with 11 additions and 6 deletions
|
@ -305,8 +305,8 @@ class parser(object):
|
||||||
raise EParseInvalidField(self)
|
raise EParseInvalidField(self)
|
||||||
|
|
||||||
def autocastcheck(self, value, tgttype):
|
def autocastcheck(self, value, tgttype):
|
||||||
"""Check if automatic dynamic cast is possible, and insert it if
|
"""Check if automatic dynamic cast is possible. If explicit casts are
|
||||||
requested explicitly.
|
requested, insert one.
|
||||||
"""
|
"""
|
||||||
tval = value.t
|
tval = value.t
|
||||||
if tval == tgttype:
|
if tval == tgttype:
|
||||||
|
@ -733,8 +733,9 @@ class parser(object):
|
||||||
pos = self.pos
|
pos = self.pos
|
||||||
errorpos = self.errorpos
|
errorpos = self.errorpos
|
||||||
tok = self.tok
|
tok = self.tok
|
||||||
|
component3 = False
|
||||||
try:
|
try:
|
||||||
ret.append(self.Parse_expression())
|
component3 = self.Parse_expression()
|
||||||
|
|
||||||
# Checking here for '>' might parse a different grammar, because
|
# Checking here for '>' might parse a different grammar, because
|
||||||
# it might allow e.g. <1,2,3==3>; as a vector, which is not valid.
|
# it might allow e.g. <1,2,3==3>; as a vector, which is not valid.
|
||||||
|
@ -751,6 +752,10 @@ class parser(object):
|
||||||
self.errorpos = errorpos
|
self.errorpos = errorpos
|
||||||
self.tok = tok
|
self.tok = tok
|
||||||
|
|
||||||
|
# We do this here to prevent a type mismatch above
|
||||||
|
if component3 is not False:
|
||||||
|
ret.append(self.autocastcheck(component3, 'float'))
|
||||||
|
|
||||||
# OK, here we are.
|
# OK, here we are.
|
||||||
inequality = self.Parse_shift() # shift is the descendant of inequality
|
inequality = self.Parse_shift() # shift is the descendant of inequality
|
||||||
while self.tok[0] in ('<', '<=', '>=', '>'):
|
while self.tok[0] in ('<', '<=', '>=', '>'):
|
||||||
|
@ -770,7 +775,7 @@ class parser(object):
|
||||||
'KEY_VALUE', 'VECTOR_VALUE', 'ROTATION_VALUE', 'LIST_VALUE',
|
'KEY_VALUE', 'VECTOR_VALUE', 'ROTATION_VALUE', 'LIST_VALUE',
|
||||||
'TRUE', 'FALSE', '++', '--', 'PRINT', '!', '~', '(', '['
|
'TRUE', 'FALSE', '++', '--', 'PRINT', '!', '~', '(', '['
|
||||||
):
|
):
|
||||||
ret.append(inequality)
|
ret.append(self.autocastcheck(inequality, 'float'))
|
||||||
return ret
|
return ret
|
||||||
# This is basically a copy/paste of the Parse_inequality handler
|
# This is basically a copy/paste of the Parse_inequality handler
|
||||||
ltype = inequality.t
|
ltype = inequality.t
|
||||||
|
@ -856,10 +861,10 @@ 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()
|
||||||
val = [self.Parse_expression()]
|
val = [self.autocastcheck(self.Parse_expression(), 'float')]
|
||||||
self.expect(',')
|
self.expect(',')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
val.append(self.Parse_expression())
|
val.append(self.autocastcheck(self.Parse_expression(), 'float'))
|
||||||
self.expect(',')
|
self.expect(',')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue