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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Formal Types</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> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-12-4.html">Previous</A> <A HREF="AA-12-5-1.html">Next</A></P>
<HR>
<H1> 12.5 Formal Types</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> [A generic formal subtype can be used to pass
to a generic unit a subtype whose type is in a certain class of types.]
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>We considered having
intermediate syntactic categories <FONT FACE="Arial, Helvetica">formal_integer_type_definition</FONT>,
<FONT FACE="Arial, Helvetica">formal_real_type_definition</FONT>, and
<FONT FACE="Arial, Helvetica">formal_fixed_point_definition</FONT>, to
be more uniform with the syntax rules for non-generic-formal types. However,
that would make the rules for formal types slightly more complicated,
and it would cause confusion, since <FONT FACE="Arial, Helvetica">formal_discrete_type_definition</FONT>
would not fit into the scheme very well. </FONT></DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">formal_type_declaration<A NAME="I4253"></A>
::= </FONT><BR>
<B>type</B> <A NAME="I4254"></A><FONT FACE="Arial, Helvetica">defining_identifier</FONT>[<A NAME="I4255"></A><FONT FACE="Arial, Helvetica">discriminant_part</FONT>] <B>is</B> <A NAME="I4256"></A><FONT FACE="Arial, Helvetica">formal_type_definition</FONT>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">formal_type_definition<A NAME="I4257"></A>
::= </FONT><BR>
<A NAME="I4258"></A><FONT FACE="Arial, Helvetica">formal_private_type_definition</FONT><BR>
| <A NAME="I4259"></A><FONT FACE="Arial, Helvetica">formal_derived_type_definition</FONT><BR>
| <A NAME="I4260"></A><FONT FACE="Arial, Helvetica">formal_discrete_type_definition</FONT><BR>
| <A NAME="I4261"></A><FONT FACE="Arial, Helvetica">formal_signed_integer_type_definition</FONT><BR>
| <A NAME="I4262"></A><FONT FACE="Arial, Helvetica">formal_modular_type_definition</FONT><BR>
| <A NAME="I4263"></A><FONT FACE="Arial, Helvetica">formal_floating_point_definition</FONT><BR>
| <A NAME="I4264"></A><FONT FACE="Arial, Helvetica">formal_ordinary_fixed_point_definition</FONT><BR>
| <A NAME="I4265"></A><FONT FACE="Arial, Helvetica">formal_decimal_fixed_point_definition</FONT><BR>
| <A NAME="I4266"></A><FONT FACE="Arial, Helvetica">formal_array_type_definition</FONT><BR>
| <A NAME="I4267"></A><FONT FACE="Arial, Helvetica">formal_access_type_definition</FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Normal"> <A NAME="I4268"></A><A NAME="I4269"></A><A NAME="I4270"></A><A NAME="I4271"></A>For
a generic formal subtype, the actual shall be a <FONT FACE="Arial, Helvetica">subtype_mark</FONT>;
it denotes the <I>(generic) actual subtype</I>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>When we say
simply ``formal'' or ``actual'' (for a generic formal that denotes a
subtype) we're talking about the subtype, not the type, since a name
that denotes a <FONT FACE="Arial, Helvetica">formal_type_declaration</FONT>
denotes a subtype, and the corresponding actual also denotes a subtype.
</FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Normal"> <A NAME="I4272"></A><A NAME="I4273"></A><A NAME="I4274"></A><A NAME="I4275"></A>A
<FONT FACE="Arial, Helvetica">formal_type_declaration</FONT> declares
a <I>(generic) formal type</I>, and its first subtype, the <I>(generic)
formal subtype</I>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A subtype
(other than the first subtype) of a generic formal type is not a generic
formal subtype. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal"> <A NAME="I4276"></A><A NAME="I4277"></A>The form
of a <FONT FACE="Arial, Helvetica">formal_type_definition</FONT> <I>determines
a class</I> to which the formal type belongs. For a <FONT FACE="Arial, Helvetica">formal_private_type_definition</FONT>
the reserved words <B>tagged</B> and <B>limited</B> indicate the class
(see <A HREF="AA-12-5-1.html">12.5.1</A>). For a <FONT FACE="Arial, Helvetica">formal_derived_type_definition</FONT>
the class is the derivation class rooted at the ancestor type. For other
formal types, the name of the syntactic category indicates the class;
a <FONT FACE="Arial, Helvetica">formal_discrete_type_definition</FONT>
defines a discrete type, and so on. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This rule is clearer
with the flat syntax rule for <FONT FACE="Arial, Helvetica">formal_type_definition</FONT>
given above. Adding <FONT FACE="Arial, Helvetica">formal_integer_type_definition</FONT>
and others would make this rule harder to state clearly. </FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal"> The actual type shall be in the class determined
for the formal. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>For example,
if the class determined for the formal is the class of all discrete types,
then the actual has to be discrete.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that this rule does not require
the actual to belong to every class to which the formal belongs. For
example, formal private types are in the class of composite types, but
the actual need not be composite. Furthermore, one can imagine an infinite
number of classes that are just arbitrary sets of types that obey the
closed-under-derivation rule, and are therefore technically classes (even
though we don't give them names, since they are uninteresting). We don't
want this rule to apply to <I>those</I> classes.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>``Limited'' is not a ``interesting''
class, but ``nonlimited'' is; it is legal to pass a nonlimited type to
a limited formal type, but not the other way around. The reserved word
<FONT FACE="Arial, Helvetica">limited</FONT> really represents a class
containing both limited and nonlimited types. ``Private'' is not a class;
a generic formal private type accepts both private and nonprivate actual
types.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>It is legal to pass a class-wide
subtype as the actual if it is in the right class, so long as the formal
has unknown discriminants. </FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0037">8652/0037</A></I>}
[The formal type also belongs to each class that contains the determined
class.] The primitive subprograms of the type are as for any type in
the determined class. For a formal type other than a formal derived type,
these are the predefined operators of the type<U>. For an elementary
formal type, the predefined operators are implicitly declared immediately
after the declaration of the formal type. For a composite formal type,
the predefined operators are implicitly declared either immediately after
the declaration of the formal type, or later in its immediate scope according
to the rules of <A HREF="AA-7-3-1.html">7.3.1</A>.</U><S>; they are implicitly
declared immediately after the declaration of the formal type.</S> In
an instance, the copy of such an implicit declaration declares a view
of the predefined operator of the actual type, even if this operator
has been overridden for the actual type. [The rules specific to formal
derived types are given in <A HREF="AA-12-5-1.html">12.5.1</A>.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>All properties
of the type are as for any type in the class. Some examples: The primitive
operations available are as defined by the language for each class. The
form of <FONT FACE="Arial, Helvetica">constraint</FONT> applicable to
a formal type in a <FONT FACE="Arial, Helvetica">subtype_indication</FONT>
depends on the class of the type as for a nonformal type. The formal
type is tagged if and only if it is declared as a tagged private type,
or as a type derived from a (visibly) tagged type. (Note that the actual
type might be tagged even if the formal type is not.) </FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>7 Generic formal types, like
all types, are not named. Instead, a <FONT FACE="Arial, Helvetica">name</FONT>
can denote a generic formal subtype. Within a generic unit, a generic
formal type is considered as being distinct from all other (formal or
nonformal) types. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Proof: </B>This follows from
the fact that each <FONT FACE="Arial, Helvetica">formal_type_declaration</FONT>
declares a type. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>8 A <FONT FACE="Arial, Helvetica">discriminant_part</FONT>
is allowed only for certain kinds of types, and therefore only for certain
kinds of generic formal types. See <A HREF="AA-3-7.html">3.7</A>. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The term
``formal floating point type'' refers to a type defined by a <FONT FACE="Arial, Helvetica">formal_floating_point_definition</FONT>.
It does not include a formal derived type whose ancestor is floating
point. Similar terminology applies to the other kinds of <FONT FACE="Arial, Helvetica">formal_type_definition</FONT>.
</FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
generic formal types:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B> Item <B>is</B> <B>private</B>;<BR>
<B>type</B> Buffer(Length : Natural) <B>is</B> <B>limited</B> <B>private</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B> Enum <B>is</B> (<>);<BR>
<B>type</B> Int <B>is</B> <B>range</B> <>;<BR>
<B>type</B> Angle <B>is</B> <B>delta</B> <>;<BR>
<B>type</B> Mass <B>is</B> <B>digits</B> <>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Examples"><TT><B>type</B> Table <B>is</B> <B>array</B> (Enum) <B>of</B> Item;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Wide" Style="margin-bottom: 0.4em"> <I>Example of a generic
formal part declaring a formal integer type:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Examples"><TT><B>generic</B><BR>
<B>type</B> Rank <B>is</B> <B>range</B> <>;<BR>
First : Rank := Rank'First;<BR>
Second : Rank := First + 1; --<I> the operator "+" of the type Rank </I></TT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>RM83 has separate sections ``Generic
Formal Xs'' and ``Matching Rules for Formal Xs'' (for various X's) with
most of the text redundant between the two. We have combined the two
in order to reduce the redundancy. In RM83, there is no ``Matching Rules
for Formal Types'' section; nor is there a ``Generic Formal Y Types''
section (for Y = Private, Scalar, Array, and Access). This causes, for
example, the duplication across all the ``Matching Rules for Y Types''
sections of the rule that the actual passed to a formal type shall be
a subtype; the new organization avoids that problem.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The matching rules are stated
more concisely.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We no longer consider the multiplying
operators that deliver a result of type <I>universal_fixed</I> to be
predefined for the various types; there is only one of each in package
Standard. Therefore, we need not mention them here as RM83 had to. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-12-4.html">Previous</A> <A HREF="AA-12-5-1.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|