LSL-PyOptimizer/unit_tests/coverage.suite/lslparse-2.out
Sei Lisa ec509b3840 Fix parenthesization of unary minus
The algorithm for adding parentheses around unary operators was not working properly. It converted a * (-b) * c into a * -b * c, which LSL handles as a * -(b * c).

Fix and add test cases for that. One of the test cases shows an example where the difference matters: 0 * (-1e20) * 1e20 should result in 0.0, but if wrongly parenthesized, it gives NaN, because 1e20*1e20 gives infinity due to float overflow, and minus infinity times 0 is indeterminate.

The addition of parentheses has been improved, but it still does not eliminate every redundant parenthesis.

Also fix the horrendous typo of using "operands" where it should be "operators".
2019-05-04 23:20:20 +02:00

93 lines
1.8 KiB
Text

string S = "ab";
integer f()
{
return 1;
}
default
{
timer()
{
"ab";
integer i;
float f;
list L;
f += (float)i;
L += (list)((integer)((float)i));
i = ~(integer)-2 * 3;
i = ~(integer)-2. * 3;
i = ~(integer)(-i) * 3;
"" + (string)((key)"");
(string)((key)"") + "";
@J;
{
jump J_autoGen00001;
{
1;
}
@J_autoGen00001;
}
{
while (1)
{
jump J_autoGen00002;
{
for (; 2; )
{
jump J_autoGen00005;
jump J_autoGen00004;
@J_autoGen00005;
}
@J_autoGen00004;
}
jump J_autoGen00003;
@J_autoGen00003;
}
@J_autoGen00002;
}
{
do
{
jump J_autoGen00007;
jump J_autoGen00006;
@J_autoGen00007;
}
while (1);
@J_autoGen00006;
}
jump x;
while (1)
@x;
jump y;
for (; 1; )
@y;
jump z;
do
@z;
while (0);
{
if (1. == (float)1)
jump J_autoGen00015;
jump J_autoGen00014;
@J_autoGen00015;
{
1;
}
@J_autoGen00014;
}
{
{
}
}
while (1)
;
while (1)
{
while (1)
while (1)
jump J_autoGen00022;
@J_autoGen00022;
}
}
}