2002-03-23 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / LocalBuilder.cs
1
2 //
3 // System.Reflection.Emit/LocalBuilder.cs
4 //
5 // Authors:
6 //   Paolo Molaro (lupus@ximian.com)
7 //   Martin Baulig (martin@gnome.org)
8 //   Miguel de Icaza (miguel@ximian.com)
9 //
10 // (C) 2001, 2002 Ximian, Inc.  http://www.ximian.com
11 //
12
13 using System;
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Globalization;
17 using System.Runtime.CompilerServices;
18 using System.Diagnostics.SymbolStore;
19
20 namespace System.Reflection.Emit {
21         public sealed class LocalBuilder {
22                 //
23                 // These are kept in sync with reflection.h
24                 //
25                 #region Sync with reflection.h
26                 private Type type;
27                 private string name;
28                 #endregion
29                 
30                 //
31                 // Order does not matter after here
32                 //
33                 private ModuleBuilder module;
34                 internal int position;
35
36                 internal LocalBuilder (ModuleBuilder m, Type t)
37                 {
38                         this.module = m;
39                         this.type = t;
40                 }
41                 public void SetLocalSymInfo (string lname, int startOffset, int endOffset)
42                 {
43                         ISymbolWriter symbol_writer = module.GetSymWriter ();
44                         name = lname;
45
46                         if (symbol_writer == null)
47                                 return;
48
49                         SignatureHelper sig_helper = SignatureHelper.GetLocalVarSigHelper (module);
50
51                         sig_helper.AddArgument (type);
52
53                         byte[] signature = sig_helper.GetSignature ();
54
55                         symbol_writer.DefineLocalVariable (name, FieldAttributes.Private,
56                                                            signature, SymAddressKind.ILOffset,
57                                                            position, 0, 0,
58                                                            startOffset, endOffset);
59                 }
60
61                 public void SetLocalSymInfo (string lname)
62                 {
63                         SetLocalSymInfo (lname, 0, 0);
64                 }
65
66
67                 public Type LocalType
68                 {
69                         get {
70                                 return type;
71                         }
72                 }
73         }
74 }