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.
0.8.0.3
Justin Clark-Casey (justincc) 2014-06-18 22:20:25 +01:00 committed by Justin Clark-Casey
parent 6f582aeaff
commit 68fcb132d9
2 changed files with 63 additions and 16 deletions

View File

@ -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);
}
/// <summary>

View File

@ -97,6 +97,53 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
}
}
/// <summary>
/// Test that line number errors are resolved as expected when preceding code contains a jump.
/// </summary>
[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<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
// foreach (KeyValuePair<int, int> key in positionMap.Keys)
// {
// KeyValuePair<int, int> 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<int, int>(7, 9),
positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
}
/// <summary>
/// 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<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
//
// foreach (KeyValuePair<int, int> key in positionMap.Keys)
// {
// KeyValuePair<int, int> 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<int, int> key in positionMap.Keys)
// {
// KeyValuePair<int, int> 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<int, int>(5, 21),