diff options
author | Aleric Inglewood | 2014-05-28 18:51:17 +0200 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-06-19 23:52:51 +0100 |
commit | c90b986d8b1ee55505b01056c4a772cfc5b210b6 (patch) | |
tree | 87587ba96757763b5863ef8a57d746a3597aecf7 /OpenSim/Region/ScriptEngine | |
parent | Fix looking up line number and colum when there is no exact match. (diff) | |
download | opensim-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/Region/ScriptEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index 0b41bc6..5988539 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | |||
@@ -724,13 +724,13 @@ namespace SecondLife | |||
724 | return assembly; | 724 | return assembly; |
725 | } | 725 | } |
726 | 726 | ||
727 | private class kvpSorter : IComparer<KeyValuePair<int, int>> | 727 | private class kvpSorter : IComparer<KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>>> |
728 | { | 728 | { |
729 | public int Compare(KeyValuePair<int, int> a, | 729 | public int Compare(KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> a, |
730 | KeyValuePair<int, int> b) | 730 | KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> b) |
731 | { | 731 | { |
732 | int kc = a.Key.CompareTo(b.Key); | 732 | int kc = a.Key.Key.CompareTo(b.Key.Key); |
733 | return (kc != 0) ? kc : a.Value.CompareTo(b.Value); | 733 | return (kc != 0) ? kc : a.Key.Value.CompareTo(b.Key.Value); |
734 | } | 734 | } |
735 | } | 735 | } |
736 | 736 | ||
@@ -747,24 +747,48 @@ namespace SecondLife | |||
747 | out ret)) | 747 | out ret)) |
748 | return ret; | 748 | return ret; |
749 | 749 | ||
750 | List<KeyValuePair<int, int>> sorted = | 750 | var sorted = new List<KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>>>(positionMap); |
751 | new List<KeyValuePair<int, int>>(positionMap.Keys); | ||
752 | 751 | ||
753 | sorted.Sort(new kvpSorter()); | 752 | sorted.Sort(new kvpSorter()); |
754 | 753 | ||
755 | int l = sorted[0].Key; | 754 | int l = 1; |
756 | int c = sorted[0].Value; | 755 | int c = 1; |
756 | int pl = 1; | ||
757 | 757 | ||
758 | foreach (KeyValuePair<int, int> cspos in sorted) | 758 | foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> posmap in sorted) |
759 | { | 759 | { |
760 | if (cspos.Key >= line && | 760 | //m_log.DebugFormat("[Compiler]: Scanning line map {0},{1} --> {2},{3}", posmap.Key.Key, posmap.Key.Value, posmap.Value.Key, posmap.Value.Value); |
761 | !(cspos.Key == line && cspos.Value <= col)) | 761 | int nl = posmap.Value.Key + line - posmap.Key.Key; // New, translated LSL line and column. |
762 | int nc = posmap.Value.Value + col - posmap.Key.Value; | ||
763 | // Keep going until we find the first point passed line,col. | ||
764 | if (posmap.Key.Key > line) | ||
765 | { | ||
766 | //m_log.DebugFormat("[Compiler]: Line is larger than requested {0},{1}, returning {2},{3}", line, col, l, c); | ||
767 | if (pl < line) | ||
768 | { | ||
769 | //m_log.DebugFormat("[Compiler]: Previous line ({0}) is less than requested line ({1}), setting column to 1.", pl, line); | ||
770 | c = 1; | ||
771 | } | ||
762 | break; | 772 | break; |
763 | l = cspos.Key; | 773 | } |
764 | c = cspos.Value; | 774 | if (posmap.Key.Key == line && posmap.Key.Value > col) |
775 | { | ||
776 | // Never move l,c backwards. | ||
777 | if (nl > l || (nl == l && nc > c)) | ||
778 | { | ||
779 | //m_log.DebugFormat("[Compiler]: Using offset relative to this: {0} + {1} - {2}, {3} + {4} - {5} = {6}, {7}", | ||
780 | // posmap.Value.Key, line, posmap.Key.Key, posmap.Value.Value, col, posmap.Key.Value, nl, nc); | ||
781 | l = nl; | ||
782 | c = nc; | ||
783 | } | ||
784 | //m_log.DebugFormat("[Compiler]: Column is larger than requested {0},{1}, returning {2},{3}", line, col, l, c); | ||
785 | break; | ||
786 | } | ||
787 | pl = posmap.Key.Key; | ||
788 | l = posmap.Value.Key; | ||
789 | c = posmap.Value.Value; | ||
765 | } | 790 | } |
766 | positionMap.TryGetValue(new KeyValuePair<int, int>(l, c), out ret); | 791 | return new KeyValuePair<int, int>(l, c); |
767 | return ret; | ||
768 | } | 792 | } |
769 | 793 | ||
770 | string ReplaceTypes(string message) | 794 | string ReplaceTypes(string message) |