VirtualBox

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

Last change on this file was 98108, checked in by vboxsync, 16 months ago

Manual (C) year updates.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use