File: RM-3-9-2.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 (243 lines) | stat: -rw-r--r-- 18,433 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <TITLE>Ada95 - 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="RM-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="RM-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="RM-3-9-1.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="RM-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">&nbsp;&nbsp;&nbsp;<A NAME="I1998"></A><A NAME="I1999"></A><A NAME="I2000"></A><A NAME="I2001"></A><A NAME="I2002"></A><A NAME="I2003"></A><A NAME="I2004"></A><A NAME="I2005"></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="I2006"></A><A NAME="I2007"></A><A NAME="I2008"></A><A NAME="I2009"></A><A NAME="I2010"></A></DIV>

<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I2011"></A><A NAME="I2012"></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="I2013"></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="I2014"></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="I2015"></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>3</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;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="I2016"></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>5</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2017"></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="I2018"></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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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. 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 is statically or dynamically tagged according to whether the
designated type of the type of the expression is specific or class-wide,
respectively. </DIV>

<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;A call on a dispatching operation shall not have
both dynamically tagged and statically tagged controlling operands. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9/1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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
object designated by the expression shall not be dynamically tagged unless
it is a controlling operand in a call on a dispatching operation. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10/1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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="RM-6-1.html">6.1</A>), it shall
statically match the first subtype of the tagged type. <A NAME="I2019"></A>If
the dispatching operation overrides an inherited subprogram, it shall
be subtype conformant with the inherited subprogram. <A NAME="I2020"></A>The
convention of an inherited or overriding dispatching operation is the
convention of the corresponding primitive operation of the parent type.
An explicitly declared dispatching operation shall not be of convention
Intrinsic. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;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>12</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;A given subprogram shall not be a dispatching
operation of two or more distinct tagged types. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;The explicit declaration of a primitive subprogram
of a tagged type shall occur before the type is frozen (see <A HREF="RM-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>

<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I2021"></A><A NAME="I2022"></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="I2023"></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="I2024"></A><A NAME="I2025"></A>If
there is more than one dynamically tagged controlling operand, a check
is made that they all have the same tag. <A NAME="I2026"></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>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="I2027"></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>20</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;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="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>70&nbsp;&nbsp;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&nbsp;&nbsp;This subclause covers
calls on primitive subprograms of a tagged type. Rules for tagged type
membership tests are described in <A HREF="RM-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="RM-5-2.html">5.2</A>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>72&nbsp;&nbsp;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&nbsp;&nbsp;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>

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