[svn]
r7410: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2:
CodeModel/ExprWalkInfo.n CodeMode...
phantom
svnadmin at nemerle.org
Tue Feb 13 08:39:37 CET 2007
Log:
Find Usages (local values) fix.
Author: phantom
Date: Tue Feb 13 08:39:35 2007
New Revision: 7410
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/SmallTestsOne.n
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n Tue Feb 13 08:39:35 2007
@@ -3,6 +3,8 @@
using Nemerle.Compiler.Parsetree;
using Nemerle.Compiler.Typedtree;
+using System.Diagnostics;
+
namespace Nemerle.Completion2
{
public delegate ExprWalkHandler(info : ExprWalkInfo) : void;
@@ -72,7 +74,20 @@
public Walk(node : TExpr) : void { Walk(w => w.Walk(node, Handler)) }
public Walk(node : Pattern) : void { Walk(w => w.Walk(node, Handler)) }
- public Stop() : void { IsStopped = true }
- public Skip() : void { Node = null }
+ public Stop() : void
+ {
+ IsStopped = true;
+#if PRINT_AST && DEBUG
+ Debug.WriteLine("Stopped!");
+#endif
+ }
+
+ public Skip() : void
+ {
+ Node = null;
+#if PRINT_AST && DEBUG
+ Debug.WriteLine("Skipped!");
+#endif
+ }
}
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n Tue Feb 13 08:39:35 2007
@@ -412,7 +412,10 @@
when (susp.IsResolved)
Go(susp.ResolutionResult);
+ | Cache(cacheDescription, e) => Go(cacheDescription.TExpr); Go(e);
+
| _ => ()
+
/*
| ImplicitValueTypeCtor
| StaticEventRef // { from : MType.Class; ev : IEvent; }
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 Tue Feb 13 08:39:35 2007
@@ -137,8 +137,6 @@
def findInMethod(localValueDeclaration)
{
def member = inType.Builder.GetMemberByLocation(fileIndex, line, column);
- Debug.WriteLine($"searching for $localValueDeclaration");
- Debug.WriteLine($"enclosing member:\n $member");
match (member)
{
| method is MethodBuilder when method.IsBodyCompilable =>
@@ -174,8 +172,8 @@
{
| method is MethodBuilder when method.IsBodyCompilable =>
debug(method);
- //VladD2: 137 символов это уже перебор. Переноси, плиз длинные строки.
- def (_, _, usageTypedExpression) = ExprFinder().Find(method.BodyParsed, method.BodyTyped, usage.Line, usage.Column);
+ 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)
{
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n Tue Feb 13 08:39:35 2007
@@ -23,12 +23,15 @@
public class Analyser
{
mutable localValue : LocalValue;
+ mutable definitionBlock : TExpr.DefValIn;
mutable localValueEntries : list[GotoInfo];
mutable definitionFound : bool;
public FindLocalValueEntries(expressionRoot : TExpr, localValue : LocalValue) : list[GotoInfo]
{
+ Debug.WriteLine($"Searching for $localValue");
this.localValue = localValue;
+ definitionBlock = null;
localValueEntries = [];
definitionFound = false;
ExprWalker().Walk(expressionRoot, FindLocalValueEntriesNodeVisitor);
@@ -50,59 +53,61 @@
enclosingLocations.Reverse()
}
- // TODO: think about (dis)advantages of switching to a parsed tree walking
+ /// Returns whether the first location is (not strictly)
+ /// after the second (the left of first is to the right of second)
+ public static StartsAfterEndOf(this first: Location, second: Location) : bool
+ {
+ if (first.Line > second.EndLine)
+ true
+ else if (first.Line < second.EndLine)
+ false
+ else if (first.Column > second.EndColumn)
+ true
+ else if (first.Column < second.EndColumn)
+ false
+ else
+ true
+ }
+
FindLocalValueEntriesNodeVisitor(exprWalkInfo: ExprWalkInfo) : void
{
def node = exprWalkInfo.Node;
log(phantom, $"processing node: $(node.ToString().Brief())");
+ log(phantom, $" type: $(node.GetType())");
when (node is TExpr)
{
def node = node :> TExpr;
- log(phantom, $"(location: $(node.Location)");
- when (localValue.Location.StartsBefore(node.Location))
+ if (definitionBlock != null)
{
- //Debug.WriteLine("located after definition or is definition");
- log(phantom, $" type of node: $(node.GetType())");
- def processLocalValueEntry(entry, definition = false)
- {
- log(phantom, $" contains $entry");
- when (entry.Name == localValue.Name)
- {
- log(phantom, $" has the same name: $(entry.Name)");
- // TODO: check the if it is really in the same scope
- // TODO: walk around LocalValue.Location incorrect value
- if (definition)
- {
- if (definitionFound)
- exprWalkInfo.Stop();
- else
- {
- definitionFound = true;
-
- def loc = match (node)
+ // TODO: enable this after locations of DefValIn will be fixed
+ //if (node.Location.StartsAfterEndOf(definitionBlock.Location))
+ //exprWalkInfo.Stop();
+ //else
+ match (node)
{
- | DefValIn(name, _, _) => name.NameLocation;
- | _ => node.Location;
- }
-
- log(phantom, $" it's a definition! (location: $(loc))");
- localValueEntries ::= GotoInfo(loc, UsageType.Definition);
- }
- }
- else
+ | LocalRef(referencedLocalValue) =>
+ when (referencedLocalValue.Equals(localValue))
{
- log(phantom, $" it's a reference! (location: $(entry.Location))");
+ log(phantom, $" it's a reference!");
localValueEntries ::= GotoInfo(node.Location, UsageType.Usage);
}
+ | _ => log(phantom, $" skipping...");
}
}
- match (node)
+ else if (node is TExpr.DefValIn)
{
- | DefValIn(entry, _, _) => processLocalValueEntry(entry, true);
- | LocalRef(entry) => processLocalValueEntry(entry);
- | _ => ();
+ def node = node :> TExpr.DefValIn;
+ if (node.name.Equals(localValue))
+ {
+ log(phantom, $" it's a definition! restricting to the location $(node.Location)");
+ definitionBlock = node;
+ localValueEntries ::= GotoInfo(node.name.Location, UsageType.Definition);
}
+ else
+ log(phantom, $" this definition is not of our local value, skipping...");
}
+ else
+ log(phantom, $" the definition hasn't been reached, skipping...");
}
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/SmallTestsOne.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/SmallTestsOne.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Refactoring/TestProjectTwo/SmallTestsOne.n Tue Feb 13 08:39:35 2007
@@ -12,8 +12,8 @@
{
mutable foo = 1; // definition {30} foo
def bar = 2; // definition {31} bar
- foo += bar;
- WriteLine(bar);
+ foo += bar; // usage {30} // usage {31}
+ WriteLine(bar); // usage {31}
}
}
}
\ No newline at end of file
More information about the svn
mailing list