aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-06-18 22:20:25 +0100
committerJustin Clark-Casey2014-08-02 00:49:02 +0100
commit68fcb132d9c6f838f41a026174a5a528d6337244 (patch)
tree4022353c3bd974835449f8f60d93fa87438f521a
parentFix previous commit to ignore water height and allow flying underwater (swimm... (diff)
downloadopensim-SC_OLD-68fcb132d9c6f838f41a026174a5a528d6337244.zip
opensim-SC_OLD-68fcb132d9c6f838f41a026174a5a528d6337244.tar.gz
opensim-SC_OLD-68fcb132d9c6f838f41a026174a5a528d6337244.tar.bz2
opensim-SC_OLD-68fcb132d9c6f838f41a026174a5a528d6337244.tar.xz
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.
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs57
2 files changed, 55 insertions, 8 deletions
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
626 string labelStatement; 626 string labelStatement;
627 627
628 if (m_insertCoopTerminationChecks) 628 if (m_insertCoopTerminationChecks)
629 labelStatement = m_coopTerminationCheck + "\n"; 629 labelStatement = m_coopTerminationCheck;
630 else 630 else
631 labelStatement = "NoOp();\n"; 631 labelStatement = "NoOp();";
632 632
633 return Generate(String.Format("{0}: ", CheckName(jl.LabelName)), jl) + labelStatement; 633 return GenerateLine(String.Format("{0}: {1}", CheckName(jl.LabelName), labelStatement), jl);
634 } 634 }
635 635
636 /// <summary> 636 /// <summary>
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
98 } 98 }
99 99
100 /// <summary> 100 /// <summary>
101 /// Test the C# compiler error message can be mapped to the correct 101 /// Test that line number errors are resolved as expected when preceding code contains a jump.
102 /// line/column in the LSL source when an undeclared variable is used.
103 /// </summary> 102 /// </summary>
104 [Test] 103 [Test]
105 public void TestUseUndeclaredVariable() 104 public void TestJumpAndSyntaxError()
106 { 105 {
107 TestHelpers.InMethod(); 106 TestHelpers.InMethod();
108 107
@@ -112,7 +111,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
112{ 111{
113 state_entry() 112 state_entry()
114 { 113 {
115 integer y = x + 3; 114 jump l;
115 @l;
116 i = 1;
116 } 117 }
117}"; 118}";
118 119
@@ -125,7 +126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
125 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap; 126 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
126 127
127 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output); 128 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
128// 129
129// foreach (KeyValuePair<int, int> key in positionMap.Keys) 130// foreach (KeyValuePair<int, int> key in positionMap.Keys)
130// { 131// {
131// KeyValuePair<int, int> val = positionMap[key]; 132// KeyValuePair<int, int> val = positionMap[key];
@@ -139,6 +140,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests
139// } 140// }
140 141
141 Assert.AreEqual( 142 Assert.AreEqual(
143 new KeyValuePair<int, int>(7, 9),
144 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
145 }
146
147 /// <summary>
148 /// Test the C# compiler error message can be mapped to the correct
149 /// line/column in the LSL source when an undeclared variable is used.
150 /// </summary>
151 [Test]
152 public void TestUseUndeclaredVariable()
153 {
154 TestHelpers.InMethod();
155
156 m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");
157
158 string input = @"default
159{
160 state_entry()
161 {
162 integer y = x + 3;
163 }
164}";
165
166 CSCodeGenerator cg = new CSCodeGenerator();
167 string output = cg.Convert(input);
168
169 output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
170 // System.Console.WriteLine(output);
171
172 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> positionMap = cg.PositionMap;
173
174 m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);
175 //
176 // foreach (KeyValuePair<int, int> key in positionMap.Keys)
177 // {
178 // KeyValuePair<int, int> val = positionMap[key];
179 //
180 // System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
181 // }
182 //
183 // foreach (CompilerError compErr in m_compilerResults.Errors)
184 // {
185 // System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
186 // }
187
188 Assert.AreEqual(
142 new KeyValuePair<int, int>(5, 21), 189 new KeyValuePair<int, int>(5, 21),
143 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]); 190 positionMap[new KeyValuePair<int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
144 } 191 }