(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.PEToolkit / build / srcgen / rows.xsl
blob26c9178fedca4a126be6b0d5cd6b01b17c4611db
1 <?xml version="1.0" encoding="iso-8859-1"?>
4 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6 <xsl:import href="gen-utils.xsl"/>
7 <xsl:output method="text"/>
10 <!--
11 -->
13 <xsl:template match="/">// Auto-generated file - DO NOT EDIT!
14 // Please edit md-schema.xml or rows.xsl if you want to make changes.
16 using System;
17 using System.IO;
19 namespace Mono.PEToolkit.Metadata {
21 <xsl:for-each select="md-schema/tables/table">
23 /// &lt;summary&gt;
24 /// Represents row in <xsl:value-of select="@name"/> table.
25 /// &lt;/summary&gt;
26 /// &lt;remarks&gt;
27 /// <xsl:if test="@section">See Partition II, Metadata; section <xsl:value-of select="@section"/></xsl:if>
28 /// &lt;/remarks&gt;
29 public class <xsl:value-of select="@name"/>Row : Row {
31 private MDTable table;
33 <xsl:for-each select="schema/field">
34 public <xsl:call-template name="get-field-type"/><xsl:value-of select="concat(' ',@name)"/>;</xsl:for-each>
36 public <xsl:value-of select="@name"/>Row()
40 public <xsl:value-of select="@name"/>Row(MDTable parent)
42 table = parent;
46 /// &lt;summary&gt;
47 /// Row in <xsl:value-of select="@name"/> table has <xsl:value-of select="count(schema/field)"/> columns.
48 /// &lt;/summary&gt;
49 public virtual int NumberOfColumns {
50 get {
51 return <xsl:value-of select="count(schema/field)"/>;
56 /// &lt;summary&gt;
57 /// Logical size of this instance in bytes.
58 /// &lt;/summary&gt;
59 public virtual int Size {
60 get {
61 return LogicalSize;
66 /// &lt;summary&gt;
67 /// &lt;/summary&gt;
68 public virtual MDTable Table {
69 get {
70 return table;
75 /// &lt;summary&gt;
76 /// Logical size of this type of row in bytes.
77 /// &lt;/summary&gt;
78 unsafe public static int LogicalSize {
79 get {
80 return <xsl:call-template name="get-expanded-size"/>;
85 /// &lt;summary&gt;
86 /// Fills the row from the array of bytes.
87 /// &lt;/summary&gt;
88 unsafe public void FromRawData(byte [] buff, int offs)
90 if (buff == null) throw new Exception("buff == null");
91 if (offs + Size > buff.Length) throw new Exception("bounds");
93 <xsl:for-each select="schema/field">
94 this.<xsl:value-of select="@name"/> = <xsl:call-template name="get-field-conversion-code"/>;
95 <xsl:if test="position() != last()">
96 <xsl:text>offs += </xsl:text>
97 <xsl:call-template name="get-expanded-size">
98 <xsl:with-param name="fields" select="."/>
99 </xsl:call-template>
100 <xsl:text>;</xsl:text>
101 </xsl:if>
102 </xsl:for-each>
105 <xsl:variable name="spaces" select="' '"/>
107 /// &lt;summary&gt;
108 /// &lt;/summary&gt;
109 public void Dump(TextWriter writer) {
110 <xsl:text>string dump = String.Format(</xsl:text>
111 <xsl:for-each select="schema/field">
112 "<xsl:value-of select="concat(@name,substring($spaces,1,18 - string-length(@name)))"/>: {<xsl:value-of select="position () - 1"/>}" <xsl:text>+ Environment.NewLine</xsl:text>
113 <xsl:if test="position() != last()"><xsl:text> + </xsl:text></xsl:if>
114 <xsl:if test="position() = last()"><xsl:text>,</xsl:text></xsl:if>
115 </xsl:for-each>
116 <xsl:for-each select="schema/field">
117 <xsl:choose><!-- TODO: do something about ugly expression below -->
118 <xsl:when test="contains(@type,'#Strings')">
119 (<xsl:text>Table == null) ? </xsl:text>
120 <xsl:value-of select="concat(@name, '.ToString()')"/>
121 <xsl:text> : "\"" + ((Table.Heap.Stream.Root.Streams["#Strings"] as MDStream).Heap as StringsHeap) [</xsl:text>
122 <xsl:value-of select="@name"/><xsl:text>] + "\" (#Strings[0x" + </xsl:text><xsl:value-of select="@name"/><xsl:text>.ToString("X") + "])"</xsl:text>
123 </xsl:when>
124 <xsl:when test="contains(@type,'index') and not(contains(@type,'coded-index'))">
125 &quot;<xsl:call-template name="extract-arg"/>[&quot; + <xsl:value-of select="@name"/><xsl:text>.ToString() + "]"</xsl:text>
126 </xsl:when>
127 <xsl:otherwise>
128 this.<xsl:value-of select="@name"/>
129 </xsl:otherwise>
130 </xsl:choose>
131 <xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>
132 </xsl:for-each>
134 writer.WriteLine(dump);
138 /// &lt;summary&gt;
139 /// &lt;/summary&gt;
140 public override string ToString()
142 StringWriter sw = new StringWriter();
143 Dump(sw);
144 return sw.ToString();
149 </xsl:for-each>
153 </xsl:template>
160 <!-- ******************************************************************* -->
161 <xsl:template name="get-field-conversion-code">
162 <xsl:param name="field" select="."/>
163 <xsl:variable name="type" select="$field/@type"/>
165 <xsl:choose>
166 <!-- RVA - library type -->
167 <xsl:when test="$type = 'RVA'">
168 <xsl:text>LEBitConverter.ToUInt32(buff, offs)</xsl:text>
169 </xsl:when>
171 <!-- table indices -->
172 <xsl:when test="starts-with($type,'index')">
173 <xsl:text>LEBitConverter.ToInt32(buff, offs)</xsl:text>
174 </xsl:when>
176 <!-- coded tokens -->
177 <xsl:when test="starts-with($type,'coded-index')">
178 <xsl:text>TabsDecoder.DecodeToken(CodedTokenId.</xsl:text>
179 <xsl:call-template name="extract-arg">
180 <xsl:with-param name="expr" select="$type"/>
181 </xsl:call-template>
182 <xsl:text>, LEBitConverter.ToInt32(buff, offs))</xsl:text>
183 </xsl:when>
185 <!-- primitive type -->
186 <xsl:otherwise>
187 <!-- explicitly mapped to library type -->
188 <xsl:if test="$field/@cli-type">
189 <xsl:value-of select="concat('(', $field/@cli-type, ') ')"/>
190 </xsl:if>
191 <xsl:choose>
192 <xsl:when test="$type = 'byte'">
193 <xsl:text>buff [offs]</xsl:text>
194 </xsl:when>
195 <xsl:when test="$type = 'short'">
196 <xsl:text>LEBitConverter.ToInt16(buff, offs)</xsl:text>
197 </xsl:when>
198 <xsl:when test="$type = 'ushort'">
199 <xsl:text>LEBitConverter.ToUInt16(buff, offs)</xsl:text>
200 </xsl:when>
201 <xsl:when test="$type = 'int'">
202 <xsl:text>LEBitConverter.ToInt32(buff, offs)</xsl:text>
203 </xsl:when>
204 <xsl:when test="$type = 'uint'">
205 <xsl:text>LEBitConverter.ToUInt32(buff, offs)</xsl:text>
206 </xsl:when>
207 <xsl:when test="$type = 'long'">
208 <xsl:text>LEBitConverter.ToInt64(buff, offs)</xsl:text>
209 </xsl:when>
210 <xsl:when test="$type = 'ulong'">
211 <xsl:text>LEBitConverter.ToUInt64(buff, offs)</xsl:text>
212 </xsl:when>
213 <xsl:otherwise>
214 <xsl:text>/* ERROR! */</xsl:text>
215 </xsl:otherwise>
216 </xsl:choose>
217 </xsl:otherwise>
218 </xsl:choose>
219 </xsl:template>
225 </xsl:stylesheet>