New test.
[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                 ArrayList sources;
21                 Mono.ILASM.SourceMethod current_method;
22                 SourceFile current_source;
23
24                 public SymbolWriter (string filename)
25                         : base (filename)
26                 {
27                         sources = new ArrayList ();
28                 }
29
30                 public Mono.ILASM.SourceMethod BeginMethod (MethodDef method, Location location)
31                 {
32                         current_method = new Mono.ILASM.SourceMethod (method, location);
33                         current_source.AddMethod (current_method);
34                         return current_method;
35                 }
36
37                 public void EndMethod (Location location)
38                 {
39                         current_method.EndLine = location.line;
40                         current_method = null;
41                 }
42
43                 public void BeginSourceFile (string filename)
44                 {
45                         current_source = new SourceFile (file, filename);
46                         sources.Add (current_source);
47                 }
48
49                 public void EndSourceFile ()
50                 {
51                         current_source = null;
52                 }
53
54                 public void Write (Guid guid)
55                 {
56                         foreach (SourceFile source in sources)
57                                 source.Write ();
58
59                         WriteSymbolFile (guid);
60                 }
61         }
62
63         public class SourceFile : SourceFileEntry
64         {
65                 private ArrayList methods = new ArrayList ();
66
67                 public SourceFile (MonoSymbolFile file, string filename)
68                         : base (file, filename)
69                 { }
70
71                 public void AddMethod (SourceMethod method)
72                 {
73                         methods.Add (method);
74                 }
75
76                 public void Write ()
77                 {
78                         foreach (SourceMethod method in methods)
79                                 method.Write (this);
80                 }
81         }
82
83         public class SourceMethod
84         {
85                 MethodDef method;
86                 ArrayList lines;
87                 public int StartLine, EndLine;
88
89                 public SourceMethod (MethodDef method, Location start)
90                 {
91                         this.method = method;
92                         this.StartLine = start.line;
93
94                         lines = new ArrayList ();
95                         MarkLocation (start.line, 0);
96                 }
97
98                 public void MarkLocation (int line, uint offset)
99                 {
100                         lines.Add (new LineNumberEntry (line, (int) offset));
101                 }
102
103                 public void Write (SourceFile file)
104                 {
105                         PEAPI.MethodDef pemethod = method.PeapiMethodDef;
106
107                         LineNumberEntry[] lne = new LineNumberEntry [lines.Count];
108                         lines.CopyTo (lne);
109
110                         uint token = ((uint) PEAPI.MDTable.Method << 24) | pemethod.Row;
111
112                         file.DefineMethod (
113                                 method.Name, (int) token, null, lne, null,
114                                 StartLine, EndLine, 0);
115                 }
116         }
117 }