~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/Parser/mcs/MonoSymbolWriter.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// Mono.CSharp.Debugger/MonoSymbolWriter.cs
3
 
//
4
 
// Author:
5
 
//   Martin Baulig (martin@ximian.com)
6
 
//
7
 
// This is the default implementation of the System.Diagnostics.SymbolStore.ISymbolWriter
8
 
// interface.
9
 
//
10
 
// (C) 2002 Ximian, Inc.  http://www.ximian.com
11
 
//
12
 
 
13
 
//
14
 
// Permission is hereby granted, free of charge, to any person obtaining
15
 
// a copy of this software and associated documentation files (the
16
 
// "Software"), to deal in the Software without restriction, including
17
 
// without limitation the rights to use, copy, modify, merge, publish,
18
 
// distribute, sublicense, and/or sell copies of the Software, and to
19
 
// permit persons to whom the Software is furnished to do so, subject to
20
 
// the following conditions:
21
 
// 
22
 
// The above copyright notice and this permission notice shall be
23
 
// included in all copies or substantial portions of the Software.
24
 
// 
25
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
 
//
33
 
 
34
 
using System;
35
 
using System.Runtime.CompilerServices;
36
 
using System.Collections.Generic;
37
 
using System.IO;
38
 
        
39
 
namespace Mono.CompilerServices.SymbolWriter
40
 
{
41
 
        public class MonoSymbolWriter
42
 
        {
43
 
                List<SourceMethodBuilder> methods;
44
 
                List<SourceFileEntry> sources;
45
 
                List<CompileUnitEntry> comp_units;
46
 
                protected readonly MonoSymbolFile file;
47
 
                string filename;
48
 
                
49
 
                private SourceMethodBuilder current_method;
50
 
#if NET_2_1
51
 
                System.Collections.Stack current_method_stack = new System.Collections.Stack ();
52
 
#else
53
 
                Stack<SourceMethodBuilder> current_method_stack = new Stack<SourceMethodBuilder> ();
54
 
#endif
55
 
 
56
 
                public MonoSymbolWriter (string filename)
57
 
                {
58
 
                        this.methods = new List<SourceMethodBuilder> ();
59
 
                        this.sources = new List<SourceFileEntry> ();
60
 
                        this.comp_units = new List<CompileUnitEntry> ();
61
 
                        this.file = new MonoSymbolFile ();
62
 
 
63
 
                        this.filename = filename + ".mdb";
64
 
                }
65
 
 
66
 
                public MonoSymbolFile SymbolFile {
67
 
                        get { return file; }
68
 
                }
69
 
 
70
 
                public void CloseNamespace ()
71
 
                { }
72
 
 
73
 
                public void DefineLocalVariable (int index, string name)
74
 
                {
75
 
                        if (current_method == null)
76
 
                                return;
77
 
 
78
 
                        current_method.AddLocal (index, name);
79
 
                }
80
 
 
81
 
                public void DefineCapturedLocal (int scope_id, string name, string captured_name)
82
 
                {
83
 
                        file.DefineCapturedVariable (scope_id, name, captured_name,
84
 
                                                     CapturedVariable.CapturedKind.Local);
85
 
                }
86
 
 
87
 
                public void DefineCapturedParameter (int scope_id, string name, string captured_name)
88
 
                {
89
 
                        file.DefineCapturedVariable (scope_id, name, captured_name,
90
 
                                                     CapturedVariable.CapturedKind.Parameter);
91
 
                }
92
 
 
93
 
                public void DefineCapturedThis (int scope_id, string captured_name)
94
 
                {
95
 
                        file.DefineCapturedVariable (scope_id, "this", captured_name,
96
 
                                                     CapturedVariable.CapturedKind.This);
97
 
                }
98
 
 
99
 
                public void DefineCapturedScope (int scope_id, int id, string captured_name)
100
 
                {
101
 
                        file.DefineCapturedScope (scope_id, id, captured_name);
102
 
                }
103
 
 
104
 
                public void DefineScopeVariable (int scope, int index)
105
 
                {
106
 
                        if (current_method == null)
107
 
                                return;
108
 
 
109
 
                        current_method.AddScopeVariable (scope, index);
110
 
                }
111
 
 
112
 
                public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column,
113
 
                                               bool is_hidden)
114
 
                {
115
 
                        if (current_method == null)
116
 
                                return;
117
 
 
118
 
                        current_method.MarkSequencePoint (offset, file, line, column, is_hidden);
119
 
                }
120
 
 
121
 
                public SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id, IMethodDef method)
122
 
                {
123
 
                        SourceMethodBuilder builder = new SourceMethodBuilder (file, ns_id, method);
124
 
                        current_method_stack.Push (current_method);
125
 
                        current_method = builder;
126
 
                        methods.Add (current_method);
127
 
                        return builder;
128
 
                }
129
 
 
130
 
                public void CloseMethod ()
131
 
                {
132
 
                        current_method = (SourceMethodBuilder) current_method_stack.Pop ();
133
 
                }
134
 
 
135
 
                public SourceFileEntry DefineDocument (string url)
136
 
                {
137
 
                        SourceFileEntry entry = new SourceFileEntry (file, url);
138
 
                        sources.Add (entry);
139
 
                        return entry;
140
 
                }
141
 
 
142
 
                public SourceFileEntry DefineDocument (string url, byte[] guid, byte[] checksum)
143
 
                {
144
 
                        SourceFileEntry entry = new SourceFileEntry (file, url, guid, checksum);
145
 
                        sources.Add (entry);
146
 
                        return entry;
147
 
                }
148
 
 
149
 
                public CompileUnitEntry DefineCompilationUnit (SourceFileEntry source)
150
 
                {
151
 
                        CompileUnitEntry entry = new CompileUnitEntry (file, source);
152
 
                        comp_units.Add (entry);
153
 
                        return entry;
154
 
                }
155
 
 
156
 
                public int DefineNamespace (string name, CompileUnitEntry unit,
157
 
                                            string[] using_clauses, int parent)
158
 
                {
159
 
                        if ((unit == null) || (using_clauses == null))
160
 
                                throw new NullReferenceException ();
161
 
 
162
 
                        return unit.DefineNamespace (name, using_clauses, parent);
163
 
                }
164
 
 
165
 
                public int OpenScope (int start_offset)
166
 
                {
167
 
                        if (current_method == null)
168
 
                                return 0;
169
 
 
170
 
                        current_method.StartBlock (CodeBlockEntry.Type.Lexical, start_offset);
171
 
                        return 0;
172
 
                }
173
 
 
174
 
                public void CloseScope (int end_offset)
175
 
                {
176
 
                        if (current_method == null)
177
 
                                return;
178
 
 
179
 
                        current_method.EndBlock (end_offset);
180
 
                }
181
 
 
182
 
                public void OpenCompilerGeneratedBlock (int start_offset)
183
 
                {
184
 
                        if (current_method == null)
185
 
                                return;
186
 
 
187
 
                        current_method.StartBlock (CodeBlockEntry.Type.CompilerGenerated,
188
 
                                                   start_offset);
189
 
                }
190
 
 
191
 
                public void CloseCompilerGeneratedBlock (int end_offset)
192
 
                {
193
 
                        if (current_method == null)
194
 
                                return;
195
 
 
196
 
                        current_method.EndBlock (end_offset);
197
 
                }
198
 
 
199
 
                public void StartIteratorBody (int start_offset)
200
 
                {
201
 
                        current_method.StartBlock (CodeBlockEntry.Type.IteratorBody,
202
 
                                                   start_offset);
203
 
                }
204
 
 
205
 
                public void EndIteratorBody (int end_offset)
206
 
                {
207
 
                        current_method.EndBlock (end_offset);
208
 
                }
209
 
 
210
 
                public void StartIteratorDispatcher (int start_offset)
211
 
                {
212
 
                        current_method.StartBlock (CodeBlockEntry.Type.IteratorDispatcher,
213
 
                                                   start_offset);
214
 
                }
215
 
 
216
 
                public void EndIteratorDispatcher (int end_offset)
217
 
                {
218
 
                        current_method.EndBlock (end_offset);
219
 
                }
220
 
 
221
 
                public void DefineAnonymousScope (int id)
222
 
                {
223
 
                        file.DefineAnonymousScope (id);
224
 
                }
225
 
 
226
 
                public void WriteSymbolFile (Guid guid)
227
 
                {
228
 
                        foreach (SourceMethodBuilder method in methods)
229
 
                                method.DefineMethod (file);
230
 
 
231
 
                        try {
232
 
                                // We mmap the file, so unlink the previous version since it may be in use
233
 
                                File.Delete (filename);
234
 
                        } catch {
235
 
                                // We can safely ignore
236
 
                        }
237
 
                        using (FileStream fs = new FileStream (filename, FileMode.Create, FileAccess.Write)) {
238
 
                                file.CreateSymbolFile (guid, fs);
239
 
                        }
240
 
                }
241
 
        }
242
 
}