[svn]
r6732: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2:
CodeModel/Project.n CompiledUnitA...
VladD2
svnadmin at nemerle.org
Thu Sep 28 02:56:41 CEST 2006
Log:
Work on relocation.
Author: VladD2
Date: Thu Sep 28 02:56:38 2006
New Revision: 6732
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CompiledUnitAstBrowser.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n Thu Sep 28 02:56:38 2006
@@ -179,9 +179,12 @@
def _start = Environment.TickCount;
- foreach (member in builder.GetMembers())
+ foreach (member in builder.GetDirectMembers())
{
- | method is MethodBuilder =>
+ // TypeBuilder can contains methods from many parts of pertiol
+ // class and super classes. We must process only memebers defined
+ // in processed file only!
+ | method is MethodBuilder when method.Location.FileIndex == fileIndex =>
#if !DEBUG
when (_start > Environment.TickCount - 2000)
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 Thu Sep 28 02:56:38 2006
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Windows.Forms;
+//using Nemerle.Collections; //Fixme: BUG!!!
using Nemerle.Compiler;
using Nemerle.Compiler.Utils;
@@ -15,30 +16,70 @@
name : string;
ty : Type;
loc : option[Location];
- subNodes : list[PropInfo]
+ subNodes : list[PropInfo];
+
+ public override ToString() : string
+ {
+ match (loc)
+ {
+ | Some(loc) => $"($loc) $ty: $name"
+ | None => $"$ty: $name"
+ }
+ }
}
- | LocationNode { name : string; loc : Location; }
+ | LocationNode
+ {
+ name : string;
+ loc : Location;
+
+ public override ToString() : string { $"($loc) $name" }
+ }
| None
}
public class CompiledUnitAstBrowser : Form
{
- static locTy : Type = typeof(Location);
- static iterTy : Type = typeof(System.Collections.IEnumerable);
- ScanVariable(name : string, obj : object) : PropInfo
+ ScanVariable(name : string, obj : object, fileIndex : int) : PropInfo
+ {
+ def tyBldTy : Type = typeof(TypeBuilder);
+ def locTy : Type = typeof(Location);
+ def locatedTy : Type = typeof(Located);
+ def iterTy : Type = typeof(System.Collections.IEnumerable);
+ def processed = Nemerle.Collections.Hashtable();
+ def compilerAssembly = typeof(Location).Assembly;
+
+ def getLoc(obj, ty)
+ {
+ if (obj != null && locatedTy.IsAssignableFrom(ty))
+ Some((obj :> Located).Location)
+ else
+ None()
+ }
+
+ def scan(name : string, obj : object) : PropInfo
{
def ty = obj.GetType();
+
+ if (!ty.Assembly.Equals(compilerAssembly) || ty.Equals(tyBldTy) || processed.ContainsKey(obj))
+ PropInfo.None()
+ else
+ {
+ processed.Add(obj, name);
//def locatedTy = typeof(Located);
if (ty.Equals(locTy))
+ if ((obj :> Location).FileIndex == fileIndex)
PropInfo.LocationNode(name, obj :> Location);
else
+ PropInfo.None()
+ else
{
mutable infos = [] : list[PropInfo];
- foreach (field in ty.GetFields())
+ def fields = ty.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ foreach (field in fields)
{
def value = field.GetValue(obj);
@@ -46,37 +87,82 @@
{
def valTy = value.GetType();
- if (valTy.IsSubclassOf(iterTy))
+ when (field.Name == "parms")
+ {
+ assert(true);
+ }
+
+ if (iterTy.IsAssignableFrom(valTy))
{
mutable infos2 = [];
+
foreach (elem in value :> System.Collections.IEnumerable)
{
- def res1 = ScanVariable("elem:", elem);
+ def res1 = scan("elem:", elem);
unless (res1 is PropInfo.None)
infos2 ::= res1;
-
- infos ::= PropInfo.SimpleNode(name, ty, None(), infos2);
}
+
+ unless (infos2 is [])
+ infos ::= PropInfo.SimpleNode(field.Name, valTy, getLoc(value, valTy), infos2);
}
else
{
- def res2 = ScanVariable(field.Name, value);
+ def res2 = scan(field.Name, value);
unless (res2 is PropInfo.None)
infos ::= res2;
}
}
}
- PropInfo.SimpleNode(name, ty, None(), infos)
+ if (infos is [])
+ PropInfo.None()
+ else
+ PropInfo.SimpleNode(name, ty, getLoc(obj, ty), infos)
+ }
}
}
+ scan(name, obj);
+ }
+
FillTree(root : Decl) : void
{
def fileIndex = root.Location.FileIndex;
mutable currNode = null;
+ def locToStr1(x) { $"($(x.Line),$(x.Column); $(x.EndLine),$(x.EndColumn))" }
+ def locToStr2(loc)
+ {
+ | Some(x) => locToStr1(x)
+ | _ => ""
+ }
+
+ def addNodeFromInfo(nodes, info)
+ {
+ match (info : PropInfo)
+ {
+ | SimpleNode(name, ty, loc, subInfos) =>
+ def subNode = nodes.Add($"$(locToStr2(loc)) $name ($(ty.Name))");
+ match (loc)
+ {
+ | Some(loc) => subNode.Tag = loc;
+ | _ => ()
+ }
+
+ foreach (subInfo in subInfos)
+ addNodeFromInfo(subNode.Nodes, subInfo);
+
+ | LocationNode(name, loc) =>
+ def subNode = nodes.Add($"$(locToStr1(loc)) $name");
+ subNode.Tag = loc;
+
+ | None => ()
+ }
+ }
+
+
def addLocation(nodes, kind, name, location)
{
when (!name.IsNullOrEmpty())
@@ -129,37 +215,21 @@
def addType(nodes, builder)
{
+ def typePrefix = builder.FullName + ".";
addLocation(nodes, "Location", " ", builder.Location);
addLacations(nodes, "PartsLocation", builder.PartsLocation);
def comparer(x, y)
{
- def (x, y) = (x.BodyLocation, y.BodyLocation);
+ def (x, y) = (x.Location, y.Location);
if (x.Line == y.Line) x.Column - y.Column else if (x.Line > y.Line) 1 else 0
}
// Filter member whith this fileIndex, convert list to list[MemberBuilder] and sort the result list.
- def fileMembers = builder.GetDirectMembers().Map(m => m :> MemberBuilder).Filter(fun(m)
- { m.BodyLocation.FileIndex == fileIndex }).Sort(comparer);
+ def fileMembers = builder.GetDirectMembers().Filter(fun(m)
+ { m.Location.FileIndex == fileIndex }).Sort(comparer);
foreach (member in fileMembers)
- {
- def info = ScanVariable($"$member", member);
- _ = info;
- addLocation(nodes, member.ToString(), " ", member.Location);
- def nodes2 = currNode.Nodes;
- addLocation(nodes2, "BodyLocation", " ", member.BodyLocation);
- match (member)
- {
- | method is MethodBuilder =>
- def header = method.GetHeader();
- addLocation(nodes2, "header", " ", header.Location);
- def headerNodes = currNode.Nodes;
- foreach (parm in header.parms)
- addLocation(headerNodes, "parm", parm.ToString(), parm.loc);
-
- | _ => ()
- }
- }
+ addNodeFromInfo(nodes, ScanVariable($"$member".Replace(typePrefix, ""), member, fileIndex));
}
def add(nodes, astNode)
@@ -174,9 +244,10 @@
addLocation(newNode.Nodes, "Alias", x.Alias, x.AliasLocation);
| Namespace as x =>
+ def decls = x.Decls;
addName(newNode.Nodes, x.Name, x.NameLocations);
addLocation(newNode.Nodes, "BodyLocation", "{}", x.BodyLocation);
- foreach (decl in x.Decls)
+ foreach (decl in decls)
add(newNode.Nodes, decl)
| Type(builder) => addType(newNode.Nodes, builder);
More information about the svn
mailing list