[svn] r7781: vs-plugin/trunk/Nemerle.Compiler.Utils: Nemerle.Completion2/CodeFormatting/CodeFormattingStag...

kliss svnadmin at nemerle.org
Sat Sep 1 15:25:13 CEST 2007


Log:
WinForms designer;
 - add support for events and properties
 - add some support for type parameters

Work on formatter

Author: kliss
Date: Sat Sep  1 15:25:08 2007
New Revision: 7781

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeFormattingStageBase.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeIndentationStage.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeLineBreakingStage.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/Formatter.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/FormatterResult.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenNotFoundException.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenStreamFinder.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/TokenFinder.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeParser.n

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeFormattingStageBase.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeFormattingStageBase.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeFormattingStageBase.n	Sat Sep  1 15:25:08 2007
@@ -87,7 +87,7 @@
     protected _fileIndex : int;
 
     protected mutable rootNamespaceNode : Decl.Namespace = null;
-    protected _tokenFinder : TokenStreamFinder = TokenStreamFinder();
+    protected _tokenFinder : TokenStreamHandler = TokenStreamHandler();
     
     private results : SCG.List.[FormatterResult] = SCG.List.[FormatterResult]();
     protected AddResult(result : FormatterResult) : void

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeIndentationStage.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeIndentationStage.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeIndentationStage.n	Sat Sep  1 15:25:08 2007
@@ -102,11 +102,34 @@
       }
     }
     
+    RecalcLocation(loc : Location) : Location
+    {
+      def recalc(col, results)
+      {
+        mutable newCol = col;
+        
+        foreach(fr in results)
+        {
+          when(fr.StartCol < col && fr.EndCol < col && fr.StartLine == fr.EndLine)
+          {
+            newCol += (fr.ReplacementString.Length - (fr.EndCol - fr.StartCol));
+          }
+        }
+        
+        newCol
+      }
+      
+      def newStartCol = recalc(loc.Column, GetResults().Filter(fr => fr.StartLine == loc.Line));
+      def newEndCol = recalc(loc.EndColumn, GetResults().Filter(fr => fr.StartLine == loc.EndLine));
+      
+      Location(loc.FileIndex, loc.Line, newStartCol, loc.EndLine, newEndCol);
+    }
+    
     indentValue = " "; // TODO: make it configurable by user.
     defaultIndentSize = 2;
-    matchCasesIndentOffset = 0; // match cases will be indented by matchCasesIndentOffset * defaultIndentSize
+    matchCasesIndentOffset = 2; // match cases will be indented by matchCasesIndentOffset * defaultIndentSize
     matchCasesBodyIndentOffset = 2;
-    variantOptionIndentOffset = 1;
+    variantOptionIndentOffset = 2;
         
     
     IndentLocation(loc : Location) : void
@@ -119,7 +142,7 @@
         builder.ToString();
       }
 
-      def canOperate = !loc.IsEmpty && _tokenFinder.GetLineTokens(loc.Line)
+      def canOperate = !loc.IsEmpty && _tokenFinder.FindAll(tok => tok.Location.Line == loc.Line)
         .Filter(tok => tok.Location.EndColumn <= loc.Column)
         .ForAll(_.IsWhiteSpace());
       def isWithinRange = if(RegionToFormat.IsEmpty) true
@@ -129,11 +152,13 @@
       {
         def expectedPosition = PeekIndent();  
         
+        unless(loc.Column == expectedPosition)
+        {
         if(expectedPosition != 1)
           AddResult(FormatterResult.Replace(loc.Line, 1, loc.Column, getIndentString(expectedPosition - 1)));
         else
           AddResult(FormatterResult.Erase(loc.Line, 1, loc.Column));
-          
+        }
       }
     }
 
@@ -233,16 +258,19 @@
             | PExpr.Sequence(body) as seq =>
                 def beginBrace = _tokenFinder.FindAt(seq.Location.Line, seq.Location.Column);
                 assert(beginBrace is Token.BeginBrace);
-                IndentLocation(beginBrace.Location);
                 
+                using(GetIndentPusher(RecalcLocation(firstKeywordLoc.UnSome()).Column))
+                {
+                  IndentLocation(beginBrace.Location);
                 using(GetIndentPusher())
                 {
                   body.Iter(FormatPExpr);
                 }
-                
                 IndentLocation(GetNextPairedBrace(beginBrace).Location);
+                }
+                
             | _ => 
-                using(GetIndentPusher())
+                using(GetIndentPusher(RecalcLocation(firstKeywordLoc.UnSome()).Column + defaultIndentSize))
                 {
                   FormatPExpr(pexpr);
                 }
@@ -264,7 +292,7 @@
                     | None => firstKeywordLoc = Some(kw.Location);
                     | _ => ()
                     }
-                    using(GetIndentPusher(firstKeywordLoc.UnSome().Column))
+                    using(GetIndentPusher(RecalcLocation(firstKeywordLoc.UnSome()).Column))
                     {
                       IndentLocation(kw.Location);
                     }
@@ -396,7 +424,7 @@
           FormatPExpr(name);
 
           def equalSign = _tokenFinder.FindNextIf(name.Location.EndLine, name.Location.EndColumn, _ is Token.Operator("="));
-          using(GetIndentPusher(equalSign.Location.EndColumn + 1))
+          using(GetIndentPusher(RecalcLocation(equalSign.Location).EndColumn + 1))
           {
             FormatPExpr(val);
           }
@@ -405,14 +433,14 @@
           FormatPExpr(name);
 
           def equalSign = _tokenFinder.FindNextIf(name.Location.EndLine, name.Location.EndColumn, _ is Token.Operator("="));
-          using(GetIndentPusher(equalSign.Location.EndColumn + 1))
+          using(GetIndentPusher(RecalcLocation(equalSign.Location).EndColumn + 1))
           {
             FormatPExpr(val);
           }
       //| Indexer (obj, parms) 
       | Call(obj, parms)  => // here obj is the func name.
           FormatPExpr(obj);
-          using(GetIndentPusher(parms.Head.Location.Column + defaultIndentSize))
+          using(GetIndentPusher(RecalcLocation(parms.Head.Location).Column + defaultIndentSize))
           {
             parms.Iter(FormatPExpr);  
           }
@@ -707,8 +735,10 @@
     }
     public override FormatRegion(startLine : int, startCol : int, endLine : int, endCol : int) : SCG.List.[FormatterResult]
     {
-      _ = base.FormatRegion(startLine, startCol, endLine, endCol);
-      FormatDocument();
-    }
+_ = base.FormatRegion(startLine, startCol, endLine, endCol);
+// The call above sets "clipping" region, and FromatDocument will respect
+// this and will not make any changes that are not inside of that region.
+FormatDocument();
+}
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeLineBreakingStage.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeLineBreakingStage.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/CodeLineBreakingStage.n	Sat Sep  1 15:25:08 2007
@@ -11,6 +11,14 @@
 
 namespace Nemerle.Completion2.CodeFormatting
 {
+/* TODO: Implement a simple line breaker                             
+ * Provide conversion between two main open brace style: the K&R style and the other. :-)
+ * List of constructs that will support brace formatting: namespace, type definitions, methods,
+ *  properties, local functions, match expressions (foreach, for, if/else and other macros that change 
+ *  syntax will be added later).
+ *
+ *
+ */
 
   class CodeLineBreakingStage : CodeFormattingStageBase
   {
@@ -22,13 +30,22 @@
 
     mutable _insertedLines = 0;
 
+    _BreakLine(_loc : Location)  : void
+    {
+    
+    }
+    
+    _UnBreakLine(_loc : Location) : void
+    {
+    
+    }
+
     SetExpectedLine(val : int) : void
     {
       _expectedLine = val;
       _insertedLines = 0;
     }
 
-    
     #region Helper methods
     
     LineBreak(loc : Location) : void

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/Formatter.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/Formatter.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/Formatter.n	Sat Sep  1 15:25:08 2007
@@ -134,6 +134,7 @@
       // and wait for changes to be applied.
       foreach(stage in stages)
       {
+        
         results.AddRange(stage.FormatRegion(startLine, startCol, endLine, endCol)); 
       }
 

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/FormatterResult.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/FormatterResult.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/FormatterResult.n	Sat Sep  1 15:25:08 2007
@@ -15,24 +15,17 @@
     [Accessor] _endLine : int = -1;
     [Accessor] _endCol : int  = -1;
     [Accessor] _replacementString : string = "";
-    public ResultType : string
-    {
-      get
+    
+    public override ToString() : string
       {
-        if(StartCol == EndCol)
+      match((StartLine, StartCol, EndLine, EndCol, ReplacementString))
         {
-          if(ReplacementString.Length > 0)
-            "Insertion"
-          else
-            "ERROR"
-        }
-        else
-        {
-          if(ReplacementString.Length == 0)
-            "Erase"
-          else
-            "Replacement"
-        } 
+      | (startLine, startCol, endLine, endCol, replacement) when startLine == endLine 
+                                                                 && startCol == endCol 
+                                                                 && replacement.Length > 0 => $"\"$replacement\" -> ($startLine, $startCol)";
+      | (startLine, startCol, endLine, endCol, replacement) when startLine == endLine => $"($startLine, $startCol-$endCol) = \"$replacement\"";
+      | (startLine, startCol, endLine, endCol, replacement) => $"($startLine, $startCol, $endLine, $endCol) = \"$replacement\"";
+      //| _ => "FormatterResult.ToString(): unexpected set of values";
       }
     }
     

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenNotFoundException.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenNotFoundException.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenNotFoundException.n	Sat Sep  1 15:25:08 2007
@@ -4,11 +4,24 @@
 
 namespace Nemerle.Completion2.CodeFormatting
 {
-  public class TokenNotFoundException : Exception
+  public class FormatterException : Exception
   {
-    public this(message : string) 
+    public this(userMessage : string)
     {
-      base(message);
+      base($"FormatterException: $userMessage");
+    }
+    
+    protected this(theMessage : string, _ : object) 
+    {
+      base(theMessage);
+    }
+  }
+  
+  public class TokenNotFoundException : FormatterException
+  {
+    public this(userMessage : string) 
+    {
+      base($"TokenNotFoundException: $userMessage", null);
     }
   }
 }
\ No newline at end of file

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenStreamFinder.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenStreamFinder.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeFormatting/TokenStreamFinder.n	Sat Sep  1 15:25:08 2007
@@ -3,215 +3,218 @@
 using System.Collections.Generic;
 
 using Nemerle;
+using Nemerle.Utility;
+using Nemerle.Completion2;
 using Nemerle.Compiler;
 using Nemerle.Completion2.CodeFormatting;
 
 namespace Nemerle.Completion2
 {
-  // This class is used to find tokens in token stream (no token groups)
-  public class TokenStreamFinder
+  // This class encapsulates work with token stream. It supports 
+  // insertion and removal of single tokens or token groups, and it 
+  // also does transparent relocation of tokens affected by any operation.
+  // And the last, but not least: it can build a diff between original stream and final one.
+  public class TokenStreamHandler
   {
-    _sortedTokens : Dictionary.[int, array[Token]] = Dictionary();
+    private class PositionHolder
+    {
+      mutable _tokens : List.[Token] = null;
+      mutable _currentIndex = 0;
     mutable isInitialized = false;
     
-    public this(){}
+      //public this(){}
     
     // We're assuming that tokens are ordered as they appear in the source, i.e. no reversing and shuffling.
-    public this(tokens : array[Token])
+      public this(tokens : List.[Token], currentIndex : int)
     {
-      Initialize(tokens);
+        Initialize(tokens, currentIndex);
     }
     
-    public Initialize(tokens : array[Token]) : void
+      public Initialize(tokens : List.[Token], currentIndex : int) : void
     {
       isInitialized = true;
-      def curLineTokens = List(); 
       
-      // Enumerate tokens starting from currentTokenPos and see if they belong 
-      // to line number linePos. As long as they do, add them to temp list.
-      // When we see a token located at line with greater number, then stop.
-      def GetLineTokens(linePos, currentTokenPos)
+        _tokens = tokens;
+        _currentIndex = currentIndex;
+      } 
+      
+      AlterPosition(advance : bool) : void
       {
-        if(currentTokenPos == tokens.Length)
-          currentTokenPos
+        if(advance)
+          _currentIndex++;
         else
-        {
-          def tok = tokens[currentTokenPos];
-          if(tok.Location.Line == linePos)
-          {
-            curLineTokens.Add(tok);
-            GetLineTokens(linePos, currentTokenPos + 1);
+          _currentIndex--;
           }
-          else if(tok.Location.Line > linePos)
+      
+      GetCurrentToken() : Token
           {
-            currentTokenPos;    
-          }
+        if(_currentIndex < 0 || _currentIndex >= _tokens.Count)
+          null
           else
-          {
-            throw ApplicationException("Order of tokens is invalid");
-          }
-        }
+          _tokens[_currentIndex];
       }
       
-      mutable curLinePos = tokens[0].Location.Line;
-      mutable curTokenIndex = 0;
-      while(curTokenIndex < tokens.Length)
+      public GetNextToken() : Token
       {
-        // Get index of last token in this line.
-        curTokenIndex = GetLineTokens(curLinePos, curTokenIndex);
-        _sortedTokens[curLinePos] = curLineTokens.ToArray();
-        curLineTokens.Clear();
-        curLinePos++;
-      }
+        def tok = GetCurrentToken();
+        AlterPosition(true);
+        tok
     }  
     
-    public FindNextIf(line : int, col : int, predicate : Token -> bool) : Token
+      public GetPrevToken() : Token
     {
-      if(!isInitialized)
-        throw InvalidOperationException("TokenStreamFinder hasn't been properly initialized. Either use constructor with parameters or Initialize() method.");
-      else
-      {
-        mutable curLine = line;
-        mutable curIndex = 0;
+        def tok = GetCurrentToken();
+        AlterPosition(false);
+        tok
+      }
 
-        def getCurrentToken()
-        {
-          if(curIndex < _sortedTokens[curLine].Length)
-            _sortedTokens[curLine][curIndex]
-          else
-            null
         }
-        def advancePosition()
-        {
-          if(curIndex < _sortedTokens[curLine].Length - 1)
-            curIndex++;
-          else //when(_sortedTokens.ContainsKey(curLine + 1))
+  
+    mutable _originalStream : List.[Token] = null;
+    mutable _stream : List.[Token] = null;
+    mutable _isInitialized = false;
+    
+    public this()
+    {}
+    
+    public this(tokens : array[Token])
           {
-            curLine++;
-            curIndex = 0;
-          }  
+      Initialize(tokens);
         }
-        def getNextToken()
+    
+    public Initialize(tokens : array[Token]) : void
         {
-          def tok = getCurrentToken();
-          advancePosition();
-          tok
+      _isInitialized = true;
+      _originalStream = List(tokens);
+      _stream = List(tokens);
         }
-        when(!_sortedTokens.ContainsKey(curLine))
-          Debug.WriteLine($"No key: $curLine");
-        mutable startLineTokens = _sortedTokens[curLine];
-        def setStartPoint()
-        {
-          if(curLine == line && curIndex < startLineTokens.Length && startLineTokens[curIndex].Location.Column < col)
+
+    RelocateToken(tok : Token, line : int, col : int, lineDelta : int, colDelta : int) : void
           {
-            curIndex++;
-            setStartPoint();
-          }
-          else when(curIndex == startLineTokens.Length)
+      match(tok)
           {
-            curLine++;
-            startLineTokens = _sortedTokens[curLine];
-            curIndex = 0;
-            setStartPoint();
+      | t when t.Location.Line == line && t.Location.Column > col with loc = t.Location =>
+          t.Location = Location(loc.FileIndex,
+                                loc.Line + lineDelta, 
+                                loc.Column + colDelta,
+                                loc.EndLine,
+                                loc.EndColumn);
+                                
+      | t when t.Location.Line > line with loc = t.Location =>
+          t.Location = Location(loc.FileIndex,
+                                loc.Line + lineDelta, 
+                                loc.Column,
+                                loc.EndLine,
+                                loc.EndColumn);
+      | _ => ()
           }
         }
         
-        setStartPoint();
-
-        // Ok, start position defined. Start matching each next token against given predicate.
-        mutable result = getNextToken();
-        while(result != null && !predicate(result))
+    Relocate(index : int, lineDelta : int, colDelta : int) : void
         {
-          result = getNextToken();
-        }
-        when(result == null)
-          throw TokenNotFoundException("Token not found");
-        result;
+      def loc = _stream[index].Location;
+      for(mutable i = index; i < _stream.Count; i++)
+      {
+        RelocateToken(_stream[i], loc.Line, loc.Column, lineDelta, colDelta); 
       }
     }
     
-    public FindPrevIf(line : int, col : int, predicate : Token -> bool) : Token
-    {
-      if(!isInitialized)
-        throw InvalidOperationException("TokenStreamFinder hasn't been properly initialized. Either use constructor with parameters or Initialize() method.");
-      else
+    SetStartPosition(line : int, col : int) : int
       {
-        mutable curLine = line;
-        mutable curIndex = _sortedTokens[curLine].Length - 1;
+      mutable result = 0;
 
-        def getCurrentToken()
+      // Here we rely on the fact that all tokens are in the right order.
+      foreach(tok in _stream)
         {
-          if(curIndex < _sortedTokens[curLine].Length)
-            _sortedTokens[curLine][curIndex]
+        if(tok.Location.Contains(line, col) && tok.Location.EndColumn != col)
+          Nemerle.Imperative.Return(result);
           else
-            null
-        }
-        def retreatPosition()
-        {
-          if(curIndex > 0)
-            curIndex--;
-          else //when(_sortedTokens.ContainsKey(curLine - 1))
-          {
-            curLine--;
-            curIndex = _sortedTokens[curLine].Length - 1;
+          result++;
           }  
+      throw FormatterException($"Position ($line, $col) is outside of document.");
         }
-        def getPrevToken()
+    
+    public InsertBefore(token : Token, insertion : Token) : void
         {
-          def tok = getCurrentToken();
-          retreatPosition();
-          tok
+      def idx = _stream.FindIndex(token : object == _);
+      Debug.WriteLine($"Insertion: found token $token at ($(token.Location.Line), $(token.Location.Column))");
+      _stream.Insert(idx, insertion);
+      def loc = insertion.Location;
+      Relocate(idx, loc.EndLine - loc.Line, loc.EndColumn - loc.Column); 
         }
-        when(!_sortedTokens.ContainsKey(curLine))
-          Debug.WriteLine($"No key: $curLine");
-        mutable startLineTokens = _sortedTokens[curLine];
-        def setStartPoint()
-        {
-          if(curLine == line && curIndex > 0 && startLineTokens[curIndex].Location.Column > col)
+    
+    // Removes tokens from startFrom token and up to (but not including) upTo token.
+    public Remove(startFrom : Token, upTo : Token) : void
           {
-            curIndex--;
-            setStartPoint();
+      def startIndex = _stream.FindIndex(startFrom : object == _);
+      def endIndex = _stream.FindIndex(upTo : object == _);
+      assert(startIndex < endIndex);
+      
+      mutable removedLocation = Location.Default;
+      for(mutable i = startIndex; i < endIndex; i++)
+        removedLocation = _stream[i].Location.Combine(removedLocation);
+      
+      _stream.RemoveRange(startIndex, endIndex - startIndex);
+      Relocate(startIndex,  
+               removedLocation.EndLine - removedLocation.Line,
+               removedLocation.EndColumn - removedLocation.Column); 
+      
           }
-          else when(curIndex == 0)
+    
+    public FindAll(predicate : Token -> bool) : IEnumerable[Token]
           {
-            curLine--;
-            startLineTokens = _sortedTokens[curLine];
-            curIndex = _sortedTokens[curLine].Length - 1;
-            setStartPoint();
-          }
+      _stream.Filter(predicate);
         }
         
-        setStartPoint();
+    public FindNextIf(line : int, col : int, predicate : Token -> bool) : Token
+    {
+      def startIndex = SetStartPosition(line, col);
+      def holder = PositionHolder(_stream, startIndex);
 
-        // Ok, start position defined. Start matching each next token against given predicate.
-        mutable result = getPrevToken();
+      mutable result = holder.GetNextToken();
         while(result != null && !predicate(result))
-        {
-          result = getPrevToken();
-        }
+        result = holder.GetNextToken();
+        
         when(result == null)
-          throw TokenNotFoundException("Token not found");
-        result;
+        throw FormatterException($"Token not found (next from ($line, $col), using predicate $predicate)");
+      result 
       }
+    
+    public FindPrevIf(line : int, col : int, predicate : Token -> bool) : Token
+    {
+      def startIndex = SetStartPosition(line, col);
+      def holder = PositionHolder(_stream, startIndex);
+      
+      mutable result = holder.GetNextToken();
+      while(result != null && !predicate(result))
+        result = holder.GetPrevToken();
+        
+      when(result == null)
+        throw FormatterException($"Token not found (prev from ($line, $col), using predicate $predicate)");
+      result 
     }
     
-    public FindAt(line : int, col : int) : Token
+    public FindNextRange(_line : int, _col : int, _predicate : Token -> bool) : array[Token]
     {
-      if(!isInitialized)
-        throw InvalidOperationException("TokenStreamFinder hasn't been properly initialized. Either use constructor with parameters or Initialize() method.");
-      else
+      throw NotImplementedException("FindNextRange");
+    }
+    
+    public FindPrevRange(_line : int, _col : int, _predicate : Token -> bool) : array[Token]
       {
-        def lineTokens = _sortedTokens[line];
-        def result = Array.Find(lineTokens, tok =>  tok.Location.Contains(line, col)
-                                                    && col != tok.Location.EndColumn);
-        result;
+      throw NotImplementedException("FindPrevRange");
       }
+    
+    public FindAt(line : int, col : int) : Token
+    {
+      def startIndex = SetStartPosition(line, col);
+      _stream[startIndex];
     }
     
-    public GetLineTokens(line : int) : array[Token]
+    public Diff() : List.[FormatterResult]
     {
-      def result = _sortedTokens[line];
-      result;
+      throw NotImplementedException("Diff");
     }
+
+    
   }
 }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n	Sat Sep  1 15:25:08 2007
@@ -60,7 +60,7 @@
         def lexer = LexerString(this.Engine, src, Location(fileIndex, 1, 1));
         lexer.Keywords = this.Engine.CoreEnv.Keywords;
 
-        def tokenFinder = TokenStreamFinder(lexer.ReadAllTokens());
+        def tokenFinder = TokenStreamHandler(lexer.ReadAllTokens());
         tokenFinder.FindAt(line, col);
       }
 
@@ -68,7 +68,7 @@
       def tok = getTokenAtCursor();
       match(tok)
       {
-      | Identifier(name) => 
+      | Token.Identifier(name) => 
               match (activeEnv.LookupType([name], activeBuilder, -1))
               {
               | Some(ti) => FindInheritors(ti);

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/TokenFinder.n
==============================================================================

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeParser.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeParser.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/NemerleCodeParser.n	Sat Sep  1 15:25:08 2007
@@ -58,7 +58,7 @@
       }
     }
 
-    protected CreateClass(cls: TypeBuilder) : CodeTypeDeclaration
+    protected CreateClass(cls : TypeBuilder) : CodeTypeDeclaration
     {
       // creates class declaration
       def classDecl = CodeTypeDeclaration(cls.Name);
@@ -97,16 +97,14 @@
     }
 
     // needed cause we may want to override it in derived classes
-    protected virtual ProcessClassMembers(members: list[IMember],classDecl: CodeTypeDeclaration) : void
+    protected virtual ProcessClassMembers(members : list[IMember], classDecl : CodeTypeDeclaration) : void
     {
       members.Iter(m : IMember =>
         match(m)
         {
           | m is TypeBuilder => {_ = classDecl.Members.Add(CreateClass(m));}
           //| m is EventBuilder => CreateEvent(m) // TODO
-          //| m is FieldBuilder => CreateField(m) 
           | m is MemberBuilder => {_ = classDecl.Members.Add(CreateMember(m));}
-          //| m is PropertyBuilder => CreateProperty(m)// TODO
 
           //| m is NetEvent 
           //| m is NetProperty
@@ -130,10 +128,10 @@
       def memberDecl : CodeTypeMember = 
         match(member)
         {
-          //| m is EventBuilder => CreateEvent(m) // TODO
+          | m is EventBuilder => CreateEvent(m) 
           | m is FieldBuilder => CreateField(m)
           | m is MethodBuilder => CreateMethod(m) 
-          //| m is PropertyBuilder => CreateProperty(m) // TODO
+          | m is PropertyBuilder => CreateProperty(m) 
           | _ => 
             { Debug.WriteLine($"CodeDomParser ignore declaration: $member : $(member.Name)"); null }
         }
@@ -182,6 +180,42 @@
       fieldDecl
     }
 
+    protected virtual CreateProperty(prop : PropertyBuilder) : CodeMemberProperty
+    {
+      Debug.Print($"CreateProperty: from $prop");
+      
+      def result = CodeMemberProperty();
+      result.Attributes = CodeDomHelper.GetMemberAttributes(prop.Attributes);
+      result.Name = prop.Name;
+      
+      when(prop.Getter != null)
+      {
+        result.HasGet = true;
+        result.Type = ToTypeRef(prop.Getter.ReturnType);
+        when(prop.Getter is MethodBuilder)
+          _ = result.GetStatements.AddRange(ToStatements((prop.Getter :> MethodBuilder).BodyParsed).ToArray())
+      }
+      when(prop.Setter != null)
+      {
+        result.HasSet = true;
+        result.Type = ToTypeRef(prop.Setter.ReturnType);
+        when(prop.Setter is MethodBuilder)
+          _ = result.SetStatements.AddRange(ToStatements((prop.Setter :> MethodBuilder).BodyParsed).ToArray())
+      }
+      result  
+    }
+
+    protected virtual CreateEvent(evt : EventBuilder) : CodeMemberEvent
+    {
+      def eventDecl = CodeMemberEvent();
+      eventDecl.Attributes = CodeDomHelper.GetMemberAttributes(evt.Attributes);
+      eventDecl.Name = evt.Name;
+      // TODO: Find Type properly
+      eventDecl.Type = ToTypeRef(evt.GetAdder().ReturnType);
+      
+      eventDecl
+    }
+    
     protected virtual CreateMethod(method: MethodBuilder) : CodeMemberMethod
     { 
       Debug.Print($"CreateMethod : from $method");
@@ -208,15 +242,14 @@
 
       //TODO: methodDecl.ImplementationTypes - how to get that
       
-
       //methodDecl.Parameters
       method.GetParameters().Iter(param =>
-          { _ = methodDecl.Parameters.Add(CodeParameterDeclarationExpression(param.SystemType, param.Name)) } 
+          { _ = methodDecl.Parameters.Add(CodeParameterDeclarationExpression(ToTypeRef(param.ty), param.Name)) } 
      );
 
       //TODO:  methodDecl.PrivateImplementationType ?
 
-      methodDecl.ReturnType = CodeTypeReference(method.ReturnType.SystemType);
+      methodDecl.ReturnType = ToTypeRef(method.ReturnType);
 
       // methodDecl.TypeParameters , TODO: check if it actually works
       method.GetHeader().typarms.Iter(typaram =>
@@ -279,15 +312,15 @@
       else CodeTypeReference(typeof(object))
     }
     
-    ToTypeRef(typeInfo : Nemerle.Compiler.TypeInfo, typeParaams : list[TyVar]) : CodeTypeReference
+    ToTypeRef(typeInfo : Nemerle.Compiler.TypeInfo, typeParams : list[TyVar]) : CodeTypeReference
     {
-      Trace.Assert(typeInfo.TyparmsCount == 0); // TODO: Add support for type parametrs!
-      Trace.Assert(typeParaams.IsEmpty);
+      //Trace.Assert(typeInfo.TyparmsCount == 0, "typeInfo.TyparmsCount == 0, value is $(typeInfo.TyparmsCount)"); // TODO: Add support for type parametrs!
+      //Trace.Assert(typeParams.IsEmpty, $"typeParams.IsEmpty, value is $(typeParams.ToString())");
     
       if (typeInfo.SystemType != null)
-        CodeTypeReference(typeInfo.SystemType);
+        CodeTypeReference(typeInfo.SystemType.FullName, typeParams.Map(ToTypeRef).ToArray());
       else
-        CodeTypeReference(typeInfo.FullName);
+        CodeTypeReference(typeInfo.FullName, typeParams.Map(ToTypeRef).ToArray());
     }
 
     protected virtual ToExpression(expr : PExpr) : CodeExpression



More information about the svn mailing list