Esempio n. 1
0
			public SelectMany(DirectVarUse keyVar, DirectVarUse valueVar, LinqOpChain innerChain)
			{
				this.keyVar = keyVar;
				this.valueVar = valueVar;
				this.innerChain = innerChain;
			}
Esempio n. 2
0
			public Select(DirectVarUse keyVar, DirectVarUse valueVar, SelectClause clause)
				: this(keyVar, valueVar, clause.Expression)
			{
			}
Esempio n. 3
0
			public Select(DirectVarUse keyVar, DirectVarUse valueVar, Expression selector)
			{
				this.keyVar = keyVar;
				this.valueVar = valueVar;
				this.selector = selector;
			}
Esempio n. 4
0
			public Where(DirectVarUse keyVar, DirectVarUse valueVar, Expression predicate)
			{
				this.keyVar = keyVar;
				this.valueVar = valueVar;
				this.predicate = predicate;
			}
Esempio n. 5
0
			public OrderBy(DirectVarUse keyVar, DirectVarUse valueVar, Expression expression,
				Ordering ordering, LinqOp next, bool isThenBy)
			{
				this.keyVar = keyVar;
				this.valueVar = valueVar;
				this.expression = expression;
				this.ordering = ordering;
				this.next = next;
				this.isThenBy = isThenBy;
			}
Esempio n. 6
0
        private void FromWhereToGenerators(List <Generator> /*!*/ generators)
        {
            // query is the inner-most query - it will be converted to OpChain //

            int i = 0;

            for (; ;)
            {
                // convert from clauses to generators if there are any;
                // (the query can start with where-clause if there was an into-clause):
                while (i < fromWhere.Count && fromWhere[i].IsFromClause)
                {
                    FromClause f = (FromClause)fromWhere[i];

                    // each from-clause contains at least one generator:
                    Debug.Assert(f.Generators.Count > 0);

                    // adds generators contained in the from clause (Rule #2):
                    foreach (Generator generator in f.Generators)
                    {
                        generators.Add(generator);
                    }

                    i++;
                }

                // no more clauses:
                if (i == fromWhere.Count)
                {
                    break;
                }

                // where-clause follows; at least one generator has been added:
                Debug.Assert(fromWhere[i].IsWhereClause && generators.Count > 0);

                Generator last_generator = generators[generators.Count - 1];

                DirectVarUse x_key   = last_generator.KeyVar;
                DirectVarUse x_value = last_generator.ValueVar;

                LinqOpChain chain   = null;
                LinqOp      last_op = null;

                // embeds where-clauses imediately preceded by a from-clause to
                // the last generator of the from-clause (Rule #3):
                do
                {
                    LinqOp.Where where_op = new LinqOp.Where(x_key, x_value, ((WhereClause)fromWhere[i]).Expression);

                    if (last_op == null)
                    {
                        chain = new LinqOpChain(last_generator.Expression, where_op);
                    }
                    else
                    {
                        last_op.Next = where_op;
                    }

                    last_op = where_op;
                    i++;
                }while (i < fromWhere.Count && fromWhere[i].IsWhereClause);

                Debug.Assert(chain != null);
                last_generator.Expression = chain;

                // no more clauses:
                if (i == fromWhere.Count)
                {
                    break;
                }
            }
        }
Esempio n. 7
0
		public Generator(Position p, Expression/*!*/ expression, DirectVarUse keyVar, DirectVarUse/*!*/ valueVar)
			: base(p)
		{
			Debug.Assert(expression != null && valueVar != null);

			this.expression = expression;
			this.keyVar = keyVar;
			this.valueVar = valueVar;
		}
Esempio n. 8
0
 public SelectMany(DirectVarUse keyVar, DirectVarUse valueVar, LinqOpChain innerChain)
 {
     this.keyVar     = keyVar;
     this.valueVar   = valueVar;
     this.innerChain = innerChain;
 }
Esempio n. 9
0
		private static LinqOp BuildOrderingOps(DirectVarUse keyVar, DirectVarUse valueVar,
			List<OrderingClause>/*!*/ clauses, LinqOp lastOp)
		{
			// PATTERNs: 
			//	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 )

			Debug.Assert(clauses != null && clauses.Count > 0);

			for (int i = clauses.Count - 1; i >= 0; i--)
				lastOp = new LinqOp.OrderBy(keyVar, valueVar, clauses[i].Expression, clauses[i].Ordering, lastOp, i != 0);

			return lastOp;
		}
Esempio n. 10
0
 public Select(DirectVarUse keyVar, DirectVarUse valueVar, SelectClause clause)
     : this(keyVar, valueVar, clause.Expression)
 {
 }
Esempio n. 11
0
 public Select(DirectVarUse keyVar, DirectVarUse valueVar, Expression selector)
 {
     this.keyVar   = keyVar;
     this.valueVar = valueVar;
     this.selector = selector;
 }
Esempio n. 12
0
 public Where(DirectVarUse keyVar, DirectVarUse valueVar, Expression predicate)
 {
     this.keyVar    = keyVar;
     this.valueVar  = valueVar;
     this.predicate = predicate;
 }
Esempio n. 13
0
        public Generator(Position p, Expression /*!*/ expression, DirectVarUse keyVar, DirectVarUse /*!*/ valueVar)
            : base(p)
        {
            Debug.Assert(expression != null && valueVar != null);

            this.expression = expression;
            this.keyVar     = keyVar;
            this.valueVar   = valueVar;
        }
Esempio n. 14
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));
                }
            }
        }
Esempio n. 15
0
			public GroupBy(DirectVarUse keyVar, DirectVarUse valueVar, GroupByClause clause)
				: this(keyVar, valueVar, clause.GroupExpr, clause.ByExpr)
			{
			}
Esempio n. 16
0
		public IntoClause(Position p, DirectVarUse keyVar, DirectVarUse/*!*/ valueVar, QueryBody/*!*/ nextQuery)
			: base(p)
		{
			Debug.Assert(valueVar != null && nextQuery != null);

			this.keyVar = keyVar;
			this.valueVar = valueVar;
			this.nextQuery = nextQuery;
		}
Esempio n. 17
0
			public GroupBy(DirectVarUse keyVar, DirectVarUse valueVar, Expression groupExpr, Expression byExpr)
			{
				this.keyVar = keyVar;
				this.valueVar = valueVar;
				this.groupExpr = groupExpr;
				this.byExpr = byExpr;
			}
Esempio n. 18
0
 public GroupBy(DirectVarUse keyVar, DirectVarUse valueVar, GroupByClause clause)
     : this(keyVar, valueVar, clause.GroupExpr, clause.ByExpr)
 {
 }