PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_2_0/Src/Microsoft.Scripting.Core/Ast/CatchBlock.cs

#
C# | 88 lines | 57 code | 15 blank | 16 comment | 5 complexity | 4e7c67a4755718641e0d63110e157604 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Microsoft Public License. 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  Microsoft Public License, 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 Microsoft Public License.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15using System; using Microsoft;
16
17
18using Microsoft.Scripting.Utils;
19
20namespace Microsoft.Linq.Expressions {
21
22    // TODO: probably should not have Annotations, since it's part of TryExpression
23    // They can either go there on on the body
24    public sealed class CatchBlock {
25        private readonly Annotations _annotations;
26        private readonly Type _test;
27        private readonly ParameterExpression _var;
28        private readonly Expression _body;
29        private readonly Expression _filter;
30
31        internal CatchBlock(Annotations annotations, Type test, ParameterExpression target, Expression body, Expression filter) {
32            _test = test;
33            _var = target;
34            _body = body;
35            _annotations = annotations;
36            _filter = filter;
37        }
38
39        public Annotations Annotations {
40            get { return _annotations; }
41        }
42
43        public ParameterExpression Variable {
44            get { return _var; }
45        }
46
47        public Type Test {
48            get { return _test; }
49        }
50
51        public Expression Body {
52            get { return _body; }
53        }
54
55        public Expression Filter {
56            get {
57                return _filter;
58            }
59        }
60    }
61
62    public partial class Expression {
63        public static CatchBlock Catch(Type type, Expression body) {
64            return Catch(type, null, body, null, Annotations.Empty);
65        }
66
67        public static CatchBlock Catch(Type type, ParameterExpression target, Expression body) {
68            return Catch(type, target, body, null, Annotations.Empty);
69        }
70
71        public static CatchBlock Catch(Type type, ParameterExpression target, Expression body, Expression filter) {
72            return Catch(type, target, body, filter, Annotations.Empty);
73        }
74
75        public static CatchBlock Catch(Type type, ParameterExpression target, Expression body, Expression filter, Annotations annotations) {
76            ContractUtils.RequiresNotNull(type, "type");
77            ContractUtils.Requires(target == null || TypeUtils.AreReferenceAssignable(target.Type, type), "target");
78            Expression.RequireVariableNotByRef(target, "target");
79            RequiresCanRead(body, "body");
80            if (filter != null) {
81                RequiresCanRead(filter, "filter");
82                ContractUtils.Requires(filter.Type == typeof(bool), Strings.ArgumentMustBeBoolean);
83            }
84
85            return new CatchBlock(annotations, type, target, body, filter);
86        }
87    }
88}