VirtualBox

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

Last change on this file since 25414 was 23223, checked in by vboxsync, 15 years ago

API: big medium handling change and lots of assorted other cleanups and fixes

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

© 2023 Oracle
ContactPrivacy policyTerms of Use