Exemple #1
0
        private static LinqOpChain BuildSelectManyChain(List <Generator> /*!*/ generators,
                                                        GroupByClause gbClause, Expression /*!*/ v, LinqOp lastOp)
        {
            // PATTERNs (Rules #6, #7):
            //	from x1 in e1 from x2 in e3 ... from xk in ek [select v | group v by g]
            //
            // TRANSLATIONs:
            //  ( e1 ) . SelectMany ( x1 =>
            //		( e2 ) . SelectMany ( x2 =>
            //			...
            //				RESPECTIVELY:
            //				( ek ) . Select ( xk => v )
            //				( ek ) . GroupBy ( xk => g, xk => v )
            //			...
            //		)
            //  )
            //	. [lastOp]

            int i = generators.Count - 1;

            LinqOp outer_op;             // outer-most operator in the current chain

            if (gbClause != null)
            {
                outer_op = new LinqOp.GroupBy(generators[i].KeyVar, generators[i].ValueVar, gbClause.ByExpr, v);
            }
            else
            {
                outer_op = new LinqOp.Select(generators[i].KeyVar, generators[i].ValueVar, v);
            }

            // inner-most:
            LinqOpChain inner_chain = new LinqOpChain(generators[i].Expression, outer_op);

            while (--i >= 0)
            {
                inner_chain = new LinqOpChain(
                    generators[i].Expression,
                    outer_op = new LinqOp.SelectMany(generators[i].KeyVar, generators[i].ValueVar, inner_chain)
                    );
            }

            outer_op.Next = lastOp;

            return(inner_chain);
        }
Exemple #2
0
		private static LinqOpChain BuildSelectManyChain(List<Generator>/*!*/ generators,
			GroupByClause gbClause, Expression/*!*/ v, LinqOp lastOp)
		{
			// PATTERNs (Rules #6, #7): 
			//	from x1 in e1 from x2 in e3 ... from xk in ek [select v | group v by g]
			//
			// TRANSLATIONs: 
			//  ( e1 ) . SelectMany ( x1 => 
			//		( e2 ) . SelectMany ( x2 =>
			//			...
			//				RESPECTIVELY:
			//				( ek ) . Select ( xk => v )       
			//				( ek ) . GroupBy ( xk => g, xk => v )
			//			... 
			//		)
			//  ) 
			//	. [lastOp]

			int i = generators.Count - 1;

			LinqOp outer_op; // outer-most operator in the current chain

			if (gbClause != null)
				outer_op = new LinqOp.GroupBy(generators[i].KeyVar, generators[i].ValueVar, gbClause.ByExpr, v);
			else
				outer_op = new LinqOp.Select(generators[i].KeyVar, generators[i].ValueVar, v);

			// inner-most:
			LinqOpChain inner_chain = new LinqOpChain(generators[i].Expression, outer_op);

			while (--i >= 0)
			{
				inner_chain = new LinqOpChain(
					generators[i].Expression,
					outer_op = new LinqOp.SelectMany(generators[i].KeyVar, generators[i].ValueVar, inner_chain)
				);
			}

			outer_op.Next = lastOp;

			return inner_chain;
		}
Exemple #3
0
        private LinqOpChain BuildSingleQueryChain(List <Generator> /*!*/ generators)
        {
            // Applies Rules #2 and #3
            FromWhereToGenerators(generators);

            if (generators.Count > 1)
            {
                // multiple from-clauses (Rules #4 to #7) //

                Expression v = (select != null) ? select.Expression : groupBy.GroupExpr;

                if (orderBy != null)
                {
                    // PATTERNs (Rules #4, #5):
                    //	from x1 in e1 from x2 in e2 ... from xk in ek orderby k1, k2, ..., kn [select v | group v by g]
                    //
                    // TRANSLATIONs:
                    //  ( e1 ) . SelectMany ( x1 =>
                    //		( e2 ) . SelectMany ( x2 =>
                    //			...
                    //				RESPECTIVELY:
                    //				( ek ) . Select ( xk => new Tuple(k1, k2, ..., kn, v) )
                    //				( ek ) . GroupBy ( xk => g, xk => new Tuple(k1, k2, ..., kn, v) )
                    //			...
                    //		)
                    //  )
                    //  . OrderBy ( tuple => tuple[0] ) . ... . ThenBy ( tuple => tuple[n - 1] ) . Select ( tuple => tuple[n] )

                    List <OrderingClause> clauses = orderBy.OrderingClauses;

                    LinqTuple tuple        = new LinqTuple(clauses, v);
                    LinqOp    order_by_ops = BuildTupleOrderingOps(clauses);
                    return(BuildSelectManyChain(generators, groupBy, tuple, order_by_ops));
                }
                else
                {
                    // PATTERNs (Rules #6, #7):
                    //	from x1 in e1 from x2 in e3 ... from xk in ek [select v | group v by g]
                    //
                    // TRANSLATIONs:
                    //  ( e1 ) . SelectMany ( x1 =>
                    //		( e2 ) . SelectMany ( x2 =>
                    //			...
                    //				RESPECTIVELY:
                    //				( ek ) . Select ( xk => v )
                    //				( ek ) . GroupBy ( xk => g, xk => v )
                    //			...
                    //		)
                    //  )

                    return(BuildSelectManyChain(generators, groupBy, v, null));
                }
            }
            else
            {
                // single from-clause (Rules #8 to #11) //

                DirectVarUse x_key   = generators[0].KeyVar;
                DirectVarUse x_value = generators[0].ValueVar;

                LinqOp last_op;
                if (select != null)
                {
                    last_op = new LinqOp.Select(x_key, x_value, select.Expression);
                }
                else
                {
                    last_op = new LinqOp.GroupBy(x_key, x_value, groupBy.GroupExpr, groupBy.ByExpr);
                }

                if (orderBy != null)
                {
                    // PATTERNs (Rules #10, #11):
                    //	from x in e orderby k1 , k2, ..., kn [select v | group v by g]
                    //
                    // TRANSLATIONs:
                    //	( e ) . OrderBy ( x => k1 ) . ThenBy ( x => k2 ) ... . ThenBy (x => kn) . Select ( x => v )
                    //	( e ) . OrderBy ( x => k1 ) . ThenBy ( x => k2 ) ... . ThenBy (x => kn) . GroupBy ( x => g, x => v )

                    return(new LinqOpChain(
                               generators[0].Expression,
                               BuildOrderingOps(x_key, x_value, orderBy.OrderingClauses, last_op)
                               ));
                }
                else
                {
                    // PATTERNs (Rules #8, #9):
                    //	from x in e [select v | group v by g]
                    //
                    // TRANSLATIONs:
                    //	( e ) . Select ( x => v )
                    //  ( e ) . GroupBy ( x => g, x => v )

                    return(new LinqOpChain(generators[0].Expression, last_op));
                }
            }
        }
Exemple #4
0
		private LinqOpChain BuildSingleQueryChain(List<Generator>/*!*/ generators)
		{
			// Applies Rules #2 and #3
			FromWhereToGenerators(generators);

			if (generators.Count > 1)
			{
				// multiple from-clauses (Rules #4 to #7) //

				Expression v = (select != null) ? select.Expression : groupBy.GroupExpr;

				if (orderBy != null)
				{
					// PATTERNs (Rules #4, #5): 
					//	from x1 in e1 from x2 in e2 ... from xk in ek orderby k1, k2, ..., kn [select v | group v by g]
					//
					// TRANSLATIONs: 
					//  ( e1 ) . SelectMany ( x1 => 
					//		( e2 ) . SelectMany ( x2 =>
					//			...
					//				RESPECTIVELY:
					//				( ek ) . Select ( xk => new Tuple(k1, k2, ..., kn, v) )       
					//				( ek ) . GroupBy ( xk => g, xk => new Tuple(k1, k2, ..., kn, v) )
					//			... 
					//		)
					//  )		
					//  . OrderBy ( tuple => tuple[0] ) . ... . ThenBy ( tuple => tuple[n - 1] ) . Select ( tuple => tuple[n] )

					List<OrderingClause> clauses = orderBy.OrderingClauses;

					LinqTuple tuple = new LinqTuple(clauses, v);
					LinqOp order_by_ops = BuildTupleOrderingOps(clauses);
					return BuildSelectManyChain(generators, groupBy, tuple, order_by_ops);
				}
				else
				{
					// PATTERNs (Rules #6, #7): 
					//	from x1 in e1 from x2 in e3 ... from xk in ek [select v | group v by g]
					//
					// TRANSLATIONs: 
					//  ( e1 ) . SelectMany ( x1 => 
					//		( e2 ) . SelectMany ( x2 =>
					//			...
					//				RESPECTIVELY:
					//				( ek ) . Select ( xk => v )       
					//				( ek ) . GroupBy ( xk => g, xk => v )
					//			... 
					//		)
					//  ) 

					return BuildSelectManyChain(generators, groupBy, v, null);
				}
			}
			else
			{
				// single from-clause (Rules #8 to #11) //

				DirectVarUse x_key = generators[0].KeyVar;
				DirectVarUse x_value = generators[0].ValueVar;

				LinqOp last_op;
				if (select != null)
					last_op = new LinqOp.Select(x_key, x_value, select.Expression);
				else
					last_op = new LinqOp.GroupBy(x_key, x_value, groupBy.GroupExpr, groupBy.ByExpr);

				if (orderBy != null)
				{
					// PATTERNs (Rules #10, #11): 
					//	from x in e orderby k1 , k2, ..., kn [select v | group v by g]
					//
					// TRANSLATIONs:
					//	( e ) . OrderBy ( x => k1 ) . ThenBy ( x => k2 ) ... . ThenBy (x => kn) . Select ( x => v )
					//	( e ) . OrderBy ( x => k1 ) . ThenBy ( x => k2 ) ... . ThenBy (x => kn) . GroupBy ( x => g, x => v )

					return new LinqOpChain(
						generators[0].Expression,
						BuildOrderingOps(x_key, x_value, orderBy.OrderingClauses, last_op)
					);
				}
				else
				{
					// PATTERNs (Rules #8, #9): 
					//	from x in e [select v | group v by g]
					//
					// TRANSLATIONs:
					//	( e ) . Select ( x => v )
					//  ( e ) . GroupBy ( x => g, x => v )

					return new LinqOpChain(generators[0].Expression, last_op);
				}
			}
		}