~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableWriter.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// MetadataTableWriter.cs
3
 
//
4
 
// Author:
5
 
//   Jb Evain (jbevain@gmail.com)
6
 
//
7
 
// Generated by /CodeGen/cecil-gen.rb do not edit
8
 
// Thu Feb 22 14:39:38 CET 2007
9
 
//
10
 
// (C) 2005 Jb Evain
11
 
//
12
 
// Permission is hereby granted, free of charge, to any person obtaining
13
 
// a copy of this software and associated documentation files (the
14
 
// "Software"), to deal in the Software without restriction, including
15
 
// without limitation the rights to use, copy, modify, merge, publish,
16
 
// distribute, sublicense, and/or sell copies of the Software, and to
17
 
// permit persons to whom the Software is furnished to do so, subject to
18
 
// the following conditions:
19
 
//
20
 
// The above copyright notice and this permission notice shall be
21
 
// included in all copies or substantial portions of the Software.
22
 
//
23
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
 
//
31
 
 
32
 
namespace Mono.Cecil.Metadata {
33
 
 
34
 
        using System;
35
 
        using System.Collections;
36
 
 
37
 
        using Mono.Cecil.Binary;
38
 
 
39
 
        internal sealed class MetadataTableWriter : BaseMetadataTableVisitor {
40
 
 
41
 
                MetadataRoot m_root;
42
 
                TablesHeap m_heap;
43
 
                MetadataRowWriter m_mrrw;
44
 
                MemoryBinaryWriter m_binaryWriter;
45
 
 
46
 
                public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer)
47
 
                {
48
 
                        m_root = mrv.GetMetadataRoot ();
49
 
                        m_heap = m_root.Streams.TablesHeap;
50
 
                        m_binaryWriter = writer;
51
 
                        m_mrrw = new MetadataRowWriter (this);
52
 
                }
53
 
 
54
 
                public MetadataRoot GetMetadataRoot ()
55
 
                {
56
 
                        return m_root;
57
 
                }
58
 
 
59
 
                public override IMetadataRowVisitor GetRowVisitor ()
60
 
                {
61
 
                        return m_mrrw;
62
 
                }
63
 
 
64
 
                public MemoryBinaryWriter GetWriter ()
65
 
                {
66
 
                        return m_binaryWriter;
67
 
                }
68
 
 
69
 
                void InitializeTable (IMetadataTable table)
70
 
                {
71
 
                        table.Rows = new RowCollection ();
72
 
                        m_heap.Valid |= 1L << table.Id;
73
 
                        m_heap.Tables.Add (table);
74
 
                }
75
 
 
76
 
                void WriteCount (int rid)
77
 
                {
78
 
                        if (m_heap.HasTable (rid))
79
 
                                m_binaryWriter.Write (m_heap [rid].Rows.Count);
80
 
                }
81
 
 
82
 
                public AssemblyTable GetAssemblyTable ()
83
 
                {
84
 
                        AssemblyTable table = m_heap [AssemblyTable.RId] as AssemblyTable;
85
 
                        if (table != null)
86
 
                                return table;
87
 
 
88
 
                        table = new AssemblyTable ();
89
 
                        InitializeTable (table);
90
 
                        return table;
91
 
                }
92
 
 
93
 
                public AssemblyOSTable GetAssemblyOSTable ()
94
 
                {
95
 
                        AssemblyOSTable table = m_heap [AssemblyOSTable.RId] as AssemblyOSTable;
96
 
                        if (table != null)
97
 
                                return table;
98
 
 
99
 
                        table = new AssemblyOSTable ();
100
 
                        InitializeTable (table);
101
 
                        return table;
102
 
                }
103
 
 
104
 
                public AssemblyProcessorTable GetAssemblyProcessorTable ()
105
 
                {
106
 
                        AssemblyProcessorTable table = m_heap [AssemblyProcessorTable.RId] as AssemblyProcessorTable;
107
 
                        if (table != null)
108
 
                                return table;
109
 
 
110
 
                        table = new AssemblyProcessorTable ();
111
 
                        InitializeTable (table);
112
 
                        return table;
113
 
                }
114
 
 
115
 
                public AssemblyRefTable GetAssemblyRefTable ()
116
 
                {
117
 
                        AssemblyRefTable table = m_heap [AssemblyRefTable.RId] as AssemblyRefTable;
118
 
                        if (table != null)
119
 
                                return table;
120
 
 
121
 
                        table = new AssemblyRefTable ();
122
 
                        InitializeTable (table);
123
 
                        return table;
124
 
                }
125
 
 
126
 
                public AssemblyRefOSTable GetAssemblyRefOSTable ()
127
 
                {
128
 
                        AssemblyRefOSTable table = m_heap [AssemblyRefOSTable.RId] as AssemblyRefOSTable;
129
 
                        if (table != null)
130
 
                                return table;
131
 
 
132
 
                        table = new AssemblyRefOSTable ();
133
 
                        InitializeTable (table);
134
 
                        return table;
135
 
                }
136
 
 
137
 
                public AssemblyRefProcessorTable GetAssemblyRefProcessorTable ()
138
 
                {
139
 
                        AssemblyRefProcessorTable table = m_heap [AssemblyRefProcessorTable.RId] as AssemblyRefProcessorTable;
140
 
                        if (table != null)
141
 
                                return table;
142
 
 
143
 
                        table = new AssemblyRefProcessorTable ();
144
 
                        InitializeTable (table);
145
 
                        return table;
146
 
                }
147
 
 
148
 
                public ClassLayoutTable GetClassLayoutTable ()
149
 
                {
150
 
                        ClassLayoutTable table = m_heap [ClassLayoutTable.RId] as ClassLayoutTable;
151
 
                        if (table != null)
152
 
                                return table;
153
 
 
154
 
                        table = new ClassLayoutTable ();
155
 
                        InitializeTable (table);
156
 
                        return table;
157
 
                }
158
 
 
159
 
                public ConstantTable GetConstantTable ()
160
 
                {
161
 
                        ConstantTable table = m_heap [ConstantTable.RId] as ConstantTable;
162
 
                        if (table != null)
163
 
                                return table;
164
 
 
165
 
                        table = new ConstantTable ();
166
 
                        InitializeTable (table);
167
 
                        return table;
168
 
                }
169
 
 
170
 
                public CustomAttributeTable GetCustomAttributeTable ()
171
 
                {
172
 
                        CustomAttributeTable table = m_heap [CustomAttributeTable.RId] as CustomAttributeTable;
173
 
                        if (table != null)
174
 
                                return table;
175
 
 
176
 
                        table = new CustomAttributeTable ();
177
 
                        InitializeTable (table);
178
 
                        return table;
179
 
                }
180
 
 
181
 
                public DeclSecurityTable GetDeclSecurityTable ()
182
 
                {
183
 
                        DeclSecurityTable table = m_heap [DeclSecurityTable.RId] as DeclSecurityTable;
184
 
                        if (table != null)
185
 
                                return table;
186
 
 
187
 
                        table = new DeclSecurityTable ();
188
 
                        InitializeTable (table);
189
 
                        return table;
190
 
                }
191
 
 
192
 
                public EventTable GetEventTable ()
193
 
                {
194
 
                        EventTable table = m_heap [EventTable.RId] as EventTable;
195
 
                        if (table != null)
196
 
                                return table;
197
 
 
198
 
                        table = new EventTable ();
199
 
                        InitializeTable (table);
200
 
                        return table;
201
 
                }
202
 
 
203
 
                public EventMapTable GetEventMapTable ()
204
 
                {
205
 
                        EventMapTable table = m_heap [EventMapTable.RId] as EventMapTable;
206
 
                        if (table != null)
207
 
                                return table;
208
 
 
209
 
                        table = new EventMapTable ();
210
 
                        InitializeTable (table);
211
 
                        return table;
212
 
                }
213
 
 
214
 
                public EventPtrTable GetEventPtrTable ()
215
 
                {
216
 
                        EventPtrTable table = m_heap [EventPtrTable.RId] as EventPtrTable;
217
 
                        if (table != null)
218
 
                                return table;
219
 
 
220
 
                        table = new EventPtrTable ();
221
 
                        InitializeTable (table);
222
 
                        return table;
223
 
                }
224
 
 
225
 
                public ExportedTypeTable GetExportedTypeTable ()
226
 
                {
227
 
                        ExportedTypeTable table = m_heap [ExportedTypeTable.RId] as ExportedTypeTable;
228
 
                        if (table != null)
229
 
                                return table;
230
 
 
231
 
                        table = new ExportedTypeTable ();
232
 
                        InitializeTable (table);
233
 
                        return table;
234
 
                }
235
 
 
236
 
                public FieldTable GetFieldTable ()
237
 
                {
238
 
                        FieldTable table = m_heap [FieldTable.RId] as FieldTable;
239
 
                        if (table != null)
240
 
                                return table;
241
 
 
242
 
                        table = new FieldTable ();
243
 
                        InitializeTable (table);
244
 
                        return table;
245
 
                }
246
 
 
247
 
                public FieldLayoutTable GetFieldLayoutTable ()
248
 
                {
249
 
                        FieldLayoutTable table = m_heap [FieldLayoutTable.RId] as FieldLayoutTable;
250
 
                        if (table != null)
251
 
                                return table;
252
 
 
253
 
                        table = new FieldLayoutTable ();
254
 
                        InitializeTable (table);
255
 
                        return table;
256
 
                }
257
 
 
258
 
                public FieldMarshalTable GetFieldMarshalTable ()
259
 
                {
260
 
                        FieldMarshalTable table = m_heap [FieldMarshalTable.RId] as FieldMarshalTable;
261
 
                        if (table != null)
262
 
                                return table;
263
 
 
264
 
                        table = new FieldMarshalTable ();
265
 
                        InitializeTable (table);
266
 
                        return table;
267
 
                }
268
 
 
269
 
                public FieldPtrTable GetFieldPtrTable ()
270
 
                {
271
 
                        FieldPtrTable table = m_heap [FieldPtrTable.RId] as FieldPtrTable;
272
 
                        if (table != null)
273
 
                                return table;
274
 
 
275
 
                        table = new FieldPtrTable ();
276
 
                        InitializeTable (table);
277
 
                        return table;
278
 
                }
279
 
 
280
 
                public FieldRVATable GetFieldRVATable ()
281
 
                {
282
 
                        FieldRVATable table = m_heap [FieldRVATable.RId] as FieldRVATable;
283
 
                        if (table != null)
284
 
                                return table;
285
 
 
286
 
                        table = new FieldRVATable ();
287
 
                        InitializeTable (table);
288
 
                        return table;
289
 
                }
290
 
 
291
 
                public FileTable GetFileTable ()
292
 
                {
293
 
                        FileTable table = m_heap [FileTable.RId] as FileTable;
294
 
                        if (table != null)
295
 
                                return table;
296
 
 
297
 
                        table = new FileTable ();
298
 
                        InitializeTable (table);
299
 
                        return table;
300
 
                }
301
 
 
302
 
                public GenericParamTable GetGenericParamTable ()
303
 
                {
304
 
                        GenericParamTable table = m_heap [GenericParamTable.RId] as GenericParamTable;
305
 
                        if (table != null)
306
 
                                return table;
307
 
 
308
 
                        table = new GenericParamTable ();
309
 
                        InitializeTable (table);
310
 
                        return table;
311
 
                }
312
 
 
313
 
                public GenericParamConstraintTable GetGenericParamConstraintTable ()
314
 
                {
315
 
                        GenericParamConstraintTable table = m_heap [GenericParamConstraintTable.RId] as GenericParamConstraintTable;
316
 
                        if (table != null)
317
 
                                return table;
318
 
 
319
 
                        table = new GenericParamConstraintTable ();
320
 
                        InitializeTable (table);
321
 
                        return table;
322
 
                }
323
 
 
324
 
                public ImplMapTable GetImplMapTable ()
325
 
                {
326
 
                        ImplMapTable table = m_heap [ImplMapTable.RId] as ImplMapTable;
327
 
                        if (table != null)
328
 
                                return table;
329
 
 
330
 
                        table = new ImplMapTable ();
331
 
                        InitializeTable (table);
332
 
                        return table;
333
 
                }
334
 
 
335
 
                public InterfaceImplTable GetInterfaceImplTable ()
336
 
                {
337
 
                        InterfaceImplTable table = m_heap [InterfaceImplTable.RId] as InterfaceImplTable;
338
 
                        if (table != null)
339
 
                                return table;
340
 
 
341
 
                        table = new InterfaceImplTable ();
342
 
                        InitializeTable (table);
343
 
                        return table;
344
 
                }
345
 
 
346
 
                public ManifestResourceTable GetManifestResourceTable ()
347
 
                {
348
 
                        ManifestResourceTable table = m_heap [ManifestResourceTable.RId] as ManifestResourceTable;
349
 
                        if (table != null)
350
 
                                return table;
351
 
 
352
 
                        table = new ManifestResourceTable ();
353
 
                        InitializeTable (table);
354
 
                        return table;
355
 
                }
356
 
 
357
 
                public MemberRefTable GetMemberRefTable ()
358
 
                {
359
 
                        MemberRefTable table = m_heap [MemberRefTable.RId] as MemberRefTable;
360
 
                        if (table != null)
361
 
                                return table;
362
 
 
363
 
                        table = new MemberRefTable ();
364
 
                        InitializeTable (table);
365
 
                        return table;
366
 
                }
367
 
 
368
 
                public MethodTable GetMethodTable ()
369
 
                {
370
 
                        MethodTable table = m_heap [MethodTable.RId] as MethodTable;
371
 
                        if (table != null)
372
 
                                return table;
373
 
 
374
 
                        table = new MethodTable ();
375
 
                        InitializeTable (table);
376
 
                        return table;
377
 
                }
378
 
 
379
 
                public MethodImplTable GetMethodImplTable ()
380
 
                {
381
 
                        MethodImplTable table = m_heap [MethodImplTable.RId] as MethodImplTable;
382
 
                        if (table != null)
383
 
                                return table;
384
 
 
385
 
                        table = new MethodImplTable ();
386
 
                        InitializeTable (table);
387
 
                        return table;
388
 
                }
389
 
 
390
 
                public MethodPtrTable GetMethodPtrTable ()
391
 
                {
392
 
                        MethodPtrTable table = m_heap [MethodPtrTable.RId] as MethodPtrTable;
393
 
                        if (table != null)
394
 
                                return table;
395
 
 
396
 
                        table = new MethodPtrTable ();
397
 
                        InitializeTable (table);
398
 
                        return table;
399
 
                }
400
 
 
401
 
                public MethodSemanticsTable GetMethodSemanticsTable ()
402
 
                {
403
 
                        MethodSemanticsTable table = m_heap [MethodSemanticsTable.RId] as MethodSemanticsTable;
404
 
                        if (table != null)
405
 
                                return table;
406
 
 
407
 
                        table = new MethodSemanticsTable ();
408
 
                        InitializeTable (table);
409
 
                        return table;
410
 
                }
411
 
 
412
 
                public MethodSpecTable GetMethodSpecTable ()
413
 
                {
414
 
                        MethodSpecTable table = m_heap [MethodSpecTable.RId] as MethodSpecTable;
415
 
                        if (table != null)
416
 
                                return table;
417
 
 
418
 
                        table = new MethodSpecTable ();
419
 
                        InitializeTable (table);
420
 
                        return table;
421
 
                }
422
 
 
423
 
                public ModuleTable GetModuleTable ()
424
 
                {
425
 
                        ModuleTable table = m_heap [ModuleTable.RId] as ModuleTable;
426
 
                        if (table != null)
427
 
                                return table;
428
 
 
429
 
                        table = new ModuleTable ();
430
 
                        InitializeTable (table);
431
 
                        return table;
432
 
                }
433
 
 
434
 
                public ModuleRefTable GetModuleRefTable ()
435
 
                {
436
 
                        ModuleRefTable table = m_heap [ModuleRefTable.RId] as ModuleRefTable;
437
 
                        if (table != null)
438
 
                                return table;
439
 
 
440
 
                        table = new ModuleRefTable ();
441
 
                        InitializeTable (table);
442
 
                        return table;
443
 
                }
444
 
 
445
 
                public NestedClassTable GetNestedClassTable ()
446
 
                {
447
 
                        NestedClassTable table = m_heap [NestedClassTable.RId] as NestedClassTable;
448
 
                        if (table != null)
449
 
                                return table;
450
 
 
451
 
                        table = new NestedClassTable ();
452
 
                        InitializeTable (table);
453
 
                        return table;
454
 
                }
455
 
 
456
 
                public ParamTable GetParamTable ()
457
 
                {
458
 
                        ParamTable table = m_heap [ParamTable.RId] as ParamTable;
459
 
                        if (table != null)
460
 
                                return table;
461
 
 
462
 
                        table = new ParamTable ();
463
 
                        InitializeTable (table);
464
 
                        return table;
465
 
                }
466
 
 
467
 
                public ParamPtrTable GetParamPtrTable ()
468
 
                {
469
 
                        ParamPtrTable table = m_heap [ParamPtrTable.RId] as ParamPtrTable;
470
 
                        if (table != null)
471
 
                                return table;
472
 
 
473
 
                        table = new ParamPtrTable ();
474
 
                        InitializeTable (table);
475
 
                        return table;
476
 
                }
477
 
 
478
 
                public PropertyTable GetPropertyTable ()
479
 
                {
480
 
                        PropertyTable table = m_heap [PropertyTable.RId] as PropertyTable;
481
 
                        if (table != null)
482
 
                                return table;
483
 
 
484
 
                        table = new PropertyTable ();
485
 
                        InitializeTable (table);
486
 
                        return table;
487
 
                }
488
 
 
489
 
                public PropertyMapTable GetPropertyMapTable ()
490
 
                {
491
 
                        PropertyMapTable table = m_heap [PropertyMapTable.RId] as PropertyMapTable;
492
 
                        if (table != null)
493
 
                                return table;
494
 
 
495
 
                        table = new PropertyMapTable ();
496
 
                        InitializeTable (table);
497
 
                        return table;
498
 
                }
499
 
 
500
 
                public PropertyPtrTable GetPropertyPtrTable ()
501
 
                {
502
 
                        PropertyPtrTable table = m_heap [PropertyPtrTable.RId] as PropertyPtrTable;
503
 
                        if (table != null)
504
 
                                return table;
505
 
 
506
 
                        table = new PropertyPtrTable ();
507
 
                        InitializeTable (table);
508
 
                        return table;
509
 
                }
510
 
 
511
 
                public StandAloneSigTable GetStandAloneSigTable ()
512
 
                {
513
 
                        StandAloneSigTable table = m_heap [StandAloneSigTable.RId] as StandAloneSigTable;
514
 
                        if (table != null)
515
 
                                return table;
516
 
 
517
 
                        table = new StandAloneSigTable ();
518
 
                        InitializeTable (table);
519
 
                        return table;
520
 
                }
521
 
 
522
 
                public TypeDefTable GetTypeDefTable ()
523
 
                {
524
 
                        TypeDefTable table = m_heap [TypeDefTable.RId] as TypeDefTable;
525
 
                        if (table != null)
526
 
                                return table;
527
 
 
528
 
                        table = new TypeDefTable ();
529
 
                        InitializeTable (table);
530
 
                        return table;
531
 
                }
532
 
 
533
 
                public TypeRefTable GetTypeRefTable ()
534
 
                {
535
 
                        TypeRefTable table = m_heap [TypeRefTable.RId] as TypeRefTable;
536
 
                        if (table != null)
537
 
                                return table;
538
 
 
539
 
                        table = new TypeRefTable ();
540
 
                        InitializeTable (table);
541
 
                        return table;
542
 
                }
543
 
 
544
 
                public TypeSpecTable GetTypeSpecTable ()
545
 
                {
546
 
                        TypeSpecTable table = m_heap [TypeSpecTable.RId] as TypeSpecTable;
547
 
                        if (table != null)
548
 
                                return table;
549
 
 
550
 
                        table = new TypeSpecTable ();
551
 
                        InitializeTable (table);
552
 
                        return table;
553
 
                }
554
 
 
555
 
                public override void VisitTableCollection (TableCollection coll)
556
 
                {
557
 
                        WriteCount (ModuleTable.RId);
558
 
                        WriteCount (TypeRefTable.RId);
559
 
                        WriteCount (TypeDefTable.RId);
560
 
                        WriteCount (FieldPtrTable.RId);
561
 
                        WriteCount (FieldTable.RId);
562
 
                        WriteCount (MethodPtrTable.RId);
563
 
                        WriteCount (MethodTable.RId);
564
 
                        WriteCount (ParamPtrTable.RId);
565
 
                        WriteCount (ParamTable.RId);
566
 
                        WriteCount (InterfaceImplTable.RId);
567
 
                        WriteCount (MemberRefTable.RId);
568
 
                        WriteCount (ConstantTable.RId);
569
 
                        WriteCount (CustomAttributeTable.RId);
570
 
                        WriteCount (FieldMarshalTable.RId);
571
 
                        WriteCount (DeclSecurityTable.RId);
572
 
                        WriteCount (ClassLayoutTable.RId);
573
 
                        WriteCount (FieldLayoutTable.RId);
574
 
                        WriteCount (StandAloneSigTable.RId);
575
 
                        WriteCount (EventMapTable.RId);
576
 
                        WriteCount (EventPtrTable.RId);
577
 
                        WriteCount (EventTable.RId);
578
 
                        WriteCount (PropertyMapTable.RId);
579
 
                        WriteCount (PropertyPtrTable.RId);
580
 
                        WriteCount (PropertyTable.RId);
581
 
                        WriteCount (MethodSemanticsTable.RId);
582
 
                        WriteCount (MethodImplTable.RId);
583
 
                        WriteCount (ModuleRefTable.RId);
584
 
                        WriteCount (TypeSpecTable.RId);
585
 
                        WriteCount (ImplMapTable.RId);
586
 
                        WriteCount (FieldRVATable.RId);
587
 
                        WriteCount (AssemblyTable.RId);
588
 
                        WriteCount (AssemblyProcessorTable.RId);
589
 
                        WriteCount (AssemblyOSTable.RId);
590
 
                        WriteCount (AssemblyRefTable.RId);
591
 
                        WriteCount (AssemblyRefProcessorTable.RId);
592
 
                        WriteCount (AssemblyRefOSTable.RId);
593
 
                        WriteCount (FileTable.RId);
594
 
                        WriteCount (ExportedTypeTable.RId);
595
 
                        WriteCount (ManifestResourceTable.RId);
596
 
                        WriteCount (NestedClassTable.RId);
597
 
                        WriteCount (GenericParamTable.RId);
598
 
                        WriteCount (MethodSpecTable.RId);
599
 
                        WriteCount (GenericParamConstraintTable.RId);
600
 
                }
601
 
        }
602
 
}