| 1 |
@Part(13, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2006/10/19 06:40:29 $} |
| 4 |
@LabeledSection{Representation Issues} |
| 5 |
|
| 6 |
@Comment{$Source: e:\\cvsroot/ARM/Source/13a.mss,v $} |
| 7 |
@Comment{$Revision: 1.69 $} |
| 8 |
|
| 9 |
@begin{Intro} |
| 10 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 11 |
@redundant[This section describes features for |
| 12 |
querying and controlling @Chg{New=[certain aspects of entities], |
| 13 |
Old=[aspects of representation]} and for interfacing to hardware.] |
| 14 |
@end{Intro} |
| 15 |
|
| 16 |
@begin{DiffWord83} |
| 17 |
The clauses of this section have been reorganized. |
| 18 |
This was necessary to preserve a logical order, |
| 19 |
given the new Ada 95 semantics given in this section. |
| 20 |
@end{DiffWord83} |
| 21 |
|
| 22 |
@LabeledRevisedClause{Version=[1],New=[Operational and Representation Items],Old=[Representation Items]} |
| 23 |
|
| 24 |
@begin{Intro} |
| 25 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 26 |
@ChgAdded{Version=[1],Text=[@Redundant[Representation and operational items can |
| 27 |
be used to specify aspects of entities. Two kinds of aspects of entities can be |
| 28 |
specified: aspects of representation and operational aspects. Representation |
| 29 |
items specify how the types and other entities of the language are to be mapped |
| 30 |
onto the underlying machine. Operational items specify other properties of |
| 31 |
entities.]]} |
| 32 |
|
| 33 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 34 |
@Defn{representation item} |
| 35 |
@RootDefn{representation pragma} |
| 36 |
@RootDefn{pragma, representation} |
| 37 |
There are @Chg{New=[six],Old=[three]} kinds of @i{representation items}: |
| 38 |
@Chg{New=[@nt{attribute_@!definition_@!clause}s for representation attributes, |
| 39 |
@nt{enumeration_@!representation_@!clause}s, |
| 40 |
@nt{record_@!representation_@!clause}s, @nt{at_clause}s, ], |
| 41 |
Old=[@nt{representation_@!clause}s, ]}@nt<component_clause>s, and |
| 42 |
@i{representation pragmas}. |
| 43 |
@Redundant[@Chg{New=[],Old=[Representation items specify how the types and other entities of |
| 44 |
the language are to be mapped onto the underlying machine.]} |
| 45 |
They can be provided to give more efficient representation or to |
| 46 |
interface with features that are outside the domain of the language |
| 47 |
(for example, peripheral hardware). |
| 48 |
@Chg{New=[],Old=[Representation items also specify other specifiable |
| 49 |
properties of entities. |
| 50 |
A representation item applies to an entity identified by |
| 51 |
a @nt<local_name>, which denotes an entity declared local to the |
| 52 |
current declarative region, or a library unit declared immediately |
| 53 |
preceding a representation pragma in a @nt<compilation>.]}] |
| 54 |
|
| 55 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 56 |
@ChgAdded{Version=[1],Text=[An @Defn{operational item}@i<operational item> is an |
| 57 |
@nt<attribute_definition_clause> for an operational attribute.]} |
| 58 |
|
| 59 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 60 |
@ChgAdded{Version=[1],Text=[@Redundant[An operational item or a representation |
| 61 |
item applies to an entity identified by a @nt<local_name>, which denotes an |
| 62 |
entity declared local to the current declarative region, or a library unit |
| 63 |
declared immediately preceding a representation pragma in a |
| 64 |
@nt<compilation>.]]} |
| 65 |
@end{Intro} |
| 66 |
|
| 67 |
@begin{Metarules} |
| 68 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 69 |
@ChgAdded{Version=[1],Text=[Aspects of representation are intended to refer to |
| 70 |
properties that need to be known before the compiler can generate code to |
| 71 |
create or access an entity. For instance, the size of an object needs to be |
| 72 |
known before the object can be created. Conversely, operational aspects are |
| 73 |
those that only need to be known before they can be used. For instance, how an |
| 74 |
object is read from a stream only needs to be known when a stream read is |
| 75 |
executed. Thus, aspects of representation have stricter rules as to when they |
| 76 |
can be specified.]} |
| 77 |
|
| 78 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 79 |
@ChgAdded{Version=[2],Text=[Confirming the value of an aspect with an |
| 80 |
operational or representation item should never change the semantics of |
| 81 |
the aspect. Thus Size = 8 (for example) means the same thing whether it |
| 82 |
was specified with a representation item or whether the compiler chose this |
| 83 |
value by default.]} |
| 84 |
@end{Metarules} |
| 85 |
|
| 86 |
@begin{Syntax} |
| 87 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 88 |
@Syn{lhs=<@Chg{New=[aspect_clause],Old=[representation_clause]}>,rhs="@Syn2{attribute_definition_clause} |
| 89 |
| @Syn2{enumeration_representation_clause} |
| 90 |
| @Syn2{record_representation_clause} |
| 91 |
| @Syn2{at_clause}"} |
| 92 |
|
| 93 |
@Syn{lhs=<local_name>,rhs="@Syn2{direct_name} |
| 94 |
| @Syn2{direct_name}@SingleQuote@Syn2{attribute_designator} |
| 95 |
| @SynI{library_unit_}@Syn2{name}"} |
| 96 |
|
| 97 |
@begin{SyntaxText} |
| 98 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 99 |
A representation pragma is allowed only at places where |
| 100 |
@Chg{New=[an @nt{aspect_clause}],Old=[a @nt{representation_clause}]} |
| 101 |
or @nt{compilation_unit} is allowed. |
| 102 |
@Chg{New=[@IndexSee(Term=(representation_clause),See=(aspect_clause))],Old=[]} |
| 103 |
@end{SyntaxText} |
| 104 |
@end{Syntax} |
| 105 |
|
| 106 |
@begin{Resolution} |
| 107 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 108 |
In @Chg{New=[an operational item or],Old=[a]} representation item, |
| 109 |
if the @nt<local_name> is a @nt<direct_name>, then it shall |
| 110 |
resolve to denote a declaration |
| 111 |
(or, in the case of a @nt{pragma}, one or more declarations) |
| 112 |
that occurs immediately within the same |
| 113 |
declarative region as the @Chg{New=[],Old=[representation ]}item. |
| 114 |
If the @nt<local_name> has an @nt<attribute_designator>, then it shall |
| 115 |
resolve to denote an implementation-defined |
| 116 |
component (see @RefSecNum{Record Representation Clauses}) |
| 117 |
or a class-wide |
| 118 |
type implicitly declared immediately within the same |
| 119 |
declarative region as the @Chg{New=[],Old=[representation ]}item. |
| 120 |
A @nt<local_name> that is a @i{library_unit_}@nt<name> (only |
| 121 |
permitted in a representation pragma) shall resolve |
| 122 |
to denote the @nt<library_item> that immediately precedes |
| 123 |
(except for other pragmas) the representation pragma. |
| 124 |
@begin{Reason} |
| 125 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 126 |
This is a @ResolutionName, |
| 127 |
because we don't want @Chg{New=[an operational or],Old=[a]} representation |
| 128 |
item for X to be ambiguous just because there's another X declared in an outer |
| 129 |
declarative region. |
| 130 |
It doesn't make much difference, since most |
| 131 |
@Chg{New=[operational or ],Old=[]}representation items are for types or |
| 132 |
subtypes, and type and subtype names can't be overloaded. |
| 133 |
@end{Reason} |
| 134 |
@begin{Ramification} |
| 135 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 136 |
The visibility rules imply that the declaration has to occur |
| 137 |
before the @Chg{New=[operational or ],Old=[]}representation item. |
| 138 |
|
| 139 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 140 |
For objects, this implies that @Chg{New=[operational or ],Old=[]}representation items can be |
| 141 |
applied only to stand-alone objects. |
| 142 |
@end{Ramification} |
| 143 |
@end{Resolution} |
| 144 |
|
| 145 |
@begin{Legality} |
| 146 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 147 |
The @nt{local_name} of @Chg{New=[an @nt<aspect_clause>], |
| 148 |
Old=[a @nt<representation_clause>]} or representation pragma shall |
| 149 |
statically denote an entity (or, in the case of a @nt{pragma}, |
| 150 |
one or more entities) declared immediately preceding it in a @nt<compilation>, |
| 151 |
or within the same @nt{declarative_@!part}, @nt{package_@!specification}, |
| 152 |
@nt{task_@!definition}, @nt{protected_@!definition}, or |
| 153 |
@nt{record_@!definition} as the representation @Chg{New=[or operational ],Old=[]}item. |
| 154 |
If a @nt<local_name> denotes a @Redundant[local] callable entity, |
| 155 |
it may do so through a @Redundant[local] |
| 156 |
@nt<subprogram_@!renaming_@!declaration> |
| 157 |
@Redundant[(as a way to resolve ambiguity in the presence of overloading)]; |
| 158 |
otherwise, the @nt<local_name> shall not denote a @nt<renaming_@!declaration>. |
| 159 |
@begin{Ramification} |
| 160 |
The @lquotes@;statically denote@rquotes@; part |
| 161 |
implies that it is impossible to specify the representation of |
| 162 |
an object that is not a stand-alone object, |
| 163 |
except in the case of a representation |
| 164 |
item like pragma Atomic |
| 165 |
that is allowed inside a @nt{component_list} |
| 166 |
(in which case the representation item specifies |
| 167 |
the representation of components of all objects of the type). |
| 168 |
It also prevents the problem of |
| 169 |
renamings of things like @lquotes@;P.@key[all]@rquotes@; |
| 170 |
(where P is an access-to-subprogram value) |
| 171 |
or @lquotes@;E(I)@rquotes@; (where E is an entry family). |
| 172 |
|
| 173 |
The part about where the denoted entity has to have been |
| 174 |
declared appears twice @em once as a @ResolutionName, |
| 175 |
and once as a @LegalityName. |
| 176 |
Suppose P renames Q, |
| 177 |
and we have a representation item in a @nt{declarative_part} |
| 178 |
whose @nt<local_name> is P. |
| 179 |
The fact that the representation item has to appear in the same |
| 180 |
@nt{declarative_part} as P is a @ResolutionName, |
| 181 |
whereas the fact that the representation item has to appear in the |
| 182 |
same @nt{declarative_part} as Q is a @LegalityName. |
| 183 |
This is subtle, but it seems like the least confusing set of rules. |
| 184 |
@end{Ramification} |
| 185 |
@begin{Discussion} |
| 186 |
A separate @LegalityName applies for @nt<component_clause>s. |
| 187 |
See @RefSec{Record Representation Clauses}. |
| 188 |
@end{Discussion} |
| 189 |
|
| 190 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 191 |
@Defn{representation of an object} |
| 192 |
@Defn2{Term=[size], Sec=(of an object)}The @i{representation} of an |
| 193 |
object consists of a certain |
| 194 |
number of bits (the @i(size) of |
| 195 |
the object). |
| 196 |
@Chg{Version=[2],New=[For an object of an elementary type, these],Old=[These]} |
| 197 |
are the bits that are normally read |
| 198 |
or updated by the machine code |
| 199 |
when loading, storing, or operating-on the value of the object. |
| 200 |
@Chg{Version=[2],New=[For an object of a composite type, these |
| 201 |
are the bits reserved for this object, and include bits occupied by |
| 202 |
subcomponents of the object. If],Old=[This includes some padding bits, when]} |
| 203 |
the size of @Chg{Version=[2],New=[an],Old=[the]} object |
| 204 |
is greater than @Chg{Version=[2],New=[that],Old=[the size]} of its subtype@Chg{Version=[2], |
| 205 |
New=[, the additional bits are padding bits.],Old=[. |
| 206 |
@Defn{gaps}]} |
| 207 |
@Defn{padding bits} |
| 208 |
@Chg{Version=[2],New=[For an elementary object, these],Old=[Such]} padding bits |
| 209 |
@Chg{Version=[2],New=[],Old=[are considered to be part of the representation of the |
| 210 |
object, rather than being gaps between objects, |
| 211 |
if these bits ]}are normally read and updated@Chg{Version=[2],New=[ along |
| 212 |
with the others. For a |
| 213 |
composite object, padding bits might not be read or updated in any given |
| 214 |
composite operation, depending on the implementation],Old=[]}. |
| 215 |
|
| 216 |
@begin{Honest} |
| 217 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 218 |
@PDefn{contiguous representation} |
| 219 |
@PDefn{discontiguous representation} |
| 220 |
Discontiguous representations are allowed, |
| 221 |
but the ones we're interested in here are generally contiguous |
| 222 |
sequences of bits.@Chg{Version=[2],New=[ For a discontiguous representation, |
| 223 |
the size doesn't necessarily describe the @lquotes@;footprint@rquotes of |
| 224 |
the object in memory (that is, the amount of space taken in the address space |
| 225 |
for the object).],Old=[]} |
| 226 |
@end{Honest} |
| 227 |
@begin{Discussion} |
| 228 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 229 |
@ChgAdded{Version=[2],Text=[In the case of composite objects, we want the |
| 230 |
implementation to have the flexibility to either do operations |
| 231 |
component-by-component, or with a block operation covering all of the bits. We |
| 232 |
carefully avoid giving a preference in the wording. There is no requirement |
| 233 |
for the choice to be documented, either, as the implementation can make that |
| 234 |
choice based on many factors, and could make a different choice for different |
| 235 |
operations on the same object.]} |
| 236 |
|
| 237 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 238 |
@ChgAdded{Version=[2],Text=[In the case of a properly aligned, contiguous |
| 239 |
object whose size is a multiple of the storage unit size, no other bits should |
| 240 |
be read or updated as part of operating on the object. We don't say this |
| 241 |
normatively because it would be difficult to normatively define |
| 242 |
@lquotes@;properly aligned@rquotes or @lquotes@;contiguous@rquotes.]} |
| 243 |
@end{Discussion} |
| 244 |
@begin{Ramification} |
| 245 |
@Leading@;Two objects with the same value do not necessarily have the same |
| 246 |
representation. |
| 247 |
For example, an implementation might represent False as zero and True |
| 248 |
as any odd value. |
| 249 |
Similarly, two objects (of the same type) |
| 250 |
with the same sequence of bits do not necessarily have the |
| 251 |
same value. |
| 252 |
For example, an implementation might use a biased representation in |
| 253 |
some cases but not others: |
| 254 |
@begin{Example} |
| 255 |
@key[subtype] S @key[is] Integer @key[range] 1..256; |
| 256 |
@key[type] A @key[is] @key[array](Natural @key[range] 1..4) @key[of] S; |
| 257 |
@key[pragma] Pack(A); |
| 258 |
X : S := 3; |
| 259 |
Y : A := (1, 2, 3, 4); |
| 260 |
@end{Example} |
| 261 |
|
| 262 |
The implementation might use a biased-by-1 representation for the |
| 263 |
array elements, but not for X. |
| 264 |
X and Y(3) have the same value, but different representation: |
| 265 |
the representation of X is a sequence of (say) 32 bits: 0...011, |
| 266 |
whereas the representation of Y(3) is a sequence of 8 bits: |
| 267 |
00000010 (assuming a two's complement representation). |
| 268 |
|
| 269 |
Such tricks are not required, but are allowed. |
| 270 |
@end{Ramification} |
| 271 |
@begin{Discussion} |
| 272 |
The value of any padding bits is not specified by the language, |
| 273 |
though for a numeric type, it will be much harder to properly implement |
| 274 |
the predefined operations if the padding bits are not either all zero, |
| 275 |
or a sign extension. |
| 276 |
@end{Discussion} |
| 277 |
@begin{Ramification} |
| 278 |
For example, suppose S'Size = 2, and an object X is of subtype S. |
| 279 |
If the machine code typically uses a 32-bit load instruction to load the |
| 280 |
value of X, then X'Size should be 32, even though 30 bits of the value |
| 281 |
are just zeros or sign-extension bits. |
| 282 |
On the other hand, if the machine code typically masks out those 30 |
| 283 |
bits, then X'Size should be 2. |
| 284 |
Usually, such masking only happens for components of a composite type |
| 285 |
for which packing, Component_Size, or record layout is specified. |
| 286 |
|
| 287 |
Note, however, that the formal parameter of an instance of |
| 288 |
Unchecked_Conversion is a special case. |
| 289 |
Its Size is required to be the same as that of its subtype. |
| 290 |
|
| 291 |
Note that we don't generally talk about the representation of a |
| 292 |
value. |
| 293 |
A value is considered to be an amorphous blob |
| 294 |
without any particular representation. |
| 295 |
An object is considered to be more concrete. |
| 296 |
@end{Ramification} |
| 297 |
|
| 298 |
@RootDefn{aspect of representation} |
| 299 |
@Defn{representation aspect} |
| 300 |
@Defn2{Term=[directly specified], |
| 301 |
Sec=(of an aspect of representation of an entity)} |
| 302 |
A representation item @i{directly specifies} |
| 303 |
an @i{aspect of representation} of the entity denoted |
| 304 |
by the @nt{local_name}, |
| 305 |
except in the case of a type-related representation item, |
| 306 |
whose @nt{local_name} shall denote a first subtype, |
| 307 |
and which directly specifies an aspect |
| 308 |
of the subtype's type. |
| 309 |
@RootDefn2{Term=[type-related], Sec=(representation item)} |
| 310 |
@RootDefn2{term=[subtype-specific], Sec=(of a representation item)} |
| 311 |
@RootDefn2{Term=[type-related], Sec=(aspect)} |
| 312 |
@RootDefn2{term=[subtype-specific], Sec=(of an aspect)} |
| 313 |
A representation item that names a subtype is either |
| 314 |
@i(subtype-specific) (Size and Alignment clauses) |
| 315 |
or @i{type-related} (all others). |
| 316 |
@Redundant[Subtype-specific aspects may differ for |
| 317 |
different subtypes of the same type.] |
| 318 |
@begin{Honest} |
| 319 |
@i{Type-related} and @i{subtype-specific} are defined likewise for |
| 320 |
the corresponding aspects of representation. |
| 321 |
@end{Honest} |
| 322 |
@begin{Honest} |
| 323 |
Some representation items directly specify more than one aspect. |
| 324 |
@end{Honest} |
| 325 |
@begin{Discussion} |
| 326 |
For example, a @nt{pragma} Export specifies the convention |
| 327 |
of an entity, |
| 328 |
and also specifies that it is exported. |
| 329 |
@end{Discussion} |
| 330 |
@begin{Ramification} |
| 331 |
Each specifiable attribute constitutes a separate aspect. |
| 332 |
An @nt{enumeration_representation_clause} specifies the coding aspect. |
| 333 |
A @nt{record_representation_clause} (without the @nt{mod_clause}) |
| 334 |
specifies the record layout aspect. |
| 335 |
Each representation pragma specifies a separate aspect. |
| 336 |
@end{Ramification} |
| 337 |
@begin{Reason} |
| 338 |
We don't need to say that an @nt{at_clause} or a |
| 339 |
@nt{mod_clause} specify separate aspects, |
| 340 |
because these are equivalent to @nt{attribute_definition_clause}s. |
| 341 |
See @RefSec{At Clauses}, and @RefSec{Mod Clauses}. |
| 342 |
@end{Reason} |
| 343 |
@begin{Ramification} |
| 344 |
@Leading@;The following representation items are type-related: |
| 345 |
@begin{Itemize} |
| 346 |
@nt{enumeration_representation_clause} |
| 347 |
|
| 348 |
@nt{record_representation_clause} |
| 349 |
|
| 350 |
Component_Size clause |
| 351 |
|
| 352 |
@ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 353 |
@ChgDeleted{Version=[1],Text=[External_Tag clause]} |
| 354 |
|
| 355 |
Small clause |
| 356 |
|
| 357 |
Bit_Order clause |
| 358 |
|
| 359 |
Storage_Pool clause |
| 360 |
|
| 361 |
Storage_Size clause |
| 362 |
|
| 363 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]} |
| 364 |
@ChgAdded{Version=[2],Text=[Stream_Size clause]} |
| 365 |
|
| 366 |
@ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 367 |
@ChgDeleted{Version=[1],Text=[Read clause]} |
| 368 |
|
| 369 |
@ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 370 |
@ChgDeleted{Version=[1],Text=[Write clause]} |
| 371 |
|
| 372 |
@ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 373 |
@ChgDeleted{Version=[1],Text=[Input clause]} |
| 374 |
|
| 375 |
@ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 376 |
@ChgDeleted{Version=[1],Text=[Output clause]} |
| 377 |
|
| 378 |
Machine_Radix clause |
| 379 |
|
| 380 |
pragma Pack |
| 381 |
|
| 382 |
pragmas Import, Export, and Convention (when applied to a type) |
| 383 |
|
| 384 |
pragmas Atomic and Volatile (when applied to a type) |
| 385 |
|
| 386 |
pragmas Atomic_Components and Volatile_Components (when applied to an array type) |
| 387 |
|
| 388 |
pragma Discard_Names (when applied to an enumeration or tagged type) |
| 389 |
@end{Itemize} |
| 390 |
|
| 391 |
@Leading@;The following representation items are subtype-specific: |
| 392 |
@begin{Itemize} |
| 393 |
Alignment clause (when applied to a first subtype) |
| 394 |
|
| 395 |
Size clause (when applied to a first subtype) |
| 396 |
@end{Itemize} |
| 397 |
|
| 398 |
@Leading@;The following representation items do not apply to subtypes, |
| 399 |
so they are neither type-related nor subtype-specific: |
| 400 |
@begin{Itemize} |
| 401 |
Address clause (applies to objects and program units) |
| 402 |
|
| 403 |
Alignment clause (when applied to an object) |
| 404 |
|
| 405 |
Size clause (when applied to an object) |
| 406 |
|
| 407 |
pragmas Import, Export, and Convention (when applied to anything other |
| 408 |
than a type) |
| 409 |
|
| 410 |
pragmas Atomic and Volatile (when applied to an object or a component) |
| 411 |
|
| 412 |
pragmas Atomic_Components and Volatile_Components (when applied to an |
| 413 |
array object) |
| 414 |
|
| 415 |
pragma Discard_Names (when applied to an exception) |
| 416 |
|
| 417 |
pragma Asynchronous (applies to procedures) |
| 418 |
|
| 419 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 420 |
@ChgAdded{Version=[2],Text=[pragma No_Return (applies to procedures)]} |
| 421 |
@end{Itemize} |
| 422 |
@end{Ramification} |
| 423 |
|
| 424 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 425 |
@ChgAdded{Version=[1],Text=[An operational item @i<directly specifies> an @i<operational aspect> |
| 426 |
of the type of the subtype denoted by the @nt{local_name}. The @nt{local_name} |
| 427 |
of an operational item shall denote a first subtype. An operational item that |
| 428 |
names a subtype is type-related. |
| 429 |
@RootDefn{operational aspect} |
| 430 |
@Defn2{Term=[directly specified], |
| 431 |
Sec=(of an operational aspect of an entity)} |
| 432 |
@RootDefn2{Term=[type-related], Sec=(operational item)} |
| 433 |
@PDefn2{Term=[type-related], Sec=(aspect)}]} |
| 434 |
|
| 435 |
@begin{Ramification} |
| 436 |
@ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 437 |
@ChgAdded{Version=[1],Type=[Leading],Text=[The following operational items are |
| 438 |
type-related:]} |
| 439 |
@begin{Itemize} |
| 440 |
|
| 441 |
@ChgRef{Version=[1],Kind=[AddedNormal]} |
| 442 |
@ChgAdded{Version=[1],Text=[External_Tag clause]} |
| 443 |
|
| 444 |
@ChgRef{Version=[1],Kind=[AddedNormal]} |
| 445 |
@ChgAdded{Version=[1],Text=[Read clause]} |
| 446 |
|
| 447 |
@ChgRef{Version=[1],Kind=[AddedNormal]} |
| 448 |
@ChgAdded{Version=[1],Text=[Write clause]} |
| 449 |
|
| 450 |
@ChgRef{Version=[1],Kind=[AddedNormal]} |
| 451 |
@ChgAdded{Version=[1],Text=[Input clause]} |
| 452 |
|
| 453 |
@ChgRef{Version=[1],Kind=[AddedNormal]} |
| 454 |
@ChgAdded{Version=[1],Text=[Output clause]} |
| 455 |
|
| 456 |
@end{Itemize} |
| 457 |
@end{Ramification} |
| 458 |
|
| 459 |
|
| 460 |
A representation item that directly specifies an aspect of a subtype or |
| 461 |
type shall appear after the type is completely defined |
| 462 |
(see @RefSecNum{Completions of Declarations}), |
| 463 |
and before the subtype or type is frozen (see @RefSecNum{Freezing Rules}). |
| 464 |
If a representation item is given that directly specifies an aspect of an |
| 465 |
entity, then it is illegal to give another representation item that |
| 466 |
directly specifies the same aspect of the entity. |
| 467 |
@begin{Ramification} |
| 468 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 469 |
The fact that a representation item @Chg{New=[(or operational item, |
| 470 |
see next paragraph) ],Old=[]}that directly specifies |
| 471 |
an aspect of an entity is required to appear before the entity is frozen |
| 472 |
prevents changing the representation of an entity |
| 473 |
after using the entity in ways that require the representation to be known. |
| 474 |
@end{Ramification} |
| 475 |
|
| 476 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 477 |
@ChgAdded{Version=[1],Text=[An operational item that directly specifies an |
| 478 |
aspect of a type |
| 479 |
shall appear before the type is frozen (see @RefSecNum{Freezing Rules}). |
| 480 |
If an operational item is given that directly specifies an aspect of a type, |
| 481 |
then it is illegal to give another operational item that directly specifies |
| 482 |
the same aspect of the type.]} |
| 483 |
@begin{Ramification} |
| 484 |
@ChgRef{Version=[1],Kind=[Added]} |
| 485 |
@ChgAdded{Version=[1],Text=[Unlike representation items, operational |
| 486 |
items can be specified on |
| 487 |
partial views. Since they don't affect the representation, the full |
| 488 |
declaration need not be known to determine their legality.]} |
| 489 |
@end{Ramification} |
| 490 |
|
| 491 |
For an untagged derived type, no type-related representation items |
| 492 |
are allowed if the parent type is a by-reference type, |
| 493 |
or has any user-defined primitive subprograms. |
| 494 |
@begin{Ramification} |
| 495 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 496 |
On the other hand, subtype-specific representation items may be given |
| 497 |
for the first subtype of such a type@Chg{New=[, as can operational items], |
| 498 |
Old=[]}. |
| 499 |
@end{Ramification} |
| 500 |
@begin{Reason} |
| 501 |
The reason for forbidding type-related representation items on |
| 502 |
untagged by-reference types is because a change of representation |
| 503 |
is impossible when passing by reference (to an inherited subprogram). |
| 504 |
The reason for forbidding type-related representation items on |
| 505 |
untagged types with user-defined primitive subprograms |
| 506 |
was to prevent implicit change of representation for type-related |
| 507 |
aspects of representation upon calling inherited subprograms, |
| 508 |
because such changes of representation are likely to be |
| 509 |
expensive at run time. |
| 510 |
Changes of subtype-specific representation attributes, however, are |
| 511 |
likely to be cheap. |
| 512 |
This rule is not needed for tagged types, |
| 513 |
because other rules prevent a type-related representation item |
| 514 |
from changing the representation of the parent part; |
| 515 |
we want to allow a type-related representation item on a type extension |
| 516 |
to specify aspects of the extension part. |
| 517 |
For example, a @nt{pragma} Pack will cause packing of the extension |
| 518 |
part, but not of the parent part. |
| 519 |
@end{Reason} |
| 520 |
|
| 521 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 522 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]} |
| 523 |
@Chg{New=[Operational and r],Old=[R]}epresentation aspects of a generic formal |
| 524 |
parameter are the same as those of the actual. |
| 525 |
@Chg{New=[Operational and representation aspects @Chg{Version=[2],New=[], |
| 526 |
Old=[of a partial view ]}are the |
| 527 |
same @Chg{Version=[2],New=[for all views of a type],Old=[as those of the full view]}.],Old=[]} |
| 528 |
A type-related representation item is not allowed for a |
| 529 |
descendant of a generic formal untagged type. |
| 530 |
@begin{Ramification} |
| 531 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 532 |
Representation items are allowed for types whose subcomponent types |
| 533 |
or index subtypes are generic formal types. |
| 534 |
@Chg{New=[Operational items and subtype-related representation items are |
| 535 |
allowed on descendants of generic formal types.],Old=[]} |
| 536 |
@end{Ramification} |
| 537 |
@begin{Reason} |
| 538 |
Since it is not known whether a formal type has |
| 539 |
user-defined primitive subprograms, specifying |
| 540 |
type-related representation items for them |
| 541 |
is not allowed, unless they are tagged (in which case only |
| 542 |
the extension part is affected in any case). |
| 543 |
@end{Reason} |
| 544 |
@begin{Ramification} |
| 545 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]} |
| 546 |
@ChgAdded{Version=[2],Text=[All views of a type, including the incomplete |
| 547 |
and partial views, have the same operational and representation aspects. |
| 548 |
That's important so that the properties don't change when changing views. |
| 549 |
While most aspects are not available for an incomplete view, we don't want |
| 550 |
to leave any holes by not saying that they are the same.]} |
| 551 |
@end{Ramification} |
| 552 |
|
| 553 |
A representation item that specifies the Size for a given subtype, |
| 554 |
or the size or storage place for an object (including a component) |
| 555 |
of a given subtype, shall allow for enough storage space to |
| 556 |
accommodate any value of the subtype. |
| 557 |
|
| 558 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 559 |
A representation @Chg{New=[or operational ],Old=[]}item that is not supported |
| 560 |
by the implementation is illegal, or raises an exception |
| 561 |
at run time. |
| 562 |
|
| 563 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]} |
| 564 |
@ChgAdded{Version=[2],Text=[A @nt{type_declaration} is illegal if it has one or |
| 565 |
more progenitors, and a representation item applies to an ancestor, and this |
| 566 |
representation item conflicts with the representation of |
| 567 |
some other ancestor. The cases that cause conflicts are |
| 568 |
implementation defined.]} |
| 569 |
@ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 570 |
Text=[The cases that cause conflicts between the representation of |
| 571 |
the ancestors of a @nt{type_declaration}.]}]} |
| 572 |
@begin{Reason} |
| 573 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 574 |
@ChgAdded{Version=[2],Type=[Leading],Text=[This rule is needed because it may be the case |
| 575 |
that only the combination of types in a type declaration causes a conflict. |
| 576 |
Thus it is not possible, in general, to reject the original representation |
| 577 |
item. For instance:]} |
| 578 |
@begin{Example} |
| 579 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 580 |
@ChgAdded{Version=[2],Text=[@key{package} Pkg1 @key{is} |
| 581 |
@key{type} Ifc @key{is interface}; |
| 582 |
@key{type} T @key{is tagged record} |
| 583 |
Fld : Integer; |
| 584 |
@key{end record}; |
| 585 |
@key{for} T @key{use record} |
| 586 |
Fld @key{at} 0 @key{range} 0 .. Integer'Size - 1; |
| 587 |
@key{end record}; |
| 588 |
@key{end} Pkg1;]} |
| 589 |
@end{Example} |
| 590 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 591 |
@ChgAdded{Version=[2],Type=[Leading],Text=[Assume the implementation uses a |
| 592 |
single tag with a default offset of zero, and that it allows the use of |
| 593 |
non-default locations for the tag (and thus accepts representation items |
| 594 |
like the one above). The representation item will force a non-default |
| 595 |
location for the tag (by putting a component other than the tag into the |
| 596 |
default location). Clearly, this package will be accepted by the |
| 597 |
implementation. However, other declarations could cause trouble. For |
| 598 |
instance, the implementation could reject:]} |
| 599 |
@begin{Example} |
| 600 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 601 |
@ChgAdded{Version=[2],Text=[@key{with} Pkg1; |
| 602 |
@key{package} Pkg2 @key{is} |
| 603 |
@key{type} NewT @key{is new} Pkg1.T @key{and} Pkg1.Ifc @key{with null record}; |
| 604 |
@key{end} Pkg2;]} |
| 605 |
@end{Example} |
| 606 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 607 |
@ChgAdded{Version=[2],Text=[because the declarations of T and Ifc have a |
| 608 |
conflict in their representation items. This is clearly necessary (it's hard |
| 609 |
to imagine how Ifc'Class could work with the tag at a location other than the |
| 610 |
one it is expecting).]} |
| 611 |
|
| 612 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 613 |
@ChgAdded{Version=[2],Text=[Conflicts will usually involve |
| 614 |
implementation-defined attributes (for specifying the location of the tag, |
| 615 |
for instance), although the example above shows that doesn't have to be the |
| 616 |
case. For this reason, we didn't try to specify exactly what causes a |
| 617 |
conflict; it will depend on the implementation's implementation model and |
| 618 |
what representation items it allows.]} |
| 619 |
@end{Reason} |
| 620 |
@begin{ImplNote} |
| 621 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 622 |
@ChgAdded{Version=[2],Text=[An implementation can only use this rule to |
| 623 |
reject @nt{type_declaration}s where one its ancestors has a representation |
| 624 |
item. An implementation must ensure that |
| 625 |
the default representations of ancestors cannot conflict.]} |
| 626 |
@end{ImplNote} |
| 627 |
@end{Legality} |
| 628 |
|
| 629 |
@begin{StaticSem} |
| 630 |
If two subtypes statically match, |
| 631 |
then their subtype-specific aspects (Size and Alignment) |
| 632 |
are the same. |
| 633 |
@PDefn2{Term=[statically matching],Sec=(effect on subtype-specific aspects)} |
| 634 |
@begin{Reason} |
| 635 |
This is necessary because we allow (for example) |
| 636 |
conversion between access types whose designated subtypes |
| 637 |
statically match. |
| 638 |
Note that it is illegal to specify an aspect (including a subtype-specific one) |
| 639 |
for a nonfirst subtype. |
| 640 |
|
| 641 |
@Leading@Keepnext@;Consider, for example: |
| 642 |
@begin{Example} |
| 643 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114} |
| 644 |
@key[package] P1 @key[is] |
| 645 |
@key[subtype] S1 @key[is] Integer @key[range] 0..2**16-1; |
| 646 |
@key[for] S1'Size @key[use] 16; --@RI{ Illegal!} |
| 647 |
--@RI{ S1'Size would be 16 by default.} |
| 648 |
@key[type] A1 @key[is] @key[access] @Chg{New=[@Key[all] ],Old=[]}S1; |
| 649 |
X1: A1; |
| 650 |
@key[end] P1; |
| 651 |
|
| 652 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114} |
| 653 |
@key[package] P2 @key[is] |
| 654 |
@key[subtype] S2 @key[is] Integer @key[range] 0..2**16-1; |
| 655 |
@key[for] S2'Size @key[use] 32; --@RI{ Illegal!} |
| 656 |
@key[type] A2 @key[is] @key[access] @Chg{New=[@Key[all] ],Old=[]}S2; |
| 657 |
X2: A2; |
| 658 |
@key[end] P2; |
| 659 |
|
| 660 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114} |
| 661 |
@key[procedure] Q @key[is] |
| 662 |
@key[use] P1, P2; |
| 663 |
@key[type] Array1 @key[is] @key[array](Integer @key[range] <>) @key[of] @key[aliased] S1; |
| 664 |
@key[pragma] Pack(Array1); |
| 665 |
Obj1: Array1(1..100); |
| 666 |
@key[type] Array2 @key[is] @key[array](Integer @key[range] <>) @key[of] @key[aliased] S2; |
| 667 |
@key[pragma] Pack(Array2); |
| 668 |
Obj2: Array2(1..100); |
| 669 |
@key[begin] |
| 670 |
X1 := Obj2(17)'@Chg{New=[Unchecked_],Old=[]}Access; |
| 671 |
X2 := Obj1(17)'@Chg{New=[Unchecked_],Old=[]}Access; |
| 672 |
@key[end] Q; |
| 673 |
@end{Example} |
| 674 |
|
| 675 |
Loads and stores through X1 would read and write 16 bits, |
| 676 |
but X1 points to a 32-bit location. |
| 677 |
Depending on the endianness of the machine, |
| 678 |
loads might load the wrong 16 bits. |
| 679 |
Stores would fail to zero the other half in any case. |
| 680 |
|
| 681 |
Loads and stores through X2 would read and write 32 bits, |
| 682 |
but X2 points to a 16-bit location. |
| 683 |
Thus, adjacent memory locations would be trashed. |
| 684 |
|
| 685 |
Hence, the above is illegal. |
| 686 |
Furthermore, the compiler is forbidden from choosing different |
| 687 |
Sizes by default, for the same reason. |
| 688 |
|
| 689 |
The same issues apply to Alignment. |
| 690 |
|
| 691 |
@end{Reason} |
| 692 |
|
| 693 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 694 |
A derived type inherits each type-related aspect |
| 695 |
@Chg{New=[of representation ],Old=[]}of its parent type that |
| 696 |
was directly specified before the declaration of the derived type, |
| 697 |
or (in the case where the parent is derived) |
| 698 |
that was inherited by the parent type from the grandparent type. |
| 699 |
A derived subtype inherits each subtype-specific aspect |
| 700 |
@Chg{New=[of representation ],Old=[]}of its parent subtype that |
| 701 |
was directly specified before the declaration of the derived type, |
| 702 |
or (in the case where the parent is derived) |
| 703 |
that was inherited by the parent subtype from the grandparent subtype, |
| 704 |
but only if the parent subtype statically matches the first subtype of |
| 705 |
the parent type. |
| 706 |
An inherited aspect of representation is overridden by a subsequent |
| 707 |
representation item that specifies the same aspect of the type or |
| 708 |
subtype. |
| 709 |
@begin{Honest} |
| 710 |
A @nt{record_representation_clause} for a record extension |
| 711 |
does not override the layout of the parent part; |
| 712 |
if the layout was specified for the parent type, |
| 713 |
it is inherited by the record extension. |
| 714 |
@end{Honest} |
| 715 |
@begin{Ramification} |
| 716 |
If a representation item for the parent appears after the |
| 717 |
@nt{derived_@!type_@!definition}, |
| 718 |
then inheritance does not happen for that representation item. |
| 719 |
@end{Ramification} |
| 720 |
|
| 721 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 722 |
@ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]} |
| 723 |
@ChgAdded{Version=[1],Text=[In contrast, whether operational aspects are |
| 724 |
inherited by @Chg{Version=[2],New=[an untagged],Old=[a]} |
| 725 |
derived type depends on each specific aspect. |
| 726 |
@Chg{Version=[2],New=[@Redundant[Operational aspects are never inherited |
| 727 |
for a tagged type.] ],Old=[]}When operational aspects are |
| 728 |
inherited by @Chg{Version=[2],New=[an untagged],Old=[a]} derived type, |
| 729 |
aspects that were directly specified @Chg{Version=[2],New=[by operational |
| 730 |
items that are visible at the point],Old=[before the declaration]} of |
| 731 |
the derived type@Chg{Version=[2],New=[ declaration],Old=[]}, or |
| 732 |
(in the case where the parent is derived) |
| 733 |
that were inherited by the parent type from the grandparent type are inherited. |
| 734 |
An inherited operational aspect is overridden by a subsequent operational item |
| 735 |
that specifies the same aspect of the type.]} |
| 736 |
@begin{Ramification} |
| 737 |
@ChgRef{Version=[1],Kind=[Added]} |
| 738 |
@ChgAdded{Version=[1],Text=[As with representation items, if an operational |
| 739 |
item for the parent appears after the @nt{derived_@!type_@!definition}, then |
| 740 |
inheritance does not happen for that operational item.]} |
| 741 |
@end{Ramification} |
| 742 |
@begin{Discussion} |
| 743 |
@ChgRef{Version=[1],Kind=[Added]} |
| 744 |
@ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]} |
| 745 |
@ChgAdded{Version=[1],Text=[@Chg{Version=[2],New=[Only],Old=[Currently, only]} |
| 746 |
untagged types inherit operational aspects. |
| 747 |
@Chg{Version=[2],New=[Inheritance from tagged types causes problems, as the |
| 748 |
different views can have different visibility on operational items @em |
| 749 |
potentially leading to operational items that depend on the view. We want |
| 750 |
aspects to be the same for all views. Untagged types don't have this problem |
| 751 |
as plain private types don't have ancestors, and thus can't inherit anything. |
| 752 |
In addition, it seems unlikely that we'll need inheritance for tagged types, |
| 753 |
as usually we'll want to incorporate the parent's operation into a new one that |
| 754 |
also handles any extension components.],Old=[We considered writing this rule |
| 755 |
that way, but rejected it as that could be too |
| 756 |
specific for future operational aspects. (After all, that is precisely the |
| 757 |
problem that caused us to introduce @lquotes@;operational aspects@rquotes in |
| 758 |
the first place.)]}]} |
| 759 |
@end{Discussion} |
| 760 |
|
| 761 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]} |
| 762 |
@ChgAdded{Version=[2],Text=[When an aspect that is a subprogram is inherited, |
| 763 |
the derived type inherits the aspect in the same way that a derived type |
| 764 |
inherits a user-defined primitive subprogram from its parent (see |
| 765 |
@RefSecNum{Derived Types and Classes}).]} |
| 766 |
@begin{Reason} |
| 767 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 768 |
@ChgAdded{Version=[2],Text=[This defines the parameter names and types, |
| 769 |
and the needed implicit conversions.]} |
| 770 |
@end{Reason} |
| 771 |
|
| 772 |
@Leading@;Each aspect of representation of an entity is as follows: |
| 773 |
@begin{Itemize} |
| 774 |
@Defn2{Term=[specified], |
| 775 |
Sec=(of an aspect of representation of an entity)} |
| 776 |
If the aspect is @i{specified} for the entity, |
| 777 |
meaning that it is |
| 778 |
either directly specified or inherited, |
| 779 |
then that aspect of the entity is as specified, |
| 780 |
except in the case of Storage_Size, |
| 781 |
which specifies a minimum. |
| 782 |
@begin{Ramification} |
| 783 |
This rule implies that queries of the aspect return the |
| 784 |
specified value. For example, if the user writes @lquotes@;@key{for} |
| 785 |
X'Size @key{use} 32;@rquotes@;, |
| 786 |
then a query of X'Size will return 32. |
| 787 |
@end{Ramification} |
| 788 |
|
| 789 |
@PDefn{unspecified} |
| 790 |
If an aspect of representation of an entity is not specified, |
| 791 |
it is chosen by default in an unspecified manner. |
| 792 |
@end{Itemize} |
| 793 |
@begin{Ramification} |
| 794 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 795 |
Note that @Chg{New=[representation items],Old=[@nt{representation_clause}s]} |
| 796 |
can affect the semantics of the entity. |
| 797 |
|
| 798 |
The rules forbid things like |
| 799 |
@lquotes@;@key[for] S'Base'Alignment @key[use] ...@rquotes@; |
| 800 |
and |
| 801 |
@lquotes@;@key[for] S'Base @key[use] record ...@rquotes@;. |
| 802 |
@end{Ramification} |
| 803 |
@begin{Discussion} |
| 804 |
The intent is that implementations will represent the |
| 805 |
components of a composite value in the same way for all subtypes of a |
| 806 |
given composite type. |
| 807 |
Hence, Component_Size and record layout are type-related aspects. |
| 808 |
@end{Discussion} |
| 809 |
|
| 810 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 811 |
@ChgAdded{Version=[1],Text=[@Defn2{Term=[specified], Sec=(of an operational aspect of an entity)} |
| 812 |
If an operational aspect is @i<specified> for an entity (meaning |
| 813 |
that it is either directly specified or inherited), then that aspect of the |
| 814 |
entity is as specified. Otherwise, the aspect of the entity has the default |
| 815 |
value for that aspect.]} |
| 816 |
|
| 817 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 818 |
@ChgAdded{Version=[2],Text=[A representation item that specifies an aspect of |
| 819 |
representation that would have been chosen in the absence of the representation |
| 820 |
item is said to be @i{confirming}.@Defn2{Term=[confirming], Sec=(representation item)}]} |
| 821 |
@end{StaticSem} |
| 822 |
|
| 823 |
@begin{RunTime} |
| 824 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 825 |
@Chg{New=[@PDefn2{Term=[elaboration], Sec=(aspect_clause)}], |
| 826 |
Old=[@PDefn2{Term=[elaboration], Sec=(representation_clause)}]} |
| 827 |
For the elaboration of @Chg{New=[an @nt{aspect_clause}], |
| 828 |
Old=[a @nt{representation_clause}]}, |
| 829 |
any evaluable constructs within it are evaluated. |
| 830 |
@begin{Ramification} |
| 831 |
Elaboration of representation pragmas is covered by the |
| 832 |
general rules for pragmas in Section 2. |
| 833 |
@end{Ramification} |
| 834 |
@end{RunTime} |
| 835 |
|
| 836 |
@begin{ImplPerm} |
| 837 |
An implementation may interpret aspects of representation in an |
| 838 |
implementation-defined manner. |
| 839 |
An implementation may place implementation-defined restrictions on |
| 840 |
representation items. |
| 841 |
@RootDefn{recommended level of support} |
| 842 |
A @i{recommended level of support} is specified for representation items |
| 843 |
and related features in each subclause. |
| 844 |
These recommendations are changed to requirements |
| 845 |
for implementations that support the Systems Programming Annex |
| 846 |
(see @RefSec{Required Representation Support}). |
| 847 |
@ImplDef{The interpretation of each aspect of representation.} |
| 848 |
@ImplDef{Any restrictions placed upon representation items.} |
| 849 |
@begin{Ramification} |
| 850 |
Implementation-defined restrictions may be enforced either at compile |
| 851 |
time or at run time. |
| 852 |
There is no requirement that an implementation justify any such |
| 853 |
restrictions. |
| 854 |
They can be based on avoiding implementation complexity, |
| 855 |
or on avoiding excessive inefficiency, for example. |
| 856 |
|
| 857 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 858 |
@ChgAdded{Version=[1],Text=[There is no such permission for operational aspects.]} |
| 859 |
@end{Ramification} |
| 860 |
@end{ImplPerm} |
| 861 |
|
| 862 |
@begin{ImplAdvice} |
| 863 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(with respect to |
| 864 |
nonstatic expressions)} |
| 865 |
The recommended level of support for all representation items |
| 866 |
is qualified as follows: |
| 867 |
@begin{Itemize} |
| 868 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 869 |
@ChgAdded{Version=[2],Text=[A confirming representation item should |
| 870 |
be supported.]} |
| 871 |
@begin{Honest} |
| 872 |
@ChgRef{Version=[2],Kind=[Added]} |
| 873 |
@ChgAdded{Version=[2],Text=[A confirming representation item might not be |
| 874 |
possible for some entities. For instance, consider an unconstrained array. |
| 875 |
The size of such a type is implementation-defined, and might not actually |
| 876 |
be a representable value, or might not be static.]} |
| 877 |
@end{Honest} |
| 878 |
An implementation need not support representation items containing |
| 879 |
nonstatic expressions, |
| 880 |
except that an implementation should support a representation item |
| 881 |
for a given entity |
| 882 |
if each nonstatic expression in the representation item |
| 883 |
is a name that statically denotes a constant declared |
| 884 |
before the entity. |
| 885 |
@begin{Reason} |
| 886 |
@Leading@;This is to avoid the following sort of thing: |
| 887 |
@begin{Example} |
| 888 |
X : Integer := F(...); |
| 889 |
Y : Address := G(...); |
| 890 |
@key[for] X'Address @key[use] Y; |
| 891 |
@end{Example} |
| 892 |
|
| 893 |
In the above, we have to evaluate the initialization expression for X |
| 894 |
before we know where to put the result. |
| 895 |
This seems like an unreasonable implementation burden. |
| 896 |
|
| 897 |
@Leading@;The above code should instead be written like this: |
| 898 |
@begin{Example} |
| 899 |
Y : @key[constant] Address := G(...); |
| 900 |
X : Integer := F(...); |
| 901 |
@key[for] X'Address @key[use] Y; |
| 902 |
@end{Example} |
| 903 |
|
| 904 |
This allows the expression @lquotes@;Y@rquotes@; to be safely evaluated before X is |
| 905 |
created. |
| 906 |
|
| 907 |
The constant could be a formal parameter of mode @key[in]. |
| 908 |
|
| 909 |
An implementation can support other nonstatic expressions if it wants |
| 910 |
to. Expressions of type Address are hardly ever static, |
| 911 |
but their value might be known at compile time anyway |
| 912 |
in many cases. |
| 913 |
@end{Reason} |
| 914 |
|
| 915 |
An implementation need not support a specification for the |
| 916 |
Size for a given composite subtype, nor the size or storage place for an object |
| 917 |
(including a component) of a given composite subtype, unless the constraints |
| 918 |
on the subtype and its composite subcomponents (if any) |
| 919 |
are all static constraints. |
| 920 |
|
| 921 |
|
| 922 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 923 |
@Chg{Version=[2],New=[An implementation need not support a nonconfirming |
| 924 |
representation item if it could cause an aliased object or an object of a |
| 925 |
by-reference type to be allocated at a nonaddressable location or, when the |
| 926 |
alignment attribute of the subtype of such an object is nonzero, at an address |
| 927 |
that is not an integral multiple of that alignment.],Old=[An aliased component, |
| 928 |
or a component whose type is by-reference, should always be allocated at an |
| 929 |
addressable location.]} |
| 930 |
@begin{Reason} |
| 931 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-0079} |
| 932 |
The intent is that access types, type System.Address, |
| 933 |
and the pointer used for a by-reference parameter should |
| 934 |
be implementable as a single machine address @em bit-field pointers |
| 935 |
should not be required. |
| 936 |
(There is no requirement that this implementation be used @em we just |
| 937 |
want to make sure @Chg{New=[it's],Old=[its]} feasible.) |
| 938 |
@end{Reason} |
| 939 |
@begin{ImplNote} |
| 940 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 941 |
@Chg{Version=[2],New=[We want subprograms to be able to assume the properties |
| 942 |
of the types of their parameters inside of subprograms. While many objects |
| 943 |
can be copied to allow this |
| 944 |
(and thus do not need limitations), aliased or by-reference objects cannot |
| 945 |
be copied (their memory location is part of their identity). Thus,], |
| 946 |
Old=[Note that]} |
| 947 |
the above rule does not apply to types that merely allow |
| 948 |
by-reference parameter passing; |
| 949 |
for such types, a copy typically needs to be made at the call site |
| 950 |
when a bit-aligned component is passed as a parameter. |
| 951 |
@end{ImplNote} |
| 952 |
|
| 953 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 954 |
@ChgAdded{Version=[2],Text=[An implementation need not support a nonconfirming |
| 955 |
representation item if it could cause an aliased object of an elementary type |
| 956 |
to have a size other than that which would have been chosen by default.]} |
| 957 |
@begin{Reason} |
| 958 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 959 |
@ChgAdded{Version=[2],Text=[Since all bits of elementary objects participate |
| 960 |
in operations, aliased objects must not have a different size than that |
| 961 |
assumed by users of the access type.]} |
| 962 |
@end{Reason} |
| 963 |
|
| 964 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 965 |
@ChgAdded{Version=[2],Text=[An implementation need not support a nonconfirming |
| 966 |
representation item if it could cause an aliased object of a composite type, or |
| 967 |
an object whose type is by-reference, to have a size smaller than that which |
| 968 |
would have been chosen by default.]} |
| 969 |
@begin{Reason} |
| 970 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 971 |
@ChgAdded{Version=[2],Text=[Unlike elementary objects, there is no |
| 972 |
requirement that all bits of a composite object participate in operations. |
| 973 |
Thus, as long as the object is the same or larger in size than that expected |
| 974 |
by the access type, all is well.]} |
| 975 |
@end{Reason} |
| 976 |
@begin{Ramification} |
| 977 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 978 |
@ChgAdded{Version=[2],Text=[This rule presumes that the implementation |
| 979 |
allocates an object of a size specified to be larger than the default size in |
| 980 |
such a way that access of the default size suffices to correctly read and |
| 981 |
write the value of the object.]} |
| 982 |
@end{Ramification} |
| 983 |
|
| 984 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 985 |
@ChgAdded{Version=[2],Text=[An implementation need not support a nonconfirming |
| 986 |
subtype-specific representation item specifying an aspect of representation of |
| 987 |
an indefinite or abstract subtype.]} |
| 988 |
@begin{Reason} |
| 989 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 990 |
@ChgAdded{Version=[2],Text=[Aspects of representations are often not |
| 991 |
well-defined for such types.]} |
| 992 |
@end{Reason} |
| 993 |
|
| 994 |
@begin{Ramification} |
| 995 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00075} |
| 996 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 997 |
A pragma Pack will typically not pack so tightly as to disobey the above |
| 998 |
@Chg{Version=[2],New=[rules],Old=[rule]}. A Component_Size clause or |
| 999 |
@nt{record_representation_clause} will typically @Chg{New=[be],Old=[by]} |
| 1000 |
illegal if it disobeys the above @Chg{Version=[2],New=[rules],Old=[rule]}. |
| 1001 |
Atomic components have similar restrictions |
| 1002 |
(see @RefSec{Shared Variable Control}). |
| 1003 |
@end{Ramification} |
| 1004 |
@end{Itemize} |
| 1005 |
|
| 1006 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 1007 |
@ChgAdded{Version=[2],Text=[For purposes of these rules, the determination of |
| 1008 |
whether a representation item applied to a type @i{could cause} an object to have |
| 1009 |
some property is based solely on the properties of the type itself, not on any |
| 1010 |
available information about how the type is used. In particular, it presumes |
| 1011 |
that minimally aligned objects of this type might be declared at some point.]} |
| 1012 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 1013 |
Text=[The recommended level of support for all representation items should be |
| 1014 |
followed.]}]} |
| 1015 |
@end{ImplAdvice} |
| 1016 |
|
| 1017 |
@begin{Incompatible83} |
| 1018 |
@Defn{incompatibilities with Ada 83} |
| 1019 |
It is now illegal for a representation item to cause a derived |
| 1020 |
by-reference type to have a different record layout from its |
| 1021 |
parent. |
| 1022 |
This is necessary for by-reference parameter passing to be feasible. |
| 1023 |
This only affects programs that specify the representation of types |
| 1024 |
derived from types containing tasks; |
| 1025 |
most by-reference types are new to Ada 95. |
| 1026 |
For example, if A1 is an array of tasks, and A2 is derived from A1, |
| 1027 |
it is illegal to apply a @nt{pragma} Pack to A2. |
| 1028 |
@end{Incompatible83} |
| 1029 |
|
| 1030 |
@begin{Extend83} |
| 1031 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1032 |
@Defn{extensions to Ada 83} |
| 1033 |
Ada 95 allows additional @Chg{New=[@nt{aspect_clause}s], |
| 1034 |
Old=[@nt{representation_clause}s]} for objects. |
| 1035 |
@end{Extend83} |
| 1036 |
|
| 1037 |
@begin{DiffWord83} |
| 1038 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1039 |
The syntax rule for @ntf{type_representation_clause} is removed; |
| 1040 |
the right-hand side of that rule is moved up to where it was used, |
| 1041 |
in @Chg{New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]}. |
| 1042 |
There are two references to @lquotes@;type representation clause@rquotes@; in RM83, |
| 1043 |
both in Section 13; these have been reworded. |
| 1044 |
@Chg{New=[Also, the @ntf{representation_clause} has been renamed the |
| 1045 |
@nt{aspect_clause} to reflect that it can be used to control more than just |
| 1046 |
representation aspects.],Old=[]} |
| 1047 |
|
| 1048 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1049 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 1050 |
We have defined a new term @lquotes@;representation item,@rquotes@; |
| 1051 |
which includes @Chg{New=[all representation clauses], |
| 1052 |
Old=[@nt{representation_clause}s]} and representation pragmas, as well as |
| 1053 |
@nt<component_clause>s. |
| 1054 |
This is convenient because the rules are almost identical for all @Chg{New=[of them], |
| 1055 |
Old=[three]}. @Chg{New=[We have also defined the new terms |
| 1056 |
@lquotes@;operational item@rquotes@; and @lquotes@;operational aspects@rquotes@; |
| 1057 |
in order to conveniently handle new types of @Chg{Version=[2],New=[specifiable],Old=[specifable]} entities.],Old=[]} |
| 1058 |
|
| 1059 |
All of the forcing occurrence stuff has been moved into its own |
| 1060 |
subclause (see @RefSecNum{Freezing Rules}), |
| 1061 |
and rewritten to use the term @lquotes@;freezing@rquotes@;. |
| 1062 |
|
| 1063 |
RM83-13.1(10) requires implementation-defined restrictions on |
| 1064 |
representation items to be enforced at compile time. |
| 1065 |
However, that is impossible in some cases. |
| 1066 |
If the user specifies a junk (nonstatic) address in an address |
| 1067 |
clause, and the implementation chooses to detect the error (for example, |
| 1068 |
using hardware memory management with protected pages), then it's |
| 1069 |
clearly going to be a run-time error. |
| 1070 |
It seems silly to call that @lquotes@;semantics@rquotes@; rather than |
| 1071 |
@lquotes@;a restriction.@rquotes@; |
| 1072 |
|
| 1073 |
RM83-13.1(10) tries to pretend that @ntf{representation_clause}s don't affect |
| 1074 |
the semantics of the program. |
| 1075 |
One counter-example is the Small clause. |
| 1076 |
Ada 95 has more counter-examples. |
| 1077 |
We have noted the opposite above. |
| 1078 |
|
| 1079 |
Some of the more stringent requirements are moved to |
| 1080 |
@RefSec{Required Representation Support}. |
| 1081 |
@end{DiffWord83} |
| 1082 |
|
| 1083 |
@begin{Extend95} |
| 1084 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 1085 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1086 |
@b[Amendment Correction:] Confirming representation items are |
| 1087 |
defined, and the recommended level of support is now that they always |
| 1088 |
be supported.]} |
| 1089 |
@end{Extend95} |
| 1090 |
|
| 1091 |
@begin{DiffWord95} |
| 1092 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1093 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added operational items |
| 1094 |
in order to eliminate unnecessary restrictions and permissions on |
| 1095 |
stream attributes. As part of this, @ntf{representation_clause} was |
| 1096 |
renamed to @nt{aspect_clause}.]} |
| 1097 |
|
| 1098 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01],ARef=[AI95-00326-01]} |
| 1099 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to say that the |
| 1100 |
partial and full views have the same operational and representation aspects. |
| 1101 |
Ada 2005 extends this to cover all views, including the incomplete view.]} |
| 1102 |
|
| 1103 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 1104 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed operational items |
| 1105 |
to have inheritance specified for each such aspect.]} |
| 1106 |
|
| 1107 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]} |
| 1108 |
@ChgAdded{Version=[2],Text=[Added wording to allow the rejection of |
| 1109 |
types with progenitors that have conflicting representation items.]} |
| 1110 |
|
| 1111 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 1112 |
@ChgAdded{Version=[2],Text=[The description of the representation of an |
| 1113 |
object was clarified (with great difficulty reaching agreement). Added |
| 1114 |
wording to say that representation items on aliased and by-reference objects |
| 1115 |
never need be supported if they would not be implementable without |
| 1116 |
distributed overhead even if other recommended level of support says |
| 1117 |
otherwise. This wording matches the rules with reality.]} |
| 1118 |
|
| 1119 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00444-01]} |
| 1120 |
@ChgAdded{Version=[2],Text=[Added wording so that inheritance depends on |
| 1121 |
whether operational items are visible rather than whether they occur before |
| 1122 |
the declaration (we don't want to look into private parts). Limited |
| 1123 |
operational inheritance to untagged types to avoid anomolies with private |
| 1124 |
extensions (this is not incompatible, no existing operational attribute |
| 1125 |
used this capability). Also added |
| 1126 |
wording to clearly define that subprogram inheritance works like derivation |
| 1127 |
of subprograms.]} |
| 1128 |
@end{DiffWord95} |
| 1129 |
|
| 1130 |
|
| 1131 |
@LabeledClause{Pragma Pack} |
| 1132 |
|
| 1133 |
@begin{Intro} |
| 1134 |
@redundant[A @nt{pragma} Pack specifies that storage |
| 1135 |
minimization should be the main criterion when |
| 1136 |
selecting the representation of a composite type.] |
| 1137 |
@end{Intro} |
| 1138 |
|
| 1139 |
@begin{Syntax} |
| 1140 |
@begin{SyntaxText} |
| 1141 |
@Leading@Keepnext@;The form of a @nt{pragma} Pack is as follows: |
| 1142 |
@end{SyntaxText} |
| 1143 |
|
| 1144 |
@PragmaSyn`@key{pragma} @prag(Pack)(@SynI{first_subtype_}@Syn2{local_name});' |
| 1145 |
@end{Syntax} |
| 1146 |
|
| 1147 |
@begin{Legality} |
| 1148 |
The @SynI{first_subtype_}@nt{local_name} of a @nt{pragma} Pack |
| 1149 |
shall denote a composite subtype. |
| 1150 |
@end{Legality} |
| 1151 |
|
| 1152 |
@begin{StaticSem} |
| 1153 |
@PDefn2{Term=[representation pragma], Sec=(Pack)} |
| 1154 |
@PDefn2{Term=[pragma, representation], Sec=(Pack)} |
| 1155 |
@PDefn2{Term=[aspect of representation], Sec=(packing)} |
| 1156 |
@Defn2{Term=[packing], Sec=(aspect of representation)} |
| 1157 |
@Defn{packed} |
| 1158 |
A @nt{pragma} Pack specifies the @i{packing} aspect of representation; |
| 1159 |
the type (or the extension part) is said to be @i{packed}. |
| 1160 |
For a type extension, the parent part is packed as for the parent |
| 1161 |
type, and a @nt{pragma} Pack causes packing only of the extension part. |
| 1162 |
@begin{Ramification} |
| 1163 |
The only high level semantic effect of a @nt{pragma} Pack |
| 1164 |
is independent addressability (see @RefSec{Shared Variables}). |
| 1165 |
@end{Ramification} |
| 1166 |
@end{StaticSem} |
| 1167 |
|
| 1168 |
@begin{ImplAdvice} |
| 1169 |
If a type is packed, then the implementation should try to minimize |
| 1170 |
storage allocated to objects of the type, |
| 1171 |
possibly at the expense of speed of accessing components, |
| 1172 |
subject to reasonable complexity in addressing calculations. |
| 1173 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1174 |
Text=[Storage allocated to objects of a packed type should be minimized.]}]} |
| 1175 |
@begin{Ramification} |
| 1176 |
A @nt{pragma} Pack is for gaining space efficiency, |
| 1177 |
possibly at the expense of time. |
| 1178 |
If more explicit control over representation is desired, |
| 1179 |
then a @nt{record_representation_clause}, |
| 1180 |
a Component_Size clause, |
| 1181 |
or a Size clause should be used instead of, |
| 1182 |
or in addition to, |
| 1183 |
a @nt{pragma} Pack. |
| 1184 |
@end{Ramification} |
| 1185 |
|
| 1186 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 1187 |
@ChgAdded{Version=[2],Text=[If a packed type has a component that is not of a |
| 1188 |
by-reference type and has no aliased part, then such a component need not be |
| 1189 |
aligned according to the Alignment of its subtype; in particular it |
| 1190 |
need not be allocated on a storage element boundary.]} |
| 1191 |
@Comment{No "should" here; thus no ImplAdvice entry. This really qualifies the |
| 1192 |
item above} |
| 1193 |
|
| 1194 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(pragma Pack)} |
| 1195 |
The recommended level of support for pragma Pack is: |
| 1196 |
@begin{Itemize} |
| 1197 |
For a packed record type, |
| 1198 |
the components should be packed as tightly as possible |
| 1199 |
subject to the Sizes of the component subtypes, |
| 1200 |
and subject to any @nt{record_representation_clause} that applies to |
| 1201 |
the type; the implementation may, but need not, reorder components |
| 1202 |
or cross aligned word boundaries to improve the packing. |
| 1203 |
A component whose Size is greater than the word size |
| 1204 |
may be allocated an integral number of words. |
| 1205 |
@begin{Ramification} |
| 1206 |
The implementation can always allocate an integral number of |
| 1207 |
words for a component that will not fit in a word. |
| 1208 |
The rule also allows small component sizes to be rounded up if such |
| 1209 |
rounding does not waste space. |
| 1210 |
For example, if Storage_Unit = 8, then a component of size 8 is |
| 1211 |
probably more efficient than a component of size 7 plus a 1-bit gap |
| 1212 |
(assuming the gap is needed anyway). |
| 1213 |
@end{Ramification} |
| 1214 |
|
| 1215 |
For a packed array type, if the component subtype's Size is less |
| 1216 |
than or equal to the word size, and Component_Size is not |
| 1217 |
specified for the type, Component_Size should be less than or |
| 1218 |
equal to the Size of the component subtype, rounded up to the nearest |
| 1219 |
factor of the word size. |
| 1220 |
@begin{Ramification} |
| 1221 |
If a component subtype is aliased, |
| 1222 |
its Size will generally be a multiple of Storage_Unit, |
| 1223 |
so it probably won't get packed very tightly. |
| 1224 |
@end{Ramification} |
| 1225 |
@end{Itemize} |
| 1226 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 1227 |
Text=[The recommended level of support for pragma Pack should be |
| 1228 |
followed.]}]} |
| 1229 |
@end{ImplAdvice} |
| 1230 |
|
| 1231 |
@begin{DiffWord95} |
| 1232 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 1233 |
@ChgAdded{Version=[2],Text=[Added clarification that pragma Pack can |
| 1234 |
ignore alignment requirements on types that don't have by-reference or |
| 1235 |
aliased parts. This was always intended, but there was no wording to that |
| 1236 |
effect.]} |
| 1237 |
@end{DiffWord95} |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
@LabeledRevisedClause{Version=[1],New=[Operational and Representation Attributes], Old=[Representation Attributes]} |
| 1242 |
|
| 1243 |
@begin{Intro} |
| 1244 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1245 |
@redundant[@Defn{representation attribute} |
| 1246 |
@Defn2{Term=[attribute], Sec=(representation)} |
| 1247 |
The values of certain implementation-dependent characteristics can be |
| 1248 |
obtained by interrogating appropriate |
| 1249 |
@Chg{New=[operational or ],Old=[]}representation attributes. |
| 1250 |
@RootDefn2{Term=[attribute], Sec=(specifying)} |
| 1251 |
Some of these attributes are specifiable via an |
| 1252 |
@nt{attribute_definition_clause}.] |
| 1253 |
@end{Intro} |
| 1254 |
|
| 1255 |
@begin{MetaRules} |
| 1256 |
In general, the meaning of a given attribute should not depend on |
| 1257 |
whether the attribute was specified via an |
| 1258 |
@nt{attribute_definition_clause}, |
| 1259 |
or chosen by default by the implementation. |
| 1260 |
@end{MetaRules} |
| 1261 |
|
| 1262 |
@begin{Syntax} |
| 1263 |
@Syn{lhs=<attribute_definition_clause>,rhs=" |
| 1264 |
@key{for} @Syn2{local_name}@SingleQuote@Syn2{attribute_designator} @key{use} @Syn2{expression}; |
| 1265 |
| @key{for} @Syn2{local_name}@SingleQuote@Syn2{attribute_designator} @key{use} @Syn2{name};"} |
| 1266 |
@end{Syntax} |
| 1267 |
|
| 1268 |
@begin{Resolution} |
| 1269 |
For an @nt{attribute_definition_clause} that specifies |
| 1270 |
an attribute that denotes a value, |
| 1271 |
the form with an @nt{expression} shall be used. |
| 1272 |
Otherwise, the form with a @nt{name} shall be used. |
| 1273 |
|
| 1274 |
@PDefn2{Term=[expected type], |
| 1275 |
Sec=(attribute_definition_clause expression or name)} |
| 1276 |
For an @nt{attribute_definition_clause} that specifies |
| 1277 |
an attribute that denotes a value or an object, |
| 1278 |
the expected type for the expression or @nt{name} |
| 1279 |
is that of the attribute. |
| 1280 |
@PDefn2{Term=[expected profile], |
| 1281 |
Sec=(attribute_definition_clause name)} |
| 1282 |
For an @nt{attribute_definition_clause} that specifies |
| 1283 |
an attribute that denotes a subprogram, |
| 1284 |
the expected profile for the @nt{name} |
| 1285 |
is the profile required for the attribute. |
| 1286 |
For an @nt{attribute_definition_clause} that specifies |
| 1287 |
an attribute that denotes some other kind of entity, |
| 1288 |
the @nt{name} shall resolve to denote an entity of the appropriate |
| 1289 |
kind. |
| 1290 |
@begin{Ramification} |
| 1291 |
For example, the Size attribute is of type @i{universal_integer}. |
| 1292 |
Therefore, the expected type for Y in @lquotes@;@key[for] X'Size @key[use] Y;@rquotes@; is |
| 1293 |
@i{universal_integer}, |
| 1294 |
which means that Y can be of any integer type. |
| 1295 |
@end{Ramification} |
| 1296 |
@begin{Discussion} |
| 1297 |
For attributes that denote subprograms, the required profile is indicated |
| 1298 |
separately for the individual attributes. |
| 1299 |
@end{Discussion} |
| 1300 |
@begin{Ramification} |
| 1301 |
@Leading@;For an @nt{attribute_definition_clause} with a @nt{name}, |
| 1302 |
the @nt{name} need not statically denote the entity it denotes. |
| 1303 |
For example, the following kinds of things are allowed: |
| 1304 |
@begin{Example} |
| 1305 |
@key[for] Some_Access_Type'Storage_Pool @key[use] Storage_Pool_Array(I); |
| 1306 |
@key[for] Some_Type'Read @key[use] Subprogram_Pointer.@key[all]; |
| 1307 |
@end{Example} |
| 1308 |
@end{Ramification} |
| 1309 |
@end{Resolution} |
| 1310 |
|
| 1311 |
@begin{Legality} |
| 1312 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1313 |
@RootDefn{specifiable (of an attribute and for an entity)} |
| 1314 |
@RootDefn2{Term=[attribute], Sec=(specifiable)} |
| 1315 |
An @nt{attribute_designator} is allowed in an |
| 1316 |
@nt{attribute_definition_clause} only if this International Standard |
| 1317 |
explicitly allows it, |
| 1318 |
or for an implementation-defined attribute |
| 1319 |
if the implementation allows it. |
| 1320 |
@PDefn2{Term=[aspect of representation], Sec=(specifiable attributes)} |
| 1321 |
Each specifiable attribute constitutes an |
| 1322 |
@Chg{New=[@PDefn2{Term=[operational aspect], Sec=(specifiable attributes)} |
| 1323 |
operational aspect or ],Old=[]}aspect of representation. |
| 1324 |
@begin{Discussion} |
| 1325 |
For each specifiable attribute, |
| 1326 |
we generally say something like, |
| 1327 |
@lquotes@;The ... attribute may be specified for ... via |
| 1328 |
an @nt{attribute_definition_clause}.@rquotes@; |
| 1329 |
|
| 1330 |
The above wording allows for |
| 1331 |
T'Class'Alignment, T'Class'Size, T'Class'Input, and T'Class'Output |
| 1332 |
to be specifiable. |
| 1333 |
|
| 1334 |
A specifiable attribute is not necessarily |
| 1335 |
specifiable for all entities for which it is defined. |
| 1336 |
For example, one is allowed to ask T'Component_Size for an array |
| 1337 |
subtype T, but @lquotes@;@key[for] T'Component_Size @key[use] ...@rquotes@; |
| 1338 |
is only allowed if T is a first subtype, |
| 1339 |
because Component_Size is a type-related aspect. |
| 1340 |
@end{Discussion} |
| 1341 |
|
| 1342 |
For an @nt{attribute_definition_clause} that specifies |
| 1343 |
an attribute that denotes a subprogram, |
| 1344 |
the profile shall be mode conformant with the one |
| 1345 |
required for the attribute, |
| 1346 |
and the convention shall be Ada. |
| 1347 |
Additional requirements are defined for particular attributes. |
| 1348 |
@Defn2{Term=[mode conformance],Sec=(required)} |
| 1349 |
@begin{Ramification} |
| 1350 |
@Leading@;This implies, for example, that if one writes: |
| 1351 |
@begin{Example} |
| 1352 |
@key[for] T'Read @key[use] R; |
| 1353 |
@end{Example} |
| 1354 |
|
| 1355 |
R has to be a procedure with two parameters with the appropriate |
| 1356 |
subtypes and modes as shown in |
| 1357 |
@RefSecNum{Stream-Oriented Attributes}. |
| 1358 |
@end{Ramification} |
| 1359 |
@end{Legality} |
| 1360 |
|
| 1361 |
@begin{StaticSem} |
| 1362 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00270-01]} |
| 1363 |
@Defn{Address clause} |
| 1364 |
@Defn{Alignment clause} |
| 1365 |
@Defn{Size clause} |
| 1366 |
@Defn{Component_Size clause} |
| 1367 |
@Defn{External_Tag clause} |
| 1368 |
@Defn{Small clause} |
| 1369 |
@Defn{Bit_Order clause} |
| 1370 |
@Defn{Storage_Pool clause} |
| 1371 |
@Defn{Storage_Size clause}@Chg{Version=[2],New=[ |
| 1372 |
@Defn{Stream_Size clause}],Old=[]} |
| 1373 |
@Defn{Read clause} |
| 1374 |
@Defn{Write clause} |
| 1375 |
@Defn{Input clause} |
| 1376 |
@Defn{Output clause} |
| 1377 |
@Defn{Machine_Radix clause} |
| 1378 |
A @i{Size clause} is an @nt{attribute_definition_clause} whose |
| 1379 |
@nt{attribute_designator} is Size. |
| 1380 |
Similar definitions apply to the other specifiable attributes. |
| 1381 |
@begin{Honest} |
| 1382 |
@PDefn2{Term=[type-related], Sec=(attribute_definition_clause)} |
| 1383 |
@PDefn2{Term=[subtype-specific], Sec=(attribute_definition_clause)} |
| 1384 |
An @nt{attribute_definition_clause} |
| 1385 |
is type-related or subtype-specific if the @nt{attribute_designator} |
| 1386 |
denotes a type-related or subtype-specific attribute, respectively. |
| 1387 |
@end{Honest} |
| 1388 |
|
| 1389 |
@Defn{storage element} |
| 1390 |
@IndexSee{Term=[byte],See=(storage element)} |
| 1391 |
A @i{storage element} is |
| 1392 |
an addressable element of storage in the machine. |
| 1393 |
@Defn{word} |
| 1394 |
A @i{word} is the largest amount of storage that can be conveniently and |
| 1395 |
efficiently manipulated by the hardware, |
| 1396 |
given the implementation's run-time model. |
| 1397 |
A word consists of an integral number of storage elements. |
| 1398 |
@begin{Discussion} |
| 1399 |
A storage element is not intended to be a single bit, |
| 1400 |
unless the machine can efficiently address individual bits. |
| 1401 |
@end{Discussion} |
| 1402 |
@begin{Ramification} |
| 1403 |
For example, on a machine with 8-bit storage elements, |
| 1404 |
if there exist 32-bit integer registers, |
| 1405 |
with a full set of arithmetic and logical instructions to manipulate those |
| 1406 |
registers, a word ought to be 4 storage elements @em that is, 32 bits. |
| 1407 |
@end{Ramification} |
| 1408 |
@begin{Discussion} |
| 1409 |
The @lquotes@;given the implementation's run-time model@rquotes@; part is |
| 1410 |
intended to imply that, for example, on an 80386 running MS-DOS, |
| 1411 |
the word might be 16 bits, even though the hardware can support 32 |
| 1412 |
bits. |
| 1413 |
|
| 1414 |
A word is what ACID refers to as a @lquotes@;natural hardware |
| 1415 |
boundary@rquotes@;. |
| 1416 |
|
| 1417 |
Storage elements may, but need not be, independently addressable |
| 1418 |
(see @RefSec{Shared Variables}). |
| 1419 |
Words are expected to be independently addressable. |
| 1420 |
@end{Discussion} |
| 1421 |
|
| 1422 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]} |
| 1423 |
@ChgAdded{Version=[2],Text=[@Defn{machine scalar} |
| 1424 |
A @i{machine scalar} is an amount of storage that can be conveniently and |
| 1425 |
efficiently loaded, stored, or operated upon by the hardware. Machine scalars |
| 1426 |
consist of an integral number of storage elements. The set of machine scalars |
| 1427 |
is implementation defined, but must include at least the storage element and |
| 1428 |
the word. Machine scalars are used to interpret @nt{component_clause}s when the |
| 1429 |
nondefault bit ordering applies.]} |
| 1430 |
@ChgImplDef{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1431 |
Text=[The set of machine scalars.]}]} |
| 1432 |
|
| 1433 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 1434 |
@Chg{New=[The following representation attributes are defined: Address, |
| 1435 |
Alignment, Size, Storage_Size, and Component_Size.], |
| 1436 |
Old=[@Leading@;The following attributes are defined:]} |
| 1437 |
|
| 1438 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 1439 |
@Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a |
| 1440 |
@Chg{New=[@nt{prefix}],Old=[prefix]} X that |
| 1441 |
denotes an object, program unit, or label]}: |
| 1442 |
@begin{Description} |
| 1443 |
@Attribute{Prefix=<X>, AttrName=<Address>, |
| 1444 |
Text=<Denotes the address of the first of the storage elements |
| 1445 |
allocated to X. For a program unit or |
| 1446 |
label, this value refers to the machine code associated with |
| 1447 |
the corresponding body or @nt{statement}. |
| 1448 |
The value of this attribute is of type System.Address.>} |
| 1449 |
@begin{Ramification} |
| 1450 |
|
| 1451 |
Here, the @lquotes@;first of the storage elements@rquotes@; is intended to mean |
| 1452 |
the one with the lowest address; |
| 1453 |
the endianness of the machine doesn't matter. |
| 1454 |
|
| 1455 |
@end{Ramification} |
| 1456 |
|
| 1457 |
@NoPrefix@;@PDefn2{Term=[specifiable], Sec=(of Address for stand-alone |
| 1458 |
objects and for program units)} |
| 1459 |
@Defn{Address clause} |
| 1460 |
@ChgNote{Removed Redundant here, as per AI-00114. Did not mark change, as it is |
| 1461 |
AARM-only, not to the text of the item.}Address may be specified for |
| 1462 |
stand-alone objects and for program units via an |
| 1463 |
@nt{attribute_definition_clause}. |
| 1464 |
@begin{Ramification} |
| 1465 |
Address is not allowed for enumeration literals, |
| 1466 |
predefined operators, derived task types, |
| 1467 |
or derived protected types, since they are not program units. |
| 1468 |
|
| 1469 |
The validity of a given address depends on the run-time model; |
| 1470 |
thus, in order to use Address clauses correctly, |
| 1471 |
one needs intimate knowledge of the run-time model. |
| 1472 |
|
| 1473 |
If the Address of an object is specified, |
| 1474 |
any explicit or implicit initialization takes place as usual, |
| 1475 |
unless a @nt{pragma} Import is also specified for the object |
| 1476 |
(in which case any necessary initialization is presumably |
| 1477 |
done in the foreign language). |
| 1478 |
|
| 1479 |
Any compilation unit containing an @nt<attribute_reference> of |
| 1480 |
a given type depends semantically on the declaration of the package |
| 1481 |
in which the type is declared, even if not mentioned |
| 1482 |
in an applicable @nt<with_clause> |
| 1483 |
@em see @RefSecNum{Compilation Units - Library Units}. |
| 1484 |
In this case, it means that if a compilation unit contains |
| 1485 |
X'Address, then it depends on the declaration of System. |
| 1486 |
Otherwise, the fact that the value of Address is of |
| 1487 |
a type in System wouldn't make sense; |
| 1488 |
it would violate the @lquotes@;legality determinable via semantic |
| 1489 |
dependences@rquotes@; @MetaRulesName. |
| 1490 |
|
| 1491 |
AI83-00305 @em If X is a task type, |
| 1492 |
then within the body of X, |
| 1493 |
X denotes the current task object; |
| 1494 |
thus, X'Address denotes the object's address. |
| 1495 |
|
| 1496 |
Interrupt entries and their addresses are |
| 1497 |
described in @RefSec{Interrupt Entries}. |
| 1498 |
|
| 1499 |
If X is not allocated on a storage element boundary, |
| 1500 |
X'Address points at the first of the storage elements |
| 1501 |
that contains any part of X. |
| 1502 |
This is important for the definition of the Position |
| 1503 |
attribute to be sensible. |
| 1504 |
@end{Ramification} |
| 1505 |
@end{Description} |
| 1506 |
@EndPrefixType{} |
| 1507 |
@end{StaticSem} |
| 1508 |
|
| 1509 |
@begin{Erron} |
| 1510 |
@PDefn2{Term=(erroneous execution),Sec=(cause)}If an Address is specified, |
| 1511 |
it is the programmer's responsibility to ensure that |
| 1512 |
the address is valid; otherwise, program execution is erroneous. |
| 1513 |
@end{Erron} |
| 1514 |
|
| 1515 |
@begin{ImplAdvice} |
| 1516 |
For an array X, X'Address should point at the first component of the |
| 1517 |
array, and not at the array bounds. |
| 1518 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1519 |
Text=[For an array X, X'Address should point at the first component of the |
| 1520 |
array rather than the array bounds.]}]} |
| 1521 |
@begin{Ramification} |
| 1522 |
On the other hand, we have no advice to offer about |
| 1523 |
discriminants and tag fields; |
| 1524 |
whether or not the address points at them is |
| 1525 |
not specified by the language. |
| 1526 |
If discriminants are stored separately, |
| 1527 |
then the Position of a discriminant might be negative, |
| 1528 |
or might raise an exception. |
| 1529 |
@end{Ramification} |
| 1530 |
|
| 1531 |
@PDefn2{Term=[recommended level of support], Sec=(Address attribute)} |
| 1532 |
@Leading@;The recommended level of support for the Address attribute is: |
| 1533 |
@begin{Itemize} |
| 1534 |
X'Address should produce a useful result if X is an |
| 1535 |
object that is aliased or of a by-reference |
| 1536 |
type, or is an entity whose Address has been specified. |
| 1537 |
@begin{Reason} |
| 1538 |
Aliased objects are the ones for which the |
| 1539 |
Unchecked_Access attribute is allowed; |
| 1540 |
hence, these have to be allocated on an addressable |
| 1541 |
boundary anyway. Similar considerations apply to objects |
| 1542 |
of a by-reference type. |
| 1543 |
|
| 1544 |
An implementation need not go to any trouble |
| 1545 |
to make Address work in other cases. |
| 1546 |
For example, if an object X is not aliased and not of a by-reference type, |
| 1547 |
and the implementation chooses to store it in a register, |
| 1548 |
X'Address might return System.Null_Address |
| 1549 |
(assuming registers are not addressable). |
| 1550 |
For a subprogram whose calling convention is Intrinsic, |
| 1551 |
or for a package, |
| 1552 |
the implementation need not generate an out-of-line |
| 1553 |
piece of code for it. |
| 1554 |
@end{Reason} |
| 1555 |
|
| 1556 |
An implementation should support Address clauses for |
| 1557 |
imported subprograms. |
| 1558 |
|
| 1559 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]} |
| 1560 |
@ChgDeleted{Version=[2],Text=[Objects (including subcomponents) that are |
| 1561 |
aliased or of a by-reference type |
| 1562 |
should be allocated on storage element boundaries.]} |
| 1563 |
@Comment{There is a now a blanket permission to this effect} |
| 1564 |
@begin{Reason} |
| 1565 |
@ChgRef{Version=[2],Kind=[Deleted]} |
| 1566 |
@ChgDeleted{Version=[2],Text=[This is necessary for the Address attribute to be |
| 1567 |
useful (since First_Bit and Last_Bit apply only to components). Implementations |
| 1568 |
generally need to do this anyway, for tasking to work properly.]} |
| 1569 |
@end{Reason} |
| 1570 |
|
| 1571 |
If the Address of an object is specified, |
| 1572 |
or it is imported or exported, |
| 1573 |
then the implementation should not perform optimizations based on |
| 1574 |
assumptions of no aliases. |
| 1575 |
@end{Itemize} |
| 1576 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 1577 |
Text=[The recommended level of support for the Address attribute should be |
| 1578 |
followed.]}]} |
| 1579 |
@end{ImplAdvice} |
| 1580 |
|
| 1581 |
@begin{Notes} |
| 1582 |
The specification of a link name in a @nt{pragma} Export |
| 1583 |
(see @RefSecNum{Interfacing Pragmas}) |
| 1584 |
for a subprogram or object is an alternative to explicit |
| 1585 |
specification of its link-time address, allowing a link-time directive |
| 1586 |
to place the subprogram or object within memory. |
| 1587 |
|
| 1588 |
The rules for the Size attribute imply, |
| 1589 |
for an aliased object X, that if X'Size = Storage_Unit, |
| 1590 |
then X'Address points at a storage element containing all |
| 1591 |
of the bits of X, and only the bits of X. |
| 1592 |
@end{Notes} |
| 1593 |
|
| 1594 |
@begin{DiffWord83} |
| 1595 |
The intended meaning of the various attributes, |
| 1596 |
and their @nt{attribute_definition_clause}s, |
| 1597 |
is more explicit. |
| 1598 |
|
| 1599 |
The @ntf{address_clause} has been renamed to @nt{at_clause} and moved |
| 1600 |
to @RefSec{Obsolescent Features}. |
| 1601 |
One can use an Address clause |
| 1602 |
(@lquotes@;for T'Address @key[use] ...;@rquotes@;) |
| 1603 |
instead. |
| 1604 |
|
| 1605 |
The attributes defined in RM83-13.7.3 are moved to |
| 1606 |
@RefSecNum{Numerics}, |
| 1607 |
@RefSecNum{Attributes of Floating Point Types}, and |
| 1608 |
@RefSecNum{Attributes of Fixed Point Types}. |
| 1609 |
@end{DiffWord83} |
| 1610 |
|
| 1611 |
@begin{MetaRules} |
| 1612 |
By default, the Alignment of a subtype should |
| 1613 |
reflect the @lquotes@;natural@rquotes@; alignment for objects of the |
| 1614 |
subtype on the machine. |
| 1615 |
The Alignment, whether specified or default, |
| 1616 |
should be known at compile time, even though |
| 1617 |
Addresses are generally not known at compile |
| 1618 |
time. |
| 1619 |
(The generated code should never need to check |
| 1620 |
at run time the number of zero bits at the end |
| 1621 |
of an address to determine an alignment). |
| 1622 |
|
| 1623 |
There are two symmetric purposes of Alignment clauses, depending on |
| 1624 |
whether or not the implementation has control over object |
| 1625 |
allocation. |
| 1626 |
If the implementation allocates an object, |
| 1627 |
the implementation should ensure that |
| 1628 |
the Address and Alignment are consistent with |
| 1629 |
each other. |
| 1630 |
If something outside the implementation allocates an |
| 1631 |
object, the implementation should be allowed to |
| 1632 |
assume that the Address and Alignment are |
| 1633 |
consistent, but should not assume stricter alignments |
| 1634 |
than that. |
| 1635 |
@end{MetaRules} |
| 1636 |
|
| 1637 |
@begin{StaticSem} |
| 1638 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 1639 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 1640 |
@Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a |
| 1641 |
@Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes @Chg{Version=[2],New=[an], |
| 1642 |
Old=[a subtype or]} object]}: |
| 1643 |
@begin{Description} |
| 1644 |
@ChgAttribute{Version=[2], Kind=[Revised], ChginAnnex=[F], Leading=[F], |
| 1645 |
Prefix=<X>, AttrName=<Alignment>, ARef=[AI95-00291-02], |
| 1646 |
Text=[@Chg{Version=[2],New=[The value of this attribute is of type |
| 1647 |
@i{universal_integer}, and nonnegative; zero means that the object is not |
| 1648 |
necessarily aligned on a storage element boundary. If X'Alignment is not |
| 1649 |
zero, then X is aligned on a storage unit boundary and X'Address], |
| 1650 |
Old=[The Address of an object that is allocated under |
| 1651 |
control of the implementation]} is an integral multiple of |
| 1652 |
@Chg{Version=[2],New=[X'Alignment],Old=[the Alignment of the object]} |
| 1653 |
(that is, the Address modulo the Alignment is zero).@Chg{Version=[2], |
| 1654 |
New=[],Old=[The offset of a record component is a multiple of the |
| 1655 |
Alignment of the component. |
| 1656 |
For an object that is not allocated under control of |
| 1657 |
the implementation |
| 1658 |
(that is, one that is imported, |
| 1659 |
that is allocated by a user-defined allocator, |
| 1660 |
whose Address has been specified, |
| 1661 |
or is designated by an access value returned by an |
| 1662 |
instance of Unchecked_Conversion), |
| 1663 |
the implementation may assume that the Address is |
| 1664 |
an integral multiple of its Alignment. |
| 1665 |
The implementation shall not assume a stricter alignment.]} |
| 1666 |
|
| 1667 |
@Comment{Deleted below causes trouble in the generated text for attributes, |
| 1668 |
but no fix appears to be possible. And the trouble is much worse in the |
| 1669 |
RTF version than the HTML version, so for now we're making a hand fix.} |
| 1670 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]} |
| 1671 |
@ChgDeleted{Version=[2],NoPrefix=[T],Text=[The value of this attribute |
| 1672 |
is of type @i{universal_integer}, and nonnegative; |
| 1673 |
zero means that the object is not necessarily |
| 1674 |
aligned on a storage element boundary.]}]}@Comment{End X'Alignment} |
| 1675 |
@EndPrefixType{} |
| 1676 |
@begin{Ramification} |
| 1677 |
The Alignment is passed by an @nt{allocator} to the Allocate operation; |
| 1678 |
the implementation has to choose a value such that if the address |
| 1679 |
returned by Allocate is aligned as requested, |
| 1680 |
the generated code can correctly access the object. |
| 1681 |
|
| 1682 |
The above mention of @lquotes@;modulo@rquotes@; is referring to the "@key[mod]" |
| 1683 |
operator declared in System.Storage_Elements; |
| 1684 |
if X @key[mod] N = 0, then X is by definition aligned on an |
| 1685 |
N-storage-element boundary. |
| 1686 |
@end{Ramification} |
| 1687 |
|
| 1688 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 1689 |
@NoPrefix@Chg{Version=[2],New=[@PDefn2{Term=[specifiable], Sec=(of Alignment for objects)}], |
| 1690 |
Old=[@PDefn2{Term=[specifiable], Sec=(of Alignment for first subtypes and objects)}]} |
| 1691 |
@Defn{Alignment clause} |
| 1692 |
Alignment may be specified for@Chg{Version=[2],New=[],Old=[ first subtypes and]} |
| 1693 |
@Redundant[stand-alone] objects via an @nt{attribute_@!definition_@!clause}; |
| 1694 |
the expression of such a clause shall be static, and its value |
| 1695 |
nonnegative.@Chg{Version=[2],New=[],Old=[If the Alignment of a subtype is |
| 1696 |
specified, then the Alignment of an object of the subtype is at least as |
| 1697 |
strict, unless the object's Alignment is also specified. |
| 1698 |
The Alignment of an object created by an allocator is that of the |
| 1699 |
designated subtype.]} |
| 1700 |
|
| 1701 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00247-01]} |
| 1702 |
@ChgDeleted{Version=[2],NoPrefix=[T],Text=[If an Alignment is specified |
| 1703 |
for a composite subtype or object, this |
| 1704 |
Alignment shall be equal to the least common multiple of any |
| 1705 |
specified Alignments of the subcomponent subtypes, or an integer |
| 1706 |
multiple thereof.]} |
| 1707 |
@end{Description} |
| 1708 |
|
| 1709 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 1710 |
@ChgAdded{Version=[2],Type=[Leading],KeepNext=[T], |
| 1711 |
Text=[For @PrefixType{every subtype S}:]} |
| 1712 |
@begin{Description} |
| 1713 |
@ChgAttribute{Version=[2], Kind=[Added], ChginAnnex=[T], Leading=[F], |
| 1714 |
Prefix=<S>, AttrName=<Alignment>, ARef=[AI95-00291-02], |
| 1715 |
Text=[@Chg{Version=[2],New=[The value of this attribute is of type |
| 1716 |
@i{universal_integer}, and nonnegative.],Old=[]} |
| 1717 |
|
| 1718 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02],ARef=[AI95-00291-02]} |
| 1719 |
@ChgAdded{Version=[2],NoPrefix=[T], Text=[For an object X of subtype S, |
| 1720 |
if S'Alignment is not zero, then X'Alignment is a nonzero integral multiple |
| 1721 |
of S'Alignment unless specified otherwise by a representation item.]}]}@Comment{End S'Alignment} |
| 1722 |
|
| 1723 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 1724 |
@ChgAdded{Version=[2],NoPrefix=[T], Text=[@PDefn2{Term=[specifiable], Sec=(of Alignment for first subtypes)} |
| 1725 |
@Defn{Alignment clause} |
| 1726 |
Alignment may be specified for first subtypes via an |
| 1727 |
@nt{attribute_@!definition_@!clause}; |
| 1728 |
the expression of such a clause shall be static, and its value |
| 1729 |
nonnegative.]} |
| 1730 |
|
| 1731 |
@end{Description} |
| 1732 |
|
| 1733 |
@end{StaticSem} |
| 1734 |
|
| 1735 |
@begin{Erron} |
| 1736 |
@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 1737 |
Program execution is erroneous if an Address clause is given that |
| 1738 |
conflicts with the Alignment. |
| 1739 |
@begin{Ramification} |
| 1740 |
The user has to either give an Alignment clause also, |
| 1741 |
or else know what Alignment the implementation will choose by default. |
| 1742 |
@end{Ramification} |
| 1743 |
|
| 1744 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02],ARef=[AI95-00291-02]} |
| 1745 |
@PDefn2{Term=(erroneous execution),Sec=(cause)} |
| 1746 |
@Chg{Version=[2],New=[For],Old=[If the Alignment is specified for]} an |
| 1747 |
object that is not allocated under control of the implementation, |
| 1748 |
execution is erroneous if the object is not aligned according to |
| 1749 |
@Chg{Version=[2],New=[its],Old=[the]} Alignment. |
| 1750 |
|
| 1751 |
@end{Erron} |
| 1752 |
|
| 1753 |
@begin{ImplAdvice} |
| 1754 |
@PDefn2{Term=[recommended level of support], Sec=(Alignment attribute |
| 1755 |
for subtypes)} |
| 1756 |
@Leading@;The recommended level of support for the Alignment attribute for |
| 1757 |
subtypes is: |
| 1758 |
@begin{Itemize} |
| 1759 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]} |
| 1760 |
An implementation should support @Chg{Version=[2],New=[an Alignment clause |
| 1761 |
for a discrete type, fixed point type, record type, or |
| 1762 |
array type, specifying an Alignment value that is zero or |
| 1763 |
a power of two],Old=[specified Alignments that are factors and multiples of |
| 1764 |
the number of storage elements per word]}, subject to the following: |
| 1765 |
|
| 1766 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]} |
| 1767 |
An implementation need not support |
| 1768 |
@Chg{Version=[2], New=[an Alignment clause for a signed |
| 1769 |
integer type specifying an Alignment greater than the largest |
| 1770 |
Alignment value that is ever chosen by default by the implementation |
| 1771 |
for any signed integer type. A corresponding limitation may be |
| 1772 |
imposed for modular integer types, fixed point types, enumeration types, |
| 1773 |
record types, and array types],Old=[specified Alignments for combinations |
| 1774 |
of Sizes and Alignments that cannot be easily loaded and |
| 1775 |
stored by available machine instructions]}. |
| 1776 |
|
| 1777 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]} |
| 1778 |
An implementation need not support |
| 1779 |
@Chg{Version=[2],New=[a nonconfirming Alignment clause which could enable the |
| 1780 |
creation of an object of an elementary type which cannot be easily loaded and |
| 1781 |
stored by available machine instructions.], |
| 1782 |
Old=[specified Alignments that are greater than the maximum |
| 1783 |
Alignment the implementation ever returns |
| 1784 |
by default.]} |
| 1785 |
|
| 1786 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 1787 |
@ChgAdded{Version=[2],Text=[An implementation need not support an |
| 1788 |
Alignment specified for a derived tagged type which is not a multiple of the |
| 1789 |
Alignment of the parent type. An implementation need not support a |
| 1790 |
nonconfirming Alignment specified for a derived untagged by-reference type.]} |
| 1791 |
@begin{Ramification} |
| 1792 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 1793 |
@ChgAdded{Version=[2],Text=[There is no recommendation to support any |
| 1794 |
nonconfirming Alignment clauses for types not mentioned above. |
| 1795 |
Remember that |
| 1796 |
@RefSecNum{Operational and Representation Items} requires support for |
| 1797 |
confirming Alignment clauses for all types.]} |
| 1798 |
@end{Ramification} |
| 1799 |
@end{Itemize} |
| 1800 |
|
| 1801 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(Alignment attribute |
| 1802 |
for objects)} |
| 1803 |
The recommended level of support for the Alignment attribute for |
| 1804 |
objects is: |
| 1805 |
@begin{Itemize} |
| 1806 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]} |
| 1807 |
@ChgDeleted{Version=[2],Text=[Same as above, for subtypes, but in addition:]} |
| 1808 |
|
| 1809 |
For stand-alone library-level objects of statically constrained |
| 1810 |
subtypes, the implementation should support all Alignments |
| 1811 |
supported by the target linker. For example, page alignment |
| 1812 |
is likely to be supported for such objects, but not for subtypes. |
| 1813 |
|
| 1814 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 1815 |
@ChgAdded{Version=[2],Text=[For other objects, an implementation should at |
| 1816 |
least support the alignments supported for their |
| 1817 |
subtype, subject to the following:]} |
| 1818 |
|
| 1819 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 1820 |
@ChgAdded{Version=[2],Text=[An implementation need not support Alignments |
| 1821 |
specified for objects of a by-reference type or for objects of types containing |
| 1822 |
aliased subcomponents if the specified Alignment is not a multiple of the |
| 1823 |
Alignment of the subtype of the object.]} |
| 1824 |
@end{Itemize} |
| 1825 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 1826 |
Text=[The recommended level of support for the Alignment attribute should be |
| 1827 |
followed.]}]} |
| 1828 |
@end{ImplAdvice} |
| 1829 |
|
| 1830 |
@begin{Notes} |
| 1831 |
Alignment is a subtype-specific attribute. |
| 1832 |
|
| 1833 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00247-01]} |
| 1834 |
@ChgDeleted{Version=[2],Text=[The Alignment of a composite object is always |
| 1835 |
equal to the least common multiple of the Alignments of its components, or a |
| 1836 |
multiple thereof.]} |
| 1837 |
@begin{Discussion} |
| 1838 |
@ChgRef{Version=[2],Kind=[Deleted]} |
| 1839 |
@ChgDeleted{Version=[2],Text=[For default Alignments, this follows from the |
| 1840 |
semantics of Alignment. For specified Alignments, it follows from a |
| 1841 |
@LegalityName stated above.]} |
| 1842 |
@end{Discussion} |
| 1843 |
|
| 1844 |
A @nt{component_clause}, Component_Size clause, or a @nt{pragma} Pack |
| 1845 |
can override a specified Alignment. |
| 1846 |
@begin{Discussion} |
| 1847 |
Most objects are allocated by the implementation; for these, the |
| 1848 |
implementation obeys the Alignment. The implementation is of course |
| 1849 |
allowed to make an object @i{more} aligned than its Alignment requires |
| 1850 |
@em an object whose Alignment is 4 might just happen to land at an |
| 1851 |
address that's a multiple of 4096. |
| 1852 |
For formal parameters, the implementation might |
| 1853 |
want to force an Alignment stricter than the parameter's subtype. |
| 1854 |
For example, on some systems, it is customary to always align |
| 1855 |
parameters to 4 storage elements. |
| 1856 |
|
| 1857 |
Hence, one might initially assume that the implementation could |
| 1858 |
evilly make all Alignments 1 by default, even though integers, say, |
| 1859 |
are normally aligned on a 4-storage-element boundary. However, the |
| 1860 |
implementation cannot get away with that @em if the Alignment is 1, |
| 1861 |
the generated code cannot assume an Alignment of 4, at least not for |
| 1862 |
objects allocated outside the control of the implementation. |
| 1863 |
|
| 1864 |
Of course implementations can assume anything they can prove, but |
| 1865 |
typically an implementation will be unable to prove much about the |
| 1866 |
alignment of, say, an imported object. Furthermore, the information |
| 1867 |
about where an address @lquotes@;came from@rquotes@; can be lost to the compiler due to |
| 1868 |
separate compilation. |
| 1869 |
|
| 1870 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 1871 |
The Alignment of an object that is a component of a packed |
| 1872 |
composite object will usually be 0, to indicate that the component is |
| 1873 |
not necessarily aligned on a storage element boundary. |
| 1874 |
For a subtype, an Alignment of 0 means that objects of the subtype are |
| 1875 |
not normally aligned on a storage element boundary at all. |
| 1876 |
For example, an implementation might choose to make Component_Size be |
| 1877 |
@Chg{Version=[2],New=[1],Old=[0]} |
| 1878 |
for an array of Booleans, even when @nt{pragma} Pack has not been |
| 1879 |
specified for the array. |
| 1880 |
In this case, Boolean'Alignment would be 0. |
| 1881 |
(In the presence of tasking, this would in general be feasible only on a |
| 1882 |
machine that had atomic test-bit and set-bit instructions.) |
| 1883 |
|
| 1884 |
If the machine has no particular natural alignments, then all subtype |
| 1885 |
Alignments will probably be 1 by default. |
| 1886 |
|
| 1887 |
Specifying an Alignment of 0 in an @nt{attribute_definition_clause} does |
| 1888 |
not require the implementation to do anything (except return 0 when the |
| 1889 |
Alignment is queried). |
| 1890 |
However, it might be taken as advice on some implementations. |
| 1891 |
|
| 1892 |
It is an error for an Address clause to disobey the object's Alignment. |
| 1893 |
The error cannot be detected at compile time, in general, because the |
| 1894 |
Address is not necessarily known at compile time (and is almost |
| 1895 |
certainly not static). We do not require a run-time check, since |
| 1896 |
efficiency seems paramount here, and Address clauses are treading on |
| 1897 |
thin ice anyway. Hence, this misuse of Address clauses is just like any |
| 1898 |
other misuse of Address clauses @em it's erroneous. |
| 1899 |
|
| 1900 |
A type extension can have a stricter Alignment than its parent. |
| 1901 |
This can happen, for example, if the Alignment of the parent is 4, |
| 1902 |
but the extension contains a component with Alignment 8. |
| 1903 |
The Alignment of a class-wide type or object will have to be the |
| 1904 |
maximum possible Alignment of any extension. |
| 1905 |
|
| 1906 |
The recommended level of support for the Alignment attribute is |
| 1907 |
intended to reflect a minimum useful set of capabilities. An |
| 1908 |
implementation can assume that all Alignments are multiples of each |
| 1909 |
other @em 1, 2, 4, and 8 might be the only supported Alignments for |
| 1910 |
subtypes. An Alignment of 3 or 6 is unlikely to be useful. |
| 1911 |
For objects that can be allocated statically, we recommend that |
| 1912 |
the implementation support larger alignments, such as 4096. We do |
| 1913 |
not recommend such large alignments for subtypes, because the maximum |
| 1914 |
subtype alignment will also have to be used as the alignment of stack |
| 1915 |
frames, heap objects, and class-wide objects. Similarly, we do not |
| 1916 |
recommend such large alignments for stack-allocated objects. |
| 1917 |
|
| 1918 |
If the maximum default Alignment is 8 |
| 1919 |
(say, Long_Float'Alignment = 8), |
| 1920 |
then the implementation can refuse to accept stricter alignments |
| 1921 |
for subtypes. This simplifies the generated code, since the compiler |
| 1922 |
can align the stack and class-wide types to this maximum without a |
| 1923 |
substantial waste of space (or time). |
| 1924 |
|
| 1925 |
Note that the recommended level of support takes into account |
| 1926 |
interactions between Size and Alignment. For example, on a 32-bit |
| 1927 |
machine with 8-bit storage elements, where load and store |
| 1928 |
instructions have to be aligned according to the size of the thing |
| 1929 |
being loaded or stored, the implementation might accept an Alignment |
| 1930 |
of 1 if the Size is 8, but might reject an Alignment of 1 if the Size |
| 1931 |
is 32. On a machine where unaligned loads and stores are merely |
| 1932 |
inefficient (as opposed to causing hardware traps), |
| 1933 |
we would expect an Alignment of 1 to be supported for any Size. |
| 1934 |
@end{Discussion} |
| 1935 |
@end{Notes} |
| 1936 |
|
| 1937 |
@begin{DiffWord83} |
| 1938 |
The nonnegative part is missing from RM83 |
| 1939 |
(for @nt{mod_clause}s, nee @ntf{alignment_clause}s, |
| 1940 |
which are an obsolete version of Alignment clauses). |
| 1941 |
@end{DiffWord83} |
| 1942 |
|
| 1943 |
@begin{StaticSem} |
| 1944 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 1945 |
@Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a |
| 1946 |
@Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes an object]}: |
| 1947 |
@begin{Description} |
| 1948 |
@Attribute{Prefix=<X>, AttrName=<Size>, |
| 1949 |
Text=<Denotes the size in bits of |
| 1950 |
the representation of the object. |
| 1951 |
The value of this attribute is of the type |
| 1952 |
@i{universal_integer}.>} |
| 1953 |
@EndPrefixType{} |
| 1954 |
@begin{Ramification} |
| 1955 |
Note that Size is in bits even if Machine_Radix is 10. |
| 1956 |
Each decimal digit (and the sign) is presumably represented |
| 1957 |
as some number of bits. |
| 1958 |
@end{Ramification} |
| 1959 |
|
| 1960 |
@NoPrefix@PDefn2{Term=[specifiable], Sec=(of Size for stand-alone objects)} |
| 1961 |
@Defn{Size clause} |
| 1962 |
Size may be specified for @Redundant[stand-alone] objects |
| 1963 |
via an @nt{attribute_definition_clause}; |
| 1964 |
the expression of such a clause shall be static and its value nonnegative. |
| 1965 |
@end{Description} |
| 1966 |
@end{StaticSem} |
| 1967 |
|
| 1968 |
@begin{ImplAdvice} |
| 1969 |
@ChgNote{Moved from 13.9} |
| 1970 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]} |
| 1971 |
@ChgAdded{Version=[2],Text=[The size of an array object should not include |
| 1972 |
its bounds.]} |
| 1973 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 1974 |
Text=[The Size of an array object should not include its bounds.]}]} |
| 1975 |
|
| 1976 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02],ARef=[AI95-00291-02]} |
| 1977 |
@ChgDeleted{Version=[2],Type=[Leading],Text=[]}@Comment{A fake to get a conditional Leading} |
| 1978 |
@PDefn2{Term=[recommended level of support], Sec=(Size attribute)} |
| 1979 |
The recommended level of support for the Size attribute |
| 1980 |
of objects is@Chg{Version=[2],New=[ the same as for subtypes (see below), |
| 1981 |
except that only a confirming Size clause need be supported for an aliased |
| 1982 |
elementary object.],Old=[:]} |
| 1983 |
@begin{Itemize} |
| 1984 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00051-02]} |
| 1985 |
@ChgDeleted{Version=[2],Text=[A Size clause should be supported for an object |
| 1986 |
if the specified Size is at least as large as its subtype's Size, and |
| 1987 |
corresponds to a size in storage elements that is a multiple of the object's |
| 1988 |
Alignment (if the Alignment is nonzero).]} |
| 1989 |
@Comment{No ImplDef summary here; there is no reason to separately mention it} |
| 1990 |
@end{Itemize} |
| 1991 |
@end{ImplAdvice} |
| 1992 |
|
| 1993 |
@begin{StaticSem} |
| 1994 |
@Leading@Keepnext@;For @PrefixType{every subtype S}: |
| 1995 |
@begin{Description} |
| 1996 |
@AttributeLeading{Prefix=<S>, AttrName=<Size>, |
| 1997 |
Text=<If S is definite, |
| 1998 |
denotes the size @Redundant{(in bits)} |
| 1999 |
that the implementation would choose for |
| 2000 |
the following objects of subtype S: |
| 2001 |
@begin{Itemize} |
| 2002 |
A record component of subtype S |
| 2003 |
when the record type is packed. |
| 2004 |
|
| 2005 |
The formal parameter of an instance of Unchecked_Conversion |
| 2006 |
that converts from subtype S to some other subtype. |
| 2007 |
@end{Itemize} |
| 2008 |
|
| 2009 |
@NoPrefix@;If S is indefinite, |
| 2010 |
the meaning is implementation defined. |
| 2011 |
The value of this attribute is of the type |
| 2012 |
@i{universal_integer}.>} |
| 2013 |
@PDefn2{Term=[specifiable], Sec=(of Size for first subtypes)} |
| 2014 |
@Defn{Size clause} |
| 2015 |
The Size of an object is at least as large as that of its subtype, |
| 2016 |
unless the object's Size is determined by a Size clause, |
| 2017 |
a component_clause, or a Component_Size clause. |
| 2018 |
Size may be specified for first subtypes |
| 2019 |
via an @nt{attribute_@!definition_@!clause}; |
| 2020 |
the expression of such a clause shall be static |
| 2021 |
and its value nonnegative. |
| 2022 |
@ImplDef{The meaning of Size for indefinite subtypes.} |
| 2023 |
@begin{Reason} |
| 2024 |
@Leading@;The effects of specifying the Size of a subtype are: |
| 2025 |
@begin{Itemize} |
| 2026 |
Unchecked_Conversion works in a predictable manner. |
| 2027 |
|
| 2028 |
A composite type cannot be packed so tightly as to override |
| 2029 |
the specified Size of a component's subtype. |
| 2030 |
|
| 2031 |
Assuming the @ImplAdviceName is obeyed, |
| 2032 |
if the specified Size allows independent addressability, |
| 2033 |
then the Size of certain objects of the subtype |
| 2034 |
should be equal to the subtype's Size. |
| 2035 |
This applies to stand-alone objects and to components |
| 2036 |
(unless a @nt{component_clause} or a Component_Size clause applies). |
| 2037 |
@end{Itemize} |
| 2038 |
|
| 2039 |
A @nt{component_clause} or a Component_Size clause can cause an object |
| 2040 |
to be smaller than its subtype's specified size. |
| 2041 |
A @nt{pragma} Pack cannot; if a component subtype's size is specified, |
| 2042 |
this limits how tightly the composite object can be packed. |
| 2043 |
|
| 2044 |
The Size of a class-wide (tagged) subtype is unspecified, |
| 2045 |
because it's not clear what it should mean; |
| 2046 |
it should certainly not depend on all of the descendants that happen |
| 2047 |
to exist in a given program. |
| 2048 |
Note that this cannot be detected at compile time, |
| 2049 |
because in a generic unit, it is not necessarily known |
| 2050 |
whether a given subtype is class-wide. |
| 2051 |
It might raise an exception on some implementations. |
| 2052 |
@end{Reason} |
| 2053 |
@begin{Ramification} |
| 2054 |
@Leading@;A Size clause for a numeric subtype need not |
| 2055 |
affect the underlying numeric type. |
| 2056 |
For example, if I say: |
| 2057 |
@begin{Example} |
| 2058 |
@key[type] S @key[is] @key[range] 1..2; |
| 2059 |
@key[for] S'Size @key[use] 64; |
| 2060 |
@end{Example} |
| 2061 |
|
| 2062 |
I am not guaranteed that S'Base'Last >= 2**63@en@;1, |
| 2063 |
nor that intermediate results will be represented in 64 bits. |
| 2064 |
@end{Ramification} |
| 2065 |
@begin{Reason} |
| 2066 |
There is no need to complicate implementations for this sort of |
| 2067 |
thing, because the right way to affect the base range of a type |
| 2068 |
is to use the normal way of declaring the base range: |
| 2069 |
@begin{Example} |
| 2070 |
@key[type] Big @key[is] @key[range] -2**63 .. 2**63 - 1; |
| 2071 |
@key[subtype] Small @key[is] Big @key[range] 1..1000; |
| 2072 |
@end{Example} |
| 2073 |
@end{Reason} |
| 2074 |
@begin{Ramification} |
| 2075 |
The Size of a large unconstrained subtype (e.g. String'Size) |
| 2076 |
is likely to raise Constraint_Error, |
| 2077 |
since it is a nonstatic expression of type @i{universal_integer} |
| 2078 |
that might overflow the largest signed integer type. |
| 2079 |
There is no requirement that the largest integer type be able to |
| 2080 |
represent the size in bits of the largest possible object. |
| 2081 |
@end{Ramification} |
| 2082 |
@end{Description} |
| 2083 |
@EndPrefixType{} |
| 2084 |
@end{StaticSem} |
| 2085 |
|
| 2086 |
@begin{ImplReq} |
| 2087 |
In an implementation, Boolean'Size shall be 1. |
| 2088 |
@end{ImplReq} |
| 2089 |
|
| 2090 |
@begin{ImplAdvice} |
| 2091 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]} |
| 2092 |
@Leading@;If the Size of a subtype @Chg{Version=[2],New=[],Old=[is specified, |
| 2093 |
and ]}allows for efficient independent addressability |
| 2094 |
(see @RefSecNum{Shared Variables}) on the target architecture, |
| 2095 |
then the Size of the following objects of the subtype should equal the |
| 2096 |
Size of the subtype: |
| 2097 |
@begin{Itemize} |
| 2098 |
Aliased objects (including components). |
| 2099 |
|
| 2100 |
Unaliased components, unless the Size of the |
| 2101 |
component is determined by a @nt{component_clause} or Component_Size |
| 2102 |
clause. |
| 2103 |
@end{Itemize} |
| 2104 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 2105 |
Text=[If the Size of a subtype allows for efficient independent |
| 2106 |
addressability, then the Size of most objects of the subtype should |
| 2107 |
equal the Size of the subtype.]}]} |
| 2108 |
@begin{Ramification} |
| 2109 |
Thus, on a typical 32-bit machine, |
| 2110 |
@lquotes@;@key[for] S'Size @key[use] 32;@rquotes@; |
| 2111 |
will guarantee that aliased objects of subtype S, |
| 2112 |
and components whose subtype is S, will have Size |
| 2113 |
= 32 (assuming the implementation chooses to obey this @ImplAdviceTitle). |
| 2114 |
On the other hand, if one writes, |
| 2115 |
@lquotes@;@key[for] S2'Size @key[use] 5;@rquotes@; |
| 2116 |
then stand-alone objects of subtype S2 will typically have their Size |
| 2117 |
rounded up to ensure independent addressability. |
| 2118 |
|
| 2119 |
Note that @lquotes@;@key[for] S'Size @key[use] 32;@rquotes@; |
| 2120 |
does not cause things like formal parameters to have Size = 32 @em |
| 2121 |
the implementation is allowed to make all parameters be at least 64 |
| 2122 |
bits, for example. |
| 2123 |
|
| 2124 |
Note that |
| 2125 |
@lquotes@;@key[for] S2'Size @key[use] 5;@rquotes@; |
| 2126 |
requires record components whose subtype is S2 to be exactly 5 bits |
| 2127 |
if the record type is packed. |
| 2128 |
The same is not true of array components; |
| 2129 |
their Size may be rounded up to the nearest factor of the word size. |
| 2130 |
@end{Ramification} |
| 2131 |
@begin{ImplNote} |
| 2132 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 2133 |
@Defn{gaps} |
| 2134 |
On most machines, arrays don't contain gaps between @Chg{Version=[2], |
| 2135 |
New=[elementary ],Old=[]}components; |
| 2136 |
if the Component_Size is greater than the Size of the component subtype, |
| 2137 |
the extra bits are generally considered part of each component, |
| 2138 |
rather than gaps between components. |
| 2139 |
On the other hand, |
| 2140 |
a record might contain gaps between @Chg{Version=[2], |
| 2141 |
New=[elementary ],Old=[]}components, |
| 2142 |
depending on what sorts of loads, stores, and masking operations |
| 2143 |
are generally done by the generated code. |
| 2144 |
|
| 2145 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]} |
| 2146 |
For an array, |
| 2147 |
any extra bits stored for each @Chg{Version=[2], |
| 2148 |
New=[elementary ],Old=[]}component will generally be part |
| 2149 |
of the component @em the whole point of storing extra bits is to |
| 2150 |
make loads and stores more efficient by avoiding the need to mask out |
| 2151 |
extra bits. |
| 2152 |
The PDP-10 is one counter-example; |
| 2153 |
since the hardware supports byte strings with a gap at the end of |
| 2154 |
each word, |
| 2155 |
one would want to pack in that manner. |
| 2156 |
@end{ImplNote} |
| 2157 |
|
| 2158 |
A Size clause on a composite subtype should not affect |
| 2159 |
the internal layout of components. |
| 2160 |
@ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2], |
| 2161 |
Text=[A Size clause on a composite subtype should not affect |
| 2162 |
the internal layout of components.]}]} |
| 2163 |
@begin{Reason} |
| 2164 |
That's what Pack @nt{pragma}s, @nt{record_representation_clause}s, |
| 2165 |
and Component_Size clauses are for. |
| 2166 |
@end{Reason} |
| 2167 |
|
| 2168 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(Size attribute)} |
| 2169 |
The recommended level of support for the Size attribute |
| 2170 |
of subtypes is: |
| 2171 |
@begin{Itemize} |
| 2172 |
|
| 2173 |
The Size (if not specified) of a static discrete or fixed point subtype |
| 2174 |
should be the number of bits needed to represent each value belonging to |
| 2175 |
the subtype using an unbiased representation, |
| 2176 |
leaving space for a sign bit only if the subtype contains negative |
| 2177 |
values. |
| 2178 |
If such a subtype is a first subtype, |
| 2179 |
then an implementation should support a specified Size for it that |
| 2180 |
reflects this representation. |
| 2181 |
|
| 2182 |
@begin{ImplNote} |
| 2183 |
This applies to static enumeration subtypes, |
| 2184 |
using the internal codes used to represent the values. |
| 2185 |
|
| 2186 |
For a two's-complement machine, this implies that |
| 2187 |
for a static signed integer subtype S, |
| 2188 |
if all values of S are in the range 0 .. 2@+{@i{n}}@en@;1, |
| 2189 |
or all values of S are in the range @en@;2@+{@i{n@en@;1}} .. 2@+{@i{n@en@;1}}@en@;1, |
| 2190 |
for some @i{n} less than or equal to the word size, |
| 2191 |
then S'Size should be <= the smallest such @i{n}. |
| 2192 |
For a one's-complement machine, |
| 2193 |
it is the same except that in the second range, |
| 2194 |
the lower bound @lquotes@;@en@;2@+{@i{n@en@;1}}@rquotes@; is replaced by @lquotes@;@en@;2@+{@i{n@en@;1}}+1@rquotes@;. |
| 2195 |
|
| 2196 |
|
| 2197 |
If an integer subtype (whether signed or unsigned) |
| 2198 |
contains no negative values, the Size should not include space |
| 2199 |
for a sign bit. |
| 2200 |
|
| 2201 |
|
| 2202 |
Typically, the implementation will choose to make the Size of a |
| 2203 |
subtype be exactly the smallest such @i{n}. |
| 2204 |
However, it might, for example, choose a biased representation, |
| 2205 |
in which case it could choose a smaller value. |
| 2206 |
|
| 2207 |
On most machines, it is in general not a good idea to pack (parts of) |
| 2208 |
multiple stand-alone objects into the same storage element, |
| 2209 |
because (1) it usually doesn't save much space, |
| 2210 |
and (2) it requires locking to prevent tasks from interfering with each |
| 2211 |
other, since separate stand-alone objects are independently |
| 2212 |
addressable. |
| 2213 |
Therefore, if S'Size = 2 |
| 2214 |
on a machine with 8-bit storage elements, |
| 2215 |
the size of a stand-alone object of subtype S will probably not be 2. |
| 2216 |
It might, for example, be 8, 16 or 32, depending on the availability |
| 2217 |
and efficiency of various machine instructions. |
| 2218 |
The same applies to components of composite types, |
| 2219 |
unless packing, Component_Size, or record layout is specified. |
| 2220 |
|
| 2221 |
For an unconstrained discriminated object, |
| 2222 |
if the implementation allocates the maximum |
| 2223 |
possible size, |
| 2224 |
then the Size attribute should return that maximum |
| 2225 |
possible size. |
| 2226 |
@end{ImplNote} |
| 2227 |
@begin{Ramification} |
| 2228 |
The Size of an object X is not usually the same as that of |
| 2229 |
its subtype S. |
| 2230 |
If X is a stand-alone object or a parameter, for example, |
| 2231 |
most implementations will round X'Size up to a storage |
| 2232 |
element boundary, or more, so X'Size might be greater than S'Size. |
| 2233 |
On the other hand, |
| 2234 |
X'Size cannot be less than S'Size, even |
| 2235 |
if the implementation can prove, for example, |
| 2236 |
that the range of values actually taken on by X during execution |
| 2237 |
is smaller than the range of S. |
| 2238 |
|
| 2239 |
For example, if S is a first integer subtype whose range |
| 2240 |
is 0..3, S'Size will be probably be 2 bits, and components of |
| 2241 |
packed composite types of this subtype will be 2 bits |
| 2242 |
(assuming Storage_Unit is a multiple of 2), |
| 2243 |
but stand-alone objects and parameters will probably |
| 2244 |
not have a size of 2 bits; they might be rounded up to |
| 2245 |
32 bits, for example. |
| 2246 |
On the other hand, Unchecked_Conversion will use the 2-bit size, |
| 2247 |
even when converting a stand-alone object, |
| 2248 |
as one would expect. |
| 2249 |
|
| 2250 |
Another reason for making the Size of an object bigger than |
| 2251 |
its subtype's Size is to support the run-time detection of |
| 2252 |
uninitialized variables. |
| 2253 |
@PDefn{uninitialized variables} |
| 2254 |
The implementation might add an extra value to a discrete subtype |
| 2255 |
that represents the uninitialized state, |
| 2256 |
and check for this value on use. |
| 2257 |
In some cases, the extra value will require an extra bit in the |
| 2258 |
representation of the object. |
| 2259 |
Such detection is not required by the language. |
| 2260 |
If it is provided, the implementation has to be able to turn it off. |
| 2261 |
For example, if the programmer gives a |
| 2262 |
@nt{record_representation_clause} or Component_Size clause that makes |
| 2263 |
a component too small to allow the extra bit, |
| 2264 |
then the implementation will not be able to perform the checking |
| 2265 |
(not using this method, anyway). |
| 2266 |
|
| 2267 |
@Leading@;The fact that the size of an object is not necessarily the same |
| 2268 |
as its subtype can be confusing: |
| 2269 |
@begin{Example} |
| 2270 |
@key[type] Device_Register @key[is] @key[range] 0..2**8 - 1; |
| 2271 |
@key[for] Device_Register'Size @key[use] 8; --@RI{ Confusing!} |
| 2272 |
My_Device : Device_Register; |
| 2273 |
@key[for] My_Device'Address @key[use] To_Address(16#FF00#); |
| 2274 |
@end{Example} |
| 2275 |
|
| 2276 |
The programmer might think that My_Device'Size is 8, |
| 2277 |
and that My_Device'Address points at an 8-bit location. |
| 2278 |
However, this is not true. |
| 2279 |
In Ada 83 (and in Ada 95), My_Device'Size might well be 32, |
| 2280 |
and My_Device'Address might well point at the high-order 8 bits of |
| 2281 |
the 32-bit object, which are always all zero bits. |
| 2282 |
If My_Device'Address is passed to an assembly language subprogram, |
| 2283 |
based on the programmer's assumption, |
| 2284 |
the program will not work properly. |
| 2285 |
@end{Ramification} |
| 2286 |
@begin{Reason} |
| 2287 |
It is not reasonable to require that an implementation allocate |
| 2288 |
exactly 8 bits to all objects of subtype Device_Register. |
| 2289 |
For example, in many run-time models, stand-alone objects |
| 2290 |
and parameters are always aligned to a word boundary. |
| 2291 |
Such run-time models are generally based on hardware considerations |
| 2292 |
that are beyond the control of the implementer. |
| 2293 |
(It is reasonable to require that an implementation allocate exactly |
| 2294 |
8 bits to all components of subtype Device_Register, if packed.) |
| 2295 |
@end{Reason} |
| 2296 |
@begin{Ramification} |
| 2297 |
@Leading@;The correct way to write the above code is like this: |
| 2298 |
@begin{Example} |
| 2299 |
@key[type] Device_Register @key[is] @key[range] 0..2**8 - 1; |
| 2300 |
My_Device : Device_Register; |
| 2301 |
@key[for] My_Device'Size @key[use] 8; |
| 2302 |
@key[for] My_Device'Address @key[use] To_Address(16#FF00#); |
| 2303 |
@end{Example} |
| 2304 |
|
| 2305 |
If the implementation cannot accept 8-bit stand-alone objects, |
| 2306 |
then this will be illegal. |
| 2307 |
However, on a machine where an 8-bit device register exists, |
| 2308 |
the implementation will probably be able to accept 8-bit stand-alone |
| 2309 |
objects. Therefore, My_Device'Size will be 8, |
| 2310 |
and My_Device'Address will point at those 8 bits, |
| 2311 |
as desired. |
| 2312 |
|
| 2313 |
If an object of subtype Device_Register is passed to a foreign |
| 2314 |
language subprogram, it will be passed according to that subprogram's |
| 2315 |
conventions. Most foreign language implementations have similar |
| 2316 |
run-time model restrictions. |
| 2317 |
For example, when passing to a C function, |
| 2318 |
where the argument is of |
| 2319 |
the C type char* (that is, pointer to char), |
| 2320 |
the C compiler will generally expect a full word value, |
| 2321 |
either on the stack, or in a register. |
| 2322 |
It will @i{not} expect a single byte. |
| 2323 |
Thus, Size clauses for subtypes really have nothing to do with |
| 2324 |
passing parameters to foreign language subprograms. |
| 2325 |
@end{Ramification} |
| 2326 |
|
| 2327 |
For a subtype implemented with levels of indirection, |
| 2328 |
the Size should include the size of the pointers, |
| 2329 |
but not the size of what they point at. |
| 2330 |
@begin{Ramification} |
| 2331 |
For example, if a task object is represented as a pointer to some |
| 2332 |
information (including a task stack), then the size of the object |
| 2333 |
should be the size of the pointer. |
| 2334 |
The Storage_Size, on the other hand, |
| 2335 |
should include the size of the stack. |
| 2336 |
@end{Ramification} |
| 2337 |
|
| 2338 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]} |
| 2339 |
@ChgAdded{Version=[2],Type=[Leading],Text=[An implementation should support a |
| 2340 |
Size clause for a discrete type, fixed point type, record type, or array type, |
| 2341 |
subject to the following:]} |
| 2342 |
@begin{InnerItemize} |
| 2343 |
|
| 2344 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]} |
| 2345 |
@ChgAdded{Version=[2],Text=[An implementation need not support a Size clause |
| 2346 |
for a signed integer type specifying a Size greater than that of the largest |
| 2347 |
signed integer type supported by the implementation in the absence of a size |
| 2348 |
clause (that is, when the size is chosen by default). A corresponding |
| 2349 |
limitation may be imposed for modular integer types, fixed point types, |
| 2350 |
enumeration types, record types, and array types.]} |
| 2351 |
|
| 2352 |
@begin{Discussion} |
| 2353 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-02]} |
| 2354 |
@ChgAdded{Version=[2],Text=[Note that the @lquotes@;corresponding |
| 2355 |
limitation@rquotes for a record or array type implies that an implementation |
| 2356 |
may impose some reasonable maximum size for records and arrays (e.g. 2**32 |
| 2357 |
bits), which is an upper bound (@lquotes@;capacity@rquotes limit) on the |
| 2358 |
size, whether chosen by default or by being specified by the user. The |
| 2359 |
largest size supported for records need not be the same as the largest |
| 2360 |
size supported for arrays.]} |
| 2361 |
@end{Discussion} |
| 2362 |
|
| 2363 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]} |
| 2364 |
@ChgAdded{Version=[2],Text=[A nonconfirming size clause for the first subtype |
| 2365 |
of a derived untagged by-reference type need not be supported.]} |
| 2366 |
@end{InnerItemize} |
| 2367 |
@end{Itemize} |
| 2368 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 2369 |
Text=[The recommended level of support for the Size attribute should be |
| 2370 |
followed.]}]} |
| 2371 |
@begin{Ramification} |
| 2372 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 2373 |
@ChgAdded{Version=[2],Text=[There is no recommendation to support any |
| 2374 |
nonconfirming Size clauses for types not mentioned above. |
| 2375 |
Remember that |
| 2376 |
@RefSecNum{Operational and Representation Items} requires support for |
| 2377 |
confirming Size clauses for all types.]} |
| 2378 |
@end{Ramification} |
| 2379 |
@end{ImplAdvice} |
| 2380 |
|
| 2381 |
@begin{Notes} |
| 2382 |
Size is a subtype-specific attribute. |
| 2383 |
|
| 2384 |
A @nt{component_clause} or Component_Size clause |
| 2385 |
can override a specified Size. |
| 2386 |
A @nt{pragma} Pack cannot. |
| 2387 |
@end{Notes} |
| 2388 |
|
| 2389 |
@begin{Inconsistent83} |
| 2390 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00114-01]} |
| 2391 |
@ChgAdded{Version=[2],Text=[We specify the meaning of Size in much more |
| 2392 |
detail than Ada 83. This is not technically an inconsistency, but it is in |
| 2393 |
practice, as most Ada 83 compilers use a different definition for Size than |
| 2394 |
is required here. This should have been documented more explicitly during |
| 2395 |
the Ada 9X process.]} |
| 2396 |
@end{Inconsistent83} |
| 2397 |
|
| 2398 |
@begin{DiffWord83} |
| 2399 |
The requirement for a nonnegative value in a Size clause |
| 2400 |
was not in RM83, but it's hard to see how it would make sense. |
| 2401 |
For uniformity, we forbid negative sizes, |
| 2402 |
rather than letting implementations define their meaning. |
| 2403 |
@end{DiffWord83} |
| 2404 |
|
| 2405 |
@begin{StaticSem} |
| 2406 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 2407 |
@Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a |
| 2408 |
@Chg{New=[@nt{prefix}],Old=[prefix]} T that denotes a task |
| 2409 |
object @Redundant[(after any implicit dereference)]]}: |
| 2410 |
@begin{Description} |
| 2411 |
@Attribute{Prefix=<T>, AttrName=<Storage_Size>, |
| 2412 |
Text=<Denotes the number of storage elements reserved for |
| 2413 |
the task. |
| 2414 |
The value of this attribute is of the type |
| 2415 |
@i{universal_integer}. |
| 2416 |
The Storage_Size includes the size of the task's stack, |
| 2417 |
if any. The language does not specify whether or |
| 2418 |
not it includes other storage associated with the task |
| 2419 |
(such as the @lquotes@;task control block@rquotes@; used by some |
| 2420 |
implementations.)>} |
| 2421 |
If a @nt{pragma} Storage_Size is given, |
| 2422 |
the value of the Storage_Size attribute is at least |
| 2423 |
the value specified in the @nt{pragma}. |
| 2424 |
@EndPrefixType{} |
| 2425 |
@begin{Ramification} |
| 2426 |
The value of this attribute is never negative, |
| 2427 |
since it is impossible to @lquotes@;reserve@rquotes@; a negative number |
| 2428 |
of storage elements. |
| 2429 |
|
| 2430 |
If the implementation chooses to allocate an initial amount of |
| 2431 |
storage, and then increase this as needed, |
| 2432 |
the Storage_Size cannot include the additional amounts |
| 2433 |
(assuming the allocation of the additional amounts can raise |
| 2434 |
Storage_Error); this is inherent in the meaning of @lquotes@;reserved.@rquotes@; |
| 2435 |
|
| 2436 |
The implementation is allowed to allocate different amounts of |
| 2437 |
storage for different tasks of the same subtype. |
| 2438 |
|
| 2439 |
Storage_Size is also defined for access subtypes |
| 2440 |
@em see @RefSecNum{Storage Management}. |
| 2441 |
@end{Ramification} |
| 2442 |
@end{Description} |
| 2443 |
@end{StaticSem} |
| 2444 |
|
| 2445 |
@begin{Intro} |
| 2446 |
@redundant[@IndexSeeAlso{Term=[Storage_Size clause],See=[pragma Storage_Size]} |
| 2447 |
A @nt{pragma} Storage_Size specifies the amount of storage to be |
| 2448 |
reserved for the execution of a task.] |
| 2449 |
@end{Intro} |
| 2450 |
|
| 2451 |
@begin{Syntax} |
| 2452 |
@begin{SyntaxText} |
| 2453 |
@Leading@;The form of a @nt{pragma} Storage_Size is as follows: |
| 2454 |
@end{SyntaxText} |
| 2455 |
|
| 2456 |
@PragmaSyn`@key{pragma} @prag(Storage_Size)(@Syn2{expression});' |
| 2457 |
|
| 2458 |
@begin{SyntaxText} |
| 2459 |
A @nt{pragma} Storage_Size is allowed only immediately within a |
| 2460 |
@nt{task_definition}. |
| 2461 |
@end{SyntaxText} |
| 2462 |
@end{Syntax} |
| 2463 |
|
| 2464 |
@begin{Resolution} |
| 2465 |
@PDefn2{Term=[expected type], |
| 2466 |
Sec=(Storage_Size pragma argument)} |
| 2467 |
The @nt{expression} of a @nt<pragma> Storage_Size |
| 2468 |
is expected to be of any integer type. |
| 2469 |
@end{Resolution} |
| 2470 |
|
| 2471 |
@begin{RunTime} |
| 2472 |
A @nt<pragma> Storage_Size is elaborated when an object |
| 2473 |
of the type defined by the immediately enclosing @nt<task_definition> |
| 2474 |
is created. |
| 2475 |
@PDefn2{Term=[elaboration],Sec=(Storage_Size pragma)} |
| 2476 |
For the elaboration of a @nt<pragma> Storage_Size, the @nt<expression> |
| 2477 |
is evaluated; the Storage_Size attribute of the newly created task object |
| 2478 |
is at least the value of the @nt<expression>. |
| 2479 |
@begin{Ramification} |
| 2480 |
The implementation is allowed to round up a specified Storage_Size |
| 2481 |
amount. |
| 2482 |
For example, if the implementation always allocates in |
| 2483 |
chunks of 4096 bytes, the number 200 might be rounded |
| 2484 |
up to 4096. Also, if the user specifies a negative |
| 2485 |
number, the implementation has to normalize this to 0, |
| 2486 |
or perhaps to a positive number. |
| 2487 |
@end{Ramification} |
| 2488 |
|
| 2489 |
@IndexCheck{Storage_Check} |
| 2490 |
@Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)} |
| 2491 |
At the point of task object creation, or upon task activation, |
| 2492 |
Storage_Error is raised if there is insufficient free storage to |
| 2493 |
accommodate the requested Storage_Size. |
| 2494 |
@end{RunTime} |
| 2495 |
|
| 2496 |
@begin{StaticSem} |
| 2497 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 2498 |
@Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a |
| 2499 |
@Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes an array subtype or |
| 2500 |
array object @Redundant[(after any implicit dereference)]]}: |
| 2501 |
@begin{Description} |
| 2502 |
@Attribute{Prefix=<X>, AttrName=<Component_Size>, |
| 2503 |
Text=<Denotes the size in bits of |
| 2504 |
components of the type of X. |
| 2505 |
The value of this attribute is of type @i{universal_integer}.>} |
| 2506 |
@EndPrefixType{} |
| 2507 |
|
| 2508 |
@NoPrefix@PDefn2{Term=[specifiable], Sec=(of Component_Size for |
| 2509 |
array types)}@Defn{Component_Size clause} |
| 2510 |
Component_Size may be specified for array types |
| 2511 |
via an @nt{attribute_@!definition_@!clause}; |
| 2512 |
the expression of such a clause shall be static, |
| 2513 |
and its value nonnegative. |
| 2514 |
@begin{ImplNote} |
| 2515 |
The intent is that the value of X'Component_Size is always nonnegative. |
| 2516 |
If the array is stored @lquotes@;backwards@rquotes@; in memory |
| 2517 |
(which might be caused by an implementation-defined pragma), |
| 2518 |
X'Component_Size is still positive. |
| 2519 |
@end{ImplNote} |
| 2520 |
@begin{Ramification} |
| 2521 |
For an array object A, A'Component_Size = A(I)'Size for any index I. |
| 2522 |
@end{Ramification} |
| 2523 |
@end{Description} |
| 2524 |
@end{StaticSem} |
| 2525 |
|
| 2526 |
@begin{ImplAdvice} |
| 2527 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(Component_Size attribute)} |
| 2528 |
The recommended level of support for the Component_Size attribute is: |
| 2529 |
@begin{Itemize} |
| 2530 |
An implementation need not support specified Component_Sizes that |
| 2531 |
are less than the Size of the component subtype. |
| 2532 |
|
| 2533 |
An implementation should support specified Component_Sizes that |
| 2534 |
are factors and multiples of the word size. |
| 2535 |
For such Component_Sizes, the array should contain no gaps between |
| 2536 |
components. |
| 2537 |
For other Component_Sizes (if supported), the array should |
| 2538 |
contain no gaps between components when packing is also specified; |
| 2539 |
the implementation should forbid this combination in cases where it |
| 2540 |
cannot support a no-gaps representation. |
| 2541 |
@begin{Ramification} |
| 2542 |
For example, if Storage_Unit = 8, and Word_Size = 32, |
| 2543 |
then the user is allowed to specify a Component_Size of |
| 2544 |
1, 2, 4, 8, 16, and 32, with no gaps. |
| 2545 |
In addition, @i{n}*32 is allowed for positive integers @i{n}, |
| 2546 |
again with no gaps. |
| 2547 |
If the implementation accepts Component_Size = 3, |
| 2548 |
then it might allocate 10 components per word, |
| 2549 |
with a 2-bit gap at the end of each word |
| 2550 |
(unless packing is also specified), |
| 2551 |
or it might not have any internal gaps at all. |
| 2552 |
(There can be gaps at either end of the array.) |
| 2553 |
@end{Ramification} |
| 2554 |
@end{Itemize} |
| 2555 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 2556 |
Text=[The recommended level of support for the Component_Size attribute should |
| 2557 |
be followed.]}]} |
| 2558 |
@end{ImplAdvice} |
| 2559 |
|
| 2560 |
@begin{StaticSem} |
| 2561 |
|
| 2562 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2563 |
@ChgAdded{Version=[1],Text=[The following operational attribute is defined: External_Tag.]} |
| 2564 |
|
| 2565 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2566 |
@Leading@;For @PrefixType{every subtype S of a tagged type @i(T) |
| 2567 |
(specific or class-wide)}@Chg{New=[],Old=[, the following |
| 2568 |
attribute is defined]}: |
| 2569 |
|
| 2570 |
@begin{Description} |
| 2571 |
@ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F], |
| 2572 |
Prefix=<S>, AttrName=<External_Tag>, Ref=[8652/0040], ARef=[AI95-00108-01], |
| 2573 |
Text=[@Defn{External_Tag clause} |
| 2574 |
@PDefn2{Term=(specifiable), Sec=(of External_Tag for a tagged type)} |
| 2575 |
S'External_Tag denotes an external string representation |
| 2576 |
for S'Tag; it is of the predefined type String. |
| 2577 |
External_Tag may be specified for a specific tagged type |
| 2578 |
via an @nt{attribute_definition_clause}; |
| 2579 |
the expression of such a clause shall be static. |
| 2580 |
The default external tag representation is implementation defined. |
| 2581 |
See @RefSecNum{Dispatching Operations of Tagged Types} and |
| 2582 |
@RefSecNum{Stream-Oriented Attributes}.]} |
| 2583 |
@Chg{New=[The value of External_Tag is never inherited@Redundant[; the |
| 2584 |
default value is always used unless a new value is directly specified |
| 2585 |
for a type].],Old=[]} |
| 2586 |
@ImplDef{The default external representation for a type tag.} |
| 2587 |
@end{Description} |
| 2588 |
@EndPrefixType() |
| 2589 |
@end{StaticSem} |
| 2590 |
|
| 2591 |
@begin{ImplReq} |
| 2592 |
In an implementation, the default external tag for each specific tagged type |
| 2593 |
declared in a partition |
| 2594 |
shall be distinct, so long as the type is declared outside an |
| 2595 |
instance of a generic body. |
| 2596 |
If the compilation unit in which |
| 2597 |
a given tagged type is declared, and all compilation units on which it |
| 2598 |
semantically depends, are the same in two different partitions, |
| 2599 |
then the external tag for the type shall be the same in the |
| 2600 |
two partitions. |
| 2601 |
What it means for a compilation unit to be the same in |
| 2602 |
two different partitions is implementation defined. |
| 2603 |
At a minimum, if the compilation unit is not recompiled |
| 2604 |
between building the two different partitions that include it, the compilation |
| 2605 |
unit is considered the same in the two partitions. |
| 2606 |
@ImplDef{What determines whether a compilation unit is the |
| 2607 |
same in two different partitions.} |
| 2608 |
@begin{Reason} |
| 2609 |
These requirements are important because external tags are used |
| 2610 |
for input/output of class-wide types. These requirements ensure |
| 2611 |
that what is written by one program can be read back by some other |
| 2612 |
program so long as they share the same declaration for the |
| 2613 |
type (and everything it depends on). |
| 2614 |
|
| 2615 |
The user may specify the external tag if (s)he wishes its value |
| 2616 |
to be stable even across changes to the compilation unit |
| 2617 |
in which the type is declared (or changes in some unit on which it |
| 2618 |
depends). |
| 2619 |
|
| 2620 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 2621 |
We use a String rather than a @Chg{Version=[2], |
| 2622 |
New=[Stream_Element_Array],Old=[Storage_Array]} to represent an |
| 2623 |
external tag for portability. |
| 2624 |
@end{Reason} |
| 2625 |
@begin{Ramification} |
| 2626 |
Note that the characters |
| 2627 |
of an external tag need not all be graphic characters. |
| 2628 |
In other words, the external tag can be a sequence of arbitrary |
| 2629 |
8-bit bytes. |
| 2630 |
@end{Ramification} |
| 2631 |
@end{ImplReq} |
| 2632 |
|
| 2633 |
@begin{Notes} |
| 2634 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00270-01]} |
| 2635 |
The following language-defined attributes are specifiable, |
| 2636 |
at least for some of the kinds of entities to which they apply: |
| 2637 |
Address, |
| 2638 |
@Chg{Version=[2],New=[],Old=[Size, Component_Size, ]}Alignment, |
| 2639 |
@Chg{Version=[2],New=[Bit_Order, Component_Size, ],Old=[]} |
| 2640 |
External_Tag, |
| 2641 |
@Chg{Version=[2],New=[Input, Machine_Radix, Output, Read, Size, ],Old=[]} |
| 2642 |
Small, @Chg{Version=[2],New=[],Old=[Bit_Order, ]} |
| 2643 |
Storage_Pool, Storage_Size, |
| 2644 |
@Chg{Version=[2],New=[Stream_Size, and ],Old=[]} |
| 2645 |
Write@Chg{Version=[2],New=[],Old=[, Output, Read, |
| 2646 |
Input, and Machine_Radix]}. |
| 2647 |
|
| 2648 |
It follows from the general rules in @RefSecNum{Operational and Representation Items} |
| 2649 |
that if one writes @lquotes@;@key[for] X'Size @key[use] Y;@rquotes@; then |
| 2650 |
the X'Size @nt{attribute_reference} will return Y |
| 2651 |
(assuming the implementation allows the Size clause). |
| 2652 |
The same is true for all of the specifiable attributes except Storage_Size. |
| 2653 |
@begin{Ramification} |
| 2654 |
An implementation may specify that an implementation-defined attribute is |
| 2655 |
specifiable for certain entities. |
| 2656 |
This follows from the fact that the semantics of |
| 2657 |
implementation-defined attributes is implementation defined. |
| 2658 |
An implementation is not allowed to make a language-defined attribute |
| 2659 |
specifiable if it isn't. |
| 2660 |
@end{Ramification} |
| 2661 |
@end{Notes} |
| 2662 |
|
| 2663 |
@begin{Examples} |
| 2664 |
@leading@keepnext@i{Examples of attribute definition clauses:} |
| 2665 |
@begin{Example} |
| 2666 |
Byte : @key[constant] := 8; |
| 2667 |
Page : @key[constant] := 2**12; |
| 2668 |
|
| 2669 |
@key[type] Medium @key[is] @key[range] 0 .. 65_000; |
| 2670 |
@key[for] Medium'Size @key[use] 2*Byte; |
| 2671 |
@key[for] Medium'Alignment @key[use] 2; |
| 2672 |
Device_Register : Medium; |
| 2673 |
@key[for] Device_Register'Size @key[use] Medium'Size; |
| 2674 |
@key[for] Device_Register'Address @key[use] System.Storage_Elements.To_Address(16#FFFF_0020#); |
| 2675 |
|
| 2676 |
@key[type] Short @key[is] @key[delta] 0.01 @key[range] -100.0 .. 100.0; |
| 2677 |
@key[for] Short'Size @key[use] 15; |
| 2678 |
|
| 2679 |
@key[for] Car_Name'Storage_Size @key[use] --@RI{ specify access type's storage pool size} |
| 2680 |
2000*((Car'Size/System.Storage_Unit) +1); --@RI{ approximately 2000 cars} |
| 2681 |
|
| 2682 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]} |
| 2683 |
@key[function] @Chg{Version=[2],New=[My_Input],Old=[My_Read]}(Stream : @key[@Chg{Version=[2],New=[not null ],Old=[]}access] Ada.Streams.Root_Stream_Type'Class) |
| 2684 |
@key[return] T; |
| 2685 |
@key(for) T'@Chg{Version=[2],New=[Input],Old=[Read]} @key(use) @Chg{Version=[2],New=[My_Input],Old=[My_Read]}; --@RI{ see @RefSecNum{Stream-Oriented Attributes}} |
| 2686 |
@end{Example} |
| 2687 |
@end{Examples} |
| 2688 |
|
| 2689 |
@begin{Notes} |
| 2690 |
@i{Notes on the examples:} |
| 2691 |
In the Size clause for Short, |
| 2692 |
fifteen bits is the minimum necessary, |
| 2693 |
since the type definition requires Short'Small <= 2**(@en@;7). |
| 2694 |
@end{Notes} |
| 2695 |
|
| 2696 |
@begin{Extend83} |
| 2697 |
@Defn{extensions to Ada 83} |
| 2698 |
The syntax rule for @ntf{length_clause} is replaced with the new syntax rule |
| 2699 |
for @nt{attribute_definition_clause}, and it is modified to allow a |
| 2700 |
@nt{name} (as well as an expression). |
| 2701 |
@end{Extend83} |
| 2702 |
|
| 2703 |
@begin{DiffWord83} |
| 2704 |
The syntax rule for @nt{attribute_definition_clause} now requires that the |
| 2705 |
prefix of the attribute be a @nt{local_name}; |
| 2706 |
in Ada 83 this rule was stated in the text. |
| 2707 |
|
| 2708 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 2709 |
In Ada 83, the relationship between a @Chg{Version=[2],New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]} |
| 2710 |
specifying a certain aspect and an attribute that queried that |
| 2711 |
aspect was unclear. |
| 2712 |
In Ada 95, they are the same, |
| 2713 |
except for certain explicit exceptions. |
| 2714 |
@end{DiffWord83} |
| 2715 |
|
| 2716 |
@begin{DiffWord95} |
| 2717 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2718 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify for |
| 2719 |
each attribute whether it is an operational or representation attribute.]} |
| 2720 |
|
| 2721 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]} |
| 2722 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that |
| 2723 |
External_Tag is never inherited.]} |
| 2724 |
|
| 2725 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-01],ARef=[AI95-00291-01]} |
| 2726 |
@ChgAdded{Version=[2],Text=[Adjusted the Recommended Level of Support for |
| 2727 |
Alignment to eliminate nonsense requirements and to ensure that useful |
| 2728 |
capabilities are required.]} |
| 2729 |
|
| 2730 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-01],ARef=[AI95-00291-01]} |
| 2731 |
@ChgAdded{Version=[2],Text=[Adjusted the Recommended Level of Support for |
| 2732 |
Size to eliminate nonsense requirements and to ensure that useful |
| 2733 |
capabilities are required. Also eliminated any dependence on whether an |
| 2734 |
aspect was specified (a confirming representation item should not affect the |
| 2735 |
semantics).]} |
| 2736 |
|
| 2737 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]} |
| 2738 |
@ChgAdded{Version=[2],Text=[Added the definition of machine scalar.]} |
| 2739 |
|
| 2740 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00247-01]} |
| 2741 |
@ChgAdded{Version=[2],Text=[Removed the requirement that specified |
| 2742 |
alignments for a composite type cannot override those for their components, |
| 2743 |
because it was never intended to apply to components whose location was |
| 2744 |
specified with a representation item. Moreover, it causes a difference in |
| 2745 |
legality when a confirming alignment is specified for one of the composite |
| 2746 |
types.]} |
| 2747 |
|
| 2748 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 2749 |
@ChgAdded{Version=[2],Text=[Removed recommended level of support rules about |
| 2750 |
types with by-reference and aliased parts, because there are now blanket |
| 2751 |
rules covering all recommended level of support rules.]} |
| 2752 |
|
| 2753 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]} |
| 2754 |
@ChgAdded{Version=[2],Text=[Split the definition of Alignment for subtypes |
| 2755 |
and for objects. This simplified the wording and eliminated confusion about |
| 2756 |
which rules applied to objects, which applied to subtypes, and which applied |
| 2757 |
to both.]} |
| 2758 |
@end{DiffWord95} |
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
@LabeledClause{Enumeration Representation Clauses} |
| 2763 |
|
| 2764 |
@begin{Intro} |
| 2765 |
@redundant[An @nt{enumeration_representation_clause} specifies the internal |
| 2766 |
codes for enumeration literals.] |
| 2767 |
@end{Intro} |
| 2768 |
|
| 2769 |
@begin{Syntax} |
| 2770 |
@Syn{lhs=<enumeration_representation_clause>,rhs=" |
| 2771 |
@key{for} @SynI{first_subtype_}@Syn2{local_name} @key{use} @Syn2{enumeration_aggregate};"} |
| 2772 |
@Syn{lhs=<enumeration_aggregate>,rhs="@Syn2{array_aggregate}"} |
| 2773 |
@end{Syntax} |
| 2774 |
|
| 2775 |
@begin{Resolution} |
| 2776 |
@PDefn2{Term=[expected type], |
| 2777 |
Sec=(enumeration_representation_clause expressions)} |
| 2778 |
The @nt<enumeration_aggregate> shall be written as a one-dimensional |
| 2779 |
@nt<array_aggregate>, for which the index subtype is the unconstrained |
| 2780 |
subtype of the enumeration type, and each component expression |
| 2781 |
is expected to be of any integer type. |
| 2782 |
@begin{Ramification} |
| 2783 |
The @lquotes@;full coverage rules@rquotes@; for @nt<aggregate>s applies. |
| 2784 |
An @key{others} is not allowed @em there is no applicable index |
| 2785 |
constraint in this context. |
| 2786 |
@end{Ramification} |
| 2787 |
@end{Resolution} |
| 2788 |
|
| 2789 |
@begin{Legality} |
| 2790 |
The @SynI{first_subtype_}@nt{local_name} of an |
| 2791 |
@nt{enumeration_representation_clause} shall denote an |
| 2792 |
enumeration subtype. |
| 2793 |
@begin{Ramification} |
| 2794 |
As for all type-related representation items, |
| 2795 |
the @nt{local_name} is required to denote a first subtype. |
| 2796 |
@end{Ramification} |
| 2797 |
|
| 2798 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 2799 |
@Chg{Version=[2],New=[Each component of the @nt{array_aggregate} shall be |
| 2800 |
given by an @nt{expression} rather than a <>. ],Old=[]}The |
| 2801 |
@Chg{Version=[2],New=[@nt{expression}s],Old=[expressions]} given in the |
| 2802 |
@nt{array_aggregate} shall be static, |
| 2803 |
and shall specify distinct integer codes for each value |
| 2804 |
of the enumeration type; the associated integer codes shall |
| 2805 |
satisfy the predefined ordering relation of the type. |
| 2806 |
@begin{Reason} |
| 2807 |
Each value of the enumeration type has to be given an internal code, |
| 2808 |
even if the first subtype of the enumeration type is constrained |
| 2809 |
to only a subrange (this is only possible if the enumeration type |
| 2810 |
is a derived type). This @lquotes@;full coverage@rquotes@; requirement |
| 2811 |
is important because one may refer to Enum'Base'First and Enum'Base'Last, |
| 2812 |
which need to have defined representations. |
| 2813 |
@end{Reason} |
| 2814 |
@end{Legality} |
| 2815 |
|
| 2816 |
@begin{StaticSem} |
| 2817 |
@PDefn2{Term=[aspect of representation], Sec=(coding)} |
| 2818 |
@Defn2{Term=[coding], Sec=(aspect of representation)} |
| 2819 |
An @nt{enumeration_representation_clause} specifies the |
| 2820 |
@i{coding} aspect of representation. |
| 2821 |
@Defn{internal code} |
| 2822 |
The coding consists of the @i{internal code} for each enumeration |
| 2823 |
literal, that is, the integral value used internally to |
| 2824 |
represent each literal. |
| 2825 |
|
| 2826 |
@end{StaticSem} |
| 2827 |
|
| 2828 |
@begin{ImplReq} |
| 2829 |
For nonboolean enumeration types, |
| 2830 |
if the coding is not specified for the type, then |
| 2831 |
for each value of the type, the internal code shall be equal to |
| 2832 |
its position number. |
| 2833 |
@begin{Reason} |
| 2834 |
This default representation is already used by all known |
| 2835 |
Ada compilers for nonboolean enumeration types. Therefore, |
| 2836 |
we make it a requirement so users can depend on it, rather |
| 2837 |
than feeling obliged to supply for every enumeration type |
| 2838 |
an enumeration representation clause that is equivalent |
| 2839 |
to this default rule. |
| 2840 |
@end{Reason} |
| 2841 |
@begin{Discussion} |
| 2842 |
For boolean types, it is relatively common to use all ones for |
| 2843 |
True, and all zeros for False, since some hardware supports |
| 2844 |
that directly. Of course, for a one-bit Boolean object |
| 2845 |
(like in a packed array), False is presumably zero and True |
| 2846 |
is presumably one (choosing the reverse would be extremely |
| 2847 |
unfriendly!). |
| 2848 |
@end{Discussion} |
| 2849 |
@end{ImplReq} |
| 2850 |
|
| 2851 |
@begin{ImplAdvice} |
| 2852 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(@nt{enumeration_representation_clause})} |
| 2853 |
The recommended level of support for @nt{enumeration_representation_clause}s is: |
| 2854 |
@begin{Itemize} |
| 2855 |
An implementation should support at least the internal codes in the |
| 2856 |
range System.Min_Int..System.Max_Int. An implementation need not support |
| 2857 |
@nt{enumeration_@!representation_@!clause}s for boolean types. |
| 2858 |
@begin{Ramification} |
| 2859 |
The implementation may support numbers outside the above |
| 2860 |
range, such as numbers greater than System.Max_Int. |
| 2861 |
See AI83-00564. |
| 2862 |
@end{Ramification} |
| 2863 |
@begin{Reason} |
| 2864 |
The benefits of specifying the internal coding of a boolean type do |
| 2865 |
not outweigh the implementation costs. |
| 2866 |
Consider, for example, the implementation of the logical operators on |
| 2867 |
a packed array of booleans with strange internal codes. |
| 2868 |
It's implementable, but not worth it. |
| 2869 |
@end{Reason} |
| 2870 |
@end{Itemize} |
| 2871 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 2872 |
Text=[The recommended level of support for |
| 2873 |
@nt{enumeration_representation_clause}s should be followed.]}]} |
| 2874 |
@end{ImplAdvice} |
| 2875 |
|
| 2876 |
@begin{Notes} |
| 2877 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2878 |
Unchecked_Conversion may be used to query the internal codes used |
| 2879 |
for an enumeration type. |
| 2880 |
The attributes of the type, such as Succ, Pred, and Pos, |
| 2881 |
are unaffected by the @Chg{New=[@nt{enumeration_representation_clause}],Old=[@nt{representation_clause}]}. |
| 2882 |
For example, Pos always returns the position number, @i{not} the |
| 2883 |
internal integer code that might have been specified in |
| 2884 |
@Chg{New=[an @nt{enumeration_representation_clause}], |
| 2885 |
Old=[a @nt{representation_clause}]}}. |
| 2886 |
@begin{Discussion} |
| 2887 |
@Leading@;Suppose the enumeration type in question is derived: |
| 2888 |
@begin{Example} |
| 2889 |
@key[type] T1 @key[is] (Red, Green, Blue); |
| 2890 |
@key[subtype] S1 @key[is] T1 @key[range] Red .. Green; |
| 2891 |
@key[type] S2 @key[is] @key[new] S1; |
| 2892 |
@key[for] S2 @key[use] (Red => 10, Green => 20, Blue => 30); |
| 2893 |
@end{Example} |
| 2894 |
|
| 2895 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2896 |
@Leading@;The @Chg{New=[@nt{enumeration_representation_clause}],Old=[@nt{representation_clause}]} |
| 2897 |
has to specify values for all enumerals, even ones that are not in S2 (such as |
| 2898 |
Blue). The Base attribute can be used to get at these values. |
| 2899 |
For example: |
| 2900 |
@begin{Example} |
| 2901 |
@key[for] I @key[in] S2'Base @key[loop] |
| 2902 |
... --@RI{ When I equals Blue, the internal code is 30.} |
| 2903 |
@key[end] @key[loop]; |
| 2904 |
@end{Example} |
| 2905 |
|
| 2906 |
We considered allowing or requiring |
| 2907 |
@lquotes@;@key[for] S2'Base @key[use] ...@rquotes@; in cases like this, |
| 2908 |
but it didn't seem worth the trouble. |
| 2909 |
@end{Discussion} |
| 2910 |
@end{Notes} |
| 2911 |
|
| 2912 |
@begin{Examples} |
| 2913 |
@leading@keepnext@i{Example of an enumeration representation clause:} |
| 2914 |
@begin{Example} |
| 2915 |
@key[type] Mix_Code @key[is] (ADD, SUB, MUL, LDA, STA, STZ); |
| 2916 |
|
| 2917 |
@key[for] Mix_Code @key[use] |
| 2918 |
(ADD => 1, SUB => 2, MUL => 3, LDA => 8, STA => 24, STZ =>33); |
| 2919 |
@end{Example} |
| 2920 |
@end{Examples} |
| 2921 |
|
| 2922 |
@begin{Extend83} |
| 2923 |
@Defn{extensions to Ada 83} |
| 2924 |
As in other similar contexts, Ada 95 allows expressions of any integer type, |
| 2925 |
not just expressions of type @i{universal_integer}, for the component |
| 2926 |
expressions in the @nt<enumeration_aggregate>. The preference rules |
| 2927 |
for the predefined operators of @i{root_integer} eliminate |
| 2928 |
any ambiguity. |
| 2929 |
|
| 2930 |
For portability, we now require that the default coding for an enumeration |
| 2931 |
type be the @lquotes@;obvious@rquotes@; coding using position numbers. |
| 2932 |
This is satisfied by all known implementations. |
| 2933 |
@end{Extend83} |
| 2934 |
|
| 2935 |
@begin{DiffWord95} |
| 2936 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 2937 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Updated to reflect that we |
| 2938 |
no longer have something called @ntf{representation_clause}.]} |
| 2939 |
|
| 2940 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 2941 |
@ChgAdded{Version=[2],Text=[Added wording to prevent the use of <> in a |
| 2942 |
@nt{enumeration_representation_clause}. (<> is newly added to |
| 2943 |
@nt{array_aggregate}s.)]} |
| 2944 |
@end{DiffWord95} |
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
@LabeledClause{Record Layout} |
| 2949 |
|
| 2950 |
@begin{Intro} |
| 2951 |
@PDefn2{Term=[aspect of representation], Sec=(layout)} |
| 2952 |
@Defn2{Term=[layout], Sec=(aspect of representation)} |
| 2953 |
@PDefn2{Term=[aspect of representation], Sec=(record layout)} |
| 2954 |
@Defn2{Term=[record layout], Sec=(aspect of representation)} |
| 2955 |
@PDefn2{Term=[aspect of representation], Sec=(storage place)} |
| 2956 |
@Defn2{Term=[storage place], Sec=(of a component)} |
| 2957 |
The @i{(record) layout} aspect of representation |
| 2958 |
consists of the @i{storage places} for some or all components, |
| 2959 |
that is, storage place attributes of the components. |
| 2960 |
The layout can be specified with a @nt{record_@!representation_@!clause}. |
| 2961 |
@end{Intro} |
| 2962 |
|
| 2963 |
|
| 2964 |
@LabeledSubClause{Record Representation Clauses} |
| 2965 |
|
| 2966 |
@begin{Intro} |
| 2967 |
@redundant[A @nt{record_representation_clause} specifies the storage representation |
| 2968 |
of records and record extensions, that is, the order, position, and size |
| 2969 |
of components (including discriminants, if any). |
| 2970 |
@IndexSee{Term=[bit field],See=(record_representation_clause)}] |
| 2971 |
@end{Intro} |
| 2972 |
|
| 2973 |
@begin{MetaRules} |
| 2974 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 2975 |
It should be feasible for an implementation to use negative offsets |
| 2976 |
in the representation of composite types. |
| 2977 |
However, no implementation should be forced to support negative |
| 2978 |
offsets. |
| 2979 |
Therefore@Chg{Version=[2],New=[, in the interest of uniformity],Old=[]}, |
| 2980 |
negative offsets should be disallowed in |
| 2981 |
@nt{record_representation_clause}s. |
| 2982 |
@end{MetaRules} |
| 2983 |
|
| 2984 |
@begin{Syntax} |
| 2985 |
@Syn{lhs=<record_representation_clause>,rhs=" |
| 2986 |
@key{for} @SynI{first_subtype_}@Syn2{local_name} @key{use} |
| 2987 |
@key{record} [@Syn2{mod_clause}] |
| 2988 |
{@Syn2{component_clause}} |
| 2989 |
@key{end} @key{record};"} |
| 2990 |
|
| 2991 |
|
| 2992 |
@Syn{lhs=<component_clause>,rhs=" |
| 2993 |
@SynI{component_}@Syn2{local_name} @key{at} @Syn2{position} @key{range} @Syn2{first_bit} .. @Syn2{last_bit};"} |
| 2994 |
|
| 2995 |
@Syn{lhs=<position>,rhs="@SynI{static_}@Syn2{expression}"} |
| 2996 |
@Syn{lhs=<first_bit>,rhs="@SynI{static_}@Syn2{simple_expression}"} |
| 2997 |
@Syn{lhs=<last_bit>,rhs="@SynI{static_}@Syn2{simple_expression}"} |
| 2998 |
@begin{Reason} |
| 2999 |
@nt{First_bit} and @nt{last_bit} need to be @nt{simple_expression} |
| 3000 |
instead of @nt{expression} for the same reason as in @nt{range} |
| 3001 |
(see @RefSec{Scalar Types}). |
| 3002 |
@end{Reason} |
| 3003 |
@end{Syntax} |
| 3004 |
|
| 3005 |
@begin{Resolution} |
| 3006 |
@PDefn2{Term=[expected type], |
| 3007 |
Sec=(component_clause expressions)} |
| 3008 |
@PDefn2{Term=[expected type], |
| 3009 |
Sec=(position)} |
| 3010 |
@PDefn2{Term=[expected type], |
| 3011 |
Sec=(first_bit)} |
| 3012 |
@PDefn2{Term=[expected type], |
| 3013 |
Sec=(last_bit)} |
| 3014 |
Each @nt{position}, @nt{first_bit}, and @nt{last_bit} is expected to |
| 3015 |
be of any integer type. |
| 3016 |
@begin{Ramification} |
| 3017 |
These need not have the same integer type. |
| 3018 |
@end{Ramification} |
| 3019 |
@end{Resolution} |
| 3020 |
|
| 3021 |
@begin{Legality} |
| 3022 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00436-01]} |
| 3023 |
The @SynI{first_subtype_}@nt{local_name} of a |
| 3024 |
@nt{record_representation_clause} shall denote a specific |
| 3025 |
@Chg{Version=[2],New=[],Old=[nonlimited ]}record or record extension subtype. |
| 3026 |
@begin{Ramification} |
| 3027 |
As for all type-related representation items, |
| 3028 |
the @nt{local_name} is required to denote a first subtype. |
| 3029 |
@end{Ramification} |
| 3030 |
|
| 3031 |
If the @i{component_}@nt<local_name> is a @nt<direct_name>, |
| 3032 |
the @nt{local_name} shall denote a component of the type. |
| 3033 |
For a record extension, the component shall not be inherited, |
| 3034 |
and shall not be a discriminant that corresponds to a discriminant of |
| 3035 |
the parent type. |
| 3036 |
If the @i{component_}@!@nt<local_@!name> has an @nt{attribute_@!designator}, |
| 3037 |
the @nt{direct_@!name} of the @nt<local_@!name> shall denote either |
| 3038 |
the declaration of the type or a component of the type, |
| 3039 |
and the @nt{attribute_@!designator} shall denote an |
| 3040 |
implementation-defined implicit component of the type. |
| 3041 |
|
| 3042 |
The @nt{position}, @nt{first_bit}, and @nt{last_bit} shall be |
| 3043 |
static expressions. |
| 3044 |
The value of @nt{position} and @nt{first_bit} shall be nonnegative. |
| 3045 |
The value of @nt{last_bit} shall be no less than |
| 3046 |
@nt{first_bit} @en 1. |
| 3047 |
@begin{Ramification} |
| 3048 |
A @nt{component_clause} such as |
| 3049 |
@lquotes@;X @key{at} 4 @key{range} 0..@en@;1;@rquotes@; |
| 3050 |
is allowed if X can fit in zero bits. |
| 3051 |
@end{Ramification} |
| 3052 |
|
| 3053 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]} |
| 3054 |
@ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[If the |
| 3055 |
nondefault bit ordering applies to the type, then either:]} |
| 3056 |
@begin{Itemize} |
| 3057 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3058 |
@ChgAdded{Version=[2],Text=[the value of @nt{last_bit} shall be |
| 3059 |
less than the size of the largest machine scalar; or]} |
| 3060 |
|
| 3061 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3062 |
@ChgAdded{Version=[2],Text=[the value of @nt{first_bit} shall be zero and the |
| 3063 |
value of @nt{last_bit} + 1 shall be a multiple of System.Storage_Unit.]} |
| 3064 |
@end{Itemize} |
| 3065 |
|
| 3066 |
At most one @nt{component_clause} is allowed for each component of |
| 3067 |
the type, including for each discriminant |
| 3068 |
(@nt{component_clause}s may be given for some, all, or none of the |
| 3069 |
components). |
| 3070 |
Storage places within a @nt{component_list} shall not overlap, |
| 3071 |
unless they are for components in distinct @nt{variant}s of the same |
| 3072 |
@nt{variant_part}. |
| 3073 |
|
| 3074 |
A name that denotes a component of a type is not allowed within |
| 3075 |
a @nt{record_representation_clause} for the type, |
| 3076 |
except as the @SynI{component_}@nt<local_name> |
| 3077 |
of a @nt{component_clause}. |
| 3078 |
@begin{Reason} |
| 3079 |
@Leading@;It might seem strange to make the |
| 3080 |
@nt{record_representation_clause} part of the declarative region, |
| 3081 |
and then disallow mentions of the components within almost all of |
| 3082 |
the @nt{record_representation_clause}. |
| 3083 |
The alternative would be to treat the |
| 3084 |
@SynI{component_}@nt<local_name> like a formal parameter name in |
| 3085 |
a subprogram call (in terms of visibility). |
| 3086 |
However, this rule would imply slightly different semantics, |
| 3087 |
because (given the actual rule) |
| 3088 |
the components can hide other declarations. |
| 3089 |
This was the rule in Ada 83, and we see no reason to change it. |
| 3090 |
The following, for example, was and is illegal: |
| 3091 |
@begin{Example} |
| 3092 |
@key[type] T @key[is] |
| 3093 |
@key[record] |
| 3094 |
X : Integer; |
| 3095 |
@key[end] @key[record]; |
| 3096 |
X : @key[constant] := 31; --@RI{ Same defining name as the component.} |
| 3097 |
@key[for] T @key[use] |
| 3098 |
@key[record] |
| 3099 |
X @key[at] 0 @key[range] 0..X; --@RI{ Illegal!} |
| 3100 |
@key[end] @key[record]; |
| 3101 |
@end{Example} |
| 3102 |
|
| 3103 |
The component X hides the named number X throughout |
| 3104 |
the @nt{record_representation_clause}. |
| 3105 |
@end{Reason} |
| 3106 |
@end{Legality} |
| 3107 |
|
| 3108 |
@begin{StaticSem} |
| 3109 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]} |
| 3110 |
A @nt{record_representation_clause} |
| 3111 |
(without the @nt{mod_clause}) |
| 3112 |
specifies the layout.@Chg{Version=[2],New=[],Old=[ |
| 3113 |
The storage place |
| 3114 |
attributes (see @RefSecNum{Storage Place Attributes}) |
| 3115 |
are taken from the |
| 3116 |
values of the @nt{position}, @nt{first_bit}, |
| 3117 |
and @nt{last_bit} expressions |
| 3118 |
after normalizing those values so that |
| 3119 |
@nt{first_bit} is less than Storage_Unit.]} |
| 3120 |
|
| 3121 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]} |
| 3122 |
@ChgAdded{Version=[2],Text=[If the default bit ordering applies to the type, |
| 3123 |
the @nt{position}, @nt{first_bit}, and @nt{last_bit} of each |
| 3124 |
@nt{component_clause} directly specify |
| 3125 |
the position and size of the corresponding component.]} |
| 3126 |
|
| 3127 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]} |
| 3128 |
@ChgAdded{Version=[2],Type=[Leading],Text=[If the nondefault bit ordering |
| 3129 |
applies to the type then the layout is determined as follows:]} |
| 3130 |
@begin{Itemize} |
| 3131 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3132 |
@ChgAdded{Version=[2],Text=[the @nt{component_clause}s for which the value of |
| 3133 |
@nt{last_bit} is greater than or equal to the size of the largest machine scalar |
| 3134 |
directly specify the position and size of the corresponding component;]} |
| 3135 |
|
| 3136 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3137 |
@ChgAdded{Version=[2],Text=[for other @nt{component_clause}s, all of the |
| 3138 |
components having the same value of @nt{position} are considered to be part of |
| 3139 |
a single machine scalar, located at that @nt{position}; this machine scalar |
| 3140 |
has a size which is the smallest machine scalar size larger than the largest |
| 3141 |
@nt{last_bit} for all @nt{component_clause}s at that @nt{position}; the |
| 3142 |
@nt{first_bit} and @nt{last_bit} of each @nt{component_clause} are then |
| 3143 |
interpreted as bit offsets in this machine scalar.]} |
| 3144 |
@end{Itemize} |
| 3145 |
|
| 3146 |
@begin{Ramification} |
| 3147 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00133-01]} |
| 3148 |
@ChgNote{We want the header title to remain, so we use @Chg instead if @ChgDeleted.} |
| 3149 |
@Chg{Version=[2],New=[],Old=[For example, |
| 3150 |
if Storage_Unit is 8, then |
| 3151 |
@lquotes@;C @key[at] 0 @key[range] 24..31;@rquotes@; |
| 3152 |
defines C'Position = 3, C'First_Bit = 0, and C'Last_Bit = 7. |
| 3153 |
This is true of machines with either bit ordering.]} |
| 3154 |
|
| 3155 |
A @nt{component_clause} also determines the value of the Size |
| 3156 |
attribute of the component, |
| 3157 |
since this attribute is related to First_Bit and Last_Bit. |
| 3158 |
@end{Ramification} |
| 3159 |
|
| 3160 |
@Redundant[A @nt{record_representation_clause} for a record extension |
| 3161 |
does not override the layout of the parent part;] |
| 3162 |
if the layout was specified for the parent type, |
| 3163 |
it is inherited by the record extension. |
| 3164 |
@end{StaticSem} |
| 3165 |
|
| 3166 |
@begin{ImplPerm} |
| 3167 |
An implementation may generate implementation-defined components (for |
| 3168 |
example, one containing the offset of another component). |
| 3169 |
An implementation may generate names that denote |
| 3170 |
such implementation-defined components; |
| 3171 |
such names shall be implementation-defined @nt{attribute_reference}s. |
| 3172 |
An implemen@!tation may allow such implementation-defined names to be |
| 3173 |
used in @nt{record_@!representation_@!clause}s. |
| 3174 |
An implementation can restrict such @nt{component_@!clause}s in any |
| 3175 |
manner it sees fit. |
| 3176 |
@ImplDef{Implementation-defined components.} |
| 3177 |
@begin{Ramification} |
| 3178 |
Of course, since the semantics of implementation-defined |
| 3179 |
attributes is implementation defined, the implementation need not |
| 3180 |
support these names in all situations. |
| 3181 |
They might be purely for the purpose of @nt{component_clause}s, |
| 3182 |
for example. |
| 3183 |
The visibility rules for such names are up to the implementation. |
| 3184 |
|
| 3185 |
We do not allow such component names to be normal identifiers |
| 3186 |
@em that would constitute blanket permission to do all kinds of evil |
| 3187 |
things. |
| 3188 |
@end{Ramification} |
| 3189 |
@begin{Discussion} |
| 3190 |
@Defn{dope} |
| 3191 |
Such implementation-defined components are known in the |
| 3192 |
vernacular as @lquotes@;dope.@rquotes@; |
| 3193 |
Their main purpose is for storing offsets of components that depend |
| 3194 |
on discriminants. |
| 3195 |
@end{Discussion} |
| 3196 |
|
| 3197 |
If a @nt<record_representation_clause> is given for an untagged derived type, |
| 3198 |
the storage place attributes for all of the components of the derived |
| 3199 |
type may differ |
| 3200 |
from those of the corresponding components of the parent type, |
| 3201 |
even for components whose storage |
| 3202 |
place is not specified explicitly in the @nt<record_@!representation_@!clause>. |
| 3203 |
@begin{Reason} |
| 3204 |
This is clearly necessary, since the whole record may need to be |
| 3205 |
laid out differently. |
| 3206 |
@end{Reason} |
| 3207 |
@end{ImplPerm} |
| 3208 |
|
| 3209 |
@begin{ImplAdvice} |
| 3210 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(@nt{record_representation_clause})} |
| 3211 |
The recommended level of support for @nt{record_representation_clause}s is: |
| 3212 |
@begin{Itemize} |
| 3213 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]} |
| 3214 |
@ChgAdded{Version=[2],Text=[An implementation should support machine scalars |
| 3215 |
that correspond to all of the integer, floating point, and address formats |
| 3216 |
supported by the machine.]} |
| 3217 |
|
| 3218 |
An implementation should support storage places that can be extracted |
| 3219 |
with a load, mask, shift sequence of machine code, |
| 3220 |
and set with a load, shift, mask, store sequence, |
| 3221 |
given the available machine instructions and run-time model. |
| 3222 |
|
| 3223 |
A storage place should be supported if its size is equal to the Size |
| 3224 |
of the component subtype, |
| 3225 |
and it starts and ends on a boundary that obeys the Alignment of the |
| 3226 |
component subtype. |
| 3227 |
|
| 3228 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]} |
| 3229 |
@Chg{Version=[2],New=[For],Old=[If the default bit ordering applies to |
| 3230 |
the declaration of a given type, then for]} a component |
| 3231 |
@Chg{Version=[2],New=[with a subtype ],Old=[]}whose |
| 3232 |
@Chg{Version=[2],New=[],Old=[subtype's ]}Size is less than the word size, any |
| 3233 |
storage place that does not cross an aligned word boundary should be supported. |
| 3234 |
|
| 3235 |
@begin{Reason} |
| 3236 |
The above recommendations are sufficient to |
| 3237 |
define interfaces to most interesting hardware. |
| 3238 |
This causes less implementation burden than the definition in ACID, |
| 3239 |
which requires arbitrary bit alignments of arbitrarily large |
| 3240 |
components. |
| 3241 |
Since the ACID definition is neither enforced by the ACVC, |
| 3242 |
nor supported by all implementations, |
| 3243 |
it seems OK for us to weaken it. |
| 3244 |
@end{Reason} |
| 3245 |
|
| 3246 |
An implementation may reserve a storage place for the tag |
| 3247 |
field of a tagged type, and disallow other components from overlapping |
| 3248 |
that place. |
| 3249 |
@begin{Ramification} |
| 3250 |
Similar permission for other dope is not granted. |
| 3251 |
@end{Ramification} |
| 3252 |
|
| 3253 |
An implementation need not support a |
| 3254 |
@nt{component_clause} for a component of an extension part |
| 3255 |
if the storage place is not after the storage places of all components |
| 3256 |
of the parent type, whether or not those storage places had been specified. |
| 3257 |
@begin{Reason} |
| 3258 |
These restrictions are probably necessary if block equality |
| 3259 |
operations are to be feasible for class-wide types. |
| 3260 |
For block comparison to work, the implementation typically has to fill |
| 3261 |
in any gaps with zero (or one) bits. |
| 3262 |
If a @lquotes@;gap@rquotes@; in the parent type is filled in with a component in a |
| 3263 |
type extension, then this won't work when a class-wide object is |
| 3264 |
passed by reference, as is required. |
| 3265 |
@end{Reason} |
| 3266 |
@end{Itemize} |
| 3267 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 3268 |
Text=[The recommended level of support for @nt{record_representation_clause}s |
| 3269 |
should be followed.]}]} |
| 3270 |
@end{ImplAdvice} |
| 3271 |
|
| 3272 |
@begin{Notes} |
| 3273 |
If no @nt{component_clause} is given for a component, then the |
| 3274 |
choice of the storage place for the component is left to the |
| 3275 |
implementation. If @nt{component_clause}s are given for all components, |
| 3276 |
the @nt{record_representation_clause} completely specifies the |
| 3277 |
representation of the type and will be obeyed exactly by the |
| 3278 |
implementation. |
| 3279 |
@begin{Ramification} |
| 3280 |
The |
| 3281 |
visibility rules prevent the name of a component of the type from |
| 3282 |
appearing in a @nt{record_representation_clause} at any place |
| 3283 |
@i{except} for the @SynI{component_}@nt<local_name> of a |
| 3284 |
@nt{component_clause}. |
| 3285 |
However, since the @nt{record_representation_clause} is part of the |
| 3286 |
declarative region of the type declaration, |
| 3287 |
the component names hide outer homographs throughout. |
| 3288 |
|
| 3289 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]} |
| 3290 |
A @nt{record_representation_clause} cannot be given for a protected type, |
| 3291 |
even though protected types, like record types, have components. |
| 3292 |
The primary reason for this rule is that there is likely to be too |
| 3293 |
much dope in a protected type @em entry queues, |
| 3294 |
bit maps for barrier values, etc. |
| 3295 |
In order to control the representation of the user-defined components, simply |
| 3296 |
declare a record type, give it a |
| 3297 |
@Chg{New=[@nt{record_@!representation_@!clause}],Old=[@nt{representation_clause}]}, |
| 3298 |
and give the protected type one component whose type is the record type. |
| 3299 |
Alternatively, if the protected object is protecting something like a |
| 3300 |
device register, it makes more sense to keep the thing being |
| 3301 |
protected outside the protected object (possibly with a pointer to it |
| 3302 |
in the protected object), in order to keep implementation-defined |
| 3303 |
components out of the way. |
| 3304 |
@end{Ramification} |
| 3305 |
@end{Notes} |
| 3306 |
|
| 3307 |
@begin{Examples} |
| 3308 |
@leading@keepnext@i{Example of specifying the layout of a record type:} |
| 3309 |
@begin{Example} |
| 3310 |
Word : @key[constant] := 4; --@RI{ storage element is byte, 4 bytes per word} |
| 3311 |
|
| 3312 |
@key[type] State @key[is] (A,M,W,P); |
| 3313 |
@key[type] Mode @key[is] (Fix, Dec, Exp, Signif); |
| 3314 |
|
| 3315 |
@key[type] Byte_Mask @key[is] @key[array] (0..7) @key[of] Boolean; |
| 3316 |
@key[type] State_Mask @key[is] @key[array] (State) @key[of] Boolean; |
| 3317 |
@key[type] Mode_Mask @key[is] @key[array] (Mode) @key[of] Boolean; |
| 3318 |
|
| 3319 |
@key[type] Program_Status_Word @key[is] |
| 3320 |
@key[record] |
| 3321 |
System_Mask : Byte_Mask; |
| 3322 |
Protection_Key : Integer @key[range] 0 .. 3; |
| 3323 |
Machine_State : State_Mask; |
| 3324 |
Interrupt_Cause : Interruption_Code; |
| 3325 |
Ilc : Integer @key[range] 0 .. 3; |
| 3326 |
Cc : Integer @key[range] 0 .. 3; |
| 3327 |
Program_Mask : Mode_Mask; |
| 3328 |
Inst_Address : Address; |
| 3329 |
@key[end] @key[record]; |
| 3330 |
|
| 3331 |
@key[for] Program_Status_Word @key[use] |
| 3332 |
@key[record] |
| 3333 |
System_Mask @key[at] 0*Word @key[range] 0 .. 7; |
| 3334 |
Protection_Key @key[at] 0*Word @key[range] 10 .. 11; --@RI{ bits 8,9 unused} |
| 3335 |
Machine_State @key[at] 0*Word @key[range] 12 .. 15; |
| 3336 |
Interrupt_Cause @key[at] 0*Word @key[range] 16 .. 31; |
| 3337 |
Ilc @key[at] 1*Word @key[range] 0 .. 1; --@RI{ second word} |
| 3338 |
Cc @key[at] 1*Word @key[range] 2 .. 3; |
| 3339 |
Program_Mask @key[at] 1*Word @key[range] 4 .. 7; |
| 3340 |
Inst_Address @key[at] 1*Word @key[range] 8 .. 31; |
| 3341 |
@key[end] @key[record]; |
| 3342 |
|
| 3343 |
@key[for] Program_Status_Word'Size @key[use] 8*System.Storage_Unit; |
| 3344 |
@key[for] Program_Status_Word'Alignment @key[use] 8; |
| 3345 |
@end{Example} |
| 3346 |
@end{Examples} |
| 3347 |
|
| 3348 |
@begin{Notes} |
| 3349 |
@i{Note on the example:} |
| 3350 |
The @nt{record_representation_clause} defines the record layout. The |
| 3351 |
Size clause guarantees that (at least) eight storage elements are used |
| 3352 |
for objects of the type. The Alignment clause guarantees that |
| 3353 |
aliased, imported, or exported objects of the type will have |
| 3354 |
addresses divisible by eight. |
| 3355 |
@end{Notes} |
| 3356 |
|
| 3357 |
|
| 3358 |
@begin{DiffWord83} |
| 3359 |
The @ntf{alignment_clause} has been renamed to @nt{mod_clause} and moved |
| 3360 |
to @RefSec{Obsolescent Features}. |
| 3361 |
|
| 3362 |
We have clarified that implementation-defined component names have to be |
| 3363 |
in the form of an @nt{attribute_reference} of a component or of the |
| 3364 |
first subtype itself; |
| 3365 |
surely Ada 83 did not intend to allow arbitrary identifiers. |
| 3366 |
|
| 3367 |
The RM83-13.4(7) wording incorrectly allows components in |
| 3368 |
non-variant records to overlap. |
| 3369 |
We have corrected that oversight. |
| 3370 |
@end{DiffWord83} |
| 3371 |
|
| 3372 |
@begin{Incompatible95} |
| 3373 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]} |
| 3374 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 3375 |
@b[Amendment Correction:] The meaning of a @nt{record_representation_clause} |
| 3376 |
for the nondefault |
| 3377 |
bit order is now clearly defined. Thus, such clauses can be portably |
| 3378 |
written. In order to do that though, the equivalence of bit 1 in word 1 to |
| 3379 |
bit 9 in word 0 (for a machine with Storage_Unit = 8) had to be dropped for |
| 3380 |
the nondefault bit order. Any @nt{record_representation_clause}s which |
| 3381 |
depends on that equivalence will break (although such code would imply a |
| 3382 |
non-contiguous representation for a component, and it seems unlikely that |
| 3383 |
compilers were supporting that anyway).]} |
| 3384 |
@end{Incompatible95} |
| 3385 |
|
| 3386 |
@begin{Extend95} |
| 3387 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00436-01]} |
| 3388 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 3389 |
@b[Amendment Correction:] The undocumented (and |
| 3390 |
likely unintentional) incompatibility with Ada 83 caused by not allowing |
| 3391 |
@nt{record_representation_clause}s on limited record types is removed.]} |
| 3392 |
@end{Extend95} |
| 3393 |
|
| 3394 |
@LabeledSubClause{Storage Place Attributes} |
| 3395 |
|
| 3396 |
@begin{StaticSem} |
| 3397 |
@Leading@Defn2{Term=[storage place attributes], Sec=(of a component)} |
| 3398 |
For @PrefixType{a component C of a composite, non-array |
| 3399 |
object R}, |
| 3400 |
the @i{storage place attributes} are defined: |
| 3401 |
@begin{Ramification} |
| 3402 |
The storage place attributes are not (individually) specifiable, |
| 3403 |
but the user may control their values by giving a |
| 3404 |
@nt{record_representation_clause}. |
| 3405 |
@end{Ramification} |
| 3406 |
@begin{Description} |
| 3407 |
@ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T], |
| 3408 |
Leading=<F>, Prefix=<R.C>, AttrName=<Position>, |
| 3409 |
ARef=[AI95-00133-01], |
| 3410 |
Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the |
| 3411 |
composite type, and if a @nt{component_clause} specifies the placement of C, |
| 3412 |
denotes the value given for the @nt{position} of the @nt{component_clause}; |
| 3413 |
otherwise, denotes],Old=[Denotes]} the same value as R.C'Address @en@; |
| 3414 |
R'Address. The value of this attribute is of the type |
| 3415 |
@i{universal_integer}.>} |
| 3416 |
@begin{Ramification} |
| 3417 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]} |
| 3418 |
Thus, @Chg{Version=[2],New=[for the default bit order, ],Old=[]}R.C'Position |
| 3419 |
is the offset of C in storage |
| 3420 |
elements from the beginning of the object, |
| 3421 |
where the first storage element of an object is numbered zero. |
| 3422 |
R'Address + R.C'Position = R.C'Address. |
| 3423 |
For record extensions, the offset is not measured from |
| 3424 |
the beginning of the extension part, but from the |
| 3425 |
beginning of the whole object, as usual. |
| 3426 |
|
| 3427 |
In @lquotes@;R.C'Address @en@; R'Address@rquotes@;, |
| 3428 |
the "@en@;" operator is the one in System.Storage_Elements |
| 3429 |
that takes two Addresses and returns a Storage_Offset. |
| 3430 |
@end{Ramification} |
| 3431 |
|
| 3432 |
@ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T], |
| 3433 |
Leading=<F>, Prefix=<R.C>, AttrName=<First_Bit>, |
| 3434 |
ARef=[AI95-00133-01], |
| 3435 |
Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the |
| 3436 |
composite type, and if a @nt{component_clause} specifies the placement of C, |
| 3437 |
denotes the value given for the @nt{first_bit} of the @nt{component_clause}; |
| 3438 |
otherwise, denotes],Old=[Denotes]} the offset, from the start of the first |
| 3439 |
of the storage elements occupied by C, of the first bit occupied by C. |
| 3440 |
This offset is measured in bits. |
| 3441 |
The first bit of a storage element is numbered zero. |
| 3442 |
The value of this attribute is of the type |
| 3443 |
@i{universal_integer}.>} |
| 3444 |
|
| 3445 |
@ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T], |
| 3446 |
Leading=<F>, Prefix=<R.C>, AttrName=<Last_Bit>, |
| 3447 |
ARef=[AI95-00133-01], |
| 3448 |
Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the |
| 3449 |
composite type, and if a @nt{component_clause} specifies the placement of C, |
| 3450 |
denotes the value given for the @nt{last_bit} of the @nt{component_clause}; |
| 3451 |
otherwise, denotes],Old=[Denotes]} the offset, from the start of the first |
| 3452 |
of the storage elements occupied by C, of the last bit occupied by C. |
| 3453 |
This offset is measured in bits. The value of this attribute |
| 3454 |
is of the type @i{universal_integer}.>} |
| 3455 |
@begin{Ramification} |
| 3456 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 3457 |
The ordering of bits in a storage element is |
| 3458 |
@Chg{Version=[2],New=[],Old=[is ]}defined in @RefSec{Bit Ordering}. |
| 3459 |
|
| 3460 |
R.C'Size = R.C'Last_Bit @en@; R.C'First_Bit + 1. |
| 3461 |
(Unless the implementation chooses an indirection |
| 3462 |
representation.) |
| 3463 |
|
| 3464 |
If a @nt{component_clause} applies to a component, |
| 3465 |
then that component will be at the same relative storage place |
| 3466 |
in all objects of the type. |
| 3467 |
Otherwise, there is no such requirement. |
| 3468 |
@end{Ramification} |
| 3469 |
@end{Description} |
| 3470 |
@EndPrefixType{} |
| 3471 |
@end{StaticSem} |
| 3472 |
|
| 3473 |
@begin{ImplAdvice} |
| 3474 |
@PDefn{contiguous representation} |
| 3475 |
@PDefn{discontiguous representation} |
| 3476 |
If a component is represented using some form of pointer (such as an |
| 3477 |
offset) to the actual data of the component, and this data is contiguous with |
| 3478 |
the rest of the object, then the storage place attributes should reflect |
| 3479 |
the place of the actual data, not the pointer. |
| 3480 |
If a component is allocated discontiguously from the rest of the object, |
| 3481 |
then a warning should be generated upon reference to one |
| 3482 |
of its storage place attributes. |
| 3483 |
@begin{Reason} |
| 3484 |
For discontiguous components, these attributes make no sense. |
| 3485 |
For example, an implementation might allocate dynamic-sized components |
| 3486 |
on the heap. |
| 3487 |
For another example, an implementation might allocate the discriminants |
| 3488 |
separately from the other components, so that multiple objects of the |
| 3489 |
same subtype can share discriminants. |
| 3490 |
Such representations cannot happen if there is a @nt{component_clause} |
| 3491 |
for that component. |
| 3492 |
@end{Reason} |
| 3493 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 3494 |
Text=[If a component is represented using a pointer to the actual data of |
| 3495 |
the component which is contiguous with |
| 3496 |
the rest of the object, then the storage place attributes should reflect |
| 3497 |
the place of the actual data. |
| 3498 |
If a component is allocated discontiguously from the rest of the object, |
| 3499 |
then a warning should be generated upon reference to one |
| 3500 |
of its storage place attributes.]}]} |
| 3501 |
@end{ImplAdvice} |
| 3502 |
|
| 3503 |
@begin{Incompatible95} |
| 3504 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]} |
| 3505 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 3506 |
@b[Amendment Correction:] The meaning of the storage place attributes for |
| 3507 |
the nondefault |
| 3508 |
bit order is now clearly defined, and can be different than that given by |
| 3509 |
strictly following the Ada 95 wording. Any code which depends on the |
| 3510 |
original Ada 95 values for a type using the nondefault bit order where |
| 3511 |
they are different will break.]} |
| 3512 |
@end{Incompatible95} |
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
@LabeledSubClause{Bit Ordering} |
| 3517 |
|
| 3518 |
@begin{Intro} |
| 3519 |
@redundant[The Bit_Order attribute specifies the interpretation of the storage |
| 3520 |
place attributes.] |
| 3521 |
@begin{Reason} |
| 3522 |
The intention is to provide uniformity in the |
| 3523 |
interpretation of storage places across implementations on a |
| 3524 |
particular machine by allowing the user to specify the Bit_Order. |
| 3525 |
It is not intended to fully support data interoperability across |
| 3526 |
different machines, |
| 3527 |
although it can be used for that purpose in some situations. |
| 3528 |
|
| 3529 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 3530 |
We can't require all implementations on a given machine to use the same |
| 3531 |
bit ordering by default; |
| 3532 |
if the user cares, a @Chg{Version=[2],New=[],Old=[@nt{pragma} ]}Bit_Order |
| 3533 |
@Chg{Version=[2],New=[@nt{attribute_definition_clause} ],Old=[]}can be used |
| 3534 |
to force all implementations to use the same bit ordering. |
| 3535 |
@end{Reason} |
| 3536 |
@end{Intro} |
| 3537 |
|
| 3538 |
@begin{StaticSem} |
| 3539 |
@Defn{bit ordering} |
| 3540 |
A bit ordering is a method of interpreting the meaning of the |
| 3541 |
storage place attributes. |
| 3542 |
@Defn{High_Order_First} |
| 3543 |
@Defn{big endian} |
| 3544 |
@Defn2{Term=[endian], Sec=(big)} |
| 3545 |
High_Order_First @Redundant[(known in the vernacular as @lquotes@;big endian@rquotes@;)] |
| 3546 |
means that the first bit of a storage element |
| 3547 |
(bit 0) is the most significant bit (interpreting the sequence of |
| 3548 |
bits that represent a component as an unsigned integer value). |
| 3549 |
@Defn{Low_Order_First} |
| 3550 |
@Defn{little endian} |
| 3551 |
@Defn2{Term=[endian], Sec=(little)} |
| 3552 |
Low_Order_First @Redundant[(known in the vernacular as @lquotes@;little endian@rquotes@;)] |
| 3553 |
means the opposite: the first bit is the least significant. |
| 3554 |
|
| 3555 |
@Leading@;For @PrefixType{every specific record subtype S}, |
| 3556 |
the following attribute is defined: |
| 3557 |
@begin{Description} |
| 3558 |
@Attribute{Prefix=<S>, AttrName=<Bit_Order>, |
| 3559 |
Text=<Denotes the bit ordering for the type of S. |
| 3560 |
The value of this attribute is of type System.Bit_Order.>} |
| 3561 |
@EndPrefixType{} |
| 3562 |
@PDefn2{Term=[specifiable], Sec=(of Bit_Order for record types and |
| 3563 |
record extensions)} |
| 3564 |
@Defn{Bit_Order clause} |
| 3565 |
Bit_Order may be specified for specific record types |
| 3566 |
via an @nt{attribute_definition_clause}; |
| 3567 |
the expression of such a clause shall be static. |
| 3568 |
@end{Description} |
| 3569 |
|
| 3570 |
If Word_Size = Storage_Unit, |
| 3571 |
the default bit ordering is implementation defined. |
| 3572 |
If Word_Size > Storage_Unit, |
| 3573 |
the default bit ordering is the same as the ordering of storage |
| 3574 |
elements in a word, when interpreted as an |
| 3575 |
integer. |
| 3576 |
@IndexSee{Term=[byte sex],See=(ordering of storage elements in a word)} |
| 3577 |
@ImplDef{If Word_Size = Storage_Unit, |
| 3578 |
the default bit ordering.} |
| 3579 |
@begin{Ramification} |
| 3580 |
Consider machines whose Word_Size = 32, |
| 3581 |
and whose Storage_Unit = 8. |
| 3582 |
Assume the default bit ordering applies. |
| 3583 |
On a machine with big-endian addresses, |
| 3584 |
the most significant storage element of an integer is at the address of |
| 3585 |
the integer. |
| 3586 |
Therefore, bit zero of a storage element is the most significant bit. |
| 3587 |
On a machine with little-endian addresses, |
| 3588 |
the least significant storage element of an integer is at the address of |
| 3589 |
the integer. |
| 3590 |
Therefore, bit zero of a storage element is the least significant |
| 3591 |
bit. |
| 3592 |
@end{Ramification} |
| 3593 |
|
| 3594 |
The storage place attributes of a |
| 3595 |
component of a type are |
| 3596 |
interpreted according to the bit ordering |
| 3597 |
of the type. |
| 3598 |
@begin{Ramification} |
| 3599 |
This implies that the interpretation of the @nt{position}, |
| 3600 |
@nt{first_bit}, and @nt{last_bit} of a @nt{component_clause} of a |
| 3601 |
@nt{record_representation_clause} obey the bit ordering given in a |
| 3602 |
representation item. |
| 3603 |
@end{Ramification} |
| 3604 |
@end{StaticSem} |
| 3605 |
|
| 3606 |
@begin{ImplAdvice} |
| 3607 |
@Leading@PDefn2{Term=[recommended level of support], Sec=(bit ordering)} |
| 3608 |
The recommended level of support for the nondefault bit ordering is: |
| 3609 |
@begin{Itemize} |
| 3610 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]} |
| 3611 |
@Chg{Version=[2],New=[The],Old=[If Word_Size = Storage_Unit, then |
| 3612 |
the]} implementation should support the nondefault bit ordering |
| 3613 |
in addition to the default bit ordering. |
| 3614 |
@end{Itemize} |
| 3615 |
@begin{Ramification} |
| 3616 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]} |
| 3617 |
@Chg{Version=[2],New=[The],Old=[If Word_Size = Storage_Unit, |
| 3618 |
the]} implementation should support both bit orderings. |
| 3619 |
@Chg{Version=[2],New=[Implementations],Old=[We don't push for support of |
| 3620 |
the nondefault bit ordering when Word_Size > Storage_Unit (except |
| 3621 |
of course for upward compatibility with a preexisting implementation |
| 3622 |
whose Ada 83 bit order did not correspond to the required Ada 95 |
| 3623 |
default bit order), because |
| 3624 |
implementations]} are required to support storage positions that cross |
| 3625 |
storage element boundaries when Word_Size > Storage_Unit@Chg{Version=[2], |
| 3626 |
New=[ but the definition of the storage place attributes for the nondefault |
| 3627 |
bit order ensures that such],Old=[. Such]} storage positions will @Chg{Version=[2], |
| 3628 |
New=[not ],Old=[]}be split into two or three pieces@Chg{Version=[2],New=[. Thus, |
| 3629 |
there is no significant implementation burden to supporting the nondefault |
| 3630 |
bit order, given that the set of machine scalars is implementation-defined], |
| 3631 |
Old=[ if the nondefault bit ordering is used, which could be onerous to |
| 3632 |
support. However, if Word_Size = Storage_Unit, |
| 3633 |
there might not be a natural bit ordering, |
| 3634 |
but the splitting problem need not occur]}. |
| 3635 |
@end{Ramification} |
| 3636 |
@ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2], |
| 3637 |
Text=[The recommended level of support for the nondefault bit ordering |
| 3638 |
should be followed.]}]} |
| 3639 |
@end{ImplAdvice} |
| 3640 |
|
| 3641 |
@begin{Notes} |
| 3642 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]} |
| 3643 |
@ChgAdded{Version=[2],Text=[Bit_Order clauses make it possible to write |
| 3644 |
@nt{record_representation_clause}s that can be ported between machines having |
| 3645 |
different bit ordering. They do not guarantee transparent exchange of data |
| 3646 |
between such machines.]} |
| 3647 |
@end{Notes} |
| 3648 |
|
| 3649 |
@begin{Extend83} |
| 3650 |
@Defn{extensions to Ada 83} |
| 3651 |
The Bit_Order attribute is new to Ada 95. |
| 3652 |
@end{Extend83} |
| 3653 |
|
| 3654 |
@begin{DiffWord95} |
| 3655 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]} |
| 3656 |
@ChgAdded{Version=[2],Text=[We now suggest that all implementations |
| 3657 |
support the nondefault bit order.]} |
| 3658 |
@end{Diffword95} |
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
@RMNewPage@Comment{For printed RM Ada 2005} |
| 3663 |
@LabeledClause{Change of Representation} |
| 3664 |
|
| 3665 |
@begin{Intro} |
| 3666 |
@redundant[@Defn{change of representation} |
| 3667 |
@Defn2{Term=[representation], Sec=(change of)} |
| 3668 |
A @nt{type_conversion} (see @RefSecNum{Type Conversions}) |
| 3669 |
can be used to convert between two different |
| 3670 |
representations of the same array or record. |
| 3671 |
To convert an array from one representation to another, |
| 3672 |
two array types need to be declared with |
| 3673 |
matching component subtypes, and convertible index types. |
| 3674 |
If one type has packing specified and the other does not, |
| 3675 |
then explicit conversion can be used to pack or unpack an array. |
| 3676 |
|
| 3677 |
To convert a record from one representation to another, |
| 3678 |
two record types with a common ancestor type need to be declared, |
| 3679 |
with no inherited subprograms. Distinct representations can then |
| 3680 |
be specified for the record types, and explicit conversion between |
| 3681 |
the types can be used to effect a change in representation.] |
| 3682 |
@begin{Ramification} |
| 3683 |
This technique does not work if the first type is an |
| 3684 |
untagged type with user-defined primitive subprograms. |
| 3685 |
It does not work at all for tagged types. |
| 3686 |
@end{Ramification} |
| 3687 |
@end{Intro} |
| 3688 |
|
| 3689 |
@begin{Examples} |
| 3690 |
@leading@keepnext@i{Example of change of representation:} |
| 3691 |
@begin{Example} |
| 3692 |
--@RI{ Packed_Descriptor and Descriptor are two different types} |
| 3693 |
--@RI{ with identical characteristics, apart from their} |
| 3694 |
--@RI{ representation} |
| 3695 |
|
| 3696 |
@key[type] Descriptor @key[is] |
| 3697 |
@key[record] |
| 3698 |
--@RI{ components of a descriptor} |
| 3699 |
@key[end] @key[record]; |
| 3700 |
|
| 3701 |
@key[type] Packed_Descriptor @key[is] @key[new] Descriptor; |
| 3702 |
|
| 3703 |
@key[for] Packed_Descriptor @key[use] |
| 3704 |
@key[record] |
| 3705 |
--@RI{ component clauses for some or for all components} |
| 3706 |
@key[end] @key[record]; |
| 3707 |
|
| 3708 |
@RI{-- Change of representation can now be accomplished by explicit type conversions:} |
| 3709 |
|
| 3710 |
D : Descriptor; |
| 3711 |
P : Packed_Descriptor; |
| 3712 |
|
| 3713 |
P := Packed_Descriptor(D); --@RI{ pack D} |
| 3714 |
D := Descriptor(P); --@RI{ unpack P} |
| 3715 |
@end{Example} |
| 3716 |
@end{Examples} |
| 3717 |
|