From a42499c947e350639da81f0e8930eae5d331c441 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Fri, 20 Feb 2009 07:40:36 +0000 Subject: Thanks DoranZemlja for a patch implementing non-shortcircuiting in logical and and logical or in LSL. Fixes Mantis #3174. --- .../Shared/CodeTools/CSCodeGenerator.cs | 23 ++++++++++++++++++---- .../Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | 20 +++++++++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index f9ab97b..71e88e3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -646,10 +646,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { string retstr = String.Empty; - retstr += GenerateNode((SYMBOL) be.kids.Pop()); - retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol), be); - foreach (SYMBOL kid in be.kids) - retstr += GenerateNode(kid); + if (be.ExpressionSymbol.Equals("&&") || be.ExpressionSymbol.Equals("||")) + { + // special case handling for logical and/or, see Mantis 3174 + retstr += "((bool)("; + retstr += GenerateNode((SYMBOL)be.kids.Pop()); + retstr += "))"; + retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be); + retstr += "((bool)("; + foreach (SYMBOL kid in be.kids) + retstr += GenerateNode(kid); + retstr += "))"; + } + else + { + retstr += GenerateNode((SYMBOL)be.kids.Pop()); + retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol), be); + foreach (SYMBOL kid in be.kids) + retstr += GenerateNode(kid); + } return retstr; } diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index a6d36c6..02108c7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs @@ -223,6 +223,8 @@ state another_state integer y; integer x = 14 + 6; y = 12 - 3; + y = 12 && 3; + y = 12 || 3; y = 12 * 3; y = 12 / 3; y = 12 | 3; @@ -238,6 +240,8 @@ state another_state "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" + "\n y = new LSL_Types.LSLInteger(12) - new LSL_Types.LSLInteger(3);" + + "\n y = ((bool)(new LSL_Types.LSLInteger(12))) & ((bool)(new LSL_Types.LSLInteger(3)));" + + "\n y = ((bool)(new LSL_Types.LSLInteger(12))) | ((bool)(new LSL_Types.LSLInteger(3)));" + "\n y = new LSL_Types.LSLInteger(12) * new LSL_Types.LSLInteger(3);" + "\n y = new LSL_Types.LSLInteger(12) / new LSL_Types.LSLInteger(3);" + "\n y = new LSL_Types.LSLInteger(12) | new LSL_Types.LSLInteger(3);" + @@ -811,15 +815,15 @@ default "\n {" + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" + "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + - "\n if (x && y)" + + "\n if (((bool)(x)) & ((bool)(y)))" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" + - "\n if (x || y)" + + "\n if (((bool)(x)) | ((bool)(y)))" + "\n {" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" + "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" + "\n return ;" + "\n }" + - "\n if (x && y || z)" + + "\n if (((bool)(((bool)(x)) & ((bool)(y)))) | ((bool)(z)))" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" + "\n else" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is false\"));" + @@ -849,7 +853,7 @@ default "\n if (!z)" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" + "\n else" + - "\n if (!(a && b))" + + "\n if (!(((bool)(a)) & ((bool)(b))))" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" + "\n else" + "\n if (b)" + @@ -894,7 +898,7 @@ default "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + "\n while (x)" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"To infinity, and beyond!\"));" + - "\n while (new LSL_Types.LSLInteger(0) || (x && new LSL_Types.LSLInteger(0)))" + + "\n while (((bool)(new LSL_Types.LSLInteger(0))) | ((bool)((((bool)(x)) & ((bool)(new LSL_Types.LSLInteger(0)))))))" + "\n {" + "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Never say never.\"));" + "\n return ;" + @@ -983,7 +987,7 @@ default "\n llOwnerSay(new LSL_Types.LSLString(\"Launch in T minus \") + x);" + "\n IncreaseRocketPower();" + "\n }" + - "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); y > new LSL_Types.LSLInteger(0) && x != y; x++, y--)" + + "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); ((bool)(y > new LSL_Types.LSLInteger(0))) & ((bool)(x != y)); x++, y--)" + "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" + "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); !y; x++, y--)" + "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" + @@ -1072,7 +1076,7 @@ default "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(1);" + "\n LSL_Types.LSLInteger z = x ^ y;" + "\n x = ~z;" + - "\n x = ~(y && z);" + + "\n x = ~(((bool)(y)) & ((bool)(z)));" + "\n y = x >> z;" + "\n z = y << x;" + "\n }\n"; @@ -1118,7 +1122,7 @@ default "\n s = (LSL_Types.LSLInteger) (new LSL_Types.LSLString(\"1\"));" + "\n s = (LSL_Types.LSLString) (llSomethingThatReturnsInteger());" + "\n s = (LSL_Types.LSLString) (new LSL_Types.LSLInteger(134));" + - "\n s = (LSL_Types.LSLString) (x ^ y | (z && l)) + (LSL_Types.LSLString) (x + y - new LSL_Types.LSLInteger(13));" + + "\n s = (LSL_Types.LSLString) (x ^ y | (((bool)(z)) & ((bool)(l)))) + (LSL_Types.LSLString) (x + y - new LSL_Types.LSLInteger(13));" + "\n llOwnerSay(new LSL_Types.LSLString(\"s is: \") + s);" + "\n }\n"; -- cgit v1.1