File: AA-3-7.html

package info (click to toggle)
ada-reference-manual 20021112web-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 18,652 kB
  • ctags: 8,921
  • sloc: makefile: 52; sh: 20
file content (534 lines) | stat: -rw-r--r-- 39,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <TITLE>AARM95 - Discriminants</TITLE>
    <META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
    <META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
    <STYLE type="text/css">
    DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
    TT {font-family: "Courier New", monospace}
    DT {display: compact}
    DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
    DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
    DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
    DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
    DIV.Index {font-family: "Times New Roman", Times, serif}
    DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
    DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
    DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
    DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
    DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
    DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
    DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left:  10.0em; margin-bottom: 0.6em}
    DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
    DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
    DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
    DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
    DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left:  15.0em; margin-bottom: 0.6em}
    UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
    DD.Hanging {margin-left: 6.0em}
    DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.IndentedHanging {margin-left: 2.0em}
    DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.HangingInBulleted {margin-left: 4.0em}
    DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.SmallHanging {margin-left: 7.5em}
    DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.SmallIndentedHanging {margin-left: 2.0em}
    DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.SmallHangingInBulleted {margin-left: 5.0em}
    DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.Enumerated {margin-left: 2.0em}
    DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.SmallEnumerated {margin-left: 2.5em}
    DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    </STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-3-6-3.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-3-7-1.html">Next</A></P>
<HR>
<H1> 3.7 Discriminants</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;[<A NAME="I1910"></A> <A NAME="I1911"></A><A NAME="I1912"></A>A
composite type (other than an array type) can have discriminants, which
parameterize the type. A <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>
specifies the discriminants of a composite type. A discriminant of an
object is a component of the object, and is either of a discrete type
or an access type. An <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>
in the declaration of a partial view of a type specifies that the discriminants
of the type are unknown for the given view; all subtypes of such a partial
view are indefinite subtypes.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Glossary entry: </B>A discriminant
is a parameter of a composite type. It can control, for example, the
bounds of a component of the type if that type is an array type. A discriminant
of a task type can be used to pass data to a task of the type upon creation.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B><A NAME="I1913"></A><A NAME="I1914"></A>A
type, and all of its subtypes, have <I>unknown discriminants</I> when
the number or names of the discriminants, if any, are unknown at the
point of the type declaration. A <FONT FACE="Arial, Helvetica">discriminant_part</FONT>
of (&lt;&gt;) is used to indicate unknown discriminants. </FONT></DIV>

<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">discriminant_part<A NAME="I1915"></A>
::= </FONT><A NAME="I1916"></A><FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>&nbsp;|&nbsp;<A NAME="I1917"></A><FONT FACE="Arial, Helvetica">known_discriminant_part</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">unknown_discriminant_part<A NAME="I1918"></A>
::= </FONT>(&lt;&gt;)</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">known_discriminant_part<A NAME="I1919"></A>
::= </FONT><BR>
&nbsp;&nbsp;&nbsp;(<A NAME="I1920"></A><FONT FACE="Arial, Helvetica">discriminant_specification</FONT>&nbsp;{;&nbsp;<A NAME="I1921"></A><FONT FACE="Arial, Helvetica">discriminant_specification</FONT>})</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">discriminant_specification<A NAME="I1922"></A>
::= </FONT><BR>
&nbsp;&nbsp;&nbsp;<A NAME="I1923"></A><FONT FACE="Arial, Helvetica">defining_identifier_list</FONT>&nbsp;:&nbsp;<A NAME="I1924"></A><FONT FACE="Arial, Helvetica">subtype_mark</FONT>&nbsp;[:=&nbsp;<A NAME="I1925"></A><FONT FACE="Arial, Helvetica">default_expression</FONT>]<BR>
&nbsp;|&nbsp;<A NAME="I1926"></A><FONT FACE="Arial, Helvetica">defining_identifier_list</FONT>&nbsp;:&nbsp;<A NAME="I1927"></A><FONT FACE="Arial, Helvetica">access_definition</FONT>&nbsp;[:=&nbsp;<A NAME="I1928"></A><FONT FACE="Arial, Helvetica">default_expression</FONT>]</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">default_expression<A NAME="I1929"></A>
::= </FONT><A NAME="I1930"></A><FONT FACE="Arial, Helvetica">expression</FONT></DIV>

<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I1931"></A>The expected type for the
<FONT FACE="Arial, Helvetica">default_expression</FONT> of a <FONT FACE="Arial, Helvetica">discriminant_specification</FONT>
is that of the corresponding discriminant. </DIV>

<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8/1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<I><A HREF="defect1.html#8652/0007">8652/0007</A></I>}
A <U><FONT FACE="Arial, Helvetica">discriminant_part</FONT></U><S><FONT FACE="Arial, Helvetica">known_discriminant_part</FONT></S>
is only permitted in a declaration for a composite type that is not an
array type [(this includes generic formal types)]<U>. A</U><S>; a</S>
type declared with a <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>
is called a <I>discriminated</I> type,<A NAME="I1932"></A> as is a type
that inherits (known) discriminants. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Discriminants
on array types were considered, but were omitted to ease (existing) implementations.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Note that the
above definition for ``discriminated type'' does not include types declared
with an <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>.
This seems consistent with Ada 83, where such types (in a generic formal
part) would not be considered discriminated types. Furthermore, the full
type for a type with unknown discriminants need not even be composite,
much less have any discriminants.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.b.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>{<I><A HREF="defect1.html#8652/0007">8652/0007</A></I>}
<U>On the other hand, <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>s
cannot be applied to type declarations that cannot have a <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>.
There is no point in having unknown discriminants on a type that can
never have discriminants (for instance, a formal modular type), even
when these are allowed syntactically.</U> </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;The subtype of a discriminant may be defined by
a <FONT FACE="Arial, Helvetica">subtype_mark</FONT>, in which case the
<FONT FACE="Arial, Helvetica">subtype_mark</FONT> shall denote a discrete
or access subtype, or it may be defined by an <FONT FACE="Arial, Helvetica">access_definition</FONT>
[(in which case the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
of the <FONT FACE="Arial, Helvetica">access_definition</FONT> may denote
any kind of subtype)]. <A NAME="I1933"></A>A discriminant that is defined
by an <FONT FACE="Arial, Helvetica">access_definition</FONT> is called
an <I>access discriminant</I> and is of an anonymous general access-to-variable
type whose designated subtype is denoted by the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
of the <FONT FACE="Arial, Helvetica">access_definition</FONT>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>In an early version
of Ada 9X, we allowed access discriminants on nonlimited types, but this
created unpleasant complexities. It turned out to be simpler and more
uniform to allow discriminants of a named access type on any discriminated
type, and keep access discriminants just for limited types.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that discriminants of a named
access type are not considered ``access discriminants.''  Similarly,
``access parameter'' only refers to a formal parameter defined by an
<FONT FACE="Arial, Helvetica">access_definition</FONT>. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;A <FONT FACE="Arial, Helvetica">discriminant_specification</FONT>
for an access discriminant shall appear only in the declaration for a
task or protected type, or for a type with the reserved word <B>limited</B>
in its [(full)] definition or in that of one of its ancestors. In addition
to the places where Legality Rules normally apply (see <A HREF="AA-12-3.html">12.3</A>),
this rule applies also in the private part of an instance of a generic
unit. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This rule implies
that a type can have an access discriminant if the type is limited, but
not if the only reason it's limited is because of a limited component.
Compare with the definition of limited type in <A HREF="AA-7-5.html">7.5</A>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>It is a consequence
of this rule that only a return-by-reference type can have an access
discriminant (see <A HREF="AA-6-5.html">6.5</A>). This is important to
avoid dangling references to local variables. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.c</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Reason:
</B>We also considered the following rules: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.d</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>If a type has an access discriminant, this automatically
makes it limited, just like having a limited component automatically
makes a type limited. This was rejected because it decreases program
readability, and because it seemed error prone (two bugs in a previous
version of the RM9X were attributable to this rule).</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.e</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>A type with an access discriminant shall be limited. This
is equivalent to the rule we actually chose, except that it allows a
type to have an access discriminant if it is limited just because of
a limited component. For example, any record containing a task would
be allowed to have an access discriminant, whereas the actual rule requires
``<B>limited</B> <B>record</B>''. This rule was also rejected due to
readability concerns, and because would interact badly with the rules
for limited types that ``become nonlimited''. </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE="Arial, Helvetica">Default_expression</FONT>s
shall be provided either for all or for none of the discriminants of
a <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>. No <FONT FACE="Arial, Helvetica">default_expression</FONT>s
are permitted in a <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>
in a declaration of a tagged type [or a generic formal type]. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The all-or-none
rule is related to the rule that a discriminant constraint shall specify
values for all discriminants. One could imagine a different rule that
allowed a constraint to specify only some of the discriminants, with
the others provided by default. Having defaults for discriminants has
a special significance -- it allows objects of the type to be unconstrained,
with the discriminants alterable as part of assigning to the object.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Defaults for discriminants of
tagged types are disallowed so that every object of a tagged type is
constrained, either by an explicit constraint, or by its initial discriminant
values. This substantially simplifies the semantic rules and the implementation
of inherited dispatching operations. For generic formal types, the restriction
simplifies the type matching rules. If one simply wants a &quot;default&quot;
value for the discriminants, a constrained subtype can be declared for
future use. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;&nbsp;For a type defined
by a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>, if
a <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT> is provided
in its declaration, then: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>The parent subtype shall be constrained;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If the parent type is not a tagged type, then each discriminant
of the derived type shall be used in the constraint defining the parent
subtype;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>This
ensures that the new discriminant can share storage with an existing
discriminant.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If a discriminant is used in the constraint defining the
parent subtype, the subtype of the discriminant shall be statically compatible
(see <A HREF="AA-4-9-1.html">4.9.1</A>) with the subtype of the corresponding
parent discriminant. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>15.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This ensures that
on conversion (or extension via an extension aggregate) to a distantly
related type, if the discriminants satisfy the target type's requirements
they satisfy all the intermediate types' requirements as well. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>There is
no requirement that the new discriminant have the same (or any) <FONT FACE="Arial, Helvetica">default_expression</FONT>
as the parent's discriminant. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;The type of the <FONT FACE="Arial, Helvetica">default_expression</FONT>,
if any, for an access discriminant shall be convertible to the anonymous
access type of the discriminant (see <A HREF="AA-4-6.html">4.6</A>).
<A NAME="I1934"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This requires
convertibility of the designated subtypes. </FONT></DIV>

<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;A <FONT FACE="Arial, Helvetica">discriminant_specification</FONT>
declares a discriminant; the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
denotes its subtype unless it is an access discriminant, in which case
the discriminant's subtype is the anonymous access-to-variable subtype
defined by the <FONT FACE="Arial, Helvetica">access_definition</FONT>.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;[For a type defined by a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>,
each discriminant of the parent type is either inherited, constrained
to equal some new discriminant of the derived type, or constrained to
the value of an expression.] <A NAME="I1935"></A>When inherited or constrained
to equal some new discriminant, the parent discriminant and the discriminant
of the derived type are said to <I>correspond</I>. Two discriminants
also correspond if there is some common discriminant to which they both
correspond. A discriminant corresponds to itself as well. <A NAME="I1936"></A>If
a discriminant of a parent type is constrained to a specific value by
a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>, then
that discriminant is said to be <I>specified</I> by that <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The correspondence
relationship is transitive, symmetric, and reflexive. That is, if A corresponds
to B, and B corresponds to C, then A, B, and C each corresponds to A,
B, and C in all combinations.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I1937"></A>A <FONT FACE="Arial, Helvetica">constraint</FONT>
that appears within the definition of a discriminated type <I>depends
on a discriminant</I> of the type if it names the discriminant as a bound
or discriminant value. A <FONT FACE="Arial, Helvetica">component_definition</FONT>
depends on a discriminant if its <FONT FACE="Arial, Helvetica">constraint</FONT>
depends on the discriminant, or on a discriminant that corresponds to
it. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A <FONT FACE="Arial, Helvetica">constraint</FONT>
in a <FONT FACE="Arial, Helvetica">task_body</FONT> is not considered
to <I>depend</I> on a discriminant of the task type, even if it names
it. It is only the <FONT FACE="Arial, Helvetica">constraint</FONT>s in
the type definition itself that are considered dependents. Similarly
for protected types. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I1938"></A>A
component <I>depends on a discriminant</I> if: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>Its <FONT FACE="Arial, Helvetica">component_definition</FONT>
depends on the discriminant; or </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>21.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A component
does <I>not</I> depend on a discriminant just because its <FONT FACE="Arial, Helvetica">default_expression</FONT>
refers to the discriminant.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>It is declared in a <FONT FACE="Arial, Helvetica">variant_part</FONT>
that is governed by the discriminant; or</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>It is a component inherited as part of a <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>,
and the <FONT FACE="Arial, Helvetica">constraint</FONT> of the <I>parent_</I><FONT FACE="Arial, Helvetica">subtype_indication</FONT>
depends on the discriminant; or </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>23.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>When the parent
subtype depends on a discriminant, the parent part of the derived type
is treated like a discriminant-dependent component. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Because of
this rule, we don't really need to worry about ``corresponding'' discriminants,
since all the inherited components will be discriminant-dependent if
there is a new <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>
whose discriminants are used to constrain the old discriminants. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>It is a subcomponent of a component that depends on the
discriminant. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The concept of
discriminant-dependent (sub)components is primarily used in various rules
that disallow renaming or 'Access, or specify that certain discriminant-changing
assignments are erroneous. The goal is to allow implementations to move
around or change the size of discriminant-dependent subcomponents upon
a discriminant-changing assignment to an enclosing object. The above
definition specifies that all subcomponents of a discriminant-dependent
component or parent part are themselves discriminant-dependent, even
though their presence or size does not in fact depend on a discriminant.
This is because it is likely that they will move in a discriminant-changing
assignment if they are a component of one of several discriminant-dependent
parts of the same record. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;Each value of a discriminated type includes a
value for each component of the type that does not depend on a discriminant[;
this includes the discriminants themselves]. The values of discriminants
determine which other component values are present in the value of the
discriminated type. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>Which values
are present might depend on discriminants of some ancestor type that
are constrained in an intervening <FONT FACE="Arial, Helvetica">derived_type_definition</FONT>.
That's why we say &quot;values of discriminants&quot; instead of &quot;values
of <I>the</I> discriminants&quot; -- a subtle point.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I1939"></A><A NAME="I1940"></A><A NAME="I1941"></A><A NAME="I1942"></A>A
type declared with a <FONT FACE="Arial, Helvetica">known_discriminant_part</FONT>
is said to have <I>known discriminants</I>; its first subtype is unconstrained.
<A NAME="I1943"></A><A NAME="I1944"></A>A type declared with an <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>
is said to have <I>unknown discriminants</I>. A type declared without
a <FONT FACE="Arial, Helvetica">discriminant_part</FONT> has no discriminants,
unless it is a derived type; if derived, such a type has the same sort
of discriminants (known, unknown, or none) as its parent (or ancestor)
type. A tagged class-wide type also has unknown discriminants. <A NAME="I1945"></A><A NAME="I1946"></A>[Any
subtype of a type with unknown discriminants is an unconstrained and
indefinite subtype (see <A HREF="AA-3-2.html">3.2</A> and <A HREF="AA-3-3.html">3.3</A>).]
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>An <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>
``(&lt;&gt;)'' is only permitted in the declaration of a (generic or
nongeneric) private type, private extension, or formal derived type.
Hence, only such types, descendants thereof, and class-wide types can
have unknown discriminants. An <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>
is used to indicate that the corresponding actual or full type might
have discriminants without defaults, or be an unconstrained array subtype.
Tagged class-wide types are also considered to have unknown discriminants
because discriminants can be added by type extensions, so the total number
of discriminants of any given value of a tagged class-wide type is not
known at compile time.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>A subtype with unknown discriminants
is indefinite, and hence an object of such a subtype needs explicit initialization.
If the subtype is limited, no (stand-alone) objects can be declared since
initialization is not permitted (though formal parameters are permitted,
and objects of the actual/full type will generally be declarable). A
limited private type with unknown discriminants is ``extremely'' limited;
such a type is useful for keeping complete control over object creation
within the package declaring the type.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>A partial view of a type might
have unknown discriminants, while the full view of the same type might
have known, unknown, or no discriminants<U>.</U><S>,</S> </FONT></DIV>

<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>27</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;An <FONT FACE="Arial, Helvetica">access_definition</FONT>
is elaborated when the value of a corresponding access discriminant is
defined, either by evaluation of its <FONT FACE="Arial, Helvetica">default_expression</FONT>
or by elaboration of a <FONT FACE="Arial, Helvetica">discriminant_constraint</FONT>.
[The elaboration of an <FONT FACE="Arial, Helvetica">access_definition</FONT>
creates the anonymous access type. When the expression defining the access
discriminant is evaluated, it is converted to this anonymous access type
(see <A HREF="AA-4-6.html">4.6</A>).] <A NAME="I1947"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This conversion
raises Constraint_Error if the initial value is <B>null</B>, or, for
an object created by an allocator of an access type T, if the initial
value is an access parameter that designates a view whose accessibility
level is deeper than that of T.</FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>50&nbsp;&nbsp;If a discriminated type
has <FONT FACE="Arial, Helvetica">default_expression</FONT>s for its
discriminants, then unconstrained variables of the type are permitted,
and the values of the discriminants can be changed by an assignment to
such a variable. If defaults are not provided for the discriminants,
then all variables of the type are constrained, either by explicit constraint
or by their initial value; the values of the discriminants of such a
variable cannot be changed after initialization. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This connection
between discriminant defaults and unconstrained variables can be a source
of confusion. For Ada 95, we considered various ways to break the connection
between defaults and unconstrainedness, but ultimately gave up for lack
of a sufficiently simple and intuitive alternative.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I1948"></A>An unconstrained
discriminated subtype with defaults is called a <I>mutable</I> subtype,
and a variable of such a subtype is called a mutable variable, because
the discriminants of such a variable can change. There are no mutable
arrays (that is, the bounds of an array object can never change), because
there is no way in the language to define default values for the bounds.
Similarly, there are no mutable class-wide subtypes, because there is
no way to define the default tag, and defaults for discriminants are
not allowed in the tagged case. Mutable tags would also require a way
for the maximum possible size of such a class-wide subtype to be known.
(In some implementations, all mutable variables are allocated with the
maximum possible size. This approach is appropriate for real-time applications
where implicit use of the heap is inappropriate.)</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>51&nbsp;&nbsp;The <FONT FACE="Arial, Helvetica">default_expression</FONT>
for a discriminant of a type is evaluated when an object of an unconstrained
subtype of the type is created.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>52&nbsp;&nbsp;Assignment to a discriminant
of an object (after its initialization) is not allowed, since the name
of a discriminant is a constant; neither <FONT FACE="Arial, Helvetica">assignment_statement</FONT>s
nor assignments inherent in passing as an <B>in out</B> or <B>out</B>
parameter are allowed. Note however that the value of a discriminant
can be changed by assigning to the enclosing object, presuming it is
an unconstrained variable. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>An <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>
is permitted only in the declaration of a private type (including generic
formal private), private extension, or generic formal derived type. These
are the things that will have a corresponding completion or generic actual,
which will either define the discriminants, or say there are none. The
(&lt;&gt;) indicates that the actual/full subtype might be an indefinite
subtype. An <FONT FACE="Arial, Helvetica">unknown_discriminant_part</FONT>
is not permitted in a normal untagged derived type declaration, because
there is no separate full type declaration for such a type. Note that
(&lt;&gt;) allows unconstrained array bounds; those are somewhat like
undefaulted discriminants.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>For a derived type, either the
discriminants are inherited as is, or completely respecified in a new
<FONT FACE="Arial, Helvetica">discriminant_part</FONT>. In this latter
case, each discriminant of the parent type shall be constrained, either
to a specific value, or to equal one of the new discriminants. Constraining
a parent type's discriminant to equal one of the new discriminants is
like a renaming of the discriminant, except that the subtype of the new
discriminant can be more restrictive than that of the parent's one. In
any case, the new discriminant can share storage with the parent's discriminant.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>31</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>53&nbsp;&nbsp;A discriminant that is
of a named access type is not called an access discriminant; that term
is used only for discriminants defined by an <FONT FACE="Arial, Helvetica">access_definition</FONT>.
</FONT></DIV>

<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>32</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;&nbsp;<I>Examples of
discriminated types:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>33</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B>&nbsp;Buffer(Size&nbsp;:&nbsp;Buffer_Size&nbsp;:=&nbsp;100)&nbsp;&nbsp;<B>is</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I>--&nbsp;see&nbsp;<A HREF="AA-3-5-4.html">3.5.4</A></I><BR>
&nbsp;&nbsp;&nbsp;<B>record</B><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pos&nbsp;&nbsp;&nbsp;:&nbsp;Buffer_Size&nbsp;:=&nbsp;0;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Value&nbsp;:&nbsp;String(1&nbsp;..&nbsp;Size);<BR>
&nbsp;&nbsp;&nbsp;<B>end</B>&nbsp;<B>record</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>34</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B>&nbsp;Matrix_Rec(Rows,&nbsp;Columns&nbsp;:&nbsp;Integer)&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>record</B><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mat&nbsp;:&nbsp;Matrix(1&nbsp;..&nbsp;Rows,&nbsp;1&nbsp;..&nbsp;Columns);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I>--&nbsp;see&nbsp;<A HREF="AA-3-6.html">3.6</A></I><BR>
&nbsp;&nbsp;&nbsp;<B>end</B>&nbsp;<B>record</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B>&nbsp;Square(Side&nbsp;:&nbsp;Integer)&nbsp;<B>is</B>&nbsp;<B>new</B><BR>
&nbsp;&nbsp;&nbsp;Matrix_Rec(Rows&nbsp;=&gt;&nbsp;Side,&nbsp;Columns&nbsp;=&gt;&nbsp;Side);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>36</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B>&nbsp;Double_Square(Number&nbsp;:&nbsp;Integer)&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>record</B><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Left&nbsp;&nbsp;:&nbsp;Square(Number);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Right&nbsp;:&nbsp;Square(Number);<BR>
&nbsp;&nbsp;&nbsp;<B>end</B>&nbsp;<B>record</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B>&nbsp;Item(Number&nbsp;:&nbsp;Positive)&nbsp;<B>is</B><BR>
&nbsp;&nbsp;&nbsp;<B>record</B><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content&nbsp;:&nbsp;Integer;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I>--&nbsp;&nbsp;no&nbsp;component&nbsp;depends&nbsp;on&nbsp;the&nbsp;discriminant</I><BR>
&nbsp;&nbsp;&nbsp;<B>end</B>&nbsp;<B>record</B>;</TT></DIV>

<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>37.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I1949"></A>The syntax
for a <FONT FACE="Arial, Helvetica">discriminant_specification</FONT>
is modified to allow an <I>access discriminant</I>, with a type specified
by an <FONT FACE="Arial, Helvetica">access_definition</FONT> (see <A HREF="AA-3-10.html">3.10</A>).</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Discriminants are allowed on all
composite types other than array types.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Discriminants may be of an access
type. </FONT></DIV>

<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>37.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><FONT FACE="Arial, Helvetica">Discriminant_part</FONT>s
are not elaborated, though an <FONT FACE="Arial, Helvetica">access_definition</FONT>
is elaborated when the discriminant is initialized.</FONT></DIV>

<HR>
<P><A HREF="AA-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-3-6-3.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-3-7-1.html">Next</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>