PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Runtime/Microsoft.Dynamic/Ast/SkipInterpretExpression.cs

#
C# | 79 lines | 48 code | 12 blank | 19 comment | 6 complexity | d6d8bfd7f3d59e022d7f9a7a4f92640c 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 System.Linq.Expressions;
  17. #else
  18. using Microsoft.Scripting.Ast;
  19. #endif
  20. using System;
  21. namespace Microsoft.Scripting.Ast {
  22. /// <summary>
  23. /// We don't need to insert code to track lines in adaptive mode as the
  24. /// interpreter does that for us. TODO: improve the adaptive compiler so we
  25. /// don't need to do this, and can just remove line tracking from languages
  26. /// </summary>
  27. public sealed class SkipInterpretExpression : Expression {
  28. private readonly Expression _body;
  29. internal SkipInterpretExpression(Expression body) {
  30. if (body.Type != typeof(void)) {
  31. body = Expression.Block(body, Utils.Empty());
  32. }
  33. _body = body;
  34. }
  35. public Expression Body {
  36. get { return _body; }
  37. }
  38. public sealed override Type Type {
  39. get { return typeof(void); }
  40. }
  41. public sealed override ExpressionType NodeType {
  42. get { return ExpressionType.Extension; }
  43. }
  44. public override bool CanReduce {
  45. get { return true; }
  46. }
  47. public override Expression Reduce() {
  48. return _body;
  49. }
  50. protected override Expression VisitChildren(ExpressionVisitor visitor) {
  51. Expression body = visitor.Visit(_body);
  52. if (body == _body) {
  53. return this;
  54. }
  55. return new SkipInterpretExpression(body);
  56. }
  57. }
  58. public static partial class Utils {
  59. public static SkipInterpretExpression SkipInterpret(Expression body) {
  60. var skip = body as SkipInterpretExpression;
  61. if (skip != null) {
  62. return skip;
  63. }
  64. return new SkipInterpretExpression(body);
  65. }
  66. }
  67. }