flush
[mcs.git] / class / Mono.Cecil / Mono.Cecil.Metadata / MetadataTableWriter.cs
blob6c7fab443ff71552062e3b968de2ad068d1a3e35
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
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
32 namespace Mono.Cecil.Metadata {
34 using System;
35 using System.Collections;
37 using Mono.Cecil.Binary;
39 internal sealed class MetadataTableWriter : BaseMetadataTableVisitor {
41 MetadataRoot m_root;
42 TablesHeap m_heap;
43 MetadataRowWriter m_mrrw;
44 MemoryBinaryWriter m_binaryWriter;
46 public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer)
48 m_root = mrv.GetMetadataRoot ();
49 m_heap = m_root.Streams.TablesHeap;
50 m_binaryWriter = writer;
51 m_mrrw = new MetadataRowWriter (this);
54 public MetadataRoot GetMetadataRoot ()
56 return m_root;
59 public override IMetadataRowVisitor GetRowVisitor ()
61 return m_mrrw;
64 public MemoryBinaryWriter GetWriter ()
66 return m_binaryWriter;
69 void InitializeTable (IMetadataTable table)
71 table.Rows = new RowCollection ();
72 m_heap.Valid |= 1L << table.Id;
73 m_heap.Tables.Add (table);
76 void WriteCount (int rid)
78 if (m_heap.HasTable (rid))
79 m_binaryWriter.Write (m_heap [rid].Rows.Count);
82 public AssemblyTable GetAssemblyTable ()
84 AssemblyTable table = m_heap [AssemblyTable.RId] as AssemblyTable;
85 if (table != null)
86 return table;
88 table = new AssemblyTable ();
89 InitializeTable (table);
90 return table;
93 public AssemblyOSTable GetAssemblyOSTable ()
95 AssemblyOSTable table = m_heap [AssemblyOSTable.RId] as AssemblyOSTable;
96 if (table != null)
97 return table;
99 table = new AssemblyOSTable ();
100 InitializeTable (table);
101 return table;
104 public AssemblyProcessorTable GetAssemblyProcessorTable ()
106 AssemblyProcessorTable table = m_heap [AssemblyProcessorTable.RId] as AssemblyProcessorTable;
107 if (table != null)
108 return table;
110 table = new AssemblyProcessorTable ();
111 InitializeTable (table);
112 return table;
115 public AssemblyRefTable GetAssemblyRefTable ()
117 AssemblyRefTable table = m_heap [AssemblyRefTable.RId] as AssemblyRefTable;
118 if (table != null)
119 return table;
121 table = new AssemblyRefTable ();
122 InitializeTable (table);
123 return table;
126 public AssemblyRefOSTable GetAssemblyRefOSTable ()
128 AssemblyRefOSTable table = m_heap [AssemblyRefOSTable.RId] as AssemblyRefOSTable;
129 if (table != null)
130 return table;
132 table = new AssemblyRefOSTable ();
133 InitializeTable (table);
134 return table;
137 public AssemblyRefProcessorTable GetAssemblyRefProcessorTable ()
139 AssemblyRefProcessorTable table = m_heap [AssemblyRefProcessorTable.RId] as AssemblyRefProcessorTable;
140 if (table != null)
141 return table;
143 table = new AssemblyRefProcessorTable ();
144 InitializeTable (table);
145 return table;
148 public ClassLayoutTable GetClassLayoutTable ()
150 ClassLayoutTable table = m_heap [ClassLayoutTable.RId] as ClassLayoutTable;
151 if (table != null)
152 return table;
154 table = new ClassLayoutTable ();
155 InitializeTable (table);
156 return table;
159 public ConstantTable GetConstantTable ()
161 ConstantTable table = m_heap [ConstantTable.RId] as ConstantTable;
162 if (table != null)
163 return table;
165 table = new ConstantTable ();
166 InitializeTable (table);
167 return table;
170 public CustomAttributeTable GetCustomAttributeTable ()
172 CustomAttributeTable table = m_heap [CustomAttributeTable.RId] as CustomAttributeTable;
173 if (table != null)
174 return table;
176 table = new CustomAttributeTable ();
177 InitializeTable (table);
178 return table;
181 public DeclSecurityTable GetDeclSecurityTable ()
183 DeclSecurityTable table = m_heap [DeclSecurityTable.RId] as DeclSecurityTable;
184 if (table != null)
185 return table;
187 table = new DeclSecurityTable ();
188 InitializeTable (table);
189 return table;
192 public EventTable GetEventTable ()
194 EventTable table = m_heap [EventTable.RId] as EventTable;
195 if (table != null)
196 return table;
198 table = new EventTable ();
199 InitializeTable (table);
200 return table;
203 public EventMapTable GetEventMapTable ()
205 EventMapTable table = m_heap [EventMapTable.RId] as EventMapTable;
206 if (table != null)
207 return table;
209 table = new EventMapTable ();
210 InitializeTable (table);
211 return table;
214 public EventPtrTable GetEventPtrTable ()
216 EventPtrTable table = m_heap [EventPtrTable.RId] as EventPtrTable;
217 if (table != null)
218 return table;
220 table = new EventPtrTable ();
221 InitializeTable (table);
222 return table;
225 public ExportedTypeTable GetExportedTypeTable ()
227 ExportedTypeTable table = m_heap [ExportedTypeTable.RId] as ExportedTypeTable;
228 if (table != null)
229 return table;
231 table = new ExportedTypeTable ();
232 InitializeTable (table);
233 return table;
236 public FieldTable GetFieldTable ()
238 FieldTable table = m_heap [FieldTable.RId] as FieldTable;
239 if (table != null)
240 return table;
242 table = new FieldTable ();
243 InitializeTable (table);
244 return table;
247 public FieldLayoutTable GetFieldLayoutTable ()
249 FieldLayoutTable table = m_heap [FieldLayoutTable.RId] as FieldLayoutTable;
250 if (table != null)
251 return table;
253 table = new FieldLayoutTable ();
254 InitializeTable (table);
255 return table;
258 public FieldMarshalTable GetFieldMarshalTable ()
260 FieldMarshalTable table = m_heap [FieldMarshalTable.RId] as FieldMarshalTable;
261 if (table != null)
262 return table;
264 table = new FieldMarshalTable ();
265 InitializeTable (table);
266 return table;
269 public FieldPtrTable GetFieldPtrTable ()
271 FieldPtrTable table = m_heap [FieldPtrTable.RId] as FieldPtrTable;
272 if (table != null)
273 return table;
275 table = new FieldPtrTable ();
276 InitializeTable (table);
277 return table;
280 public FieldRVATable GetFieldRVATable ()
282 FieldRVATable table = m_heap [FieldRVATable.RId] as FieldRVATable;
283 if (table != null)
284 return table;
286 table = new FieldRVATable ();
287 InitializeTable (table);
288 return table;
291 public FileTable GetFileTable ()
293 FileTable table = m_heap [FileTable.RId] as FileTable;
294 if (table != null)
295 return table;
297 table = new FileTable ();
298 InitializeTable (table);
299 return table;
302 public GenericParamTable GetGenericParamTable ()
304 GenericParamTable table = m_heap [GenericParamTable.RId] as GenericParamTable;
305 if (table != null)
306 return table;
308 table = new GenericParamTable ();
309 InitializeTable (table);
310 return table;
313 public GenericParamConstraintTable GetGenericParamConstraintTable ()
315 GenericParamConstraintTable table = m_heap [GenericParamConstraintTable.RId] as GenericParamConstraintTable;
316 if (table != null)
317 return table;
319 table = new GenericParamConstraintTable ();
320 InitializeTable (table);
321 return table;
324 public ImplMapTable GetImplMapTable ()
326 ImplMapTable table = m_heap [ImplMapTable.RId] as ImplMapTable;
327 if (table != null)
328 return table;
330 table = new ImplMapTable ();
331 InitializeTable (table);
332 return table;
335 public InterfaceImplTable GetInterfaceImplTable ()
337 InterfaceImplTable table = m_heap [InterfaceImplTable.RId] as InterfaceImplTable;
338 if (table != null)
339 return table;
341 table = new InterfaceImplTable ();
342 InitializeTable (table);
343 return table;
346 public ManifestResourceTable GetManifestResourceTable ()
348 ManifestResourceTable table = m_heap [ManifestResourceTable.RId] as ManifestResourceTable;
349 if (table != null)
350 return table;
352 table = new ManifestResourceTable ();
353 InitializeTable (table);
354 return table;
357 public MemberRefTable GetMemberRefTable ()
359 MemberRefTable table = m_heap [MemberRefTable.RId] as MemberRefTable;
360 if (table != null)
361 return table;
363 table = new MemberRefTable ();
364 InitializeTable (table);
365 return table;
368 public MethodTable GetMethodTable ()
370 MethodTable table = m_heap [MethodTable.RId] as MethodTable;
371 if (table != null)
372 return table;
374 table = new MethodTable ();
375 InitializeTable (table);
376 return table;
379 public MethodImplTable GetMethodImplTable ()
381 MethodImplTable table = m_heap [MethodImplTable.RId] as MethodImplTable;
382 if (table != null)
383 return table;
385 table = new MethodImplTable ();
386 InitializeTable (table);
387 return table;
390 public MethodPtrTable GetMethodPtrTable ()
392 MethodPtrTable table = m_heap [MethodPtrTable.RId] as MethodPtrTable;
393 if (table != null)
394 return table;
396 table = new MethodPtrTable ();
397 InitializeTable (table);
398 return table;
401 public MethodSemanticsTable GetMethodSemanticsTable ()
403 MethodSemanticsTable table = m_heap [MethodSemanticsTable.RId] as MethodSemanticsTable;
404 if (table != null)
405 return table;
407 table = new MethodSemanticsTable ();
408 InitializeTable (table);
409 return table;
412 public MethodSpecTable GetMethodSpecTable ()
414 MethodSpecTable table = m_heap [MethodSpecTable.RId] as MethodSpecTable;
415 if (table != null)
416 return table;
418 table = new MethodSpecTable ();
419 InitializeTable (table);
420 return table;
423 public ModuleTable GetModuleTable ()
425 ModuleTable table = m_heap [ModuleTable.RId] as ModuleTable;
426 if (table != null)
427 return table;
429 table = new ModuleTable ();
430 InitializeTable (table);
431 return table;
434 public ModuleRefTable GetModuleRefTable ()
436 ModuleRefTable table = m_heap [ModuleRefTable.RId] as ModuleRefTable;
437 if (table != null)
438 return table;
440 table = new ModuleRefTable ();
441 InitializeTable (table);
442 return table;
445 public NestedClassTable GetNestedClassTable ()
447 NestedClassTable table = m_heap [NestedClassTable.RId] as NestedClassTable;
448 if (table != null)
449 return table;
451 table = new NestedClassTable ();
452 InitializeTable (table);
453 return table;
456 public ParamTable GetParamTable ()
458 ParamTable table = m_heap [ParamTable.RId] as ParamTable;
459 if (table != null)
460 return table;
462 table = new ParamTable ();
463 InitializeTable (table);
464 return table;
467 public ParamPtrTable GetParamPtrTable ()
469 ParamPtrTable table = m_heap [ParamPtrTable.RId] as ParamPtrTable;
470 if (table != null)
471 return table;
473 table = new ParamPtrTable ();
474 InitializeTable (table);
475 return table;
478 public PropertyTable GetPropertyTable ()
480 PropertyTable table = m_heap [PropertyTable.RId] as PropertyTable;
481 if (table != null)
482 return table;
484 table = new PropertyTable ();
485 InitializeTable (table);
486 return table;
489 public PropertyMapTable GetPropertyMapTable ()
491 PropertyMapTable table = m_heap [PropertyMapTable.RId] as PropertyMapTable;
492 if (table != null)
493 return table;
495 table = new PropertyMapTable ();
496 InitializeTable (table);
497 return table;
500 public PropertyPtrTable GetPropertyPtrTable ()
502 PropertyPtrTable table = m_heap [PropertyPtrTable.RId] as PropertyPtrTable;
503 if (table != null)
504 return table;
506 table = new PropertyPtrTable ();
507 InitializeTable (table);
508 return table;
511 public StandAloneSigTable GetStandAloneSigTable ()
513 StandAloneSigTable table = m_heap [StandAloneSigTable.RId] as StandAloneSigTable;
514 if (table != null)
515 return table;
517 table = new StandAloneSigTable ();
518 InitializeTable (table);
519 return table;
522 public TypeDefTable GetTypeDefTable ()
524 TypeDefTable table = m_heap [TypeDefTable.RId] as TypeDefTable;
525 if (table != null)
526 return table;
528 table = new TypeDefTable ();
529 InitializeTable (table);
530 return table;
533 public TypeRefTable GetTypeRefTable ()
535 TypeRefTable table = m_heap [TypeRefTable.RId] as TypeRefTable;
536 if (table != null)
537 return table;
539 table = new TypeRefTable ();
540 InitializeTable (table);
541 return table;
544 public TypeSpecTable GetTypeSpecTable ()
546 TypeSpecTable table = m_heap [TypeSpecTable.RId] as TypeSpecTable;
547 if (table != null)
548 return table;
550 table = new TypeSpecTable ();
551 InitializeTable (table);
552 return table;
555 public override void VisitTableCollection (TableCollection coll)
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);