/IronPython_Main/Runtime/Microsoft.Dynamic/Actions/Calls/ReturnReferenceArgBuilder.cs
C# | 71 lines | 41 code | 12 blank | 18 comment | 2 complexity | 2c531e8355384e4fb964d52c8f337287 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
- /* ****************************************************************************
- *
- * Copyright (c) Microsoft Corporation.
- *
- * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
- * copy of the license can be found in the License.html file at the root of this distribution. If
- * you cannot locate the Apache License, Version 2.0, please send an email to
- * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
- * by the terms of the Apache License, Version 2.0.
- *
- * You must not remove this notice, or any other, from this software.
- *
- *
- * ***************************************************************************/
-
- #if !CLR2
- using System.Linq.Expressions;
- #else
- using Microsoft.Scripting.Ast;
- #endif
-
- using System;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Reflection;
-
- namespace Microsoft.Scripting.Actions.Calls {
- using Ast = Expression;
-
- /// <summary>
- /// Builds a parameter for a reference argument when a StrongBox has not been provided. The
- /// updated return value is returned as one of the resulting return values.
- /// </summary>
- internal sealed class ReturnReferenceArgBuilder : SimpleArgBuilder {
- private ParameterExpression _tmp;
-
- public ReturnReferenceArgBuilder(ParameterInfo info, int index)
- : base(info, info.ParameterType.GetElementType(), index, false, false) {
- }
-
- protected override SimpleArgBuilder Copy(int newIndex) {
- return new ReturnReferenceArgBuilder(ParameterInfo, newIndex);
- }
-
- public override ArgBuilder Clone(ParameterInfo newType) {
- return new ReturnReferenceArgBuilder(newType, Index);
- }
-
- internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
- if (_tmp == null) {
- _tmp = resolver.GetTemporary(Type, "outParam");
- }
-
- return Ast.Block(Ast.Assign(_tmp, base.ToExpression(resolver, args, hasBeenUsed)), _tmp);
- }
-
- internal override Expression ToReturnExpression(OverloadResolver resolver) {
- return _tmp;
- }
-
- internal override Expression ByRefArgument {
- get { return _tmp; }
- }
-
- public override int Priority {
- get {
- return 5;
- }
- }
- }
- }