[svn] r7452: nemerle/trunk/ncc/parsing/MainParser-Extensions.n nemerle/trunk/ncc/parsing/MainParser.n neme...

IT svnadmin at nemerle.org
Tue Feb 20 00:16:11 CET 2007


Log:
Working on ExprFinder.

Author: IT
Date: Tue Feb 20 00:16:06 2007
New Revision: 7452

Modified:
   nemerle/trunk/ncc/parsing/MainParser-Extensions.n
   nemerle/trunk/ncc/parsing/MainParser.n
   nemerle/trunk/ncc/parsing/ParseTree.n
   nemerle/trunk/ncc/typing/Typer-PatternTyper.n
   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/Tests/Content/QuickTip2.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n

Modified: nemerle/trunk/ncc/parsing/MainParser-Extensions.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser-Extensions.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser-Extensions.n	Tue Feb 20 00:16:06 2007
@@ -267,11 +267,12 @@
     
     parse_syntax_definition (tree : GrammarElement, stop : TokenStoppers) : PExpr
     {
+      def nm  = last_tok.ToString();
       def loc = last_tok.Location;
       def (end, parms) = parse_grammar_rule (tree, stop, (1 << 15) :> MacroTargets);
       match (end) {
         | GrammarElement.End (definition) =>
-          PExpr.MacroCall (loc, mkname (""), definition.MacroNamespace,
+          PExpr.MacroCall (loc.Combine(last_tok.Location), mkname (nm, loc), definition.MacroNamespace,
                            definition.Permute (parms))
         | _ =>
           fatal_error (loc, "unable to parse syntax rule, stopped at: " + end.ToString ())

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Tue Feb 20 00:16:06 2007
@@ -457,6 +457,10 @@
       Name.NameInCurrentColor (id, env)
     }
     
+    mkname (id : string, loc : Location) : Name {
+      Name.NameInCurrentColor (id, loc, env)
+    }
+
     TokenMap ['a] (tokens : Token, f : void -> 'a) : list ['a] {
       mutable result = [];
       foreach (tok is Token.LooseGroup in tokens) {
@@ -1625,7 +1629,7 @@
         null
     }
     
-    make_operator_call (name : string, e1 : PExpr, e2 : PExpr) : PExpr
+    make_operator_call (name : string, op_loc: Location, e1 : PExpr, e2 : PExpr) : PExpr
     {
       def loc = e1.Location + e2.Location;
       match (name) {
@@ -1646,7 +1650,7 @@
         | "matches" =>
           Util.locate (loc, <[ match ($e1) { | $e2 => true | _ => false } ]>)
           
-        | _ => PExpr.Call (loc, PExpr.Ref (loc, mkname (name)), [e1, e2])
+        | _ => PExpr.Call (loc, PExpr.Ref (op_loc, mkname (name)), [e1, e2])
       }
     }
 
@@ -1682,12 +1686,12 @@
       result
     } 
     
-    roll_operators (exprs : ref list [PExpr], ops : ref list [OperatorInfo], priority : int) : void
+    roll_operators (exprs : ref list [PExpr], ops : ref list [OperatorInfo * Location], priority : int) : void
     {
       def loop () {
         match (ops) {
           | [] => ()
-          | x :: xs =>
+          | (x, op_loc) :: xs =>
             // a * b + c --- *'s right is higher, than +'s left, so a*b rolls
             // when + occurs
             when (x.RightPriority >= priority) {
@@ -1703,7 +1707,7 @@
                     match (exprs) {
                       | e1 :: e2 :: rest =>
                         exprs = rest;
-                        make_operator_call (x.Name, e2, e1)
+                        make_operator_call (x.Name, op_loc, e2, e1)
                       | _ => Util.ice ("not enough parms for binary")
                     }
                   | _ =>
@@ -1739,6 +1743,7 @@
       def loop () {
         if (_op_context == OpContext.Prefix) {
           def tok = peek_token ();
+          def loc = tok.Location;
           match (tok) {
             | Token.Operator ("..") =>
               shift ();
@@ -1768,7 +1773,7 @@
                   
                   if (info is UnaryOperatorInfo) {
                     shift ();
-                    rpn_op_stack = info :: rpn_op_stack;
+                    rpn_op_stack = (info, loc) :: rpn_op_stack;
                     // we leave prefix context here (for things like `!!expr')
                   }
                   else {
@@ -1791,6 +1796,7 @@
         else {
           mutable group = null : Token;
           def tok = peek_token ();
+          def loc = tok.Location;
           def info = 
             match (tok) {
               | Token.Operator ("*") =>
@@ -1840,12 +1846,12 @@
             if (info.Name == "*") {
               _op_context = OpContext.Prefix;
               match (rpn_op_stack) {
-                | x :: _ when x.Name == "*" => ()
-                | _ => rpn_op_stack = info :: rpn_op_stack;
+                | (x, _) :: _ when x.Name == "*" => ()
+                | _ => rpn_op_stack = (info, loc) :: rpn_op_stack;
               }
             }
             else
-              rpn_op_stack = info :: rpn_op_stack;
+              rpn_op_stack = (info, loc) :: rpn_op_stack;
 
             // parse inner elements of bracket-like operators: `( ... )'
             _expr_stack = parse_expr_sequence (group, _expr_stack);

Modified: nemerle/trunk/ncc/parsing/ParseTree.n
==============================================================================
--- nemerle/trunk/ncc/parsing/ParseTree.n	(original)
+++ nemerle/trunk/ncc/parsing/ParseTree.n	Tue Feb 20 00:16:06 2007
@@ -289,7 +289,7 @@
   /** class encapsulating name of variable for purpose of
       quotation and renaming
    */    
-  public class Name : System.IComparable [Name]
+  public class Name : Located, System.IComparable [Name]
   {
     public idl : string;
     public color : int;
@@ -302,6 +302,12 @@
       idl = id;
     }
 
+    public this (id : string, loc : Location)
+    {
+      this(id);
+      this.loc = loc;
+    }
+
     public this (id : string, color : int, context : GlobalEnv)
     {
       this.color = color;
@@ -309,11 +315,22 @@
       idl = id;
     }
 
+    public this (id : string, loc : Location, color : int, context : GlobalEnv)
+    {
+      this(id, color, context);
+      this.loc = loc;
+    }
+
     static public NameInCurrentColor (id : string, context : GlobalEnv) : Name
     {
       Name (id, context.Manager.MacroColors.Color, context)
     }
     
+    static public NameInCurrentColor (id : string, loc : Location, context : GlobalEnv) : Name
+    {
+      Name (id, loc, context.Manager.MacroColors.Color, context)
+    }
+
     static public Global (mgr : ManagerClass, id : string) : Name
     {
       Name (id, 1, mgr.CoreEnv)

Modified: nemerle/trunk/ncc/typing/Typer-PatternTyper.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-PatternTyper.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-PatternTyper.n	Tue Feb 20 00:16:06 2007
@@ -617,10 +617,8 @@
             }
 
 
-          | PT.PExpr.Is (nested, needed_type) =>
-            def nested = nested;
-            def needed_type = needed_type;
-            def needed_type = typer.BindType (needed_type).FixedValue;
+          | PT.PExpr.Is (nested, needed_is_type) =>
+            def needed_type = typer.BindType (needed_is_type).FixedValue;
             def properly_subtypes = matched_value_type.TryProvide (needed_type);
 
             def res =
@@ -659,6 +657,7 @@
               | ty =>
                 def typed_pattern =
                   Pattern.HasType (pattern.loc, matched_value_type, ty);
+                needed_is_type.typed_object = typed_pattern;
                 match (TypePattern (needed_type, nested)) {
                   | Pattern.As (Pattern.Wildcard, decl) =>
                     Pattern.As (pattern.loc, matched_value_type, 

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	Tue Feb 20 00:16:06 2007
@@ -56,8 +56,12 @@
 
             match (info.Node)
             {
-            | PExpr.Wildcard
-            | PExpr.MacroCall => info.Stop();
+            | PExpr.Wildcard => info.Stop();
+            | PExpr.MacroCall(name, _, _) when IsIn(name.Location) =>
+
+              _location = name.Location;
+              info.Stop();
+
             | _               => ()
             }
           }
@@ -70,10 +74,10 @@
 
       match (info.Node)
       {
-      | PExpr.MacroCall as mc =>
+      //| PExpr.MacroCall as mc =>
 
-        if (IsIn(mc.loc)) find(mc);
-        else              Print(mc, mc.loc, info.Nodes.Length);
+      //  if (IsIn(mc.loc)) find(mc);
+      //  else              Print(mc, mc.loc, info.Nodes.Length);
 
       | l is Located          => find(l);
       | _                     => ()
@@ -95,12 +99,14 @@
 
           _pexprObject = match (_pexprObject)
           {
+          | PExpr.As    (_, Splicable.Name as name) when IsIn(name.Location)
           | PExpr.Member(_, Splicable.Name as name) when IsIn(name.Location) => setobj(name);
           | PExpr.TypeEnforcement(Ref as r, _) when IsIn(r.Location) && _parentObject is PExpr.DefMutable =>
 
             _texprObject = (_parentObject :> PExpr).TypedObject;
             r;
 
+          | PExpr.Call(Ref as r, _) when _texprObject is TExpr.MacroEnvelope && IsIn(r.Location) => setobj(r);
           | o => o;
           }
 
@@ -112,6 +118,7 @@
             if (dt != null && dt.Name == _pexprObject.ToString()) dt else name : object
 
           | Pattern.As             (_, decl)        when IsInEx(decl.NameLocation) => decl;
+          | Pattern.HasType        (typ)                                           => typ;
           | TExpr.DefValIn         (name, _, _)     when IsInEx(name.NameLocation) => setloc(name, name.NameLocation);
           | TExpr.TypeConversion   (_, ty, _, tloc) when IsInEx(tloc)              => setloc(ty,   tloc);
           | parm is T.Fun_parm      => parm.decl;

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 20 00:16:06 2007
@@ -222,6 +222,19 @@
       }
     }
 
+    private Sort[T] (lst : list[T]) : list[T] where T : Located
+    {
+      lst.Sort((i1, i2) =>
+      {
+        match (i1.Location.Line - i2.Location.Line)
+        {
+        | n when n < 0 => -1
+        | 0            => i1.Location.Column - i2.Location.Column
+        | _            =>  1
+        }
+      });
+    }
+
     private Go(expression : P.PExpr) : void
     {
       when (_info.Push(expression))
@@ -259,7 +272,14 @@
         | 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]; }
+        | Indexer         (e, lst) =>                 // { obj : PExpr; args : list [PExpr]; }
+
+          match (lst)
+          {
+          | [] => Go(e);
+          | _  => Go(Sort(e :: lst));
+          }
+
         | ListLiteral     (lst)                       // { elements : list [PExpr]; }
         | Sequence        (lst)                       // { body : list [PExpr]; }
         | Tuple           (lst)                       // { args : list [PExpr]; }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/QuickTip2.n	Tue Feb 20 00:16:06 2007
@@ -10,11 +10,38 @@
 
   public class Class1
   {
-    MatchTest(sss : string, myvar : MyVar) : void
+    public static TestMType(t : Nemerle.Compiler.MType) : string
     {
+    | Fun as f =>
+      def fromTy = f.from.Fix();
+      def toTy   = f.to.Fix();
+      if (fromTy /*026:-2*/ : object == t || toTy : object == t)
+        ""
+      else
+        ""
+    }
+
+    Operators(val : string)
+    {
+      mutable ss = "";
+      foreach (s in [""])
+        ss += /*025:-2*/s;
+
+      _ = "1" + /*022:-1*/ val;
+    }
+
+    MatchTest(sss : string, myvar : MyVar, o : object) : void
+    {
+      match (o)
+      {
+      | s is MyVar. Op1 /*024:-2*/=> ()
+      | s is string /*023:-2*/=> ()
+      | _ => ()
+      }
+
       match (myvar)
       {
-      | Op2 as op2 => _ = op2.lst. Map /*020:-2*/(_.ToString());
+      | Op2 as op2 /*021:-2*/ => _ = op2.lst. Map /*020:-2*/(_.ToString());
       | Op1 /*016:-2*/(parms) =>
         def res = match ( parms /*019:-2*/)
         {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n	Tue Feb 20 00:16:06 2007
@@ -38,6 +38,12 @@
           Assert.AreEqual(len, result.ColEnd - result.ColStart);
       }
 
+      test("026", 6, "fromTy");
+      test("025", 2, "+=");
+      test("024", 3, "Op1");
+      test("023", 6, "String");
+      test("022", 1, "op_Addition");
+      test("021", 3, "op2");
       test("020", 3, "Map");
       test("019", 5, "parms");
       test("018", 9, "Substring");



More information about the svn mailing list