[svn] r6599: nemerle/trunk: lib/narray.n
ncc/completion/CodeCompletionEngine.n ncc/parsing/AST.n ncc/passe...
VladD2
svnadmin at nemerle.org
Sat Sep 2 20:25:52 CEST 2006
Log:
1. Move extension methods to class 'NCollectionsUtils'.
2. Add Relacation support to Location.
Author: VladD2
Date: Sat Sep 2 20:25:44 2006
New Revision: 6599
Modified:
nemerle/trunk/lib/narray.n
nemerle/trunk/ncc/completion/CodeCompletionEngine.n
nemerle/trunk/ncc/parsing/AST.n
nemerle/trunk/ncc/passes.n
Modified: nemerle/trunk/lib/narray.n
==============================================================================
--- nemerle/trunk/lib/narray.n (original)
+++ nemerle/trunk/lib/narray.n Sat Sep 2 20:25:44 2006
@@ -31,6 +31,122 @@
namespace Nemerle.Utility
{
+ public module NCollectionsUtils
+ {
+ public BinarySearch [TElem] (
+ this collection : SCG.IList [TElem],
+ lo : int,
+ hi : int,
+ comparer : TElem -> int
+ ) : int
+ {
+ if (lo <= hi)
+ {
+ def i = (lo + hi) >> 1;
+ def cmpResult = comparer(collection[i]);
+
+ if (cmpResult == 0)
+ i
+ else if (cmpResult < 0)
+ BinarySearch (collection, i + 1, hi, comparer)
+ else
+ BinarySearch (collection, lo, i - 1, comparer)
+ }
+ else
+ ~lo
+ }
+
+ public BinarySearch [TElem] (
+ this collection : SCG.IList [TElem],
+ comparer : TElem -> int
+ ) : int
+ {
+ BinarySearch (collection, 0, collection.Count - 1, comparer);
+ }
+
+ /** Convert collection to array. */
+ public ToArray[T] (this sourse : SCG.ICollection[T]) : array [T]
+ {
+ if (sourse is null)
+ array (0)
+ else
+ {
+ def tmp = array (sourse.Count);
+ sourse.CopyTo (tmp, 0);
+ tmp
+ }
+ }
+
+ /** Convert sequence to array. */
+ public ToArray[T] (this sourse : SCG.IEnumerable [T]) : array [T]
+ {
+ match (sourse)
+ {
+ | coll is SCG.ICollection[T] => coll.ToArray();
+ | null => array (0);
+ | _ =>
+ def dest = SCG.List();
+
+ foreach (elem in sourse)
+ dest.Add(elem);
+
+ dest.ToArray()
+ }
+ }
+
+ /**
+ * Convert collection of one type to array of another type.
+ */
+ public ToArray[From, To] (this sourse : SCG.ICollection[From],
+ f : From -> To) : array [To]
+ {
+ if (sourse is null)
+ array (0)
+ else
+ {
+ def tmp = array (sourse.Count);
+ sourse.CopyTo (tmp, 0);
+ tmp.ConvertTo (f)
+ }
+ }
+
+ /**
+ * Convert sequence of one type to array of another type.
+ */
+ public ToArray[From, To] (this sourse : SCG.IEnumerable [From],
+ f : From -> To) : array [To]
+ {
+ match (sourse)
+ {
+ | coll is SCG.ICollection[From] => coll.ToArray (f);
+ | null => array (0);
+ | _ =>
+ def dest = SCG.List();
+
+ foreach (elem in sourse)
+ dest.Add(f (elem));
+
+ dest.ToArray()
+ }
+ }
+
+ /** Convert sequence to array with filtration. */
+ public ToArrayFiltered[T] (this sourse : SCG.IEnumerable [T], isMatch : T -> bool) : array [T]
+ {
+ match (sourse)
+ {
+ | null => array (0);
+ | _ =>
+ def dest = SCG.List();
+
+ foreach (elem when isMatch(elem) in sourse)
+ dest.Add(elem);
+
+ dest.ToArray()
+ }
+ }
+ }
+
/**
* Helper functions, absent from System.Array.
*/
@@ -373,88 +489,6 @@
dest;
}
- /** Convert collection to array. */
- public ToArray[T] (this sourse : SCG.ICollection[T]) : array [T]
- {
- if (sourse is null)
- array (0)
- else
- {
- def tmp = array (sourse.Count);
- sourse.CopyTo (tmp, 0);
- tmp
- }
- }
-
- /** Convert sequence to array. */
- public ToArray[T] (this sourse : SCG.IEnumerable [T]) : array [T]
- {
- match (sourse)
- {
- | coll is SCG.ICollection[T] => coll.ToArray();
- | null => array (0);
- | _ =>
- def dest = SCG.List();
-
- foreach (elem in sourse)
- dest.Add(elem);
-
- dest.ToArray()
- }
- }
-
- /**
- * Convert collection of one type to array of another type.
- */
- public ToArray[From, To] (this sourse : SCG.ICollection[From],
- f : From -> To) : array [To]
- {
- if (sourse is null)
- array (0)
- else
- {
- def tmp = array (sourse.Count);
- sourse.CopyTo (tmp, 0);
- tmp.ConvertTo (f)
- }
- }
-
- /**
- * Convert sequence of one type to array of another type.
- */
- public ToArray[From, To] (this sourse : SCG.IEnumerable [From],
- f : From -> To) : array [To]
- {
- match (sourse)
- {
- | coll is SCG.ICollection[From] => coll.ToArray (f);
- | null => array (0);
- | _ =>
- def dest = SCG.List();
-
- foreach (elem in sourse)
- dest.Add(f (elem));
-
- dest.ToArray()
- }
- }
-
- /** Convert sequence to array with filtration. */
- public ToArrayFiltered[T] (this sourse : SCG.IEnumerable [T], isMatch : T -> bool) : array [T]
- {
- match (sourse)
- {
- | null => array (0);
- | _ =>
- def dest = SCG.List();
-
- foreach (elem when isMatch(elem) in sourse)
- dest.Add(elem);
-
- dest.ToArray()
- }
- }
-
/** Attention! It's inplace sort. */
public SortInplace[T] (this sourse : array [T], comparison : System.Comparison[T]) : array [T]
{
Modified: nemerle/trunk/ncc/completion/CodeCompletionEngine.n
==============================================================================
--- nemerle/trunk/ncc/completion/CodeCompletionEngine.n (original)
+++ nemerle/trunk/ncc/completion/CodeCompletionEngine.n Sat Sep 2 20:25:44 2006
@@ -48,6 +48,15 @@
namespace Nemerle.Compiler
{
+ [Record]
+ public struct Relocation
+ {
+ public Line : int;
+ public Column : int;
+ public LineOffset : int;
+ public ColumnOffset : int;
+ }
+
public module Completion
{
CmpOptins = System.StringComparison.InvariantCultureIgnoreCase;
@@ -367,11 +376,6 @@
syncObject : object;
- mutable is_completion : bool;
- public override IsInCompletionMode : bool {
- get { is_completion }
- }
-
public this()
{
this (CompilationOptions ());
@@ -381,7 +385,7 @@
{
base (options);
state = EngineState.Pure;
- is_completion = false;
+ _isInCompletionMode = true;
syncObject = object();
Defines = DefineCollection (this);
References = ReferenceCollection (this);
@@ -502,8 +506,6 @@
requires completionPosition <= contents.Length
{
// Tell the methods we are in completion mode
- is_completion = true;
-
mutable completionList = null;
def env = observedMethod.DeclaringType.GlobalEnv;
Modified: nemerle/trunk/ncc/parsing/AST.n
==============================================================================
--- nemerle/trunk/ncc/parsing/AST.n (original)
+++ nemerle/trunk/ncc/parsing/AST.n Sat Sep 2 20:25:44 2006
@@ -30,6 +30,7 @@
using Nemerle.Collections;
using Nemerle.Utility;
using System.Math;
+using SCG = System.Collections.Generic;
namespace Nemerle.Compiler {
@@ -93,6 +94,8 @@
public static ComputeToken (file_idx : int, line : int, col : int,
end_line : int, end_col : int) : ulong
{
+ def compute (file_idx : int, line : int, col : int, end_line : int, end_col : int) : ulong
+ {
(file_idx :> ulong) %|
((end_line :> ulong) << end_line_bits) %|
((if (end_col > 255) 255UL else (end_col :> ulong)) << end_col_bits) %|
@@ -100,6 +103,19 @@
((if (col > 255) 255UL else (col :> ulong)) << col_bits)
}
+ if (Manager.IsInCompletionMode && Manager.RelocationMaps[file_idx] != null)
+ {
+ def relocLine = RelocateLine (file_idx, line);
+ def relocEndLine = RelocateLine (file_idx, end_line);
+ def relocColumn = RelocateColumn (file_idx, line, col);
+ def relocEndColumn = RelocateColumn (file_idx, end_line, end_col);
+ compute (file_idx, line - (relocLine - line), col - (relocColumn - col),
+ end_line - (relocEndLine - end_line), end_col - (relocEndColumn - end_col))
+ }
+ else
+ compute (file_idx, line, col, end_line, end_col)
+ }
+
/** Adds new filename to locations index. If filename in already in
store, an error message is outputted.
*/
@@ -145,39 +161,118 @@
public FileIndex : int
{
- get {
- (token & file_mask) :> int
- }
+ get { (token & file_mask) :> int }
}
public File : string
{
[Nemerle.Assertions.Ensures (value != null)]
- get {
- Manager.Location_file_names [(token %& file_mask) :> int];
- }
+ get { Manager.Location_file_names [(token %& file_mask) :> int]; }
}
+ //private class RelocationLineComparer : SCG.IComparer[Relocation]
+ //{
+ // public static Default : RelocationLineComparer = RelocationLineComparer ();
+ //
+ // public Compare(x : Relocation, y : Relocation) : int implements SCG.IComparer.Compare
+ // {
+ // x.Line - y.Line
+ // }
+ //}
+
public Line : int
{
- get { ((token >> line_bits) %& ((1UL << 19) - 1UL)) :> int }
+ get
+ {
+ def line = ((token >> line_bits) %& ((1UL << 19) - 1UL)) :> int;
+ if (Manager.IsInCompletionMode)
+ RelocateLine (FileIndex, line)
+ else
+ line
+ }
}
/** we allow only columns in range 0-255 */
public Column : int
{
- get { ((token >> col_bits) %& 255UL) :> int }
+ get
+ {
+ def col = ((token >> col_bits) %& 255UL) :> int;
+
+ if (Manager.IsInCompletionMode)
+ RelocateColumn (FileIndex, Line, col)
+ else
+ col
+ }
}
public EndLine : int
{
- get { ((token %& end_line_mask) >> end_line_bits) :> int }
+ get
+ {
+ def line = ((token %& end_line_mask) >> end_line_bits) :> int;
+ if (Manager.IsInCompletionMode)
+ RelocateLine (FileIndex, line)
+ else
+ line
+ }
}
/** we allow only columns in range 0-255 */
public EndColumn : int
{
- get { ((token %& end_col_mask) >> end_col_bits) :> int }
+ get
+ {
+ def col = ((token %& end_col_mask) >> end_col_bits) :> int;
+
+ if (Manager.IsInCompletionMode)
+ RelocateColumn (FileIndex, EndLine, col)
+ else
+ col
+ }
+ }
+
+ private static RelocateLine (fileIndex : int, line : int) : int
+ {
+ def relMap = Manager.RelocationMaps[fileIndex];
+
+ if (relMap != null)
+ {
+ def res = relMap.BinarySearch (elem => elem.Line - line);
+
+ if (res < 0)
+ {
+ def index = ~res;
+
+ def value = if (index > 0)
+ line + relMap[index - 1].LineOffset;
+ else
+ line;
+
+ value
+ }
+ else
+ line + relMap[res].LineOffset;
+ }
+ else
+ line
+ }
+
+ private static RelocateColumn (fileIndex : int, line : int, col : int) : int
+ {
+ def relMap = Manager.RelocationMaps[fileIndex];
+
+ if (relMap != null)
+ {
+ def res = relMap.BinarySearch (elem => elem.Line - line);
+
+ if (res >= 0)
+ col + relMap[res - 1].ColumnOffset;
+ else
+ col;
+ }
+ else
+ col
}
public CompareTo (x : Location) : int
Modified: nemerle/trunk/ncc/passes.n
==============================================================================
--- nemerle/trunk/ncc/passes.n (original)
+++ nemerle/trunk/ncc/passes.n Sat Sep 2 20:25:44 2006
@@ -26,6 +26,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using SCG = System.Collections.Generic;
using Nemerle.Collections;
using Nemerle.Compiler.Parsetree;
@@ -107,7 +108,9 @@
public LocationStack : Vector [Location] = Vector (32);
/** mapping from index to file name */
- internal Location_file_names : array [string] = array (1024);
+ static FilesCapacity = 1024;
+ protected internal RelocationMaps : array [SCG.List [Relocation]] = array (FilesCapacity);
+ internal Location_file_names : array [string] = array (FilesCapacity);
internal mutable Location_file_names_amount : int;
/** encountered file names with mapping to their indices */
@@ -278,8 +281,10 @@
ProgressBar (10 + current_tyinfo_count * 90 / tyinfo_counter);
}
- public virtual IsInCompletionMode : bool {
- get { false }
+ protected mutable _isInCompletionMode : bool = false;
+
+ public IsInCompletionMode : bool {
+ get { _isInCompletionMode }
}
ProgressBar (stage : int) : void
More information about the svn
mailing list