[svn] r7482: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2: CodeModel/Project.Refactoring.n C...

phantom svnadmin at nemerle.org
Sat Feb 24 23:34:39 CET 2007


Log:
Find Usages for function parameters.

Author: phantom
Date: Sat Feb 24 23:34:37 2007
New Revision: 7482

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Static.Analysis.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n

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	Sat Feb 24 23:34:37 2007
@@ -180,14 +180,27 @@
           #endif
       }
       
-      def findInMethod(localValueDeclaration)
+      def findLocalValueReferences(localValue)
       {
         def member = inType.Builder.GetMemberByLocation(fileIndex, line, column);
         match (member)
         {
           | method is MethodBuilder when method.IsBodyCompilable =>
             debug(method);
-            Analyser().FindLocalValueEntries(method.BodyTyped, localValueDeclaration);
+            Analyser().FindLocalValueEntries(method.BodyTyped, localValue);
+          | _ => []
+        }
+      }
+
+      // TODO: remove code duplication
+      def findFunctionParameterReferences(functionParameter)
+      {
+        def member = inType.Builder.GetMemberByLocation(fileIndex, line, column);
+        match (member)
+        {
+          | method is MethodBuilder when method.IsBodyCompilable =>
+            debug(method);
+            Analyser().FindFunctionParameterEntries(method.BodyTyped, functionParameter);
           | _ => []
         }
       }
@@ -241,7 +254,9 @@
 
       match (declarationObject)
       {
-        | localValue is LocalValue => findInMethod(localValue)
+        | localValue is LocalValue => findLocalValueReferences(localValue)
+        | functionParameter is Nemerle.Compiler.Typedtree.Fun_parm =>
+          GotoInfo(declarationLocation) :: findFunctionParameterReferences(functionParameter)
         | member is MemberBuilder =>
           def declarationLocation = member.Ast.name.Location;
           findPossibleUsages(member.Name, onlyThisFile).Map(makeUsage(_, declarationLocation)).Filter(usageIsReal(member, _))

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	Sat Feb 24 23:34:37 2007
@@ -137,7 +137,7 @@
         if (method.BodyLocation.Contains(line, col))
         {
           def found = ExprFinder().Find(method.BodyParsed, method.BodyTyped, line, col);
-          def (location, parsedObject, typedObject) = found;
+          def (_, _, typedObject) = found;
 
           def getParameter(name, parsedParameters, typedParameters)
           {

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	Sat Feb 24 23:34:37 2007
@@ -23,22 +23,31 @@
   public class Analyser
   {
     mutable localValue : LocalValue;
-    mutable localValueEntries : list[GotoInfo];
-    mutable definitionBlock : TExpr.DefValIn;
+    mutable functionParameter : T.Fun_parm;
+    mutable foundEntries : 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);
-      // phantom: test case 3 (test project 1) returns duplicate entries (foo += _ => foo = foo + _)
-      def entries = localValueEntries.Reverse().RemoveDuplicates();
+      CoreFind(expressionRoot, FindLocalValueEntriesNodeVisitor)
+    }
+    
+    public FindFunctionParameterEntries(expressionRoot : TExpr, functionParameter : T.Fun_parm) : list[GotoInfo]
+    {
+      Debug.WriteLine($"Searching for $functionParameter");
+      this.functionParameter = functionParameter;
+      CoreFind(expressionRoot, FindFunctionParameterEntriesNodeVisitor)
+    }
+    
+    public CoreFind(expressionRoot : TExpr, finder : ExprWalkInfo -> void) : list[GotoInfo]
+    {
+      foundEntries = [];
+      ExprWalker().Walk(expressionRoot, finder);
+      def entries = foundEntries.Reverse().RemoveDuplicates();
       Debug.WriteLine($"Found $(entries.Length) entries:");
-      // why it doesn't guess about type?
       entries.Iter(location : GotoInfo => Debug.WriteLine(location));
       entries
     }
@@ -81,7 +90,7 @@
         {
           | TExpr.LocalRef(referenced) as pointer when (referenced.Equals(localValue)) =>
             log(phantom, "  it's a reference!");
-            localValueEntries ::= GotoInfo(pointer.Location, UsageType.Usage);
+            foundEntries ::= GotoInfo(pointer.Location, UsageType.Usage);
           | _ => log(phantom, "  skipping...");
         }
       else
@@ -91,9 +100,22 @@
           | Pattern.As(_, definition) when (definition.Equals(localValue)) =>
             log(phantom, "  it's a definition!");
             definitionFound = true;
-            //definitionBlock = node;
-            localValueEntries ::= GotoInfo(definition.Location, UsageType.Definition);
-          //| Match_case as node => definitionBlock = node.body;
+            foundEntries ::= GotoInfo(definition.Location, UsageType.Definition);
+          | _ => log(phantom, "  skipping...");
+        }
+    }
+    
+    FindFunctionParameterEntriesNodeVisitor(exprWalkInfo: ExprWalkInfo) : void
+    {
+      def node = exprWalkInfo.Node;
+      log(phantom, $"processing node: $(node.ToString().Brief())");
+      log(phantom, $" type: $(node.GetType())");
+      match (node)
+      {
+        | TExpr.LocalRef(referenced) as pointer when (referenced.ValKind is LocalValue.Kind.FunParm
+          && referenced.Name == functionParameter.Name) =>
+          log(phantom, "  it's a reference!");
+          foundEntries ::= GotoInfo(pointer.Location, UsageType.Usage);
           | _ => log(phantom, "  skipping...");
         }
     }

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	Sat Feb 24 23:34:37 2007
@@ -29,8 +29,8 @@
     
     public static RunTheTest() : void
     {
-      def suite = FindDefinitionTestProjectTwo();
-      //def suite = FindUsagesTestProjectTwo();
+      //def suite = FindDefinitionTestProjectTwo();
+      def suite = FindUsagesTestProjectTwo();
       suite.SetUp();
       suite.Test043();
     }



More information about the svn mailing list