VirtualBox

source: vbox/trunk/src/VBox/Main/idl/midl.xsl@ 16560

Last change on this file since 16560 was 14572, checked in by vboxsync, 16 years ago

Main/XIDL: Added recognition of the following new tags:

  • <desc>/<result> in <method> and <attribute>;
  • <descGroup> everywhere to define logical description groups (modules in doxygen);
  • <desc> in <idl> to generat main documentation page.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.1 KB
Line 
1<?xml version="1.0"?>
2<!-- $Id: midl.xsl 14572 2008-11-25 13:37:40Z vboxsync $ -->
3
4<!--
5 * A template to generate a MS IDL compatible interface definition file
6 * from the generic interface definition expressed in XML.
7
8 Copyright (C) 2006-2008 Sun Microsystems, Inc.
9
10 This file is part of VirtualBox Open Source Edition (OSE), as
11 available from http://www.virtualbox.org. This file is free software;
12 you can redistribute it and/or modify it under the terms of the GNU
13 General Public License (GPL) as published by the Free Software
14 Foundation, in version 2 as it comes in the "COPYING" file of the
15 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17
18 Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 Clara, CA 95054 USA or visit http://www.sun.com if you need
20 additional information or have any questions.
21-->
22
23<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
24<xsl:output method="text"/>
25
26<xsl:strip-space elements="*"/>
27
28
29<!--
30// helper definitions
31/////////////////////////////////////////////////////////////////////////////
32-->
33
34<!--
35 * capitalizes the first letter
36-->
37<xsl:template name="capitalize">
38 <xsl:param name="str" select="."/>
39 <xsl:value-of select="
40 concat(
41 translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
42 substring($str,2)
43 )
44 "/>
45</xsl:template>
46
47<!--
48 * uncapitalizes the first letter only if the second one is not capital
49 * otherwise leaves the string unchanged
50-->
51<xsl:template name="uncapitalize">
52 <xsl:param name="str" select="."/>
53 <xsl:choose>
54 <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring($str,2,1)))">
55 <xsl:value-of select="
56 concat(
57 translate(substring($str,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
58 substring($str,2)
59 )
60 "/>
61 </xsl:when>
62 <xsl:otherwise>
63 <xsl:value-of select="string($str)"/>
64 </xsl:otherwise>
65 </xsl:choose>
66</xsl:template>
67
68
69<!--
70// templates
71/////////////////////////////////////////////////////////////////////////////
72-->
73
74<!--
75 * not explicitly matched elements and attributes
76-->
77<xsl:template match="*"/>
78
79
80<!--
81 * header
82-->
83<xsl:template match="/idl">
84 <xsl:text>
85/*
86 * DO NOT EDIT! This is a generated file.
87 *
88 * MS IDL (MIDL) definition for VirtualBox Main API (COM interfaces)
89 * generated from XIDL (XML interface definition).
90 *
91 * Source : src/VBox/Main/idl/VirtualBox.xidl
92 * Generator : src/VBox/Main/idl/midl.xsl
93 */
94 </xsl:text>
95 <xsl:text>&#x0A;</xsl:text>
96 <xsl:text>import "unknwn.idl";&#x0A;&#x0A;</xsl:text>
97 <xsl:apply-templates/>
98</xsl:template>
99
100
101<!--
102 * ignore all |if|s except those for MIDL target
103-->
104<xsl:template match="if">
105 <xsl:if test="@target='midl'">
106 <xsl:apply-templates/>
107 </xsl:if>
108</xsl:template>
109<xsl:template match="if" mode="forward">
110 <xsl:if test="@target='midl'">
111 <xsl:apply-templates mode="forward"/>
112 </xsl:if>
113</xsl:template>
114<xsl:template match="if" mode="forwarder">
115 <xsl:param name="nameOnly"/>
116 <xsl:if test="@target='midl'">
117 <xsl:apply-templates mode="forwarder">
118 <xsl:with-param name="nameOnly" select="$nameOnly"/>
119 </xsl:apply-templates>
120 </xsl:if>
121</xsl:template>
122
123
124<!--
125 * cpp_quote
126-->
127<xsl:template match="cpp">
128 <xsl:text>cpp_quote("</xsl:text>
129 <xsl:value-of select="@line"/>
130 <xsl:text>")&#x0A;&#x0A;</xsl:text>
131</xsl:template>
132
133
134<!--
135 * #if statement (@if attribute)
136-->
137<xsl:template match="@if" mode="begin">
138 <xsl:text>#if </xsl:text>
139 <xsl:value-of select="."/>
140 <xsl:text>&#x0A;</xsl:text>
141</xsl:template>
142<xsl:template match="@if" mode="end">
143 <xsl:text>#endif&#x0A;</xsl:text>
144</xsl:template>
145
146
147<!--
148 * libraries
149-->
150<xsl:template match="library">[
151 uuid(<xsl:value-of select="@uuid"/>),
152 version(<xsl:value-of select="@version"/>),
153 helpstring("<xsl:value-of select="@desc"/>")
154]
155<xsl:text>library </xsl:text>
156 <xsl:value-of select="@name"/>
157 <xsl:text>&#x0A;{&#x0A;</xsl:text>
158 <xsl:text>&#x0A;importlib("stdole2.tlb");&#x0A;&#x0A;</xsl:text>
159 <!-- result codes -->
160 <xsl:for-each select="result">
161 <xsl:apply-templates select="."/>
162 </xsl:for-each>
163 <xsl:text>&#x0A;</xsl:text>
164 <!-- forward declarations -->
165 <xsl:apply-templates select="if | interface | collection | enumerator" mode="forward"/>
166 <xsl:text>&#x0A;</xsl:text>
167 <!-- all enums go first -->
168 <xsl:apply-templates select="enum | if/enum"/>
169 <!-- everything else but result codes and enums -->
170 <xsl:apply-templates select="*[not(self::result or self::enum) and
171 not(self::if[result] or self::if[enum])]"/>
172 <!-- -->
173 <xsl:text>}; /* library </xsl:text>
174 <xsl:value-of select="@name"/>
175 <xsl:text> */&#x0A;&#x0A;</xsl:text>
176</xsl:template>
177
178
179<!--
180 * result codes
181-->
182<xsl:template match="result">
183 <xsl:text>cpp_quote("</xsl:text>
184 <xsl:value-of select="concat('#define ',@name,' ',@value)"/>
185 <xsl:text>")&#x0A;</xsl:text>
186</xsl:template>
187
188
189<!--
190 * forward declarations
191-->
192<xsl:template match="interface | collection | enumerator" mode="forward">
193 <xsl:text>interface </xsl:text>
194 <xsl:value-of select="@name"/>
195 <xsl:text>;&#x0A;</xsl:text>
196</xsl:template>
197
198
199<!--
200 * interfaces
201-->
202<xsl:template match="interface">[
203 uuid(<xsl:value-of select="@uuid"/>),
204 object,
205 dual
206]
207<xsl:text>interface </xsl:text>
208 <xsl:value-of select="@name"/>
209 <xsl:text> : </xsl:text>
210 <xsl:choose>
211 <xsl:when test="@extends='$unknown'">IUnknown</xsl:when>
212 <xsl:when test="@extends='$dispatched'">IDispatch</xsl:when>
213 <xsl:when test="@extends='$errorinfo'">IErrorInfo</xsl:when>
214 <xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
215 </xsl:choose>
216 <xsl:text>&#x0A;{&#x0A;</xsl:text>
217 <!-- attributes (properties) -->
218 <xsl:apply-templates select="attribute"/>
219 <!-- methods -->
220 <xsl:apply-templates select="method"/>
221 <!-- 'if' enclosed elements, unsorted -->
222 <xsl:apply-templates select="if"/>
223 <!-- -->
224 <xsl:text>}; /* interface </xsl:text>
225 <xsl:value-of select="@name"/>
226 <xsl:text> */&#x0A;&#x0A;</xsl:text>
227 <!-- Interface implementation forwarder macro -->
228 <xsl:text>/* Interface implementation forwarder macro */&#x0A;</xsl:text>
229 <!-- 1) indivudual methods -->
230 <xsl:apply-templates select="attribute" mode="forwarder"/>
231 <xsl:apply-templates select="method" mode="forwarder"/>
232 <xsl:apply-templates select="if" mode="forwarder"/>
233 <!-- 2) COM_FORWARD_Interface_TO(smth) -->
234 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
235 <xsl:value-of select="@name"/>
236 <xsl:text>_TO(smth) </xsl:text>
237 <xsl:apply-templates select="attribute" mode="forwarder">
238 <xsl:with-param name="nameOnly" select="'yes'"/>
239 </xsl:apply-templates>
240 <xsl:apply-templates select="method" mode="forwarder">
241 <xsl:with-param name="nameOnly" select="'yes'"/>
242 </xsl:apply-templates>
243 <xsl:apply-templates select="if" mode="forwarder">
244 <xsl:with-param name="nameOnly" select="'yes'"/>
245 </xsl:apply-templates>
246 <xsl:text>")&#x0A;</xsl:text>
247 <!-- 3) COM_FORWARD_Interface_TO_OBJ(obj) -->
248 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
249 <xsl:value-of select="@name"/>
250 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
251 <xsl:value-of select="@name"/>
252 <xsl:text>_TO ((obj)->)")&#x0A;</xsl:text>
253 <!-- 4) COM_FORWARD_Interface_TO_BASE(base) -->
254 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
255 <xsl:value-of select="@name"/>
256 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
257 <xsl:value-of select="@name"/>
258 <xsl:text>_TO (base::)")&#x0A;</xsl:text>
259 <!-- end -->
260 <xsl:text>&#x0A;</xsl:text>
261</xsl:template>
262
263
264<!--
265 * attributes
266-->
267<xsl:template match="interface//attribute | collection//attribute">
268 <xsl:apply-templates select="@if" mode="begin"/>
269 <xsl:if test="@array">
270 <xsl:message terminate="yes">
271 <xsl:value-of select="concat(../@name,'::',@name,': ')"/>
272 <xsl:text>'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
273 </xsl:message>
274 </xsl:if>
275 <!-- getter -->
276 <xsl:text> [propget] HRESULT </xsl:text>
277 <xsl:call-template name="capitalize">
278 <xsl:with-param name="str" select="@name"/>
279 </xsl:call-template>
280 <xsl:text> ([out, retval] </xsl:text>
281 <xsl:if test="@safearray='yes'">
282 <xsl:text>SAFEARRAY(</xsl:text>
283 </xsl:if>
284 <xsl:apply-templates select="@type"/>
285 <xsl:if test="@safearray='yes'">
286 <xsl:text>)</xsl:text>
287 </xsl:if>
288 <xsl:text> * a</xsl:text>
289 <xsl:call-template name="capitalize">
290 <xsl:with-param name="str" select="@name"/>
291 </xsl:call-template>
292 <xsl:text>);&#x0A;</xsl:text>
293 <!-- setter -->
294 <xsl:if test="not(@readonly='yes')">
295 <xsl:text> [propput] HRESULT </xsl:text>
296 <xsl:call-template name="capitalize">
297 <xsl:with-param name="str" select="@name"/>
298 </xsl:call-template>
299 <xsl:text> ([in</xsl:text>
300 <xsl:if test="@safearray='yes'">
301 <!-- VB supports only [in, out], [out] and [out, retval] arrays -->
302 <xsl:text>, out</xsl:text>
303 </xsl:if>
304 <xsl:text>] </xsl:text>
305 <xsl:if test="@safearray='yes'">
306 <xsl:text>SAFEARRAY(</xsl:text>
307 </xsl:if>
308 <xsl:apply-templates select="@type"/>
309 <xsl:if test="@safearray='yes'">
310 <xsl:text>) *</xsl:text>
311 </xsl:if>
312 <xsl:text> a</xsl:text>
313 <xsl:call-template name="capitalize">
314 <xsl:with-param name="str" select="@name"/>
315 </xsl:call-template>
316 <xsl:text>);&#x0A;</xsl:text>
317 </xsl:if>
318 <xsl:apply-templates select="@if" mode="end"/>
319 <xsl:text>&#x0A;</xsl:text>
320</xsl:template>
321
322<xsl:template match="interface//attribute | collection//attribute" mode="forwarder">
323
324 <!-- if nameOnly='yes' then only the macro name is composed
325 followed by a space -->
326 <xsl:param name="nameOnly"/>
327
328 <xsl:variable name="parent" select="ancestor::interface | ancestor::collection"/>
329
330 <xsl:apply-templates select="@if" mode="begin"/>
331
332 <xsl:choose>
333 <xsl:when test="$nameOnly='yes'">
334 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO(smth) -->
335 <xsl:text>COM_FORWARD_</xsl:text>
336 <xsl:value-of select="$parent/@name"/>
337 <xsl:text>_GETTER_</xsl:text>
338 <xsl:call-template name="capitalize">
339 <xsl:with-param name="str" select="@name"/>
340 </xsl:call-template>
341 <xsl:text>_TO (smth) </xsl:text>
342 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO(smth) -->
343 <xsl:if test="not(@readonly='yes')">
344 <xsl:text>COM_FORWARD_</xsl:text>
345 <xsl:value-of select="$parent/@name"/>
346 <xsl:text>_SETTER_</xsl:text>
347 <xsl:call-template name="capitalize">
348 <xsl:with-param name="str" select="@name"/>
349 </xsl:call-template>
350 <xsl:text>_TO (smth) </xsl:text>
351 </xsl:if>
352 </xsl:when>
353 <xsl:otherwise>
354 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO(smth) -->
355 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
356 <xsl:value-of select="$parent/@name"/>
357 <xsl:text>_GETTER_</xsl:text>
358 <xsl:call-template name="capitalize">
359 <xsl:with-param name="str" select="@name"/>
360 </xsl:call-template>
361 <xsl:text>_TO(smth) HRESULT STDMETHODCALLTYPE get_</xsl:text>
362 <xsl:call-template name="capitalize">
363 <xsl:with-param name="str" select="@name"/>
364 </xsl:call-template>
365 <xsl:text> (</xsl:text>
366 <xsl:choose>
367 <xsl:when test="@safearray='yes'">
368 <xsl:text>SAFEARRAY *</xsl:text>
369 </xsl:when>
370 <xsl:otherwise>
371 <xsl:apply-templates select="@type"/>
372 </xsl:otherwise>
373 </xsl:choose>
374 <xsl:text> * a</xsl:text>
375 <xsl:call-template name="capitalize">
376 <xsl:with-param name="str" select="@name"/>
377 </xsl:call-template>
378 <xsl:text>) { return smth get_</xsl:text>
379 <xsl:call-template name="capitalize">
380 <xsl:with-param name="str" select="@name"/>
381 </xsl:call-template>
382 <xsl:text> (a</xsl:text>
383 <xsl:call-template name="capitalize">
384 <xsl:with-param name="str" select="@name"/>
385 </xsl:call-template>
386 <xsl:text>); }")&#x0A;</xsl:text>
387 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO_OBJ(obj) -->
388 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
389 <xsl:value-of select="$parent/@name"/>
390 <xsl:text>_GETTER_</xsl:text>
391 <xsl:call-template name="capitalize">
392 <xsl:with-param name="str" select="@name"/>
393 </xsl:call-template>
394 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
395 <xsl:value-of select="$parent/@name"/>
396 <xsl:text>_GETTER_</xsl:text>
397 <xsl:call-template name="capitalize">
398 <xsl:with-param name="str" select="@name"/>
399 </xsl:call-template>
400 <xsl:text>_TO ((obj)->)")&#x0A;</xsl:text>
401 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO_BASE(base) -->
402 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
403 <xsl:value-of select="$parent/@name"/>
404 <xsl:text>_GETTER_</xsl:text>
405 <xsl:call-template name="capitalize">
406 <xsl:with-param name="str" select="@name"/>
407 </xsl:call-template>
408 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
409 <xsl:value-of select="$parent/@name"/>
410 <xsl:text>_GETTER_</xsl:text>
411 <xsl:call-template name="capitalize">
412 <xsl:with-param name="str" select="@name"/>
413 </xsl:call-template>
414 <xsl:text>_TO (base::)")&#x0A;</xsl:text>
415 <!-- -->
416 <xsl:if test="not(@readonly='yes')">
417 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO(smth) -->
418 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
419 <xsl:value-of select="$parent/@name"/>
420 <xsl:text>_SETTER_</xsl:text>
421 <xsl:call-template name="capitalize">
422 <xsl:with-param name="str" select="@name"/>
423 </xsl:call-template>
424 <xsl:text>_TO(smth) HRESULT STDMETHODCALLTYPE put_</xsl:text>
425 <xsl:call-template name="capitalize">
426 <xsl:with-param name="str" select="@name"/>
427 </xsl:call-template>
428 <xsl:text> (</xsl:text>
429 <xsl:choose>
430 <xsl:when test="@safearray='yes'">
431 <xsl:text>SAFEARRAY *</xsl:text>
432 </xsl:when>
433 <xsl:otherwise>
434 <xsl:apply-templates select="@type"/>
435 </xsl:otherwise>
436 </xsl:choose>
437 <xsl:text> a</xsl:text>
438 <xsl:call-template name="capitalize">
439 <xsl:with-param name="str" select="@name"/>
440 </xsl:call-template>
441 <xsl:text>) { return smth put_</xsl:text>
442 <xsl:call-template name="capitalize">
443 <xsl:with-param name="str" select="@name"/>
444 </xsl:call-template>
445 <xsl:text> (a</xsl:text>
446 <xsl:call-template name="capitalize">
447 <xsl:with-param name="str" select="@name"/>
448 </xsl:call-template>
449 <xsl:text>); }")&#x0A;</xsl:text>
450 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO_OBJ(obj) -->
451 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
452 <xsl:value-of select="$parent/@name"/>
453 <xsl:text>_SETTER_</xsl:text>
454 <xsl:call-template name="capitalize">
455 <xsl:with-param name="str" select="@name"/>
456 </xsl:call-template>
457 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
458 <xsl:value-of select="$parent/@name"/>
459 <xsl:text>_SETTER_</xsl:text>
460 <xsl:call-template name="capitalize">
461 <xsl:with-param name="str" select="@name"/>
462 </xsl:call-template>
463 <xsl:text>_TO ((obj)->)")&#x0A;</xsl:text>
464 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO_BASE(base) -->
465 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
466 <xsl:value-of select="$parent/@name"/>
467 <xsl:text>_SETTER_</xsl:text>
468 <xsl:call-template name="capitalize">
469 <xsl:with-param name="str" select="@name"/>
470 </xsl:call-template>
471 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
472 <xsl:value-of select="$parent/@name"/>
473 <xsl:text>_SETTER_</xsl:text>
474 <xsl:call-template name="capitalize">
475 <xsl:with-param name="str" select="@name"/>
476 </xsl:call-template>
477 <xsl:text>_TO (base::)")&#x0A;</xsl:text>
478 </xsl:if>
479 </xsl:otherwise>
480 </xsl:choose>
481
482 <xsl:apply-templates select="@if" mode="end"/>
483
484</xsl:template>
485
486
487<!--
488 * methods
489-->
490<xsl:template match="interface//method | collection//method">
491 <xsl:apply-templates select="@if" mode="begin"/>
492 <xsl:text> HRESULT </xsl:text>
493 <xsl:call-template name="capitalize">
494 <xsl:with-param name="str" select="@name"/>
495 </xsl:call-template>
496 <xsl:choose>
497 <xsl:when test="param">
498 <xsl:text> (&#x0A;</xsl:text>
499 <xsl:for-each select="param [position() != last()]">
500 <xsl:text> </xsl:text>
501 <xsl:apply-templates select="."/>
502 <xsl:text>,&#x0A;</xsl:text>
503 </xsl:for-each>
504 <xsl:text> </xsl:text>
505 <xsl:apply-templates select="param [last()]"/>
506 <xsl:text>&#x0A; );&#x0A;</xsl:text>
507 </xsl:when>
508 <xsl:otherwise test="not(param)">
509 <xsl:text>();&#x0A;</xsl:text>
510 </xsl:otherwise>
511 </xsl:choose>
512 <xsl:apply-templates select="@if" mode="end"/>
513 <xsl:text>&#x0A;</xsl:text>
514</xsl:template>
515
516<xsl:template match="interface//method | collection//method" mode="forwarder">
517
518 <!-- if nameOnly='yes' then only the macro name is composed followed by \ -->
519 <xsl:param name="nameOnly"/>
520
521 <xsl:variable name="parent" select="ancestor::interface | ancestor::collection"/>
522
523 <xsl:apply-templates select="@if" mode="begin"/>
524
525 <xsl:choose>
526 <xsl:when test="$nameOnly='yes'">
527 <!-- COM_FORWARD_Interface_Method_TO(smth) -->
528 <xsl:text>COM_FORWARD_</xsl:text>
529 <xsl:value-of select="$parent/@name"/>
530 <xsl:text>_</xsl:text>
531 <xsl:call-template name="capitalize">
532 <xsl:with-param name="str" select="@name"/>
533 </xsl:call-template>
534 <xsl:text>_TO (smth) </xsl:text>
535 </xsl:when>
536 <xsl:otherwise>
537 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
538 <xsl:value-of select="$parent/@name"/>
539 <xsl:text>_</xsl:text>
540 <xsl:call-template name="capitalize">
541 <xsl:with-param name="str" select="@name"/>
542 </xsl:call-template>
543 <xsl:text>_TO(smth) HRESULT STDMETHODCALLTYPE </xsl:text>
544 <xsl:call-template name="capitalize">
545 <xsl:with-param name="str" select="@name"/>
546 </xsl:call-template>
547 <xsl:choose>
548 <xsl:when test="param">
549 <xsl:text> (</xsl:text>
550 <xsl:for-each select="param [position() != last()]">
551 <xsl:apply-templates select="." mode="forwarder"/>
552 <xsl:text>, </xsl:text>
553 </xsl:for-each>
554 <xsl:apply-templates select="param [last()]" mode="forwarder"/>
555 <xsl:text>) { return smth </xsl:text>
556 <xsl:call-template name="capitalize">
557 <xsl:with-param name="str" select="@name"/>
558 </xsl:call-template>
559 <xsl:text> (</xsl:text>
560 <xsl:for-each select="param [position() != last()]">
561 <xsl:text>a</xsl:text>
562 <xsl:call-template name="capitalize">
563 <xsl:with-param name="str" select="@name"/>
564 </xsl:call-template>
565 <xsl:text>, </xsl:text>
566 </xsl:for-each>
567 <xsl:text>a</xsl:text>
568 <xsl:call-template name="capitalize">
569 <xsl:with-param name="str" select="param [last()]/@name"/>
570 </xsl:call-template>
571 <xsl:text>); }</xsl:text>
572 </xsl:when>
573 <xsl:otherwise test="not(param)">
574 <xsl:text>() { return smth </xsl:text>
575 <xsl:call-template name="capitalize">
576 <xsl:with-param name="str" select="@name"/>
577 </xsl:call-template>
578 <xsl:text>(); }</xsl:text>
579 </xsl:otherwise>
580 </xsl:choose>
581 <xsl:text>")&#x0A;</xsl:text>
582 <!-- COM_FORWARD_Interface_Method_TO_OBJ(obj) -->
583 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
584 <xsl:value-of select="$parent/@name"/>
585 <xsl:text>_</xsl:text>
586 <xsl:call-template name="capitalize">
587 <xsl:with-param name="str" select="@name"/>
588 </xsl:call-template>
589 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
590 <xsl:value-of select="$parent/@name"/>
591 <xsl:text>_</xsl:text>
592 <xsl:call-template name="capitalize">
593 <xsl:with-param name="str" select="@name"/>
594 </xsl:call-template>
595 <xsl:text>_TO ((obj)->)")&#x0A;</xsl:text>
596 <!-- COM_FORWARD_Interface_Method_TO_BASE(base) -->
597 <xsl:text>cpp_quote("#define COM_FORWARD_</xsl:text>
598 <xsl:value-of select="$parent/@name"/>
599 <xsl:text>_</xsl:text>
600 <xsl:call-template name="capitalize">
601 <xsl:with-param name="str" select="@name"/>
602 </xsl:call-template>
603 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
604 <xsl:value-of select="$parent/@name"/>
605 <xsl:text>_</xsl:text>
606 <xsl:call-template name="capitalize">
607 <xsl:with-param name="str" select="@name"/>
608 </xsl:call-template>
609 <xsl:text>_TO (base::)")&#x0A;</xsl:text>
610 </xsl:otherwise>
611 </xsl:choose>
612
613 <xsl:apply-templates select="@if" mode="end"/>
614
615</xsl:template>
616
617
618<!--
619 * modules
620-->
621<xsl:template match="module">
622 <xsl:apply-templates select="class"/>
623</xsl:template>
624
625
626<!--
627 * co-classes
628-->
629<xsl:template match="module/class">[
630 uuid(<xsl:value-of select="@uuid"/>)
631]
632<xsl:text>coclass </xsl:text>
633 <xsl:value-of select="@name"/>
634 <xsl:text>&#x0A;{&#x0A;</xsl:text>
635 <xsl:for-each select="interface">
636 <xsl:text> </xsl:text>
637 <xsl:if test="@default='yes'">
638 <xsl:text>[default] </xsl:text>
639 </xsl:if>
640 <xsl:text>interface </xsl:text>
641 <xsl:value-of select="@name"/>
642 <xsl:text>;&#x0A;</xsl:text>
643 </xsl:for-each>
644 <xsl:text>&#x0A;}; /* coclass </xsl:text>
645 <xsl:value-of select="@name"/>
646 <xsl:text> */&#x0A;&#x0A;</xsl:text>
647</xsl:template>
648
649
650<!--
651 * enumerators
652-->
653<xsl:template match="enumerator">[
654 uuid(<xsl:value-of select="@uuid"/>),
655 object,
656 dual
657]
658<xsl:text>interface </xsl:text>
659 <xsl:value-of select="@name"/>
660 <xsl:text> : IUnknown&#x0A;{&#x0A;</xsl:text>
661 <!-- HasMore -->
662 <xsl:text> HRESULT HasMore ([out, retval] BOOL * more);&#x0A;&#x0A;</xsl:text>
663 <!-- GetNext -->
664 <xsl:text> HRESULT GetNext ([out, retval] </xsl:text>
665 <xsl:apply-templates select="@type"/>
666 <xsl:text> * next);&#x0A;&#x0A;</xsl:text>
667 <!-- -->
668 <xsl:text>&#x0A;}; /* interface </xsl:text>
669 <xsl:value-of select="@name"/>
670 <xsl:text> */&#x0A;&#x0A;</xsl:text>
671</xsl:template>
672
673
674<!--
675 * collections
676-->
677<xsl:template match="collection">
678 <xsl:if test="not(@readonly='yes')">
679 <xsl:message terminate="yes">
680 <xsl:value-of select="concat(@name,': ')"/>
681 <xsl:text>non-readonly collections are not currently supported</xsl:text>
682 </xsl:message>
683 </xsl:if>[
684 uuid(<xsl:value-of select="@uuid"/>),
685 object,
686 dual
687]
688<xsl:text>interface </xsl:text>
689 <xsl:value-of select="@name"/>
690 <xsl:text> : IUnknown&#x0A;{&#x0A;</xsl:text>
691 <!-- Count -->
692 <xsl:text> [propget] HRESULT Count ([out, retval] ULONG * count);&#x0A;&#x0A;</xsl:text>
693 <!-- GetItemAt -->
694 <xsl:text> HRESULT GetItemAt ([in] ULONG index, [out, retval] </xsl:text>
695 <xsl:apply-templates select="@type"/>
696 <xsl:text> * item);&#x0A;&#x0A;</xsl:text>
697 <!-- Enumerate -->
698 <xsl:text> HRESULT Enumerate ([out, retval] </xsl:text>
699 <xsl:apply-templates select="@enumerator"/>
700 <xsl:text> * enumerator);&#x0A;&#x0A;</xsl:text>
701 <!-- other extra attributes (properties) -->
702 <xsl:apply-templates select="attribute"/>
703 <!-- other extra methods -->
704 <xsl:apply-templates select="method"/>
705 <!-- 'if' enclosed elements, unsorted -->
706 <xsl:apply-templates select="if"/>
707 <!-- -->
708 <xsl:text>&#x0A;}; /* interface </xsl:text>
709 <xsl:value-of select="@name"/>
710 <xsl:text> */&#x0A;&#x0A;</xsl:text>
711</xsl:template>
712
713
714<!--
715 * enums
716-->
717<xsl:template match="enum">[
718 uuid(<xsl:value-of select="@uuid"/>),
719 v1_enum
720]
721<xsl:text>typedef enum &#x0A;{&#x0A;</xsl:text>
722 <xsl:for-each select="const">
723 <xsl:text> </xsl:text>
724 <xsl:value-of select="concat(../@name,'_',@name)"/> = <xsl:value-of select="@value"/>
725 <xsl:choose>
726 <xsl:when test="position()!=last()"><xsl:text>,&#x0A;</xsl:text></xsl:when>
727 <xsl:otherwise><xsl:text>&#x0A;</xsl:text></xsl:otherwise>
728 </xsl:choose>
729 </xsl:for-each>
730 <xsl:text>} </xsl:text>
731 <xsl:value-of select="@name"/>
732 <xsl:text>;&#x0A;&#x0A;</xsl:text>
733 <!-- -->
734 <xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */&#x0A;')"/>
735 <xsl:value-of select="concat('cpp_quote(&quot;#define ', @name, '_T', ' ',
736 @name, '&quot;)&#x0A;&#x0A;')"/>
737 <xsl:text>&#x0A;&#x0A;</xsl:text>
738</xsl:template>
739
740
741<!--
742 * method parameters
743-->
744<xsl:template match="method/param">
745 <xsl:text>[</xsl:text>
746 <xsl:choose>
747 <xsl:when test="@dir='in'">in</xsl:when>
748 <xsl:when test="@dir='out'">out</xsl:when>
749 <xsl:when test="@dir='return'">out, retval</xsl:when>
750 <xsl:otherwise>in</xsl:otherwise>
751 </xsl:choose>
752 <xsl:if test="@safearray='yes'">
753 <!-- VB supports only [in, out], [out] and [out, retval] arrays -->
754 <xsl:if test="@dir='in'">, out</xsl:if>
755 </xsl:if>
756 <xsl:if test="@array">
757 <xsl:if test="@dir='return'">
758 <xsl:message terminate="yes">
759 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
760 <xsl:text>return 'array' parameters are not supported, use 'safearray="yes"' instead.</xsl:text>
761 </xsl:message>
762 </xsl:if>
763 <xsl:choose>
764 <xsl:when test="../param[@name=current()/@array]">
765 <xsl:if test="../param[@name=current()/@array]/@dir != @dir">
766 <xsl:message terminate="yes">
767 <xsl:value-of select="concat(../../@name,'::',../@name,': ')"/>
768 <xsl:value-of select="concat(@name,' and ',../param[@name=current()/@array]/@name)"/>
769 <xsl:text> must have the same direction</xsl:text>
770 </xsl:message>
771 </xsl:if>
772 <xsl:text>, size_is(</xsl:text>
773 <xsl:if test="@dir='out'">
774 <xsl:text>, *</xsl:text>
775 </xsl:if>
776 <xsl:text>a</xsl:text>
777 <xsl:call-template name="capitalize">
778 <xsl:with-param name="str" select="@array"/>
779 </xsl:call-template>
780 <xsl:text>)</xsl:text>
781 </xsl:when>
782 <xsl:otherwise>
783 <xsl:message terminate="yes">
784 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
785 <xsl:text>array attribute refers to non-existent param: </xsl:text>
786 <xsl:value-of select="@array"/>
787 </xsl:message>
788 </xsl:otherwise>
789 </xsl:choose>
790 </xsl:if>
791 <xsl:text>] </xsl:text>
792 <xsl:if test="@safearray='yes'">
793 <xsl:text>SAFEARRAY(</xsl:text>
794 </xsl:if>
795 <xsl:apply-templates select="@type"/>
796 <xsl:if test="@safearray='yes'">
797 <xsl:text>)</xsl:text>
798 </xsl:if>
799 <xsl:if test="@array">
800 <xsl:text> *</xsl:text>
801 </xsl:if>
802 <xsl:if test="@dir='out' or @dir='return' or @safearray='yes'">
803 <xsl:text> *</xsl:text>
804 </xsl:if>
805 <xsl:text> a</xsl:text>
806 <xsl:call-template name="capitalize">
807 <xsl:with-param name="str" select="@name"/>
808 </xsl:call-template>
809</xsl:template>
810
811<xsl:template match="method/param" mode="forwarder">
812 <xsl:choose>
813 <xsl:when test="@safearray='yes'">
814 <xsl:text>SAFEARRAY *</xsl:text>
815 </xsl:when>
816 <xsl:otherwise>
817 <xsl:apply-templates select="@type"/>
818 </xsl:otherwise>
819 </xsl:choose>
820 <xsl:if test="@array">
821 <xsl:text> *</xsl:text>
822 </xsl:if>
823 <xsl:if test="@dir='out' or @dir='return' or @safearray='yes'">
824 <xsl:text> *</xsl:text>
825 </xsl:if>
826 <xsl:text> a</xsl:text>
827 <xsl:call-template name="capitalize">
828 <xsl:with-param name="str" select="@name"/>
829 </xsl:call-template>
830</xsl:template>
831
832
833<!--
834 * attribute/parameter type conversion
835-->
836<xsl:template match="
837 attribute/@type | param/@type |
838 enumerator/@type | collection/@type | collection/@enumerator
839">
840 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
841
842 <xsl:if test="../@array and ../@safearray='yes'">
843 <xsl:message terminate="yes">
844 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
845 <xsl:text>either 'array' or 'safearray="yes"' attribute is allowed, but not both!</xsl:text>
846 </xsl:message>
847 </xsl:if>
848
849 <xsl:choose>
850 <!-- modifiers (ignored for 'enumeration' attributes)-->
851 <xsl:when test="name(current())='type' and ../@mod">
852 <xsl:choose>
853 <xsl:when test="../@mod='ptr'">
854 <xsl:choose>
855 <!-- standard types -->
856 <!--xsl:when test=".='result'">??</xsl:when-->
857 <xsl:when test=".='boolean'">BOOL *</xsl:when>
858 <xsl:when test=".='octet'">BYTE *</xsl:when>
859 <xsl:when test=".='short'">SHORT *</xsl:when>
860 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
861 <xsl:when test=".='long'">LONG *</xsl:when>
862 <xsl:when test=".='long long'">LONG64 *</xsl:when>
863 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
864 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
865 <xsl:when test=".='char'">CHAR *</xsl:when>
866 <!--xsl:when test=".='string'">??</xsl:when-->
867 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
868 <!--xsl:when test=".='wstring'">??</xsl:when-->
869 <xsl:otherwise>
870 <xsl:message terminate="yes">
871 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
872 <xsl:text>attribute 'mod=</xsl:text>
873 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
874 <xsl:text>' cannot be used with type </xsl:text>
875 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
876 </xsl:message>
877 </xsl:otherwise>
878 </xsl:choose>
879 </xsl:when>
880 <xsl:otherwise>
881 <xsl:message terminate="yes">
882 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
883 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
884 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
885 </xsl:message>
886 </xsl:otherwise>
887 </xsl:choose>
888 </xsl:when>
889 <!-- no modifiers -->
890 <xsl:otherwise>
891 <xsl:choose>
892 <!-- standard types -->
893 <xsl:when test=".='result'">HRESULT</xsl:when>
894 <xsl:when test=".='boolean'">BOOL</xsl:when>
895 <xsl:when test=".='octet'">BYTE</xsl:when>
896 <xsl:when test=".='short'">SHORT</xsl:when>
897 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
898 <xsl:when test=".='long'">LONG</xsl:when>
899 <xsl:when test=".='long long'">LONG64</xsl:when>
900 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
901 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
902 <xsl:when test=".='char'">CHAR</xsl:when>
903 <xsl:when test=".='string'">CHAR *</xsl:when>
904 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
905 <xsl:when test=".='wstring'">BSTR</xsl:when>
906 <!-- UUID type -->
907 <xsl:when test=".='uuid'">GUID</xsl:when>
908 <!-- system interface types -->
909 <xsl:when test=".='$unknown'">IUnknown *</xsl:when>
910 <xsl:otherwise>
911 <xsl:choose>
912 <!-- enum types -->
913 <xsl:when test="
914 (ancestor::library/enum[@name=current()]) or
915 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
916 ">
917 <xsl:value-of select="."/>
918 </xsl:when>
919 <!-- custom interface types -->
920 <xsl:when test="
921 (name(current())='enumerator' and
922 ((ancestor::library/enumerator[@name=current()]) or
923 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
924 ) or
925 ((ancestor::library/interface[@name=current()]) or
926 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
927 ) or
928 ((ancestor::library/collection[@name=current()]) or
929 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
930 )
931 ">
932 <xsl:value-of select="."/><xsl:text> *</xsl:text>
933 </xsl:when>
934 <!-- other types -->
935 <xsl:otherwise>
936 <xsl:message terminate="yes">
937 <xsl:text>Unknown parameter type: </xsl:text>
938 <xsl:value-of select="."/>
939 </xsl:message>
940 </xsl:otherwise>
941 </xsl:choose>
942 </xsl:otherwise>
943 </xsl:choose>
944 </xsl:otherwise>
945 </xsl:choose>
946</xsl:template>
947
948</xsl:stylesheet>
949
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use