The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ AddressOf

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /* This class records the fact that the operand was preceded by an & operator. */
  16. namespace Microsoft.JScript
  17. {
  18.    
  19.     using System;
  20.     using System.Reflection;
  21.     using System.Reflection.Emit;
  22.    
  23.     internal sealed class AddressOf : UnaryOp
  24.     {
  25.        
  26.         internal AddressOf(Context context, AST operand) : base(context, operand)
  27.         {
  28.             Debug.Assert(operand is Member || operand is Lookup);
  29.         }
  30.        
  31.         internal override object Evaluate()
  32.         {
  33.             return this.operand.Evaluate();
  34.         }
  35.        
  36.         internal FieldInfo GetField()
  37.         {
  38.             //Used to detect local variables used as out parameters
  39.             //Such locals are not restored when returning from a call out of a function that must
  40.             //save its stack locals for use by nested functions
  41.             if (!(this.operand is Binding))
  42.                 return null;
  43.             MemberInfo result = ((Binding)this.operand).member;
  44.             if (result is FieldInfo)
  45.                 return (FieldInfo)result;
  46.             return null;
  47.         }
  48.        
  49.         internal override IReflect InferType(JSField inference_target)
  50.         {
  51.             return this.operand.InferType(inference_target);
  52.         }
  53.        
  54.         internal override AST PartiallyEvaluate()
  55.         {
  56.             this.operand = this.operand.PartiallyEvaluate();
  57.             if (!(this.operand is Binding) || !((Binding)this.operand).RefersToMemoryLocation())
  58.                 this.context.HandleError(JSError.DoesNotHaveAnAddress);
  59.             return this;
  60.         }
  61.        
  62.         internal override void TranslateToIL(ILGenerator il, Type rtype)
  63.         {
  64.             this.operand.TranslateToIL(il, rtype);
  65.         }
  66.        
  67.         internal override void TranslateToILPreSet(ILGenerator il)
  68.         {
  69.             this.operand.TranslateToILPreSet(il);
  70.         }
  71.        
  72.         internal override object TranslateToILReference(ILGenerator il, Type rtype)
  73.         {
  74.             return this.operand.TranslateToILReference(il, rtype);
  75.         }
  76.        
  77.         internal override void TranslateToILSet(ILGenerator il, AST rhvalue)
  78.         {
  79.             this.operand.TranslateToILSet(il, rhvalue);
  80.         }
  81.     }
  82. }

Developer Fusion