SetCompilerGenerated is nonsense
[mono.git] / mcs / mcs / symbolwriter.cs
1 //
2 // symbolwriter.cs: The symbol writer
3 //
4 // Author:
5 //   Martin Baulig (martin@ximian.com)
6 //
7 // Copyright 2003 Ximian, Inc.
8 // Copyright 2003-2008 Novell, Inc.
9 //
10
11 using System;
12 using System.Collections;
13 using System.Reflection;
14 using System.Reflection.Emit;
15
16 using Mono.CompilerServices.SymbolWriter;
17
18 namespace Mono.CSharp {
19         public static class SymbolWriter
20         {
21                 public static bool HasSymbolWriter {
22                         get { return symwriter != null; }
23                 }
24
25                 private static SymbolWriterImpl symwriter;
26
27                 class SymbolWriterImpl : MonoSymbolWriter {
28                         delegate int GetILOffsetFunc (ILGenerator ig);
29                         delegate Guid GetGuidFunc (ModuleBuilder mb);
30
31                         GetILOffsetFunc get_il_offset_func;
32                         GetGuidFunc get_guid_func;
33
34                         ModuleBuilder module_builder;
35
36                         public SymbolWriterImpl (ModuleBuilder module_builder, string filename)
37                                 : base (filename)
38                         {
39                                 this.module_builder = module_builder;
40                         }
41
42                         public int GetILOffset (ILGenerator ig)
43                         {
44                                 return get_il_offset_func (ig);
45                         }
46
47                         public void WriteSymbolFile ()
48                         {
49                                 Guid guid = get_guid_func (module_builder);
50                                 WriteSymbolFile (guid);
51                         }
52
53                         public bool Initialize ()
54                         {
55                                 MethodInfo mi = typeof (ILGenerator).GetMethod (
56                                         "Mono_GetCurrentOffset",
57                                         BindingFlags.Static | BindingFlags.NonPublic);
58                                 if (mi == null)
59                                         return false;
60
61                                 get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
62                                         typeof (GetILOffsetFunc), mi);
63
64                                 mi = typeof (ModuleBuilder).GetMethod (
65                                         "Mono_GetGuid",
66                                         BindingFlags.Static | BindingFlags.NonPublic);
67                                 if (mi == null)
68                                         return false;
69
70                                 get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
71                                         typeof (GetGuidFunc), mi);
72
73                                 Location.DefineSymbolDocuments (this);
74
75                                 return true;
76                         }
77                 }
78
79                 public static void DefineLocalVariable (string name, LocalBuilder builder)
80                 {
81                         if (symwriter != null) {
82                                 int index = MonoDebuggerSupport.GetLocalIndex (builder);
83                                 symwriter.DefineLocalVariable (index, name);
84                         }
85                 }
86
87                 public static void OpenMethod (ICompileUnit file, ISourceMethod method)
88                 {
89                         if (symwriter != null)
90                                 symwriter.OpenMethod (file, method);
91                 }
92
93                 public static void CloseMethod ()
94                 {
95                         if (symwriter != null)
96                                 symwriter.CloseMethod ();
97                 }
98
99                 public static int OpenScope (ILGenerator ig)
100                 {
101                         if (symwriter != null) {
102                                 int offset = symwriter.GetILOffset (ig);
103                                 return symwriter.OpenScope (offset);
104                         } else {
105                                 return -1;
106                         }
107                 }
108
109                 public static void CloseScope (ILGenerator ig)
110                 {
111                         if (symwriter != null) {
112                                 int offset = symwriter.GetILOffset (ig);
113                                 symwriter.CloseScope (offset);
114                         }
115                 }
116
117                 public static int DefineNamespace (string name, CompileUnitEntry source,
118                                                    string[] using_clauses, int parent)
119                 {
120                         if (symwriter != null)
121                                 return symwriter.DefineNamespace (name, source, using_clauses, parent);
122                         else
123                                 return -1;
124                 }
125
126 #region Terrania additions
127                 public static void DefineAnonymousScope (int id)
128                 {
129                         if (symwriter != null)
130                                 symwriter.DefineAnonymousScope (id);
131                 }
132
133                 public static void DefineScopeVariable (int scope, LocalBuilder builder)
134                 {
135                         if (symwriter != null) {
136                                 int index = MonoDebuggerSupport.GetLocalIndex (builder);
137                                 symwriter.DefineScopeVariable (scope, index);
138                         }
139                 }
140
141                 public static void DefineScopeVariable (int scope)
142                 {
143                         if (symwriter != null)
144                                 symwriter.DefineScopeVariable (scope, -1);
145                 }
146
147                 public static void DefineCapturedLocal (int scope_id, string name,
148                                                         string captured_name)
149                 {
150                         if (symwriter != null)
151                                 symwriter.DefineCapturedLocal (scope_id, name, captured_name);
152                 }
153
154                 public static void DefineCapturedParameter (int scope_id, string name,
155                                                             string captured_name)
156                 {
157                         if (symwriter != null)
158                                 symwriter.DefineCapturedParameter (scope_id, name, captured_name);
159                 }
160
161                 public static void DefineCapturedThis (int scope_id, string captured_name)
162                 {
163                         if (symwriter != null)
164                                 symwriter.DefineCapturedThis (scope_id, captured_name);
165                 }
166
167                 public static void DefineCapturedScope (int scope_id, int id, string captured_name)
168                 {
169                         if (symwriter != null)
170                                 symwriter.DefineCapturedScope (scope_id, id, captured_name);
171                 }
172
173                 public static void SetRealMethodName (string name)
174                 {
175                         if (symwriter != null)
176                                 symwriter.SetRealMethodName (name);
177                 }
178
179                 [Obsolete ("Duplicates corlib infrastructure")]
180                 public static void SetCompilerGenerated ()
181                 {
182                         if (symwriter != null)
183                                 symwriter.SetCompilerGenerated ();
184                 }
185
186                 public static void OpenCompilerGeneratedBlock (ILGenerator ig)
187                 {
188                         if (symwriter != null) {
189                                 int offset = symwriter.GetILOffset (ig);
190                                 symwriter.OpenCompilerGeneratedBlock (offset);
191                         }
192                 }
193
194                 public static void CloseCompilerGeneratedBlock (ILGenerator ig)
195                 {
196                         if (symwriter != null) {
197                                 int offset = symwriter.GetILOffset (ig);
198                                 symwriter.CloseCompilerGeneratedBlock (offset);
199                         }
200                 }
201
202                 public static void StartIteratorBody (ILGenerator ig)
203                 {
204                         if (symwriter != null) {
205                                 int offset = symwriter.GetILOffset (ig);
206                                 symwriter.StartIteratorBody (offset);
207                         }
208                 }
209
210                 public static void EndIteratorBody (ILGenerator ig)
211                 {
212                         if (symwriter != null) {
213                                 int offset = symwriter.GetILOffset (ig);
214                                 symwriter.EndIteratorBody (offset);
215                         }
216                 }
217
218                 public static void StartIteratorDispatcher (ILGenerator ig)
219                 {
220                         if (symwriter != null) {
221                                 int offset = symwriter.GetILOffset (ig);
222                                 symwriter.StartIteratorDispatcher (offset);
223                         }
224                 }
225
226                 public static void EndIteratorDispatcher (ILGenerator ig)
227                 {
228                         if (symwriter != null) {
229                                 int offset = symwriter.GetILOffset (ig);
230                                 symwriter.EndIteratorDispatcher (offset);
231                         }
232                 }
233 #endregion
234
235                 public static void MarkSequencePoint (ILGenerator ig, Location loc)
236                 {
237                         if (symwriter != null) {
238                                 int offset = symwriter.GetILOffset (ig);
239                                 symwriter.MarkSequencePoint (
240                                         offset, loc.File, loc.Row, loc.Column, loc.Hidden);
241                         }
242                 }
243
244                 public static void WriteSymbolFile ()
245                 {
246                         if (symwriter != null)
247                                 symwriter.WriteSymbolFile ();
248                 }
249
250                 public static bool Initialize (ModuleBuilder module, string filename)
251                 {
252                         symwriter = new SymbolWriterImpl (module, filename);
253                         if (!symwriter.Initialize ()) {
254                                 symwriter = null;
255                                 return false;
256                         }
257
258                         return true;
259                 }
260         }
261 }