VirtualBox

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

Last change on this file since 2988 was 2988, checked in by vboxsync, 18 years ago

InnoTek -> innotek part 4: more miscellaneous files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 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 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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.
81 *
82 * This IDL is automatically generated from the generic interface definition
83 * using MS IDL (MIDL) syntax.
84 */
85 </xsl:text>
86 <xsl:text>&#x0A;</xsl:text>
87 <xsl:text>import "unknwn.idl";&#x0A;&#x0A;</xsl:text>
88 <xsl:apply-templates/>
89</xsl:template>
90
91
92<!--
93 * ignore all |if|s except those for MIDL target
94-->
95<xsl:template match="if">
96 <xsl:if test="@target='midl'">
97 <xsl:apply-templates/>
98 </xsl:if>
99</xsl:template>
100<xsl:template match="if" mode="forward">
101 <xsl:if test="@target='midl'">
102 <xsl:apply-templates mode="forward"/>
103 </xsl:if>
104</xsl:template>
105
106
107<!--
108 * cpp_quote
109-->
110<xsl:template match="cpp">
111 <xsl:text>cpp_quote("</xsl:text>
112 <xsl:value-of select="@line"/>
113 <xsl:text>")&#x0A;&#x0A;</xsl:text>
114</xsl:template>
115
116
117<!--
118 * #if statement (@if attribute)
119-->
120<xsl:template match="@if" mode="begin">
121 <xsl:text>#if </xsl:text>
122 <xsl:value-of select="."/>
123 <xsl:text>&#x0A;</xsl:text>
124</xsl:template>
125<xsl:template match="@if" mode="end">
126 <xsl:text>#endif&#x0A;</xsl:text>
127</xsl:template>
128
129
130<!--
131 * libraries
132-->
133<xsl:template match="module">[
134 uuid(<xsl:value-of select="@uuid"/>),
135 version(<xsl:value-of select="@version"/>),
136 helpstring("<xsl:value-of select="@desc"/>")
137]
138<xsl:text>library </xsl:text>
139 <xsl:value-of select="@name"/>
140 <xsl:text>&#x0A;{&#x0A;</xsl:text>
141 <xsl:text>&#x0A;importlib("stdole2.tlb");&#x0A;&#x0A;</xsl:text>
142 <!-- forward declarations -->
143 <xsl:apply-templates select="if | interface | collection | enumerator" mode="forward"/>
144 <xsl:text>&#x0A;</xsl:text>
145 <!-- all enums go first -->
146 <xsl:apply-templates select="enum | if/enum"/>
147 <!-- everything else but enums -->
148 <xsl:apply-templates select="*[not(self::enum) and not(self::if[enum])]"/>
149 <!-- -->
150 <xsl:text>}; /* library </xsl:text>
151 <xsl:value-of select="@name"/>
152 <xsl:text> */&#x0A;&#x0A;</xsl:text>
153</xsl:template>
154
155
156<!--
157 * forward declarations
158-->
159<xsl:template match="interface | collection | enumerator" mode="forward">
160 <xsl:text>interface </xsl:text>
161 <xsl:value-of select="@name"/>
162 <xsl:text>;&#x0A;</xsl:text>
163</xsl:template>
164
165
166<!--
167 * interfaces
168-->
169<xsl:template match="interface">[
170 uuid(<xsl:value-of select="@uuid"/>),
171 object,
172 dual
173]
174<xsl:text>interface </xsl:text>
175 <xsl:value-of select="@name"/>
176 <xsl:text> : </xsl:text>
177 <xsl:choose>
178 <xsl:when test="@extends='$unknown'">IUnknown</xsl:when>
179 <xsl:when test="@extends='$dispatched'">IDispatch</xsl:when>
180 <xsl:when test="@extends='$errorinfo'">IErrorInfo</xsl:when>
181 <xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
182 </xsl:choose>
183 <xsl:text>&#x0A;{&#x0A;</xsl:text>
184 <!-- attributes (properties) -->
185 <xsl:apply-templates select="attribute"/>
186 <!-- methods -->
187 <xsl:apply-templates select="method"/>
188 <!-- 'if' enclosed elements, unsorted -->
189 <xsl:apply-templates select="if"/>
190 <!-- -->
191 <xsl:text>}; /* interface </xsl:text>
192 <xsl:value-of select="@name"/>
193 <xsl:text> */&#x0A;&#x0A;</xsl:text>
194</xsl:template>
195
196
197<!--
198 * attributes
199-->
200<xsl:template match="interface//attribute | collection//attribute">
201 <xsl:apply-templates select="@if" mode="begin"/>
202 <xsl:text> [propget] HRESULT </xsl:text>
203 <xsl:call-template name="capitalize">
204 <xsl:with-param name="str" select="@name"/>
205 </xsl:call-template>
206 <xsl:text> ([out, retval] </xsl:text>
207 <xsl:apply-templates select="@type"/>
208 <xsl:text> * a</xsl:text>
209 <xsl:call-template name="capitalize">
210 <xsl:with-param name="str" select="@name"/>
211 </xsl:call-template>
212 <xsl:text>);&#x0A;</xsl:text>
213 <xsl:if test="not(@readonly='yes')">
214 <xsl:text> [propput] HRESULT </xsl:text>
215 <xsl:call-template name="capitalize">
216 <xsl:with-param name="str" select="@name"/>
217 </xsl:call-template>
218 <xsl:text> ([in] </xsl:text>
219 <xsl:apply-templates select="@type"/>
220 <xsl:text> a</xsl:text>
221 <xsl:call-template name="capitalize">
222 <xsl:with-param name="str" select="@name"/>
223 </xsl:call-template>
224 <xsl:text>);&#x0A;</xsl:text>
225 </xsl:if>
226 <xsl:apply-templates select="@if" mode="end"/>
227 <xsl:text>&#x0A;</xsl:text>
228</xsl:template>
229
230
231<!--
232 * methods
233-->
234<xsl:template match="interface//method | collection//method">
235 <xsl:apply-templates select="@if" mode="begin"/>
236 <xsl:text> HRESULT </xsl:text>
237 <xsl:call-template name="capitalize">
238 <xsl:with-param name="str" select="@name"/>
239 </xsl:call-template>
240 <xsl:if test="param">
241 <xsl:text> (&#x0A;</xsl:text>
242 <xsl:for-each select="param [position() != last()]">
243 <xsl:text> </xsl:text>
244 <xsl:apply-templates select="."/>
245 <xsl:text>,&#x0A;</xsl:text>
246 </xsl:for-each>
247 <xsl:text> </xsl:text>
248 <xsl:apply-templates select="param [last()]"/>
249 <xsl:text>&#x0A; );&#x0A;</xsl:text>
250 </xsl:if>
251 <xsl:if test="not(param)">
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 * co-classes
261-->
262<xsl:template match="class">[
263 uuid(<xsl:value-of select="@uuid"/>)
264]
265<xsl:text>coclass </xsl:text>
266 <xsl:value-of select="@name"/>
267 <xsl:text>&#x0A;{&#x0A;</xsl:text>
268 <xsl:for-each select="interface">
269 <xsl:text> </xsl:text>
270 <xsl:if test="@default='yes'">
271 <xsl:text>[default] </xsl:text>
272 </xsl:if>
273 <xsl:text>interface </xsl:text>
274 <xsl:value-of select="@name"/>
275 <xsl:text>;&#x0A;</xsl:text>
276 </xsl:for-each>
277 <xsl:text>&#x0A;}; /* coclass </xsl:text>
278 <xsl:value-of select="@name"/>
279 <xsl:text> */&#x0A;&#x0A;</xsl:text>
280</xsl:template>
281
282
283<!--
284 * enumerators
285-->
286<xsl:template match="enumerator">[
287 uuid(<xsl:value-of select="@uuid"/>),
288 object,
289 dual
290]
291<xsl:text>interface </xsl:text>
292 <xsl:value-of select="@name"/>
293 <xsl:text> : IUnknown&#x0A;{&#x0A;</xsl:text>
294 <!-- HasMore -->
295 <xsl:text> HRESULT HasMore ([out, retval] BOOL * more);&#x0A;&#x0A;</xsl:text>
296 <!-- GetNext -->
297 <xsl:text> HRESULT GetNext ([out, retval] </xsl:text>
298 <xsl:apply-templates select="@type"/>
299 <xsl:text> * next);&#x0A;&#x0A;</xsl:text>
300 <!-- -->
301 <xsl:text>&#x0A;}; /* interface </xsl:text>
302 <xsl:value-of select="@name"/>
303 <xsl:text> */&#x0A;&#x0A;</xsl:text>
304</xsl:template>
305
306
307<!--
308 * collections
309-->
310<xsl:template match="collection">
311 <xsl:if test="not(@readonly='yes')">
312 <xsl:message terminate="yes">
313 <xsl:value-of select="concat(@name,': ')"/>
314 <xsl:text>non-readonly collections are not currently supported</xsl:text>
315 </xsl:message>
316 </xsl:if>[
317 uuid(<xsl:value-of select="@uuid"/>),
318 object,
319 dual
320]
321<xsl:text>interface </xsl:text>
322 <xsl:value-of select="@name"/>
323 <xsl:text> : IUnknown&#x0A;{&#x0A;</xsl:text>
324 <!-- Count -->
325 <xsl:text> [propget] HRESULT Count ([out, retval] ULONG * count);&#x0A;&#x0A;</xsl:text>
326 <!-- GetItemAt -->
327 <xsl:text> HRESULT GetItemAt ([in] ULONG index, [out, retval] </xsl:text>
328 <xsl:apply-templates select="@type"/>
329 <xsl:text> * item);&#x0A;&#x0A;</xsl:text>
330 <!-- Enumerate -->
331 <xsl:text> HRESULT Enumerate ([out, retval] </xsl:text>
332 <xsl:apply-templates select="@enumerator"/>
333 <xsl:text> * enumerator);&#x0A;&#x0A;</xsl:text>
334 <!-- other extra attributes (properties) -->
335 <xsl:apply-templates select="attribute"/>
336 <!-- other extra methods -->
337 <xsl:apply-templates select="method"/>
338 <!-- 'if' enclosed elements, unsorted -->
339 <xsl:apply-templates select="if"/>
340 <!-- -->
341 <xsl:text>&#x0A;}; /* interface </xsl:text>
342 <xsl:value-of select="@name"/>
343 <xsl:text> */&#x0A;&#x0A;</xsl:text>
344</xsl:template>
345
346
347<!--
348 * enums
349-->
350<xsl:template match="enum">[
351 uuid(<xsl:value-of select="@uuid"/>),
352 v1_enum
353]
354<xsl:text>typedef enum &#x0A;{&#x0A;</xsl:text>
355 <xsl:for-each select="const">
356 <xsl:text> </xsl:text>
357 <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>
358 <xsl:choose>
359 <xsl:when test="position()!=last()"><xsl:text>,&#x0A;</xsl:text></xsl:when>
360 <xsl:otherwise><xsl:text>&#x0A;</xsl:text></xsl:otherwise>
361 </xsl:choose>
362 </xsl:for-each>
363 <xsl:text>} </xsl:text>
364 <xsl:value-of select="@name"/>
365 <xsl:text>;&#x0A;&#x0A;</xsl:text>
366 <!-- -->
367 <xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */&#x0A;')"/>
368 <xsl:value-of select="concat('cpp_quote(&quot;#define ', @name, '_T', ' ',
369 @name, '&quot;)&#x0A;&#x0A;')"/>
370 <xsl:text>cpp_quote("")&#x0A;</xsl:text>
371 <!-- -->
372 <xsl:value-of select="concat('/* cross-platform constants for ', @name, ' */&#x0A;')"/>
373 <xsl:for-each select="const">
374 <xsl:value-of select="concat('cpp_quote(&quot;#define ', ../@name, '_', @name, ' ',
375 @name, '&quot;)&#x0A;')"/>
376 <xsl:choose>
377 <xsl:when test="position()=last()"><xsl:text>cpp_quote("")&#x0A;</xsl:text></xsl:when>
378 </xsl:choose>
379 </xsl:for-each>
380 <xsl:text>&#x0A;&#x0A;</xsl:text>
381</xsl:template>
382
383
384<!--
385 * method parameters
386-->
387<xsl:template match="method/param">
388 <xsl:text>[</xsl:text>
389 <xsl:choose>
390 <xsl:when test="@dir='in'">in</xsl:when>
391 <xsl:when test="@dir='out'">out</xsl:when>
392 <xsl:when test="@dir='return'">out, retval</xsl:when>
393 <xsl:otherwise>in</xsl:otherwise>
394 </xsl:choose>
395 <xsl:if test="@array">
396 <xsl:if test="@dir='return'">
397 <xsl:message terminate="yes">
398 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
399 <xsl:text>return array parameters are not currently supported</xsl:text>
400 </xsl:message>
401 </xsl:if>
402 <xsl:choose>
403 <xsl:when test="../param[@name=current()/@array]">
404 <xsl:if test="../param[@name=current()/@array]/@dir != @dir">
405 <xsl:message terminate="yes">
406 <xsl:value-of select="concat(../../@name,'::',../@name,': ')"/>
407 <xsl:value-of select="concat(@name,' and ',../param[@name=current()/@array]/@name)"/>
408 <xsl:text> must have the same direction</xsl:text>
409 </xsl:message>
410 </xsl:if>
411 <xsl:text>, size_is(</xsl:text>
412 <xsl:if test="@dir='out'">
413 <xsl:text>, </xsl:text>
414 </xsl:if>
415 <xsl:if test="../param[@name=current()/@array]/@dir='out'">
416 <xsl:text>*</xsl:text>
417 </xsl:if>
418 <!--xsl:value-of select="@array"/-->
419 <xsl:text>a</xsl:text>
420 <xsl:call-template name="capitalize">
421 <xsl:with-param name="str" select="@array"/>
422 </xsl:call-template>
423 <xsl:text>)</xsl:text>
424 </xsl:when>
425 <xsl:otherwise>
426 <xsl:message terminate="yes">
427 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
428 <xsl:text>array attribute refers to non-existent param: </xsl:text>
429 <xsl:value-of select="@array"/>
430 </xsl:message>
431 </xsl:otherwise>
432 </xsl:choose>
433 </xsl:if>
434 <xsl:text>] </xsl:text>
435 <xsl:apply-templates select="@type"/>
436 <xsl:text> </xsl:text>
437 <xsl:if test="@array">
438 <xsl:text>* </xsl:text>
439 </xsl:if>
440 <xsl:if test="@dir='out' or @dir='return'">
441 <xsl:text>* </xsl:text>
442 </xsl:if>
443 <!--xsl:value-of select="@name"/-->
444 <xsl:text>a</xsl:text>
445 <xsl:call-template name="capitalize">
446 <xsl:with-param name="str" select="@name"/>
447 </xsl:call-template>
448</xsl:template>
449
450
451<!--
452 * attribute/parameter type conversion
453-->
454<xsl:template match="
455 attribute/@type | param/@type |
456 enumerator/@type | collection/@type | collection/@enumerator
457">
458 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
459
460 <xsl:choose>
461 <!-- modifiers (ignored for 'enumeration' attributes)-->
462 <xsl:when test="name(current())='type' and ../@mod">
463 <xsl:if test="../@array">
464 <xsl:message terminate="yes">
465 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
466 <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
467 </xsl:message>
468 </xsl:if>
469 <xsl:choose>
470 <xsl:when test="../@mod='ptr'">
471 <xsl:choose>
472 <!-- standard types -->
473 <!--xsl:when test=".='result'">??</xsl:when-->
474 <xsl:when test=".='boolean'">BOOL *</xsl:when>
475 <xsl:when test=".='octet'">BYTE *</xsl:when>
476 <xsl:when test=".='short'">SHORT *</xsl:when>
477 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
478 <xsl:when test=".='long'">LONG *</xsl:when>
479 <xsl:when test=".='long long'">LONG64 *</xsl:when>
480 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
481 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
482 <xsl:when test=".='char'">CHAR *</xsl:when>
483 <!--xsl:when test=".='string'">??</xsl:when-->
484 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
485 <!--xsl:when test=".='wstring'">??</xsl:when-->
486 <xsl:otherwise>
487 <xsl:message terminate="yes">
488 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
489 <xsl:text>attribute 'mod=</xsl:text>
490 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
491 <xsl:text>' cannot be used with type </xsl:text>
492 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
493 </xsl:message>
494 </xsl:otherwise>
495 </xsl:choose>
496 </xsl:when>
497 <xsl:otherwise>
498 <xsl:message terminate="yes">
499 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
500 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
501 <xsl:text>of attibute 'mod' is invalid!</xsl:text>
502 </xsl:message>
503 </xsl:otherwise>
504 </xsl:choose>
505 </xsl:when>
506 <!-- no modifiers -->
507 <xsl:otherwise>
508 <xsl:choose>
509 <!-- standard types -->
510 <xsl:when test=".='result'">HRESULT</xsl:when>
511 <xsl:when test=".='boolean'">BOOL</xsl:when>
512 <xsl:when test=".='octet'">BYTE</xsl:when>
513 <xsl:when test=".='short'">SHORT</xsl:when>
514 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
515 <xsl:when test=".='long'">LONG</xsl:when>
516 <xsl:when test=".='long long'">LONG64</xsl:when>
517 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
518 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
519 <xsl:when test=".='char'">CHAR</xsl:when>
520 <xsl:when test=".='string'">CHAR *</xsl:when>
521 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
522 <xsl:when test=".='wstring'">BSTR</xsl:when>
523 <!-- UUID type -->
524 <xsl:when test=".='uuid'">GUID</xsl:when>
525 <!-- system interface types -->
526 <xsl:when test=".='$unknown'">IUnknown *</xsl:when>
527 <xsl:otherwise>
528 <xsl:choose>
529 <!-- enum types -->
530 <xsl:when test="
531 (ancestor::module/enum[@name=current()]) or
532 (ancestor::module/if[@target=$self_target]/enum[@name=current()])
533 ">
534 <xsl:value-of select="."/>
535 </xsl:when>
536 <!-- custom interface types -->
537 <xsl:when test="
538 (name(current())='enumerator' and
539 ((ancestor::module/enumerator[@name=current()]) or
540 (ancestor::module/if[@target=$self_target]/enumerator[@name=current()]))
541 ) or
542 ((ancestor::module/interface[@name=current()]) or
543 (ancestor::module/if[@target=$self_target]/interface[@name=current()])
544 ) or
545 ((ancestor::module/collection[@name=current()]) or
546 (ancestor::module/if[@target=$self_target]/collection[@name=current()])
547 )
548 ">
549 <xsl:value-of select="."/><xsl:text> *</xsl:text>
550 </xsl:when>
551 <!-- other types -->
552 <xsl:otherwise>
553 <xsl:message terminate="yes">
554 <xsl:text>Unknown parameter type: </xsl:text>
555 <xsl:value-of select="."/>
556 </xsl:message>
557 </xsl:otherwise>
558 </xsl:choose>
559 </xsl:otherwise>
560 </xsl:choose>
561 </xsl:otherwise>
562 </xsl:choose>
563</xsl:template>
564
565</xsl:stylesheet>
566
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