PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/IronPython/Compiler/Ast/GeneratorExpression.cs

#
C# | 82 lines | 54 code | 14 blank | 14 comment | 1 complexity | 081ead57e37cd0fe0dbb121e38f383ff MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16#if !CLR2
17using MSAst = System.Linq.Expressions;
18#else
19using MSAst = Microsoft.Scripting.Ast;
20#endif
21
22using System;
23using System.Diagnostics;
24
25using Microsoft.Scripting.Actions;
26
27using IronPython.Runtime;
28using IronPython.Runtime.Binding;
29
30namespace IronPython.Compiler.Ast {
31    using Ast = MSAst.Expression;
32
33    public class GeneratorExpression : Expression {
34        private readonly FunctionDefinition _function;
35        private readonly Expression _iterable;
36
37        public GeneratorExpression(FunctionDefinition function, Expression iterable) {
38            _function = function;
39            _iterable = iterable;
40        }
41
42        public override MSAst.Expression Reduce() {
43            return Ast.Call(
44                AstMethods.MakeGeneratorExpression,
45                _function.MakeFunctionExpression(),
46                _iterable
47            );
48        }
49
50        public FunctionDefinition Function {
51            get {
52                return _function;
53            }
54        }
55
56        public Expression Iterable {
57            get {
58                return _iterable;
59            }
60        }
61
62        internal override string CheckAssign() {
63            return "can't assign to generator expression";
64        }
65
66        internal override string CheckAugmentedAssign() {
67            return CheckAssign();
68        }
69
70        internal override string CheckDelete() {
71            return "can't delete generator expression";
72        }
73
74        public override void Walk(PythonWalker walker) {
75            if (walker.Walk(this)) {
76                _function.Walk(walker);
77                _iterable.Walk(walker);
78            }
79            walker.PostWalk(this);
80        }
81    }
82}