From cda6b2466868cc74367da1b17d676f7168b84f6d Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Sun, 7 Jun 2009 10:22:55 +0000 Subject: Skip lone ident statments or for-loop assignments SL's LSL supports lone idents: integer x; x; as well as lone idents in for-loop assignments: for (x; x < 10; x++) { ... } while those are errors in C# (MONO at least). This patch skips lone idents in such places. Fixes Mantis #3042. --- .../Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index a7d4fa9..5dfbdbc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs @@ -133,6 +133,32 @@ state another_state } [Test] + public void TestLoneIdent() + { + // A lone ident should be removed completely as it's an error in C# + // (MONO at least). + string input = @"default +{ + touch_start(integer num_detected) + { + integer x; + x; + } +} +"; + string expected = + "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + + "\n {" + + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" + + "\n ;" + + "\n }\n"; + + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); + Assert.AreEqual(expected, output); + } + + [Test] public void TestAssignments() { string input = @"default @@ -1541,6 +1567,31 @@ default } [Test] + public void TestForLoopWithOnlyIdentInAssignment() + { + string input = @"default +{ + state_entry() + { + integer x = 4; + for (x; 1<0; x += 2); + } +}"; + + string expected = + "\n public void default_event_state_entry()" + + "\n {" + + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(4);" + + "\n for (; new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" + + "\n ;" + + "\n }\n"; + + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); + Assert.AreEqual(expected, output); + } + + [Test] public void TestAssignmentInIfWhileDoWhile() { string input = @"default -- cgit v1.1