mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix extendedtypecast problem with negative constants after typecasts.
This commit is contained in:
parent
4cc268b574
commit
1160fea8cf
1 changed files with 22 additions and 1 deletions
|
@ -984,7 +984,28 @@ list lazy_list_set(list L, integer i, list v)
|
||||||
if self.extendedtypecast:
|
if self.extendedtypecast:
|
||||||
# Allow any unary expression (except assignment). The type cast
|
# Allow any unary expression (except assignment). The type cast
|
||||||
# acts as a prefix operator.
|
# acts as a prefix operator.
|
||||||
expr = self.Parse_unary_expression(AllowAssignment = False)
|
|
||||||
|
# Deal with the case of minus a constant integer or float.
|
||||||
|
# E.g. ~(integer)-2*3 should be parsed as (~(integer)-2)*3
|
||||||
|
# and not as ~(integer)(-(2*3))
|
||||||
|
# Note ~(integer)-a*3 is also parsed as ~(integer)(-a)*3
|
||||||
|
# which is bordering a violation of the POLA because of the
|
||||||
|
# priority of - with respect to *. But the syntax is quite
|
||||||
|
# explicit: what is typecast is always a unary expression,
|
||||||
|
# therefore processed first.
|
||||||
|
if self.tok[0] == '-':
|
||||||
|
self.NextToken()
|
||||||
|
if self.tok[0] == 'INTEGER_VALUE':
|
||||||
|
expr = {'nt':'CONST','t':'integer','value':-self.tok[1]}
|
||||||
|
self.NextToken()
|
||||||
|
elif self.tok[0] == 'FLOAT_VALUE':
|
||||||
|
expr = {'nt':'CONST','t':'float','value':-self.tok[1]}
|
||||||
|
self.NextToken()
|
||||||
|
else:
|
||||||
|
expr = self.Parse_unary_expression(AllowAssignment = False)
|
||||||
|
expr = {'nt':'NEG','t':expr['t'],'ch':[expr]}
|
||||||
|
else:
|
||||||
|
expr = self.Parse_unary_expression(AllowAssignment = False)
|
||||||
else:
|
else:
|
||||||
if self.tok[0] == '(':
|
if self.tok[0] == '(':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue