aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/Compiler/Program.cs
diff options
context:
space:
mode:
authorAleric Inglewood2014-05-28 18:51:17 +0200
committerJustin Clark-Casey (justincc)2014-06-19 23:52:51 +0100
commitc90b986d8b1ee55505b01056c4a772cfc5b210b6 (patch)
tree87587ba96757763b5863ef8a57d746a3597aecf7 /OpenSim/Tools/Compiler/Program.cs
parentFix looking up line number and colum when there is no exact match. (diff)
downloadopensim-SC-c90b986d8b1ee55505b01056c4a772cfc5b210b6.zip
opensim-SC-c90b986d8b1ee55505b01056c4a772cfc5b210b6.tar.gz
opensim-SC-c90b986d8b1ee55505b01056c4a772cfc5b210b6.tar.bz2
opensim-SC-c90b986d8b1ee55505b01056c4a772cfc5b210b6.tar.xz
Improved line map heuristics.
If the C# column can't be found in the positionMap (but the line can), use the map immediately after it while correcting for the offset, unless that results in an LSL position before the previous LSL position in the positionMap. The idea behind this heuristic is that in most, if not all cases C# consumes more characters than LSL (for example LSL_Types.LSLInteger instead of just 'integer'). Thus if the distance between the columns of two markers differ in the C# and LSL file, the distance in the C# file will be larger. Moreover, we can assume that every time this happens we will have a marker at the beginning of the longer 'keyword', because those keywords were generated by us in the first place. For example: C#: LSL_Types.LSLInteger f2(LSL_Types.LSLString s) ^ ^ 1 2 will always have markers at the beginning of the long keywords 'LSL_Types.LSLInteger' and 'LSL_Types.LSLString'. If an error is generated in between (for example at the beginning of the function name 'f2') then the correct position is found by using an offset relative to 2 rather than 1. Note that a case where this isn't working correctly is when the user adds extra spaces. For example: LSL: integer f2( string s) would still use the start of 'string' as reference and then go backwards 3 characters only because the corresponding C# still looks like C#: LSL_Types.LSLInteger f2(LSL_Types.LSLString s) ^ ^ only 3 chars difference and the reported error at 'f2' would be here: LSL: integer f2( string s) ^ This can only be fixed by generating a mapping for 'f2' itself, or generating a mapping whenever the amount of spaces is changed.
Diffstat (limited to 'OpenSim/Tools/Compiler/Program.cs')
-rw-r--r--OpenSim/Tools/Compiler/Program.cs56
1 files changed, 40 insertions, 16 deletions
diff --git a/OpenSim/Tools/Compiler/Program.cs b/OpenSim/Tools/Compiler/Program.cs
index b9c960b..b010eaf 100644
--- a/OpenSim/Tools/Compiler/Program.cs
+++ b/OpenSim/Tools/Compiler/Program.cs
@@ -255,13 +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<KeyValuePair<int, int>, KeyValuePair<int, int>>>
259 { 259 {
260 public int Compare(KeyValuePair<int, int> a, 260 public int Compare(KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> a,
261 KeyValuePair<int, int> b) 261 KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> b)
262 { 262 {
263 int kc = a.Key.CompareTo(b.Key); 263 int kc = a.Key.Key.CompareTo(b.Key.Key);
264 return (kc != 0) ? kc : a.Value.CompareTo(b.Value); 264 return (kc != 0) ? kc : a.Key.Value.CompareTo(b.Key.Value);
265 } 265 }
266 } 266 }
267 267
@@ -278,24 +278,48 @@ namespace OpenSim.Tools.LSL.Compiler
278 out ret)) 278 out ret))
279 return ret; 279 return ret;
280 280
281 List<KeyValuePair<int, int>> sorted = 281 var sorted = new List<KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>>>(positionMap);
282 new List<KeyValuePair<int, int>>(positionMap.Keys);
283 282
284 sorted.Sort(new kvpSorter()); 283 sorted.Sort(new kvpSorter());
285 284
286 int l = sorted[0].Key; 285 int l = 1;
287 int c = sorted[0].Value; 286 int c = 1;
287 int pl = 1;
288 288
289 foreach (KeyValuePair<int, int> cspos in sorted) 289 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> posmap in sorted)
290 { 290 {
291 if (cspos.Key >= line && 291 //m_log.DebugFormat("[Compiler]: Scanning line map {0},{1} --> {2},{3}", posmap.Key.Key, posmap.Key.Value, posmap.Value.Key, posmap.Value.Value);
292 !(cspos.Key == line && cspos.Value <= col)) 292 int nl = posmap.Value.Key + line - posmap.Key.Key; // New, translated LSL line and column.
293 int nc = posmap.Value.Value + col - posmap.Key.Value;
294 // Keep going until we find the first point passed line,col.
295 if (posmap.Key.Key > line)
296 {
297 //m_log.DebugFormat("[Compiler]: Line is larger than requested {0},{1}, returning {2},{3}", line, col, l, c);
298 if (pl < line)
299 {
300 //m_log.DebugFormat("[Compiler]: Previous line ({0}) is less than requested line ({1}), setting column to 1.", pl, line);
301 c = 1;
302 }
293 break; 303 break;
294 l = cspos.Key; 304 }
295 c = cspos.Value; 305 if (posmap.Key.Key == line && posmap.Key.Value > col)
306 {
307 // Never move l,c backwards.
308 if (nl > l || (nl == l && nc > c))
309 {
310 //m_log.DebugFormat("[Compiler]: Using offset relative to this: {0} + {1} - {2}, {3} + {4} - {5} = {6}, {7}",
311 // posmap.Value.Key, line, posmap.Key.Key, posmap.Value.Value, col, posmap.Key.Value, nl, nc);
312 l = nl;
313 c = nc;
314 }
315 //m_log.DebugFormat("[Compiler]: Column is larger than requested {0},{1}, returning {2},{3}", line, col, l, c);
316 break;
317 }
318 pl = posmap.Key.Key;
319 l = posmap.Value.Key;
320 c = posmap.Value.Value;
296 } 321 }
297 positionMap.TryGetValue(new KeyValuePair<int, int>(l, c), out ret); 322 return new KeyValuePair<int, int>(l, c);
298 return ret;
299 } 323 }
300 } 324 }
301} 325}