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

/IronPython_Main/Runtime/Microsoft.Dynamic/Actions/Calls/ReturnReferenceArgBuilder.cs

#
C# | 71 lines | 41 code | 12 blank | 18 comment | 2 complexity | 2c531e8355384e4fb964d52c8f337287 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;
23using System.Collections.Generic;
24using System.Dynamic;
25using System.Reflection;
26
27namespace Microsoft.Scripting.Actions.Calls {
28    using Ast = Expression;
29
30    /// <summary>
31    /// Builds a parameter for a reference argument when a StrongBox has not been provided.  The
32    /// updated return value is returned as one of the resulting return values.
33    /// </summary>
34    internal sealed class ReturnReferenceArgBuilder : SimpleArgBuilder {
35        private ParameterExpression _tmp;
36
37        public ReturnReferenceArgBuilder(ParameterInfo info, int index)
38            : base(info, info.ParameterType.GetElementType(), index, false, false) {
39        }
40
41        protected override SimpleArgBuilder Copy(int newIndex) {
42            return new ReturnReferenceArgBuilder(ParameterInfo, newIndex);
43        }
44
45        public override ArgBuilder Clone(ParameterInfo newType) {
46            return new ReturnReferenceArgBuilder(newType, Index);
47        }
48
49        internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
50            if (_tmp == null) {
51                _tmp = resolver.GetTemporary(Type, "outParam");
52            }
53
54            return Ast.Block(Ast.Assign(_tmp, base.ToExpression(resolver, args, hasBeenUsed)), _tmp);
55        }
56
57        internal override Expression ToReturnExpression(OverloadResolver resolver) {
58            return _tmp;
59        }
60
61        internal override Expression ByRefArgument {
62            get { return _tmp; }
63        }
64
65        public override int Priority {
66            get {
67                return 5;
68            }
69        }
70    }
71}