aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/Compiler
diff options
context:
space:
mode:
authorAleric Inglewood2014-05-24 02:36:12 +0200
committerJustin Clark-Casey (justincc)2014-06-19 23:52:51 +0100
commit3fe9c7c49d9c39ad879c1175c01c8cacced56046 (patch)
treeedd97dc031f64abedaf9a2edb2c06b5cc8a51a92 /OpenSim/Tools/Compiler
parentBulletSim: stop processing linkset child when it is discovered that the (diff)
downloadopensim-SC-3fe9c7c49d9c39ad879c1175c01c8cacced56046.zip
opensim-SC-3fe9c7c49d9c39ad879c1175c01c8cacced56046.tar.gz
opensim-SC-3fe9c7c49d9c39ad879c1175c01c8cacced56046.tar.bz2
opensim-SC-3fe9c7c49d9c39ad879c1175c01c8cacced56046.tar.xz
Fix looking up line number and colum when there is no exact match.
When a compile error reports a colum/error that is not an exact match in the positionMap dictionary, the last position in the map with a line number and position before the reported error should be returned. The old code had the following problems: 1) It returns l,c - which are line and column of the C# file, not LSL. 2) It doesn't set l to 'line' when the map has an entry with 'line'. 3) It sorts the map without taking columns into account, which may result in a random order of the columns. With my mono implementation the columns were reversed in order. For example, if the map contains the following lines: 99,5,49,10 100,30,50,10 100,40,1,0 101,5,51,10 and a translation of 100,35 was requested, then the old code would compare '100' with the keys in the first column - setting l to that key while it is smaller. Hence, l is set to 99. Then it finds the key 100 and doesn't update l. Because of the reversed sort order, it first compares the column 35 with 40, finding that it is smaller and therefore it stops; returning 99,1 instead of finding the correct 100,30 entry and returning 50,10. This patch causes 50,10 to be returned. The remaining problems after this patch are: 1) The sorting might not be necessary at all. 2) The is code duplication (I fixed both instances, but really there should be no code duplication imho).
Diffstat (limited to 'OpenSim/Tools/Compiler')
-rw-r--r--OpenSim/Tools/Compiler/Program.cs39
1 files changed, 16 insertions, 23 deletions
diff --git a/OpenSim/Tools/Compiler/Program.cs b/OpenSim/Tools/Compiler/Program.cs
index 6c59c31..b9c960b 100644
--- a/OpenSim/Tools/Compiler/Program.cs
+++ b/OpenSim/Tools/Compiler/Program.cs
@@ -255,12 +255,13 @@ namespace OpenSim.Tools.LSL.Compiler
255 return FindErrorPosition(line, col, null); 255 return FindErrorPosition(line, col, null);
256 } 256 }
257 257
258 private class kvpSorter : IComparer<KeyValuePair<int,int>> 258 private class kvpSorter : IComparer<KeyValuePair<int, int>>
259 { 259 {
260 public int Compare(KeyValuePair<int,int> a, 260 public int Compare(KeyValuePair<int, int> a,
261 KeyValuePair<int,int> b) 261 KeyValuePair<int, int> b)
262 { 262 {
263 return a.Key.CompareTo(b.Key); 263 int kc = a.Key.CompareTo(b.Key);
264 return (kc != 0) ? kc : a.Value.CompareTo(b.Value);
264 } 265 }
265 } 266 }
266 267
@@ -277,32 +278,24 @@ namespace OpenSim.Tools.LSL.Compiler
277 out ret)) 278 out ret))
278 return ret; 279 return ret;
279 280
280 List<KeyValuePair<int,int>> sorted = 281 List<KeyValuePair<int, int>> sorted =
281 new List<KeyValuePair<int,int>>(positionMap.Keys); 282 new List<KeyValuePair<int, int>>(positionMap.Keys);
282 283
283 sorted.Sort(new kvpSorter()); 284 sorted.Sort(new kvpSorter());
284 285
285 int l = 1; 286 int l = sorted[0].Key;
286 int c = 1; 287 int c = sorted[0].Value;
287 288
288 foreach (KeyValuePair<int, int> cspos in sorted) 289 foreach (KeyValuePair<int, int> cspos in sorted)
289 { 290 {
290 if (cspos.Key >= line) 291 if (cspos.Key >= line &&
291 { 292 !(cspos.Key == line && cspos.Value <= col))
292 if (cspos.Key > line) 293 break;
293 return new KeyValuePair<int, int>(l, c); 294 l = cspos.Key;
294 if (cspos.Value > col) 295 c = cspos.Value;
295 return new KeyValuePair<int, int>(l, c);
296 c = cspos.Value;
297 if (c == 0)
298 c++;
299 }
300 else
301 {
302 l = cspos.Key;
303 }
304 } 296 }
305 return new KeyValuePair<int, int>(l, c); 297 positionMap.TryGetValue(new KeyValuePair<int, int>(l, c), out ret);
298 return ret;
306 } 299 }
307 } 300 }
308} 301}