mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix "" + list_expr producing list_expr
The type checks were not strong enough. While on it, strengthen other similar checks as well. Reported by @Tonaie. Fixes #13.
This commit is contained in:
parent
4d75f0f792
commit
0affbf13dd
5 changed files with 68 additions and 9 deletions
|
@ -905,7 +905,7 @@ class foldconst(object):
|
||||||
rnt = rval.nt
|
rnt = rval.nt
|
||||||
|
|
||||||
if optype == 'list' and not (ltype == rtype == 'list'):
|
if optype == 'list' and not (ltype == rtype == 'list'):
|
||||||
if lnt == 'CONST' and not lval.value:
|
if lnt == 'CONST' and ltype == 'list' and not lval.value:
|
||||||
# [] + nonlist -> (list)nonlist
|
# [] + nonlist -> (list)nonlist
|
||||||
parent[index] = self.Cast(rval, optype)
|
parent[index] = self.Cast(rval, optype)
|
||||||
# node is SEF if rval is
|
# node is SEF if rval is
|
||||||
|
@ -928,18 +928,26 @@ class foldconst(object):
|
||||||
if optype in ('string', 'float', 'list'):
|
if optype in ('string', 'float', 'list'):
|
||||||
# All these types evaluate to boolean False when they are
|
# All these types evaluate to boolean False when they are
|
||||||
# the neutral addition element.
|
# the neutral addition element.
|
||||||
if lnt == 'CONST' and not lval.value:
|
if lnt == 'CONST' and not lval.value and (ltype == rtype
|
||||||
# 0. + expr -> expr
|
or ltype == 'integer' and rtype == 'float'
|
||||||
# "" + expr -> expr
|
or ltype == 'float' and rtype == 'integer'):
|
||||||
# [] + expr -> expr
|
# 0 + fval -> fval
|
||||||
|
# 0. + fval -> fval
|
||||||
|
# 0. + ival -> fval
|
||||||
|
# "" + sval -> sval
|
||||||
|
# [] + lval -> lval
|
||||||
parent[index] = self.Cast(rval, optype)
|
parent[index] = self.Cast(rval, optype)
|
||||||
# node is SEF if rval is
|
# node is SEF if rval is
|
||||||
parent[index].SEF = rval.SEF
|
parent[index].SEF = rval.SEF
|
||||||
return
|
return
|
||||||
if rnt == 'CONST' and not rval.value:
|
if rnt == 'CONST' and not rval.value and (rtype == ltype
|
||||||
# expr + 0. -> expr
|
or rtype == 'integer' and ltype == 'float'
|
||||||
# expr + "" -> expr
|
or rtype == 'float' and ltype == 'integer'):
|
||||||
# expr + [] -> expr
|
# fval + 0 -> fval
|
||||||
|
# fval + 0. -> fval
|
||||||
|
# ival + 0. -> fval
|
||||||
|
# sval + "" -> sval
|
||||||
|
# lval + [] -> lval
|
||||||
parent[index] = self.Cast(lval, optype)
|
parent[index] = self.Cast(lval, optype)
|
||||||
# node is SEF if lval is
|
# node is SEF if lval is
|
||||||
parent[index].SEF = lval.SEF
|
parent[index].SEF = lval.SEF
|
||||||
|
|
10
unit_tests/regression.suite/issue-13.lsl
Normal file
10
unit_tests/regression.suite/issue-13.lsl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
default
|
||||||
|
{
|
||||||
|
state_entry()
|
||||||
|
{
|
||||||
|
llParticleSystem("" + llGetPhysicsMaterial());
|
||||||
|
llParticleSystem((list)"" + llGetPhysicsMaterial());
|
||||||
|
llParticleSystem(0 + llGetPhysicsMaterial());
|
||||||
|
llParticleSystem((list)0 + llGetPhysicsMaterial());
|
||||||
|
}
|
||||||
|
}
|
10
unit_tests/regression.suite/issue-13.out
Normal file
10
unit_tests/regression.suite/issue-13.out
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
default
|
||||||
|
{
|
||||||
|
state_entry()
|
||||||
|
{
|
||||||
|
llParticleSystem("" + llGetPhysicsMaterial());
|
||||||
|
llParticleSystem("" + llGetPhysicsMaterial());
|
||||||
|
llParticleSystem(0 + llGetPhysicsMaterial());
|
||||||
|
llParticleSystem(0 + llGetPhysicsMaterial());
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,5 +23,21 @@ default{timer(){
|
||||||
a = (list)(list)(list)(list)(list)[b] + a;
|
a = (list)(list)(list)(list)(list)[b] + a;
|
||||||
a = (list)(list)(list)(list)(list)1 + a;
|
a = (list)(list)(list)(list)(list)1 + a;
|
||||||
a = (list)(list)(list)(list)(list)b + a;
|
a = (list)(list)(list)(list)(list)b + a;
|
||||||
|
a += (llGetPhysicsMaterial() + 0);
|
||||||
|
a += (llGetPhysicsMaterial() + 0.);
|
||||||
|
a += (llGetPhysicsMaterial() + "");
|
||||||
|
a += (llGetPhysicsMaterial() + []);
|
||||||
|
a += (0 + llGetPhysicsMaterial());
|
||||||
|
a += (0. + llGetPhysicsMaterial());
|
||||||
|
a += ("" + llGetPhysicsMaterial());
|
||||||
|
a += ([] + llGetPhysicsMaterial());
|
||||||
|
a += ([] + llGetPhysicsMaterial() + []);
|
||||||
|
a += (0 + []);
|
||||||
|
a += (0. + []);
|
||||||
|
a += ("" + []);
|
||||||
|
a += ([] + 0);
|
||||||
|
a += ([] + 0.);
|
||||||
|
a += ([] + "");
|
||||||
|
a += ([] + []);
|
||||||
llParticleSystem(a);
|
llParticleSystem(a);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -24,6 +24,21 @@ default
|
||||||
a = b + a;
|
a = b + a;
|
||||||
a = 1 + a;
|
a = 1 + a;
|
||||||
a = b + a;
|
a = b + a;
|
||||||
|
a = a + (llGetPhysicsMaterial() + 0);
|
||||||
|
a = a + (llGetPhysicsMaterial() + ((float)0));
|
||||||
|
a = a + (llGetPhysicsMaterial() + "");
|
||||||
|
a = a + llGetPhysicsMaterial();
|
||||||
|
a = a + (0 + llGetPhysicsMaterial());
|
||||||
|
a = a + (((float)0) + llGetPhysicsMaterial());
|
||||||
|
a = a + ("" + llGetPhysicsMaterial());
|
||||||
|
a = a + llGetPhysicsMaterial();
|
||||||
|
a = a + llGetPhysicsMaterial();
|
||||||
|
a = a + 0;
|
||||||
|
a = a + ((float)0);
|
||||||
|
a = a + "";
|
||||||
|
a = a + 0;
|
||||||
|
a = a + ((float)0);
|
||||||
|
a = a + "";
|
||||||
llParticleSystem(a);
|
llParticleSystem(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue