• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3   Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
4
5   Distributed under the Boost Software License, Version 1.0.
6   (See accompanying file LICENSE_1_0.txt or copy at
7   http://www.boost.org/LICENSE_1_0.txt)
8  -->
9<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10                version="1.0">
11
12  <xsl:param name="template.param.brief" select="false()"/>
13
14  <!-- Determine the length of a template header synopsis -->
15  <xsl:template name="template.synopsis.length">
16    <xsl:variable name="text">
17      <xsl:apply-templates select="template" mode="synopsis">
18        <xsl:with-param name="indentation" select="0"/>
19        <xsl:with-param name="wrap" select="false()"/>
20        <xsl:with-param name="highlight" select="false()"/>
21      </xsl:apply-templates>
22    </xsl:variable>
23    <xsl:value-of select="string-length($text)"/>
24  </xsl:template>
25
26  <!-- Determine the length of a template header reference -->
27  <xsl:template name="template.reference.length">
28    <xsl:choose>
29      <xsl:when test="not(template)">
30        0
31      </xsl:when>
32      <xsl:when test="template/*/purpose">
33        <!-- TBD: The resulting value need only be greater than the number of
34             columns. We chose to add 17 because it's funny for C++
35             programmers. :) -->
36        <xsl:value-of select="$max-columns + 17"/>
37      </xsl:when>
38      <xsl:otherwise>
39        <xsl:call-template name="template.synopsis.length"/>
40      </xsl:otherwise>
41    </xsl:choose>
42  </xsl:template>
43
44  <!-- Output a template header in synopsis mode -->
45  <xsl:template match="template" mode="synopsis">
46    <xsl:param name="indentation" select="0"/>
47    <xsl:param name="wrap" select="true()"/>
48    <xsl:param name="highlight" select="true()"/>
49
50    <xsl:call-template name="template.synopsis">
51      <xsl:with-param name="indentation" select="$indentation"/>
52      <xsl:with-param name="wrap" select="$wrap"/>
53      <xsl:with-param name="highlight" select="$highlight"/>
54    </xsl:call-template>
55  </xsl:template>
56
57  <!-- Output a template header in reference mode -->
58  <xsl:template match="template" mode="reference">
59    <xsl:param name="indentation" select="0"/>
60    <xsl:param name="highlight" select="true()"/>
61    <xsl:call-template name="template.reference">
62      <xsl:with-param name="indentation" select="$indentation"/>
63      <xsl:with-param name="highlight" select="$highlight"/>
64    </xsl:call-template>
65  </xsl:template>
66
67  <!-- Emit a template header synopsis -->
68  <xsl:template name="template.synopsis">
69    <xsl:param name="indentation" select="0"/>
70    <xsl:param name="wrap" select="true()"/>
71    <xsl:param name="highlight" select="true()"/>
72
73    <xsl:choose>
74      <xsl:when test="$highlight">
75        <xsl:call-template name="highlight-keyword">
76          <xsl:with-param name="keyword" select="'template'"/>
77        </xsl:call-template>
78        <xsl:call-template name="highlight-special">
79          <xsl:with-param name="text" select="'&lt;'"/>
80        </xsl:call-template>
81      </xsl:when>
82      <xsl:otherwise>
83        <xsl:text>template</xsl:text>
84        <xsl:text>&lt;</xsl:text>
85      </xsl:otherwise>
86    </xsl:choose>
87    <xsl:call-template name="template.synopsis.parameters">
88      <xsl:with-param name="indentation" select="$indentation + 9"/>
89      <xsl:with-param name="wrap" select="$wrap"/>
90      <xsl:with-param name="highlight" select="$highlight"/>
91    </xsl:call-template>
92    <xsl:choose>
93      <xsl:when test="$highlight">
94        <xsl:call-template name="highlight-special">
95          <xsl:with-param name="text" select="'&gt;'"/>
96        </xsl:call-template>
97        <xsl:text> </xsl:text>
98      </xsl:when>
99      <xsl:otherwise>
100        <xsl:text>&gt; </xsl:text>
101      </xsl:otherwise>
102    </xsl:choose>
103  </xsl:template>
104
105  <!-- Display a list of template parameters for a synopsis (no comments) -->
106  <xsl:template name="template.synopsis.parameters">
107    <xsl:param name="indentation"/>
108    <xsl:param name="wrap" select="true()"/>
109    <xsl:param name="highlight" select="true()"/>
110
111    <xsl:param name="column" select="$indentation"/>
112    <xsl:param name="prefix" select="''"/>
113    <xsl:param name="parameters" select="template-type-parameter|template-varargs|template-nontype-parameter"/>
114    <xsl:param name="first-on-line" select="true()"/>
115
116    <xsl:if test="$parameters">
117      <!-- Emit the prefix (either a comma-space, or empty if this is
118           the first parameter) -->
119      <xsl:choose>
120        <xsl:when test="$highlight">
121          <xsl:call-template name="highlight-text">
122            <xsl:with-param name="text" select="$prefix"/>
123          </xsl:call-template>
124        </xsl:when>
125        <xsl:otherwise>
126          <xsl:value-of select="$prefix"/>
127        </xsl:otherwise>
128      </xsl:choose>
129
130      <!-- Get the actual parameter and its attributes -->
131      <xsl:variable name="parameter" select="$parameters[position()=1]"/>
132      <xsl:variable name="rest" select="$parameters[position()!=1]"/>
133
134      <!-- Compute the actual text of this parameter -->
135      <xsl:variable name="text">
136        <xsl:call-template name="template.parameter">
137          <xsl:with-param name="parameter" select="$parameter"/>
138          <xsl:with-param name="is-last" select="not(rest)"/>
139          <xsl:with-param name="highlight" select="false()"/>
140        </xsl:call-template>
141      </xsl:variable>
142
143      <!-- Where will this template parameter finish? -->
144      <xsl:variable name="end-column"
145        select="$column + string-length($prefix) + string-length($text)"/>
146
147      <!-- Should the text go on this line or on the next? -->
148      <xsl:choose>
149        <xsl:when test="$first-on-line or ($end-column &lt; $max-columns) or
150                        not($wrap)">
151          <!-- Print on this line -->
152          <xsl:call-template name="template.parameter">
153            <xsl:with-param name="parameter" select="$parameter"/>
154            <xsl:with-param name="is-last" select="not($rest)"/>
155            <xsl:with-param name="highlight" select="$highlight"/>
156          </xsl:call-template>
157
158          <!-- Recurse -->
159          <xsl:call-template name="template.synopsis.parameters">
160            <xsl:with-param name="indentation" select="$indentation"/>
161            <xsl:with-param name="wrap" select="$wrap"/>
162            <xsl:with-param name="highlight" select="$highlight"/>
163            <xsl:with-param name="column" select="$end-column"/>
164            <xsl:with-param name="prefix" select="', '"/>
165            <xsl:with-param name="parameters" select="$rest"/>
166            <xsl:with-param name="first-on-line" select="false()"/>
167          </xsl:call-template>
168        </xsl:when>
169        <xsl:otherwise>
170          <!-- Print on next line -->
171          <xsl:text>&#10;</xsl:text>
172          <xsl:call-template name="indent">
173            <xsl:with-param name="indentation" select="$indentation"/>
174          </xsl:call-template>
175          <xsl:call-template name="template.parameter">
176            <xsl:with-param name="parameter" select="$parameter"/>
177            <xsl:with-param name="is-last" select="not($rest)"/>
178            <xsl:with-param name="highlight" select="$highlight"/>
179          </xsl:call-template>
180
181          <xsl:call-template name="template.synopsis.parameters">
182            <xsl:with-param name="indentation" select="$indentation"/>
183            <xsl:with-param name="wrap" select="$wrap"/>
184            <xsl:with-param name="highlight" select="$highlight"/>
185            <xsl:with-param name="column"
186              select="$indentation + string-length($text)"/>
187            <xsl:with-param name="prefix" select="', '"/>
188            <xsl:with-param name="parameters" select="$rest"/>
189            <xsl:with-param name="first-on-line" select="false()"/>
190          </xsl:call-template>
191        </xsl:otherwise>
192      </xsl:choose>
193    </xsl:if>
194  </xsl:template>
195
196  <!-- Emit a template header reference -->
197  <xsl:template name="template.reference">
198    <xsl:param name="indentation" select="0"/>
199    <xsl:param name="highlight" select="true()"/>
200
201    <xsl:if test="template-type-parameter|template-varargs|template-nontype-parameter">
202      <xsl:choose>
203        <xsl:when test="$highlight">
204          <xsl:call-template name="highlight-keyword">
205            <xsl:with-param name="keyword" select="'template'"/>
206          </xsl:call-template>
207          <xsl:call-template name="highlight-special">
208            <xsl:with-param name="text" select="'&lt;'"/>
209          </xsl:call-template>
210        </xsl:when>
211        <xsl:otherwise>
212          <xsl:text>template</xsl:text>
213          <xsl:text>&lt;</xsl:text>
214        </xsl:otherwise>
215      </xsl:choose>
216      <xsl:call-template name="template.reference.parameters">
217        <xsl:with-param name="indentation" select="$indentation + 9"/>
218        <xsl:with-param name="highlight" select="$highlight"/>
219      </xsl:call-template>
220      <xsl:choose>
221        <xsl:when test="$highlight">
222          <xsl:call-template name="highlight-special">
223            <xsl:with-param name="text" select="'&gt;'"/>
224          </xsl:call-template>
225          <xsl:text> </xsl:text>
226        </xsl:when>
227        <xsl:otherwise>
228          <xsl:text>&gt; </xsl:text>
229        </xsl:otherwise>
230      </xsl:choose>
231    </xsl:if>
232  </xsl:template>
233
234  <!-- Display a set of template parameters for a reference -->
235  <xsl:template name="template.reference.parameters">
236    <xsl:param name="indentation"/>
237    <xsl:param name="highlight" select="true()"/>
238    <xsl:param name="parameters" select="template-type-parameter|template-varargs|template-nontype-parameter"/>
239
240    <xsl:choose>
241      <xsl:when test="$parameters/purpose and $template.param.brief">
242        <xsl:call-template name="template.reference.parameters.comments">
243          <xsl:with-param name="indentation" select="$indentation"/>
244          <xsl:with-param name="highlight" select="$highlight"/>
245        </xsl:call-template>
246      </xsl:when>
247      <xsl:otherwise>
248        <xsl:call-template name="template.synopsis.parameters">
249          <xsl:with-param name="indentation" select="$indentation"/>
250          <xsl:with-param name="wrap" select="true()"/>
251          <xsl:with-param name="highlight" select="$highlight"/>
252        </xsl:call-template>
253      </xsl:otherwise>
254    </xsl:choose>
255  </xsl:template>
256
257  <!-- Output template parameters when there are comments with the parameters.
258       For clarity, we output each template parameter on a separate line. -->
259  <xsl:template name="template.reference.parameters.comments">
260    <xsl:param name="indentation"/>
261    <xsl:param name="highlight" select="true()"/>
262    <xsl:param name="parameters" select="template-type-parameter|template-varargs|template-nontype-parameter"/>
263
264    <xsl:if test="$parameters">
265      <!-- Get the actual parameter and its attributes -->
266      <xsl:variable name="parameter" select="$parameters[position()=1]"/>
267      <xsl:variable name="rest" select="$parameters[position()!=1]"/>
268
269      <!-- Display the parameter -->
270      <xsl:call-template name="template.parameter">
271        <xsl:with-param name="parameter" select="$parameter"/>
272        <xsl:with-param name="is-last" select="not($rest)"/>
273        <xsl:with-param name="highlight" select="$highlight"/>
274      </xsl:call-template>
275
276      <xsl:if test="$rest">
277        <xsl:choose>
278          <xsl:when test="$highlight">
279            <xsl:call-template name="highlight-text">
280              <xsl:with-param name="text" select="', '"/>
281            </xsl:call-template>
282          </xsl:when>
283          <xsl:otherwise>
284            <xsl:text>, </xsl:text>
285          </xsl:otherwise>
286        </xsl:choose>
287      </xsl:if>
288
289      <!-- Display the comment -->
290      <xsl:if test="$parameter/purpose">
291        <xsl:variable name="param-text">
292          <!-- Display the parameter -->
293          <xsl:call-template name="template.parameter">
294            <xsl:with-param name="parameter" select="$parameter"/>
295            <xsl:with-param name="is-last" select="not($rest)"/>
296            <xsl:with-param name="highlight" select="false()"/>
297          </xsl:call-template>
298        </xsl:variable>
299        <xsl:call-template name="highlight-comment">
300          <xsl:with-param name="text">
301            <xsl:text>  // </xsl:text>
302            <xsl:apply-templates
303              select="$parameter/purpose/*|$parameter/purpose/text()" mode="comment">
304              <xsl:with-param name="wrap" select="true()"/>
305              <xsl:with-param name="prefix">
306                <xsl:call-template name="indent">
307                  <xsl:with-param name="indentation" select="$indentation + string-length($param-text)"/>
308                </xsl:call-template>
309                <xsl:if test="$rest">
310                  <xsl:text>  </xsl:text>
311                </xsl:if>
312                <xsl:text>  // </xsl:text>
313              </xsl:with-param>
314            </xsl:apply-templates>
315          </xsl:with-param>
316        </xsl:call-template>
317      </xsl:if>
318
319      <!-- Indent the next line -->
320      <xsl:if test="$parameter/purpose or $rest">
321        <xsl:text>&#10;</xsl:text>
322        <xsl:call-template name="indent">
323          <xsl:with-param name="indentation" select="$indentation"/>
324        </xsl:call-template>
325      </xsl:if>
326
327      <!-- Recurse to print the rest of the parameters -->
328      <xsl:call-template name="template.reference.parameters.comments">
329        <xsl:with-param name="indentation" select="$indentation"/>
330        <xsl:with-param name="highlight" select="$highlight"/>
331        <xsl:with-param name="parameters" select="$rest"/>
332      </xsl:call-template>
333    </xsl:if>
334  </xsl:template>
335
336  <!-- Print a template parameter -->
337  <xsl:template name="template.parameter">
338    <xsl:param name="parameter"/>
339    <xsl:param name="is-last"/>
340    <xsl:param name="highlight" select="true()"/>
341    <xsl:apply-templates select="$parameter"
342      mode="print.parameter">
343      <xsl:with-param name="parameter" select="$parameter"/>
344      <xsl:with-param name="is-last" select="$is-last"/>
345      <xsl:with-param name="highlight" select="$highlight"/>
346    </xsl:apply-templates>
347  </xsl:template>
348
349  <xsl:template name="template.parameter.name">
350    <xsl:param name="name" select="@name"/>
351    <xsl:param name="highlight" select="true()"/>
352
353    <xsl:choose>
354      <xsl:when test="$highlight">
355        <xsl:call-template name="concept.link">
356          <xsl:with-param name="name"
357            select="translate($name, '0123456789', '')"/>
358          <xsl:with-param name="text" select="$name"/>
359          <xsl:with-param name="warn" select="false"/>
360        </xsl:call-template>
361      </xsl:when>
362      <xsl:otherwise>
363        <xsl:value-of select="$name"/>
364      </xsl:otherwise>
365    </xsl:choose>
366  </xsl:template>
367
368  <xsl:template match="template-type-parameter" mode="print.parameter">
369    <xsl:param name="parameter"/>
370    <xsl:param name="is-last"/>
371    <xsl:param name="highlight"/>
372
373    <xsl:choose>
374      <xsl:when test="$highlight">
375        <xsl:call-template name="highlight-keyword">
376          <xsl:with-param name="keyword" select="'typename'"/>
377        </xsl:call-template>
378      </xsl:when>
379      <xsl:otherwise>
380        <xsl:text>typename</xsl:text>
381      </xsl:otherwise>
382    </xsl:choose>
383    <xsl:if test="$parameter/@pack=1">
384      <xsl:choose>
385        <xsl:when test="$highlight">
386          <xsl:call-template name="highlight-text">
387            <xsl:with-param name="text" select="'...'"/>
388          </xsl:call-template>
389        </xsl:when>
390        <xsl:otherwise>
391          <xsl:text>...</xsl:text>
392        </xsl:otherwise>
393      </xsl:choose>
394    </xsl:if>
395    <xsl:text> </xsl:text>
396
397    <xsl:call-template name="template.parameter.name">
398      <xsl:with-param name="name" select="$parameter/@name"/>
399      <xsl:with-param name="highlight" select="$highlight"/>
400    </xsl:call-template>
401
402    <xsl:variable name="def">
403      <xsl:choose>
404        <xsl:when test="$parameter/@default">
405          <xsl:message>
406            <xsl:text>Warning: 'default' attribute of template parameter element is deprecated. Use 'default' element.</xsl:text>
407            <xsl:call-template name="print.warning.context"/>
408          </xsl:message>
409          <xsl:choose>
410            <xsl:when test="$highlight and false()">
411              <xsl:call-template name="source-highlight">
412                <xsl:with-param name="text">
413                  <xsl:value-of select="$parameter/@default"/>
414                </xsl:with-param>
415              </xsl:call-template>
416            </xsl:when>
417            <xsl:otherwise>
418              <xsl:value-of select="$parameter/@default"/>
419            </xsl:otherwise>
420          </xsl:choose>
421        </xsl:when>
422        <xsl:when test="$parameter/default">
423          <xsl:choose>
424            <xsl:when test="$highlight">
425              <xsl:apply-templates
426                select="$parameter/default/*|$parameter/default/text()"
427                mode="highlight"/>
428            </xsl:when>
429            <xsl:otherwise>
430              <xsl:value-of select="string($parameter/default)"/>
431            </xsl:otherwise>
432          </xsl:choose>
433        </xsl:when>
434      </xsl:choose>
435    </xsl:variable>
436
437    <xsl:if test="not($def='')">
438      <xsl:choose>
439        <xsl:when test="$highlight">
440          <xsl:call-template name="highlight-text">
441            <xsl:with-param name="text" select="' = '"/>
442          </xsl:call-template>
443        </xsl:when>
444        <xsl:otherwise>
445          <xsl:text> = </xsl:text>
446        </xsl:otherwise>
447      </xsl:choose>
448
449      <xsl:copy-of select="$def"/>
450
451      <!-- If this is the last parameter, add an extra space to
452           avoid printing >> -->
453      <xsl:if
454        test="$is-last and (substring($def, string-length($def))='&gt;')">
455        <xsl:text> </xsl:text>
456      </xsl:if>
457    </xsl:if>
458  </xsl:template>
459
460  <xsl:template match="template-nontype-parameter" mode="print.parameter">
461    <xsl:param name="parameter"/>
462    <xsl:param name="is-last"/>
463    <xsl:param name="highlight"/>
464
465    <xsl:choose>
466      <xsl:when test="$highlight">
467        <xsl:call-template name="source-highlight">
468          <xsl:with-param name="text">
469            <xsl:apply-templates
470              select="$parameter/type/*|$parameter/type/text()"/>
471          </xsl:with-param>
472        </xsl:call-template>
473      </xsl:when>
474      <xsl:otherwise>
475        <xsl:value-of select="$parameter/type/*|$parameter/type/text()"/>
476      </xsl:otherwise>
477    </xsl:choose>
478    <xsl:if test="$parameter/@pack=1">
479      <xsl:choose>
480        <xsl:when test="$highlight">
481          <xsl:call-template name="highlight-text">
482            <xsl:with-param name="text" select="'...'"/>
483          </xsl:call-template>
484        </xsl:when>
485        <xsl:otherwise>
486          <xsl:text>...</xsl:text>
487        </xsl:otherwise>
488      </xsl:choose>
489    </xsl:if>
490    <xsl:text> </xsl:text>
491
492    <xsl:call-template name="template.parameter.name">
493      <xsl:with-param name="name" select="$parameter/@name"/>
494      <xsl:with-param name="highlight" select="$highlight"/>
495    </xsl:call-template>
496
497    <xsl:variable name="def">
498      <xsl:value-of select="string($parameter/default)"/>
499    </xsl:variable>
500
501    <xsl:if test="not($def='')">
502      <xsl:choose>
503        <xsl:when test="$highlight">
504          <xsl:call-template name="highlight-text">
505            <xsl:with-param name="text" select="' = '"/>
506          </xsl:call-template>
507        </xsl:when>
508        <xsl:otherwise>
509          <xsl:text> = </xsl:text>
510        </xsl:otherwise>
511      </xsl:choose>
512
513      <xsl:choose>
514        <xsl:when test="$highlight">
515          <xsl:apply-templates select="$parameter/default/*|$parameter/default/text()" mode="highlight"/>
516        </xsl:when>
517        <xsl:otherwise>
518          <xsl:value-of select="$def"/>
519        </xsl:otherwise>
520      </xsl:choose>
521
522      <!-- If this is the last parameter, add an extra space to
523           avoid printing >> -->
524      <xsl:if
525        test="$is-last and (substring($def, string-length($def))='&gt;')">
526        <xsl:text> </xsl:text>
527      </xsl:if>
528    </xsl:if>
529  </xsl:template>
530
531  <xsl:template match="template-varargs" mode="print.parameter">
532    <xsl:param name="highlight" select="true()"/>
533    <xsl:choose>
534      <xsl:when test="$highlight">
535        <xsl:call-template name="highlight-text">
536          <xsl:with-param name="text" select="'...'"/>
537        </xsl:call-template>
538      </xsl:when>
539      <xsl:otherwise>
540        <xsl:text>...</xsl:text>
541      </xsl:otherwise>
542    </xsl:choose>
543  </xsl:template>
544
545  <xsl:template match="specialization">
546    <xsl:param name="highlight" select="true()"/>
547    <xsl:choose>
548      <xsl:when test="$highlight">
549        <xsl:call-template name="highlight-text">
550          <xsl:with-param name="text" select="'&lt;'"/>
551        </xsl:call-template>
552      </xsl:when>
553      <xsl:otherwise>
554        <xsl:text>&lt;</xsl:text>
555      </xsl:otherwise>
556    </xsl:choose>
557    <xsl:apply-templates select="template-arg">
558      <xsl:with-param name="highlight" select="$highlight"/>
559    </xsl:apply-templates>
560    <xsl:choose>
561      <xsl:when test="$highlight">
562        <xsl:call-template name="highlight-text">
563          <xsl:with-param name="text" select="'&gt;'"/>
564        </xsl:call-template>
565      </xsl:when>
566      <xsl:otherwise>
567        <xsl:text>&gt;</xsl:text>
568      </xsl:otherwise>
569    </xsl:choose>
570  </xsl:template>
571
572  <xsl:template match="template-arg">
573    <xsl:param name="highlight" select="true()"/>
574    <xsl:if test="position() &gt; 1">
575      <xsl:choose>
576        <xsl:when test="$highlight">
577          <xsl:call-template name="highlight-text">
578            <xsl:with-param name="text" select="', '"/>
579          </xsl:call-template>
580        </xsl:when>
581        <xsl:otherwise>
582          <xsl:text>, </xsl:text>
583        </xsl:otherwise>
584      </xsl:choose>
585    </xsl:if>
586    <xsl:apply-templates mode="highlight"/>
587    <xsl:if test="@pack=1">
588      <xsl:choose>
589        <xsl:when test="$highlight">
590          <xsl:call-template name="highlight-text">
591            <xsl:with-param name="text" select="'...'"/>
592          </xsl:call-template>
593        </xsl:when>
594        <xsl:otherwise>
595          <xsl:text>...</xsl:text>
596        </xsl:otherwise>
597      </xsl:choose>
598    </xsl:if>
599  </xsl:template>
600</xsl:stylesheet>
601
602