From 68fcb132d9c6f838f41a026174a5a528d6337244 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 18 Jun 2014 22:20:25 +0100 Subject: [PATCH] Fix issue with LSL jumps screwing up the C# compiler error -> LSL code position map and leading to invalid error line numbers/columns This is because jump statement generation was mistakenly inserting its own line without updating the csharp positions in CSCodeGenerator. This is Aleric Inglewood's patch in http://opensimulator.org/mantis/view.php?id=7195 but applied to opensim itself rather than the defunct code generation in opensim-libs. Thanks! This patch also adds a regression test for this case from myself. --- .../Shared/CodeTools/CSCodeGenerator.cs | 6 +- .../Shared/CodeTools/Tests/CompilerTest.cs | 73 +++++++++++++++---- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 8b8e038951..4e0c273332 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -626,11 +626,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools string labelStatement; if (m_insertCoopTerminationChecks) - labelStatement = m_coopTerminationCheck + "\n"; + labelStatement = m_coopTerminationCheck; else - labelStatement = "NoOp();\n"; + labelStatement = "NoOp();"; - return Generate(String.Format("{0}: ", CheckName(jl.LabelName)), jl) + labelStatement; + return GenerateLine(String.Format("{0}: {1}", CheckName(jl.LabelName), labelStatement), jl); } /// diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index 713b280497..6b2fdadeb0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs @@ -97,6 +97,53 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests } } + /// + /// Test that line number errors are resolved as expected when preceding code contains a jump. + /// + [Test] + public void TestJumpAndSyntaxError() + { + TestHelpers.InMethod(); + + m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); + + string input = @"default +{ + state_entry() + { + jump l; + @l; + i = 1; + } +}"; + + CSCodeGenerator cg = new CSCodeGenerator(); + string output = cg.Convert(input); + + output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); +// System.Console.WriteLine(output); + + Dictionary, KeyValuePair> positionMap = cg.PositionMap; + + m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); + +// foreach (KeyValuePair key in positionMap.Keys) +// { +// KeyValuePair val = positionMap[key]; +// +// System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value); +// } +// +// foreach (CompilerError compErr in m_compilerResults.Errors) +// { +// System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr); +// } + + Assert.AreEqual( + new KeyValuePair(7, 9), + positionMap[new KeyValuePair(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); + } + /// /// Test the C# compiler error message can be mapped to the correct /// line/column in the LSL source when an undeclared variable is used. @@ -120,23 +167,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests string output = cg.Convert(input); output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null); -// System.Console.WriteLine(output); + // System.Console.WriteLine(output); Dictionary, KeyValuePair> positionMap = cg.PositionMap; m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); -// -// foreach (KeyValuePair key in positionMap.Keys) -// { -// KeyValuePair val = positionMap[key]; -// -// System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value); -// } -// -// foreach (CompilerError compErr in m_compilerResults.Errors) -// { -// System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr); -// } + // + // foreach (KeyValuePair key in positionMap.Keys) + // { + // KeyValuePair val = positionMap[key]; + // + // System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value); + // } + // + // foreach (CompilerError compErr in m_compilerResults.Errors) + // { + // System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr); + // } Assert.AreEqual( new KeyValuePair(5, 21),