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

  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. namespace Microsoft.JScript
  16. {
  17.    
  18.     using System;
  19.     using System.Collections;
  20.     using System.Reflection;
  21.     using System.Reflection.Emit;
  22.    
  23.     public class BlockScope : ActivationObject
  24.     {
  25.         private static int counter = 0;
  26.         internal bool catchHanderScope = false;
  27.        
  28.         internal int scopeId;
  29.         // the following field tracks the JSLocalFields that have to be emitted in a debugger local block
  30.         private ArrayList localFieldsForDebugInfo;
  31.        
  32.         internal BlockScope(ScriptObject parent) : base(parent)
  33.         {
  34.             this.scopeId = BlockScope.counter++;
  35.             this.isKnownAtCompileTime = true;
  36.             this.fast = parent is ActivationObject ? ((ActivationObject)parent).fast : true;
  37.             this.localFieldsForDebugInfo = new ArrayList();
  38.         }
  39.        
  40.         public BlockScope(ScriptObject parent, string name, int scopeId) : base(parent)
  41.         {
  42.             this.scopeId = scopeId;
  43.             JSField field = (JSField)this.parent.GetField(name + ":" + this.scopeId, BindingFlags.Public);
  44.             this.name_table[name] = field;
  45.             this.field_table.Add(field);
  46.         }
  47.        
  48.         internal void AddFieldForLocalScopeDebugInfo(JSLocalField field)
  49.         {
  50.             this.localFieldsForDebugInfo.Add(field);
  51.         }
  52.        
  53.         protected override JSVariableField CreateField(string name, FieldAttributes attributeFlags, object value)
  54.         {
  55.             if (!(this.parent is ActivationObject))
  56.                 return base.CreateField(name, attributeFlags, value);
  57.             JSVariableField field = ((ActivationObject)this.parent).AddNewField(name + ":" + this.scopeId, value, attributeFlags);
  58.             field.debuggerName = name;
  59.             return field;
  60.         }
  61.        
  62.         internal void EmitLocalInfoForFields(ILGenerator il)
  63.         {
  64.             foreach (JSLocalField field in this.localFieldsForDebugInfo) {
  65.                 ((LocalBuilder)field.metaData).SetLocalSymInfo(field.debuggerName);
  66.             }
  67.             if (this.parent is GlobalScope) {
  68.                 LocalBuilder loc = il.DeclareLocal(Typeob.Int32);
  69.                 loc.SetLocalSymInfo("scopeId for catch block");
  70.                 ConstantWrapper.TranslateToILInt(il, this.scopeId);
  71.                 il.Emit(OpCodes.Stloc, loc);
  72.             }
  73.         }
  74.        
  75.     }
  76. }

Developer Fusion