VirtualBox

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

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

Main: XIDL: Added support for <result> tags in <library> (MIDL, XPIDL, Doxygen). Added a couple of exemplary VBOX_E_ result codes.

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