[svn] r6748: vs-plugin/trunk/Nemerle.Compiler.Utils: Nemerle.Compiler.Utils.csproj Nemerle.Completion2/Cod...

IT svnadmin at nemerle.org
Thu Oct 5 00:17:42 CEST 2006


Log:
ExprWalker/ExprFinder refactoring.

Author: IT
Date: Thu Oct  5 00:17:37 2006
New Revision: 6748

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n
Removed:
   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/ExprFinder.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalker.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n

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	Thu Oct  5 00:17:37 2006
@@ -126,7 +126,7 @@
     <Compile Include="Nemerle.Completion2\CodeModel\ExprWalker.n" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Nemerle.Completion2\CodeModel\WalkAction.n" />
+    <Compile Include="Nemerle.Completion2\CodeModel\ExprWalkInfo.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. 

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	Thu Oct  5 00:17:37 2006
@@ -7,6 +7,9 @@
 using Nemerle.Compiler.Utils;
 using Nemerle.Imperative;
 
+using P = Nemerle.Compiler.Parsetree;
+using T = Nemerle.Compiler.Typedtree;
+
 namespace Nemerle.Completion2
 {
   class ExprFinder
@@ -23,216 +26,47 @@
 
     #region Find PExpr
 
-    DoSyntaxElement(syntaxElement : SyntaxElement) : void
+    PFinder(info : ExprWalkInfo) : void
     {
-      when (_stop || syntaxElement == null || !IsIn(_curLocation))
+      when (info.Node is PExpr.Literal || !IsIn(_curLocation))
         return;
 
-      match (syntaxElement)
-      {
-      | Expression(expr)    // { body : PExpr; }
-      | TType     (expr) => // { body : PExpr; }
-
-        Go(expr)
-
-      | MatchCase(mc)    => // { body : Parsetree.MatchCase; }
-
-        mc.patterns.Iter(Go);
-        Go(mc.body);
-
-      | Function            // { body : Function_decl; }
-      | Parameter           // { body : Fun_parm; }
-      | RawToken            // { body : Token; }
-      | ClassMember         // { body : Parsetree.ClassMember; }
-      | TypeBuilder         // { body : Compiler.TypeBuilder; }
-      | FieldBuilder        // { body : Compiler.FieldBuilder; }
-      | MethodBuilder       // { body : Compiler.MethodBuilder; }
-      | PropertyBuilder     // { body : Compiler.PropertyBuilder; }
-      | EventBuilder        // { body : Compiler.EventBuilder; }
-      | ParameterBuilder => // { body : Typedtree.Fun_parm; }
+      when (info.Node is Located)
+        Print(info.Node :> Located, info.Nodes.Length);
 
-        PrintUnknown(syntaxElement);
-
-      }
-    }
-
-    DoSplicable(element : Splicable) : void
+      match (info.Node)
     {
-      when (_stop || element == null || !IsIn(_curLocation))
-        return;
-
-      match (element)
-      {
-      | Expression(e) => Go(e);
-      | Name  (name)
-      | HalfId(name)  => CheckObject(element.Location, name);
-      }
-    }
-
-    DoFunctionDecl(func : Function_decl) : void
-    {
-      when (_stop || func == null || !IsIn(_curLocation))
-        return;
-
-      if (IsIn(func.header.Location))
-      {
-        foreach (p in func.header.parms)
-          Go(p.ty);
-
-        Go(func.header.ret_type);
-      }
-      else
-      {
-        Go(func.body);
-      }
-    }
-
-    Go(expression : PExpr) : void
-    {
-      when (_stop || expression == null || expression is PExpr.Literal || !IsIn(_curLocation))
-        return;
-
-      Print(expression);
-      _counter++;
-
-      match (expression)
-      {
-      | EmptyArray (lst)           // { sizes : list [PExpr]; }
-      | Tuple      (lst)           // { args : list [PExpr]; }
-      | ListLiteral(lst)           // { elements : list [PExpr]; }
-      | Sequence   (lst)        => // { body : list [PExpr]; }
-
-        lst.Iter(Go);
-
-      | MacroCall(_, _, elems)  => // { name : Name; ns : NamespaceTree.Node; parms : list [SyntaxElement]; }
-
-        CheckLocated(expression);
-        elems.Iter(DoSyntaxElement);
-
-      | GenericSpecifier(e, l)     // { func : PExpr; generic_parms : list [PExpr]; }
-      | Indexer         (e, l)     // { obj : PExpr; args : list [PExpr]; }
-      | Call            (e, l)  => // { func : PExpr; parms : list [PExpr]; }
-
-        Go(e);
-        l.Iter(Go);
-
-      | Ref    (obj : object)   => // { name : Name; }
-      //| Literal(obj : object)   => // { val : Nemerle.Compiler.Literal; }
-
-        CheckObject(expression.Location, obj);
-
-      | Array          (e1, e2)    // { rank : PExpr; args : PExpr; }
-      | TypeConversion (e1, e2)    // { expr : PExpr; ty : PExpr; }  // (expr :> ty)
-      | TypeEnforcement(e1, e2)    // { expr : PExpr; ty : PExpr; } // (expr : ty)
-      | Assign         (e1, e2)    // { target : PExpr; source : PExpr; }
-      | Define         (e1, e2)    // { pattern : PExpr; val : PExpr; }
-      | TryFinally     (e1, e2)    // { body : PExpr; handler : PExpr; }
-      | Is             (e1, e2)    // { pat : PExpr; ty : PExpr; }
-      | Where          (e1, e2)    // { name : PExpr; fields : PExpr; }
-      | DefMutable     (e1, e2) => // { name : PExpr; val : PExpr; }
-
-        Go(e1);
-        Go(e2);
-
-      | This
-      | Base
-      | Void                       // `void' used only in types
-      | Error                   => // placeholder of missing tree (where some errors occured)
-
-        ();
-
-      | As    (e, sp)              // { pat : PExpr; name : Splicable; }
-      | Member(e, sp)           => // { obj : PExpr; member : Splicable; }
-
-        Go(e);
-        DoSplicable(sp);
-
-      | Spliced  (e)               // { body : PExpr; }
-      | Ellipsis (e)               // { body : PExpr; }
-      | ParmByRef(e)               // { parm : PExpr; }
-      | ParmOut  (e)               // { parm : PExpr; }
-      | Throw    (e)               // { exn : PExpr; }
-      | Typeof   (e)            => // { ty : PExpr; }
-
-        Go(e);
-
-      | Wildcard                => // `_' used mainly in patterns, but also in `_ = ignored'
-
-        CheckLocated(expression)
-
-      | DefFunctions(funs)      => // { funs : list [Function_decl]; }
+      | pexpr is PExpr =>
 
-        funs.Iter(DoFunctionDecl);
-
-      | Lambda(decl)            => // { decl : Function_decl; }
-
-        DoFunctionDecl(decl);
-
-      | Match(e, l)             => // { expr : PExpr; cases : list [MatchCase]; }
-
-        Go(e);
-        foreach (mc in l)
+        match (pexpr)
         {
-          mc.patterns.Iter(Go);
-          Go(mc.body);
+        | Wildcard
+        | MacroCall              => CheckLocated(pexpr);
+        | ToComplete(o : object)
+        | TypedType (o : object)
+        | Ref       (o : object) => CheckObject(pexpr.Location, o);
+        | _ => ()
         }
 
-      | Quoted(se)              => // { body : SyntaxElement; }
+      | sp is Splicable =>
 
-        DoSyntaxElement(se);
-
-      | Try(body, cases)        => // { body : PExpr; cases : list [TryCase]; }
-
-        Go(body);
-
-        foreach (c when !_stop in cases)
-          match (c)
+        match (sp)
           {
-          | Catch(exn, exn_ty, handler) => //{ exn : Splicable; exn_ty : PExpr; handler : PExpr; }
-
-            DoSplicable(exn);
-            Go(exn_ty);
-            Go(handler);
-
-          | Filter(exn, exn_ty, filter, handler) => // { exn : Splicable; exn_ty : PExpr; filter : PExpr; handler : PExpr; }
-
-            DoSplicable(exn);
-            Go(exn_ty);
-            Go(filter);
-            Go(handler);
-
-          | Ellipsis(body) => // { body : PExpr; }
-
-            Go(body);
-
+        | HalfId(name) => CheckObject(sp.Location, name)
+        | _ => ()
           }
-
-      | ToComplete(o : object)     // { body : Name; }
-      | TypedType (o : object)  => // { body : TyVar; }
-
-        CheckObject(expression.Location, o);
-
-      | Typed              // { body : Typedtree.TExpr; }
-      | TypedPattern       // { body : Typedtree.Pattern; }
-      | _ =>
-
-        PrintUnknown(expression);
-
+      | _ => ()
       }
 
-      _counter--;
+      when (_stop)
+        info.Stop();
     }
 
-    public Find(
-      root : PExpr,
-      line : int,
-      col  : int
-    )
-      : Location * object
+    public Find(root : PExpr, line : int, col : int) : Location * object
     {
       Init(root.Location, line, col);
 
-      Go(root);
+      ExprWalker().Walk(root, PFinder);
 
       (_retLocation, _retObject)
     }
@@ -241,93 +75,59 @@
 
     #region Find TExpr
 
-    DoPattern(pattern : Pattern) : void
+    FindPattern(pattern : Pattern, info : ExprWalkInfo) : void
     {
-      when (_stop || pattern == null || pattern is Pattern.Literal || !IsIn(_curLocation))
-        return;
-
-      Print(pattern);
-      _counter++;
-
       match (pattern)
       {
-      | Wildcard
-      | Literal            => // { val : Nemerle.Compiler.Literal; }
-
-        ()
-
       | Error              =>
 
         _stop = _stop || IsIn(pattern.Location);
 
-      | Application as app => // { name : TypeInfo; arg : Pattern; }
+      | Application(name, arg) =>
 
-        DoPattern(app.arg);
-        CheckObject(pattern.Location, app.name);
+        info.Walk(arg);
+        CheckObject(pattern.Location, name);
 
-      | Record(args)       => // { args : list [IMember * Pattern]; }
+      | HasType    (typ)       =>
 
-        foreach ((_member, pattern) in args)
-          DoPattern(pattern);
+        CheckObject(pattern.Location, typ);
 
       | As(Wildcard, decl) when decl.Location.Line < pattern.Location.Line =>
 
         CheckObject(pattern.Location, decl)
 
-      | As(pat, decl)      => // { pat : Pattern; decl : LocalValue; }
+      | As(pattern, decl) =>
 
         Check(
-          pat. Location, fun() { DoPattern   (pat)  },
-          decl.Location, fun() { CheckLocated(decl) });
-
-      | HasType as ht      => // { typ : MType; }
-
-        CheckObject(pattern.Location, ht.typ);
-
-      | Tuple(args)        => // { args : list [Pattern]; }
-
-        args.Iter(DoPattern);
-
-      | Enum               => // { fld : IField; val : Nemerle.Compiler.Literal; }
-
-        Print(pattern);
+          pattern.Location, () => info.Walk(pattern),
+          decl.   Location, () => CheckLocated(decl));
 
+      | _ => ()
       }
-
-      _counter--;
     }
 
-    Go(expression : TExpr) : void
+    FindExpr(expression : TExpr, info : ExprWalkInfo) : void
     {
-      when (_stop || expression == null || expression is TExpr.Literal || !IsIn(_curLocation))
-        return;
-
-      Print(expression);
-      _counter++;
-
       when (_findLocation && _pexprLocation.IsEqualExcludingFile(expression.Location))
       {
-        _stop        = true;
         _retObject   = expression;
         _retLocation = _pexprLocation;
 
+        info.Stop();
         return;
       }
 
       match (expression)
       {
-      | StaticRef        (_, mem : IMember, _) // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
-      | ConstantObjectRef(_, mem : IMember)    // { from : MType.Class; mem : IField; }
-      | StaticPropertyRef(_, mem : IMember)    // { from : MType.Class; prop : IProperty; }
-      | StaticEventRef   (_, mem : IMember)    // { from : MType.Class; ev : IEvent; }
-      | Base                (mem : IMember) => // { base_ctor : IMethod; }
-
-        CheckObject(expression.Location, mem);
-
-      | LocalFunRef(lv, _)         // { decl : LocalValue; type_parms : list [TyVar]; }
-      | LocalRef   (lv)         => // { decl : LocalValue; }
+      | StaticRef        (_, o : object, _)      // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
+      | ConstantObjectRef(_, o : object)         // { from : MType.Class; mem : IField; }
+      | StaticPropertyRef(_, o : object)         // { from : MType.Class; prop : IProperty; }
+      | StaticEventRef   (_, o : object)         // { from : MType.Class; ev : IEvent; }
+      | Base                (o : object)         // { base_ctor : IMethod; }
+      | LocalFunRef         (o : object, _)      // { decl : LocalValue; type_parms : list [TyVar]; }
+      | LocalRef            (o : object) =>      // { decl : LocalValue; }
 
-        CheckObject(expression.Location, lv)
+        CheckObject(expression.Location, o);
 
       | Error
       | ImplicitValueTypeCtor
@@ -345,190 +145,75 @@
 
         Check(
           expression.Location, () => CheckObject(expression.Location, mem),
-          obj.Location,        () => Go(obj));
+          obj.Location,        () => info.Walk(obj));
 
       | TypeConversion(e, t, _) => // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
 
-        Go(e);
+        info.Walk(e);
         CheckObject(expression.Location, t);
 
-      | Block         (_, e)       // { jump_out : LocalValue; body : TExpr; }
-      | Throw         (e)          // { exn : TExpr; }
-      | Label         (_, e)    => // { id : int; body : TExpr; }
-
-        Go(e);
-
-      | Call as call            => // { mutable func : TExpr; mutable parms : list [Parm]; mutable is_tail : bool; }
-
-        foreach (parm in call.parms)
-          Go(parm.expr);
-
-        Go(call.func);
-
-      | Try(body, cases)        => // { body : TExpr; mutable cases : list [Try_case]; }
-
-        def walkTry_case(cases)
-        {
-        | Try_case.Fault(handler) :: tail  // { handler : TExpr; }
-        | Catch(_, handler) :: tail     => // { exn : LocalValue; handler : TExpr; }
-
-          Go(handler);
-          walkTry_case(tail)
-
-        | Filter(_, filter, handler) :: tail => // { exn : LocalValue; filter : TExpr; handler : TExpr; }
-
-          Go(filter);
-          Go(handler);
-          walkTry_case(tail)
-
-        | [] => ()
-        }
-
-        Go(body); 
-        walkTry_case(cases);
-
       | DefValIn(nm, val, body) => // { name : LocalValue; val : TExpr; mutable body : TExpr; }
 
         Check(
           nm. Location, () => CheckLocated(nm),
-          val.Location, () => Go(val));
+          val.Location, () => info.Walk(val));
 
         unless (body == null)
-          Go(body);
+          info.Walk(body);
 
       | Sequence(Call(Base as b, _, _), e2) as seq =>
 
         when (seq.Location != b.Location)
-          Go(b);
-
-        Go(e2);
-
-      | Assign    (e1, e2)         // { target : TExpr; source : TExpr; }
-      | TryFinally(e1, e2)         // { body : TExpr; handler : TExpr; }
-      | Sequence  (e1, e2)      => // { mutable e1 : TExpr; mutable e2 : TExpr; }
-
-        Go(e1);
-        Go(e2);
-
-      | Tuple(args)             => // { args : list [TExpr]; }
-
-        args.Iter(Go);
-
-      | Array(args, dim)        => // { args : list [TExpr]; dimensions : list [TExpr]; }
-
-        args.Iter(Go);
-        dim. Iter(Go);
-
-      | ArrayIndexer(obj, args) => // { obj : TExpr; args : list [TExpr]; }
-
-        Go(obj);
-        args.Iter(Go);
-
-      | TupleIndexer(obj, _, _) => // { obj : TExpr; pos : int; len : int; } // 0-based
+          info.Walk(b);
 
-        Go(obj);
+        info.Walk(e2);
 
       | Delayed(susp)           => // { susp : Typer.DelayedTyping; }
 
         unless (susp.IsResolved)
           susp.Resolve();
 
-        when (susp.IsResolved)
-          Go(susp.ResolutionResult);
+      | HasType as ht                     => // { expr : TExpr; test_ty : MType; }
 
-      | DefFunctionsIn as dfun  => // { funs : list [Fun_header]; mutable body : TExpr; }
+        info.Walk(ht.expr);
+        CheckObject(ht.Location, ht.test_ty);
 
-        foreach (f in dfun.funs)
-        {
-          if (IsIn(f.Location))
-          {
-            foreach (p in f.parms)
-              CheckObject(p.Location, p.decl);
+      | TypeOf as to                      => // { target_type : TyVar; }
 
-            CheckLocated(f);
-          }
-          else
-          {
-            match (f.body)
-            {
-            | Typed(expr) => Go(expr);
-            | _ => ();
-            }
-          }
+        CheckObject(to.Location, to.target_type);
 
-          when (_stop)
-            break;
+      | _ => ()
+      }
         }
 
-        unless (_stop)
-          Go(dfun.body);
-
-      | Match as m            => // { expr : TExpr; cases : list [Match_case]; }
+    TFinder(info : ExprWalkInfo) : void
+    {
+      when (info.Node is TExpr.Literal || info.Node is Pattern.Literal || !IsIn(_curLocation))
+        return;
 
-        Go(m.expr);
+      when (info.Node is Located)
+        Print(info.Node :> Located, info.Nodes.Length);
 
-        unless (_stop) foreach (c in m.cases)
+      match (info.Node)
         {
-          foreach ((pattern, pexpr, assigns) in c.patterns)
-          {
-            DoPattern(pattern);
+      | pat  is Pattern      => FindPattern(pat,  info)
+      | expr is TExpr        => FindExpr   (expr, info);
+      | hdr  is T.Fun_header =>
 
-            unless (_stop)
+        when (IsIn(hdr.Location))
             {
-              Go(pexpr);
-
-              foreach ((_localValue, aexpr) in assigns)
-                Go(aexpr);
-            }
+          foreach (p in hdr.parms)
+            CheckObject(p.Location, p.decl);
 
-            when (_stop)
-              break;
+          CheckLocated(hdr);
+          info.Skip();
           }
 
-          Go(c.body);
-
-          when (_stop)
-            break;
-        }
-
-      | If as eif             => // { cond : TExpr; e_then : TExpr; e_else : TExpr; }
-
-        Go(eif.cond);
-        Go(eif.e_then);
-        Go(eif.e_else);
-
-      | Switch as e_switch    => // { indexing_expr : TExpr; default : option [TExpr]; cases : list [int * TExpr]; }
-
-        Go(e_switch.indexing_expr); 
-
-        match (e_switch.default)
-        {
-        | Some(expr) => Go(expr)
         | _ => ()
         }
 
-        foreach ((_, expr) in e_switch.cases)
-          Go(expr);
-
-      | HasType as ht         => // { expr : TExpr; test_ty : MType; }
-
-        Go(ht.expr);
-        CheckObject(ht.Location, ht.test_ty);
-
-      | TypeOf as to          => // { target_type : TyVar; }
-
-        CheckObject(to.Location, to.target_type);
-
-      | SelfTailCall             // { parms : list [Parm]; }
-      | MethodAddress            // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
-      | MultipleAssign           // { assigns : list [LocalValue * TExpr]; }
-      | _ =>
-
-        PrintUnknown(expression);
-
-      }
-
-      _counter--;
+      when (_stop)
+        info.Stop();
     }
 
     public Find(
@@ -545,7 +230,7 @@
       _pexprLocation = pexprLocation;
       _findLocation  = findLocation;
 
-      Go(root);
+      ExprWalker().Walk(root, TFinder);
 
       (_retLocation, _retObject)
     }
@@ -559,7 +244,7 @@
       when (_stop || token == null)
         return stack;
 
-      Print(token, token.Location);
+      Print(token, token.Location, _counter);
       _counter++;
 
       mutable newStack = match (token)
@@ -604,7 +289,7 @@
     {
       Init(root.Location, line, col);
 
-      (Go(root, []));
+      Go(root, [])
     }
 
     #endregion
@@ -683,25 +368,17 @@
       }
     }
 
-    PrintUnknown[T](ex : T) : void
-    {
-#if PRINT_AST
-      Trace.WriteLine($"Unknown expression $(ex.GetType().FullName) : $ex.");
-#endif
-      ignore(ex);
-    }
-
-    Print(ex : Located) : void
+    Print(ex : Located, level : int) : void
     {
-      Print(ex, ex.Location);
+      Print(ex, ex.Location, level);
     }
 
-    Print(obj : object, loc : Location) : void
+    Print(obj : object, loc : Location, level : int) : void
     {
 #if PRINT_AST
       mutable s = "";
 
-      for (mutable i = 0; i < _counter; i++)
+      for (mutable i = 0; i < level; i++)
         s += "  ";
 
       Trace.WriteLine(s + $"$(obj.GetType().FullName) $(loc.Line):$(loc.Column):"

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ExprWalkInfo.n	Thu Oct  5 00:17:37 2006
@@ -0,0 +1,75 @@
+using System;
+
+using Nemerle.Compiler.Parsetree;
+using Nemerle.Compiler.Typedtree;
+
+namespace Nemerle.Completion2
+{
+  public delegate ExprWalkHandler(info : ExprWalkInfo) : void;
+
+  public class ExprWalkInfo
+  {
+    internal this(handler : ExprWalkHandler)
+    {
+      Handler = handler;
+    }
+
+    public mutable IsStoped : bool;
+    public mutable Handler  : ExprWalkHandler;
+    public mutable Node     : object;
+    public mutable Nodes    : list[object] = [];
+
+    internal Push(node : object) : bool
+    {
+      Node = node;
+
+      if (IsStoped || Node == null || Handler == null)
+      {
+        false;
+      }
+      else
+      {
+        Handler(this);
+
+        if (!IsStoped && Node != null)
+        {
+          Nodes ::= node;
+          true
+        }
+        else
+          false
+      }
+    }
+
+    internal Pop() : void
+    {
+      unless (IsStoped)
+      {
+        match (Nodes)
+        {
+        | _ :: tail => Nodes = tail;
+        | [] => ()
+        }
+      }
+    }
+
+    private Walk(walk : ExprWalker -> void) : void
+    {
+      def walker = ExprWalker();
+
+      walk(walker);
+
+      when (IsStoped)
+        Nodes = walker.Info.Nodes :: Nodes;
+
+      Skip();
+    }
+
+    public Walk(expr : PExpr)   : void { Walk(_.Walk(expr, Handler)) }
+    public Walk(expr : TExpr)   : void { Walk(_.Walk(expr, Handler)) }
+    public Walk(pat  : Pattern) : void { Walk(_.Walk(pat,  Handler)) }
+
+    public Stop() : void { IsStoped = true }
+    public Skip() : void { Node     = null }
+  }
+}

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	Thu Oct  5 00:17:37 2006
@@ -3,44 +3,71 @@
 using Nemerle.Assertions;
 using Nemerle.Compiler;
 using Nemerle.Compiler.Parsetree;
+using Nemerle.Compiler.Typedtree;
 using Nemerle.Imperative;
+using Nemerle.Utility;
+
+using P = Nemerle.Compiler.Parsetree;
+using T = Nemerle.Compiler.Typedtree;
 
 namespace Nemerle.Completion2
 {
-  delegate PExprWalkHandler(expression : PExpr) : WalkAction;
-
-  class ExprWalker
+  public class ExprWalker
   {
-    mutable _walkHandler : PExprWalkHandler;
-    mutable _stop        : bool;
+    [Accessor] mutable _info  : ExprWalkInfo;
 
-    private Go(lst : list[PExpr])         : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[ClassMember])   : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[Splicable])     : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[SyntaxElement]) : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[Function_decl]) : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[MatchCase])     : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[TryCase])       : void { when (lst != null) foreach (item in lst) Go(item); }
-    private Go(lst : list[Fun_parm])      : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.PExpr])         : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.ClassMember])   : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.Splicable])     : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.SyntaxElement]) : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.Function_decl]) : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.MatchCase])     : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.TryCase])       : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[P.Fun_parm])      : void { when (lst != null) foreach (item in lst) Go(item); }
+
+    private Go(lst : list[T.TExpr])         : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[T.Parm])          : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[T.Try_case])      : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[T.Fun_parm])      : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[T.Fun_header])    : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[T.Pattern])       : void { when (lst != null) foreach (item in lst) Go(item); }
+    private Go(lst : list[T.Match_case])    : void { when (lst != null) foreach (item in lst) Go(item); }
 
-    private Go(splicable : Splicable) : void
+    private Go(body : FunBody) : void
     {
-      when (_stop || splicable == null)
-        return;
+      when (_info.Push(body))
+      {
+        match (body)
+        {
+        | Parsed(e) => Go(e); // { expr : Parsetree.PExpr; }
+        | Typed (e) => Go(e); // { expr : Typedtree.TExpr; }
+        | ILed
+        | Abstract  => ();
+        }
+
+        _info.Pop();
+      }
+    }
 
+    private Go(splicable : P.Splicable) : void
+    {
+      when (_info.Push(splicable))
+      {
       match (splicable)
       {
       | Expression(e) => Go(e); // { expr : PExpr; }
       | Name                    // { body : Parsetree.Name; }
       | HalfId        => ();    // { prefix : Parsetree.Name; }
       }
+
+        _info.Pop();
+      }
     }
 
-    private Go(parms : Typarms) : void
+    private Go(parms : P.Typarms) : void
+    {
+      when (_info.Push(parms))
     {
-      when (_stop || parms == null)
-        return;
-
       Go(parms.tyvars);
 
       foreach (c in parms.constraints)
@@ -48,78 +75,76 @@
         Go(c.tyvar);
         Go(c.ty);
       }
+
+        _info.Pop();
+      }
     }
 
-    private Go(header : Fun_header) : void
+    private Go(header : P.Fun_header) : void
+    {
+      when (_info.Push(header))
     {
-      when (_stop || header == null)
-        return;
-
       Go(header.typarms);
       Go(header.name);
       Go(header.ret_type);
       Go(header.parms);
+
+        _info.Pop();
+      }
     }
 
-    private Go(decl : Function_decl) : void
+    private Go(decl : P.Function_decl) : void
+    {
+      when (_info.Push(decl))
     {
-      when (_stop || decl == null)
-        return;
-
       Go(decl.header);
       Go(decl.body);
+
+        _info.Pop();
+      }
     }
 
-    private Go(parm : Fun_parm) : void
+    private Go(parm : P.Fun_parm) : void
+    {
+      when (_info.Push(parm))
     {
-      when (_stop || parm == null)
-        return;
-
       Go(parm.ty);
       Go(parm.name);
-    }
-
-    private Go(body : FunBody) : void
-    {
-      when (_stop || body == null)
-        return;
 
-      match (body)
-      {
-      | Parsed(e) => Go(e); // { expr : Parsetree.PExpr; }
-      | Typed               // { expr : Typedtree.TExpr; }
-      | ILed
-      | Abstract  => ();
+        _info.Pop();
       }
     }
 
-    private Go(tryCase : TryCase) : void
+    private Go(tryCase : P.TryCase) : void
+    {
+      when (_info.Push(tryCase))
     {
-      when (_stop || tryCase == null)
-        return;
-
       match (tryCase)
       {
-      | Catch(sp, e1, e2)      => Go(sp); Go(e1); Go(e2);         // { exn : Splicable; exn_ty : PExpr; handler : PExpr; }
+        | 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; }
       }
+
+        _info.Pop();
+      }
     }
 
-    private Go(matchCase : MatchCase) : void
+    private Go(matchCase : P.MatchCase) : void
+    {
+      when (_info.Push(matchCase))
     {
-      when (_stop || matchCase == null)
-        return;
-
       Go(matchCase.patterns);
       Go(matchCase.body);
+
+        _info.Pop();
+      }
     }
 
-    private Go(decl : TopDeclaration) : void
+    private Go(decl : P.TopDeclaration) : void
+    {
+      when (_info.Push(decl))
     {
-      when (_stop || decl == null)
-        return;
-
       match (decl)
       {
       | Class    (lst, m)                              // { mutable t_extends : list [PExpr]; decls : list [ClassMember]; }
@@ -133,13 +158,15 @@
       }
 
       Go(decl.name);
+
+        _info.Pop();
+      }
     }
 
-    private Go(member : ClassMember) : void
+    private Go(member : P.ClassMember) : void
+    {
+      when (_info.Push(member))
     {
-      when (_stop || member == null)
-        return;
-
       match (member)
       {
       | TypeDeclaration(td)    => Go(td);          // { td : TopDeclaration; }
@@ -164,13 +191,15 @@
       }
 
       Go(member.name);
+
+        _info.Pop();
+      }
     }
 
-    private Go(element : SyntaxElement) : void
+    private Go(element : P.SyntaxElement) : void
+    {
+      when (_info.Push(element))
     {
-      when (_stop || element == null)
-        return;
-
       match (element)
       {
       | Expression      (e)                 // { body : PExpr; }
@@ -187,20 +216,15 @@
       | PropertyBuilder                     // { body : Compiler.PropertyBuilder; }
       | EventBuilder           => ();       // { body : Compiler.EventBuilder; }
       }
+
+        _info.Pop();
+      }
     }
 
-    private Go(expression : PExpr) : void
+    private Go(expression : P.PExpr) : void
     {
-      when (_stop || expression == null)
-        return;
-
-      match (_walkHandler(expression))
+      when (_info.Push(expression))
       {
-      | Skip     => return;
-      | Stop     => _stop = true; return;
-      | Continue => ();
-      }
-
       match (expression)
       {
       | Wildcard
@@ -210,10 +234,10 @@
       | Base
       | Error
       | ToComplete                                  // { body : Name; }
-      | Typed                                       // { body : Typedtree.TExpr; }
       | TypedPattern                                // { body : Typedtree.Pattern; }
       | TypedType                                   // { body : TyVar; }
       | Void                     => ()
+        | Typed           (body)   => Go(body);       // { body : Typedtree.TExpr; }
       | 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; }
@@ -245,14 +269,185 @@
       | Quoted          (el)     => Go(el);         // { body : SyntaxElement; }
       | MacroCall  (_, _, parms) => Go(parms);      // { name : Name; ns : NamespaceTree.Node; parms : list [SyntaxElement]; }
       }
+
+        _info.Pop();
+      }
     }
 
-    public Walk([NotNull] expression : PExpr, [NotNull] walkHandler : PExprWalkHandler) : void
+    private Go(parm : T.Parm) : void
+    {
+      when (_info.Push(parm))
     {
-      _walkHandler = walkHandler;
-      _stop        = false;
+        Go(parm.expr);
 
+        _info.Pop();
+      }
+    }
+
+    private Go(tryCase : T.Try_case) : void
+    {
+      when (_info.Push(tryCase))
+      {
+        match (tryCase)
+        {
+        | Fault    (e)                         // { handler : TExpr; }
+        | Catch (_, e)      => Go(e);          // { exn : LocalValue; handler : TExpr; }
+        | Filter(_, e1, e2) => Go(e1); Go(e2); // { exn : LocalValue; filter : TExpr; handler : TExpr; }
+        }
+
+        _info.Pop();
+      }
+    }
+
+    private Go(parm : T.Fun_parm) : void
+    {
+      when (_info.Push(parm))
+      {
+        match (parm.default_value) { | Some(e) => Go(e) | _ => () }
+
+        _info.Pop();
+      }
+    }
+
+    private Go(header : T.Fun_header) : void
+    {
+      when (_info.Push(header))
+      {
+        Go(header.parms);
+        Go(header.body);
+
+        _info.Pop();
+      }
+    }
+
+    private Go(case : T.Match_case) : void
+    {
+      when (_info.Push(case))
+      {
+        foreach ((pat, expr, lst) in case.patterns)
+        {
+          Go(pat);
+          Go(expr);
+
+          foreach ((_, expr) in lst)
+            Go(expr);
+        }
+
+        Go(case.body);
+
+        _info.Pop();
+      }
+    }
+
+    private Go(pattern : T.Pattern) : void
+    {
+      when (_info.Push(pattern))
+      {
+        match (pattern)
+        {
+        | Literal                         // { lit : Nemerle.Compiler.Literal; }
+        | Enum                            // { fld : IField; val : Nemerle.Compiler.Literal; }
+        | HasType                         // { typ : MType; }
+        | Wildcard
+        | Error               => ()
+        | Application(_, pat)             // { name : TypeInfo; arg : Pattern; }
+        | As         (pat, _) => Go(pat); // { pat : Pattern; decl : LocalValue; }
+        | Tuple      (lst)    => Go(lst); // { args : list [Pattern]; }
+        | Record     (args)   =>          // { args : list [IMember * Pattern]; }
+
+          foreach ((_, pat) in args)
+            Go(pat);
+        }
+
+        _info.Pop();
+      }
+    }
+
+    private Go(expression : T.TExpr) : void
+    {
+      when (_info.Push(expression))
+      {
+        match (expression)
+        {
+        | ImplicitValueTypeCtor     
+        | StaticEventRef                                        // { from : MType.Class; ev : IEvent; }
+        | ConstantObjectRef                                     // { from : MType.Class; mem : IField; }
+        | StaticPropertyRef                                     // { from : MType.Class; prop : IProperty; }
+        | StaticRef                                             // { from : MType.Class; mem : IMember; type_parms : list [TyVar]; }
+        | LocalRef                                              // { decl : LocalValue; }
+        | LocalFunRef                                           // { decl : LocalValue; type_parms : list [TyVar]; }
+        | Literal                                               // { val : Nemerle.Compiler.Literal; }
+        | MethodAddress                                         // { from : TyVar; meth : IMethod; is_virt : bool; type_parms : list [TyVar]; }
+        | Base                                                  // { base_ctor : IMethod; }
+        | TypeOf                                                // { target_type : TyVar; }
+        | OpCode                                                // { name : string; }
+        | Goto                                                  // { target : int; mutable try_block : int; }
+        | DefaultValue
+        | Error
+        | This                       => ()
+        | Block         (_, e)                                  // { jump_out : LocalValue; body : TExpr; }
+        | Label         (_, e)                                  // { id : int; body : TExpr; }
+        | TupleIndexer  (e, _, _)                               // { obj : TExpr; pos : int; len : int; } // 0-based
+        | Throw         (e)                                     // { exn : TExpr; }
+        | HasType       (e, _)                                  // { expr : TExpr; test_ty : MType; }
+        | PropertyMember(e, _)                                  // { obj : TExpr; prop : IProperty; }
+        | FieldMember   (e, _)                                  // { obj : TExpr; fld : IField; }
+        | EventMember   (e, _)                                  // { obj : TExpr; ev : IEvent; }
+        | TypeConversion(e, _, _)                               // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
+        | MethodRef     (e, _, _, _) => Go(e);                  // { obj : TExpr; meth : IMethod; type_parms : list [TyVar]; notvirtual : bool; }
+        | ArrayIndexer  (e, lst)     => Go(e); Go(lst);         // { obj : TExpr; args : list [TExpr]; }
+        | Call          (e, lst, _)  => Go(e); Go(lst);         // { mutable func : TExpr; mutable parms : list [Parm]; mutable is_tail : bool; }
+        | Sequence      (e1, e2)                                // { mutable e1 : TExpr; mutable e2 : TExpr; }
+        | TryFinally    (e1, e2)                                // { body : TExpr; handler : TExpr; }
+        | Assign        (e1, e2)                                // { target : TExpr; source : TExpr; }
+        | DefValIn   (_, e1, e2)     => Go(e1); Go(e2);         // { name : LocalValue; val : TExpr; mutable body : TExpr; }
+        | Try           (e, lst)     => Go(e); Go(lst);         // { body : TExpr; mutable cases : list [Try_case]; }
+        | Tuple         (lst)        => Go(lst);                // { args : list [TExpr]; }
+        | SelfTailCall  (lst)        => Go(lst);                // { parms : list [Parm]; }
+        | Array         (l1, l2)     => Go(l1); Go(l2);         // { args : list [TExpr]; dimensions : list [TExpr]; }
+        | DefFunctionsIn(lst, e)     => Go(lst); Go(e);         // { funs : list [Fun_header]; mutable body : TExpr; }
+        | Match         (e, lst)     => Go(e); Go(lst);         // { expr : TExpr; cases : list [Match_case]; }
+        | If            (e1, e2, e3) => Go(e1); Go(e2); Go(e3); // { cond : TExpr; e_then : TExpr; e_else : TExpr; }
+        | Switch        (e, o, lst)  =>                         // { indexing_expr : TExpr; default : option [TExpr]; cases : list [int * TExpr]; }
+
+          Go(e);
+          match (o) { | Some(e) => Go(e) | _ => () }
+
+          foreach ((_, e) in lst)
+            Go(e);
+
+        | MultipleAssign(lst)        =>                         // { assigns : list [LocalValue * TExpr]; }
+
+          foreach ((_, e) in lst)
+            Go(e);
+
+        | Delayed(susp)              =>                         // { susp : Typer.DelayedTyping; }
+
+          when (susp.IsResolved)
+            Go(susp.ResolutionResult);
+        }
+
+        _info.Pop();
+      }
+    }
+
+    public Walk([NotNull] expression : PExpr, [NotNull] walkHandler : ExprWalkHandler) : void
+    {
+      _info = ExprWalkInfo(walkHandler);
+      Go(expression);
+    }
+
+    public Walk([NotNull] pattern : Pattern, [NotNull] walkHandler : ExprWalkHandler) : void
+    {
+      _info = ExprWalkInfo(walkHandler);
+      Go(pattern);
+    }
+
+    public Walk([NotNull] expression : TExpr, [NotNull] walkHandler : ExprWalkHandler) : void
+    {
+      _info = ExprWalkInfo(walkHandler);
       Go(expression);
     }
   }
 }
+

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 Oct  5 00:17:37 2006
@@ -246,17 +246,18 @@
 
               when (pExpr != null)
               {
-                ExprWalker().Walk(pExpr, fun(expr : PExpr)
+                ExprWalker().Walk(pExpr, fun(info : ExprWalkInfo)
                 {
-                | DefFunctions(funs) => // { funs : list [Function_decl]; }
+                  match (info.Node)
+                  {
+                  | 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;
+                  | _ => ()
+                  }
                 });
               }
 



More information about the svn mailing list