PageRenderTime 624ms CodeModel.GetById 16ms RepoModel.GetById 1ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. #if !CLR2
  16. using MSAst = System.Linq.Expressions;
  17. #else
  18. using MSAst = Microsoft.Scripting.Ast;
  19. #endif
  20. using System;
  21. using System.Diagnostics;
  22. using Microsoft.Scripting.Actions;
  23. using IronPython.Runtime;
  24. using IronPython.Runtime.Binding;
  25. namespace IronPython.Compiler.Ast {
  26. using Ast = MSAst.Expression;
  27. public class GeneratorExpression : Expression {
  28. private readonly FunctionDefinition _function;
  29. private readonly Expression _iterable;
  30. public GeneratorExpression(FunctionDefinition function, Expression iterable) {
  31. _function = function;
  32. _iterable = iterable;
  33. }
  34. public override MSAst.Expression Reduce() {
  35. return Ast.Call(
  36. AstMethods.MakeGeneratorExpression,
  37. _function.MakeFunctionExpression(),
  38. _iterable
  39. );
  40. }
  41. public FunctionDefinition Function {
  42. get {
  43. return _function;
  44. }
  45. }
  46. public Expression Iterable {
  47. get {
  48. return _iterable;
  49. }
  50. }
  51. internal override string CheckAssign() {
  52. return "can't assign to generator expression";
  53. }
  54. internal override string CheckAugmentedAssign() {
  55. return CheckAssign();
  56. }
  57. internal override string CheckDelete() {
  58. return "can't delete generator expression";
  59. }
  60. public override void Walk(PythonWalker walker) {
  61. if (walker.Walk(this)) {
  62. _function.Walk(walker);
  63. _iterable.Walk(walker);
  64. }
  65. walker.PostWalk(this);
  66. }
  67. }
  68. }