VirtualBox

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

Last change on this file since 45434 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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