2 // MetadataTableWriter.cs
5 // Jb Evain (jbevain@gmail.com)
7 // Generated by /CodeGen/cecil-gen.rb do not edit
8 // Thu Feb 22 14:39:38 CET 2007
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
{
35 using System
.Collections
;
37 using Mono
.Cecil
.Binary
;
39 internal sealed class MetadataTableWriter
: BaseMetadataTableVisitor
{
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 ()
59 public override IMetadataRowVisitor
GetRowVisitor ()
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
;
88 table
= new AssemblyTable ();
89 InitializeTable (table
);
93 public AssemblyOSTable
GetAssemblyOSTable ()
95 AssemblyOSTable table
= m_heap
[AssemblyOSTable
.RId
] as AssemblyOSTable
;
99 table
= new AssemblyOSTable ();
100 InitializeTable (table
);
104 public AssemblyProcessorTable
GetAssemblyProcessorTable ()
106 AssemblyProcessorTable table
= m_heap
[AssemblyProcessorTable
.RId
] as AssemblyProcessorTable
;
110 table
= new AssemblyProcessorTable ();
111 InitializeTable (table
);
115 public AssemblyRefTable
GetAssemblyRefTable ()
117 AssemblyRefTable table
= m_heap
[AssemblyRefTable
.RId
] as AssemblyRefTable
;
121 table
= new AssemblyRefTable ();
122 InitializeTable (table
);
126 public AssemblyRefOSTable
GetAssemblyRefOSTable ()
128 AssemblyRefOSTable table
= m_heap
[AssemblyRefOSTable
.RId
] as AssemblyRefOSTable
;
132 table
= new AssemblyRefOSTable ();
133 InitializeTable (table
);
137 public AssemblyRefProcessorTable
GetAssemblyRefProcessorTable ()
139 AssemblyRefProcessorTable table
= m_heap
[AssemblyRefProcessorTable
.RId
] as AssemblyRefProcessorTable
;
143 table
= new AssemblyRefProcessorTable ();
144 InitializeTable (table
);
148 public ClassLayoutTable
GetClassLayoutTable ()
150 ClassLayoutTable table
= m_heap
[ClassLayoutTable
.RId
] as ClassLayoutTable
;
154 table
= new ClassLayoutTable ();
155 InitializeTable (table
);
159 public ConstantTable
GetConstantTable ()
161 ConstantTable table
= m_heap
[ConstantTable
.RId
] as ConstantTable
;
165 table
= new ConstantTable ();
166 InitializeTable (table
);
170 public CustomAttributeTable
GetCustomAttributeTable ()
172 CustomAttributeTable table
= m_heap
[CustomAttributeTable
.RId
] as CustomAttributeTable
;
176 table
= new CustomAttributeTable ();
177 InitializeTable (table
);
181 public DeclSecurityTable
GetDeclSecurityTable ()
183 DeclSecurityTable table
= m_heap
[DeclSecurityTable
.RId
] as DeclSecurityTable
;
187 table
= new DeclSecurityTable ();
188 InitializeTable (table
);
192 public EventTable
GetEventTable ()
194 EventTable table
= m_heap
[EventTable
.RId
] as EventTable
;
198 table
= new EventTable ();
199 InitializeTable (table
);
203 public EventMapTable
GetEventMapTable ()
205 EventMapTable table
= m_heap
[EventMapTable
.RId
] as EventMapTable
;
209 table
= new EventMapTable ();
210 InitializeTable (table
);
214 public EventPtrTable
GetEventPtrTable ()
216 EventPtrTable table
= m_heap
[EventPtrTable
.RId
] as EventPtrTable
;
220 table
= new EventPtrTable ();
221 InitializeTable (table
);
225 public ExportedTypeTable
GetExportedTypeTable ()
227 ExportedTypeTable table
= m_heap
[ExportedTypeTable
.RId
] as ExportedTypeTable
;
231 table
= new ExportedTypeTable ();
232 InitializeTable (table
);
236 public FieldTable
GetFieldTable ()
238 FieldTable table
= m_heap
[FieldTable
.RId
] as FieldTable
;
242 table
= new FieldTable ();
243 InitializeTable (table
);
247 public FieldLayoutTable
GetFieldLayoutTable ()
249 FieldLayoutTable table
= m_heap
[FieldLayoutTable
.RId
] as FieldLayoutTable
;
253 table
= new FieldLayoutTable ();
254 InitializeTable (table
);
258 public FieldMarshalTable
GetFieldMarshalTable ()
260 FieldMarshalTable table
= m_heap
[FieldMarshalTable
.RId
] as FieldMarshalTable
;
264 table
= new FieldMarshalTable ();
265 InitializeTable (table
);
269 public FieldPtrTable
GetFieldPtrTable ()
271 FieldPtrTable table
= m_heap
[FieldPtrTable
.RId
] as FieldPtrTable
;
275 table
= new FieldPtrTable ();
276 InitializeTable (table
);
280 public FieldRVATable
GetFieldRVATable ()
282 FieldRVATable table
= m_heap
[FieldRVATable
.RId
] as FieldRVATable
;
286 table
= new FieldRVATable ();
287 InitializeTable (table
);
291 public FileTable
GetFileTable ()
293 FileTable table
= m_heap
[FileTable
.RId
] as FileTable
;
297 table
= new FileTable ();
298 InitializeTable (table
);
302 public GenericParamTable
GetGenericParamTable ()
304 GenericParamTable table
= m_heap
[GenericParamTable
.RId
] as GenericParamTable
;
308 table
= new GenericParamTable ();
309 InitializeTable (table
);
313 public GenericParamConstraintTable
GetGenericParamConstraintTable ()
315 GenericParamConstraintTable table
= m_heap
[GenericParamConstraintTable
.RId
] as GenericParamConstraintTable
;
319 table
= new GenericParamConstraintTable ();
320 InitializeTable (table
);
324 public ImplMapTable
GetImplMapTable ()
326 ImplMapTable table
= m_heap
[ImplMapTable
.RId
] as ImplMapTable
;
330 table
= new ImplMapTable ();
331 InitializeTable (table
);
335 public InterfaceImplTable
GetInterfaceImplTable ()
337 InterfaceImplTable table
= m_heap
[InterfaceImplTable
.RId
] as InterfaceImplTable
;
341 table
= new InterfaceImplTable ();
342 InitializeTable (table
);
346 public ManifestResourceTable
GetManifestResourceTable ()
348 ManifestResourceTable table
= m_heap
[ManifestResourceTable
.RId
] as ManifestResourceTable
;
352 table
= new ManifestResourceTable ();
353 InitializeTable (table
);
357 public MemberRefTable
GetMemberRefTable ()
359 MemberRefTable table
= m_heap
[MemberRefTable
.RId
] as MemberRefTable
;
363 table
= new MemberRefTable ();
364 InitializeTable (table
);
368 public MethodTable
GetMethodTable ()
370 MethodTable table
= m_heap
[MethodTable
.RId
] as MethodTable
;
374 table
= new MethodTable ();
375 InitializeTable (table
);
379 public MethodImplTable
GetMethodImplTable ()
381 MethodImplTable table
= m_heap
[MethodImplTable
.RId
] as MethodImplTable
;
385 table
= new MethodImplTable ();
386 InitializeTable (table
);
390 public MethodPtrTable
GetMethodPtrTable ()
392 MethodPtrTable table
= m_heap
[MethodPtrTable
.RId
] as MethodPtrTable
;
396 table
= new MethodPtrTable ();
397 InitializeTable (table
);
401 public MethodSemanticsTable
GetMethodSemanticsTable ()
403 MethodSemanticsTable table
= m_heap
[MethodSemanticsTable
.RId
] as MethodSemanticsTable
;
407 table
= new MethodSemanticsTable ();
408 InitializeTable (table
);
412 public MethodSpecTable
GetMethodSpecTable ()
414 MethodSpecTable table
= m_heap
[MethodSpecTable
.RId
] as MethodSpecTable
;
418 table
= new MethodSpecTable ();
419 InitializeTable (table
);
423 public ModuleTable
GetModuleTable ()
425 ModuleTable table
= m_heap
[ModuleTable
.RId
] as ModuleTable
;
429 table
= new ModuleTable ();
430 InitializeTable (table
);
434 public ModuleRefTable
GetModuleRefTable ()
436 ModuleRefTable table
= m_heap
[ModuleRefTable
.RId
] as ModuleRefTable
;
440 table
= new ModuleRefTable ();
441 InitializeTable (table
);
445 public NestedClassTable
GetNestedClassTable ()
447 NestedClassTable table
= m_heap
[NestedClassTable
.RId
] as NestedClassTable
;
451 table
= new NestedClassTable ();
452 InitializeTable (table
);
456 public ParamTable
GetParamTable ()
458 ParamTable table
= m_heap
[ParamTable
.RId
] as ParamTable
;
462 table
= new ParamTable ();
463 InitializeTable (table
);
467 public ParamPtrTable
GetParamPtrTable ()
469 ParamPtrTable table
= m_heap
[ParamPtrTable
.RId
] as ParamPtrTable
;
473 table
= new ParamPtrTable ();
474 InitializeTable (table
);
478 public PropertyTable
GetPropertyTable ()
480 PropertyTable table
= m_heap
[PropertyTable
.RId
] as PropertyTable
;
484 table
= new PropertyTable ();
485 InitializeTable (table
);
489 public PropertyMapTable
GetPropertyMapTable ()
491 PropertyMapTable table
= m_heap
[PropertyMapTable
.RId
] as PropertyMapTable
;
495 table
= new PropertyMapTable ();
496 InitializeTable (table
);
500 public PropertyPtrTable
GetPropertyPtrTable ()
502 PropertyPtrTable table
= m_heap
[PropertyPtrTable
.RId
] as PropertyPtrTable
;
506 table
= new PropertyPtrTable ();
507 InitializeTable (table
);
511 public StandAloneSigTable
GetStandAloneSigTable ()
513 StandAloneSigTable table
= m_heap
[StandAloneSigTable
.RId
] as StandAloneSigTable
;
517 table
= new StandAloneSigTable ();
518 InitializeTable (table
);
522 public TypeDefTable
GetTypeDefTable ()
524 TypeDefTable table
= m_heap
[TypeDefTable
.RId
] as TypeDefTable
;
528 table
= new TypeDefTable ();
529 InitializeTable (table
);
533 public TypeRefTable
GetTypeRefTable ()
535 TypeRefTable table
= m_heap
[TypeRefTable
.RId
] as TypeRefTable
;
539 table
= new TypeRefTable ();
540 InitializeTable (table
);
544 public TypeSpecTable
GetTypeSpecTable ()
546 TypeSpecTable table
= m_heap
[TypeSpecTable
.RId
] as TypeSpecTable
;
550 table
= new TypeSpecTable ();
551 InitializeTable (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
);