VirtualBox

source: vbox/trunk/src/VBox/Main/idl/xpidl.xsl@ 53913

Last change on this file since 53913 was 50183, checked in by vboxsync, 11 years ago

Main/cbinding: bring the C binding to a new functionality level, making them handle both COM and XPCOM based platforms, plus some xsl cleanup to eliminate the $dispatch case which was unused for many years (and will not be used again)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.6 KB
Line 
1<?xml version="1.0"?>
2<!-- $Id: xpidl.xsl 50183 2014-01-23 15:58:21Z vboxsync $ -->
3
4<!--
5 * A template to generate a XPCOM IDL compatible interface definition file
6 * from the generic interface definition expressed in XML.
7
8 Copyright (C) 2006-2014 Oracle Corporation
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
19<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
20<xsl:output method="text"/>
21
22<xsl:strip-space elements="*"/>
23
24
25<!--
26// helper definitions
27/////////////////////////////////////////////////////////////////////////////
28-->
29
30<!--
31 * capitalizes the first letter
32-->
33<xsl:template name="capitalize">
34 <xsl:param name="str" select="."/>
35 <xsl:value-of select="
36 concat(
37 translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
38 substring($str,2)
39 )
40 "/>
41</xsl:template>
42
43<!--
44 * uncapitalizes the first letter only if the second one is not capital
45 * otherwise leaves the string unchanged
46-->
47<xsl:template name="uncapitalize">
48 <xsl:param name="str" select="."/>
49 <xsl:choose>
50 <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring($str,2,1)))">
51 <xsl:value-of select="
52 concat(
53 translate(substring($str,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
54 substring($str,2)
55 )
56 "/>
57 </xsl:when>
58 <xsl:otherwise>
59 <xsl:value-of select="string($str)"/>
60 </xsl:otherwise>
61 </xsl:choose>
62</xsl:template>
63
64<!--
65 * translates the string to uppercase
66-->
67<xsl:template name="uppercase">
68 <xsl:param name="str" select="."/>
69 <xsl:value-of select="
70 translate($str,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
71 "/>
72</xsl:template>
73
74
75<!--
76// templates
77/////////////////////////////////////////////////////////////////////////////
78-->
79
80
81<!--
82 * not explicitly matched elements and attributes
83-->
84<xsl:template match="*"/>
85
86
87<!--
88 * header
89-->
90<xsl:template match="/idl">
91 <xsl:text>
92/*
93 * DO NOT EDIT! This is a generated file.
94 *
95 * XPCOM IDL (XPIDL) definition for VirtualBox Main API (COM interfaces)
96 * generated from XIDL (XML interface definition).
97 *
98 * Source : src/VBox/Main/idl/VirtualBox.xidl
99 * Generator : src/VBox/Main/idl/xpidl.xsl
100 */
101
102#include "nsISupports.idl"
103#include "nsIException.idl"
104
105</xsl:text>
106 <!-- native typedefs for the 'mod="ptr"' attribute -->
107 <xsl:text>
108[ptr] native booleanPtr (PRBool);
109[ptr] native octetPtr (PRUint8);
110[ptr] native shortPtr (PRInt16);
111[ptr] native ushortPtr (PRUint16);
112[ptr] native longPtr (PRInt32);
113[ptr] native llongPtr (PRInt64);
114[ptr] native ulongPtr (PRUint32);
115[ptr] native ullongPtr (PRUint64);
116<!-- charPtr is already defined in nsrootidl.idl -->
117<!-- [ptr] native charPtr (char) -->
118[ptr] native stringPtr (string);
119[ptr] native wcharPtr (wchar);
120[ptr] native wstringPtr (wstring);
121
122</xsl:text>
123 <xsl:apply-templates/>
124</xsl:template>
125
126
127<!--
128 * ignore all |if|s except those for XPIDL target
129-->
130<xsl:template match="if">
131 <xsl:if test="@target='xpidl'">
132 <xsl:apply-templates/>
133 </xsl:if>
134</xsl:template>
135<xsl:template match="if" mode="forward">
136 <xsl:if test="@target='xpidl'">
137 <xsl:apply-templates mode="forward"/>
138 </xsl:if>
139</xsl:template>
140<xsl:template match="if" mode="forwarder">
141 <xsl:if test="@target='midl'">
142 <xsl:apply-templates mode="forwarder"/>
143 </xsl:if>
144</xsl:template>
145
146
147<!--
148 * cpp_quote
149-->
150<xsl:template match="cpp">
151 <xsl:if test="text()">
152 <xsl:text>%{C++</xsl:text>
153 <xsl:value-of select="text()"/>
154 <xsl:text>&#x0A;%}&#x0A;&#x0A;</xsl:text>
155 </xsl:if>
156 <xsl:if test="not(text()) and @line">
157 <xsl:text>%{C++&#x0A;</xsl:text>
158 <xsl:value-of select="@line"/>
159 <xsl:text>&#x0A;%}&#x0A;&#x0A;</xsl:text>
160 </xsl:if>
161</xsl:template>
162
163
164<!--
165 * #if statement (@if attribute)
166 * @note
167 * xpidl doesn't support any preprocessor defines other than #include
168 * (it just ignores them), so the generated IDL will most likely be
169 * invalid. So for now we forbid using @if attributes
170-->
171<xsl:template match="@if" mode="begin">
172 <xsl:message terminate="yes">
173 @if attributes are not currently allowed because xpidl lacks
174 support for #ifdef and stuff.
175 </xsl:message>
176 <xsl:text>#if </xsl:text>
177 <xsl:value-of select="."/>
178 <xsl:text>&#x0A;</xsl:text>
179</xsl:template>
180<xsl:template match="@if" mode="end">
181 <xsl:text>#endif&#x0A;</xsl:text>
182</xsl:template>
183
184
185<!--
186 * libraries
187-->
188<xsl:template match="library">
189 <xsl:text>%{C++&#x0A;</xsl:text>
190 <xsl:text>#ifndef VBOX_EXTERN_C&#x0A;</xsl:text>
191 <xsl:text># ifdef __cplusplus&#x0A;</xsl:text>
192 <xsl:text># define VBOX_EXTERN_C extern "C"&#x0A;</xsl:text>
193 <xsl:text># else // !__cplusplus&#x0A;</xsl:text>
194 <xsl:text># define VBOX_EXTERN_C extern&#x0A;</xsl:text>
195 <xsl:text># endif // !__cplusplus&#x0A;</xsl:text>
196 <xsl:text>#endif // !VBOX_EXTERN_C&#x0A;</xsl:text>
197 <!-- result codes -->
198 <xsl:text>// result codes declared in API spec&#x0A;</xsl:text>
199 <xsl:for-each select="result">
200 <xsl:apply-templates select="."/>
201 </xsl:for-each>
202 <xsl:text>%}&#x0A;&#x0A;</xsl:text>
203 <!-- forward declarations -->
204 <xsl:apply-templates select="if | interface" mode="forward"/>
205 <xsl:text>&#x0A;</xsl:text>
206 <!-- all enums go first -->
207 <xsl:apply-templates select="enum | if/enum"/>
208 <!-- everything else but result codes and enums -->
209 <xsl:apply-templates select="*[not(self::result or self::enum) and
210 not(self::if[result] or self::if[enum])]"/>
211 <!-- -->
212</xsl:template>
213
214
215<!--
216 * result codes
217-->
218<xsl:template match="result">
219 <xsl:value-of select="concat('#define ',@name,' ',@value)"/>
220 <xsl:text>&#x0A;</xsl:text>
221</xsl:template>
222
223
224<!--
225 * forward declarations
226-->
227<xsl:template match="interface" mode="forward">
228 <xsl:text>interface </xsl:text>
229 <xsl:value-of select="@name"/>
230 <xsl:text>;&#x0A;</xsl:text>
231</xsl:template>
232
233
234<!--
235 * interfaces
236-->
237<xsl:template match="interface">[
238 uuid(<xsl:value-of select="@uuid"/>),
239 scriptable
240]
241<xsl:text>interface </xsl:text>
242 <xsl:value-of select="@name"/>
243 <xsl:text> : </xsl:text>
244 <xsl:choose>
245 <xsl:when test="@extends='$unknown'">nsISupports</xsl:when>
246 <xsl:when test="@extends='$errorinfo'">nsIException</xsl:when>
247 <xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
248 </xsl:choose>
249 <xsl:text>&#x0A;{&#x0A;</xsl:text>
250 <!-- attributes (properties) -->
251 <xsl:apply-templates select="attribute"/>
252 <!-- methods -->
253 <xsl:apply-templates select="method"/>
254 <!-- 'if' enclosed elements, unsorted -->
255 <xsl:apply-templates select="if"/>
256 <!-- -->
257 <xsl:text>}; /* interface </xsl:text>
258 <xsl:value-of select="@name"/>
259 <xsl:text> */&#x0A;&#x0A;</xsl:text>
260 <!-- Interface implementation forwarder macro -->
261 <xsl:text>/* Interface implementation forwarder macro */&#x0A;</xsl:text>
262 <xsl:text>%{C++&#x0A;</xsl:text>
263 <!-- 1) individual methods -->
264 <xsl:apply-templates select="attribute" mode="forwarder"/>
265 <xsl:apply-templates select="method" mode="forwarder"/>
266 <xsl:apply-templates select="if" mode="forwarder"/>
267 <!-- 2) COM_FORWARD_Interface_TO(smth) -->
268 <xsl:text>#define COM_FORWARD_</xsl:text>
269 <xsl:value-of select="@name"/>
270 <xsl:text>_TO(smth) NS_FORWARD_</xsl:text>
271 <xsl:call-template name="uppercase">
272 <xsl:with-param name="str" select="@name"/>
273 </xsl:call-template>
274 <xsl:text> (smth)&#x0A;</xsl:text>
275 <!-- 3) COM_FORWARD_Interface_TO_OBJ(obj) -->
276 <xsl:text>#define COM_FORWARD_</xsl:text>
277 <xsl:value-of select="@name"/>
278 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
279 <xsl:value-of select="@name"/>
280 <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
281 <!-- 4) COM_FORWARD_Interface_TO_BASE(base) -->
282 <xsl:text>#define COM_FORWARD_</xsl:text>
283 <xsl:value-of select="@name"/>
284 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
285 <xsl:value-of select="@name"/>
286 <xsl:text>_TO (base::)&#x0A;&#x0A;</xsl:text>
287 <!-- -->
288 <xsl:text>// for compatibility with Win32&#x0A;</xsl:text>
289 <xsl:text>VBOX_EXTERN_C const nsID IID_</xsl:text>
290 <xsl:value-of select="@name"/>
291 <xsl:text>;&#x0A;</xsl:text>
292 <xsl:text>%}&#x0A;&#x0A;</xsl:text>
293 <!-- end -->
294</xsl:template>
295
296
297<!--
298 * attributes
299-->
300<xsl:template match="interface//attribute">
301 <xsl:apply-templates select="@if" mode="begin"/>
302 <xsl:if test="@mod='ptr'">
303 <!-- attributes using native types must be non-scriptable -->
304 <xsl:text> [noscript]&#x0A;</xsl:text>
305 </xsl:if>
306 <xsl:choose>
307 <!-- safearray pseudo attribute -->
308 <xsl:when test="@safearray='yes'">
309 <!-- getter -->
310 <xsl:text> void get</xsl:text>
311 <xsl:call-template name="capitalize">
312 <xsl:with-param name="str" select="@name"/>
313 </xsl:call-template>
314 <xsl:text> (&#x0A;</xsl:text>
315 <!-- array size -->
316 <xsl:text> out unsigned long </xsl:text>
317 <xsl:value-of select="@name"/>
318 <xsl:text>Size,&#x0A;</xsl:text>
319 <!-- array pointer -->
320 <xsl:text> [array, size_is(</xsl:text>
321 <xsl:value-of select="@name"/>
322 <xsl:text>Size), retval] out </xsl:text>
323 <xsl:apply-templates select="@type"/>
324 <xsl:text> </xsl:text>
325 <xsl:value-of select="@name"/>
326 <xsl:text>&#x0A; );&#x0A;</xsl:text>
327 <!-- setter -->
328 <xsl:if test="not(@readonly='yes')">
329 <xsl:text> void set</xsl:text>
330 <xsl:call-template name="capitalize">
331 <xsl:with-param name="str" select="@name"/>
332 </xsl:call-template>
333 <xsl:text> (&#x0A;</xsl:text>
334 <!-- array size -->
335 <xsl:text> in unsigned long </xsl:text>
336 <xsl:value-of select="@name"/>
337 <xsl:text>Size,&#x0A;</xsl:text>
338 <!-- array pointer -->
339 <xsl:text> [array, size_is(</xsl:text>
340 <xsl:value-of select="@name"/>
341 <xsl:text>Size)] in </xsl:text>
342 <xsl:apply-templates select="@type"/>
343 <xsl:text> </xsl:text>
344 <xsl:value-of select="@name"/>
345 <xsl:text>&#x0A; );&#x0A;</xsl:text>
346 </xsl:if>
347 </xsl:when>
348 <!-- normal attribute -->
349 <xsl:otherwise>
350 <xsl:text> </xsl:text>
351 <xsl:if test="@readonly='yes'">
352 <xsl:text>readonly </xsl:text>
353 </xsl:if>
354 <xsl:text>attribute </xsl:text>
355 <xsl:apply-templates select="@type"/>
356 <xsl:text> </xsl:text>
357 <xsl:value-of select="@name"/>
358 <xsl:text>;&#x0A;</xsl:text>
359 </xsl:otherwise>
360 </xsl:choose>
361 <xsl:apply-templates select="@if" mode="end"/>
362 <xsl:text>&#x0A;</xsl:text>
363</xsl:template>
364
365<xsl:template match="interface//attribute" mode="forwarder">
366
367 <xsl:variable name="parent" select="ancestor::interface"/>
368
369 <xsl:apply-templates select="@if" mode="begin"/>
370
371 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO(smth) -->
372 <xsl:text>#define COM_FORWARD_</xsl:text>
373 <xsl:value-of select="$parent/@name"/>
374 <xsl:text>_GETTER_</xsl:text>
375 <xsl:call-template name="capitalize">
376 <xsl:with-param name="str" select="@name"/>
377 </xsl:call-template>
378 <xsl:text>_TO(smth) NS_IMETHOD Get</xsl:text>
379 <xsl:call-template name="capitalize">
380 <xsl:with-param name="str" select="@name"/>
381 </xsl:call-template>
382 <xsl:text> (</xsl:text>
383 <xsl:if test="@safearray='yes'">
384 <xsl:text>PRUint32 * a</xsl:text>
385 <xsl:call-template name="capitalize">
386 <xsl:with-param name="str" select="@name"/>
387 </xsl:call-template>
388 <xsl:text>Size, </xsl:text>
389 </xsl:if>
390 <xsl:apply-templates select="@type" mode="forwarder"/>
391 <xsl:if test="@safearray='yes'">
392 <xsl:text> *</xsl:text>
393 </xsl:if>
394 <xsl:text> * a</xsl:text>
395 <xsl:call-template name="capitalize">
396 <xsl:with-param name="str" select="@name"/>
397 </xsl:call-template>
398 <xsl:text>) { return smth Get</xsl:text>
399 <xsl:call-template name="capitalize">
400 <xsl:with-param name="str" select="@name"/>
401 </xsl:call-template>
402 <xsl:text> (</xsl:text>
403 <xsl:if test="@safearray='yes'">
404 <xsl:text>a</xsl:text>
405 <xsl:call-template name="capitalize">
406 <xsl:with-param name="str" select="@name"/>
407 </xsl:call-template>
408 <xsl:text>Size, </xsl:text>
409 </xsl:if>
410 <xsl:text>a</xsl:text>
411 <xsl:call-template name="capitalize">
412 <xsl:with-param name="str" select="@name"/>
413 </xsl:call-template>
414 <xsl:text>); }&#x0A;</xsl:text>
415 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO_OBJ(obj) -->
416 <xsl:text>#define COM_FORWARD_</xsl:text>
417 <xsl:value-of select="$parent/@name"/>
418 <xsl:text>_GETTER_</xsl:text>
419 <xsl:call-template name="capitalize">
420 <xsl:with-param name="str" select="@name"/>
421 </xsl:call-template>
422 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
423 <xsl:value-of select="$parent/@name"/>
424 <xsl:text>_GETTER_</xsl:text>
425 <xsl:call-template name="capitalize">
426 <xsl:with-param name="str" select="@name"/>
427 </xsl:call-template>
428 <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
429 <!-- getter: COM_FORWARD_Interface_GETTER_Name_TO_BASE(base) -->
430 <xsl:text>#define COM_FORWARD_</xsl:text>
431 <xsl:value-of select="$parent/@name"/>
432 <xsl:text>_GETTER_</xsl:text>
433 <xsl:call-template name="capitalize">
434 <xsl:with-param name="str" select="@name"/>
435 </xsl:call-template>
436 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
437 <xsl:value-of select="$parent/@name"/>
438 <xsl:text>_GETTER_</xsl:text>
439 <xsl:call-template name="capitalize">
440 <xsl:with-param name="str" select="@name"/>
441 </xsl:call-template>
442 <xsl:text>_TO (base::)&#x0A;</xsl:text>
443 <!-- -->
444 <xsl:if test="not(@readonly='yes')">
445 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO(smth) -->
446 <xsl:text>#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(smth) NS_IMETHOD Set</xsl:text>
453 <xsl:call-template name="capitalize">
454 <xsl:with-param name="str" select="@name"/>
455 </xsl:call-template>
456 <xsl:text> (</xsl:text>
457 <xsl:if test="@safearray='yes'">
458 <xsl:text>PRUint32 a</xsl:text>
459 <xsl:call-template name="capitalize">
460 <xsl:with-param name="str" select="@name"/>
461 </xsl:call-template>
462 <xsl:text>Size, </xsl:text>
463 </xsl:if>
464 <xsl:if test="not(@safearray='yes') and (@type='string' or @type='wstring')">
465 <xsl:text>const </xsl:text>
466 </xsl:if>
467 <xsl:apply-templates select="@type" mode="forwarder"/>
468 <xsl:if test="@safearray='yes'">
469 <xsl:text> *</xsl:text>
470 </xsl:if>
471 <xsl:text> a</xsl:text>
472 <xsl:call-template name="capitalize">
473 <xsl:with-param name="str" select="@name"/>
474 </xsl:call-template>
475 <xsl:text>) { return smth Set</xsl:text>
476 <xsl:call-template name="capitalize">
477 <xsl:with-param name="str" select="@name"/>
478 </xsl:call-template>
479 <xsl:text> (a</xsl:text>
480 <xsl:call-template name="capitalize">
481 <xsl:with-param name="str" select="@name"/>
482 </xsl:call-template>
483 <xsl:text>); }&#x0A;</xsl:text>
484 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO_OBJ(obj) -->
485 <xsl:text>#define COM_FORWARD_</xsl:text>
486 <xsl:value-of select="$parent/@name"/>
487 <xsl:text>_SETTER_</xsl:text>
488 <xsl:call-template name="capitalize">
489 <xsl:with-param name="str" select="@name"/>
490 </xsl:call-template>
491 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
492 <xsl:value-of select="$parent/@name"/>
493 <xsl:text>_SETTER_</xsl:text>
494 <xsl:call-template name="capitalize">
495 <xsl:with-param name="str" select="@name"/>
496 </xsl:call-template>
497 <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
498 <!-- setter: COM_FORWARD_Interface_SETTER_Name_TO_BASE(base) -->
499 <xsl:text>#define COM_FORWARD_</xsl:text>
500 <xsl:value-of select="$parent/@name"/>
501 <xsl:text>_SETTER_</xsl:text>
502 <xsl:call-template name="capitalize">
503 <xsl:with-param name="str" select="@name"/>
504 </xsl:call-template>
505 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
506 <xsl:value-of select="$parent/@name"/>
507 <xsl:text>_SETTER_</xsl:text>
508 <xsl:call-template name="capitalize">
509 <xsl:with-param name="str" select="@name"/>
510 </xsl:call-template>
511 <xsl:text>_TO (base::)&#x0A;</xsl:text>
512 </xsl:if>
513
514 <xsl:apply-templates select="@if" mode="end"/>
515
516</xsl:template>
517
518
519<!--
520 * methods
521-->
522<xsl:template match="interface//method">
523 <xsl:apply-templates select="@if" mode="begin"/>
524 <xsl:if test="param/@mod='ptr'">
525 <!-- methods using native types must be non-scriptable -->
526 <xsl:text> [noscript]&#x0A;</xsl:text>
527 </xsl:if>
528 <xsl:text> void </xsl:text>
529 <xsl:value-of select="@name"/>
530 <xsl:if test="param">
531 <xsl:text> (&#x0A;</xsl:text>
532 <xsl:for-each select="param [position() != last()]">
533 <xsl:text> </xsl:text>
534 <xsl:apply-templates select="."/>
535 <xsl:text>,&#x0A;</xsl:text>
536 </xsl:for-each>
537 <xsl:text> </xsl:text>
538 <xsl:apply-templates select="param [last()]"/>
539 <xsl:text>&#x0A; );&#x0A;</xsl:text>
540 </xsl:if>
541 <xsl:if test="not(param)">
542 <xsl:text>();&#x0A;</xsl:text>
543 </xsl:if>
544 <xsl:apply-templates select="@if" mode="end"/>
545 <xsl:text>&#x0A;</xsl:text>
546</xsl:template>
547
548<xsl:template match="interface//method" mode="forwarder">
549
550 <xsl:variable name="parent" select="ancestor::interface"/>
551
552 <xsl:apply-templates select="@if" mode="begin"/>
553
554 <xsl:text>#define COM_FORWARD_</xsl:text>
555 <xsl:value-of select="$parent/@name"/>
556 <xsl:text>_</xsl:text>
557 <xsl:call-template name="capitalize">
558 <xsl:with-param name="str" select="@name"/>
559 </xsl:call-template>
560 <xsl:text>_TO(smth) NS_IMETHOD </xsl:text>
561 <xsl:call-template name="capitalize">
562 <xsl:with-param name="str" select="@name"/>
563 </xsl:call-template>
564 <xsl:choose>
565 <xsl:when test="param">
566 <xsl:text> (</xsl:text>
567 <xsl:for-each select="param [position() != last()]">
568 <xsl:apply-templates select="." mode="forwarder"/>
569 <xsl:text>, </xsl:text>
570 </xsl:for-each>
571 <xsl:apply-templates select="param [last()]" mode="forwarder"/>
572 <xsl:text>) { return smth </xsl:text>
573 <xsl:call-template name="capitalize">
574 <xsl:with-param name="str" select="@name"/>
575 </xsl:call-template>
576 <xsl:text> (</xsl:text>
577 <xsl:for-each select="param [position() != last()]">
578 <xsl:if test="@safearray='yes'">
579 <xsl:text>a</xsl:text>
580 <xsl:call-template name="capitalize">
581 <xsl:with-param name="str" select="@name"/>
582 </xsl:call-template>
583 <xsl:text>Size+++, </xsl:text>
584 </xsl:if>
585 <xsl:text>a</xsl:text>
586 <xsl:call-template name="capitalize">
587 <xsl:with-param name="str" select="@name"/>
588 </xsl:call-template>
589 <xsl:text>, </xsl:text>
590 </xsl:for-each>
591 <xsl:if test="param [last()]/@safearray='yes'">
592 <xsl:text>a</xsl:text>
593 <xsl:call-template name="capitalize">
594 <xsl:with-param name="str" select="param [last()]/@name"/>
595 </xsl:call-template>
596 <xsl:text>Size, </xsl:text>
597 </xsl:if>
598 <xsl:text>a</xsl:text>
599 <xsl:call-template name="capitalize">
600 <xsl:with-param name="str" select="param [last()]/@name"/>
601 </xsl:call-template>
602 <xsl:text>); }</xsl:text>
603 </xsl:when>
604 <xsl:otherwise test="not(param)">
605 <xsl:text>() { return smth </xsl:text>
606 <xsl:call-template name="capitalize">
607 <xsl:with-param name="str" select="@name"/>
608 </xsl:call-template>
609 <xsl:text>(); }</xsl:text>
610 </xsl:otherwise>
611 </xsl:choose>
612 <xsl:text>&#x0A;</xsl:text>
613 <!-- COM_FORWARD_Interface_Method_TO_OBJ(obj) -->
614 <xsl:text>#define COM_FORWARD_</xsl:text>
615 <xsl:value-of select="$parent/@name"/>
616 <xsl:text>_</xsl:text>
617 <xsl:call-template name="capitalize">
618 <xsl:with-param name="str" select="@name"/>
619 </xsl:call-template>
620 <xsl:text>_TO_OBJ(obj) COM_FORWARD_</xsl:text>
621 <xsl:value-of select="$parent/@name"/>
622 <xsl:text>_</xsl:text>
623 <xsl:call-template name="capitalize">
624 <xsl:with-param name="str" select="@name"/>
625 </xsl:call-template>
626 <xsl:text>_TO ((obj)->)&#x0A;</xsl:text>
627 <!-- COM_FORWARD_Interface_Method_TO_BASE(base) -->
628 <xsl:text>#define COM_FORWARD_</xsl:text>
629 <xsl:value-of select="$parent/@name"/>
630 <xsl:text>_</xsl:text>
631 <xsl:call-template name="capitalize">
632 <xsl:with-param name="str" select="@name"/>
633 </xsl:call-template>
634 <xsl:text>_TO_BASE(base) COM_FORWARD_</xsl:text>
635 <xsl:value-of select="$parent/@name"/>
636 <xsl:text>_</xsl:text>
637 <xsl:call-template name="capitalize">
638 <xsl:with-param name="str" select="@name"/>
639 </xsl:call-template>
640 <xsl:text>_TO (base::)&#x0A;</xsl:text>
641
642 <xsl:apply-templates select="@if" mode="end"/>
643
644</xsl:template>
645
646
647<!--
648 * modules
649-->
650<xsl:template match="module">
651 <xsl:apply-templates select="class"/>
652</xsl:template>
653
654
655<!--
656 * co-classes
657-->
658<xsl:template match="module/class">
659 <!-- class and contract id -->
660 <xsl:text>%{C++&#x0A;</xsl:text>
661 <xsl:text>// Definitions for module </xsl:text>
662 <xsl:value-of select="../@name"/>
663 <xsl:text>, class </xsl:text>
664 <xsl:value-of select="@name"/>
665 <xsl:text>:&#x0A;</xsl:text>
666 <xsl:text>#define NS_</xsl:text>
667 <xsl:call-template name="uppercase">
668 <xsl:with-param name="str" select="@name"/>
669 </xsl:call-template>
670 <xsl:text>_CID { \&#x0A;</xsl:text>
671 <xsl:text> 0x</xsl:text><xsl:value-of select="substring(@uuid,1,8)"/>
672 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,10,4)"/>
673 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,15,4)"/>
674 <xsl:text>, \&#x0A; </xsl:text>
675 <xsl:text>{ 0x</xsl:text><xsl:value-of select="substring(@uuid,20,2)"/>
676 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,22,2)"/>
677 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,25,2)"/>
678 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,27,2)"/>
679 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,29,2)"/>
680 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,31,2)"/>
681 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,33,2)"/>
682 <xsl:text>, 0x</xsl:text><xsl:value-of select="substring(@uuid,35,2)"/>
683 <xsl:text> } \&#x0A;}&#x0A;</xsl:text>
684 <xsl:text>#define NS_</xsl:text>
685 <xsl:call-template name="uppercase">
686 <xsl:with-param name="str" select="@name"/>
687 </xsl:call-template>
688 <!-- Contract ID -->
689 <xsl:text>_CONTRACTID &quot;@</xsl:text>
690 <xsl:value-of select="@namespace"/>
691 <xsl:text>/</xsl:text>
692 <xsl:value-of select="@name"/>
693 <xsl:text>;1&quot;&#x0A;</xsl:text>
694 <!-- CLSID_xxx declarations for XPCOM, for compatibility with Win32 -->
695 <xsl:text>// for compatibility with Win32&#x0A;</xsl:text>
696 <xsl:text>VBOX_EXTERN_C const nsCID CLSID_</xsl:text>
697 <xsl:value-of select="@name"/>
698 <xsl:text>;&#x0A;</xsl:text>
699 <xsl:text>%}&#x0A;&#x0A;</xsl:text>
700</xsl:template>
701
702
703<!--
704 * enums
705-->
706<xsl:template match="enum">[
707 uuid(<xsl:value-of select="@uuid"/>),
708 scriptable
709]
710<xsl:text>interface </xsl:text>
711 <xsl:value-of select="@name"/>
712 <xsl:text>&#x0A;{&#x0A;</xsl:text>
713 <xsl:for-each select="const">
714 <xsl:text> const PRUint32 </xsl:text>
715 <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>
716 <xsl:text>;&#x0A;</xsl:text>
717 </xsl:for-each>
718 <xsl:text>};&#x0A;&#x0A;</xsl:text>
719 <!-- -->
720 <xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */&#x0A;')"/>
721 <xsl:text>%{C++&#x0A;</xsl:text>
722 <xsl:value-of select="concat('#define ', @name, '_T', ' ',
723 'PRUint32&#x0A;')"/>
724 <xsl:text>%}&#x0A;&#x0A;</xsl:text>
725 <!-- -->
726 <xsl:value-of select="concat('/* cross-platform constants for ', @name, ' */&#x0A;')"/>
727 <xsl:text>%{C++&#x0A;</xsl:text>
728 <xsl:for-each select="const">
729 <xsl:value-of select="concat('#define ', ../@name, '_', @name, ' ',
730 ../@name, '::', @name, '&#x0A;')"/>
731 </xsl:for-each>
732 <xsl:text>%}&#x0A;&#x0A;</xsl:text>
733</xsl:template>
734
735
736<!--
737 * method parameters
738-->
739<xsl:template match="method/param">
740 <xsl:choose>
741 <!-- safearray parameters -->
742 <xsl:when test="@safearray='yes'">
743 <!-- array size -->
744 <xsl:choose>
745 <xsl:when test="@dir='in'">in </xsl:when>
746 <xsl:when test="@dir='out'">out </xsl:when>
747 <xsl:when test="@dir='return'">out </xsl:when>
748 <xsl:otherwise>in </xsl:otherwise>
749 </xsl:choose>
750 <xsl:text>unsigned long </xsl:text>
751 <xsl:value-of select="@name"/>
752 <xsl:text>Size,&#x0A;</xsl:text>
753 <!-- array pointer -->
754 <xsl:text> [array, size_is(</xsl:text>
755 <xsl:value-of select="@name"/>
756 <xsl:text>Size)</xsl:text>
757 <xsl:choose>
758 <xsl:when test="@dir='in'">] in </xsl:when>
759 <xsl:when test="@dir='out'">] out </xsl:when>
760 <xsl:when test="@dir='return'"> , retval] out </xsl:when>
761 <xsl:otherwise>] in </xsl:otherwise>
762 </xsl:choose>
763 <xsl:apply-templates select="@type"/>
764 <xsl:text> </xsl:text>
765 <xsl:value-of select="@name"/>
766 </xsl:when>
767 <!-- normal and array parameters -->
768 <xsl:otherwise>
769 <xsl:choose>
770 <xsl:when test="@dir='in'">in </xsl:when>
771 <xsl:when test="@dir='out'">out </xsl:when>
772 <xsl:when test="@dir='return'">[retval] out </xsl:when>
773 <xsl:otherwise>in </xsl:otherwise>
774 </xsl:choose>
775 <xsl:apply-templates select="@type"/>
776 <xsl:text> </xsl:text>
777 <xsl:value-of select="@name"/>
778 </xsl:otherwise>
779 </xsl:choose>
780</xsl:template>
781
782<xsl:template match="method/param" mode="forwarder">
783 <xsl:if test="@safearray='yes'">
784 <xsl:text>PRUint32</xsl:text>
785 <xsl:if test="@dir='out' or @dir='return'">
786 <xsl:text> *</xsl:text>
787 </xsl:if>
788 <xsl:text> a</xsl:text>
789 <xsl:call-template name="capitalize">
790 <xsl:with-param name="str" select="@name"/>
791 </xsl:call-template>
792 <xsl:text>Size, </xsl:text>
793 </xsl:if>
794 <xsl:apply-templates select="@type" mode="forwarder"/>
795 <xsl:if test="@dir='out' or @dir='return'">
796 <xsl:text> *</xsl:text>
797 </xsl:if>
798 <xsl:if test="@safearray='yes'">
799 <xsl:text> *</xsl:text>
800 </xsl:if>
801 <xsl:text> a</xsl:text>
802 <xsl:call-template name="capitalize">
803 <xsl:with-param name="str" select="@name"/>
804 </xsl:call-template>
805</xsl:template>
806
807
808<!--
809 * attribute/parameter type conversion
810-->
811<xsl:template match="attribute/@type | param/@type">
812 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
813
814 <xsl:choose>
815 <!-- modifiers (ignored for 'enumeration' attributes)-->
816 <xsl:when test="name(current())='type' and ../@mod">
817 <xsl:choose>
818 <xsl:when test="../@mod='ptr'">
819 <xsl:choose>
820 <!-- standard types -->
821 <!--xsl:when test=".='result'">??</xsl:when-->
822 <xsl:when test=".='boolean'">booleanPtr</xsl:when>
823 <xsl:when test=".='octet'">octetPtr</xsl:when>
824 <xsl:when test=".='short'">shortPtr</xsl:when>
825 <xsl:when test=".='unsigned short'">ushortPtr</xsl:when>
826 <xsl:when test=".='long'">longPtr</xsl:when>
827 <xsl:when test=".='long long'">llongPtr</xsl:when>
828 <xsl:when test=".='unsigned long'">ulongPtr</xsl:when>
829 <xsl:when test=".='unsigned long long'">ullongPtr</xsl:when>
830 <xsl:otherwise>
831 <xsl:message terminate="yes">
832 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
833 <xsl:text>attribute 'mod=</xsl:text>
834 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
835 <xsl:text>' cannot be used with type </xsl:text>
836 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
837 </xsl:message>
838 </xsl:otherwise>
839 </xsl:choose>
840 </xsl:when>
841 <xsl:when test="../@mod='string'">
842 <xsl:choose>
843 <!-- standard types -->
844 <!--xsl:when test=".='result'">??</xsl:when-->
845 <xsl:when test=".='uuid'">wstring</xsl:when>
846 <xsl:otherwise>
847 <xsl:message terminate="yes">
848 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
849 <xsl:text>attribute 'mod=</xsl:text>
850 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
851 <xsl:text>' cannot be used with type </xsl:text>
852 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
853 </xsl:message>
854 </xsl:otherwise>
855 </xsl:choose>
856 </xsl:when>
857 <xsl:otherwise>
858 <xsl:message terminate="yes">
859 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
860 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
861 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
862 </xsl:message>
863 </xsl:otherwise>
864 </xsl:choose>
865 </xsl:when>
866 <!-- no modifiers -->
867 <xsl:otherwise>
868 <xsl:choose>
869 <!-- standard types -->
870 <xsl:when test=".='result'">nsresult</xsl:when>
871 <xsl:when test=".='boolean'">boolean</xsl:when>
872 <xsl:when test=".='octet'">octet</xsl:when>
873 <xsl:when test=".='short'">short</xsl:when>
874 <xsl:when test=".='unsigned short'">unsigned short</xsl:when>
875 <xsl:when test=".='long'">long</xsl:when>
876 <xsl:when test=".='long long'">long long</xsl:when>
877 <xsl:when test=".='unsigned long'">unsigned long</xsl:when>
878 <xsl:when test=".='unsigned long long'">unsigned long long</xsl:when>
879 <xsl:when test=".='char'">char</xsl:when>
880 <xsl:when test=".='wchar'">wchar</xsl:when>
881 <xsl:when test=".='string'">string</xsl:when>
882 <xsl:when test=".='wstring'">wstring</xsl:when>
883 <!-- UUID type -->
884 <xsl:when test=".='uuid'">
885 <xsl:choose>
886 <xsl:when test="name(..)='attribute'">
887 <xsl:choose>
888 <xsl:when test="../@readonly='yes'">
889 <xsl:text>nsIDPtr</xsl:text>
890 </xsl:when>
891 <xsl:otherwise>
892 <xsl:message terminate="yes">
893 <xsl:value-of select="../@name"/>
894 <xsl:text>: Non-readonly uuid attributes are not supported!</xsl:text>
895 </xsl:message>
896 </xsl:otherwise>
897 </xsl:choose>
898 </xsl:when>
899 <xsl:when test="name(..)='param'">
900 <xsl:choose>
901 <xsl:when test="../@dir='in' and not(../@safearray='yes')">
902 <xsl:text>nsIDRef</xsl:text>
903 </xsl:when>
904 <xsl:otherwise>
905 <xsl:text>nsIDPtr</xsl:text>
906 </xsl:otherwise>
907 </xsl:choose>
908 </xsl:when>
909 </xsl:choose>
910 </xsl:when>
911 <!-- system interface types -->
912 <xsl:when test=".='$unknown'">nsISupports</xsl:when>
913 <xsl:otherwise>
914 <xsl:choose>
915 <!-- enum types -->
916 <xsl:when test="
917 (ancestor::library/enum[@name=current()]) or
918 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
919 ">
920 <xsl:text>PRUint32</xsl:text>
921 </xsl:when>
922 <!-- custom interface types -->
923 <xsl:when test="
924 (ancestor::library/interface[@name=current()]) or
925 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
926 ">
927 <xsl:value-of select="."/>
928 </xsl:when>
929 <!-- other types -->
930 <xsl:otherwise>
931 <xsl:message terminate="yes">
932 <xsl:text>Unknown parameter type: </xsl:text>
933 <xsl:value-of select="."/>
934 </xsl:message>
935 </xsl:otherwise>
936 </xsl:choose>
937 </xsl:otherwise>
938 </xsl:choose>
939 </xsl:otherwise>
940 </xsl:choose>
941</xsl:template>
942
943<xsl:template match="attribute/@type | param/@type" mode="forwarder">
944
945 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
946
947 <xsl:choose>
948 <!-- modifiers (ignored for 'enumeration' attributes)-->
949 <xsl:when test="name(current())='type' and ../@mod">
950 <xsl:choose>
951 <xsl:when test="../@mod='ptr'">
952 <xsl:choose>
953 <!-- standard types -->
954 <!--xsl:when test=".='result'">??</xsl:when-->
955 <xsl:when test=".='boolean'">PRBool *</xsl:when>
956 <xsl:when test=".='octet'">PRUint8 *</xsl:when>
957 <xsl:when test=".='short'">PRInt16 *</xsl:when>
958 <xsl:when test=".='unsigned short'">PRUint16 *</xsl:when>
959 <xsl:when test=".='long'">PRInt32 *</xsl:when>
960 <xsl:when test=".='long long'">PRInt64 *</xsl:when>
961 <xsl:when test=".='unsigned long'">PRUint32 *</xsl:when>
962 <xsl:when test=".='unsigned long long'">PRUint64 *</xsl:when>
963 <xsl:when test=".='char'">char *</xsl:when>
964 <xsl:otherwise>
965 <xsl:message terminate="yes">
966 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
967 <xsl:text>attribute 'mod=</xsl:text>
968 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
969 <xsl:text>' cannot be used with type </xsl:text>
970 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
971 </xsl:message>
972 </xsl:otherwise>
973 </xsl:choose>
974 </xsl:when>
975 <xsl:when test="../@mod='string'">
976 <xsl:choose>
977 <!-- standard types -->
978 <!--xsl:when test=".='result'">??</xsl:when-->
979 <xsl:when test=".='uuid'">PRUnichar *</xsl:when>
980 <xsl:otherwise>
981 <xsl:message terminate="yes">
982 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
983 <xsl:text>attribute 'mod=</xsl:text>
984 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
985 <xsl:text>' cannot be used with type </xsl:text>
986 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
987 </xsl:message>
988 </xsl:otherwise>
989 </xsl:choose>
990 </xsl:when>
991 </xsl:choose>
992 </xsl:when>
993 <!-- no modifiers -->
994 <xsl:otherwise>
995 <xsl:choose>
996 <!-- standard types -->
997 <xsl:when test=".='result'">nsresult</xsl:when>
998 <xsl:when test=".='boolean'">PRBool</xsl:when>
999 <xsl:when test=".='octet'">PRUint8</xsl:when>
1000 <xsl:when test=".='short'">PRInt16</xsl:when>
1001 <xsl:when test=".='unsigned short'">PRUint16</xsl:when>
1002 <xsl:when test=".='long'">PRInt32</xsl:when>
1003 <xsl:when test=".='long long'">PRInt64</xsl:when>
1004 <xsl:when test=".='unsigned long'">PRUint32</xsl:when>
1005 <xsl:when test=".='unsigned long long'">PRUint64</xsl:when>
1006 <xsl:when test=".='char'">char</xsl:when>
1007 <xsl:when test=".='wchar'">PRUnichar</xsl:when>
1008 <!-- string types -->
1009 <xsl:when test=".='string'">char *</xsl:when>
1010 <xsl:when test=".='wstring'">PRUnichar *</xsl:when>
1011 <!-- UUID type -->
1012 <xsl:when test=".='uuid'">
1013 <xsl:choose>
1014 <xsl:when test="name(..)='attribute'">
1015 <xsl:choose>
1016 <xsl:when test="../@readonly='yes'">
1017 <xsl:text>nsID *</xsl:text>
1018 </xsl:when>
1019 </xsl:choose>
1020 </xsl:when>
1021 <xsl:when test="name(..)='param'">
1022 <xsl:choose>
1023 <xsl:when test="../@dir='in' and not(../@safearray='yes')">
1024 <xsl:text>const nsID &amp;</xsl:text>
1025 </xsl:when>
1026 <xsl:otherwise>
1027 <xsl:text>nsID *</xsl:text>
1028 </xsl:otherwise>
1029 </xsl:choose>
1030 </xsl:when>
1031 </xsl:choose>
1032 </xsl:when>
1033 <!-- system interface types -->
1034 <xsl:when test=".='$unknown'">nsISupports *</xsl:when>
1035 <xsl:otherwise>
1036 <xsl:choose>
1037 <!-- enum types -->
1038 <xsl:when test="
1039 (ancestor::library/enum[@name=current()]) or
1040 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1041 ">
1042 <xsl:text>PRUint32</xsl:text>
1043 </xsl:when>
1044 <!-- custom interface types -->
1045 <xsl:when test="
1046 (ancestor::library/interface[@name=current()]) or
1047 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1048 ">
1049 <xsl:value-of select="."/>
1050 <xsl:text> *</xsl:text>
1051 </xsl:when>
1052 <!-- other types -->
1053 </xsl:choose>
1054 </xsl:otherwise>
1055 </xsl:choose>
1056 </xsl:otherwise>
1057 </xsl:choose>
1058</xsl:template>
1059
1060</xsl:stylesheet>
1061
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