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