VirtualBox

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

Last change on this file since 8170 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.7 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 * A template to generate a MS IDL compatible interface definition file
5 * from the generic interface definition expressed in XML.
6
7 Copyright (C) 2006-2007 Sun Microsystems, Inc.
8
9 This file is part of VirtualBox Open Source Edition (OSE), as
10 available from http://www.virtualbox.org. This file is free software;
11 you can redistribute it and/or modify it under the terms of the GNU
12 General Public License (GPL) as published by the Free Software
13 Foundation, in version 2 as it comes in the "COPYING" file of the
14 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16
17 Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 Clara, CA 95054 USA or visit http://www.sun.com if you need
19 additional information or have any questions.
20-->
21
22<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
23<xsl:output method="text"/>
24
25<xsl:strip-space elements="*"/>
26
27
28<!--
29// helper definitions
30/////////////////////////////////////////////////////////////////////////////
31-->
32
33<!--
34 * capitalizes the first letter
35-->
36<xsl:template name="capitalize">
37 <xsl:param name="str" select="."/>
38 <xsl:value-of select="
39 concat(
40 translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
41 substring($str,2)
42 )
43 "/>
44</xsl:template>
45
46<!--
47 * uncapitalizes the first letter only if the second one is not capital
48 * otherwise leaves the string unchanged
49-->
50<xsl:template name="uncapitalize">
51 <xsl:param name="str" select="."/>
52 <xsl:choose>
53 <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring($str,2,1)))">
54 <xsl:value-of select="
55 concat(
56 translate(substring($str,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
57 substring($str,2)
58 )
59 "/>
60 </xsl:when>
61 <xsl:otherwise>
62 <xsl:value-of select="string($str)"/>
63 </xsl:otherwise>
64 </xsl:choose>
65</xsl:template>
66
67
68<!--
69// templates
70/////////////////////////////////////////////////////////////////////////////
71-->
72
73
74<!--
75 * header
76-->
77<xsl:template match="/idl">
78 <xsl:text>
79/*
80 * DO NOT EDIT! This is a generated file.
81 *
82 * MS IDL (MIDL) definition for VirualBox Main API (COM interfaces)
83 * generated from XIDL (XML interface definition).
84 *
85 * Source : src/VBox/Main/idl/VirtualBox.xidl
86 * Generator : src/VBox/Main/idl/midl.xsl
87 */
88 </xsl:text>
89 <xsl:text>&#x0A;</xsl:text>
90 <xsl:text>import "unknwn.idl";&#x0A;&#x0A;</xsl:text>
91 <xsl:apply-templates/>
92</xsl:template>
93
94
95<!--
96 * ignore all |if|s except those for MIDL target
97-->
98<xsl:template match="if">
99 <xsl:if test="@target='midl'">
100 <xsl:apply-templates/>
101 </xsl:if>
102</xsl:template>
103<xsl:template match="if" mode="forward">
104 <xsl:if test="@target='midl'">
105 <xsl:apply-templates mode="forward"/>
106 </xsl:if>
107</xsl:template>
108
109
110<!--
111 * cpp_quote
112-->
113<xsl:template match="cpp">
114 <xsl:text>cpp_quote("</xsl:text>
115 <xsl:value-of select="@line"/>
116 <xsl:text>")&#x0A;&#x0A;</xsl:text>
117</xsl:template>
118
119
120<!--
121 * #if statement (@if attribute)
122-->
123<xsl:template match="@if" mode="begin">
124 <xsl:text>#if </xsl:text>
125 <xsl:value-of select="."/>
126 <xsl:text>&#x0A;</xsl:text>
127</xsl:template>
128<xsl:template match="@if" mode="end">
129 <xsl:text>#endif&#x0A;</xsl:text>
130</xsl:template>
131
132
133<!--
134 * libraries
135-->
136<xsl:template match="library">[
137 uuid(<xsl:value-of select="@uuid"/>),
138 version(<xsl:value-of select="@version"/>),
139 helpstring("<xsl:value-of select="@desc"/>")
140]
141<xsl:text>library </xsl:text>
142 <xsl:value-of select="@name"/>
143 <xsl:text>&#x0A;{&#x0A;</xsl:text>
144 <xsl:text>&#x0A;importlib("stdole2.tlb");&#x0A;&#x0A;</xsl:text>
145 <!-- forward declarations -->
146 <xsl:apply-templates select="if | interface | collection | enumerator" mode="forward"/>
147 <xsl:text>&#x0A;</xsl:text>
148 <!-- all enums go first -->
149 <xsl:apply-templates select="enum | if/enum"/>
150 <!-- everything else but enums -->
151 <xsl:apply-templates select="*[not(self::enum) and not(self::if[enum])]"/>
152 <!-- -->
153 <xsl:text>}; /* library </xsl:text>
154 <xsl:value-of select="@name"/>
155 <xsl:text> */&#x0A;&#x0A;</xsl:text>
156</xsl:template>
157
158
159<!--
160 * forward declarations
161-->
162<xsl:template match="interface | collection | enumerator" mode="forward">
163 <xsl:text>interface </xsl:text>
164 <xsl:value-of select="@name"/>
165 <xsl:text>;&#x0A;</xsl:text>
166</xsl:template>
167
168
169<!--
170 * interfaces
171-->
172<xsl:template match="interface">[
173 uuid(<xsl:value-of select="@uuid"/>),
174 object,
175 dual
176]
177<xsl:text>interface </xsl:text>
178 <xsl:value-of select="@name"/>
179 <xsl:text> : </xsl:text>
180 <xsl:choose>
181 <xsl:when test="@extends='$unknown'">IUnknown</xsl:when>
182 <xsl:when test="@extends='$dispatched'">IDispatch</xsl:when>
183 <xsl:when test="@extends='$errorinfo'">IErrorInfo</xsl:when>
184 <xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
185 </xsl:choose>
186 <xsl:text>&#x0A;{&#x0A;</xsl:text>
187 <!-- attributes (properties) -->
188 <xsl:apply-templates select="attribute"/>
189 <!-- methods -->
190 <xsl:apply-templates select="method"/>
191 <!-- 'if' enclosed elements, unsorted -->
192 <xsl:apply-templates select="if"/>
193 <!-- -->
194 <xsl:text>}; /* interface </xsl:text>
195 <xsl:value-of select="@name"/>
196 <xsl:text> */&#x0A;&#x0A;</xsl:text>
197</xsl:template>
198
199
200<!--
201 * attributes
202-->
203<xsl:template match="interface//attribute | collection//attribute">
204 <xsl:apply-templates select="@if" mode="begin"/>
205 <xsl:if test="@array">
206 <xsl:message terminate="yes">
207 <xsl:value-of select="concat(../@name,'::',@name,': ')"/>
208 <xsl:text>'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
209 </xsl:message>
210 </xsl:if>
211 <!-- getter -->
212 <xsl:text> [propget] HRESULT </xsl:text>
213 <xsl:call-template name="capitalize">
214 <xsl:with-param name="str" select="@name"/>
215 </xsl:call-template>
216 <xsl:text> ([out, retval] </xsl:text>
217 <xsl:if test="@safearray='yes'">
218 <xsl:text>SAFEARRAY(</xsl:text>
219 </xsl:if>
220 <xsl:apply-templates select="@type"/>
221 <xsl:if test="@safearray='yes'">
222 <xsl:text>)</xsl:text>
223 </xsl:if>
224 <xsl:text> * a</xsl:text>
225 <xsl:call-template name="capitalize">
226 <xsl:with-param name="str" select="@name"/>
227 </xsl:call-template>
228 <xsl:text>);&#x0A;</xsl:text>
229 <!-- setter -->
230 <xsl:if test="not(@readonly='yes')">
231 <xsl:text> [propput] HRESULT </xsl:text>
232 <xsl:call-template name="capitalize">
233 <xsl:with-param name="str" select="@name"/>
234 </xsl:call-template>
235 <xsl:text> ([in</xsl:text>
236 <xsl:if test="@safearray='yes'">
237 <!-- VB supports only [in, out], [out] and [out, retval] arrays -->
238 <xsl:text>, out</xsl:text>
239 </xsl:if>
240 <xsl:text>] </xsl:text>
241 <xsl:if test="@safearray='yes'">
242 <xsl:text>SAFEARRAY(</xsl:text>
243 </xsl:if>
244 <xsl:apply-templates select="@type"/>
245 <xsl:if test="@safearray='yes'">
246 <xsl:text>) *</xsl:text>
247 </xsl:if>
248 <xsl:text> a</xsl:text>
249 <xsl:call-template name="capitalize">
250 <xsl:with-param name="str" select="@name"/>
251 </xsl:call-template>
252 <xsl:text>);&#x0A;</xsl:text>
253 </xsl:if>
254 <xsl:apply-templates select="@if" mode="end"/>
255 <xsl:text>&#x0A;</xsl:text>
256</xsl:template>
257
258
259<!--
260 * methods
261-->
262<xsl:template match="interface//method | collection//method">
263 <xsl:apply-templates select="@if" mode="begin"/>
264 <xsl:text> HRESULT </xsl:text>
265 <xsl:call-template name="capitalize">
266 <xsl:with-param name="str" select="@name"/>
267 </xsl:call-template>
268 <xsl:if test="param">
269 <xsl:text> (&#x0A;</xsl:text>
270 <xsl:for-each select="param [position() != last()]">
271 <xsl:text> </xsl:text>
272 <xsl:apply-templates select="."/>
273 <xsl:text>,&#x0A;</xsl:text>
274 </xsl:for-each>
275 <xsl:text> </xsl:text>
276 <xsl:apply-templates select="param [last()]"/>
277 <xsl:text>&#x0A; );&#x0A;</xsl:text>
278 </xsl:if>
279 <xsl:if test="not(param)">
280 <xsl:text>();&#x0A;</xsl:text>
281 </xsl:if>
282 <xsl:apply-templates select="@if" mode="end"/>
283 <xsl:text>&#x0A;</xsl:text>
284</xsl:template>
285
286
287<!--
288 * co-classes
289-->
290<xsl:template match="module/class">[
291 uuid(<xsl:value-of select="@uuid"/>)
292]
293<xsl:text>coclass </xsl:text>
294 <xsl:value-of select="@name"/>
295 <xsl:text>&#x0A;{&#x0A;</xsl:text>
296 <xsl:for-each select="interface">
297 <xsl:text> </xsl:text>
298 <xsl:if test="@default='yes'">
299 <xsl:text>[default] </xsl:text>
300 </xsl:if>
301 <xsl:text>interface </xsl:text>
302 <xsl:value-of select="@name"/>
303 <xsl:text>;&#x0A;</xsl:text>
304 </xsl:for-each>
305 <xsl:text>&#x0A;}; /* coclass </xsl:text>
306 <xsl:value-of select="@name"/>
307 <xsl:text> */&#x0A;&#x0A;</xsl:text>
308</xsl:template>
309
310
311<!--
312 * enumerators
313-->
314<xsl:template match="enumerator">[
315 uuid(<xsl:value-of select="@uuid"/>),
316 object,
317 dual
318]
319<xsl:text>interface </xsl:text>
320 <xsl:value-of select="@name"/>
321 <xsl:text> : IUnknown&#x0A;{&#x0A;</xsl:text>
322 <!-- HasMore -->
323 <xsl:text> HRESULT HasMore ([out, retval] BOOL * more);&#x0A;&#x0A;</xsl:text>
324 <!-- GetNext -->
325 <xsl:text> HRESULT GetNext ([out, retval] </xsl:text>
326 <xsl:apply-templates select="@type"/>
327 <xsl:text> * next);&#x0A;&#x0A;</xsl:text>
328 <!-- -->
329 <xsl:text>&#x0A;}; /* interface </xsl:text>
330 <xsl:value-of select="@name"/>
331 <xsl:text> */&#x0A;&#x0A;</xsl:text>
332</xsl:template>
333
334
335<!--
336 * collections
337-->
338<xsl:template match="collection">
339 <xsl:if test="not(@readonly='yes')">
340 <xsl:message terminate="yes">
341 <xsl:value-of select="concat(@name,': ')"/>
342 <xsl:text>non-readonly collections are not currently supported</xsl:text>
343 </xsl:message>
344 </xsl:if>[
345 uuid(<xsl:value-of select="@uuid"/>),
346 object,
347 dual
348]
349<xsl:text>interface </xsl:text>
350 <xsl:value-of select="@name"/>
351 <xsl:text> : IUnknown&#x0A;{&#x0A;</xsl:text>
352 <!-- Count -->
353 <xsl:text> [propget] HRESULT Count ([out, retval] ULONG * count);&#x0A;&#x0A;</xsl:text>
354 <!-- GetItemAt -->
355 <xsl:text> HRESULT GetItemAt ([in] ULONG index, [out, retval] </xsl:text>
356 <xsl:apply-templates select="@type"/>
357 <xsl:text> * item);&#x0A;&#x0A;</xsl:text>
358 <!-- Enumerate -->
359 <xsl:text> HRESULT Enumerate ([out, retval] </xsl:text>
360 <xsl:apply-templates select="@enumerator"/>
361 <xsl:text> * enumerator);&#x0A;&#x0A;</xsl:text>
362 <!-- other extra attributes (properties) -->
363 <xsl:apply-templates select="attribute"/>
364 <!-- other extra methods -->
365 <xsl:apply-templates select="method"/>
366 <!-- 'if' enclosed elements, unsorted -->
367 <xsl:apply-templates select="if"/>
368 <!-- -->
369 <xsl:text>&#x0A;}; /* interface </xsl:text>
370 <xsl:value-of select="@name"/>
371 <xsl:text> */&#x0A;&#x0A;</xsl:text>
372</xsl:template>
373
374
375<!--
376 * enums
377-->
378<xsl:template match="enum">[
379 uuid(<xsl:value-of select="@uuid"/>),
380 v1_enum
381]
382<xsl:text>typedef enum &#x0A;{&#x0A;</xsl:text>
383 <xsl:for-each select="const">
384 <xsl:text> </xsl:text>
385 <xsl:value-of select="concat(../@name,'_',@name)"/> = <xsl:value-of select="@value"/>
386 <xsl:choose>
387 <xsl:when test="position()!=last()"><xsl:text>,&#x0A;</xsl:text></xsl:when>
388 <xsl:otherwise><xsl:text>&#x0A;</xsl:text></xsl:otherwise>
389 </xsl:choose>
390 </xsl:for-each>
391 <xsl:text>} </xsl:text>
392 <xsl:value-of select="@name"/>
393 <xsl:text>;&#x0A;&#x0A;</xsl:text>
394 <!-- -->
395 <xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */&#x0A;')"/>
396 <xsl:value-of select="concat('cpp_quote(&quot;#define ', @name, '_T', ' ',
397 @name, '&quot;)&#x0A;&#x0A;')"/>
398 <xsl:text>&#x0A;&#x0A;</xsl:text>
399</xsl:template>
400
401
402<!--
403 * method parameters
404-->
405<xsl:template match="method/param">
406 <xsl:text>[</xsl:text>
407 <xsl:choose>
408 <xsl:when test="@dir='in'">in</xsl:when>
409 <xsl:when test="@dir='out'">out</xsl:when>
410 <xsl:when test="@dir='return'">out, retval</xsl:when>
411 <xsl:otherwise>in</xsl:otherwise>
412 </xsl:choose>
413 <xsl:if test="@safearray='yes'">
414 <!-- VB supports only [in, out], [out] and [out, retval] arrays -->
415 <xsl:if test="@dir='in'">, out</xsl:if>
416 </xsl:if>
417 <xsl:if test="@array">
418 <xsl:if test="@dir='return'">
419 <xsl:message terminate="yes">
420 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
421 <xsl:text>return 'array' parameters are not supported, use 'safearray="yes"' instead.</xsl:text>
422 </xsl:message>
423 </xsl:if>
424 <xsl:choose>
425 <xsl:when test="../param[@name=current()/@array]">
426 <xsl:if test="../param[@name=current()/@array]/@dir != @dir">
427 <xsl:message terminate="yes">
428 <xsl:value-of select="concat(../../@name,'::',../@name,': ')"/>
429 <xsl:value-of select="concat(@name,' and ',../param[@name=current()/@array]/@name)"/>
430 <xsl:text> must have the same direction</xsl:text>
431 </xsl:message>
432 </xsl:if>
433 <xsl:text>, size_is(</xsl:text>
434 <xsl:if test="@dir='out'">
435 <xsl:text>, *</xsl:text>
436 </xsl:if>
437 <xsl:text>a</xsl:text>
438 <xsl:call-template name="capitalize">
439 <xsl:with-param name="str" select="@array"/>
440 </xsl:call-template>
441 <xsl:text>)</xsl:text>
442 </xsl:when>
443 <xsl:otherwise>
444 <xsl:message terminate="yes">
445 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
446 <xsl:text>array attribute refers to non-existent param: </xsl:text>
447 <xsl:value-of select="@array"/>
448 </xsl:message>
449 </xsl:otherwise>
450 </xsl:choose>
451 </xsl:if>
452 <xsl:text>] </xsl:text>
453 <xsl:if test="@safearray='yes'">
454 <xsl:text>SAFEARRAY(</xsl:text>
455 </xsl:if>
456 <xsl:apply-templates select="@type"/>
457 <xsl:if test="@safearray='yes'">
458 <xsl:text>)</xsl:text>
459 </xsl:if>
460 <xsl:if test="@array">
461 <xsl:text> *</xsl:text>
462 </xsl:if>
463 <xsl:if test="@dir='out' or @dir='return' or @safearray='yes'">
464 <xsl:text> *</xsl:text>
465 </xsl:if>
466 <xsl:text> a</xsl:text>
467 <xsl:call-template name="capitalize">
468 <xsl:with-param name="str" select="@name"/>
469 </xsl:call-template>
470</xsl:template>
471
472
473<!--
474 * attribute/parameter type conversion
475-->
476<xsl:template match="
477 attribute/@type | param/@type |
478 enumerator/@type | collection/@type | collection/@enumerator
479">
480 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
481
482 <xsl:if test="../@array and ../@safearray='yes'">
483 <xsl:message terminate="yes">
484 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
485 <xsl:text>either 'array' or 'safearray="yes"' attribute is allowed, but not both!</xsl:text>
486 </xsl:message>
487 </xsl:if>
488
489 <xsl:choose>
490 <!-- modifiers (ignored for 'enumeration' attributes)-->
491 <xsl:when test="name(current())='type' and ../@mod">
492 <xsl:choose>
493 <xsl:when test="../@mod='ptr'">
494 <xsl:choose>
495 <!-- standard types -->
496 <!--xsl:when test=".='result'">??</xsl:when-->
497 <xsl:when test=".='boolean'">BOOL *</xsl:when>
498 <xsl:when test=".='octet'">BYTE *</xsl:when>
499 <xsl:when test=".='short'">SHORT *</xsl:when>
500 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
501 <xsl:when test=".='long'">LONG *</xsl:when>
502 <xsl:when test=".='long long'">LONG64 *</xsl:when>
503 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
504 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
505 <xsl:when test=".='char'">CHAR *</xsl:when>
506 <!--xsl:when test=".='string'">??</xsl:when-->
507 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
508 <!--xsl:when test=".='wstring'">??</xsl:when-->
509 <xsl:otherwise>
510 <xsl:message terminate="yes">
511 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
512 <xsl:text>attribute 'mod=</xsl:text>
513 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
514 <xsl:text>' cannot be used with type </xsl:text>
515 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
516 </xsl:message>
517 </xsl:otherwise>
518 </xsl:choose>
519 </xsl:when>
520 <xsl:otherwise>
521 <xsl:message terminate="yes">
522 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
523 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
524 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
525 </xsl:message>
526 </xsl:otherwise>
527 </xsl:choose>
528 </xsl:when>
529 <!-- no modifiers -->
530 <xsl:otherwise>
531 <xsl:choose>
532 <!-- standard types -->
533 <xsl:when test=".='result'">HRESULT</xsl:when>
534 <xsl:when test=".='boolean'">BOOL</xsl:when>
535 <xsl:when test=".='octet'">BYTE</xsl:when>
536 <xsl:when test=".='short'">SHORT</xsl:when>
537 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
538 <xsl:when test=".='long'">LONG</xsl:when>
539 <xsl:when test=".='long long'">LONG64</xsl:when>
540 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
541 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
542 <xsl:when test=".='char'">CHAR</xsl:when>
543 <xsl:when test=".='string'">CHAR *</xsl:when>
544 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
545 <xsl:when test=".='wstring'">BSTR</xsl:when>
546 <!-- UUID type -->
547 <xsl:when test=".='uuid'">GUID</xsl:when>
548 <!-- system interface types -->
549 <xsl:when test=".='$unknown'">IUnknown *</xsl:when>
550 <xsl:otherwise>
551 <xsl:choose>
552 <!-- enum types -->
553 <xsl:when test="
554 (ancestor::library/enum[@name=current()]) or
555 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
556 ">
557 <xsl:value-of select="."/>
558 </xsl:when>
559 <!-- custom interface types -->
560 <xsl:when test="
561 (name(current())='enumerator' and
562 ((ancestor::library/enumerator[@name=current()]) or
563 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
564 ) or
565 ((ancestor::library/interface[@name=current()]) or
566 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
567 ) or
568 ((ancestor::library/collection[@name=current()]) or
569 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
570 )
571 ">
572 <xsl:value-of select="."/><xsl:text> *</xsl:text>
573 </xsl:when>
574 <!-- other types -->
575 <xsl:otherwise>
576 <xsl:message terminate="yes">
577 <xsl:text>Unknown parameter type: </xsl:text>
578 <xsl:value-of select="."/>
579 </xsl:message>
580 </xsl:otherwise>
581 </xsl:choose>
582 </xsl:otherwise>
583 </xsl:choose>
584 </xsl:otherwise>
585 </xsl:choose>
586</xsl:template>
587
588</xsl:stylesheet>
589
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