Author: marek
Date: 2007-06-08 11:43:05 -0400 (Fri, 08 Jun 2007)
New Revision: 78963

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/cs-parser.jay
   trunk/mcs/gmcs/linq.cs
Log:
2007-06-08  Marek Safar  <[EMAIL PROTECTED]>

        * cs-parser.jay: Uses newly defined GroupBy class.
        
        * linq.cs (GroupBy): Implemented.
        (AQueryClause.BuildQueryClause): Refactored to allow customize 
        query method arguments.



Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2007-06-08 15:41:44 UTC (rev 78962)
+++ trunk/mcs/gmcs/ChangeLog    2007-06-08 15:43:05 UTC (rev 78963)
@@ -1,5 +1,13 @@
 2007-06-08  Marek Safar  <[EMAIL PROTECTED]>
 
+       * cs-parser.jay: Uses newly defined GroupBy class.
+       
+       * linq.cs (GroupBy): Implemented.
+       (AQueryClause.BuildQueryClause): Refactored to allow customize query
+       method arguments.
+
+2007-06-08  Marek Safar  <[EMAIL PROTECTED]>
+
        * generics.cs (InferTypeArguments): Uses AnonymousMethodExpression
        InferTypeArguments.
 

Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay        2007-06-08 15:41:44 UTC (rev 78962)
+++ trunk/mcs/gmcs/cs-parser.jay        2007-06-08 15:43:05 UTC (rev 78963)
@@ -5416,6 +5416,10 @@
                $$ = ret;
          }
        | opt_from_let_where_clauses opt_orderby_clause group_clause 
opt_query_continuation
+         {
+               Linq.AQueryClause ret = (Linq.AQueryClause)$3;
+               $$ = ret;
+         }
        ;
        
 opt_from_let_where_clauses
@@ -5468,6 +5472,9 @@
        
 group_clause
        : GROUP expression BY expression
+         {
+           $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation 
($1));
+         }
        ;
 
 opt_query_continuation

Modified: trunk/mcs/gmcs/linq.cs
===================================================================
--- trunk/mcs/gmcs/linq.cs      2007-06-08 15:41:44 UTC (rev 78962)
+++ trunk/mcs/gmcs/linq.cs      2007-06-08 15:43:05 UTC (rev 78963)
@@ -76,10 +76,7 @@
                                        MemberTypes.Method, BindingFlags.Static 
| BindingFlags.Public,
                                        Type.FilterName, MethodName);
 
-                               // TODO: implement correct selection
-                               MethodInfo[] mi = new MethodInfo[] { 
(MethodInfo)ml[0] };
-
-                               method_group = new MethodGroupExpr (mi, loc);
+                               method_group = new MethodGroupExpr 
(ArrayList.Adapter (ml), loc);
                                methods.Add (MethodName, method_group);
                                return method_group;
                        }
@@ -117,16 +114,20 @@
                        ame.Block = new ToplevelBlock (parameters, loc);
                        ame.Block.AddStatement (new Return (expr, loc));
 
-                       ArrayList args = new ArrayList (2);
-                       args.Add (new Argument (from));
-                       args.Add (new Argument (ame));
-
-                       expr = new Invocation (MethodGroup, args);
+                       expr = new Invocation (MethodGroup, CreateArguments 
(ame, from));
                        if (Next != null)
                                return Next.BuildQueryClause (ec, top, this, 
li);
 
                        return expr;
                }
+                                              
+               protected virtual ArrayList CreateArguments 
(AnonymousMethodExpression ame, Expression from)
+               {
+                       ArrayList args = new ArrayList (2);
+                       args.Add (new Argument (from));
+                       args.Add (new Argument (ame));
+                       return args;
+               }
        }
 
        public class Cast : ALinqExpression
@@ -161,6 +162,37 @@
                }
        }
 
+       public class GroupBy : AQueryClause
+       {
+               readonly Expression element_selector;
+               
+               public GroupBy (Expression elementSelector, Expression 
keySelector, Location loc)
+                       : base (keySelector, loc)
+               {
+                       this.element_selector = elementSelector;
+               }
+
+               protected override ArrayList CreateArguments 
(AnonymousMethodExpression ame, Expression from)
+               {
+                       ArrayList args = base.CreateArguments (ame, from);
+                       
+                       // A query can be optimized when selector is not group 
by specific
+                       if (!element_selector.Equals (from)) {
+                               AnonymousMethodExpression am_element = new 
AnonymousMethodExpression (
+                                       null, null, ame.Host, ame.Parameters, 
ame.Container, loc);
+                               am_element.Block = new ToplevelBlock 
(ame.Parameters, loc);
+                               am_element.Block.AddStatement (new Return 
(element_selector, loc));
+                               
+                               args.Add (new Argument (am_element));
+                       }
+                       return args;
+               }
+
+               protected override string MethodName {
+                       get { return "GroupBy"; }
+               }
+       }
+
        public class Select : AQueryClause
        {
                public Select (Expression expr, Location loc)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to