| 1 |
@Part(13, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2006/10/18 00:25:26 $} |
| 4 |
|
| 5 |
@Comment{$Source: e:\\cvsroot/ARM/Source/13b.mss,v $} |
| 6 |
@Comment{$Revision: 1.53 $} |
| 7 |
|
| 8 |
@RMNewPage |
| 9 |
@LabeledClause{The Package System} |
| 10 |
|
| 11 |
@begin{Intro} |
| 12 |
@redundant[For each implementation there is a library package called System |
| 13 |
which includes the definitions of certain configuration-dependent |
| 14 |
characteristics.] |
| 15 |
@end{Intro} |
| 16 |
|
| 17 |
@begin{StaticSem} |
| 18 |
@Leading@;The following language-defined library package exists: |
| 19 |
@ChgImplDef{Version=[2],Kind=[Revised],Text=[The contents of the visible part |
| 20 |
of package System@Chg{Version=[2],New=[],Old=[and its language-defined children]}.]} |
| 21 |
@begin{Example} |
| 22 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]} |
| 23 |
@RootLibUnit{System}@key[package] System @key[is] |
| 24 |
@key{pragma} @Chg{Version=[2],New=[Pure],Old=[Preelaborate]}(System); |
| 25 |
|
| 26 |
@key[type] @AdaTypeDefn{Name} @key[is] @RI{implementation-defined-enumeration-type}; |
| 27 |
@AdaObjDefn{System_Name} : @key[constant] Name := @RI{implementation-defined}; |
| 28 |
|
| 29 |
|
| 30 |
--@RI{ System-Dependent Named Numbers:} |
| 31 |
|
| 32 |
@AdaObjDefn{Min_Int} : @key[constant] := @RI{root_integer}'First; |
| 33 |
@AdaObjDefn{Max_Int} : @key[constant] := @RI{root_integer}'Last; |
| 34 |
|
| 35 |
@AdaObjDefn{Max_Binary_Modulus} : @key[constant] := @RI{implementation-defined}; |
| 36 |
@AdaObjDefn{Max_Nonbinary_Modulus} : @key[constant] := @RI{implementation-defined}; |
| 37 |
|
| 38 |
@AdaObjDefn{Max_Base_Digits} : @key[constant] := @RI{root_real}'Digits; |
| 39 |
@AdaObjDefn{Max_Digits} : @key[constant] := @RI{implementation-defined}; |
| 40 |
|
| 41 |
@AdaObjDefn{Max_Mantissa} : @key[constant] := @RI{implementation-defined}; |
| 42 |
@AdaObjDefn{Fine_Delta} : @key[constant] := @RI{implementation-defined}; |
| 43 |
|
| 44 |
@AdaObjDefn{Tick} : @key[constant] := @RI{implementation-defined}; |
| 45 |
|
| 46 |
|
| 47 |
--@RI{ Storage-related Declarations:} |
| 48 |
|
| 49 |
@key[type] @AdaTypeDefn{Address} @key[is] @RI{implementation-defined}; |
| 50 |
@AdaObjDefn{Null_Address} : @key[constant] Address; |
| 51 |
|
| 52 |
@AdaObjDefn{Storage_Unit} : @key[constant] := @RI{implementation-defined}; |
| 53 |
@AdaObjDefn{Word_Size} : @key[constant] := @RI{implementation-defined} * Storage_Unit; |
| 54 |
@AdaObjDefn{Memory_Size} : @key[constant] := @RI{implementation-defined}; |
| 55 |
|
| 56 |
--@RI{ @Defn2{Term=[address], Sec=(comparison)}Address Comparison:} |
| 57 |
@key(function) "<" (Left, Right : Address) @key(return) Boolean; |
| 58 |
@key(function) "<="(Left, Right : Address) @key(return) Boolean; |
| 59 |
@key(function) ">" (Left, Right : Address) @key(return) Boolean; |
| 60 |
@key(function) ">="(Left, Right : Address) @key(return) Boolean; |
| 61 |
@key(function) "=" (Left, Right : Address) @key(return) Boolean; |
| 62 |
-- @key(function) "/=" (Left, Right : Address) @key(return) Boolean; |
| 63 |
--@RI{ "/=" is implicitly defined} |
| 64 |
@key[pragma] Convention(Intrinsic, "<"); |
| 65 |
... --@RI{ and so on for all language-defined subprograms in this package} |
| 66 |
|
| 67 |
|
| 68 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00221-01]} |
| 69 |
--@RI{ Other System-Dependent Declarations:} |
| 70 |
@key[type] @AdaTypeDefn{Bit_Order} @key[is] (@AdaObjDefn{High_Order_First}, @AdaObjDefn{Low_Order_First}); |
| 71 |
@AdaObjDefn{Default_Bit_Order} : @key[constant] Bit_Order@Chg{Version=[2],New=[ := @RI{implementation-defined}],Old=[]}; |
| 72 |
|
| 73 |
|
| 74 |
--@RI{ Priority-related declarations (see @RefSecNum{Task Priorities}):} |
| 75 |
@key{subtype} @AdaSubtypeDefn{Name=[Any_Priority],Of=[Integer]} @key{is} Integer @key{range} @RI{implementation-defined}; |
| 76 |
@key{subtype} @AdaSubtypeDefn{Name=[Priority],Of=[Any_Priority]} @key{is} Any_Priority @key{range} Any_Priority'First .. |
| 77 |
@RI{implementation-defined}; |
| 78 |
@key{subtype} @AdaSubtypeDefn{Name=[Interrupt_Priority],Of=[Any_Priority]} @key{is} Any_Priority @key{range} Priority'Last+1 .. |
| 79 |
Any_Priority'Last; |
| 80 |
|
| 81 |
@AdaObjDefn{Default_Priority} : @key{constant} Priority := |
| 82 |
(Priority'First + Priority'Last)/2; |
| 83 |
|
| 84 |
@key[private] |
| 85 |
... -- @RI{not specified by the language} |
| 86 |
@key[end] System; |
| 87 |
@end{Example} |
| 88 |
|
| 89 |
|
| 90 |
Name is an enumeration subtype. |
| 91 |
Values of type Name are the names of alternative machine |
| 92 |
configura@!tions handled by the implementation. |
| 93 |
System_Name represents the current machine configuration. |
| 94 |
|
| 95 |
The named numbers Fine_Delta and Tick are of the type |
| 96 |
@i{universal_real}; the others are of the type @i{universal_integer}. |
| 97 |
|
| 98 |
@Leading@;The meanings of the named numbers are: |
| 99 |
@begin{Description} |
| 100 |
@Redundant[ |
| 101 |
Min_Int @\The smallest (most negative) value |
| 102 |
allowed for the expressions of a |
| 103 |
@nt{signed_@!integer_@!type_@!definition}. |
| 104 |
|
| 105 |
Max_Int @\The largest (most positive) value |
| 106 |
allowed for the expressions of a |
| 107 |
@nt{signed_@!integer_@!type_@!definition}. |
| 108 |
|
| 109 |
Max_Binary_Modulus @\A power of two such that it, |
| 110 |
and all lesser positive powers of two, are allowed |
| 111 |
as the modulus of a @nt<modular_type_definition>. |
| 112 |
|
| 113 |
Max_Nonbinary_Modulus @\A value such that it, |
| 114 |
and all lesser positive integers, are allowed |
| 115 |
as the modulus of a @nt<modular_type_definition>. |
| 116 |
@begin{Ramification} |
| 117 |
There is no requirement that Max_Nonbinary_Modulus |
| 118 |
be less than or equal to Max_Binary_Modulus, |
| 119 |
although that's what makes most sense. |
| 120 |
On a typical 32-bit machine, for example, |
| 121 |
Max_Binary_Modulus will be 2**32 |
| 122 |
and Max_Nonbinary_Modulus will be 2**31, |
| 123 |
because supporting nonbinary moduli in above 2**31 |
| 124 |
causes implementation difficulties. |
| 125 |
@end{Ramification} |
| 126 |
|
| 127 |
Max_Base_Digits @\The largest value allowed for the requested decimal |
| 128 |
precision in a @nt{floating_@!point_@!definition}. |
| 129 |
|
| 130 |
Max_Digits @\The largest value allowed for the requested decimal |
| 131 |
precision in a @nt{floating_@!point_@!definition} |
| 132 |
that has no @nt{real_@!range_@!specification}. |
| 133 |
Max_Digits is less than or equal to Max_Base_Digits. |
| 134 |
|
| 135 |
Max_Mantissa @\The largest possible number of binary digits in the mantissa |
| 136 |
of machine numbers of a user-defined ordinary fixed point type. |
| 137 |
(The mantissa is defined in @RefSecNum{Numerics}.) |
| 138 |
|
| 139 |
Fine_Delta @\The smallest delta allowed in an @nt{ordinary_fixed_point_definition} that |
| 140 |
has the @nt{real_@!range_@!specification} @key{range} @en@;1.0 .. 1.0. |
| 141 |
] |
| 142 |
|
| 143 |
Tick @\A period in seconds approximating the real time interval during |
| 144 |
which the value of Calendar.Clock remains constant. |
| 145 |
@begin{Ramification} |
| 146 |
There is no required relationship between System.Tick and |
| 147 |
Duration'Small, |
| 148 |
other than the one described here. |
| 149 |
|
| 150 |
The inaccuracy of the @nt{delay_statement} has no relation to Tick. |
| 151 |
In particular, it is possible that the clock used for the |
| 152 |
@nt{delay_statement} is less accurate than Calendar.Clock. |
| 153 |
|
| 154 |
We considered making Tick a run-time-determined quantity, |
| 155 |
to allow for easier configurability. |
| 156 |
However, this would not be upward compatible, |
| 157 |
and the desired configurability can be achieved using |
| 158 |
functionality defined in @RefSec{Real-Time Systems}. |
| 159 |
@end{Ramification} |
| 160 |
|
| 161 |
Storage_Unit @\The number of bits per storage element. |
| 162 |
|
| 163 |
Word_Size @\The number of bits per word. |
| 164 |
|
| 165 |
Memory_Size @\An implementation-defined value |
| 166 |
@Redundant[that is intended to reflect the memory size of the |
| 167 |
configuration in storage elements.] |
| 168 |
@begin{Discussion} |
| 169 |
It is unspecified whether this refers to the size of the |
| 170 |
address space, the amount of physical memory on the machine, |
| 171 |
or perhaps some other interpretation of @lquotes@;memory size.@rquotes@; |
| 172 |
In any case, the value has to be given by a static expression, |
| 173 |
even though the amount of memory on many modern machines is |
| 174 |
a dynamic quantity in several ways. |
| 175 |
Thus, Memory_Size is not very useful. |
| 176 |
@end{Discussion} |
| 177 |
@end{Description} |
| 178 |
|
| 179 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]} |
| 180 |
Address is @Chg{Version=[2],New=[],Old=[of ]}a definite, nonlimited |
| 181 |
type@Chg{Version=[2],New=[ with preelaborable initialization (see |
| 182 |
@RefSecNum{Elaboration Control})],Old=[]}. |
| 183 |
Address represents machine addresses capable of addressing individual |
| 184 |
storage elements. |
| 185 |
Null_Address is an address that is distinct from the |
| 186 |
address of any object or program unit. |
| 187 |
@IndexSee{Term=[pointer],See=(type System.Address)} |
| 188 |
@begin{Ramification} |
| 189 |
The implementation has to ensure that there is at least one |
| 190 |
address that nothing will be allocated to; |
| 191 |
Null_Address will be one such address. |
| 192 |
@end{Ramification} |
| 193 |
@begin{Ramification} |
| 194 |
Address is the type of the result of the attribute Address. |
| 195 |
@end{Ramification} |
| 196 |
@begin{Reason} |
| 197 |
Address is required to be nonlimited and definite because |
| 198 |
it is important to be able to assign addresses, |
| 199 |
and to declare uninitialized address variables. |
| 200 |
@end{Reason} |
| 201 |
@begin{Ramification} |
| 202 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]} |
| 203 |
@ChgAdded{Version=[2],Text=[If System.Address is defined as a private type |
| 204 |
(as suggested below), it might be necessary to add a pragma |
| 205 |
Preelaborable_Initialization to the specification of System in order that |
| 206 |
Address have preelaborable initialization as required.]} |
| 207 |
@end{Ramification} |
| 208 |
|
| 209 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00221-01]} |
| 210 |
@Chg{Version=[2],New=[ Default_Bit_Order shall |
| 211 |
be a static constant. ],Old=[]}See @RefSecNum{Bit Ordering} for an |
| 212 |
explanation of Bit_Order and Default_Bit_Order. |
| 213 |
@end{StaticSem} |
| 214 |
|
| 215 |
@begin{ImplPerm} |
| 216 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]} |
| 217 |
An implementation may add additional implementation-defined |
| 218 |
declarations to package System and its children. |
| 219 |
@Redundant[However, it is usually better |
| 220 |
for the implementation to provide |
| 221 |
additional functionality via implementation-defined |
| 222 |
children of System.]@Chg{Version=[2],New=[],Old=[ |
| 223 |
Package System may be declared pure.]} |
| 224 |
@begin{Ramification} |
| 225 |
The declarations in package System and its children can be implicit. |
| 226 |
For example, since Address is not limited, |
| 227 |
the predefined "=" and "/=" operations are probably sufficient. |
| 228 |
However, the implementation is not @i{required} to use the predefined |
| 229 |
"=". |
| 230 |
@end{Ramification} |
| 231 |
@end{ImplPerm} |
| 232 |
|
| 233 |
@begin{ImplAdvice} |
| 234 |
@ChgNote{Version=[1],Kind=[Revised]}@ChgNote{Remove bogus "of"} |
| 235 |
Address should be @Chg{New=[],Old=[of ]}a private type. |
| 236 |
@begin{Reason} |
| 237 |
This promotes uniformity by avoiding having |
| 238 |
implementation-defined predefined operations for the type. |
| 239 |
We don't require it, because implementations may want to stick with |
| 240 |
what they have. |
| 241 |
@end{Reason} |
| 242 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 243 |
Text=[Type System.Address should be a private type.]}]} |
| 244 |
@begin{ImplNote} |
| 245 |
It is not necessary for Address to be able to point at |
| 246 |
individual bits within a storage element. |
| 247 |
Nor is it necessary for it to be able to point at machine registers. |
| 248 |
It is intended as a memory address that matches the hardware's notion |
| 249 |
of an address. |
| 250 |
|
| 251 |
The representation of the @key{null} value of a general access type should |
| 252 |
be the same as that of Null_Address; |
| 253 |
instantiations of Unchecked_Conversion should work accordingly. |
| 254 |
If the implementation supports interfaces to other languages, |
| 255 |
the representation of the @key{null} value of a general access type |
| 256 |
should be the same as in those other languages, if appropriate. |
| 257 |
|
| 258 |
Note that the children of the Interfaces package will generally provide |
| 259 |
foreign-language-specific null values where appropriate. |
| 260 |
See UI-0065 regarding Null_Address. |
| 261 |
@end{ImplNote} |
| 262 |
@end{ImplAdvice} |
| 263 |
|
| 264 |
@begin{Notes} |
| 265 |
There are also some language-defined child packages of System |
| 266 |
defined elsewhere. |
| 267 |
@end{Notes} |
| 268 |
|
| 269 |
@begin{Extend83} |
| 270 |
@ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00114} |
| 271 |
@ChgAdded{Version=[1],Text=[@Defn{extensions to Ada 83} |
| 272 |
The declarations Max_Binary_Modulus, Max_Nonbinary_Modulus, Max_Base_Digits, |
| 273 |
Null_Address, Word_Size, Bit_Order, Default_Bit_Order, Any_Priority, |
| 274 |
Interrupt_Priority, and Default_Priority are added to System in Ada 95. |
| 275 |
The presence of ordering operators for type Address is also guaranteed (the |
| 276 |
existence of these depends on the definition of Address in an Ada 83 |
| 277 |
implementation). We do not list these as incompatibilities, as the contents of |
| 278 |
System can vary between implementations anyway; thus a program that depends on |
| 279 |
the contents of System (by using @f{@key[use] System;} for example) is |
| 280 |
already at risk of being incompatible when moved between Ada implementations.]} |
| 281 |
@end{Extend83} |
| 282 |
|
| 283 |
@begin{DiffWord83} |
| 284 |
Much of the content of System is standardized, |
| 285 |
to provide more uniformity across implementations. |
| 286 |
Implementations can still add their own declarations to System, |
| 287 |
but are encouraged to do so via children of System. |
| 288 |
|
| 289 |
Some of the named numbers are defined more explicitly in terms of the |
| 290 |
standard numeric types. |
| 291 |
|
| 292 |
The pragmas System_Name, Storage_Unit, and Memory_Size are no |
| 293 |
longer defined by the language. |
| 294 |
However, the corresponding declarations in package |
| 295 |
System still exist. |
| 296 |
Existing implementations may continue to support the three |
| 297 |
pragmas as implementation-defined pragmas, |
| 298 |
if they so desire. |
| 299 |
|
| 300 |
Priority semantics, including subtype Priority, |
| 301 |
have been moved to the Real Time Annex. |
| 302 |
@end{DiffWord83} |
| 303 |
|
| 304 |
@begin{Extend95} |
| 305 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]} |
| 306 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 307 |
@b[Amendment Correction:] Type Address is defined to have preelaborable |
| 308 |
initialization, so that it |
| 309 |
can be used without restriction in preelaborated units. (If Address is |
| 310 |
defined to be a private type, as suggested by the @ImplAdviceTitle, |
| 311 |
in Ada 95 it cannot be used in some contexts in a preelaborated units. |
| 312 |
This is an unnecessary portability issue.)]} |
| 313 |
|
| 314 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00221-01]} |
| 315 |
@ChgAdded{Version=[2],Text=[@b[Amendment Correction:] Default_Bit_Order |
| 316 |
is now a static constant.]} |
| 317 |
|
| 318 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]} |
| 319 |
@ChgAdded{Version=[2],Text=[Package System is now Pure, so it can be |
| 320 |
portably used in more places. (Ada 95 allowed it to be Pure, but did not |
| 321 |
require that.)]} |
| 322 |
@end{Extend95} |
| 323 |
|
| 324 |
|
| 325 |
@LabeledSubClause{The Package System.Storage_Elements} |
| 326 |
|
| 327 |
@begin{StaticSem} |
| 328 |
@Leading@;The following language-defined library package exists: |
| 329 |
@begin{Example} |
| 330 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]} |
| 331 |
@ChildUnit{Parent=[System],Child=[Storage_Elements]}@key[package] System.Storage_Elements @key[is] |
| 332 |
@key{pragma} @Chg{Version=[2],New=[Pure(],Old=[Preelaborate(System.]}Storage_Elements); |
| 333 |
|
| 334 |
@key[type] @AdaTypeDefn{Storage_Offset} @key[is] @key[range] @RI(implementation-defined); |
| 335 |
|
| 336 |
@key[subtype] @AdaSubtypeDefn{Name=[Storage_Count],Of=[Storage_Offset]} @key[is] Storage_Offset @key[range] 0..Storage_Offset'Last; |
| 337 |
|
| 338 |
|
| 339 |
@key[type] @AdaTypeDefn{Storage_Element} @key[is] @key[mod] @RI{implementation-defined}; |
| 340 |
@key[for] Storage_Element'Size @key[use] Storage_Unit; |
| 341 |
@key[type] @AdaTypeDefn{Storage_Array} @key[is] @key[array] |
| 342 |
(Storage_Offset @key[range] <>) @key[of] @key[aliased] Storage_Element; |
| 343 |
@key[for] Storage_Array'Component_Size @key[use] Storage_Unit; |
| 344 |
|
| 345 |
|
| 346 |
--@RI{ @Defn2{Term=[address], Sec=(arithmetic)}Address Arithmetic:} |
| 347 |
|
| 348 |
@key(function) "+"(Left : Address; Right : Storage_Offset) |
| 349 |
@key(return) Address; |
| 350 |
@key(function) "+"(Left : Storage_Offset; Right : Address) |
| 351 |
@key(return) Address; |
| 352 |
@key(function) "-"(Left : Address; Right : Storage_Offset) |
| 353 |
@key(return) Address; |
| 354 |
@key(function) "-"(Left, Right : Address) |
| 355 |
@key(return) Storage_Offset; |
| 356 |
|
| 357 |
|
| 358 |
@key(function) "@key(mod)"(Left : Address; Right : Storage_Offset) |
| 359 |
@key(return) Storage_Offset; |
| 360 |
|
| 361 |
|
| 362 |
--@RI{ Conversion to/from integers:} |
| 363 |
|
| 364 |
@key[type] @AdaTypeDefn{Integer_Address} @key[is] @RI{implementation-defined}; |
| 365 |
@key[function] @AdaSubDefn{To_Address}(Value : Integer_Address) @key[return] Address; |
| 366 |
@key[function] @AdaSubDefn{To_Integer}(Value : Address) @key[return] Integer_Address; |
| 367 |
|
| 368 |
|
| 369 |
@key[pragma] Convention(Intrinsic, "+"); |
| 370 |
@RI(-- ...and so on for all language-defined subprograms declared in this package.) |
| 371 |
@key[end] System.Storage_Elements; |
| 372 |
@end{Example} |
| 373 |
@begin{Reason} |
| 374 |
The Convention @nt{pragma}s imply that |
| 375 |
the attribute Access is not allowed for those operations. |
| 376 |
|
| 377 |
The @key(mod) function is needed so that the |
| 378 |
definition of Alignment makes sense. |
| 379 |
@end{Reason} |
| 380 |
@ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 381 |
Text=[The range of Storage_Elements.Storage_Offset, the modulus of |
| 382 |
Storage_Elements.Storage_Element, and the declaration of |
| 383 |
Storage_Elements.Integer_Address.]}.]} |
| 384 |
|
| 385 |
Storage_Element represents a storage element. |
| 386 |
Storage_Offset represents an offset in storage elements. |
| 387 |
Storage_Count represents a number of storage elements. |
| 388 |
@PDefn{contiguous representation} |
| 389 |
@PDefn{discontiguous representation} |
| 390 |
Storage_Array represents a contiguous sequence of storage elements. |
| 391 |
@begin{Reason} |
| 392 |
The index subtype of Storage_Array is Storage_Offset |
| 393 |
because we wish to allow maximum flexibility. |
| 394 |
Most Storage_Arrays will probably have a lower bound of 0 or 1, |
| 395 |
but other lower bounds, including negative ones, |
| 396 |
make sense in some situations. |
| 397 |
|
| 398 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]} |
| 399 |
@ChgDeleted{Version=[2],Text=[Note that there are some language-defined |
| 400 |
subprograms that fill part of a Storage_Array, and return the index of the |
| 401 |
last element filled as a Storage_Offset. |
| 402 |
The Read procedures in |
| 403 |
Streams (see @RefSecNum{The Package Streams}), |
| 404 |
Streams.Stream_IO (see @RefSecNum{The Package Streams.Stream_IO}), |
| 405 |
and System.RPC (see @RefSecNum{Partition Communication Subsystem}) |
| 406 |
behave in this manner. |
| 407 |
These will raise Constraint_Error if the resulting Last value is not in |
| 408 |
Storage_Offset. |
| 409 |
This implies that the Storage_Array passed to these subprograms should |
| 410 |
not have a lower bound of Storage_Offset'First, |
| 411 |
because then a read of 0 elements would always raise Constraint_Error. |
| 412 |
A better choice of lower bound is 1.]} |
| 413 |
@end{Reason} |
| 414 |
|
| 415 |
Integer_Address is a @Redundant[(signed or modular)] integer subtype. |
| 416 |
To_Address and To_Integer convert back and forth between |
| 417 |
this type and Address. |
| 418 |
@end{StaticSem} |
| 419 |
|
| 420 |
@begin{ImplReq} |
| 421 |
Storage_Offset'Last shall be greater than or equal to Integer'Last or |
| 422 |
the largest possible storage offset, |
| 423 |
whichever is smaller. |
| 424 |
Storage_Offset'First shall be <= (@en@;Storage_Offset'Last). |
| 425 |
@end{ImplReq} |
| 426 |
|
| 427 |
@begin{ImplPerm} |
| 428 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00362-01]} |
| 429 |
@ChgDeleted{Version=[2],Text=[Package System.Storage_Elements may be declared |
| 430 |
pure.]} |
| 431 |
@end{ImplPerm} |
| 432 |
|
| 433 |
@begin{ImplAdvice} |
| 434 |
Operations in System and its children should reflect the |
| 435 |
target environment semantics as closely as is reasonable. |
| 436 |
For example, on most machines, it makes sense for address arithmetic |
| 437 |
to @lquotes@;wrap around.@rquotes@; |
| 438 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 439 |
Operations that do not make sense should raise |
| 440 |
Program_Error. |
| 441 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 442 |
Text=[Operations in System and its children should reflect the |
| 443 |
target environment; operations that do not make sense should raise Program_Error.]}]} |
| 444 |
@begin{Discussion} |
| 445 |
For example, on a segmented architecture, |
| 446 |
X < Y might raise Program_Error if X and Y do not point at the same |
| 447 |
segment (assuming segments are unordered). |
| 448 |
Similarly, on a segmented architecture, |
| 449 |
the conversions between Integer_Address and Address |
| 450 |
might not make sense for some values, |
| 451 |
and so might raise Program_Error. |
| 452 |
@end{Discussion} |
| 453 |
@begin{Reason} |
| 454 |
We considered making Storage_Element a private type. |
| 455 |
However, it is better to declare it as a modular type in the visible part, |
| 456 |
since code that uses it is already low level, |
| 457 |
and might as well have access to the underlying representation. |
| 458 |
We also considered allowing Storage_Element to be any |
| 459 |
integer type, signed integer or modular, but it is better to have |
| 460 |
uniformity across implementations in this regard, and viewing storage elements |
| 461 |
as unsigned seemed to make the most sense. |
| 462 |
@end{Reason} |
| 463 |
@begin{ImplNote} |
| 464 |
To_Address is intended for use in Address clauses. |
| 465 |
Implementations should overload To_Address if appropriate. |
| 466 |
For example, on a segmented architecture, |
| 467 |
it might make sense to have a record type representing a |
| 468 |
segment/offset pair, and have a To_Address conversion that |
| 469 |
converts from that record type to type Address. |
| 470 |
@end{ImplNote} |
| 471 |
@end{ImplAdvice} |
| 472 |
|
| 473 |
@begin{Extend95} |
| 474 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]} |
| 475 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 476 |
Package System.Storage_Elements is now Pure, so it can be |
| 477 |
portably used in more places. (Ada 95 allowed it to be Pure, but did not |
| 478 |
require that.)]} |
| 479 |
@end{Extend95} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
@LabeledSubClause{The Package System.Address_To_Access_Conversions} |
| 484 |
|
| 485 |
@begin{StaticSem} |
| 486 |
|
| 487 |
@Leading@;The following language-defined generic library package exists: |
| 488 |
@begin{Example} |
| 489 |
@ChildUnit{Parent=[System],Child=[Address_@!To_@!Access_@!Conversions]}@key[generic] |
| 490 |
@key[type] Object(<>) @key[is] @key[limited] @key[private]; |
| 491 |
@key[package] System.Address_To_Access_Conversions @key[is] |
| 492 |
@key[pragma] Preelaborate(Address_To_Access_Conversions); |
| 493 |
|
| 494 |
@key[type] Object_Pointer @key[is] @key[access] @key[all] Object; |
| 495 |
@key[function] @AdaSubDefn{To_Pointer}(Value : Address) @key[return] Object_Pointer; |
| 496 |
@key[function] @AdaSubDefn{To_Address}(Value : Object_Pointer) @key[return] Address; |
| 497 |
|
| 498 |
@key[pragma] Convention(Intrinsic, To_Pointer); |
| 499 |
@key[pragma] Convention(Intrinsic, To_Address); |
| 500 |
@key[end] System.Address_To_Access_Conversions; |
| 501 |
@end{Example} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]} |
| 506 |
The To_Pointer and To_Address subprograms |
| 507 |
convert back and forth between |
| 508 |
values of types Object_Pointer and Address. |
| 509 |
To_Pointer(X'Address) is equal to X'Unchecked_Access |
| 510 |
for any X that allows Unchecked_Access. |
| 511 |
To_Pointer(Null_Address) returns @key[null]. |
| 512 |
@PDefn{unspecified} |
| 513 |
For other addresses, |
| 514 |
the behavior is unspecified. |
| 515 |
To_Address(@key[null]) returns Null_Address@Chg{Version=[2],New=[],Old=[ (for |
| 516 |
@key[null] of the appropriate type)]}. |
| 517 |
To_Address(Y), where Y /= @key[null], returns Y.@key[all]'Address. |
| 518 |
@begin{Discussion} |
| 519 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 520 |
The programmer should ensure that |
| 521 |
the address passed to To_Pointer is either Null_Address, |
| 522 |
or the address of an object of type Object. @Chg{Version=[2],New=[(If Object is not |
| 523 |
a not by-reference type, the object ought to be aliased; recall that the |
| 524 |
Address attribute is not required to provide a useful result other objects.)],Old=[]} |
| 525 |
Otherwise, the behavior of the program is unspecified; |
| 526 |
it might raise an exception or crash, for example. |
| 527 |
@end{Discussion} |
| 528 |
@begin{Reason} |
| 529 |
Unspecified is almost the same thing as erroneous; |
| 530 |
they both allow arbitrarily bad behavior. |
| 531 |
We don't say erroneous here, because the implementation |
| 532 |
might allow the address passed to To_Pointer to point |
| 533 |
at some memory that just happens to @lquotes@;look like@rquotes@; an |
| 534 |
object of type Object. |
| 535 |
That's not necessarily an error; it's just not portable. |
| 536 |
However, if the actual type passed to Object is (for example) |
| 537 |
an array type, the programmer |
| 538 |
would need to be aware of any dope that the implementation expects to |
| 539 |
exist, when passing an address that did not come from the Address |
| 540 |
attribute of an object of type Object. |
| 541 |
|
| 542 |
One might wonder why To_Pointer and To_Address are any better than |
| 543 |
unchecked conversions. The answer is that Address does not necessarily |
| 544 |
have the same representation as an access type. For example, an access |
| 545 |
value might point at the bounds of an array when an address would point |
| 546 |
at the first element. Or an access value might be an offset in words |
| 547 |
from someplace, whereas an address might be an offset in bytes from the |
| 548 |
beginning of memory. |
| 549 |
@end{Reason} |
| 550 |
@end{StaticSem} |
| 551 |
|
| 552 |
@begin{ImplPerm} |
| 553 |
An implementation may place restrictions on instantiations of |
| 554 |
Address_To_Access_Conversions. |
| 555 |
@begin{Ramification} |
| 556 |
For example, if the hardware requires aligned loads and stores, |
| 557 |
then dereferencing an access value that is not properly aligned might |
| 558 |
raise an exception. |
| 559 |
|
| 560 |
For another example, |
| 561 |
if the implementation has chosen to use negative component offsets |
| 562 |
(from an access value), |
| 563 |
it might not be possible to preserve the semantics, |
| 564 |
since negative offsets from the Address are not allowed. |
| 565 |
(The Address attribute always points at |
| 566 |
@lquotes@;the first of the storage elements....@rquotes@;) |
| 567 |
Note that while the implementation knows how to convert an access |
| 568 |
value into an address, it might not be able to do the reverse. |
| 569 |
To avoid generic contract model violations, |
| 570 |
the restriction might have to be detected at run time in some cases. |
| 571 |
@end{Ramification} |
| 572 |
@end{ImplPerm} |
| 573 |
|
| 574 |
@LabeledClause{Machine Code Insertions} |
| 575 |
|
| 576 |
@begin{Intro} |
| 577 |
@redundant[@Defn{machine code insertion} |
| 578 |
A machine code insertion can be achieved by a call to a subprogram whose |
| 579 |
@nt{sequence_of_statements} contains @nt{code_statement}s.] |
| 580 |
@end{Intro} |
| 581 |
|
| 582 |
@begin{Syntax} |
| 583 |
@Syn{lhs=<code_statement>,rhs="@Syn2{qualified_expression};"} |
| 584 |
|
| 585 |
@begin{SyntaxText} |
| 586 |
A @nt{code_statement} is only allowed in the |
| 587 |
@nt{handled_sequence_of_@!statements} of a @nt{subprogram_@!body}. |
| 588 |
If a @nt{subprogram_@!body} contains any @nt{code_@!statement}s, then within |
| 589 |
this @nt{subprogram_@!body} the only allowed form of @nt{statement} is a |
| 590 |
@nt{code_@!statement} (labeled or not), |
| 591 |
the only allowed @nt{declarative_@!item}s are @nt{use_@!clause}s, |
| 592 |
and no @nt{exception_@!handler} is allowed (@nt{comment}s and |
| 593 |
@nt{pragma}s are allowed as usual). |
| 594 |
@end{SyntaxText} |
| 595 |
@end{Syntax} |
| 596 |
|
| 597 |
@begin{Resolution} |
| 598 |
@PDefn2{Term=[expected type], |
| 599 |
Sec=(code_statement)} |
| 600 |
The @nt{qualified_expression} is expected to be of any type. |
| 601 |
@end{Resolution} |
| 602 |
|
| 603 |
@begin{Legality} |
| 604 |
The @nt{qualified_expression} shall be of a |
| 605 |
type declared in package System.Machine_Code. |
| 606 |
@begin{Ramification} |
| 607 |
This includes types declared in children of System.Machine_Code. |
| 608 |
@end{Ramification} |
| 609 |
|
| 610 |
A @nt<code_statement> shall appear only within the scope of |
| 611 |
a @nt<with_clause> that mentions package System.Machine_Code. |
| 612 |
@begin{Ramification} |
| 613 |
Note that this is not a note; |
| 614 |
without this rule, it would be possible to write machine code |
| 615 |
in compilation units which depend on System.Machine_Code only indirectly. |
| 616 |
@end{Ramification} |
| 617 |
@end{Legality} |
| 618 |
|
| 619 |
@begin{StaticSem} |
| 620 |
@Defn{System.Machine_Code} |
| 621 |
@ChildUnit{Parent=[System],Child=[Machine_Code]} |
| 622 |
The contents of the library package System.Machine_Code |
| 623 |
(if provided) are implementation defined. |
| 624 |
The meaning of @nt{code_statement}s is implementation defined. |
| 625 |
@Redundant{Typically, each @nt{qualified_expression} |
| 626 |
represents a machine instruction or assembly directive.} |
| 627 |
@begin{Discussion} |
| 628 |
For example, an instruction might be a record with an Op_Code |
| 629 |
component and other components for the operands. |
| 630 |
@end{Discussion} |
| 631 |
@ImplDef{The contents of the visible part of package System.Machine_Code, |
| 632 |
and the meaning of @nt{code_statement}s.} |
| 633 |
@end{StaticSem} |
| 634 |
|
| 635 |
@begin{ImplPerm} |
| 636 |
An implementation may place restrictions on @nt{code_statement}s. |
| 637 |
An implementation is not required to provide package System.Machine_Code. |
| 638 |
@end{ImplPerm} |
| 639 |
|
| 640 |
@begin{Notes} |
| 641 |
An implementation may provide implementation-defined pragmas |
| 642 |
specifying register conventions and calling conventions. |
| 643 |
|
| 644 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 645 |
Machine code functions are exempt from the rule that a |
| 646 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 647 |
is required. In fact, |
| 648 |
@Chg{Version=[2],New=[return statements],Old=[@nt{return_@!statement}s]} are |
| 649 |
forbidden, since only @nt{code_statement}s are allowed. |
| 650 |
@begin{Discussion} |
| 651 |
The idea is that the author of a machine code subprogram knows |
| 652 |
the calling conventions, and refers to parameters and results |
| 653 |
accordingly. |
| 654 |
The implementation should document where to put the result of a |
| 655 |
machine code function, for example, |
| 656 |
@lquotes@;Scalar results are returned in register 0.@rquotes@; |
| 657 |
@end{Discussion} |
| 658 |
|
| 659 |
Intrinsic subprograms (see @RefSec{Conformance Rules}) |
| 660 |
can also be used to achieve machine code insertions. |
| 661 |
Interface to assembly language can be achieved |
| 662 |
using the features in @RefSec{Interface to Other Languages}. |
| 663 |
@end{Notes} |
| 664 |
|
| 665 |
@begin{Examples} |
| 666 |
@leading@keepnext@i{Example of a code statement:} |
| 667 |
@begin{Example} |
| 668 |
M : Mask; |
| 669 |
@key[procedure] Set_Mask; @key[pragma] Inline(Set_Mask); |
| 670 |
|
| 671 |
@key[procedure] Set_Mask @key[is] |
| 672 |
@key[use] System.Machine_Code; --@RI{ assume @lquotes@;@key[with] System.Machine_Code;@rquotes@; appears somewhere above} |
| 673 |
@key[begin] |
| 674 |
SI_Format'(Code => SSM, B => M'Base_Reg, D => M'Disp); |
| 675 |
--@RI{ Base_Reg and Disp are implementation-defined attributes} |
| 676 |
@key[end] Set_Mask; |
| 677 |
@end{Example} |
| 678 |
@end{Examples} |
| 679 |
|
| 680 |
@begin{Extend83} |
| 681 |
@Defn{extensions to Ada 83} |
| 682 |
Machine code functions are allowed in Ada 95; |
| 683 |
in Ada 83, only procedures were allowed. |
| 684 |
@end{Extend83} |
| 685 |
|
| 686 |
@begin{DiffWord83} |
| 687 |
The syntax for @nt{code_statement} is changed to say |
| 688 |
@lquotes@;@nt{qualified_expression}@rquotes@; instead of |
| 689 |
@lquotes@;@Syn2{subtype_mark}'@Syn2{record_aggregate}@rquotes@;. |
| 690 |
Requiring the type of each instruction to be a record type is |
| 691 |
overspecification. |
| 692 |
@end{DiffWord83} |
| 693 |
|
| 694 |
@LabeledClause{Unchecked Type Conversions} |
| 695 |
|
| 696 |
@begin{Intro} |
| 697 |
@redundant[@Defn{unchecked type conversion} |
| 698 |
@Defn2{Term=[type conversion], Sec=(unchecked)} |
| 699 |
@Defn2{Term=[conversion], Sec=(unchecked)} |
| 700 |
@IndexSeeAlso{Term=[type_conversion],See=(unchecked type conversion)} |
| 701 |
@IndexSee{Term=[cast],See=(unchecked type conversion)} |
| 702 |
An unchecked type conversion can be achieved by a call to an instance |
| 703 |
of the generic function Unchecked_Conversion.] |
| 704 |
@end{Intro} |
| 705 |
|
| 706 |
@begin{StaticSem} |
| 707 |
@Leading@keepnext@;The following language-defined generic library function exists: |
| 708 |
@begin{Example} |
| 709 |
@key[generic] |
| 710 |
@key[type] Source(<>) @key[is] @key[limited] @key[private]; |
| 711 |
@key[type] Target(<>) @key[is] @key[limited] @key[private]; |
| 712 |
@SubChildUnit{Parent=[Ada],Child=[Unchecked_Conversion]}@key[function] Ada.Unchecked_Conversion(S : Source) @key[return] Target; |
| 713 |
@key[pragma] Convention(Intrinsic, Ada.Unchecked_Conversion); |
| 714 |
@key[pragma] Pure(Ada.Unchecked_Conversion); |
| 715 |
@end{Example} |
| 716 |
@begin{Reason} |
| 717 |
The @nt{pragma} Convention implies that |
| 718 |
the attribute Access is not allowed |
| 719 |
for instances of Unchecked_Conversion. |
| 720 |
@end{Reason} |
| 721 |
@end{StaticSem} |
| 722 |
|
| 723 |
@begin{RunTime} |
| 724 |
The size of the formal parameter S in an instance of |
| 725 |
Unchecked_Conversion is that of its subtype. |
| 726 |
@Redundant[This is the actual subtype passed to Source, |
| 727 |
except when the actual is an unconstrained composite subtype, |
| 728 |
in which case the subtype is constrained by the bounds or |
| 729 |
discriminants of the value of the actual expression passed to S.] |
| 730 |
|
| 731 |
@Leading@;If all of the following are true, |
| 732 |
the effect of an unchecked conversion is to return the |
| 733 |
value of an object of the target subtype whose representation is the |
| 734 |
same as that of the source object S: |
| 735 |
@begin{Itemize} |
| 736 |
S'Size = Target'Size. |
| 737 |
@begin{Ramification} |
| 738 |
Note that there is no requirement that the Sizes be known at compile |
| 739 |
time. |
| 740 |
@end{Ramification} |
| 741 |
|
| 742 |
S'Alignment = Target'Alignment. |
| 743 |
|
| 744 |
The target subtype is not an unconstrained composite subtype. |
| 745 |
|
| 746 |
@PDefn{contiguous representation} |
| 747 |
@PDefn{discontiguous representation} |
| 748 |
S and the target subtype both have a contiguous |
| 749 |
representation. |
| 750 |
|
| 751 |
The representation of S is a representation of |
| 752 |
an object of the target subtype. |
| 753 |
@end{Itemize} |
| 754 |
|
| 755 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00426-01]} |
| 756 |
Otherwise, @Chg{Version=[2],New=[if the result type is scalar, the result |
| 757 |
of the function is implementation defined, and can have an invalid |
| 758 |
representation (see @RefSecNum{Data Validity}). |
| 759 |
If the result type is nonscalar, ],Old=[]}the effect is implementation defined; |
| 760 |
in particular, the result can be abnormal |
| 761 |
(see @RefSecNum{Data Validity}). |
| 762 |
|
| 763 |
@ChgImplDef{Version=[2],Kind=[Added],Text=[@Chg{Version=[2],New=[The result |
| 764 |
of unchecked conversion for instances with scalar result types whose |
| 765 |
result is not defined by the language.],Old=[]}]} |
| 766 |
@ChgImplDef{Version=[2],Kind=[Revised],Text=[The effect of unchecked |
| 767 |
conversion@Chg{Version=[2],New=[ for instances |
| 768 |
with nonscalar result types whose effect is not defined by |
| 769 |
the language],Old=[]}.]} |
| 770 |
@begin{Reason} |
| 771 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]} |
| 772 |
@ChgAdded{Version=[2],Text=[Note the difference between these sentences; |
| 773 |
the first only says that the bits returned are implementation defined, while |
| 774 |
the latter allows any effect. The difference is because scalar objects should |
| 775 |
never be abnormal unless their assignment was disrupted or if they are a |
| 776 |
subcomponent of an abnormal composite object. Neither exception applies to |
| 777 |
instances of Unchecked_Conversion.]} |
| 778 |
@end{Reason} |
| 779 |
@begin{Ramification} |
| 780 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]} |
| 781 |
Whenever unchecked conversions are used, it is the programmer's |
| 782 |
responsibility to ensure that these conversions maintain the properties |
| 783 |
that are guaranteed by the language for objects of the target type. |
| 784 |
@Chg{Version=[2],New=[For nonscalar types, this],Old=[This]} requires the |
| 785 |
user to understand the underlying run-time model of the implementation. |
| 786 |
The execution of a program that violates these properties by means of |
| 787 |
unchecked conversions @Chg{Version=[2],New=[returning a nonscalar type ], |
| 788 |
Old=[]}is erroneous.@Chg{Version=[2],New=[ Properties of scalar types can |
| 789 |
be checked by using the Valid attribute (see @RefSecNum{The Valid Attribute}); |
| 790 |
programs can avoid violating properties of the type (and erroneous |
| 791 |
execution) by careful use of this attribute.],Old=[]} |
| 792 |
|
| 793 |
An instance of Unchecked_Conversion can be applied to an object of a |
| 794 |
private type, assuming the implementation allows it. |
| 795 |
@end{Ramification} |
| 796 |
@end{RunTime} |
| 797 |
|
| 798 |
@begin{ImplPerm} |
| 799 |
An implementation may return the result of |
| 800 |
an unchecked conversion |
| 801 |
by reference, if the Source type is not a by-copy type. |
| 802 |
@Redundant[In this case, the result of the unchecked conversion represents |
| 803 |
simply a different (read-only) view of the operand of the conversion.] |
| 804 |
@begin{Ramification} |
| 805 |
In other words, the result object of a call on an instance |
| 806 |
of Unchecked_Conversion can occupy the same storage as the |
| 807 |
formal parameter S. |
| 808 |
@end{Ramification} |
| 809 |
|
| 810 |
An implementation may place restrictions on Unchecked_Conversion. |
| 811 |
@begin{Ramification} |
| 812 |
For example, an instantiation of Unchecked_Conversion for types for |
| 813 |
which unchecked conversion doesn't make sense may be disallowed. |
| 814 |
@end{Ramification} |
| 815 |
@end{ImplPerm} |
| 816 |
|
| 817 |
@begin{ImplAdvice} |
| 818 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]} |
| 819 |
@Chg{Version=[2],New=[Since the],Old=[The]} Size of an array object |
| 820 |
@Chg{Version=[2],New=[generally does],Old=[should]} not include its |
| 821 |
bounds@Chg{Version=[2],New=[],Old=[; hence]}, the bounds should not be part |
| 822 |
of the converted data. |
| 823 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 824 |
Text=[Since the Size of an array object generally does not include its bounds, |
| 825 |
the bounds should not be part of the converted data in an instance of |
| 826 |
Unchecked_Conversion.]}]} |
| 827 |
@begin{Ramification} |
| 828 |
On the other hand, we have no advice to offer about |
| 829 |
discriminants and tag fields. |
| 830 |
@end{Ramification} |
| 831 |
|
| 832 |
The implementation should not generate unnecessary run-time checks |
| 833 |
to ensure that the representation of S is a representation of the target |
| 834 |
type. |
| 835 |
It should take advantage of the permission to return by reference |
| 836 |
when possible. |
| 837 |
Restrictions on unchecked conversions should be avoided |
| 838 |
unless required by the target environment. |
| 839 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 840 |
Text=[There should not be unnecessary run-time checks on the result of |
| 841 |
an Unchecked_Conversion; the result should be returned by reference when |
| 842 |
possible. Restrictions on Unchecked_Conversions should be avoided.]}]} |
| 843 |
@begin{ImplNote} |
| 844 |
As an example of an unnecessary run-time check, |
| 845 |
consider a record type with gaps between components. |
| 846 |
The compiler might assume that such gaps are always zero bits. |
| 847 |
If a value is produced that does not obey that assumption, |
| 848 |
then the program might misbehave. |
| 849 |
The implementation should not generate extra code to check for zero bits |
| 850 |
(except, perhaps, in a special error-checking mode). |
| 851 |
@end{ImplNote} |
| 852 |
|
| 853 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(unchecked conversion)} |
| 854 |
The recommended level of support for unchecked conversions is: |
| 855 |
@begin{Itemize} |
| 856 |
Unchecked conversions should be supported and should be reversible in |
| 857 |
the cases where this clause defines the result. |
| 858 |
@PDefn{contiguous representation} |
| 859 |
@PDefn{discontiguous representation} |
| 860 |
To enable meaningful use of unchecked conversion, |
| 861 |
a contiguous representation should be used for elementary subtypes, |
| 862 |
for statically constrained array subtypes whose component subtype is |
| 863 |
one of the subtypes described in this paragraph, |
| 864 |
and for record subtypes without discriminants |
| 865 |
whose component subtypes are described in this paragraph. |
| 866 |
@end{Itemize} |
| 867 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 868 |
Text=[The recommended level of support for Unchecked_Conversion should be |
| 869 |
followed.]}]} |
| 870 |
@end{ImplAdvice} |
| 871 |
|
| 872 |
@begin{DiffWord95} |
| 873 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-02]} |
| 874 |
@ChgAdded{Version=[2],Text=[The implementation advice about the size of |
| 875 |
array objects was moved to 13.3 so that all of the advice about Size is |
| 876 |
in one place.]} |
| 877 |
|
| 878 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]} |
| 879 |
@ChgAdded{Version=[2],Text=[Clarified that the result of Unchecked_Conversion |
| 880 |
for scalar types can be invalid, but not abnormal.]} |
| 881 |
@end{DiffWord95} |
| 882 |
|
| 883 |
|
| 884 |
@LabeledSubClause{Data Validity} |
| 885 |
|
| 886 |
@begin{Intro} |
| 887 |
Certain actions that can potentially lead to erroneous execution are not |
| 888 |
directly erroneous, |
| 889 |
but instead can cause objects to become @i{abnormal}. |
| 890 |
Subsequent uses of abnormal objects can be erroneous. |
| 891 |
|
| 892 |
A scalar object can have an @i{invalid representation}, |
| 893 |
which means that the object's representation does not represent any |
| 894 |
value of the object's subtype. |
| 895 |
@RootDefn{uninitialized variables} |
| 896 |
The primary cause of invalid representations is uninitialized variables. |
| 897 |
|
| 898 |
Abnormal objects and invalid representations are explained in this |
| 899 |
subclause. |
| 900 |
@end{Intro} |
| 901 |
|
| 902 |
@begin{RunTime} |
| 903 |
@Leading@RootDefn{normal state of an object} |
| 904 |
@RootDefn{abnormal state of an object} |
| 905 |
When an object is first created, and any explicit or default |
| 906 |
initializations have been performed, the object |
| 907 |
and all of its parts are in the @i{normal} state. |
| 908 |
Subsequent operations generally leave them normal. |
| 909 |
However, an object or part of an object can become @i{abnormal} |
| 910 |
in the following ways: |
| 911 |
@begin{Itemize} |
| 912 |
@Defn{disruption of an assignment} |
| 913 |
An assignment to the object is disrupted due to an abort |
| 914 |
(see @RefSecNum{Abort of a Task - Abort of a Sequence of Statements}) |
| 915 |
or due to the failure of a language-defined check |
| 916 |
(see @RefSecNum{Exceptions and Optimization}). |
| 917 |
|
| 918 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00426-01]} |
| 919 |
The object is not scalar, and is passed to an @key[in out] |
| 920 |
or @key[out] parameter of an imported procedure@Chg{Version=[2],New=[, |
| 921 |
the Read procedure of an instance of Sequential_IO, |
| 922 |
Direct_IO, or Storage_IO, or the stream attribute T'Read], Old=[ or |
| 923 |
language-defined input procedure]}, |
| 924 |
if after return from the procedure the representation of the parameter |
| 925 |
does not represent a value of the parameter's subtype. |
| 926 |
|
| 927 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]} |
| 928 |
@ChgAdded{Version=[2],Text=[The object is the return object of a function call |
| 929 |
of a nonscalar type, and the function is an imported function, an instance of |
| 930 |
Unchecked_Conversion, or the stream attribute T'Input, if after return from the |
| 931 |
function the representation of the return object does not represent a value of |
| 932 |
the function's subtype.]} |
| 933 |
|
| 934 |
@begin{Discussion} |
| 935 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 936 |
@ChgAdded{Version=[2],Text=[We explicitly list the routines involved in order |
| 937 |
to avoid future arguments. All possibilities are listed.]} |
| 938 |
|
| 939 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 940 |
@ChgAdded{Version=[2],Text=[We did not include Stream_IO.Read in the list |
| 941 |
above. A Stream_Element should include all possible bit patterns, and thus it |
| 942 |
cannot be invalid. Therefore, the parameter will always represent a value of |
| 943 |
its subtype. By omitting this routine, we make it possible to write arbitrary |
| 944 |
I/O operations without any possibility of abnormal objects.]} |
| 945 |
@end{Discussion} |
| 946 |
|
| 947 |
@end{Itemize} |
| 948 |
|
| 949 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]} |
| 950 |
@ChgAdded{Version=[2],Text=[@Redundant[For an imported object, it is the |
| 951 |
programmer's responsibility to ensure that the object remains in a normal |
| 952 |
state.]]} |
| 953 |
@begin{TheProof} |
| 954 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 955 |
@ChgAdded{Version=[2],Text=[This follows (and echos) the standard rule |
| 956 |
of interfacing; the programmer must ensure that Ada semantics are |
| 957 |
followed (see @RefSecNum{Interfacing Pragmas}).]} |
| 958 |
@end{TheProof} |
| 959 |
|
| 960 |
@PDefn{unspecified} |
| 961 |
Whether or not an object actually becomes abnormal in these cases is |
| 962 |
not specified. |
| 963 |
An abnormal object becomes normal again upon successful completion of |
| 964 |
an assignment to the object as a whole. |
| 965 |
@end{RunTime} |
| 966 |
|
| 967 |
@begin{Erron} |
| 968 |
@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 969 |
It is erroneous to evaluate a @nt<primary> that is a @nt<name> |
| 970 |
denoting an abnormal object, |
| 971 |
or to evaluate a @nt{prefix} that denotes an abnormal object. |
| 972 |
@begin{Ramification} |
| 973 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]} |
| 974 |
@Comment{There appears to be no justification for this statement; everything |
| 975 |
can become abnormal. We leave the prefix for the next paragraph, so we use |
| 976 |
Chg rather than ChgDeleted.} |
| 977 |
@Chg{Version=[2],New=[],Old=[Although a composite object with no |
| 978 |
subcomponents of an access type, and with static constraints all the way down |
| 979 |
cannot become abnormal, a scalar subcomponent of such an object can become |
| 980 |
abnormal.]} |
| 981 |
|
| 982 |
The @key[in out] or @key[out] parameter case does not apply to scalars; |
| 983 |
bad scalars are merely invalid representations, |
| 984 |
rather than abnormal, in this case. |
| 985 |
@end{Ramification} |
| 986 |
@begin{Reason} |
| 987 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 988 |
The reason we allow access objects, and objects containing subcomponents of an |
| 989 |
access type, to become abnormal is because the correctness of an access |
| 990 |
value cannot necessarily be determined merely by looking at the bits of |
| 991 |
the object. |
| 992 |
The reason we allow scalar objects to become abnormal is that we wish to |
| 993 |
allow the compiler to optimize assuming that the value of a scalar |
| 994 |
object belongs to the object's subtype, |
| 995 |
if the compiler can prove that the object is initialized with a value |
| 996 |
that belongs to the subtype. |
| 997 |
The reason we allow composite objects to become abnormal |
| 998 |
@Chg{Version=[2],New=[],Old=[if some constraints are nonstatic ]}is |
| 999 |
that such object might be represented with implicit levels of indirection; |
| 1000 |
if those are corrupted, then even assigning into a component of the |
| 1001 |
object, or simply asking for its Address, might have an unpredictable |
| 1002 |
effect. The same is true if the discriminants have been destroyed. |
| 1003 |
@end{Reason} |
| 1004 |
@end{Erron} |
| 1005 |
|
| 1006 |
@begin{Bounded} |
| 1007 |
@Leading@Defn{invalid representation}@PDefn2{Term=(bounded error),Sec=(cause)} |
| 1008 |
If the representation of a scalar object does not represent a value of |
| 1009 |
the object's subtype |
| 1010 |
(perhaps because the object was not initialized), |
| 1011 |
the object is said to have an @i{invalid representation}. |
| 1012 |
It is a bounded error to evaluate the value of such |
| 1013 |
an object. |
| 1014 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 1015 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 1016 |
If the error is detected, either Constraint_Error or Program_Error is |
| 1017 |
raised. |
| 1018 |
Otherwise, execution continues using the invalid representation. |
| 1019 |
The rules of the language outside this subclause assume that all objects |
| 1020 |
have valid representations. |
| 1021 |
The semantics of operations on invalid representations are as follows: |
| 1022 |
|
| 1023 |
@begin{Discussion} |
| 1024 |
|
| 1025 |
The AARM is more explicit about what happens when |
| 1026 |
the value of the case expression is an invalid representation. |
| 1027 |
|
| 1028 |
@end{Discussion} |
| 1029 |
@begin{Ramification} |
| 1030 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]} |
| 1031 |
@ChgAdded{Version=[2],Text=[This includes the result object of functions, |
| 1032 |
including the result of Unchecked_Conversion, T'Input, and imported |
| 1033 |
functions.]} |
| 1034 |
@end{Ramification} |
| 1035 |
|
| 1036 |
@begin{Itemize} |
| 1037 |
If the representation of the object represents a value of the object's |
| 1038 |
type, the value of the type is used. |
| 1039 |
|
| 1040 |
If the representation of the object does not represent a value of the |
| 1041 |
object's type, |
| 1042 |
the semantics of operations on such representations is |
| 1043 |
implementation-defined, but does not by itself lead to |
| 1044 |
erroneous or unpredictable |
| 1045 |
execution, or to other objects becoming abnormal. |
| 1046 |
@begin{ImplNote} |
| 1047 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]} |
| 1048 |
@ChgAdded{Version=[2],Text=[This means that the implementation must take care |
| 1049 |
not to use an invalid representation in a way that might cause erroneous |
| 1050 |
execution. For instance, the exception mandated for @nt{case_statement}s |
| 1051 |
must be raised. Array indexing must not cause memory outside of |
| 1052 |
the array to be written (and usually, not read either). These cases and |
| 1053 |
similar cases may require explicit checks by the implementation.]} |
| 1054 |
@end{ImplNote} |
| 1055 |
|
| 1056 |
@end{Itemize} |
| 1057 |
@end{Bounded} |
| 1058 |
|
| 1059 |
@begin{Erron} |
| 1060 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]} |
| 1061 |
@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 1062 |
A call to an imported function or an instance of Unchecked_Conversion is |
| 1063 |
erroneous if the result is scalar, @Chg{Version=[2],New=[],Old=[and ]}the |
| 1064 |
result object has an invalid representation@Chg{Version=[2],New=[, and |
| 1065 |
the result is used other than as the @nt{expression} of |
| 1066 |
an @nt{assignment_statement} or an @nt{object_declaration}, or as the |
| 1067 |
@nt{prefix} of a Valid attribute. If such a result object is used as the source |
| 1068 |
of an assignment, and the assigned value is an invalid representation for the |
| 1069 |
target of the assignment, then any use of the target object prior to a further |
| 1070 |
assignment to the target object, other than as the @nt{prefix} of a Valid |
| 1071 |
attribute reference, is erroneous],Old=[]}. |
| 1072 |
@begin{Ramification} |
| 1073 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]} |
| 1074 |
In a typical implementation, every bit pattern that fits in an object of |
| 1075 |
@Chg{Version=[2],New=[a signed],Old=[an]} integer subtype will represent a |
| 1076 |
value of the type, if not of the subtype. |
| 1077 |
However, for an enumeration or floating point type,@Chg{Version=[2],New=[ as |
| 1078 |
well as some modular types,],Old=[]} |
| 1079 |
there are typically bit patterns that do not represent any |
| 1080 |
value of the type. |
| 1081 |
In such cases, the implementation ought to define the semantics of |
| 1082 |
operations on the invalid representations in the obvious manner |
| 1083 |
(assuming the bounded error is not detected): |
| 1084 |
a given representation should be equal to itself, |
| 1085 |
a representation that is in between the internal codes of |
| 1086 |
two enumeration literals should behave accordingly when passed to |
| 1087 |
comparison operators and membership tests, etc. |
| 1088 |
We considered @i{requiring} such sensible behavior, |
| 1089 |
but it resulted in too much arcane verbiage, |
| 1090 |
and since implementations have little incentive to behave |
| 1091 |
irrationally, such verbiage is not important to have. |
| 1092 |
|
| 1093 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]} |
| 1094 |
If a stand-alone scalar object is initialized to a an in-range |
| 1095 |
value, then the implementation can take advantage of the fact |
| 1096 |
that @Chg{Version=[2],New=[the use of ],Old=[]}any out-of-range value |
| 1097 |
has to be @Chg{Version=[2],New=[erroneous],Old=[abnormal]}.@ChgNote{Do you |
| 1098 |
see "abnormal" in the rules above? Thought not.} |
| 1099 |
Such an out-of-range value can be produced only by things like |
| 1100 |
unchecked conversion, @Chg{Version=[2],New=[imported functions],Old=[input]}, |
| 1101 |
and @Chg{Version=[2],New=[abnormal values caused by ],Old=[]}disruption |
| 1102 |
of an assignment due to abort or to failure of a |
| 1103 |
language-defined check. |
| 1104 |
This depends on out-of-range values being checked before |
| 1105 |
assignment (that is, checks are not optimized away unless they |
| 1106 |
are proven redundant). |
| 1107 |
|
| 1108 |
@Leading@;Consider the following example: |
| 1109 |
@begin{Example} |
| 1110 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]} |
| 1111 |
@key[type] My_Int @key[is] @key[range] 0..99; |
| 1112 |
@key[function] Safe_Convert @key[is] @key[new] Unchecked_Conversion(My_Int, Integer); |
| 1113 |
@key[function] Unsafe_Convert @key[is] @key[new] Unchecked_Conversion(My_Int, Positive); |
| 1114 |
X : Positive := Safe_Convert(0); --@RI{ Raises Constraint_Error.} |
| 1115 |
Y : Positive := Unsafe_Convert(0); --@Chg{Version=[2],New=[@RI{ Bounded Error, may be invalid.} |
| 1116 |
B : Boolean := Y'Valid; --@RI{ OK, B = False.} |
| 1117 |
Z : Positive := Y+1; --@RI{ Erroneous to use Y.}],Old=[@RI{ Erroneous.}]} |
| 1118 |
|
| 1119 |
@end{Example} |
| 1120 |
|
| 1121 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01],ARef=[AI95-00426-01]} |
| 1122 |
The call to Unsafe_Convert @Chg{Version=[2],New=[ is a bounded error, which |
| 1123 |
might raise Constraint_Error, Program_Error, or return an invalid value. |
| 1124 |
Moreover, if an exception is not raised, most uses of that invalid value |
| 1125 |
(including the use of Y) cause],Old=[causes]} erroneous execution. |
| 1126 |
The call to Safe_Convert is not erroneous. |
| 1127 |
The result object is an object of subtype Integer containing the value 0. |
| 1128 |
The assignment to X is required to do a constraint check; |
| 1129 |
the fact that the conversion is unchecked does not obviate the need for |
| 1130 |
subsequent checks required by the language rules. |
| 1131 |
|
| 1132 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00167-01],ARef=[AI95-00426-01]} |
| 1133 |
@ChgAdded{Version=[2],Text=[The reason for delaying erroneous execution until |
| 1134 |
the object is used is so that the invalid representation can be tested |
| 1135 |
for validity using the Valid attribute (see @RefSecNum{The Valid Attribute}) |
| 1136 |
without causing execution to become erroneous. Note that this delay does not |
| 1137 |
imply an exception will not be raised; an implementation could treat both |
| 1138 |
conversions in the example in the same way and raise Constraint_Error.]} |
| 1139 |
@end{Ramification} |
| 1140 |
@begin{ImplNote} |
| 1141 |
If an implementation wants to have a @lquotes@;friendly@rquotes@; mode, it |
| 1142 |
might always assign an uninitialized scalar a default initial value |
| 1143 |
that is outside the object's subtype (if there is one), and check |
| 1144 |
for this value on some or all reads of the object, so as to help |
| 1145 |
detect references to uninitialized scalars. |
| 1146 |
Alternatively, an implementation might want to provide an |
| 1147 |
@lquotes@;unsafe@rquotes@; mode where it presumed even uninitialized scalars |
| 1148 |
were always within their subtype. |
| 1149 |
@end{ImplNote} |
| 1150 |
@begin{Ramification} |
| 1151 |
The above rules imply that it is a bounded error |
| 1152 |
to apply a predefined operator to |
| 1153 |
an object with a scalar subcomponent having an invalid representation, |
| 1154 |
since this implies reading the value of each subcomponent. |
| 1155 |
Either Program_Error or Constraint_Error is raised, |
| 1156 |
or some result is produced, which if composite, might have a corresponding |
| 1157 |
scalar subcomponent still with an invalid representation. |
| 1158 |
|
| 1159 |
Note that it is not an error to assign, convert, or pass as a parameter |
| 1160 |
a composite object with an uninitialized scalar subcomponent. |
| 1161 |
In the other hand, it is a (bounded) error to apply |
| 1162 |
a predefined operator such as =, <, and @key(xor) |
| 1163 |
to a composite operand with an invalid scalar subcomponent. |
| 1164 |
@end{Ramification} |
| 1165 |
|
| 1166 |
@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 1167 |
The dereference of an access value is erroneous if |
| 1168 |
it does not designate an object of an appropriate type or a subprogram |
| 1169 |
with an appropriate profile, |
| 1170 |
if it designates a nonexistent object, |
| 1171 |
or if it is an access-to-variable value that designates a |
| 1172 |
constant object. |
| 1173 |
@Redundant[Such an access value can exist, for example, because of |
| 1174 |
Unchecked_Deallocation, Unchecked_Access, or Unchecked_Conversion.] |
| 1175 |
@begin{Ramification} |
| 1176 |
The above mentioned Unchecked_... features are not the only causes |
| 1177 |
of such access values. |
| 1178 |
For example, interfacing to other languages can also cause the problem. |
| 1179 |
|
| 1180 |
One obscure example is if the Adjust subprogram of a controlled type |
| 1181 |
uses Unchecked_Access to create an access-to-variable value designating |
| 1182 |
a subcomponent of its controlled parameter, and saves this access value |
| 1183 |
in a global object. When Adjust is called during the initialization of a |
| 1184 |
constant object of the type, |
| 1185 |
the end result will be an access-to-variable value that designates a |
| 1186 |
constant object. |
| 1187 |
@end{Ramification} |
| 1188 |
@end{Erron} |
| 1189 |
|
| 1190 |
@begin{Notes} |
| 1191 |
Objects can become abnormal due to other kinds of actions that directly |
| 1192 |
update the object's representation; |
| 1193 |
such actions are generally considered directly erroneous, however. |
| 1194 |
@end{Notes} |
| 1195 |
|
| 1196 |
@begin{DiffWord83} |
| 1197 |
In order to reduce the amount of erroneousness, |
| 1198 |
we separate the concept of an undefined value into |
| 1199 |
objects with invalid representation (scalars only) |
| 1200 |
and abnormal objects. |
| 1201 |
|
| 1202 |
Reading an object with an invalid representation is a bounded error |
| 1203 |
rather than erroneous; |
| 1204 |
reading an abnormal object is still erroneous. |
| 1205 |
In fact, the only safe thing to do to an abnormal object is |
| 1206 |
to assign to the object as a whole. |
| 1207 |
@end{DiffWord83} |
| 1208 |
|
| 1209 |
@begin{DiffWord95} |
| 1210 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00167-01]} |
| 1211 |
@ChgAdded{Version=[2],Text=[The description of erroneous execution for |
| 1212 |
Unchecked_Conversion and imported objects was tightened up so that |
| 1213 |
using the Valid attribute to test such a value is not erroneous.]} |
| 1214 |
|
| 1215 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]} |
| 1216 |
@ChgAdded{Version=[2],Text=[Clarified the definition of objects that can |
| 1217 |
become abnormal; made sure that all of the possibilities are included.]} |
| 1218 |
@end{DiffWord95} |
| 1219 |
|
| 1220 |
|
| 1221 |
@LabeledSubClause{The Valid Attribute} |
| 1222 |
|
| 1223 |
@begin{Intro} |
| 1224 |
The Valid attribute can be used to check the validity of data produced |
| 1225 |
by unchecked conversion, input, interface to foreign languages, |
| 1226 |
and the like. |
| 1227 |
@end{Intro} |
| 1228 |
|
| 1229 |
@begin{StaticSem} |
| 1230 |
@Leading@;For @PrefixType{a |
| 1231 |
@nt<prefix> X that denotes a scalar object |
| 1232 |
@Redundant[(after any implicit dereference)]}, |
| 1233 |
the following attribute is defined: |
| 1234 |
@begin(description) |
| 1235 |
@Attribute{Prefix=<X>, AttrName=<Valid>, |
| 1236 |
Text=<Yields True if and only if |
| 1237 |
the object denoted by X is normal and has a valid |
| 1238 |
representation. |
| 1239 |
The value of this attribute is of the predefined type Boolean.>} |
| 1240 |
@begin{Ramification} |
| 1241 |
Having checked that X'Valid is True, it is safe to read the |
| 1242 |
value of X without fear of erroneous execution |
| 1243 |
caused by abnormality, |
| 1244 |
or a bounded error caused by an invalid representation. |
| 1245 |
Such a read will produce a value in the subtype of X. |
| 1246 |
@end{Ramification} |
| 1247 |
@end{description} |
| 1248 |
@EndPrefixType{} |
| 1249 |
@end{StaticSem} |
| 1250 |
|
| 1251 |
@begin{Notes} |
| 1252 |
@Leading@;Invalid data can be created in the following cases |
| 1253 |
(not counting erroneous or unpredictable execution): |
| 1254 |
@begin{Itemize} |
| 1255 |
an uninitialized scalar object, |
| 1256 |
|
| 1257 |
the result of an unchecked conversion, |
| 1258 |
|
| 1259 |
input, |
| 1260 |
|
| 1261 |
interface to another language (including machine code), |
| 1262 |
|
| 1263 |
aborting an assignment, |
| 1264 |
|
| 1265 |
disrupting an assignment due to the failure |
| 1266 |
of a language-defined check |
| 1267 |
(see @RefSecNum{Exceptions and Optimization}), and |
| 1268 |
|
| 1269 |
use of an object whose Address has been specified. |
| 1270 |
@end{Itemize} |
| 1271 |
|
| 1272 |
X'Valid is not considered to be a read of X; |
| 1273 |
hence, it is not an error to check the validity |
| 1274 |
of invalid data. |
| 1275 |
|
| 1276 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]} |
| 1277 |
@ChgAdded{Version=[2],Text=[The Valid attribute may be used to check the |
| 1278 |
result of calling an instance of Unchecked_Conversion (or any other |
| 1279 |
operation that can return invalid values). However, an exception handler |
| 1280 |
should also be provided because implementations are permitted to raise |
| 1281 |
Constraint_Error or Program_Error if they detect the use of an invalid |
| 1282 |
representation (see @RefSecNum{Data Validity}).]} |
| 1283 |
|
| 1284 |
@begin{Ramification} |
| 1285 |
If X is of an enumeration type with a representation clause, then |
| 1286 |
X'Valid checks that the value of X when viewed as an integer is one of |
| 1287 |
the specified internal codes. |
| 1288 |
@end{Ramification} |
| 1289 |
@begin{Reason} |
| 1290 |
Valid is defined only for scalar objects because the implementation |
| 1291 |
and description burden would be too high for other types. |
| 1292 |
For example, given a typical run-time model, it is impossible to check |
| 1293 |
the validity of an access value. |
| 1294 |
The same applies to composite types implemented with internal pointers. |
| 1295 |
One can check the validity of a composite object by checking the |
| 1296 |
validity of each of its scalar subcomponents. |
| 1297 |
The user should ensure that any composite types that need to be checked |
| 1298 |
for validity are represented in a way that does not involve |
| 1299 |
implementation-defined components, or gaps between components. |
| 1300 |
Furthermore, such types should not contain access subcomponents. |
| 1301 |
|
| 1302 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]} |
| 1303 |
@ChgNote{This was never true, even in Ada 95} |
| 1304 |
@ChgDeleted{Version=[2],Text=[Note that one can safely check the validity |
| 1305 |
of a composite object with |
| 1306 |
an abnormal value only if the constraints on |
| 1307 |
the object and all of its subcomponents are static. |
| 1308 |
Otherwise, evaluation of the @nt{prefix} of the @nt{attribute_reference} |
| 1309 |
causes erroneous execution (see @RefSecNum{Names}).]} |
| 1310 |
@end{Reason} |
| 1311 |
@end{Notes} |
| 1312 |
|
| 1313 |
@begin{Extend83} |
| 1314 |
@Defn{extensions to Ada 83} |
| 1315 |
X'Valid is new in Ada 95. |
| 1316 |
@end{Extend83} |
| 1317 |
|
| 1318 |
@begin{DiffWord95} |
| 1319 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]} |
| 1320 |
@ChgAdded{Version=[2],Text=[Added a note explaining that handlers for |
| 1321 |
Constraint_Error and Program_Error are needed in the general case of |
| 1322 |
testing for validity. (An implementation could document cases where these |
| 1323 |
are not necessary, but there is no language requirement.]} |
| 1324 |
@end{DiffWord95} |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
@LabeledClause{Unchecked Access Value Creation} |
| 1329 |
|
| 1330 |
@begin{Intro} |
| 1331 |
@redundant[The attribute Unchecked_Access is used to create access values |
| 1332 |
in an unsafe manner @em the programmer is responsible for preventing |
| 1333 |
@lquotes@;dangling references.@rquotes@;] |
| 1334 |
@end{Intro} |
| 1335 |
|
| 1336 |
@begin{StaticSem} |
| 1337 |
@Leading@;The following attribute is defined for @PrefixType{a @nt{prefix} X that |
| 1338 |
denotes an aliased view of an object}: |
| 1339 |
@begin{Description} |
| 1340 |
@Attribute{Prefix=<X>, AttrName=<Unchecked_Access>, |
| 1341 |
Text=<All rules and semantics that apply to |
| 1342 |
X'Access (see @RefSecNum{Operations of Access Types}) |
| 1343 |
apply also to X'Unchecked_Access, |
| 1344 |
except that, |
| 1345 |
for the purposes of accessibility rules and checks, |
| 1346 |
it is as if X were declared immediately within a library package.>} |
| 1347 |
@IndexSeeAlso{Term=[Access attribute],See=(Unchecked_Access attribute)} |
| 1348 |
@end{Description} |
| 1349 |
@EndPrefixType{} |
| 1350 |
@end{StaticSem} |
| 1351 |
|
| 1352 |
@begin{Notes} |
| 1353 |
This attribute is provided to support the situation where a local |
| 1354 |
object is to be inserted into a global linked data structure, when the |
| 1355 |
programmer knows that it will always be removed from the data structure prior |
| 1356 |
to exiting the object's scope. The Access attribute would |
| 1357 |
be illegal in this case |
| 1358 |
(see @RefSec{Operations of Access Types}). |
| 1359 |
@begin{Ramification} |
| 1360 |
@PDefn2{Term=[expected type], |
| 1361 |
Sec=(Unchecked_Access attribute)} |
| 1362 |
The expected type for X'Unchecked_Access is as for X'Access. |
| 1363 |
|
| 1364 |
If an @nt<attribute_reference> with Unchecked_Access is used |
| 1365 |
as the actual parameter for an access parameter, |
| 1366 |
an Accessibility_Check can never fail on that access |
| 1367 |
parameter. |
| 1368 |
@end{Ramification} |
| 1369 |
|
| 1370 |
There is no Unchecked_Access attribute for subprograms. |
| 1371 |
@begin{Reason} |
| 1372 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]} |
| 1373 |
Such an attribute would allow @Chg{Version=[2],New=[unsafe ], |
| 1374 |
Old=[]}@lquotes@;downward closures@rquotes@;, |
| 1375 |
where an access value designating a more nested subprogram is passed |
| 1376 |
to a less nested subprogram.@Chg{Version=[2],New=[ (Anonymous |
| 1377 |
access-to-subprogram parameters provide safe |
| 1378 |
@lquotes@;downward closures@rquotes@;.)],Old=[]} |
| 1379 |
This requires some means of reconstructing the global environment for |
| 1380 |
the more nested subprogram, |
| 1381 |
so that it can do up-level references to objects. |
| 1382 |
The two methods of implementing up-level references are displays and |
| 1383 |
static links. |
| 1384 |
If @Chg{Version=[2],New=[unsafe ],Old=[]}downward closures were |
| 1385 |
supported, |
| 1386 |
each access-to-subprogram value would have to carry the static link |
| 1387 |
or display with it. |
| 1388 |
@Chg{Version=[2],New=[We don't want to require the space and time |
| 1389 |
overhead of requiring the extra information for all access-to-subprogram |
| 1390 |
types, especially as including it |
| 1391 |
would make interfacing to other languages (like C) harder],Old=[In the case |
| 1392 |
of displays, this was judged to be infeasible, |
| 1393 |
and we don't want to disrupt implementations by forcing them |
| 1394 |
to use static links if they already use displays]}. |
| 1395 |
|
| 1396 |
If desired, an instance of Unchecked_Conversion can be used to create |
| 1397 |
an access value of a global access-to-subprogram type that |
| 1398 |
designates a local subprogram. The semantics of using |
| 1399 |
such a value are not specified by the language. |
| 1400 |
In particular, it is not specified what happens if such |
| 1401 |
subprograms make up-level references; even if the frame |
| 1402 |
being referenced still exists, the up-level reference might |
| 1403 |
go awry if the representation of a value of a global access-to-subprogram |
| 1404 |
type doesn't include a static link. |
| 1405 |
@end{Reason} |
| 1406 |
|
| 1407 |
@end{Notes} |
| 1408 |
|
| 1409 |
@LabeledClause{Storage Management} |
| 1410 |
|
| 1411 |
@begin{Intro} |
| 1412 |
@Redundant[ |
| 1413 |
@Defn{user-defined storage management} |
| 1414 |
@Defn2{Term=[storage management], Sec=(user-defined)} |
| 1415 |
@Defn{user-defined heap management} |
| 1416 |
@Defn2{Term=[heap management], Sec=(user-defined)} |
| 1417 |
Each access-to-object type has an associated storage |
| 1418 |
pool. |
| 1419 |
The storage allocated by an @nt{allocator} comes from the pool; |
| 1420 |
instances of Unchecked_Deallocation return storage to the pool. |
| 1421 |
Several access types can share the same pool.] |
| 1422 |
|
| 1423 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00435-01]} |
| 1424 |
@Redundant[A storage pool is a variable of a type in the class rooted |
| 1425 |
at Root_Storage_Pool, which is an abstract limited controlled type. |
| 1426 |
By default, the implementation chooses a @i{standard storage pool} |
| 1427 |
for each access@Chg{Version=[2],New=[-to-object],Old=[]} type. |
| 1428 |
The user may define new pool types, |
| 1429 |
and may override the choice of pool for an access@Chg{Version=[2],New=[-to-object],Old=[]} |
| 1430 |
type by specifying Storage_Pool for the type.] |
| 1431 |
@begin{Ramification} |
| 1432 |
By default, the implementation might choose to have a single global |
| 1433 |
storage pool, |
| 1434 |
which is used (by default) by all access types, |
| 1435 |
which might mean that storage is reclaimed automatically only |
| 1436 |
upon partition completion. |
| 1437 |
Alternatively, it might choose to create a new pool |
| 1438 |
at each accessibility level, |
| 1439 |
which might mean that storage is reclaimed for an access type |
| 1440 |
when leaving the appropriate scope. |
| 1441 |
Other schemes are possible. |
| 1442 |
@end{Ramification} |
| 1443 |
@end{Intro} |
| 1444 |
|
| 1445 |
@begin{Legality} |
| 1446 |
If Storage_Pool is specified for a given access type, |
| 1447 |
Storage_Size shall not be specified for it. |
| 1448 |
@begin{Reason} |
| 1449 |
The Storage_Pool determines the Storage_Size; |
| 1450 |
hence it would not make sense to specify both. |
| 1451 |
Note that this rule is simplified by the fact that the aspects in |
| 1452 |
question cannot be specified for derived types, |
| 1453 |
nor for non-first subtypes, |
| 1454 |
so we don't have to worry about whether, say, Storage_Pool on a |
| 1455 |
derived type overrides Storage_Size on the parent type. |
| 1456 |
For the same reason, @lquotes@;specified@rquotes@; means the same thing as |
| 1457 |
@lquotes@;directly specified@rquotes@; here. |
| 1458 |
@end{Reason} |
| 1459 |
@end{Legality} |
| 1460 |
|
| 1461 |
@begin{StaticSem} |
| 1462 |
@Leading@keepnext@;The following language-defined library package exists: |
| 1463 |
@begin{Example} |
| 1464 |
@key[with] Ada.Finalization; |
| 1465 |
@key[with] System.Storage_Elements; |
| 1466 |
@ChildUnit{Parent=[System],Child=[Storage_Pools]}@key[package] System.Storage_Pools @key[is] |
| 1467 |
@key{pragma} Preelaborate(System.Storage_Pools); |
| 1468 |
|
| 1469 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]} |
| 1470 |
@key[type] @AdaTypeDefn{Root_Storage_Pool} @key[is] |
| 1471 |
@key[abstract] @key[new] Ada.Finalization.Limited_Controlled @key[with] @key[private];@Chg{Version=[2],New=[ |
| 1472 |
@key[pragma] Preelaborable_Initialization(Root_Storage_Pool);],Old=[]} |
| 1473 |
|
| 1474 |
@key[procedure] @AdaSubDefn{Allocate}( |
| 1475 |
Pool : @key[in] @key[out] Root_Storage_Pool; |
| 1476 |
Storage_Address : @key[out] Address; |
| 1477 |
Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count; |
| 1478 |
Alignment : @key[in] Storage_Elements.Storage_Count) @key[is] @key[abstract]; |
| 1479 |
|
| 1480 |
@key[procedure] @AdaSubDefn{Deallocate}( |
| 1481 |
Pool : @key[in] @key[out] Root_Storage_Pool; |
| 1482 |
Storage_Address : @key[in] Address; |
| 1483 |
Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count; |
| 1484 |
Alignment : @key[in] Storage_Elements.Storage_Count) @key[is] @key[abstract]; |
| 1485 |
|
| 1486 |
@key[function] @AdaSubDefn{Storage_Size}(Pool : Root_Storage_Pool) |
| 1487 |
@key[return] Storage_Elements.Storage_Count @key[is] @key[abstract]; |
| 1488 |
|
| 1489 |
@key[private] |
| 1490 |
... -- @RI{not specified by the language} |
| 1491 |
@key[end] System.Storage_Pools; |
| 1492 |
@end{Example} |
| 1493 |
@begin{Reason} |
| 1494 |
The Alignment parameter is provided to Deallocate because some |
| 1495 |
allocation strategies require it. |
| 1496 |
If it is not needed, it can be ignored. |
| 1497 |
@end{Reason} |
| 1498 |
|
| 1499 |
@Defn{storage pool type} |
| 1500 |
@Defn{pool type} |
| 1501 |
A @i{storage pool type} (or @i{pool type}) is a descendant of |
| 1502 |
Root_Storage_Pool. |
| 1503 |
@Defn{storage pool element} |
| 1504 |
@Defn{pool element} |
| 1505 |
@Defn2{Term=[element], Sec=(of a storage pool)} |
| 1506 |
The @i{elements} of a storage pool are the objects allocated in the |
| 1507 |
pool by @nt{allocator}s. |
| 1508 |
@begin{Discussion} |
| 1509 |
In most cases, an element corresponds to a single memory block |
| 1510 |
allocated by Allocate. |
| 1511 |
However, in some cases the implementation may choose to associate |
| 1512 |
more than one memory block with a given pool element. |
| 1513 |
@end{Discussion} |
| 1514 |
|
| 1515 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1516 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00435-01]} |
| 1517 |
@Leading@;For @PrefixType{every access@Chg{Version=[2],New=[-to-object],Old=[]} subtype S}, |
| 1518 |
the following @Chg{New=[representation ],Old=[]}attributes are defined: |
| 1519 |
@begin{Description} |
| 1520 |
@Attribute{Prefix=<S>, AttrName=<Storage_Pool>, |
| 1521 |
Text=<Denotes the storage pool of the type of S. |
| 1522 |
The type of this attribute is Root_@!Storage_@!Pool'Class.>} |
| 1523 |
|
| 1524 |
@Attribute{Prefix=<S>, AttrName=<Storage_Size>, |
| 1525 |
Text=<Yields the result of calling |
| 1526 |
Storage_Size(S'Storage_Pool)@Redundant{, |
| 1527 |
which is intended to be a measure of the number of storage elements |
| 1528 |
reserved for the pool.} |
| 1529 |
The type of this attribute is @i{universal_integer}.>} |
| 1530 |
@EndPrefixType{} |
| 1531 |
@begin{Ramification} |
| 1532 |
Storage_Size is also defined for task subtypes and objects |
| 1533 |
@em see @RefSecNum{Operational and Representation Attributes}. |
| 1534 |
|
| 1535 |
Storage_Size is not a measure of how much un-allocated space is |
| 1536 |
left in the pool. |
| 1537 |
That is, it includes both allocated and unallocated space. |
| 1538 |
Implementations and users may provide a Storage_Available function |
| 1539 |
for their pools, if so desired. |
| 1540 |
@end{Ramification} |
| 1541 |
@end{Description} |
| 1542 |
|
| 1543 |
@PDefn2{Term=[specifiable], Sec=(of Storage_Size for |
| 1544 |
a non-derived access-to-object type)} |
| 1545 |
@PDefn2{Term=[specifiable], Sec=(of Storage_Pool for |
| 1546 |
a non-derived access-to-object type)} |
| 1547 |
@Defn{Storage_Pool clause} |
| 1548 |
@Defn{Storage_Size clause} |
| 1549 |
Storage_Size or Storage_Pool may be specified for |
| 1550 |
a non-derived access-to-object type |
| 1551 |
via an @nt{attribute_@!definition_@!clause}; |
| 1552 |
the @nt{name} in a Storage_Pool clause shall denote a variable. |
| 1553 |
|
| 1554 |
An @nt{allocator} of type T allocates storage from T's storage pool. |
| 1555 |
If the storage pool is a user-defined object, then |
| 1556 |
the storage is allocated by calling Allocate, |
| 1557 |
passing T'Storage_Pool as the Pool parameter. |
| 1558 |
The Size_In_Storage_Elements parameter indicates the number of storage elements |
| 1559 |
to be allocated, |
| 1560 |
and is no more than D'Max_Size_In_Storage_Elements, |
| 1561 |
where D is the designated subtype. |
| 1562 |
The Alignment parameter is D'Alignment. |
| 1563 |
@PDefn{contiguous representation} |
| 1564 |
@PDefn{discontiguous representation} |
| 1565 |
The result returned in the Storage_Address parameter is used by the |
| 1566 |
@nt{allocator} as the address of the allocated storage, |
| 1567 |
which is a contiguous block of memory of Size_In_@!Storage_@!Elements |
| 1568 |
storage elements. |
| 1569 |
@Redundant[Any exception propagated by Allocate is propagated by the |
| 1570 |
@nt{allocator}.] |
| 1571 |
@begin{Ramification} |
| 1572 |
If the implementation chooses to represent the designated |
| 1573 |
subtype in multiple pieces, |
| 1574 |
one @nt{allocator} evaluation might result in more than one call upon |
| 1575 |
Allocate. |
| 1576 |
In any case, @nt{allocator}s for the access type obtain all the required |
| 1577 |
storage for an object of the designated type by calling the |
| 1578 |
specified Allocate procedure. |
| 1579 |
|
| 1580 |
Note that the implementation does not turn other exceptions into |
| 1581 |
Storage_Error. |
| 1582 |
|
| 1583 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0111],ARef=[AI95-00103-01]} |
| 1584 |
@ChgAdded{Version=[1],Text=[If D (the designated type of T) includes |
| 1585 |
subcomponents of other access types, they will be allocated from the storage |
| 1586 |
pools for those types, even if those @nt{allocator}s are executed as part of |
| 1587 |
the @nt{allocator} of T (as part of the initialization of the object). For |
| 1588 |
instance, an access-to-task type TT may allocate the data structures used to |
| 1589 |
implement the task value from other storage pools. (In particular, the task |
| 1590 |
stack does not necessarily need to be allocated from the storage pool for |
| 1591 |
TT.)]} |
| 1592 |
@end{Ramification} |
| 1593 |
|
| 1594 |
@Defn{standard storage pool} |
| 1595 |
If Storage_Pool is not specified for a type defined by an |
| 1596 |
@nt{access_to_object_definition}, |
| 1597 |
then the implementation chooses a standard storage pool for it |
| 1598 |
in an implementation-defined manner. |
| 1599 |
@IndexCheck{Storage_Check} |
| 1600 |
@Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)} |
| 1601 |
In this case, |
| 1602 |
the exception Storage_Error is raised by an @nt{allocator} |
| 1603 |
if there is not enough storage. |
| 1604 |
It is implementation defined whether or not the implementation |
| 1605 |
provides user-accessible names for the standard pool type(s). |
| 1606 |
@ChgImplDef{Version=[2],Kind=[Deleted],Text=[@ChgDeleted{Version=[2],Text=[The |
| 1607 |
manner of choosing a storage pool for an access type when |
| 1608 |
Storage_Pool is not specified for the type.]}]} |
| 1609 |
@begin{Discussion} |
| 1610 |
@ChgRef{Version=[2],Kind=[Added]} |
| 1611 |
@ChgAdded{Version=[2],Text=[The manner of choosing a storage pool is |
| 1612 |
covered by a @DocReqName below, so it is not summarized here.]} |
| 1613 |
@end{Discussion} |
| 1614 |
@ImplDef{Whether or not the implementation |
| 1615 |
provides user-accessible names for the standard pool type(s).} |
| 1616 |
@begin{Ramification} |
| 1617 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]} |
| 1618 |
@ChgNote{This was never true.}@Chg{Version=[2],New=[],Old=[An anonymous access |
| 1619 |
type has no pool. ]}An access-to-object type defined by a |
| 1620 |
@nt{derived_type_definition} |
| 1621 |
inherits its pool from its parent type, so |
| 1622 |
all access-to-object types in the same derivation class share the same pool. |
| 1623 |
Hence the @lquotes@;defined by an @nt{access_to_object_definition}@rquotes@; wording |
| 1624 |
above. |
| 1625 |
|
| 1626 |
@PDefn{contiguous representation} |
| 1627 |
@PDefn{discontiguous representation} |
| 1628 |
There is no requirement that all storage pools be implemented using a |
| 1629 |
contiguous block of memory (although each allocation returns |
| 1630 |
a pointer to a contiguous block of memory). |
| 1631 |
@end{Ramification} |
| 1632 |
|
| 1633 |
If Storage_Size is specified for an access type, |
| 1634 |
then the Storage_Size of this pool is at least that requested, |
| 1635 |
and the storage for the pool is reclaimed when the master containing |
| 1636 |
the declaration of the access type is left. |
| 1637 |
@Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)} |
| 1638 |
If the implementation cannot satisfy the request, |
| 1639 |
Storage_Error is raised at the point of the |
| 1640 |
@nt{attribute_@!definition_@!clause}. |
| 1641 |
If neither Storage_Pool nor Storage_Size are specified, |
| 1642 |
then the meaning of Storage_Size is implementation defined. |
| 1643 |
@ChgImplDef{Version=[2],Kind=[Revised],Text=[The meaning of |
| 1644 |
Storage_Size@Chg{Version=[2], New=[ when neither the |
| 1645 |
Storage_Size nor the Storage_Pool is specified for an access type],Old=[]}.]} |
| 1646 |
@begin{Ramification} |
| 1647 |
The Storage_Size function and attribute will return the actual |
| 1648 |
size, rather than the requested size. |
| 1649 |
Comments about rounding up, zero, and negative |
| 1650 |
on task Storage_Size apply here, as well. |
| 1651 |
See also AI83-00557, AI83-00558, and AI83-00608. |
| 1652 |
|
| 1653 |
The expression in a Storage_Size clause |
| 1654 |
need not be static. |
| 1655 |
|
| 1656 |
The reclamation happens after the master is finalized. |
| 1657 |
@end{Ramification} |
| 1658 |
@begin{ImplNote} |
| 1659 |
For a pool allocated on the stack, normal stack cut-back can |
| 1660 |
accomplish the reclamation. |
| 1661 |
For a library-level pool, normal partition termination actions can |
| 1662 |
accomplish the reclamation. |
| 1663 |
@end{ImplNote} |
| 1664 |
|
| 1665 |
If Storage_Pool is specified for an access type, |
| 1666 |
then the specified pool is used. |
| 1667 |
|
| 1668 |
@PDefn{unspecified} |
| 1669 |
The effect of calling Allocate and Deallocate for a standard storage |
| 1670 |
pool directly |
| 1671 |
(rather than implicitly via an @nt{allocator} or an instance |
| 1672 |
of Unchecked_Deallocation) is unspecified. |
| 1673 |
@begin{Ramification} |
| 1674 |
For example, an @nt{allocator} might put the pool element on a |
| 1675 |
finalization list. |
| 1676 |
If the user directly Deallocates it, instead of calling an instance |
| 1677 |
of Unchecked_Deallocation, then the implementation would probably try |
| 1678 |
to finalize the object upon master completion, |
| 1679 |
which would be bad news. |
| 1680 |
Therefore, the implementation should define such situations as |
| 1681 |
erroneous. |
| 1682 |
@end{Ramification} |
| 1683 |
@end{StaticSem} |
| 1684 |
|
| 1685 |
@begin{Erron} |
| 1686 |
@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 1687 |
If Storage_Pool is specified for an access type, |
| 1688 |
then if Allocate can satisfy the request, |
| 1689 |
it should allocate a contiguous block of memory, |
| 1690 |
and return the address of the first storage element in Storage_Address. |
| 1691 |
The block should contain Size_In_Storage_Elements storage elements, |
| 1692 |
and should be aligned according to Alignment. |
| 1693 |
The allocated storage should not be used for any |
| 1694 |
other purpose while the pool element remains in existence. |
| 1695 |
If the request cannot be satisfied, |
| 1696 |
then Allocate should propagate an exception |
| 1697 |
@Redundant[(such as Storage_Error)]. |
| 1698 |
If Allocate behaves in any other manner, |
| 1699 |
then the program execution is erroneous. |
| 1700 |
@end{Erron} |
| 1701 |
|
| 1702 |
@begin{DocReq} |
| 1703 |
An implementation shall document |
| 1704 |
the set of values that a user-defined Allocate procedure needs |
| 1705 |
to accept for the Alignment parameter. |
| 1706 |
An implementation shall document |
| 1707 |
how the standard storage pool is chosen, |
| 1708 |
and how storage is allocated by standard storage pools. |
| 1709 |
@ChgImplDef{Version=[2],Kind=[Deleted],Text=[@ChgDeleted{Version=[2], |
| 1710 |
Text=[Implementation-defined aspects of storage pools.]}]} |
| 1711 |
@ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[ |
| 1712 |
The set of values that a user-defined Allocate procedure needs |
| 1713 |
to accept for the Alignment parameter. |
| 1714 |
How the standard storage pool is chosen, and how storage is allocated |
| 1715 |
by standard storage pools.]}]} |
| 1716 |
@end{DocReq} |
| 1717 |
|
| 1718 |
@begin{ImplAdvice} |
| 1719 |
An implementation should document any cases in which it dynamically |
| 1720 |
allocates heap storage for a purpose other than the evaluation of an |
| 1721 |
@nt{allocator}. |
| 1722 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1723 |
Text=[Any cases in which heap storage is dynamically allocated other than |
| 1724 |
as part of the evaluation of an @nt{allocator} should be documented.]}]} |
| 1725 |
@begin{Reason} |
| 1726 |
This is @lquotes@;@ImplAdviceTitle@rquotes@; because the term @lquotes@;heap storage@rquotes@; |
| 1727 |
is not formally definable; |
| 1728 |
therefore, it is not testable whether the implementation obeys this advice. |
| 1729 |
@end{Reason} |
| 1730 |
|
| 1731 |
A default (implementation-provided) storage pool for an |
| 1732 |
access-to-constant type should |
| 1733 |
not have overhead to support deallocation of individual objects. |
| 1734 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1735 |
Text=[A default storage pool for an access-to-constant type should |
| 1736 |
not have overhead to support deallocation of individual objects.]}]} |
| 1737 |
@begin{Ramification} |
| 1738 |
Unchecked_Deallocation is not defined for |
| 1739 |
such types. If the access-to-constant type is library-level, |
| 1740 |
then no deallocation (other than at partition completion) will |
| 1741 |
ever be necessary, so if the size needed by an @nt{allocator} |
| 1742 |
of the type is known at link-time, then the allocation |
| 1743 |
should be performed statically. |
| 1744 |
If, in addition, the initial value of the designated object is known |
| 1745 |
at compile time, the object can be allocated to read-only memory. |
| 1746 |
@end{Ramification} |
| 1747 |
@begin{ImplNote} |
| 1748 |
If the Storage_Size for an access type is specified, |
| 1749 |
the storage pool should consist of a contiguous block of memory, |
| 1750 |
possibly allocated on the stack. |
| 1751 |
The pool should contain approximately this number of |
| 1752 |
storage elements. |
| 1753 |
These storage elements should be reserved at the place of the |
| 1754 |
Storage_Size clause, |
| 1755 |
so that @nt{allocator}s cannot raise Storage_Error due to running out |
| 1756 |
of pool space until the appropriate number of storage elements has |
| 1757 |
been used up. |
| 1758 |
This approximate (possibly rounded-up) value should be used as a maximum; |
| 1759 |
the implementation should not increase the size of the pool on the fly. |
| 1760 |
If the Storage_Size for an access type is specified as zero, |
| 1761 |
then the pool should not take up any storage space, |
| 1762 |
and any @nt{allocator} for the type should raise Storage_Error. |
| 1763 |
@end{ImplNote} |
| 1764 |
@begin{Ramification} |
| 1765 |
Note that most of this is approximate, |
| 1766 |
and so cannot be (portably) tested. |
| 1767 |
That's why we make it an Implementation Note. |
| 1768 |
There is no particular number of allocations that is guaranteed to |
| 1769 |
succeed, and there is no particular number of allocations that is |
| 1770 |
guaranteed to fail. |
| 1771 |
@end{Ramification} |
| 1772 |
|
| 1773 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]} |
| 1774 |
@ChgNote{Use ChgAdded to get conditional Leading}@ChgAdded{Version=[2], |
| 1775 |
Type=[Leading],Text=[]}@Chg{Version=[2],New=[The],Old=[A]} |
| 1776 |
storage pool @Chg{Version=[2],New=[used ],Old=[]}for |
| 1777 |
@Chg{Version=[2],New=[an @nt{allocator} of ],Old=[]}an |
| 1778 |
anonymous access type should be |
| 1779 |
@Chg{Version=[2],New=[determined as follows:],Old=[created |
| 1780 |
at the point of an allocator for the type, and be reclaimed when |
| 1781 |
the designated object becomes inaccessible;]} |
| 1782 |
|
| 1783 |
@begin{Itemize} |
| 1784 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00416-01]} |
| 1785 |
@ChgAdded{Version=[2],Text=[If the @nt{allocator} is defining a |
| 1786 |
coextension (see @RefSecNum{Operations of Access Types}) of an object |
| 1787 |
being created by an outer @nt{allocator}, then |
| 1788 |
the storage pool used for the outer @nt{allocator} should also be used for |
| 1789 |
the coextension;]} |
| 1790 |
|
| 1791 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]} |
| 1792 |
@ChgAdded{Version=[2],Text=[For other access discriminants and access |
| 1793 |
parameters, the storage pool should be created at the point of the |
| 1794 |
@nt{allocator}, and be reclaimed when the allocated object becomes |
| 1795 |
inaccessible;]} |
| 1796 |
|
| 1797 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]} |
| 1798 |
@ChgAdded{Version=[2],Text=[Otherwise, a default storage pool should be |
| 1799 |
created at the point where the anonymous access type is elaborated; such |
| 1800 |
a storage pool need not support deallocation of individual objects.]} |
| 1801 |
@end{Itemize} |
| 1802 |
|
| 1803 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1804 |
Text=[Usually, a storage pool for an access discriminant or access parameter |
| 1805 |
should be created at the point of an @nt{allocator}, and be reclaimed when |
| 1806 |
the designated object becomes inaccessible. For other anonymous access types, |
| 1807 |
the pool should be created at the point where the type is elaborated and need |
| 1808 |
not support deallocation of individual objects.]}]} |
| 1809 |
|
| 1810 |
@begin{ImplNote} |
| 1811 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]} |
| 1812 |
@Chg{Version=[2],New=[For access parameters and access discriminants,], |
| 1813 |
Old=[Normally]} the "storage pool" for an anonymous access type |
| 1814 |
would not @Chg{Version=[2],New=[normally ],Old=[]}exist as a separate |
| 1815 |
entity. |
| 1816 |
Instead, the designated object of the allocator |
| 1817 |
would be allocated, in the case of an access parameter, |
| 1818 |
as a local aliased variable at the call site, and in the |
| 1819 |
case of an access discriminant, contiguous with the object |
| 1820 |
containing the discriminant. |
| 1821 |
This is similar to the way storage for @nt{aggregate}s is typically |
| 1822 |
managed. |
| 1823 |
|
| 1824 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]} |
| 1825 |
@ChgAdded{Version=[2],Text=[For other sorts of anonymous access types, this |
| 1826 |
implementation is not possible in general, as the accessibility of the |
| 1827 |
anonymous access type is that of its declaration, while the @nt{allocator} |
| 1828 |
could be more nested. In this case, a "real" storage pool is required. |
| 1829 |
Note, however, that this storage pool need not support (separate) |
| 1830 |
deallocation, as it is not possible to instantiate Unchecked_Deallocation |
| 1831 |
with an anonymous access type. (If deallocation is needed, the object should |
| 1832 |
be allocated for a named access type and converted.) Thus, deallocation only |
| 1833 |
need happen when the anonymous access type itself goes out of scope; |
| 1834 |
this is similar to the case of an access-to-constant type.]} |
| 1835 |
@end{ImplNote} |
| 1836 |
@end{ImplAdvice} |
| 1837 |
|
| 1838 |
@begin{Notes} |
| 1839 |
A user-defined storage pool type can be obtained by extending the |
| 1840 |
Root_Storage_Pool type, |
| 1841 |
and overriding the primitive subprograms Allocate, Deallocate, and |
| 1842 |
Storage_Size. |
| 1843 |
A user-defined storage pool can then be obtained by declaring |
| 1844 |
an object of the type extension. |
| 1845 |
The user can override Initialize and Finalize if there is any need |
| 1846 |
for non-trivial initialization and finalization for a user-defined |
| 1847 |
pool type. |
| 1848 |
For example, Finalize might reclaim blocks of storage that are allocated |
| 1849 |
separately from the pool object itself. |
| 1850 |
|
| 1851 |
@Leading@;The writer of the user-defined allocation and deallocation |
| 1852 |
procedures, and users of @nt{allocator}s for the associated access |
| 1853 |
type, are responsible for dealing with any interactions with |
| 1854 |
tasking. In particular: |
| 1855 |
@begin{itemize} |
| 1856 |
If the @nt{allocator}s are used in different tasks, they require |
| 1857 |
mutual exclusion. |
| 1858 |
|
| 1859 |
If they are used inside protected objects, they cannot block. |
| 1860 |
|
| 1861 |
If they are used by interrupt handlers |
| 1862 |
(see @RefSec{Interrupt Support}), |
| 1863 |
the mutual exclusion mechanism has to work properly in that context. |
| 1864 |
@end{itemize} |
| 1865 |
|
| 1866 |
The primitives Allocate, Deallocate, and Storage_Size are declared as |
| 1867 |
abstract (see @RefSecNum{Abstract Types and Subprograms}), |
| 1868 |
and therefore they have to be overridden when |
| 1869 |
a new (non-abstract) storage pool type is declared. |
| 1870 |
@begin{Ramification} |
| 1871 |
Note that the Storage_Pool attribute denotes an object, |
| 1872 |
rather than a value, |
| 1873 |
which is somewhat unusual for attributes. |
| 1874 |
|
| 1875 |
The calls to Allocate, Deallocate, and Storage_Size are dispatching |
| 1876 |
calls @em this follows from the fact that the actual parameter for |
| 1877 |
Pool is T'Storage_Pool, which is of type Root_Storage_Pool'Class. In |
| 1878 |
many cases (including all cases in which Storage_Pool is not |
| 1879 |
specified), the compiler can determine the tag statically. |
| 1880 |
However, it is possible to construct cases where it cannot. |
| 1881 |
|
| 1882 |
All access types in the same derivation class share the same pool, |
| 1883 |
whether implementation defined or user defined. |
| 1884 |
This is necessary because we allow type conversions among them |
| 1885 |
(even if they are pool-specific), |
| 1886 |
and we want pool-specific access values to always designate |
| 1887 |
an element of the right pool. |
| 1888 |
@end{Ramification} |
| 1889 |
@begin{ImplNote} |
| 1890 |
If an access type has a standard storage pool, |
| 1891 |
then the implementation doesn't actually have to follow the pool |
| 1892 |
interface described here, |
| 1893 |
since this would be semantically invisible. |
| 1894 |
For example, the allocator could conceivably be implemented with inline |
| 1895 |
code. |
| 1896 |
@end{ImplNote} |
| 1897 |
@end{Notes} |
| 1898 |
|
| 1899 |
@begin{Examples} |
| 1900 |
@Leading@;To associate an access type with a storage pool object, the user |
| 1901 |
first declares a pool object of some type derived from |
| 1902 |
Root_Storage_Pool. Then, the user defines its Storage_Pool |
| 1903 |
attribute, as follows: |
| 1904 |
|
| 1905 |
@begin{Example} |
| 1906 |
Pool_Object : Some_Storage_Pool_Type; |
| 1907 |
|
| 1908 |
@key[type] T @key[is] @key[access] Designated; |
| 1909 |
@key[for] T'Storage_Pool @key[use] Pool_Object; |
| 1910 |
@end{Example} |
| 1911 |
|
| 1912 |
@begin{Wide} |
| 1913 |
@Leading@;Another access type may be added to an existing storage pool, via: |
| 1914 |
@end{Wide} |
| 1915 |
@begin{Example} |
| 1916 |
@key[for] T2'Storage_Pool @key[use] T'Storage_Pool; |
| 1917 |
@end{Example} |
| 1918 |
|
| 1919 |
The semantics of this is implementation defined |
| 1920 |
for a standard storage pool. |
| 1921 |
@begin{Reason} |
| 1922 |
For example, the implementation is allowed to choose a storage pool |
| 1923 |
for T that takes advantage of the fact that T is of a certain size. |
| 1924 |
If T2 is not of that size, then the above will probably not work. |
| 1925 |
@end{Reason} |
| 1926 |
|
| 1927 |
@Leading@;As usual, a derivative of Root_Storage_Pool may define additional |
| 1928 |
operations. For example, presuming that Mark_Release_Pool_Type has |
| 1929 |
two additional operations, Mark and Release, |
| 1930 |
the following is a possible use: |
| 1931 |
@begin{Example} |
| 1932 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0041],ARef=[AI95-00066-01]} |
| 1933 |
@key[type] Mark_Release_Pool_Type |
| 1934 |
(Pool_Size : Storage_Elements.Storage_Count; |
| 1935 |
Block_Size : Storage_Elements.Storage_Count) |
| 1936 |
@key[is] @key[new] Root_Storage_Pool @key[with @Chg{New=[],Old=[limited ]}private]; |
| 1937 |
|
| 1938 |
... |
| 1939 |
|
| 1940 |
MR_Pool : Mark_Release_Pool_Type (Pool_Size => 2000, |
| 1941 |
Block_Size => 100); |
| 1942 |
|
| 1943 |
@key[type] Acc @key[is] @key[access] ...; |
| 1944 |
@key[for] Acc'Storage_Pool @key[use] MR_Pool; |
| 1945 |
... |
| 1946 |
|
| 1947 |
Mark(MR_Pool); |
| 1948 |
... --@RI{ Allocate objects using @lquotes@;@key[new] Designated(...)@rquotes@;.} |
| 1949 |
Release(MR_Pool); --@RI{ Reclaim the storage.} |
| 1950 |
@end{Example} |
| 1951 |
@end{Examples} |
| 1952 |
|
| 1953 |
@begin{Extend83} |
| 1954 |
@Defn{extensions to Ada 83} |
| 1955 |
User-defined storage pools are new to Ada 95. |
| 1956 |
@end{Extend83} |
| 1957 |
|
| 1958 |
@begin{DiffWord83} |
| 1959 |
Ada 83 had a concept called a @lquotes@;collection,@rquotes@; |
| 1960 |
which is similar to what we call a storage pool. |
| 1961 |
All access types in the same derivation class |
| 1962 |
shared the same collection. |
| 1963 |
In Ada 95, all access types in the same derivation class |
| 1964 |
share the same storage pool, |
| 1965 |
but other (unrelated) access types can also share the same storage pool, |
| 1966 |
either by default, or as specified by the user. |
| 1967 |
A collection was an amorphous collection of objects; |
| 1968 |
a storage pool is a more concrete concept @em hence |
| 1969 |
the different name. |
| 1970 |
|
| 1971 |
RM83 states the erroneousness of reading or updating deallocated |
| 1972 |
objects incorrectly by missing various cases. |
| 1973 |
@end{DiffWord83} |
| 1974 |
|
| 1975 |
@begin{Incompatible95} |
| 1976 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00435-01]} |
| 1977 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 1978 |
@b<Amendment Correction:> Storage pools (and Storage_Size) |
| 1979 |
are not defined for access-to-subprogram types. The original Ada 95 wording |
| 1980 |
defined the attributes, but said nothing about their values. |
| 1981 |
If a program uses attributes Storage_Pool or Storage_Size on an |
| 1982 |
access-to-subprogram type, it will need to be corrected for Ada 2005. |
| 1983 |
That's a good thing, as such a use is a bug @em the concepts |
| 1984 |
never were defined for such types.]} |
| 1985 |
@end{Incompatible95} |
| 1986 |
|
| 1987 |
@begin{Extend95} |
| 1988 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]} |
| 1989 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1990 |
@b[Amendment Correction:] Added @nt{pragma} Preelaborable_Initialization to |
| 1991 |
type Root_Storage_Pool, so that extensions of it can be used to declare |
| 1992 |
default-initialized objects in preelaborated units.]} |
| 1993 |
@end{Extend95} |
| 1994 |
|
| 1995 |
|
| 1996 |
@begin{DiffWord95} |
| 1997 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1998 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that |
| 1999 |
these are representation attributes.]} |
| 2000 |
|
| 2001 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00416-01]} |
| 2002 |
@ChgAdded{Version=[2],Text=[Added wording to clarify that an @nt{allocator} |
| 2003 |
for a coextension nested inside an outer @nt{allocator} shares |
| 2004 |
the pool with the outer @nt{allocator}.]} |
| 2005 |
@end{DiffWord95} |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
@LabeledSubClause{The Max_Size_In_Storage_Elements Attribute} |
| 2010 |
|
| 2011 |
@begin{Intro} |
| 2012 |
@redundant[The Max_Size_In_Storage_Elements attribute is useful in writing user-defined pool |
| 2013 |
types.] |
| 2014 |
@end{Intro} |
| 2015 |
|
| 2016 |
@begin{StaticSem} |
| 2017 |
@Leading@;For @PrefixType{every subtype S}, |
| 2018 |
the following attribute is defined: |
| 2019 |
@begin{Description} |
| 2020 |
@ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T], |
| 2021 |
Leading=<F>, Prefix=<S>, AttrName=<Max_Size_In_Storage_Elements>, |
| 2022 |
ARef=[AI95-00256-01],ARef=[AI95-00416-01], |
| 2023 |
Text=<Denotes the maximum value for Size_In_Storage_Elements |
| 2024 |
that @Chg{Version=[2],New=[could],Old=[will]} be requested @Chg{Version=[2], |
| 2025 |
New=[by the implementation ],Old=[]}via Allocate for an access type whose |
| 2026 |
designated subtype is S.@Chg{Version=[2],New=[ For a type with access |
| 2027 |
discriminants, if the implementation allocates space for a coextension |
| 2028 |
in the same pool as that of the object having the access discriminant, |
| 2029 |
then this accounts for any calls on Allocate that could be performed to |
| 2030 |
provide space for such coextensions.],Old=[]} |
| 2031 |
The value of this attribute is of type @i{universal_integer}.>} |
| 2032 |
@EndPrefixType{} |
| 2033 |
@begin{Ramification} |
| 2034 |
If S is an unconstrained array subtype, |
| 2035 |
or an unconstrained subtype with discriminants, |
| 2036 |
S'Max_Size_In_Storage_Elements might be very large. |
| 2037 |
@end{Ramification} |
| 2038 |
@end{Description} |
| 2039 |
@end{StaticSem} |
| 2040 |
|
| 2041 |
@begin{DiffWord95} |
| 2042 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00256-01]} |
| 2043 |
@ChgAdded{Version=[2],Text=[Corrected the wording so that a |
| 2044 |
fortune-telling compiler that can see the future execution of the |
| 2045 |
program is not required.]} |
| 2046 |
@end{DiffWord95} |
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
@RMNewPage@Comment{For printed Ada 2005 RM only} |
| 2051 |
@LabeledSubClause{Unchecked Storage Deallocation} |
| 2052 |
|
| 2053 |
@begin{Intro} |
| 2054 |
@redundant[@Defn{unchecked storage deallocation} |
| 2055 |
@Defn2{Term=[storage deallocation], Sec=(unchecked)} |
| 2056 |
@Defn{deallocation of storage} |
| 2057 |
@Defn{reclamation of storage} |
| 2058 |
@Defn{freeing storage} |
| 2059 |
Unchecked storage deallocation of an object designated by a value of an |
| 2060 |
access type is achieved by a call to an instance of |
| 2061 |
the generic procedure Unchecked_Deallocation.] |
| 2062 |
@end{Intro} |
| 2063 |
|
| 2064 |
@begin{StaticSem} |
| 2065 |
@leading@keepnext@;The following language-defined generic library procedure exists: |
| 2066 |
@begin{Example} |
| 2067 |
@key[generic] |
| 2068 |
@key[type] Object(<>) @key[is] @key[limited] @key[private]; |
| 2069 |
@key[type] Name @key[is] @key[access] Object; |
| 2070 |
@SubChildUnit{Parent=[Ada],Child=[Unchecked_Deallocation]}@key[procedure] Ada.Unchecked_Deallocation(X : @key[in] @key[out] Name); |
| 2071 |
@key[pragma] Convention(Intrinsic, Ada.Unchecked_Deallocation); |
| 2072 |
@key[pragma] Preelaborate(Ada.Unchecked_Deallocation); |
| 2073 |
@end{Example} |
| 2074 |
@begin{Reason} |
| 2075 |
The @nt{pragma} Convention implies that |
| 2076 |
the attribute Access is not allowed |
| 2077 |
for instances of Unchecked_Deallocation. |
| 2078 |
@end{Reason} |
| 2079 |
@end{StaticSem} |
| 2080 |
|
| 2081 |
@begin{RunTime} |
| 2082 |
@Leading@;Given an instance of Unchecked_Deallocation |
| 2083 |
declared as follows: |
| 2084 |
@begin{Example} |
| 2085 |
@key[procedure] Free @key[is] |
| 2086 |
@key[new] Ada.Unchecked_Deallocation( |
| 2087 |
@RI[object_subtype_name], @RI[access_to_variable_subtype_name]); |
| 2088 |
@end{Example} |
| 2089 |
|
| 2090 |
@begin{Wide} |
| 2091 |
@Leading@Keepnext@;Procedure Free has the following effect: |
| 2092 |
@end{Wide} |
| 2093 |
@begin{Enumerate} |
| 2094 |
After executing Free(X), the value of X is @key{null}. |
| 2095 |
|
| 2096 |
Free(X), when X is already equal to @key{null}, has no effect. |
| 2097 |
|
| 2098 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]} |
| 2099 |
Free(X), when X is not equal to @key{null} first |
| 2100 |
performs finalization@Chg{Version=[2],New=[ of the object designated by X (and |
| 2101 |
any coextensions of the object @em see @RefSecNum{Operations of Access Types})], |
| 2102 |
Old=[]}, as described in |
| 2103 |
@Chg{Version=[2],New=[@RefSecNum{Completion and Finalization}], |
| 2104 |
Old=[@RefSecNum{User-Defined Assignment and Finalization}]}. |
| 2105 |
It then deallocates the storage occupied by the object designated by |
| 2106 |
X@Chg{Version=[2],New=[ (and any coextensions)],Old=[]}. |
| 2107 |
If the storage pool is a user-defined object, then |
| 2108 |
the storage is deallocated by calling Deallocate, |
| 2109 |
passing @i[access_to_@!variable_@!subtype_name]'Storage_Pool as the Pool parameter. |
| 2110 |
Storage_Address is the value returned in the Storage_Address parameter of the |
| 2111 |
corresponding Allocate call. |
| 2112 |
Size_In_@!Storage_@!Elements and Alignment are the same values passed to the |
| 2113 |
corresponding Allocate call. |
| 2114 |
There is one exception: if the object being freed contains tasks, |
| 2115 |
the object might not be deallocated. |
| 2116 |
@begin{Ramification} |
| 2117 |
Free calls only the specified Deallocate procedure |
| 2118 |
to do deallocation. |
| 2119 |
For any given object deallocation, |
| 2120 |
the number of calls to Free (usually one) |
| 2121 |
will be equal to the number of Allocate calls it took |
| 2122 |
to allocate the object. |
| 2123 |
We do not define the relative order of multiple calls used to deallocate |
| 2124 |
the same object @em that is, if the @nt{allocator} allocated two pieces @i{x} |
| 2125 |
and @i{y}, then Free might deallocate @i{x} and then @i{y}, |
| 2126 |
or it might deallocate @i{y} and then @i{x}. |
| 2127 |
@end{Ramification} |
| 2128 |
@end{Enumerate} |
| 2129 |
|
| 2130 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]} |
| 2131 |
@IndexSee{Term=[freed],See=(nonexistent)} |
| 2132 |
@Defn{nonexistent} |
| 2133 |
@PDefn2{Term=[exist],Sec=[cease to]} |
| 2134 |
@PDefn2{Term=[cease to exist],Sec=[object]} |
| 2135 |
After Free(X), the object designated by X, and any |
| 2136 |
subcomponents @Chg{Version=[2],New=[(and coextensions) ],Old=[]}thereof, no |
| 2137 |
longer exist; their storage can be reused for other purposes. |
| 2138 |
@end{RunTime} |
| 2139 |
|
| 2140 |
@begin{Bounded} |
| 2141 |
@Leading@PDefn2{Term=(bounded error),Sec=(cause)} |
| 2142 |
It is a bounded error to free a discriminated, unterminated |
| 2143 |
task object. The possible consequences are: |
| 2144 |
@begin{Reason} |
| 2145 |
This is an error because the task might refer to its discriminants, |
| 2146 |
and the discriminants might be deallocated by freeing the task object. |
| 2147 |
@end{Reason} |
| 2148 |
@begin{Itemize} |
| 2149 |
No exception is raised. |
| 2150 |
|
| 2151 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 2152 |
@Defn2{Term=[Tasking_Error],Sec=(raised by failure of run-time check)} |
| 2153 |
Program_Error or Tasking_Error is raised at the point of the |
| 2154 |
deallocation. |
| 2155 |
|
| 2156 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 2157 |
@Defn2{Term=[Tasking_Error],Sec=(raised by failure of run-time check)} |
| 2158 |
Program_Error or Tasking_Error is raised in the task the next time it |
| 2159 |
references any of the discriminants. |
| 2160 |
@begin{ImplNote} |
| 2161 |
This last case presumes an implementation where the task references |
| 2162 |
its discriminants indirectly, |
| 2163 |
and the pointer is nulled out when the task object is deallocated. |
| 2164 |
@end{ImplNote} |
| 2165 |
@end{Itemize} |
| 2166 |
|
| 2167 |
In the first two cases, |
| 2168 |
the storage for the discriminants |
| 2169 |
(and for any enclosing object if it is designated by an access |
| 2170 |
discriminant of the task) |
| 2171 |
is not reclaimed prior to task termination. |
| 2172 |
@begin{Ramification} |
| 2173 |
The storage might never be reclaimed. |
| 2174 |
@end{Ramification} |
| 2175 |
@end{Bounded} |
| 2176 |
|
| 2177 |
@begin{Erron} |
| 2178 |
@Defn{nonexistent}@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 2179 |
Evaluating a name that denotes a nonexistent object is erroneous. |
| 2180 |
The execution of a call to an instance of Unchecked_Deallocation is |
| 2181 |
erroneous if the object was created other than by an @nt<allocator> for |
| 2182 |
an access type whose pool is Name'Storage_Pool. |
| 2183 |
@end{Erron} |
| 2184 |
|
| 2185 |
@begin{ImplAdvice} |
| 2186 |
For a standard storage pool, |
| 2187 |
Free should actually reclaim the storage. |
| 2188 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 2189 |
Text=[For a standard storage pool, an instance of Unchecked_Deallocation |
| 2190 |
should actually reclaim the storage.]}]} |
| 2191 |
@begin{Ramification} |
| 2192 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 2193 |
This is not a testable property, |
| 2194 |
since we do not @Chg{Version=[2],New=[know ],Old=[]}how much storage is used |
| 2195 |
by a given pool element, nor whether fragmentation can occur. |
| 2196 |
@end{Ramification} |
| 2197 |
|
| 2198 |
@end{ImplAdvice} |
| 2199 |
|
| 2200 |
@begin{Notes} |
| 2201 |
The rules here that refer to Free apply to any instance |
| 2202 |
of Unchecked_Deallocation. |
| 2203 |
|
| 2204 |
Unchecked_Deallocation cannot be instantiated for an |
| 2205 |
access-to-constant type. |
| 2206 |
This is implied by the rules of @RefSecNum{Formal Access Types}. |
| 2207 |
@end{Notes} |
| 2208 |
|
| 2209 |
@begin{DiffWord95} |
| 2210 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 2211 |
@ChgAdded{Version=[2],Text=[The rules for coextensions are clarified |
| 2212 |
(mainly by adding that term). In theory, this reflects no change from |
| 2213 |
Ada 95 (coextensions existed in Ada 95, they just didn't have a name).]} |
| 2214 |
@end{DiffWord95} |
| 2215 |
|
| 2216 |
|
| 2217 |
@LabeledSubClause{Pragma Controlled} |
| 2218 |
|
| 2219 |
@begin{Intro} |
| 2220 |
@Redundant[Pragma Controlled is used to prevent any automatic |
| 2221 |
reclamation of storage (garbage collection) for the objects |
| 2222 |
created by @nt<allocator>s of a given access type.] |
| 2223 |
@end{Intro} |
| 2224 |
|
| 2225 |
@begin{Syntax} |
| 2226 |
@begin{SyntaxText} |
| 2227 |
@Leading@Keepnext@;The form of a @nt{pragma} Controlled is as follows: |
| 2228 |
@end{SyntaxText} |
| 2229 |
|
| 2230 |
@PragmaSyn`@key{pragma} @prag(Controlled)(@SynI{first_subtype_}@Syn2{local_name});' |
| 2231 |
@begin{Discussion} |
| 2232 |
Not to be confused with type Finalization.Controlled. |
| 2233 |
@end{Discussion} |
| 2234 |
@end{Syntax} |
| 2235 |
|
| 2236 |
@begin{Legality} |
| 2237 |
The @SynI{first_subtype_}@nt<local_name> of a @nt{pragma} Controlled |
| 2238 |
shall denote a non-derived access subtype. |
| 2239 |
@end{Legality} |
| 2240 |
|
| 2241 |
@begin{StaticSem} |
| 2242 |
@PDefn2{Term=[representation pragma], Sec=(Controlled)} |
| 2243 |
@PDefn2{Term=[pragma, representation], Sec=(Controlled)} |
| 2244 |
A @nt{pragma} Controlled is a representation pragma |
| 2245 |
@PDefn2{Term=[aspect of representation], Sec=(controlled)} |
| 2246 |
@Defn2{Term=[controlled], Sec=(aspect of representation)} |
| 2247 |
that specifies the @i{controlled} aspect of representation. |
| 2248 |
|
| 2249 |
@Defn{garbage collection} |
| 2250 |
@i{Garbage collection} is a process that automatically reclaims storage, |
| 2251 |
or moves objects to a different address, |
| 2252 |
while the objects still exist. |
| 2253 |
@begin{Ramification} |
| 2254 |
Storage reclamation upon leaving a master is not considered garbage |
| 2255 |
collection. |
| 2256 |
|
| 2257 |
Note that garbage collection includes compaction of a pool |
| 2258 |
(@lquotes@;moved to a different Address@rquotes@;), even if storage reclamation is not |
| 2259 |
done. |
| 2260 |
@end{Ramification} |
| 2261 |
@begin{Reason} |
| 2262 |
Programs that will be damaged by automatic storage reclamation |
| 2263 |
are just as likely to be damaged by having objects moved to different |
| 2264 |
locations in memory. |
| 2265 |
A @nt{pragma} Controlled should turn off both flavors of garbage collection. |
| 2266 |
@end{Reason} |
| 2267 |
@begin{ImplNote} |
| 2268 |
If garbage collection reclaims the storage of a controlled object, |
| 2269 |
it should first finalize it. |
| 2270 |
Finalization is not done when moving an object; |
| 2271 |
any self-relative pointers will have to be updated by the garbage |
| 2272 |
collector. |
| 2273 |
If an implementation provides garbage collection |
| 2274 |
for a storage pool containing controlled objects |
| 2275 |
(see @RefSecNum{User-Defined Assignment and Finalization}), |
| 2276 |
then it should provide a means for deferring garbage collection of |
| 2277 |
those controlled objects. |
| 2278 |
@end{ImplNote} |
| 2279 |
@begin{Reason} |
| 2280 |
@Leading@;This allows the manager of a resource released by a |
| 2281 |
Finalize operation to defer garbage collection during its critical regions; |
| 2282 |
it is up to the author of the Finalize operation to do so. |
| 2283 |
Garbage collection, at least in some systems, |
| 2284 |
can happen asynchronously with respect to normal user code. |
| 2285 |
Note that it is not enough to defer garbage collection |
| 2286 |
during Initialize, Adjust, and Finalize, |
| 2287 |
because the resource in question might be used |
| 2288 |
in other situations as well. |
| 2289 |
For example: |
| 2290 |
@begin{Example} |
| 2291 |
@key[with] Ada.Finalization; |
| 2292 |
@key[package] P @key[is] |
| 2293 |
|
| 2294 |
@key[type] My_Controlled @key[is] |
| 2295 |
@key[new] Ada.Finalization.Limited_Controlled @key[with] @key[private]; |
| 2296 |
@key[procedure] Finalize(Object : @key[in] @key[out] My_Controlled); |
| 2297 |
@key[type] My_Controlled_Access @key[is] @key[access] My_Controlled; |
| 2298 |
|
| 2299 |
@key[procedure] Non_Reentrant; |
| 2300 |
|
| 2301 |
@key[private] |
| 2302 |
... |
| 2303 |
@key[end] P; |
| 2304 |
|
| 2305 |
@key[package] @key[body] P @key[is] |
| 2306 |
X : Integer := 0; |
| 2307 |
A : @key[array](Integer @key[range] 1..10) @key[of] Integer; |
| 2308 |
|
| 2309 |
@key[procedure] Non_Reentrant @key[is] |
| 2310 |
@key[begin] |
| 2311 |
X := X + 1; |
| 2312 |
--@RI{ If the system decides to do a garbage collection here,} |
| 2313 |
--@RI{ then we're in trouble, because it will call Finalize on} |
| 2314 |
--@RI{ the collected objects; we essentially have two threads} |
| 2315 |
--@RI{ of control erroneously accessing shared variables.} |
| 2316 |
--@RI{ The garbage collector behaves like a separate thread} |
| 2317 |
--@RI{ of control, even though the user hasn't declared} |
| 2318 |
--@RI{ any tasks.} |
| 2319 |
A(X) := ...; |
| 2320 |
@key[end] Non_Reentrant; |
| 2321 |
|
| 2322 |
@key[procedure] Finalize(Object : @key[in] @key[out] My_Controlled) @key[is] |
| 2323 |
@key[begin] |
| 2324 |
Non_Reentrant; |
| 2325 |
@key[end] Finalize; |
| 2326 |
@key[end] P; |
| 2327 |
|
| 2328 |
@key[with] P; @key[use] P; |
| 2329 |
@key[procedure] Main @key[is] |
| 2330 |
@key[begin] |
| 2331 |
... @key[new] My_Controlled ... --@RI{ allocate some objects} |
| 2332 |
... @RI{ forget the pointers to some of them, so they become garbage} |
| 2333 |
Non_Reentrant; |
| 2334 |
@key[end] Main; |
| 2335 |
@end{Example} |
| 2336 |
|
| 2337 |
It is the user's responsibility to protect against this sort of |
| 2338 |
thing, and the implementation's responsibility to provide the |
| 2339 |
necessary operations. |
| 2340 |
|
| 2341 |
We do not give these operations names, |
| 2342 |
nor explain their exact semantics, |
| 2343 |
because different implementations of garbage collection might have |
| 2344 |
different needs, and because garbage collection is not supported by |
| 2345 |
most Ada implementations, so portability is not important here. |
| 2346 |
Another reason not to |
| 2347 |
turn off garbage collection during each entire |
| 2348 |
Finalize operation is that it would create a serial bottleneck; |
| 2349 |
it might be only part of the Finalize operation that conflicts with |
| 2350 |
some other resource. |
| 2351 |
It is the intention that the mechanisms provided be finer-grained |
| 2352 |
than pragma Controlled. |
| 2353 |
@end{Reason} |
| 2354 |
|
| 2355 |
If a @nt{pragma} Controlled is specified for an access type |
| 2356 |
with a standard storage pool, |
| 2357 |
then garbage collection is not performed for objects in that pool. |
| 2358 |
@begin{Ramification} |
| 2359 |
If Controlled is not specified, |
| 2360 |
the implementation may, but need not, perform garbage |
| 2361 |
collection. |
| 2362 |
If Storage_Pool is specified, |
| 2363 |
then a @nt{pragma} Controlled for that type is ignored. |
| 2364 |
@end{Ramification} |
| 2365 |
@begin{Reason} |
| 2366 |
Controlled means that implementation-provided garbage collection is |
| 2367 |
turned off; |
| 2368 |
if the Storage_Pool is specified, the pool controls |
| 2369 |
whether garbage collection is done. |
| 2370 |
@end{Reason} |
| 2371 |
@end{StaticSem} |
| 2372 |
|
| 2373 |
@begin{ImplPerm} |
| 2374 |
An implementation need not support garbage collection, in which case, |
| 2375 |
a pragma Controlled has no effect. |
| 2376 |
@end{ImplPerm} |
| 2377 |
|
| 2378 |
@begin{DiffWord83} |
| 2379 |
Ada 83 used the term @lquotes@;automatic storage reclamation@rquotes@; to refer to what |
| 2380 |
is known traditionally as @lquotes@;garbage collection@rquotes@;. |
| 2381 |
Because of the existence of storage pools |
| 2382 |
(see @RefSecNum{Storage Management}), |
| 2383 |
we need to distinguish this from the storage reclamation that might |
| 2384 |
happen upon leaving a master. |
| 2385 |
Therefore, we now use the term @lquotes@;garbage collection@rquotes@; |
| 2386 |
in its normal computer-science sense. |
| 2387 |
This has the additional advantage of making our terminology more |
| 2388 |
accessible to people outside the Ada world. |
| 2389 |
@end{DiffWord83} |
| 2390 |
|
| 2391 |
|
| 2392 |
@LabeledClause{Pragma Restrictions} |
| 2393 |
|
| 2394 |
@begin{Intro} |
| 2395 |
@redundant[A @nt{pragma} Restrictions expresses the user's intent to abide by |
| 2396 |
certain restrictions. |
| 2397 |
This may facilitate the construction of |
| 2398 |
simpler run-time environments.] |
| 2399 |
@end{Intro} |
| 2400 |
|
| 2401 |
@begin{Syntax} |
| 2402 |
@begin{SyntaxText} |
| 2403 |
@Leading@keepnext@;The form of a @nt{pragma} Restrictions is as follows: |
| 2404 |
@end{SyntaxText} |
| 2405 |
|
| 2406 |
@PragmaSyn`@key{pragma} @prag(Restrictions)(@Syn2{restriction}{, @Syn2{restriction}});' |
| 2407 |
|
| 2408 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00381-01]} |
| 2409 |
@Syn{lhs=(restriction), rhs="@SynI{restriction_}@Syn2{identifier} |
| 2410 |
| @SynI{restriction_parameter_}@Syn2{identifier} => @Chg{Version=[2],New=[@Syn2{restriction_parameter_argument}],Old=[@Syn2{expression}]}"} |
| 2411 |
|
| 2412 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00381-01]} |
| 2413 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<restriction_parameter_argument>,Old=<>}>, |
| 2414 |
rhs="@Chg{Version=[2],New=<@Syn2{name} | @Syn2{expression}>,Old=<>}"} |
| 2415 |
|
| 2416 |
@end{Syntax} |
| 2417 |
|
| 2418 |
@begin{Resolution} |
| 2419 |
@PDefn2{Term=[expected type], |
| 2420 |
Sec=(restriction parameter expression)} |
| 2421 |
Unless otherwise specified for a particular restriction, |
| 2422 |
the @nt{expression} is expected to be of any integer type. |
| 2423 |
@end{Resolution} |
| 2424 |
|
| 2425 |
@begin{Legality} |
| 2426 |
Unless otherwise specified for a particular restriction, |
| 2427 |
the @nt{expression} shall be static, |
| 2428 |
and its value shall be nonnegative. |
| 2429 |
@end{Legality} |
| 2430 |
|
| 2431 |
@begin{StaticSem} |
| 2432 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00394-01]} |
| 2433 |
The set of @Chg{Version=[2],New=[restrictions],Old=[@ntf{restrictions}]} is |
| 2434 |
implementation defined. |
| 2435 |
@ChgImplDef{Version=[2],Kind=[Revised],Text=[The set of |
| 2436 |
@Chg{Version=[2],New=[restrictions],Old=[@ntf{restrictions}]} |
| 2437 |
allowed in a @nt{pragma} Restrictions.]} |
| 2438 |
@end{StaticSem} |
| 2439 |
|
| 2440 |
@begin{LinkTime} |
| 2441 |
@PDefn2{Term=[configuration pragma], Sec=(Restrictions)} |
| 2442 |
@PDefn2{Term=[pragma, configuration], Sec=(Restrictions)} |
| 2443 |
A @nt{pragma} Restrictions is a configuration pragma; |
| 2444 |
unless otherwise specified for a particular restriction, |
| 2445 |
a partition shall obey the restriction |
| 2446 |
if a @nt{pragma} Restrictions applies to any compilation unit |
| 2447 |
included in the partition. |
| 2448 |
|
| 2449 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]} |
| 2450 |
@ChgAdded{Version=[1],Type=[Leading],Text=[For the purpose of checking whether |
| 2451 |
a partition contains constructs that violate any restriction (unless specified |
| 2452 |
otherwise for a particular restriction):]} |
| 2453 |
|
| 2454 |
@begin{itemize} |
| 2455 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]} |
| 2456 |
@ChgAdded{Version=[1],Text=[Generic instances are logically expanded at the |
| 2457 |
point of instantiation;]} |
| 2458 |
|
| 2459 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]} |
| 2460 |
@ChgAdded{Version=[1],Text=[If an object of a type is declared or allocated and |
| 2461 |
not explicitly initialized, then all expressions appearing in the definition |
| 2462 |
for the type and any of its ancestors are presumed to be used;]} |
| 2463 |
|
| 2464 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]} |
| 2465 |
@ChgAdded{Version=[1],Text=[A @nt{default_expression} for a formal parameter or |
| 2466 |
a generic formal object is considered to be used if and only if the |
| 2467 |
corresponding actual parameter is not provided in a given call or |
| 2468 |
instantiation.]} |
| 2469 |
@end{itemize} |
| 2470 |
@end{LinkTime} |
| 2471 |
|
| 2472 |
@begin{ImplPerm} |
| 2473 |
An implementation may place limitations on the values of the |
| 2474 |
@nt{expression} that are supported, |
| 2475 |
and limitations on the supported combinations of restrictions. |
| 2476 |
The consequences of violating such limitations are |
| 2477 |
implementation defined. |
| 2478 |
@ImplDef{The consequences of violating limitations on |
| 2479 |
Restrictions @nt{pragma}s.} |
| 2480 |
@begin{Ramification} |
| 2481 |
Such limitations may be enforced at compile time or at run time. |
| 2482 |
Alternatively, the implementation is allowed to declare violations of |
| 2483 |
the restrictions to be erroneous, and not enforce them at all. |
| 2484 |
@end{Ramification} |
| 2485 |
|
| 2486 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]} |
| 2487 |
@ChgAdded{Version=[1],Text=[An implementation is permitted to omit restriction |
| 2488 |
checks for code that is recognized at compile time to be unreachable and for |
| 2489 |
which no code is generated.]} |
| 2490 |
|
| 2491 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0043],ARef=[AI95-00190-01]} |
| 2492 |
@ChgAdded{Version=[1],Text=[Whenever enforcement of a restriction is not |
| 2493 |
required prior to execution, an implementation may nevertheless enforce the |
| 2494 |
restriction prior to execution of a partition to which the restriction applies, |
| 2495 |
provided that every execution of the partition would violate the restriction.]} |
| 2496 |
@end{ImplPerm} |
| 2497 |
|
| 2498 |
@begin{Notes} |
| 2499 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00347-01]} |
| 2500 |
Restrictions intended to facilitate the construction of |
| 2501 |
efficient tasking run-time systems are defined |
| 2502 |
in @RefSecNum{Tasking Restrictions}. |
| 2503 |
@Chg{Version=[2],New=[Restrictions intended for use when constructing |
| 2504 |
high integrity systems],Old=[Safety- and security-related |
| 2505 |
restrictions]} are defined in |
| 2506 |
@RefSecNum{High Integrity Restrictions}. |
| 2507 |
|
| 2508 |
An implementation has to enforce the restrictions in cases where |
| 2509 |
enforcement is required, |
| 2510 |
even if it chooses not to take advantage of the restrictions in terms of |
| 2511 |
efficiency. |
| 2512 |
@begin{Discussion} |
| 2513 |
It is not the intent that an implementation will support a different |
| 2514 |
run-time system for every possible combination of restrictions. |
| 2515 |
An implementation might support only two run-time systems, |
| 2516 |
and document a set of restrictions that is sufficient to allow |
| 2517 |
use of the more efficient and safe one. |
| 2518 |
@end{Discussion} |
| 2519 |
@end{Notes} |
| 2520 |
|
| 2521 |
@begin{Extend83} |
| 2522 |
@Defn{extensions to Ada 83} |
| 2523 |
Pragma Restrictions is new to Ada 95. |
| 2524 |
@end{Extend83} |
| 2525 |
|
| 2526 |
@begin{DiffWord95} |
| 2527 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0042],ARef=[AI95-00130-01]} |
| 2528 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the wording so that |
| 2529 |
restrictions are checked inside of generic instantiations and in default |
| 2530 |
expressions. Since not making these checks would violate the purpose of |
| 2531 |
restrictions, we are not documenting this as an incompatibility.]} |
| 2532 |
|
| 2533 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0043],ARef=[AI95-00190-01]} |
| 2534 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added a permission that |
| 2535 |
restrictions can be enforced at compile-time. While this is technically |
| 2536 |
incompatible, documenting it as such would be unnecessarily alarming - |
| 2537 |
there should not be any programs depending on the runtime failure of |
| 2538 |
restrictions.]} |
| 2539 |
|
| 2540 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]} |
| 2541 |
@ChgAdded{Version=[2],Text=[The syntax of a @nt{restriction_parameter_argument} |
| 2542 |
has been defined to better support restriction No_Dependence (see |
| 2543 |
@RefSecNum{Language-Defined Restrictions}).]} |
| 2544 |
@end{DiffWord95} |
| 2545 |
|
| 2546 |
|
| 2547 |
@LabeledAddedSubclause{Version=[2], Name=[Language-Defined Restrictions]} |
| 2548 |
|
| 2549 |
@begin{StaticSem} |
| 2550 |
|
| 2551 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01]} |
| 2552 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The following |
| 2553 |
@SynI{restriction_}@nt{identifier}s are language-defined (additional |
| 2554 |
restrictions are defined in the Specialized Needs Annexes):]} |
| 2555 |
|
| 2556 |
@begin{Description} |
| 2557 |
|
| 2558 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01]} |
| 2559 |
@ChgAdded{Version=[2],Text=[@Defn2{Term=[Restrictions],Sec=(No_Implementation_Attributes)}No_Implementation_Attributes @\There |
| 2560 |
are no implementation-defined attributes. This restriction applies |
| 2561 |
only to the current compilation or environment, not the entire partition.]} |
| 2562 |
@begin{Discussion} |
| 2563 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2564 |
@ChgAdded{Version=[2],Text=[This restriction (as well as No_Implementation_Pragmas) |
| 2565 |
only applies to the current compilation, because it is likely that the |
| 2566 |
runtime (and possibly user-written low-level code) will need to use |
| 2567 |
implementation-defined entities. But a partition-wide restriction applies |
| 2568 |
everywhere, including the runtime.]} |
| 2569 |
@end{Discussion} |
| 2570 |
|
| 2571 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01]} |
| 2572 |
@ChgAdded{Version=[2],Text=[@Defn2{Term=[Restrictions],Sec=(No_Implementation_Pragmas)}No_Implementation_Pragmas @\There |
| 2573 |
are no implementation-defined pragmas or pragma arguments. This |
| 2574 |
restriction applies only to the current compilation or environment, not the |
| 2575 |
entire partition.]} |
| 2576 |
|
| 2577 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00368-01]} |
| 2578 |
@ChgAdded{Version=[2],Text=[@Defn2{Term=[Restrictions],Sec=(No_Obsolescent_Features)}No_Obsolescent_Features @\There |
| 2579 |
is no use of language features defined in Annex J. It is |
| 2580 |
implementation-defined if uses of the renamings of |
| 2581 |
@RefSecNum{Renamings of Ada 83 Library Units} are detected by this |
| 2582 |
restriction. This restriction applies only to the current compilation or |
| 2583 |
environment, not the entire partition.]} |
| 2584 |
@begin{Reason} |
| 2585 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2586 |
@ChgAdded{Version=[2],Type=[Leading],Text=[A user could compile a rename |
| 2587 |
like]} |
| 2588 |
@begin{Example} |
| 2589 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2590 |
@ChgAdded{Version=[2],Text=[@key{with} Ada.Text_IO; |
| 2591 |
@key{package} Text_IO @key{renames} Ada.Text_IO;]} |
| 2592 |
@end{Example} |
| 2593 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2594 |
@ChgAdded{Version=[2],Text=[Such a rename must not be disallowed |
| 2595 |
by this restriction, nor should the compilation of such a rename be |
| 2596 |
restricted by an implementation. Many implementations implement the renames |
| 2597 |
of @RefSecNum{Renamings of Ada 83 Library Units} |
| 2598 |
by compiling them normally; we do not want to require implementations to use |
| 2599 |
a special mechanism to implement these renames.]} |
| 2600 |
@end{Reason} |
| 2601 |
|
| 2602 |
@end{Description} |
| 2603 |
|
| 2604 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]} |
| 2605 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The following |
| 2606 |
@SynI{restriction_parameter_}@nt{identifier} is language defined:]} |
| 2607 |
|
| 2608 |
@begin{Description} |
| 2609 |
|
| 2610 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]} |
| 2611 |
@ChgAdded{Version=[2],Text=[@Defn2{Term=[Restrictions],Sec=(No_Dependence)}No_Dependence @\Specifies |
| 2612 |
a library unit on which there are no semantic dependences.]} |
| 2613 |
@end{Description} |
| 2614 |
|
| 2615 |
@end{StaticSem} |
| 2616 |
|
| 2617 |
@begin{Legality} |
| 2618 |
|
| 2619 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]} |
| 2620 |
@ChgAdded{Version=[2],Text=[The @nt{restriction_parameter_argument} of a |
| 2621 |
No_Dependence restriction shall be a @nt{name}; the @nt{name} shall have |
| 2622 |
the form of a full expanded name of a library unit, but need not denote a unit |
| 2623 |
present in the environment.]} |
| 2624 |
|
| 2625 |
@begin{Ramification} |
| 2626 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2627 |
@ChgAdded{Version=[2],Text=[This @nt{name} is not resolved.]} |
| 2628 |
@end{Ramification} |
| 2629 |
|
| 2630 |
@end{Legality} |
| 2631 |
|
| 2632 |
@begin{LinkTime} |
| 2633 |
|
| 2634 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]} |
| 2635 |
@ChgAdded{Version=[2],Text=[No compilation unit included in the partition shall |
| 2636 |
depend semantically on the library unit identified by the @nt{name}.]} |
| 2637 |
|
| 2638 |
@begin{Ramification} |
| 2639 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2640 |
@ChgAdded{Version=[2],Text=[There is no requirement that the library unit |
| 2641 |
actually exist. One possible use of the pragma is to prevent the use of |
| 2642 |
implementation-defined units; when the program is ported to a different |
| 2643 |
compiler, it is perfectly reasonable that no unit with the name exist.]} |
| 2644 |
@end{Ramification} |
| 2645 |
|
| 2646 |
@end{LinkTime} |
| 2647 |
|
| 2648 |
@begin{Extend95} |
| 2649 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01],ARef=[AI95-00368-01]} |
| 2650 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 2651 |
Restrictions No_Implementation_Attributes, No_Implementation_Pragmas, and |
| 2652 |
No_Obsolescent_Features are new.]} |
| 2653 |
|
| 2654 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]} |
| 2655 |
@ChgAdded{Version=[2],Text=[Restriction No_Dependence is new.]} |
| 2656 |
@end{Extend95} |
| 2657 |
|
| 2658 |
|
| 2659 |
@LabeledClause{Streams} |
| 2660 |
|
| 2661 |
@begin{Intro} |
| 2662 |
@Defn{stream} |
| 2663 |
@Defn{stream type} |
| 2664 |
A @i{stream} is a sequence of elements comprising values from |
| 2665 |
possibly different types and allowing sequential access to these values. |
| 2666 |
A @i{stream type} is a type in the class whose root type is |
| 2667 |
Streams.Root_Stream_Type. |
| 2668 |
A stream type may be implemented in various ways, |
| 2669 |
such as an external sequential file, an internal buffer, |
| 2670 |
or a network channel. |
| 2671 |
@begin{Discussion} |
| 2672 |
A stream element will often be the same size as a storage element, |
| 2673 |
but that is not required. |
| 2674 |
@end{Discussion} |
| 2675 |
@end{Intro} |
| 2676 |
|
| 2677 |
@begin{Extend83} |
| 2678 |
@Defn{extensions to Ada 83} |
| 2679 |
Streams are new in Ada 95. |
| 2680 |
@end{Extend83} |
| 2681 |
|
| 2682 |
@LabeledSubClause{The Package Streams} |
| 2683 |
|
| 2684 |
@begin{StaticSem} |
| 2685 |
The abstract type Root_Stream_Type is the root type of the class of |
| 2686 |
stream types. The types in this class represent different kinds of |
| 2687 |
streams. A new stream type is defined by extending the root type |
| 2688 |
(or some other stream type), overriding the Read and Write |
| 2689 |
operations, and optionally defining additional primitive |
| 2690 |
subprograms, |
| 2691 |
according to the requirements of the particular kind of stream. |
| 2692 |
The predefined stream-oriented attributes like T'Read and T'Write |
| 2693 |
make dispatching |
| 2694 |
calls on the Read and Write procedures of the Root_Stream_Type. |
| 2695 |
(User-defined T'Read and T'Write attributes can also make such calls, |
| 2696 |
or can call the Read and Write attributes of other types.) |
| 2697 |
@begin{example} |
| 2698 |
@ChildUnit{Parent=[Ada],Child=[Streams]}@key[package] Ada.Streams @key[is] |
| 2699 |
@key[pragma] Pure(Streams)@Defn{unpolluted};@Comment{This *must* be a Duff joke} |
| 2700 |
|
| 2701 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]} |
| 2702 |
@key[type] @AdaTypeDefn{Root_Stream_Type} @key[is] @key[abstract tagged limited private];@Chg{Version=[2],New=[ |
| 2703 |
@key[pragma] Preelaborable_Initialization(Root_Stream_Type);],Old=[]} |
| 2704 |
|
| 2705 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0044],ARef=[AI95-00181-01]} |
| 2706 |
@key[type] @AdaTypeDefn{Stream_Element} @key[is] @key[mod] @RI{implementation-defined}; |
| 2707 |
@key[type] @AdaTypeDefn{Stream_Element_Offset} @key[is] @key[range] @RI{implementation-defined}; |
| 2708 |
@key[subtype] @AdaSubtypeDefn{Name=[Stream_Element_Count],Of=[Stream_Element_Offset]} @key[is] |
| 2709 |
Stream_Element_Offset @key[range] 0..Stream_Element_Offset'Last; |
| 2710 |
@key[type] @AdaTypeDefn{Stream_Element_Array} @key[is] |
| 2711 |
@key[array](Stream_Element_Offset @key[range] <>) @key[of]@Chg{New=[@key[ aliased]],Old=[]} Stream_Element; |
| 2712 |
|
| 2713 |
@key[procedure] @AdaSubDefn{Read}( |
| 2714 |
Stream : @key[in] @key[out] Root_Stream_Type; |
| 2715 |
Item : @key[out] Stream_Element_Array; |
| 2716 |
Last : @key[out] Stream_Element_Offset) @key[is abstract]; |
| 2717 |
|
| 2718 |
@key[procedure] @AdaSubDefn{Write}( |
| 2719 |
Stream : @key[in] @key[out] Root_Stream_Type; |
| 2720 |
Item : @key[in] Stream_Element_Array) @key[is abstract]; |
| 2721 |
|
| 2722 |
@key[private] |
| 2723 |
... -- @RI{not specified by the language} |
| 2724 |
@key[end] Ada.Streams; |
| 2725 |
@end{example} |
| 2726 |
|
| 2727 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00227-01]} |
| 2728 |
The Read operation transfers @Chg{Version=[2],New=[],Old=[Item'Length ]}stream |
| 2729 |
elements from the specified stream to fill the array Item. |
| 2730 |
@Chg{Version=[2],New=[Elements are transferred until Item'Length elements have |
| 2731 |
been transferred, or until the end of the stream is reached. If any elements |
| 2732 |
are transferred, the],Old=[The]} index of the last stream element transferred is |
| 2733 |
returned in Last. @Chg{Version=[2],New=[Otherwise, Item'First - 1 is returned |
| 2734 |
in Last. ],Old=[]}Last is less than Item'Last only if the end of the stream is |
| 2735 |
reached.@Comment{This last sentence should be marked Redundant.} |
| 2736 |
|
| 2737 |
The Write operation appends Item to the specified stream. |
| 2738 |
|
| 2739 |
@begin{Discussion} |
| 2740 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]} |
| 2741 |
@ChgNote{This was moved from 13.7.1.} |
| 2742 |
@ChgAdded{Version=[2],Text=[The index subtype of Stream_Element_Array is |
| 2743 |
Stream_Element_Offset because we wish to allow maximum flexibility. Most |
| 2744 |
Stream_Element_Arrays will probably have a lower bound of 0 or 1, but other |
| 2745 |
lower bounds, including negative ones, make sense in some situations.]} |
| 2746 |
|
| 2747 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]} |
| 2748 |
@ChgNote{This was moved from 13.7.1, where it was totally bogus.} |
| 2749 |
@ChgAdded{Version=[2],Text=[Note that there are some language-defined |
| 2750 |
subprograms that fill part of a Stream_Element_Array, and return the index of the |
| 2751 |
last element filled as a Stream_Element_Offset. The Read procedures declared |
| 2752 |
here, Streams.Stream_IO (see @RefSecNum{The Package Streams.Stream_IO}), |
| 2753 |
and System.RPC (see @RefSecNum{Partition Communication Subsystem}) |
| 2754 |
behave in this manner. |
| 2755 |
These will raise Constraint_Error if the resulting Last value is not in |
| 2756 |
Stream_Element_Offset. |
| 2757 |
This implies that the Stream_Element_Array passed to these subprograms should |
| 2758 |
not have a lower bound of Stream_Element_Offset'First, |
| 2759 |
because then a read of 0 elements would always raise Constraint_Error. |
| 2760 |
A better choice of lower bound is 1.]} |
| 2761 |
@end{Discussion} |
| 2762 |
|
| 2763 |
@end{StaticSem} |
| 2764 |
|
| 2765 |
@begin{ImplPerm} |
| 2766 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0044],ARef=[AI95-00181-01]} |
| 2767 |
@ChgAdded{Version=[1],Text=[If Stream_Element'Size is not a multiple of |
| 2768 |
System.Storage_Unit, then the components of Stream_@!Element_@!Array need |
| 2769 |
not be aliased.]} |
| 2770 |
@begin{Ramification} |
| 2771 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2772 |
@ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00114-01]} |
| 2773 |
@ChgAdded{Version=[1],Text=[If the Stream_Element'Size is less than the size of |
| 2774 |
System.Storage_Unit, then components of Stream_@!Element_@!Array need not be |
| 2775 |
aliased. This is necessary as the components of type Stream_Element size might |
| 2776 |
not be addressable on the target @Chg{Version=[2],New=[architecture],Old=[architechture]}.]} |
| 2777 |
@end{Ramification} |
| 2778 |
@end{ImplPerm} |
| 2779 |
|
| 2780 |
@begin{Notes} |
| 2781 |
See @RefSec{The Package Streams.Stream_IO} for an example of extending |
| 2782 |
type Root_Stream_Type. |
| 2783 |
|
| 2784 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00227-01]} |
| 2785 |
@ChgAdded{Version=[2],Text=[If the end of stream has been reached, and |
| 2786 |
Item'First is Stream_Element_Offset'First, Read will raise Constraint_Error.]} |
| 2787 |
@begin{Ramification} |
| 2788 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2789 |
@ChgAdded{Version=[2],Text=[Thus, Stream_Element_Arrays should start at 0 or |
| 2790 |
1, not Stream_Element_Offset'First.]} |
| 2791 |
@end{Ramification} |
| 2792 |
@end{Notes} |
| 2793 |
|
| 2794 |
@begin{Extend95} |
| 2795 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]} |
| 2796 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 2797 |
@b[Amendment Correction:] Added @nt{pragma} Preelaborable_Initialization |
| 2798 |
to type Root_Stream_Type.]} |
| 2799 |
@end{Extend95} |
| 2800 |
|
| 2801 |
@begin{DiffWord95} |
| 2802 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0044],ARef=[AI95-00181-01]} |
| 2803 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Stream elements are aliased |
| 2804 |
presuming that makes sense.]} |
| 2805 |
|
| 2806 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00227-01]} |
| 2807 |
@ChgAdded{Version=[2],Text=[Fixed the wording for Read to properly define |
| 2808 |
the result in Last when no stream elements are transfered.]} |
| 2809 |
@end{DiffWord95} |
| 2810 |
|
| 2811 |
|
| 2812 |
@LabeledSubClause{Stream-Oriented Attributes} |
| 2813 |
|
| 2814 |
@begin{Intro} |
| 2815 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2816 |
The @Chg{New=[operational attributes ],Old=[]}Write, Read, Output, and |
| 2817 |
Input @Chg{New=[],Old=[attributes ]}convert values to a |
| 2818 |
stream of elements and reconstruct values from a stream. |
| 2819 |
@end{Intro} |
| 2820 |
|
| 2821 |
@begin{StaticSem} |
| 2822 |
|
| 2823 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]} |
| 2824 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For @PrefixType{every subtype S of |
| 2825 |
an elementary type @i(T)}, the following representation attribute is defined:]} |
| 2826 |
@begin{Description} |
| 2827 |
|
| 2828 |
@ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T], |
| 2829 |
Leading=<T>, Prefix=<S>, AttrName=<Stream_Size>, ARef=[AI95-00270-01], |
| 2830 |
Text=[@Chg{Version=[2],New=[Denotes the number of bits occupied |
| 2831 |
in a stream by items of subtype S. Hence, the number of stream elements |
| 2832 |
required per item of elementary type @i<T> is:],Old=[]} |
| 2833 |
|
| 2834 |
@begin(Descexample) |
| 2835 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2836 |
@ChgAdded{Version=[2],Text=[@i<T>'Stream_Size / Ada.Streams.Stream_Element'Size]} |
| 2837 |
@end(Descexample) |
| 2838 |
|
| 2839 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2840 |
@ChgAdded{Version=[2],NoPrefix=[T],Text=[The value of this attribute is of |
| 2841 |
type @i{universal_integer} and is a multiple of Stream_Element'Size.]}]}@Comment{end attribute Stream_Size} |
| 2842 |
|
| 2843 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2844 |
@ChgAdded{Version=[2],NoPrefix=[T],Text=[Stream_Size may be specified for |
| 2845 |
first subtypes via an @nt{attribute_definition_clause}; the @nt{expression} |
| 2846 |
of such a clause shall be static, nonnegative, and a multiple of |
| 2847 |
Stream_Element'Size.]} |
| 2848 |
@end{Description} |
| 2849 |
@EndPrefixType{} |
| 2850 |
|
| 2851 |
@begin{Discussion} |
| 2852 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2853 |
@ChgAdded{Version=[2],Text=[Stream_Size is a type-related attribute (see |
| 2854 |
@RefSecNum{Operational and Representation Items}).]} |
| 2855 |
@end{Discussion} |
| 2856 |
@end{StaticSem} |
| 2857 |
|
| 2858 |
@begin{ImplAdvice} |
| 2859 |
|
| 2860 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]} |
| 2861 |
@ChgAdded{Version=[2],Text=[If not specified, the value of Stream_Size for an |
| 2862 |
elementary type should be the number of bits that corresponds to the |
| 2863 |
minimum number of stream elements required by the |
| 2864 |
first subtype of the type, rounded up to the nearest factor or multiple of the |
| 2865 |
word size that is also a multiple of the stream element size.]} |
| 2866 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 2867 |
Text=[If not specified, the value of Stream_Size for an |
| 2868 |
elementary type should be the number of bits that corresponds to the |
| 2869 |
minimum number of stream elements required by the |
| 2870 |
first subtype of the type, rounded up to the nearest factor or multiple of the |
| 2871 |
word size that is also a multiple of the stream element size.]}]} |
| 2872 |
@begin{Reason} |
| 2873 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00270-01]} |
| 2874 |
@ChgAdded{Version=[2],Text=[This is @ImplAdviceTitle because we want to |
| 2875 |
allow implementations to remain compatible with their Ada 95 implementations, |
| 2876 |
which may have a different handling of the number of stream elements. Users |
| 2877 |
can always specify Stream_Size if they need a specific number of stream |
| 2878 |
elements.]} |
| 2879 |
@end{Reason} |
| 2880 |
|
| 2881 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]} |
| 2882 |
@ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[@PDefn2{Term=[recommended level of support], |
| 2883 |
Sec=(Stream_Size attribute)} |
| 2884 |
The recommended level of support for the Stream_Size attribute is:]} |
| 2885 |
@begin{Itemize} |
| 2886 |
|
| 2887 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]} |
| 2888 |
@ChgAdded{Version=[2],Text=[A Stream_Size clause should be supported for a |
| 2889 |
discrete or fixed point type @i<T> if the specified Stream_Size is a multiple |
| 2890 |
of Stream_Element'Size and is no less than the size of the first subtype |
| 2891 |
of @i<T>, and no greater than the size of the largest type of the same |
| 2892 |
elementary class (signed integer, modular integer, enumeration, |
| 2893 |
ordinary fixed point, or decimal fixed point).]} |
| 2894 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 2895 |
Text=[The recommended level of support for the Stream_Size attribute should be |
| 2896 |
followed.]}]} |
| 2897 |
@begin{Ramification} |
| 2898 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2899 |
@ChgAdded{Version=[2],Text=[There are no requirements beyond supporting |
| 2900 |
confirming Stream_Size clauses for floating point and access types. |
| 2901 |
Floating point and access types usually only have a handful of defined |
| 2902 |
formats, streaming anything else makes no sense for them.]} |
| 2903 |
|
| 2904 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2905 |
@ChgAdded{Version=[2],Text=[For discrete and fixed point types, this |
| 2906 |
may require support for sizes other than the @lquotes@;natural@rquotes |
| 2907 |
ones. For instance, on a typical machine with 32-bit integers and a |
| 2908 |
Stream_Element'Size of 8, setting Stream_Size to 24 must be supported. |
| 2909 |
This is required as such formats can be useful for interoperability with |
| 2910 |
unusual machines, and there is no difficulty with the implementation |
| 2911 |
(drop extra bits on output, sign extend on input).]} |
| 2912 |
@end{Ramification} |
| 2913 |
|
| 2914 |
@end{Itemize} |
| 2915 |
@end{ImplAdvice} |
| 2916 |
|
| 2917 |
@RMNewPage@Comment{For printed Ada 2005 RM} |
| 2918 |
@begin{StaticSem} |
| 2919 |
|
| 2920 |
For @PrefixType{every subtype S of a specific type @i(T)}, |
| 2921 |
the following attributes are defined. |
| 2922 |
@begin{Description} |
| 2923 |
@AttributeLeading{Prefix=<S>, AttrName=<Write>, |
| 2924 |
Text=<S'Write denotes a procedure with the following specification: |
| 2925 |
@begin{DescExample} |
| 2926 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 2927 |
@key(procedure) S'Write( |
| 2928 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class; |
| 2929 |
@RI{Item} : @key{in} @RI(T)) |
| 2930 |
@end{DescExample} |
| 2931 |
|
| 2932 |
@noprefix@;S'Write writes the value of @i{Item} to @i{Stream}.>} |
| 2933 |
|
| 2934 |
@AttributeLeading{Prefix=<S>, AttrName=<Read>, |
| 2935 |
Text=<S'Read denotes a procedure with the following specification: |
| 2936 |
@begin{DescExample} |
| 2937 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 2938 |
@key(procedure) S'Read( |
| 2939 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class; |
| 2940 |
@RI{Item} : @key{out} @RI(T)) |
| 2941 |
@end{DescExample} |
| 2942 |
|
| 2943 |
@noprefix@;S'Read reads the value of @i{Item} from @i{Stream}.>} |
| 2944 |
@end{Description} |
| 2945 |
@EndPrefixType{} |
| 2946 |
|
| 2947 |
|
| 2948 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 2949 |
@ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]} |
| 2950 |
@ChgAdded{Version=[1],Text=[For @Chg{Version=[2],New=[an ],Old=[]}untagged |
| 2951 |
derived @Chg{Version=[2],New=[type],Old=[types]}, the Write |
| 2952 |
@Chg{Version=[2],New=[(resp.],Old=[and]} |
| 2953 |
Read@Chg{Version=[2],New=[) attribute is],Old=[ attributes are]} |
| 2954 |
inherited @Chg{Version=[2],New=[according to the rules given],Old=[as specified]} |
| 2955 |
in @RefSecNum(Operational and Representation Items)@Chg{Version=[2], |
| 2956 |
New=[ if the attribute is available for the parent type at the point |
| 2957 |
where @i{T} is declared. For a tagged derived type, these attributes are |
| 2958 |
not inherited, but rather],Old=[; otherwise,]} the default |
| 2959 |
implementations @Chg{Version=[2],New=[],Old=[of these attributes ]}are |
| 2960 |
used.@Chg{Version=[2],New=[],Old=[The default implementations of Write and |
| 2961 |
Read attributes execute as follows:]}]} |
| 2962 |
|
| 2963 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]} |
| 2964 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The default implementations of |
| 2965 |
the Write and Read attributes, where available, execute as follows:]} |
| 2966 |
|
| 2967 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 2968 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01],ARef=[AI95-00251-01],ARef=[AI95-00270-01]} |
| 2969 |
For elementary types, @Chg{Version=[2],New=[Read reads (and Write writes) the |
| 2970 |
number of stream elements implied by the Stream_Size for the type @i<T>;], |
| 2971 |
Old=[]} the representation @Chg{Version=[2],New=[],Old=[in terms ]}of@Chg{Version=[2], |
| 2972 |
New=[ those],Old=[]} stream elements is implementation defined. |
| 2973 |
For composite types, the Write or Read attribute for each component is |
| 2974 |
called in @Chg{New=[],Old=[a ]}canonical order@Chg{New=[, which], |
| 2975 |
Old=[. The canonical order of components]} is last dimension varying |
| 2976 |
fastest for an array, and positional aggregate order for a record. |
| 2977 |
Bounds are not included in the stream if @i(T) is an array type. |
| 2978 |
If @i(T) is a discriminated type, discriminants are included only if they have |
| 2979 |
defaults. If @i(T) is a tagged type, the tag is not included. |
| 2980 |
@Chg{New=[For type extensions, the Write or Read attribute for the parent type |
| 2981 |
is called, followed by the Write or Read attribute of each component of the |
| 2982 |
extension part, in canonical order. For a limited type extension, if the |
| 2983 |
attribute of @Chg{Version=[2],New=[the parent],Old=[any ancestor]} type |
| 2984 |
@Chg{Version=[2],New=[or any progenitor type ],Old=[]}of |
| 2985 |
@i(T) @Chg{Version=[2],New=[is available anywhere within the immediate scope |
| 2986 |
of @i<T>,],Old=[has been directly specified]} and the attribute |
| 2987 |
of @Chg{Version=[2],New=[the parent type or],Old=[any ancestor type of]} the |
| 2988 |
type of any of the extension components |
| 2989 |
@Chg{Version=[2],New=[is not available at the freezing point of @i<T>, then], |
| 2990 |
Old=[which are of a limited type has not been specified,]} |
| 2991 |
the attribute of @i(T) shall be directly specified.],Old=[]} |
| 2992 |
|
| 2993 |
@ChgImplDef{Version=[2],Kind=[Revised],Text=[The @Chg{Version=[2],New=[contents |
| 2994 |
of the stream elements read and written],Old=[representation used]} by the |
| 2995 |
Read and Write attributes of elementary types@Chg{Version=[2],New=[],Old=[ in |
| 2996 |
terms of stream elements]}.]} |
| 2997 |
@begin{Reason} |
| 2998 |
A discriminant with a default value is treated simply as |
| 2999 |
a component of the object. On the other hand, |
| 3000 |
an array bound or a discriminant without a default value, |
| 3001 |
is treated as @lquotes@;descriptor@rquotes@; or @lquotes@;dope@rquotes@; |
| 3002 |
that must be provided in order to create the object and thus is logically |
| 3003 |
separate from the regular components. Such @lquotes@;descriptor@rquotes@; |
| 3004 |
data are written by 'Output and produced as part of the delivered result by |
| 3005 |
the 'Input function, but they are not written by 'Write nor read by 'Read. |
| 3006 |
A tag is like a discriminant without a default. |
| 3007 |
|
| 3008 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 3009 |
@ChgAdded{Version=[1],Text=[For limited type extensions, we must have a |
| 3010 |
definition of 'Read and 'Write if the parent type has one, as it is possible |
| 3011 |
to make a dispatching call through the attributes. The rule is designed to |
| 3012 |
automatically do the right thing in as many cases as possible.]} |
| 3013 |
|
| 3014 |
@ChgRef{Version=[1],Kind=[Added],ARef=[AI95-00251-01]} |
| 3015 |
@ChgAdded{Version=[1],Text=[Similarly, a type that has a progenitor |
| 3016 |
with an available attribute must also have that attribute, for the |
| 3017 |
same reason.]} |
| 3018 |
@end{Reason} |
| 3019 |
@begin{Ramification} |
| 3020 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]} |
| 3021 |
For a composite object, the subprogram denoted by the |
| 3022 |
Write or Read attribute of each component is called, whether it is the |
| 3023 |
default or is user-specified.@Chg{Version=[2],New=[ Implementations are |
| 3024 |
allowed to optimize these calls (see below), presuming the properties |
| 3025 |
of the attributes are preserved.],Old=[]} |
| 3026 |
@end{Ramification} |
| 3027 |
|
| 3028 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]} |
| 3029 |
@ChgAdded{Version=[2],Text=[Constraint_Error is raised by the predefined Write |
| 3030 |
attribute if the value of the elementary item is outside the range of values |
| 3031 |
representable using Stream_Size bits. For a signed integer type, an enumeration |
| 3032 |
type, or a fixed point type, the range is unsigned only if the integer code for |
| 3033 |
the lower bound of the first subtype is nonnegative, and a (symmetric) signed |
| 3034 |
range that covers all values of the first subtype would require more than |
| 3035 |
Stream_Size bits; otherwise the range is signed.]} |
| 3036 |
|
| 3037 |
|
| 3038 |
@Leading@;For @PrefixType{every subtype S'Class of a class-wide type |
| 3039 |
@i(T)'Class}: |
| 3040 |
@begin{Description} |
| 3041 |
@AttributeLeading{Prefix=<S'Class>, AttrName=<Write>, |
| 3042 |
Text=<S'Class'Write denotes a procedure with the following |
| 3043 |
specification: |
| 3044 |
@begin{DescExample} |
| 3045 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3046 |
@key(procedure) S'Class'Write( |
| 3047 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class; |
| 3048 |
@RI{Item} : @key{in} @RI(T)'Class) |
| 3049 |
@end{DescExample} |
| 3050 |
|
| 3051 |
@noprefix@;Dispatches to the subprogram denoted by the Write attribute of |
| 3052 |
the specific type identified by the tag of Item.>} |
| 3053 |
|
| 3054 |
@AttributeLeading{Prefix=<S'Class>, AttrName=<Read>, |
| 3055 |
Text=<S'Class'Read denotes a procedure with the following specification: |
| 3056 |
@begin{DescExample} |
| 3057 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3058 |
@key(procedure) S'Class'Read( |
| 3059 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class; |
| 3060 |
@RI{Item} : @key{out} @RI(T)'Class) |
| 3061 |
@end{DescExample} |
| 3062 |
|
| 3063 |
@noprefix@;Dispatches to the subprogram denoted by the Read attribute of |
| 3064 |
the specific type identified by the tag of Item.>} |
| 3065 |
@begin{Reason} |
| 3066 |
It is necessary to have class-wide versions of Read and Write |
| 3067 |
in order to avoid generic contract model violations; |
| 3068 |
in a generic, we don't necessarily know at compile time whether a given |
| 3069 |
type is specific or class-wide. |
| 3070 |
@end{Reason} |
| 3071 |
@end{Description} |
| 3072 |
@EndPrefixType{} |
| 3073 |
@end{StaticSem} |
| 3074 |
|
| 3075 |
@begin{ImplAdvice} |
| 3076 |
|
| 3077 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00270-01]} |
| 3078 |
@ChgDeleted{Version=[2],Text=[If a |
| 3079 |
stream element is the same size as a storage element, |
| 3080 |
then the normal in-memory representation should be used by Read and |
| 3081 |
Write for scalar objects. |
| 3082 |
Otherwise, Read and Write should use the smallest |
| 3083 |
number of stream elements needed |
| 3084 |
to represent all values in the base range of the scalar type.]} |
| 3085 |
@ChgNote{We don't add an Implementation Advice tag here, as we're deleting this.} |
| 3086 |
@end{ImplAdvice} |
| 3087 |
|
| 3088 |
@begin{StaticSem} |
| 3089 |
For @PrefixType{every subtype S of a specific type @i(T)}, |
| 3090 |
the following attributes are defined. |
| 3091 |
@begin{Description} |
| 3092 |
@AttributeLeading{Prefix=<S>, AttrName=<Output>, |
| 3093 |
Text=<S'Output denotes a procedure with the following specification: |
| 3094 |
@begin{DescExample} |
| 3095 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3096 |
@key(procedure) S'Output( |
| 3097 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class; |
| 3098 |
@RI{Item} : @key{in} @RI(T)) |
| 3099 |
@end{DescExample} |
| 3100 |
|
| 3101 |
@noprefix@;S'Output writes the value of @i{Item} to @i{Stream}, including |
| 3102 |
any bounds or discriminants.>} |
| 3103 |
@begin{Ramification} |
| 3104 |
Note that the bounds are included even for an array type whose |
| 3105 |
first subtype is constrained. |
| 3106 |
@end{Ramification} |
| 3107 |
|
| 3108 |
@AttributeLeading{Prefix=<S>, AttrName=<Input>, |
| 3109 |
Text=<S'Input denotes a function with the following specification: |
| 3110 |
@begin{DescExample} |
| 3111 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3112 |
@key(function) S'Input( |
| 3113 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class) |
| 3114 |
@key(return) @RI(T) |
| 3115 |
@end{DescExample} |
| 3116 |
|
| 3117 |
@noprefix@;S'Input reads and returns one value from |
| 3118 |
@i{Stream}, using any bounds or discriminants written by a corresponding |
| 3119 |
S'Output to determine how much to read.>} |
| 3120 |
@end{Description} |
| 3121 |
@EndPrefixType{} |
| 3122 |
|
| 3123 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 3124 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00444-01]} |
| 3125 |
@Chg{New=[For @Chg{Version=[2],New=[an ],Old=[]}untagged derived |
| 3126 |
@Chg{Version=[2],New=[type],Old=[types]}, the Output |
| 3127 |
@Chg{Version=[2],New=[(resp.],Old=[and]} Input@Chg{Version=[2],New=[) attribute |
| 3128 |
is],Old=[attributes of the parent type are]} |
| 3129 |
inherited @Chg{Version=[2],New=[according to the rules given], |
| 3130 |
Old=[as specified]} in |
| 3131 |
@RefSecNum(Operational and Representation Items)@Chg{Version=[2], |
| 3132 |
New=[ if the attribute is available for the parent type at the point where @i{T} |
| 3133 |
is declared. For a tagged derived type, these attributes are not |
| 3134 |
inherited, but rather],Old=[; otherwise,]} the default |
| 3135 |
implementations@Chg{Version=[2],New=[],Old=[ of these |
| 3136 |
attributes]} are used.@Chg{Version=[2],New=[],Old=[ The default implementations of |
| 3137 |
Output and Input attributes execute as follows:]}], |
| 3138 |
Old=[Unless overridden by an @nt<attribute_definition_clause>, these |
| 3139 |
subprograms execute as follows:]} |
| 3140 |
|
| 3141 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]} |
| 3142 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The default implementations of the |
| 3143 |
Output and Input attributes, where available, execute as follows:]} |
| 3144 |
@begin(Itemize) |
| 3145 |
If @i(T) is an array type, S'Output first writes the bounds, |
| 3146 |
and S'Input first reads the bounds. |
| 3147 |
If @i(T) has discriminants without defaults, S'Output first writes |
| 3148 |
the discriminants (using S'Write for each), and S'Input first |
| 3149 |
reads the discriminants (using S'Read for each). |
| 3150 |
|
| 3151 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]} |
| 3152 |
S'Output then calls S'Write to write the value of @i{Item} to the stream. |
| 3153 |
S'Input then creates an object (with the bounds or discriminants, if any, |
| 3154 |
taken from the stream), @Chg{Version=[2],New=[passes],Old=[initializes]} it |
| 3155 |
@Chg{Version=[2],New=[to],Old=[with]} S'Read, and returns |
| 3156 |
the value of the object.@Chg{Version=[2],New=[ Normal default initialization |
| 3157 |
and finalization take place for this object (see @RefSecNum{Object Declarations}, |
| 3158 |
@RefSecNum{User-Defined Assignment and Finalization}, and |
| 3159 |
@RefSecNum{Completion and Finalization}).],Old=[]} |
| 3160 |
@end(Itemize) |
| 3161 |
|
| 3162 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]} |
| 3163 |
@ChgAdded{Version=[2],Text=[If @i<T> is an abstract type, then S'Input is |
| 3164 |
an abstract function.]} |
| 3165 |
|
| 3166 |
@begin{Ramification} |
| 3167 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3168 |
@ChgAdded{Version=[2],Text=[For an abstract type @i<T>, S'Input can be |
| 3169 |
called in a dispatching call, or passed to a abstract formal |
| 3170 |
subprogram. But it cannot be used in non-dispatching |
| 3171 |
contexts, because we don't allow objects of abstract types to exist. |
| 3172 |
The designation of this function as abstract has no |
| 3173 |
impact on descendants of @i<T>, as @i<T>'Input is not inherited for |
| 3174 |
tagged types, but rather recreated (and the default |
| 3175 |
implementation of @i<T>'Input calls @i<T>'Read, not the parent type's |
| 3176 |
@i<T>'Input). Note that @i<T>'Input cannot be specified in this case, as any |
| 3177 |
function with the proper profile is necessarily abstract, and specifying |
| 3178 |
abstract subprograms in an @nt{attribute_definition_clause} is illegal.]} |
| 3179 |
@end{Ramification} |
| 3180 |
|
| 3181 |
@Leading@;For @PrefixType{every subtype S'Class of a class-wide type |
| 3182 |
@i(T)'Class}: |
| 3183 |
@begin{Description} |
| 3184 |
@AttributeLeading{Prefix=<S'Class>, AttrName=<Output>, |
| 3185 |
Text=<S'Class'Output denotes a procedure with the following |
| 3186 |
specification: |
| 3187 |
@begin{DescExample} |
| 3188 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3189 |
@key(procedure) S'Class'Output( |
| 3190 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class; |
| 3191 |
@RI{Item} : @key{in} @RI(T)'Class) |
| 3192 |
@end{DescExample} |
| 3193 |
|
| 3194 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]} |
| 3195 |
@noprefix@;First writes the external tag of @i{Item} to @i{Stream} |
| 3196 |
(by calling String'Output(@Chg{Version=[2],New=[@I{Stream}, ],Old=[]}Tags.@!External_Tag(@i{Item}'Tag)@Chg{Version=[2],New=[)],Old=[]} |
| 3197 |
@em see @RefSecNum{Tagged Types and Type Extensions}) |
| 3198 |
and then dispatches to the subprogram denoted by the Output attribute of |
| 3199 |
the specific type identified by the tag.@Chg{Version=[2],New=[ Tag_Error is |
| 3200 |
raised if the tag of Item identifies a type declared at an accessibility |
| 3201 |
level deeper than that of S.],Old=[]}>}@Comment{End of S'Class'Output attribute} |
| 3202 |
@begin{Reason} |
| 3203 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]} |
| 3204 |
@ChgAdded{Version=[2],Text=[We raise Tag_Error here for nested types as |
| 3205 |
such a type cannot be successfully read with S'Class'Input, and it doesn't |
| 3206 |
make sense to allow writing a value that cannot be read.]} |
| 3207 |
@end{Reason} |
| 3208 |
|
| 3209 |
@AttributeLeading{Prefix=<S'Class>, AttrName=<Input>, |
| 3210 |
Text=<S'Class'Input denotes a function with the following specification: |
| 3211 |
@begin{DescExample} |
| 3212 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3213 |
@key(function) S'Class'Input( |
| 3214 |
@RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class) |
| 3215 |
@key{return} @RI(T)'Class |
| 3216 |
@end{DescExample} |
| 3217 |
|
| 3218 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00279-01],ARef=[AI95-00344-01]} |
| 3219 |
@noprefix@;First reads the external tag from @i{Stream} and determines |
| 3220 |
the corresponding internal tag |
| 3221 |
(by calling Tags.@Chg{Version=[2],New=[Descendant_Tag], |
| 3222 |
Old=[Internal_Tag]}(String'Input(@i{Stream})@Chg{Version=[2],New=[, S'Tag],Old=[]}) |
| 3223 |
@Chg{Version=[2],New=[which might raise Tag_Error ],Old=[]}@em |
| 3224 |
see @RefSecNum{Tagged Types and Type Extensions}) |
| 3225 |
and then dispatches to the subprogram denoted by the Input attribute of |
| 3226 |
the specific type identified by the internal tag; |
| 3227 |
returns that result.@Chg{Version=[2],New=[ If the specific type identified |
| 3228 |
by the internal tag is not covered by @i<T>'Class or is abstract, Constraint_Error |
| 3229 |
is raised.],Old=[]}>}@Comment{End S'Class'Input attribute} |
| 3230 |
@end{Description} |
| 3231 |
@EndPrefixType{} |
| 3232 |
|
| 3233 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]} |
| 3234 |
@IndexCheck{Range_Check} |
| 3235 |
In the default implementation of Read and Input for a composite type, |
| 3236 |
for each scalar component that is a discriminant or whose |
| 3237 |
@nt{component_declaration} includes a @nt{default_expression}, |
| 3238 |
a check is made that the value returned by Read for the component |
| 3239 |
belongs to its subtype. |
| 3240 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 3241 |
Constraint_Error is raised if this check fails. |
| 3242 |
For other scalar components, no check is made. |
| 3243 |
For each component that is of an access type, if the implementation can |
| 3244 |
detect that the value returned by Read for the component is not |
| 3245 |
a value of its subtype, Constraint_Error is raised. If the value |
| 3246 |
is not a value of its subtype and this error is not detected, |
| 3247 |
the component has an abnormal value, and erroneous execution |
| 3248 |
can result (see @RefSecNum{Data Validity}).@Chg{Version=[2],New=[ In the |
| 3249 |
default implementation of Read for a composite type with defaulted |
| 3250 |
discriminants, if the actual parameter of Read is constrained, a check is made |
| 3251 |
that the discriminants read from the stream are equal to those of the actual |
| 3252 |
parameter. Constraint_Error is raised if this check fails.],Old=[]} |
| 3253 |
|
| 3254 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3255 |
@ChgAdded{Version=[2],Text=[@PDefn{unspecified}It is unspecified at which point |
| 3256 |
and in which order these checks are performed. In particular, if |
| 3257 |
Constraint_Error is raised due to the failure of one of these checks, it is |
| 3258 |
unspecified how many stream elements have been read from the stream.]} |
| 3259 |
|
| 3260 |
@ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0045],ARef=[AI95-00132-01]} |
| 3261 |
@ChgAdded{Version=[1],Text=[@Defn2{Term=[End_Error],Sec=(raised by failure of run-time check)} |
| 3262 |
In the default implementation of Read and Input for a type, End_Error |
| 3263 |
is raised if the end of the stream is reached before the reading of a value of |
| 3264 |
the type is completed.]} |
| 3265 |
|
| 3266 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 3267 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01],ARef=[AI95-00251-01]} |
| 3268 |
@PDefn2{Term=[specifiable], Sec=(of Read for a type)} |
| 3269 |
@PDefn2{Term=[specifiable], Sec=(of Write for a type)} |
| 3270 |
@PDefn2{Term=[specifiable], Sec=(of Input for a type)} |
| 3271 |
@PDefn2{Term=[specifiable], Sec=(of Output for a type)} |
| 3272 |
@Defn{Read clause} |
| 3273 |
@Defn{Write clause} |
| 3274 |
@Defn{Input clause} |
| 3275 |
@Defn{Output clause} |
| 3276 |
The stream-oriented attributes may be specified |
| 3277 |
for any type via an @nt{attribute_definition_clause}. |
| 3278 |
@Chg{Version=[2],New=[The subprogram name given in such a |
| 3279 |
clause shall not denote an abstract subprogram. Furthermore, if a |
| 3280 |
stream-oriented attribute is specified for an interface type by an |
| 3281 |
@nt{attribute_definition_clause}, the subprogram name given in the clause shall |
| 3282 |
statically denote a null procedure.], |
| 3283 |
Old=[All nonlimited types have default implementations |
| 3284 |
for these operations. An @nt{attribute_reference} for one of |
| 3285 |
these attributes is illegal if the type is limited, |
| 3286 |
unless the attribute has been specified by an |
| 3287 |
@nt{attribute_@!definition_@!clause}@Chg{New=[ or @Redundant[(for a type extension)] |
| 3288 |
the attribute has been specified for an ancestor type],Old=[]}. |
| 3289 |
For an @nt{attribute_@!definition_@!clause} specifying one of these |
| 3290 |
attributes, the subtype of the Item parameter shall be the base subtype |
| 3291 |
if scalar, and the first subtype otherwise. |
| 3292 |
The same rule applies to the result of the Input function.]} |
| 3293 |
@ChgNote{Most of the old text is moved down} |
| 3294 |
|
| 3295 |
@begin{Reason}@ChgNote{This belongs below} |
| 3296 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00195-01]} |
| 3297 |
@ChgDeleted{Version=[2],Text=[This is to simplify implementation.]} |
| 3298 |
@end{Reason} |
| 3299 |
|
| 3300 |
@begin{Discussion}@ChgNote{This is junk} |
| 3301 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 3302 |
@ChgRef{Version=[2],Kind=[DeletedAdded],ARef=[AI95-00195-01]} |
| 3303 |
@ChgDeleted{Version=[2],Text=[@Chg{Version=[1],New=[@lquotes@;Specified@rquotes |
| 3304 |
includes inherited attributes, and default implementations are never inherited. |
| 3305 |
So, for untagged limited types, the second part of the @nt{attribute_reference} |
| 3306 |
rule has the same meaning as the first part. However, tagged types never inherit |
| 3307 |
attributes, so the second rule is needed so that the default implementations |
| 3308 |
for the attributes can be called when those are constructed from a directly |
| 3309 |
specified ancestor.],Old=[]}]} |
| 3310 |
@end{Discussion} |
| 3311 |
|
| 3312 |
@begin{Discussion} |
| 3313 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]} |
| 3314 |
@ChgAdded{Version=[2],Type=[Leading],Text=[Stream attributes (other than |
| 3315 |
Input) are always null procedures for interface types (they have no |
| 3316 |
components). We need to allow explicit setting of the Read and Write |
| 3317 |
attributes in order that the class-wide attributes like LI'Class'Input |
| 3318 |
can be made available. (In that case, any descendant of the interface type |
| 3319 |
would require available attributes.) But we don't allow any concrete |
| 3320 |
implementation because these don't participate in extensions (unless the |
| 3321 |
interface is the parent type). If we didn't ban concrete implementations, |
| 3322 |
the order of declaration of a pair of interfaces would become significant. |
| 3323 |
For example, if Int1 and Int2 are interfaces with concrete implementations |
| 3324 |
of 'Read, then the following declarations would have different |
| 3325 |
implementations for 'Read:]} |
| 3326 |
@begin{Example} |
| 3327 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3328 |
@ChgAdded{Version=[2],Text=[@key{type} Con1 @key{is new} Int1 @key{and} Int2 @key{with null record}; |
| 3329 |
@key{type} Con2 @key{is new} Int2 @key{and} Int1 @key{with null record};]} |
| 3330 |
@end{Example} |
| 3331 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3332 |
@ChgAdded{Version=[2],Type=[Trailing],Text=[This would violate our design |
| 3333 |
principle that the order of the specification |
| 3334 |
of the interfaces in a @nt{derived_type_definition} doesn't matter.]} |
| 3335 |
@end{Discussion} |
| 3336 |
|
| 3337 |
@begin{Ramification} |
| 3338 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3339 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The Input attribute cannot be |
| 3340 |
specified for an interface. As it is a function, a null procedure is |
| 3341 |
impossible; a concrete function is not possible anyway as any function |
| 3342 |
returning an abstract type must be abstract. And we don't allow specifying |
| 3343 |
stream attributes to be abstract subprograms. This has no impact, as the |
| 3344 |
availability of Int'Class'Input (where Int is a limited interface) depends |
| 3345 |
on whether Int'Read (not Int'Input) is specified. There is no reason to |
| 3346 |
allow Int'Output to be specified, either, but there is equally no reason to |
| 3347 |
disallow it, so we don't have a special rule for that.]} |
| 3348 |
@end{Ramification} |
| 3349 |
|
| 3350 |
@begin{Discussion} |
| 3351 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3352 |
@ChgAdded{Version=[2],Text=[Limited types generally do not have default |
| 3353 |
implementations of the stream-oriented attributes. The rules defining when |
| 3354 |
a stream-oriented attribute is available (see below) determine when an |
| 3355 |
attribute of a limited type is in fact well defined and usable. The rules are |
| 3356 |
designed to maximize the number of cases in which the attributes are usable. |
| 3357 |
For instance, when the language provides a default implementation of |
| 3358 |
an attribute for a limited type based on a specified attribute for the parent |
| 3359 |
type, we want to be able to call that attribute.]} |
| 3360 |
@end{Discussion} |
| 3361 |
|
| 3362 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3363 |
@ChgAdded{Version=[2],Type=[Leading],Text=[A stream-oriented attribute for a |
| 3364 |
subtype of a specific type @i<T> is @i<available> at places where one of the |
| 3365 |
following conditions is true: @Defn2{Term=[available],Sec=[stream attribute]}]} |
| 3366 |
|
| 3367 |
@begin{Itemize} |
| 3368 |
|
| 3369 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3370 |
@ChgAdded{Version=[2],Text=[@i<T> is nonlimited.]} |
| 3371 |
|
| 3372 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3373 |
@ChgAdded{Version=[2],Text=[The @nt{attribute_designator} is Read (resp. Write) |
| 3374 |
and @i<T> is a limited record extension, and the attribute Read (resp. Write) |
| 3375 |
is available for the parent type of @i<T> and for the types of all of the |
| 3376 |
extension components.]} |
| 3377 |
@begin{Reason} |
| 3378 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3379 |
@ChgAdded{Version=[2],Text=[In this case, the language provides a |
| 3380 |
well-defined default implementation, which we want to be able to call.]} |
| 3381 |
@end{Reason} |
| 3382 |
|
| 3383 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3384 |
@ChgAdded{Version=[2],Text=[@i{T} is a limited untagged derived type, and the |
| 3385 |
attribute was inherited for the type.]} |
| 3386 |
@begin{Reason} |
| 3387 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3388 |
@ChgAdded{Version=[2],Text=[Attributes are only inherited for |
| 3389 |
untagged derived types, and surely we want to be able to call |
| 3390 |
inherited attributes.]} |
| 3391 |
@end{Reason} |
| 3392 |
|
| 3393 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3394 |
@ChgAdded{Version=[2],Text=[The @nt{attribute_designator} is Input (resp. |
| 3395 |
Output), and @i<T> is a limited type, and the attribute Read (resp. Write) is |
| 3396 |
available for @i<T>.]} |
| 3397 |
@begin{Reason} |
| 3398 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3399 |
@ChgAdded{Version=[2],Text=[The default implementation of Input and Output |
| 3400 |
are based on Read and Write; so if the implementation of Read or Write is |
| 3401 |
good, so is the matching implementation of Input or Output.]} |
| 3402 |
@end{Reason} |
| 3403 |
|
| 3404 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3405 |
@ChgAdded{Version=[2],Text=[The attribute has been specified via an |
| 3406 |
@nt{attribute_definition_clause}, and the @nt{attribute_definition_clause} |
| 3407 |
is visible.]} |
| 3408 |
@begin{Reason} |
| 3409 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3410 |
@ChgAdded{Version=[2],Text=[We always want to allow calling a specified |
| 3411 |
attribute. But we don't want availability to break privacy. |
| 3412 |
Therefore, only attributes whose specification can be seen count. Yes, we |
| 3413 |
defined the visibility of an @nt{attribute_definition_clause} |
| 3414 |
(see @RefSecNum{Visibility}).]} |
| 3415 |
@end{Reason} |
| 3416 |
@end{Itemize} |
| 3417 |
|
| 3418 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3419 |
@ChgAdded{Version=[2],Type=[Leading],Text=[A stream-oriented attribute for a subtype of a class-wide type |
| 3420 |
@i<T>'Class is available at places where one of the following conditions is true:]} |
| 3421 |
|
| 3422 |
@begin{Itemize} |
| 3423 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3424 |
@ChgAdded{Version=[2],Text=[@i<T> is nonlimited;]} |
| 3425 |
|
| 3426 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3427 |
@ChgAdded{Version=[2],Text=[the attribute has been specified via an |
| 3428 |
@nt{attribute_definition_clause}, and the @nt{attribute_definition_clause} |
| 3429 |
is visible; or]} |
| 3430 |
|
| 3431 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3432 |
@ChgAdded{Version=[2],Text=[the corresponding attribute of @i<T> is |
| 3433 |
available, provided that if @i<T> has a partial view, the corresponding |
| 3434 |
attribute is available at the end of the visible part where @i<T> is |
| 3435 |
declared.]} |
| 3436 |
|
| 3437 |
@end{Itemize} |
| 3438 |
@begin{Reason} |
| 3439 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3440 |
@ChgAdded{Version=[2],Text=[The rules are stricter for class-wide attributes |
| 3441 |
because (for the default implementation) we must ensure that any specific |
| 3442 |
attribute that might ever be dispatched to is available. Because we require |
| 3443 |
specification of attributes for extensions of limited parent types with |
| 3444 |
available attributes, we can in fact know this. Otherwise, we would not be |
| 3445 |
able to use default class-wide attributes with limited types, a significant |
| 3446 |
limitation.]} |
| 3447 |
@end{Reason} |
| 3448 |
|
| 3449 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3450 |
@ChgAdded{Version=[2],Text=[An @nt{attribute_reference} for one of the |
| 3451 |
stream-oriented attributes is illegal unless the attribute is available at |
| 3452 |
the place of the @nt{attribute_reference}. Furthermore, an |
| 3453 |
@nt{attribute_reference} for @i<T>'Input is illegal if @i<T> is an abstract |
| 3454 |
type.]} |
| 3455 |
|
| 3456 |
@begin{Discussion} |
| 3457 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3458 |
@ChgAdded{Version=[2],Text=[Stream attributes always exist. It is illegal |
| 3459 |
to call them in some cases. Having the attributes not be defined for |
| 3460 |
some limited types would seem to be a cleaner solution, but it would lead |
| 3461 |
to contract model problems for limited private types.]} |
| 3462 |
|
| 3463 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3464 |
@ChgAdded{Version=[2],Text=[@i<T>'Input is available for abstract types |
| 3465 |
so that @i<T>'Class'Input is available. But we certainly don't want to allow |
| 3466 |
calls that could create an object of an abstract type. Remember that |
| 3467 |
@i<T>'Class is never abstract, so the above legality rule doesn't apply to |
| 3468 |
it. We don't have to discuss whether the attribute is specified, as it cannot |
| 3469 |
be: any function returning the type would have to be abstract, and we do not |
| 3470 |
allow specifying an attribute with an abstract subprogram.]} |
| 3471 |
@end{Discussion} |
| 3472 |
|
| 3473 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3474 |
@ChgAdded{Version=[2],Text=[In the @nt{parameter_and_result_profile}s for the |
| 3475 |
stream-oriented attributes, the subtype of the Item parameter is the base |
| 3476 |
subtype of @i<T> if @i<T> is a scalar type, and the first subtype otherwise. |
| 3477 |
The same rule applies to the result of the Input attribute.]} |
| 3478 |
|
| 3479 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3480 |
@ChgAdded{Version=[2],Text=[For an @nt{attribute_definition_clause} specifying |
| 3481 |
one of these attributes, the subtype of the Item parameter shall be the base |
| 3482 |
subtype if scalar, and the first subtype otherwise. The same rule applies to |
| 3483 |
the result of the Input function.]} |
| 3484 |
|
| 3485 |
@begin{Reason} |
| 3486 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3487 |
@ChgAdded{Version=[2],Text=[This is to simplify implementation.]} |
| 3488 |
@end{Reason} |
| 3489 |
@begin{Ramification} |
| 3490 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3491 |
@ChgAdded{Version=[2],Text=[The view of the type at the point of the |
| 3492 |
@nt{attribute_definition_clause} determines whether the first subtype or base |
| 3493 |
subtype is required. Thus, for a scalar type with a partial view (which is |
| 3494 |
never scalar), whether the first subtype or the base subtype is required is |
| 3495 |
determined by whether the @nt{attribute_definition_clause} occurs before or |
| 3496 |
after the full definition of the scalar type.]} |
| 3497 |
@end{Ramification} |
| 3498 |
|
| 3499 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]} |
| 3500 |
@ChgAdded{Version=[2],Text=[@Defn{support external streaming} |
| 3501 |
@Defn2{Term=[external streaming],Sec={type supports}} |
| 3502 |
@Redundant[A type is said to @i{support external streaming} if Read and Write attributes |
| 3503 |
are provided for sending values of such a type between active |
| 3504 |
partitions, with Write marshalling the representation, and Read unmarshalling |
| 3505 |
the representation.] A limited type supports external streaming only if |
| 3506 |
it has available Read and Write attributes. A type with a part that is of an |
| 3507 |
access type supports external streaming only if that access type or the type of |
| 3508 |
some part that includes the access type component, has Read and Write |
| 3509 |
attributes that have been specified via an @nt{attribute_definition_clause}, |
| 3510 |
and that @nt{attribute_definition_clause} is visible. @Redundant[An anonymous |
| 3511 |
access type does not support external streaming. ]All other types support |
| 3512 |
external streaming.]} |
| 3513 |
|
| 3514 |
@begin{Ramification} |
| 3515 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3516 |
@ChgAdded{Version=[2],Text=[A limited type with a part that is of an access |
| 3517 |
type needs to satisfy both rules.]} |
| 3518 |
@end{Ramification} |
| 3519 |
|
| 3520 |
@end{StaticSem} |
| 3521 |
|
| 3522 |
@begin{Erron} |
| 3523 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01],ARef=[AI95-00344-01]} |
| 3524 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 3525 |
If the internal tag returned by Descendant_Tag to T'Class'Input identifies a |
| 3526 |
type that is not library-level and whose tag has not been created, or does not |
| 3527 |
exist in the partition at the time of the call, execution is erroneous.]} |
| 3528 |
@begin{Ramification} |
| 3529 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3530 |
@ChgAdded{Version=[2],Text=[The definition of Descendant_Tag prevents such |
| 3531 |
a tag from being provided to T'Class'Input if T is a library-level type. |
| 3532 |
However, this rule is needed for nested tagged types.]} |
| 3533 |
@end{Ramification} |
| 3534 |
@end{Erron} |
| 3535 |
|
| 3536 |
@begin{ImplReq} |
| 3537 |
@ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 3538 |
@ChgAdded{Version=[1],Text=[For every subtype @i<S> of a language-defined |
| 3539 |
nonlimited specific type @i<T>, the output generated by S'Output or S'Write |
| 3540 |
shall be readable by S'Input or S'Read, respectively. This rule applies |
| 3541 |
across partitions if the implementation conforms to the Distributed Systems |
| 3542 |
Annex.]} |
| 3543 |
|
| 3544 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3545 |
@ChgAdded{Version=[2],Text=[If Constraint_Error is raised during a call to |
| 3546 |
Read because of failure of one the above checks, the implementation must |
| 3547 |
ensure that the discriminants of the actual parameter of Read are not |
| 3548 |
modified.]} |
| 3549 |
@end{ImplReq} |
| 3550 |
|
| 3551 |
@begin{ImplPerm} |
| 3552 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3553 |
@ChgAdded{Version=[2],Text=[The number of calls performed by the predefined |
| 3554 |
implementation of the stream-oriented attributes on the Read and Write |
| 3555 |
operations of the stream type is unspecified. An implementation may take |
| 3556 |
advantage of this permission to perform internal buffering. However, all the |
| 3557 |
calls on the Read and Write operations of the stream type needed to implement |
| 3558 |
an explicit invocation of a stream-oriented attribute must take place before |
| 3559 |
this invocation returns. An explicit invocation is one appearing explicitly |
| 3560 |
in the program text, possibly through a generic instantiation (see |
| 3561 |
@RefSecNum{Generic Instantiation}).]} |
| 3562 |
@end{ImplPerm} |
| 3563 |
|
| 3564 |
@begin{Notes} |
| 3565 |
For a definite subtype S of a type @i(T), only @i(T)'Write and @i(T)'Read |
| 3566 |
are needed to pass |
| 3567 |
an arbitrary value of the subtype through a stream. |
| 3568 |
For an indefinite subtype S of a type @i(T), @i(T)'Output and @i(T)'Input |
| 3569 |
will normally be needed, since @i(T)'Write and @i(T)'Read do not |
| 3570 |
pass bounds, discriminants, or tags. |
| 3571 |
|
| 3572 |
User-specified attributes of S'Class are not inherited by other |
| 3573 |
class-wide types descended from S. |
| 3574 |
@end{Notes} |
| 3575 |
|
| 3576 |
@begin{Examples} |
| 3577 |
@leading@keepnext@i{Example of user-defined Write attribute:} |
| 3578 |
@begin{Example} |
| 3579 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 3580 |
@key[procedure] My_Write( |
| 3581 |
Stream : @key[@Chg{Version=[2],New=[not null ],Old=[]}access] Ada.Streams.Root_Stream_Type'Class;@Chg{Version=[2],New=[ |
| 3582 |
],Old=[]}Item@Chg{Version=[2],New=[ ],Old=[]} : My_Integer'Base); |
| 3583 |
@key(for) My_Integer'Write @key(use) My_Write; |
| 3584 |
@end{Example} |
| 3585 |
@begin{Discussion} |
| 3586 |
@leading@keepnext@i{Example of network input/output using input output attributes:} |
| 3587 |
@begin{Example} |
| 3588 |
@key(with) Ada.Streams; @key(use) Ada.Streams; |
| 3589 |
@key(generic) |
| 3590 |
@key(type) Msg_Type(<>) @key(is private); |
| 3591 |
@key(package) Network_IO @key(is) |
| 3592 |
--@RI[ Connect/Disconnect are used to establish the stream] |
| 3593 |
@key(procedure) Connect(...); |
| 3594 |
@key(procedure) Disconnect(...); |
| 3595 |
|
| 3596 |
--@RI[ Send/Receive transfer messages across the network] |
| 3597 |
@key(procedure) Send(X : @key[in] Msg_Type); |
| 3598 |
@key(function) Receive @key(return) Msg_Type; |
| 3599 |
@key(private) |
| 3600 |
@key(type) Network_Stream @key(is new) Root_Stream_Type @key(with) ... |
| 3601 |
@key(procedure) Read(...); --@RI[ define Read/Write for Network_Stream] |
| 3602 |
@key(procedure) Write(...); |
| 3603 |
@key(end) Network_IO; |
| 3604 |
|
| 3605 |
@key(with) Ada.Streams; @key(use) Ada.Streams; |
| 3606 |
@key(package body) Network_IO @key(is) |
| 3607 |
Current_Stream : @key(aliased) Network_Stream; |
| 3608 |
. . . |
| 3609 |
@key(procedure) Connect(...) @key(is) ...; |
| 3610 |
@key(procedure) Disconnect(...) @key(is) ...; |
| 3611 |
|
| 3612 |
@key(procedure) Send(X : @key[in] Msg_Type) @key(is) |
| 3613 |
@key(begin) |
| 3614 |
Msg_Type'Output(Current_Stream'Access, X); |
| 3615 |
@key(end) Send; |
| 3616 |
|
| 3617 |
@key(function) Receive @key(return) Msg_Type @key(is) |
| 3618 |
@key(begin) |
| 3619 |
@key(return) Msg_Type'Input(Current_Stream'Access); |
| 3620 |
@key(end) Receive; |
| 3621 |
@key(end) Network_IO; |
| 3622 |
@end{Example} |
| 3623 |
@end{Discussion} |
| 3624 |
@end{Examples} |
| 3625 |
|
| 3626 |
@begin{Inconsistent95} |
| 3627 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 3628 |
@ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95} |
| 3629 |
@b<Corrigendum:> Clarified how the default |
| 3630 |
implementation for stream attributes is determined (eliminating conflicting |
| 3631 |
language). The new wording provides that attributes for type extensions are |
| 3632 |
created by composing the parent's attribute with those for the extension |
| 3633 |
components if any. If a program was written assuming that the extension |
| 3634 |
components were not included in the stream (as in original Ada 95), it |
| 3635 |
would fail to work in the language as corrected by the Corrigendum.]} |
| 3636 |
|
| 3637 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3638 |
@ChgAdded{Version=[2],Text=[@B[Amendment Correction:] Explicitly provided a |
| 3639 |
permission that the number of calls to the underlying stream Read and Write |
| 3640 |
operations may differ from the number determined by the canonical operations. |
| 3641 |
If Ada 95 code somehow depended on the number of calls to Read or Write, it |
| 3642 |
could fail with an Ada 2005 implementation. Such code is likely to be very |
| 3643 |
rare; moreover, such code is really wrong, as the permission applies to Ada |
| 3644 |
95 as well.]} |
| 3645 |
@end{Inconsistent95} |
| 3646 |
|
| 3647 |
@begin{Extend95} |
| 3648 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00270-01]} |
| 3649 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 3650 |
The Stream_Size attribute is new. It allows specifying the number of bits |
| 3651 |
that will be streamed for a type. The @ImplAdviceTitle involving this |
| 3652 |
also was changed; this is not incompatible because @ImplAdviceTitle does |
| 3653 |
not have to be followed.]} |
| 3654 |
|
| 3655 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01],ARef=[AI95-00195-01],ARef=[AI95-00444-01]} |
| 3656 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Limited types may have default |
| 3657 |
constructed attributes if all of the parent and (for extensions) extension |
| 3658 |
components have available attributes. Ada 2005 adds the notion of |
| 3659 |
availability to patch up some holes in the Corrigendum model.]} |
| 3660 |
@end{Extend95} |
| 3661 |
|
| 3662 |
@begin{DiffWord95} |
| 3663 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 3664 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that |
| 3665 |
these are operational attributes.]} |
| 3666 |
|
| 3667 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0045],ARef=[AI95-00132-01]} |
| 3668 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that End_Error |
| 3669 |
is raised by the default implementation of Read and Input if the end of |
| 3670 |
the stream is reached. (The result could have been abnormal without this |
| 3671 |
clarification, thus this is not an inconsistency, as the programmer could |
| 3672 |
not have depended on the previous behavior.)]} |
| 3673 |
|
| 3674 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3675 |
@ChgAdded{Version=[2],Text=[Clarified that the default implementation of |
| 3676 |
S'Input does normal initialization on the object that it passes to S'Read.]} |
| 3677 |
|
| 3678 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]} |
| 3679 |
@ChgAdded{Version=[2],Text=[Explicitly stated that what is read from a |
| 3680 |
stream when a required check fails is unspecified.]} |
| 3681 |
|
| 3682 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]} |
| 3683 |
@ChgAdded{Version=[2],Text=[Defined availability and default implementations |
| 3684 |
for types with progenitors.]} |
| 3685 |
|
| 3686 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]} |
| 3687 |
@ChgAdded{Version=[2],Text=[Specified that Constraint_Error is raised if |
| 3688 |
the internal tag retrieved for S'Class'Input is for some type not covered |
| 3689 |
by S'Class or is abstract. We also explicitly state that the program is |
| 3690 |
erroneous if the tag has not been created or does not currently exist in |
| 3691 |
the partition. (Ada 95 did not specify what happened in these |
| 3692 |
cases; it's very unlikely to have provided some useful result, so this is |
| 3693 |
not considered an inconsistency.)]} |
| 3694 |
|
| 3695 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]} |
| 3696 |
@ChgAdded{Version=[2],Text=[Added wording to support nested type extensions. |
| 3697 |
S'Input and S'Output always raise Tag_Error for such extensions, and such |
| 3698 |
extensions were not permitted in Ada 95, so this is neither an extension |
| 3699 |
nor an incompatibility.]} |
| 3700 |
|
| 3701 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]} |
| 3702 |
@ChgAdded{Version=[2],Text=[Defined @i<supports external streaming> to |
| 3703 |
put all of the rules about @lquotes@;good@rquotes stream attributes in one |
| 3704 |
place. This is used for distribution and for defining pragma Pure.]} |
| 3705 |
|
| 3706 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00441-01]} |
| 3707 |
@ChgAdded{Version=[2],Text=[Added the @key[not null] qualifier to the |
| 3708 |
first parameter of all of the stream attributes, so that the semantics |
| 3709 |
doesn't change between Ada 95 and Ada 2005. This change is compatible, |
| 3710 |
because mode conformance is required for subprograms specified as |
| 3711 |
stream attributes, and @nt{null_exclusion}s are not considered for |
| 3712 |
mode conformance.]} |
| 3713 |
|
| 3714 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00444-01]} |
| 3715 |
@ChgAdded{Version=[2],Text=[Improved the wording to make it clear that |
| 3716 |
we don't define the default implementations of attributes that cannot be |
| 3717 |
called (that is, aren't @lquotes@;available@rquotes@;). Also clarified when |
| 3718 |
inheritance takes place.]} |
| 3719 |
@end{DiffWord95} |
| 3720 |
|
| 3721 |
|
| 3722 |
@LabeledClause{Freezing Rules} |
| 3723 |
|
| 3724 |
@begin{Intro} |
| 3725 |
@redundant[This clause defines |
| 3726 |
a place in the program text where each declared entity becomes |
| 3727 |
@lquotes@;frozen.@rquotes@; |
| 3728 |
A use of an entity, such as a reference to it by name, |
| 3729 |
or (for a type) an expression of the type, |
| 3730 |
causes freezing of the entity in some contexts, |
| 3731 |
as described below. |
| 3732 |
The @LegalityTitle forbid certain kinds of uses of an entity |
| 3733 |
in the region of text where it is frozen.] |
| 3734 |
@begin{Reason} |
| 3735 |
This concept has two purposes: a compile-time one and a run-time one. |
| 3736 |
|
| 3737 |
The compile-time purpose of the freezing rules comes from the fact that |
| 3738 |
the evaluation of static expressions depends on overload resolution, |
| 3739 |
and overload resolution sometimes depends on the value of a |
| 3740 |
static expression. |
| 3741 |
(The dependence of static evaluation upon overload resolution is |
| 3742 |
obvious. The dependence in the other direction is more subtle. |
| 3743 |
There are three rules that require static expressions in contexts that |
| 3744 |
can appear in declarative places: The expression in an |
| 3745 |
@nt{attribute_designator} shall be static. |
| 3746 |
In a record aggregate, variant-controlling discriminants shall be static. |
| 3747 |
In an array aggregate with more than one named association, |
| 3748 |
the choices shall be static. |
| 3749 |
The compiler needs to know the value of these expressions in order to |
| 3750 |
perform overload resolution and legality checking.) |
| 3751 |
We wish to allow a compiler to evaluate static expressions when it sees |
| 3752 |
them in a single pass over the @nt{compilation_unit}. |
| 3753 |
The freezing rules ensure that. |
| 3754 |
|
| 3755 |
The run-time purpose of the freezing rules is called the @lquotes@;linear |
| 3756 |
elaboration model.@rquotes@; |
| 3757 |
This means that declarations are elaborated in the order in which they |
| 3758 |
appear in the program text, |
| 3759 |
and later elaborations can depend on the results of earlier ones. |
| 3760 |
The elaboration of the declarations of certain entities requires run-time |
| 3761 |
information about the implementation details of other entities. |
| 3762 |
The freezing rules ensure that this information has been calculated by |
| 3763 |
the time it is used. |
| 3764 |
For example, suppose the initial value of a constant is the result of |
| 3765 |
a function call that takes a parameter of type @i(T). |
| 3766 |
In order to pass that parameter, the size of type @i(T) has to be known. |
| 3767 |
If @i(T) is composite, that size might be known only at run time. |
| 3768 |
|
| 3769 |
(Note that in these discussions, words like @lquotes@;before@rquotes@; and @lquotes@;after@rquotes@; |
| 3770 |
generally refer to places in the program text, |
| 3771 |
as opposed to times at run time.) |
| 3772 |
@end{Reason} |
| 3773 |
@begin{Discussion} |
| 3774 |
@leading@;The @lquotes@;implementation details@rquotes@; we're talking |
| 3775 |
about above are: |
| 3776 |
@begin{Itemize} |
| 3777 |
For a tagged type, |
| 3778 |
the implementations of all the primitive subprograms of the type |
| 3779 |
@em that is (in the canonical implementation model), |
| 3780 |
the contents of the type descriptor, which contains pointers to the code for |
| 3781 |
each primitive subprogram. |
| 3782 |
|
| 3783 |
For a type, the full type declaration of any parts (including the type itself) |
| 3784 |
that are private. |
| 3785 |
|
| 3786 |
For a deferred constant, |
| 3787 |
the full constant declaration, which gives the constant's value. |
| 3788 |
(Since this information necessarily comes after the constant's type |
| 3789 |
and subtype are fully |
| 3790 |
known, there's no need to worry about its type or subtype.) |
| 3791 |
|
| 3792 |
For any entity, |
| 3793 |
representation information specified by the user |
| 3794 |
via representation items. |
| 3795 |
Most representation items are for types |
| 3796 |
or subtypes; however, various other kinds of entities, |
| 3797 |
such as objects and subprograms, are possible. |
| 3798 |
@end{Itemize} |
| 3799 |
|
| 3800 |
Similar issues arise for incomplete types. |
| 3801 |
However, we do not use freezing there; |
| 3802 |
incomplete types have different, more severe, restrictions. |
| 3803 |
Similar issues also arise for subprograms, protected operations, |
| 3804 |
tasks and generic units. |
| 3805 |
However, we do not use freezing there either; |
| 3806 |
@RefSecNum{Declarative Parts} prevents problems with run-time |
| 3807 |
Elaboration_Checks. |
| 3808 |
@end{Discussion} |
| 3809 |
@end{Intro} |
| 3810 |
|
| 3811 |
@begin{MetaRules} |
| 3812 |
An evaluable construct should freeze anything that's needed to evaluate |
| 3813 |
it. |
| 3814 |
|
| 3815 |
However, if the construct is not evaluated where it appears, |
| 3816 |
let it cause freezing later, when it is evaluated. |
| 3817 |
This is the case for @nt{default_expression}s and @nt{default_name}s. |
| 3818 |
(Formal parameters, generic formal parameters, and components can have |
| 3819 |
@nt{default_expression}s or @nt{default_name}s.) |
| 3820 |
|
| 3821 |
The compiler should be allowed to evaluate static expressions without |
| 3822 |
knowledge of their context. (I.e. there should not be any special |
| 3823 |
rules for static expressions that happen to occur in a context that |
| 3824 |
requires a static expression.) |
| 3825 |
|
| 3826 |
Compilers should be allowed to evaluate static expressions (and record |
| 3827 |
the results) using the run-time representation of the type. |
| 3828 |
For example, suppose Color'Pos(Red) = 1, but the internal code for Red |
| 3829 |
is 37. |
| 3830 |
If the value of a static expression is Red, |
| 3831 |
some compilers might store 1 in their symbol table, |
| 3832 |
and other compilers might store 37. |
| 3833 |
Either compiler design should be feasible. |
| 3834 |
|
| 3835 |
Compilers should never be required to detect erroneousness or exceptions at |
| 3836 |
compile time (although it's very nice if they do). |
| 3837 |
This implies that we should not require |
| 3838 |
code-generation for a nonstatic expression of type @i(T) too early, |
| 3839 |
even if we can prove that that expression will be erroneous, |
| 3840 |
or will raise an exception. |
| 3841 |
|
| 3842 |
@Leading@;Here's an example (modified from AI83-00039, Example 3): |
| 3843 |
@begin{example} |
| 3844 |
@key[type] T @key[is] |
| 3845 |
@key[record] |
| 3846 |
... |
| 3847 |
@key[end] @key[record]; |
| 3848 |
@key[function] F @key[return] T; |
| 3849 |
@key[function] G(X : T) @key[return] Boolean; |
| 3850 |
Y : Boolean := G(F); --@RI{ doesn't force T in Ada 83} |
| 3851 |
@key[for] T @key[use] |
| 3852 |
@key[record] |
| 3853 |
... |
| 3854 |
@key[end] @key[record]; |
| 3855 |
@end{example} |
| 3856 |
|
| 3857 |
@Leading@;AI83-00039 says this is legal. |
| 3858 |
Of course, it raises Program_Error because the function bodies aren't |
| 3859 |
elaborated yet. A one-pass compiler has to generate code for an expression of |
| 3860 |
type T before it knows the representation of T. |
| 3861 |
Here's a similar example, which AI83-00039 also says is legal: |
| 3862 |
@begin{example} |
| 3863 |
@key[package] P @key[is] |
| 3864 |
@key[type] T @key[is] @key[private]; |
| 3865 |
@key[function] F @key[return] T; |
| 3866 |
@key[function] G(X : T) @key[return] Boolean; |
| 3867 |
Y : Boolean := G(F); --@RI{ doesn't force T in Ada 83} |
| 3868 |
@key[private] |
| 3869 |
@key[type] T @key[is] |
| 3870 |
@key[record] |
| 3871 |
... |
| 3872 |
@key[end] @key[record]; |
| 3873 |
@key[end] P; |
| 3874 |
@end{example} |
| 3875 |
|
| 3876 |
If T's size were dynamic, that size would be stored in some |
| 3877 |
compiler-generated dope; this dope would be initialized at the place |
| 3878 |
of the full type declaration. |
| 3879 |
However, the generated code for the function calls |
| 3880 |
would most likely allocate a temp of the size specified by the dope |
| 3881 |
@i{before} checking for Program_Error. |
| 3882 |
That dope would contain uninitialized junk, |
| 3883 |
resulting in disaster. |
| 3884 |
To avoid doing that, |
| 3885 |
the compiler would have to determine, |
| 3886 |
at compile time, that the expression will raise Program_Error. |
| 3887 |
|
| 3888 |
This is silly. If we're going to require compilers to detect the exception at |
| 3889 |
compile time, we might as well formulate the rule as a legality rule. |
| 3890 |
|
| 3891 |
Compilers should not be required to generate code to load the value |
| 3892 |
of a variable before the address of the variable has been determined. |
| 3893 |
|
| 3894 |
After an entity has been frozen, no further requirements may be |
| 3895 |
placed on its representation (such as by a representation item |
| 3896 |
or a @nt{full_type_declaration}). |
| 3897 |
@end{MetaRules} |
| 3898 |
|
| 3899 |
@begin{Intro} |
| 3900 |
@RootDefn2{Term=[freezing], Sec=(entity)} |
| 3901 |
@Defn2{Term=[freezing points], Sec=(entity)} |
| 3902 |
The @i(freezing) of an entity occurs at one or more places |
| 3903 |
(@i{freezing points}) in the program |
| 3904 |
text where the representation for the entity has to be |
| 3905 |
fully determined. Each entity is frozen from its first |
| 3906 |
freezing point to the end of the program text |
| 3907 |
(given the ordering of compilation units defined in |
| 3908 |
@RefSecNum{The Compilation Process}). |
| 3909 |
@begin{Ramification} |
| 3910 |
The @lquotes@;representation@rquotes@; for a subprogram includes its calling convention |
| 3911 |
and means for referencing the subprogram body, either a @lquotes@;link-name@rquotes@; or |
| 3912 |
specified address. It does |
| 3913 |
not include the code for the subprogram body itself, nor its |
| 3914 |
address if a link-name is used to reference the body. |
| 3915 |
@end{Ramification} |
| 3916 |
|
| 3917 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0014]} |
| 3918 |
@Defn2{Term=[freezing], |
| 3919 |
Sec=(entity caused by the end of an enclosing construct)} |
| 3920 |
The end of a @nt{declarative_part}, @nt{protected_body}, |
| 3921 |
or a declaration of a library package or generic library package, |
| 3922 |
causes @i(freezing) of each entity declared within it, |
| 3923 |
except for incomplete types. |
| 3924 |
@Defn2{Term=[freezing], Sec=(entity caused by a body)} |
| 3925 |
A noninstance body@Chg{New=[ other than a renames-as-body],Old=[]} causes |
| 3926 |
freezing of each entity declared before it within the same |
| 3927 |
@nt{declarative_part}. |
| 3928 |
@begin{Discussion} |
| 3929 |
This is worded carefully to handle nested packages |
| 3930 |
and private types. |
| 3931 |
Entities declared in a nested @nt{package_specification} |
| 3932 |
will be frozen by some containing construct. |
| 3933 |
|
| 3934 |
An incomplete type declared in the private part of |
| 3935 |
a library @nt{package_specification} |
| 3936 |
can be completed in the body. |
| 3937 |
@end{Discussion} |
| 3938 |
@begin{Ramification} |
| 3939 |
The part about bodies does not say @i{immediately} within. |
| 3940 |
A renaming-as-body does not have this property. |
| 3941 |
Nor does a @nt{pragma} Import. |
| 3942 |
@end{Ramification} |
| 3943 |
@begin{Reason} |
| 3944 |
The reason bodies cause freezing is because we want |
| 3945 |
@ntf{proper_bodies} and @nt{body_stub}s to be interchangeable @em one |
| 3946 |
should be able to move a @nt{proper_body} to a @nt{subunit}, and |
| 3947 |
vice-versa, without changing the semantics. |
| 3948 |
Clearly, anything that should cause freezing should do so even if |
| 3949 |
it's inside a @nt{proper_body}. |
| 3950 |
However, if we make it a @nt{body_stub}, then the compiler can't |
| 3951 |
see that thing that should cause freezing. |
| 3952 |
So we make @nt{body_stub}s cause freezing, just in case they |
| 3953 |
contain something that should cause freezing. |
| 3954 |
But that means we need to do the same for @ntf{proper_bodies}. |
| 3955 |
|
| 3956 |
Another reason for bodies to cause freezing, |
| 3957 |
there could be an added implementation burden if an entity |
| 3958 |
declared in an enclosing @nt<declarative_part> is frozen |
| 3959 |
within a nested body, |
| 3960 |
since some compilers look at bodies after looking |
| 3961 |
at the containing @nt{declarative_part}. |
| 3962 |
@end{Reason} |
| 3963 |
|
| 3964 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0046],ARef=[AI95-00106-01]} |
| 3965 |
@Leading@RootDefn2{Term=[freezing], Sec=(entity caused by a construct)} |
| 3966 |
A construct that (explicitly or implicitly) references an |
| 3967 |
entity can cause the @i(freezing) of the entity, as defined by |
| 3968 |
subsequent paragraphs. |
| 3969 |
@PDefn2{Term=[freezing], Sec=(by a constituent of a construct)} |
| 3970 |
At the place where a construct causes freezing, |
| 3971 |
each @nt<name>, @Chg{New=[@nt<expression>, @nt<implicit_dereference>], |
| 3972 |
Old=[expression]}@Redundant[, or @nt{range}] within the construct causes |
| 3973 |
freezing: |
| 3974 |
@begin{Ramification} |
| 3975 |
Note that in the sense of this paragraph, |
| 3976 |
a @nt{subtype_mark} @lquotes@;references@rquotes@; the denoted subtype, |
| 3977 |
but not the type. |
| 3978 |
@end{Ramification} |
| 3979 |
|
| 3980 |
@begin{Itemize} |
| 3981 |
@Leading@PDefn2{Term=[freezing], Sec=(generic_instantiation)} |
| 3982 |
The occurrence of a @nt{generic_instantiation} causes freezing; |
| 3983 |
also, if a parameter of the instantiation is defaulted, |
| 3984 |
the @nt{default_expression} or @nt{default_name} for that parameter |
| 3985 |
causes freezing. |
| 3986 |
|
| 3987 |
@Leading@PDefn2{Term=[freezing], Sec=(object_declaration)} |
| 3988 |
The occurrence of an @nt<object_declaration> that has no corresponding |
| 3989 |
completion causes freezing. |
| 3990 |
@begin{Ramification} |
| 3991 |
Note that this does not include a @nt{formal_object_declaration}. |
| 3992 |
@end{Ramification} |
| 3993 |
|
| 3994 |
@PDefn2{Term=[freezing], Sec=(subtype caused by a record extension)} |
| 3995 |
The declaration of a record extension causes freezing of the parent |
| 3996 |
subtype. |
| 3997 |
@begin{Ramification} |
| 3998 |
This combined with another rule specifying |
| 3999 |
that primitive subprogram declarations shall precede freezing |
| 4000 |
ensures that all descendants of a tagged type implement all of |
| 4001 |
its dispatching operations. |
| 4002 |
|
| 4003 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]} |
| 4004 |
The declaration of a private |
| 4005 |
extension does not cause freezing. The freezing is deferred |
| 4006 |
until the full type declaration, which will necessarily be |
| 4007 |
for a record extension@Chg{Version=[2],New=[, task, or protected type (the |
| 4008 |
latter only for a limited private extension derived from an interface)], |
| 4009 |
Old=[]}. |
| 4010 |
@end{Ramification} |
| 4011 |
|
| 4012 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]} |
| 4013 |
@ChgAdded{Version=[2],Text=[The declaration of a record extension, |
| 4014 |
interface type, task unit, or protected unit causes freezing of any |
| 4015 |
progenitor types specified in the declaration.]} |
| 4016 |
@begin{Reason} |
| 4017 |
@ChgRef{Version=[2],Kind=[Added]} |
| 4018 |
@ChgAdded{Version=[2],Text=[This rule has the same purpose as the one |
| 4019 |
above: ensuring that all descendants of an interface tagged type implement all |
| 4020 |
of its dispatching operations. As with the previous rule, a private extension |
| 4021 |
does not freeze its progenitors; the full type declaration (which must have the |
| 4022 |
same progenitors) will do that.]} |
| 4023 |
@end{Reason} |
| 4024 |
@begin{Ramification} |
| 4025 |
@ChgRef{Version=[2],Kind=[Added]} |
| 4026 |
@ChgAdded{Version=[2],Text=[An interface type can be a parent as well as a |
| 4027 |
progenitor; these rules are similar so that the location of an interface |
| 4028 |
in a record extension does not have an effect on the freezing of the interface |
| 4029 |
type.]} |
| 4030 |
@end{Ramification} |
| 4031 |
@end{Itemize} |
| 4032 |
|
| 4033 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0046],ARef=[AI95-00106-01]} |
| 4034 |
@PDefn2{Term=[freezing], Sec=(by an expression)} |
| 4035 |
A static expression causes freezing where it occurs. |
| 4036 |
@Chg{New=[@PDefn2{Term=[freezing], Sec=(by an object name)} |
| 4037 |
An object name or],Old=[A]} nonstatic expression causes freezing where it |
| 4038 |
occurs, unless the @Chg{New=[name or ],Old=[]}expression is part of a |
| 4039 |
@nt<default_expression>, a @nt<default_name>, or a per-object expression |
| 4040 |
of a component's @nt<constraint>, in which case, |
| 4041 |
the freezing occurs later as part of another construct. |
| 4042 |
|
| 4043 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0046],ARef=[AI95-00106-01]} |
| 4044 |
@ChgAdded{Version=[1],Text=[@PDefn2{Term=[freezing], Sec=(by an implicit call)} |
| 4045 |
An implicit call freezes the same entities that would be frozen by an |
| 4046 |
explicit call. This is true even if the implicit call is removed via |
| 4047 |
implementation permissions.]} |
| 4048 |
|
| 4049 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0046],ARef=[AI95-00106-01]} |
| 4050 |
@ChgAdded{Version=[1],Text=[@PDefn2{Term=[freezing], Sec=(subtype caused by an implicit conversion)} |
| 4051 |
If an expression is implicitly converted to a type or subtype @i(T), |
| 4052 |
then at the place where the expression causes freezing, @i(T) is frozen.]} |
| 4053 |
|
| 4054 |
@Leading@;The following rules define which entities are frozen at the place where |
| 4055 |
a construct causes freezing: |
| 4056 |
@begin{Itemize} |
| 4057 |
@Leading@PDefn2{Term=[freezing], Sec=(type caused by an expression)} |
| 4058 |
At the place where an expression causes freezing, |
| 4059 |
the type of the expression is frozen, |
| 4060 |
unless the expression is an enumeration literal used as a |
| 4061 |
@nt{discrete_choice} of the @nt{array_@!aggregate} of an |
| 4062 |
@nt{enumeration_@!representation_@!clause}. |
| 4063 |
@begin{Reason} |
| 4064 |
We considered making enumeration literals never cause freezing, |
| 4065 |
which would be more upward compatible, |
| 4066 |
but examples like the variant record aggregate (Discrim => Red, ...) |
| 4067 |
caused us to change our mind. |
| 4068 |
Furthermore, an enumeration literal is a static expression, |
| 4069 |
so the implementation should be allowed to represent it using its |
| 4070 |
representation. |
| 4071 |
@end{Reason} |
| 4072 |
@begin{Ramification} |
| 4073 |
@Leading@;The following pathological example was legal in Ada 83, |
| 4074 |
but is illegal in Ada 95: |
| 4075 |
@begin{Example} |
| 4076 |
@key[package] P1 @key[is] |
| 4077 |
@key[type] T @key[is] @key[private]; |
| 4078 |
@key[package] P2 @key[is] |
| 4079 |
@key[type] Composite(D : Boolean) @key[is] |
| 4080 |
@key[record] |
| 4081 |
@key[case] D @key[is] |
| 4082 |
@key[when] False => Cf : Integer; |
| 4083 |
@key[when] True => Ct : T; |
| 4084 |
@key[end] @key[case]; |
| 4085 |
@key[end] @key[record]; |
| 4086 |
@key[end] P2; |
| 4087 |
X : Boolean := P2."="( (False,1), (False,1) ); |
| 4088 |
@key[private] |
| 4089 |
@key[type] T @key[is] @key[array](1..Func_Call) @key[of] Integer; |
| 4090 |
@key[end]; |
| 4091 |
@end{Example} |
| 4092 |
|
| 4093 |
In Ada 95, the declaration of X freezes Composite |
| 4094 |
(because it contains an expression of that type), |
| 4095 |
which in turn freezes T (even though Ct does not exist in this |
| 4096 |
particular case). |
| 4097 |
But type T is not completely defined at that point, |
| 4098 |
violating the rule that a type shall be completely defined before it |
| 4099 |
is frozen. |
| 4100 |
In Ada 83, on the other hand, there is no occurrence of the name T, |
| 4101 |
hence no forcing occurrence of T. |
| 4102 |
@end{Ramification} |
| 4103 |
|
| 4104 |
@Leading@PDefn2{Term=[freezing], Sec=(entity caused by a name)} |
| 4105 |
At the place where a @nt<name> causes freezing, |
| 4106 |
the entity denoted by the @nt<name> is frozen, unless |
| 4107 |
the @nt<name> is a @nt<prefix> of an expanded name; |
| 4108 |
@PDefn2{Term=[freezing], Sec=(nominal subtype caused by a name)} |
| 4109 |
at the place where an object @nt{name} causes freezing, the |
| 4110 |
nominal subtype associated with the @nt<name> is frozen. |
| 4111 |
@begin{Ramification} |
| 4112 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 4113 |
This only matters in the presence of deferred constants or |
| 4114 |
access types; an @nt{object_declaration} other than a |
| 4115 |
@Chg{Version=[2],New=[deferred constant declaration],Old=[@ntf{deferred_constant_declaration}]} |
| 4116 |
causes freezing of the nominal subtype, plus all component junk. |
| 4117 |
|
| 4118 |
@ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0046],ARef=[AI95-00106-01]} |
| 4119 |
@ChgDeleted{Version=[1],Text=[@nt{Implicit_dereference}s are covered by |
| 4120 |
@nt{expression}.]} |
| 4121 |
@Comment{This statement is just plain wrong.} |
| 4122 |
@end{Ramification} |
| 4123 |
|
| 4124 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0046],ARef=[AI95-00106-01]} |
| 4125 |
@ChgAdded{Version=[1],Type=[Leading],Text=[@PDefn2{Term=[freezing], Sec=(subtype caused by an implicit dereference)} |
| 4126 |
At the place where an @nt{implicit_dereference} causes freezing, |
| 4127 |
the nominal subtype associated with the @nt{implicit_dereference} is frozen.]} |
| 4128 |
|
| 4129 |
@begin{Discussion} |
| 4130 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4131 |
@ChgAdded{Version=[2],Text=[This rule ensures that X.D freezes the same |
| 4132 |
entities that X.@key{all}.D does. Note that an @nt{implicit_dereference} is |
| 4133 |
neither a @nt{name} nor @nt{expression} by itself, so it isn't covered by |
| 4134 |
other rules.]} |
| 4135 |
@end{Discussion} |
| 4136 |
|
| 4137 |
@Leading@Redundant[@PDefn2{Term=[freezing], Sec=(type caused by a range)} |
| 4138 |
At the place where a @nt{range} causes freezing, the type of the |
| 4139 |
@nt<range> is frozen.] |
| 4140 |
@begin{TheProof} |
| 4141 |
This is consequence of the facts that expressions freeze their type, |
| 4142 |
and the Range attribute is defined to be equivalent |
| 4143 |
to a pair of expressions separated by @lquotes@;..@rquotes@;.} |
| 4144 |
@end{TheProof} |
| 4145 |
|
| 4146 |
@Leading@PDefn2{Term=[freezing], |
| 4147 |
Sec=(designated subtype caused by an allocator)} |
| 4148 |
At the place where an @nt<allocator> causes freezing, |
| 4149 |
the designated subtype of its type is frozen. |
| 4150 |
If the type of the @nt<allocator> is a derived type, |
| 4151 |
then all ancestor types are also frozen. |
| 4152 |
@begin{Ramification} |
| 4153 |
@nt{Allocator}s also freeze the named subtype, |
| 4154 |
as a consequence of other rules. |
| 4155 |
|
| 4156 |
@Leading@;The ancestor types are frozen to prevent things like this: |
| 4157 |
@begin{Example} |
| 4158 |
@key[type] Pool_Ptr @key[is] @key[access] System.Storage_Pools.Root_Storage_Pool'Class; |
| 4159 |
@key[function] F @key[return] Pool_Ptr; |
| 4160 |
|
| 4161 |
@key[package] P @key[is] |
| 4162 |
@key[type] A1 @key[is] @key[access] Boolean; |
| 4163 |
@key[type] A2 @key[is] @key[new] A1; |
| 4164 |
@key[type] A3 @key[is] @key[new] A2; |
| 4165 |
X : A3 := @key[new] Boolean; --@RI{ Don't know what pool yet!} |
| 4166 |
@key[for] A1'Storage_Pool @key[use] F.all; |
| 4167 |
@key[end] P; |
| 4168 |
@end{Example} |
| 4169 |
|
| 4170 |
This is necessary because derived access types share their parent's pool. |
| 4171 |
@end{Ramification} |
| 4172 |
|
| 4173 |
@Leading@PDefn2{Term=[freezing], Sec=(subtypes of the profile of a callable entity)} |
| 4174 |
At the place where a callable entity is frozen, |
| 4175 |
each subtype of its profile is frozen. |
| 4176 |
If the callable entity is a member of an entry family, the |
| 4177 |
index subtype of the family is frozen. |
| 4178 |
@PDefn2{Term=[freezing], Sec=(function call)} |
| 4179 |
At the place where a function call |
| 4180 |
causes freezing, if a parameter of the call is defaulted, |
| 4181 |
the @nt{default_@!expression} for that parameter causes freezing. |
| 4182 |
@begin{Discussion} |
| 4183 |
We don't worry about freezing for procedure calls or entry calls, since |
| 4184 |
a body freezes everything that precedes it, and |
| 4185 |
the end of a declarative part freezes everything in the declarative |
| 4186 |
part. |
| 4187 |
@end{Discussion} |
| 4188 |
|
| 4189 |
@Leading@PDefn2{Term=[freezing], |
| 4190 |
Sec=[type caused by the freezing of a subtype]} |
| 4191 |
At the place where a subtype is frozen, |
| 4192 |
its type is frozen. |
| 4193 |
@PDefn2{Term=[freezing], Sec=(constituents of a full type definition)} |
| 4194 |
@PDefn2{Term=[freezing], |
| 4195 |
Sec=(first subtype caused by the freezing of the type)} |
| 4196 |
At the place where a type is frozen, any expressions or @nt<name>s within |
| 4197 |
the full type definition cause freezing; |
| 4198 |
the first subtype, and |
| 4199 |
any component subtypes, |
| 4200 |
index subtypes, and parent subtype |
| 4201 |
of the type are frozen as well. |
| 4202 |
@PDefn2{Term=[freezing], |
| 4203 |
Sec=(class-wide type caused by the freezing of the specific type)} |
| 4204 |
@PDefn2{Term=[freezing], |
| 4205 |
Sec=(specific type caused by the freezing of the class-wide type)} |
| 4206 |
For a specific tagged type, |
| 4207 |
the corresponding class-wide type is frozen as well. |
| 4208 |
For a class-wide type, |
| 4209 |
the corresponding specific type is frozen as well. |
| 4210 |
@begin{Ramification} |
| 4211 |
Freezing a type needs to freeze its first subtype in order to |
| 4212 |
preserve the property that the subtype-specific aspects of statically |
| 4213 |
matching subtypes are the same. |
| 4214 |
|
| 4215 |
Freezing an access type does not freeze its designated subtype. |
| 4216 |
@end{Ramification} |
| 4217 |
|
| 4218 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00341-01]} |
| 4219 |
@ChgAdded{Version=[2],Type=[Leading],Text=[At the place where a specific |
| 4220 |
tagged type is frozen, the primitive subprograms of the type are frozen.]} |
| 4221 |
@begin{Reason} |
| 4222 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4223 |
@ChgAdded{Version=[2],Text=[We have a language design principle that all of |
| 4224 |
the details of a specific tagged type are known at its freezing point. |
| 4225 |
But that is only true if the primitive subprograms are frozen at this |
| 4226 |
point as well. Late changes of Import and address clauses violate the |
| 4227 |
principle.]} |
| 4228 |
@end{Reason} |
| 4229 |
@begin{ImplNote} |
| 4230 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4231 |
@ChgAdded{Version=[2],Text=[This rule means that no implicit call to |
| 4232 |
Initialize or Adjust can freeze a subprogram (the type and thus subprograms |
| 4233 |
would have been frozen at worst at the same point).]} |
| 4234 |
@end{ImplNote} |
| 4235 |
|
| 4236 |
@end{Itemize} |
| 4237 |
|
| 4238 |
@end{Intro} |
| 4239 |
|
| 4240 |
@begin{Legality} |
| 4241 |
|
| 4242 |
@Comment{"Leading" below is to get the last paragraph onto the page with everything else.} |
| 4243 |
@Leading@Redundant[The explicit declaration of a primitive subprogram of a |
| 4244 |
tagged type shall occur before the type is frozen |
| 4245 |
(see @RefSecNum{Dispatching Operations of Tagged Types}).] |
| 4246 |
@begin{Reason} |
| 4247 |
This rule is needed |
| 4248 |
because (1) we don't want people dispatching to things that haven't |
| 4249 |
been declared yet, and (2) we want to allow tagged type descriptors |
| 4250 |
to be static (allocated statically, and initialized to link-time-known |
| 4251 |
symbols). Suppose T2 inherits primitive P from T1, and then |
| 4252 |
overrides P. Suppose P is called @i{before} the declaration of the |
| 4253 |
overriding P. What should it dispatch to? If the answer is the new |
| 4254 |
P, we've violated the first principle above. If the answer is the |
| 4255 |
old P, we've violated the second principle. (A call |
| 4256 |
to the new one necessarily raises Program_Error, but that's |
| 4257 |
beside the point.) |
| 4258 |
|
| 4259 |
Note that a call upon a dispatching operation of type @i(T) will freeze @i(T). |
| 4260 |
|
| 4261 |
We considered applying this rule to all derived types, for uniformity. |
| 4262 |
However, that would be upward incompatible, so we rejected the idea. |
| 4263 |
As in Ada 83, for an untagged type, the above call upon P will call the |
| 4264 |
old P (which is arguably confusing). |
| 4265 |
@end{Reason} |
| 4266 |
|
| 4267 |
@Leading@Redundant[A type shall be completely defined before it is frozen |
| 4268 |
(see @RefSecNum{Completions of Declarations} and |
| 4269 |
@RefSecNum{Private Types and Private Extensions}).] |
| 4270 |
|
| 4271 |
@Leading@Redundant[The completion of a deferred constant declaration shall occur |
| 4272 |
before the constant is frozen |
| 4273 |
(see @RefSecNum{Deferred Constants}).] |
| 4274 |
|
| 4275 |
@begin{TheProof} |
| 4276 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]} |
| 4277 |
@ChgAdded{Version=[2],Text=[The above @LegalityTitle are stated |
| 4278 |
@lquotes@;officially@rquotes@; in the referenced clauses.]} |
| 4279 |
@end{TheProof} |
| 4280 |
|
| 4281 |
@Leading@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 4282 |
@Chg{New=[An operational or],Old=[A]} representation item that |
| 4283 |
directly specifies an aspect of an entity shall appear before the entity is |
| 4284 |
frozen (see @RefSecNum{Operational and Representation Items}). |
| 4285 |
@ChgNote{A last minute change (requested by WG9) moved this rule to 13.1(9). |
| 4286 |
However, the rule there only covers types and subtypes. So this rule is not |
| 4287 |
redundant, and I removed the @Redundant for it. I don't have a way to mark |
| 4288 |
that as a change, so it is just gone. RLB-29-08-00} |
| 4289 |
|
| 4290 |
@begin{Discussion} |
| 4291 |
|
| 4292 |
@comment{The following is a "fix" to keep consistent with v. 5.95; |
| 4293 |
appearently 6.0 is different. |
| 4294 |
@ChgRef{Version=[1],Kind=[Deleted]} |
| 4295 |
@ChgDeleted{Version=[1],Text=[Old @b{Change}.]}} |
| 4296 |
|
| 4297 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 4298 |
From RM83-13.1(7). The wording here forbids freezing |
| 4299 |
within the @Chg{New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]} |
| 4300 |
itself, which was not true of the Ada 83 wording. |
| 4301 |
The wording of this rule is carefully written to |
| 4302 |
work properly for type-related representation items. |
| 4303 |
For example, an @nt{enumeration_@!representation_@!clause} is illegal after the |
| 4304 |
type is frozen, even though the @ntf{_clause} refers to the first subtype. |
| 4305 |
|
| 4306 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00114-01]} |
| 4307 |
@ChgAdded{Version=[2],Text=[The above @LegalityName is stated |
| 4308 |
for types and subtypes in @RefSecNum{Operational and Representation Items}, |
| 4309 |
but the rule here covers all other entities as well.]} |
| 4310 |
@end{Discussion} |
| 4311 |
@begin{TheProof} |
| 4312 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]} |
| 4313 |
@ChgDeleted{Version=[2],Text=[The above @LegalityTitle |
| 4314 |
are stated @lquotes@;officially@rquotes@; |
| 4315 |
in the referenced clauses]}. |
| 4316 |
@end{TheProof} |
| 4317 |
@begin{Discussion} |
| 4318 |
@Leading@;Here's an example that illustrates when freezing occurs in the |
| 4319 |
presence of defaults: |
| 4320 |
@begin{Example} |
| 4321 |
@key[type] T @key[is] ...; |
| 4322 |
@key[function] F @key[return] T; |
| 4323 |
@key[type] R @key[is] |
| 4324 |
@key[record] |
| 4325 |
C : T := F; |
| 4326 |
D : Boolean := F = F; |
| 4327 |
@key[end] @key[record]; |
| 4328 |
X : R; |
| 4329 |
@end{Example} |
| 4330 |
|
| 4331 |
Since the elaboration of R's declaration does not allocate component C, |
| 4332 |
there is no need to freeze C's subtype at that place. |
| 4333 |
Similarly, since the elaboration of R does not evaluate the |
| 4334 |
@nt{default_expression} @lquotes@;F = F@rquotes@;, there is no need to freeze the types |
| 4335 |
involved at that point. |
| 4336 |
However, the declaration of X @i{does} need to freeze these things. |
| 4337 |
Note that even if component C did not exist, the elaboration of the |
| 4338 |
declaration of X would still need information about T @em even though |
| 4339 |
D is not of type T, |
| 4340 |
its @nt{default_expression} requires that information. |
| 4341 |
@end{Discussion} |
| 4342 |
@begin{Ramification} |
| 4343 |
Although we define freezing in terms of the program text as a whole |
| 4344 |
(i.e. after applying the rules of Section 10), |
| 4345 |
the freezing rules actually have no effect beyond compilation unit |
| 4346 |
boundaries. |
| 4347 |
@end{Ramification} |
| 4348 |
@begin{Reason} |
| 4349 |
That is important, because Section 10 allows some |
| 4350 |
implementation definedness in the order of things, |
| 4351 |
and we don't want the freezing rules to be implementation defined. |
| 4352 |
@end{Reason} |
| 4353 |
@begin{Ramification} |
| 4354 |
These rules also have no effect in @nt{statement}s @em they only apply within |
| 4355 |
a single @nt{declarative_part}, @nt{package_specification}, |
| 4356 |
@nt{task_definition}, |
| 4357 |
@nt{protected_definition}, |
| 4358 |
or @nt{protected_body}. |
| 4359 |
@end{Ramification} |
| 4360 |
@begin{ImplNote} |
| 4361 |
An implementation may choose to generate code for |
| 4362 |
@nt{default_expression}s and @nt{default_name}s in |
| 4363 |
line at the place of use. |
| 4364 |
@Defn{thunk} |
| 4365 |
Alternatively, an implementation may choose to generate thunks |
| 4366 |
(subprograms implicitly generated by the compiler) |
| 4367 |
for evaluation of defaults. |
| 4368 |
Thunk generation cannot, in general, be done at the place of the |
| 4369 |
declaration that includes the default. |
| 4370 |
Instead, they can be generated at the first freezing point of the |
| 4371 |
type(s) involved. |
| 4372 |
(It is impossible to write a purely one-pass Ada compiler, |
| 4373 |
for various reasons. |
| 4374 |
This is one of them @em the compiler needs to store a representation of |
| 4375 |
defaults in its symbol table, and then walk that representation later, |
| 4376 |
no earlier than the first freezing point.) |
| 4377 |
|
| 4378 |
In implementation terms, the linear elaboration model can be thought of |
| 4379 |
as preventing uninitialized dope. |
| 4380 |
For example, the implementation might generate dope to contain the size |
| 4381 |
of a private type. |
| 4382 |
This dope is initialized at the place where the type becomes |
| 4383 |
completely defined. |
| 4384 |
It cannot be initialized earlier, |
| 4385 |
because of the order-of-elaboration rules. |
| 4386 |
The freezing rules prevent elaboration of earlier declarations from |
| 4387 |
accessing the size dope for a private type before it is initialized. |
| 4388 |
|
| 4389 |
@RefSecNum{Pragmas} overrides the freezing rules in the case of |
| 4390 |
unrecognized @nt{pragma}s. |
| 4391 |
|
| 4392 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 4393 |
@Chg{New=[An @nt{aspect_clause}],Old=[A @nt{representation_clause}]} for |
| 4394 |
an entity should most certainly @i{not} be a freezing point for the entity. |
| 4395 |
@end{ImplNote} |
| 4396 |
@end{Legality} |
| 4397 |
|
| 4398 |
@begin{RunTime} |
| 4399 |
@ChgNote{This is the last normative paragraph in the clause} |
| 4400 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]} |
| 4401 |
@ChgAdded{Version=[2],Text=[The tag (see |
| 4402 |
@RefSecNum{Tagged Types and Type Extensions}) of a tagged type T |
| 4403 |
is created at the point where T is frozen.@PDefn2{Term=[creation],Sec=[of a tag]}]} |
| 4404 |
@end{RunTime} |
| 4405 |
|
| 4406 |
@begin{Incompatible83} |
| 4407 |
@Defn{incompatibilities with Ada 83} |
| 4408 |
RM83 defines a forcing occurrence of a type as follows: |
| 4409 |
@lquotes@;A forcing occurrence is any occurrence [of the name of the type, |
| 4410 |
subtypes of the type, or types or subtypes with subcomponents of the type] |
| 4411 |
other than in a type or subtype |
| 4412 |
declaration, a subprogram specification, an entry declaration, a deferred |
| 4413 |
constant declaration, a @nt{pragma}, or a @ntf{representation_clause} for the type |
| 4414 |
itself. In any case, an occurrence within an expression is always forcing.@rquotes@; |
| 4415 |
|
| 4416 |
@Leading@;It seems like the wording allows things like this: |
| 4417 |
@begin{Example} |
| 4418 |
@key[type] A @key[is] @key[array](Integer @key[range] 1..10) @key[of] Boolean; |
| 4419 |
@key[subtype] S @key[is] Integer @key[range] A'Range; |
| 4420 |
--@RI{ not forcing for A} |
| 4421 |
@end{Example} |
| 4422 |
|
| 4423 |
Occurrences within @nt{pragma}s can cause freezing in Ada 95. |
| 4424 |
(Since such @nt{pragma}s are ignored in Ada 83, |
| 4425 |
this will probably fix more bugs than it causes.) |
| 4426 |
@end{Incompatible83} |
| 4427 |
|
| 4428 |
@begin{Extend83} |
| 4429 |
@Leading@;@Defn{extensions to Ada 83} |
| 4430 |
In Ada 95, @nt{generic_formal_parameter_declaration}s |
| 4431 |
do not normally freeze the entities from which they are defined. |
| 4432 |
For example: |
| 4433 |
@begin{example} |
| 4434 |
@key[package] Outer @key[is] |
| 4435 |
@key[type] T @key[is] @key[tagged] @key[limited] @key[private]; |
| 4436 |
@key[generic] |
| 4437 |
@key[type] T2 @key[is] |
| 4438 |
@key[new] T @key[with] @key[private]; --@RI{ Does not freeze T} |
| 4439 |
--@RI{ in Ada 95.} |
| 4440 |
@key[package] Inner @key[is] |
| 4441 |
... |
| 4442 |
@key[end] Inner; |
| 4443 |
@key[private] |
| 4444 |
@key[type] T @key[is] ...; |
| 4445 |
@key[end] Outer; |
| 4446 |
@end{example} |
| 4447 |
|
| 4448 |
This is important for the usability of generics. |
| 4449 |
The above example uses the Ada 95 feature of formal derived types. |
| 4450 |
Examples using the kinds of formal parameters already allowed in |
| 4451 |
Ada 83 are well known. |
| 4452 |
See, for example, comments 83-00627 and 83-00688. |
| 4453 |
The extensive use expected for formal derived types |
| 4454 |
makes this issue even more compelling |
| 4455 |
than described by those comments. |
| 4456 |
Unfortunately, we are unable to solve the problem that |
| 4457 |
@nt{explicit_generic_actual_parameter}s cause freezing, even though a package |
| 4458 |
equivalent to the instance would not cause freezing. |
| 4459 |
This is primarily because such an equivalent package would have its |
| 4460 |
body in the body of the containing program unit, whereas an instance |
| 4461 |
has its body right there. |
| 4462 |
@end{Extend83} |
| 4463 |
|
| 4464 |
@begin{DiffWord83} |
| 4465 |
The concept of freezing is based on Ada 83's concept of @lquotes@;forcing |
| 4466 |
occurrences.@rquotes@; |
| 4467 |
The first freezing point of an entity |
| 4468 |
corresponds roughly to the place of the first forcing occurrence, in Ada |
| 4469 |
83 terms. |
| 4470 |
The reason for changing the terminology is that the new rules do not |
| 4471 |
refer to any particular @lquotes@;occurrence@rquotes@; of a name of an entity. |
| 4472 |
Instead, we refer to @lquotes@;uses@rquotes@; of an entity, |
| 4473 |
which are sometimes implicit. |
| 4474 |
|
| 4475 |
In Ada 83, forcing occurrences were used only in rules about |
| 4476 |
@ntf{representation_clause}s. |
| 4477 |
We have expanded the concept to cover private types, |
| 4478 |
because the rules stated in RM83-7.4.1(4) are almost identical to the |
| 4479 |
forcing occurrence rules. |
| 4480 |
|
| 4481 |
@Leading@;The Ada 83 rules are changed in Ada 95 for the following reasons: |
| 4482 |
@begin{Itemize} |
| 4483 |
The Ada 83 rules do not work right for subtype-specific aspects. |
| 4484 |
In an earlier version of Ada 9X, we considered allowing representation |
| 4485 |
items to apply to subtypes other than the first subtype. |
| 4486 |
This was part of the reason for changing the Ada 83 rules. |
| 4487 |
However, now that we have dropped that functionality, |
| 4488 |
we still need the rules to be different from the Ada 83 rules. |
| 4489 |
|
| 4490 |
The Ada 83 rules do not achieve the intended effect. |
| 4491 |
In Ada 83, either with or without the AIs, |
| 4492 |
it is possible to force the compiler to generate code that references |
| 4493 |
uninitialized dope, or force it to detect erroneousness and exception |
| 4494 |
raising at compile time. |
| 4495 |
|
| 4496 |
It was a goal of Ada 83 to avoid uninitialized access values. |
| 4497 |
However, in the case of deferred constants, this goal was not achieved. |
| 4498 |
|
| 4499 |
The Ada 83 rules are not only too weak @em they are also too strong. |
| 4500 |
They allow loopholes (as described above), |
| 4501 |
but they also prevent certain kinds of @nt{default_expression}s that are |
| 4502 |
harmless, |
| 4503 |
and certain kinds of @nt{generic_declaration}s that are both harmless |
| 4504 |
and very useful. |
| 4505 |
|
| 4506 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 4507 |
Ada 83 had a case where a @Chg{Version=[2],New=[@nt{aspect_clause}], |
| 4508 |
Old=[@nt{representation_clause}]} had a strong |
| 4509 |
effect on the semantics of the program @em 'Small. |
| 4510 |
This caused certain semantic anomalies. |
| 4511 |
There are more cases in Ada 95, |
| 4512 |
because the @Chg{Version=[2],New=[@nt{attribute_definition_clause}], |
| 4513 |
Old=[@ntf{attribute_representation_clause}]} has been generalized. |
| 4514 |
@end{Itemize} |
| 4515 |
@end{DiffWord83} |
| 4516 |
|
| 4517 |
@begin{Incompatible95} |
| 4518 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0046],ARef=[AI95-00106-01],ARef=[AI95-00341-01]} |
| 4519 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 4520 |
@b<Corrigendum:> Various freezing rules were added to fix holes in the rules. |
| 4521 |
Most importantly, implicit calls are now freezing, which make some |
| 4522 |
representation clauses illegal in Ada 2005 that were legal (but dubious) in |
| 4523 |
Ada 95. @b[Amendment Correction:] Similarly, the primitive subprograms of a |
| 4524 |
specific tagged type are frozen when the type is frozen, preventing dubious |
| 4525 |
convention changes (and address clauses) after the freezing point. In both |
| 4526 |
cases, the code is dubious and the workaround is easy.]} |
| 4527 |
@end{Incompatible95} |
| 4528 |
|
| 4529 |
@begin{DiffWord95} |
| 4530 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 4531 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that |
| 4532 |
both operational and representation attributes must be specified before |
| 4533 |
the type is frozen.]} |
| 4534 |
|
| 4535 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]} |
| 4536 |
@ChgAdded{Version=[2],Text=[Added wording that declaring a specific |
| 4537 |
descendant of an interface type freezes the interface type.]} |
| 4538 |
|
| 4539 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]} |
| 4540 |
@ChgAdded{Version=[2],Text=[Added wording that defines when a tag is created |
| 4541 |
for a type (at the freezing point of the type). This is used to specify |
| 4542 |
checking for uncreated tags (see @RefSecNum{Tagged Types and Type Extensions}).]} |
| 4543 |
@end{DiffWord95} |
| 4544 |
|