From 68fcb132d9c6f838f41a026174a5a528d6337244 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 18 Jun 2014 22:20:25 +0100 Subject: 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 | 57 ++++++++++++++++++++-- 2 files changed, 55 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index 8b8e038..4e0c273 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 713b280..6b2fdad 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs @@ -98,11 +98,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests } /// - /// Test the C# compiler error message can be mapped to the correct - /// line/column in the LSL source when an undeclared variable is used. + /// Test that line number errors are resolved as expected when preceding code contains a jump. /// [Test] - public void TestUseUndeclaredVariable() + public void TestJumpAndSyntaxError() { TestHelpers.InMethod(); @@ -112,7 +111,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests { state_entry() { - integer y = x + 3; + jump l; + @l; + i = 1; } }"; @@ -125,7 +126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests Dictionary, KeyValuePair> positionMap = cg.PositionMap; m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); -// + // foreach (KeyValuePair key in positionMap.Keys) // { // KeyValuePair val = positionMap[key]; @@ -139,6 +140,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests // } 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. + /// + [Test] + public void TestUseUndeclaredVariable() + { + TestHelpers.InMethod(); + + m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll"); + + string input = @"default +{ + state_entry() + { + integer y = x + 3; + } +}"; + + 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(5, 21), positionMap[new KeyValuePair(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); } -- cgit v1.1