[svn] r6824: vs-plugin/trunk: ConsoleTest/Program.cs
Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Cont...
VladD2
svnadmin at nemerle.org
Fri Nov 3 10:59:02 CET 2006
Log:
Work on incremental compilation of methods body.
1. Implement ISourceTextManager in ProjectManager class.
2. Add tests.
Author: VladD2
Date: Fri Nov 3 10:58:59 2006
New Revision: 6824
Modified:
vs-plugin/trunk/ConsoleTest/Program.cs
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n
Modified: vs-plugin/trunk/ConsoleTest/Program.cs
==============================================================================
--- vs-plugin/trunk/ConsoleTest/Program.cs (original)
+++ vs-plugin/trunk/ConsoleTest/Program.cs Fri Nov 3 10:58:59 2006
@@ -12,9 +12,12 @@
Test1 test = new Test1();
test.Init();
- test.SimpleSourceTextManager_Start_block_1();
- test.SimpleSourceTextManager_Start_block_2();
- test.SimpleSourceTextManager_Start_block_3();
+ test.SimpleSourceTextManager_GetLine();
+ test.SimpleSourceTextManager_GetLine_EOF();
+ test.SimpleSourceTextManager_GetLineAndColumn();
+ test.SimpleSourceTextManager_GetRegion_block_1();
+ test.SimpleSourceTextManager_GetRegion_block_2();
+ test.SimpleSourceTextManager_GetRegion_block_3();
test.Hint_on_return();
test.Hint_in_body_of_implicit_match();
test.Overload1();
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n Fri Nov 3 10:58:59 2006
@@ -167,4 +167,4 @@
{
0
}
-}
+}/*EOF:0*/
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n Fri Nov 3 10:58:59 2006
@@ -14,7 +14,47 @@
public partial class Test1
{
[Test]
- public SimpleSourceTextManager_Start_block_1() : void
+ public SimpleSourceTextManager_GetLine() : void
+ {
+ def file = FilePath1;
+ def (line, _) = ReadLocation(file, $"Start block 1");
+ def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+
+ def result = txtMan.GetLine(line);
+
+ Assert.IsNotNull(result, "result is null");
+ Assert.AreEqual (result, " /*Start block 1:-0*/;");
+ }
+
+ [Test]
+ public SimpleSourceTextManager_GetLine_EOF() : void
+ {
+ def file = FilePath1;
+ def (line, _) = ReadLocation(file, $"EOF");
+ def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+
+ def result = txtMan.GetLine(line);
+
+ Assert.IsNotNull(result, "result is null");
+ Assert.AreEqual (result, "}/*EOF:0*/");
+ }
+
+ [Test]
+ public SimpleSourceTextManager_GetLineAndColumn() : void
+ {
+ def file = FilePath1;
+ def (line, col) = ReadLocation(file, $"Start block 1");
+ def txtMan = ProjectManager.SimpleSourceTextManager(File.ReadAllText(file));
+
+ def pos = txtMan.ToPosition(line, col);
+ def (line2, col2) = txtMan.GetLineAndColumn(pos);
+
+ Assert.AreEqual(line2, line);
+ Assert.AreEqual(col2, col);
+ }
+
+ [Test]
+ public SimpleSourceTextManager_GetRegion_block_1() : void
{
SimpleSourceTextManager_Start_block(1,
@"/*Start block 1:-0*/;
@@ -22,14 +62,14 @@
}
[Test]
- public SimpleSourceTextManager_Start_block_2() : void
+ public SimpleSourceTextManager_GetRegion_block_2() : void
{
SimpleSourceTextManager_Start_block(2,
@"/*Start block 2:-0*/;/*End block 2:0*/");
}
[Test]
- public SimpleSourceTextManager_Start_block_3() : void
+ public SimpleSourceTextManager_GetRegion_block_3() : void
{
SimpleSourceTextManager_Start_block(3,
@"/*Start block 3:-0*/;
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/TextManagement/ProjectManager.n Fri Nov 3 10:58:59 2006
@@ -9,6 +9,7 @@
{
[Accessor] _engine : Engine;
+ /// Get manager of code file.
public virtual GetSourceManager(filePath : string) : ISourceTextManager
{
SimpleSourceTextManager(this.Engine.Sources[filePath])
@@ -19,64 +20,50 @@
{
[Accessor] _code : string;
- public GetRegion(lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string
+ /// Convert location (line/char coordinate) to position (character offset).
+ /// Coordinats is 1 based.
+ public ToPosition(line : int, @char : int) : int
+ {
+ ToPositionImpl(0, 0, 0, line - 1, @char - 1)
+ }
+
+ /// !!! Coordinats is zero based!
+ private ToPositionImpl(
+ startLine : int,
+ startChar : int,
+ startPosition : int,
+ line : int,
+ @char : int
+ )
+ : int
{
- def lineStart = lineStart - 1;
- def colStart = colStart - 1;
- def lineEnd = lineEnd - 1;
- def colEnd = colEnd - 1;
+ assert(line > startLine || line == startLine && @char >= startChar);
def code = Code;
- mutable i = 0;
- mutable startPos = -1;
- mutable endPos = -1;
- mutable chOffset = 0;
+ mutable i = startPosition;
def peek() { if (i < code.Length) code[i] else '\0' }
def next() { def ch = peek(); i++; ch }
def skip() { i++; }
- def scanChars(ch, stopChOffset)
- {
- match (ch)
- {
- | '\r' when peek() == '\n' =>
- chOffset++;
- scanChars(next(), stopChOffset);
-
- | '\r' | '\n' | '\0' =>
- if (chOffset == stopChOffset)
- i - 1
- else
- throw ArgumentOutOfRangeException("colStart or colEnd");
-
- | _ =>
- if (chOffset == stopChOffset)
- {
- chOffset++;
- i - 1
- }
- else
- {
- chOffset++;
- scanChars(next(), stopChOffset);
- }
- }
- }
-
def scanLines(ln, stopLn)
{
def ch = next();
+ def x = i; def code = code; _ = x;
if (ln == stopLn)
- if (startPos < 0)
{
- startPos = scanChars(ch, colStart);
- scanLines(ln, lineEnd)
+ def chOffset = if (startLine == stopLn) @char - startChar else @char;
+ if (chOffset + i >= code.Length)
+ {
+ assert(true);
+ throw ArgumentOutOfRangeException("char");
}
- else
+ else if (code.IndexOfAny(array['\r', '\n'], i - 1, chOffset) >= 0)
{
- when (lineStart != lineEnd)
- chOffset = 0;
- endPos = scanChars(ch, colEnd)
+ assert(true);
+ throw ArgumentOutOfRangeException("char");
+ }
+ else
+ i + chOffset - 1
}
else match (ch)
{
@@ -86,25 +73,77 @@
scanLines(ln + 1, stopLn)
| '\n' => scanLines(ln + 1, stopLn)
- | '\0' => ()
+ | '\0' => throw ArgumentOutOfRangeException("line or char");
| _ => scanLines(ln, stopLn)
}
}
- scanLines(0, lineStart);
- assert (startPos >= 0 && endPos >= 0);
- code.Substring(startPos, endPos - startPos);
+ def result = scanLines(startLine, line);
+ assert(result >= 0 && result < code.Length);
+ result
+ }
+
+ /// Return string corresponding to given coordinates.
+ /// Coordinats is 1 based.
+ public GetRegion(lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string
+ {
+ def startPos = ToPositionImpl(0, 0, 0, lineStart - 1, colStart - 1);
+ def endPos = ToPositionImpl(lineStart - 1, colStart - 1, startPos,
+ lineEnd - 1, colEnd - 1);
+ Code.Substring(startPos, endPos - startPos);
}
+ /// Return string corresponding to given location.
+ /// Coordinats is 1 based.
public GetRegion(location : Location) : string
{
def x = location;
GetRegion(x.Line, x.Column, x.EndLine, x.EndColumn)
}
- public GetLine(_line : int) : string { throw NotImplementedException(); }
+ /// Return string corresponding to given line.
+ /// Coordinate is 1 based.
+ public GetLine(line : int) : string
+ {
+ def startPos = ToPositionImpl(0, 0, 0, line - 1, 0);
+ def endIndex = Code.IndexOfAny(array['\r', '\n'], startPos, Code.Length - startPos);
+ if (endIndex >= 0)
+ Code.Substring(startPos, endIndex - startPos);
+ else
+ Code.Substring(startPos, Code.Length - startPos);
+ }
+
public GetNearestPosition(_line : int, _col : int) : int { throw NotImplementedException(); }
- public GetLineAndColumn(_pos : int) : int * int { throw NotImplementedException(); }
+
+ /// Return coordinate corresponding to given position.
+ /// "position" is zero based. Returning coordinate is 1 based.
+ public GetLineAndColumn(position : int) : int * int
+ {
+ mutable i = 0;
+ def code = Code;
+ def peek() { if (i < code.Length) code[i] else '\0' }
+ def next() { def ch = peek(); i++; ch }
+ def skip() { i++; }
+
+ def scanLines(ln, @char)
+ {
+ if (i == position)
+ (ln, @char)
+ else match (next())
+ {
+ | '\r' =>
+ when (peek() == '\n')
+ skip();
+ scanLines(ln + 1, 1)
+
+ | '\n' => scanLines(ln + 1, 1)
+ | '\0' => throw ArgumentOutOfRangeException("position");
+ | _ => scanLines(ln, @char + 1)
+ }
+ }
+
+ scanLines(1, 1);
+ }
} // class SimpleSourceTextManager
} // class ProjectManager
} // namespace Nemerle.Completion2
More information about the svn
mailing list