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