Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / IKVM.Reflection / Impl / MdbWriter.cs
1 /*
2   Copyright (C) 2009 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 #if MONO
25 using System;
26 using System.Collections.Generic;
27 using Mono.CompilerServices.SymbolWriter;
28 using IKVM.Reflection.Emit;
29
30 namespace IKVM.Reflection.Impl
31 {
32         sealed class Method : IMethodDef
33         {
34                 internal int token;
35                 internal string name;
36                 internal SymbolDocumentWriter document;
37                 internal int[] offsets;
38                 internal int[] lines;
39                 internal int[] columns;
40                 internal List<string> variables = new List<string>();
41
42                 public string Name
43                 {
44                         get { return name; }
45                 }
46
47                 public int Token
48                 {
49                         get { return token; }
50                 }
51         }
52
53         sealed class SymbolDocumentWriter : System.Diagnostics.SymbolStore.ISymbolDocumentWriter
54         {
55                 internal readonly string url;
56                 internal SourceFileEntry source;
57
58                 internal SymbolDocumentWriter(string url)
59                 {
60                         this.url = url;
61                 }
62
63                 public void SetCheckSum(Guid algorithmId, byte[] checkSum)
64                 {
65                 }
66
67                 public void SetSource(byte[] source)
68                 {
69                 }
70         }
71
72         sealed class MdbWriter : ISymbolWriterImpl
73         {
74                 private readonly ModuleBuilder moduleBuilder;
75                 private readonly Dictionary<int, Method> methods = new Dictionary<int, Method>();
76                 private readonly Dictionary<string, SymbolDocumentWriter> documents = new Dictionary<string, SymbolDocumentWriter>();
77                 private Method currentMethod;
78
79                 internal MdbWriter(ModuleBuilder moduleBuilder)
80                 {
81                         this.moduleBuilder = moduleBuilder;
82                 }
83
84                 public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
85                 {
86                         return Empty<byte>.Array;
87                 }
88
89                 public void RemapToken(int oldToken, int newToken)
90                 {
91                         if (methods.ContainsKey(oldToken))
92                         {
93                                 methods[oldToken].token = newToken;
94                         }
95                 }
96
97                 public void Close()
98                 {
99                         MonoSymbolWriter writer = new MonoSymbolWriter(moduleBuilder.FullyQualifiedName);
100
101                         foreach (Method method in methods.Values)
102                         {
103                                 if (method.document != null)
104                                 {
105                                         if (method.document.source == null)
106                                         {
107                                                 method.document.source = new SourceFileEntry(writer.SymbolFile, method.document.url);
108                                         }
109                                         ICompileUnit file = new CompileUnitEntry(writer.SymbolFile, method.document.source);
110                                         SourceMethodBuilder smb = writer.OpenMethod(file, 0, method);
111                                         for (int i = 0; i < method.offsets.Length; i++)
112                                         {
113                                                 smb.MarkSequencePoint(method.offsets[i], method.document.source, method.lines[i], method.columns[i], false);
114                                         }
115                                         for (int i = 0; i < method.variables.Count; i++)
116                                         {
117                                                 writer.DefineLocalVariable(i, method.variables[i]);
118                                         }
119                                         writer.CloseMethod();
120                                 }
121                         }
122
123                         writer.WriteSymbolFile(moduleBuilder.ModuleVersionId);
124                 }
125
126                 public System.Diagnostics.SymbolStore.ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
127                 {
128                         SymbolDocumentWriter writer;
129                         if (!documents.TryGetValue(url, out writer))
130                         {
131                                 writer = new SymbolDocumentWriter(url);
132                                 documents.Add(url, writer);
133                         }
134                         return writer;
135                 }
136
137                 public void OpenMethod(System.Diagnostics.SymbolStore.SymbolToken method)
138                 {
139                         throw new NotImplementedException();
140                 }
141
142                 public void OpenMethod(System.Diagnostics.SymbolStore.SymbolToken token, MethodBase mb)
143                 {
144                         Method method = new Method();
145                         method.token = token.GetToken();
146                         method.name = mb.Name;
147                         methods.Add(token.GetToken(), method);
148                         currentMethod = method;
149                 }
150
151                 public void CloseMethod()
152                 {
153                         currentMethod = null;
154                 }
155
156                 public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
157                 {
158                 }
159
160                 public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
161                 {
162                         currentMethod.variables.Add(name);
163                 }
164
165                 public void DefineSequencePoints(System.Diagnostics.SymbolStore.ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
166                 {
167                         currentMethod.document = (SymbolDocumentWriter)document;
168                         currentMethod.offsets = offsets;
169                         currentMethod.lines = lines;
170                         currentMethod.columns = columns;
171                 }
172
173                 public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3)
174                 {
175                 }
176
177                 public void DefineField(System.Diagnostics.SymbolStore.SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3)
178                 {
179                 }
180
181                 public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3)
182                 {
183                 }
184
185                 public void OpenNamespace(string name)
186                 {
187                 }
188
189                 public void CloseNamespace()
190                 {
191                 }
192
193                 public void UsingNamespace(string fullName)
194                 {
195                 }
196
197                 public int OpenScope(int startOffset)
198                 {
199                         return 0;
200                 }
201
202                 public void CloseScope(int endOffset)
203                 {
204                 }
205
206                 public void SetMethodSourceRange(System.Diagnostics.SymbolStore.ISymbolDocumentWriter startDoc, int startLine, int startColumn, System.Diagnostics.SymbolStore.ISymbolDocumentWriter endDoc, int endLine, int endColumn)
207                 {
208                 }
209
210                 public void SetScopeRange(int scopeID, int startOffset, int endOffset)
211                 {
212                 }
213
214                 public void SetSymAttribute(System.Diagnostics.SymbolStore.SymbolToken parent, string name, byte[] data)
215                 {
216                 }
217
218                 public void SetUserEntryPoint(System.Diagnostics.SymbolStore.SymbolToken entryMethod)
219                 {
220                 }
221
222                 public void SetUnderlyingWriter(IntPtr underlyingWriter)
223                 {
224                         throw new InvalidOperationException();
225                 }
226
227                 public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
228                 {
229                         throw new InvalidOperationException();
230                 }
231         }
232 }
233 #endif // MONO