28
30
<xsl:include href="db_pdf_params.xsl"/>
30
32
<!-- Start of Dialyzer type/spec tags.
31
See also the template matching "name" and the template "bookmarks6"
33
See also the templates matching "name" and "seealso" as well as
34
the template "bookmarks6"
34
37
<xsl:param name="specs_file" select="''"/>
35
38
<xsl:variable name="i" select="document($specs_file)"></xsl:variable>
37
40
<xsl:template name="err">
38
42
<xsl:param name="m"/>
39
43
<xsl:param name="n"/>
40
44
<xsl:param name="a"/>
41
45
<xsl:param name="s"/>
42
46
<xsl:message terminate="yes">
43
Error <xsl:if test="$m != ''"><xsl:value-of select ="$m"/>:</xsl:if>
45
select="$n"/>/<xsl:value-of
46
select="$a"/>: <xsl:value-of select="$s"/>
47
Error <xsl:if test="$f != ''">in <xsl:value-of select ="$f"/>:</xsl:if>
48
<xsl:if test="$m != ''"><xsl:value-of select ="$m"/>:</xsl:if>
49
<xsl:value-of select="$n"/>
50
<xsl:if test="$a != ''">/<xsl:value-of
51
select ="$a"/></xsl:if>: <xsl:value-of select="$s"/>
55
<xsl:template name="find_spec">
56
<xsl:variable name="curModule" select="ancestor::erlref/module"/>
57
<xsl:variable name="mod" select="@mod"/>
58
<xsl:variable name="name" select="@name"/>
59
<xsl:variable name="arity" select="@arity"/>
60
<xsl:variable name="clause_i" select="@clause_i"/>
61
<xsl:variable name="spec0" select=
62
"$i/specs/module[@name=$curModule]/spec
63
[name=$name and arity=$arity
64
and (string-length($mod) = 0 or module = $mod)]"/>
65
<xsl:variable name="spec" select="$spec0[string-length($clause_i) = 0
66
or position() = $clause_i]"/>
68
<xsl:if test="count($spec) != 1">
69
<xsl:variable name="why">
71
<xsl:when test="count($spec) > 1">ambiguous spec</xsl:when>
72
<xsl:when test="count($spec) = 0">unknown spec</xsl:when>
75
<xsl:call-template name="err">
76
<xsl:with-param name="f" select="$curModule"/>
77
<xsl:with-param name="m" select="$mod"/>
78
<xsl:with-param name="n" select="$name"/>
79
<xsl:with-param name="a" select="$arity"/>
80
<xsl:with-param name="s" select="$why"/>
83
<xsl:copy-of select="$spec"/>
50
86
<xsl:template name="spec_name">
51
<xsl:variable name="curModule" select="ancestor::erlref/module"/>
52
<xsl:variable name="mod" select="@mod"/>
53
87
<xsl:variable name="name" select="@name"/>
54
88
<xsl:variable name="arity" select="@arity"/>
55
<xsl:variable name="clause" select="@clause"/>
56
<xsl:variable name="spec0" select=
57
"$i/specs/module[@name=$curModule]/spec
58
[name=$name and arity=$arity
59
and (string-length($mod) = 0 or module = $mod)]"/>
60
<xsl:variable name="spec" select="$spec0[string-length($clause) = 0
61
or position() = $clause]"/>
62
<xsl:if test="count($spec) = 0">
63
<xsl:call-template name="err">
64
<xsl:with-param name="m" select="$mod"/>
65
<xsl:with-param name="n" select="$name"/>
66
<xsl:with-param name="a" select="$arity"/>
67
<xsl:with-param name="s">unknown spec</xsl:with-param>
89
<xsl:variable name="spec0">
90
<xsl:call-template name="find_spec"/>
92
<xsl:variable name="spec" select="exsl:node-set($spec0)/spec"/>
72
95
<xsl:when test="ancestor::cref">
77
100
<xsl:when test="ancestor::erlref">
78
101
<fo:block id="{generate-id()}">
80
<xsl:when test="string(@with_guards) = 'no'">
81
<xsl:apply-templates select="$spec/contract/clause/head"/>
84
<xsl:call-template name="contract">
85
<xsl:with-param name="contract" select="$spec/contract"/>
102
<xsl:apply-templates select="$spec/contract/clause/head"/>
94
<xsl:template name="contract">
95
<xsl:param name="contract"/>
96
<xsl:call-template name="clause">
97
<xsl:with-param name="clause" select="$contract/clause"/>
108
<xsl:template match="head">
109
<fo:block xsl:use-attribute-sets="function-name">
110
<xsl:apply-templates/>
101
<xsl:template name="clause">
102
<xsl:param name="clause"/>
114
<!-- The *last* <name name="..." arity=".."/> -->
115
<xsl:template match="name" mode="types">
116
<xsl:variable name="name" select="@name"/>
117
<xsl:variable name="arity" select="@arity"/>
118
<xsl:variable name="spec0">
119
<xsl:call-template name="find_spec"/>
121
<xsl:variable name="spec" select="exsl:node-set($spec0)/spec"/>
122
<xsl:variable name="clause" select="$spec/contract/clause"/>
103
124
<xsl:variable name="type_desc" select="../type_desc"/>
104
<xsl:for-each select="$clause">
105
<xsl:apply-templates select="head"/>
106
<xsl:if test="count(guard) > 0">
107
<xsl:call-template name="guard">
108
<xsl:with-param name="guard" select="guard"/>
125
<!-- $type is data types to be presented as guards ("local types") -->
126
<xsl:variable name="type"
127
select="../type[string-length(@name) > 0
128
or string-length(@variable) > 0]"/>
129
<xsl:variable name="type_variables"
130
select ="$type[string-length(@variable) > 0]"/>
131
<xsl:variable name="local_types"
132
select ="$type[string-length(@name) > 0]"/>
133
<xsl:variable name="output_subtypes" select="count($type_variables) = 0"/>
135
<!-- It is assumed there is no support for overloaded specs
136
(there is no spec with more than one clause) -->
137
<xsl:if test="count($clause/guard) > 0 or count($type) > 0">
139
<xsl:text>Types:</xsl:text>
141
<fo:list-block xsl:use-attribute-sets="type-listblock">
143
<xsl:when test="$output_subtypes">
144
<xsl:call-template name="subtype">
145
<xsl:with-param name="subtype" select="$clause/guard/subtype"/>
146
<xsl:with-param name="type_desc" select="$type_desc"/>
147
<xsl:with-param name="local_types" select="$local_types"/>
151
<xsl:call-template name="type_variables">
152
<xsl:with-param name="type_variables" select="$type_variables"/>
153
<xsl:with-param name="type_desc" select="$type_desc"/>
154
<xsl:with-param name="local_types" select="$local_types"/>
155
<xsl:with-param name="fname" select="$name"/>
156
<xsl:with-param name="arity" select="$arity"/>
162
<xsl:call-template name="local_type">
109
163
<xsl:with-param name="type_desc" select="$type_desc"/>
164
<xsl:with-param name="local_types" select="$local_types"/>
170
<!-- Handle <type variable="..." name_i="..."/> -->
171
<xsl:template name="type_variables">
172
<xsl:param name="type_variables"/>
173
<xsl:param name="type_desc"/>
174
<xsl:param name="local_types"/>
175
<xsl:param name="fname"/>
176
<xsl:param name="arity"/>
178
<xsl:variable name="names" select="../name[string-length(@arity) > 0]"/>
179
<xsl:for-each select="$type_variables">
180
<xsl:variable name="name_i">
182
<xsl:when test="string-length(@name_i) > 0">
183
<xsl:value-of select="@name_i"/>
186
<xsl:value-of select="count($names)"/>
190
<xsl:variable name="spec0">
191
<xsl:for-each select="$names[position() = $name_i]">
192
<xsl:call-template name="find_spec"/>
195
<xsl:variable name="spec" select="exsl:node-set($spec0)/spec"/>
196
<xsl:variable name="clause" select="$spec/contract/clause"/>
197
<xsl:variable name="variable" select="@variable"/>
198
<xsl:variable name="subtype"
199
select="$clause/guard/subtype[typename = $variable]"/>
201
<xsl:if test="count($subtype) = 0">
202
<xsl:call-template name="err">
203
<xsl:with-param name="f" select="ancestor::erlref/module"/>
204
<xsl:with-param name="n" select="$fname"/>
205
<xsl:with-param name="a" select="$arity"/>
206
<xsl:with-param name="s">unknown type variable <xsl:value-of select="$variable"/>
110
208
</xsl:call-template>
115
<xsl:template match="head">
116
<fo:block xsl:use-attribute-sets="function-name">
117
<xsl:apply-templates/>
121
<xsl:template name="guard">
123
<xsl:text>Types:</xsl:text>
125
<fo:list-block xsl:use-attribute-sets="type-listblock">
126
211
<xsl:call-template name="subtype">
127
<xsl:with-param name="subtype" select="$guard/subtype"/>
128
<xsl:with-param name="type_desc" select="$type_desc"/>
212
<xsl:with-param name="subtype" select="$subtype"/>
213
<xsl:with-param name="type_desc" select="$type_desc"/>
129
214
</xsl:call-template>
219
<fo:block xsl:use-attribute-sets="function-name">
221
<fo:block font-weight="bold">
222
to get proper indentation (a monospace font)
133
224
<xsl:template name="subtype">
134
225
<xsl:param name="subtype"/>
135
226
<xsl:param name="type_desc"/>
136
228
<xsl:for-each select="$subtype">
137
229
<xsl:variable name="tname" select="typename"/>
138
<xsl:variable name="tdesc" select="$type_desc[@name = $tname]"/>
139
<fo:list-item xsl:use-attribute-sets="type-listitem">
140
<fo:list-item-label end-indent="label-end()">
143
</fo:list-item-label>
144
<fo:list-item-body start-indent="body-start()" format="justify">
145
<fo:block font-weight="bold">
146
<xsl:apply-templates select="string"/>
150
<xsl:apply-templates select="$type_desc[@name = $tname]"/>
230
<fo:list-item xsl:use-attribute-sets="type-listitem">
231
<fo:list-item-label end-indent="label-end()">
234
</fo:list-item-label>
235
<fo:list-item-body start-indent="body-start()" format="justify">
236
<fo:block xsl:use-attribute-sets="function-name">
237
<xsl:apply-templates select="string"/>
241
<xsl:apply-templates select="$type_desc[@variable = $tname]"/>
245
<xsl:template name="local_type">
246
<xsl:param name="type_desc"/>
247
<xsl:param name="local_types"/>
249
<xsl:for-each select="$local_types">
250
<fo:list-item xsl:use-attribute-sets="type-listitem">
251
<fo:list-item-label end-indent="label-end()">
254
</fo:list-item-label>
255
<fo:list-item-body start-indent="body-start()" format="justify">
256
<!-- <fo:block font-weight="bold">
257
(use function-name in "typehead" instead) -->
258
<xsl:call-template name="type_name">
259
<xsl:with-param name="mode" select="'local_type'"/>
264
<xsl:variable name="tname" select="@name"/>
265
<xsl:variable name="tnvars" select="@n_vars"/>
266
<xsl:apply-templates select=
267
"$type_desc[@name = $tname
268
and (@n_vars = $tnvars
269
or string-length(@n_vars) = 0 and
270
string-length($tnvars) = 0)]"/>
182
302
<xsl:apply-templates select="desc"/>
185
<!-- Like <head>... -->
186
<xsl:template match="typehead">
187
<fo:block xsl:use-attribute-sets="function-name">
188
<xsl:apply-templates/>
192
<!-- Like <guard>, except "Types:"... -->
193
<xsl:template match="local_defs">
194
<fo:list-block xsl:use-attribute-sets="type-listblock">
195
<xsl:apply-templates/>
199
<!-- Like <subtype>... -->
200
<xsl:template match="local_def">
201
<fo:list-item xsl:use-attribute-sets="type-listitem">
202
<fo:list-item-label end-indent="label-end()">
205
</fo:list-item-label>
206
<fo:list-item-body start-indent="body-start()" format="justify">
207
<fo:block font-weight="bold">
208
<xsl:apply-templates/>
214
305
<xsl:template name="type_name">
306
<xsl:param name="mode"/> <!-- '' if <datatype> -->
215
307
<xsl:variable name="curModule" select="ancestor::erlref/module"/>
216
308
<xsl:variable name="mod" select="@mod"/>
217
309
<xsl:variable name="name" select="@name"/>
218
<xsl:variable name="n_vars">
220
<xsl:when test="string-length(@n_vars) > 0">
221
<xsl:value-of select="@n_vars"/>
224
<xsl:value-of select="0"/>
310
<xsl:variable name="n_vars" select="@n_vars"/>
230
313
<xsl:when test="string-length($name) > 0">
231
314
<xsl:variable name="type" select=
232
315
"$i/specs/module[@name=$curModule]/type
233
[name=$name and n_vars=$n_vars
317
and (string-length($n_vars) = 0 or n_vars = $n_vars)
234
318
and (string-length($mod) = 0 or module = $mod)]"/>
236
320
<xsl:if test="count($type) != 1">
321
<xsl:variable name="why">
323
<xsl:when test="count($type) > 1">ambiguous type</xsl:when>
324
<xsl:when test="count($type) = 0">unknown type</xsl:when>
237
327
<xsl:call-template name="err">
328
<xsl:with-param name="f" select="$curModule"/>
238
329
<xsl:with-param name="m" select="$mod"/>
239
330
<xsl:with-param name="n" select="$name"/>
240
331
<xsl:with-param name="a" select="$n_vars"/>
241
<xsl:with-param name="s">unknown type</xsl:with-param>
332
<xsl:with-param name="s" select="$why"/>
242
333
</xsl:call-template>
244
<xsl:apply-templates select="$type/typedecl"/>
336
<xsl:when test="$mode = ''">
337
<xsl:apply-templates select="$type/typedecl"/>
339
<xsl:when test="$mode = 'local_type'">
340
<xsl:apply-templates select="$type/typedecl" mode="local_type"/>
247
345
<fo:inline font-weight="bold" xsl:use-attribute-sets="type-listitem">
352
<!-- Like <head>... -->
353
<xsl:template match="typehead">
354
<fo:block xsl:use-attribute-sets="function-name">
355
<xsl:apply-templates/>
360
<fo:block xsl:use-attribute-sets="function-name">
362
<fo:block font-weight="bold">
363
to get proper indentation (a monospace font)
366
<xsl:template match="typehead" mode="local_type">
367
<fo:block xsl:use-attribute-sets="function-name">
368
<xsl:apply-templates/>
372
<!-- Not used right now -->
373
<!-- Like <guard>, except "Types:"... -->
374
<xsl:template match="local_defs">
375
<fo:list-block xsl:use-attribute-sets="type-listblock">
376
<xsl:apply-templates/>
380
<!-- Like <subtype>... -->
381
<xsl:template match="local_def">
382
<fo:list-item xsl:use-attribute-sets="type-listitem">
383
<fo:list-item-label end-indent="label-end()">
386
</fo:list-item-label>
387
<fo:list-item-body start-indent="body-start()" format="justify">
388
<fo:block font-weight="bold">
389
<xsl:apply-templates/>
254
395
<!-- Used both in <datatype> and in <func>! -->
255
396
<xsl:template match="anno">
256
397
<xsl:variable name="curModule" select="ancestor::erlref/module"/>
257
398
<xsl:variable name="anno" select="normalize-space(text())"/>
258
399
<xsl:variable name="namespec"
259
select="ancestor::desc/preceding-sibling::name"/>
400
select="ancestor::type_desc/preceding-sibling::name
401
| ancestor::desc/preceding-sibling::name"/>
260
402
<xsl:if test="count($namespec) = 0 and string-length($specs_file) > 0">
261
403
<xsl:call-template name="err">
262
<xsl:with-param name="s">cannot find 'name' (<xsl:value-of select="$anno"/>)
267
<xsl:variable name="mod" select="$namespec/@mod"/>
268
<xsl:variable name="name" select="$namespec/@name"/>
269
<xsl:variable name="arity" select="$namespec/@arity"/>
270
<xsl:variable name="clause" select="$namespec/@clause"/>
271
<xsl:variable name="tmp_n_vars" select="$namespec/@n_vars"/>
272
<xsl:variable name="n_vars">
274
<xsl:when test="string-length($tmp_n_vars) > 0">
275
<xsl:value-of select="$tmp_n_vars"/>
278
<xsl:value-of select="0"/>
404
<xsl:with-param name="f" select="$curModule"/>
405
<xsl:with-param name="s">cannot find tag 'name' (anno <xsl:value-of select="$anno"/>)
410
<!-- Search "local types" as well -->
411
<xsl:variable name="local_types"
412
select="ancestor::desc/preceding-sibling::type
413
[string-length(@name) > 0]
414
| ancestor::type_desc/preceding-sibling::type
415
[string-length(@name) > 0]"/>
416
<xsl:variable name="has_anno_in_local_type">
417
<xsl:for-each select="$local_types">
418
<xsl:call-template name="anno_name">
419
<xsl:with-param name="curModule" select="$curModule"/>
420
<xsl:with-param name="anno" select="$anno"/>
425
<xsl:variable name="has_anno">
426
<xsl:for-each select="$namespec">
427
<xsl:call-template name="anno_name">
428
<xsl:with-param name="curModule" select="$curModule"/>
429
<xsl:with-param name="anno" select="$anno"/>
434
<xsl:if test="$has_anno = '' and $has_anno_in_local_type = ''">
435
<xsl:call-template name="err">
436
<xsl:with-param name="f" select="$curModule"/>
437
<xsl:with-param name="m" select="$namespec/@mod"/>
438
<xsl:with-param name="n" select="$namespec/@name"/>
439
<xsl:with-param name="a" select="'-'"/>
440
<xsl:with-param name="s">unknown annotation <xsl:value-of select="$anno"/>
444
<xsl:value-of select="$anno"/>
447
<xsl:template name="anno_name">
448
<xsl:param name="curModule"/>
449
<xsl:param name="anno"/>
450
<xsl:variable name="mod" select="@mod"/>
451
<xsl:variable name="name" select="@name"/>
452
<xsl:variable name="arity" select="@arity"/>
453
<xsl:variable name="n_vars" select="@n_vars"/>
454
<xsl:variable name="clause_i" select="@clause_i"/>
282
456
<xsl:variable name="spec0" select=
283
457
"$i/specs/module[@name=$curModule]/spec
284
458
[name=$name and arity=$arity
285
459
and (string-length($mod) = 0 or module = $mod)]"/>
286
460
<xsl:variable name="spec_annos" select=
287
"$spec0[string-length($clause) = 0
288
or position() = $clause]/anno[.=$anno]"/>
461
"$spec0[string-length($clause_i) = 0
462
or position() = $clause_i]/anno[.=$anno]"/>
289
463
<xsl:variable name="type_annos" select=
290
464
"$i/specs/module[@name=$curModule]/type
291
[name=$name and n_vars=$n_vars
466
and (string-length($n_vars) = 0 or n_vars=$n_vars)
292
467
and (string-length($mod) = 0 or module = $mod)]/anno[.=$anno]"/>
294
<xsl:if test="count($spec_annos) = 0
295
and count($type_annos) = 0
296
and string-length($specs_file) > 0">
297
<xsl:variable name="n">
299
<xsl:when test="string-length($arity) = 0">
300
<xsl:value-of select="$n_vars"/>
303
<xsl:value-of select="$arity"/>
307
<xsl:call-template name="err">
308
<xsl:with-param name="m" select="$mod"/>
309
<xsl:with-param name="n" select="$name"/>
310
<xsl:with-param name="a" select="$n"/>
311
<xsl:with-param name="s">unknown annotation <xsl:value-of select="$anno"/>
468
<xsl:if test="count($spec_annos) != 0
469
or count($type_annos) != 0
470
or string-length($specs_file) = 0">
471
<xsl:value-of select="true()"/>
315
<xsl:value-of select="$anno"/>
318
475
<!-- Used for indentation of formatted types and specs -->