* DataGrid.cs (set_CurrentCell): because EnsureCellVisibility
[mono-project.git] / mcs / class / Mono.CompilerServices.SymbolWriter / SymbolWriterImpl.cs
blob4d4bc83a0a3637274085765188ad52c4854aad81
1 //
2 // SymbolWriterImpl.cs
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005 Novell, Inc. http://www.novell.com
8 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Reflection;
33 using System.Reflection.Emit;
34 using System.Runtime.CompilerServices;
35 using System.Collections;
36 using System.IO;
37 using System.Diagnostics.SymbolStore;
39 namespace Mono.CompilerServices.SymbolWriter
41 public class SymbolWriterImpl: ISymbolWriter
43 MonoSymbolWriter msw;
44 ModuleBuilder mb;
46 delegate Guid GetGuidFunc (ModuleBuilder mb);
47 GetGuidFunc get_guid_func;
49 int nextLocalIndex;
50 int currentToken;
51 string methodName;
52 Stack namespaceStack = new Stack ();
53 bool methodOpened;
55 Hashtable documents = new Hashtable ();
57 public SymbolWriterImpl (ModuleBuilder mb)
59 this.mb = mb;
62 public void Close ()
64 MethodInfo mi = typeof (ModuleBuilder).GetMethod (
65 "Mono_GetGuid",
66 BindingFlags.Static | BindingFlags.NonPublic);
67 if (mi == null)
68 return;
70 get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
71 typeof (GetGuidFunc), mi);
73 msw.WriteSymbolFile (get_guid_func (mb));
76 public void CloseMethod ()
78 if (methodOpened) {
79 methodOpened = false;
80 nextLocalIndex = 0;
81 msw.CloseMethod ();
85 public void CloseNamespace ()
87 namespaceStack.Pop ();
88 msw.CloseNamespace ();
91 public void CloseScope (int endOffset)
93 msw.CloseScope (endOffset);
96 public ISymbolDocumentWriter DefineDocument (
97 string url,
98 Guid language,
99 Guid languageVendor,
100 Guid documentType)
102 SymbolDocumentWriterImpl doc = (SymbolDocumentWriterImpl) documents [url];
103 if (doc == null) {
104 doc = new SymbolDocumentWriterImpl (msw.DefineDocument (url));
105 documents [url] = doc;
107 return doc;
110 public void DefineField (
111 SymbolToken parent,
112 string name,
113 FieldAttributes attributes,
114 byte[] signature,
115 SymAddressKind addrKind,
116 int addr1,
117 int addr2,
118 int addr3)
122 public void DefineGlobalVariable (
123 string name,
124 FieldAttributes attributes,
125 byte[] signature,
126 SymAddressKind addrKind,
127 int addr1,
128 int addr2,
129 int addr3)
133 public void DefineLocalVariable (
134 string name,
135 FieldAttributes attributes,
136 byte[] signature,
137 SymAddressKind addrKind,
138 int addr1,
139 int addr2,
140 int addr3,
141 int startOffset,
142 int endOffset)
144 msw.DefineLocalVariable (nextLocalIndex++, name, signature);
147 public void DefineParameter (
148 string name,
149 ParameterAttributes attributes,
150 int sequence,
151 SymAddressKind addrKind,
152 int addr1,
153 int addr2,
154 int addr3)
158 public void DefineSequencePoints (
159 ISymbolDocumentWriter document,
160 int[] offsets,
161 int[] lines,
162 int[] columns,
163 int[] endLines,
164 int[] endColumns)
166 for (int n=0; n<offsets.Length; n++) {
167 if (n > 0 && offsets[n] == offsets[n-1] && lines[n] == lines[n-1] && columns[n] == columns[n-1])
168 continue;
169 msw.MarkSequencePoint (offsets[n], lines[n], columns[n]);
173 public void Initialize (IntPtr emitter, string filename, bool fFullBuild)
175 msw = new MonoSymbolWriter (filename);
178 public void OpenMethod (SymbolToken method)
180 currentToken = method.GetToken ();
183 public void OpenNamespace (string name)
185 NamespaceInfo n = new NamespaceInfo ();
186 n.NamespaceID = -1;
187 n.Name = name;
188 namespaceStack.Push (n);
191 public int OpenScope (int startOffset)
193 return msw.OpenScope (startOffset);
196 public void SetMethodSourceRange (
197 ISymbolDocumentWriter startDoc,
198 int startLine,
199 int startColumn,
200 ISymbolDocumentWriter endDoc,
201 int endLine,
202 int endColumn)
204 SourceMethodImpl sm = new SourceMethodImpl (methodName, currentToken, GetCurrentNamespace (startDoc));
205 msw.OpenMethod (startDoc as ISourceFile, sm, startLine, startColumn, endLine, endColumn);
206 methodOpened = true;
209 public void SetScopeRange (int scopeID, int startOffset, int endOffset)
213 public void SetSymAttribute (SymbolToken parent, string name, byte[] data)
215 // This is a hack! but MonoSymbolWriter needs the method name
216 // and ISymbolWriter does not have any method for providing it
217 if (name == "__name")
218 methodName = System.Text.Encoding.UTF8.GetString (data);
221 public void SetUnderlyingWriter (IntPtr underlyingWriter)
225 public void SetUserEntryPoint (SymbolToken entryMethod)
229 public void UsingNamespace (string fullName)
231 if (namespaceStack.Count == 0) {
232 OpenNamespace ("");
235 NamespaceInfo ni = (NamespaceInfo) namespaceStack.Peek ();
236 if (ni.NamespaceID != -1) {
237 NamespaceInfo old = ni;
238 CloseNamespace ();
239 OpenNamespace (old.Name);
240 ni = (NamespaceInfo) namespaceStack.Peek ();
241 ni.UsingClauses = old.UsingClauses;
243 ni.UsingClauses.Add (fullName);
246 int GetCurrentNamespace (ISymbolDocumentWriter doc)
248 if (namespaceStack.Count == 0) {
249 OpenNamespace ("");
252 NamespaceInfo ni = (NamespaceInfo) namespaceStack.Peek ();
253 if (ni.NamespaceID == -1)
255 string[] usings = (string[]) ni.UsingClauses.ToArray (typeof(string));
257 int parentId = 0;
258 if (namespaceStack.Count > 1) {
259 namespaceStack.Pop ();
260 parentId = ((NamespaceInfo) namespaceStack.Peek ()).NamespaceID;
261 namespaceStack.Push (ni);
264 ni.NamespaceID = msw.DefineNamespace (ni.Name, ((ISourceFile)doc).Entry, usings, parentId);
266 return ni.NamespaceID;
270 class SymbolDocumentWriterImpl: ISymbolDocumentWriter, ISourceFile
272 SourceFileEntry entry;
274 public SymbolDocumentWriterImpl (SourceFileEntry e)
276 entry = e;
279 public void SetCheckSum (Guid algorithmId, byte[] checkSum)
283 public void SetSource (byte[] source)
287 public SourceFileEntry Entry {
288 get { return entry; }
292 class SourceMethodImpl: ISourceMethod
294 string name;
295 int token;
296 int namespaceID;
298 public SourceMethodImpl (string name, int token, int namespaceID)
300 this.name = name;
301 this.token = token;
302 this.namespaceID = namespaceID;
305 public string Name {
306 get { return name; }
309 public int NamespaceID {
310 get { return namespaceID; }
313 public int Token {
314 get { return token; }
318 class NamespaceInfo
320 public string Name;
321 public int NamespaceID;
322 public ArrayList UsingClauses = new ArrayList ();