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).0.8.0.3
parent
03c6d2b0b4
commit
28babf307e
|
@ -729,7 +729,8 @@ namespace SecondLife
|
||||||
public int Compare(KeyValuePair<int, int> a,
|
public int Compare(KeyValuePair<int, int> a,
|
||||||
KeyValuePair<int, int> b)
|
KeyValuePair<int, int> b)
|
||||||
{
|
{
|
||||||
return a.Key.CompareTo(b.Key);
|
int kc = a.Key.CompareTo(b.Key);
|
||||||
|
return (kc != 0) ? kc : a.Value.CompareTo(b.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,27 +752,19 @@ namespace SecondLife
|
||||||
|
|
||||||
sorted.Sort(new kvpSorter());
|
sorted.Sort(new kvpSorter());
|
||||||
|
|
||||||
int l = 1;
|
int l = sorted[0].Key;
|
||||||
int c = 1;
|
int c = sorted[0].Value;
|
||||||
|
|
||||||
foreach (KeyValuePair<int, int> cspos in sorted)
|
foreach (KeyValuePair<int, int> cspos in sorted)
|
||||||
{
|
{
|
||||||
if (cspos.Key >= line)
|
if (cspos.Key >= line &&
|
||||||
{
|
!(cspos.Key == line && cspos.Value <= col))
|
||||||
if (cspos.Key > line)
|
break;
|
||||||
return new KeyValuePair<int, int>(l, c);
|
|
||||||
if (cspos.Value > col)
|
|
||||||
return new KeyValuePair<int, int>(l, c);
|
|
||||||
c = cspos.Value;
|
|
||||||
if (c == 0)
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
l = cspos.Key;
|
l = cspos.Key;
|
||||||
|
c = cspos.Value;
|
||||||
}
|
}
|
||||||
}
|
positionMap.TryGetValue(new KeyValuePair<int, int>(l, c), out ret);
|
||||||
return new KeyValuePair<int, int>(l, c);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ReplaceTypes(string message)
|
string ReplaceTypes(string message)
|
||||||
|
|
|
@ -260,7 +260,8 @@ namespace OpenSim.Tools.LSL.Compiler
|
||||||
public int Compare(KeyValuePair<int, int> a,
|
public int Compare(KeyValuePair<int, int> a,
|
||||||
KeyValuePair<int, int> b)
|
KeyValuePair<int, int> b)
|
||||||
{
|
{
|
||||||
return a.Key.CompareTo(b.Key);
|
int kc = a.Key.CompareTo(b.Key);
|
||||||
|
return (kc != 0) ? kc : a.Value.CompareTo(b.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,27 +283,19 @@ namespace OpenSim.Tools.LSL.Compiler
|
||||||
|
|
||||||
sorted.Sort(new kvpSorter());
|
sorted.Sort(new kvpSorter());
|
||||||
|
|
||||||
int l = 1;
|
int l = sorted[0].Key;
|
||||||
int c = 1;
|
int c = sorted[0].Value;
|
||||||
|
|
||||||
foreach (KeyValuePair<int, int> cspos in sorted)
|
foreach (KeyValuePair<int, int> cspos in sorted)
|
||||||
{
|
{
|
||||||
if (cspos.Key >= line)
|
if (cspos.Key >= line &&
|
||||||
{
|
!(cspos.Key == line && cspos.Value <= col))
|
||||||
if (cspos.Key > line)
|
break;
|
||||||
return new KeyValuePair<int, int>(l, c);
|
|
||||||
if (cspos.Value > col)
|
|
||||||
return new KeyValuePair<int, int>(l, c);
|
|
||||||
c = cspos.Value;
|
|
||||||
if (c == 0)
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
l = cspos.Key;
|
l = cspos.Key;
|
||||||
|
c = cspos.Value;
|
||||||
}
|
}
|
||||||
}
|
positionMap.TryGetValue(new KeyValuePair<int, int>(l, c), out ret);
|
||||||
return new KeyValuePair<int, int>(l, c);
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue