Exemplo n.º 1
0
        public override MSAst.Expression Reduce()
        {
            MSAst.ParameterExpression list = Ast.Parameter(typeof(List), "list_comprehension_list");

            // 1. Initialization code - create list and store it in the temp variable
            MSAst.Expression initialize =
                Ast.Assign(
                    list,
                    Ast.Call(AstMethods.MakeList)
                    );

            // 2. Create body from _item:   list.Append(_item)
            MSAst.Expression body = GlobalParent.AddDebugInfo(
                Ast.Call(
                    AstMethods.ListAddForComprehension,
                    list,
                    AstUtils.Convert(_item, typeof(object))
                    ),
                _item.Span
                );

            // 3. Transform all iterators in reverse order, building the true body:
            int current = _iterators.Length;

            while (current-- > 0)
            {
                ListComprehensionIterator iterator = _iterators[current];
                body = iterator.Transform(body);
            }

            return(Ast.Block(
                       new[] { list },
                       initialize,
                       body,
                       list                 // result
                       ));
        }
Exemplo n.º 2
0
 public ListComprehension(Expression item, ListComprehensionIterator[] citers)
 {
     this.item = item; this.iters = citers;
 }
Exemplo n.º 3
0
 public ListComprehension(Expression item, ListComprehensionIterator[] iterators) {
     _item = item;
     _iterators = iterators;
 }