2003-02-09 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / mcs / symbolwriter.cs
1 //
2 // symbolwriter.cs: The symbol writer
3 //
4 // Author:
5 //   Martin Baulig (martin@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc.
8 //
9
10 using System;
11 using System.Collections;
12 using System.Reflection;
13 using System.Reflection.Emit;
14 using System.Diagnostics.SymbolStore;
15
16 namespace Mono.CSharp {
17         public class SymbolWriter {
18                 ISymbolWriter symwriter;
19
20                 protected SymbolWriter (ISymbolWriter symwriter)
21                 {
22                         this.symwriter = symwriter;
23                 }
24
25                 bool Initialize ()
26                 {
27                         Location.DefineSymbolDocuments (this);
28
29                         return true;
30                 }
31
32                 public ISymbolDocumentWriter DefineDocument (string path)
33                 {
34                         return symwriter.DefineDocument (
35                                 path, SymLanguageType.CSharp, SymLanguageVendor.Microsoft,
36                                 SymDocumentType.Text);
37                 }
38
39                 public void OpenMethod (MethodToken token, Location start, Location end)
40                 {
41                         symwriter.OpenMethod (new SymbolToken (token.Token));
42                         symwriter.SetMethodSourceRange (
43                                 start.SymbolDocument, start.Row, 0, end.SymbolDocument, end.Row, 0);
44                 }
45
46                 public void CloseMethod ()
47                 {
48                         symwriter.CloseMethod ();
49                 }
50
51                 public static SymbolWriter GetSymbolWriter (ModuleBuilder module)
52                 {
53                         ISymbolWriter symwriter = module.GetSymWriter ();
54
55                         if (symwriter == null)
56                                 return null;
57
58                         SymbolWriter writer = new SymbolWriter (symwriter);
59                         if (!writer.Initialize ())
60                                 return null;
61
62                         return writer;
63                 }
64         }
65 }