VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/COMWrappers.xsl@ 1467

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

FE/Qt: Cosmetic refactoring.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.6 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4/*
5 * A template to generate wrapper classes for [XP]COM interfaces (defined
6 * in XIDL) to use them in the main Qt-based GUI in platform-independent
7 * script-like manner.
8 *
9 * The generated header requires COMDefs.h and must be included from there.
10 */
11
12/*
13 * Copyright (C) 2006 InnoTek Systemberatung GmbH
14 *
15 * This file is part of VirtualBox Open Source Edition (OSE), as
16 * available from http://www.virtualbox.org. This file is free software;
17 * you can redistribute it and/or modify it under the terms of the GNU
18 * General Public License as published by the Free Software Foundation,
19 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
20 * distribution. VirtualBox OSE is distributed in the hope that it will
21 * be useful, but WITHOUT ANY WARRANTY of any kind.
22 *
23 * If you received this file as part of a commercial VirtualBox
24 * distribution, then only the terms of your commercial VirtualBox
25 * license agreement apply instead of the previous paragraph.
26 */
27-->
28
29<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
30<xsl:output method="text"/>
31
32<xsl:strip-space elements="*"/>
33
34
35<!--
36// helper definitions
37/////////////////////////////////////////////////////////////////////////////
38-->
39
40<!--
41 * capitalizes the first letter
42-->
43<xsl:template name="capitalize">
44 <xsl:param name="str" select="."/>
45 <xsl:value-of select="
46 concat(
47 translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
48 substring($str,2)
49 )
50 "/>
51</xsl:template>
52
53<!--
54 * uncapitalizes the first letter only if the second one is not capital
55 * otherwise leaves the string unchanged
56-->
57<xsl:template name="uncapitalize">
58 <xsl:param name="str" select="."/>
59 <xsl:choose>
60 <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring($str,2,1)))">
61 <xsl:value-of select="
62 concat(
63 translate(substring($str,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
64 substring($str,2)
65 )
66 "/>
67 </xsl:when>
68 <xsl:otherwise>
69 <xsl:value-of select="string($str)"/>
70 </xsl:otherwise>
71 </xsl:choose>
72</xsl:template>
73
74<!--
75 * translates the string to uppercase
76-->
77<xsl:template name="uppercase">
78 <xsl:param name="str" select="."/>
79 <xsl:value-of select="
80 translate($str,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
81 "/>
82</xsl:template>
83
84
85<!--
86// templates
87/////////////////////////////////////////////////////////////////////////////
88-->
89
90
91<!--
92 * shut down all implicit templates
93-->
94<xsl:template match="*"/>
95<xsl:template match="*|/" mode="declare"/>
96<xsl:template match="*|/" mode="define"/>
97<xsl:template match="*|/" mode="end"/>
98<xsl:template match="*|/" mode="begin"/>
99
100
101<!--
102 * header
103-->
104<xsl:template match="/idl">
105
106<xsl:text>
107/*
108 * DO NOT EDIT.
109 *
110 * This header is automatically generated from the generic interface definition
111 * and contains Qt-based wrapper classes for [XP]COM interfaces.
112 *
113 * Note: this header must be included from COMDefs.h, never directly.
114 */
115</xsl:text>
116
117 <!-- all enum declarations as a single class -->
118<xsl:text>
119// all enums
120
121class CEnums
122{
123public:
124
125</xsl:text>
126 <xsl:for-each select="*/enum">
127 <xsl:text> enum </xsl:text>
128 <xsl:value-of select="@name"/>
129 <xsl:text> {&#x0A;</xsl:text>
130 <xsl:for-each select="const">
131 <xsl:text> </xsl:text>
132 <xsl:value-of select="@name"/>
133 <xsl:text> = ::</xsl:text>
134 <xsl:value-of select="parent::node()/@name"/>
135 <xsl:text>_</xsl:text>
136 <xsl:value-of select="@name"/>
137 <xsl:text>,&#x0A;</xsl:text>
138 </xsl:for-each>
139 <xsl:text> </xsl:text>
140 <xsl:value-of select="@name"/>
141 <xsl:text>_COUNT&#x0A;</xsl:text>
142 <xsl:text> };&#x0A;&#x0A;</xsl:text>
143 </xsl:for-each>
144 <xsl:text>};&#x0A;&#x0A;</xsl:text>
145
146 <xsl:apply-templates/>
147
148</xsl:template>
149
150
151<!--
152 * encloses |if| element's contents (unconditionally expanded by
153 * <apply-templates mode="define"/>) with #ifdef / #endif.
154 *
155 * @note this can produce an empty #if/#endif block if |if|'s children
156 * expand to nothing (such as |cpp|). I see no need to handle this situation
157 * specially.
158-->
159<xsl:template match="if" mode="define">
160 <xsl:apply-templates select="." mode="begin"/>
161 <xsl:apply-templates mode="define"/>
162 <xsl:apply-templates select="." mode="end"/>
163 <xsl:text>&#x0A;</xsl:text>
164</xsl:template>
165
166
167<!--
168 * encloses |if| element's contents (unconditionally expanded by
169 * <apply-templates mode="declare"/>) with #ifdef / #endif.
170 *
171 * @note this can produce an empty #if/#endif block if |if|'s children
172 * expand to nothing (such as |cpp|). I see no need to handle this situation
173 * specially.
174-->
175<xsl:template match="if" mode="declare">
176 <xsl:apply-templates select="." mode="begin"/>
177 <xsl:apply-templates mode="declare"/>
178 <xsl:apply-templates select="." mode="end"/>
179 <xsl:text>&#x0A;</xsl:text>
180</xsl:template>
181
182
183<!--
184 * |<if target="...">| element): begin and end.
185-->
186<xsl:template match="if" mode="begin">
187 <xsl:if test="@target='xpidl'">
188 <xsl:text>#if !defined (Q_WS_WIN32)&#x0A;</xsl:text>
189 </xsl:if>
190 <xsl:if test="@target='midl'">
191 <xsl:text>#if defined (Q_WS_WIN32)&#x0A;</xsl:text>
192 </xsl:if>
193</xsl:template>
194<xsl:template match="if" mode="end">
195 <xsl:text>#endif&#x0A;</xsl:text>
196</xsl:template>
197
198
199<!--
200 * cpp_quote
201-->
202<xsl:template match="cpp"/>
203
204
205<!--
206 * #ifdef statement (@if attribute): begin and end
207-->
208<xsl:template match="@if" mode="begin">
209 <xsl:text>#if </xsl:text>
210 <xsl:value-of select="."/>
211 <xsl:text>&#x0A;</xsl:text>
212</xsl:template>
213<xsl:template match="@if" mode="end">
214 <xsl:text>#endif&#x0A;</xsl:text>
215</xsl:template>
216
217
218<!--
219 * libraries
220-->
221<xsl:template match="module">
222 <!-- forward declarations -->
223 <xsl:text>// forward declarations&#x0A;&#x0A;</xsl:text>
224 <xsl:for-each select="interface | collection | enumerator">
225 <xsl:text>class C</xsl:text>
226 <xsl:value-of select="substring(@name,2)"/>
227 <xsl:text>;&#x0A;</xsl:text>
228 </xsl:for-each>
229 <xsl:text>&#x0A;</xsl:text>
230 <!-- wrapper declarations -->
231 <xsl:text>// wrapper declarations&#x0A;&#x0A;</xsl:text>
232 <xsl:apply-templates select="
233 if |
234 interface[not(@internal='yes')] |
235 collection[not(@internal='yes')] |
236 enumerator[not(@internal='yes')]
237 "
238 mode="declare"
239 />
240 <!-- wrapper definitions -->
241 <xsl:text>// wrapper definitions&#x0A;&#x0A;</xsl:text>
242 <xsl:apply-templates select="
243 if |
244 interface[not(@internal='yes')] |
245 collection[not(@internal='yes')] |
246 enumerator[not(@internal='yes')]
247 "
248 mode="define"
249 />
250</xsl:template>
251
252
253<!--
254 * interface declarations
255-->
256<xsl:template match="interface | collection | enumerator" mode="declare">
257
258 <xsl:text>// </xsl:text>
259 <xsl:value-of select="@name"/>
260 <xsl:text> wrapper&#x0A;&#x0A;class C</xsl:text>
261 <xsl:value-of select="substring(@name,2)"/>
262 <xsl:text> : public CInterface &lt;</xsl:text>
263 <xsl:value-of select="@name"/>
264 <!-- use the correct base if supportsErrorInfo -->
265 <xsl:call-template name="tryComposeFetchErrorInfo">
266 <xsl:with-param name="mode" select="'getBaseClassName'"/>
267 </xsl:call-template>
268 <xsl:text>&gt;&#x0A;{&#x0A;public:&#x0A;&#x0A;</xsl:text>
269
270 <!-- generate the Base typedef-->
271 <xsl:text> typedef CInterface &lt;</xsl:text>
272 <xsl:value-of select="@name"/>
273 <!-- Use the correct base if supportsErrorInfo -->
274 <xsl:call-template name="tryComposeFetchErrorInfo">
275 <xsl:with-param name="mode" select="'getBaseClassName'"/>
276 </xsl:call-template>
277 <xsl:text>&gt; Base;&#x0A;&#x0A;</xsl:text>
278
279 <xsl:if test="name()='collection'">
280 <xsl:text> // collection stuff&#x0A;&#x0A;</xsl:text>
281 <xsl:text> ULONG GetCount () const;&#x0A;</xsl:text>
282 <xsl:text> </xsl:text>
283 <xsl:apply-templates select="@type"/>
284 <xsl:text> GetItemAt (ULONG index) const;&#x0A;</xsl:text>
285 <xsl:text> </xsl:text>
286 <xsl:apply-templates select="@enumerator"/>
287 <xsl:text> Enumerate () const;&#x0A;&#x0A;</xsl:text>
288 </xsl:if>
289
290 <xsl:if test="name()='enumerator'">
291 <xsl:text> // enumerator stuff&#x0A;&#x0A;</xsl:text>
292 <xsl:text> BOOL HasMore () const;&#x0A;</xsl:text>
293 <xsl:text> </xsl:text>
294 <xsl:apply-templates select="@type"/>
295 <xsl:text> GetNext () const;&#x0A;&#x0A;</xsl:text>
296 <xsl:text> // friend wrappers&#x0A;&#x0A;</xsl:text>
297 <xsl:text> friend class CUnknown;&#x0A;</xsl:text>
298 <xsl:variable name="name" select="@name"/>
299 <xsl:variable name="parent" select=".."/>
300 <!-- for definitions inside <if> -->
301 <xsl:if test="name(..)='if'">
302 <xsl:for-each select="
303 preceding-sibling::collection | following-sibling::collection |
304 ../preceding-sibling::if[@target=$parent/@target]/collection |
305 ../following-sibling::if[@target=$parent/@target]/collection
306 ">
307 <xsl:if test="@enumerator=$name">
308 <xsl:text> friend class C</xsl:text>
309 <xsl:value-of select="substring(@name,2)"/>
310 <xsl:text>;&#x0A;</xsl:text>
311 </xsl:if>
312 </xsl:for-each>
313 </xsl:if>
314 <!-- for definitions outside <if> (i.e. inside <module>) -->
315 <xsl:if test="name(..)!='if'">
316 <xsl:for-each select="
317 preceding-sibling::collection | following-sibling::collection
318 ">
319 <xsl:if test="@enumerator=$name">
320 <xsl:text> friend class C</xsl:text>
321 <xsl:value-of select="substring(@name,2)"/>
322 <xsl:text>;&#x0A;</xsl:text>
323 </xsl:if>
324 </xsl:for-each>
325 </xsl:if>
326 </xsl:if>
327
328 <xsl:if test="name()='interface' or name()='collection'">
329 <xsl:call-template name="declareMembers"/>
330 </xsl:if>
331
332 <xsl:text>};&#x0A;&#x0A;</xsl:text>
333
334</xsl:template>
335
336<xsl:template name="declareMembers">
337
338 <xsl:text> // constructors and assignments taking CUnknown and </xsl:text>
339 <xsl:text>raw iface pointer&#x0A;&#x0A;</xsl:text>
340 <!-- default constructor -->
341 <xsl:text> C</xsl:text>
342 <xsl:value-of select="substring(@name,2)"/>
343 <xsl:text> () : Base () {}&#x0A;</xsl:text>
344 <!-- constructor taking CUnknown -->
345 <xsl:text> C</xsl:text>
346 <xsl:value-of select="substring(@name,2)"/>
347 <xsl:text> (const CUnknown &amp; that) : Base (that) {}&#x0A;</xsl:text>
348 <!-- constructor taking raw iface pointer -->
349 <xsl:text> C</xsl:text>
350 <xsl:value-of select="substring(@name,2)"/>
351 <xsl:text> (</xsl:text>
352 <xsl:value-of select="@name"/>
353 <xsl:text> *i) : Base (i) {}&#x0A;</xsl:text>
354 <!-- assignment taking CUnknown -->
355 <xsl:text> C</xsl:text>
356 <xsl:value-of select="substring(@name,2)"/>
357 <xsl:text> &amp; operator = (const CUnknown &amp; that) {&#x0A; return (C</xsl:text>
358 <xsl:value-of select="substring(@name,2)"/>
359 <xsl:text> &amp;) Base::operator = (that);&#x0A; }&#x0A;&#x0A;</xsl:text>
360
361 <xsl:text> // attributes (properties)&#x0A;&#x0A;</xsl:text>
362 <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="declare"/>
363 <xsl:if test=".//attribute[not(@internal='yes')]">
364 <xsl:text>&#x0A;</xsl:text>
365 </xsl:if>
366
367 <xsl:text> // methods&#x0A;&#x0A;</xsl:text>
368 <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="declare"/>
369 <xsl:if test=".//method[not(@internal='yes')]">
370 <xsl:text>&#x0A;</xsl:text>
371 </xsl:if>
372
373 <xsl:text> // friend wrappers&#x0A;&#x0A;</xsl:text>
374 <xsl:text> friend class CUnknown;&#x0A;</xsl:text>
375 <xsl:variable name="name" select="@name"/>
376 <xsl:variable name="parent" select=".."/>
377 <!-- for definitions inside <if> -->
378 <xsl:if test="name(..)='if'">
379 <xsl:for-each select="
380 preceding-sibling::*[self::interface or self::collection or self::enumerator] |
381 following-sibling::*[self::interface or self::collection or self::enumerator] |
382 ../preceding-sibling::*[self::interface or self::collection or self::enumerator] |
383 ../following-sibling::*[self::interface or self::collection or self::enumerator] |
384 ../preceding-sibling::if[@target=$parent/@target]/*[self::interface or self::collection or self::enumerator] |
385 ../following-sibling::if[@target=$parent/@target]/*[self::interface or self::collection or self::enumerator]
386 ">
387 <xsl:if test="
388 ((name()='interface' or name()='collection')
389 and
390 ((name(..)!='if' and (if[@target=$parent/@target]/method/param[@type=$name]
391 or
392 if[@target=$parent/@target]/attribute[@type=$name]))
393 or
394 (.//method/param[@type=$name] or attribute[@type=$name])))
395 or
396 (name(..)='if' and (name()='collection' or name()='enumerator') and @type=$name)
397 ">
398 <xsl:text> friend class C</xsl:text>
399 <xsl:value-of select="substring(@name,2)"/>
400 <xsl:text>;&#x0A;</xsl:text>
401 </xsl:if>
402 </xsl:for-each>
403 </xsl:if>
404 <!-- for definitions outside <if> (i.e. inside <module>) -->
405 <xsl:if test="name(..)!='if'">
406 <xsl:for-each select="
407 preceding-sibling::*[self::interface or self::collection or self::enumerator] |
408 following-sibling::*[self::interface or self::collection or self::enumerator] |
409 preceding-sibling::if/*[self::interface or self::collection or self::enumerator] |
410 following-sibling::if/*[self::interface or self::collection or self::enumerator]
411 ">
412 <xsl:if test="
413 ((name()='interface' or name()='collection')
414 and
415 (.//method/param[@type=$name] or attribute[@type=$name]))
416 or
417 ((name()='collection' or name()='enumerator') and @type=$name)
418 ">
419 <xsl:text> friend class C</xsl:text>
420 <xsl:value-of select="substring(@name,2)"/>
421 <xsl:text>;&#x0A;</xsl:text>
422 </xsl:if>
423 </xsl:for-each>
424 </xsl:if>
425
426</xsl:template>
427
428<xsl:template match="interface//attribute | collection//attribute" mode="declare">
429 <xsl:apply-templates select="parent::node()" mode="begin"/>
430 <xsl:apply-templates select="@if" mode="begin"/>
431 <xsl:call-template name="composeMethod">
432 <xsl:with-param name="return" select="."/>
433 </xsl:call-template>
434 <xsl:if test="not(@readonly='yes')">
435 <xsl:call-template name="composeMethod">
436 <xsl:with-param name="return" select="''"/>
437 </xsl:call-template>
438 </xsl:if>
439 <xsl:apply-templates select="@if" mode="end"/>
440 <xsl:apply-templates select="parent::node()" mode="end"/>
441</xsl:template>
442
443<xsl:template match="interface//method | collection//method" mode="declare">
444 <xsl:apply-templates select="parent::node()" mode="begin"/>
445 <xsl:apply-templates select="@if" mode="begin"/>
446 <xsl:call-template name="composeMethod"/>
447 <xsl:apply-templates select="@if" mode="end"/>
448 <xsl:apply-templates select="parent::node()" mode="end"/>
449</xsl:template>
450
451
452<!--
453 * interface definitions
454-->
455<xsl:template match="interface | collection | enumerator" mode="define">
456
457 <xsl:text>// </xsl:text>
458 <xsl:value-of select="@name"/>
459 <xsl:text> wrapper&#x0A;&#x0A;</xsl:text>
460
461 <xsl:if test="name()='collection'">
462 <!-- GetCount -->
463 <xsl:text>inline ULONG C</xsl:text>
464 <xsl:value-of select="substring(@name,2)"/>
465 <xsl:text>::GetCount () const {&#x0A;</xsl:text>
466 <xsl:text> ULONG count = 0;&#x0A;</xsl:text>
467 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
468 <xsl:text> if (!mIface)&#x0A; return count;&#x0A;</xsl:text>
469 <xsl:text> mRC = mIface->COMGETTER(Count) (&amp;count);&#x0A;</xsl:text>
470 <xsl:call-template name="tryComposeFetchErrorInfo"/>
471 <xsl:text> return count;&#x0A;</xsl:text>
472 <xsl:text>}&#x0A;&#x0A;</xsl:text>
473 <!-- GetItemAt -->
474 <xsl:text>inline </xsl:text>
475 <xsl:apply-templates select="@type"/>
476 <xsl:text> C</xsl:text>
477 <xsl:value-of select="substring(@name,2)"/>
478 <xsl:text>::GetItemAt (ULONG index) const {&#x0A;</xsl:text>
479 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/>
480 <xsl:text> item;&#x0A;</xsl:text>
481 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
482 <xsl:text> if (!mIface)&#x0A; return item;&#x0A;</xsl:text>
483 <xsl:text> mRC = mIface->GetItemAt (index, &amp;item.mIface);&#x0A;</xsl:text>
484 <xsl:call-template name="tryComposeFetchErrorInfo"/>
485 <xsl:text> return item;&#x0A;</xsl:text>
486 <xsl:text>}&#x0A;&#x0A;</xsl:text>
487 <!-- Enumerate -->
488 <xsl:text>inline </xsl:text>
489 <xsl:apply-templates select="@enumerator"/>
490 <xsl:text> C</xsl:text>
491 <xsl:value-of select="substring(@name,2)"/>
492 <xsl:text>::Enumerate () const {&#x0A;</xsl:text>
493 <xsl:text> </xsl:text><xsl:apply-templates select="@enumerator"/>
494 <xsl:text> enumerator;&#x0A;</xsl:text>
495 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
496 <xsl:text> if (!mIface)&#x0A; return enumerator;&#x0A;</xsl:text>
497 <xsl:text> mRC = mIface->Enumerate (&amp;enumerator.mIface);&#x0A;</xsl:text>
498 <xsl:call-template name="tryComposeFetchErrorInfo"/>
499 <xsl:text> return enumerator;&#x0A;</xsl:text>
500 <xsl:text>}&#x0A;&#x0A;</xsl:text>
501 </xsl:if>
502
503 <xsl:if test="name()='enumerator'">
504 <!-- HasMore -->
505 <xsl:text>inline BOOL C</xsl:text>
506 <xsl:value-of select="substring(@name,2)"/>
507 <xsl:text>::HasMore () const {&#x0A;</xsl:text>
508 <xsl:text> BOOL more = FALSE;&#x0A;</xsl:text>
509 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
510 <xsl:text> if (!mIface)&#x0A; return more;&#x0A;</xsl:text>
511 <xsl:text> mRC = mIface->HasMore (&amp;more);&#x0A;</xsl:text>
512 <xsl:call-template name="tryComposeFetchErrorInfo"/>
513 <xsl:text> return more;&#x0A;</xsl:text>
514 <xsl:text>}&#x0A;&#x0A;</xsl:text>
515 <!-- GetNext -->
516 <xsl:text>inline </xsl:text>
517 <xsl:apply-templates select="@type"/>
518 <xsl:text> C</xsl:text>
519 <xsl:value-of select="substring(@name,2)"/>
520 <xsl:text>::GetNext () const {&#x0A;</xsl:text>
521 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/>
522 <xsl:text> next;&#x0A;</xsl:text>
523 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
524 <xsl:text> if (!mIface)&#x0A; return next;&#x0A;</xsl:text>
525 <xsl:text> mRC = mIface->GetNext (&amp;next.mIface);&#x0A;</xsl:text>
526 <xsl:call-template name="tryComposeFetchErrorInfo"/>
527 <xsl:text> return next;&#x0A;</xsl:text>
528 <xsl:text>}&#x0A;&#x0A;</xsl:text>
529 </xsl:if>
530
531 <xsl:if test="name()='interface' or name()='collection'">
532 <xsl:call-template name="defineMembers"/>
533 </xsl:if>
534
535</xsl:template>
536
537<xsl:template name="defineMembers">
538 <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="define"/>
539 <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="define"/>
540</xsl:template>
541
542<xsl:template match="interface//attribute | collection//attribute" mode="define">
543 <xsl:apply-templates select="parent::node()" mode="begin"/>
544 <xsl:apply-templates select="@if" mode="begin"/>
545 <xsl:call-template name="composeMethod">
546 <xsl:with-param name="return" select="."/>
547 <xsl:with-param name="define" select="'yes'"/>
548 </xsl:call-template>
549 <xsl:if test="not(@readonly='yes')">
550 <xsl:call-template name="composeMethod">
551 <xsl:with-param name="return" select="''"/>
552 <xsl:with-param name="define" select="'yes'"/>
553 </xsl:call-template>
554 </xsl:if>
555 <xsl:apply-templates select="@if" mode="end"/>
556 <xsl:apply-templates select="parent::node()" mode="end"/>
557 <xsl:text>&#x0A;</xsl:text>
558</xsl:template>
559
560<xsl:template match="interface//method | collection//method" mode="define">
561 <xsl:apply-templates select="parent::node()" mode="begin"/>
562 <xsl:apply-templates select="@if" mode="begin"/>
563 <xsl:call-template name="composeMethod">
564 <xsl:with-param name="define" select="'yes'"/>
565 </xsl:call-template>
566 <xsl:apply-templates select="@if" mode="end"/>
567 <xsl:apply-templates select="parent::node()" mode="end"/>
568 <xsl:text>&#x0A;</xsl:text>
569</xsl:template>
570
571
572<!--
573 * co-classes
574-->
575<xsl:template match="class"/>
576
577
578<!--
579 * enums
580-->
581<xsl:template match="enum"/>
582
583
584<!--
585 * base template to produce interface methods
586 *
587 * @param return
588 * - in <attribute> context, must be '.' for getters and
589 * '' for setters
590 * - in <method> context, must not be specified (the default value
591 * will apply)
592 * @param define
593 * 'yes' to procuce inlined definition outside the class
594 * declaration, or
595 * empty string to produce method declaration only (w/o body)
596-->
597<xsl:template name="composeMethod">
598 <xsl:param name="return" select="param[@dir='return']"/>
599 <xsl:param name="define" select="''"/>
600 <xsl:variable name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
601 <xsl:choose>
602 <!-- no return value -->
603 <xsl:when test="not($return)">
604 <xsl:choose>
605 <xsl:when test="$define">
606 <xsl:text>inline </xsl:text>
607 </xsl:when>
608 <xsl:otherwise>
609 <xsl:text> </xsl:text>
610 </xsl:otherwise>
611 </xsl:choose>
612 <xsl:text>void </xsl:text>
613 <xsl:if test="$define">
614 <xsl:text>C</xsl:text>
615 <xsl:value-of select="substring($namespace/@name,2)"/>
616 <xsl:text>::</xsl:text>
617 </xsl:if>
618 <xsl:call-template name="composeMethodDecl">
619 <xsl:with-param name="isSetter" select="'yes'"/>
620 </xsl:call-template>
621 <xsl:if test="$define">
622 <xsl:text> {&#x0A;</xsl:text>
623 <!-- iface assertion -->
624 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
625 <xsl:text> if (!mIface)&#x0A; return;&#x0A;</xsl:text>
626 <!-- method call -->
627 <xsl:call-template name="composeMethodCall">
628 <xsl:with-param name="isSetter" select="'yes'"/>
629 </xsl:call-template>
630 <xsl:text>}&#x0A;</xsl:text>
631 </xsl:if>
632 <xsl:if test="not($define)">
633 <xsl:text>;&#x0A;</xsl:text>
634 </xsl:if>
635 </xsl:when>
636 <!-- has a return value -->
637 <xsl:when test="count($return) = 1">
638 <xsl:choose>
639 <xsl:when test="$define">
640 <xsl:text>inline </xsl:text>
641 </xsl:when>
642 <xsl:otherwise>
643 <xsl:text> </xsl:text>
644 </xsl:otherwise>
645 </xsl:choose>
646 <xsl:apply-templates select="$return/@type"/>
647 <xsl:text> </xsl:text>
648 <xsl:if test="$define">
649 <xsl:text>C</xsl:text>
650 <xsl:value-of select="substring($namespace/@name,2)"/>
651 <xsl:text>::</xsl:text>
652 </xsl:if>
653 <xsl:call-template name="composeMethodDecl"/>
654 <xsl:if test="$define">
655 <xsl:text> {&#x0A; </xsl:text>
656 <xsl:apply-templates select="$return/@type"/>
657 <xsl:text> a_</xsl:text>
658 <!-- ### xsl:call-template name="capitalize">
659 <xsl:with-param name="str" select="$return/@name"/>
660 </xsl:call-template-->
661 <!--
662 using one of the blocks marked with ### causes sabcmd on RedHat
663 to stupidly fail, so we use <value-of> instead.
664 -->
665 <xsl:value-of select="$return/@name"/>
666 <xsl:apply-templates select="$return/@type" mode="initializer"/>
667 <xsl:text>;&#x0A;</xsl:text>
668 <!-- iface assertion -->
669 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
670 <xsl:text> if (!mIface)&#x0A; return a_</xsl:text>
671 <!-- ### xsl:call-template name="capitalize">
672 <xsl:with-param name="str" select="$return/@name"/>
673 </xsl:call-template-->
674 <xsl:value-of select="$return/@name"/>
675 <xsl:text>;&#x0A;</xsl:text>
676 <!-- method call -->
677 <xsl:call-template name="composeMethodCall"/>
678 <!-- return statement -->
679 <xsl:text> return a_</xsl:text>
680 <!-- ### xsl:call-template name="capitalize">
681 <xsl:with-param name="str" select="$return/@name"/>
682 </xsl:call-template -->
683 <xsl:value-of select="$return/@name"/>
684 <xsl:text>;&#x0A;}&#x0A;</xsl:text>
685 </xsl:if>
686 <xsl:if test="not($define)">
687 <xsl:text>;&#x0A;</xsl:text>
688 </xsl:if>
689 </xsl:when>
690 <!-- otherwise error -->
691 <xsl:otherwise>
692 <xsl:message terminate="yes">
693 <xsl:text>More than one return value in method: </xsl:text>
694 <xsl:value-of select="$namespace/@name"/>
695 <xsl:text>::</xsl:text>
696 <xsl:value-of select="@name"/>
697 </xsl:message>
698 </xsl:otherwise>
699 </xsl:choose>
700</xsl:template>
701
702<xsl:template name="composeMethodDecl">
703 <xsl:param name="isSetter" select="''"/>
704 <xsl:choose>
705 <!-- attribute method call -->
706 <xsl:when test="name()='attribute'">
707 <xsl:choose>
708 <xsl:when test="$isSetter">
709 <!-- name -->
710 <xsl:text>Set</xsl:text>
711 <xsl:call-template name="capitalize">
712 <xsl:with-param name="str" select="@name"/>
713 </xsl:call-template>
714 <xsl:text> (</xsl:text>
715 <!-- parameter -->
716 <xsl:apply-templates select="@type" mode="param"/>
717 <xsl:text> a_</xsl:text>
718 <!-- ### xsl:call-template name="capitalize">
719 <xsl:with-param name="str" select="@name"/>
720 </xsl:call-template -->
721 <xsl:value-of select="@name"/>
722 <xsl:text>)</xsl:text>
723 </xsl:when>
724 <xsl:otherwise>
725 <!-- name -->
726 <xsl:text>Get</xsl:text>
727 <xsl:call-template name="capitalize">
728 <xsl:with-param name="str" select="@name"/>
729 </xsl:call-template>
730 <xsl:text> (</xsl:text>
731 <!-- const method -->
732 <xsl:text>) const</xsl:text>
733 </xsl:otherwise>
734 </xsl:choose>
735 </xsl:when>
736 <!-- regular method call -->
737 <xsl:when test="name()='method'">
738 <!-- name -->
739 <xsl:call-template name="capitalize">
740 <xsl:with-param name="str" select="@name"/>
741 </xsl:call-template>
742 <xsl:text> (</xsl:text>
743 <!-- parameters -->
744 <xsl:for-each select="param[@dir!='return']">
745 <xsl:apply-templates select="@type" mode="param"/>
746 <xsl:text> a_</xsl:text>
747 <!-- ### xsl:call-template name="capitalize">
748 <xsl:with-param name="str" select="@name"/>
749 </xsl:call-template -->
750 <xsl:value-of select="@name"/>
751 <xsl:if test="position() != last()">
752 <xsl:text>, </xsl:text>
753 </xsl:if>
754 </xsl:for-each>
755 <xsl:text>)</xsl:text>
756 <!-- const method -->
757 <xsl:if test="@const='yes'"> const</xsl:if>
758 </xsl:when>
759 </xsl:choose>
760</xsl:template>
761
762<xsl:template name="composeMethodCall">
763 <xsl:param name="isSetter" select="''"/>
764 <xsl:text> mRC = mIface-></xsl:text>
765 <xsl:choose>
766 <!-- attribute method call -->
767 <xsl:when test="name()='attribute'">
768 <!-- method name -->
769 <xsl:choose>
770 <xsl:when test="$isSetter">
771 <xsl:text>COMSETTER(</xsl:text>
772 </xsl:when>
773 <xsl:otherwise>
774 <xsl:text>COMGETTER(</xsl:text>
775 </xsl:otherwise>
776 </xsl:choose>
777 <xsl:call-template name="capitalize">
778 <xsl:with-param name="str" select="@name"/>
779 </xsl:call-template>
780 <xsl:text>) (</xsl:text>
781 <!-- parameter -->
782 <xsl:call-template name="composeMethodCallParam">
783 <xsl:with-param name="isIn" select="$isSetter"/>
784 <xsl:with-param name="isOut" select="not($isSetter)"/>
785 </xsl:call-template>
786 </xsl:when>
787 <!-- regular method call -->
788 <xsl:when test="name()='method'">
789 <!-- method name -->
790 <xsl:call-template name="capitalize">
791 <xsl:with-param name="str" select="@name"/>
792 </xsl:call-template>
793 <xsl:text> (</xsl:text>
794 <!-- parameters -->
795 <xsl:for-each select="param">
796 <xsl:call-template name="composeMethodCallParam"/>
797 <xsl:if test="position() != last()">
798 <xsl:text>, </xsl:text>
799 </xsl:if>
800 </xsl:for-each>
801 </xsl:when>
802 </xsl:choose>
803 <xsl:text>);&#x0A;</xsl:text>
804 <xsl:call-template name="tryComposeFetchErrorInfo"/>
805</xsl:template>
806
807<!--
808 * Composes a 'fetch error info' call or returns the name of the
809 * appropriate base class name that provides error info functionality
810 * (depending on the mode parameter). Does nothing if the current
811 * entity (interface, collection or enumerator) does not support error info.
812 *
813 * @param mode
814 * - 'getBaseClassName': expands to the base class name
815 * - any other value: composes a 'fetch error info' method call
816-->
817<xsl:template name="tryComposeFetchErrorInfo">
818 <xsl:param name="mode" select="''"/>
819 <xsl:variable name="ifaceSupportsErrorInfo" select="
820 (ancestor-or-self::interface |
821 ancestor-or-self::collection |
822 ancestor-or-self::enumerator)[1]/@supportsErrorInfo
823 "/>
824 <xsl:variable name="moduleSupportsErrorInfo" select="ancestor::module/@supportsErrorInfo"/>
825 <xsl:choose>
826 <xsl:when test="$ifaceSupportsErrorInfo">
827 <xsl:call-template name="composeFetchErrorInfo">
828 <xsl:with-param name="supports" select="string($ifaceSupportsErrorInfo)"/>
829 <xsl:with-param name="mode" select="$mode"/>
830 </xsl:call-template>
831 </xsl:when>
832 <xsl:when test="$moduleSupportsErrorInfo">
833 <xsl:call-template name="composeFetchErrorInfo">
834 <xsl:with-param name="supports" select="string($moduleSupportsErrorInfo)"/>
835 <xsl:with-param name="mode" select="$mode"/>
836 </xsl:call-template>
837 </xsl:when>
838 </xsl:choose>
839</xsl:template>
840
841<xsl:template name="composeFetchErrorInfo">
842 <xsl:param name="supports" select="''"/>
843 <xsl:param name="mode" select="''"/>
844 <xsl:choose>
845 <xsl:when test="$mode='getBaseClassName'">
846 <xsl:if test="$supports='strict' or $supports='yes'">
847 <xsl:text>, COMBaseWithEI</xsl:text>
848 </xsl:if>
849 </xsl:when>
850 <xsl:otherwise>
851 <xsl:if test="$supports='strict' or $supports='yes'">
852 <xsl:text> if (FAILED (mRC)) {&#x0A;</xsl:text>
853 <xsl:text> fetchErrorInfo (mIface, &amp;COM_IIDOF (Base::Iface));&#x0A;</xsl:text>
854 <xsl:if test="$supports='strict'">
855 <xsl:text> AssertMsg (errInfo.isFullAvailable(), </xsl:text>
856 <xsl:text>("for RC=0x%08X\n", mRC));&#x0A;</xsl:text>
857 </xsl:if>
858 <xsl:text> }&#x0A;</xsl:text>
859 </xsl:if>
860 </xsl:otherwise>
861 </xsl:choose>
862</xsl:template>
863
864<xsl:template name="composeMethodCallParam">
865 <xsl:param name="isIn" select="@dir='in'"/>
866 <xsl:param name="isOut" select="@dir='out' or @dir='return'"/>
867
868 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
869
870 <xsl:choose>
871 <!-- string types -->
872 <xsl:when test="@type = 'wstring'">
873 <xsl:choose>
874 <xsl:when test="$isIn">
875 <xsl:text>BSTRIn (a_</xsl:text>
876 <!-- ### xsl:call-template name="capitalize">
877 <xsl:with-param name="str" select="@name"/>
878 </xsl:call-template -->
879 <xsl:value-of select="@name"/>
880 <xsl:text>)</xsl:text>
881 </xsl:when>
882 <xsl:when test="$isOut">
883 <xsl:text>BSTROut (a_</xsl:text>
884 <!-- ### xsl:call-template name="capitalize">
885 <xsl:with-param name="str" select="@name"/>
886 </xsl:call-template -->
887 <xsl:value-of select="@name"/>
888 <xsl:text>)</xsl:text>
889 </xsl:when>
890 </xsl:choose>
891 </xsl:when>
892 <!-- uuid type -->
893 <xsl:when test="@type = 'uuid'">
894 <xsl:choose>
895 <xsl:when test="$isIn">
896 <xsl:text>GUIDIn (a_</xsl:text>
897 <!-- ### xsl:call-template name="capitalize">
898 <xsl:with-param name="str" select="@name"/>
899 </xsl:call-template -->
900 <xsl:value-of select="@name"/>
901 <xsl:text>)</xsl:text>
902 </xsl:when>
903 <xsl:when test="$isOut">
904 <xsl:text>GUIDOut (a_</xsl:text>
905 <!-- ### xsl:call-template name="capitalize">
906 <xsl:with-param name="str" select="@name"/>
907 </xsl:call-template -->
908 <xsl:value-of select="@name"/>
909 <xsl:text>)</xsl:text>
910 </xsl:when>
911 </xsl:choose>
912 </xsl:when>
913 <!-- enum types -->
914 <xsl:when test="
915 (ancestor::module/enum[@name=current()/@type]) or
916 (ancestor::module/if[@target=$self_target]/enum[@name=current()/@type])
917 ">
918 <xsl:choose>
919 <xsl:when test="$isIn">
920 <xsl:text>(</xsl:text>
921 <xsl:value-of select="@type"/>
922 <xsl:text>_T) a_</xsl:text>
923 <!-- ### xsl:call-template name="capitalize">
924 <xsl:with-param name="str" select="@name"/>
925 </xsl:call-template -->
926 <xsl:value-of select="@name"/>
927 </xsl:when>
928 <xsl:when test="$isOut">
929 <xsl:text>ENUMOut &lt;CEnums::</xsl:text>
930 <xsl:value-of select="@type"/>
931 <xsl:text>, </xsl:text>
932 <xsl:value-of select="@type"/>
933 <xsl:text>_T&gt; (a_</xsl:text>
934 <!-- ### xsl:call-template name="capitalize">
935 <xsl:with-param name="str" select="@name"/>
936 </xsl:call-template -->
937 <xsl:value-of select="@name"/>
938 <xsl:text>)</xsl:text>
939 </xsl:when>
940 </xsl:choose>
941 </xsl:when>
942 <!-- interface types -->
943 <xsl:when test="
944 @type='$unknown' or
945 ((ancestor::module/enumerator[@name=current()/@type]) or
946 (ancestor::module/if[@target=$self_target]/enumerator[@name=current()/@type])
947 ) or
948 ((ancestor::module/interface[@name=current()/@type]) or
949 (ancestor::module/if[@target=$self_target]/interface[@name=current()/@type])
950 ) or
951 ((ancestor::module/collection[@name=current()/@type]) or
952 (ancestor::module/if[@target=$self_target]/collection[@name=current()/@type])
953 )
954 ">
955 <xsl:choose>
956 <xsl:when test="$isIn">
957 <xsl:text>a_</xsl:text>
958 <!-- ### xsl:call-template name="capitalize">
959 <xsl:with-param name="str" select="@name"/>
960 </xsl:call-template -->
961 <xsl:value-of select="@name"/>
962 <xsl:choose>
963 <xsl:when test="@type='$unknown'">
964 <xsl:text>.iface()</xsl:text>
965 </xsl:when>
966 <xsl:otherwise>
967 <xsl:text>.mIface</xsl:text>
968 </xsl:otherwise>
969 </xsl:choose>
970 </xsl:when>
971 <xsl:when test="$isOut">
972 <xsl:text>&amp;a_</xsl:text>
973 <!-- ### xsl:call-template name="capitalize">
974 <xsl:with-param name="str" select="@name"/>
975 </xsl:call-template -->
976 <xsl:value-of select="@name"/>
977 <xsl:choose>
978 <xsl:when test="@type='$unknown'">
979 <xsl:text>.ifaceRef()</xsl:text>
980 </xsl:when>
981 <xsl:otherwise>
982 <xsl:text>.mIface</xsl:text>
983 </xsl:otherwise>
984 </xsl:choose>
985 </xsl:when>
986 </xsl:choose>
987 </xsl:when>
988 <!-- currently unsupported types -->
989 <xsl:when test="@type = 'string'">
990 <xsl:message terminate="yes">
991 <xsl:text>Parameter type </xsl:text>
992 <xsl:value-of select="@type"/>
993 <xsl:text>is not currently supported</xsl:text>
994 </xsl:message>
995 </xsl:when>
996 <!-- assuming scalar types -->
997 <xsl:otherwise>
998 <xsl:choose>
999 <xsl:when test="$isIn">
1000 <xsl:text>a_</xsl:text>
1001 <!-- ### xsl:call-template name="capitalize">
1002 <xsl:with-param name="str" select="@name"/>
1003 </xsl:call-template -->
1004 <xsl:value-of select="@name"/>
1005 </xsl:when>
1006 <xsl:when test="$isOut">
1007 <xsl:text>&amp;a_</xsl:text>
1008 <!-- ### xsl:call-template name="capitalize">
1009 <xsl:with-param name="str" select="@name"/>
1010 </xsl:call-template -->
1011 <xsl:value-of select="@name"/>
1012 </xsl:when>
1013 </xsl:choose>
1014 </xsl:otherwise>
1015 </xsl:choose>
1016</xsl:template>
1017
1018
1019<!--
1020 * attribute/parameter type conversion (plain type name)
1021-->
1022<xsl:template match="
1023 attribute/@type | param/@type |
1024 enumerator/@type | collection/@type | collection/@enumerator
1025">
1026 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1027
1028 <xsl:if test="name(..)='param' and ../@array and ../@dir='return'">
1029 <xsl:message terminate="yes">
1030 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1031 <xsl:text>return array parameters are not currently supported</xsl:text>
1032 </xsl:message>
1033 </xsl:if>
1034
1035 <xsl:choose>
1036 <!-- modifiers (ignored for 'enumeration' attributes)-->
1037 <xsl:when test="name(current())='type' and ../@mod">
1038 <xsl:if test="../@array">
1039 <xsl:message terminate="yes">
1040 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1041 <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
1042 </xsl:message>
1043 </xsl:if>
1044 <xsl:choose>
1045 <xsl:when test="../@mod='ptr'">
1046 <xsl:choose>
1047 <!-- standard types -->
1048 <!--xsl:when test=".='result'">??</xsl:when-->
1049 <xsl:when test=".='boolean'">BOOL *</xsl:when>
1050 <xsl:when test=".='octet'">BYTE *</xsl:when>
1051 <xsl:when test=".='short'">SHORT *</xsl:when>
1052 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
1053 <xsl:when test=".='long'">LONG *</xsl:when>
1054 <xsl:when test=".='long long'">LONG64 *</xsl:when>
1055 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
1056 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
1057 <xsl:when test=".='char'">CHAR *</xsl:when>
1058 <!--<xsl:when test=".='string'">??</xsl:when-->
1059 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
1060 <!--<xsl:when test=".='wstring'">??</xsl:when-->
1061 <xsl:otherwise>
1062 <xsl:message terminate="yes">
1063 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1064 <xsl:text>attribute 'mod=</xsl:text>
1065 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1066 <xsl:text>' cannot be used with type </xsl:text>
1067 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1068 </xsl:message>
1069 </xsl:otherwise>
1070 </xsl:choose>
1071 </xsl:when>
1072 <xsl:otherwise>
1073 <xsl:message terminate="yes">
1074 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1075 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1076 <xsl:text>of attibute 'mod' is invalid!</xsl:text>
1077 </xsl:message>
1078 </xsl:otherwise>
1079 </xsl:choose>
1080 </xsl:when>
1081 <!-- no modifiers -->
1082 <xsl:otherwise>
1083 <xsl:choose>
1084 <!-- standard types -->
1085 <xsl:when test=".='result'">HRESULT</xsl:when>
1086 <xsl:when test=".='boolean'">BOOL</xsl:when>
1087 <xsl:when test=".='octet'">BYTE</xsl:when>
1088 <xsl:when test=".='short'">SHORT</xsl:when>
1089 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
1090 <xsl:when test=".='long'">LONG</xsl:when>
1091 <xsl:when test=".='long long'">LONG64</xsl:when>
1092 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
1093 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
1094 <xsl:when test=".='char'">CHAR</xsl:when>
1095 <xsl:when test=".='string'">CHAR *</xsl:when>
1096 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
1097 <xsl:when test=".='wstring'">QString</xsl:when>
1098 <!-- UUID type -->
1099 <xsl:when test=".='uuid'">QUuid</xsl:when>
1100 <!-- system interface types -->
1101 <xsl:when test=".='$unknown'">CUnknown</xsl:when>
1102 <xsl:otherwise>
1103 <xsl:choose>
1104 <!-- enum types -->
1105 <xsl:when test="
1106 (ancestor::module/enum[@name=current()]) or
1107 (ancestor::module/if[@target=$self_target]/enum[@name=current()])
1108 ">
1109 <xsl:value-of select="concat('CEnums::',string(.))"/>
1110 </xsl:when>
1111 <!-- custom interface types -->
1112 <xsl:when test="
1113 (name(current())='enumerator' and
1114 ((ancestor::module/enumerator[@name=current()]) or
1115 (ancestor::module/if[@target=$self_target]/enumerator[@name=current()]))
1116 ) or
1117 ((ancestor::module/interface[@name=current()]) or
1118 (ancestor::module/if[@target=$self_target]/interface[@name=current()])
1119 ) or
1120 ((ancestor::module/collection[@name=current()]) or
1121 (ancestor::module/if[@target=$self_target]/collection[@name=current()])
1122 )
1123 ">
1124 <xsl:value-of select="concat('C',substring(.,2))"/>
1125 </xsl:when>
1126 <!-- other types -->
1127 <xsl:otherwise>
1128 <xsl:message terminate="yes">
1129 <xsl:text>Unknown parameter type: </xsl:text>
1130 <xsl:value-of select="."/>
1131 </xsl:message>
1132 </xsl:otherwise>
1133 </xsl:choose>
1134 </xsl:otherwise>
1135 </xsl:choose>
1136 </xsl:otherwise>
1137 </xsl:choose>
1138</xsl:template>
1139
1140
1141<!--
1142 * generates a null initializer for all scalar types (such as bool or long)
1143 * and enum types in the form of ' = <null_initializer>', or nothing for other
1144 * types.
1145-->
1146<xsl:template match="
1147 attribute/@type | param/@type |
1148 enumerator/@type | collection/@type | collection/@enumerator
1149" mode="initializer">
1150
1151 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1152
1153 <xsl:choose>
1154 <!-- modifiers (ignored for 'enumeration' attributes)-->
1155 <xsl:when test="name(current())='type' and ../@mod">
1156 <xsl:if test="../@array">
1157 <xsl:message terminate="yes">
1158 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1159 <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
1160 </xsl:message>
1161 </xsl:if>
1162 <xsl:choose>
1163 <xsl:when test="../@mod='ptr'">
1164 <xsl:choose>
1165 <!-- standard types -->
1166 <!--xsl:when test=".='result'">??</xsl:when-->
1167 <xsl:when test=".='boolean'"> = NULL</xsl:when>
1168 <xsl:when test=".='octet'"> = NULL</xsl:when>
1169 <xsl:when test=".='short'"> = NULL</xsl:when>
1170 <xsl:when test=".='unsigned short'"> = NULL</xsl:when>
1171 <xsl:when test=".='long'"> = NULL</xsl:when>
1172 <xsl:when test=".='long long'"> = NULL</xsl:when>
1173 <xsl:when test=".='unsigned long'"> = NULL</xsl:when>
1174 <xsl:when test=".='unsigned long long'"> = NULL</xsl:when>
1175 <xsl:when test=".='char'"> = NULL</xsl:when>
1176 <!--<xsl:when test=".='string'">??</xsl:when-->
1177 <xsl:when test=".='wchar'"> = NULL</xsl:when>
1178 <!--<xsl:when test=".='wstring'">??</xsl:when-->
1179 <xsl:otherwise>
1180 <xsl:message terminate="yes">
1181 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1182 <xsl:text>attribute 'mod=</xsl:text>
1183 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1184 <xsl:text>' cannot be used with type </xsl:text>
1185 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1186 </xsl:message>
1187 </xsl:otherwise>
1188 </xsl:choose>
1189 </xsl:when>
1190 <xsl:otherwise>
1191 <xsl:message terminate="yes">
1192 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1193 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1194 <xsl:text>of attibute 'mod' is invalid!</xsl:text>
1195 </xsl:message>
1196 </xsl:otherwise>
1197 </xsl:choose>
1198 </xsl:when>
1199 <!-- no modifiers -->
1200 <xsl:otherwise>
1201 <xsl:choose>
1202 <!-- standard types that need a zero initializer -->
1203 <xsl:when test=".='result'"> = S_OK</xsl:when>
1204 <xsl:when test=".='boolean'"> = FALSE</xsl:when>
1205 <xsl:when test=".='octet'"> = 0</xsl:when>
1206 <xsl:when test=".='short'"> = 0</xsl:when>
1207 <xsl:when test=".='unsigned short'"> = 0</xsl:when>
1208 <xsl:when test=".='long'"> = 0</xsl:when>
1209 <xsl:when test=".='long long'"> = 0</xsl:when>
1210 <xsl:when test=".='unsigned long'"> = 0</xsl:when>
1211 <xsl:when test=".='unsigned long long'"> = 0</xsl:when>
1212 <xsl:when test=".='char'"> = 0</xsl:when>
1213 <xsl:when test=".='string'"> = NULL</xsl:when>
1214 <xsl:when test=".='wchar'"> = 0</xsl:when>
1215 <xsl:otherwise>
1216 <xsl:choose>
1217 <!-- enum types initialized with 0 -->
1218 <xsl:when test="
1219 (ancestor::module/enum[@name=current()]) or
1220 (ancestor::module/if[@target=$self_target]/enum[@name=current()])
1221 ">
1222 <xsl:value-of select="concat(' = (CEnums::',string(.),') 0')"/>
1223 </xsl:when>
1224 </xsl:choose>
1225 </xsl:otherwise>
1226 </xsl:choose>
1227 </xsl:otherwise>
1228 </xsl:choose>
1229</xsl:template>
1230
1231
1232<!--
1233 * attribute/parameter type conversion (for method declaration)
1234-->
1235<xsl:template match="attribute/@type | param/@type" mode="param">
1236
1237 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1238
1239 <xsl:choose>
1240 <!-- class types -->
1241 <xsl:when test="
1242 .='string' or
1243 .='wstring' or
1244 ((ancestor::module/enum[@name=current()]) or
1245 (ancestor::module/if[@target=$self_target]/enum[@name=current()])
1246 ) or
1247 .='$unknown' or
1248 ((ancestor::module/enumerator[@name=current()]) or
1249 (ancestor::module/if[@target=$self_target]/enumerator[@name=current()])
1250 ) or
1251 ((ancestor::module/interface[@name=current()]) or
1252 (ancestor::module/if[@target=$self_target]/interface[@name=current()])
1253 ) or
1254 ((ancestor::module/collection[@name=current()]) or
1255 (ancestor::module/if[@target=$self_target]/collection[@name=current()])
1256 )
1257 ">
1258 <xsl:choose>
1259 <!-- <attribute> context -->
1260 <xsl:when test="name(..)='attribute'">
1261 <xsl:text>const </xsl:text>
1262 <xsl:apply-templates select="."/>
1263 <xsl:text> &amp;</xsl:text>
1264 </xsl:when>
1265 <!-- <param> context -->
1266 <xsl:when test="name(..)='param'">
1267 <xsl:if test="../@array">
1268 <xsl:message terminate="yes">
1269 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1270 <xsl:text>arrays of non-scalar types are not currently supported</xsl:text>
1271 </xsl:message>
1272 </xsl:if>
1273 <xsl:choose>
1274 <xsl:when test="../@dir='in'">
1275 <xsl:text>const </xsl:text>
1276 <xsl:apply-templates select="."/>
1277 <xsl:text> &amp;</xsl:text>
1278 </xsl:when>
1279 <xsl:when test="../@dir='out'">
1280 <xsl:apply-templates select="."/>
1281 <xsl:text> &amp;</xsl:text>
1282 </xsl:when>
1283 <xsl:when test="../@dir='return'">
1284 <xsl:apply-templates select="."/>
1285 </xsl:when>
1286 </xsl:choose>
1287 </xsl:when>
1288 </xsl:choose>
1289 </xsl:when>
1290 <!-- assume scalar types -->
1291 <xsl:otherwise>
1292 <xsl:choose>
1293 <!-- <attribute> context -->
1294 <xsl:when test="name(..)='attribute'">
1295 <xsl:apply-templates select="."/>
1296 </xsl:when>
1297 <!-- <param> context -->
1298 <xsl:when test="name(..)='param'">
1299 <xsl:choose>
1300 <xsl:when test="../@array">
1301 <xsl:apply-templates select="."/>
1302 <xsl:text> *</xsl:text>
1303 <xsl:if test="../@dir='out'">
1304 <xsl:text> &amp;</xsl:text>
1305 </xsl:if>
1306 </xsl:when>
1307 <xsl:otherwise>
1308 <xsl:apply-templates select="."/>
1309 <xsl:if test="../@dir='out'">
1310 <xsl:text> &amp;</xsl:text>
1311 </xsl:if>
1312 </xsl:otherwise>
1313 </xsl:choose>
1314 </xsl:when>
1315 </xsl:choose>
1316 </xsl:otherwise>
1317 </xsl:choose>
1318</xsl:template>
1319
1320
1321</xsl:stylesheet>
1322
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