VirtualBox

source: vbox/trunk/src/VBox/Main/idl/stringify-enums.xsl@ 94884

Last change on this file since 94884 was 93412, checked in by vboxsync, 3 years ago

Main: Generate enum value to string conversion functions for the API. Use these for logging instead of the Global::stringify* ones as they are untranslated, the Global:: ones are for use in error message when translated enum value names are desired (questionable). [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 stringify-enums.xsl - Generates stringify functions for all the enums in VirtualBox.xidl.
5
6 Copyright (C) 2022 Oracle Corporation
7
8 This file is part of VirtualBox Open Source Edition (OSE), as
9 available from http://www.virtualbox.org. This file is free software;
10 you can redistribute it and/or modify it under the terms of the GNU
11 General Public License (GPL) as published by the Free Software
12 Foundation, in version 2 as it comes in the "COPYING" file of the
13 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15-->
16
17<xsl:stylesheet
18 version="1.0"
19 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20 xmlns:exsl="http://exslt.org/common"
21 extension-element-prefixes="exsl">
22
23<xsl:output method="text"/>
24
25<xsl:strip-space elements="*"/>
26
27
28<!-- - - - - - - - - - - - - - - - - - - - - - -
29 Parameters
30 - - - - - - - - - - - - - - - - - - - - - - -->
31
32<xsl:param name="G_kind">source</xsl:param>
33
34
35<!-- - - - - - - - - - - - - - - - - - - - - - -
36templates for file headers
37 - - - - - - - - - - - - - - - - - - - - - - -->
38
39<xsl:template name="fileheader">
40 <xsl:param name="class"/>
41 <xsl:param name="name"/>
42 <xsl:param name="type"/>
43
44 <xsl:text>/** @file
45 * VirtualBox API Enum Stringifier - </xsl:text>
46 <xsl:choose>
47 <xsl:when test="$G_kind = 'header'">Header</xsl:when>
48 <xsl:when test="$G_kind = 'source'">Definition</xsl:when>
49 </xsl:choose>
50<xsl:text>.
51 *
52 * DO NOT EDIT! This is a generated file.
53 * Generated from: src/VBox/Main/idl/VirtualBox.xidl
54 * Generator: src/VBox/Main/idl/stringify-enums.xsl
55 */
56
57/*
58 * Copyright (C) 2006-2022 Oracle Corporation
59 *
60 * This file is part of VirtualBox Open Source Edition (OSE), as
61 * available from http://www.virtualbox.org. This file is free software;
62 * you can redistribute it and/or modify it under the terms of the GNU
63 * General Public License (GPL) as published by the Free Software
64 * Foundation, in version 2 as it comes in the "COPYING" file of the
65 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
66 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
67 */
68
69</xsl:text>
70</xsl:template>
71
72
73<!-- - - - - - - - - - - - - - - - - - - - - - -
74 Emits a function prototype for the header file.
75 - - - - - - - - - - - - - - - - - - - - - - -->
76<xsl:template name="emitEnumStringifyPrototype">
77 <xsl:text>const char *stringify</xsl:text><xsl:value-of select="@name"/><xsl:text>(</xsl:text>
78 <xsl:value-of select="@name"/><xsl:text>_T aValue) RT_NOEXCEPT;
79</xsl:text>
80</xsl:template>
81
82
83<!-- - - - - - - - - - - - - - - - - - - - - - -
84 Emits a function definition for the source file.
85 - - - - - - - - - - - - - - - - - - - - - - -->
86<xsl:template name="emitEnumStringifyFunction">
87 <xsl:text>
88
89const char *stringify</xsl:text><xsl:value-of select="@name"/><xsl:text>(</xsl:text>
90 <xsl:value-of select="@name"/><xsl:text>_T aValue) RT_NOEXCEPT
91{
92 switch (aValue)
93 {
94</xsl:text>
95 <xsl:apply-templates/>
96 <xsl:text> default:
97 AssertMsgFailedReturn(("%d / %#x\n", aValue, aValue), formatUnknown("</xsl:text>
98 <xsl:value-of select="@name"/><xsl:text>", (int)aValue));
99 }
100}
101</xsl:text>
102</xsl:template>
103
104
105<!-- - - - - - - - - - - - - - - - - - - - - - -
106 wildcard match, ignore everything which has no explicit match
107 - - - - - - - - - - - - - - - - - - - - - - -->
108<xsl:template match="*"/>
109
110<!-- - - - - - - - - - - - - - - - - - - - - - -
111 ignore all if tags except those for XPIDL or MIDL target
112 - - - - - - - - - - - - - - - - - - - - - - -->
113<xsl:template match="if">
114 <xsl:if test="(@target = 'xpidl') or (@target = 'midl')">
115 <xsl:apply-templates/>
116 </xsl:if>
117</xsl:template>
118
119<!-- - - - - - - - - - - - - - - - - - - - - - -
120 const match - emits case statemtns
121 - - - - - - - - - - - - - - - - - - - - - - -->
122<xsl:template match="const">
123 <!-- HACK ALERT! There are 4 enums in MachineState that have duplicate values,
124 we exploit the existing @wsmap="suppress" markers on these to
125 avoid generating code which doesn't compile. -->
126 <xsl:if test="not(@wsmap) or @wsmap != 'suppress'">
127 <xsl:text> case </xsl:text><xsl:value-of select="../@name"/>
128 <xsl:text>_</xsl:text>
129 <xsl:value-of select="@name"/><xsl:text>:
130 return "</xsl:text><xsl:value-of select="@name"/><xsl:text>";
131</xsl:text>
132 </xsl:if>
133</xsl:template>
134
135<!-- - - - - - - - - - - - - - - - - - - - - - -
136 enum match
137 - - - - - - - - - - - - - - - - - - - - - - -->
138<xsl:template match="enum">
139 <xsl:choose>
140 <xsl:when test="$G_kind = 'header'">
141 <xsl:call-template name="emitEnumStringifyPrototype"/>
142 </xsl:when>
143 <xsl:when test="$G_kind = 'source'">
144 <xsl:call-template name="emitEnumStringifyFunction"/>
145 </xsl:when>
146 </xsl:choose>
147</xsl:template>
148
149<!-- - - - - - - - - - - - - - - - - - - - - - -
150 application match
151 - - - - - - - - - - - - - - - - - - - - - - -->
152<xsl:template match="application">
153 <xsl:apply-templates/>
154</xsl:template>
155
156<!-- - - - - - - - - - - - - - - - - - - - - - -
157 library match
158 - - - - - - - - - - - - - - - - - - - - - - -->
159<xsl:template match="library">
160 <xsl:apply-templates/>
161</xsl:template>
162
163
164<!-- - - - - - - - - - - - - - - - - - - - - - -
165 root match
166 - - - - - - - - - - - - - - - - - - - - - - -->
167<xsl:template match="/idl">
168 <xsl:choose>
169 <xsl:when test="$G_kind = 'header'">
170 <xsl:call-template name="fileheader"/>
171 <xsl:text>
172#ifndef INCLUDED_GENERATED_StringifyEnums_h
173#define INCLUDED_GENERATED_StringifyEnums_h
174#ifndef RT_WITHOUT_PRAGMA_ONCE
175# pragma once
176#endif
177
178#include "VBox/com/VirtualBox.h"
179
180</xsl:text>
181 <xsl:apply-templates/>
182 <xsl:text>
183#endif /* INCLUDED_GENERATED_StringifyEnums_h */
184</xsl:text>
185 </xsl:when>
186
187 <xsl:when test="$G_kind = 'source'">
188 <xsl:call-template name="fileheader"/>
189 <xsl:text>
190
191/*********************************************************************************************************************************
192* Header Files *
193*********************************************************************************************************************************/
194#include "StringifyEnums.h"
195
196#include "iprt/asm.h"
197#include "iprt/assert.h"
198#include "iprt/string.h"
199
200
201/*********************************************************************************************************************************
202* Global Variables *
203*********************************************************************************************************************************/
204typedef char UNKNOWNBUF[64];
205static UNKNOWNBUF s_aszUnknown[16];
206static uint32_t volatile s_iUnknown = 0;
207
208
209static const char *formatUnknown(const char *pszName, int iValue)
210{
211 size_t iUnknown = ASMAtomicIncU32(&amp;s_iUnknown) % RT_ELEMENTS(s_aszUnknown);
212 char *pszBuf = s_aszUnknown[iUnknown];
213 RTStrPrintf(pszBuf, sizeof(UNKNOWNBUF), "Unk-%s-%#x", pszName, iValue);
214 return pszBuf;
215}
216
217</xsl:text>
218 <xsl:apply-templates/>
219 </xsl:when>
220
221 <xsl:otherwise>
222 <xsl:message terminate="yes">
223 Unknown string parameter value: G_kind='<xsl:value-of select="$G_kind"/>'
224 </xsl:message>
225 </xsl:otherwise>
226 </xsl:choose>
227</xsl:template>
228
229</xsl:stylesheet>
230<!-- vi: set tabstop=4 shiftwidth=4 expandtab: -->
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette