[svn] r6740: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj Nemerle.Compiler.Utils/...

IT svnadmin at nemerle.org
Mon Oct 2 05:37:07 CEST 2006


Log:
Local function's regions.

Author: IT
Date: Mon Oct  2 05:36:58 2006
New Revision: 6740

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/WalkAction.n
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
   vs-plugin/trunk/Nemerle.VSIP.sln
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	Mon Oct  2 05:36:58 2006
@@ -122,6 +122,12 @@
   <ItemGroup>
     <Compile Include="Nemerle.Completion2\ISourceTextManager.n" />
   </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Nemerle.Completion2\CodeModel\ExprWalker.n" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Nemerle.Completion2\CodeModel\WalkAction.n" />
+  </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n	Mon Oct  2 05:36:58 2006
@@ -0,0 +1,213 @@
+using System;
+
+using Nemerle.Assertions;
+using Nemerle.Compiler;
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Imperative;
+
+namespace Nemerle.Completion2
+{
+  delegate PExprWalkHandler(expression : PExpr) : WalkAction;
+
+  class ExprWalker
+  {
+    mutable _walkHandler : PExprWalkHandler;
+    mutable _stop        : bool;
+
+    private Go(lst : list[PExpr])         : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[ClassMember])   : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[Splicable])     : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[SyntaxElement]) : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[Function_decl]) : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[MatchCase])     : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[TryCase])       : void { foreach (item in lst) Go(item); }
+    private Go(lst : list[Fun_parm])      : void { foreach (item in lst) Go(item); }
+
+    private Go(splicable : Splicable) : void
+    {
+    | Expression(e) => Go(e); // { expr : PExpr; }
+    | Name                    // { body : Parsetree.Name; }
+    | HalfId        => ();    // { prefix : Parsetree.Name; }
+    }
+
+    private Go(parms : Typarms) : void
+    {
+      Go(parms.tyvars);
+
+      foreach (c in parms.constraints)
+      {
+        Go(c.tyvar);
+        Go(c.ty);
+      }
+    }
+
+    private Go(header : Fun_header) : void
+    {
+      Go(header.typarms);
+      Go(header.name);
+      Go(header.ret_type);
+      Go(header.parms);
+    }
+
+    private Go(fun_decl : Function_decl) : void
+    {
+      Go(fun_decl.header);
+      Go(fun_decl.body);
+    }
+
+    private Go(parm : Fun_parm) : void
+    {
+      Go(parm.ty);
+      Go(parm.name);
+    }
+
+    private Go(body : FunBody) : void
+    {
+    | Parsed(e) => Go(e); // { expr : Parsetree.PExpr; }
+    | Typed               // { expr : Typedtree.TExpr; }
+    | ILed
+    | Abstract  => ();
+    }
+
+    private Go(tryCase : TryCase) : void
+    {
+    | Catch(sp, e1, e2)      => Go(sp); Go(e1); Go(e2);         // { exn : Splicable; exn_ty : PExpr; handler : PExpr; }
+    | Filter(sp, e1, e2, e3) => Go(sp); Go(e1); Go(e2); Go(e3); // { exn : Splicable; exn_ty : PExpr; filter : PExpr; handler : PExpr; }
+    | Ellipsis(e)            => Go(e);                          // { body : PExpr; }
+    }
+
+    private Go(matchCase : MatchCase) : void
+    {
+      Go(matchCase.patterns);
+      Go(matchCase.body);
+    }
+
+    private Go(decl : TopDeclaration) : void
+    {
+      match (decl)
+      {
+      | Class    (lst, m)                              // { mutable t_extends : list [PExpr]; decls : list [ClassMember]; }
+      | Interface(lst, m)                              // { mutable t_extends : list [PExpr]; methods : list [ClassMember]; }
+      | Variant  (lst, m)                              // { mutable t_extends : list [PExpr]; mutable decls : list [ClassMember]; }
+      | Enum     (lst, m)    => Go(lst); Go(m);        // { t_extends : list [PExpr]; decls : list[ClassMember]; }
+      | Alias    (ty)        => Go(ty);                // { ty : PExpr; }
+      | VariantOption(decls) => Go(decls);             // { decls : list [ClassMember]; }
+      | Macro    (h, lst, e) => Go(h); Go(lst); Go(e); // { header : Fun_header; synt : list [PExpr]; expr : PExpr; }
+      | Delegate (h)         => Go(h);                 // { header : Fun_header; }
+      }
+
+      Go(decl.name);
+    }
+
+    private Go(member : ClassMember) : void
+    {
+      match (member)
+      {
+      | TypeDeclaration(td)    => Go(td);          // { td : TopDeclaration; }
+      | Field     (e)                              // { mutable ty : PExpr; }
+      | EnumOption(Some(e))    => Go(e);           // { value : option [PExpr]; }
+      | Function  (h, _, body) => Go(h); Go(body); // { header : Fun_header; kind : FunKind; mutable body : FunBody; }
+      | EnumOption             => ()
+      | Property(ty, prop_ty, dims, get, set) =>   // { ty : PExpr; prop_ty : PExpr; dims : list [Fun_parm]; get : option [ClassMember]; set : option [ClassMember]; }
+
+        Go(ty);
+        Go(prop_ty);
+        Go(dims);
+        match (get) { | Some(m) => Go(m) | _ => () }
+        match (set) { | Some(m) => Go(m) | _ => () }
+
+      | Event(ty, field, add, remove)         =>   // { ty : PExpr; field : ClassMember.Field; add : ClassMember.Function; remove : ClassMember.Function; }
+
+        Go(ty);
+        Go(field);
+        Go(add);
+        Go(remove);
+      }
+
+      Go(member.name);
+    }
+
+    private Go(element : SyntaxElement) : void
+    {
+    | Expression      (e)                 // { body : PExpr; }
+    | TType           (e)    => Go(e);    // { body : PExpr; }
+    | MatchCase       (mc)   => Go(mc);   // { body : Parsetree.MatchCase; }
+    | Function        (body) => Go(body); // { body : Function_decl; }
+    | Parameter       (body) => Go(body); // { body : Fun_parm; }
+    | ClassMember     (body) => Go(body); // { body : Parsetree.ClassMember; }
+    | ParameterBuilder                    // { body : Typedtree.Fun_parm; }
+    | RawToken                            // { body : Token; }
+    | TypeBuilder                         // { body : Compiler.TypeBuilder; }
+    | FieldBuilder                        // { body : Compiler.FieldBuilder; }
+    | MethodBuilder                       // { body : Compiler.MethodBuilder; }
+    | PropertyBuilder                     // { body : Compiler.PropertyBuilder; }
+    | EventBuilder           => ();       // { body : Compiler.EventBuilder; }
+    }
+
+    private Go(expression : PExpr) : void
+    {
+      when (_stop || expression == null)
+        return;
+
+      match (_walkHandler(expression))
+      {
+      | Skip     => return;
+      | Stop     => _stop = true; return;
+      | Continue => ();
+      }
+
+      match (expression)
+      {
+      | Wildcard
+      | Ref                                         // { name : Name; }
+      | Literal                                     // { val : Nemerle.Compiler.Literal; }
+      | This
+      | Base
+      | Error
+      | ToComplete                                  // { body : Name; }
+      | Typed                                       // { body : Typedtree.TExpr; }
+      | TypedPattern                                // { body : Typedtree.Pattern; }
+      | TypedType                                   // { body : TyVar; }
+      | Void                     => ()
+      | As              (e, sp)                     // { pat : PExpr; name : Splicable; }
+      | Member          (e, sp)  => Go(e); Go(sp);  // { obj : PExpr; member : Splicable; }
+      | Is              (e1, e2)                    // { pat : PExpr; ty : PExpr; }
+      | Where           (e1, e2)                    // { name : PExpr; fields : PExpr; }
+      | Assign          (e1, e2)                    // { target : PExpr; source : PExpr; }
+      | DefMutable      (e1, e2)                    // { name : PExpr; val : PExpr; }
+      | Define          (e1, e2)                    // { pattern : PExpr; val : PExpr; }
+      | TryFinally      (e1, e2)                    // { body : PExpr; handler : PExpr; }
+      | TypeConversion  (e1, e2)                    // { expr : PExpr; ty : PExpr; }  // (expr :> ty)
+      | TypeEnforcement (e1, e2)                    // { expr : PExpr; ty : PExpr; } // (expr : ty)
+      | Array           (e1, e2) => Go(e1); Go(e2); // { rank : PExpr; args : PExpr; }
+      | Throw           (e)                         // { exn : PExpr; }
+      | Typeof          (e)                         // { ty : PExpr; }
+      | ParmByRef       (e)                         // { parm : PExpr; }
+      | ParmOut         (e)                         // { parm : PExpr; }
+      | Spliced         (e)                         // { body : PExpr; }
+      | Ellipsis        (e)      => Go(e);          // { body : PExpr; }
+      | Match           (e, cs)  => Go(e); Go(cs);  // { expr : PExpr; cases : list [MatchCase]; }
+      | Call            (e, lst)                    // { func : PExpr; parms : list [PExpr]; }
+      | GenericSpecifier(e, lst)                    // { func : PExpr; generic_parms : list [PExpr]; }
+      | Indexer         (e, lst) => Go(e); Go(lst); // { obj : PExpr; args : list [PExpr]; }
+      | ListLiteral     (lst)                       // { elements : list [PExpr]; }
+      | Sequence        (lst)                       // { body : list [PExpr]; }
+      | Tuple           (lst)                       // { args : list [PExpr]; }
+      | EmptyArray      (lst)    => Go(lst);        // { sizes : list [PExpr]; }
+      | DefFunctions    (funs)   => Go(funs);       // { funs : list [Function_decl]; }
+      | Lambda          (decl)   => Go(decl);       // { decl : Function_decl; }
+      | Try             (b, cs)  => Go(b); Go(cs);  // { body : PExpr; cases : list [TryCase]; }
+      | Quoted          (el)     => Go(el);         // { body : SyntaxElement; }
+      | MacroCall  (_, _, parms) => Go(parms);      // { name : Name; ns : NamespaceTree.Node; parms : list [SyntaxElement]; }
+      }
+    }
+
+    public Walk([NotNull] expression : PExpr, [NotNull] walkHandler : PExprWalkHandler) : void
+    {
+      _walkHandler = walkHandler;
+      _stop        = false;
+
+      Go(expression);
+    }
+  }
+}

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 Oct  2 05:36:58 2006
@@ -97,7 +97,7 @@
 
           def (pLoc, pExpr, findLocation) = if (pBody != null)
           {
-            def (pLoc, pObj) = ExprFinder().Find(pBody.expr, line, col);
+            def (pLoc, pObj) = ExprFinder().Find(pBody, line, col);
 
             match (pObj)
             {
@@ -110,7 +110,7 @@
 
           if (tBody != null)
           {
-            def (eLoc, obj) = ExprFinder().Find(tBody.expr, line, col, pLoc, findLocation);
+            def (eLoc, obj) = ExprFinder().Find(tBody, line, col, pLoc, findLocation);
 
             def loc = if (pLoc.Contains(line, col)) pLoc.Intersect(eLoc) else eLoc;
 

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	Mon Oct  2 05:36:58 2006
@@ -2,15 +2,15 @@
 using System.Collections.Generic;
 using System.Diagnostics;
 
-using Nemerle.Assertions;
 using Nemerle.Compiler;
 using Nemerle.Compiler.Parsetree;
-using Nemerle.Utility;
-using Nemerle.Imperative;
 using Nemerle.Compiler.Typedtree;
-
 using Nemerle.Compiler.Utils;
 
+using Nemerle.Assertions;
+using Nemerle.Utility;
+using Nemerle.Imperative;
+
 using SCG = System.Collections.Generic;
 
 namespace Nemerle.Completion2
@@ -189,7 +189,22 @@
             afterUsingLine = line;
         }
 
-		    def processBuilder(builder)
+        def addRegion(loc)
+        {
+          when (!loc.IsEmpty())
+          {
+            addHiddenRegion(
+              if (isNext(loc.Line, loc.Column, ' '))
+                Location(fileIndex, loc.Line, loc.Column + 1, loc.EndLine, loc.EndColumn)
+              else
+                loc,
+              true);
+
+            checkLine(loc.Line);
+          }
+        }
+
+        def processBuilder(builder : TypeBuilder)
         {
           // Region for the type itself.
           //
@@ -214,40 +229,45 @@
           // TypeBuilder can contains methods from many parts of partial 
           // class and super classes. We must process only memebers defined 
           // in processed file only!
+          //
           | method is MethodBuilder when method.Location.FileIndex == fileIndex =>
 
-  #if !DEBUG
+#if !DEBUG
             when (_start > Environment.TickCount - 2000)
             {
-  #endif
+#endif
               // Get errors.
               //
               def location = method.BodyLocation;
               def bodyCode = source.GetRegion(location.Line, location.Column, location.EndLine, location.EndColumn);
 
-              _ = _engine.CompileMethod(method, bodyCode, location);
+              def (pExpr, _, _) = _engine.CompileMethod(method, bodyCode, location);
+
+              when (pExpr != null)
+              {
+                ExprWalker().Walk(pExpr, fun(expr : PExpr)
+                {
+                | DefFunctions(funs) => // { funs : list [Function_decl]; }
+
+                  funs.Iter(f => addRegion(
+                    Utils.Combine(f.header.Location, f.body.Location).
+                    TrimStart(f.header.Location, false)));
+
+                  WalkAction.Continue;
+
+                | _ => WalkAction.Continue;
+                });
+              }
 
               foreach (cm in _engine.CompilerMessages)
                 addError(cm);
-  #if !DEBUG
+#if !DEBUG
             }
-  #endif
+#endif
 
             // Get the method region location.
             //
-            def loc = method.Location.TrimStart(method.fun_header.Location, false);
-
-            when (!loc.IsEmpty())
-            {
-              addHiddenRegion(
-                if (isNext(loc.Line, loc.Column, ' '))
-                  Location(fileIndex, loc.Line, loc.Column + 1, loc.EndLine, loc.EndColumn)
-                else
-                  loc,
-                true);
-
-              checkLine(loc.Line);
-            }
+            addRegion(method.Location.TrimStart(method.fun_header.Location, false));
 
           | builder is TypeBuilder when builder.Location.FileIndex == fileIndex =>
 

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/WalkAction.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/WalkAction.n	Mon Oct  2 05:36:58 2006
@@ -0,0 +1,11 @@
+using System;
+
+namespace Nemerle.Completion2
+{
+  public enum WalkAction
+  {
+  | Stop
+  | Skip
+  | Continue
+  }
+}

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n	Mon Oct  2 05:36:58 2006
@@ -184,7 +184,7 @@
       /*[NotNull]*/ content  : string,
                     location : Location
     )
-      : FunBody.Parsed * FunBody.Typed * Exception
+      : PExpr * Typedtree.TExpr * Exception
     {
         ClearCompilerMessages();
         _isInCompletionMode = true;
@@ -197,12 +197,15 @@
           try
           {
             method.RunBodyTyper();
-            (pBody, method.GetHeader().body :> FunBody.Typed, null)
+
+            def tExpr = method.GetHeader().body :> FunBody.Typed;
+
+            (pBody.expr, if (tExpr != null) tExpr.expr else null, null)
           }
-          catch { | ex => (pBody, null, ex) }
+          catch { | ex => (pBody.expr, null, ex) }
         }
         else
-          (pBody, null, null)
+          (null, null, null)
     }
 
     public PreParse([NotNull] content : string, location : Location) : Token.BracesGroup

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/ISourceTextManager.n	Mon Oct  2 05:36:58 2006
@@ -1,10 +1,13 @@
 using System;
 
+using Nemerle.Compiler;
+
 namespace Nemerle.Completion2
 {
   public interface ISourceTextManager
   {
     GetRegion         (lineStart : int, colStart : int, lineEnd : int, colEnd : int) : string;
+    GetRegion         (location : Location) : string;
     GetLine           (line : int) : string;
     GetNearestPosition(line : int, col : int) : int;
     GetLineAndColumn  (pos  : int) : int * int;

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	Mon Oct  2 05:36:58 2006
@@ -136,6 +136,11 @@
         builder.ToString();
       }
 
+      public GetRegion(loc : Location) : string
+      {
+        GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn)
+      }
+
       public GetLine(_line : int) : string
       {
         throw NotImplementedException();

Modified: vs-plugin/trunk/Nemerle.VSIP.sln
==============================================================================
--- vs-plugin/trunk/Nemerle.VSIP.sln	(original)
+++ vs-plugin/trunk/Nemerle.VSIP.sln	Mon Oct  2 05:36:58 2006
@@ -13,6 +13,9 @@
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{D5EB7C03-398D-4C41-91C9-4ED474CC1312}"
 EndProject
 Global
+	GlobalSection(DPCodeReviewSolutionGUID) = preSolution
+		DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
+	EndGlobalSection
 	GlobalSection(TextTemplating) = postSolution
 		TextTemplating = 1
 	EndGlobalSection

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/SourceTextManager.cs	Mon Oct  2 05:36:58 2006
@@ -7,6 +7,7 @@
 using Nemerle.Builtins;
 
 using Nemerle.Completion2;
+using Nemerle.Compiler;
 
 namespace Nemerle.VisualStudio.LanguageService
 {
@@ -54,6 +55,11 @@
 			return "";
 		}
 
+		public string GetRegion(Location loc)
+		{
+			return GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
+		}
+
 		/// <summary>
 		/// Get text of line frome text bufer of IDE.
 		/// </summary>

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Nemerle.VsIntegration.csproj	Mon Oct  2 05:36:58 2006
@@ -24,6 +24,7 @@
     <DefineConstants>TRACE;DEBUG</DefineConstants>
     <WarningLevel>4</WarningLevel>
     <IncrementalBuild>false</IncrementalBuild>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <DebugSymbols>false</DebugSymbols>



More information about the svn mailing list