PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 0ms 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
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 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. * ***************************************************************************/
  15. using System; using Microsoft;
  16. using Microsoft.Scripting.Utils;
  17. namespace Microsoft.Linq.Expressions {
  18. // TODO: probably should not have Annotations, since it's part of TryExpression
  19. // They can either go there on on the body
  20. public sealed class CatchBlock {
  21. private readonly Annotations _annotations;
  22. private readonly Type _test;
  23. private readonly ParameterExpression _var;
  24. private readonly Expression _body;
  25. private readonly Expression _filter;
  26. internal CatchBlock(Annotations annotations, Type test, ParameterExpression target, Expression body, Expression filter) {
  27. _test = test;
  28. _var = target;
  29. _body = body;
  30. _annotations = annotations;
  31. _filter = filter;
  32. }
  33. public Annotations Annotations {
  34. get { return _annotations; }
  35. }
  36. public ParameterExpression Variable {
  37. get { return _var; }
  38. }
  39. public Type Test {
  40. get { return _test; }
  41. }
  42. public Expression Body {
  43. get { return _body; }
  44. }
  45. public Expression Filter {
  46. get {
  47. return _filter;
  48. }
  49. }
  50. }
  51. public partial class Expression {
  52. public static CatchBlock Catch(Type type, Expression body) {
  53. return Catch(type, null, body, null, Annotations.Empty);
  54. }
  55. public static CatchBlock Catch(Type type, ParameterExpression target, Expression body) {
  56. return Catch(type, target, body, null, Annotations.Empty);
  57. }
  58. public static CatchBlock Catch(Type type, ParameterExpression target, Expression body, Expression filter) {
  59. return Catch(type, target, body, filter, Annotations.Empty);
  60. }
  61. public static CatchBlock Catch(Type type, ParameterExpression target, Expression body, Expression filter, Annotations annotations) {
  62. ContractUtils.RequiresNotNull(type, "type");
  63. ContractUtils.Requires(target == null || TypeUtils.AreReferenceAssignable(target.Type, type), "target");
  64. Expression.RequireVariableNotByRef(target, "target");
  65. RequiresCanRead(body, "body");
  66. if (filter != null) {
  67. RequiresCanRead(filter, "filter");
  68. ContractUtils.Requires(filter.Type == typeof(bool), Strings.ArgumentMustBeBoolean);
  69. }
  70. return new CatchBlock(annotations, type, target, body, filter);
  71. }
  72. }
  73. }