PageRenderTime 1ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/Quartz/Runtime/Calls/RubyAccessorInfo.cs

http://quartz.codeplex.com
C# | 98 lines | 69 code | 15 blank | 14 comment | 6 complexity | 5cfe3411f078990f33ff0b7a27a9eb30 MD5 | raw file
Possible License(s): CPL-1.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. * ironruby@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;
  16. using System.Diagnostics;
  17. using System.Reflection;
  18. using IronRuby.Builtins;
  19. using IronRuby.Compiler;
  20. using Microsoft.Scripting.Utils;
  21. using AstUtils = Microsoft.Scripting.Ast.Utils;
  22. namespace IronRuby.Runtime.Calls {
  23. using AstFactory = IronRuby.Compiler.Ast.AstFactory;
  24. public abstract class RubyAttributeAccessorInfo : RubyMemberInfo {
  25. private readonly string/*!*/ _instanceVariableName;
  26. protected string/*!*/ InstanceVariableName { get { return _instanceVariableName; } }
  27. protected RubyAttributeAccessorInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule, string/*!*/ variableName)
  28. : base(flags, declaringModule) {
  29. Assert.NotEmpty(variableName);
  30. Debug.Assert(variableName.StartsWith("@"));
  31. _instanceVariableName = variableName;
  32. }
  33. internal override bool IsDataMember {
  34. get { return true; }
  35. }
  36. public override MemberInfo/*!*/[]/*!*/ GetMembers() {
  37. return Utils.EmptyMemberInfos;
  38. }
  39. }
  40. public sealed class RubyAttributeReaderInfo : RubyAttributeAccessorInfo {
  41. public RubyAttributeReaderInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule, string/*!*/ variableName)
  42. : base(flags, declaringModule, variableName) {
  43. }
  44. internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
  45. var actualArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, 0);
  46. if (!metaBuilder.Error) {
  47. metaBuilder.Result = Methods.GetInstanceVariable.OpCall(
  48. AstUtils.Convert(args.MetaScope.Expression, typeof(RubyScope)),
  49. AstFactory.Box(args.TargetExpression),
  50. AstUtils.Constant(InstanceVariableName)
  51. );
  52. }
  53. }
  54. protected internal override RubyMemberInfo/*!*/ Copy(RubyMemberFlags flags, RubyModule/*!*/ module) {
  55. return new RubyAttributeReaderInfo(flags, module, InstanceVariableName);
  56. }
  57. public override RubyMemberInfo TrySelectOverload(Type/*!*/[]/*!*/ parameterTypes) {
  58. return parameterTypes.Length == 0 ? this : null;
  59. }
  60. }
  61. public sealed class RubyAttributeWriterInfo : RubyAttributeAccessorInfo {
  62. public RubyAttributeWriterInfo(RubyMemberFlags flags, RubyModule/*!*/ declaringModule, string/*!*/ name)
  63. : base(flags, declaringModule, name) {
  64. }
  65. internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
  66. var actualArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 1, 1);
  67. if (!metaBuilder.Error) {
  68. metaBuilder.Result = Methods.SetInstanceVariable.OpCall(
  69. AstFactory.Box(args.TargetExpression),
  70. AstFactory.Box(actualArgs[0].Expression),
  71. AstUtils.Convert(args.MetaScope.Expression, typeof(RubyScope)),
  72. AstUtils.Constant(InstanceVariableName)
  73. );
  74. }
  75. }
  76. protected internal override RubyMemberInfo/*!*/ Copy(RubyMemberFlags flags, RubyModule/*!*/ module) {
  77. return new RubyAttributeWriterInfo(flags, module, InstanceVariableName);
  78. }
  79. public override RubyMemberInfo TrySelectOverload(Type/*!*/[]/*!*/ parameterTypes) {
  80. return parameterTypes.Length == 1 && parameterTypes[0] == typeof(object) ? this : null;
  81. }
  82. }
  83. }