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