PageRenderTime 84ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_2_0/Src/IronPython/Runtime/Binding/SetMemberBinder.cs

#
C# | 89 lines | 57 code | 18 blank | 14 comment | 5 complexity | 7679669b4b5e136700742d4e6c81f7c9 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;
  17. using Microsoft.Scripting.Actions;
  18. using Microsoft.Linq.Expressions;
  19. using Microsoft.Scripting.Runtime;
  20. using IronPython.Runtime.Binding;
  21. using IronPython.Runtime.Operations;
  22. using IronPython.Runtime.Types;
  23. namespace IronPython.Runtime.Binding {
  24. using Ast = Microsoft.Linq.Expressions.Expression;
  25. class SetMemberBinder : SetMemberAction, IPythonSite, IExpressionSerializable {
  26. private readonly BinderState/*!*/ _state;
  27. public SetMemberBinder(BinderState/*!*/ binder, string/*!*/ name)
  28. : this(binder, name, false) {
  29. }
  30. public SetMemberBinder(BinderState/*!*/ binder, string/*!*/ name, bool caseInsensitive)
  31. : base(name, caseInsensitive) {
  32. _state = binder;
  33. }
  34. public override MetaObject Fallback(MetaObject self, MetaObject value, MetaObject onBindingError) {
  35. if (self.NeedsDeferral()) {
  36. return Defer(self, value);
  37. }
  38. return Binder.Binder.SetMember(Name, self, value, Ast.Constant(Binder.Context));
  39. }
  40. public BinderState/*!*/ Binder {
  41. get {
  42. return _state;
  43. }
  44. }
  45. public override object HashCookie {
  46. get { return this; }
  47. }
  48. public override int GetHashCode() {
  49. return base.GetHashCode() ^ _state.Binder.GetHashCode();
  50. }
  51. public override bool Equals(object obj) {
  52. SetMemberBinder ob = obj as SetMemberBinder;
  53. if (ob == null) {
  54. return false;
  55. }
  56. return ob._state.Binder == _state.Binder && base.Equals(obj);
  57. }
  58. public override string ToString() {
  59. return "Python SetMember " + Name;
  60. }
  61. #region IExpressionSerializable Members
  62. public Expression CreateExpression() {
  63. return Ast.Call(
  64. typeof(PythonOps).GetMethod("MakeSetAction"),
  65. BindingHelpers.CreateBinderStateExpression(),
  66. Ast.Constant(Name)
  67. );
  68. }
  69. #endregion
  70. }
  71. }