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