Merge pull request #1931 from kasthack/system.web-fixes
[mono.git] / mcs / ilasm / codegen / DebuggingInfo.cs
1 //
2 // Mono.ILASM.DebuggingInfo.cs
3 //
4 // Author(s):
5 //  Martin Baulig (martin@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc.
8 //
9
10 using PEAPI;
11 using System;
12 using System.IO;
13 using System.Collections;
14 using Mono.CompilerServices.SymbolWriter;
15
16 namespace Mono.ILASM {
17
18         public class SymbolWriter : MonoSymbolWriter
19         {
20                 Mono.ILASM.SourceMethod current_method;
21                 CompileUnitEntry current_source;
22                 ArrayList methods;
23
24                 public SymbolWriter (string filename)
25                         : base (filename)
26                 {
27                         methods = new ArrayList ();
28                 }
29
30                 public Mono.ILASM.SourceMethod BeginMethod (MethodDef method, Location start)
31                 {
32                         current_method = new Mono.ILASM.SourceMethod (current_source, method, start);
33                         methods.Add (current_method);
34                         return current_method;
35                 }
36
37                 public void EndMethod (Location end)
38                 {
39                         current_method.EndLine = end.line;
40                         current_method = null;
41                 }
42
43                 public void BeginSourceFile (string filename)
44                 {
45                         SourceFileEntry file = DefineDocument (filename, null, null);
46                         current_source = DefineCompilationUnit (file);
47                 }
48
49                 public void EndSourceFile ()
50                 {
51                         current_source = null;
52                 }
53
54                 public void Write (Guid guid)
55                 {
56                         foreach (Mono.ILASM.SourceMethod method in methods)
57                                 method.Write (this);
58
59                         WriteSymbolFile (guid);
60                 }
61         }
62
63         public class SourceMethod : IMethodDef
64         {
65                 CompileUnitEntry file;
66                 MethodDef method;
67                 ArrayList lines;
68                 public int StartLine, EndLine;
69
70                 public SourceMethod (CompileUnitEntry file, MethodDef method, Location start)
71                 {
72                         this.file = file;
73                         this.method = method;
74                         this.StartLine = start.line;
75
76                         lines = new ArrayList ();
77                         MarkLocation (start.line, 0);
78                 }
79
80                 public string Name {
81                         get { return method.Name; }
82                 }
83
84                 public int Token {
85                         get {
86                                 PEAPI.MethodDef pemethod = method.PeapiMethodDef;
87                                 return (int) (((uint) PEAPI.MDTable.Method << 24) | pemethod.Row);
88                         }
89                 }
90
91                 public void MarkLocation (int line, uint offset)
92                 {
93                         lines.Add (new LineNumberEntry (0, line, (int) offset));
94                 }
95
96                 public void Write (MonoSymbolWriter writer)
97                 {
98                         LineNumberEntry[] the_lines = new LineNumberEntry [lines.Count];
99                         lines.CopyTo (the_lines, 0);
100
101                         LocalVariableEntry[] locals = method.GetLocalVars ();
102
103                         MethodEntry entry = writer.SymbolFile.DefineMethod (
104                                 file, Token, null, locals, the_lines, null, null, 0, 0);
105                 }
106         }
107 }