resources/examples/libgit2/styles/gccxml2def-utils.xsl
changeset 25 9718bd0f1028
equal deleted inserted replaced
24:e7afa531abcf 25:9718bd0f1028
       
     1 <?xml version="1.0" encoding="iso-8859-2"?>
       
     2 <xsl:stylesheet 
       
     3     version="1.0"
       
     4     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       
     5 
       
     6   <xsl:template name="c-type-string">
       
     7     <xsl:param name="c-type-id"/>
       
     8     <xsl:param name="c-name-id" select="$c-type-id"/>
       
     9     
       
    10     <xsl:choose>
       
    11       <xsl:when test="/GCC_XML/PointerType[@id = $c-type-id]">
       
    12 	<xsl:text>(pointer-to </xsl:text>
       
    13 	
       
    14 	<xsl:choose>
       
    15 	  <!-- Pointer is a part of the user defined type -->
       
    16 	  <!-- save the name that type -->
       
    17 	  <xsl:when test="/GCC_XML/Typedef[@type = $c-type-id]">
       
    18 	    <xsl:call-template name="c-type-string">
       
    19 	      <xsl:with-param name="c-type-id" select="/GCC_XML/PointerType[@id = $c-type-id]/@type"/>
       
    20 	      <xsl:with-param name="c-name-id" select="/GCC_XML/Typedef[@type = $c-type-id]/@name"/>          
       
    21 	    </xsl:call-template>            
       
    22 	  </xsl:when>
       
    23 
       
    24 	  <xsl:otherwise>
       
    25 	    <xsl:call-template name="c-type-string">
       
    26 	      <xsl:with-param name="c-type-id" select="/GCC_XML/PointerType[@id = $c-type-id]/@type"/>
       
    27 	      <xsl:with-param name="c-name-id" select="/GCC_XML/PointerType[@id = $c-type-id]/@type"/>          
       
    28 	    </xsl:call-template>            
       
    29 	  </xsl:otherwise>
       
    30 	</xsl:choose>
       
    31 	<xsl:text>)</xsl:text>        
       
    32       </xsl:when>
       
    33 
       
    34       <xsl:when test="/GCC_XML/CvQualifiedType[@id = $c-type-id]">
       
    35 	<xsl:if test="/GCC_XML/CvQualifiedType[@id = $c-type-id]/@const = 1"><xsl:text>const </xsl:text></xsl:if>
       
    36 	<xsl:call-template name="c-type-string">
       
    37 	  <xsl:with-param name="c-type-id" select="/GCC_XML/CvQualifiedType[@id = $c-type-id]/@type"/>	 
       
    38 	</xsl:call-template>
       
    39       </xsl:when>
       
    40       
       
    41       <xsl:when test="/GCC_XML/FundamentalType[@id = $c-type-id]">
       
    42 	<xsl:value-of select="/GCC_XML/FundamentalType[@id = $c-type-id]/@name"/>
       
    43       </xsl:when>
       
    44 
       
    45       <xsl:when test="/GCC_XML/Typedef[@id = $c-type-id]">
       
    46 	<xsl:choose>
       
    47 	  <!-- Fundamental types are resolved -->
       
    48 	  <xsl:when test="/GCC_XML/FundamentalType[@id = /GCC_XML/Typedef[@id = $c-type-id]/@type]" >
       
    49 	    <xsl:value-of select="/GCC_XML/FundamentalType[@id = /GCC_XML/Typedef[@id = $c-type-id]/@type]/@name"/>
       
    50 	  </xsl:when>
       
    51 
       
    52 	  <!-- Pointers are resolved -->
       
    53 	  <xsl:when test="/GCC_XML/PointerType[@id = /GCC_XML/Typedef[@id = $c-type-id]/@type]" >
       
    54 	    <xsl:call-template name="c-type-string">
       
    55 	      <xsl:with-param name="c-type-id" select="/GCC_XML/Typedef[@id = $c-type-id]/@type"/>	 
       
    56 	    </xsl:call-template>
       
    57 	  </xsl:when>
       
    58 
       
    59 	  <!-- Typedefs are resolved -->
       
    60 	  <xsl:when test="/GCC_XML/Typedef[@id = /GCC_XML/Typedef[@id = $c-type-id]/@type]" >
       
    61 	    <xsl:call-template name="c-type-string">
       
    62 	      <xsl:with-param name="c-type-id" select="/GCC_XML/Typedef[@id = $c-type-id]/@type"/>	 
       
    63 	    </xsl:call-template>
       
    64 	  </xsl:when>         
       
    65 	  
       
    66 	  <!-- Function types are resolved -->
       
    67 	  <xsl:when test="/GCC_XML/FunctionType[@id = /GCC_XML/Typedef[@id = $c-type-id]/@type]">
       
    68 	    <xsl:call-template name="c-type-string">
       
    69 	      <xsl:with-param name="c-type-id" select="/GCC_XML/Typedef[@id = $c-type-id]/@type"/>
       
    70 	      <xsl:with-param name="c-name-id" select="/GCC_XML/Typedef[@id = $c-type-id]/@name"/>	 
       
    71 	    </xsl:call-template>
       
    72 	  </xsl:when>
       
    73 
       
    74 	  <!-- remaining not, possible loop in struct -->
       
    75 	  <xsl:otherwise>
       
    76 	    <xsl:value-of select="/GCC_XML/Typedef[@id = $c-type-id]/@name"/>
       
    77 	  </xsl:otherwise>
       
    78 	</xsl:choose>       	                    
       
    79       </xsl:when>
       
    80 
       
    81       <xsl:when test="/GCC_XML/FunctionType[@id = $c-type-id]">
       
    82 	<xsl:text>(function-type </xsl:text>        
       
    83 	<xsl:value-of select="$c-name-id"/>       
       
    84 	<xsl:text>&#10;&#09;&#09;&#09;(</xsl:text>
       
    85 
       
    86 	<xsl:for-each select="/GCC_XML/FunctionType[@id = $c-type-id]/Argument">
       
    87 	  <xsl:text>&#10;&#09;&#09;&#09;&#09;(argument (</xsl:text>
       
    88 	  <xsl:call-template name="c-type-string">
       
    89 	    <xsl:with-param name="c-type-id" select="@type"/>
       
    90 	  </xsl:call-template>
       
    91 	  <xsl:text>) </xsl:text>
       
    92 	  <xsl:value-of select="@name"/>
       
    93 	  <xsl:text>)</xsl:text>			
       
    94 	</xsl:for-each>
       
    95 	<xsl:text>)&#10;&#09;&#09;&#09;(return </xsl:text>
       
    96 	<xsl:call-template name="c-type-string">
       
    97 	  <xsl:with-param name="c-type-id" select="/GCC_XML/FunctionType[@id = $c-type-id]/@returns"/>
       
    98 	</xsl:call-template>
       
    99 	<xsl:text>))</xsl:text>
       
   100       </xsl:when>
       
   101 
       
   102       <xsl:when test="/GCC_XML/Enumeration[@id = $c-type-id]">
       
   103 	<xsl:value-of select="/GCC_XML/Enumeration[@id = $c-type-id]/@name"/>
       
   104       </xsl:when>
       
   105 
       
   106       <xsl:when test="/GCC_XML/Struct[@id = $c-type-id]">
       
   107 	<xsl:choose>
       
   108 	  <xsl:when test="/GCC_XML/Struct[@id = $c-type-id and not(@name)] or /GCC_XML/Struct[@id = $c-type-id]/@name = ''">
       
   109 	    <xsl:value-of select="/GCC_XML/Struct[@id = $c-type-id]/@id"/>  
       
   110 	  </xsl:when>
       
   111 	  <xsl:otherwise>
       
   112 	    <xsl:value-of select="/GCC_XML/Struct[@id = $c-type-id]/@name"/>
       
   113 	  </xsl:otherwise>
       
   114 	</xsl:choose>                
       
   115       </xsl:when>
       
   116 
       
   117       <xsl:when test="/GCC_XML/ArrayType[@id = $c-type-id]">
       
   118 	<xsl:text>(array (</xsl:text>        
       
   119 	<xsl:call-template name="c-type-string">
       
   120 	  <xsl:with-param name="c-type-id" select="/GCC_XML/ArrayType[@id = $c-type-id]/@type"/>	 
       
   121 	</xsl:call-template>
       
   122 	<xsl:text>) </xsl:text>
       
   123 	<xsl:value-of select="/GCC_XML/ArrayType[@id = $c-type-id]/@max"/>                
       
   124 	<xsl:text>)</xsl:text>                
       
   125       </xsl:when>
       
   126       
       
   127       <xsl:when test="/GCC_XML/Union[@id = $c-type-id]">
       
   128 	<xsl:choose>
       
   129 	  <xsl:when test="/GCC_XML/Union[@id = $c-type-id and not(@name)] or /GCC_XML/Union[@id = $c-type-id]/@name = ''">
       
   130 	    <xsl:value-of select="/GCC_XML/Union[@id = $c-type-id]/@id"/>  
       
   131 	  </xsl:when>
       
   132 	  <xsl:otherwise>            
       
   133 	    <xsl:value-of select="/GCC_XML/Union[@id = $c-type-id]/@name"/>
       
   134 	  </xsl:otherwise>
       
   135 	</xsl:choose>        
       
   136       </xsl:when>
       
   137       
       
   138       <xsl:otherwise>
       
   139 	<xsl:message>
       
   140 	  <xsl:text>&#10;#Error: --c-type-string-- Unknown C type with id </xsl:text>
       
   141 	  <xsl:value-of select="$c-type-id"/>
       
   142 	</xsl:message>
       
   143       </xsl:otherwise>
       
   144     </xsl:choose>
       
   145   </xsl:template>  
       
   146 
       
   147   
       
   148   <!--- ========== Tokenizer ================== -->
       
   149   <xsl:template name="tokenize">
       
   150     <xsl:param name="string" select="''" />
       
   151     <xsl:param name="delimiter" select="' '" />
       
   152     <xsl:param name="indent" select="1"/>
       
   153     <xsl:choose>
       
   154       <xsl:when test="not($string)" />
       
   155       <xsl:when test="not($delimiter)" />
       
   156       <xsl:when test="$string = ''" />
       
   157       <xsl:otherwise>
       
   158 	<xsl:call-template name="_tokenize-delimiter">
       
   159 	  <xsl:with-param name="string" select="$string" />
       
   160 	  <xsl:with-param name="delimiter" select="$delimiter" />
       
   161 	  <xsl:with-param name="indent" select="$indent" />
       
   162 	</xsl:call-template>
       
   163       </xsl:otherwise>
       
   164     </xsl:choose>
       
   165   </xsl:template>
       
   166 
       
   167   <xsl:template name="_tokenize-delimiter">
       
   168     <xsl:param name="string" />
       
   169     <xsl:param name="delimiter" />
       
   170     <xsl:param name="indent" />
       
   171     <xsl:choose>
       
   172       <xsl:when test="not($string)" />
       
   173 
       
   174       <xsl:when test="contains($string, $delimiter)">
       
   175 
       
   176 	<xsl:call-template name="find-field">
       
   177 	  <xsl:with-param name="field-id" select="substring-before($string, $delimiter)"/>
       
   178 	  <xsl:with-param name="string" select="$string"/>
       
   179 	  <xsl:with-param name="indent" select="$indent" />
       
   180 	</xsl:call-template>       
       
   181 
       
   182 	<xsl:call-template name="_tokenize-delimiter">
       
   183 	  <xsl:with-param name="string"	select="substring-after($string, $delimiter)" />
       
   184 	  <xsl:with-param name="delimiter" select="$delimiter" />
       
   185 	  <xsl:with-param name="indent" select="$indent" />
       
   186 	</xsl:call-template>
       
   187       </xsl:when>	  
       
   188       
       
   189       <xsl:otherwise>
       
   190 	<xsl:message>              
       
   191 	  <xsl:text>&#10;#Error: --tokenizer-- Nothing happend for string </xsl:text>            
       
   192 	  <xsl:value-of select="$string"/>
       
   193 	</xsl:message>            
       
   194       </xsl:otherwise>
       
   195     </xsl:choose>
       
   196     
       
   197   </xsl:template>
       
   198 
       
   199   
       
   200 
       
   201   <!--- ========== Find Field ================== -->  
       
   202   <xsl:template name="find-field">
       
   203     <xsl:param name="field-id"/>
       
   204     <xsl:param name="field" select="/GCC_XML/*[@id = $field-id]"/>
       
   205     <xsl:param name="field-type" select="/GCC_XML/*[@id = $field/@type]"/>
       
   206     <xsl:param name="string"/>
       
   207     <xsl:param name="indent" />
       
   208     <xsl:choose>
       
   209 
       
   210       <xsl:when test="not($field)">
       
   211 	<xsl:message>
       
   212 	  <xsl:text>&#10;#Error: find-field: Field with id </xsl:text>
       
   213 	  <xsl:value-of select="$field-id"/>
       
   214 	  <xsl:text> not found!</xsl:text>
       
   215 	</xsl:message>
       
   216       </xsl:when>
       
   217 
       
   218       <xsl:when test="local-name($field) = 'Struct'"/>
       
   219       <xsl:when test="local-name($field) = 'Enumeration'"/>
       
   220       <xsl:when test="local-name($field) = 'Union'"/>
       
   221 
       
   222       <xsl:when test="$field">
       
   223 	<xsl:text>&#10;</xsl:text>
       
   224 	<xsl:call-template name="indent">
       
   225 	  <xsl:with-param name="count" select="$indent"/>
       
   226 	</xsl:call-template>	
       
   227 	<xsl:text>(field (</xsl:text>	
       
   228 	<xsl:choose>
       
   229 	  <xsl:when test="not($field-type/@name)">
       
   230 	    <xsl:text>&#10;</xsl:text>
       
   231 	    <xsl:call-template name="indent">
       
   232 	      <xsl:with-param name="count" select="$indent+1"/>
       
   233 	    </xsl:call-template>
       
   234 	    <xsl:choose>
       
   235 	      <xsl:when test="
       
   236 		   local-name($field-type) = 'PointerType'
       
   237 		or local-name($field-type) = 'FundamentalType'
       
   238 		or local-name($field-type) = 'CvQualifiedType'
       
   239 		or local-name($field-type) =  'ArrayType'
       
   240 		">
       
   241 		<xsl:call-template name="c-type-string">
       
   242 		  <xsl:with-param name="c-type-id" select="/GCC_XML/Field[@id = $field-id]/@type"/>
       
   243 		</xsl:call-template>
       
   244 	      </xsl:when>
       
   245 	      <xsl:otherwise>
       
   246 		<xsl:apply-templates select="$field-type"/>
       
   247 	      </xsl:otherwise>
       
   248 	    </xsl:choose>
       
   249 	    <xsl:text>&#10;</xsl:text>
       
   250 	  </xsl:when>
       
   251 	  <xsl:otherwise>
       
   252 	    <xsl:call-template name="c-type-string">
       
   253 	      <xsl:with-param name="c-type-id" select="/GCC_XML/Field[@id = $field-id]/@type"/>
       
   254 	    </xsl:call-template>        
       
   255 	  </xsl:otherwise>
       
   256 	</xsl:choose>
       
   257 	<xsl:text>) </xsl:text>
       
   258 	
       
   259 	<xsl:if test="/GCC_XML/Field[@id = $field-id]/@name = ''">
       
   260 	  <!-- Field has not defined name -->
       
   261 	  <xsl:text>unknown</xsl:text>
       
   262 	  <xsl:value-of select="/GCC_XML/Field[@id = $field-id]/@id"/>
       
   263 	</xsl:if>
       
   264 	<xsl:value-of select="/GCC_XML/Field[@id = $field-id]/@name"/>
       
   265 
       
   266 	<xsl:text> :offset </xsl:text>
       
   267 	<xsl:value-of select="/GCC_XML/Field[@id = $field-id]/@offset"/>
       
   268 	
       
   269 	<xsl:text>)</xsl:text>               
       
   270       </xsl:when>
       
   271 
       
   272       <xsl:otherwise>
       
   273 	<xsl:message>
       
   274 	  <xsl:text>&#10;#Error: find-field: Unknown error for id </xsl:text>
       
   275 	  <xsl:value-of select="$field-id"/>
       
   276 	</xsl:message>
       
   277       </xsl:otherwise>
       
   278     </xsl:choose>
       
   279   </xsl:template>
       
   280   
       
   281   
       
   282   
       
   283   <!--- ========== indent ================== -->
       
   284   <xsl:template name="indent">  
       
   285     <xsl:param name="count" select="1"/>
       
   286     
       
   287     <xsl:if test="$count > 0">
       
   288       <xsl:text>&#09;</xsl:text>      
       
   289       <xsl:call-template name="indent">
       
   290 	<xsl:with-param name="count" select="$count - 1"/>
       
   291       </xsl:call-template>
       
   292     </xsl:if>      
       
   293   </xsl:template>  
       
   294   
       
   295   
       
   296 </xsl:stylesheet>