[svn] r6642: nemerle/trunk: Nemerle.nproj boot/Nemerle.Compiler.dll boot/Nemerle.MSBuild.Tasks.dll boot/Ne...

VladD2 svnadmin at nemerle.org
Sun Sep 10 12:34:36 CEST 2006


Log:
Change Location implementation.

Author: VladD2
Date: Sun Sep 10 12:31:20 2006
New Revision: 6642

Modified:
   nemerle/trunk/Nemerle.nproj
   nemerle/trunk/boot/Nemerle.Compiler.dll
   nemerle/trunk/boot/Nemerle.MSBuild.Tasks.dll
   nemerle/trunk/boot/Nemerle.Macros.dll
   nemerle/trunk/boot/Nemerle.dll
   nemerle/trunk/boot/ncc.exe
   nemerle/trunk/ncc/completion/CodeCompletionEngine.n
   nemerle/trunk/ncc/parsing/AST.n
   nemerle/trunk/ncc/passes.n

Modified: nemerle/trunk/Nemerle.nproj
==============================================================================
--- nemerle/trunk/Nemerle.nproj	(original)
+++ nemerle/trunk/Nemerle.nproj	Sun Sep 10 12:31:20 2006
@@ -30,6 +30,9 @@
     <Folder Include="lib" />
   </ItemGroup>
   <ItemGroup>
+    <!--
+    <Compile Include="lib\*.n" />
+    -->
     <Compile Include="lib\internal-numbered.n">
       <SubType>Code</SubType>
     </Compile>

Modified: nemerle/trunk/boot/Nemerle.Compiler.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.MSBuild.Tasks.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.Macros.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/ncc.exe
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/ncc/completion/CodeCompletionEngine.n
==============================================================================
--- nemerle/trunk/ncc/completion/CodeCompletionEngine.n	(original)
+++ nemerle/trunk/ncc/completion/CodeCompletionEngine.n	Sun Sep 10 12:31:20 2006
@@ -55,6 +55,11 @@
     public Column       : int;
     public LineOffset   : int;
     public ColumnOffset : int;
+      
+    override public ToString() : string
+    {
+      $"Line=$Line Column=$Column LineOffset=$LineOffset ColumnOffset=$ColumnOffset"
+    }
   }
   
   public module Completion

Modified: nemerle/trunk/ncc/parsing/AST.n
==============================================================================
--- nemerle/trunk/ncc/parsing/AST.n	(original)
+++ nemerle/trunk/ncc/parsing/AST.n	Sun Sep 10 12:31:20 2006
@@ -31,89 +31,79 @@
 using Nemerle.Utility;
 using System.Math;
 using SCG = System.Collections.Generic;
+using System.Diagnostics;
 
 namespace Nemerle.Compiler {
 
   public struct Location : Nemerle.IComparable [Location]
   {
-    /** The format of token is fixed and holding following info:
-        19 bits for end line number
-        8 bits for end column number
-        19 bits for (start) line number (0-524287 line numbers)
-        8 bits for (start) column number (0-255 column numbers)
-        10 bits for filename index  (1024 filenames)
-        = 64 bits of data
-     */       
-    token : ulong;
-
-    this (t : ulong) { token = t; }
-
-    public this (file_idx : int, line : int, col : int) {
-      token = ComputeToken (file_idx, line, col, line, col);
-    }    
-
-    public this (file_idx : int, line : int, col : int, end_line : int, end_col : int) {
-      token = ComputeToken (file_idx, line, col, end_line, end_col);
+    static this ()
+    {
+      def index = AddFile(""); // fake file with index 0
+      assert(index == 0);
     }    
     
-    public static Default : Location = Location (0UL);
+    public static mutable IsUseRelocationMaps : bool = false;
+    public static RelocationMaps : SCG.List [SCG.List [Relocation]] = SCG.List ();
+    private static _files : SCG.List[string] = SCG.List();
+    private static _filesMap : Hashtable[string, int] = Hashtable();
 
-    public static @== (x : Location, y : Location) : bool { x.token == y.token }
-    public static @!= (x : Location, y : Location) : bool { x.token != y.token }
-   
-    // NOTE: this is not commutative
-    public static @+ (x : Location, y : Location) : Location {
-      Location ((x.token %& (~(end_line_mask %| end_col_mask))) %|
-                (y.token %& (end_line_mask %| end_col_mask)))
+    public this (fileIndex : int, line : int, col : int)
+    {
+      this (fileIndex, line, col, line, col);
     }    
     
-    /** the bit number (from least important as 0) where line info begins */
-    static line_bits : int = 18;
-    static col_bits : int = 10;
-    static end_line_bits : int = 45;
-    static end_col_bits : int = 37;
-    static end_line_mask : ulong = ((1UL << 19) - 1UL) << 45;
-    static end_col_mask : ulong = ((1UL << 8) - 1UL) << 37;
-
-    /** bits reserved for index of file */
-    static file_mask : ulong = 0b1111111111UL;
-
-    static Manager : ManagerClass
+    public this (fileName : string, line : int, col : int, endLine : int, endCol : int)
     {
-      get { ManagerClass.Instance }
+      this (GetFileIndex (fileName), line, col, endLine, endCol);
     }
 
-    public static Init () : void
+    public this (fileIndex : int, line : int, col : int, endLine : int, endCol : int)
     {
-      Manager.Location_file_indices.Clear ();
-      Manager.Location_file_indices.Add ("", 0);
-      Manager.Location_file_names [0] = "";
-      Manager.Location_file_names_amount = 1;
-    }
+      assert(fileIndex >= 0);
     
-    public static ComputeToken (file_idx : int, line : int, col : int, 
-                                end_line : int, end_col : int) : ulong
+      if (IsUseRelocationMaps && RelocationMaps[fileIndex] != null)
     {
-      def compute (file_idx : int, line : int, col : int, end_line : int, end_col : int) : ulong
+        def relocLine      = RelocateLine (fileIndex, line);
+        def relocEndLine   = RelocateLine (fileIndex, endLine);
+        def relocColumn    = RelocateColumn (fileIndex, line, col);
+        def relocEndColumn = RelocateColumn (fileIndex, endLine, endCol);
+        _fileIndex         = fileIndex;
+        _line              = line - (relocLine - line);
+        _column            = (col - (relocColumn - col)) :> short;
+        _endLine           = endLine - (relocEndLine - endLine);
+        _endColumn         = (endCol - (relocEndColumn - endCol)) :> short;
+      }
+      else
       {
-        (file_idx :> ulong) %|
-        ((end_line :> ulong) << end_line_bits) %| 
-        ((if (end_col > 255) 255UL else (end_col :> ulong)) << end_col_bits) %|
-        ((line :> ulong) << line_bits) %| 
-        ((if (col > 255) 255UL else (col :> ulong)) << col_bits)
+        _fileIndex = fileIndex;
+        _line      = line;
+        _column    = col :> short;
+        _endLine   = endLine;
+        _endColumn = endCol :> short;
+      }
       }
 
-      if (Manager.IsInCompletionMode && Manager.RelocationMaps[file_idx] != null)
+    public static Default : Location = Location (0, 0, 0, 0, 0);
+
+    public static @== (x : Location, y : Location) : bool { x.Equals(y) }
+    public static @!= (x : Location, y : Location) : bool { !x.Equals(y) }
+   
+    /// This operator is not commutative!
+    public static @+ (x : Location, y : Location) : Location
       {
-        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))
-      }
+      if (x._fileIndex == y._fileIndex)
+        Location(x._fileIndex, x.Line, x.Column, y.EndLine, y.EndColumn)
+      else
+      {
+        //throw System.ArgumentException ($"Combinig locations of different files ($x and $y)");
+        //System.Console.WriteLine($">>>> Combinig locations of different files ($x and $y)\n $(System.Diagnostics.StackTrace())");
+
+        if (x == Default)
+          y
       else
-        compute (file_idx, line, col, end_line, end_col)
+          x
+      }
     }
 
     /** Adds new filename to locations index. If filename in already in
@@ -121,19 +111,16 @@
      */
     public static AddFile (name : string) : int
     {
-      when (Manager.Location_file_indices.Contains (name))
+      when (_filesMap.Contains (name))
         Message.Error ($"file $name occured twice on the list to compile");
+
       GetFileIndex (name)
     }
     
     /** Removes a filename from the location index */
     public static RemoveFile (name : string) : void
     {
-        if (Manager.Location_file_indices.Contains (name))
-        {
-            Manager.Location_file_indices.Remove (name);
-        }
-        else
+      unless ((_filesMap : SCG.Dictionary[string, int]).Remove (name))
             throw System.ArgumentException ($"file $name do not exist");
     }
 
@@ -142,99 +129,39 @@
      */
     public static GetFileIndex (name : string) : int
     {
-      match (Manager.Location_file_indices.Get (name)) {
-        | Some (idx) => idx
-        | None =>
-          if (Manager.Location_file_names_amount == Manager.Location_file_names.Length) {
-            Message.Warning ("too many filenames... Location cache overflow");
-            0
-          }
-          else {
-            assert (Manager.Location_file_names_amount > 0);
-            Manager.Location_file_indices.Add (name, Manager.Location_file_names_amount);
-            Manager.Location_file_names [Manager.Location_file_names_amount] = name;
-            ++Manager.Location_file_names_amount;
-            Manager.Location_file_names_amount - 1
-          }
-      }
-    }
+      mutable index;
 
-    public FileIndex : int
-    {
-      get { (token & file_mask) :> int }
-    }
-    
-    public File : string
-    {
-      [Nemerle.Assertions.Ensures (value != null)]
-      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
-      {
-        def line = ((token >> line_bits) %& ((1UL << 19) - 1UL)) :> int;
-        if (Manager.IsInCompletionMode)
-          RelocateLine (FileIndex, line)
+      if (_filesMap.TryGetValue(name, out index))
+        index
         else
-          line
+      {
+        index = _files.Count;
+        _files.Add(name);
+        _filesMap[name] = index;
+        RelocationMaps.Add(null);
+        index
       }
     }
 
-    /** we allow only columns in range 0-255 */
-    public Column : int
-    {
-      get
-      {
-        def col = ((token >> col_bits) %& 255UL) :> int;
         
-        if (Manager.IsInCompletionMode)
-          RelocateColumn (FileIndex, Line, col)
-        else
-          col
-      }
-    }
+    [Accessor] _fileIndex : int;
+    [Accessor] _line : int;
+    _column : short;
+    public Column : int { get { _column } }
 
-    public EndLine : int
-    {
-      get
-      {
-        def line = ((token %& end_line_mask) >> end_line_bits) :> int;
-        if (Manager.IsInCompletionMode)
-          RelocateLine (FileIndex, line)
-        else
-          line
-      }
-    }
+    [Accessor] _endLine : int;
+    _endColumn : short;
+    public EndColumn : int { get { _endColumn } }
 
-    /** we allow only columns in range 0-255 */
-    public EndColumn : int
-    {
-      get
+    public File : string
       {
-        def col = ((token %& end_col_mask) >> end_col_bits) :> int;
-        
-        if (Manager.IsInCompletionMode)
-          RelocateColumn (FileIndex, EndLine, col)
-        else
-          col
-      }
+      [Nemerle.Assertions.Ensures (value != null)]
+      get { _files [_fileIndex]; }
     }
 
     private static RelocateLine (fileIndex : int, line : int) : int
     {
-      def relMap = Manager.RelocationMaps[fileIndex];
+      def relMap = RelocationMaps[fileIndex];
       
       if (relMap != null)
       {
@@ -260,14 +187,14 @@
     
     private static RelocateColumn (fileIndex : int, line : int, col : int) : int
     {
-      def relMap = Manager.RelocationMaps[fileIndex];
+      def relMap = RelocationMaps[fileIndex];
       
       if (relMap != null)
       {
         def res = relMap.BinarySearch (elem => elem.Line - line);
 
         if (res > 0)
-          col + relMap[res - 1].ColumnOffset;
+          col + relMap[res].ColumnOffset;
         else
           col;
       }
@@ -277,15 +204,14 @@
     
     public CompareTo (x : Location) : int
     {
-      if (token %& file_mask == x.token %& file_mask)
+      if (_fileIndex == x._fileIndex)
         if (Line == x.Line)
           Column.CompareTo (x.Column)
         else
           Line.CompareTo (x.Line)
-      else {
+      else
         File.CompareTo (x.File)
       }
-    }
 
     public override ToString () : string {
       if (this == Default)
@@ -302,8 +228,9 @@
     [Nemerle.OverrideObjectEquals]
     public Equals (other : Location) : bool
     {
-      token == other.token
-    }
+      _fileIndex == other._fileIndex
+      && _line == other._line       && _column == other._column
+      && _endLine == other._endLine && _endColumn == other._endColumn}
   }
   
   public class Located

Modified: nemerle/trunk/ncc/passes.n
==============================================================================
--- nemerle/trunk/ncc/passes.n	(original)
+++ nemerle/trunk/ncc/passes.n	Sun Sep 10 12:31:20 2006
@@ -107,20 +107,6 @@
     protected internal mutable Message_output : System.IO.TextWriter;
     public LocationStack : Vector [Location] = Vector (32);
 
-    /** mapping from index to file name */
-    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 */
-    internal Location_file_indices : Hashtable [string, int] = Hashtable ();
-
-    public GetFileIndex(filePath : string) : int
-    {
-      Location_file_indices[filePath];
-    }
-
     /** Called by parser when simple "using" directive parsed .
      * name : list [string] - qualified identifier/
      * prevEnv : GlobalEnv - GlobalEnv before adding current using directive.
@@ -188,11 +174,6 @@
       Message_error_cnt = 0;
       Message_warning_cnt = 0;
       Message_emitted_hints.Clear ();
-
-      Location_file_indices.Clear ();
-      Location_file_indices.Add ("", 0);
-      Location_file_names [0] = "";
-      Location_file_names_amount = 1;
     }
     #endregion
 
@@ -208,10 +189,6 @@
       SystemTypeCache = SystemTypeClass (this);
       AttributeCompiler = AttributeCompilerClass (this);
       Stats = StatsClass ();
-
-      Location_file_indices.Add ("", 0);
-      Location_file_names [0] = "";
-      Location_file_names_amount = 1;
     }
     
     public MarkAsUsed (member : IMember) : void
@@ -323,7 +300,6 @@
       KillStatics ();
       Stats.Reset ();
       MacroColors = MacroColorizator ();
-      Location.Init ();
       if (shouldCreate (NameTree))
         NameTree = NamespaceTree (this);
       else



More information about the svn mailing list