resources/styles/gccxml2def.xsl
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 30 May 2012 19:57:40 +0000
changeset 21 899da9dea8a9
parent 8 b823a5b502d7
permissions -rw-r--r--
Fixes in styles for modern GCC XML

<?xml version="1.0" encoding="iso-8859-2"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="gccxml2def-function.xsl"/>

  <xsl:output method="text"/>

  <!-- Do not copy white characters from input to output -->
  <xsl:strip-space elements="*" />

  <!-- c-header-file should be set to source C header file from command line -->
  <xsl:param name="c-header-file" select="/GCC_XML/File[1]/@name"/>
  <!-- get ID of source header file; file with ID = f0 is NOT always source header file -->
  <xsl:param name="c-header-file-id" select="/GCC_XML/File[contains(@name,substring($c-header-file,1,string-length($c-header-file)-4))]/@id"/>
  <xsl:param name="c-header-filename" select="/GCC_XML/File[@id=$c-header-file-id]/@name"/>


  <xsl:template match="/">
    <xsl:text>#Generated from: </xsl:text>
      <xsl:value-of select="$c-header-filename"/>
    <xsl:text>&#10;</xsl:text>
<!--
	<xsl:apply-templates select="//*[@file=$c-header-file-id]"/>
-->
    <xsl:apply-templates select="/GCC_XML/*[@context='_1']"/>
  </xsl:template>


  <!-- file has no meaning -->
  <xsl:template match="/GCC_XML/File"/>

  <!-- FunctionType has no meaning -->
  <xsl:template match="/GCC_XML/FunctionType"/>

  <!-- CvQualifiedType is processed by c-type-string template -->
  <xsl:template match="/GCC_XML/CvQualifiedType"/>

  <!-- FundamentalType is processed by c-type-string template -->
  <xsl:template match="/GCC_XML/FundamentalType"/>

  <!-- PointerType is processed by c-type-string template -->
  <xsl:template match="/GCC_XML/PointerType"/>

  <!-- ArrayType is processed by c-type-string template -->
  <xsl:template match="/GCC_XML/ArrayType"/>

  <!-- Class has no meaning -->
  <xsl:template match="/GCC_XML/Class"/>

  <!-- constructors of structures ??? -->
  <xsl:template match="/GCC_XML/Constructor"/>

  <!-- Converter has no meaning -->
  <xsl:template match="/GCC_XML/Converter"/>

  <!-- Destructor has no meaning -->
  <xsl:template match="/GCC_XML/Destructor"/>

  <!-- Method has no meaning -->
  <xsl:template match="/GCC_XML/Method"/>

  <!-- MethodType has no meaning -->
  <xsl:template match="/GCC_XML/MethodType"/>

  <!-- namespace has no meaning -->
  <xsl:template match="/GCC_XML/Namespace"/>

  <!-- NamespaceAlias has no meaning -->
  <xsl:template match="/GCC_XML/NamespaceAlias"/>

  <!-- OperatorFunction has no meaning -->
  <xsl:template match="/GCC_XML/OperatorFunction"/>

  <!-- OperatorMethod has no meaning -->
  <xsl:template match="/GCC_XML/OperatorMethod"/>

  <!-- OffsetType has no meaning -->
  <xsl:template match="/GCC_XML/OffsetType"/>

  <!-- Unimplemented has no meaning -->
  <xsl:template match="/GCC_XML/Unimplemented"/>

  <!-- ReferenceType has no meaning, it has some connection with Constructor -->
  <xsl:template match="/GCC_XML/ReferenceType"/>

  <!-- Variable has no meaning -->
  <xsl:template match="/GCC_XML/Variable"/>

  <xsl:template match="/GCC_XML/Struct">
    <xsl:param name="id" select="@id" />

      <xsl:text>(</xsl:text>
      <xsl:text>struct</xsl:text>
      <xsl:if test="not(@file=$c-header-file-id)">
	<xsl:text>-foreign</xsl:text>
      </xsl:if>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@name"/>
      <xsl:text> :size </xsl:text>
      <xsl:choose>
	<xsl:when test="@size">
	  <xsl:value-of select="@size"/>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:text>0</xsl:text>
	</xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="tokenize">
	<xsl:with-param name="string" select="@members" />
      </xsl:call-template>
      <xsl:text>)&#10;</xsl:text>

  </xsl:template>

  <!-- fields of structures, processed indirectly through tokenize -->
  <xsl:template match="/GCC_XML/Field"/>

  <xsl:template match="/GCC_XML/Enumeration">
    <xsl:param name="id" select="@id" />

      <xsl:text>(</xsl:text>
      <xsl:text>enum</xsl:text>
      <xsl:if test="not(@file=$c-header-file-id)">
	<xsl:text>-foreign</xsl:text>
      </xsl:if>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@name"/>

      <xsl:for-each select="./EnumValue">
	<xsl:text>&#10;&#09;(value (</xsl:text>
	<xsl:value-of select="@name"/>
	<xsl:text>) </xsl:text>
	<xsl:value-of select="@init"/>
	<xsl:text>)</xsl:text>
      </xsl:for-each>

      <xsl:text>)&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="/GCC_XML/Union">
    <xsl:param name="id" select="@id" />

      <xsl:text>(</xsl:text>
      <xsl:text>union</xsl:text>
      <xsl:if test="not(@file=$c-header-file-id)">
	<xsl:text>-foreign</xsl:text>
	  </xsl:if>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@name"/>
      <xsl:text> :size </xsl:text>
      <xsl:choose>
	<xsl:when test="@size">
	  <xsl:value-of select="@size"/>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:text>0</xsl:text>
	</xsl:otherwise>
      </xsl:choose>

      <xsl:text> </xsl:text>


      <xsl:call-template name="tokenize">
	<xsl:with-param name="string" select="@members" />
      </xsl:call-template>

      <xsl:text>)&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="/GCC_XML/Typedef">
	  <xsl:param name="name" select="@name" />
	  <xsl:param name="type" select="@type" />

    <xsl:choose>
      <!-- Omits Typedefs of Structs or Enumaretions with same name -->
      <xsl:when test="/GCC_XML/Struct[@id = $type and @name = $name] or /GCC_XML/Enumeration[@id = $type and @name = $name]"/>

      <!-- Omits Typedefs of Function types and pointers on function types -->
      <xsl:when test="/GCC_XML/FunctionType[@id = $type] or /GCC_XML/FunctionType[@id = /GCC_XML/PointerType[@id = $type]/@type]"/>

      <xsl:otherwise>
	<xsl:text>(typedef</xsl:text>
	<xsl:if test="not(@file=$c-header-file-id)">
	  <xsl:text>-foreign</xsl:text>
	    </xsl:if>
	<xsl:text> </xsl:text>
	<xsl:value-of select="@name"/>
	<xsl:text>&#10;&#09;</xsl:text>

	<xsl:call-template name="c-type-string">
	  <xsl:with-param name="c-type-id" select="@type"/>
	</xsl:call-template>

       <xsl:text>)&#10;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/GCC_XML/Function">
    <xsl:if test="@file = $c-header-file-id">
      <xsl:call-template name="function"/>
    </xsl:if>
  </xsl:template>

  <!-- If reaches here some element is not processed -->
  <xsl:template match="/GCC_XML/*">
    <xsl:message>
      <xsl:text>&#10;#Error: No template for element </xsl:text>
      <xsl:value-of select="local-name(.)"/>
    </xsl:message>
  </xsl:template>

</xsl:stylesheet>