VirtualBox

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

Last change on this file since 28851 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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