[svn]
r6675: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2:
CompiledUnitAstBrowser.n Engine/E...
VladD2
svnadmin at nemerle.org
Fri Sep 22 03:37:42 CEST 2006
Log:
Work on relocation.
Author: VladD2
Date: Fri Sep 22 03:37:40 2006
New Revision: 6675
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CompiledUnitAstBrowser.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Relocation.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CompiledUnitAstBrowser.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CompiledUnitAstBrowser.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CompiledUnitAstBrowser.n Fri Sep 22 03:37:40 2006
@@ -11,15 +11,38 @@
{
FillTree(root : Decl) : void
{
+ def fileIndex = root.Location.FileIndex;
+
def addLocation(nodes, kind, name, location)
{
when (!name.IsNullOrEmpty())
{
- def newNode = nodes.Add($"$kind: $name");
+ def x = location;
+ def newNode = nodes.Add($"($(x.Line),$(x.Column); $(x.EndLine),$(x.EndColumn)) $kind: $name");
newNode.Tag = location;
}
}
+ def addLacations(nodes, text, locations)
+ {
+ when (!text.IsNullOrEmpty())
+ {
+ def newNode = nodes.Add(text);
+ mutable locAll = Nemerle.Compiler.Location.Default;
+
+ foreach (loc in locations)
+ {
+ locAll += loc;
+ def newSubNode = newNode.Nodes.Add($"($(loc.Line),$(loc.Column); $(loc.EndLine),$(loc.EndColumn))");
+ newSubNode.Tag = loc;
+ when (loc.FileIndex == fileIndex)
+ newSubNode.ForeColor = System.Drawing.Color.Red;
+ }
+
+ newNode.Tag = locAll;
+ }
+ }
+
def addName(nodes, name, locations)
{
when (!name.IsNullOrEmpty())
@@ -30,7 +53,8 @@
foreach (loc in locations)
{
locAll += loc;
- def newSubNode = newNode.Nodes.Add("name part");
+ def x = loc;
+ def newSubNode = newNode.Nodes.Add($"name part ($(x.Line),$(x.Column); $(x.EndLine),$(x.EndColumn))");
newSubNode.Tag = loc;
}
@@ -38,15 +62,19 @@
}
}
- def addType(builder)
+ def addType(nodes, builder)
{
- _ = builder;
+ addLocation(nodes, "Location", " ", builder.Location);
+ addLacations(nodes, "PartsLocation", builder.PartsLocation);
+ foreach (member :> MemberBuilder in builder.GetDirectMembers())
+ when (member.BodyLocation.FileIndex == fileIndex)
+ addLocation(nodes, member.ToString(), " ", member.BodyLocation);
}
def add(nodes, astNode)
{
def newNode = nodes.Add($"$(astNode.GetType().Name): $astNode");
- newNode.Tag = astNode;
+ newNode.Tag = astNode.Location;
match (astNode : Decl)
{
@@ -60,18 +88,68 @@
foreach (decl in x.Decls)
add(newNode.Nodes, decl)
- | Type(builder) => addType(builder);
+ | Type(builder) => addType(newNode.Nodes, builder);
| GlobalAttribute => ()
| None => ()
}
}
+ def getNodesInfo() : list[int]
+ {
+ mutable acc = [];
+ mutable i = 0;
+
+ def loop(nodes : TreeNodeCollection)
+ {
+ foreach (node :> TreeNode in nodes)
+ {
+ i++;
+ when (node.IsExpanded)
+ acc ::= i;
+
+ loop(node.Nodes);
+ }
+ }
+
+ loop(Tree.Nodes);
+ acc.Rev()
+ }
+
+ def setNodesInfo(nodesInfo)
+ {
+ mutable acc = nodesInfo;
+ mutable i = 0;
+
+ def loop(nodes : TreeNodeCollection)
+ {
+ foreach (node :> TreeNode in nodes)
+ {
+ i++;
+ if (acc.IsEmpty)
+ Nemerle.Imperative.Return();
+ else when (acc.Head == i)
+ {
+ node.Expand();
+ acc = acc.Tail;
+ }
+
+ loop(node.Nodes);
+ }
+ }
+
+ loop(Tree.Nodes);
+ }
+
try
{
Tree.BeginUpdate();
+ def nodesInfo = getNodesInfo();
+ def count = Tree.GetNodeCount(true);
Tree.Nodes.Clear();
add(Tree.Nodes, root);
+ when (count == Tree.GetNodeCount(true))
+ setNodesInfo(nodesInfo);
}
finally
{
@@ -116,6 +194,7 @@
{
//def scrBnds = Screen.PrimaryScreen.Bounds;
Tree = TreeView();
+ Tree.HideSelection = false;
TopMost = true;
Tree.Dock = DockStyle.Fill;
Controls.Add(Tree);
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-Relocation.n Fri Sep 22 03:37:40 2006
@@ -28,7 +28,7 @@
def prj = this.Project;
def unit = prj.CompileUnits[fileIndex] : Decl;
- unit.Relocate(oldEndLine, oldEndChar, newEndLine - oldEndLine, newEndChar - oldEndChar);
+ unit.Relocate(fileIndex, oldEndLine, oldEndChar, newEndLine - oldEndLine, newEndChar - oldEndChar);
}
} // end class Engine
} // end namespace
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Relocation.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Relocation.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Relocation.n Fri Sep 22 03:37:40 2006
@@ -5,21 +5,23 @@
{
module Relocation
{
- public Relocate(this decl : Decl, line : int, ch : int, lineOffset : int, chOffset : int) : void
+ public Relocate(this decl : Decl, fileIndex : int, line : int, ch : int, lineOffset : int, chOffset : int) : void
{
def loc = decl.Location;
+ assert(loc.FileIndex == fileIndex);
+
def isLocationChanged = loc.EndLine > line || loc.EndLine == line && loc.EndColumn >= ch;
def relocateChildren(_ : Decl) : void
{
| GlobalAttribute => ()
| Using as x =>
- x.NameLocations = x.NameLocations.Map(Relocate(_, line, ch, lineOffset, chOffset));
- x.AliasLocation = Relocate(x.AliasLocation, line, ch, lineOffset, chOffset);
+ x.NameLocations = x.NameLocations.Map(Completion.Relocate(_, line, ch, lineOffset, chOffset));
+ x.AliasLocation = Completion.Relocate(x.AliasLocation, line, ch, lineOffset, chOffset);
| Namespace as x =>
- x.Decls.Iter(Relocate(_, line, ch, lineOffset, chOffset));
- x.NameLocations = x.NameLocations.Map(Relocate(_, line, ch, lineOffset, chOffset));
- x.BodyLocation = Relocate(x.BodyLocation, line, ch, lineOffset, chOffset);
+ x.Decls.Iter(Relocate(_, fileIndex, line, ch, lineOffset, chOffset));
+ x.NameLocations = x.NameLocations.Map(Completion.Relocate(_, fileIndex, line, ch, lineOffset, chOffset));
+ x.BodyLocation = Completion.Relocate(x.BodyLocation, fileIndex, line, ch, lineOffset, chOffset);
| Type(builder) => builder.Relocate(loc.FileIndex, line, ch, lineOffset, chOffset);
| None => ()
@@ -28,40 +30,8 @@
when (isLocationChanged)
{
relocateChildren(decl);
- decl.Location = Relocate(loc, line, ch, lineOffset, chOffset);
- }
- }
-
- public Relocate(
- this typeBuilder : TypeBuilder,
- fileIndex : int,
- line : int,
- ch : int,
- lineOffset : int,
- chOffset : int
- )
- : void
- {
- _ = typeBuilder;
- _ = fileIndex + line + ch + lineOffset + chOffset;
- }
-
- /// Ńäâčăŕĺň Location íŕ îďđĺäĺëĺííîĺ ęîëč÷ĺńňâî ńňđîę č ńčěâîëîâ.
- public static Relocate(loc : Location, line : int, ch : int, lineOffset : int, chOffset : int) : Location
- {
- def relocatePoint(oldLn, oldCh)
- {
- if (oldLn > line) (oldLn + lineOffset, oldCh)
- else if (oldLn == line && oldCh >= ch)
- if (lineOffset == 0) (oldLn, oldCh + chOffset)
- else (oldLn + lineOffset, chOffset)
- else (oldLn, oldCh)
- }
-
- def (newLn, newCh) = relocatePoint(loc.Line, loc.Column);
- def (newEndLn, newEndCh) = relocatePoint(loc.EndLine, loc.EndColumn);
-
- Location(loc.FileIndex, newLn, newCh, newEndLn, newEndCh);
+ decl.Location = Completion.Relocate(loc, fileIndex, line, ch, lineOffset, chOffset);
}
}
-}
+ } // module Relocation
+} // namespace Nemerle.Completion2
More information about the svn
mailing list