2016-02-24 11:11:41 +11:00
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:fo= "http://www.w3.org/1999/XSL/Format" >
<xsl:output method= "text" omit-xml-declaration= "yes" indent= "no" />
<!-- type declarations -->
<xsl:template match= "type[@category='basetype']" >
using <xsl:value-of select= "name" /> = <xsl:value-of select= "type" /> ;
</xsl:template>
<xsl:template match= "type[@category='bitmask']" >
using <xsl:value-of select= "name" /> = <xsl:value-of select= "type" /> ;
</xsl:template>
<xsl:template match= "type[@category='handle']" >
// actually a 64 bit pointer
// should make use of parent info
using <xsl:value-of select= "name" /> = uint64_t;
</xsl:template>
<xsl:template match= "type[@category='funcpointer']" >
// should make use of function parameters
typedef void (*<xsl:value-of select= "name" /> ) (void);
</xsl:template>
<xsl:template match= "type[@category='struct']" >
struct <xsl:value-of select= "@name" /> {
<xsl:for-each select= "member" >
<xsl:for-each select= ".//text()" >
<xsl:value-of select= "." />
<xsl:text > </xsl:text>
</xsl:for-each>
<xsl:text > ;</xsl:text>
</xsl:for-each>
};
</xsl:template>
<xsl:template match= "type[@category='union']" >
// should make use of member types
union <xsl:value-of select= "@name" /> {
<xsl:for-each select= "member" >
<xsl:value-of select= "type" />
<xsl:text > </xsl:text>
<xsl:value-of select= "name" />
<xsl:text > ;</xsl:text>
</xsl:for-each>
};
</xsl:template>
<!-- we have to define these system types manually because they aren't consistent types -->
2017-05-26 16:31:31 +10:00
<xsl:template match= "type[not(@category) and @name]" />
2016-02-24 11:11:41 +11:00
<xsl:template match= "type[@category='define']" /> <!-- we handle defines manually -->
<xsl:template match= "type[@category='enum']" /> <!-- handed where the values are declared -->
<xsl:template match= "type[@category='include']" /> <!-- we can't arbitrarily include headers in a platform independant way -->
<xsl:template match= "types" >
<xsl:apply-templates />
</xsl:template>
<!-- enumerations -->
<xsl:template match= "enums[@name='API Constants']" >
<xsl:for-each select= "enum" >
constexpr auto <xsl:value-of select= "@name" /> = <xsl:value-of select= "@value" /> ;
</xsl:for-each>
</xsl:template>
<xsl:template match= "enums[@type='enum']" >
// make use of @expand
enum <xsl:value-of select= "@name" /> {
<xsl:for-each select= "enum" >
<xsl:value-of select= "@name" /> = <xsl:value-of select= "@value" /> ,
</xsl:for-each>
};
</xsl:template>
<xsl:template match= "enums[@type='bitmask']" >
enum <xsl:value-of select= '@name' /> {
<xsl:for-each select= "enum" >
<xsl:choose >
<xsl:when test= "@bitpos" >
<xsl:value-of select= "@name" /> = 1UL < < <xsl:value-of select= "@bitpos" />
</xsl:when>
<xsl:when test= "@value" >
<xsl:value-of select= "@name" /> = <xsl:value-of select= "@value" />
</xsl:when>
<xsl:otherwise >
<xsl:message terminate= "yes" >
#error Unhandle enum type for <xml:value-of select= "name()" />
</xsl:message>
</xsl:otherwise>
</xsl:choose> ,
</xsl:for-each>
};
</xsl:template>
<!-- public functions -->
<xsl:template match= "command" >
<xsl:value-of select= "proto/type" />
<xsl:text > </xsl:text>
<xsl:value-of select= "proto/name" /> (
<xsl:for-each select= "param" >
<xsl:for-each select= ".//text()" >
<xsl:value-of select= "." />
<xsl:text > </xsl:text>
</xsl:for-each>
<xsl:if test= "position() != last()" > ,</xsl:if>
</xsl:for-each>
);
</xsl:template>
<!-- elements we don't care about just yet -->
<xsl:template match= "extensions" />
<xsl:template match= "feature" />
<xsl:template match= "comment" />
<xsl:template match= "vendorids" />
<xsl:template match= "tags" />
<!-- top level sectioning commands we just want to iterate over -->
<xsl:template match= "commands" >
<xsl:apply-templates />
</xsl:template>
<xsl:template match= "registry" >
<xsl:text >
#ifndef __VK_HPP
#define __VK_HPP
#include < cstdint>
#include < cstddef>
2017-05-26 16:31:31 +10:00
#ifdef __cplusplus
extern "C" {
#endif
2016-02-24 11:11:41 +11:00
struct Display;
struct VisualID;
using Window = unsigned long;
struct ANativeWindow;
struct MirConnection;
struct MirSurface;
struct wl_display;
struct wl_surface;
using HANDLE = void*;
using HINSTANCE = HANDLE;
using HWND = HANDLE;
2017-05-26 16:31:31 +10:00
using SECURITY_ATTRIBUTES = HANDLE;
using DWORD = uint32_t;
using LPCWSTR = char16_t*;
2016-02-24 11:11:41 +11:00
struct xcb_connection_t;
struct xcb_visualid_t;
using xcb_window_t = uint32_t;
2017-05-26 16:31:31 +10:00
using XID = unsigned long;
using RROutput = XID;
// because, in its wisdom, the spec doesn't actually allow us to
// extract the value for VK_NULL_HANDLE from the XML we'll just
// hard code it here.
#define VK_NULL_HANDLE uintptr_t(0)
2016-02-24 11:11:41 +11:00
</xsl:text>
<!-- deliberately instane enums before types, as the latter depends on the former -->
<xsl:apply-templates select= "comment" />
<xsl:apply-templates select= "vendorids" />
<xsl:apply-templates select= "tags" />
<xsl:apply-templates select= "enums" />
<xsl:apply-templates select= "types" />
<xsl:apply-templates select= "commands" />
<xsl:apply-templates select= "feature" />
<xsl:apply-templates select= "extensions" />
<xsl:text >
2017-05-26 16:31:31 +10:00
#ifdef __cplusplus
}
#endif
2016-02-24 11:11:41 +11:00
#endif
</xsl:text>
</xsl:template>
<xsl:template match= "*/text()" />
<xsl:template match= "*" >
<xml:message terminate= "no" >
#error Unmatched element < <xsl:value-of select= "name()" /> <xsl:for-each select= "@*" > <xsl:value-of select= "name()" /> =<xsl:value-of select= "." /> </xsl:for-each> >
</xml:message>
</xsl:template>
</xsl:stylesheet>