File: AA-3-4-1.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 (254 lines) | stat: -rw-r--r-- 18,843 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <TITLE>AARM95 - Derivation Classes</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-4.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-3-5.html">Next</A></P>
<HR>
<H1> 3.4.1 Derivation Classes</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;In addition to the various language-defined classes
of types, types can be grouped into <I>derivation classes</I>. </DIV>

<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I1523"></A>A derived type is <I>derived
from</I> its parent type <I>directly</I>; it is derived <I>indirectly</I>
from any type from which its parent type is derived. <A NAME="I1524"></A><A NAME="I1525"></A><A NAME="I1526"></A>The
derivation class of types for a type <I>T</I> (also called the class
<I>rooted</I> at <I>T</I>) is the set consisting of <I>T</I> (the <I>root
type</I> of the class) and all types derived from <I>T</I> (directly
or indirectly) plus any associated universal or class-wide types (defined
below). </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Note that the
definition of ``derived from'' is a recursive definition. We don't define
a root type for all interesting language-defined classes, though presumably
we could. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>By the class-wide
type ``associated'' with a type <I>T</I>, we mean the type <I>T</I>'Class.
Similarly, the universal type associated with <I>root_integer</I>, <I>root_real</I>,
and <I>root_fixed</I> are <I>universal_integer</I>, <I>universal_real</I>,
and <I>universal_fixed</I>, respectively. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;Every type is either a <I>specific</I> type, a
<I>class-wide</I> type, or a <I>universal</I> type. <A NAME="I1527"></A>A
specific type is one defined by a <FONT FACE="Arial, Helvetica">type_declaration</FONT>,
a <FONT FACE="Arial, Helvetica">formal_type_declaration</FONT>, or a
full type definition embedded in a declaration for an object. Class-wide
and universal types are implicitly defined, to act as representatives
for an entire class of types, as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>The root
types <I>root_integer</I>, <I>root_real</I>, and <I>root_fixed</I> are
also specific types. They are declared in the specification of package
Standard. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DL Class="Hanging"><DT>&nbsp;&nbsp;&nbsp;<A NAME="I1528"></A>Class-wide types <DD Class="Hanging">
Class-wide types are defined for [(and belong to)] each derivation class
rooted at a tagged type (see <A HREF="AA-3-9.html">3.9</A>). Given a
subtype S of a tagged type <I>T</I>, S'Class is the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
for a corresponding subtype of the tagged class-wide type <I>T</I>'Class.
Such types are called ``class-wide'' because when a formal parameter
is defined to be of a class-wide type <I>T</I>'Class, an actual parameter
of any type in the derivation class rooted at <I>T</I> is acceptable
(see <A HREF="AA-8-6.html">8.6</A>).</DL>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DL Class="Hanging"><DD Class ="Hanging"><A NAME="I1529"></A>The set of values for a class-wide
type <I>T</I>'Class is the discriminated union of the set of values of
each specific type in the derivation class rooted at <I>T</I> (the tag
acts as the implicit discriminant -- see <A HREF="AA-3-9.html">3.9</A>).
Class-wide types have no primitive subprograms of their own. However,
as explained in <A HREF="AA-3-9-2.html">3.9.2</A>, operands of a class-wide
type <I>T</I>'Class can be used as part of a dispatching call on a primitive
subprogram of the type <I>T</I>. The only components [(including discriminants)]
of <I>T</I>'Class that are visible are those of <I>T</I>. If S is a first
subtype, then S'Class is a first subtype. </DL>
<DIV Class="Paranum"><FONT SIZE=-2>5.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>We want S'Class
to be a first subtype when S is, so that an <FONT FACE="Arial, Helvetica">attribute_definition_clause</FONT>
like ``<B>for</B> S'Class'Output <B>use</B> ...;'' will be legal. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DL Class="Hanging"><DT>&nbsp;&nbsp;&nbsp;<A NAME="I1530"></A>Universal types <DD Class="Hanging">
Universal types are defined for [(and belong to)] the integer, real,
and fixed point classes, and are referred to in this standard as respectively,
<I>universal_integer</I>, <I>universal_real</I>, and <I>universal_fixed</I>.
These are analogous to class-wide types for these language-defined numeric
classes. As with class-wide types, if a formal parameter is of a universal
type, then an actual parameter of any type in the corresponding class
is acceptable. In addition, a value of a universal type (including an
integer or real <FONT FACE="Arial, Helvetica">numeric_literal</FONT>)
is ``universal'' in that it is acceptable where some particular type
in the class is expected (see <A HREF="AA-8-6.html">8.6</A>).</DL>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DL Class="Hanging"><DD Class ="Hanging">The set of values of a universal type is the undiscriminated
union of the set of values possible for any definable type in the associated
class. Like class-wide types, universal types have no primitive subprograms
of their own. However, their ``universality'' allows them to be used
as operands with the primitive subprograms of any type in the corresponding
class. </DL>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>A class-wide
type is only class-wide in one direction, from specific to class-wide,
whereas a universal type is class-wide (universal) in both directions,
from specific to universal and back.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We considered defining class-wide
or perhaps universal types for all derivation classes, not just tagged
classes and these three numeric classes. However, this was felt to overly
weaken the strong-typing model in some situations. Tagged types preserve
strong type distinctions thanks to the run-time tag. Class-wide or universal
types for untagged types would weaken the compile-time type distinctions
without providing a compensating run-time-checkable distinction.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We considered defining standard
names for the universal numeric types so they could be used in formal
parameter specifications. However, this was felt to impose an undue implementation
burden for some implementations. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>Formally,
the set of values of a universal type is actually a <I>copy</I> of the
undiscriminated union of the values of the types in its class. This is
because we want each value to have exactly one type, with explicit or
implicit conversion needed to go between types. An alternative, consistent
model would be to associate a class, rather than a particular type, with
a value, even though any given expression would have a particular type.
In that case, implicit type conversions would not generally need to change
the value, although an associated subtype conversion might need to. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I1531"></A><A NAME="I1532"></A>The integer
and real numeric classes each have a specific root type in addition to
their universal type, named respectively <I>root_integer</I> and <I>root_real</I>.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I1533"></A>A class-wide or universal
type is said to <I>cover</I> all of the types in its class. A specific
type covers only itself.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I1534"></A>A specific type <I>T2</I>
is defined to be a <I>descendant</I> of a type <I>T1</I> if <I>T2</I>
is the same as <I>T1</I>, or if <I>T2</I> is derived (directly or indirectly)
from <I>T1</I>. A class-wide type <I>T2</I>'Class is defined to be a
descendant of type <I>T1</I> if <I>T2</I> is a descendant of <I>T1</I>.
Similarly, the universal types are defined to be descendants of the root
types of their classes. <A NAME="I1535"></A>If a type <I>T2</I> is a
descendant of a type <I>T1</I>, then <I>T1</I> is called an <I>ancestor</I>
of <I>T2</I>. <A NAME="I1536"></A><A NAME="I1537"></A>The <I>ultimate
ancestor</I> of a type is the ancestor of the type that is not a descendant
of any other type. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A specific
type is a descendant of itself. Class-wide types are considered descendants
of the corresponding specific type, and do not have any descendants of
their own.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>A specific type is an ancestor
of itself. The root of a derivation class is an ancestor of all types
in the class, including any class-wide types in the class. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.c</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Discussion:
</B>The terms root, parent, ancestor, and ultimate ancestor are all related.
For example: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.d</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Each type has at most one parent, and one or more ancestor
types; each type has exactly one ultimate ancestor. In Ada 83, the term
``parent type'' was sometimes used more generally to include any ancestor
type (e.g. RM83-9.4(14)). In Ada 95, we restrict parent to mean the immediate
ancestor.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.e</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>A class of types has at most one root type; a derivation
class has exactly one root type.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.f</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The root of a class is an ancestor of all of the types
in the class (including itself).</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.g</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The type <I>root_integer</I> is the root of the integer
class, and is the ultimate ancestor of all integer types. A similar statement
applies to <I>root_real</I>. </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I1538"></A>An inherited component [(including
an inherited discriminant)] of a derived type is inherited <I>from</I>
a given ancestor of the type if the corresponding component was inherited
by each derived type in the chain of derivations going back to the given
ancestor.</DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>18&nbsp;&nbsp;Because operands of a
universal type are acceptable to the predefined operators of any type
in their class, ambiguity can result. For <I>universal_integer</I> and
<I>universal_real</I>, this potential ambiguity is resolved by giving
a preference (see <A HREF="AA-8-6.html">8.6</A>) to the predefined operators
of the corresponding root types (<I>root_integer</I> and <I>root_real</I>,
respectively). Hence, in an apparently ambiguous expression like </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>1&nbsp;+&nbsp;4&nbsp;&lt;&nbsp;7</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>where each of the literals is of type
<I>universal_integer</I>, the predefined operators of <I>root_integer</I>
will be preferred over those of other specific integer types, thereby
resolving the ambiguity. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Except for
this preference, a root numeric type is essentially like any other specific
type in the associated numeric class. In particular, the result of a
predefined operator of a root numeric type is not ``universal'' (implicitly
convertible) even if both operands were. </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-4.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-3-5.html">Next</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>