This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / gmcs / 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                 MethodInfo define_namespace;
20                 MethodInfo open_method;
21
22                 protected SymbolWriter (ISymbolWriter symwriter)
23                 {
24                         this.symwriter = symwriter;
25                 }
26
27                 bool Initialize ()
28                 {
29                         Type type = symwriter.GetType ();
30                         define_namespace = type.GetMethod ("DefineNamespace", new Type[] {
31                                 typeof (string), typeof (ISymbolDocumentWriter),
32                                 typeof (string []), typeof (int) });
33                         if (define_namespace == null)
34                                 return false;
35
36                         open_method = type.GetMethod ("OpenMethod", new Type[] {
37                                 typeof (ISymbolDocumentWriter), typeof (int), typeof (int),
38                                 typeof (int), typeof (int), typeof (MethodBase), typeof (int) });
39                         if (open_method == null)
40                                 return false;
41
42                         Location.DefineSymbolDocuments (this);
43                         Namespace.DefineNamespaces (this);
44
45                         return true;
46                 }
47
48                 public ISymbolDocumentWriter DefineDocument (string path)
49                 {
50                         return symwriter.DefineDocument (
51                                 path, SymLanguageType.CSharp, SymLanguageVendor.Microsoft,
52                                 SymDocumentType.Text);
53                 }
54
55                 public int DefineNamespace (string name, SourceFile file, string[] using_list, int parent)
56                 {
57                         if (file.SymbolDocument == null)
58                                 return 0;
59                         return (int) define_namespace.Invoke (symwriter, new object[] {
60                                 name, file.SymbolDocument, using_list, parent });
61                 }
62
63                 public void OpenMethod (TypeContainer parent, MethodBase method, Location start, Location end)
64                 {
65                         int ns_id = parent.NamespaceEntry.SymbolFileID;
66                         open_method.Invoke (symwriter, new object[] {
67                                 start.SymbolDocument, start.Row, 0, end.Row, 0, method, ns_id });
68                 }
69
70                 public void CloseMethod ()
71                 {
72                         symwriter.CloseMethod ();
73                 }
74
75                 public static SymbolWriter GetSymbolWriter (ModuleBuilder module)
76                 {
77                         ISymbolWriter symwriter = module.GetSymWriter ();
78
79                         if (symwriter == null)
80                                 return null;
81
82                         SymbolWriter writer = new SymbolWriter (symwriter);
83                         if (!writer.Initialize ())
84                                 return null;
85
86                         return writer;
87                 }
88         }
89 }