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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Dispatching Operations of Tagged 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-3-9-1.html">Previous</A> <A HREF="AA-3-9-3.html">Next</A></P>
<HR>
<H1> 3.9.2 Dispatching Operations of Tagged Types</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2089"></A><A NAME="I2090"></A><A NAME="I2091"></A><A NAME="I2092"></A><A NAME="I2093"></A><A NAME="I2094"></A><A NAME="I2095"></A><A NAME="I2096"></A>The
primitive subprograms of a tagged type are called <I>dispatching operations</I>.
[A dispatching operation can be called using a statically determined
<I>controlling</I> tag, in which case the body to be executed is determined
at compile time. Alternatively, the controlling tag can be dynamically
determined, in which case the call <I>dispatches</I> to a body that is
determined at run time;] such a call is termed a <I>dispatching call</I>.
[As explained below, the properties of the operands and the context of
a particular call on a dispatching operation determine how the controlling
tag is determined, and hence whether or not the call is a dispatching
call. Run-time polymorphism is achieved when a dispatching operation
is called by a dispatching call.] <A NAME="I2097"></A><A NAME="I2098"></A><A NAME="I2099"></A><A NAME="I2100"></A><A NAME="I2101"></A></DIV>
<H4 ALIGN=CENTER>Language Design Principles</H4>
<DIV Class="Paranum"><FONT SIZE=-2>1.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The controlling tag determination
rules are analogous to the overload resolution rules, except they deal
with run-time type identification (tags) rather than compile-time type
resolution. As with overload resolution, controlling tag determination
may depend on operands or result context. </FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2102"></A><A NAME="I2103"></A>A <I>call
on a dispatching operation</I> is a call whose <FONT FACE="Arial, Helvetica">name</FONT>
or <FONT FACE="Arial, Helvetica">prefix</FONT> denotes the declaration
of a primitive subprogram of a tagged type, that is, a dispatching operation.
<A NAME="I2104"></A>A <I>controlling operand</I> in a call on a dispatching
operation of a tagged type <I>T</I> is one whose corresponding formal
parameter is of type <I>T</I> or is of an anonymous access type with
designated type <I>T</I>; <A NAME="I2105"></A>the corresponding formal
parameter is called a <I>controlling formal parameter</I>. If the controlling
formal parameter is an access parameter, the controlling operand is the
object designated by the actual parameter, rather than the actual parameter
itself. <A NAME="I2106"></A>If the call is to a (primitive) function
with result type <I>T</I>, then the call has a <I>controlling result</I>
-- the context of the call can control the dispatching. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This definition
implies that a call through the dereference of an access-to-subprogram
value is never considered a call on a dispatching operation. Note also
that if the <FONT FACE="Arial, Helvetica">prefix</FONT> denotes a <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>,
the place where the renaming occurs determines whether it is primitive;
the thing being renamed is irrelevant. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> A <FONT FACE="Arial, Helvetica">name</FONT>
or expression of a tagged type is either <I>statically</I> tagged, <I>dynamically</I>
tagged, or <I>tag indeterminate</I>, according to whether, when used
as a controlling operand, the tag that controls dispatching is determined
statically by the operand's (specific) type, dynamically by its tag at
run time, or from context. A <FONT FACE="Arial, Helvetica">qualified_expression</FONT>
or parenthesized expression is statically, dynamically, or indeterminately
tagged according to its operand. For other kinds of <FONT FACE="Arial, Helvetica">name</FONT>s
and expressions, this is determined as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2107"></A>The <FONT FACE="Arial, Helvetica">name</FONT>
or expression is <I>statically tagged</I> if it is of a specific tagged
type and, if it is a call with a controlling result, it has at least
one statically tagged controlling operand; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>4.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>It is illegal
to have both statically tagged and dynamically tagged controlling operands
in the same call -- see below.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2108"></A>The <FONT FACE="Arial, Helvetica">name</FONT>
or expression is <I>dynamically tagged</I> if it is of a class-wide type,
or it is a call with a controlling result and at least one dynamically
tagged controlling operand;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2109"></A>The <FONT FACE="Arial, Helvetica">name</FONT>
or expression is <I>tag indeterminate</I> if it is a call with a controlling
result, all of whose controlling operands (if any) are tag indeterminate.
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0010">8652/0010</A></I>}
[A <FONT FACE="Arial, Helvetica">type_conversion</FONT> is statically
or dynamically tagged according to whether the type determined by the
<FONT FACE="Arial, Helvetica">subtype_mark</FONT> is specific or class-wide,
respectively.] <U>For an object that is designated by an expression whose
expected type is an anonymous access-to-specific tagged type, the object
is dynamically tagged if the expression, ignoring enclosing parentheses,
is of the form X'Access, where X is of a class-wide type, or is of the
form <B>new</B> T'(...), where T denotes a class-wide subtype. Otherwise,
the object</U><S>For a controlling operand that is designated by an actual
parameter, the controlling operand</S> is statically or dynamically tagged
according to whether the designated type <U>of the type of the expression</U><S>of
the actual parameter</S> is specific or class-wide, respectively. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A <FONT FACE="Arial, Helvetica">type_conversion</FONT>
is never tag indeterminate, even if its operand is. A designated object
is never tag indeterminate.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>{<I><A HREF="defect1.html#8652/0010">8652/0010</A></I>}
<U>Allocators and access attributes of specific types can be used as
the controlling parameters of dispatching calls.</U> </FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal"> A call on a dispatching operation shall not have
both dynamically tagged and statically tagged controlling operands. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This restriction
is intended to minimize confusion between whether the dynamically tagged
operands are implicitly converted to, or tag checked against the specific
type of the statically tagged operand(s). </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0010">8652/0010</A></I>}
If the expected type for an expression or <FONT FACE="Arial, Helvetica">name</FONT>
is some specific tagged type, then the expression or <FONT FACE="Arial, Helvetica">name</FONT>
shall not be dynamically tagged unless it is a controlling operand in
a call on a dispatching operation. Similarly, if the expected type for
an expression is an anonymous access-to-specific tagged type, then the
<U>object designated by the expression shall not be dynamically tagged
unless it is</U><S>expression shall not be of an access-to-class-wide
type unless it designates</S> a controlling operand in a call on a dispatching
operation. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This prevents implicit
"truncation" of a dynamically-tagged value to the specific
type of the target object/formal. An explicit conversion is required
to request this truncation. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This rule
applies to all expressions or <FONT FACE="Arial, Helvetica">name</FONT>s
with a specific expected type, not just those that are actual parameters
to a dispatching call. This rule does not apply to a membership test
whose <FONT FACE="Arial, Helvetica">expression</FONT> is class-wide,
since any type that covers the tested type is explicitly allowed. See
<A HREF="AA-4-5-2.html">4.5.2</A>. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0011">8652/0011</A></I>}
In the declaration of a dispatching operation of a tagged type, everywhere
a subtype of the tagged type appears as a subtype of the profile (see
<A HREF="AA-6-1.html">6.1</A>), it shall statically match the first subtype
of the tagged type. <A NAME="I2110"></A>If the dispatching operation
overrides an inherited subprogram, it shall be subtype conformant with
the inherited subprogram. <A NAME="I2111"></A><U>The convention of an
inherited or overriding dispatching operation is the convention of the
corresponding primitive operation of the parent type. An explicitly declared</U><S>A</S>
dispatching operation shall not be of convention Intrinsic.<S> If a dispatching
operation overrides the predefined equals operator, then it shall be
of convention Ada [(either explicitly or by default -- see <A HREF="AA-6-3-1.html">6.3.1</A>)].</S>
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>These rules ensure
that constraint checks can be performed by the caller in a dispatching
call, and parameter passing conventions match up properly. A special
rule on aggregates prevents values of a tagged type from being created
that are outside of its first subtype. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> The <FONT FACE="Arial, Helvetica">default_expression</FONT>
for a controlling formal parameter of a dispatching operation shall be
tag indeterminate. A controlling formal parameter that is an access parameter
shall not have a <FONT FACE="Arial, Helvetica">default_expression</FONT>.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The first part
ensures that the <FONT FACE="Arial, Helvetica">default_expression</FONT>
always produces the "correct" tag when called with or without
dispatching, or when inherited by a descendant. If it were statically
tagged, the default would be useless for a dispatching call; if it were
dynamically tagged, the default would be useless for a nondispatching
call.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The second part is consistent
with the first part, since designated objects are never tag-indeterminate.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal"> A given subprogram shall not be a dispatching
operation of two or more distinct tagged types. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This restriction
minimizes confusion since multiple dispatching is not provided. The normal
solution is to replace all but one of the tagged types with their class-wide
types. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>{<I><A HREF="defect2.html#8652/0098">8652/0098</A></I>}
<U>This restriction applies even if the partial view (see <A HREF="AA-7-3.html">7.3</A>)
of one or both of the types is untagged. This follows from the definition
of dispatching operation: the operation is a dispatching operation anywhere
the full views of the (tagged) types are visible.</U> </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Normal"> The explicit declaration of a primitive subprogram
of a tagged type shall occur before the type is frozen (see <A HREF="AA-13-14.html">13.14</A>).
[For example, new dispatching operations cannot be added after objects
or values of the type exist, nor after deriving a record extension from
it, nor after a body.]</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This rule is needed
because (1) we don't want people dispatching to things that haven't been
declared yet, and (2) we want to allow tagged type descriptors to be
static (allocated statically, and initialized to link-time-known symbols).
Suppose T2 inherits primitive P from T1, and then overrides P. Suppose
P is called <I>before</I> the declaration of the overriding P. What should
it dispatch to? If the answer is the new P, we've violated the first
principle above. If the answer is the old P, we've violated the second
principle. (A call to the new one necessarily raises Program_Error, but
that's beside the point.)</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that a call upon a dispatching
operation of type <I>T</I> will freeze <I>T</I>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We considered applying this rule
to all derived types, for uniformity. However, that would be upward incompatible,
so we rejected the idea. As in Ada 83, for an untagged type, the above
call upon P will call the old P (which is arguably confusing). </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Because
of this rule, the type descriptor can be created (presumably containing
linker symbols pointing at the not-yet-compiled bodies) at the first
freezing point of the type. It also prevents, for a tagged type declared
in a <FONT FACE="Arial, Helvetica">package_specification</FONT>, overriding
in the body or by a child subprogram. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A consequence
is that for a <FONT FACE="Arial, Helvetica">derived_type_declaration</FONT>
in a <FONT FACE="Arial, Helvetica">declarative_part</FONT>, only the
first primitive subprogram can be declared by a <FONT FACE="Arial, Helvetica">subprogram_body</FONT>.
</FONT></DIV>
<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I2112"></A><A NAME="I2113"></A>For
the execution of a call on a dispatching operation of a type <I>T</I>,
the <I>controlling tag value</I> determines which subprogram body is
executed. The controlling tag value is defined as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2114"></A>If one or more controlling operands
are statically tagged, then the controlling tag value is <I>statically
determined</I> to be the tag of <I>T</I>.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If one or more controlling operands are dynamically tagged,
then the controlling tag value is not statically determined, but is rather
determined by the tags of the controlling operands. <A NAME="I2115"></A><A NAME="I2116"></A>If
there is more than one dynamically tagged controlling operand, a check
is made that they all have the same tag. <A NAME="I2117"></A>If this
check fails, Constraint_Error is raised unless the call is a <FONT FACE="Arial, Helvetica">function_call</FONT>
whose <FONT FACE="Arial, Helvetica">name</FONT> denotes the declaration
of an equality operator (predefined or user defined) that returns Boolean,
in which case the result of the call is defined to indicate inequality,
and no <FONT FACE="Arial, Helvetica">subprogram_body</FONT> is executed.
This check is performed prior to evaluating any tag-indeterminate controlling
operands. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>16.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Tag mismatch is
considered an error (except for "=" and "/=") since
the corresponding primitive subprograms in each specific type expect
all controlling operands to be of the same type. For tag mismatch with
an equality operator, rather than raising an exception, "="
returns False and "/=" returns True. No equality operator is
actually invoked, since there is no common tag value to control the dispatch.
Equality is a special case to be consistent with the existing Ada 83
principle that equality comparisons, even between objects with different
constraints, never raise Constraint_Error. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>If all of the controlling operands are tag-indeterminate,
then: </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>If the call has a controlling result and is itself a (possibly
parenthesized or qualified) controlling operand of an enclosing call
on a dispatching operation of type <I>T</I>, then its controlling tag
value is determined by the controlling tag value of this enclosing call;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC><A NAME="I2118"></A>Otherwise, the controlling tag value
is statically determined to be the tag of type <I>T</I>. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>19.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This includes
the cases of a tag-indeterminate procedure call, and a tag-indeterminate
<FONT FACE="Arial, Helvetica">function_call</FONT> that is used to initialize
a class-wide formal parameter or class-wide object. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Normal"> For the execution of a call on a dispatching
operation, the body executed is the one for the corresponding primitive
subprogram of the specific type identified by the controlling tag value.
The body for an explicitly declared dispatching operation is the corresponding
explicit body for the subprogram. The body for an implicitly declared
dispatching operation that is overridden is the body for the overriding
subprogram, [even if the overriding occurs in a private part.] The body
for an inherited dispatching operation that is not overridden is the
body of the corresponding subprogram of the parent or ancestor type.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>In the unusual
case in which a dispatching subprogram is explicitly declared (overridden)
by a body (with no preceding <FONT FACE="Arial, Helvetica">subprogram_declaration</FONT>),
the body for that dispatching subprogram is that body; that is, the ``corresponding
explicit body'' in the above rule is the body itself. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.b</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Reason:
</B>The wording of the above rule is intended to ensure that the same
body is executed for a given tag, whether that tag is determined statically
or dynamically. For a type declared in a package, it doesn't matter whether
a given subprogram is overridden in the visible part or the private part,
and it doesn't matter whether the call is inside or outside the package.
For example: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.c</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>package</B> P1 <B>is</B><BR>
<B>type</B> T1 <B>is</B> <B>tagged</B> <B>null</B> <B>record</B>;<BR>
<B>procedure</B> Op_A(Arg : <B>in</B> T1);<BR>
<B>procedure</B> Op_B(Arg : <B>in</B> T1);<BR>
<B>end</B> P1;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.d</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>with</B> P1; <B>use</B> P1;<BR>
<B>package</B> P2 <B>is</B><BR>
<B>type</B> T2 <B>is</B> <B>new</B> T1 <B>with</B> <B>null</B> <B>record</B>;<BR>
<B>procedure</B> Op_A(Param : <B>in</B> T2);<BR>
<B>private</B><BR>
<B>procedure</B> Op_B(Param : <B>in</B> T2);<BR>
<B>end</B> P2;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.e/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>with</B> P1; <B>with</B> P2;<BR>
<B>procedure</B> Main <B>is</B><BR>
X : <U>P2.</U>T2;<BR>
Y : <U>P1.</U>T1'Class := X;<BR>
<B>begin</B><BR>
P2.Op_A(Param => X); --<I> Nondispatching call<U> to a dispatching operation</U>.</I><BR>
P1.Op_A(Arg => Y); --<I> Dispatching call.</I><BR>
P2.Op_B(Arg => X); --<I> Nondispatching call<U> to a dispatching operation</U>.</I><BR>
P1.Op_B(Arg => Y); --<I> Dispatching call.</I><BR>
<B>end</B> Main;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.f</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The two calls to Op_A both execute
the body of Op_A that has to occur in the body of package P2. Similarly,
the two calls to Op_B both execute the body of Op_B that has to occur
in the body of package P2, even though Op_B is overridden in the private
part of P2. Note, however, that the formal parameter names are different
for P2.Op_A versus P2.Op_B. The overriding declaration for P2.Op_B is
not visible in Main, so the name in the call actually denotes the implicit
declaration of Op_B inherited from T1.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>If a call occurs in the program
text before an overriding, which can happen only if the call is part
of a default expression, the overriding will still take effect for that
call.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.h</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Even
when a tag is not <I>statically determined</I>, a compiler might still
be able to figure it out and thereby avoid the overhead of run-time dispatching.</FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>70 The body to be executed
for a call on a dispatching operation is determined by the tag; it does
not matter whether that tag is determined statically or dynamically,
and it does not matter whether the subprogram's declaration is visible
at the place of the call.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>71 This subclause covers
calls on primitive subprograms of a tagged type. Rules for tagged type
membership tests are described in <A HREF="AA-4-5-2.html">4.5.2</A>.
Controlling tag determination for an <FONT FACE="Arial, Helvetica">assignment_statement</FONT>
is described in <A HREF="AA-5-2.html">5.2</A>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>72 A dispatching call can
dispatch to a body whose declaration is not visible at the place of the
call.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>73 A call through an access-to-subprogram
value is never a dispatching call, even if the access value designates
a dispatching operation. Similarly a call whose <FONT FACE="Arial, Helvetica">prefix</FONT>
denotes a <FONT FACE="Arial, Helvetica">subprogram_renaming_declaration</FONT>
cannot be a dispatching call unless the renaming itself is the declaration
of a primitive subprogram. </FONT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2119"></A>The concept
of dispatching operations is new. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-3-9-1.html">Previous</A> <A HREF="AA-3-9-3.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|