[svn] r7046: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
Nemerle.Co...
phantom
svnadmin at nemerle.org
Mon Dec 4 20:20:30 CET 2006
Log:
Some improvements to Find Usages.
Author: phantom
Date: Mon Dec 4 20:20:28 2006
New Revision: 7046
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/GotoInfo.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/Christianity.n
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprFinder.n Mon Dec 4 20:20:28 2006
@@ -77,21 +77,31 @@
ProcessNodeInFindLocalValueEntries(exprWalkInfo: ExprWalkInfo) : void
{
def node = exprWalkInfo.Node;
+ #if phantom
Debug.WriteLine($"processing node: $(node.ToString().Brief())");
+ #endif
when (node is TExpr)
{
def node = node :> TExpr;
+ #if phantom
Debug.WriteLine($"(location: $(node.Location)");
+ #endif
when (localValue.Location.NotStrictlyBefore(node.Location))
{
//Debug.WriteLine("located after definition or is definition");
+ #if phantom
Debug.WriteLine($" type of node: $(node.GetType())");
+ #endif
def processLocalValueEntry(entry, definition = false)
{
+ #if phantom
Debug.WriteLine($" contains $entry");
+ #endif
when (entry.Name == localValue.Name)
{
+ #if phantom
Debug.WriteLine($" has the same name: $(entry.Name)");
+ #endif
// TODO: check the if it is really in the same scope
// TODO: walk around LocalValue.Location incorrect value
if (definition)
@@ -326,7 +336,7 @@
(Location.Default, null, null)
}
- public FindLocalValueEntries(typedExpressionRoot : TExpr, localValue: LocalValue) : list[GotoInfo]
+ public FindLocalValueEntries(typedExpressionRoot : TExpr, localValue : LocalValue) : list[GotoInfo]
{
this.localValue = localValue;
localValueEntries = [];
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/GotoInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/GotoInfo.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/GotoInfo.n Mon Dec 4 20:20:28 2006
@@ -20,7 +20,7 @@
public class GotoInfo
{
- [Nemerle.DesignPatterns.ProxyPublicMembers(Include = [Line, Column, EndLine, EndColumn])]
+ [Nemerle.DesignPatterns.ProxyPublicMembers(Include = [FileIndex, Line, Column, EndLine, EndColumn])]
[Accessor] _location : Location;
[Accessor] _member : System.Reflection.MemberInfo;
[Accessor] _usageType : UsageType = UsageType.Definition;
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n Mon Dec 4 20:20:28 2006
@@ -174,7 +174,9 @@
}
else if (ast.header.Location.Contains(line, col))
{
- if (ast.header.ret_type.Location.Contains(line, col))
+ if (ast.header.name.Location.Contains(line, col))
+ (ast.header.name.Location, ast, method)
+ else if (ast.header.ret_type.Location.Contains(line, col))
checkType(ast.header.ret_type, method.ReturnType);
else if (ast.modifiers.custom_attrs.OrderedContains(line, col))
{
@@ -372,9 +374,11 @@
// (It may be done by GetAllMetodsDefinedInFile(fileIndex : int) : SCG.List[MethodBuilder])
// If lacations from step 2 intersect with method try find entries
// in it method.
- private FindUsages(ty : Decl.Type, fileIndex : int, line : int, column : int, onlyThisFile : bool = false) : list [GotoInfo]
+ private FindUsages(inType : Decl.Type, fileIndex : int, line : int, column : int, onlyThisFile : bool = false) : list [GotoInfo]
{
- def (_, _, declarationObject) = FindObject(ty, fileIndex, line, column);
+ def (declarationLocation, _, declarationObject) = FindObject(inType, fileIndex, line, column);
+ // TODO: test project 2, test case 3: incorrect location found if starting from line 98 - see why ExprFinder returns incorrect location
+ Debug.WriteLine($"Found declaration: $declarationLocation");
// TODO: for rename refactoring, we should know all usages, including generated
// however, this implementation neglects generated usages
@@ -404,42 +408,90 @@
}
findEntry(0);
}
-
entries.Reverse()
}
+ def debug(method)
+ {
+ ignore(method);
+ #if phantom
+ Debug.WriteLine("parsed tree:");
+ when (method.BodyLocation.FileIndex > 0)
+ Debug.WriteLine(PrettyPrint.SprintExpr(None(), method.BodyParsed));
+ Debug.WriteLine("typed tree:");
+ Debug.WriteLine(PrettyPrint.SprintTyExpr(method.BodyTyped));
+ #endif
+ }
+
def findInMethod(localValueDeclaration)
{
- def member = ty.Builder.GetActiveMember(fileIndex, line, column);
+ def member = inType.Builder.GetActiveMember(fileIndex, line, column);
Debug.WriteLine($"searching for $localValueDeclaration");
Debug.WriteLine($"enclosing member:\n $member");
match (member)
{
| method is MethodBuilder =>
- Debug.WriteLine("parsed tree:");
- when (method.BodyLocation.FileIndex > 0)
- Debug.WriteLine(PrettyPrint.SprintExpr(None(), method.BodyParsed));
- Debug.WriteLine("typed tree:");
- Debug.WriteLine(PrettyPrint.SprintTyExpr(method.BodyTyped));
+ debug(method);
ExprFinder().FindLocalValueEntries(method.BodyTyped, localValueDeclaration);
| _ => []
}
}
- def isReal(_member, _usage)
+ def makeUsage(location, declarationLocation)
{
+ if (location == declarationLocation)
+ GotoInfo(location, UsageType.Definition)
+ else
+ GotoInfo(location, UsageType.Usage)
+ }
+ def usageIsReal(mustBeMember : IMember, usage)
+ {
+ if (usage.UsageType == UsageType.Definition)
true
+ else
+ {
+ Debug.WriteLine($"checking usage $usage for consistency");
+ Debug.WriteLine($"must be member:\n $mustBeMember");
+ // phantom: strange, why it doesn't catch exeption on christianity.n, any interface member?
+ try
+ {
+ match (GetActiveDecl(usage.FileIndex, usage.Line, usage.Column))
+ {
+ | type' is Decl.Type =>
+ match (type'.Builder.GetActiveMember(usage.FileIndex, usage.Line, usage.Column))
+ {
+ | method is MethodBuilder =>
+ debug(method);
+ def (_, _, usageTypedExpression) = ExprFinder().Find(method.BodyParsed, method.BodyTyped, usage.Line, usage.Column);
+ Debug.WriteLine($"Expression Finder found such an expression of a usage: $usageTypedExpression");
+ match (usageTypedExpression)
+ {
+ | member is IMember => mustBeMember.GetFullName() == member.GetFullName()
+ | _ => Debug.WriteLine("Not known IMember type! Perhaps, should be added to isReal function"); false
+ }
+ | _ => false
+ }
+ | _ => false
+ }
+ }
+ catch
+ {
+ | _ => false // somewhere tree is not consistent
+ }
+ }
}
- def usages = match (declarationObject)
+ match (declarationObject)
{
| localValue is LocalValue => findInMethod(localValue)
- | member is IMember =>
- $[GotoInfo(usage) | usage in findPossibleUsages(member.Name, onlyThisFile), isReal(member, usage)]
+ | member is MemberBuilder =>
+ def declarationLocation = member.Ast.name.Location;
+ findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage(_, declarationLocation)).Filter(usageIsReal(member, _))
+ //| member is IMember =>
+ //findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage).Filter(usageIsReal(member, _));
| _ => [] //TODO: May be it wrong!
}
- usages
}
GetMethodTip(
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n Mon Dec 4 20:20:28 2006
@@ -156,13 +156,20 @@
def comparator(gotoOne, gotoTwo)
{
- def comparedLocations = gotoOne.Location.CompareLines(gotoTwo.Location);
+ def comparedLocations = gotoOne.Location.CompareTo(gotoTwo.Location);
if (comparedLocations != 0)
comparedLocations
else if (gotoOne.UsageType == gotoTwo.UsageType)
0
else
- gotoOne.Location.CompareTo(gotoTwo.Location)
+ 1
+ //def comparedLocations = gotoOne.Location.CompareLines(gotoTwo.Location);
+ //if (comparedLocations != 0)
+ //comparedLocations
+ //else if (gotoOne.UsageType == gotoTwo.UsageType)
+ //0
+ //else
+ //gotoOne.Location.CompareTo(gotoTwo.Location)
};
def notFound = one.Filter(one' => !two.Exists(two' => comparator(one', two') == 0));
@@ -248,7 +255,7 @@
public stopAfterFirstFailedTest = false;
- skipTestCases : list[int] = [7]; // neglect some tests for a while
+ skipTestCases : list[int] = [];//[7]; // neglect some tests for a while
public FindUsages(line: string, testCase : int, declaration : Location, starter : string) : bool
{
@@ -292,7 +299,7 @@
ring
});
Write($"found $(found.Length) usages, checking for correspondance... ");
- def success = FoundUsagesAreRight(testCase, shouldFindRing, found);
+ def success = FoundUsagesAreRight(testCase, shouldFindRing, found); // put breakpoint here to see what usages are actually found
def message = if (success) "ok" else "incorrect!.. saving changes...";
WriteLine(message);
unless (success)
@@ -332,9 +339,9 @@
| _ => reference
}) + [
@"$(Nemerle)\Nemerle.Macros.dll",
- @"$(Nemerle)\Nemerle.Compiler.dll"
];
- def references = references.Map(_.Replace("$(Nemerle)", @"C:\Program Files\Nemerle"));
+ def references = references.Map(_.Replace("$(Nemerle)", @"C:\Program Files\Nemerle")).RemoveDuplicates();
+ //def references = references.Filter(reference => !reference.Contains("Nemerle"));
WriteLine($"$(references.Length) reference files found");
def runner = TestRunner();
@@ -349,7 +356,7 @@
{
def suite = FindUsagesTestProjectTwo();
suite.SetUp();
- suite.Test001();
+ suite.Test007();
}
public static Main() : void
@@ -404,7 +411,9 @@
def manager = ProjectManager();
engine = Engine(manager, null);
manager.Engine = engine;
+ WriteLine($"Compiler is in completion mode: $(engine.IsInCompletionMode)");
+ WriteLine(references);
references.Iter(assembly =>
if (assembly.StartsWith(@"C:\")) // HACK: if wanna more general pathes, rewrite the code spot
engine.References.Add(assembly, Assembly.LoadFile(assembly))
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/Christianity.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/Christianity.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/Christianity.n Mon Dec 4 20:20:28 2006
@@ -17,59 +17,59 @@
public class God : Spirit, IHuman
{
- public static Instance : God = God();
+ public static Instance : God = God(); // definition {4} Instance
- public mutable FirstHumanBeing : Human;
+ public mutable FirstHumanBeing : Human; // definition {5} FirstHumanBeing
- public CreateHumanBeing() : IHuman
+ public CreateHumanBeing() : IHuman // definition {3} CreateHumanBeing
{
- Instance.FirstHumanBeing = Human(this);
- Instance.FirstHumanBeing
+ Instance.FirstHumanBeing = Human(this); // usage {4} // usage {5}
+ Instance.FirstHumanBeing // usage {4} // usage {5}
}
- public Listen(message : string) : void
+ public Listen(message : string) : void // definition {6} Listen
{
WriteLine($"I am God, receiving message: $message");
}
- public RobeFirstHumanInFlesh() : void
+ public RobeFirstHumanInFlesh() : void // definition {7} RobeFirstHumanInFlesh //possibly not found definition {7}
{
- RemoveFirstHumanFrom(Instance);
+ RemoveFirstHumanFrom(Instance); // usage {4}
}
- RemoveFirstHumanFrom(creator : God) : void
+ RemoveFirstHumanFrom(creator : God) : void // definition {8} RemoveFirstHumanFrom
{
- creator.FirstHumanBeing = null;
+ creator.FirstHumanBeing = null; // usage {5}
}
- public CheckContact() : string
+ public CheckContact() : string // definition {9} CheckContact
{
- def status = if (FirstHumanBeing != null) "ok" else "lost :(";
+ def status = if (FirstHumanBeing != null) "ok" else "lost :("; // usage {5}
$"Contact with first human being is $status"
}
[Nemerle.NotImplemented]
- public virtual SpeakWithCreator(_ : string) : void {}
+ public virtual SpeakWithCreator(_ : string) : void {} // definition {10} SpeakWithCreator
[Nemerle.NotImplemented]
- public virtual Fall() : void {}
+ public virtual Fall() : void {} // definition {11} Fall
[Nemerle.NotImplemented]
- public virtual Cry() : void {}
+ public virtual Cry() : void {} // definition {12} Cry
}
public class Human : God
{
- public mutable imageOfGod : God;
+ public mutable imageOfGod : God; // definition {13} imageOfGod
public this(imageAndLikeness : God)
{
imageOfGod = imageAndLikeness;
}
- public override SpeakWithCreator(message : string) : void
+ public override SpeakWithCreator(message : string) : void // definition {14} SpeakWithCreator
{
- imageOfGod.Listen(message);
+ imageOfGod.Listen(message); // usage {6}
}
public override Fall() : void
@@ -95,7 +95,7 @@
{
public VeryLongAgo() : void
{
- def firstHuman = God.Instance.CreateHumanBeing(); // definition {1} firstHuman
+ def firstHuman = God.Instance.CreateHumanBeing(); // definition {1} firstHuman // usage {3} // usage {4}
WriteLine($"First human is alive: $(firstHuman != null)"); // usage {1}
WriteLine($"First human being is spirit: $(firstHuman is Spirit)"); // usage {1}
firstHuman.SpeakWithCreator("Hello, God..."); // usage {1}
@@ -103,7 +103,7 @@
{
reasons()
}
- def someReasons = (ChristianVision.TheFallOf(firstHuman), God.Instance.RobeFirstHumanInFlesh); // usage {1} // definition {2} someReasons
+ def someReasons = (ChristianVision.TheFallOf(firstHuman), God.Instance.RobeFirstHumanInFlesh); // usage {1} // definition {2} someReasons // usage {4} // usage {7} //possibly not found usage {7}
actualize(someReasons[0]); // usage {2}
actualize(someReasons[1]); // usage {2}
try
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs Mon Dec 4 20:20:28 2006
@@ -87,7 +87,7 @@
public void SetSource(string source, int offset)
{
- System.Diagnostics.Debug.WriteLine(string.Format("Scan line {0}", _currentLine));
+ //System.Diagnostics.Debug.WriteLine(string.Format("Scan line {0}", _currentLine));
ScanLexer lexer = GetLexer();
More information about the svn
mailing list