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 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 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
47 | templates 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) 2006-2022 Oracle Corporation
|
---|
70 | *
|
---|
71 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
72 | * available from http://www.virtualbox.org. This file is free software;
|
---|
73 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
74 | * General Public License (GPL) as published by the Free Software
|
---|
75 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
76 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
77 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
78 | */
|
---|
79 |
|
---|
80 | </xsl:text>
|
---|
81 | </xsl:template>
|
---|
82 |
|
---|
83 |
|
---|
84 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
85 | Emits a function prototype for the header file.
|
---|
86 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
87 | <xsl:template name="emitEnumStringifyPrototype">
|
---|
88 | <xsl:text>const char *stringify</xsl:text><xsl:value-of select="@name"/><xsl:text>(</xsl:text>
|
---|
89 | <xsl:value-of select="@name"/><xsl:text>_T aValue) RT_NOEXCEPT;
|
---|
90 | </xsl:text>
|
---|
91 | </xsl:template>
|
---|
92 |
|
---|
93 |
|
---|
94 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
95 | Emits a function definition for the source file.
|
---|
96 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
97 | <xsl:template name="emitEnumStringifyFunction">
|
---|
98 | <xsl:text>
|
---|
99 |
|
---|
100 | const char *stringify</xsl:text><xsl:value-of select="@name"/><xsl:text>(</xsl:text>
|
---|
101 | <xsl:value-of select="@name"/><xsl:text>_T aValue) RT_NOEXCEPT
|
---|
102 | {
|
---|
103 | switch (aValue)
|
---|
104 | {
|
---|
105 | </xsl:text>
|
---|
106 | <xsl:apply-templates/>
|
---|
107 | <xsl:text> default:
|
---|
108 | AssertMsgFailedReturn(("%d / %#x\n", aValue, aValue), formatUnknown("</xsl:text>
|
---|
109 | <xsl:value-of select="@name"/><xsl:text>", (int)aValue));
|
---|
110 | }
|
---|
111 | }
|
---|
112 | </xsl:text>
|
---|
113 | </xsl:template>
|
---|
114 |
|
---|
115 |
|
---|
116 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
117 | wildcard match, ignore everything which has no explicit match
|
---|
118 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
119 | <xsl:template match="*"/>
|
---|
120 |
|
---|
121 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
122 | ignore all if tags except those for XPIDL or MIDL target
|
---|
123 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
124 | <xsl:template match="if">
|
---|
125 | <xsl:if test="(@target = 'xpidl') or (@target = 'midl')">
|
---|
126 | <xsl:apply-templates/>
|
---|
127 | </xsl:if>
|
---|
128 | </xsl:template>
|
---|
129 |
|
---|
130 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
131 | const match - emits case statemtns
|
---|
132 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
133 | <xsl:template match="const">
|
---|
134 | <!-- HACK ALERT! There are 4 enums in MachineState that have duplicate values,
|
---|
135 | we exploit the existing @wsmap="suppress" markers on these to
|
---|
136 | avoid generating code which doesn't compile. -->
|
---|
137 | <xsl:if test="not(@wsmap) or @wsmap != 'suppress'">
|
---|
138 | <xsl:text> case </xsl:text><xsl:value-of select="../@name"/>
|
---|
139 | <xsl:text>_</xsl:text>
|
---|
140 | <xsl:value-of select="@name"/><xsl:text>:
|
---|
141 | return "</xsl:text><xsl:value-of select="@name"/><xsl:text>";
|
---|
142 | </xsl:text>
|
---|
143 | </xsl:if>
|
---|
144 | </xsl:template>
|
---|
145 |
|
---|
146 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
147 | enum match
|
---|
148 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
149 | <xsl:template match="enum">
|
---|
150 | <xsl:choose>
|
---|
151 | <xsl:when test="$G_kind = 'header'">
|
---|
152 | <xsl:call-template name="emitEnumStringifyPrototype"/>
|
---|
153 | </xsl:when>
|
---|
154 | <xsl:when test="$G_kind = 'source'">
|
---|
155 | <xsl:call-template name="emitEnumStringifyFunction"/>
|
---|
156 | </xsl:when>
|
---|
157 | </xsl:choose>
|
---|
158 | </xsl:template>
|
---|
159 |
|
---|
160 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
161 | application match
|
---|
162 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
163 | <xsl:template match="application">
|
---|
164 | <xsl:apply-templates/>
|
---|
165 | </xsl:template>
|
---|
166 |
|
---|
167 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
168 | library match
|
---|
169 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
170 | <xsl:template match="library">
|
---|
171 | <xsl:apply-templates/>
|
---|
172 | </xsl:template>
|
---|
173 |
|
---|
174 |
|
---|
175 | <!-- - - - - - - - - - - - - - - - - - - - - - -
|
---|
176 | root match
|
---|
177 | - - - - - - - - - - - - - - - - - - - - - - -->
|
---|
178 | <xsl:template match="/idl">
|
---|
179 | <xsl:choose>
|
---|
180 | <xsl:when test="$G_kind = 'header'">
|
---|
181 | <xsl:call-template name="fileheader"/>
|
---|
182 | <xsl:text>
|
---|
183 | #ifndef INCLUDED_GENERATED_StringifyEnums_h
|
---|
184 | #define INCLUDED_GENERATED_StringifyEnums_h
|
---|
185 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
186 | # pragma once
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | #include "VBox/com/VirtualBox.h"
|
---|
190 |
|
---|
191 | </xsl:text>
|
---|
192 | <xsl:apply-templates/>
|
---|
193 | <xsl:text>
|
---|
194 | #endif /* INCLUDED_GENERATED_StringifyEnums_h */
|
---|
195 | </xsl:text>
|
---|
196 | </xsl:when>
|
---|
197 |
|
---|
198 | <xsl:when test="$G_kind = 'source'">
|
---|
199 | <xsl:call-template name="fileheader"/>
|
---|
200 | <xsl:text>
|
---|
201 |
|
---|
202 | /*********************************************************************************************************************************
|
---|
203 | * Header Files *
|
---|
204 | *********************************************************************************************************************************/
|
---|
205 | #include "StringifyEnums.h"
|
---|
206 |
|
---|
207 | #include "iprt/asm.h"
|
---|
208 | #include "iprt/assert.h"
|
---|
209 | #include "iprt/string.h"
|
---|
210 |
|
---|
211 |
|
---|
212 | /*********************************************************************************************************************************
|
---|
213 | * Global Variables *
|
---|
214 | *********************************************************************************************************************************/
|
---|
215 | typedef char UNKNOWNBUF[64];
|
---|
216 | static UNKNOWNBUF s_aszUnknown[16];
|
---|
217 | static uint32_t volatile s_iUnknown = 0;
|
---|
218 |
|
---|
219 |
|
---|
220 | static const char *formatUnknown(const char *pszName, int iValue)
|
---|
221 | {
|
---|
222 | size_t iUnknown = ASMAtomicIncU32(&s_iUnknown) % RT_ELEMENTS(s_aszUnknown);
|
---|
223 | char *pszBuf = s_aszUnknown[iUnknown];
|
---|
224 | RTStrPrintf(pszBuf, sizeof(UNKNOWNBUF), "Unk-%s-%#x", pszName, iValue);
|
---|
225 | return pszBuf;
|
---|
226 | }
|
---|
227 |
|
---|
228 | </xsl:text>
|
---|
229 | <xsl:apply-templates/>
|
---|
230 | </xsl:when>
|
---|
231 |
|
---|
232 | <xsl:otherwise>
|
---|
233 | <xsl:message terminate="yes">
|
---|
234 | Unknown string parameter value: G_kind='<xsl:value-of select="$G_kind"/>'
|
---|
235 | </xsl:message>
|
---|
236 | </xsl:otherwise>
|
---|
237 | </xsl:choose>
|
---|
238 | </xsl:template>
|
---|
239 |
|
---|
240 | </xsl:stylesheet>
|
---|
241 | <!-- vi: set tabstop=4 shiftwidth=4 expandtab: -->
|
---|