Debian Codegraph @

source_2012/03c.mss

raw
1 @Part(03, Root="ada.mss")
2
3 @Comment{$Date: 2016/02/09 04:55:40 $}
4
5 @Comment{$Source: e:\\cvsroot/ARM/Source/03c.mss,v $}
6 @Comment{$Revision: 1.136 $}
7
8 @LabeledClause{Tagged Types and Type Extensions}
9
10 @begin{Intro}
11 @redundant[@PDefn{dispatching operation}
12 @Defn{polymorphism}
13 @IndexSee{Term=[dynamic binding],See=(dispatching operation)}
14 @IndexSeeAlso{Term=[generic unit],See=(dispatching operation)}
15 @IndexSeeAlso{Term=[variant],See=(tagged type)}
16 Tagged types and type extensions support
17 object-oriented programming, based on
18 inheritance with extension and run-time polymorphism via
19 @i(dispatching operations).
20 @IndexSee{Term=[object-oriented programming (OOP)],See=[tagged types and type extensions]}
21 @IndexSee{Term=[OOP (object-oriented programming)],See=[tagged types and type extensions]}
22 @IndexSeeAlso{Term=[inheritance],See=[tagged types and type extension]}]
23 @end{Intro}
24
25 @begin{MetaRules}
26 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
27 The intended implementation model is for @Chg{Version=[2],New=[the static
28 portion of ],Old=[]}a tag to be represented as a
29 pointer to a statically allocated and link-time initialized type
30 descriptor. The type descriptor contains the address of the code for
31 each primitive operation of the type. It probably also contains
32 other information, such as might make membership tests convenient and
33 efficient.@Chg{Version=[2],New=[ Tags for nested type extensions must also have
34 a dynamic part that identifies the particular elaboration of the type.],Old=[]}
35
36 The primitive operations of a tagged type are known at its first
37 freezing point; the type descriptor is laid out at that point.
38 It contains linker symbols for each primitive operation; the linker
39 fills in the actual addresses.
40
41 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
42 @ChgAdded{Version=[2],Text=[Primitive operations of type extensions that are
43 declared at a level deeper than the level of the ultimate ancestor from which
44 they are derived can
45 be represented by wrappers that use the dynamic part of the tag to call the
46 actual primitive operation. The dynamic part would generally be some way to
47 represent the static link or display necessary for making a nested call. One
48 implementation strategy would be to store that information in the extension
49 part of such nested type extensions, and use the dynamic part of the tag to
50 point at it. (That way, the @lquotes@;dynamic@rquotes@; part of the tag could
51 be static, at the cost of indirect access.)]}
52
53 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
54 @ChgAdded{Version=[2],Text=[If the tagged type is descended from any interface
55 types, it also will need to include @lquotes@;subtags@rquotes@; (one for
56 each interface) that describe the mapping of the primitive operations of the
57 interface to the primitives of the type. These subtags could directly reference
58 the primitive operations (for faster performance), or simply provide the tag
59 @lquotes@;slot@rquotes@; numbers for the primitive operations (for easier
60 derivation). In either case, the subtags would be used for calls that dispatch
61 through a class-wide type of the interface.]}
62
63 Other implementation models are possible.
64
65 The rules ensure that @lquotes@;dangling dispatching@rquotes@; is impossible;
66 that is, when a dispatching call is made, there is always a body to
67 execute. This is different from some other object-oriented
68 languages, such as Smalltalk, where it is possible to get a run-time
69 error from a missing method.
70
71 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
72 Dispatching calls should be efficient, and should have a bounded
73 worst-case execution time. This is important in a language intended
74 for real-time applications. In the intended implementation model, a
75 dispatching call involves calling indirect through the appropriate
76 slot in the dispatch table. No complicated "method lookup" is
77 involved@Chg{Version=[2],New=[ although a call which is dispatching on
78 an interface may require a lookup of the appropriate interface subtag],Old=[]}.
79
80 The programmer should have the choice at each call site of a
81 dispatching operation whether to do a dispatching call or a
82 statically determined call (i.e. whether the body executed should be
83 determined at run time or at compile time).
84
85 The same body should be executed for a call where the tag is
86 statically determined to be T'Tag as for a dispatching call where the
87 tag is found at run time to be T'Tag. This allows one to test a
88 given tagged type with statically determined calls, with some
89 confidence that run-time dispatching will produce the same behavior.
90
91 All views of a type should share the same type descriptor and the
92 same tag.
93
94 The visibility rules determine what is legal at compile time; they
95 have nothing to do with what bodies can be executed at run time.
96 Thus, it is possible to dispatch to a subprogram whose declaration is
97 not visible at the call site. In fact, this is one of the primary
98 facts that gives object-oriented programming its power. The
99 subprogram that ends up being dispatched to by a given call might
100 even be designed long after the call site has been coded and
101 compiled.
102
103 Given that Ada has overloading, determining whether a given
104 subprogram overrides another is based both on the names and the type
105 profiles of the operations.
106
107 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
108 When a type extension is declared, if there is any place within its
109 immediate scope where a certain subprogram of the parent
110 @Chg{Version=[2],New=[or progenitor ],Old=[]}is visible,
111 then a matching subprogram should override. If there is no such
112 place, then a matching subprogram should be totally unrelated, and
113 occupy a different slot in the type descriptor. This is important to
114 preserve the privacy of private parts; when an operation declared in
115 a private part is inherited, the inherited version can be overridden
116 only in that private part, in the package body, and in any children
117 of the package.
118
119 If an implementation shares code for instances
120 of generic bodies, it should be
121 allowed to share type descriptors of tagged types
122 declared in the generic body, so long as they are not extensions of types
123 declared in the specification of the generic unit.
124 @end{MetaRules}
125
126 @begin{StaticSem}
127 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
128 @Defn{tagged type}
129 A record type or private type that has the reserved word @key(tagged)
130 in its declaration is called a @i(tagged) type.@Chg{Version=[2],New=[ In
131 addition, an interface type is a tagged type, as is a task or protected
132 type derived from an interface (see @RefSecNum{Interface Types}).],Old=[]}
133 @Redundant[When deriving
134 from a tagged type, @Chg{Version=[2],New=[as],Old=[additional components
135 may be defined. As]} for any derived type,
136 additional primitive subprograms may be defined,
137 and inherited primitive subprograms may be overridden.]
138 @Defn{type extension}
139 @Defn2{Term=[extension], Sec=(of a type)}
140 The derived type is called an @i(extension)
141 of @Chg{Version=[2],New=[its],Old=[the]} ancestor
142 @Chg{Version=[2],New=[types],Old=[type]}, or simply a @i(type
143 extension).@Chg{Version=[2],New=[],Old=[ @Defn2{Term=[extension], Sec=(of a record type)}
144 @Defn{private extension}
145 @Defn2{Term=[extension], Sec=(of a private type)}
146 Every type extension is also a tagged type, and
147 is either a @i(record extension) or a @i(private extension) of
148 some other tagged type.
149 A record extension is defined by a @nt<derived_type_definition>
150 with a @nt<record_extension_part>.
151 A private extension, which is a partial view of a record extension,
152 can be declared in the visible part of a package
153 (see @RefSecNum(Private Types and Private Extensions))
154 or in a generic formal part
155 (see @RefSecNum(Formal Private and Derived Types)).]}
156
157 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
158 @ChgAdded{Version=[2],Text=[@Defn2{Term=[extension], Sec=(of a record type)}
159 @Defn{private extension}
160 @Defn2{Term=[extension], Sec=(of a private type)}
161 Every type extension is also a tagged type, and
162 is a @i(record extension) or a @i(private extension) of some other
163 tagged type, or a noninterface synchronized tagged type (see
164 @RefSecNum{Interface Types}).
165 A record extension is defined by a @nt<derived_type_definition>
166 with a @nt<record_extension_part> (see @RefSecNum{Type Extensions})@Redundant[,
167 which may include the definition of additional components].
168 A private extension, which is a partial view of a record extension or
169 of a synchronized tagged type,
170 can be declared in the visible part of a package
171 (see @RefSecNum(Private Types and Private Extensions))
172 or in a generic formal part
173 (see @RefSecNum(Formal Private and Derived Types)).]}
174 @ToGlossary{Term=<Tagged type>,
175 Text=<The objects of a tagged type have a run-time type tag,
176 which indicates the specific type with which the object was originally
177 created.
178 An operand of a class-wide tagged type
179 can be used in a dispatching call;
180 the tag indicates which subprogram body to invoke.
181 Nondispatching calls, in which the subprogram body to invoke
182 is determined at compile time, are also allowed.
183 Tagged types may be extended with additional components.>}
184 @begin{Ramification}
185 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]}
186 If a tagged type is declared other than in a @nt{package_specification},
187 it is impossible to add new primitive subprograms for that type,
188 although it can inherit primitive subprograms,
189 and those can be overridden.
190 If the user incorrectly thinks a certain subprogram is primitive when it
191 is not, and tries to call it with a dispatching call, an error message
192 will be given at the call site.@Chg{Version=[2],New=[ Similarly, by using
193 an @nt{overriding_indicator} (see @RefSecNum{Subprogram Declarations}),
194 the user can declare that a subprogram is intended to be overriding, and
195 get an error message when they made a mistake. The use of
196 @nt{overriding_indicator}s is highly recommended in new code that does not
197 need to be compatible with Ada 95.],Old=[]}
198
199 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00344-01]}
200 @ChgDeleted{Version=[2],Text=[Note that the accessibility rules imply that a
201 tagged type declared in a library @nt{package_specification} cannot be
202 extended in a nested subprogram or task body.]}
203 @end{Ramification}
204
205 @Defn{tag of an object}
206 An object of a tagged type has an associated (run-time)
207 @i(tag) that identifies the specific tagged type used to create
208 the object originally.
209 @Redundant[
210 The tag of an operand of a class-wide tagged type @i(T)'Class
211 controls which subprogram body is to be executed when a
212 primitive subprogram of type @i(T) is applied to
213 the operand
214 (see @RefSecNum(Dispatching Operations of Tagged Types));
215 @Defn{dispatching}
216 using a tag to control which body to execute is called @i(dispatching).]
217 @IndexSee{Term=[type tag],See=[tag]}
218 @IndexSee{Term=[run-time type],See=[tag]}
219 @IndexSeeAlso{Term=[type],See=[tag]}
220 @IndexSeeAlso{Term=[class],See=[tag]}
221
222 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
223 The tag of a specific tagged type identifies
224 the @nt<full_type_declaration> of the type@Chg{Version=[2],New=[, and
225 for a type extension, is sufficient to uniquely identify the type among
226 all descendants of the same ancestor],Old=[]}.
227 If a declaration for a tagged type occurs within a
228 @nt{generic_package_declaration},
229 then the corresponding type declarations in distinct
230 instances of the generic package are associated with distinct tags.
231 For a tagged type that is local to a generic package body@Chg{Version=[2],
232 New=[ and with all of its ancestors (if any) also local to the
233 generic body],Old=[]},
234 the language does not specify whether repeated instantiations
235 of the generic body result in distinct tags.@PDefn{Unspecified}
236 @begin{Reason}
237 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00344-01]}
238 @ChgDeleted{Version=[2],Text=[This eases generic code sharing.]}
239 @end{reason}
240
241 @begin{ImplNote}
242 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
243 @ChgAdded{Version=[2],Text=[In most cases, a tag need only identify a particular
244 tagged type declaration, and can therefore be a simple link-time-known
245 address. However, for tag checks
246 (see @RefSecNum{Dispatching Operations of Tagged Types}) it is essential
247 that each descendant (that currently exists) of a given type have
248 a unique tag. Hence, for types declared in shared generic bodies
249 where an ancestor comes from outside the generic, or for types
250 declared at a deeper level than an ancestor, the tag needs to be
251 augmented with some kind of dynamic descriptor (which may be a
252 static link, global display, instance descriptor pointer, or combination).
253 This implies that type Tag may need to be two words, the second of which
254 is normally null, but in these identified special cases needs to
255 include a static link or equivalent. Within an object of one of
256 these types with a two-word tag, the two parts of the tag would
257 typically be separated, one part as the first word of the object,
258 the second placed in the first extension part that corresponds to a
259 type declared more nested than its parent or declared in a shared
260 generic body when the parent is declared outside. Alternatively,
261 by using an extra level of indirection, the type Tag could remain
262 a single-word.]}
263
264 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
265 @Chg{Version=[2],New=[For types that are not type extensions (even
266 for ones declared in nested scopes), we do not require that],
267 Old=[The language does not specify whether]}
268 repeated elaborations of the same @nt<full_type_declaration>
269 correspond to distinct tags. @Chg{Version=[2],New=[This was done so that
270 Ada 2005 implementations of tagged types could maintain representation
271 compatibility with Ada 95 implementations. Only type extensions that were
272 not allowed in Ada 95 require additional information with the tag.],
273 Old=[In most cases, we
274 expect that all elaborations will correspond to the same tag,
275 since the tag will frequently be the address (or index) of a statically
276 allocated type descriptor. However, with shared
277 generics, the type descriptor might have to be allocated on a per-instance
278 basis, which in some implementation models implies per-elaboration of the
279 instantiation.]}
280 @end{implnote}
281
282 @begin{Honest}
283 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
284 @ChgAdded{Version=[2],Text=[The wording @lquotes@;is sufficient to uniquely
285 identify the type among all descendants of the same ancestor@rquotes@; only
286 applies to types that currently exist. It is not necessary to distinguish
287 between descendants that currently exist, and descendants of the same type
288 that no longer exist.
289 For instance, the address of the stack frame of the subprogram that created
290 the tag is sufficient to meet the requirements of this rule, even though
291 it is possible, after the subprogram returns, that a later call of the
292 subprogram could have the same stack frame and thus have an identical tag.]}
293 @end{Honest}
294
295 @Leading@keepnext@;The following language-defined library package exists:
296 @begin{Example}
297 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
298 @ChildUnit{Parent=[Ada],Child=[Tags]}@key[package] Ada.Tags @key[is]
299 @Chg{Version=[2],New=[@key[pragma] Preelaborate(Tags);
300 ],Old=[]}@key[type] @AdaTypeDefn{Tag} @key[is] @key[private];@Chg{Version=[2],New=[
301 @key[pragma] Preelaborable_Initialization(Tag);],Old=[]}
302
303 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
304 @ChgAdded{Version=[2],Text=[ @AdaObjDefn{No_Tag} : @key[constant] Tag;]}
305
306 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00400-01]}
307 @key[function] @AdaSubDefn{Expanded_Name}(T : Tag) @key[return] String;@Chg{Version=[2],New=[
308 @key[function] @AdaSubDefn{Wide_Expanded_Name}(T : Tag) @key[return] Wide_String;
309 @key[function] @AdaSubDefn{Wide_Wide_Expanded_Name}(T : Tag) @key[return] Wide_Wide_String;],Old=[]}
310 @key[function] @AdaSubDefn{External_Tag}(T : Tag) @key[return] String;
311 @key[function] @AdaSubDefn{Internal_Tag}(External : String) @key[return] Tag;
312
313 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
314 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Descendant_Tag}(External : String; Ancestor : Tag) @key[return] Tag;
315 @key[function] @AdaSubDefn{Is_Descendant_At_Same_Level}(Descendant, Ancestor : Tag)
316 @key[return] Boolean;]}
317
318 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
319 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Parent_Tag} (T : Tag) @key[return] Tag;]}
320
321 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00405-01]}
322 @ChgAdded{Version=[2],Text=[ @key[type] @AdaTypeDefn{Tag_Array} @key[is array] (Positive @key[range] <>) @key[of] Tag;]}
323
324 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00405-01]}
325 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Interface_Ancestor_Tags} (T : Tag) @key[return] Tag_Array;]}
326
327 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0173-1]}
328 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Is_Abstract} (T : Tag) @key[return] Boolean;]}
329
330 @AdaExcDefn{Tag_Error} : @key[exception];
331
332 @key[private]
333 ... -- @RI{not specified by the language}
334 @key[end] Ada.Tags;
335 @end{Example}
336 @begin{Reason}
337 Tag is a nonlimited, definite subtype,
338 because it needs the equality operators,
339 so that tag checking makes sense.
340 Also, equality, assignment, and object declaration
341 are all useful capabilities for this subtype.
342
343 For an object X and a type T,
344 @lquotes@;X'Tag = T'Tag@rquotes@; is not needed,
345 because a membership test can be used.
346 However, comparing the tags of two objects
347 cannot be done via membership.
348 This is one reason to allow equality for type Tag.
349 @end{Reason}
350
351 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
352 @ChgAdded{Version=[2],Text=[No_Tag is the default initial value of type Tag.]}
353 @begin{Reason}
354 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
355 @ChgAdded{Version=[2],Text=[This is similar to the requirement that all
356 access values be initialized to @key[null].]}
357 @end{Reason}
358
359 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00400-01]}
360 The function @Chg{Version=[2],New=[Wide_@!Wide_@!Expanded_@!Name],
361 Old=[Expanded_@!Name]} returns the full expanded name of the
362 first subtype of the specific type identified by the tag,
363 in upper case, starting with a root library unit.
364 The result is implementation defined if the type is declared within
365 an unnamed @nt{block_statement}.
366 @begin{Honest}
367 This name, as well as each @nt{prefix} of it,
368 does not denote a @nt{renaming_declaration}.
369 @end{Honest}
370 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
371 Text=[The result of @Chg{Version=[2],
372 New=[Tags.Wide_@!Wide_@!Expanded_@!Name],Old=[Tags.Expanded_@!Name]} for types
373 declared within an unnamed @nt{block_statement}.]}
374
375 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00400-01]}
376 @ChgAdded{Version=[2],Text=[The function Expanded_Name (respectively,
377 Wide_Expanded_Name) returns the same sequence of graphic characters as that
378 defined for Wide_Wide_Expanded_Name, if all the graphic characters are defined
379 in Character (respectively, Wide_Character); otherwise, the sequence of
380 characters is implementation defined, but no shorter than that returned by
381 Wide_Wide_Expanded_Name for the same value of the argument.]}
382 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@Chg{Version=[2],New=[
383 The sequence of characters of the value returned by Tags.Expanded_Name
384 (respectively, Tags.Wide_Expanded_Name)
385 when some of the graphic characters of Tags.Wide_Wide_Expanded_Name are not
386 defined in Character (respectively, Wide_Character).],Old=[]}]}
387
388 The function External_Tag returns a string to be used in an
389 external representation for the given tag. The call External_Tag(S'Tag)
390 is equivalent to the @nt<attribute_reference> S'External_Tag
391 (see @RefSecNum{Operational and Representation Attributes}).
392 @begin{Reason}
393 It might seem redundant to provide both the function External_Tag and
394 the attribute External_Tag.
395 The function is needed because the attribute can't be applied to
396 values of type Tag.
397 The attribute is needed so that it can be @Chg{Version=[2],
398 New=[specified],Old=[specifiable]}
399 via an @nt{attribute_definition_clause}.
400 @end{Reason}
401
402 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00417-01]}
403 @ChgAdded{Version=[2],Text=[The string returned by the functions Expanded_Name,
404 Wide_@!Expanded_@!Name, Wide_Wide_@!Expanded_@!Name, and External_Tag has lower bound
405 1.]}
406
407 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00279-01]}
408 The function Internal_Tag returns @Chg{Version=[2],New=[a],Old=[the]} tag that
409 corresponds to the given external tag, or raises Tag_Error if the given string
410 is not the external tag for any specific
411 type of the partition.@Chg{Version=[2],New=[ Tag_Error is also raised
412 if the specific type identified is a library-level type whose tag
413 has not yet been created (see @RefSecNum{Freezing Rules}).],Old=[]}
414
415 @begin{Reason}
416 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
417 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
418 @ChgAdded{Version=[2],Text=[The check for uncreated library-level types
419 prevents a reference to the type before execution reaches the freezing point
420 of the type. This is important so that T'Class'Input or an instance of
421 Tags.Generic_Dispatching_Constructor do not try to create an object of a type
422 that hasn't been frozen (which @Chg{Version=[3],New=[might],Old=[may]}
423 not have yet elaborated its constraints).
424 We don't require this behavior for non-library-level types as the tag can
425 be created multiple times and possibly multiple copies can exist at the
426 same time, making the check complex.]}
427 @end{Reason}
428
429 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
430 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0113-1]}
431 @ChgAdded{Version=[2],Text=[The function Descendant_Tag returns the (internal)
432 tag for the type that corresponds to the given external tag and is both a
433 descendant of the type identified by the Ancestor tag and has the same
434 accessibility level as the identified ancestor. Tag_Error is raised if External
435 is not the external tag for such a type. Tag_Error is also raised if the
436 specific type identified is a library-level type whose tag has not yet been
437 created@Chg{Version=[3],New=[, or if the given external tag identifies more than
438 one type that has the appropriate Ancestor and accessibility level],Old=[]}.]}
439
440 @begin{Reason}
441 @ChgRef{Version=[2],Kind=[AddedNormal]}
442 @ChgAdded{Version=[2],Text=[Descendant_Tag is used by T'Class'Input to
443 identify the type identified by an external tag. Because there can be
444 multiple elaborations of a given type declaration, Internal_Tag does not
445 have enough information to choose a unique such type. Descendant_Tag does
446 not return the tag for types declared at deeper accessibility levels than
447 the ancestor because there could be ambiguity in the presence of
448 recursion or multiple tasks. Descendant_Tag can
449 be used in constructing a user-defined replacement for T'Class'Input.]}
450
451 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0113-1]}
452 @ChgAdded{Version=[3],Text=[Rules for specifying external tags will usually
453 prevent an external tag from identifying more than one type. However, an
454 external tag can identify multiple types if a generic body contains a
455 derivation of a tagged type declared outside of the generic, and there are
456 multiple instances at the same accessibility level as the type. (The Standard
457 allows default external tags to not be unique in this case.)]}
458 @end{Reason}
459
460 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
461 @ChgAdded{Version=[2],Text=[The function Is_Descendant_At_Same_Level returns
462 True if the Descendant tag identifies a type that is both a descendant of the
463 type identified by Ancestor and at the same accessibility level. If not, it
464 returns False.]}
465
466 @begin{Reason}
467 @ChgRef{Version=[2],Kind=[AddedNormal]}
468 @ChgAdded{Version=[2],Text=[Is_Descendant_At_Same_Level (or something similar
469 to it) is used by T'Class'Output to determine whether the item being
470 written is at the same accessibility level as T. It may be used to
471 determine prior to using T'Class'Output whether Tag_Error will be raised,
472 and also can be used in constructing a user-defined replacement
473 for T'Class'Output.]}
474 @end{Reason}
475
476 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0115-1]}
477 @ChgAdded{Version=[3],Text=[For the purposes of the dynamic semantics of
478 functions Descendant_Tag and Is_Descendant_At_Same_Level, a tagged type T2
479 is a @i<descendant> of
480 a type T1 if it is the same as T1, or if its parent type or one of its
481 progenitor types is a descendant of type T1 by this rule@Redundant[,
482 even if at the point of the declaration of T2, one of the derivations
483 in the chain is not visible].@Defn2{Term=[descendant],Sec=[at run-time]}]}
484
485 @begin{Discussion}
486 @ChgRef{Version=[3],Kind=[Added]}
487 @ChgAdded{Version=[3],Text=[In other contexts, @ldquote@;descendant@rdquote
488 is dependent on visibility, and the particular view a derived type has of
489 its parent type. See @RefSecNum{Private Operations}.]}
490 @end{Discussion}
491
492 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
493 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
494 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0056-1]}
495 @ChgAdded{Version=[2],Text=[The function Parent_Tag returns the tag of the
496 parent type of the type whose tag is T. If the type does not have a parent type
497 (that is, it was not @Chg{Version=[4],New=[defined],Old=[declared]} by a
498 @Chg{Version=[4],New=[@nt{derived_type_definition}],Old=[derived_type_declaration]}),
499 then No_Tag is returned.]}
500
501 @begin{Ramification}
502 @ChgRef{Version=[2],Kind=[AddedNormal]}
503 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
504 @ChgAdded{Version=[2],Text=[The parent type is always the parent of the full
505 type; a private extension appears to define a parent type, but it does not
506 (only the various forms of derivation do that). As this is a run-time
507 operation, ignoring @Chg{Version=[4],New=[privacy],Old=[privateness]} is OK.]}
508 @end{Ramification}
509
510 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00405-01]}
511 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Paragraph number changed}
512 @ChgAdded{Version=[2],Text=[The function Interface_Ancestor_Tags returns an
513 array containing the tag of each interface ancestor type of the type whose tag
514 is T, other than T itself. The lower bound of the returned array is 1, and the
515 order of the returned tags is unspecified. Each tag appears in the result
516 exactly once.@Redundant[ If the type whose tag is T has no interface ancestors,
517 a null array is returned.]]}@PDefn{Unspecified}
518
519 @begin{Ramification}
520 @ChgRef{Version=[2],Kind=[AddedNormal]}
521 @ChgAdded{Version=[2],Text=[The result of Interface_Ancestor_Tags includes the
522 tag of the parent type, if the parent is an interface.]}
523
524 @ChgRef{Version=[2],Kind=[AddedNormal]}
525 @ChgAdded{Version=[2],Text=[Indirect interface ancestors are included in the
526 result of Interface_Ancestor_Tags. That's because where an interface appears
527 in the derivation tree has no effect on the semantics of the type; the only
528 interesting property is whether the type has an interface as an ancestor.]}
529 @end{Ramification}
530
531 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0173-1]}
532 @ChgAdded{Version=[3],Text=[The function Is_Abstract returns True if the type
533 whose tag is T is abstract, and False otherwise.]}
534
535 For @PrefixType{every subtype S of a tagged type @i(T)
536 (specific or class-wide)}, the following attributes are
537 defined:
538 @begin(description)
539 @Attribute{Prefix=<S>, AttrName=<Class>,
540 Text=[S'Class
541 denotes a subtype of the class-wide type
542 (called @i(T)'Class in this International Standard) for the class
543 rooted at @i(T) (or if S already denotes a class-wide subtype,
544 then S'Class is the same as S).
545
546 @Noprefix@Defn2{Term=[unconstrained], Sec=(subtype)}
547 @Defn2{Term=[constrained], Sec=(subtype)}
548 S'Class is unconstrained. However,
549 if S is constrained, then the values of S'Class are only those
550 that when converted to the type @i(T) belong to S.]}
551 @begin{Ramification}
552 This attribute is defined for both specific
553 and class-wide subtypes. The definition is such
554 that S'Class'Class is the same as S'Class.
555
556 Note that if S is constrained, S'Class is only partially constrained,
557 since there might be additional discriminants
558 added in descendants of @i(T) which are not constrained.
559 @end{Ramification}
560 @begin{Reason}
561 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
562 The Class attribute is not defined for untagged subtypes
563 (except for incomplete types and private types
564 whose full view is tagged
565 @em see @Chg{Version=[2],New=[@RefSecNum{The Class Attribute of Untagged Incomplete Types}],
566 Old=[@RefSecNum{Incomplete Type Declarations}]} and
567 @RefSecNum{Private Operations})
568 so as to preclude implicit conversion in the absence of run-time
569 type information. If it were defined for untagged subtypes, it would
570 correspond to the concept of universal types provided for the predefined
571 numeric classes.
572 @end{Reason}
573
574 @Attribute{Prefix=<S>, AttrName=<Tag>,
575 Text=[S'Tag denotes the tag of
576 the type @i(T) (or if @i(T) is class-wide, the tag of the root type of the
577 corresponding class).
578 The value of this attribute is of type Tag.]}
579 @begin{Reason}
580 S'Class'Tag equals S'Tag, to avoid generic
581 contract model problems when S'Class is the actual
582 type associated with a generic formal derived type.@end{reason}
583 @end(description)
584 @EndPrefixType{}
585
586 Given @PrefixType{a @nt<prefix> X that is of a class-wide
587 tagged type @Redundant[(after any implicit dereference)]},
588 the following attribute is defined:
589 @begin(description)
590 @Attribute{Prefix=<X>, AttrName=<Tag>,
591 Text=[X'Tag denotes the tag of X.
592 The value of this attribute is of type Tag.]}
593 @begin(Reason)
594 X'Tag is not defined if X is of a specific type.
595 This is primarily to avoid confusion that might result
596 about whether the Tag attribute should reflect the tag of
597 the type of X, or the tag of X. No such
598 confusion is possible if X is of a class-wide type.
599 @end(Reason)
600 @end(description)
601 @EndPrefixType{}
602
603 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02],ARef=[AI95-00441-01]}
604 @ChgAdded{Version=[2],Type=[Leading],Text=[The following language-defined
605 generic function exists:]}
606
607 @begin{Example}
608 @ChgRef{Version=[2],Kind=[Added]}
609 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0229-1]}
610 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Tags],Child=[Generic_@!Dispatching_@!Constructor]}@key{generic}
611 @key{type} T (<>) @key{is abstract tagged limited private};
612 @key{type} Parameters (<>) @key{is limited private};
613 @key{with function} Constructor (Params : @key{not null access} Parameters)
614 @key{return} T @key{is abstract};
615 @key{function} Ada.Tags.Generic_Dispatching_Constructor
616 (The_Tag : Tag;
617 Params : @key{not null access} Parameters) @key{return} T'Class@Chg{Version=[3],New=[
618 @key{with} Convention => Intrinsic],Old=[]};
619 @key{pragma} Preelaborate(Generic_Dispatching_Constructor);@Chg{Version=[3],New=[],Old=[
620 @key{pragma} Convention(Intrinsic, Generic_Dispatching_Constructor);]}]}
621 @end{Example}
622
623 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
624 @ChgAdded{Version=[2],Text=[Tags.Generic_Dispatching_Constructor provides
625 a mechanism to create an object of an appropriate type from just a tag value.
626 The function Constructor is expected to create the object given a reference to
627 an object of type Parameters.]}
628
629 @begin{Discussion}
630 @ChgRef{Version=[2],Kind=[AddedNormal]}
631 @ChgAdded{Version=[2],Text=[This specification is designed to make it easy to
632 create dispatching constructors for streams; in particular, this can be used to
633 construct overridings for T'Class'Input.]}
634
635 @ChgRef{Version=[2],Kind=[AddedNormal]}
636 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
637 @ChgAdded{Version=[2],Text=[Note that @Chg{Version=[5],New=[almost ],Old=[]}any
638 tagged type @Chg{Version=[5],New=[can be used in an instance of
639 Generic_Dispatching_Constructor. Using a tagged incomplete view or a tagged
640 partial view before the completion of the type in such an instance would be
641 illegal; all other tagged types can be used in an instance of
642 Generic_Dispatching_Constructor],Old=[will match T (see
643 @RefSecNum{Formal Private and Derived Types})]}.]}
644 @end{Discussion}
645
646 @end{StaticSem}
647
648 @begin{RunTime}
649 @Leading@keepnext@;The tag associated with an object of a tagged type is
650 determined as follows:
651 @begin(Itemize)
652 @PDefn2{Term=[tag of an object], Sec=(stand-alone object, component, or @nt<aggregate>)}
653 The tag of a stand-alone object, a component, or an
654 @nt<aggregate> of a specific tagged type @i(T)
655 identifies @i(T).
656 @begin{Discussion}
657 The tag of a formal parameter of type @i(T)
658 is not necessarily the tag of @i(T), if, for example, the actual was a
659 type conversion.
660 @end{Discussion}
661
662 @PDefn2{Term=[tag of an object], Sec=(object created by an @nt<allocator>)}
663 The tag of an object created by an allocator for an
664 access type with a specific designated tagged type @i(T),
665 identifies @i(T).
666 @begin{Discussion}
667 The tag of an object designated by a
668 value of such an access type might not be @i(T), if, for
669 example, the access value is the result of a type conversion.@end{discussion}
670
671 @PDefn2{Term=[tag of an object], Sec=(class-wide object)}
672 The tag of an object of a class-wide tagged type
673 is that of its initialization expression.
674 @begin{Ramification}
675 The tag of an object (even a class-wide one)
676 cannot be changed after it is initialized, since a @lquotes@;class-wide@rquotes@;
677 @nt{assignment_statement} raises Constraint_Error if the tags don't
678 match, and a @lquotes@;specific@rquotes@; @nt{assignment_statement} does not affect
679 the tag.
680 @end{Ramification}
681
682 @PDefn2{Term=[tag of an object], Sec=(returned by a function)}
683 The tag of the result returned by a function whose
684 result type is a specific tagged type @i(T) identifies @i(T).
685 @begin{ImplNote}
686 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
687 @Chg{Version=[2],New=[For a limited tagged type, the return object is
688 @lquotes@;built in place@rquotes in the ultimate result object with the
689 appropriate tag.], Old=[This requires
690 a run-time check for limited tagged types, since they are
691 returned "by-reference."]}
692 For a nonlimited
693 type, a new anonymous object with the appropriate tag
694 is created as part of the function
695 return@Chg{Version=[2],New=[],Old=[, and then assigned the value of the
696 return expression]}.
697 See @RefSec{Return Statements}.
698 @end{ImplNote}
699
700 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
701 @PDefn2{Term=[tag of an object], Sec=(returned by a function)}
702 The tag of the result returned by a
703 function with a class-wide result
704 type is that of the return @Chg{Version=[2],New=[object],Old=[expression]}.
705 @end(Itemize)
706
707 @PDefn2{Term=[tag of an object], Sec=(preserved by type conversion and parameter passing)}
708 The tag is preserved by type conversion and by parameter passing.
709 The tag of a value is the tag of the associated object
710 (see @RefSecNum{Formal Parameter Modes}).
711
712 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02],ARef=[AI95-00344-01],ARef=[AI95-00405-01]}
713 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1],ARef=[AI05-0262-1]}
714 @ChgAdded{Version=[2],Text=[Tag_Error is raised by a call of Descendant_Tag,
715 Expanded_Name, External_Tag, @Chg{Version=[3],New=[Interface_@!Ancestor_@!Tags],
716 Old=[Interface_Ancestor_Tag]},@Chg{Version=[3],New=[
717 Is_Abstract,],Old=[]}
718 Is_Descendant_@!At_Same_Level,
719 @Chg{Version=[3],New=[],Old=[or ]}Parent_Tag@Chg{Version=[3],New=[,
720 Wide_Expanded_Name, or Wide_Wide_Expanded_Name],Old=[]} if any
721 tag passed is No_Tag.]}
722
723 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
724 @ChgAdded{Version=[2],Text=[An instance of Tags.Generic_Dispatching_Constructor
725 raises Tag_Error if The_Tag does not represent a concrete descendant of T or
726 if the innermost master (see @RefSecNum{Completion and Finalization}) of this
727 descendant is not also a master of the instance.
728 Otherwise, it dispatches to the primitive function denoted by the formal
729 Constructor for the type identified by The_Tag, passing Params, and
730 returns the result. Any exception raised by the function is propagated.]}
731
732 @begin{Ramification}
733 @ChgRef{Version=[2],Kind=[AddedNormal]}
734 @ChgAdded{Version=[2],Text=[The tag check checks both that The_Tag is in
735 T'Class, and that it is not abstract. These checks are similar to the ones
736 required by streams for T'Class'Input
737 (see @RefSecNum{Stream-Oriented Attributes}). In addition, there is a
738 check that the tag identifies a type declared on the current dynamic
739 call chain, and not a more nested type or a type declared by another
740 task. This check is not necessary for streams, because the stream attributes
741 are declared at the same dynamic level as the type used.]}
742 @end{Ramification}
743
744 @end{RunTime}
745
746 @begin{Erron}
747 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
748 @ChgAdded{Version=[2],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
749 If an internal tag provided to an instance of
750 Tags.Generic_Dispatching_Constructor or to any subprogram declared in
751 package Tags identifies either a type that is not
752 library-level and whose tag has not been created
753 (see @RefSecNum{Freezing Rules}), or a type that does not exist in the
754 partition at the time of the call, then execution is erroneous.]}
755
756 @begin{Ramification}
757 @ChgRef{Version=[2],Kind=[AddedNormal]}
758 @ChgAdded{Version=[2],Text=[One reason that a type might not exist in
759 the partition is that the tag refers to a type whose declaration was
760 elaborated as part of an execution of a @nt{subprogram_body} which has been
761 left (see @RefSecNum{Completion and Finalization}).]}
762
763 @ChgRef{Version=[2],Kind=[AddedNormal]}
764 @ChgAdded{Version=[2],Text=[We exclude tags of library-level types from
765 the current execution of the partition, because misuse of such tags
766 should always be detected. T'Tag freezes the type (and thus creates the tag),
767 and Internal_Tag and Descendant_Tag
768 cannot return the tag of a library-level type that has not been created.
769 All ancestors of a tagged type must be frozen no later than the (full)
770 declaration of a type that uses them, so Parent_Tag and Interface_Ancestor_Tags
771 cannot return a tag that has not been created.
772 Finally, library-level types never cease to exist while the partition is
773 executing. Thus, if the tag comes from
774 a library-level type, there cannot be erroneous execution (the use of
775 Descendant_Tag rather than Internal_Tag can help ensure that the tag is
776 of a library-level type). This is also similar to the rules for T'Class'Input
777 (see @RefSecNum{Stream-Oriented Attributes}).]}
778 @end{Ramification}
779 @begin{Discussion}
780 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
781 @ChgAdded{Version=[2],Text=[Ada 95 allowed Tag_Error in this case, or expected
782 the functions to work. This worked because most implementations used tags
783 constructed at link-time, and each elaboration of the same @nt{type_declaration}
784 produced the same tag. However, Ada 2005 requires at least part of the tags
785 to be dynamically constructed for a type derived from a type at a shallower
786 level. For dynamically constructed tags, detecting the error can be expensive
787 and unreliable. To see
788 this, consider a program containing two tasks. Task A creates a nested tagged
789 type, passes the tag to task B (which saves it), and then terminates. The
790 nested tag (if dynamic) probably will need to refer in some way to the stack
791 frame for task A.
792 If task B later tries to use the tag created by task A, the tag's reference to
793 the stack frame of A probably is a dangling pointer. Avoiding this would
794 require some sort of protected tag manager, which would be a bottleneck in a
795 program's performance. Moreover, we'd still have a race condition; if task A
796 terminated after the tag check, but before the tag was used, we'd still have
797 a problem. That means that all of these operations would have to be serialized.
798 That could be a significant performance drain, whether or not nested tagged
799 types are ever used. Therefore, we allow execution to become erroneous
800 as we do for other dangling pointers. If the implementation can detect the
801 error, we recommend that Tag_Error be raised.]}
802 @end{Discussion}
803 @end{Erron}
804
805 @begin{ImplPerm}
806 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00279-01]}
807 The implementation of @Chg{Version=[2],New=[Internal_Tag and Descendant_Tag],
808 Old=[the functions in Ada.Tags]}
809 may raise Tag_Error if no specific type corresponding to the
810 @Chg{Version=[2],New=[string External],Old=[tag]} passed
811 as a parameter exists in the partition at the time the function is
812 called@Chg{Version=[2],New=[, or if there is no such type whose innermost
813 master is a master of the point of the function call],Old=[]}.
814 @begin{Reason}
815 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00279-01],ARef=[AI95-00344-01]}
816 @Chg{Version=[2],New=[Locking would be required to ensure that the mapping of
817 strings to tags never returned tags of types which no longer exist, because
818 types can cease to exist (because they belong to another task, as described
819 above) during the execution of these operations. Moreover, even if these
820 functions did use locking, that would not prevent the type from ceasing to
821 exist at the instant that the function returned. Thus, we do not require the
822 overhead of locking;],Old=[In most implementations,
823 repeated elaborations of the same
824 @nt{type_declaration} will all produce the same tag.
825 In such an implementation, Tag_Error will be raised in cases where the
826 internal or external tag was passed from a different partition.
827 However, some implementations might create a new tag value at run time
828 for each elaboration of a @nt{type_declaration}.
829 In that case, Tag_Error could also be raised if the created type
830 no longer exists because the subprogram
831 containing it has returned, for example.
832 We don't require the latter behavior;]} hence the word
833 @lquotes@;may@rquotes@; in this rule.
834 @end{Reason}
835 @end{ImplPerm}
836
837 @begin{ImplAdvice}
838 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00260-02]}
839 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0113-1]}
840 @ChgAdded{Version=[2],Text=[Internal_Tag should return the tag of
841 a type@Chg{Version=[3],New=[, if one exists,],Old=[]} whose
842 innermost master is @Chg{Version=[3],New=[a],Old=[the]} master of the point of the function call.]}
843 @ChgImplAdvice{Version=[3],Kind=[Revised],InitialVersion=[2],
844 Text=[@Chg{Version=[2],
845 New=[Tags.Internal_Tag should return the tag of
846 a type@Chg{Version=[3],New=[, if one exists,],Old=[]} whose innermost master
847 is @Chg{Version=[3],New=[a],Old=[the]} master of the point of the function call.],Old=[]}.]}
848 @begin{Reason}
849 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02],ARef=[AI95-00344-01]}
850 @ChgAdded{Version=[2],Text=[It's not helpful if Internal_Tag returns the tag of
851 some type in another task when one is available in the task that made the call.
852 We don't require this behavior (because it requires the same implementation
853 techniques we decided not to insist on previously), but encourage it.]}
854 @end{Reason}
855 @begin{Discussion}
856 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0113-1]}
857 @ChgAdded{Version=[3],Text=[There is no Advice for the result of Internal_Tag
858 if no such type exists. In most cases, the @ImplPermName can be
859 used to raise Tag_Error, but some other tag can be returned as well.]}
860 @end{Discussion}
861 @end{ImplAdvice}
862
863 @begin{Notes}
864 A type declared with the reserved word @key[tagged]
865 should normally be declared in a @nt{package_specification},
866 so that new primitive subprograms can be declared for it.
867
868 Once an object has been created,
869 its tag never changes.
870
871 Class-wide types are defined to have unknown discriminants
872 (see @RefSecNum(Discriminants)). This means that objects of a class-wide
873 type have to be explicitly initialized (whether created by
874 an @nt<object_declaration> or an @nt<allocator>),
875 and that @nt<aggregate>s have to be explicitly qualified with a specific
876 type when their expected type is class-wide.
877
878 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00326-01]}
879 @Chg{Version=[2],New=[The capability provided by
880 Tags.Generic_Dispatching_Constructor is sometimes known as a
881 @i<factory>.@Defn{factory}@Defn{class factory}],Old=[If S denotes an
882 untagged private type whose full type is tagged,
883 then S'Class is also allowed before the full type definition,
884 but only in the private part of the package in which the type is
885 declared
886 (see @RefSecNum(Private Operations)).
887 Similarly, the Class attribute is defined
888 for incomplete types whose full type is tagged, but only within
889 the library unit in which the incomplete type is declared
890 (see @RefSecNum(Incomplete Type Declarations)).]}
891 @end{Notes}
892
893 @begin{Examples}
894 @Leading@keepnext@i(Examples of tagged record types:)
895 @begin(Example)
896 @key(type) Point @key(is tagged)
897 @key(record)
898 X, Y : Real := 0.0;
899 @key(end record);
900
901 @key(type) Expression @key(is tagged null record);
902 --@RI[ Components will be added by each extension]
903 @end(Example)
904 @end{Examples}
905
906 @begin{Extend83}
907 @Defn{extensions to Ada 83}
908 Tagged types are a new concept.
909 @end{Extend83}
910
911 @begin{Inconsistent95}
912 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
913 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
914 @b[Amendment Correction:] Added wording specifying that Internal_Tag
915 must raise Tag_Error if the tag of a library-level type has not yet been
916 created. Ada 95 gave an Implementation Permission to do this; we require
917 it to avoid erroneous execution when streaming in an object of a
918 library-level type that has not yet been elaborated. This is technically
919 inconsistent; a program that used Internal_Tag outside of streaming and
920 used a compiler that didn't take advantage of the Implementation Permission
921 would not have raised Tag_Error, and may have returned a useful tag. (If
922 the tag was used in streaming, the program would have been erroneous.)
923 Since such a program would not have been portable to a compiler that did
924 take advantage of the Implementation Permission, this is not a significant
925 inconsistency.]}
926
927 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00417-01]}
928 @ChgAdded{Version=[2],Text=<We now define the lower bound of the string
929 returned from [[Wide_]Wide_]Expanded_Name and External_Name. This makes
930 working with the returned string easier, and is consistent with many other
931 string-returning functions in Ada. This is technically an inconsistency; if a
932 program depended on some other lower bound for the string returned from one
933 of these functions, it could fail when compiled with Ada 2005. Such code is
934 not portable even between Ada 95 implementations, so it should be very
935 rare.>}
936 @end{Inconsistent95}
937
938 @begin{Incompatible95}
939 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02],ARef=[AI95-00344-01],ARef=[AI95-00400-01],ARef=[AI95-00405-01]}
940 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
941 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
942 Constant No_Tag, and functions Parent_Tag, Interface_Ancestor_Tags,
943 Descendant_Tag, Is_Descendant_At_Same_Level, Wide_Expanded_Name,
944 and Wide_Wide_Expanded_Name are @Chg{Version=[3],New=[],Old=[newly ]}added
945 to Ada.Tags.
946 If Ada.Tags is referenced in a @nt{use_clause}, and an entity @i<E> with the
947 same @nt{defining_identifier} as a new entity in Ada.Tags is defined in a
948 package that is also referenced in a @nt{use_clause}, the entity @i<E> may no
949 longer be use-visible, resulting in errors. This should be rare and is easily
950 fixed if it does occur.]}
951 @end{Incompatible95}
952
953 @begin{Extend95}
954 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
955 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
956 Ada.Tags is now defined to be preelaborated.]}
957
958 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
959 @ChgAdded{Version=[2],Text=[Generic function
960 Tags.Generic_Dispatching_Constructor is new.]}
961 @end{Extend95}
962
963 @begin{DiffWord95}
964 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
965 @ChgAdded{Version=[2],Text=[We talk about return objects rather than
966 return expressions, as functions can return using an
967 @nt{extended_return_statement}.]}
968
969 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
970 @ChgAdded{Version=[2],Text=[Added wording to define that tags for all
971 descendants of a tagged type must be distinct. This is needed to ensure
972 that more nested type extensions will work properly. The wording does not
973 require implementation changes for types that were allowed in Ada 95.]}
974 @end{DiffWord95}
975
976 @begin{Inconsistent2005}
977 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0113-1]}
978 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
979 @b[Correction:] Added wording specifying that Dependent_Tag
980 must raise Tag_Error if there is more than one type which matches the
981 requirements. If an implementation had returned a random tag of the matching
982 types, a program may have worked properly. However, such a program would
983 not be portable (another implementation may return a different tag) and the
984 conditions that would cause the problem are unlikely (most likely, a tagged
985 type extension declared in a generic body with multiple instances in the
986 same scope).]}
987 @end{Inconsistent2005}
988
989 @begin{Incompatible2005}
990 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0173-1]}
991 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
992 Function Is_Abstract is added to Ada.Tags.
993 If Ada.Tags is referenced in a @nt{use_clause}, and an entity @i<E> with the
994 @nt{defining_identifier} Is_Abstract is defined in a
995 package that is also referenced in a @nt{use_clause}, the entity @i<E> may no
996 longer be use-visible, resulting in errors. This should be rare and is easily
997 fixed if it does occur.]}
998 @end{Incompatible2005}
999
1000 @begin{DiffWord2005}
1001 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0115-1]}
1002 @ChgAdded{Version=[3],Text=[@b<Correction:> We explicitly define the meaning
1003 of "descendant" at runtime, so that it does not depend on visibility
1004 as does the usual meaning.]}
1005 @end{DiffWord2005}
1006
1007
1008 @LabeledSubClause{Type Extensions}
1009
1010 @begin{Intro}
1011 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
1012 @Redundant[@Defn{type extension}
1013 @Defn2{Term=[extension], Sec=(of a type)}
1014 @Defn{record extension}
1015 @Defn2{Term=[extension], Sec=(of a record type)}
1016 @Defn{private extension}
1017 @Defn2{Term=[extension], Sec=(of a private type)}
1018 Every type extension is a tagged type, and
1019 is @Chg{Version=[2],New=[],Old=[either ]}a @i(record extension) or a
1020 @i(private extension) of
1021 some other tagged type@Chg{Version=[2],New=[, or a noninterface
1022 synchronized tagged type],Old=[]}.]
1023 @end{Intro}
1024
1025 @begin{MetaRules}
1026
1027 We want to make sure that we can extend a generic formal
1028 tagged type, without knowing its discriminants.
1029
1030 We don't want to allow components in an extension aggregate
1031 to depend on discriminants inherited from the parent value,
1032 since such dependence requires staticness in aggregates, at least for
1033 variants.
1034 @end{MetaRules}
1035
1036 @begin{Syntax}
1037 @Syn{lhs=<record_extension_part>,rhs="@key(with) @Syn2{record_definition}"}
1038 @end{Syntax}
1039
1040 @begin{Legality}
1041 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01],ARef=[AI95-00345-01],ARef=[AI95-00419-01]}
1042 The parent type of a record extension shall not be
1043 a class-wide type@Chg{Version=[2],New=[ nor shall it be a synchronized
1044 tagged type (see @RefSecNum{Interface Types})],Old=[]}.
1045 If the parent type@Chg{Version=[2],New=[ or any progenitor],Old=[]} is
1046 nonlimited, then each of the
1047 components of the @nt{record_extension_part} shall be
1048 nonlimited.@Chg{Version=[2],New=[],Old=[
1049 @PDefn2{Term=[accessibility rule],Sec=(record extension)}
1050 The accessibility level
1051 (see @RefSecNum(Operations of Access Types))
1052 of a record extension shall not be statically deeper than that of its
1053 parent type.]}
1054 @PDefn{generic contract issue}
1055 In addition to the places where @LegalityTitle normally apply
1056 (see @RefSecNum{Generic Instantiation}),
1057 these rules apply also in the private part of an
1058 instance of a generic unit.
1059 @begin{Reason}
1060 If the parent is a limited formal type,
1061 then the actual might be nonlimited.
1062
1063 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1064 @Chg{Version=[2],New=[Ada 95 required the record extensions to be the
1065 same level as the parent type. Now we use accessibility checks on class-wide
1066 @nt{allocator}s and return statements to prevent objects from living
1067 longer than their type.],
1068 Old=[A similar accessibility rule is not needed for
1069 private extensions, because in a package, the rule will apply to the
1070 @nt{full_type_declaration},
1071 and for a generic formal private extension,
1072 the actual is all that matters.]}
1073
1074 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
1075 @ChgAdded{Version=[2],Text=[Synchronized tagged types cannot be extended. We
1076 have this limitation so that all of the data of a task or protected type is
1077 defined within the type. Data defined outside of the type wouldn't be
1078 subject to the mutual exclusion properties of a protected type, and couldn't
1079 be used by a task, and thus doesn't seem to be worth the potential impact
1080 on implementations.]}
1081 @end{Reason}
1082
1083 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1084 @Chg{Version=[2],New=[Within the body of a generic unit, or the body of any of
1085 its descendant library units, a tagged type],Old=[A type extension]}
1086 shall not be declared
1087 @Chg{Version=[2],New=[as a descendant of a formal type
1088 declared within the formal part of the generic unit],
1089 Old=[in a generic body if the parent type is declared outside that body]}.
1090
1091 @begin{Reason}
1092 This paragraph ensures that a dispatching call will never
1093 attempt to execute an inaccessible subprogram body.
1094
1095 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00344-01]}
1096 @ChgAdded{Version=[2],Text=[The convoluted wording (@ldquote@;formal type declared
1097 within the formal part@rdquote@;) is necessary to include tagged types that
1098 are formal parameters of formal packages of the generic unit, as well as
1099 formal tagged and tagged formal derived types of the generic unit.]}
1100
1101 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1102 @ChgNote{This rule is only about generic bodies (and always was only
1103 about generic bodies. So we drop the extra text.}
1104 @Chg{Version=[2],New=[This rule],Old=[The part about generic bodies]} is
1105 necessary in order to preserve the contract model.
1106
1107 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI05-0005-1]}
1108 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1109 @Chg{Version=[2],New=[If an ancestor],Old=[Since a generic unit can be instantiated at a
1110 deeper accessibility level than the generic unit, it is necessary to prevent
1111 type extensions whose parent is declared outside the generic unit.
1112 The same is true if the parent]} is a formal of the generic unit
1113 @Chg{Version=[2],New=[, we have a problem],Old=[.
1114 If the parent is declared in the @nt{generic_declaration}
1115 (but is not a formal), we don't run afoul of the accessibility rules,
1116 because we know that the instance declaration and body will be at the
1117 same accessibility level.
1118 However, we still have a problem in that case,]} because
1119 it might have an unknown number of@Chg{Version=[3],New=[],Old=[ abstract]}
1120 subprograms@Chg{Version=[3],New=[ that require overriding],Old=[]},
1121 as in the following example:
1122 @begin{Example}
1123 @ChgRef{Version=[2],Kind=[Revised]}
1124 @key[package] P @key[is]
1125 @key[type] T @key[is] @key[tagged] @key[null] @key[record];
1126 @key[function] F @key[return] T; --@RI{ Inherited versions will @Chg{Version=[2],New=[require overriding],Old=[be abstract]}.}
1127 @key[end] P;
1128
1129 @key[generic]
1130 @key[type] TT @key[is] @key[tagged] @key[private];
1131 @key[package] Gp @key[is]
1132 @key[type] NT @key[is] @key[abstract new] TT @key[with] @key[null] @key[record];
1133 @key[procedure] Q(X : @key[in] NT) @key[is abstract];
1134 @key[end] Gp;
1135
1136 @ChgRef{Version=[2],Kind=[Revised]}
1137 @key[package] @key[body] Gp @key[is]
1138 @key[type] NT2 @key[is] @key[new] NT @key[with] @key[null] @key[record]; --@RI{ Illegal!}
1139 @key[procedure] Q(X : @key[in] NT2) @key[is] @key[begin] @key[null]; @key[end] Q;
1140 --@RI{ Is this legal or not? Can't decide because}
1141 --@RI{ we don't know whether TT had any functions that @Chg{Version=[2],New=[require],Old=[go abstract]}}
1142 --@RI{ @Chg{Version=[2],New=[overriding ],Old=[]}on extension.}
1143 @key[end] Gp;
1144
1145 @key[package] I @key[is] @key[new] Gp(TT => P.T);
1146 @end{Example}
1147
1148 @ChgRef{Version=[2],Kind=[Revised]}
1149 I.NT is an abstract type with two abstract subprograms:
1150 F (inherited as abstract) and Q (explicitly declared as abstract).
1151 But the generic body doesn't know about F,
1152 so we don't know that it needs to be overridden to make a nonabstract
1153 extension of NT.@Chg{Version=[2],New=[],Old=[
1154 Furthermore, a formal tagged limited private type can be extended with
1155 limited components,
1156 but the actual might not be limited,
1157 which would allow assignment of limited types,
1158 which is bad.]} Hence, we have to disallow this
1159 case@Chg{Version=[2],New=[],Old=[ as well]}.
1160
1161 @ChgRef{Version=[2],Kind=[Added]}
1162 @ChgAdded{Version=[2],Text=[Similarly, since the actual type for a
1163 formal tagged limited private type can be a nonlimited type, we would have
1164 a problem if a type extension of a limited private formal type could be
1165 declared in a generic body. Such an
1166 extension could have a task component, for example, and an object of that
1167 type could be passed to a dispatching operation of a nonlimited ancestor
1168 type. That operation could try to copy the object with the task component.
1169 That would be bad. So we disallow this as well.]}
1170
1171 If TT were declared as abstract, then we could have the same
1172 problem with abstract procedures.
1173
1174 We considered disallowing all tagged types in a generic body,
1175 for simplicity.
1176 We decided not to go that far,
1177 in order to avoid unnecessary restrictions.
1178
1179 @PDefn2{Term=[accessibility rule],Sec=(not part of generic contract)}
1180 We also considered trying make the accessibility level part of the
1181 contract; i.e. invent some way of saying (in the
1182 @nt{generic_declaration}) @lquotes@;all instances of this generic unit will
1183 have the same accessibility level as the
1184 @nt{generic_declaration}.@rquotes@;
1185 Unfortunately, that doesn't solve the part of the problem having to do
1186 with abstract types.
1187
1188 @ChgRef{Version=[2],Kind=[Deleted]}
1189 @ChgDeleted{Version=[2],Text=[Children of
1190 generic units obviate the need for extension in the body somewhat.]}
1191 @end{Reason}
1192
1193 @begin{Ramification}
1194 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344]}
1195 @ChgAdded{Version=[2],Text=[This rule applies to types with ancestors (directly
1196 or indirectly) of formal interface types
1197 (see @RefSecNum{Formal Interface Types}), formal tagged private types
1198 (see @RefSecNum{Formal Private and Derived Types}), and
1199 formal derived private types whose ancestor type is tagged
1200 (see @RefSecNum{Formal Private and Derived Types}).]}
1201 @end{Ramification}
1202 @end{Legality}
1203
1204 @begin{StaticSem}
1205 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00391-01]}
1206 @ChgAdded{Version=[2],Text=[@defn{null extension}
1207 A record extension is a @i{null extension} if its declaration
1208 has no @nt{known_discriminant_part} and its @nt{record_extension_part}
1209 includes no @nt{component_declaration}s.]}
1210 @end{StaticSem}
1211
1212 @begin{RunTime}
1213 @PDefn2{Term=[elaboration], Sec=(record_extension_part)}
1214 The elaboration of a @nt{record_extension_part} consists
1215 of the elaboration of the @nt{record_definition}.
1216 @end{RunTime}
1217
1218 @begin{Notes}
1219 The term @lquotes@;type extension@rquotes@; refers to a type as a whole.
1220 The term @lquotes@;extension part@rquotes@; refers to the piece
1221 of text that defines the additional components (if any) the
1222 type extension has relative to its specified ancestor type.
1223 @begin(Discussion)
1224 We considered other terminology, such as @lquotes@;extended type.@rquotes@;
1225 However, the terms @lquotes@;private extended type@rquotes@; and @lquotes@;record extended type@rquotes@;
1226 did not convey the proper meaning. Hence, we have chosen
1227 to uniformly use the term @lquotes@;extension@rquotes@; as the type resulting
1228 from extending a type, with @lquotes@;private extension@rquotes@; being one
1229 produced by privately extending the type, and @lquotes@;record extension@rquotes@;
1230 being one produced by extending the type with an additional record-like set
1231 of components.
1232 Note also that the term @lquotes@;type extension@rquotes@; refers to the result
1233 of extending a type in the language Oberon as well (though there
1234 the term @lquotes@;extended type@rquotes@; is also used, interchangeably, perhaps because
1235 Oberon doesn't have the concept of a @lquotes@;private extension@rquotes@;).
1236 @end(Discussion)
1237
1238 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
1239 @Chg{Version=[2],New=[],Old=[The accessibility rules imply that a tagged type
1240 declared in a library @nt{package_specification} can be extended only
1241 at library level or as a generic formal. ]}When
1242 @Chg{Version=[2],New=[an],Old=[the]} extension is declared immediately within
1243 a @Chg{Version=[2],New=[body],Old=[@nt{package_body}]},
1244 primitive subprograms are inherited and are overridable,
1245 but new primitive subprograms cannot be added.
1246
1247 A @nt<name> that denotes a component (including a discriminant) of
1248 the parent type is not allowed within the
1249 @nt{record_extension_part}.
1250 Similarly, a @nt<name> that denotes a component defined within the
1251 @nt{record_extension_part} is not allowed within
1252 the @nt{record_extension_part}.
1253 It is permissible to use a @nt<name>
1254 that denotes a discriminant of the record extension, providing there is
1255 a new @nt{known_discriminant_part} in the enclosing type declaration.
1256 (The full rule is given in @RefSecNum(Record Types).)
1257 @begin(Reason)
1258 The restriction against depending on
1259 discriminants of the parent is to simplify the definition of extension
1260 aggregates. The restriction against using parent components in other
1261 ways is methodological; it presumably simplifies implementation as
1262 well.
1263 @end(Reason)
1264
1265 Each visible component of a record extension has to have a
1266 unique name, whether the component is (visibly) inherited
1267 from the parent type or declared in the
1268 @nt<record_extension_part> (see @RefSecNum{Visibility}).
1269 @end{Notes}
1270
1271 @begin{Examples}
1272 @Leading@keepnext@i{Examples of record extensions (of types defined above in @RefSecNum(Tagged Types and Type Extensions)):}
1273 @begin(Example)
1274 @key(type) Painted_Point @key(is new) Point @key(with)
1275 @key(record)
1276 Paint : Color := White;
1277 @key(end record);
1278 --@RI[ Components X and Y are inherited]
1279
1280 Origin : @key(constant) Painted_Point := (X | Y => 0.0, Paint => Black);
1281
1282 @key(type) Literal @key(is new) Expression @key(with)
1283 @key(record) --@RI[ a leaf in an Expression tree]
1284 Value : Real;
1285 @key(end record);
1286
1287 @key(type) Expr_Ptr @key(is access all) Expression'Class;
1288 --@RI[ see @RefSecNum(Access Types)]
1289
1290 @key(type) Binary_Operation @key(is new) Expression @key(with)
1291 @key(record) --@RI[ an internal node in an Expression tree]
1292 Left, Right : Expr_Ptr;
1293 @key(end record);
1294
1295 @key(type) Addition @key(is new) Binary_Operation @key(with null record);
1296 @key(type) Subtraction @key(is new) Binary_Operation @key(with null record);
1297 --@RI[ No additional components needed for these extensions]
1298
1299 Tree : Expr_Ptr := --@RI[ A tree representation of @lquotes@;5.0 + (13.0@en@;7.0)@rquotes@;]
1300 @key(new) Addition'(
1301 Left => @key(new) Literal'(Value => 5.0),
1302 Right => @key(new) Subtraction'(
1303 Left => @key(new) Literal'(Value => 13.0),
1304 Right => @key(new) Literal'(Value => 7.0)));
1305 @end(Example)
1306
1307 @end{Examples}
1308
1309 @begin{Extend83}
1310 @Defn{extensions to Ada 83}
1311 Type extension is a new concept.
1312 @end{Extend83}
1313
1314 @begin{Extend95}
1315 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
1316 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1317 Type extensions now can be
1318 declared in more nested scopes than their parent types. Additional
1319 accessibility checks on @nt{allocator}s and return statements prevent
1320 objects from outliving their type.]}
1321 @end{Extend95}
1322
1323 @begin{DiffWord95}
1324 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
1325 @ChgAdded{Version=[2],Text=[Added wording to prevent extending synchronized
1326 tagged types.]}
1327
1328 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
1329 @ChgAdded{Version=[2],Text=[Defined null extension for use elsewhere.]}
1330 @end{DiffWord95}
1331
1332
1333 @LabeledSubClause{Dispatching Operations of Tagged Types}
1334
1335 @begin{Intro}
1336 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00335-01]}
1337 @RootDefn{dispatching operation}
1338 @Defn2{Term=[dispatching call], Sec=(on a dispatching operation)}
1339 @Defn2{Term=[nondispatching call], Sec=(on a dispatching operation)}
1340 @Defn{statically determined tag}
1341 @Defn{dynamically determined tag}
1342 @Defn{polymorphism}
1343 @Defn{run-time polymorphism}
1344 @Defn2{Term=[controlling tag], Sec=(for a call on a dispatching operation)}
1345 The primitive subprograms of a tagged type@Chg{Version=[2],New=[, the
1346 subprograms declared by @nt{formal_@!abstract_@!subprogram_@!declaration}s,
1347 and the stream attributes of a specific tagged type that are available (see
1348 @RefSecNum{Stream-Oriented Attributes}) at the end of the declaration list
1349 where the type is declared],Old=[]}
1350 are called @i(dispatching operations).
1351 @Redundant[A dispatching operation can be called using a statically
1352 determined @i{controlling} tag, in which case the body to be
1353 executed is determined at compile time.
1354 Alternatively, the controlling tag can be dynamically determined,
1355 in which case the call @i{dispatches} to a
1356 body that is determined at run time;]
1357 such a call is termed a @i{dispatching call}.
1358 @Redundant[As explained below, the properties of the operands
1359 and the context of a particular call on a dispatching operation
1360 determine how the controlling tag is determined,
1361 and hence whether or not the call is a dispatching call.
1362 Run-time polymorphism is achieved when a dispatching operation is called
1363 by a dispatching call.]
1364 @IndexSee{Term=[object-oriented programming (OOP)],See=[dispatching operations of tagged types]}
1365 @IndexSee{Term=[OOP (object-oriented programming)],See=[dispatching operations of tagged types]}
1366 @IndexSee{Term=[message],See=[dispatching call]}
1367 @IndexSee{Term=[method],See=[dispatching subprogram]}
1368 @IndexSee{Term=[virtual function],See=[dispatching subprogram]}
1369 @begin{Reason}
1370 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00335-01]}
1371 @ChgAdded{Version=[2],Text=[For the stream attributes of a type
1372 declared immediately within a @nt{package_specification} that has a
1373 partial view, the declaration list to consider is the visible part of the
1374 package. Stream attributes that are not available in the same declaration
1375 list are not dispatching as there is no guarantee that descendants of the
1376 type have available attributes (there is such a guarantee for visibly
1377 available attributes). If we allowed dispatching for any available
1378 attribute, then for attributes defined in the private part we could end up
1379 executing a nonexistent body.]}
1380 @end{Reason}
1381
1382 @end{Intro}
1383
1384 @begin{MetaRules}
1385 The controlling tag determination rules are analogous to the
1386 overload resolution rules, except they deal with run-time
1387 type identification (tags) rather than compile-time type
1388 resolution. As with overload resolution, controlling tag determination
1389 may depend on operands or result context.
1390 @end{MetaRules}
1391
1392 @begin{StaticSem}
1393 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00416-01]}
1394 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0076-1]}
1395 @Defn{call on a dispatching operation}
1396 @Defn{dispatching operation}
1397 A @i{call on a dispatching operation} is a call whose @nt<name> or
1398 @nt<prefix> denotes the declaration of@Chg{Version=[2],New=[],
1399 Old=[ a primitive subprogram of a tagged type, that is,]} a dispatching
1400 operation.
1401 @Defn{controlling operand}
1402 A @i{controlling operand} in a call on a dispatching operation of a tagged
1403 type @i(T) is one whose corresponding formal parameter is of type @i(T)
1404 or is of an anonymous access type with designated type @i(T);
1405 @Defn{controlling formal parameter}
1406 the corresponding formal parameter is called a
1407 @i(controlling formal parameter).
1408 If the controlling formal parameter is an access parameter, the
1409 controlling operand is the object designated by the actual parameter,
1410 rather than the actual parameter itself.
1411 @Defn{controlling result}@Chg{Version=[3],New=[@Defn2{Term=[function],Sec=[with a controlling result]}],Old=[]}
1412 If the call is to a (primitive) function with result type
1413 @i(T)@Chg{Version=[3],New=[ (a @i{function with a controlling result})],Old=[]},
1414 then the call has a @i(controlling result) @em
1415 the context of the call can control the dispatching.@Chg{Version=[2],
1416 New=[ Similarly, if the call is to a function with
1417 @Chg{Version=[3],New=[an ],Old=[]}access result type designating
1418 @i(T)@Chg{Version=[3],New=[ (a @i{function with a controlling access result})],Old=[]},
1419 then the call has a @i(controlling access result), and
1420 the context can similarly control dispatching.],Old=[]}@Chg{Version=[3],New=[@Defn{controlling access result}@Defn2{Term=[function],Sec=[with a controlling access result]}],Old=[]}
1421 @begin{Ramification}
1422 This definition implies that a call through the dereference of an
1423 access-to-subprogram value is never considered a call on
1424 a dispatching operation.
1425 Note also that if the @nt{prefix} denotes a @nt{renaming_declaration},
1426 the place where the renaming occurs determines whether it is
1427 primitive; the thing being renamed is irrelevant.
1428 @end{Ramification}
1429
1430 @Leading@;A @nt<name> or expression of a tagged type
1431 is either @i(statically) tagged,
1432 @i(dynamically) tagged, or @i(tag indeterminate), according
1433 to whether, when used as a controlling operand, the tag
1434 that controls dispatching is determined statically by the operand's
1435 (specific) type,
1436 dynamically by its tag at run time,
1437 or from context.
1438 A @nt<qualified_expression> or parenthesized expression is
1439 statically, dynamically, or indeterminately tagged according
1440 to its operand. For other kinds of @nt<name>s and expressions, this
1441 is determined as follows:
1442 @begin(Itemize)
1443 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1444 @Defn{statically tagged}
1445 The @nt<name> or expression is @i(statically
1446 tagged) if it is of a specific tagged type and,
1447 if it is a call with a controlling result@Chg{Version=[2],New=[ or
1448 controlling access result],Old=[]}, it has at least
1449 one statically tagged controlling operand;
1450 @begin{Discussion}
1451 It is illegal to have both statically tagged and
1452 dynamically tagged controlling operands in the same call -- see below.
1453 @end{discussion}
1454
1455 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1456 @Defn{dynamically tagged}
1457 The @nt<name> or expression is @i(dynamically tagged)
1458 if it is of a class-wide type, or it is a call with
1459 a controlling result@Chg{Version=[2],New=[ or
1460 controlling access result],Old=[]} and at least one dynamically
1461 tagged controlling operand;
1462
1463 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1464 @Defn{tag indeterminate}
1465 The @nt<name> or expression is @i(tag indeterminate)
1466 if it is a call with a controlling result@Chg{Version=[2],New=[ or
1467 controlling access result],Old=[]}, all of whose
1468 controlling operands (if any) are tag indeterminate.
1469 @end(itemize)
1470
1471 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
1472 @Redundant[A @nt<type_conversion> is statically or dynamically
1473 tagged according to whether the type determined by the @nt<subtype_mark>
1474 is specific or class-wide, respectively.]
1475 @Chg{New=[For an object that is designated by an expression whose expected type
1476 is an anonymous access-to-specific tagged type, the object is dynamically
1477 tagged if the expression, ignoring enclosing parentheses, is of the form
1478 X'Access, where X is of a class-wide type, or is of the form
1479 @key(new) T'(...), where T denotes a class-wide subtype. Otherwise, the object],
1480 Old=[For a controlling operand that is designated by an actual parameter,
1481 the controlling operand]} is statically or dynamically tagged according to
1482 whether the designated type @Chg{New=[of the type of the expression],
1483 Old=[of the actual parameter]} is specific or class-wide, respectively.
1484 @begin{Ramification}
1485 A @nt<type_conversion> is never tag indeterminate, even if its
1486 operand is. A designated object is never tag indeterminate.
1487
1488 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0010],ARef=[AI95-00127-01]}
1489 @ChgAdded{Version=[1],Text=[Allocators and access attributes of class-wide types can be used as
1490 the controlling parameters of dispatching calls.]}
1491 @end{Ramification}
1492 @end{StaticSem}
1493
1494 @begin{Legality}
1495 A call on a dispatching operation shall not
1496 have both dynamically tagged and statically tagged controlling operands.
1497 @begin{Reason}
1498 This restriction is intended to minimize
1499 confusion between whether the dynamically tagged operands
1500 are implicitly converted to, or tag checked against the
1501 specific type of the statically tagged operand(s).
1502 @end{Reason}
1503
1504 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
1505 If the expected type for an expression or @nt<name>
1506 is some specific tagged type, then the expression or @nt<name>
1507 shall not be dynamically tagged unless it is a controlling operand in a call
1508 on a dispatching operation.
1509 Similarly, if the expected type for an expression
1510 is an anonymous access-to-specific
1511 tagged type, then the @Chg{New=[object designated by the expression
1512 shall not be dynamically tagged unless it is],Old=[expression shall not be
1513 of an access-to-class-wide type unless it designates]} a controlling
1514 operand in a call on a dispatching operation.
1515 @begin(Reason)
1516 This prevents implicit "truncation"
1517 of a dynamically-tagged value to the specific type of the
1518 target object/formal. An explicit conversion is required to request
1519 this truncation.
1520 @end(Reason)
1521 @begin(Ramification)
1522 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01]}@ChgNote{Add info about prefix calls}
1523 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
1524 This rule applies to all expressions
1525 or @nt<name>s with a specific expected type, not just those that
1526 are actual parameters to a dispatching call. This rule does not apply to
1527 a membership test whose
1528 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt<expression>]}
1529 is class-wide, since any type that covers the tested type is explicitly allowed.
1530 See @RefSecNum(Relational Operators and Membership Tests).@Chg{Version=[2],
1531 New=[ This rule also doesn't apply to a @nt{selected_component} whose
1532 @nt{selector_name} is a subprogram, since the rules explicitly say that
1533 the prefix may be class-wide (see @RefSecNum{Selected Components}).],Old=[]}
1534 @end(Ramification)
1535
1536 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0011],ARef=[AI95-00117-01]}
1537 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00430-01]}
1538 In the declaration of a dispatching operation of a tagged type,
1539 everywhere a subtype of the tagged type appears as a
1540 subtype of the profile (see @RefSecNum(Subprogram Declarations)),
1541 it shall statically match the first subtype of the tagged type.
1542 @PDefn2{Term=[statically matching],Sec=(required)}
1543 If the dispatching operation overrides an inherited subprogram,
1544 it shall be subtype conformant with the inherited subprogram.
1545 @Defn2{Term=[subtype conformance],Sec=(required)}
1546 @Chg{New=[The convention of an inherited @Chg{Version=[2],New=[],
1547 Old=[or overriding ]}dispatching operation is
1548 the convention of the corresponding primitive operation of the parent
1549 @Chg{Version=[2],New=[or progenitor ],Old=[]}type. @Chg{Version=[2],New=[The
1550 default convention of a dispatching operation that overrides an inherited
1551 primitive operation is the convention of the inherited operation; if the
1552 operation overrides multiple inherited operations, then they shall all
1553 have the same convention. ],Old=[]}An
1554 explicitly declared],Old=[A]} dispatching operation shall not be of convention
1555 Intrinsic.@Chg{New=[],Old=[ If a dispatching operation overrides the predefined
1556 equals operator, then it shall be of convention Ada @Redundant[(either
1557 explicitly or by default @em see @RefSecNum{Conformance Rules})].]}
1558 @begin{Reason}
1559 These rules ensure that constraint checks can be performed by the
1560 caller in a dispatching call, and parameter passing conventions
1561 match up properly. A special rule on aggregates
1562 prevents values of a tagged type from being created that
1563 are outside of its first subtype.
1564 @end{reason}
1565
1566 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1567 The @nt<default_expression> for a controlling formal parameter
1568 of a dispatching operation shall be tag indeter@!minate.@Chg{Version=[2],
1569 New=[],Old=[ A controlling formal parameter that is an access parameter
1570 shall not have a @nt<default_expression>.]}
1571 @begin(Reason)
1572 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1573 @Chg{Version=[2],New=[This rule],Old=[The first part]} ensures
1574 that the @nt{default_expression} always produces the "correct"
1575 tag when called with or without dispatching,
1576 or when inherited by a descendant. If
1577 it were statically tagged, the default would be useless for
1578 a dispatching call; if it were dynamically tagged, the default
1579 would be useless for a nondispatching call.
1580
1581 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00416-01]}
1582 @ChgDeleted{Version=[2],Text=[The second part is consistent with the
1583 first part, since designated objects are never tag-indeterminate.]}
1584 @end(Reason)
1585
1586 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00404-01]}
1587 @ChgAdded{Version=[2],Text=[If a dispatching operation is defined by a
1588 @nt{subprogram_renaming_declaration} or the instantiation of a generic
1589 subprogram, any access parameter of the renamed subprogram or the generic
1590 subprogram that corresponds to a controlling access parameter of the
1591 dispatching operation, shall have a subtype that excludes null.]}
1592
1593 A given subprogram shall not be a dispatching operation of two
1594 or more distinct tagged types.
1595 @begin{Reason}
1596 This restriction minimizes
1597 confusion since multiple dispatching is not provided. The normal
1598 solution is to replace all but one of the tagged types with their
1599 class-wide types.
1600 @end{reason}
1601 @begin{ramification}
1602 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0098],ARef=[AI95-00183-01]}
1603 @ChgAdded{Version=[1],Text=[This restriction applies even if the partial view (see
1604 @RefSecNum{Private Types and Private Extensions}) of one or both
1605 of the types is untagged. This follows from the definition of dispatching
1606 operation: the operation is a dispatching operation anywhere the full
1607 views of the (tagged) types are visible.]}
1608 @end{ramification}
1609
1610 The explicit declaration of a primitive subprogram of a
1611 tagged type shall occur before the type is frozen
1612 (see @RefSecNum{Freezing Rules}).
1613 @Redundant[For example, new dispatching operations cannot be added after
1614 objects or values of the type exist,
1615 nor after deriving a record extension from it,
1616 nor after a body.]
1617
1618 @comment{The following is a "fix" to keep consistent with v. 5.95;
1619 appearently 6.0 is different.
1620 @begin{Discussion}
1621 @ChgRef{Version=[1],Kind=[Deleted]}
1622 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}
1623 @end{Discussion}}
1624 @begin{Reason}
1625 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}@ChgNote{Tags now have two parts, logically}
1626 This rule is needed
1627 because (1) we don't want people dispatching to things that haven't
1628 been declared yet, and (2) we want to allow @Chg{Version=[2],New=[the static
1629 part of ],Old=[]}tagged type descriptors
1630 to be static (allocated statically, and initialized to link-time-known
1631 symbols). Suppose T2 inherits primitive P from T1, and then
1632 overrides P. Suppose P is called @i{before} the declaration of the
1633 overriding P. What should it dispatch to? If the answer is the new
1634 P, we've violated the first principle above. If the answer is the
1635 old P, we've violated the second principle. (A call
1636 to the new one necessarily raises Program_Error, but that's
1637 beside the point.)
1638
1639 Note that a call upon a dispatching operation of type @i(T) will freeze @i(T).
1640
1641 We considered applying this rule to all derived types,
1642 for uniformity.
1643 However, that would be upward incompatible,
1644 so we rejected the idea.
1645 As in Ada 83, for an untagged type, the above call upon P will call the
1646 old P (which is arguably confusing).
1647 @end{Reason}
1648 @begin{ImplNote}
1649 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}@ChgNote{We have tagged incomplete types now, and they don't freeze}
1650 Because of this rule,
1651 the type descriptor can be created (presumably containing linker
1652 symbols pointing at the not-yet-compiled bodies) at the first
1653 freezing point of the type.
1654 It also prevents, for a @Chg{Version=[2],New=[(nonincomplete) ],Old=[]}tagged
1655 type declared in a
1656 @nt{package_specification}, overriding in the body or by a child subprogram.
1657 @end{ImplNote}
1658 @begin{Ramification}
1659 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}@ChgNote{Interfaces cause this too}
1660 A consequence is that for a @Chg{Version=[2],New=[tagged type declaration],
1661 Old=[@ntf{derived_type_declaration}]} in a
1662 @nt{declarative_part}, only the @Chg{Version=[2],New=[last (overriding)],Old=[first]}
1663 primitive subprogram can be
1664 declared by a @nt{subprogram_body}.@Chg{Version=[2],New=[ (Other overridings
1665 must be provided by @nt{subprogram_declaration}s.)],Old=[]}
1666 @end{Ramification}
1667 @begin{Honest}
1668 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0222-1]}
1669 @ChgAdded{Version=[3],Text=[This rule applies only to "original" declarations
1670 and not to the completion of a primitive subprogram, even though a completion
1671 is technically an explicit declaration, and it may declare a primitive
1672 subprogram.]}
1673 @end{Honest}
1674
1675 @end{Legality}
1676
1677 @begin{RunTime}
1678 @Leading@PDefn2{Term=[execution], Sec=(call on a dispatching operation)}
1679 @Defn{controlling tag value}
1680 For the execution of a call on a dispatching operation of a type @i(T),
1681 the @i(controlling tag value) determines
1682 which subprogram body is executed.
1683 The controlling tag value is defined as follows:
1684 @begin(itemize)
1685 @PDefn{statically determined tag}
1686 If one or more controlling operands are statically tagged, then
1687 the controlling tag value is @i(statically determined) to be the tag
1688 of @i(T).
1689
1690 If one or more controlling operands are dynamically tagged, then
1691 the controlling tag value is not statically determined, but is
1692 rather determined by
1693 the tags of the controlling operands.
1694 @IndexCheck{Tag_Check}
1695 If there is more than one dynamically tagged controlling operand,
1696 a check is made that they all have the same tag.
1697 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
1698 If this check fails, Constraint_Error is raised
1699 unless the call is a @nt<function_call> whose @nt<name> denotes
1700 the declaration of an equality operator (predefined or user defined) that
1701 returns Boolean,
1702 in which case the result of the call is defined to indicate
1703 inequality, and no @nt<subprogram_body> is executed.
1704 This check is performed prior to evaluating any tag-indeterminate
1705 controlling operands.
1706 @begin(Reason)
1707 Tag mismatch is considered an error (except for "=" and "/=")
1708 since the corresponding primitive
1709 subprograms in each specific type expect all controlling
1710 operands to be of the same type.
1711 For tag mismatch with an equality operator, rather than raising
1712 an exception, "=" returns False and "/=" returns True.
1713 No equality operator is actually invoked, since there
1714 is no common tag value to control the dispatch.
1715 Equality is a special case to be consistent with the existing
1716 Ada 83 principle that equality comparisons, even
1717 between objects with different constraints, never raise Constraint_Error.
1718 @end(Reason)
1719
1720 @Leading@keepnext@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00196-01]}
1721 If all of the controlling operands @Chg{Version=[2],New=[(if any) ],Old=[]}are
1722 tag-indeterminate, then:
1723 @begin(inneritemize)
1724 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00239-01],ARef=[AI95-00416-01]}
1725 If the call has a controlling result@Chg{Version=[2],New=[ or controlling
1726 access result],Old=[]} and is itself@Chg{Version=[2],New=[, or designates,],Old=[]}
1727 a (possibly parenthesized or qualified)
1728 controlling operand of an enclosing call on a dispatching operation
1729 of @Chg{Version=[2],New=[a descendant of ],Old=[]}type @i(T),
1730 then its controlling tag value is determined by the controlling tag
1731 value of this enclosing call;
1732
1733 @begin{Discussion}
1734 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00239-01]}
1735 @ChgAdded{Version=[2],Text=[For code that a user can write explicitly,
1736 the only contexts that can control dispatching of a function with a
1737 controlling result of type T are those that involve controlling operands
1738 of the same type T: if the two types differ there is an illegality and
1739 the dynamic semantics are irrelevant.]}
1740
1741 @ChgRef{Version=[2],Kind=[AddedNormal]}
1742 @ChgAdded{Version=[2],Text=[In the case of an inherited subprogram
1743 however, if a default expression is a function call, it may be of type T
1744 while the parameter is of a type derived from T. To cover this case, we
1745 talk about "a descendant of T" above. This is safe, because if the type
1746 of the parameter is descended from the type of the function result, it is
1747 guaranteed to inherit or override the function, and this ensures that
1748 there will be an appropriate body to dispatch to. Note that abstract
1749 functions are not an issue here because the call to the function is a
1750 dispatching call, so it is guaranteed to always land on a concrete
1751 body.]}
1752 @end{Discussion}
1753
1754 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00196-01],ARef=[AI95-00416-01]}
1755 @ChgAdded{Version=[2],Text=[If the call has a controlling result or
1756 controlling access result and (possibly parenthesized, qualified, or
1757 dereferenced) is the expression of an @nt{assignment_statement} whose
1758 target is of a class-wide type, then its controlling tag value is
1759 determined by the target;]}
1760
1761 @PDefn{statically determined tag}
1762 Otherwise, the controlling tag value is statically determined to be
1763 the tag of type @i(T).
1764 @begin{Ramification}
1765 This includes the cases of
1766 a tag-indeterminate procedure call, and
1767 a tag-indeterminate @nt{function_call} that is
1768 used to initialize a class-wide formal parameter or class-wide
1769 object.
1770 @end{Ramification}
1771 @end(inneritemize)
1772 @end(itemize)
1773
1774 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
1775 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0126-1]}
1776 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@ChgNote{Dummy add to allow conditional "leading"}
1777 For the execution of a call on a dispatching operation,
1778 the @Chg{Version=[2],New=[action performed is determined by the properties
1779 of the corresponding dispatching operation],Old=[body executed is the one for
1780 the corresponding primitive subprogram]} of the specific type
1781 identified by the controlling tag value@Chg{Version=[3],New=[:],Old=[.
1782 @Chg{Version=[2],New=[If the corresponding operation is],Old=[The body
1783 for an]} explicitly declared
1784 @Chg{Version=[2],New=[for this type, @Redundant[even if the declaration occurs
1785 in a private part], then the action comprises an invocation of the],
1786 Old=[dispatching operation is the corresponding]}
1787 explicit body for the
1788 @Chg{Version=[2],New=[operation. If the corresponding operation is
1789 implicitly declared for this type:],Old=[subprogram.
1790 The body for an implicitly
1791 declared dispatching operation that is overridden is the body for the
1792 overriding subprogram, @Redundant[even if the overriding occurs in a private
1793 part.] The body for an inherited dispatching operation that is not overridden
1794 is the body of the corresponding subprogram of the parent or ancestor type.]}]}
1795
1796 @begin{Itemize}
1797 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0126-1]}
1798 @ChgAdded{Version=[3],Text=[if the corresponding operation is explicitly
1799 declared for this type, @Redundant[even if the declaration occurs in a private
1800 part], then the action comprises an invocation of the explicit body for the
1801 operation;]}
1802
1803 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1804 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0126-1]}
1805 @ChgAdded{Version=[2],Text=[if the
1806 @Chg{Version=[3],New=[corresponding ],Old=[]}operation is
1807 @Chg{Version=[3],New=[implicitly
1808 declared for this type and is ],Old=[]}implemented by an entry or
1809 protected subprogram (see @RefSecNum{Task Units and Task Objects} and
1810 @RefSecNum{Protected Units and Protected Objects}), then the action comprises a
1811 call on this entry or protected subprogram, with the target object being given
1812 by the first actual parameter of the call, and the actual parameters of the
1813 entry or protected subprogram being given by the remaining actual parameters of
1814 the call, if any;]}
1815
1816 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0197-1]}
1817 @ChgAdded{Version=[3],Text=[if the corresponding operation is a predefined
1818 operator then the action comprises an invocation of that operator;]}
1819
1820 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1821 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0126-1],ARef=[AI05-0197-1],ARef=[AI05-0250-1],ARef=[AI05-0254-1]}
1822 @ChgAdded{Version=[2],Text=[otherwise, the action is the same as the action for
1823 the corresponding operation of the parent type@Chg{Version=[3],New=[ or
1824 progenitor type from which the operation was inherited except that additional
1825 invariant checks (see @RefSecnum{Type Invariants}) and class-wide postcondition
1826 checks (see @RefSecNum{Preconditions and Postconditions}) may apply. If there is
1827 more than one such corresponding operation, the action is that for the operation
1828 that is not a null procedure, if any; otherwise, the action is that of an
1829 arbitrary one of the operations],Old=[]}.]}
1830 @end{Itemize}
1831
1832 @begin{Honest}
1833 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0126-1]}
1834 @ChgDeleted{Version=[3],Text=[In the unusual case in which a
1835 dispatching subprogram is explicitly declared (overridden) by a body (with no
1836 preceding @nt{subprogram_declaration}), the body for that dispatching subprogram
1837 is that body; that is, the @lquotes@;corresponding explicit body@rquotes@; in
1838 the above rule is the body itself.]}
1839 @end{Honest}
1840 @begin{Ramification}
1841 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0005-1],ARef=[AI05-0126-1]}
1842 @ChgAdded{Version=[3],Text=[@ldquote@;Corresponding dispatching operation@rdquote
1843 refers to the inheritance relationship between subprograms. Primitive
1844 operations are always inherited for a type T, but they might not be declared if
1845 the primitive operation is never visible within the immediate scope of the type
1846 T. If no corresponding operation is declared, the last bullet is used and the
1847 corresponding operation of the parent type is executed (an explicit body that
1848 happens to have the same name and profile is not called in that case).]}
1849
1850 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0005-1],ARef=[AI05-0126-1]}
1851 @ChgAdded{Version=[3],Text=[We have to talk about progenitors in the last
1852 bullet in case the corresponding operation is a null procedure inherited
1853 from an interface. In that case, the parent type might not even have the
1854 operation in question.]}
1855
1856 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0197-1]}
1857 @ChgAdded{Version=[3],Text=[For the last bullet, if there are multiple
1858 corresponding operations for the parent and progenitors, all but one of them
1859 have to be a null procedure. (If the progenitors declared abstract routines,
1860 there would have to be an explicit overriding of the operation, and then the
1861 first bullet would apply.) We call the nonnull routine if one exists.]}
1862
1863 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0126-1]}
1864 @ChgAdded{Version=[3],Text=[Any explicit declaration for an inherited
1865 corresponding operation has to be an overriding routine.
1866 These rules mean that a dispatching call executes the
1867 overriding routine (if any) for the specific type.]}
1868 @end{Ramification}
1869 @begin{Reason}
1870 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
1871 @Leading@;The wording of the above @Chg{Version=[3],New=[rules],Old=[rule]}
1872 is intended to ensure that the same body is executed for a given tag,
1873 whether that tag is determined statically or dynamically.
1874 For a type declared in a package,
1875 it doesn't matter whether a given subprogram is
1876 overridden in the visible part or the private part,
1877 and it doesn't matter whether the call is inside or outside the package.
1878 For example:
1879 @begin{Example}
1880 @key[package] P1 @key[is]
1881 @key[type] T1 @key[is] @key[tagged] @key[null] @key[record];
1882 @key[procedure] Op_A(Arg : @key[in] T1);
1883 @key[procedure] Op_B(Arg : @key[in] T1);
1884 @key[end] P1;
1885
1886 @key[with] P1; @key[use] P1;
1887 @key[package] P2 @key[is]
1888 @key[type] T2 @key[is] @key[new] T1 @key[with] @key[null] @key[record];
1889 @key[procedure] Op_A(Param : @key[in] T2);
1890 @key[private]
1891 @key[procedure] Op_B(Param : @key[in] T2);
1892 @key[end] P2;
1893
1894 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00009 & AI-00114}
1895 @key[with] P1; @key[with] P2;
1896 @key[procedure] Main @key[is]
1897 X : @Chg{New=[P2.],Old=[]}T2;
1898 Y : @Chg{New=[P1.],Old=[]}T1'Class := X;
1899 @key[begin]
1900 P2.Op_A(Param => X); --@RI{ Nondispatching call@Chg{New=[ to a dispatching operation],Old=[]}.}
1901 P1.Op_A(Arg => Y); --@RI{ Dispatching call.}
1902 P2.Op_B(Arg => X); --@RI{ Nondispatching call@Chg{New=[ to a dispatching operation],Old=[]}.}
1903 P1.Op_B(Arg => Y); --@RI{ Dispatching call.}
1904 @key[end] Main;
1905 @end{Example}
1906
1907 The two calls to Op_A both execute the body of Op_A that has to occur in
1908 the body of package P2.
1909 Similarly,
1910 the two calls to Op_B both execute the body of Op_B that has to occur in
1911 the body of package P2,
1912 even though Op_B is overridden in the private part of P2.
1913 Note, however, that the formal parameter names are different for P2.Op_A
1914 versus P2.Op_B.
1915 The overriding declaration for P2.Op_B is not visible in Main,
1916 so the name in the call actually denotes the implicit declaration
1917 of Op_B inherited from T1.
1918
1919
1920 If a call occurs in the program text before an overriding,
1921 which can happen only if the call is part of a default expression,
1922 the overriding will still take effect for that call.
1923
1924 @end{Reason}
1925
1926 @begin{ImplNote}
1927 Even when a tag is not @i(statically determined), a compiler
1928 might still be able to figure it out and thereby avoid
1929 the overhead of run-time dispatching.
1930 @end{implnote}
1931
1932 @end{RunTime}
1933
1934 @begin{Notes}
1935
1936 The body to be executed for a call on a dispatching operation is
1937 determined by the tag;
1938 it does not matter whether that tag is determined statically or
1939 dynamically,
1940 and it does not matter whether the subprogram's declaration is visible at
1941 the place of the call.
1942
1943
1944 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02]}
1945 This subclause covers calls on @Chg{Version=[2],New=[dispatching],
1946 Old=[primitive]} subprograms of a tagged type.
1947 Rules for tagged type membership tests are described
1948 in @RefSecNum(Relational Operators and Membership Tests).
1949 Controlling tag determination for an
1950 @nt{assignment_statement}
1951 is described in @RefSecNum(Assignment Statements).
1952
1953 A dispatching call can dispatch to a body whose declaration is
1954 not visible at the place of the call.
1955
1956 A call through an access-to-subprogram value is never
1957 a dispatching call, even if the
1958 access value designates a dispatching operation. Similarly
1959 a call whose @nt<prefix> denotes a @nt<subprogram_renaming_declaration>
1960 cannot be a dispatching call unless the renaming itself is the
1961 declaration of a primitive subprogram.
1962 @end{Notes}
1963
1964 @begin{Extend83}
1965 @Defn{extensions to Ada 83}
1966 The concept of dispatching operations is new.
1967 @end{Extend83}
1968
1969 @begin{Incompatible95}
1970 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00404-01]}
1971 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
1972 If a dispatching operation is defined by a
1973 @nt{subprogram_renaming_declaration}, and it has a controlling access
1974 parameter, Ada 2005 requires the subtype of the parameter to exclude null.
1975 The same applies to instantiations. This is required so that all
1976 calls to the subprogram operate the same way (controlling access parameters
1977 have to exclude null so that dispatching calls will work).
1978 Since Ada 95 didn't have the notion of access subtypes
1979 that exclude null, and all access parameters excluded null, it had no such
1980 rules. These rules will require the
1981 addition of an explicit @key{not null} on nondispatching operations that are
1982 later renamed to be dispatching, or on a generic that is used to define a
1983 dispatching operation.]}
1984 @end{Incompatible95}
1985
1986 @begin{Extend95}
1987 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
1988 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1989 Functions that have an access result type can be dispatching in
1990 the same way as a function that returns a tagged object directly.]}
1991 @end{Extend95}
1992
1993 @begin{Diffword95}
1994 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0010],ARef=[AI95-00127-01]}
1995 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1996 @ChgAdded{Version=[2],Text=[@b<Corrigendum:>@ChgNote{This is documented as an extension in
1997 the two @Chg{Version=[3],New=[clauses],Old=[sections]} referenced below.}
1998 Allocators and access attributes of objects of class-wide types
1999 can be used as the controlling parameter in a dispatching calls. This
2000 was an oversight in the definition of Ada 95. (See @RefSecNum{Operations of Access Types} and
2001 @RefSecNum{Allocators}).]}
2002
2003 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0011],ARef=[AI95-00117-01],ARef=[AI95-00430-01]}
2004 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the conventions of
2005 dispatching operations. This is extended in Ada 2005 to cover operations
2006 inherited from progenitors, and to ensure that the conventions of all
2007 inherited operations are the same.]}
2008
2009 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00196-01]}
2010 @ChgAdded{Version=[2],Text=[Clarified the wording to ensure that functions with
2011 no controlling operands are tag-indeterminate, and to describe that the
2012 controlling tag can come from the target of an @nt{assignment_statement}.]}
2013
2014 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00239-01]}
2015 @ChgAdded{Version=[2],Text=[Fixed the wording to cover default expressions
2016 inherited by derived subprograms. A literal reading of the old wording
2017 would have implied that operations would be called with objects of the
2018 wrong type.]}
2019
2020 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
2021 @ChgAdded{Version=[2],Text=[An abstract formal subprogram is a dispatching
2022 operation, even though it is not a primitive operation. See
2023 @RefSec{Formal Subprograms}.]}
2024
2025 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2026 @ChgAdded{Version=[2],Text=[Dispatching calls include operations
2027 implemented by entries and protected operations, so we have to update the
2028 wording to reflect that.]}
2029
2030 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00335-01]}
2031 @ChgAdded{Version=[2],Text=[A stream attribute of a tagged type is
2032 usually a dispatching operation, even though it is not a primitive
2033 operation. If they weren't dispatching, T'Class'Input and T'Class'Output
2034 wouldn't work.]}
2035 @end{Diffword95}
2036
2037 @begin{Diffword2005}
2038 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0076-1]}
2039 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined
2040 @ldquote@;function with a controlling result@rdquote, as it is used
2041 in @RefSecNum{Abstract Types and Subprograms}.]}
2042
2043 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0126-1],ARef=[AI05-0197-1]}
2044 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected holes in the
2045 definition of dynamic dispatching: the behavior for operations that are
2046 never declared and/or inherited from a progenitor were not specified.]}
2047 @end{Diffword2005}
2048
2049
2050 @LabeledSubClause{Abstract Types and Subprograms}
2051
2052 @begin{Intro}
2053 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
2054 @redundant[@Defn{abstract type}
2055 @IndexSeeAlso{Term=[abstract data type (ADT)],See=(abstract type)}
2056 @IndexSeeAlso{Term=[ADT (abstract data type)],See=(abstract type)}
2057 @IndexSee{Term=[concrete type],See=(nonabstract type)}
2058 An @i(abstract type) is a tagged type intended
2059 for use as @Chg{Version=[2],New=[an ancestor of other types],Old=[a parent
2060 type for type extensions]}, but which is not allowed to have objects of its own.
2061 @Defn{abstract subprogram}
2062 @IndexSee{Term=[concrete subprogram],See=(nonabstract subprogram)}
2063 An @i(abstract subprogram) is a subprogram that has no body,
2064 but is intended to be overridden at some point when inherited.
2065 Because objects of an abstract type cannot be created,
2066 a dispatching call to an abstract subprogram always
2067 dispatches to some overriding body.]
2068 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Abstract type>,
2069 Text=<@ChgAdded{Version=[2],Text=[An abstract type is a tagged type
2070 intended for use as an ancestor of other types, but which is not allowed to
2071 have objects of its own.]}>}
2072 @end{Intro}
2073
2074 @begin{MetaRules}
2075 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2076 An abstract subprogram has no body, so the
2077 rules in this @Chg{Version=[3],New=[subclause],Old=[clause]} are
2078 designed to ensure (at compile time)
2079 that the body will never be invoked.
2080 We do so primarily by disallowing the creation of
2081 values of the abstract type.
2082 Therefore, since type conversion and parameter passing
2083 don't change the tag, we know we will
2084 never get a class-wide value with a tag identifying an abstract type.
2085 This means that we only have to disallow nondispatching calls
2086 on abstract subprograms (dispatching calls will never reach them).
2087 @end{MetaRules}
2088
2089 @begin{Syntax}
2090 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00218-03],ARef=[AI95-00348-01]}
2091 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
2092 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<abstract_subprogram_declaration>,Old=<>}>,
2093 rhs="@Chg{Version=[2],New=<
2094 [@Syn2{overriding_indicator}]
2095 @Syn2{subprogram_specification} @key{is} @key{abstract}@Chg{Version=[3],New=<
2096 [@Syn2{aspect_specification}]>,Old=[]};>,Old=<>}"}
2097 @end{Syntax}
2098
2099 @begin{StaticSem}
2100 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
2101 @Chg{Version=[2],New=[@Defn{abstract type}
2102 @Defn2{Term=[type], Sec=(abstract)}Interface types
2103 (see @RefSecNum{Interface Types}) are
2104 abstract types. In addition, a tagged type that has the reserved word
2105 @key{abstract} in its declaration is an abstract type. The class-wide type
2106 (see @RefSecNum{Derivation Classes}) rooted at an abstract type is not itself
2107 an abstract type.],Old=[]}
2108 @end{StaticSem}
2109
2110 @begin{Legality}
2111 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
2112 @Chg{Version=[2],New=[Only a tagged type shall have],Old=[@Defn{abstract type}
2113 @Defn2{Term=[type], Sec=(abstract)}
2114 An @i{abstract type} is a specific type
2115 that has]} the reserved word @key{abstract} in its
2116 declaration.@Chg{Version=[2],New=[],Old=[Only a tagged type is allowed to be
2117 declared abstract.]}
2118 @begin{Ramification}@ChgNote{These AARM notes really belong on the
2119 Static Semantics paragraph, but I won't move them, as it's not worth the time.}
2120 Untagged types are never abstract,
2121 even though they can have primitive abstract subprograms.
2122 Such subprograms cannot be called,
2123 unless they also happen to be dispatching operations of
2124 some tagged type, and then only via a dispatching call.
2125
2126 Class-wide types are never abstract.
2127 If T is abstract, then it is illegal to declare a stand-alone
2128 object of type T,
2129 but it is OK to declare a stand-alone object of type T'Class;
2130 the latter will get a tag from its initial value,
2131 and this tag will necessarily be different from T'Tag.
2132 @end{Ramification}
2133
2134 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02],ARef=[AI95-00348-01]}
2135 @Defn{abstract subprogram}
2136 @Defn2{Term=[subprogram], Sec=(abstract)}
2137 A subprogram declared by an @nt{abstract_@!subprogram_@!declaration}
2138 @Chg{Version=[2],New=[or a
2139 @nt{formal_@!abstract_@!subprogram_@!declaration} (see @RefSecNum{Formal Subprograms})],
2140 Old=[(see @RefSecNum{Subprogram Declarations})]}
2141 is an @i{abstract subprogram}.
2142 If it is a primitive subprogram of a tagged type,
2143 then the tagged type shall be abstract.
2144 @begin{Ramification}
2145 @Leading@keepnext@;Note that for a private type, this applies to both views.
2146 The following is illegal:
2147 @begin{Example}
2148 @key[package] P @key[is]
2149 @key[type] T @key[is] @key[abstract] @key[tagged] @key[private];
2150 @key[function] Foo (X : T) @key[return] Boolean @key[is] @key[abstract]; --@RI{ Illegal!}
2151 @key[private]
2152 @key[type] T @key[is] @key[tagged] @key[null] @key[record]; --@RI{ Illegal!}
2153 X : T;
2154 Y : Boolean := Foo (T'Class (X));
2155 @key[end] P;
2156 @end{Example}
2157
2158 The full view of T is not abstract,
2159 but has an abstract operation Foo,
2160 which is illegal.
2161 The two lines marked "--@i{ Illegal!}" are illegal when taken together.
2162 @end{Ramification}
2163 @begin{Reason}
2164 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]}
2165 We considered disallowing untagged types from having abstract
2166 primitive subprograms.
2167 However, we rejected that plan, because it introduced some silly
2168 anomalies, and because such subprograms are harmless@Chg{Version=[2],
2169 New=[],Old=[ (if not terribly useful)]}.
2170 For example:
2171 @begin{Example}
2172 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00010}
2173 @key[package] P @key[is]
2174 @key[type] Field_Size @key[is] @key[range] 0..100;
2175 @key[type] T @key[is] @key[abstract tagged] @key[null] @key[record];
2176 @key[procedure] Print(X : @key[in] T; F : @key[in] Field_Size := 0) @key[is] @Chg{New=[@key[abstract]],Old=[abstract]};
2177 . . .
2178 @key[package] Q @key[is]
2179 @key[type] My_Field_Size @key[is] @key[new] Field_Size;
2180 --@RI{ implicit declaration of Print(X : T; F : My_Field_Size := 0) @Chg{New=[@key[is abstract]],Old=[is abstract]};}
2181 @key[end] Q;
2182 @end{Example}
2183
2184 It seemed silly to make the derivative of My_Field_Size illegal,
2185 just because there was an implicitly declared abstract subprogram
2186 that was not primitive on some tagged type.
2187 Other rules could be formulated to solve this problem,
2188 but the current ones seem like the simplest.
2189
2190 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00310-01]}
2191 @ChgAdded{Version=[2],Text=[In Ada 2005, abstract primitive subprograms of
2192 an untagged type may be used to @lquotes@;undefine@rquotes@; an operation.]}
2193 @end{Reason}
2194
2195 @begin{Ramification}
2196 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
2197 @ChgAdded{Version=[2],Text=[Note that the second sentence does not apply to
2198 abstract formal subprograms, as they are never primitive operations of
2199 a type.]}
2200 @end{Ramification}
2201
2202 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00334-01],ARef=[AI95-00391-01]}
2203 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0097-1],ARef=[AI05-0198-1]}
2204 @Chg{Version=[2],New=[If a type has an implicitly declared primitive subprogram
2205 that is inherited or is @Chg{Version=[3],New=[a],Old=[the]} predefined
2206 @Chg{Version=[3],New=[],Old=[equality ]}operator, and the corresponding
2207 primitive subprogram of],Old=[For a derived type, if]}
2208 the parent or ancestor type
2209 @Chg{Version=[2],New=[is abstract or is a function with a controlling access
2210 result, or if a type other than a
2211 @Chg{Version=[3],New=[nonabstract ],Old=[]}null extension inherits a],
2212 Old=[has an abstract primitive subprogram, or a primitive]}
2213 function with a controlling result, then:
2214 @begin{Ramification}
2215 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0068-1]}
2216 @ChgAdded{Version=[3],Text=[These rules apply to each view of the type
2217 individually. That is necessary to preserve privacy. For instance, in the
2218 following example:]}
2219 @begin{Example}
2220 @ChgRef{Version=[3],Kind=[AddedNormal]}
2221 @ChgAdded{Version=[3],Text=[@key[package] P @key[is]
2222 @key[type] I @key[is interface];
2223 @key[procedure] Op (X : I) @key[is abstract];
2224 @key[end] P;]}
2225
2226 @ChgRef{Version=[3],Kind=[AddedNormal]}
2227 @ChgAdded{Version=[3],Text=[@key[with] P;
2228 @key[package] Q @key[is]
2229 @key[type] T @key[is abstract new] P.I @key[with private];
2230 -- @RI[Op inherited here.]
2231 @key[private]
2232 @key[type] T @key[is abstract new] P.I @key[with null record];
2233 @key[procedure] Op (X : T) @key[is null];
2234 @key[end] Q;]}
2235
2236 @ChgRef{Version=[3],Kind=[AddedNormal]}
2237 @ChgAdded{Version=[3],Text=[@key[with] Q;
2238 @key[package] R @key[is]
2239 @key[type] T2 @key[is new] Q.T @key[with null record];
2240 -- @RI[Illegal. Op inherited here, but requires overriding.]
2241 @key[end] R;]}
2242 @end{Example}
2243 @ChgRef{Version=[3],Kind=[AddedNormal]}
2244 @ChgAdded{Version=[3],Text=[If this did not depend on the view,
2245 this would be legal. But in that case, the fact that Op is overridden
2246 in the private part would be visible; package R would have to be
2247 illegal if no overriding was in the private part.]}
2248
2249 @ChgRef{Version=[3],Kind=[AddedNormal]}
2250 @ChgAdded{Version=[3],Text=[Note that this means that whether an inherited
2251 subprogram is abstract or concrete depends on where it inherited.
2252 In the case of Q, Q.Op in the visible part is abstract,
2253 while Q.Op in the private part is concrete. That is, R is illegal since
2254 it is an unrelated unit (and thus it cannot see the private part), but if
2255 R had been a private child of Q, it would have been legal.]}
2256 @end{Ramification}
2257 @begin{Itemize}
2258 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00334-01]}
2259 If the @Chg{Version=[2],New=[],Old=[derived ]}type is abstract or untagged,
2260 the @Chg{Version=[2],New=[implicitly declared],Old=[inherited]} subprogram is
2261 @i{abstract}.
2262 @begin{Ramification}
2263 Note that it is possible to override a concrete subprogram
2264 with an abstract one.
2265 @end{Ramification}
2266
2267 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00391-01]}
2268 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
2269 Otherwise, the subprogram shall be overridden with a nonabstract
2270 subprogram@Chg{Version=[2],New=[ or, in the case of a private extension
2271 inheriting a @Chg{Version=[4],New=[nonabstract ],Old=[]}function with a
2272 controlling result, have a full type that is a null
2273 extension],Old=[]}@Redundant[; for a type declared in the visible part of
2274 a package, the overriding may be either in the visible or the private part].
2275 @Chg{Version=[2],New=[Such a subprogram is said to
2276 @i{require overriding}.@Defn{require overriding} ],Old=[]}However,
2277 if the type is a generic formal type,
2278 the subprogram need not be overridden for the formal type itself;
2279 @Redundant[a nonabstract version will necessarily be provided by the
2280 actual type.]
2281 @begin{Reason}
2282 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00228-01],ARef=[AI95-00391-01]}
2283 A function that returns the parent type @Chg{Version=[2],New=[requires
2284 overriding],Old=[becomes abstract]}@ChgNote{Can't leave this ancient and broken terminology around here!!}
2285 for @Chg{Version=[2],New=[a],Old=[an abstract]} type
2286 extension @Chg{Version=[2],New=[(or becomes abstract for an abstract type)],
2287 Old=[(if not overridden)]} because conversion
2288 from a parent type to a type extension is
2289 not defined, and function return semantics is defined in terms
2290 of conversion@Chg{Version=[2],New=[ (other than for a null extension;
2291 see below)],Old=[]}. (Note that parameters of mode @key{in out} or
2292 @key{out} do not have this problem, because the tag of the actual
2293 is not changed.)
2294
2295 @Leading@keepnext@;Note that the overriding required above can be in the
2296 private part, which allows the following:
2297 @begin{Example}
2298 @key[package] Pack1 @key[is]
2299 @key[type] Ancestor @key[is] @key[abstract] ...;
2300 @key[procedure] Do_Something(X : @key[in] Ancestor) @key[is] @key[abstract];
2301 @key[end] Pack1;
2302
2303 @key[with] Pack1; @key[use] Pack1;
2304 @key[package] Pack2 @key[is]
2305 @key[type] T1 @key[is] @key[new] Ancestor @key[with] @key[record] ...;
2306 --@RI{ A concrete type.}
2307 @key[procedure] Do_Something(X : @key[in] T1); --@RI{ Have to override.}
2308 @key[end] Pack2;
2309
2310 @key[with] Pack1; @key[use] Pack1;
2311 @key[with] Pack2; @key[use] Pack2;
2312 @key[package] Pack3 @key[is]
2313 @key[type] T2 @key[is] @key[new] Ancestor @key[with] @key[private];
2314 --@RI{ A concrete type.}
2315 @key[private]
2316 @key[type] T2 @key[is] @key[new] T1 @key[with] --@RI{ Parent different from ancestor.}
2317 @key[record] ... @key[end] @key[record];
2318 --@RI{ Here, we inherit Pack2.Do_Something.}
2319 @key[end] Pack3;
2320 @end{Example}
2321
2322 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00011}
2323 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00228-01]}
2324 T2 inherits an abstract Do_Something, but @Chg{New=[T2],Old=[T]} is not
2325 abstract, so Do_Something has to be overridden.
2326 However, it is OK to override it in the private part.
2327 In this case, we override it by inheriting a concrete version
2328 from a different type.
2329 Nondispatching calls to Pack3.Do_Something are allowed
2330 both inside and outside package Pack3@Chg{Version=[2],New=[, as the
2331 client @lquotes@;knows@rquotes@; that the subprogram was necessarily
2332 overridden somewhere],Old=[]}.
2333
2334 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2335 @ChgAdded{Version=[2],Text=[For a null extension, the result of a function
2336 with a controlling result is defined in terms of an @nt{extension_aggregate}
2337 with a @key{null record} extension part
2338 (see @RefSecNum{Derived Types and Classes}). This means that these
2339 restrictions on functions with a controlling result do not have to apply to
2340 null extensions.]}
2341
2342 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2343 @ChgAdded{Version=[2],Text=[However, functions with controlling access
2344 results still require overriding. Changing the tag in place might clobber
2345 a preexisting object, and allocating new memory would possibly change the
2346 pool of the object, leading to storage leaks. Moreover, copying the object
2347 isn't possible for limited types. We don't need to restrict functions
2348 that have an access return type of an untagged type, as derived types
2349 with primitive subprograms have to have the same representation as their
2350 parent type.]}
2351 @end{Reason}
2352 @end{Itemize}
2353
2354 A call on an abstract subprogram shall be a dispatching call;
2355 @Redundant[nondispatching calls to an abstract subprogram are not
2356 allowed.]
2357 @begin{Ramification}
2358 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]}
2359 If an abstract subprogram is not a dispatching operation of
2360 some tagged type, then it cannot be called at
2361 all.@Chg{Version=[2],New=[ In Ada 2005, such subprograms are not
2362 even considered by name resolution (see @RefSecNum{Subprogram Calls}).],Old=[]}
2363 @end{Ramification}
2364
2365 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0073-1],ARef=[AI05-0203-1]}
2366 The type of an @nt{aggregate}, or of an object created by an
2367 @nt{object_declaration} or an @nt{allocator},
2368 or a generic formal object of mode @key[in],
2369 shall not be abstract.
2370 The type of the target of an assignment
2371 operation (see @RefSecNum{Assignment Statements}) shall not
2372 be abstract.
2373 The type of a component shall not be abstract.
2374 If the result type of a function is abstract,
2375 then the function shall be abstract.@Chg{Version=[3],New=[
2376 If a function has an access result type
2377 designating an abstract type, then the function shall be abstract.
2378 The type denoted by a @nt{return_subtype_indication} (see
2379 @RefSecNum{Return Statements}) shall not be abstract. A generic function
2380 shall not have an abstract result type or an access result type designating an
2381 abstract type.],Old=[]}
2382 @begin{Reason}
2383 This ensures that values of an abstract type cannot be created,
2384 which ensures that a dispatching call to an abstract subprogram
2385 will not try to execute the nonexistent body.
2386
2387 Generic formal objects of mode @key[in] are like constants;
2388 therefore they should be forbidden for abstract types. Generic formal
2389 objects of mode @key[in out] are like renamings; therefore, abstract
2390 types are OK for them, though probably not terribly useful.
2391
2392 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0073-1]}
2393 @ChgAdded{Version=[3],Text=[Generic functions returning a formal
2394 abstract type are illegal because any instance would have to be
2395 instantiated with a nonabstract type in order to avoid violating
2396 the function rule (generic functions cannot be declared abstract).
2397 But that would be an implied contract; it would be better for the
2398 contract to be explicit by the formal type not being declared
2399 abstract. Moreover, the implied contract does not add any capability.]}
2400 @end{Reason}
2401
2402 If a partial view is not abstract, the corresponding
2403 full view shall not be abstract.
2404 If a generic formal type is abstract,
2405 then for each primitive subprogram of the formal that is not abstract,
2406 the corresponding primitive subprogram of the actual shall
2407 not be abstract.
2408 @begin{Discussion}
2409 By contrast, we allow the actual type to be nonabstract
2410 even if the formal type is declared abstract.
2411 Hence, the most general formal tagged type possible is "@key(type)
2412 T(<>) @key(is abstract tagged limited private);".
2413
2414 For an abstract private extension declared in the visible
2415 part of a package, it is only possible for the
2416 full type to be nonabstract if the private extension has
2417 no abstract dispatching operations.
2418 @end{Discussion}
2419 @begin{Honest}
2420 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00294-01]}
2421 @ChgAdded{Version=[2],Type=[Leading],Text=[In the sentence about primitive
2422 subprograms above, there is some ambiguity as to what is meant by
2423 @lquotes@;corresponding@rquotes@; in the
2424 case where an inherited operation is overridden. This is best explained by
2425 an example, where the implicit declarations are shown as comments:]}
2426 @begin{Example}
2427 @ChgRef{Version=[2],Kind=[AddedNormal]}
2428 @ChgAdded{Version=[2],Text=[@key{package} P1 @key{is}
2429 @key{type} T1 @key{is abstract tagged null record};
2430 @key{procedure} P (X : T1); -- @RI[(1)]
2431 @key{end} P1;]}
2432
2433 @ChgRef{Version=[2],Kind=[AddedNormal]}
2434 @ChgAdded{Version=[2],Text=[@key{package} P2 @key{is}
2435 @key{type} T2 @key{is abstract new} P1.T1 @key{with null record};
2436 -- @RI[@key{procedure} P (X : T2); -- (2)]
2437 @key{procedure} P (X : T2) @key{is abstract}; -- (3)
2438 end P2;]}
2439
2440 @ChgRef{Version=[2],Kind=[AddedNormal]}
2441 @ChgAdded{Version=[2],Text=[@key{generic}
2442 @key{type} D @key{is abstract new} P1.T1 @key{with private};
2443 -- @RI[@key{procedure} P (X : D); -- (4)]
2444 @key{procedure} G (X : D);]}
2445
2446 @ChgRef{Version=[2],Kind=[AddedNormal]}
2447 @ChgAdded{Version=[2],Text=[@key{procedure} I @key{is new} G (P2.T2); -- @RI[Illegal.]]}
2448 @end{Example}
2449
2450 @ChgRef{Version=[2],Kind=[AddedNormal]}
2451 @Chg{Version=[2],New=[Type T2 inherits a nonabstract procedure P (2) from the
2452 primitive procedure P (1) of T1. P (2) is overridden by the explicitly declared
2453 abstract procedure P (3). Type D inherits a nonabstract procedure P (4) from P
2454 (1). In instantiation I, the operation corresponding to P (4) is the one which
2455 is not overridden, that is, P (3): the overridden operation P (2) does not
2456 @lquotes@;reemerge@rquotes@;. Therefore, the instantiation is illegal.],Old=[]}
2457 @end{Honest}
2458
2459 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0073-1]}
2460 For an abstract type declared in a visible part,
2461 an abstract primitive subprogram
2462 shall not be declared in the private part,
2463 unless it is overriding an abstract subprogram
2464 implicitly declared in the visible part.
2465 For a tagged type declared in a visible part,
2466 a primitive function with a controlling result@Chg{Version=[3],New=[
2467 or a controlling access result],Old=[]} shall not be declared
2468 in the private part, unless it is overriding a function
2469 implicitly declared in the visible part.
2470 @begin{Reason}
2471 @Leading@;The @lquotes@;visible part@rquotes@; could be that of a package
2472 or a generic package. This rule is needed because a nonabstract type extension
2473 declared outside the package would not know about any abstract primitive
2474 subprograms or primitive functions with controlling results
2475 declared in the private part, and wouldn't know that they
2476 need to be overridden with nonabstract subprograms.
2477 The rule applies to a tagged record type or record extension declared
2478 in a visible part,
2479 just as to a tagged private type or private extension.
2480 The rule applies to explicitly and implicitly declared abstract
2481 subprograms:
2482 @begin{Example}
2483 @key[package] Pack @key[is]
2484 @key[type] T @key[is] @key[abstract] @key[new] T1 @key[with] @key[private];
2485 @key[private]
2486 @key[type] T @key[is] @key[abstract] @key[new] T2 @key[with] @key[record] ... @key[end] @key[record];
2487 ...
2488 @key[end] Pack;
2489 @end{Example}
2490
2491 The above example would be illegal if T1 has a nonabstract primitive
2492 procedure P, but T2 overrides P with an abstract one;
2493 the private part should override P with a nonabstract version.
2494 On the other hand, if the P were abstract for both T1 and T2,
2495 the example would be legal as is.
2496 @end{Reason}
2497
2498 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02]}
2499 A generic actual subprogram shall not be an abstract
2500 subprogram @Chg{Version=[2],New=[unless the generic formal subprogram is
2501 declared by a @nt{formal_abstract_subprogram_declaration}],Old=[]}.
2502 The @nt{prefix} of an @nt{attribute_reference} for the Access,
2503 Unchecked_Access, or Address attributes shall not denote an abstract subprogram.
2504 @begin{Ramification}
2505 An @nt{abstract_subprogram_declaration} is not syntactically a
2506 @nt{subprogram_declaration}.
2507 Nonetheless, an abstract subprogram is a subprogram,
2508 and an @nt{abstract_subprogram_declaration} is a declaration of a subprogram.
2509
2510 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00260-02]}
2511 The part about generic actual subprograms includes those given by
2512 default.@Chg{Version=[2],New=[ Of course, an abstract formal subprogram's
2513 actual subprogram can be abstract.],Old=[]}
2514 @end{Ramification}
2515 @end{Legality}
2516
2517 @begin{Runtime}
2518 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]}
2519 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[elaboration], Sec=(abstract_subprogram_declaration)}
2520 The elaboration of an @nt{abstract_subprogram_declaration} has no effect.]}
2521 @end{Runtime}
2522
2523 @begin{Notes}
2524 Abstractness is not inherited; to declare an abstract type,
2525 the reserved word @key[abstract] has to be used
2526 in the declaration of the type extension.
2527 @begin{Ramification}
2528 A derived type can be abstract even if its parent is not.
2529 Similarly, an inherited concrete subprogram can be overridden with an
2530 abstract subprogram.
2531 @end{Ramification}
2532
2533 A class-wide type is never abstract. Even if a class
2534 is rooted at an abstract type, the class-wide type for the
2535 class is not abstract, and an object of the class-wide type
2536 can be created; the tag of such an object will identify
2537 some nonabstract type in the class.
2538 @end{Notes}
2539
2540 @begin{Examples}
2541 @Leading@keepnext@i(Example of an abstract type representing a set of natural numbers:)
2542 @begin{Example}
2543 @key(package) Sets @key(is)
2544 @key(subtype) Element_Type @key(is) Natural;
2545 @key(type) Set @key(is abstract tagged null record);
2546 @key(function) Empty @key(return) Set @key(is abstract);
2547 @key(function) Union(Left, Right : Set) @key(return) Set @key(is abstract);
2548 @key(function) Intersection(Left, Right : Set) @key(return) Set @key(is abstract);
2549 @key(function) Unit_Set(Element : Element_Type) @key(return) Set @key(is abstract);
2550 @key(procedure) Take(Element : @key(out) Element_Type;
2551 From : @key(in out) Set) @key(is abstract);
2552 @key(end) Sets;
2553 @end{Example}
2554 @end{Examples}
2555
2556 @begin{Notes}
2557 @i(Notes on the example:)
2558 Given the above abstract type, one could then derive
2559 various (nonabstract) extensions of the type, representing
2560 alternative implementations of a set. One might use a bit
2561 vector, but impose an upper bound on the largest element representable,
2562 while another might use a hash table, trading off space for flexibility.
2563 @begin{Discussion}
2564 One way to export a type from a package with some components visible
2565 and some components private is as follows:
2566 @begin{Example}
2567 @key[package] P @key[is]
2568 @key[type] Public_Part @key[is] @key[abstract] @key[tagged]
2569 @key[record]
2570 ...
2571 @key[end] @key[record];
2572 @key[type] T @key[is] @key[new] Public_Part @key[with] @key[private];
2573 ...
2574 @key[private]
2575 @key[type] T @key[is] @key[new] Public_Part @key[with]
2576 @key[record]
2577 ...
2578 @key[end] @key[record];
2579 @key[end] P;
2580 @end{Example}
2581
2582 The fact that Public_Part is abstract tells clients they have to
2583 create objects of type T instead of Public_Part.
2584 Note that the public part has to come first;
2585 it would be illegal to declare a private type Private_Part,
2586 and then a record extension T of it,
2587 unless T were in the private part after the full declaration of Private_Part,
2588 but then clients of the package would not have visibility to T.
2589 @end{Discussion}
2590 @end{Notes}
2591
2592 @begin{Extend95}
2593 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2594 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2595 It is not necessary to override functions with a controlling result
2596 for a null extension. This makes it easier to derive a tagged type
2597 to complete a private type.]}
2598 @end{Extend95}
2599
2600 @begin{Diffword95}
2601 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2602 @ChgAdded{Version=[2],Text=[Updated the wording to reflect the addition of
2603 interface types (see @RefSecNum{Interface Types}).]}
2604
2605 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00260-02]}
2606 @ChgAdded{Version=[2],Text=[Updated the wording to reflect the addition of
2607 abstract formal subprograms (see @RefSecNum{Formal Subprograms}).]}
2608
2609 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00334-01]}
2610 @ChgAdded{Version=[2],Text=[The wording of shall-be-overridden was clarified
2611 so that it clearly applies to abstract predefined equality.]}
2612
2613 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]}
2614 @ChgAdded{Version=[2],Text=[Moved the syntax and elaboration rule for
2615 @nt{abstract_subprogram_declaration} here, so the syntax and most of the
2616 semantics are together (which is consistent with null procedures).]}
2617
2618 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
2619 @ChgAdded{Version=[2],Text=[We define the term @i<require overriding>
2620 to make other wording easier to understand.]}
2621 @end{Diffword95}
2622
2623 @begin{Incompatible2005}
2624 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0073-1]}
2625 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2626 Added rules to eliminate holes with controlling access results and generic
2627 functions that return abstract types. While these changes are technically
2628 incompatible, it is unlikely that they could be used in a program without
2629 violating some other rule of the use of abstract types.]}
2630
2631 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0097-1]}
2632 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected a minor
2633 glitch having to do with abstract null extensions. The Ada 2005
2634 rule allowed such extensions to inherit concrete operations in some
2635 rare cases. It is unlikely that these cases exist in user code.]}
2636 @end{Incompatible2005}
2637
2638 @begin{Extend2005}
2639 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2640 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2641 An optional @nt{aspect_specification} can be used in an
2642 @nt{abstract_subprogram_declaration}.
2643 This is described in @RefSecNum{Aspect Specifications}.]}
2644 @end{Extend2005}
2645
2646 @begin{Diffword2005}
2647 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0198-1]}
2648 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that the predefined
2649 operator corresponding to an inherited abstract operator is also abstract. The
2650 Ada 2005 rules caused the predefined operator and the inherited operator to
2651 override each other, which is weird. But the effect is the same either way
2652 (the operator is not considered for resolution).]}
2653
2654 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0203-1]}
2655 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to
2656 disallow abstract return objects. These were illegal in Ada 2005 by other
2657 rules; the extension to support class-wide type better opened a hole which
2658 has now been plugged.]}
2659 @end{Diffword2005}
2660
2661
2662 @LabeledAddedSubClause{Version=[2],Name=[Interface Types]}
2663
2664 @begin{Intro}
2665 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2666 @ChgAdded{Version=[2],Text=[@Redundant[An interface type is an abstract tagged
2667 type that provides a restricted form of multiple inheritance. A tagged type,
2668 task type, or protected type may have one or more interface types as
2669 ancestors.]]}
2670 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Interface type>,
2671 Text=<@ChgAdded{Version=[2],Text=[An interface type is a form of abstract
2672 tagged type which has no components or concrete operations
2673 except possibly null procedures. Interface types are used for
2674 composing other interfaces and tagged types and thereby
2675 provide multiple inheritance. Only an interface type can be used as a
2676 progenitor of another type.]}>}
2677 @end{Intro}
2678
2679 @begin{MetaRules}
2680 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2681 @ChgAdded{Version=[2],Type=[Leading],Text=[The rules are designed so that an
2682 interface can be used as either a parent type or a progenitor type without
2683 changing the meaning. That's important so that the order that interfaces are
2684 specified in a @nt{derived_type_definition} is not significant. In particular,
2685 we want:]}
2686 @begin{Example}
2687 @ChgRef{Version=[2],Kind=[AddedNormal]}
2688 @ChgAdded{Version=[2],Text=[@key{type} Con1 @key{is new} Int1 @key{and} Int2 @key{with null record};
2689 @key{type} Con2 @key{is new} Int2 @key{and} Int1 @key{with null record};]}
2690 @end{Example}
2691 @ChgRef{Version=[2],Kind=[AddedNormal]}
2692 @ChgAdded{Version=[2],Type=[Trailing],Text=[to mean exactly the same thing.]}
2693 @end{MetaRules}
2694
2695 @begin{Syntax}
2696
2697 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2698 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<interface_type_definition>,Old=<>}>,
2699 rhs="@Chg{Version=[2],New=<
2700 [@key{limited} | @key{task} | @key{protected} | @key{synchronized}] @key{interface} [@key{and} @Syn2{interface_list}]>,Old=<>}"}
2701
2702 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00419-01]}
2703 @Syn{lhs=<@Chg{Version=[2],New=<interface_list>,Old=<>}>,
2704 rhs="@Chg{Version=[2],New=<@SynI{interface_}@Syn2{subtype_mark} {@key{and} @SynI{interface_}@Syn2{subtype_mark}}>,Old=<>}"}
2705
2706 @end{Syntax}
2707
2708 @begin{StaticSem}
2709
2710 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2711 @Chg{Version=[2],New=[An interface type (also called an @i{interface})
2712 is@RootDefn{interface}@PDefn2{Term=[interface],Sec=[type]}
2713 a specific abstract tagged type that is defined by
2714 an @nt{interface_type_definition}.],Old=[]}
2715
2716 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2717 @ChgAdded{Version=[2],Text=[An interface with the reserved word @key{limited},
2718 @key{task}, @key{protected},
2719 or @key{synchronized} in its definition is termed, respectively, a @i{limited
2720 interface}, a @i{task interface}, a @i{protected interface}, or a
2721 @i{synchronized interface}.
2722 In addition,@PDefn2{Term=[interface],Sec=[synchronized]}
2723 @PDefn2{Term=[interface],Sec=[protected]}
2724 @PDefn2{Term=[interface],Sec=[task]}
2725 @PDefn2{Term=[interface],Sec=[limited]}
2726 @PDefn2{Term=[interface],Sec=[nonlimited]}
2727 @Defn{synchronized interface}
2728 @Defn{protected interface}
2729 @Defn{task interface}
2730 @Defn{limited interface}
2731 @Defn{nonlimited interface}
2732 all task and protected interfaces
2733 are synchronized interfaces, and all synchronized interfaces are limited
2734 interfaces.]}
2735 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Synchronized>,
2736 Text=<@ChgAdded{Version=[2],Text=[A synchronized entity is one
2737 that will work safely with multiple tasks at one time. A synchronized
2738 interface can be an ancestor of a task or a protected type. Such a
2739 task or protected type is called a synchronized tagged type.]}>}
2740
2741 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00443-01]}
2742 @ChgAdded{Version=[2],Text=[@Defn{synchronized tagged type}
2743 @PDefn2{Term=[type],Sec=[synchronized tagged]}
2744 @PDefn2{Term=[tagged type],Sec=[synchronized]}
2745 @PDefn2{Term=[tagged type],Sec=[task]}
2746 @PDefn2{Term=[tagged type],Sec=[protected]}
2747 @Defn{task tagged type}
2748 @Defn{protected tagged type}
2749 @Redundant[A task or protected type derived from an interface is a tagged type.]
2750 Such a tagged type is called a @i<synchronized> tagged
2751 type, as are synchronized interfaces and private extensions whose declaration
2752 includes the reserved word @b{synchronized}.]}
2753
2754 @begin{TheProof}
2755 @ChgRef{Version=[2],Kind=[AddedNormal]}
2756 @ChgAdded{Version=[2],Text=[The full definition of tagged types given in
2757 @RefSecNum{Tagged Types and Type Extensions} includes task and protected types
2758 derived from interfaces.]}
2759 @end{TheProof}
2760 @begin{Ramification}
2761 @ChgRef{Version=[2],Kind=[AddedNormal]}
2762 @ChgAdded{Version=[2],Text=[The class-wide type associated with a tagged task
2763 type (including a task interface type) is a task type, because
2764 @lquotes@;task@rquotes is one of the language-defined classes of types (see
2765 @RefSecNum{Types and Subtypes}). However, the class-wide type associated with an
2766 interface is @i<not> an interface type, as @lquotes@;interface@rquotes is
2767 @i<not> one of the language-defined classes (as it is not closed under
2768 derivation). In this sense, @lquotes@;interface@rquotes is similar to
2769 @lquotes@;abstract@rquotes. The class-wide type associated with an interface is
2770 a concrete (nonabstract) indefinite tagged composite type.]}
2771
2772 @ChgRef{Version=[2],Kind=[AddedNormal]}
2773 @ChgAdded{Version=[2],Text=[@lquotes@;Private extension@rquotes@; includes
2774 generic formal private extensions, as explained in
2775 @RefSecNum{Formal Private and Derived Types}.]}
2776 @end{Ramification}
2777
2778 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2779 @ChgAdded{Version=[2],Text=[A task interface is an @Redundant[abstract] task
2780 type. A protected interface is an @Redundant[abstract] protected type.]}
2781 @begin{TheProof}
2782 @ChgRef{Version=[2],Kind=[AddedNormal]}
2783 @ChgAdded{Version=[2],Text=[The @lquotes@;abstract@rquotes follows
2784 from the definition of an interface type.]}
2785 @end{TheProof}
2786 @begin{Reason}
2787 @ChgRef{Version=[2],Kind=[AddedNormal]}
2788 @ChgAdded{Version=[2],Text=[This ensures that task operations (like abort and
2789 the Terminated attribute) can be applied to a task interface type and the
2790 associated class-wide type. While there are no protected type operations,
2791 we apply the same rule to protected interfaces for consistency.]}
2792 @end{Reason}
2793
2794 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2795 @Chg{Version=[2],New=[@Redundant[An interface type has no components.]],Old=[]}
2796 @begin{TheProof}
2797 @ChgRef{Version=[2],Kind=[AddedNormal]}
2798 @ChgAdded{Version=[2],Text=[This follows from the syntax and the fact that
2799 discriminants are not allowed for interface types.]}
2800 @end{TheProof}
2801
2802 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00419-01]}
2803 @ChgAdded{Version=[2],Text=[@Defn{progenitor subtype}@Defn{progenitor type}
2804 An @Syni(interface_)@nt{subtype_mark} in an @nt{interface_list} names a
2805 @i(progenitor subtype); its type is the @i(progenitor type).
2806 An interface type inherits user-defined primitive subprograms from each
2807 progenitor type in the same way that a derived type inherits user-defined
2808 primitive subprograms from its progenitor types
2809 (see @RefSecNum{Derived Types and Classes}).]}
2810 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Progenitor>,
2811 Text=<@ChgAdded{Version=[2],Text=[A progenitor of a derived type is
2812 one of the types given in the definition of the derived type other
2813 than the first. A progenitor is always an interface type.
2814 Interfaces, tasks, and protected types may also have progenitors.]}>}
2815
2816 @end{StaticSem}
2817
2818 @begin{Legality}
2819
2820 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2821 @Chg{Version=[2],New=[All user-defined primitive subprograms of an interface
2822 type shall be abstract subprograms or null procedures.],Old=[]}
2823
2824 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2825 @Chg{Version=[2],New=[The type of a subtype named in an @nt{interface_list}
2826 shall be an interface type.],Old=[]}
2827
2828 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
2829 @ChgAdded{Version=[2],Text=[A type derived from a nonlimited interface shall be
2830 nonlimited.]}
2831
2832 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2833 @ChgAdded{Version=[2],Text=[An interface derived from a task interface shall
2834 include the reserved word @key{task} in its
2835 definition; any other type derived from a task interface shall be a private
2836 extension or a task type declared by a task declaration (see
2837 @RefSecNum{Task Units and Task Objects}).]}
2838
2839 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2840 @ChgAdded{Version=[2],Text=[An interface derived from a
2841 protected interface shall include
2842 the reserved word @key{protected} in its definition; any other type derived
2843 from a protected interface shall be a private extension or a protected type
2844 declared by a protected declaration (see
2845 @RefSecNum{Protected Units and Protected Objects}).]}
2846
2847 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2848 @ChgAdded{Version=[2],Text=[An interface derived from
2849 a synchronized interface shall include one of the reserved words @key{task},
2850 @key{protected}, or @key{synchronized} in its definition; any other type
2851 derived from a synchronized interface shall be a private extension, a task
2852 type declared by a task declaration, or a protected type declared by a protected
2853 declaration.]}
2854
2855 @begin{Reason}
2856 @ChgRef{Version=[2],Kind=[AddedNormal]}
2857 @ChgAdded{Version=[2],Text=[We require that an interface descendant of a
2858 task, protected, or synchronized interface repeat the explicit kind of
2859 interface it will be, rather than simply inheriting it, so that a reader is
2860 always aware of whether the interface provides synchronization and whether
2861 it may be implemented only by a task or protected type. The only place where
2862 inheritance of the kind of interface might be useful would be in a generic
2863 if you didn't know the kind of the actual interface. However, the value of
2864 that is low because you cannot implement an interface properly if you don't
2865 know whether it is a task, protected, or synchronized interface. Hence, we
2866 require the kind of the actual interface to match the kind of the formal
2867 interface (see @RefSecNum{Formal Interface Types}).]}
2868 @end{Reason}
2869
2870 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2871 @ChgAdded{Version=[2],Text=[No type shall be derived from both a task interface
2872 and a protected interface.]}
2873
2874 @begin{Reason}
2875 @ChgAdded{Version=[2],Text=[This prevents a single private
2876 extension from inheriting from both a task and a protected interface. For a
2877 private type, there can be no legal completion. For a generic formal derived
2878 type, there can be no possible matching type (so no instantiation could be
2879 legal). This rule provides early detection of the errors.]}
2880 @end{Reason}
2881
2882 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2883 @ChgAdded{Version=[2],Text=[In addition to the places where @LegalityTitle
2884 normally apply (see @RefSecNum{Generic Instantiation}), these rules apply also
2885 in the private part of an instance of a generic
2886 unit.@PDefn{generic contract issue}]}
2887 @begin{Ramification}
2888 @ChgRef{Version=[2],Kind=[AddedNormal]}
2889 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2890 @ChgAdded{Version=[2],Text=[This paragraph is intended to apply to all of the
2891 @LegalityTitle@; in this @Chg{Version=[3],New=[subclause],Old=[clause]}. We
2892 cannot allow interface types which do not
2893 obey these rules, anywhere. Luckily, deriving from a formal type (which might
2894 be an interface) is not allowed for any tagged types in a generic body. So
2895 checking in the private part of a generic covers all of the cases.]}
2896 @end{Ramification}
2897
2898 @end{Legality}
2899
2900 @begin{Runtime}
2901 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2902 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0070-1]}
2903 @ChgAdded{Version=[2],Text=[The elaboration of an
2904 @nt{interface_type_definition} @Chg{Version=[3],New=[creates
2905 the interface type and its first subtype],Old=[has no effect]}.]}
2906 @begin{Discussion}
2907 @ChgRef{Version=[2],Kind=[AddedNormal]}
2908 @ChgRef{Version=[3],Kind=[Revised]}
2909 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[There is no other
2910 effect. ],Old=[]}An @nt{interface_list} is made up of
2911 @nt{subtype_mark}s, which do not need to be elaborated, so the
2912 @nt{interface_list} does not either. This is consistent with the
2913 handling of @nt{discriminant_part}s.]}
2914 @end{Discussion}
2915 @end{Runtime}
2916
2917 @begin{Notes}
2918 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00411-01]}
2919 @ChgAdded{Version=[2],Text=[Nonlimited interface types have predefined
2920 nonabstract equality operators. These may be overridden with user-defined
2921 abstract equality operators. Such operators will then require
2922 an explicit overriding for any nonabstract descendant of the interface.]}
2923 @end{Notes}
2924
2925 @begin{Examples}
2926
2927 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
2928 @ChgAdded{Version=[2],Type=[Leading],Text=[@i{Example of a limited
2929 interface and a synchronized interface extending it:}]}
2930
2931 @begin{Example}
2932 @ChgRef{Version=[2],Kind=[AddedNormal]}
2933 @ChgAdded{Version=[2],Text=[@key{type} Queue @key{is limited interface};
2934 @key{procedure} Append(Q : @key{in out} Queue; Person : @key{in} Person_Name) @key{is abstract};
2935 @key{procedure} Remove_First(Q : @key{in out} Queue;
2936 Person : @key{out} Person_Name) @key{is abstract};
2937 @key{function} Cur_Count(Q : @key{in} Queue) @key{return} Natural @key{is abstract};
2938 @key{function} Max_Count(Q : @key{in} Queue) @key{return} Natural @key{is abstract};
2939 -- @RI[See @RefSecNum{Incomplete Type Declarations} for Person_Name.]]}
2940
2941 @ChgRef{Version=[2],Kind=[AddedNormal]}
2942 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0004-1]}
2943 @ChgAdded{Version=[2],Text=[Queue_Error : @key{exception};
2944 --@RI[ Append raises Queue_Error if @Chg{Version=[3],New=[Cur_Count],Old=[Count]}(Q) = Max_Count(Q)]
2945 --@RI[ Remove_First raises Queue_Error if @Chg{Version=[3],New=[Cur_Count],Old=[Count]}(Q) = 0]]}
2946
2947 @ChgRef{Version=[2],Kind=[AddedNormal]}
2948 @ChgAdded{Version=[2],Text=[@key{type} Synchronized_Queue @key{is synchronized interface and} Queue; --@RI[ see @RefSecNum{Example of Tasking and Synchronization}]
2949 @key{procedure} Append_Wait(Q : @key{in out} Synchronized_Queue;
2950 Person : @key{in} Person_Name) @key{is abstract};
2951 @key{procedure} Remove_First_Wait(Q : @key{in out} Synchronized_Queue;
2952 Person : @key{out} Person_Name) @key{is abstract};]}
2953
2954 @ChgRef{Version=[2],Kind=[AddedNormal]}
2955 @ChgAdded{Version=[2],Text=[...]}
2956
2957 @ChgRef{Version=[2],Kind=[AddedNormal]}
2958 @ChgAdded{Version=[2],Text=[@key{procedure} Transfer(From : @key{in out} Queue'Class;
2959 To : @key{in out} Queue'Class;
2960 Number : @key{in} Natural := 1) @key{is}
2961 Person : Person_Name;
2962 @key{begin}
2963 @key{for} I @key{in} 1..Number @key{loop}
2964 Remove_First(From, Person);
2965 Append(To, Person);
2966 @key{end loop};
2967 @key{end} Transfer;]}
2968 @end{Example}
2969
2970 @ChgRef{Version=[2],Kind=[AddedNormal]}
2971 @ChgAdded{Version=[2],Text=[This defines a Queue interface defining a queue of
2972 people. (A similar design could be created to define any kind of queue simply
2973 by replacing Person_Name by an appropriate type.) The Queue interface has four
2974 dispatching operations, Append, Remove_First, Cur_Count, and Max_Count. The
2975 body of a class-wide operation, Transfer is also shown. Every nonabstract
2976 extension of Queue must provide implementations for at least its four
2977 dispatching operations, as they are abstract. Any object of a type derived from
2978 Queue may be passed to Transfer as either the From or the To operand. The two
2979 operands need not be of the same type in any given call.]}
2980
2981 @ChgRef{Version=[2],Kind=[AddedNormal]}
2982 @ChgAdded{Version=[2],Text=[The Synchronized_Queue interface inherits the four
2983 dispatching operations from Queue and adds two additional dispatching
2984 operations, which wait if necessary rather than raising the Queue_Error
2985 exception. This synchronized interface may only be implemented by a task or
2986 protected type, and as such ensures safe concurrent access.]}
2987
2988 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
2989 @ChgAdded{Version=[2],Type=[Leading],Text=[@i{Example use of the interface:}]}
2990
2991 @begin{Example}
2992 @ChgRef{Version=[2],Kind=[AddedNormal]}
2993 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
2994 @ChgAdded{Version=[2],Text=[@key{type} Fast_Food_Queue @key{is new} Queue @key{with record} ...;
2995 @key{procedure} Append(Q : @key{in out} Fast_Food_Queue; Person : @key{in} Person_Name);
2996 @key{procedure} Remove_First(Q : @key{in out} Fast_Food_Queue; Person : @Chg{Version=[3],New=[@key{out}],Old=[@key{in}]} Person_Name);
2997 @key{function} Cur_Count(Q : @key{in} Fast_Food_Queue) @key{return} Natural;
2998 @key{function} Max_Count(Q : @key{in} Fast_Food_Queue) @key{return} Natural;]}
2999
3000 @ChgRef{Version=[2],Kind=[AddedNormal]}
3001 @ChgAdded{Version=[2],Text=[...]}
3002
3003 @ChgRef{Version=[2],Kind=[AddedNormal]}
3004 @ChgAdded{Version=[2],Text=[Cashier, Counter : Fast_Food_Queue;]}
3005
3006 @ChgRef{Version=[2],Kind=[AddedNormal]}
3007 @ChgAdded{Version=[2],Text=[...
3008 -- @RI[Add George (see @RefSecNum{Incomplete Type Declarations}) to the cashier's queue:]
3009 Append (Cashier, George);
3010 -- @RI[After payment, move George to the sandwich counter queue:]
3011 Transfer (Cashier, Counter);
3012 ...]}
3013 @end{Example}
3014
3015 @ChgRef{Version=[2],Kind=[AddedNormal]}
3016 @ChgAdded{Version=[2],Text=[An interface such as Queue can be used directly as
3017 the parent of a new type (as shown here), or can be used as a progenitor when a
3018 type is derived. In either case, the primitive operations of the
3019 interface are inherited. For Queue, the implementation of the four inherited
3020 routines must be provided. Inside the call of Transfer, calls will dispatch to
3021 the implementations of Append and Remove_First for type Fast_Food_Queue.]}
3022
3023 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3024 @ChgAdded{Version=[2],Type=[Leading],Text=[@i{Example of a task interface:}]}
3025
3026 @begin{Example}
3027 @ChgRef{Version=[2],Kind=[AddedNormal]}
3028 @ChgAdded{Version=[2],Text=[@key{type} Serial_Device @key{is task interface}; --@RI[ see @RefSecNum{Task Units and Task Objects}]
3029 @key{procedure} Read (Dev : @key{in} Serial_Device; C : @key{out} Character) @key{is abstract};
3030 @key{procedure} Write(Dev : @key{in} Serial_Device; C : @key{in} Character) @key{is abstract};]}
3031 @end{Example}
3032
3033 @ChgRef{Version=[2],Kind=[AddedNormal]}
3034 @ChgAdded{Version=[2],Text=[The Serial_Device interface has two dispatching
3035 operations which are intended to be implemented by task entries (see 9.1).]}
3036
3037 @end{Examples}
3038
3039 @begin{Extend95}
3040 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00345-01]}
3041 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}Interface types
3042 are new. They provide multiple inheritance of interfaces, similar to the
3043 facility provided in Java and other recent language designs.]}
3044 @end{Extend95}
3045
3046 @begin{DiffWord2005}
3047 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0070-1]}
3048 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the definition
3049 of elaboration for an @nt{interface_type_definition} to match that
3050 of other type definitions.]}
3051 @end{DiffWord2005}
3052
3053
3054 @LabeledClause{Access Types}
3055
3056 @begin{Intro}
3057 @Defn{access type}
3058 @Defn{access value}
3059 @Defn{designate}
3060 A value of an access type (an @i(access value))
3061 provides indirect access to the object or subprogram
3062 it @i(designates). Depending on its type, an access value
3063 can designate either subprograms, objects created by allocators
3064 (see @RefSecNum(Allocators)), or more generally @i(aliased) objects of
3065 an appropriate type.
3066 @IndexSee{Term=[pointer],See=(access value)}
3067 @IndexSee{Term=[pointer type],See=(access type)}
3068 @begin(Discussion)
3069 A @nt<name> @i(denotes) an entity; an access value @i(designates) an
3070 entity. The @lquotes@;dereference@rquotes@; of an access value X, written
3071 @lquotes@;X.@key[all]@rquotes@;, is a @nt<name> that denotes the entity designated by X.
3072 @end(Discussion)
3073 @end{Intro}
3074
3075 @begin{MetaRules}
3076 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3077 Access values should always be well defined
3078 (barring uses of certain unchecked features of @Chg{Version=[3],New=[Clause],Old=[Section]}
3079 @RefSecNum{Representation Issues}).
3080 In particular, uninitialized access variables should be prevented
3081 by compile-time rules.
3082 @end{MetaRules}
3083
3084 @begin{Syntax}
3085 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
3086 @Syn{lhs=<access_type_definition>,rhs="
3087 @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{access_to_object_definition}
3088 | @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{access_to_subprogram_definition}"}
3089
3090 @Syn{lhs=<access_to_object_definition>,rhs="
3091 @key{access} [@Syn2{general_access_modifier}] @Syn2{subtype_indication}"}
3092 @Syn{lhs=<general_access_modifier>,rhs="@key{all} | @key{constant}"}
3093
3094 @Syn{lhs=<access_to_subprogram_definition>,rhs="
3095 @key{access} [@key{protected}] @key{procedure} @Syn2{parameter_profile}
3096 | @key{access} [@key{protected}] @key{function} @Syn2{parameter_and_result_profile}"}
3097
3098 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3099 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[null_exclusion],Old=[]}>,
3100 rhs="@Chg{Version=[2],New=[@key{not} @key{null}],Old=[]}"}
3101
3102 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00404-01]}
3103 @Syn{lhs=<access_definition>,rhs="@Chg{Version=[2],New=<
3104 [@Syn2{null_exclusion}] @key{access} [@key{constant}] @Syn2{subtype_mark}
3105 | [@Syn2{null_exclusion}] @key{access} [@key{protected}] @key{procedure} @Syn2{parameter_profile}
3106 | [@Syn2{null_exclusion}] @key{access} [@key{protected}] @key{function} @Syn2{parameter_and_result_profile}>,
3107 Old=[@key{access} @Syn2{subtype_mark}]}"}
3108
3109 @end{Syntax}
3110
3111 @begin{StaticSem}
3112 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0012],ARef=[AI95-00062-01]}
3113 @Defn{access-to-object type}
3114 @Defn{access-to-subprogram type}
3115 @Defn{pool-specific access type}
3116 @Defn{general access type}
3117 There are two kinds of access types, @i{access-to-object} types, whose
3118 values designate objects, and @i(access-to-subprogram) types, whose
3119 values designate subprograms.
3120 @Defn{storage pool}
3121 Associated with an access-to-object type is a @i(storage pool);
3122 several access types may share the same storage pool.
3123 @Chg{New=[All descendants of an access type share the same storage pool.],Old=[]}
3124 @Defn{pool element}
3125 A storage pool is an area of storage used to hold dynamically
3126 allocated objects (called @i(pool elements)) created
3127 by allocators@Redundant[; storage pools
3128 are described further in @RefSec(Storage Management)].
3129
3130 @Defn{pool-specific access type}
3131 @Defn{general access type}
3132 Access-to-object types are further subdivided into
3133 @i(pool-specific) access types, whose values can designate only
3134 the elements of their associated storage pool,
3135 and @i(general) access types, whose
3136 values can designate the elements of any storage pool,
3137 as well as aliased objects created by declarations
3138 rather than allocators,
3139 and aliased subcomponents of other objects.
3140 @begin(ImplNote)
3141 The value of an access type will typically be a machine address.
3142 However, a value of a pool-specific access type can be
3143 represented as an offset (or index) relative to its storage pool,
3144 since it can point only to the elements of that pool.
3145 @end(ImplNote)
3146
3147 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00225-01],ARef=[AI95-00363-01]}
3148 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0053-1],ARef=[AI05-0142-4],ARef=[AI05-0277-1]}
3149 @Defn{aliased}
3150 A view of an object is defined to be @i(aliased) if
3151 it is defined by an @nt<object_@!declaration>@Chg{Version=[3],New=[,],Old=[ or]}
3152 @nt<component_@!definition>@Chg{Version=[3],New=[,
3153 @nt{parameter_@!specification}, or
3154 @nt{extended_return_object_declaration}],Old=[]}
3155 with the reserved word @key(aliased), or by a renaming of an aliased view.
3156 In addition, the dereference of an access-to-object
3157 value denotes an aliased view, as does a view conversion
3158 (see @RefSecNum{Type Conversions}) of an aliased view.
3159 @Chg{Version=[2],New=[The],Old=[Finally, the]} current instance of
3160 @Chg{Version=[3],New=[an immutably limited type (see @RefSecNum{Limited Types})
3161 is],Old=[a limited@Chg{Version=[2],New=[ tagged],Old=[]} type,
3162 @Chg{Version=[2],New=[a protected type, a task type, or a type that has the
3163 reserved word @key{limited} in its full definition is also],Old=[]}]}
3164 @Chg{Version=[2],New=[defined to be aliased. Finally,],Old=[and]}
3165 a formal parameter or generic formal object of a
3166 tagged type @Chg{Version=[2],New=[is],Old=[are]} defined to be aliased.
3167 @Redundant[Aliased views are the ones that can be designated by an
3168 access value.]
3169 @Chg{Version=[2],New=[],Old=[@Defn2{Term=[constrained], Sec=(object)}
3170 @Defn2{Term=[unconstrained], Sec=(object)}
3171 @Defn{constrained by its initial value}
3172 If the view defined by an @nt{object_@!declaration} is aliased,
3173 and the type of the object has discriminants,
3174 then the object is constrained;
3175 if its nominal subtype is unconstrained,
3176 then the object is constrained by its initial value.
3177 @Redundant[Similarly, if the object created by an @nt<allocator>
3178 has discriminants, the object is constrained,
3179 either by the designated subtype, or by its initial value.]]}
3180 @ToGlossary{Term=<Aliased>,
3181 Text=<An aliased view of an object is one that can be designated by an
3182 access value.
3183 Objects allocated by allocators are aliased.
3184 Objects can also be explicitly declared as aliased with
3185 the reserved word @key(aliased).
3186 The Access attribute can be used to create an access value
3187 designating an aliased object.>}
3188 @begin(Ramification)
3189 The current instance of a nonlimited type is not aliased.
3190
3191 The object created by an allocator is aliased, but not its
3192 subcomponents, except of course for those that themselves have @key(aliased)
3193 in their @nt<component_definition>.
3194
3195 The renaming of an aliased object is aliased.
3196
3197 Slices are never aliased.
3198 See @RefSecNum{Slices} for more discussion.
3199 @end(Ramification)
3200 @begin(Reason)
3201 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00225-01]}
3202 The current instance of a limited type is defined to be aliased
3203 so that an access discriminant of a component can be initialized
3204 with T'Access inside the definition of T.@Chg{Version=[2],New=[ Note that
3205 we don't want this to apply to a type that could become nonlimited later
3206 within its immediate scope, so we require the full definition to be limited.],Old=[]}
3207
3208 A formal parameter of a tagged type is defined to be aliased
3209 so that a (tagged) parameter X may be passed to an access parameter P
3210 by using P => X'Access. Access parameters are most important
3211 for tagged types because of dispatching-on-access-parameters
3212 (see @RefSecNum(Dispatching Operations of Tagged Types)).
3213 By restricting this to formal parameters, we minimize problems
3214 associated with allowing components that are not declared aliased
3215 to be pointed-to from within the same record.
3216
3217 @Leading@;A view conversion of an aliased view is aliased so that
3218 the type of an access parameter can be changed without
3219 first converting to a named access type. For example:
3220 @begin{Example}
3221 @key(type) T1 @key(is tagged) ...;
3222 @key(procedure) P(X : @key(access) T1);
3223
3224 @key(type) T2 @key(is new) T1 @key(with) ...;
3225 @key(procedure) P(X : @key(access) T2) @key(is)
3226 @key(begin)
3227 P(T1(X.@key(all))'Access); --@RI[ hand off to T1's P]
3228 . . . --@RI[ now do extra T2-specific processing]
3229 @key(end) P;
3230 @end{Example}
3231
3232 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00363-01]}
3233 @ChgDeleted{Version=[2],Text=[The rule about objects with discriminants is
3234 necessary because values of a constrained access subtype
3235 can designate an object whose nominal subtype is unconstrained;
3236 without this rule, a check on every use of such values would
3237 be required to ensure that the discriminants of the object had not
3238 changed.
3239 With this rule (among others), we ensure that if there might
3240 exist aliased views of a discriminated object, then the object is
3241 necessarily constrained.
3242 Note that this rule is necessary only for untagged types,
3243 since a discriminant of a tagged type can't have a default,
3244 so all tagged discriminated objects are always constrained
3245 anyway.]}
3246 @ChgNote{This rule was a disaster, so it thankfully has been repealed.
3247 We instead make general access constrained subtypes illegal if the type
3248 allows unconstrained instances, see Discriminant Constraints.}
3249
3250 @ChgRef{Version=[2],Kind=[Revised]}@ChgNote{Eilers reported double word}
3251 We considered making more kinds of objects aliased by default.
3252 In particular, any object of a by-reference type will pretty
3253 much have to be allocated at an addressable location,
3254 so it can be passed by reference without using bit-field
3255 pointers. Therefore, one might wish to allow the Access and
3256 @Chg{Version=[2],New=[],Old=[and ]}Unchecked_Access attributes for such
3257 objects. However, private parts are transparent to the definition of
3258 @lquotes@;by-reference type@rquotes@;, so if we made all objects of a by-reference
3259 type aliased, we would be violating the privacy of private parts.
3260 Instead, we would have to define a concept of @lquotes@;visibly by-reference@rquotes@;
3261 and base the rule on that.
3262 This seemed to complicate the rules more than it was worth,
3263 especially since there is no way to declare an untagged limited
3264 private type to be by-reference, since the full type might by
3265 nonlimited.
3266 @end(Reason)
3267 @begin{Discussion}
3268 Note that we do not use the term @lquotes@;aliased@rquotes@; to refer to formal
3269 parameters that are referenced through multiple access paths
3270 (see @RefSecNum{Formal Parameter Modes}).
3271 @end{Discussion}
3272
3273 An @nt{access_to_object_definition} defines
3274 an access-to-object type and its first subtype;
3275 @Defn2{Term=[designated subtype], Sec=(of a named access type)}
3276 @Defn2{Term=[designated type], Sec=(of a named access type)}
3277 the @nt<subtype_@!indication> defines the @i(designated subtype)
3278 of the access type.
3279 If a @nt<general_@!access_@!modifier> appears, then the access type
3280 is a general access type.
3281 @Defn{access-to-constant type}
3282 If the modifier is the reserved word @key(constant), then the type is an
3283 @i(access-to-constant type)@Redundant[; a designated object cannot be updated
3284 through a value of such a type].
3285 @Defn{access-to-variable type}
3286 If the modifier is the reserved word @key(all),
3287 then the type is an @i(access-to-variable type)@Redundant[; a designated object
3288 can be both read and updated through a value of such a type].
3289 If no @nt<general_@!access_@!modifier> appears in the
3290 @nt<access_to_@!object_@!definition>, the access type is a
3291 pool-specific access-to-variable type.
3292 @begin{Honest}
3293 The type of the designated subtype is called the
3294 @i{designated type}.
3295 @end{Honest}
3296 @begin(Reason)
3297 The modifier @key(all) was picked to suggest that
3298 values of a general access type could point into @lquotes@;all@rquotes@; storage pools,
3299 as well as to objects declared aliased, and that @lquotes@;all@rquotes@; access
3300 (both read and update) to the designated object was provided.
3301 We couldn't think of any use for pool-specific
3302 access-to-constant types, so any access type defined with
3303 the modifier @key(constant) is considered a general access type,
3304 and can point into any storage pool or at other (appropriate)
3305 aliased objects.
3306 @end(Reason)
3307 @begin(ImplNote)
3308 The predefined generic Unchecked_Deallocation can be
3309 instantiated for any named access-to-variable type. There
3310 is no (language-defined) support for deallocating objects
3311 designated by a value of an access-to-constant type. Because of this,
3312 an allocator for an access-to-constant type can allocate
3313 out of a storage pool with no support for deallocation.
3314 Frequently, the allocation can be done at link-time,
3315 if the size and initial value are known then.
3316 @end(ImplNote)
3317 @begin(Discussion)
3318 For the purpose of generic formal type matching, the relevant
3319 subclasses of access types are access-to-subprogram
3320 types, access-to-constant types, and (named) access-to-variable types,
3321 with its subclass (named) general access-to-variable types.
3322 Pool-specific access-to-variable types are not a separately matchable
3323 subclass of types, since they don't have any @lquotes@;extra@rquotes@; operations
3324 relative to all (named) access-to-variable types.
3325 @end(Discussion)
3326
3327 @Defn{access-to-subprogram type}
3328 An @nt{access_to_subprogram_definition} defines
3329 an access-to-subprogram type and its first subtype;
3330 @Defn2{Term=[designated profile], Sec=(of an access-to-subprogram type)}
3331 the @nt<parameter_profile> or @nt<parameter_and_result_profile>
3332 defines the @i(designated profile) of the access type.
3333 @Defn2{Term=[calling convention], Sec=(associated with a designated profile)}
3334 There is a @i(calling convention) associated with the designated
3335 profile@Redundant[; only subprograms with this
3336 calling convention can be designated by
3337 values of the access type.]
3338 By default, the calling convention is @lquotes@i(protected)@rquotes@; if the reserved
3339 word @key(protected) appears, and @lquotes@;Ada@rquotes@; otherwise.
3340 @Redundant[See @RefSecNum{Interface to Other Languages}
3341 for how to override this default.]
3342 @begin(Ramification)
3343 The calling convention @i(protected) is
3344 in italics to emphasize that it cannot be specified explicitly
3345 by the user. This is a consequence of it being a reserved word.
3346 @end(Ramification)
3347 @begin(ImplNote)
3348 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
3349 For @Chg{Version=[2],New=[a named],Old=[an]} access-to-subprogram type, the
3350 representation of an access value might include
3351 implementation-defined information needed to support
3352 up-level references @em for example, a static link.
3353 The accessibility rules (see @RefSecNum(Operations of Access Types)) ensure
3354 that in a "global-display-based" implementation model (as opposed to
3355 a static-link-based model), @Chg{Version=[2],New=[a named],Old=[an]}
3356 access-to-(unprotected)-subprogram value need consist only of the
3357 address of the subprogram. The global display is guaranteed
3358 to be properly set up any time the designated subprogram is called.
3359 Even in a static-link-based model, the only time a static link
3360 is definitely required is for an access-to-subprogram type declared
3361 in a scope nested at least two levels deep within subprogram or
3362 task bodies, since values of such a type might designate subprograms
3363 nested a smaller number of levels. For the normal case of
3364 @Chg{Version=[2],New=[a named],Old=[an]} access-to-subprogram type
3365 declared at the outermost (library) level,
3366 a code address by itself should be sufficient to represent the
3367 access value in many implementations.
3368
3369 For access-to-protected-subprogram, the access values will necessarily
3370 include both an address (or other identification) of the code of the
3371 subprogram, as well as the address of the associated protected object.
3372 This could be thought of as a static link, but it will be needed even
3373 for global-display-based implementation models. It corresponds
3374 to the value of the @lquotes@;implicit parameter@rquotes@; that is passed into
3375 every call of a protected operation, to identify the current instance
3376 of the protected type on which they are to operate.
3377
3378 Any Elaboration_Check is performed when a call
3379 is made through an access value, rather than when the
3380 access value is first "created" via a 'Access.
3381 For implementation models that normally put that check at the
3382 call-site, an access value will have to point to a separate
3383 entry point that does the check. Alternatively, the
3384 access value could point to a "subprogram descriptor" that
3385 consisted of two words (or perhaps more), the first being
3386 the address of the code, the second being the elaboration bit.
3387 Or perhaps more efficiently, just the address of the code,
3388 but using the trick that the descriptor is initialized to
3389 point to a Raise-Program-Error routine initially, and then
3390 set to point to the "real" code when the body is elaborated.
3391
3392 For implementations that share code between generic instantiations,
3393 the extra level of indirection suggested above to support
3394 Elaboration_Checks could also be used to provide a pointer to the
3395 per-instance data area normally required when calling shared code.
3396 The trick would be to put a pointer to the per-instance data
3397 area into the subprogram descriptor, and then make sure that
3398 the address of the subprogram descriptor is loaded into a
3399 "known" register whenever an indirect call is performed.
3400 Once inside the shared code, the address of the per-instance
3401 data area can be retrieved out of the subprogram descriptor,
3402 by indexing off the "known" register.
3403
3404 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00344-01]}
3405 @ChgNote{This is not remotely true with nested extensions and with
3406 interfaces. I don't much feel like trying to explain this properly.}
3407 @ChgDeleted{Version=[2],Text=[Essentially the same implementation issues
3408 arise for calls on dispatching operations of tagged types, except that
3409 the static link is always known "statically."]}
3410
3411 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
3412 Note that access parameters of an
3413 anonymous access-to-subprogram type are @Chg{Version=[2],New=[],Old=[not ]}permitted.
3414 @Chg{Version=[2],New=[Such],Old=[If there were such]} parameters@Chg{Version=[2],
3415 New=[ represent],Old=[,]} full @lquotes@;downward@rquotes@;
3416 closures@Chg{Version=[2],New=[],Old=[would be required]}, meaning that
3417 in an implementation that uses a per-task (global) display,
3418 the display @Chg{Version=[2],New=[will],Old=[would]} have to be passed
3419 as a hidden parameter,
3420 and reconstructed at the point of call.@Chg{Version=[2],New=[],
3421 Old=[ This was felt to be an undue implementation burden,
3422 given that an equivalent (actually, more general) capability
3423 is available via formal subprogram parameters to a generic.]}
3424 @end(ImplNote)
3425
3426 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
3427 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3428 @Defn{anonymous access type}
3429 @Defn2{Term=[designated subtype], Sec=(of an anonymous access type)}
3430 @Defn2{Term=[designated type], Sec=(of an anonymous access type)}
3431 An @nt{access_definition} defines an anonymous
3432 general @Chg{Version=[2],New=[access type or an
3433 anonymous access-to-subprogram type. For a general access type,],
3434 Old=[access-to-variable type;]} the @nt<subtype_mark> denotes
3435 its @i(designated subtype)@Chg{Version=[2],New=[; if the
3436 @nt{general_@!access_@!modifier} @key{constant} appears, the type is an
3437 access-to-constant type; otherwise@Chg{Version=[3],New=[,],Old=[]} it is
3438 an access-to-variable type. For an access-to-subprogram type, the
3439 @nt{parameter_@!profile} or @nt{parameter_@!and_@!result_@!profile} denotes its
3440 @i{designated profile}.@Defn2{Term=[designated profile], Sec=(of an anonymous access type)}],
3441 Old=[. @Redundant[An @nt<access_definition> is used in the
3442 specification of an access discriminant
3443 (see @RefSecNum(Discriminants)) or an access
3444 parameter (see @RefSecNum(Subprogram Declarations)).]]}
3445
3446 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
3447 @Defn2{Term=[null value], Sec=(of an access type)}
3448 For each @Chg{Version=[2],New=[],Old=[(named) ]}access type, there is
3449 @Chg{Version=[2],New=[],Old=[a literal @key(null) which has ]}a null
3450 access value designating no entity at all@Chg{Version=[2],New=[, which can be
3451 obtained by (implicitly) converting the literal @key{null} to the access
3452 type],Old=[]}.
3453 @Redundant[The null value of @Chg{Version=[2],New=[an],Old=[a named]} access
3454 type is the default initial value of the type.]
3455 @Chg{Version=[2],New=[Nonnull],Old=[Other]} values of an
3456 access@Chg{Version=[2],New=[-to-object],Old=[]} type are
3457 obtained by evaluating @Chg{Version=[2],New=[],Old=[an
3458 @nt<attribute_reference> for the Access or Unchecked_Access
3459 attribute of an aliased view of an object or nonintrinsic
3460 subprogram, or, in the case of a named access-to-object type,]}
3461 an @nt<allocator>@Redundant[, which
3462 returns an access value designating a newly created object
3463 (see @RefSecNum(Operations of Access Types))]@Chg{Version=[2],New=[, or in the
3464 case of a general access-to-object type, evaluating an
3465 @nt{attribute_reference} for the Access or Unchecked_Access
3466 attribute of an aliased view of an object. Nonnull values of an
3467 access-to-subprogram type are obtained by evaluating an
3468 @nt{attribute_reference} for the Access attribute of a
3469 nonintrinsic subprogram],Old=[]}.
3470
3471 @begin{Ramification}
3472 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00231-01]}
3473 @ChgDeleted{Version=[2],Text=[A value of an anonymous access type
3474 (that is, the value of an access parameter or access discriminant)
3475 cannot be null.]}
3476 @end{ramification}
3477 @begin{Reason}
3478 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00231-01]}
3479 @ChgDeleted{Version=[2],Text=[Access parameters allow dispatching on the
3480 tag of the object designated
3481 by the actual parameter (which gets converted to the anonymous access
3482 type as part of the call).
3483 In order for dispatching to work properly,
3484 there had better be such an object.
3485 Hence, the type conversion will raise Constraint_Error if the value of
3486 the actual parameter is null.]}
3487 @end{Reason}
3488
3489 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3490 @ChgAdded{Version=[2],Text=[@Defn2{Term=[excludes null],Sec=[subtype]}
3491 A @nt{null_exclusion} in a construct specifies
3492 that the null value does not belong to the access subtype defined by the
3493 construct, that is, the access subtype @i{excludes null}. In addition, the
3494 anonymous access subtype defined by the @nt{access_definition} for a controlling
3495 access parameter (see @RefSecNum{Dispatching Operations of Tagged Types})
3496 excludes null. Finally, for a @nt{subtype_indication} without a
3497 @nt{null_exclusion}, the subtype denoted by the @nt{subtype_indication}
3498 excludes null if and only if the subtype denoted by the @nt{subtype_mark} in
3499 the @nt{subtype_indication} excludes null.]}
3500 @begin{Reason}
3501 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3502 @ChgAdded{Version=[2],Text=[An @nt{access_definition} used in a controlling
3503 parameter excludes null because it is necessary to read the tag to
3504 dispatch, and null has no tag. We would have preferred to
3505 require @key{not null} to be specified for such
3506 parameters, but that would have been too incompatible with Ada 95 code
3507 to require.]}
3508
3509 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
3510 @ChgAdded{Version=[2],Text=[Note that we considered imposing a similar
3511 implicit null exclusion for controlling access results, but chose not to do
3512 that, because there is no Ada 95 compatibility issue, and there is no
3513 automatic null check inherent in the use of a controlling access result. If a
3514 null check is necessary, it is because there is a dereference of the result,
3515 or because the value is passed to a parameter whose subtype excludes null.
3516 If there is no dereference of the result, a null return value is perfectly
3517 acceptable, and can be a useful indication of a particular status of the
3518 call.]}
3519 @end{Reason}
3520
3521 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0013],ARef=[AI95-00012-01]}
3522 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3523 @PDefn2{Term=[constrained],Sec=(subtype)}
3524 @PDefn2{Term=[unconstrained],Sec=(subtype)}
3525 @Redundant[All subtypes of an access-to-subprogram type
3526 are constrained.] The first subtype of a type defined by
3527 an @Chg{New=[@nt<access_definition>],Old=[@nt<access_type_definition>]} or an
3528 @nt<access_to_object_definition> is unconstrained if the designated subtype
3529 is an unconstrained array or discriminated @Chg{New=[subtype],Old=[type]};
3530 otherwise@Chg{Version=[3],New=[,],Old=[]} it is constrained.
3531 @begin(TheProof)
3532 The @LegalityTitle on @nt<range_constraint>s (see @RefSecNum(Scalar Types))
3533 do not permit the @nt<subtype_mark> of the @nt<subtype_indication> to denote
3534 an access-to-scalar type, only a scalar type.
3535 The @LegalityTitle on @nt<index_constraint>s
3536 (see @RefSecNum(Index Constraints and Discrete Ranges)) and
3537 @nt<discriminant_constraint>s (see @RefSecNum(Discriminant Constraints))
3538 both permit access-to-composite types in a @nt<subtype_indication>
3539 with such _@nt<constraint>s. Note that an access-to-access-to-composite
3540 is never permitted in a @nt<subtype_indication> with a @nt<constraint>.
3541 @end(TheProof)
3542 @begin(Reason)
3543 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
3544 Only @nt<composite_constraint>s are permitted
3545 for an access type, and only
3546 on access-to-composite types.
3547 A constraint on an access-to-scalar or access-to-access type
3548 might be violated due to assignments
3549 via other access paths that were not so constrained. By contrast,
3550 if the designated subtype is an array or discriminated
3551 type@Chg{Version=[2],New=[ without defaults],Old=[]},
3552 the constraint could not be violated by unconstrained assignments,
3553 since array objects are always constrained, and
3554 @Chg{Version=[2],New=[],Old=[aliased]} discriminated objects are
3555 also constrained @Chg{Version=[2],New=[when the type does not have defaults
3556 for its discriminants. Constraints are not allowed on general access-to-unconstrained
3557 discriminated types if the type has defaults for its discriminants;
3558 constraints on pool-specific access types are usually allowed because
3559 allocated objects are usually constrained by their initial value.],
3560 Old=[(by fiat, see @StaticSemTitle).]}
3561 @end(Reason)
3562 @end{StaticSem}
3563
3564 @begin{Legality}
3565 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
3566 @ChgAdded{Version=[2],Text=[If a
3567 @nt{subtype_@!indication}, @nt{discriminant_@!specification},
3568 @nt{parameter_@!specification}, @nt{parameter_@!and_@!result_@!profile},
3569 @nt{object_@!renaming_@!declaration}, or @nt{formal_@!object_@!declaration}
3570 has a @nt{null_@!exclusion}, the @nt{subtype_@!mark} in that construct
3571 shall denote an access subtype that does not exclude null.]}
3572 @begin(Honest)
3573 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3574 @ChgAdded{Version=[2],Text=[This means @lquotes@;directly allowed in@rquotes;
3575 we are not talking about a @nt{null_exclusion} that occurs in an
3576 @nt{access_definition} in one of these constructs (for an
3577 @nt{access_definition}, the @nt{subtype_mark} in such an
3578 @nt{access_definition} is not restricted).]}
3579 @end(Honest)
3580 @begin(Reason)
3581 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3582 @ChgAdded{Version=[2],Text=[This is similar to doubly constraining a
3583 composite subtype, which we also don't allow.]}
3584 @end(Reason)
3585 @end{Legality}
3586
3587 @begin{RunTime}
3588 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
3589 @PDefn2{Term=[compatibility],
3590 Sec=(composite_constraint with an access subtype)}
3591 A @nt<composite_constraint> is @i(compatible) with an unconstrained
3592 access subtype if it is compatible with the designated
3593 subtype.@Chg{Version=[2],New=[ A @nt{null_exclusion} is compatible with any
3594 access subtype that does not exclude null.],Old=[]}
3595 @PDefn2{Term=[satisfies], Sec=(for an access value)}
3596 An access value @i(satisfies) a @nt<composite_constraint> of an access
3597 subtype if it equals the null value of its type
3598 or if it designates an object whose value satisfies the
3599 constraint.@Chg{Version=[2],New=[ An access value satisfies an exclusion
3600 of the null value if it does not equal the
3601 null value of its type.],Old=[]}
3602
3603 @PDefn2{Term=[elaboration], Sec=(access_type_definition)}
3604 The elaboration of an @nt{access_type_definition}
3605 creates the access type and its first subtype.
3606 For an access-to-object type,
3607 this elaboration includes the elaboration of the @nt{subtype_indication},
3608 which creates the designated subtype.
3609
3610 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00254-01]}
3611 @PDefn2{Term=[elaboration], Sec=(access_definition)}
3612 The elaboration of an @nt{access_definition} creates
3613 an anonymous@Chg{Version=[2],New=[],Old=[ general]} access@Chg{Version=[2],
3614 New=[],Old=[-to-variable]} type@Chg{Version=[2],New=[],
3615 Old=[ @Redundant[(this happens as part of the initialization of
3616 an access parameter or access discriminant)]]}.
3617 @end{RunTime}
3618
3619 @begin{Notes}
3620 Access values are called @lquotes@;pointers@rquotes@; or @lquotes@;references@rquotes@; in
3621 some other languages.
3622
3623 Each access-to-object type has an associated storage pool;
3624 several access types can share the same pool.
3625 An object can be created in the storage pool of an
3626 access type by an @nt{allocator} (see @RefSecNum{Allocators})
3627 for the access type.
3628 A storage pool (roughly) corresponds to what some other languages
3629 call a @lquotes@;heap.@rquotes@;
3630 See @RefSecNum{Storage Management} for a discussion of pools.
3631
3632 Only @nt<index_constraint>s and @nt<discriminant_constraint>s
3633 can be applied to access types
3634 (see @RefSecNum{Index Constraints and Discrete Ranges} and
3635 @RefSecNum{Discriminant Constraints}).
3636 @end{Notes}
3637
3638 @begin{Examples}
3639 @Leading@keepnext@i{Examples of access-to-object types:}
3640 @begin{Example}
3641 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
3642 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0056-1]}
3643 @Chg{Version=[4],New=[@key[type] Frame @key<is access> Matrix; --@RI[ see @RefSecNum{Array Types}]
3644 ],Old=[]}@key[type] Peripheral_Ref @key<is @Chg{Version=[2],New=[not null ],Old=[]}access> Peripheral; --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}]
3645 @key[type] Binop_Ptr @key[is access all] Binary_Operation'Class;
3646 --@RI[ general access-to-class-wide, see @RefSecNum{Type Extensions}]
3647 @end{Example}
3648
3649 @begin{WideAbove}
3650 @leading@keepnext@i{Example of an access subtype:}
3651 @end{WideAbove}
3652 @begin{Example}
3653 @key[subtype] Drum_Ref @key[is] Peripheral_Ref(Drum); --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}]
3654 @end{Example}
3655
3656 @begin{WideAbove}
3657 @leading@keepnext@i{Example of an access-to-subprogram type:}
3658 @end{WideAbove}
3659 @begin{Example}
3660 @key[type] Message_Procedure @key[is] @key[access] @key[procedure] (M : @key[in] String := "Error!");
3661 @key[procedure] Default_Message_Procedure(M : @key[in] String);
3662 Give_Message : Message_Procedure := Default_Message_Procedure'Access;
3663 ...
3664 @key[procedure] Other_Procedure(M : @key[in] String);
3665 ...
3666 Give_Message := Other_Procedure'Access;
3667 ...
3668 Give_Message("File not found."); --@RI{ call with parameter (.@key[all] is optional)}
3669 Give_Message.@key[all]; --@RI{ call with no parameters}
3670 @end{Example}
3671 @end{Examples}
3672
3673 @begin{Extend83}
3674 @Defn{extensions to Ada 83}
3675 The syntax for @nt{access_type_definition} is
3676 changed to support general access
3677 types (including access-to-constants) and access-to-subprograms.
3678 The syntax rules for @nt{general_access_modifier} and
3679 @nt{access_definition} are new.
3680 @end{Extend83}
3681
3682 @begin{DiffWord83}
3683 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1]}
3684 We use the term "storage pool" to talk about the data area from which
3685 allocation takes place. The term "collection" is @Chg{Version=[3],New=[only
3686 used for finalization],Old=[no longer used]}. ("Collection" and "storage pool"
3687 are not the same thing because multiple unrelated access types can share the
3688 same storage pool; see @RefSecNum(Storage Management) for more discussion.)
3689 @end{DiffWord83}
3690
3691 @begin{Inconsistent95}
3692 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3693 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
3694 Access discriminants and noncontrolling access parameters no longer
3695 exclude null. A program which passed @key{null} to such an access
3696 discriminant or access parameter and expected it to raise Constraint_Error
3697 may fail @ChgNote{but not if the parameter is dereferenced in the subprogram or
3698 record }when compiled with Ada 2005. One hopes that there no such programs
3699 outside of the ACATS. (Of course, a program which actually wants to pass
3700 @key{null} will work, which is far more likely.)]}
3701
3702 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
3703 @ChgAdded{Version=[2],Text=[Most unconstrained aliased objects
3704 with defaulted discriminants are no longer
3705 constrained by their initial values. This means that a program that
3706 raised Constraint_Error from an attempt to change the discriminants
3707 will no longer do so. The change only affects programs that depended
3708 on the raising of Constraint_Error in this case, so the inconsistency
3709 is unlikely to occur outside of the ACATS. This change may however cause
3710 compilers to implement these objects differently, possibly taking additional
3711 memory or time. This is unlikely to be worse than the differences caused by
3712 any major compiler upgrade.]}
3713 @end{Inconsistent95}
3714
3715 @begin{Incompatible95}
3716 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00225-01]}
3717 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
3718 @B[Amendment Correction:] The rule defining when a current instance of a
3719 limited type is considered to be aliased has been tightened to apply only to
3720 types that cannot become nonlimited. A program that attempts to take 'Access
3721 of the current instance of a limited type that can become nonlimited will be
3722 illegal in Ada 2005. While original Ada 95 allowed the current instance of
3723 any limited type to be treated as aliased, this was inconsistently
3724 implemented in compilers, and was likely to not work as expected for types
3725 that are ultimately nonlimited.]}
3726 @end{Incompatible95}
3727
3728 @begin{Extend95}
3729 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
3730 @Chg{Version=[2],New=[@Defn{extensions to Ada 95}The @nt{null_exclusion} is
3731 new. It can be used in both anonymous and named access type definitions.
3732 It is most useful to declare that parameters cannot be @key{null},
3733 thus eliminating the need for checks on use.],Old=[]}
3734
3735 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00404-01]}
3736 @Chg{Version=[2],New=[The kinds of anonymous
3737 access types allowed were increased by adding anonymous access-to-constant
3738 and anonymous access-to-subprogram types. Anonymous access-to-subprogram
3739 types used as parameters allow passing of subprograms at any level.],Old=[]}
3740 @end{Extend95}
3741
3742 @begin{DiffWord95}
3743 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0012],ARef=[AI95-00062-01]}
3744 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added accidentally-omitted
3745 wording that says that a derived access type shares its storage pool with its
3746 parent type. This was clearly intended, both because of a note in
3747 @RefSecNum{Derived Types and Classes}, and because anything else would
3748 have been incompatible with Ada 83.]}
3749
3750 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0013],ARef=[AI95-00012-01]}
3751 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Fixed typographical errors in
3752 the description of when access types are constrained.]}
3753
3754 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
3755 @ChgAdded{Version=[2],Text=[The wording was fixed to allow @nt{allocator}s and
3756 the literal @key{null} for anonymous access types. The former was clearly
3757 intended by Ada 95; see the @ImplAdviceTitle in @RefSecNum{Storage Management}.]}
3758
3759 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
3760 @ChgAdded{Version=[2],Text=[The rules about aliased objects being constrained by
3761 their initial values now apply only to allocated objects, and thus have
3762 been moved to @RefSec{Allocators}.]}
3763 @end{DiffWord95}
3764
3765 @begin{DiffWord2005}
3766 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0053-1],ARef=[AI05-0277-1]}
3767 @ChgAdded{Version=[3],Text=[@b<Correction:> The rule about a current instance
3768 being aliased now is worded in terms of immutably limited types.
3769 Wording was also added to make extended return object declarations that have the
3770 keyword @key[aliased] be considered aliased. This latter was a significant
3771 oversight in Ada 2005 @em technically, the keyword @key[aliased] had no
3772 effect. But of course implementations followed the intent, not the letter of
3773 the Standard.]}
3774
3775 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]}
3776 @ChgAdded{Version=[3],Text=[Explicitly aliased parameters (see
3777 @RefSecNum{Subprogram Declarations}) are defined to be aliased.]}
3778 @end{DiffWord2005}
3779
3780
3781 @LabeledSubClause{Incomplete Type Declarations}
3782
3783 @begin{Intro}
3784 There are no particular limitations on the designated type of an
3785 access type. In particular, the type of a component of the
3786 designated type can be another access type, or even the same access
3787 type. This permits mutually dependent and recursive access types.
3788 An @nt<incomplete_type_declaration> can be used to introduce a type
3789 to be used as a designated type, while deferring its full definition
3790 to a subsequent @nt<full_type_declaration>.
3791 @end{Intro}
3792
3793 @begin{Syntax}
3794 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
3795 @Syn{lhs=<incomplete_type_declaration>,
3796 rhs="@key{type} @Syn2{defining_identifier} [@Syn2{discriminant_part}]@Chg{Version=[2],New=< [@key{is tagged}]>,Old=<>};"}
3797 @end{Syntax}
3798
3799 @begin{StaticSem}
3800 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
3801 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0137-1]}
3802 @ChgAdded{Version=[2],Text=[@Defn{incomplete type}@Defn{incomplete view}
3803 An @nt{incomplete_type_declaration} declares
3804 an @i{incomplete view} of a
3805 type and its first subtype; the first subtype is unconstrained if
3806 a @nt<discriminant_part> appears. If the
3807 @nt{incomplete_@!type_@!declaration} includes the reserved word @key{tagged}, it
3808 declares a @i{tagged incomplete view}.@Defn2{Term=[incomplete view],Sec=[tagged]}@Defn{tagged incomplete view}
3809 @Chg{Version=[4],New=[If @i{T} denotes a tagged incomplete view, then
3810 @i{T}'Class denotes a tagged incomplete view. ],Old=[]}@Redundant[An incomplete
3811 view of a type is a limited view of the type (see @RefSecNum{Limited Types}).]]}
3812
3813 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
3814 @ChgAdded{Version=[2],Type=[Leading],Text=[Given an access type @i{A} whose
3815 designated type @i{T} is
3816 an incomplete view, a dereference of a value of type @i{A} also
3817 has this incomplete view except when:]}
3818 @begin{Discussion}
3819 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0208-1]}
3820 @ChgAdded{Version=[3],Text=[Whether the designated type is an incomplete view
3821 (and thus whether this set of rules applies) is determined by the view of the
3822 type at the declaration of the access type; it does not change during the life
3823 of the type.]}
3824 @end{Discussion}
3825 @begin{Itemize}
3826 @ChgRef{Version=[2],Kind=[Added]}
3827 @Chg{Version=[2],New=[it occurs within the immediate scope of the completion
3828 of @i{T}, or],Old=[]}
3829
3830 @ChgRef{Version=[2],Kind=[Added]}
3831 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0208-1]}
3832 @ChgAdded{Version=[2],Text=[it occurs within the scope of a @nt{nonlimited_with_clause}
3833 that mentions a library package in whose visible part the completion of @i{T}
3834 is declared@Chg{Version=[3],New=[, or],Old=[.]}]}
3835
3836 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0208-1]}
3837 @ChgAdded{Version=[3],Text=[it occurs within the scope of the completion
3838 of @i{T} and @i{T} is an incomplete view declared by an
3839 @nt{incomplete_type_declaration}.]}
3840 @end{Itemize}
3841
3842 @ChgRef{Version=[2],Kind=[Added]}
3843 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0162-1]}
3844 @ChgAdded{Version=[2],Text=[In these cases, the dereference has the
3845 @Chg{Version=[3],New=[],Old=[full ]}view
3846 of @i{T}@Chg{Version=[3],New=[
3847 visible at the point of the dereference],Old=[]}.]}
3848 @begin{Discussion}
3849 @ChgRef{Version=[2],Kind=[AddedNormal]}
3850 @ChgAdded{Version=[2],Type=[Leading],Text=[We need the @lquotes@;in
3851 whose visible part@rquotes@; rule so that the second rule doesn't trigger
3852 in the body of a package with a @key{with} of a child unit:]}
3853 @begin{Example}
3854 @ChgRef{Version=[2],Kind=[AddedNormal]}
3855 @Chg{Version=[2],New=[@Key{package} P @Key{is}
3856 @Key{private}
3857 @Key{type} T;
3858 @Key{type} PtrT @Key{is access} T;
3859 @Key{end} P;],Old=[]}
3860
3861 @ChgRef{Version=[2],Kind=[AddedNormal]}
3862 @Chg{Version=[2],New=[@Key{private package} P.C @Key{is}
3863 Ptr : PtrT;
3864 @Key{end} P.C;],Old=[]}
3865
3866 @ChgRef{Version=[2],Kind=[AddedNormal]}
3867 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
3868 @Chg{Version=[2],New=[@Key{with} P.C;
3869 @Key{package body} P @Key{is}
3870 -- @RI{Ptr.all'Size is not legal here, but @Chg{Version=[3],New=[we are within],Old=[it is in]} the scope}
3871 -- @RI{of a @nt{nonlimited_with_clause} @RI{for P.}}
3872 @Key{type} T @Key{is} ...
3873 -- @RI{Ptr.all'Size is legal here.}
3874 @Key{end} P;],Old=[]}
3875 @end{Example}
3876 @end{Discussion}
3877
3878 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00412-01]}
3879 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0162-1],ARef=[AI05-0208-1]}
3880 @ChgAdded{Version=[2],Text=[Similarly, if a @nt{subtype_mark} denotes a
3881 @nt{subtype_declaration} defining a subtype of an incomplete view @i<T>, the
3882 @nt{subtype_mark} denotes an incomplete view except under the
3883 same @Chg{Version=[3],New=[three],Old=[two]}
3884 circumstances given above, in which case it denotes the
3885 @Chg{Version=[3],New=[],Old=[full ]}view of @i<T>@Chg{Version=[3],New=[ visible at the
3886 point of the @nt{subtype_mark}],Old=[]}.]}
3887 @end{StaticSem}
3888
3889 @begin{Legality}
3890 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0162-1]}
3891 @PDefn2{Term=[requires a completion], Sec=(@nt<incomplete_type_declaration>)}
3892 An @nt{incomplete_@!type_@!declaration} requires a completion, which shall
3893 be a @Chg{Version=[3],New=[@nt{type_@!declaration} other than an
3894 @nt{incomplete_@!type_@!declaration}],Old=[@nt{full_@!type_@!declaration}]}.
3895 @Redundant[If the @nt{incomplete_@!type_@!declaration} occurs immediately
3896 within either the visible part of a
3897 @nt{package_@!specification} or a @nt<declarative_@!part>,
3898 then the @Chg{Version=[3],New=[@nt{type_@!declaration}],
3899 Old=[@nt{full_@!type_@!declaration}]} shall occur later and immediately within this
3900 visible part or @nt<declarative_@!part>.
3901 If the @nt{incomplete_@!type_@!declaration} occurs
3902 immediately within the private part of a
3903 given @nt<package_@!specification>, then the
3904 @Chg{Version=[3],New=[@nt{type_@!declaration}],
3905 Old=[@nt{full_@!type_@!declaration}]} shall occur later and immediately
3906 within either the private part itself, or the @nt{declarative_@!part}
3907 of the corresponding @nt{package_@!body}.]
3908 @begin{TheProof}
3909 This is implied by the next AARM-only rule,
3910 plus the rules in @RefSec{Completions of Declarations}
3911 which require a completion to appear later and immediately within
3912 the same declarative region.
3913 @end{TheProof}
3914 @begin{Honest}
3915 If the @nt{incomplete_type_declaration} occurs immediately within
3916 the visible part of a @nt{package_specification},
3917 then the @Chg{Version=[3],New=[completing @nt{type_@!declaration}],
3918 Old=[@nt{full_@!type_@!declaration}]}
3919 shall occur immediately within this visible part.
3920 @end{Honest}
3921 @begin(Honest)
3922 If the implementation supports it, an
3923 @nt{incomplete_type_declaration} can be @Chg{Version=[3],New=[imported
3924 (using aspect Import, see @RefSecNum{Interfacing Aspects}), in which
3925 case no explicit completion is allowed],Old=[completed by a @nt{pragma}
3926 Import]}.
3927 @end(Honest)
3928
3929 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
3930 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0162-1]}
3931 @Chg{Version=[2],New=[If an @nt{incomplete_@!type_@!declaration} includes the
3932 reserved word @key{tagged}, then a @Chg{Version=[3],New=[@nt{type_@!declaration}],
3933 Old=[@nt{full_@!type_@!declaration}]} that completes
3934 it shall declare a tagged type. ],Old=[]}If an @nt{incomplete_@!type_@!declaration}
3935 has a @nt{known_@!discriminant_@!part},
3936 then a @Chg{Version=[3],New=[@nt{type_@!declaration}],
3937 Old=[@nt{full_@!type_@!declaration}]} that completes it shall have a fully
3938 conforming (explicit) @nt{known_@!discriminant_@!part}
3939 (see @RefSecNum(Conformance Rules)).
3940 @Defn2{Term=[full conformance],Sec=(required)}
3941 @Redundant[If an @nt{incomplete_@!type_@!declaration} has no @nt<discriminant_part>
3942 (or an @nt<unknown_@!discriminant_@!part>),
3943 then a corresponding @Chg{Version=[3],New=[@nt{type_@!declaration}],
3944 Old=[@nt{full_@!type_@!declaration}]} is nevertheless allowed
3945 to have discriminants, either explicitly, or inherited via derivation.]
3946
3947
3948 @Leading@keepnext@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
3949 @Chg{Version=[2],New=[A],Old=[The only allowed uses of a]} @nt{name} that
3950 denotes an @Chg{Version=[2],New=[incomplete view of a type may be used],
3951 Old=[@nt{incomplete_type_declaration} are]} as follows:
3952 @begin(Discussion)
3953 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00326-01]}
3954 @ChgDeleted{Version=[2],Text=[No need to say "prior to the end of the
3955 @nt{full_type_declaration}" since the name would not denote the
3956 @nt{incomplete_type_declaration} after the end of the
3957 @nt{full_type_declaration}. Also, with child library units, it would not be
3958 well defined whether they come before or after the @nt<full_type_declaration>
3959 for deferred incomplete types.]}
3960 @end(Discussion)
3961 @begin(itemize)
3962 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0098-1]}
3963 as the @nt{subtype_mark} in the @nt{subtype_indication}
3964 of an @nt{access_to_@!object_@!definition};
3965 @Redundant[the only form of @nt{constraint} allowed in this
3966 @nt{subtype_indication} is a @nt{discriminant_constraint}@Chg{Version=[3],New=[
3967 @Redundant[(a @nt{null_exclusion} is not allowed)]],Old=[]};]
3968 @begin(ImplNote)
3969 We now allow @nt<discriminant_constraint>s even if the
3970 full type is deferred to the package body. However, there
3971 is no particular implementation burden because we have
3972 dropped the concept of the dependent compatibility check.
3973 In other words, we have effectively repealed AI83-00007.
3974 @end(ImplNote)
3975
3976 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01],ARef=[AI95-00412-01]}@ChgNote{The old rule is moved}
3977 as the @nt{subtype_mark} @Chg{Version=[2],New=[in the @nt{subtype_indication}
3978 of a @nt{subtype_declaration}; the @nt{subtype_@!indication} shall not have a
3979 @nt{null_@!exclusion} or a @nt{constraint};],Old=[defining the subtype
3980 of a parameter or result of an @nt{access_to_@!subprogram_@!definition};]}
3981 @begin{Reason}
3982 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00326-01]}@ChgNote{Really moved}
3983 @ChgDeleted{Version=[2],Text=[This allows, for example, a record to have a
3984 component designating a subprogram that takes that same record
3985 type as a parameter.]}
3986 @end{Reason}
3987
3988 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
3989 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0151-1]}
3990 as the @nt<subtype_mark> in an
3991 @nt<access_definition>@Chg{Version=[2],New=[@Chg{Version=[3],New=[ for
3992 an access-to-object type;],Old=[.]}],Old=[;]}
3993 @begin{Honest}
3994 @ChgRef{Version=[2],Kind=[AddedNormal]}
3995 @ChgAdded{Version=[2],Text=[This does not mean any random @nt{subtype_mark}
3996 in a construct that makes up an @nt<access_definition>, such as
3997 a @nt<formal_part>, just the one given directly in the syntax of
3998 @nt<access_definition>.]}
3999 @end{Honest}
4000
4001 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0151-1]}
4002 @ChgAdded{Version=[3],Text=[as the @nt{subtype_mark} defining the subtype
4003 of a parameter or result in a profile occurring within a
4004 @nt{basic_declaration};]}
4005 @begin{Ramification}
4006 @ChgRef{Version=[3],Kind=[AddedNormal]}
4007 @ChgAdded{Version=[3],Text=[But not in the profile for a body or entry.]}
4008 @end{Ramification}
4009
4010 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0213-1]}
4011 @ChgAdded{Version=[3],Text=[as a generic actual parameter whose corresponding
4012 generic formal parameter is a formal incomplete type (see
4013 @RefSecNum{Formal Private and Derived Types}).]}
4014 @end{Itemize}
4015
4016 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4017 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[If such a @nt{name}
4018 denotes a tagged incomplete view, it may also be used:]}
4019
4020 @begin{Itemize}
4021 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4022 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0151-1]}
4023 @ChgAdded{Version=[2],Text=[as the @nt{subtype_mark} defining the subtype of a
4024 parameter in @Chg{Version=[3],New=[the profile for a @nt{subprogram_body},
4025 @nt{entry_body}, or @nt{accept_statement}],Old=[a @nt{formal_part}]};]}
4026
4027 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4028 as the @nt{prefix} of an @nt{attribute_reference}
4029 whose @nt{attribute_@!designator}
4030 is Class; such an @nt{attribute_@!reference}
4031 is @Chg{Version=[2],New=[],Old=[similarly ]}restricted to the uses
4032 allowed here;
4033 @Chg{Version=[2],New=[it denotes a tagged incomplete view],
4034 Old=[when used in this way,
4035 the corresponding @nt{full_type_@!declaration} shall
4036 declare a tagged type, and the @nt<attribute_@!reference>
4037 shall occur in the same library unit as
4038 the @nt<incomplete_@!type_@!declaration>]}.
4039 @begin{Reason}
4040 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00326-01]}
4041 @ChgDeleted{Version=[2],Text=[This is to prevent
4042 children from imposing requirements on their ancestor library
4043 units for deferred incomplete types.]}
4044 @end{reason}
4045 @end(itemize)
4046
4047 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4048 @ChgRef{Version=[3],Kind=[DeletedAdded],ARef=[AI05-0151-1]}
4049 @ChgAdded{Version=[2],Type=[Leading],Text=[@Chg{Version=[3],New=[],Old=[If
4050 such a @nt{name} occurs within
4051 the declaration list containing the completion of the
4052 incomplete view, it may also be used:]}]}
4053
4054 @begin{Itemize}
4055 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}@ChgNote{Really moved}
4056 @ChgRef{Version=[3],Kind=[DeletedAdded],ARef=[AI05-0098-1],ARef=[AI05-0151-1]}@ChgNote{Now part of the next paragraph}
4057 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[as the @nt{subtype_mark} defining the subtype of a
4058 parameter or result of an @nt{access_to_@!subprogram_@!definition}.]}]}
4059 @begin{Reason}
4060 @ChgRef{Version=[2],Kind=[AddedNormal]}
4061 @ChgRef{Version=[3],Kind=[Deleted]}
4062 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[This allows,
4063 for example, a record to have a
4064 component designating a subprogram that takes that same record
4065 type as a parameter.]}]}
4066 @end{Reason}
4067 @end{Itemize}
4068
4069 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4070 @ChgAdded{Version=[2],Text=[If any of the above uses occurs as part of the
4071 declaration of a primitive subprogram of the incomplete view,
4072 and the declaration occurs immediately within the private part of a package, then
4073 the completion of the incomplete view shall also
4074 occur immediately within the private part; it shall not be deferred to the
4075 package body.]}
4076 @begin{Reason}
4077 @ChgRef{Version=[2],Kind=[AddedNormal]}
4078 @ChgAdded{Version=[2],Text=[This fixes a hole in Ada 95 where a dispatching
4079 operation with an access parameter could be declared in a private part
4080 and a dispatching call on it could occur in a child even though there is
4081 no visibility on the full type, requiring access to the controlling tag
4082 without access to the representation of the type.]}
4083 @end{Reason}
4084
4085 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
4086 @ChgAdded{Version=[2],Text=[No other uses of a @nt{name} that denotes an
4087 incomplete view of a type are allowed.]}
4088
4089 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
4090 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0151-1]}
4091 @Chg{Version=[2],New=[A @nt{prefix} that denotes an object],
4092 Old=[A dereference (whether implicit or explicit @em see @RefSecNum(Names))]}
4093 shall not be of an incomplete @Chg{Version=[2],New=[view],Old=[type]}.@Chg{Version=[3],New=[
4094 An actual parameter in a call shall not be of an untagged incomplete
4095 view. The result object of a function call shall not be of an
4096 incomplete view. A @nt{prefix} shall not denote a subprogram
4097 having a formal parameter of an untagged incomplete view,
4098 nor a return type that is an incomplete view.],Old=[]}
4099 @begin{Reason}
4100 @ChgRef{Version=[2],Kind=[AddedNormal]}
4101 @ChgAdded{Version=[2],Text=[We used to disallow all dereferences of an incomplete
4102 type. Now we only disallow such dereferences when used as a @nt{prefix}.
4103 Dereferences used in other contexts do not pose a problem since normal type
4104 matching will preclude their use except when the full type is @lquotes@;nearby@rquotes@;
4105 as context (for example, as the expected type).]}
4106
4107 @ChgRef{Version=[2],Kind=[AddedNormal]}
4108 @ChgAdded{Version=[2],Text=[This also disallows @nt{prefix}es that are
4109 directly of an incomplete view. For instance, a parameter @i{P} can be
4110 declared of a tagged incomplete type, but we don't want to allow @i{P}'Size,
4111 @i{P}'Alignment, or the like, as representation values aren't known for an
4112 incomplete view.]}
4113
4114 @ChgRef{Version=[2],Kind=[AddedNormal]}
4115 @ChgAdded{Version=[2],Text=[We say @lquotes@;denotes an object@rquotes
4116 so that prefixes that directly name an incomplete view are not covered;
4117 the previous rules cover such cases, and we certainly don't want to ban
4118 Incomp'Class.]}
4119
4120 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0151-1]}
4121 @ChgAdded{Version=[3],Text=[As subprogram profiles now may include any
4122 kind of incomplete type, we also disallow passing objects of untagged
4123 incomplete types in subprogram calls (as the parameter passing method
4124 is not known as it is for tagged types) and disallow returning any
4125 sort of incomplete objects (since we don't know how big they are).]}
4126 @end{Reason}
4127 @end{Legality}
4128
4129 @begin{StaticSem}
4130 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00326-01]}
4131 @ChgDeleted{Version=[2],Text=[@Defn{incomplete type}
4132 An @nt{incomplete_type_declaration} declares an incomplete
4133 type and its first subtype; the first subtype is unconstrained if
4134 a @nt<known_discriminant_part> appears.]}
4135 @begin{Reason}
4136 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4137 @ChgDeleted{Version=[2],Text=[If an @nt<unknown_discriminant_part> or
4138 no @nt{discriminant_part}
4139 appears, then the constrainedness of the first subtype doesn't matter
4140 for any other rules or semantics, so we don't bother defining it.
4141 The case with a @nt<known_discriminant_part> is the only case in which
4142 a constraint could later be given in a @nt{subtype_indication} naming
4143 the incomplete type.]}
4144 @end{Reason}
4145 @end{StaticSem}
4146 @begin{NotIso}
4147 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Paragraph 11 was
4148 deleted.>}]}@Comment{This message should be deleted if the paragraphs
4149 are ever renumbered.}
4150 @end{NotIso}
4151
4152 @begin{RunTime}
4153 @PDefn2{Term=[elaboration], Sec=(incomplete_type_declaration)}
4154 The elaboration of an @nt{incomplete_type_declaration} has no effect.
4155 @begin(Reason)
4156 An incomplete type has no real existence, so it doesn't need to be
4157 "created" in the usual sense we do for other types.
4158 It is roughly equivalent to a "forward;" declaration in Pascal.
4159 Private types are different, because they have a different
4160 set of characteristics from their full type.
4161 @end(Reason)
4162 @end{RunTime}
4163
4164 @begin{Notes}
4165 @PDefn{completion legality}
4166 Within a @nt<declarative_part>, an @nt<incomplete_type_declaration>
4167 and a corresponding @nt<full_type_declaration> cannot be separated
4168 by an intervening body.
4169 This is because a type has to
4170 be completely defined before it is frozen, and a body freezes
4171 all types declared prior to it in the same @nt<declarative_part>
4172 (see @RefSecNum{Freezing Rules}).
4173
4174 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0151-1],ARef=[AI05-0269-1]}
4175 @ChgAdded{Version=[3],Text=[A @nt{name} that denotes an object of an
4176 incomplete view is defined to be of a limited type. Hence, the target of
4177 an assignment statement cannot be of an incomplete view.]}
4178
4179 @end{Notes}
4180
4181 @begin{Examples}
4182 @Leading@keepnext@i(Example of a recursive type:)
4183 @begin(Example)
4184 @key(type) Cell; --@RI[ incomplete type declaration]
4185 @key(type) Link @key(is) @key(access) Cell;
4186
4187 @key(type) Cell @key(is)
4188 @key(record)
4189 Value : Integer;
4190 Succ : Link;
4191 Pred : Link;
4192 @key(end) @key(record);
4193
4194 Head : Link := @key(new) Cell'(0, @key(null), @key(null));
4195 Next : Link := Head.Succ;
4196 @end(Example)
4197
4198 @i(Examples of mutually dependent access types:)
4199 @begin(Example)
4200 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
4201 @key(type) Person(<>); --@RI[ incomplete type declaration]
4202 @key(type) Car@Chg{Version=[2],New=[ @key{is tagged};],Old=[; ]} --@RI[ incomplete type declaration]
4203
4204 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
4205 @key(type) Person_Name @key(is) @key(access) Person;
4206 @key(type) Car_Name @key(is) @key(access) @key(all) Car@Chg{Version=[2],New=['Class],Old=[]};
4207
4208 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
4209 @key(type) Car @key(is)@Chg{Version=[2],New=[ @key(tagged)],Old=[]}
4210 @key(record)
4211 Number : Integer;
4212 Owner : Person_Name;
4213 @key(end) @key(record);
4214
4215
4216 @key(type) Person(Sex : Gender) @key(is)
4217 @key(record)
4218 Name : String(1 .. 20);
4219 Birth : Date;
4220 Age : Integer @key(range) 0 .. 130;
4221 Vehicle : Car_Name;
4222 @key(case) Sex @key(is)
4223 @key(when) M => Wife : Person_Name(Sex => F);
4224 @key(when) F => Husband : Person_Name(Sex => M);
4225 @key(end) @key(case);
4226 @key(end) @key(record);
4227
4228 My_Car, Your_Car, Next_Car : Car_Name := @key[new] Car; --@RI[ see @RefSecNum{Allocators}]
4229 George : Person_Name := @key[new] Person(M);
4230 ...
4231 George.Vehicle := Your_Car;
4232 @end(Example)
4233
4234 @end{Examples}
4235
4236 @begin{Extend83}
4237 @Defn{extensions to Ada 83}
4238 The @nt{full_type_declaration} that completes an
4239 @nt{incomplete_type_declaration} may have a
4240 @nt{known_discriminant_part} even if the
4241 @nt{incomplete_type_declaration} does not.
4242
4243 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00013}
4244 A @nt<discriminant_constraint> may be applied
4245 to an incomplete type, even if @Chg{New=[],Old=[it ]}its completion is
4246 deferred to the package body, because there is no
4247 @lquotes@;dependent compatibility check@rquotes@; required any more.
4248 Of course, the constraint can be specified only if
4249 a @nt<known_discriminant_part> was given in the
4250 @nt<incomplete_type_declaration>. As mentioned in the previous
4251 paragraph, that is no longer required even when the full type
4252 has discriminants.
4253 @end{Extend83}
4254
4255 @begin{DiffWord83}
4256 @Leading@;Dereferences producing incomplete types
4257 were not explicitly disallowed in RM83, though
4258 AI83-00039 indicated that it was not strictly necessary since
4259 troublesome cases would result in Constraint_Error at run time,
4260 since the access value would necessarily be null.
4261 However, this introduces an undesirable implementation burden,
4262 as illustrated by Example 4 of AI83-00039:
4263 @begin{example}
4264 @key[package] Pack @key[is]
4265 @key[type] Pri @key[is] @key[private];
4266 @key[private]
4267 @key[type] Sep;
4268 @key[type] Pri @key[is] @key[access] Sep;
4269 X : Pri;
4270 @key[end] Pack;
4271
4272 @key[package] @key[body] Pack @key[is] --@RI{ Could be separately compiled!}
4273 @key[type] Sep @key[is] ...;
4274 X := @key[new] Sep;
4275 @key[end] Pack;
4276
4277 @key[pragma] Elaborate(Pack);
4278 @key[private] @key[package] Pack.Child @key[is]
4279 I : Integer := X.@key{all}'Size; --@RI{ Legal, by AI-00039.}
4280 @key[end] Pack.Child;
4281 @end{example}
4282
4283 Generating code for the above example could be a serious implementation
4284 burden, since it would require all aliased objects to store size dope,
4285 and for that dope to be in the same format for all kinds of types
4286 (or some other equivalently inefficient implementation).
4287 On the contrary, most implementations allocate dope differently (or
4288 not at all) for different designated subtypes.
4289 @end{DiffWord83}
4290
4291 @begin{Incompatible95}
4292 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4293 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
4294 It is now illegal to use an incomplete view (type) as the parameter or result
4295 of an access-to-subprogram type unless the incomplete view is completed in
4296 the same declaration list as the use. This was allowed in Ada 95 for
4297 incomplete types where the completion was deferred to the body. By
4298 disallowing this rare use of incomplete views, we can allow the use of
4299 incomplete views in many more places, which is especially valuable for
4300 limited views.]}
4301
4302 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4303 @ChgAdded{Version=[2],Text=[It is now illegal to use an incomplete view
4304 (type) in a primitive subprogram of the type unless the incomplete view is
4305 completed in the package specification. This was allowed in Ada 95 for
4306 incomplete types where the completion was deferred to the body (the use would
4307 have to be in an access parameter). This incompatibility was caused by the
4308 fix for the hole noted in @LegalityTitle above.]}
4309 @end{Incompatible95}
4310
4311 @begin{Extend95}
4312 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4313 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}Tagged incomplete types
4314 are new. They are allowed in parameter declarations as well as the usual
4315 places, as tagged types are always by-reference types (and thus there can
4316 be no code generation issue).]}
4317
4318 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00412-01]}
4319 @ChgAdded{Version=[2],Text=[A @nt{subtype_declaration} can be used to
4320 give a new name to an incomplete view of a type. This is valuable to
4321 give shorter names to entities imported with a @nt{limited_with_clause}.]}
4322 @end{Extend95}
4323
4324 @begin{DiffWord95}
4325 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
4326 @ChgAdded{Version=[2],Text=[The description of incomplete types as
4327 @i{incomplete views} is new. Ada 95 defined these as separate types, but
4328 neglected to give any rules for matching them with other types. Luckily,
4329 implementers did the right thing anyway. This change also makes it easier to
4330 describe the meaning of a limited view.]}
4331 @end{DiffWord95}
4332
4333 @begin{Extend2005}
4334 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0098-1]}
4335 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:>
4336 Fixed the definition so that an anonymous access-to-subprogram type can use an
4337 incomplete view in the same way that a named access-to-subprogram type can.]}
4338
4339 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0151-1]}
4340 @ChgAdded{Version=[3],Text=[Incomplete types now can be used
4341 in subprogram declarations. The type has to be complete before any calls
4342 or the body is declared. This reduces the places where access types are
4343 required for types imported from limited views of packages.]}
4344
4345 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0162-1]}
4346 @ChgAdded{Version=[3],Text=[Incomplete types now can be
4347 completed by private types and private extensions. Since this can already
4348 happen for limited views, there is no remaining reason to disallow it for
4349 explicitly declared incomplete types.]}
4350 @end{Extend2005}
4351
4352 @begin{DiffWord2005}
4353 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0208-1]}
4354 @ChgAdded{Version=[3],Text=[@b<Correction:> Changed the
4355 rules of uses of dereferences of incomplete views such that it does not
4356 introduce an unintentional incompatibility with Ada 83 and Ada 95.]}
4357
4358 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0213-1]}
4359 @ChgAdded{Version=[3],Text=[Incomplete types now can be used as actuals to
4360 formal incomplete types (see @RefSecNum{Formal Private and Derived Types}).]}
4361 @end{DiffWord2005}
4362
4363 @begin{DiffWord2012}
4364 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0137-1]}
4365 @ChgAdded{Version=[4],Text=[@b<Corrigndum:> Changed the wording to clarify
4366 that the class-wide type associated with a specific tagged type that has
4367 an incomplete view is also an incomplete view.
4368 While this was previously undefined, an interpretation where it is not
4369 an incomplete view is leads to semantic nonsense, and thus we don't consider
4370 this a potential incompatibility, as compilers most likely are doing the
4371 right thing.]}
4372 @end{DiffWord2012}
4373
4374
4375 @LabeledSubClause{Operations of Access Types}
4376
4377 @begin{Intro}
4378 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
4379 @Redundant[The attribute Access is used to create access values
4380 designating aliased objects and nonintrinsic subprograms.
4381 The @lquotes@;accessibility@rquotes@; rules prevent dangling references
4382 (in the absence of uses of certain unchecked features
4383 @em see @Chg{Version=[3],New=[Clause],Old=[Section]}
4384 @RefSecNum{Representation Issues}).]
4385 @end{Intro}
4386
4387 @begin{MetaRules}
4388 It should be possible for an access value to designate an object
4389 declared by an object declaration, or a subcomponent thereof.
4390 In implementation terms, this means pointing at stack-allocated and
4391 statically allocated data structures.
4392 However, dangling references should be prevented, primarily via
4393 compile-time rules, so long as features like Unchecked_Access and
4394 Unchecked_Deallocation are not used.
4395
4396 In order to create such access values, we require that the access type be a
4397 general access type, that the designated object be aliased,
4398 and that the accessibility rules be obeyed.
4399 @end{MetaRules}
4400
4401 @begin{Resolution}
4402 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235-01]}
4403 @PDefn2{Term=[expected type], Sec=(access attribute_reference)}
4404 For an @nt<attribute_reference> with @nt<attribute_designator>
4405 Access (or Unchecked_Access @em see @RefSecNum(Unchecked Access Value Creation)),
4406 the expected type shall be a single
4407 access type@Chg{Version=[2],New=[ @i<A> such that:],Old=[@Redundant[; the
4408 @nt<prefix> of such an @nt<attribute_reference>
4409 is never interpreted as an @nt<implicit_dereference>].
4410 @PDefn2{Term=[expected profile],
4411 Sec=(Access @nt<attribute_reference> @nt<prefix>)}
4412 If the expected type is an access-to-subprogram type,
4413 then the expected profile of the @nt<prefix> is the
4414 designated profile of the access type.]}
4415 @begin{Itemize}
4416 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00235-01]}
4417 @Chg{Version=[2],New=[@i{A} is an access-to-object type with designated type
4418 @i{D} and the type of the @nt{prefix} is @i{D}'Class or is covered by @i{D}, or],Old=[]}
4419
4420 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00235-01]}
4421 @Chg{Version=[2],New=[@i{A} is an access-to-subprogram type whose designated
4422 profile is type conformant with that of the prefix.],Old=[]}
4423 @end{Itemize}
4424
4425 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00235-01]}
4426 @Chg{Version=[2],New=[@Redundant[The @nt{prefix} of such an
4427 @nt{attribute_reference} is never interpreted as an @nt{implicit_dereference}
4428 or a parameterless @nt{function_call} (see @RefSecNum{Attributes}).]
4429 @PDefn2{Term=[expected profile],
4430 Sec=(Access @nt<attribute_reference> @nt<prefix>)}
4431 @PDefn2{Term=[expected type],
4432 Sec=(Access @nt<attribute_reference> @nt<prefix>)}
4433 The designated type or profile of the expected type of the @nt{attribute_reference}
4434 is the expected type or profile for the @nt{prefix}.],Old=[]}
4435 @begin(Discussion)
4436 Saying that the expected type shall be a "single access type"
4437 is our "new" way of saying that the type has to be determinable from
4438 context using only the fact that it is an access type.
4439 See @RefSecNum{Literals} and @RefSecNum{The Context of Overload Resolution}.
4440 Specifying the expected profile only implies type conformance.
4441 The more stringent subtype conformance is required by a Legality
4442 Rule. This is the only Resolution Rule that applies to the
4443 @nt<name> in a @nt{prefix} of an @nt{attribute_reference}.
4444 In all other cases, the @nt{name} has to be resolved without
4445 using context. See @RefSecNum{Attributes}.
4446
4447 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]}
4448 @ChgAdded{Version=[2],Type=[Leading],Text=[Saying @lquotes@;single access
4449 type@rquotes@; is a bit of a fudge. Both the context and the @nt{prefix} may
4450 provide both multiple types; @lquotes@;single@rquotes@; only means that a
4451 single, specific interpretation must remain after resolution. We say
4452 @lquotes@;single@rquotes@; here to trigger the @LegalityTitle of
4453 @RefSecNum{The Context of Overload Resolution}. The resolution of an access
4454 attribute is similar to that of an @nt{assignment_statement}. For example:]}
4455 @begin{Example}
4456 @ChgRef{Version=[2],Kind=[AddedNormal]}
4457 @Chg{Version=[2],New=[@key{type} Int_Ptr @key{is access all} Integer;
4458 @key{type} Char_Ptr @key{is access all} Character;
4459 @key{type} Float_Ptr @key{is access all} Float;],Old=[]}
4460
4461 @ChgRef{Version=[2],Kind=[AddedNormal]}
4462 @Chg{Version=[2],New=[@key{function} Zap (Val : Int_Ptr) @key{return} Float; -- @RI[(1)]
4463 @key{function} Zap (Val : Float_Ptr) @key{return} Float; -- @RI[(2)]
4464 @key{function} Zop @key{return} Int_Ptr; -- @RI[(3)]
4465 @key{function} Zop @key{return} Char_Ptr; -- @RI[(4)]],Old=[]}
4466
4467 @ChgRef{Version=[2],Kind=[AddedNormal]}
4468 @Chg{Version=[2],New=[Result : Float := Zap (Zop.@key{all}'Access); -- @RI[Resolves to Zap (1) and Zop (3).]],Old=[]}
4469 @end{Example}
4470 @end(Discussion)
4471 @end{Resolution}
4472
4473 @begin{StaticSem}
4474
4475 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00162-01]}
4476 @Defn{accessibility level}
4477 @Defn2{Term=[level],Sec=(accessibility)}
4478 @Defn2{Term=[deeper],Sec=(accessibility level)}
4479 @Defn2{Term=[depth],Sec=(accessibility level)}
4480 @Defn2{Term=[dangling references],Sec=(prevention via accessibility rules)}
4481 @Defn{lifetime}
4482 @Redundant[The accessibility rules,
4483 which prevent dangling references,
4484 are written in terms of @i{accessibility levels},
4485 which reflect the run-time nesting of @i{masters}. As explained in
4486 @RefSecNum{Completion and Finalization},
4487 a master is the execution of a
4488 @Chg{Version=[2],New=[certain construct, such as],Old=[,@nt{task_body}, a @nt{block_statement},]}
4489 a @nt{subprogram_body}@Chg{Version=[2],New=[],Old=[, an @nt{entry_body}, or an @nt{accept_statement}]}.
4490 An accessibility level is @i{deeper than} another if it is more
4491 deeply nested at run time.
4492 For example, an object declared local to a called subprogram has a deeper
4493 accessibility level than an object declared local to the calling
4494 subprogram.
4495 The accessibility rules for access types require that the
4496 accessibility level of an object designated by an access value be no
4497 deeper than that of the access type.
4498 This ensures that the object will live at least as long as the access
4499 type, which in turn ensures that the access value cannot later
4500 designate an object that no longer exists.
4501 The Unchecked_Access attribute may be used to circumvent the
4502 accessibility rules.]
4503
4504 @begin{Discussion}
4505 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
4506 @ChgAdded{Version=[3],Text=[The Unchecked_Access attribute acts as if the
4507 object was declared at library-level; this applies even when it is used as the
4508 value of anonymous access type.
4509 See @RefSecNum{Unchecked Access Value Creation}.]}
4510
4511 @ChgRef{Version=[3],Kind=[AddedNormal]}
4512 @ChgAdded{Version=[3],Text=[Subclause @RefSecNum{Operations of Access Types},
4513 home of the accessibility rules, is informally known
4514 as the @ldquote@;Heart of Darkness@rdquote amongst the maintainers of Ada.
4515 Woe unto all who enter here (well, at least unto anyone that needs to understand
4516 any of these rules).
4517 @Defn{Heart of Darkness}@IndexSeeAlso{Term=[accessibility rules],See=[Heart of Darkness]}]}
4518 @end{Discussion}
4519
4520 @Defn{statically deeper}
4521 @Defn2{Term=[deeper],Sec=(statically)}
4522 @Redundant[A given accessibility level is said to be @i{statically
4523 deeper} than another if the given level is known at compile time (as
4524 defined below) to be deeper than the other for all possible executions.
4525 In most cases, accessibility is enforced at compile time by
4526 @LegalityTitle.
4527 Run-time accessibility checks are also used,
4528 since the @LegalityTitle do not cover
4529 certain cases involving access parameters and generic packages.]
4530
4531 @Leading@keepnext@;Each master, and each entity and view created by it,
4532 has an accessibility level:
4533 @begin{Itemize}
4534 The accessibility level of a given master is deeper than
4535 that of each dynamically enclosing master,
4536 and deeper than that of each master upon which the task executing the
4537 given master directly depends
4538 (see @RefSecNum{Task Dependence - Termination of Tasks}).
4539
4540 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00162-01],ARef=[AI95-00416-01]}
4541 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0235-1]}
4542 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0067-1],ARef=[AI12-0089-1]}
4543 An entity or view @Chg{Version=[2],New=[defined],Old=[created]} by a
4544 declaration@Chg{Version=[2],New=[ and created as part of its elaboration],Old=[]}
4545 has the same accessibility level
4546 as the innermost @Chg{Version=[2],New=[],Old=[enclosing ]}master
4547 @Chg{Version=[2],New=[of the declaration ],Old=[]}except in the
4548 cases of renaming and derived access types described below.
4549 @Chg{Version=[3],New=[Other than for an explicitly aliased
4550 parameter@Chg{Version=[4],New=[ of a function or generic function],Old=[]}, a
4551 formal],Old=[A]} parameter of a
4552 @Chg{Version=[3],New=[callable entity],Old=[master]} has the same
4553 accessibility level as the master@Chg{Version=[3],New=[ representing the
4554 invocation of the entity],Old=[]}.
4555 @begin{Reason}
4556 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4557 @ChgAdded{Version=[2],Text=[This rule defines the @lquotes@;normal@rquotes
4558 accessibility of entities. In the absence of special rules below, we intend
4559 for this rule to apply.]}
4560 @end{Reason}
4561 @begin{Discussion}
4562 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4563 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
4564 @ChgAdded{Version=[2],Text=[This rule defines the accessibility of all
4565 named access types, as well as the accessibility level of
4566 @Chg{Version=[4],New=[],Old=[all ]}anonymous
4567 access types @Chg{Version=[4],New=[in a @nt{component_definition}],Old=[other
4568 than those for access parameters and access discriminants.]} Special rules
4569 exist for the accessibility level of @Chg{Version=[4],New=[other],Old=[such]}
4570 anonymous types. Components@Chg{Version=[4],New=[],Old=[,
4571 stand-alone objects, and function results]} whose
4572 (anonymous) type is defined by an @nt{access_definition} have
4573 accessibility levels corresponding to named access types defined at
4574 the same point.]}
4575 @end{Discussion}
4576 @begin{Ramification}
4577 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
4578 @ChgAdded{Version=[2],Text=[Because accessibility level is determined
4579 by where the @nt{access_definition} is elaborated, for a type extension,
4580 the anonymous access types of components (other than access discriminants)
4581 inherited from the parent have the same accessibility as they did in the
4582 parent; those in the extension part have the accessibility
4583 determined by the scope where the type extension is declared.
4584 Similarly, the types of the nondiscriminant access components
4585 of a derived untagged type have the same accessibility as they
4586 did in the parent.]}
4587 @end{Ramification}
4588 @begin{Honest}
4589 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
4590 @ChgAdded{Version=[3],Text=[We use "invocation of" in the parameter case
4591 as a master is formally an execution of something. But we mean this to be
4592 interpreted statically (for instance, as the body of the subprogram) for the
4593 purposes of computing "statically deeper than" (see below).]}
4594 @end{Honest}
4595 @begin{Ramification}
4596 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
4597 @ChgAdded{Version=[3],Text=[Note that accessibility can differ depending on
4598 the view of an object (for both static and dynamic accessibility). For
4599 instance, the accessibility level of a formal parameter may be different than
4600 the accessibility level of the corresponding actual parameter. This occurs
4601 in other cases as well.]}
4602 @end{Ramification}
4603 @begin{Reason}
4604 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
4605 @ChgAdded{Version=[3],Text=[We define the (dynamic) accessibility of formal
4606 parameters in order that it does not depend on the parameter passing model
4607 (by-reference or by-copy) as that is implementation defined. Otherwise, there
4608 would be a portability issue.]}
4609 @end{Reason}
4610
4611 The accessibility level of
4612 a view of an object or subprogram defined by a @nt{renaming_declaration}
4613 is the same as that of
4614 the renamed view.
4615
4616 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
4617 The accessibility level of
4618 a view conversion@Chg{Version=[2],New=[, @nt{qualified_expression}, or
4619 parenthesized expression,],Old=[]}
4620 is the same as that of
4621 the operand.
4622
4623 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
4624 @ChgAdded{Version=[3],Text=[The accessibility level of a
4625 @nt{conditional_expression} is the accessibility level of the evaluated
4626 @Syni{dependent_}@nt{expression}.]}
4627
4628 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00416-01]}
4629 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0234-1]}
4630 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0027-1]}
4631 @Chg{Version=[2],New=[The],Old=[For a function whose result type is a
4632 return-by-reference type,
4633 the accessibility level of the result object is the same as
4634 that of the master that elaborated the function body. For
4635 any other function, the]} accessibility level of @Chg{Version=[2],New=[an
4636 @nt{aggregate} @Chg{Version=[3],New=[],Old=[or the result of a function call @Redundant[(or equivalent use
4637 of an operator)] ]}that is
4638 used (in its entirety) to directly initialize part of an],Old=[the result]}
4639 object is that of the
4640 @Chg{Version=[2],New=[object being initialized. In other contexts, the
4641 accessibility level of an @nt{aggregate} @Chg{Version=[3],New=[],Old=[or the
4642 result of a function call ]}is that of the innermost
4643 master that evaluates the @nt{aggregate}@Chg{Version=[3],New=[],Old=[ or
4644 function call]}],Old=[execution of the called
4645 function]}.@Chg{Version=[4],New=[ Corresponding rules apply to a value conversion
4646 (see @RefSecNum{Type Conversions}).],Old=[]}
4647
4648 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4649 @ChgAdded{Version=[3],Type=[Leading],Text=[The accessibility level of the result
4650 of a function call is that of the @i<master of the function call>, which is
4651 determined by the point of call as follows:@Defn{master of a call}@Defn2{Term=[call],Sec=[master of]}@Defn2{Term=[function call],Sec=[master of]}]}
4652
4653 @begin{InnerItemize}
4654
4655 @ChgRef{Version=[3],Kind=[Added]}
4656 @ChgAdded{Version=[3],Text=[If the result is used (in its entirety) to
4657 directly initialize part of an object, the master is that of the object being
4658 initialized. In the case where the initialized object is a coextension
4659 (see below) that becomes a coextension of another object, the master is that
4660 of the eventual object to which the coextension will be transferred.]}
4661
4662 @begin{Honest}
4663 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4664 @ChgAdded{Version=[2],Text=[The first sentence is talking about a static
4665 use of the entire return object @em a slice that happens to be the entire
4666 return object doesn't count. On the other hand, this is intended to allow
4667 parentheses and @nt{qualified_expression}s.]}
4668 @end{Honest}
4669 @begin{Ramification}
4670 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4671 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0234-1]}
4672 @ChgAdded{Version=[2],Text=[If the function is used as a @nt{prefix},
4673 @Chg{Version=[3],New=[this bullet does not apply],Old=[the second sentence
4674 applies]}. Similarly, an @nt{assignment_statement} is not an initialization
4675 of an object, so @Chg{Version=[3],New=[this bullet does not apply],Old=[the second sentence
4676 applies]}.]}
4677 @end{Ramification}
4678
4679 @ChgRef{Version=[3],Kind=[Added]}
4680 @ChgAdded{Version=[3],Text=[If the result is of an anonymous access type and
4681 is the operand of an explicit conversion, the master is that of the target
4682 type of the conversion;]}
4683
4684 @ChgRef{Version=[3],Kind=[Added]}
4685 @ChgAdded{Version=[3],Text=[If the result is of an anonymous access type and
4686 defines an access discriminant, the master is the same as that for an object
4687 created by an anonymous @nt{allocator} that defines an access discriminant
4688 (even if the access result is of an access-to-subprogram type).]}
4689
4690 @ChgRef{Version=[3],Kind=[Added]}
4691 @ChgAdded{Version=[3],Text=[If the call itself defines the result of a
4692 function to which one of the above rules applies, these rules are applied
4693 recursively;]}
4694
4695 @ChgRef{Version=[3],Kind=[Added]}
4696 @ChgAdded{Version=[3],Text=[In other cases, the master of the call is that of
4697 the innermost master that evaluates the function call.]}
4698
4699 @begin{Ramification}
4700 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02],ARef=[AI95-00416-01]}
4701 @ChgAdded{Version=[2],Text=[The @lquotes@;innermost master which evaluated
4702 the function call@rquotes@; does not include the function call itself (which
4703 might be a master).]}
4704
4705 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02],ARef=[AI95-00416-01]}
4706 @ChgAdded{Version=[2],Text=[We really mean the innermost master here,
4707 which could be a very short lifetime. Consider a function call used as
4708 a parameter of a procedure call. In this case the innermost master which
4709 evaluated the function call is the procedure call.]}
4710 @end{Ramification}
4711
4712 @end{InnerItemize}
4713
4714 @begin{Ramification}
4715 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4716 @ChgAdded{Version=[3],Text=[These rules do not mention whether the result
4717 object is built-in-place (see @RefSecNum{Assignment and Finalization}). In
4718 particular, in the case where building in place is optional, the choice
4719 whether or not to build-in-place has no effect on masters, lifetimes, or
4720 accessibility.]}
4721 @end{Ramification}
4722
4723 @begin{ImplNote}
4724 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4725 @ChgAdded{Version=[3],Type=[Leading],Text=[There are several cases where the
4726 implementation may have to pass in the accessibility level of the result
4727 object on a call, to support later rules where the accessibility level comes
4728 from the master of the call:]}
4729
4730 @begin{Itemize}
4731 @ChgRef{Version=[3],Kind=[Added]}
4732 @ChgAdded{Version=[3],Text=[when the function result may have a part with
4733 access discriminants;]}
4734
4735 @ChgRef{Version=[3],Kind=[Added]}
4736 @ChgAdded{Version=[3],Text=[when the function result type is an anonymous
4737 access type;]}
4738
4739 @ChgRef{Version=[3],Kind=[Added]}
4740 @ChgAdded{Version=[3],Text=[when the function result is built-in-place;]}
4741
4742 @ChgRef{Version=[3],Kind=[Added]}
4743 @ChgAdded{Version=[3],Text=[when the function has an explicitly
4744 aliased parameter.]}
4745 @end{Itemize}
4746
4747 @ChgRef{Version=[3],Kind=[Added]}
4748 @ChgAdded{Version=[3],Text=[In particular, this implies passing a level
4749 parameter when the result type is class-wide, since descendants may add access
4750 discriminants. For most implementations this will mean that functions with
4751 controlling results will also need a level parameter.]}
4752 @end{ImplNote}
4753
4754 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0284-1]}
4755 @ChgAdded{Version=[3],NoPrefix=[T],Text=[In the case of a call to a function
4756 whose result type is an anonymous access type, the accessibility level of the
4757 type of the result of the function call is also determined by the point of call
4758 as described above.]}
4759
4760 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4761 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Just because the paragraph number is changed}
4762 @ChgAdded{Version=[2],Text=[Within a return statement, the accessibility level
4763 of the return object is that of the execution of the return statement. If the
4764 return statement completes normally by returning from the
4765 function, then prior to leaving the function, the accessibility level
4766 of the return object changes to be a level determined by the point
4767 of call, as does the level of any coextensions (see below) of the
4768 return object.]}
4769
4770 @begin{Reason}
4771 @ChgRef{Version=[2],Kind=[AddedNormal]}
4772 @ChgAdded{Version=[2],Text=[We define the accessibility level of the return
4773 object during the return statement to be that of the return statement itself
4774 so that the object may be designated by objects local to the return
4775 statement, but not by objects outside the return statement. In addition, the
4776 intent is that the return object gets finalized if the return statement ends
4777 without actually returning (for example, due to propagating an exception, or
4778 a goto). For a normal return, of course, no finalization is done before
4779 returning.]}
4780 @end{Reason}
4781
4782 The accessibility level of
4783 a derived access type
4784 is the same as that of
4785 its ultimate ancestor.
4786
4787 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
4788 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access
4789 type defined by an @nt{access_definition} of an
4790 @nt{object_renaming_declaration} is the same as that of the renamed view.]}
4791
4792 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00416-01]}
4793 @ChgNote{Use ChgAdded below to get conditional Leading}
4794 @ChgAdded{Version=[2],Type=[Leading],Text=[]}The accessibility level
4795 of the anonymous access type of an access discriminant
4796 @Chg{Version=[2],New=[in the @nt{subtype_indication} or
4797 @nt{qualified_expression} of an @nt{allocator}, or in the @nt{expression} or
4798 @nt{return_@!subtype_@!indication} of a return statement is determined as
4799 follows:],Old=[is the same as that of the containing object or associated
4800 constrained subtype.]}
4801
4802 @begin{InnerItemize}
4803 @ChgRef{Version=[2],Kind=[Added]}
4804 @ChgAdded{Version=[2],Text=[If the value of the access discriminant is
4805 determined by a @nt{discriminant_association} in a @nt{subtype_indication},
4806 the accessibility level of the object or subprogram designated by
4807 the associated value (or library level if the value is null);]}
4808 @begin{Discussion}
4809 @ChgRef{Version=[2],Kind=[AddedNormal]}
4810 @ChgAdded{Version=[2],Type=[Leading],Text=[This deals with the following cases,
4811 when they occur in the context of an @nt{allocator} or return statement:]}
4812 @begin{InnerItemize}
4813 @ChgRef{Version=[2],Kind=[AddedNormal]}
4814 @ChgAdded{Version=[2],Text=[An @nt{extension_aggregate} where the
4815 @nt{ancestor_part} is a @nt{subtype_mark} denoting a constrained subtype;]}
4816
4817 @ChgRef{Version=[2],Kind=[AddedNormal]}
4818 @ChgAdded{Version=[2],Text=[An uninitialized @nt{allocator} where the
4819 @nt{subtype_indication} defines a constrained subtype;]}
4820
4821 @ChgRef{Version=[2],Kind=[AddedNormal]}
4822 @ChgAdded{Version=[2],Text=[A discriminant of an object with a constrained
4823 nominal subtype, including constrained components, the result of calling
4824 a function with a constrained result subtype, the dereference of an
4825 access-to-constrained subtype, etc.]}
4826 @end{InnerItemize}
4827 @end{Discussion}
4828 @begin{Ramification}
4829 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0281-1]}
4830 @ChgAdded{Version=[3],Text=[The @nt{subtype_indication} mentioned in this
4831 bullet is not necessarily the one given in the @nt{allocator} or
4832 return statement that is determining the accessibility level; the constrained
4833 subtype might have been defined in an earlier declaration (as a named
4834 subtype).]}
4835
4836 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
4837 @ChgAdded{Version=[3],Text=[If the value for this rule and the next one is
4838 derived from an Unchecked_Access attribute, the accessibility is library-level
4839 no matter what the accessibility level of the object is (see
4840 @RefSecNum{Unchecked Access Value Creation}).]}
4841 @end{Ramification}
4842
4843 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0234-1]}
4844 @ChgAdded{Version=[3],Text=[If the value of the access discriminant is
4845 determined by a @nt{default_expression} in the declaration of the discriminant,
4846 the level of the object or subprogram designated by the associated value (or
4847 library level if null);]}
4848 @begin{Discussion}
4849 @ChgRef{Version=[3],Kind=[Added]}
4850 @ChgAdded{Version=[3],Text=[This covers the case of an unconstrained
4851 subcomponent of a limited type with defaulted access discriminants.]}
4852 @end{Discussion}
4853
4854 @ChgRef{Version=[2],Kind=[Added]}
4855 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0004-1]}
4856 @ChgAdded{Version=[2],Text=[If the value of the access discriminant is
4857 determined by a @Chg{Version=[3],New=[@nt{record_component_association}],
4858 Old=[@ntf{component_association}]} in an @nt{aggregate}, the
4859 accessibility level of the object or subprogram designated by the associated
4860 value (or library level if the value is null);]}
4861
4862 @begin{Discussion}
4863 @ChgRef{Version=[2],Kind=[AddedNormal]}
4864 @ChgAdded{Version=[2],Text=[In this bullet, the @nt{aggregate} has to occur
4865 in the context of an @nt{allocator} or return statement, while the
4866 @nt{subtype_indication} of the previous bullet can occur anywhere
4867 (it doesn't have to be directly given in the @nt{allocator} or
4868 return statement).]}
4869 @end{Discussion}
4870
4871 @ChgRef{Version=[2],Kind=[Added]}
4872 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Just because the paragraph number is changed}
4873 @ChgAdded{Version=[2],Text=[In other cases, where the value of the access
4874 discriminant is determined by an object
4875 with an unconstrained nominal subtype, the accessibility level of the object.]}
4876
4877 @end{InnerItemize}
4878 @begin{Discussion}
4879 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
4880 @ChgAdded{Version=[2],Text=[In other words, if you know the value of the
4881 discriminant for an @nt{allocator} or return statement from a discriminant
4882 constraint or an @nt{aggregate} component
4883 association, then that determines the accessibility level; if you don't know
4884 it, then it is based on the object itself.]}
4885 @end{Discussion}
4886
4887 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4888 @ChgRef{Version=[3],Kind=[RevisedAdded]}@ChgNote{Just because the paragraph number is changed}
4889 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access
4890 type of an access discriminant in any other context is that of the
4891 enclosing object.]}
4892
4893 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00162-01],ARef=[AI95-00254-01]}
4894 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0270-1]}
4895 The accessibility level of
4896 the anonymous access type of an access
4897 parameter@Chg{Version=[2],New=[ specifying an access-to-object type],Old=[]}
4898 is the same as that of
4899 the view designated by the actual@Chg{Version=[3],New=[ (or library-level
4900 if the actual is null)],Old=[]}.@Chg{Version=[2],New=[],Old=[ If the
4901 actual is an @nt{allocator},
4902 this is the accessibility level of the execution of the called
4903 subprogram.]}
4904 @begin{Ramification}
4905 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
4906 @ChgAdded{Version=[3],Text=[If the value of the actual is derived from an
4907 Unchecked_Access attribute, the accessibility is always library-level (see
4908 @RefSecNum{Unchecked Access Value Creation}).]}
4909 @end{Ramification}
4910
4911
4912 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]}
4913 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access type
4914 of an access parameter specifying an access-to-subprogram type is
4915 deeper than that of any master; all such
4916 anonymous access types have this same level.]}
4917 @begin{Reason}
4918 @ChgRef{Version=[2],Kind=[AddedNormal]}
4919 @ChgAdded{Version=[2],Text=[@Defn{downward closure}
4920 @Defn2{Term=[closure],Sec=(downward)}
4921 These represent @lquotes@;downward closures@rquotes@; and
4922 thus require passing of static links or global display information (along
4923 with generic sharing information if the implementation does sharing) along
4924 with the address of the subprogram. We must prevent conversions of these to
4925 types with @lquotes@;normal@rquotes@; accessibility, as those typically don't
4926 include the extra information needed to make a call.]}
4927 @end{Reason}
4928
4929 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0070-1]}
4930 @ChgAdded{Version=[4],Text=[The accessibility level of the anonymous access
4931 subtype defined by a @nt{return_subtype_indication} that is
4932 an @nt{access_definition} (see @RefSecNum{Return Statements})
4933 is that of the result subtype of the enclosing function.]}
4934
4935 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1],ARef=[AI05-0240-1]}
4936 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0070-1]}@ChgNote{Just to reflect the paragraph number change}
4937 @ChgAdded{Version=[3],Text=[The accessibility level of the type of a stand-alone
4938 object of an anonymous access-to-object type is the same as the accessibility
4939 level of the type of the access value most recently assigned to the
4940 object@Redundant[; accessibility checks ensure that this
4941 is never deeper than that of the declaration of the stand-alone object].]}
4942
4943 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0240-1]}
4944 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0070-1]}@ChgNote{Just to reflect the paragraph number change}
4945 @ChgAdded{Version=[3],Text=[The accessibility level of an explicitly aliased
4946 (see @RefSecNum{Subprogram Declarations}) formal parameter in a function body is
4947 determined by the point of call; it is the same level that the return object
4948 ultimately will have.]}
4949
4950 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
4951 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0051-1],ARef=[AI05-0253-1]}
4952 @ChgNote{Use ChgAdded below to get conditional Leading}
4953 @ChgAdded{Version=[2],Type=[Leading],Text=[]}
4954 The accessibility level of an object created by an @nt{allocator}
4955 is the same as that of
4956 the access type@Chg{Version=[2],New=[, except for an @nt{allocator} of an
4957 anonymous access type @Chg{Version=[3],New=[(an @i<anonymous allocator>) in
4958 @Defn{anonymous allocator}certain contexts, as follows: For an anonymous
4959 allocator that defines the result of a function with an access result, the
4960 accessibility level is determined as though the @nt{allocator} were in place
4961 of the call of the function; in the special case of a call that is the operand of a
4962 type conversion, the level is that of the target access type of the
4963 conversion],Old=[that defines the value of an access parameter or an access
4964 discriminant]}. For an @Chg{Version=[3],New=[anonymous
4965 allocator],Old=[@nt{allocator}]} defining the value of an access parameter, the
4966 accessibility level is that of the innermost master of the call.
4967 @Chg{Version=[3],New=[For an anonymous allocator whose type is that of a
4968 stand-alone object of an anonymous access-to-object type, the accessibility
4969 level is that of the declaration of the stand-alone object. ],Old=[]}For one
4970 defining an access discriminant, the accessibility level is determined as
4971 follows:],Old=[.]}
4972
4973 @begin{InnerItemize}
4974
4975 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4976 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1]}
4977 @ChgAdded{Version=[2],Text=[for an @nt{allocator} used to define the
4978 @Chg{Version=[3],New=[discriminant of an object,
4979 the level of the object],Old=[constraint in a
4980 @nt{subtype_declaration}, the level of the @nt{subtype_declaration}]};]}
4981
4982 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4983 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1]}
4984 @ChgAdded{Version=[2],Text=[for an @nt{allocator} used to define the constraint
4985 in a @Chg{Version=[3],New=[@nt{subtype_indication} in any other context, the
4986 level of the master that elaborates the
4987 @nt{subtype_indication}.],Old=[@nt{component_definition}, the level of the
4988 enclosing type;]}]}
4989
4990 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4991 @ChgRef{Version=[3],Kind=[DeletedAdded],ARef=[AI05-0024-1]}
4992 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[for an @nt{allocator}
4993 used to define the discriminant of an object, the level of the object.]}]}
4994
4995 @end{InnerItemize}
4996
4997 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
4998 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0024-1],ARef=[AI05-0066-1]}
4999 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=[coextension],Sec=(of an object)}
5000 In @Chg{Version=[3],New=[the first],Old=[this last]} case, the allocated object
5001 is said to be a @i{coextension} of the object whose discriminant designates it,
5002 as well as of any object of which the discriminated object is itself a
5003 coextension or subcomponent.@Chg{Version=[3],New=[ If the allocated object is
5004 a coextension of an
5005 anonymous object representing the result of an aggregate or function
5006 call that is used (in its entirety) to directly initialize a part of
5007 an object, after the result is assigned, the coextension becomes a
5008 coextension of the object being initialized and is no longer
5009 considered a coextension of the anonymous object.],Old=[]}
5010 All coextensions of an object @Chg{Version=[3],New=[@Redundant[(which have not
5011 thus been transfered by such an initialization)] ],Old=[]}are finalized when
5012 the object is finalized (see @RefSecNum{Completion and Finalization}).]}
5013 @begin{Ramification}
5014 @ChgRef{Version=[2],Kind=[Added]}
5015 @ChgAdded{Version=[2],Text=[The rules of access discriminants are such that
5016 when the space for an object with a coextension is reclaimed, the space for
5017 the coextensions can be reclaimed. Hence, there is implementation advice (see
5018 13.11) that an object and its coextensions all be allocated from the same
5019 storage pool (or stack frame, in the case of a declared object).]}
5020 @end{Ramification}
5021
5022 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1]}
5023 @ChgAdded{Version=[3],Text=[Within a return statement, the accessibility level
5024 of the anonymous access type of an access result is that of the master of the
5025 call.]}
5026
5027 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0014-1]}
5028 The accessibility level of a view of an object or subprogram
5029 @Chg{Version=[3],New=[designated by],Old=[denoted by a dereference of]} an
5030 access value is the same as that of the access type.
5031 @begin{Discussion}
5032 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0014-1]}
5033 @ChgAdded{Version=[3],Text=[This rule applies even when no dereference exists,
5034 for example when an access value is passed as an access parameter.
5035 This rule ensures that implementations are not required to include dynamic
5036 accessibility values with all access values.]}
5037 @end{Discussion}
5038
5039 The accessibility level of
5040 a component, protected subprogram, or entry
5041 of (a view of) a composite object
5042 is the same as that of
5043 (the view of) the composite object.
5044 @end{Itemize}
5045
5046 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
5047 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0262-1]}
5048 @ChgAdded{Version=[2],Text=[In the above rules, the operand of a view
5049 conversion, parenthesized
5050 expression or @nt{qualified_expression} is considered to be used in a context
5051 if the view conversion, parenthesized expression or @nt{qualified_expression}
5052 itself is used in that context.@Chg{Version=[3],New=[
5053 Similarly, a @SynI{dependent_}@nt{expression} of a @nt{conditional_expression}
5054 is considered to be used in a context if the @nt{conditional_expression} itself
5055 is used in that context.],Old=[]}]}
5056
5057 @begin{WideAbove}
5058 @Leading@Defn{statically deeper}
5059 @Defn2{Term=[deeper],Sec=(statically)}
5060 One accessibility level is defined to be
5061 @i{statically deeper} than another in the following cases:
5062 @end{WideAbove}
5063 @begin{Itemize}
5064 For a master that is statically nested within another master,
5065 the accessibility level of the inner master is statically deeper than
5066 that of the outer master.
5067 @begin{Honest}
5068 Strictly speaking, this should talk about the @i{constructs}
5069 (such as @ntf{subprogram_bodies})
5070 being statically nested within one another;
5071 the masters are really the @i{executions} of those constructs.
5072 @end{Honest}
5073 @begin{Honest}
5074 If a given accessibility level is statically deeper than another,
5075 then each level defined to be the same as the given
5076 level is statically deeper than each level defined to be the same as
5077 the other level.
5078 @end{Honest}
5079
5080 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]}
5081 @ChgAdded{Version=[2],Text=[The accessibility level of the anonymous access type
5082 of an access parameter specifying an access-to-subprogram type is
5083 statically deeper than that of any master; all such
5084 anonymous access types have this same level.]}
5085 @begin{Ramification}
5086 @ChgRef{Version=[2],Kind=[AddedNormal]}
5087 @ChgAdded{Version=[2],Text=[This rule means that it is illegal to convert an
5088 access parameter specifying an access to subprogram to a
5089 named access to subprogram type, but it is allowed to pass such an access
5090 parameter to another access parameter (the implicit conversion's accessibility
5091 will succeed).]}
5092 @end{Ramification}
5093
5094 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
5095 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0082-1]}
5096 The statically deeper relationship does not apply to the accessibility
5097 level of the anonymous type of an access parameter@Chg{Version=[2],
5098 New=[ specifying an access-to-object type],Old=[]}@Chg{Version=[3],
5099 New=[ nor does it apply to a descendant of a generic formal type],Old=[]};
5100 that is, such an accessibility level is not considered to be statically
5101 deeper, nor statically shallower, than any other.
5102
5103 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5104 @ChgAdded{Version=[3],Text=[The statically deeper relationship does not apply to
5105 the accessibility level of the type of a stand-alone object of an anonymous
5106 access-to-object type; that is, such an accessibility level is not considered to
5107 be statically deeper, nor statically shallower, than any other.]}
5108
5109 @begin{Ramification}
5110 @ChgRef{Version=[3],Kind=[AddedNormal]}
5111 @ChgAdded{Version=[3],Text=[In these cases, we use dynamic accessibility
5112 checks.]}
5113 @end{Ramification}
5114
5115 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0235-1]}
5116 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0089-1],ARef=[AI12-0157-1]}
5117 @ChgAdded{Version=[3],Text=[Inside a return statement that applies to a function
5118 @Chg{Version=[4],New=[or generic function ],Old=[]}@i<F>,
5119 @Chg{Version=[4],New=[or the return expression of an expression function
5120 @i<F>, ],Old=[]}when determining
5121 whether the accessibility level of an explicitly aliased
5122 parameter of @i<F> is statically deeper than the level of the return object of
5123 @i<F>, the level of the return object is considered to be the same as that of
5124 the level of the explicitly aliased parameter; for statically comparing with the
5125 level of other entities, an explicitly aliased parameter of @i<F> is considered to
5126 have the accessibility level of the body of @i<F>.]}
5127
5128 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1],ARef=[AI05-0234-1],ARef=[AI05-0235-1]}
5129 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0089-1],ARef=[AI12-0157-1]}
5130 @ChgAdded{Version=[3],Text=[For determining whether a level is statically deeper
5131 than the level of the anonymous access type of an access result of a
5132 function@Chg{Version=[4],New=[ or generic function @i<F>],Old=[]},
5133 when within a return statement that applies to
5134 @Chg{Version=[4],New=[@i<F> or the return expression of expression
5135 function @i<F>],Old=[the function]}, the level
5136 of the master of the call is presumed to be the same as that of the level
5137 of the master that elaborated the@Chg{Version=[4],New=[],Old=[ function]}
5138 body@Chg{Version=[4],New=[ of @i<F>],Old=[]}.]}
5139
5140 @Chg{Version=[4],New=[ or generic function @i<F>],Old=[]}@begin{Honest}
5141 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0235-1]}
5142 @ChgAdded{Version=[3],Text=[This rule has no effect if the previous bullet
5143 also applies (that is, the @ldquote@;a level@rdquote is of
5144 an explicitly aliased parameter).]}
5145 @end{Honest}
5146
5147
5148
5149 @Redundant[For determining whether one level is statically deeper than another
5150 when within a generic package body, the generic package is presumed to be
5151 instantiated at the same level as where it was declared;
5152 run-time checks are needed in the case of more deeply nested instantiations.]
5153 @begin{TheProof}
5154 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0082-1]}
5155 @ChgAdded{Version=[3],Text=[A generic package does not introduce a new master,
5156 so it has the static level of its declaration; the rest follows from the
5157 other @ldquote@;statically deeper@rdquote rules.]}
5158 @end{TheProof}
5159
5160 For determining whether one level is statically deeper than another when
5161 within the declarative region of a @nt{type_declaration},
5162 the current instance of the type is presumed to be an object created at
5163 a deeper level than that of the type.
5164 @begin{Ramification}
5165 In other words, the rules are checked at compile time of the
5166 @nt{type_declaration}, in an assume-the-worst manner.
5167 @end{Ramification}
5168 @end{Itemize}
5169
5170 @Defn{library level}
5171 @Defn2{Term=[level],Sec=(library)}
5172 The accessibility level of all library units is called the
5173 @i{library level};
5174 a library-level declaration or entity is one whose accessibility level
5175 is the library level.
5176 @begin{Ramification}
5177 @nt{Library_unit_declaration}s are library level.
5178 Nested declarations are library level if they are nested only within
5179 packages (possibly more than one),
5180 and not within subprograms, tasks, etc.
5181 @end{Ramification}
5182 @begin{Honest}
5183 @ChgRef{Version=[2],Kind=[Revised]}
5184 @Leading@;The definition of the accessibility level of the anonymous type
5185 of an access parameter@Chg{Version=[2],New=[ specifying an access-to-object
5186 type],Old=[]} cheats a bit, since it refers to the view designated
5187 by the actual, but access values designate objects, not views of objects.
5188 What we really mean is the view that @lquotes@;would be@rquotes@; denoted by an
5189 expression @lquotes@;X.@key[all]@rquotes@;, where X is the actual, even though such
5190 an expression is a figment of our imagination.
5191 The definition is intended to be equivalent to the
5192 following more verbose version:
5193 The accessibility level of the anonymous type of an access parameter is
5194 as follows:
5195 @begin{Itemize}
5196 if the actual is
5197 an expression of a named access type @em
5198 the accessibility level of that type;
5199
5200 if the actual is
5201 an @nt{allocator} @em
5202 the accessibility level of the execution of the called
5203 subprogram;
5204
5205 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
5206 if the actual is
5207 a reference to the Access attribute @em
5208 the accessibility level of the view denoted by the @Chg{New=[@nt{prefix}],Old=[prefix]};
5209
5210 if the actual is
5211 a reference to the Unchecked_Access attribute @em
5212 library accessibility level;
5213
5214 if the actual is
5215 an access parameter @em
5216 the accessibility level of its type.
5217 @end{Itemize}
5218
5219 Note that the @nt{allocator} case is explicitly mentioned in the RM95,
5220 because otherwise the definition would be circular:
5221 the level of the anonymous type is that of the view designated by the
5222 actual, which is that of the access type.
5223 @end{Honest}
5224 @begin{Discussion}
5225 A deeper accessibility level implies a shorter maximum lifetime.
5226 Hence, when a rule requires X to have a level that is
5227 @lquotes@;not deeper than@rquotes@; Y's level,
5228 this requires that X has a lifetime at least as long as Y.
5229 (We say @lquotes@;maximum lifetime@rquotes@; here, because the accessibility
5230 level really represents an upper bound on the lifetime;
5231 an object created by an @nt{allocator} can have its lifetime
5232 prematurely ended by an instance of Unchecked_Deallocation.)
5233
5234 Package elaborations are not masters, and are therefore
5235 invisible to the accessibility rules:
5236 an object declared immediately within a package has the
5237 same accessibility level as an object declared immediately within the
5238 declarative region containing the package.
5239 This is true even in the body of a package;
5240 it jibes with the fact that objects declared in a
5241 @nt{package_body} live as long as objects declared
5242 outside the package,
5243 even though the body objects are not visible outside the package.
5244
5245 Note that the level of the @i{view} denoted by X.@key[all]
5246 can be different from the level of the @i{object} denoted by X.@key[all].
5247 The former is determined by the type of X;
5248 the latter is determined either by the type of the @nt{allocator},
5249 or by the master in which the object was declared.
5250 The former is used in several @LegalityTitle and run-time checks;
5251 the latter is used to define when X.@key[all] gets finalized.
5252 The level of a view reflects what we can conservatively @lquotes@;know@rquotes@;
5253 about the object of that view;
5254 for example, due to @nt{type_conversion}s,
5255 an access value might designate an object that was allocated by an
5256 @nt{allocator} for a different access type.
5257
5258 Similarly, the level of the view denoted by X.@key[all].Comp
5259 can be different from the level of the object denoted by X.@key[all].Comp.
5260
5261 If Y is statically deeper than X,
5262 this implies that Y will be (dynamically) deeper than X in all
5263 possible executions.
5264
5265 @Leading@;Most accessibility checking is done at compile time;
5266 the rules are stated in terms of @lquotes@;statically deeper than@rquotes@;.
5267 The exceptions are:
5268 @begin{Itemize}
5269 @ChgRef{Version=[2],Kind=[Revised]}
5270 Checks involving access parameters@Chg{Version=[2],New=[ of an
5271 access-to-object type],Old=[]}. The fact that @lquotes@;statically deeper
5272 than@rquotes@; is not defined for the anonymous access type of an access
5273 parameter implies that any rule saying @lquotes@;shall not be statically
5274 deeper than@rquotes@; does not apply to such a type, nor to anything defined
5275 to have @lquotes@;the same@rquotes@; level as such a type.
5276
5277 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0082-1]}
5278 @ChgAdded{Version=[3],Text=[Checks involving generic formal types
5279 and their descendants. This is because the actual type can be more
5280 or less deeply nested than the generic unit. Note that this only
5281 applies to the generic unit itself, and not to the instance. Any
5282 static checks needed in the instance will be performed. Any other
5283 checks (such as those in the generic body) will require a run-time
5284 check of some sort (although implementations that macro-expand
5285 generics can determine the result of the check when the generic
5286 is expanded).]}
5287
5288 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0082-1]}
5289 Checks involving @Chg{Version=[3],New=[other ],Old=[]}entities and
5290 views within generic packages. This is because an instantiation can
5291 be at a level that is more deeply nested than the generic package itself.
5292 In implementations that use a macro-expansion model of generics,
5293 these violations can be detected at macro-expansion time.
5294 For implementations that share generics,
5295 run-time code is needed to detect the error.
5296
5297 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01],ARef=[AI95-00416-01]}
5298 Checks during function return@Chg{Version=[2],New=[ and @nt{allocator}s,
5299 for nested type extensions and access discriminants],Old=[]}.
5300 @end{Itemize}
5301
5302 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
5303 Note that run-time checks are not required
5304 for access discriminants@Chg{Version=[3],New=[ (except during
5305 function returns and @nt{allocator}s)],Old=[]}, because their accessibility is
5306 determined statically by the accessibility level of the enclosing object.
5307
5308 @ChgRef{Version=[2],Kind=[Revised]}
5309 @Chg{Version=[2],New=[],Old=[This ]}The accessibility level of the result
5310 object of a function reflects
5311 the time when that object will be finalized;
5312 we don't allow pointers to the object to survive beyond that time.
5313
5314 We sometimes use the terms @lquotes@;accessible@rquotes@;
5315 and @lquotes@;inaccessible@rquotes@; to mean that something has an
5316 accessibility level that is not deeper, or deeper,
5317 respectively, than something else.
5318 @end{Discussion}
5319 @begin(ImplNote)
5320 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01],ARef=[AI95-00416-01]}
5321 If an accessibility @LegalityName is satisfied,
5322 then the corresponding run-time check (if any)
5323 cannot fail (and a reasonable implementation will not
5324 generate any checking code)
5325 unless @Chg{Version=[2],New=[one of the cases requiring run-time checks mentioned
5326 previously is],Old=[access parameters or shared generic bodies are]} involved.
5327
5328 Accessibility levels are defined in terms of the relations
5329 @lquotes@;the same as@rquotes@; and @lquotes@;deeper than@rquotes@;.
5330 To make the discussion more concrete,
5331 we can assign actual numbers to each level.
5332 Here, we assume that library-level accessibility is level 0,
5333 and each level defined as @lquotes@;deeper than@rquotes@; is one level deeper.
5334 Thus, a subprogram directly called from the environment task
5335 (such as the main subprogram) would be at level 1,
5336 and so on.
5337
5338 @ChgRef{Version=[2],Kind=[Revised]}
5339 Accessibility is not enforced at compile time for access
5340 parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}.
5341 The @lquotes@;obvious@rquotes@; implementation of the run-time checks would be
5342 inefficient, and would involve distributed overhead;
5343 therefore, an efficient method is given below.
5344 The @lquotes@;obvious@rquotes@; implementation would be to pass
5345 the level of the caller at each subprogram call,
5346 task creation, etc.
5347 This level would be incremented by 1 for each
5348 dynamically nested master.
5349 An Accessibility_Check would be implemented as a simple
5350 comparison @em checking that X is not deeper than Y
5351 would involve checking that X <= Y.
5352
5353 A more efficient method is based on passing @i{static}
5354 nesting levels
5355 (within constructs that correspond at run time to
5356 masters @em packages don't count).
5357 Whenever an access parameter is passed,
5358 an implicit extra parameter is passed with it.
5359 The extra parameter represents (in an indirect way)
5360 the accessibility level of the anonymous access type,
5361 and, therefore, the level of the view denoted
5362 by a dereference of the access parameter.
5363 This is analogous to the implicit @lquotes@;Constrained@rquotes@; bit associated
5364 with certain formal parameters of an unconstrained but definite
5365 composite subtype.
5366 In this method, we avoid distributed overhead:
5367 it is not necessary to pass any extra information
5368 to subprograms that have no access parameters.
5369 For anything other than an access parameter and its anonymous type,
5370 the static nesting level is known at compile time,
5371 and is defined analogously to the RM95 definition
5372 of accessibility level (e.g. derived access types
5373 get their nesting level from their parent).
5374 Checking @lquotes@;not deeper than@rquotes@; is a "<=" test on the levels.
5375
5376 @ChgRef{Version=[2],Kind=[Revised]}
5377 @Leading@keepnext@;For each access parameter@Chg{Version=[2],New=[ of
5378 an access-to-object type],Old=[]}, the static depth passed depends on the
5379 actual, as follows:
5380 @begin{Itemize}
5381 If the actual is
5382 an expression of a named access type,
5383 pass the static nesting level of that type.
5384
5385 If the actual is
5386 an @nt{allocator},
5387 pass the static nesting level of the caller,
5388 plus one.
5389
5390 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
5391 If the actual is
5392 a reference to the Access attribute,
5393 pass the level of the view denoted by the @Chg{New=[@nt{prefix}],Old=[prefix]}.
5394
5395 If the actual is
5396 a reference to the Unchecked_Access attribute,
5397 pass 0 (the library accessibility level).
5398
5399 @ChgRef{Version=[2],Kind=[Revised]}
5400 If the actual is an access parameter@Chg{Version=[2],New=[ of
5401 an access-to-object type],Old=[]},
5402 usually just pass along the level passed in.
5403 However, if the
5404 static nesting level of the formal (access) parameter is greater than
5405 the static nesting level of the actual (access) parameter,
5406 the level to
5407 be passed is the minimum of the static nesting level
5408 of the access parameter
5409 and the actual level passed in.
5410 @end{Itemize}
5411
5412 @ChgRef{Version=[2],Kind=[Revised]}
5413 For the Accessibility_Check associated with a @nt{type_conversion}
5414 of an access parameter@Chg{Version=[2],New=[ of
5415 an access-to-object type],Old=[]} of a given subprogram to a
5416 named access type,
5417 if the target type is statically nested within the subprogram,
5418 do nothing; the check can't fail in this case.
5419 Otherwise, check that the value passed in is <= the static
5420 nesting depth of the target type.
5421 The other Accessibility_Checks are handled in a similar manner.
5422
5423 This method, using statically known values most of the time,
5424 is efficient, and, more importantly, avoids distributed overhead.
5425
5426 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5427 @ChgAdded{Version=[3],Text=[The implementation of accessibility checks for
5428 stand-alone objects of anonymous access-to-object types can be similar to
5429 that for anonymous access-to-object parameters. A static level suffices; it
5430 can be calculated using rules similar to those previously described for access
5431 parameters.]}
5432
5433 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5434 @ChgAdded{Version=[3],Text=[One important difference between the stand-alone
5435 access variables and access parameters is that one can assign a local access
5436 parameter to a more global stand-alone access variable. Similarly, one can
5437 assign a more global access parameter to a more local stand-alone access
5438 variable.]}
5439
5440 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0148-1]}
5441 @ChgAdded{Version=[3],Text=[For these cases, it is important to note that the
5442 @ldquote@;correct@rdquote static accessibility level for an access parameter
5443 assigned to a stand-alone access object is the minimum of the passed in
5444 level and the static accessibility level of the stand-alone object itself.
5445 This is true since the static accessibility level passed in might be deeper
5446 than that of the stand-alone object, but the dynamic accessibility of the
5447 passed in object clearly must be shallower than the stand-alone object
5448 (whatever is passed in must live at least as long as the subprogram call). We
5449 do not need to keep a more local static level as accesses to objects
5450 statically deeper than the stand-alone object cannot be stored into the
5451 stand-alone object.]}
5452 @end(ImplNote)
5453 @begin{Discussion}
5454 @Leading@keepnext@;Examples of accessibility:
5455 @begin{Example}
5456 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}@Comment{A1 is access-to-variable, X better be a variable}
5457 @key[package] @key[body] Lib_Unit @key[is]
5458 @key[type] T @key[is] @key[tagged] ...;
5459 @key[type] A0 @key[is] @key[access] @key[all] T;
5460 Global: A0 := ...;
5461 @key[procedure] P(X: @Chg{Version=[3],New=[@key[in out] ],Old=[]}T) @key[is]
5462 Y: @key[aliased] T;
5463 @key[type] A1 @key[is] @key[access] @key[all] T;
5464 Ptr0: A0 := Global; --@RI{ OK.}
5465 Ptr1: A1 := X'Access; --@RI{ OK.}
5466 @key[begin]
5467 Ptr1 := Y'Access; --@RI{ OK;}
5468 Ptr0 := A0(Ptr1); --@RI{ Illegal type conversion!}
5469 Ptr0 := X'Access; --@RI{ Illegal reference to Access attribute!}
5470 Ptr0 := Y'Access; --@RI{ Illegal reference to Access attribute!}
5471 Global := Ptr0; --@RI{ OK.}
5472 @key[end] P;
5473 @key[end] Lib_Unit;
5474 @end{Example}
5475
5476 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
5477 The above illegal statements are illegal because the accessibility
5478 @Chg{Version=[3],New=[levels],Old=[level]} of X and Y are statically deeper
5479 than the accessibility level of A0.
5480 In every possible execution of any program including this library
5481 unit, if P is called, the accessibility level of X will be
5482 (dynamically) deeper than that of A0.
5483 Note that the accessibility levels of X and Y are the same.
5484
5485 @ChgRef{Version=[2],Kind=[Revised]}
5486 @Leading@keepnext@;Here's an example involving access
5487 parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}:
5488 @begin{Example}
5489 @key[procedure] Main @key[is]
5490 @key[type] Level_1_Type @key[is] @key[access] @key[all] Integer;
5491
5492 @key[procedure] P(X: @key[access] Integer) @key[is]
5493 @key[type] Nested_Type @key[is] @key[access] @key[all] Integer;
5494 @key[begin]
5495 ... Nested_Type(X) ... --@RI{ (1)}
5496 ... Level_1_Type(X) ... --@RI{ (2)}
5497 @key[end] P;
5498
5499 @key[procedure] Q(X: @key[access] Integer) @key[is]
5500 @key[procedure] Nested(X: @key[access] Integer) @key[is]
5501 @key[begin]
5502 P(X);
5503 @key[end] Nested;
5504 @key[begin]
5505 Nested(X);
5506 @key[end] Q;
5507
5508 @key[procedure] R @key[is]
5509 Level_2: @key[aliased] Integer;
5510 @key[begin]
5511 Q(Level_2'Access); --@RI{ (3)}
5512 @key[end] R;
5513
5514 Level_1: @key[aliased] Integer;
5515 @key[begin]
5516 Q(Level_1'Access); --@RI{ (4)}
5517 R;
5518 @key[end] Main;
5519 @end{Example}
5520
5521 The run-time Accessibility_Check at (1) can never fail,
5522 and no code should be generated to check it.
5523 The check at (2) will fail when called from (3),
5524 but not when called from (4).
5525
5526 @Leading@;Within a @nt{type_declaration}, the rules are checked in an
5527 assume-the-worst manner.
5528 For example:
5529 @begin{Example}
5530 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0298-1]}
5531 @key[package] P @key[is]
5532 @key[type] Int_Ptr @key[is] @key[access] @key[all] Integer;
5533 @key[type] Rec(D: @key[access] Integer) @key[is] @key[limited] @key[private];
5534 @key[private]
5535 @key[type] Rec_Ptr @key[is] @key[access] @key[all] Rec;
5536 @key[function] F(X: Rec_Ptr) @key[return] Boolean;
5537 @key[function] G(X: @key[access] Rec) @key[return] Boolean;
5538 @key[type] Rec(D: @key[access] Integer) @key[is]
5539 @Chg{Version=[3],New=[@key[limited] ],Old=[]}@key[record]
5540 C1: Int_Ptr := Int_Ptr(D); --@RI{ Illegal!}
5541 C2: Rec_Ptr := Rec'Access; --@RI{ Illegal!}
5542 C3: Boolean := F(Rec'Access); --@RI{ Illegal!}
5543 C4: Boolean := G(Rec'Access);
5544 @key[end] @key[record];
5545 @key[end] P;
5546 @end{Example}
5547
5548 C1, C2, and C3 are all illegal, because one might declare an object of
5549 type Rec at a more deeply nested place than the declaration of the type.
5550 C4 is legal, but the accessibility level of the object will be passed to
5551 function G, and constraint checks within G will prevent it from
5552 doing any evil deeds.
5553
5554 Note that we cannot defer the checks on C1, C2, and C3 until
5555 compile-time of the object creation, because that would cause violation
5556 of the privacy of private parts.
5557 Furthermore, the problems might occur within a task or protected body,
5558 which the compiler can't see while compiling an object creation.
5559 @end{Discussion}
5560
5561 @begin{WideAbove}
5562 @Leading@;The following attribute is defined for @PrefixType{a @nt{prefix} X that
5563 denotes an aliased view of an object}:
5564 @end{WideAbove}
5565 @begin(description)
5566 @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
5567 Prefix=<X>, AttrName=<Access>, Ref=[8652/0010], ARef=[AI95-00127-01],
5568 Text=<X'Access yields an access value that designates the object
5569 denoted by X. The type of X'Access is an access-to-object type,
5570 as determined by the expected type.
5571 The expected type shall be a general access type.>}
5572 @IndexSeeAlso{Term=[Unchecked_Access attribute],See=(Access attribute)}
5573 @EndPrefixType{}
5574 X shall denote an aliased view of an object@Redundant[, including possibly the
5575 current instance (see @RefSecNum{The Context of Overload Resolution})
5576 of a limited type within its definition, or a formal parameter
5577 or generic formal object of a tagged type].
5578 The view denoted by the @nt<prefix> X
5579 shall satisfy the following additional requirements, presuming the
5580 expected type for X'Access is the general access type
5581 @i(A)@Chg{New=[ with designated type @i(D)],Old=[]}:
5582 @begin(itemize)
5583 If @i(A) is an access-to-variable type, then the view shall be a
5584 variable; @Redundant[on the other hand, if @i(A) is an
5585 access-to-constant type, the view may be either a constant
5586 or a variable.]
5587 @begin{Discussion}
5588 The current instance of a limited type
5589 is considered a variable.
5590 @end{discussion}
5591
5592 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
5593 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0008-1],ARef=[AI05-0041-1]}
5594 The view shall not be a subcomponent that
5595 depends on discriminants of @Chg{Version=[3],New=[an object unless
5596 the object is known to be constrained],Old=[a
5597 variable whose nominal subtype is unconstrained,
5598 unless this subtype is indefinite,
5599 or the variable is @Chg{Version=[2],New=[constrained by its initial value],
5600 Old=[aliased]}]}.
5601
5602 @begin(Discussion)
5603 @comment{The following is a "fix" to keep consistent with v. 5.95;
5604 appearently 6.0 is different.
5605 @ChgRef{Version=[1],Kind=[Deleted]}
5606 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}}
5607
5608 This restriction is intended to be similar to the restriction
5609 on renaming discriminant-dependent subcomponents.
5610 @end{Discussion}
5611 @begin{Reason}
5612 This prevents references to subcomponents that might
5613 disappear or move or change constraints after creating the reference.
5614 @end{Reason}
5615 @begin{ImplNote}
5616 @Leading@;There was some thought to making this restriction
5617 more stringent, roughly:
5618 "X shall not denote a subcomponent of a variable
5619 with discriminant-dependent subcomponents, if the nominal
5620 subtype of the variable is an unconstrained definite subtype."
5621 This was because in some implementations, it is not
5622 just the discriminant-dependent subcomponents that might
5623 move as the result of an assignment that changed the discriminants
5624 of the enclosing object. However, it was decided not to make
5625 this change because a reasonable implementation strategy was identified
5626 to avoid such problems, as follows:
5627 @begin(Itemize)
5628 Place non-discriminant-dependent components with any aliased parts
5629 at offsets preceding any discriminant-dependent components
5630 in a discriminated record type with defaulted discriminants.
5631
5632 Preallocate the maximum space for unconstrained discriminated
5633 variables with aliased subcomponents, rather than allocating
5634 the initial size and moving them to a larger (heap-resident)
5635 place if they grow as the result of an assignment.
5636 @end(Itemize)
5637
5638 Note that for objects of a by-reference type, it is not an error
5639 for a programmer to take advantage of the fact that such objects
5640 are passed by reference. Therefore, the above approach is also
5641 necessary for discriminated record types with components of
5642 a by-reference type.
5643
5644 To make the above strategy work, it is important that
5645 a component of a derived type is defined to be
5646 discriminant-dependent if it is inherited and the parent subtype
5647 constraint is defined in terms of a discriminant of the derived type
5648 (see @RefSecNum(Discriminants)).
5649 @end{ImplNote}
5650
5651 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0010],ARef=[AI95-00127-01]}
5652 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
5653 If @Chg{New=[@i(A) is a named access type and @i(D) is a tagged type],
5654 Old=[the designated type of @i(A) is tagged]}, then the type of the view
5655 shall be covered by @Chg{New=[@i(D)],Old=[the designated type]};
5656 @Chg{New=[if @i(A) is anonymous and @i(D) is tagged, then the type of the
5657 view shall be either @i(D)'Class or a type covered by
5658 @Chg{Version=[2],New=[@i<D>],Old=[D]};],Old=[]}
5659 if @Chg{New=[@i(D) is untagged],Old=[@i(A)'s designated type is not tagged]},
5660 then the type of the view shall be
5661 @Chg{New=[@i(D)],Old=[the same]},
5662 and @Chg{Version=[2],New=[either:],Old=[@Chg{New=[],Old=[either ]}@i(A)'s
5663 designated subtype shall @Chg{New=[either ],Old=[]}
5664 statically match the nominal subtype of the view@Chg{New=[ or be],
5665 Old=[, or the designated subtype shall be]} discriminated
5666 and unconstrained;
5667 @PDefn2{Term=[statically matching],Sec=(required)}]}
5668 @begin{InnerItemize}
5669 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
5670 @ChgAdded{Version=[2],Text=[the designated subtype of @i{A} shall statically
5671 match the nominal subtype of the view;
5672 or@PDefn2{Term=[statically matching],Sec=(required)}]}
5673
5674 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
5675 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0041-1]}
5676 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0095-1]}
5677 @ChgAdded{Version=[2],Text=[@i{D} shall be discriminated in its full view
5678 and unconstrained in any partial view, and the designated subtype of
5679 @i{A} shall be unconstrained.@Chg{Version=[3],New=[@Chg{Version=[4],New=[],
5680 Old=[ For the purposes
5681 of determining within a generic body whether @i{D} is unconstrained
5682 in any partial view, a discriminated subtype is
5683 considered to have a constrained partial view if it is a descendant
5684 of an untagged generic formal private or derived type.]}],Old=[]}]}
5685 @end{InnerItemize}
5686 @begin{ImplNote}
5687 This ensures
5688 that the dope for an aliased array object can always be stored contiguous
5689 with it, but need not be if its nominal subtype is constrained.
5690 @end{implnote}
5691 @begin{Ramification}
5692 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0010],ARef=[AI95-00127-01]}
5693 @Chg{New=[An access attribute can be used as the controlling operand in a
5694 dispatching call; see @RefSecNum{Dispatching Operations of Tagged Types}.],
5695 Old=[]}
5696
5697 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00363-01]}
5698 @Chg{Version=[2],New=[This does not require that types have a partial view
5699 in order to allow an access attribute of an unconstrained discriminated
5700 object, only that any partial view that does exist is unconstrained.],Old=[]}
5701 @end{Ramification}
5702
5703 @begin{Discussion}
5704 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]}
5705 @ChgAdded{Version=[4],Text=[We assume the worst in a generic body whether
5706 or not a formal subtype has a constrained partial view; specifically, in a
5707 generic body a discriminated subtype is considered to have a constrained
5708 partial view if it is a descendant of an untagged generic formal private
5709 or derived type (see @RefSecNum{Formal Private and Derived Types} for the
5710 formal definition of this rule).]}
5711 @end{Discussion}
5712
5713 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0041-1]}
5714 The accessibility level of the view shall not be statically deeper
5715 than that of the access type @i{A}.@Chg{Version=[3],New=[],Old=[
5716 In addition to the places where @LegalityTitle normally apply
5717 (see @RefSecNum{Generic Instantiation}),
5718 this rule applies also in the private part of an
5719 instance of a generic unit.@PDefn{generic contract issue}]}
5720 @PDefn2{Term=[accessibility rule],Sec=(Access attribute)}
5721 @begin(Ramification)
5722 In an instance body, a run-time check applies.
5723
5724 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
5725 If @i(A) is an anonymous@Chg{Version=[2],New=[ access-to-object type of
5726 an access parameter],Old=[access type]}, then the view can never have a
5727 deeper accessibility level than @i(A)@Chg{Version=[2],New=[. The same is
5728 true for an anonymous access-to-object type of an access
5729 discriminant],Old=[]}, except when X'Access is used to initialize
5730 an access discriminant of an object created by an @nt<allocator>.
5731 The latter case is illegal if the accessibility level of X
5732 is statically deeper than that of the access type of the
5733 @nt<allocator>; a run-time check is needed in the case where the
5734 initial value comes from an access parameter.@Chg{Version=[2],New=[ Other
5735 anonymous access-to-object types have "normal" accessibility checks.],Old=[]}
5736 @end(Ramification)
5737 @end(itemize)
5738
5739 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0041-1]}
5740 @ChgAdded{Version=[3],NoPrefix=[T],Text=[In addition to the places where
5741 @LegalityTitle normally apply
5742 (see @RefSecNum{Generic Instantiation}), these requirements apply
5743 also in the private part of an instance of a generic
5744 unit.@PDefn{generic contract issue}]}
5745
5746 @NoPrefix@IndexCheck{Accessibility_Check}
5747 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
5748 A check is made that the accessibility level of X is not
5749 deeper than that of the access type @i(A).
5750 If this check fails, Program_Error is raised.
5751 @begin{Ramification}
5752 @ChgRef{Version=[2],Kind=[Revised]}
5753 The check is needed for access parameters @Chg{Version=[2],New=[ of
5754 an access-to-object type],Old=[]} and in instance bodies.
5755
5756 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0024-1]}
5757 @ChgAdded{Version=[3],Text=[Because there are no access parameters permitted for task
5758 entries, the accessibility levels are always comparable. We would have to
5759 switch to the terminology used in @RefSecNum{Allocators} and
5760 @RefSecNum{Return Statements} based on inclusion within
5761 masters if we relax this restriction. That might introduce unacceptable
5762 distributed overhead.]}
5763 @end{Ramification}
5764 @begin(ImplNote)
5765 @ChgRef{Version=[2],Kind=[Revised]}
5766 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0148-1]}
5767 This check requires that some indication of lifetime is
5768 passed as an implicit parameter along with access parameters@Chg{Version=[2],
5769 New=[ of an access-to-object type],Old=[]}.@Chg{Version=[3],New=[ A similar
5770 indication is required for stand-alone objects of anonymous access-to-object
5771 types.],Old=[]}No such requirement applies to @Chg{Version=[2],New=[other
5772 anonymous access types],Old=[access discriminants]}, since
5773 the checks associated with them are all compile-time checks.
5774 @end(ImplNote)
5775
5776 @NoPrefix@PDefn2{Term=[implicit subtype conversion],Sec=(Access attribute)}
5777 If the nominal subtype of X does not statically match the designated
5778 subtype of @i(A), a view conversion of X to the designated subtype
5779 is evaluated (which might raise Constraint_Error @em
5780 see @RefSecNum(Type Conversions))
5781 and the value of X'Access designates that view.
5782 @end(description)
5783
5784 The following attribute is defined for @PrefixType{a @nt{prefix} P that
5785 denotes a subprogram}:
5786 @begin(description)
5787 @ChgAttribute{Version=[3],Kind=[Revised],ChginAnnex=[F], Leading=[F],
5788 Prefix=<P>, AttrName=<Access>,ARef=[AI95-00229-01], ARef=[AI95-00254-01],ARef=[AI05-0239-1],
5789 Text=<P'Access yields an access value that designates the subprogram
5790 denoted by P.
5791 The type of P'Access is an access-to-subprogram type (@i(S)),
5792 as determined by the expected type.>}
5793 @EndPrefixType{}
5794 @PDefn2{Term=[accessibility rule],Sec=(Access attribute)}
5795 The accessibility level of P shall not be statically deeper than
5796 that of @i{S}.
5797 @PDefn{generic contract issue}
5798 In addition to the places where @LegalityTitle normally apply
5799 (see @RefSecNum{Generic Instantiation}),
5800 this rule applies also in the private part of an
5801 instance of a generic unit.
5802 The profile of P
5803 shall be @Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]}
5804 with the designated profile of @i(S),
5805 and shall not be Intrinsic.
5806 @Defn2{Term=[subtype conformance],Sec=(required)}
5807 If the subprogram denoted by P is declared within a
5808 generic @Chg{Version=[2],New=[unit, and the expression P'Access occurs within
5809 the body of that generic unit or within the body of a generic unit declared
5810 within the declarative region of the generic unit, then the ultimate ancestor
5811 of @i{S} shall be either a nonformal type declared within the generic unit
5812 or an anonymous access type of an access parameter.],
5813 Old=[body, @i{S} shall be declared within the generic body.]}
5814
5815 @begin(Discussion)
5816 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00229-01]}
5817 The part about generic bodies is worded in terms of the denoted
5818 subprogram, not the denoted view; this implies that renaming is
5819 invisible to this part of the
5820 rule.@Chg{Version=[2],New=[ @lquotes@;Declared within the declarative region of
5821 the generic@rquotes@; is referring to child and nested generic
5822 units.],Old=[]} This rule is partly to prevent contract model problems
5823 with respect to the accessibility rules,
5824 and partly to ease shared-generic-body implementations,
5825 in which a subprogram declared in an instance needs to have a
5826 different calling convention from other subprograms with the same
5827 profile.
5828
5829 @Comment{The change is from AI05-0239-1, just punctuation}
5830 Overload resolution ensures only that the profile
5831 is @Chg{Version=[3],New=[type conformant],Old=[type-conformant]}.
5832 This rule specifies that subtype conformance is required (which also
5833 requires matching calling conventions).
5834 P cannot denote an entry because access-to-subprogram types
5835 never have the @i(entry) calling convention. P cannot denote
5836 an enumeration literal or an attribute function because
5837 these have intrinsic calling conventions.
5838 @end(Discussion)
5839 @end(description)
5840
5841 @end{StaticSem}
5842
5843 @begin{Legality}
5844 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
5845 @ChgAdded{Version=[3],Type=[Leading],Text=[An @nt{expression} is said to have
5846 @i{distributed accessibility} if it
5847 is@Defn{distributed accessibility}@Defn2{Term=[accessibility],Sec=[distributed]}]}
5848
5849 @begin{Itemize}
5850 @ChgRef{Version=[3],Kind=[Added]}
5851 @ChgAdded{Version=[3],Text=[a @nt{conditional_expression} (see
5852 @RefSecNum{Conditional Expressions}); or]}
5853
5854 @ChgRef{Version=[3],Kind=[Added]}
5855 @ChgAdded{Version=[3],Text=[a view conversion, @nt{qualified_expression},
5856 or parenthesized expression whose operand has distributed accessibility.]}
5857 @end{Itemize}
5858
5859 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
5860 @ChgAdded{Version=[3],Text=[The statically deeper relationship does not apply to
5861 the accessibility level of an @nt{expression} having distributed accessibility;
5862 that is, such an accessibility level is not considered to be statically deeper,
5863 nor statically shallower, than any other.]}
5864
5865 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0188-1]}
5866 @ChgAdded{Version=[3],Text=[Any static accessibility requirement that is imposed
5867 on an @nt{expression} that has distributed accessibility (or on its type) is
5868 instead imposed on the @SynI{dependent_}@nt{expression}s of the underlying
5869 @nt{conditional_expression}. This rule is applied recursively if a
5870 @SynI{dependent_}@nt{expression} also has distributed accessibility.]}
5871
5872 @begin{Discussion}
5873 @ChgRef{Version=[3],Kind=[AddedNormal]}
5874 @ChgAdded{Version=[3],Text=[This means that any @LegalityName requiring that
5875 the accessibility level of an @nt{expression} (or that of the type of an
5876 @nt{expression}) shall or shall not be statically deeper than some other level
5877 also applies, in the case where the @nt{expression} has distributed
5878 accessibility, to each @SynI{dependent_}@nt{expression} of the underlying
5879 @nt{conditional_expression}.]}
5880 @end{Discussion}
5881
5882 @end{Legality}
5883
5884 @begin{Notes}
5885 The Unchecked_Access attribute yields the same result as the Access
5886 attribute for objects, but has fewer restrictions
5887 (see @RefSecNum{Unchecked Access Value Creation}).
5888 There are other predefined operations that yield access values:
5889 an @nt<allocator> can be used to create an object, and return an
5890 access value that designates it (see @RefSecNum(Allocators));
5891 evaluating the literal @key(null) yields a null access value that designates
5892 no entity at all (see @RefSecNum(Literals)).
5893
5894 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
5895 @PDefn2{Term=[predefined operations],Sec=(of an access type)}
5896 The predefined operations of an access type also include
5897 the assignment operation, qualification, and membership tests.
5898 Explicit conversion is allowed between general access types with
5899 matching designated subtypes; explicit conversion is allowed
5900 between access-to-subprogram types with subtype conformant profiles
5901 (see @RefSecNum{Type Conversions}).
5902 @PDefn{subtype conformance}
5903 Named access types have predefined equality operators;
5904 anonymous access types do not@Chg{Version=[2],New=[, but they can use the
5905 predefined equality operators for @i<universal_access> ],Old=[]}(see
5906 @RefSecNum{Relational Operators and Membership Tests}).
5907 @begin(Reason)
5908 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
5909 @Chg{Version=[2],New=[Anonymous access types can use the universal access
5910 equality operators declared in Standard, while named access types cannot
5911 for compatibility reasons. ],Old=[]}By not
5912 having equality operators for anonymous access types,
5913 we eliminate the need to specify exactly where the
5914 predefined operators for anonymous access types would be defined, as
5915 well as the need for an implementer to insert an implicit
5916 declaration for "=", etc. at the appropriate place in their symbol table.
5917 Note that @Chg{Version=[2],New=[":=", ],Old=[]}'Access@Chg{Version=[2],New=[,],Old=[]} and
5918 ".@key[all]" are defined@Chg{Version=[2],New=[],Old=[, and ":=" is defined
5919 though useless since all instances are constant. The literal
5920 @key(null) is also defined for the
5921 purposes of overload resolution, but is disallowed by a @LegalityTitle
5922 of this subclause]}.
5923 @end(Reason)
5924
5925 The object or subprogram designated by an access value can be named
5926 with a dereference, either an @nt<explicit_@!dereference> or an
5927 @nt<implicit_dereference>. See @RefSecNum{Names}.
5928
5929 A call through the dereference of an access-to-subprogram
5930 value is never a dispatching call.
5931 @begin{TheProof}
5932 See @RefSecNum{Dispatching Operations of Tagged Types}.
5933 @end{TheProof}
5934
5935 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
5936 @Defn{downward closure}
5937 @Defn2{Term=[closure],Sec=(downward)}
5938 @Chg{Version=[2],New=[The],Old=[The accessibility rules imply that it
5939 is not possible to use the]} Access
5940 attribute@Chg{Version=[2],New=[ for subprograms and parameters of an
5941 anonymous access-to-subprogram type may together be used],Old=[]}
5942 to implement @lquotes@;downward closures@rquotes@; @em that is,
5943 to pass a more-nested subprogram as a parameter to a
5944 less-nested subprogram, as might be @Chg{Version=[2],
5945 New=[appropriate],Old=[desired for example]} for an
5946 iterator abstraction@Chg{Version=[2],New=[ or numerical integration.
5947 Downward],Old=[. Instead, downward]}
5948 closures can @Chg{Version=[2],New=[also ],Old=[]}be implemented using
5949 generic formal subprograms (see @RefSecNum{Formal Subprograms}).
5950 Note that Unchecked_Access is not allowed for subprograms.
5951
5952 Note that using
5953 an access-to-class-wide tagged type with a dispatching operation
5954 is a potentially more structured alternative to using an
5955 access-to-subprogram type.
5956
5957 An implementation may consider
5958 two access-to-subprogram values to be unequal,
5959 even though they designate the same subprogram. This might
5960 be because one points directly to the subprogram,
5961 while the other points to a special prologue that
5962 performs an Elaboration_Check and then jumps to the subprogram.
5963 See @RefSecNum(Relational Operators and Membership Tests).
5964 @begin{Ramification}
5965
5966 If equality of
5967 access-to-subprogram values is important to the logic
5968 of a program, a reference to the Access attribute of a subprogram
5969 should be evaluated only once
5970 and stored in a global constant for subsequent use and equality
5971 comparison.@end{ramification}
5972 @end{Notes}
5973
5974 @begin{Examples}
5975 @Leading@keepnext@i{Example of use of the Access attribute:}
5976 @begin{Example}
5977 Martha : Person_Name := @key[new] Person(F); --@RI[ see @RefSecNum{Incomplete Type Declarations}]
5978 Cars : @key[array] (1..2) @key[of] @key[aliased] Car;
5979 ...
5980 Martha.Vehicle := Cars(1)'Access;
5981 George.Vehicle := Cars(2)'Access;
5982 @end{Example}
5983 @end{Examples}
5984
5985 @begin{Extend83}
5986 @Defn{extensions to Ada 83}
5987 We no longer make things like 'Last and ".component"
5988 (basic) operations of an access type that need to be "declared"
5989 somewhere. Instead, implicit dereference
5990 in a @nt{prefix} takes care of them all. This means that
5991 there should never be a case when X.@key{all}'Last is legal
5992 while X'Last is not. See AI83-00154.
5993 @end{Extend83}
5994
5995 @begin{Incompatible95}
5996 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
5997 @Chg{Version=[2],New=[@Leading@;@Defn{incompatibilities with Ada 95} Aliased
5998 variables are not necessarily constrained in Ada 2005 (see
5999 @RefSecNum{Array Types}). Therefore, a subcomponent of an aliased variable
6000 may disappear or change shape, and taking 'Access of such a subcomponent
6001 thus is illegal, while the same operation would have been legal in Ada 95.
6002 Note that most allocated objects are
6003 still constrained by their initial value (see @RefSecNum{Allocators}), and thus
6004 legality of 'Access didn't change for them. For example:],Old=[]}
6005 @begin{Example}
6006 @ChgRef{Version=[2],Kind=[AddedNormal]}
6007 @Chg{Version=[2],New=[@key{type} T1 (D1 : Boolean := False) @key{is}
6008 @key{record}
6009 @key{case} D1 @key{is}
6010 @key{when} False =>
6011 C1 : @key{aliased} Integer;
6012 @key{when} True =>
6013 @key{null};
6014 @key{end} @key{case};
6015 @key{end} @key{record};
6016 @key{type} Acc_Int @key{is access all} Integer;],Old=[]}
6017
6018 @ChgRef{Version=[2],Kind=[AddedNormal]}
6019 @Chg{Version=[2],New=[A_T : @key{aliased} T1;
6020 Ptr : Acc_Int := A_T.C1'Access; -- @RI[Illegal in Ada 2005, legal in Ada 95]
6021 A_T := (D1 => True); -- @RI[Raised Constraint_Error in Ada 95, but does not]
6022 -- @RI[in Ada 2005, so Ptr would become invalid when this]
6023 -- @RI[is assigned (thus Ptr is illegal).]],Old=[]}
6024 @end{Example}
6025
6026 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
6027 @Chg{Version=[2],New=[If a discriminated full type has a partial view (private
6028 type) that is constrained, we do not allow 'Access on objects to create a value
6029 of an object of an
6030 access-to-unconstrained type. Ada 95 allowed this attribute and various
6031 access subtypes, requiring that the heap object be constrained and thus making
6032 details of the implementation of the private type visible to the client of
6033 the private type. See @RefSecNum{Allocators} for more on this topic.],Old=[]}
6034
6035 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00229-01],ARef=[AI95-00254-01]}
6036 @ChgAdded{Version=[2],Text=[@b[Amendment Correction:] Taking 'Access of a subprogram
6037 declared in a generic unit in the body of that generic is no longer allowed.
6038 Such references can easily be used to create dangling pointers, as
6039 @LegalityTitle are not rechecked in instance bodies. At the same time, the
6040 rules were loosened a bit where that is harmless, and also to allow any routine
6041 to be passed to an access parameter of an access-to-subprogram type. The now
6042 illegal uses of 'Access can almost always be moved to the private part of the
6043 generic unit, where they are still legal (and rechecked upon instantiation for
6044 possibly dangling pointers).]}
6045 @end{Incompatible95}
6046
6047 @begin{Extend95}
6048 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0010],ARef=[AI95-00127-01]}
6049 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> @Defn{extensions to Ada 95}
6050 Access attributes of objects of class-wide types
6051 can be used as the controlling parameter in a dispatching calls (see
6052 @RefSecNum{Dispatching Operations of Tagged Types}). This was an oversight in
6053 Ada 95.]}
6054
6055 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]}
6056 @ChgAdded{Version=[2],Text=[@b[Amendment Correction:] The type of the prefix
6057 can now be used in resolving Access attributes. This allows more uses of the
6058 Access attribute to resolve. For example:]}
6059 @begin{Example}
6060 @ChgRef{Version=[2],Kind=[AddedNormal]}
6061 @ChgAdded{Version=[2],Text=[@key{type} Int_Ptr @key{is access all} Integer;
6062 @key{type} Float_Ptr @key{is access all} Float;]}
6063
6064 @ChgRef{Version=[2],Kind=[AddedNormal]}
6065 @ChgAdded{Version=[2],Text=[@key{function} Zap (Val : Int_Ptr) @key{return} Float;
6066 @key{function} Zap (Val : Float_Ptr) @key{return} Float;]}
6067
6068 @ChgRef{Version=[2],Kind=[AddedNormal]}
6069 @ChgAdded{Version=[2],Text=[Value : @key{aliased} Integer := 10;]}
6070
6071 @ChgRef{Version=[2],Kind=[AddedNormal]}
6072 @ChgAdded{Version=[2],Text=[Result1 : Float := Zap (Value'access); -- @RI[Ambiguous in Ada 95; resolves in Ada 2005.]
6073 Result2 : Float := Zap (Int_Ptr'(Value'access)); -- @RI[Resolves in Ada 95 and Ada 2005.]]}
6074 @end{Example}
6075 @ChgRef{Version=[2],Kind=[AddedNormal]}
6076 @ChgAdded{Version=[2],Text=[This change is upward compatible; any expression
6077 that does not resolve by the new rules would have failed a Legality Rule.]}
6078 @end{Extend95}
6079
6080 @begin{DiffWord95}
6081 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00162-01]}
6082 @ChgAdded{Version=[2],Text=[Adjusted the wording to reflect the fact that
6083 expressions and function calls are masters.]}
6084
6085 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00254-01],ARef=[AI95-00318-02],ARef=[AI95-00385-01],ARef=[AI95-00416-01]}
6086 @ChgAdded{Version=[2],Text=[Defined the accessibility of the various new kinds and
6087 uses of anonymous access types.]}
6088 @end{DiffWord95}
6089
6090 @begin{Incompatible2005}
6091 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
6092 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
6093 Simplified the description of when a discriminant-dependent component is
6094 allowed as the prefix of 'Access to when the object is known to be
6095 constrained. This fixes a confusion as to whether a subcomponent of an object
6096 that is not certain to be constrained can be used as a prefix of 'Access. The
6097 fix introduces an incompatibility, as the rule did not apply in Ada 95 if the
6098 prefix was a constant; but it now applies no matter what kind of object is
6099 involved. The incompatibility is not too bad, since most kinds of constants
6100 are known to be constrained.]}
6101
6102 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0041-1]}
6103 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the checks for the
6104 constrainedness of the prefix of the Access attribute so that assume-the-worst
6105 is used in generic bodies. This may make some programs illegal, but those
6106 programs were at risk having objects disappear while valid access values still
6107 pointed at them.]}
6108 @end{Incompatible2005}
6109
6110 @begin{Extend2005}
6111 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0082-1]}
6112 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:>
6113 Eliminated the static accessibility definition for generic formal types, as
6114 the actual can be more or less nested than the generic itself. This allows
6115 programs that were illegal for Ada 95 and for Ada 2005.]}
6116
6117 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0148-1],ARef=[AI05-0253-1]}
6118 @ChgAdded{Version=[3],Text=[Eliminate the static
6119 accessibility definition for stand-alone objects of anonymous access-to-object
6120 types. This allows such objects to be used as temporaries without causing
6121 accessibility problems.]}
6122 @end{Extend2005}
6123
6124 @begin{DiffWord2005}
6125 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0014-1]}
6126 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the rules so that the
6127 accessibility of the object designated by an access object is that of the
6128 access type, even when no dereference is given. The accessibility was not
6129 specified in the past. This correction applies to both Ada 95 and Ada 2005.]}
6130
6131 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0024-1]}
6132 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected accessibility rules for
6133 access discriminants so that no cases are omitted.]}
6134
6135 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0051-1],ARef=[AI05-0234-1],ARef=[AI05-0235-1],ARef=[AI05-0284-1]}
6136 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected accessibility rules for
6137 anonymous access return types and access discriminants in return statements.]}
6138
6139 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0066-1]}
6140 @ChgAdded{Version=[3],Text=[@b<Correction:> Changed coextension rules so that
6141 coextensions that belong to an anonymous object are transfered to the ultimate
6142 object.]}
6143
6144 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4],ARef=[AI05-0188-1],ARef=[AI05-0235-1]}
6145 @ChgAdded{Version=[3],Text=[Defined the accessibility of explicitly
6146 aliased parameters (see @RefSecNum{Subprogram Declarations}) and
6147 @nt{conditional_expression}s (see @RefSecNum{Conditional Expressions}).]}
6148
6149 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]}
6150 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the term @ldquote@;master
6151 of the call@rdquote to simplify other wording, especially that for the
6152 accessibility checks associated with return statements and explicitly aliased
6153 parameters.]}
6154
6155 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0270-1]}
6156 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the (omitted)
6157 accessibility level of null values when those are passed as the actual of an
6158 access-to-object parameter.]}
6159 @end{DiffWord2005}
6160
6161 @begin{Incompatible2012}
6162 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0027-1]}
6163 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
6164 Defined the accessibility of a value conversion, so that it is treated like
6165 an @nt{aggregate} built at the point of the conversion. This was
6166 previously unspecified, so this change might be
6167 incompatible if an Ada implementation treated the accessibility of such
6168 conversions as that of the operand type; in that case, previous legal
6169 conversions probably will become illegal as the lifetime of the conversion
6170 is very short. However, code that could tell this difference is fairly rare
6171 (taking 'Access of a component of a result of a type conversion), code
6172 depending on this accessibility was not portable, and such code could have
6173 created an immediately dangling pointer if the conversion actually made
6174 a copy (which is necessary in some instances).]}
6175 @end{Incompatible2012}
6176
6177 @begin{DiffWord2012}
6178 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0067-1]}
6179 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Corrected so that it is clear
6180 that explicitly aliased parameters in procedures have the same accessibility
6181 as other parameters. Only explicitly aliased parameters in functions are
6182 special.]}
6183
6184 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0070-1]}
6185 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> The accessibility of
6186 an anonymous access type of an @nt{extended_return_statement} is defined
6187 here rather than in @RefSecNum{Return Statements} so that all accessibility
6188 rules are here.]}
6189
6190 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0089-1]}
6191 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Corrected a number of rules so
6192 that they clearly apply to generic functions as well as functions. (Remember,
6193 a generic function is not a function.)]}
6194
6195 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0095-1]}
6196 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Moved the assume the worst rule
6197 about constrainedness of the prefix of attribute Access to
6198 @RefSecNum{Formal Private and Derived Types}, as a number of places in the
6199 Standard need this rule.]}
6200
6201 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0157-1]}
6202 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Ensured that the statically
6203 deeper relationship applies within the return expression of an expression
6204 function. (Dynamic properties apply by equivalence, but static properties
6205 are handled separately.)]}
6206 @end{DiffWord2012}
6207
6208
6209 @RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
6210 @LabeledClause{Declarative Parts}
6211
6212 @begin{Intro}
6213 @Redundant[A @nt<declarative_part> contains @nt<declarative_item>s
6214 (possibly none).]
6215 @end{Intro}
6216
6217 @begin{Syntax}
6218 @Syn{lhs=<declarative_part>,rhs="{@Syn2{declarative_item}}"}
6219
6220
6221 @Syn{lhs=<declarative_item>,rhs="
6222 @Syn2{basic_declarative_item} | @Syn2{body}"}
6223
6224 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
6225 @Syn{lhs=<basic_declarative_item>,rhs="
6226 @Syn2{basic_declaration} | @Chg{New=[@Syn2{aspect_clause}],Old=[@Syn2{representation_clause}]} | @Syn2{use_clause}"}
6227
6228 @Syn{lhs=<body>,rhs="@Syn2{proper_body} | @Syn2{body_stub}"}
6229
6230 @Syn{lhs=<proper_body>,rhs="
6231 @Syn2{subprogram_body} | @Syn2{package_body} | @Syn2{task_body} | @Syn2{protected_body}"}
6232 @end{Syntax}
6233
6234 @begin{StaticSem}
6235 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00420-01]}
6236 @ChgAdded{Version=[2],Text=[The list of @nt{declarative_item}s of a
6237 @nt{declarative_part} is called the @i{declaration list} of the
6238 @nt{declarative_part}.@PDefn2{Term=[declaration list],Sec=[declarative_part]}]}
6239 @end{StaticSem}
6240
6241 @begin{RunTime}
6242 @PDefn2{Term=[elaboration], Sec=(declarative_part)}
6243 The elaboration of a @nt{declarative_part} consists of the elaboration of
6244 the @nt{declarative_item}s, if any, in the order in which they are given
6245 in the @nt{declarative_part}.
6246
6247 @Defn{elaborated}
6248 An elaborable construct is in the @i(elaborated) state after the
6249 normal completion of its elaboration.
6250 Prior to that, it is @i(not yet elaborated).
6251 @begin{Ramification}
6252 The elaborated state is only important for bodies;
6253 certain uses of a body raise an exception if the body is not yet
6254 elaborated.
6255
6256 Note that "prior" implies before the start of elaboration,
6257 as well as during elaboration.
6258
6259 The use of the term "normal completion" implies that
6260 if the elaboration propagates an exception or is aborted, the
6261 declaration is not elaborated.
6262 RM83 missed the aborted case.
6263 @end{Ramification}
6264
6265 @IndexCheck{Elaboration_Check}
6266 For a construct that attempts to use a body,
6267 a check (Elaboration_Check) is performed, as follows:
6268 @begin{Itemize}
6269 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0014],ARef=[AI95-00064-01]}
6270 For a call to a (non-protected) subprogram that has
6271 an explicit body, a check is made that the
6272 @Chg{New=[body],Old=[@nt{subprogram_body}]} is already elaborated.
6273 This check and the evaluations of any actual parameters of the call
6274 are done in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6275 @begin{Discussion}
6276 AI83-00180 specifies that there is no elaboration check for
6277 a subprogram defined by a @nt{pragma} Interface (or equivalently,
6278 @nt{pragma} Import). AI83-00430 specifies that there is no elaboration check
6279 for an enumeration literal. AI83-00406 specifies that the evaluation
6280 of parameters and the elaboration check occur in an arbitrary order.
6281 AI83-00406 applies to generic instantiation as well (see below).
6282
6283 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0014],ARef=[AI95-00064-01]}
6284 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0177-1]}
6285 @ChgAdded{Version=[1],Text=[A subprogram can be completed by a
6286 renaming-as-body@Chg{Version=[3],New=[, a @nt{null_procedure_declaration}, or
6287 an @nt{expression_function_declaration}],Old=[]}, and we need
6288 to make an elaboration check on such a body, so we use
6289 @lquotes@;body@rquotes@; rather than @nt{subprogram_body} above.]}
6290 @end{Discussion}
6291
6292 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6293 For a call to a protected operation of a protected type
6294 (that has a body @em no check is performed if @Chg{Version=[3],New=[],Old=[a
6295 @nt{pragma} Import applies to]} the protected type@Chg{Version=[3],New=[ is
6296 imported @em see @RefSecNum{Interfacing Aspects}],Old=[]}),
6297 a check is made that the @nt<protected_body> is already elaborated.
6298 This check and the evaluations of any actual parameters of the call
6299 are done in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6300 @begin{Discussion}
6301 A protected type has only one elaboration @lquotes@;bit,@rquotes@; rather than
6302 one for each operation, because one call may result in evaluating
6303 the barriers of other entries, and because there are no elaborable
6304 declarations between the bodies of the operations. In fact,
6305 the elaboration of a @nt<protected_body> does not elaborate
6306 the enclosed bodies, since they are not considered independently
6307 elaborable.
6308
6309 Note that there is no elaboration check when calling a task entry.
6310 Task entry calls are permitted even before the associated @nt<task_body>
6311 has been seen. Such calls are simply queued until the task is
6312 activated and reaches a corresponding @nt<accept_statement>.
6313 We considered a similar rule for protected entries @em simply
6314 queuing all calls until the @nt<protected_body> was seen, but felt
6315 it was not worth the possible implementation overhead, particularly
6316 given that there might be multiple instances of the protected type.
6317 @end{Discussion}
6318
6319 For the activation of a task, a check is made by the
6320 activator that the @nt{task_body} is already elaborated.
6321 If two or more tasks are being activated together
6322 (see @RefSecNum{Task Execution - Task Activation}),
6323 as the result of the elaboration of
6324 a @nt{declarative_part} or the initialization
6325 for the object created by an allocator,
6326 this check is done for all of them before activating any
6327 of them.
6328 @begin{Reason}
6329 As specified by AI83-00149, the check is done by the
6330 activator, rather than by the task itself. If it were
6331 done by the task itself, it would be turned into a Tasking_Error
6332 in the activator, and the other tasks would still be activated.
6333 @end{Reason}
6334
6335 For the instantiation of a generic unit that has a body, a check is
6336 made that this body is already elaborated.
6337 This check and the evaluation of any @nt{explicit_generic_actual_parameter}s
6338 of the instantiation are done in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6339 @end{Itemize}
6340
6341 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
6342 The exception Program_Error is raised if any of these checks fails.
6343 @end{RunTime}
6344
6345 @begin{Extend83}
6346 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6347 @Defn{extensions to Ada 83}
6348 The syntax for @nt{declarative_part} is modified to remove the ordering
6349 restrictions of Ada 83; that is, the distinction between
6350 @nt{basic_declarative_item}s and @ntf{later_declarative_item}s
6351 within @nt{declarative_part}s is removed.
6352 This means that things like @nt{use_clause}s and
6353 @Chg{Version=[2],New=[@nt{object_declaration}s],Old=[@ntf{variable_declaration}s]}
6354 can be freely intermixed with things like bodies.
6355
6356 The syntax rule for @nt{proper_body} now allows a @nt{protected_body},
6357 and the rules for elaboration checks now cover calls on
6358 protected operations.
6359 @end{Extend83}
6360
6361 @begin{DiffWord83}
6362 The syntax rule for @ntf{later_declarative_item} is removed;
6363 the syntax rule for @nt{declarative_item} is new.
6364
6365 RM83 defines @lquotes@;elaborated@rquotes@; and @lquotes@;not yet elaborated@rquotes@; for
6366 @nt{declarative_item}s here, and for other things in @RefSec{Declarations}.
6367 That's no longer necessary, since these terms are fully defined in
6368 @RefSecNum{Declarations}.
6369
6370 In RM83, all uses of @nt{declarative_part} are optional
6371 (except for the one in @nt{block_statement} with a @key(declare))
6372 which is sort of strange, since a @nt{declarative_part} can be empty,
6373 according to the syntax.
6374 That is, @nt{declarative_part}s are sort of @lquotes@;doubly optional@rquotes@;.
6375 In Ada 95, these @nt{declarative_part}s are always required
6376 (but can still be empty).
6377 To simplify description, we go further and say
6378 (see @RefSec(Block Statements)) that a
6379 @nt<block_statement> without an explicit @nt<declarative_part>
6380 is equivalent to one with an empty one.
6381 @end{DiffWord83}
6382
6383 @begin{DiffWord95}
6384 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
6385 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed representation clauses
6386 to aspect clauses to reflect that they are used for more than just
6387 representation.]}
6388
6389 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0014],ARef=[AI95-00064-01]}
6390 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the elaboration
6391 check applies to all kinds of subprogram bodies.]}
6392
6393 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00420-01]}
6394 @ChgAdded{Version=[2],Text=[Defined @lquotes@;declaration list@rquotes to
6395 avoid confusion for various rules. Other kinds of declaration list are
6396 defined elsewhere.]}
6397 @end{DiffWord95}
6398
6399
6400 @LabeledSubClause{Completions of Declarations}
6401
6402 @begin{Intro}
6403 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0014],ARef=[AI95-00064-01]}
6404 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]}
6405 Declarations sometimes come in two parts.
6406 @Defn{requires a completion}
6407 A declaration that requires a second part is said to @i(require completion).
6408 @Defn2{Term=[completion], Sec=(compile-time concept)}
6409 The second part is called the @i(completion) of the declaration (and of
6410 the entity declared),
6411 and is either another declaration, a body, or a @nt<pragma>.
6412 @Chg{New=[A @defn<body>@i<body> is a @nt<body>,
6413 an @nt<entry_body>,@Chg{Version=[3],New=[ a @nt{null_procedure_declaration} or an
6414 @nt{expression_function_declaration} that completes another declaration,],Old=[]} or
6415 a renaming-as-body
6416 (see @RefSecNum<Subprogram Renaming Declarations>).],Old=[]}
6417 @begin{Discussion}
6418 @Leading@keepnext@;Throughout the RM95, there are rules about completions that
6419 define the following:
6420 @begin{Itemize}
6421 Which declarations require a corresponding completion.
6422
6423 Which constructs can only serve as the completion
6424 of a declaration.
6425
6426 Where the completion of a declaration is allowed to be.
6427
6428 What kinds of completions are allowed to correspond to each kind of
6429 declaration that allows one.
6430 @end{Itemize}
6431
6432 Don't confuse this compile-time concept with
6433 the run-time concept of completion
6434 defined in @RefSecNum{Completion and Finalization}.
6435
6436 Note that the declaration of a private type (if limited) can be
6437 completed with the declaration of a task type, which is then completed
6438 with a body.
6439 Thus, a declaration can actually come in @i{three} parts.
6440
6441 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
6442 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0162-1]}
6443 @Chg{Version=[2],New=[@Chg{Version=[3],New=[An incomplete type (whether declared
6444 in the limited view of a package or not) may be completed by a private type
6445 declaration],Old=[In Ada 2005 the limited view of the package contains an
6446 incomplete view of the private type]}, so we can
6447 @Chg{Version=[3],New=[in fact ],Old=[]}have @i{four}
6448 parts@Chg{Version=[3],New=[],Old=[ now]}.],Old=[]}
6449
6450 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
6451 @ChgAdded{Version=[3],Text=[In Ada 2012, there are no language-defined pragmas
6452 that act as completions. Pragma Import (which is obsolescent) has the effect of
6453 setting aspect Import to True; such an aspect makes giving a completion illegal.
6454 The wording that allows pragmas as completions was left as it is harmless and
6455 appears in many places in this Standard.]}
6456 @end{Discussion}
6457 @end{Intro}
6458
6459 @begin{Resolution}
6460 @Leading@keepnext@;A construct that can be a completion
6461 is interpreted as the completion of a prior
6462 declaration only if:
6463 @begin(itemize)
6464 The declaration and the completion occur immediately within
6465 the same declarative region;
6466
6467 The defining name or @nt{defining_program_unit_name}
6468 in the completion is the same as in the declaration,
6469 or in the case of a @nt{pragma}, the @nt{pragma} applies to
6470 the declaration;
6471
6472 If the declaration is overloadable, then the completion
6473 either has a type-conformant profile,
6474 or is a @nt{pragma}.
6475 @Defn2{Term=[type conformance],Sec=(required)}
6476 @end(itemize)
6477 @end{Resolution}
6478
6479 @begin{Legality}
6480 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6481 An implicit declaration shall not have a completion.
6482 @RootDefn{requires a completion}
6483 For any explicit declaration that is specified
6484 to @i(require completion), there shall be a corresponding explicit
6485 completion@Chg{Version=[3],New=[, unless the declared
6486 entity is imported (see @RefSecNum{Interfacing Aspects})],Old=[]}.
6487 @begin(Honest)
6488 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
6489 @ChgAdded{Version=[2],Text=[The implicit declarations occurring in a
6490 limited view do have a completion (the explicit declaration occurring in the
6491 full view) but that's a special case, since the implicit declarations are
6492 actually built from the explicit ones. So they do not @i{require} a
6493 completion, they have one by @i{fiat}.]}
6494 @end{Honest}
6495
6496 @begin(Discussion)
6497 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6498 The implicit declarations of predefined operators are not allowed to
6499 have a completion.
6500 Enumeration literals, although they are subprograms, are not allowed to have a
6501 corresponding @nt{subprogram_body}.
6502 That's because the completion rules are described in terms of constructs
6503 (@nt{subprogram_declaration}s) and not entities (subprograms).
6504 When a completion is required, it has to be explicit;
6505 the implicit null @nt{package_body} that @Chg{Version=[3],New=[Clause],Old=[Section]}
6506 @RefSecNum{Packages}
6507 talks about cannot serve as the completion of a
6508 @nt{package_declaration} if a completion is required.
6509 @end(Discussion)
6510
6511 At most one completion is allowed for a given declaration.
6512 Additional requirements on completions appear where each kind
6513 of completion is defined.
6514 @begin{Ramification}
6515 A subunit is not a completion;
6516 the stub is.
6517
6518 If the completion of a declaration is also a declaration,
6519 then @i{that} declaration might have a completion, too.
6520 For example, a limited private type can be completed with a task type,
6521 which can then be completed with a task body.
6522 This is not a violation of the @lquotes@;at most one completion@rquotes@; rule.
6523 @end{Ramification}
6524
6525 @Defn{completely defined}
6526 A type is @i(completely defined) at a place that is after its
6527 full type definition (if it has one) and after all of its
6528 subcomponent types are completely defined.
6529 A type shall be completely defined before it is frozen
6530 (see @RefSecNum{Freezing Rules} and
6531 @RefSecNum{Private Types and Private Extensions}).
6532 @begin(Reason)
6533 @comment{The following is a "fix" to keep consistent with v. 5.95;
6534 appearently 6.0 is different.
6535 @ChgRef{Version=[1],Kind=[Deleted]}
6536 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}}
6537
6538 Index types are always completely defined @em no need to mention them.
6539 There is no way for a completely defined type to depend on the value of
6540 a (still) deferred constant.
6541 @end(Reason)
6542 @end{Legality}
6543
6544 @begin{Notes}
6545 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6546 Completions are in principle allowed for any kind of explicit declaration.
6547 However, for some kinds of declaration,
6548 the only allowed completion is @Chg{Version=[3],New=[an implementation-defined
6549 pragma], Old=[a @nt{pragma} Import]},
6550 and implementations are not required to @Chg{Version=[3],New=[have any
6551 such pragmas],Old=[support @nt{pragma} Import for
6552 every kind of entity]}.
6553 @begin(Discussion)
6554 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]}
6555 @ChgDeleted{Version=[3],Text=[In fact, we expect that implementations
6556 will @i{not} support pragma
6557 Import of things like types @em it's hard to even define the
6558 semantics of what it would mean.
6559 Therefore, in practice, @i{not} every explicit declaration
6560 can have a completion.
6561 In any case, if an implementation chooses to support pragma Import for,
6562 say, types, it can place whatever restrictions on the feature it wants
6563 to. For example, it might want the @nt{pragma} to be a freezing point for
6564 the type.]}
6565 @end(Discussion)
6566
6567 There are rules that prevent premature uses of declarations that have a
6568 corresponding completion.
6569 The Elaboration_Checks of @RefSecNum{Declarative Parts} prevent such
6570 uses at run time for subprograms, protected operations, tasks, and
6571 generic units.
6572 The rules of @RefSec{Freezing Rules}
6573 prevent, at compile time, premature uses of other entities
6574 such as private types and deferred constants.
6575 @end{Notes}
6576
6577 @begin{DiffWord83}
6578 This subclause is new. It is intended to cover all
6579 kinds of completions of declarations, be they a body for a spec,
6580 a full type for an incomplete or private type, a full constant
6581 declaration for a deferred constant declaration, or a @nt{pragma} Import
6582 for any kind of entity.
6583 @end{DiffWord83}
6584
6585 @begin{DiffWord95}
6586 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0014],ARef=[AI95-00064-01]}
6587 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added a definition of @i{body},
6588 which is different than @nt{body} or @key{body}.]}
6589 @end{DiffWord95}
6590
6591 @begin{DiffWord2005}
6592 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0177-1]}
6593 @ChgAdded{Version=[3],Text=[Added null procedures and expression functions
6594 that are completions to the definition of @i<body>.]}
6595 @end{DiffWord2005}