[svn] r6810: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel: ExprFinder.n ExprWalker...

IT svnadmin at nemerle.org
Mon Oct 30 02:52:32 CET 2006


Log:
Added MacroEnvelope handling.

Author: IT
Date: Mon Oct 30 02:52:28 2006
New Revision: 6810

Modified:
   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/GotoInfo.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n

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 Oct 30 02:52:28 2006
@@ -31,6 +31,7 @@
     {
       match (obj)
       {
+      | PExpr.Wildcard as wc => wc.Location == _pexprLocation
       | PExpr.Sequence
       | PExpr.Is       => true
       | _              => false
@@ -75,8 +76,19 @@
       def dt = name.DeclaringType;
       if (dt != null && dt.Name == PExprName) dt else name
 
-    | HasType    (o : object)      // { typ : MType; }
-    | As      (_, o : object) => o // { pat : Pattern; decl : LocalValue; }
+    | HasType(typ)         =>      // { typ : MType; }
+
+        match (typ)
+        {
+        | Class(tycon, _) =>
+
+          def dt = tycon.DeclaringType;
+          if (dt != null && dt.Name == PExprName) dt else typ : object
+
+        | _ => typ
+        }
+
+    | As      (_, decl)    => decl // { pat : Pattern; decl : LocalValue; }
     | _                       => pattern
     }
 
@@ -86,6 +98,23 @@
 
       if (from.tycon.Name == PExprName) from else mem : object
 
+    | TypeConversion(_, tt, _)         =>      // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
+
+      if (tt.IsFixed)
+      {
+        match (tt.FixedValue)
+        {
+        | Class(tycon, _) =>
+
+          def dt = tycon.DeclaringType;
+          if (dt != null && dt.Name == PExprName) dt else tt : object
+
+        | _ => tt
+        }
+      }
+      else
+        tt
+
     | ConstantObjectRef(_, o : object)         // { from : MType.Class; mem : IField; }
     | StaticPropertyRef(_, o : object)         // { from : MType.Class; prop : IProperty; }
     | StaticEventRef   (_, o : object)         // { from : MType.Class; ev : IEvent; }
@@ -96,7 +125,6 @@
     | EventMember      (_, o : object)         // { obj : TExpr; ev : IEvent; }
     | FieldMember      (_, o : object)         // { obj : TExpr; fld : IField; }
     | PropertyMember   (_, o : object)         // { obj : TExpr; prop : IProperty; }
-    | TypeConversion   (_, o : object, _)      // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
     | DefValIn            (o : object, _, _)   // { name : LocalValue; val : TExpr; mutable body : TExpr; }
     | HasType          (_, o : object)         // { expr : TExpr; test_ty : MType; }
     | TypeOf              (o : object) => o    // { target_type : TyVar; }
@@ -107,23 +135,35 @@
     {
       match (obj)
       {
-      | pat is Pattern =>
-
-        match (pat)
+      | pat is Pattern => match (pat)
         {
+        | Wildcard => pat.ToString() != PExprName
         | Record   => _texprObject is Pattern.Application
-        | Wildcard => _texprObject is Pattern.Application || _texprObject is Pattern.As
         | HasType  => _texprObject is Pattern.As && (_texprObject :> Pattern.As).decl.Name == PExprName
         | _        => false
         }
+      | expr is TExpr  => match (expr)
+        {
+        | LocalRef(LocalValue where (ValKind = ClosurisedThisPointer)) => expr.Location == _texprLocation
+        | TypeConversion => _Debug(obj); true
+        | Literal        => expr.ToString() != PExprName
+        | _              => false
+        }
       | _ => false
       }
     }
 
     TFinder(info : ExprWalkInfo) : void
     {
-      when (info.Node is Located)
+      match (info.Node)
       {
+      | TExpr.Delayed(susp) =>
+
+        unless (susp.IsResolved)
+          susp.Resolve();
+
+      | _ when (info.Node is Located) =>
+
         def loc = (info.Node :> Located).Location;
 
         when (IsIn(loc))
@@ -142,12 +182,24 @@
 
             _texprLocation = loc;
             _texprObject   = info.Node;
-          }
 
-          when (_pexprObject is PExpr.MacroCall && loc == _pexprLocation)
-            info.Stop();
+            when (loc == _pexprLocation && _texprObject is TExpr)
+            {
+              match (_texprObject :> TExpr)
+              {
+              | MethodRef     (_, meth, _, _) when meth.Name == PExprName
+              | FieldMember   (_, fld)        when fld. Name == PExprName
+              | PropertyMember(_, prop)       when prop.Name == PExprName
+              | EventMember   (_, ev)         when ev.  Name == PExprName
+              | MacroEnvelope => info.Stop();
+              | _ => ()
+              }
+            }
         }
       }
+
+      | _ => ()
+      }
     }
 
     public Find(pRoot : PExpr, tRoot : TExpr, line : int, col : int) : Location * object * object
@@ -174,17 +226,7 @@
           {
           | pat  is Pattern      => GetPattern(pat)
           | expr is TExpr        => GetExpr   (expr);
-          /*| hdr  is T.Fun_header =>
-
-            when (IsIn(hdr.Location))
-            {
-              foreach (p in hdr.parms)
-                CheckObject(p.Location, p.decl);
-
-              CheckLocated(hdr);
-              info.Skip();
-            }
-          */
+          | parm is T.Fun_parm => parm.decl;
           | _ => _texprObject
           }
         )
@@ -243,5 +285,10 @@
 
       ignore(level);
     }
+
+    _Debug[T](o : T) : void
+    {
+      _ = o.ToString();
+    }
   }
 }

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	Mon Oct 30 02:52:28 2006
@@ -378,6 +378,7 @@
         | FieldMember   (e, _)                                  // { obj : TExpr; fld : IField; }
         | EventMember   (e, _)                                  // { obj : TExpr; ev : IEvent; }
         | TypeConversion(e, _, _)                               // { mutable expr : TExpr; target_type : TyVar; kind : ConversionKind; }
+        | MacroEnvelope (_, _, e)                               // { original : Parsetree.PExpr; the_macro : IMacro; expanded : TExpr; }
         | 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; }

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 Oct 30 02:52:28 2006
@@ -53,15 +53,9 @@
     {
     }
 
-    public this(_mc : PExpr.MacroCall, _texpr : TExpr)
+    public this(me : TExpr.MacroEnvelope)
     {
-      def t =
-
-      match (_mc.ns.Value)
-      {
-      | MacroCall(m) => m.GetType();
-      | _ => throw ArgumentException("mc");
-      }
+      def t = me.the_macro.GetType();
 
       _lineEnd  = -1;
       _filePath = t.Assembly.GetLocalPath();

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 30 02:52:28 2006
@@ -97,53 +97,10 @@
 
           def (pBody, tBody, _) = _engine.CompileMethod(method, bodyCode, loc);
 
-
           ExprFinder().Find(pBody, tBody, line, col);
-
-          /*
-          def (pLoc, pExpr, findLocation) = if (pBody != null)
-          {
-            def (pLoc, pObj) = ExprFinder().Find(pBody, line, col);
-
-            match (pObj)
-            {
-            | PExpr.MacroCall as mc => (pLoc, mc,   true)
-            | _                     => (pLoc, null, false)
-            }
           }
           else
-            (Location.Default, null, false);
-
-          if (tBody != null)
           {
-            def (eLoc, obj) = ExprFinder().Find(tBody, line, col, pLoc, findLocation);
-
-            def loc = if (pLoc.Contains(line, col)) pLoc.Intersect(eLoc) else eLoc;
-
-            match (pExpr)
-            {
-            | PExpr.MacroCall as mc when findLocation => (loc, (mc, obj :> TExpr))
-            | _                                       => (loc, obj)
-            }
-          }
-          else
-            (Location.Default, null)
-          */
-        }
-        else
-        {
-          /*
-          // Completin in AutoModule
-          if (member.DeclaringType.FullName == _autoModule)
-          {
-            //_topKeywords;
-          }
-          else
-          {
-            //Trace.WriteLine($"# Completion outside body");
-            //array(0); // completion outside body (try conplete types)
-          }
-          */
           (Location.Default, null, null)
         }
 
@@ -166,14 +123,11 @@
     )
       : QuickTipInfo
     {
-      def (loc, pObj, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
+      def (loc, _, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
 
       match (tObj)
       {
-      | mc is TExpr when pObj is PExpr.MacroCall =>
-
-        (QuickTipInfo(loc, pObj :> PExpr.MacroCall, mc))
-
+      | me is TExpr.MacroEnvelope  => (QuickTipInfo(loc,         me))
       | lv is LocalValue           => (QuickTipInfo(loc,         lv))
       | mm is IMember              => (QuickTipInfo(loc,         mm))
       | tv is TyVar                => (QuickTipInfo(loc,         tv))
@@ -194,14 +148,11 @@
     )
       : GotoInfo
     {
-      def (_, pObj, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
+      def (_, _, tObj) = FindObject(typeDecl, fileIndex, line, col, source);
 
       match (tObj)
       {
-      | mc is TExpr when pObj is PExpr.MacroCall =>
-
-        (GotoInfo(pObj :> PExpr.MacroCall, mc))
-
+      | me is TExpr.MacroEnvelope  => (GotoInfo(me))
       | lv is LocalValue           => (GotoInfo(lv))
       | mm is IMember              => (GotoInfo(mm))
       | tv is TyVar                => (GotoInfo(tv))

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/QuickTipInfo.n	Mon Oct 30 02:52:28 2006
@@ -67,10 +67,10 @@
       _text += ") : " + fh.ret_type.ToDisplayString();
     }
 
-    public this(location : Location, mc : PExpr.MacroCall, texpr : TExpr)
+    public this(location : Location, me : TExpr.MacroEnvelope)
     {
       SetLocation(location);
-      _text = mc.MakeHint() + "\n\n" + texpr.ToString();
+      _text = me.MakeHint();
     }
 
     private SetLocation(location : Location) : void
@@ -299,28 +299,21 @@
       }
     }
 
-    public static MakeHint(this macroCall : PExpr.MacroCall) : string
+    public static MakeHint(this mc : TExpr.MacroEnvelope) : string
     {
-      "macro " + macroCall.ns.GetDisplayName() + MakeMacroCallInfo(macroCall)
-    }
-
-    private static MakeMacroCallInfo(macroCall : PExpr.MacroCall) : string
-    {
-      mutable text = "";
-
-      match (macroCall.ns.Value)
-      {
-      | MacroCall(m) =>
+      def m = mc.the_macro;
 
+      "macro " + m.GetNamespace() + "." + m.GetName()
+      +
+      (
         match (m.Keywords)
         {
-        | [] => ()
-        | _  => text += "\n\nKeywords:\n   " + m.Keywords.ToString(", ");
+        | [] => ""
+        | _  => "\n\nKeywords:\n   " + m.Keywords.ToString(", ")
         }
-      | _ => ()
-      }
-
-      text
+      )
+      +
+      "\n\n" + mc.expanded.ToString();
     }
   }
 }



More information about the svn mailing list