Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Parser/mcs/symbolwriter.cs @ 15888

Last change on this file since 15888 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 5.3 KB
Line 
1//
2// symbolwriter.cs: The debug symbol writer
3//
4// Authors: Martin Baulig (martin@ximian.com)
5//          Marek Safar (marek.safar@gmail.com)
6//
7// Dual licensed under the terms of the MIT X11 or GNU GPL
8//
9// Copyright 2003 Ximian, Inc (http://www.ximian.com)
10// Copyright 2004-2010 Novell, Inc
11//
12
13using System;
14
15#if STATIC
16using IKVM.Reflection;
17using IKVM.Reflection.Emit;
18#else
19using System.Reflection;
20using System.Reflection.Emit;
21#endif
22
23using Mono.CompilerServices.SymbolWriter;
24
25namespace Mono.CSharp
26{
27  static class SymbolWriter
28  {
29#if !NET_4_0 && !STATIC
30    delegate int GetILOffsetFunc (ILGenerator ig);
31    static GetILOffsetFunc get_il_offset_func;
32
33    delegate Guid GetGuidFunc (ModuleBuilder mb);
34    static GetGuidFunc get_guid_func;
35
36    static void Initialize ()
37    {
38      var mi = typeof (ILGenerator).GetMethod (
39        "Mono_GetCurrentOffset",
40        BindingFlags.Static | BindingFlags.NonPublic);
41      if (mi == null)
42        throw new MissingMethodException ("Mono_GetCurrentOffset");
43
44      get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
45        typeof (GetILOffsetFunc), mi);
46
47      mi = typeof (ModuleBuilder).GetMethod (
48        "Mono_GetGuid",
49        BindingFlags.Static | BindingFlags.NonPublic);
50      if (mi == null)
51        throw new MissingMethodException ("Mono_GetGuid");
52
53      get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
54        typeof (GetGuidFunc), mi);
55    }
56#endif
57
58    static int GetILOffset (ILGenerator ig)
59    {
60#if NET_4_0 || STATIC
61      return ig.ILOffset;
62#else
63      if (get_il_offset_func == null)
64        Initialize ();
65
66      return get_il_offset_func (ig);
67#endif
68    }
69
70    public static Guid GetGuid (ModuleBuilder module)
71    {
72#if NET_4_0 || STATIC
73      return module.ModuleVersionId;
74#else
75      if (get_guid_func == null)
76        Initialize ();
77
78      return get_guid_func (module);
79#endif
80    }
81
82    public static bool HasSymbolWriter {
83      get { return symwriter != null; }
84    }
85
86    public static MonoSymbolWriter symwriter;
87
88    public static void DefineLocalVariable (string name, LocalBuilder builder)
89    {
90      if (symwriter != null) {
91        symwriter.DefineLocalVariable (builder.LocalIndex, name);
92      }
93    }
94
95    public static SourceMethodBuilder OpenMethod (ICompileUnit file, IMethodDef method)
96    {
97      if (symwriter != null)
98        return symwriter.OpenMethod (file, -1 /* Not used */, method);
99      else
100        return null;
101    }
102
103    public static void CloseMethod ()
104    {
105      if (symwriter != null)
106        symwriter.CloseMethod ();
107    }
108
109    public static int OpenScope (ILGenerator ig)
110    {
111      if (symwriter != null) {
112        int offset = GetILOffset (ig);
113        return symwriter.OpenScope (offset);
114      } else {
115        return -1;
116      }
117    }
118
119    public static void CloseScope (ILGenerator ig)
120    {
121      if (symwriter != null) {
122        int offset = GetILOffset (ig);
123        symwriter.CloseScope (offset);
124      }
125    }
126
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        symwriter.DefineScopeVariable (scope, builder.LocalIndex);
137      }
138    }
139
140    public static void DefineScopeVariable (int scope)
141    {
142      if (symwriter != null)
143        symwriter.DefineScopeVariable (scope, -1);
144    }
145
146    public static void DefineCapturedLocal (int scope_id, string name,
147              string captured_name)
148    {
149      if (symwriter != null)
150        symwriter.DefineCapturedLocal (scope_id, name, captured_name);
151    }
152
153    public static void DefineCapturedParameter (int scope_id, string name,
154                  string captured_name)
155    {
156      if (symwriter != null)
157        symwriter.DefineCapturedParameter (scope_id, name, captured_name);
158    }
159
160    public static void DefineCapturedThis (int scope_id, string captured_name)
161    {
162      if (symwriter != null)
163        symwriter.DefineCapturedThis (scope_id, captured_name);
164    }
165
166    public static void DefineCapturedScope (int scope_id, int id, string captured_name)
167    {
168      if (symwriter != null)
169        symwriter.DefineCapturedScope (scope_id, id, captured_name);
170    }
171
172    public static void OpenCompilerGeneratedBlock (EmitContext ec)
173    {
174      if (symwriter != null) {
175        int offset = GetILOffset (ec.ig);
176        symwriter.OpenCompilerGeneratedBlock (offset);
177      }
178    }
179
180    public static void CloseCompilerGeneratedBlock (EmitContext ec)
181    {
182      if (symwriter != null) {
183        int offset = GetILOffset (ec.ig);
184        symwriter.CloseCompilerGeneratedBlock (offset);
185      }
186    }
187
188    public static void StartIteratorBody (EmitContext ec)
189    {
190      if (symwriter != null) {
191        int offset = GetILOffset (ec.ig);
192        symwriter.StartIteratorBody (offset);
193      }
194    }
195
196    public static void EndIteratorBody (EmitContext ec)
197    {
198      if (symwriter != null) {
199        int offset = GetILOffset (ec.ig);
200        symwriter.EndIteratorBody (offset);
201      }
202    }
203
204    public static void StartIteratorDispatcher (EmitContext ec)
205    {
206      if (symwriter != null) {
207        int offset = GetILOffset (ec.ig);
208        symwriter.StartIteratorDispatcher (offset);
209      }
210    }
211
212    public static void EndIteratorDispatcher (EmitContext ec)
213    {
214      if (symwriter != null) {
215        int offset = GetILOffset (ec.ig);
216        symwriter.EndIteratorDispatcher (offset);
217      }
218    }
219
220    public static void MarkSequencePoint (ILGenerator ig, Location loc)
221    {
222      if (symwriter != null) {
223        SourceFileEntry file = loc.SourceFile.SourceFileEntry;
224        int offset = GetILOffset (ig);
225        symwriter.MarkSequencePoint (offset, file, loc.Row, loc.Column, false);
226      }
227    }
228
229    public static void Reset ()
230    {
231      symwriter = null;
232    }
233  }
234}
Note: See TracBrowser for help on using the repository browser.