VirtualBox

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

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

Main, Installer:

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