<commit_before><commit_msg>Initial revision of test-to-c transformer<commit_after><?xml version="1.0" encoding="ISO-8859-1"?>
<!--   
This transform generates C source code from a language independent
test representation.
-->

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:str="http://exslt.org/strings"><!-- TODO: exslt not currently used -->
    <!--  relative to transform   -->
    <xsl:param name="interfaces-docname">../build/dom1-interfaces.xml</xsl:param>
    <xsl:param name="target-uri-base">http://www.w3.org/2001/DOM-Test-Suite/tests/Level-1/</xsl:param>
<xsl:output method="text" encoding="UTF-8"/>
<xsl:variable name="domspec" select="document($interfaces-docname)"/>

<!-- swallow any text which we don't understand -->
<xsl:template match="text()"/>

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="*[local-name() = 'test']">
<xsl:text>
int main(int argc, char **argv) {
</xsl:text>
<xsl:apply-templates/>
<xsl:text>
	return 0;
}
</xsl:text>
</xsl:template>

<xsl:template match="*[local-name() = 'var']">
<xsl:text>	struct </xsl:text><xsl:call-template name="convert_var_type"> <xsl:with-param name="var_type" select="@type"/>
</xsl:call-template> *<xsl:value-of select="@name"/>;
</xsl:template>

<xsl:template match="*[local-name() = 'if']">
<xsl:text>	if (</xsl:text><!-- TODO: condition --><xsl:text>) {
</xsl:text>
<!-- TODO: statement(s) -->
<xsl:text>
	}</xsl:text>
<xsl:for-each select="*[local-name() = 'else']">
	<xsl:text> else {
	</xsl:text>
	<xsl:apply-templates/>
	<xsl:text>}</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>

<!--
================================
Assert templates
================================
-->

<xsl:template match="*[local-name() = 'assertNotNull']">
	<!-- TODO: what does the @id string do, and do we need it here? -->
	<xsl:text>	assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> != NULL);
</xsl:text>
</xsl:template>

<xsl:template match="*[local-name() = 'assertNull']">
	<!-- TODO: what does the @id string do, and do we need it here? -->
	<xsl:text>	assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> == NULL);
	</xsl:text>
</xsl:template>

<!-- helper templates -->

<xsl:template name="convert_var_type">
<!-- TODO: convert certain types, e.g. from DocumentType to dom_document_type -->
<xsl:param name="var_type"/>
<xsl:text>dom_</xsl:text><xsl:choose>
	<xsl:when test="$var_type = 'Document'">
		<xsl:text>document</xsl:text>
	</xsl:when>
	<xsl:when test="$var_type = 'DocumentType'">
		<xsl:text>document_type</xsl:text>
	</xsl:when>
	<xsl:when test="$var_type = 'DOMString'">
		<xsl:text>string</xsl:text>
	</xsl:when>
	<xsl:otherwise>
		<xsl:message terminate="no">Warning in convert_var_type template: unrecognised variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
		<xsl:value-of select="$var_type"/>
	</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
{'fraction_non_alphanumeric': 0.24513749161636486, 'fraction_numerical': 0.0077129443326626424, 'mean_word_length': 5.387580299785867, 'pattern_counts': {'":': 0, '<': 98, '<?xml version=': 1, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5480228', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1052, 'n_words': 204}