Debian Codegraph @

source_2020/13a.mss

raw
1 @Part(13, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4 @LabeledSection{Representation Issues}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/13a.mss,v $}
7 @Comment{$Revision: 1.129 $}
8
9 @begin{Intro}
10 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
11 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
12 @redundant[This @Chg{Version=[3],New=[clause],Old=[section]} describes features for
13 querying and controlling @Chg{New=[certain aspects of entities],
14 Old=[aspects of representation]} and for interfacing to hardware.]
15 @end{Intro}
16
17 @begin{DiffWord83}
18 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
19 The @Chg{Version=[3],New=[subclauses],Old=[clauses]} of this
20 @Chg{Version=[3],New=[clause],Old=[section]} have been reorganized.
21 This was necessary to preserve a logical order,
22 given the new Ada 95 semantics given in this section.
23 @end{DiffWord83}
24
25 @LabeledRevisedClause{Version=[3],New=[Operational and Representation Aspects],Old=[Representation Items]}
26 @Comment{@LabeledRevisedClause{Version=[1],New=[Operational and Representation Items],Old=[Representation Items]} Don't have a way to include the middle title}
27
28 @begin{Intro}
29 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
30 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
31 @ChgAdded{Version=[1],Text=[@Redundant[@Chg{Version=[3],New=[@Defn{aspect}],
32 Old=[Representation and operational items can be used to specify aspects of
33 entities. ]}Two kinds of aspects of entities can be specified:
34 @Chg{Version=[3],New=[],Old=[aspects of ]}representation@Chg{Version=[3],
35 New=[ aspects],Old=[]} and operational aspects. Representation
36 @Chg{Version=[3],New=[aspects affect],Old=[items specify]}
37 how the types and other entities of the language are to be mapped onto
38 the underlying machine. Operational @Chg{Version=[3],New=[aspects determine],
39 Old=[items specify]} other properties of entities.]]}
40
41 @Comment{The index entries for these glossary items are found later in this
42 subclause}
43
44 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Operational Aspect>,
45 Text=<@ChgAdded{Version=[5],Text=[An aspect that indicates a logical property of
46 an entity, such as the precondition of a subprogram, or the procedure used to
47 write a given type of object to a stream.]}>}
48
49 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Representation Aspect>,
50 Text=<@ChgAdded{Version=[5],Text=[An aspect that indicates how an entity is
51 mapped onto the underlying hardware, for example the size or alignment of an
52 object.]}>}
53
54 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1],ARef=[AI05-0295-1]}
55 @ChgAdded{Version=[1],Text=[@Redundant[Either kind of aspect of an entity may be
56 specified by means of an @nt{aspect_specification} (see @RefSecNum{Aspect Specifications}),
57 which is an optional element
58 of most kinds of declarations and applies to the entity or entities being
59 declared. Aspects may also be specified by certain other constructs occurring
60 subsequent to the declaration of the affected entity: a representation aspect
61 value may be specified by means of a representation item
62 and an operational aspect value may be specified by means of an
63 operational item.]]}
64
65 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
66 @Defn{representation item}
67 @RootDefn{representation pragma}
68 @RootDefn{pragma, representation}
69 There are @Chg{New=[six],Old=[three]} kinds of @i{representation items}:
70 @Chg{New=[@nt{attribute_@!definition_@!clause}s for representation attributes,
71 @nt{enumeration_@!representation_@!clause}s,
72 @nt{record_@!representation_@!clause}s, @nt{at_clause}s, ],
73 Old=[@nt{representation_@!clause}s, ]}@nt<component_clause>s, and
74 @i{representation pragmas}.
75 @Redundant[@Chg{New=[],Old=[Representation items specify how the types and other entities of
76 the language are to be mapped onto the underlying machine.]}
77 They can be provided to give more efficient representation or to
78 interface with features that are outside the domain of the language
79 (for example, peripheral hardware).
80 @Chg{New=[],Old=[Representation items also specify other specifiable
81 properties of entities.
82 A representation item applies to an entity identified by
83 a @nt<local_name>, which denotes an entity declared local to the
84 current declarative region, or a library unit declared immediately
85 preceding a representation pragma in a @nt<compilation>.]}]
86
87 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
88 @ChgAdded{Version=[1],Text=[An @Defn{operational item}@i<operational item> is an
89 @nt<attribute_definition_clause> for an operational attribute.]}
90
91 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
92 @ChgAdded{Version=[1],Text=[@Redundant[An operational item or a representation
93 item applies to an entity identified by a @nt<local_name>, which denotes an
94 entity declared local to the current declarative region, or a library unit
95 declared immediately preceding a representation pragma in a
96 @nt<compilation>.]]}
97 @end{Intro}
98
99 @begin{Metarules}
100 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
101 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
102 @ChgAdded{Version=[1],Text=[@Chg{Version=[3],New=[Representation
103 aspects],Old=[Aspects of representation]} are intended to refer to
104 properties that need to be known before the compiler can generate code to
105 create or access an entity. For instance, the size of an object needs to be
106 known before the object can be created. Conversely, operational aspects are
107 those that only need to be known before they can be used. For instance, how an
108 object is read from a stream only needs to be known when a stream read is
109 executed. Thus, @Chg{Version=[3],New=[],Old=[aspects of
110 ]}representation@Chg{Version=[3], New=[ aspects],Old=[]} have stricter rules as
111 to when they can be specified.]}
112
113 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
114 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
115 @ChgAdded{Version=[2],Text=[Confirming the value of an aspect
116 @Chg{Version=[3],New=[],Old=[with an operational or representation item ]}should
117 never change the semantics of
118 the aspect. Thus Size = 8 (for example) means the same thing whether it
119 was specified with a representation item or whether the compiler chose this
120 value by default.]}
121 @end{Metarules}
122
123 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Aspect>,
124 Text=<@ChgAdded{Version=[3],Text=[An aspect is
125 a specifiable property of an entity. An aspect may be specified by an
126 @nt{aspect_specification} on the declaration of the entity. Some aspects may be
127 queried via attributes.]}>}
128
129 @begin{Syntax}
130 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
131 @Syn{lhs=<@Chg{New=[aspect_clause],Old=[representation_clause]}>,rhs="@Syn2{attribute_definition_clause}
132 | @Syn2{enumeration_representation_clause}
133 | @Syn2{record_representation_clause}
134 | @Syn2{at_clause}"}
135
136 @Syn{lhs=<local_name>,rhs="@Syn2{direct_name}
137 | @Syn2{direct_name}@SingleQuote@Syn2{attribute_designator}
138 | @SynI{library_unit_}@Syn2{name}"}
139
140 @begin{SyntaxText}
141 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
142 A representation pragma is allowed only at places where
143 @Chg{New=[an @nt{aspect_clause}],Old=[a @nt{representation_clause}]}
144 or @nt{compilation_unit} is allowed.
145 @Chg{New=[@IndexSee(Term=(representation_clause),See=(aspect_clause))],Old=[]}
146 @end{SyntaxText}
147 @end{Syntax}
148
149 @begin{Resolution}
150 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
151 In @Chg{New=[an operational item or],Old=[a]} representation item,
152 if the @nt<local_name> is a @nt<direct_name>, then it shall
153 resolve to denote a declaration
154 (or, in the case of a @nt{pragma}, one or more declarations)
155 that occurs immediately within the same
156 declarative region as the @Chg{New=[],Old=[representation ]}item.
157 If the @nt<local_name> has an @nt<attribute_designator>, then it shall
158 resolve to denote an implementation-defined
159 component (see @RefSecNum{Record Representation Clauses})
160 or a class-wide
161 type implicitly declared immediately within the same
162 declarative region as the @Chg{New=[],Old=[representation ]}item.
163 A @nt<local_name> that is a @i{library_unit_}@nt<name> (only
164 permitted in a representation pragma) shall resolve
165 to denote the @nt<library_item> that immediately precedes
166 (except for other pragmas) the representation pragma.
167 @begin{Reason}
168 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
169 This is a @ResolutionName,
170 because we don't want @Chg{New=[an operational or],Old=[a]} representation
171 item for X to be ambiguous just because there's another X declared in an outer
172 declarative region.
173 It doesn't make much difference, since most
174 @Chg{New=[operational or ],Old=[]}representation items are for types or
175 subtypes, and type and subtype names can't be overloaded.
176 @end{Reason}
177 @begin{Ramification}
178 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
179 The visibility rules imply that the declaration has to occur
180 before the @Chg{New=[operational or ],Old=[]}representation item.
181
182 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
183 For objects, this implies that @Chg{New=[operational or ],Old=[]}representation items can be
184 applied only to stand-alone objects.
185 @end{Ramification}
186 @end{Resolution}
187
188 @begin{Legality}
189 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
190 The @nt{local_name} of @Chg{New=[an @nt<aspect_clause>],
191 Old=[a @nt<representation_clause>]} or representation pragma shall
192 statically denote an entity (or, in the case of a @nt{pragma},
193 one or more entities) declared immediately preceding it in a @nt<compilation>,
194 or within the same @nt{declarative_@!part}, @nt{package_@!specification},
195 @nt{task_@!definition}, @nt{protected_@!definition}, or
196 @nt{record_@!definition} as the representation @Chg{New=[or operational ],Old=[]}item.
197 If a @nt<local_name> denotes a @Redundant[local] callable entity,
198 it may do so through a @Redundant[local]
199 @nt<subprogram_@!renaming_@!declaration>
200 @Redundant[(as a way to resolve ambiguity in the presence of overloading)];
201 otherwise, the @nt<local_name> shall not denote a @nt<renaming_@!declaration>.
202 @begin{Ramification}
203 The @lquotes@;statically denote@rquotes@; part
204 implies that it is impossible to specify the representation of
205 an object that is not a stand-alone object,
206 except in the case of a representation
207 item like pragma Atomic
208 that is allowed inside a @nt{component_list}
209 (in which case the representation item specifies
210 the representation of components of all objects of the type).
211 It also prevents the problem of
212 renamings of things like @lquotes@;P.@key[all]@rquotes@;
213 (where P is an access-to-subprogram value)
214 or @lquotes@;E(I)@rquotes@; (where E is an entry family).
215
216 The part about where the denoted entity has to have been
217 declared appears twice @em once as a @ResolutionName,
218 and once as a @LegalityName.
219 Suppose P renames Q,
220 and we have a representation item in a @nt{declarative_part}
221 whose @nt<local_name> is P.
222 The fact that the representation item has to appear in the same
223 @nt{declarative_part} as P is a @ResolutionName,
224 whereas the fact that the representation item has to appear in the
225 same @nt{declarative_part} as Q is a @LegalityName.
226 This is subtle, but it seems like the least confusing set of rules.
227 @end{Ramification}
228 @begin{Discussion}
229 A separate @LegalityName applies for @nt<component_clause>s.
230 See @RefSec{Record Representation Clauses}.
231 @end{Discussion}
232
233 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
234 @Defn{representation of an object}
235 @Defn2{Term=[size], Sec=(of an object)}The @i{representation} of an
236 object consists of a certain
237 number of bits (the @i(size) of
238 the object).
239 @Chg{Version=[2],New=[For an object of an elementary type, these],Old=[These]}
240 are the bits that are normally read
241 or updated by the machine code
242 when loading, storing, or operating-on the value of the object.
243 @Chg{Version=[2],New=[For an object of a composite type, these
244 are the bits reserved for this object, and include bits occupied by
245 subcomponents of the object. If],Old=[This includes some padding bits, when]}
246 the size of @Chg{Version=[2],New=[an],Old=[the]} object
247 is greater than @Chg{Version=[2],New=[that],Old=[the size]} of its subtype@Chg{Version=[2],
248 New=[, the additional bits are padding bits.],Old=[.
249 @Defn{gaps}]}
250 @Defn{padding bits}
251 @Chg{Version=[2],New=[For an elementary object, these],Old=[Such]} padding bits
252 @Chg{Version=[2],New=[],Old=[are considered to be part of the representation of the
253 object, rather than being gaps between objects,
254 if these bits ]}are normally read and updated@Chg{Version=[2],New=[ along
255 with the others. For a
256 composite object, padding bits might not be read or updated in any given
257 composite operation, depending on the implementation],Old=[]}.
258
259 @begin{Honest}
260 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
261 @PDefn{contiguous representation}
262 @PDefn{discontiguous representation}
263 Discontiguous representations are allowed,
264 but the ones we're interested in here are generally contiguous
265 sequences of bits.@Chg{Version=[2],New=[ For a discontiguous representation,
266 the size doesn't necessarily describe the @lquotes@;footprint@rquotes of
267 the object in memory (that is, the amount of space taken in the address space
268 for the object).],Old=[]}
269 @end{Honest}
270 @begin{Discussion}
271 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
272 @ChgAdded{Version=[2],Text=[In the case of composite objects, we want the
273 implementation to have the flexibility to either do operations
274 component-by-component, or with a block operation covering all of the bits. We
275 carefully avoid giving a preference in the wording. There is no requirement
276 for the choice to be documented, either, as the implementation can make that
277 choice based on many factors, and could make a different choice for different
278 operations on the same object.]}
279
280 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
281 @ChgAdded{Version=[2],Text=[In the case of a properly aligned, contiguous
282 object whose size is a multiple of the storage unit size, no other bits should
283 be read or updated as part of operating on the object. We don't say this
284 normatively because it would be difficult to normatively define
285 @lquotes@;properly aligned@rquotes or @lquotes@;contiguous@rquotes.]}
286 @end{Discussion}
287 @begin{Ramification}
288 @Leading@;Two objects with the same value do not necessarily have the same
289 representation.
290 For example, an implementation might represent False as zero and True
291 as any odd value.
292 Similarly, two objects (of the same type)
293 with the same sequence of bits do not necessarily have the
294 same value.
295 For example, an implementation might use a biased representation in
296 some cases but not others:
297 @begin{Example}
298 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
299 @key[subtype] S @key[is] Integer @key[range] 1..256;
300 @key[type] A @key[is] @key[array](Natural @key[range] 1..4) @key[of] S@Chg{Version=[3],New=[
301 @key[with] Pack],Old=[;
302 @key[pragma] Pack(A)]};
303 X : S := 3;
304 Y : A := (1, 2, 3, 4);
305 @end{Example}
306
307 The implementation might use a biased-by-1 representation for the
308 array elements, but not for X.
309 X and Y(3) have the same value, but different representation:
310 the representation of X is a sequence of (say) 32 bits: 0...011,
311 whereas the representation of Y(3) is a sequence of 8 bits:
312 00000010 (assuming a two's complement representation).
313
314 Such tricks are not required, but are allowed.
315 @end{Ramification}
316 @begin{Discussion}
317 The value of any padding bits is not specified by the language,
318 though for a numeric type, it will be much harder to properly implement
319 the predefined operations if the padding bits are not either all zero,
320 or a sign extension.
321 @end{Discussion}
322 @begin{Ramification}
323 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
324 For example, suppose S'Size = 2, and an object X is of subtype S.
325 If the machine code typically uses a 32-bit load instruction to load the
326 value of X, then X'Size should be 32, even though 30 bits of the value
327 are just zeros or sign-extension bits.
328 On the other hand, if the machine code typically masks out those 30
329 bits, then X'Size should be 2.
330 Usually, such masking only happens for components of a composite type
331 for which @Chg{Version=[3],New=[Pack],Old=[packing]}, Component_Size, or
332 record layout is specified.
333
334 Note, however, that the formal parameter of an instance of
335 Unchecked_Conversion is a special case.
336 Its Size is required to be the same as that of its subtype.
337
338 Note that we don't generally talk about the representation of a
339 value.
340 A value is considered to be an amorphous blob
341 without any particular representation.
342 An object is considered to be more concrete.
343 @end{Ramification}
344
345 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0112-1],ARef=[AI05-0295-1]}
346 @RootDefn{aspect of representation}
347 @Defn{representation aspect}
348 @Chg{Version=[3],New=[@Defn2{Term=[directly specified],
349 Sec=(of a representation aspect of an entity)}],
350 Old=[@Defn2{Term=[directly specified],
351 Sec=(of an aspect of representation of an entity)}]}
352 A representation item @i{directly specifies}
353 @Chg{Version=[3],New=[a @i{representation aspect}],
354 Old=[an @i{aspect of representation}]} of the entity denoted
355 by the @nt{local_name},
356 except in the case of a type-related representation item,
357 whose @nt{local_name} shall denote a first subtype,
358 and which directly specifies an aspect
359 of the subtype's type.
360 @RootDefn2{Term=[type-related], Sec=(representation item)}
361 @RootDefn2{term=[subtype-specific], Sec=(of a representation item)}
362 @RootDefn2{Term=[type-related], Sec=(aspect)}
363 @RootDefn2{term=[subtype-specific], Sec=(of an aspect)}
364 A representation item that names a subtype is either
365 @i(subtype-specific) (Size and Alignment clauses)
366 or @i{type-related} (all others).
367 @Redundant[Subtype-specific aspects may differ for
368 different subtypes of the same type.]
369
370 @begin{Honest}
371 @i{Type-related} and @i{subtype-specific} are defined likewise for
372 the corresponding aspects of representation.
373 @end{Honest}
374 @begin{Honest}
375 Some representation items directly specify more than one aspect.
376 @end{Honest}
377 @begin{Discussion}
378 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
379 For example, a @nt{pragma} Export
380 @Chg{Version=[3],New=[(see @RefSecNum{Interfacing Pragmas}) ],Old=[]}specifies the convention
381 of an entity,
382 and also specifies that it is exported.@Chg{Version=[3],New=[ Such items are
383 obsolescent; directly specifying
384 the associated aspects is preferred.],Old=[]}
385 @end{Discussion}
386 @begin{Ramification}
387 Each specifiable attribute constitutes a separate aspect.
388 An @nt{enumeration_representation_clause} specifies the coding aspect.
389 A @nt{record_representation_clause} (without the @nt{mod_clause})
390 specifies the record layout aspect.
391 Each representation pragma specifies a separate aspect.
392 @end{Ramification}
393 @begin{Reason}
394 We don't need to say that an @nt{at_clause} or a
395 @nt{mod_clause} specify separate aspects,
396 because these are equivalent to @nt{attribute_definition_clause}s.
397 See @RefSec{At Clauses}, and @RefSec{Mod Clauses}.
398
399 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0112-1]}
400 @ChgAdded{Version=[3],Text=[We give a default naming for representation
401 aspects of representation pragmas so we don't have to do that for every
402 pragma. Operational and representation attributes are given a default naming
403 in @RefSecNum{Operational and Representation Attributes}.
404 We don't want any anonymous aspects; that would make other rules
405 more difficult to write and understand.]}
406 @end{Reason}
407 @begin{Ramification}
408 @Leading@;The following representation items are type-related:
409 @begin{Itemize}
410 @nt{enumeration_representation_clause}
411
412 @nt{record_representation_clause}
413
414 Component_Size clause
415
416 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
417 @ChgDeleted{Version=[1],Text=[External_Tag clause]}
418
419 Small clause
420
421 Bit_Order clause
422
423 Storage_Pool clause
424
425 Storage_Size clause
426
427
428 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
429 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00270-01]}
430 @Chg{Version=[1],New=[@Chg{Version=[2],New=[Stream_Size clause],Old=[]}],Old=[Read clause]}
431
432 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
433 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0005-1]}
434 @Chg{Version=[1],New=[@Chg{Version=[5],New=[pragma Unchecked_Union],Old=[]}],Old=[Write clause]}
435
436 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
437 @ChgDeleted{Version=[1],Text=[Input clause]}
438
439 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0009],ARef=[AI95-00137-01]}
440 @ChgDeleted{Version=[1],Text=[Output clause]}
441
442 Machine_Radix clause
443
444 pragma Pack
445
446 pragmas Import, Export, and Convention (when applied to a type)
447
448 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
449 pragmas Atomic@Chg{Version=[3],New=[, Independent,],Old=[]} and Volatile
450 (when applied to a type)
451
452 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
453 pragmas Atomic_Components@Chg{Version=[3],New=[, Independent_Components,],Old=[]}
454 and Volatile_Components (when applied to @Chg{Version=[3],New=[a],Old=[an
455 array]} type)
456
457 pragma Discard_Names (when applied to an enumeration or tagged type)
458
459 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
460 @ChgAdded{Version=[5],Text=[pragmas Priority and Interrupt_Priority (when applied
461 to a task or protected type)]}
462
463 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
464 @ChgAdded{Version=[5],Text=[pragma CPU (when applied
465 to a task or protected type)]}
466
467 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
468 @ChgAdded{Version=[5],Text=[pragma Dispatching_Domain]}
469
470 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
471 @ChgAdded{Version=[5],Text=[pragma Relative_Deadline (when applied
472 to a task or protected type)]}
473
474 @end{Itemize}
475
476 @Leading@;The following representation items are subtype-specific:
477 @begin{Itemize}
478 Alignment clause (when applied to a first subtype)
479
480 Size clause (when applied to a first subtype)
481 @end{Itemize}
482
483 @Leading@;The following representation items do not apply to subtypes,
484 so they are neither type-related nor subtype-specific:
485 @begin{Itemize}
486 Address clause (applies to objects and program units)
487
488 Alignment clause (when applied to an object)
489
490 Size clause (when applied to an object)
491
492 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]}
493 @ChgAdded{Version=[2],Text=[pragma Inline (applies to subprograms)]}
494
495 pragmas Import, Export, and Convention (when applied to anything other
496 than a type)
497
498 pragmas Atomic and Volatile (when applied to an object or a component)
499
500 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
501 pragmas Atomic_Components@Chg{Version=[3],New=[, Independent_Components,],Old=[]}
502 and Volatile_Components (when applied to an array object)
503
504 pragma Discard_Names (when applied to an exception)
505
506 pragma Asynchronous (applies to procedures)
507
508 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]}
509 @ChgAdded{Version=[2],Text=[pragma No_Return (applies to subprograms)]}
510
511 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
512 @ChgAdded{Version=[5],Text=[pragmas Attach_Handler and Interrupt_Handler (apply
513 to protected units)]}
514
515 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
516 @ChgAdded{Version=[5],Text=[pragmas Priority and Interrupt_Priority (when applied
517 to a subprogram)]}
518
519 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
520 @ChgAdded{Version=[5],Text=[pragma CPU (when applied
521 to a subprogram)]}
522
523 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
524 @ChgAdded{Version=[5],Text=[pragma Relative_Deadline (when applied
525 to a subprogram)]}
526
527 @end{Itemize}
528
529 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
530 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
531 @ChgAdded{Version=[3],Text=[While an @nt{aspect_specification} is not
532 a representation item, a similar categorization applies to the aspect
533 that corresponds to each of these representation items@Chg{Version=[5],New=[.
534 In adition, there are representation],Old=[ (along with]}
535 aspects that do not have associated representation items@Chg{Version=[5],New=[],
536 Old=[)]}.]}
537
538 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
539 @ChgAdded{Version=[5],Type=[Leading],Text=[The following representation aspects
540 that do not have associated representation items are type-related:]}
541 @begin{Itemize}
542 @ChgRef{Version=[5],Kind=[Added]}
543 @ChgAdded{Version=[5],Text=[aspect Default_Value]}
544
545 @ChgAdded{Version=[5],Text=[aspect Default_Component_Value]}
546
547 @ChgAdded{Version=[5],Text=[aspect Exclusion_Functions]}
548
549 @ChgAdded{Version=[5],Text=[aspects Link_Name and External_Name (when applied to a type)]}
550
551 @ChgAdded{Version=[5],Text=[aspect Max_Entry_Queue_Length (when applied to a task or protected type)]}
552 @end{Itemize}
553
554 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
555 @ChgAdded{Version=[5],Text=[There are no subtype-specific representation aspects
556 that do not have associated representation items.]}
557
558 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
559 @ChgAdded{Version=[5],Type=[Leading],Text=[The following representation aspects
560 that do not have associated representation items also do not apply to subtypes, so
561 they are neither type-related nor subtype-specific:]}
562 @begin{Itemize}
563 @ChgRef{Version=[5],Kind=[Added]}
564 @ChgAdded{Version=[5],Text=[aspect Static (applies to expression functions)]}
565
566 @ChgAdded{Version=[5],Text=[aspect Synchronization (applies to procedures)]}
567
568 @ChgAdded{Version=[5],Text=[aspects Link_Name and External_Name (when applied to
569 anything other than a type)]}
570
571 @ChgAdded{Version=[5],Text=[aspect Max_Entry_Queue_Length (when applied to an entry)]}
572 @end{Itemize}
573 @end{Ramification}
574
575 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
576 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
577 @ChgAdded{Version=[1],Text=[An operational item @i<directly specifies> an @i<operational aspect>
578 of the @Chg{Version=[3],New=[entity],Old=[type of the subtype]} denoted by
579 the @nt{local_name}@Chg{Version=[3],New=[, except in
580 the case of a type-related operational item, whose @nt{local_name} shall
581 denote a first subtype, and which directly specifies an aspect of the
582 type of the subtype],Old=[. The @nt{local_name}
583 of an operational item shall denote a first subtype. An operational item that
584 names a subtype is type-related]}.
585 @RootDefn{operational aspect}
586 @Defn2{Term=[directly specified],
587 Sec=(of an operational aspect of an entity)}
588 @RootDefn2{Term=[type-related], Sec=(operational item)}
589 @Defn2{Term=[type-related], Sec=(aspect)}]}
590
591 @begin{Ramification}
592 @ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
593 @ChgAdded{Version=[1],Type=[Leading],Text=[The following operational items are
594 type-related:]}
595 @begin{Itemize}
596
597 @ChgRef{Version=[1],Kind=[AddedNormal]}
598 @ChgAdded{Version=[1],Text=[External_Tag clause]}
599
600 @ChgRef{Version=[1],Kind=[AddedNormal]}
601 @ChgAdded{Version=[1],Text=[Read clause]}
602
603 @ChgRef{Version=[1],Kind=[AddedNormal]}
604 @ChgAdded{Version=[1],Text=[Write clause]}
605
606 @ChgRef{Version=[1],Kind=[AddedNormal]}
607 @ChgAdded{Version=[1],Text=[Input clause]}
608
609 @ChgRef{Version=[1],Kind=[AddedNormal]}
610 @ChgAdded{Version=[1],Text=[Output clause]}
611
612 @end{Itemize}
613
614 @end{Ramification}
615
616
617 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
618 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0116-1]}
619 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0181-1],ARef=[AI12-0222-1]}
620 @Chg{Version=[5],New=[A representation item or operational item that directly
621 specifies an aspect of an entity shall
622 appear before the entity is frozen (see @RefSecNum{Freezing Rules}).],Old=[ A
623 representation item that directly specifies an aspect of a subtype or type shall appear after
624 the type is completely defined
625 (see @RefSecNum{Completions of Declarations})
626 and before the subtype or type is frozen (see
627 @RefSecNum{Freezing Rules}).@Chg{Version=[4],New=[],Old=[ If a
628 representation item @Chg{Version=[3],New=[or @nt{aspect_specification} ],Old=[]}is
629 given that directly specifies an aspect of an
630 entity, then it is illegal to give another representation item
631 @Chg{Version=[3],New=[or @nt{aspect_specification} ],Old=[]}that
632 directly specifies the same aspect of the entity.]}]}
633 @begin{Ramification}
634 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
635 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0222-1]}
636 The fact that a representation item @Chg{New=[(or operational item@Chg{Version=[5],New=[],Old=[,
637 see next paragraph]}) ],Old=[]}that directly specifies
638 an aspect of an entity is required to appear before the entity is frozen
639 prevents changing the representation of an entity
640 after using the entity in ways that require the representation to be known.
641 @end{Ramification}
642 @begin{Honest}
643 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
644 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0116-1]}
645 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[The rule preventing
646 multiple specification
647 is also intended to cover other ways to specify representation aspects,
648 such as obsolescent @nt{pragma} Priority. Priority is not a representation
649 pragma, and as such is neither a representation item nor an
650 @nt{aspect_specification}. Regardless, giving both a @nt{pragma} Priority
651 and an @nt{aspect_specification} for Priority is illegal. We didn't want
652 to complicate the wording solely to support obsolescent features.]}]}
653 @end{Honest}
654
655 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0181-1],ARef=[AI12-0222-1]}
656 @ChgAdded{Version=[5],Text=[An @nt{expression} or @nt{name} that freezes an
657 entity shall not occur within an @nt{aspect_specification} that specifies a
658 representation or operational aspect of that entity.]}
659
660 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
661 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
662 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0116-1]}
663 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0222-1]}
664 @ChgAdded{Version=[1],Text=[@Chg{Version=[5],New=[A representation aspect of
665 a subtype or type shall not be specified (whether
666 by a representation item or an @nt{aspect_specification}) before the type is
667 completely defined (see @RefSecNum{Completions of Declarations}).],Old=[An
668 operational item that directly specifies an
669 aspect of @Chg{Version=[3],New=[an entity],Old=[a type]} shall appear before the
670 @Chg{Version=[3],New=[entity],Old=[type]} is frozen (see
671 @RefSecNum{Freezing Rules}).@Chg{Version=[4],New=[],Old=[ If an operational
672 item @Chg{Version=[3],New=[or
673 @nt{aspect_specification} ],Old=[]}is given that directly specifies an aspect of
674 @Chg{Version=[3],New=[an entity],Old=[a type]}, then it is illegal to give
675 another operational item @Chg{Version=[3],New=[or @nt{aspect_specification}
676 ],Old=[]}that directly specifies the same aspect of the
677 @Chg{Version=[3],New=[entity],Old=[type]}.]}]}]}
678 @begin{Ramification}
679 @ChgRef{Version=[1],Kind=[AddedNormal]}
680 @ChgAdded{Version=[1],Text=[Unlike representation items, operational
681 items can be specified on
682 partial views. Since they don't affect the representation, the full
683 declaration need not be known to determine their legality.]}
684 @end{Ramification}
685
686 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0116-1]}
687 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0181-1]}@Comment{Just a paragraph number change}
688 @ChgAdded{Version=[4],Text=[If a representation item, operational item, or
689 @nt{aspect_specification} is given that directly specifies an aspect of an
690 entity, then it is illegal to give another representation item, operational
691 item, or @nt{aspect_specification} that directly specifies the same aspect of
692 the entity.]}
693
694 @begin{Ramification}
695 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0116-1]}
696 @ChgAdded{Version=[4],Text=[This rule applies to all aspects, not just
697 those that are operational aspects or representation aspects. For instance,
698 it applies to subtype predicates and type invariants.]}
699 @end{Ramification}
700 @begin{Honest}
701 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0116-1]}
702 @ChgAdded{Version=[4],Text=[This rule is also intended to cover other ways
703 to specify representation aspects,
704 such as obsolescent @nt{pragma} Priority. Priority is not a representation
705 pragma, and as such is neither a representation item nor an
706 @nt{aspect_specification}. Regardless, giving both a @nt{pragma} Priority
707 and an @nt{aspect_specification} for Priority is illegal. We didn't want
708 to complicate the wording solely to support obsolescent features.]}
709 @end{Honest}
710
711 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0106-1],ARef=[AI05-0295-1]}
712 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0116-1]}@Comment{Just a paragraph number change}
713 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0181-1]}@Comment{Just a paragraph number change}
714 @ChgAdded{Version=[3],Text=[Unless otherwise specified, it is illegal to
715 specify an operational or representation aspect of a generic formal
716 parameter.]}
717 @begin{Reason}
718 @ChgRef{Version=[3],Kind=[AddedNormal]}
719 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0064-2]}
720 @ChgAdded{Version=[3],Text=[Specifying an aspect on a generic formal
721 parameter implies an added contract for a generic unit. That contract
722 needs to be defined via generic parameter matching rules, and, as
723 aspects vary widely, that has to be done for each such aspect. Since
724 most aspects do not need this complexity@Chg{Version=[5],New=[],Old=[ (including
725 all language-defined aspects as of this writing)]}, we avoid the complexity
726 by saying that such contract-forming aspect specifications are banned unless
727 the rules defining them explicitly exist. Note that the method of
728 specification does not matter: @nt{aspect_specification}s, representation
729 items, and operational items are all covered by this
730 @Chg{Version=[5],New=[rule],Old=[(and similar) rules]}.]}
731 @end{Reason}
732
733 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
734 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0109-1]}
735 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0376-1]}
736 @Chg{Version=[5],New=[],Old=[For an untagged derived
737 type, ]}@Chg{Version=[3],New=[@Chg{Version=[5],New=[It],Old=[it]}
738 is illegal to specify a@Chg{Version=[5],New=[ nonconfirming],Old=[]}],Old=[no]}
739 type-related representation
740 @Chg{Version=[3],New=[aspect],Old=[items are allowed]}
741 @Chg{Version=[5],New=[for an untagged by-reference type @i<T> if it is derived
742 from ],Old=[if the parent type is]} a by-reference type, or
743 @Chg{Version=[5],New=[if one or more types],Old=[has any user-defined primitive
744 subprograms.]}@Chg{Version=[4],New=[@Chg{Version=[5],New=[],Old=[ Similarly,
745 it is illegal to specify a nonconfirming type-related representation aspect
746 for an untagged by-reference type after one or more types]} have been
747 derived from @Chg{Version=[5],New=[@i<T> prior
748 to the specification of the aspect],Old=[it]}.],Old=[]}
749 @begin{Ramification}
750 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
751 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
752 On the other hand, subtype-specific representation
753 @Chg{Version=[3],New=[aspects],Old=[items]} may
754 be @Chg{Version=[3],New=[specified],Old=[given]}
755 for the first subtype of such a type@Chg{New=[, as can operational
756 @Chg{Version=[3],New=[aspects],Old=[items]}],Old=[]}.
757 @end{Ramification}
758 @begin{Reason}
759 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1],ARef=[AI05-0295-1]}
760 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0109-1]}
761 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0376-1]}
762 The reason for forbidding
763 @Chg{Version=[3],New=[specification of ],Old=[]}type-related
764 representation @Chg{Version=[3],New=[aspects],Old=[items]} on
765 untagged by-reference types is because a change of representation
766 is impossible when passing by reference (to an inherited
767 subprogram).@Chg{Version=[4],New=[ (A by-reference object cannot be copied
768 to change its representation.)],Old=[]}@Chg{Version=[5],New=[],Old=[
769 The reason for forbidding
770 @Chg{Version=[3],New=[specification of ],Old=[]}type-related
771 representation @Chg{Version=[3],New=[aspects],Old=[items]} on
772 untagged types with user-defined primitive subprograms
773 was to prevent implicit change of representation for type-related
774 aspects of representation upon calling inherited subprograms,
775 because such changes of representation are likely to be
776 expensive at run time.
777 Changes of subtype-specific representation attributes, however, are
778 likely to be cheap.]}
779 This rule is not needed for tagged types,
780 because other rules prevent a type-related representation
781 @Chg{Version=[3],New=[aspect],Old=[item]}
782 from changing the representation of the parent part;
783 we want to allow
784 @Chg{Version=[3],New=[specifying ],Old=[]}a type-related
785 representation @Chg{Version=[3],New=[aspect],Old=[item]}
786 on a type extension to specify aspects of the extension part.
787 For example, @Chg{Version=[3],New=[specifying aspect],Old=[a @nt{pragma}]}
788 Pack will cause packing of the extension part, but not of the parent part.
789 @end{Reason}
790 @begin{Discussion}
791 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0109-1]}
792 @ChgAdded{Version=[4],Text=[@Ldquote@;By-reference type@rdquote usually
793 cannot be used in @LegalityTitle, as it is privacy breaking. Our use here
794 is privacy breaking, but we're stuck with it for compatibility reasons.
795 Since representation aspects cannot be specified on partial views, privacy
796 violations only can happen when a type includes a component of a private type.
797 In that case, whether these rules are triggered depends on the full type of
798 the private type @em which is clearly privacy breaking.]}
799 @end{Discussion}
800
801 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01],Ref=[8652/0011],ARef=[AI95-00117-01]}
802 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
803 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
804 @Chg{New=[Operational and representation],Old=[Representation]} aspects of
805 a generic formal parameter are the same as those of the actual.
806 @Chg{New=[Operational and representation aspects
807 @Chg{Version=[2],New=[],Old=[of a partial view ]}are the
808 same @Chg{Version=[2],New=[for all views of a type],Old=[as those of the full view]}.],Old=[]}
809 @Chg{Version=[3],New=[Specification of a],Old=[A]}
810 type-related representation @Chg{Version=[3],New=[aspect],Old=[item]}
811 is not allowed for a descendant of a generic formal untagged type.
812 @begin{Ramification}
813 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
814 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
815 @Chg{Version=[3],New=[Specifying representation aspects is],Old=[Representation
816 items are]} allowed for
817 types whose subcomponent types
818 or index subtypes are generic formal types.
819 @Chg{New=[@Chg{Version=[3],New=[Specifying operational
820 aspects],Old=[Operational items]} and subtype-related representation
821 @Chg{Version=[3],New=[aspects is],Old=[items are]}
822 allowed on descendants of generic formal types.],Old=[]}
823 @end{Ramification}
824 @begin{Reason}
825 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
826 Since it is not known whether a formal type has
827 user-defined primitive subprograms, specifying
828 type-related representation @Chg{Version=[3],New=[aspects],Old=[items]}
829 for them is not allowed, unless they are tagged (in which case only
830 the extension part is affected in any case).
831 @end{Reason}
832 @begin{Ramification}
833 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
834 @ChgAdded{Version=[2],Text=[All views of a type, including the incomplete
835 and partial views, have the same operational and representation aspects.
836 That's important so that the properties don't change when changing views.
837 While most aspects are not available for an incomplete view, we don't want
838 to leave any holes by not saying that they are the same.]}
839
840 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0083-1]}
841 @ChgAdded{Version=[3],Text=[However, this does not apply to objects.
842 Different views of an object can have
843 different representation aspects. For instance, an actual object passed
844 by reference and the associated formal parameter may have different values for
845 Alignment even though the formal parameter is merely a view of the
846 actual object. This is necessary to maintain the language design principle
847 that Alignments are always known at compile time.]}
848 @end{Ramification}
849
850 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
851 @Chg{Version=[3],New=[The specification of],Old=[A
852 representation item that specifies]} the Size@Chg{Version=[3],New=[ aspect],Old=[]}
853 for a given subtype, or the size or storage place for an object (including a component)
854 of a given subtype, shall allow for enough storage space to
855 accommodate any value of the subtype.
856
857 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
858 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
859 @Chg{Version=[3],New=[If a specification of a],Old=[A]}
860 representation @Chg{New=[or operational ],Old=[]}@Chg{Version=[3],New=[aspect],
861 Old=[item that]} is
862 not supported by the implementation@Chg{Version=[3],New=[, it ],Old=[]}is
863 illegal@Chg{Version=[3],New=[],Old=[,]} or raises an exception at run time.
864
865 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
866 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
867 @ChgAdded{Version=[2],Text=[A @nt{type_declaration} is illegal if it has one or
868 more progenitors, and a
869 @Chg{Version=[3],New=[nonconfirming value was specified
870 for a ],Old=[]}representation
871 @Chg{Version=[3],New=[aspect of],Old=[item applies to]}
872 an ancestor, and this@Chg{Version=[3],New=[],Old=[ representation item]}
873 conflicts with the representation of
874 some other ancestor. The cases that cause conflicts are
875 implementation defined.]}
876 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
877 Text=[The cases that cause conflicts between the representation of
878 the ancestors of a @nt{type_declaration}.]}]}
879 @begin{Reason}
880 @ChgRef{Version=[2],Kind=[AddedNormal]}
881 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
882 @ChgAdded{Version=[2],Type=[Leading],Text=[This rule is needed because it may be the case
883 that only the combination of types in a type declaration causes a conflict.
884 Thus it is not possible, in general, to reject the original representation
885 item@Chg{Version=[3],New=[ or @nt{aspect_specification}],Old=[]}.
886 For instance:]}
887 @begin{Example}
888 @ChgRef{Version=[2],Kind=[AddedNormal]}
889 @ChgAdded{Version=[2],Text=[@key{package} Pkg1 @key{is}
890 @key{type} Ifc @key{is interface};
891 @key{type} T @key{is tagged record}
892 Fld : Integer;
893 @key{end record};
894 @key{for} T @key{use record}
895 Fld @key{at} 0 @key{range} 0 .. Integer'Size - 1;
896 @key{end record};
897 @key{end} Pkg1;]}
898 @end{Example}
899 @ChgRef{Version=[2],Kind=[AddedNormal]}
900 @ChgAdded{Version=[2],Type=[Leading],Text=[Assume the implementation uses a
901 single tag with a default offset of zero, and that it allows the use of
902 nondefault locations for the tag (and thus accepts representation items
903 like the one above). The representation item will force a nondefault
904 location for the tag (by putting a component other than the tag into the
905 default location). Clearly, this package will be accepted by the
906 implementation. However, other declarations could cause trouble. For
907 instance, the implementation could reject:]}
908 @begin{Example}
909 @ChgRef{Version=[2],Kind=[AddedNormal]}
910 @ChgAdded{Version=[2],Text=[@key{with} Pkg1;
911 @key{package} Pkg2 @key{is}
912 @key{type} NewT @key{is new} Pkg1.T @key{and} Pkg1.Ifc @key{with null record};
913 @key{end} Pkg2;]}
914 @end{Example}
915 @ChgRef{Version=[2],Kind=[AddedNormal]}
916 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
917 @ChgAdded{Version=[2],Text=[because the declarations of T and Ifc have a
918 conflict in their representation items. This is clearly necessary (it's hard
919 to imagine how Ifc'Class could work with the tag at a location other than the
920 one it is expecting@Chg{Version=[3],New=[ without introducing distributed
921 overhead],Old=[]}).]}@Comment{Make Steve happy.}
922
923 @ChgRef{Version=[2],Kind=[AddedNormal]}
924 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
925 @ChgAdded{Version=[2],Text=[Conflicts will usually involve
926 implementation-defined attributes (for specifying the location of the tag,
927 for instance), although the example above shows that doesn't have to be the
928 case. For this reason, we didn't try to specify exactly what causes a
929 conflict; it will depend on the implementation's implementation model and
930 what representation @Chg{Version=[3],New=[aspects],Old=[items]} it
931 allows@Chg{Version=[3],New=[ to be changed],Old=[]}.]}
932 @end{Reason}
933 @begin{ImplNote}
934 @ChgRef{Version=[2],Kind=[AddedNormal]}
935 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
936 @ChgAdded{Version=[2],Text=[An implementation can only use this rule to
937 reject @nt{type_declaration}s where one of its ancestors
938 @Chg{Version=[3],New=[had a nonconfirming],Old=[has a]} representation
939 @Chg{Version=[3],New=[value specified],Old=[item]}.
940 An implementation must ensure that
941 the default representations of ancestors cannot conflict.]}
942 @end{ImplNote}
943 @end{Legality}
944
945 @begin{StaticSem}
946 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
947 If two subtypes statically match, then their subtype-specific aspects
948 (@Chg{Version=[5],New=[for example, ],Old=[]}Size and Alignment)
949 are the same.
950 @PDefn2{Term=[statically matching],Sec=(effect on subtype-specific aspects)}
951 @begin{Reason}
952 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
953 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
954 This is necessary because we allow (for example)
955 conversion between access types whose designated subtypes
956 statically match.
957 Note that @Chg{Version=[3],New=[most aspects (including the subtype-specific
958 aspects Size and Alignment) may not be specified for a nonfirst subtype.
959 The only language-defined exceptions to this rule are the
960 @Chg{Version=[5],New=[Object_Size, ],Old=[]}Static_Predicate@Chg{Version=[5],New=[,],Old=[]}
961 and Dynamic_Predicate aspects.],Old=[it is illegal to specify an aspect
962 (including a subtype-specific one) for a nonfirst subtype.]}
963
964 @Leading@Keepnext@;Consider, for example:
965 @begin{Example}
966 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114}
967 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
968 @key[package] P1 @key[is]
969 @key[subtype] S1 @key[is] Integer @key[range] 0..2**16-1@Chg{Version=[5],New=[
970 @key[with] Size =>],Old=[;
971 @key[for] S1'Size @key[use]]} 16; --@RI{ Illegal!}
972 --@RI{ S1'Size would be 16 by default.}
973 @key[type] A1 @key[is] @key[access] @Chg{New=[@Key[all] ],Old=[]}S1;
974 X1: A1;
975 @key[end] P1;
976
977 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114}
978 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
979 @key[package] P2 @key[is]
980 @key[subtype] S2 @key[is] Integer @key[range] 0..2**16-1@Chg{Version=[5],New=[
981 @key[with] Size =>],Old=[;
982 @key[for] S2'Size @key[use]]} 32; --@RI{ Illegal!}
983 @key[type] A2 @key[is] @key[access] @Chg{New=[@Key[all] ],Old=[]}S2;
984 X2: A2;
985 @key[end] P2;
986
987 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00114}
988 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
989 @key[procedure] Q @key[is]
990 @key[use] P1, P2;
991 @key[type] Array1 @key[is] @key[array](Integer @key[range] <>) @key[of] @key[aliased] S1@Chg{Version=[3],New=[
992 @key[with] Pack],Old=[;
993 @key[pragma] Pack(Array1)]};
994 Obj1: Array1(1..100);
995 @key[type] Array2 @key[is] @key[array](Integer @key[range] <>) @key[of] @key[aliased] S2@Chg{Version=[3],New=[
996 @key[with] Pack],Old=[;
997 @key[pragma] Pack(Array2)]};
998 Obj2: Array2(1..100);
999 @key[begin]
1000 X1 := Obj2(17)'@Chg{New=[Unchecked_],Old=[]}Access;
1001 X2 := Obj1(17)'@Chg{New=[Unchecked_],Old=[]}Access;
1002 @key[end] Q;
1003 @end{Example}
1004
1005 Loads and stores through X1 would read and write 16 bits,
1006 but X1 points to a 32-bit location.
1007 Depending on the endianness of the machine,
1008 loads might load the wrong 16 bits.
1009 Stores would fail to zero the other half in any case.
1010
1011 Loads and stores through X2 would read and write 32 bits,
1012 but X2 points to a 16-bit location.
1013 Thus, adjacent memory locations would be trashed.
1014
1015 Hence, the above is illegal.
1016 Furthermore, the compiler is forbidden from choosing different
1017 Sizes by default, for the same reason.
1018
1019 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
1020 The same issues apply to Alignment.@Chg{Version=[5],New=[ Similar issues
1021 apply to Object_Size, Static_Predicate, and Dynamic_Predicate, but the
1022 chosen solution is different: explicit rules in
1023 @RefSecNum{Statically Matching Constraints and Subtypes} to ensure that
1024 the aspects are the same if specified.],Old=[]}
1025
1026 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
1027 @ChgAdded{Version=[5],Text=[The above static matching rule combined
1028 with the definition of static matching in
1029 @RefSecNum{Statically Matching Constraints and Subtypes} (after updating to
1030 add Object_Size) does not cause incompatibilities in existing Ada 2012 code
1031 that does not mention Object_Size. But it does constrain the
1032 implementation-defined value of Object_Size when it is not specified for a
1033 subtype; the above rule applies even in that case. (The effects noted in the
1034 example above would occur otherwise.)]}
1035
1036 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
1037 @ChgAdded{Version=[5],Text=[We need this rule even though static matching
1038 explicitly excludes confirming values of Object_Size. That's because a general
1039 access type can designate any aliased object whose subtype statically matches
1040 the the designated subtype. Since the Object_Size of a subtype determines the
1041 number of bits allocated for an aliased object of the subtype, if we allowed
1042 different Object_Sizes for statically matching subtypes, we'd be allowing the
1043 access type to designate objects with differing numbers of bits. That isn't
1044 going to work.]}
1045 @end{Reason}
1046
1047 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]}
1048 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1],ARef=[AI05-0295-1]}
1049 A derived type inherits each type-related
1050 @Chg{Version=[3],New=[representation ],Old=[]}aspect
1051 @Chg{Version=[3],New=[],Old=[@Chg{New=[of representation ],Old=[]}]}of
1052 its parent type that
1053 was directly specified before the declaration of the derived type,
1054 or (in the case where the parent is derived)
1055 that was inherited by the parent type from the grandparent type.
1056 A derived subtype inherits each subtype-specific
1057 @Chg{Version=[3],New=[representation ],Old=[]}aspect
1058 @Chg{Version=[3],New=[],Old=[@Chg{New=[of representation ],Old=[]}]}of
1059 its parent subtype that
1060 was directly specified before the declaration of the derived type,
1061 or (in the case where the parent is derived)
1062 that was inherited by the parent subtype from the grandparent subtype,
1063 but only if the parent subtype statically matches the first subtype of
1064 the parent type.
1065 An inherited @Chg{Version=[3],New=[representation ],Old=[]}aspect
1066 @Chg{Version=[3],New=[],Old=[of representation ]}is
1067 overridden by a subsequent
1068 @Chg{Version=[3],New=[@nt{aspect_specification} or ],Old=[]}representation
1069 item that specifies @Chg{Version=[3],New=[a different value for ],Old=[]}the
1070 same aspect of the type or subtype.
1071 @begin{Honest}
1072 A @nt{record_representation_clause} for a record extension
1073 does not override the layout of the parent part;
1074 if the layout was specified for the parent type,
1075 it is inherited by the record extension.
1076 @end{Honest}
1077 @begin{Ramification}
1078 If a representation item for the parent appears after the
1079 @nt{derived_@!type_@!definition},
1080 then inheritance does not happen for that representation item.
1081
1082 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0295-1]}
1083 @ChgAdded{Version=[3],Text=[If an inherited aspect is confirmed by
1084 an @nt{aspect_specification} or a later representation item for a derived type,
1085 the confirming specification does
1086 not override the inherited one. Thus the derived type has both a specified
1087 confirming value and an inherited nonconfirming representation value @em this
1088 means that rules that apply only to nonconfirming representation values still
1089 apply to this type.]}
1090
1091 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0109-1]}
1092 @ChgAdded{Version=[4],Text=[If an aspect was specified by an
1093 @nt{aspect_specification} and the parent type has not yet been frozen, then
1094 the inherited aspect might not yet have been resolved and evaluated. The
1095 implementation will need to have a mechanism to handle such an aspect.]}
1096 @end{Ramification}
1097
1098 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
1099 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]}
1100 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1],ARef=[AI05-0295-1]}
1101 @ChgAdded{Version=[1],Text=[In contrast, whether operational aspects are
1102 inherited by @Chg{Version=[3],New=[a],Old=[@Chg{Version=[2],New=[an untagged],Old=[a]}]}
1103 derived type depends on each specific aspect@Chg{Version=[3],New=[; unless specified,
1104 an operational aspect is not inherited],Old=[]}. @Chg{Version=[3],New=[],
1105 Old=[@Chg{Version=[2],New=[@Redundant[Operational aspects are never inherited
1106 for a tagged type.] ],Old=[]}]}When operational aspects are
1107 inherited by @Chg{Version=[3],New=[a],Old=[@Chg{Version=[2],New=[an untagged],Old=[a]}]} derived type,
1108 aspects that were directly specified @Chg{Version=[2],New=[by
1109 @Chg{Version=[3],New=[@nt{aspect_specification}s or ],Old=[]}operational
1110 items that are visible at the point],Old=[before the declaration]} of
1111 the derived type@Chg{Version=[2],New=[ declaration],Old=[]}, or
1112 (in the case where the parent is derived)
1113 that were inherited by the parent type from the grandparent type are inherited.
1114 An inherited operational aspect is overridden by a subsequent
1115 @Chg{Version=[3],New=[@nt{aspect_specification} or ],Old=[]}operational
1116 item that specifies the same aspect of the type.]}
1117 @begin{Ramification}
1118 @ChgRef{Version=[1],Kind=[Added]}
1119 @ChgAdded{Version=[1],Text=[As with representation items, if an operational
1120 item for the parent appears after the @nt{derived_@!type_@!definition}, then
1121 inheritance does not happen for that operational item.]}
1122 @end{Ramification}
1123 @begin{Discussion}
1124 @ChgRef{Version=[1],Kind=[Added]}
1125 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]}
1126 @ChgRef{Version=[3],Kind=[DeletedAddedNoDelMsg],ARef=[AI05-0183-1]}
1127 @ChgDeleted{Version=[3],Text=[@Chg{Version=[1],New=[@Chg{Version=[2],New=[Only],Old=[Currently, only]}
1128 untagged types inherit operational aspects.
1129 @Chg{Version=[2],New=[Inheritance from tagged types causes problems, as the
1130 different views can have different visibility on operational items @em
1131 potentially leading to operational items that depend on the view. We want
1132 aspects to be the same for all views. Untagged types don't have this problem
1133 as plain private types don't have ancestors, and thus can't inherit anything.
1134 In addition, it seems unlikely that we'll need inheritance for tagged types,
1135 as usually we'll want to incorporate the parent's operation into a new one that
1136 also handles any extension components.],Old=[We considered writing this rule
1137 that way, but rejected it as that could be too
1138 specific for future operational aspects. (After all, that is precisely the
1139 problem that caused us to introduce @lquotes@;operational aspects@rquotes in
1140 the first place.)]}],Old=[]}]}
1141 @end{Discussion}
1142
1143 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]}
1144 @ChgAdded{Version=[2],Text=[When an aspect that is a subprogram is inherited,
1145 the derived type inherits the aspect in the same way that a derived type
1146 inherits a user-defined primitive subprogram from its parent (see
1147 @RefSecNum{Derived Types and Classes}).]}
1148 @begin{Reason}
1149 @ChgRef{Version=[2],Kind=[AddedNormal]}
1150 @ChgAdded{Version=[2],Text=[This defines the parameter names and types,
1151 and the needed implicit conversions.]}
1152 @end{Reason}
1153
1154 @Leading@;Each aspect of representation of an entity is as follows:
1155 @begin{Itemize}
1156 @Defn2{Term=[specified],
1157 Sec=(of an aspect of representation of an entity)}
1158 If the aspect is @i{specified} for the entity,
1159 meaning that it is
1160 either directly specified or inherited,
1161 then that aspect of the entity is as specified,
1162 except in the case of Storage_Size,
1163 which specifies a minimum.
1164 @begin{Ramification}
1165 This rule implies that queries of the aspect return the
1166 specified value. For example, if the user writes @lquotes@;@key{for}
1167 X'Size @key{use} 32;@rquotes@;,
1168 then a query of X'Size will return 32.
1169 @end{Ramification}
1170
1171 @PDefn{unspecified}
1172 If an aspect of representation of an entity is not specified,
1173 it is chosen by default in an unspecified manner.
1174 @end{Itemize}
1175 @begin{Ramification}
1176 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1177 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1178 Note that @Chg{New=[@Chg{Version=[3],New=[specifying a ],Old=[]}representation
1179 @Chg{Version=[3],New=[aspect],Old=[items]}],Old=[@nt{representation_clause}s]}
1180 can affect the semantics of the entity.
1181
1182 The rules forbid things like
1183 @lquotes@;@key[for] S'Base'Alignment @key[use] ...@rquotes@;
1184 and
1185 @lquotes@;@key[for] S'Base @key[use] record ...@rquotes@;.
1186 @end{Ramification}
1187 @begin{Discussion}
1188 The intent is that implementations will represent the
1189 components of a composite value in the same way for all subtypes of a
1190 given composite type.
1191 Hence, Component_Size and record layout are type-related aspects.
1192 @end{Discussion}
1193 @begin{Ramification}
1194 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0083-1]}
1195 @ChgAdded{Version=[3],Text=[As noted previously, in the case of an
1196 object, the entity mentioned in this text is a specific view of an object. That
1197 means that only references to the same view of an object that has a specified
1198 value for a representation aspect @i<R> necessarily have that value for the
1199 aspect @i<R>. The value of the aspect @i<R> for a different view of that object
1200 is unspecified. In particular, this means that the representation values for
1201 by-reference parameters is unspecified; they do not have to be the same as those
1202 of the underlying object.]}
1203 @end{Ramification}
1204
1205 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
1206 @ChgAdded{Version=[1],Text=[@Defn2{Term=[specified], Sec=(of an operational aspect of an entity)}
1207 If an operational aspect is @i<specified> for an entity (meaning
1208 that it is either directly specified or inherited), then that aspect of the
1209 entity is as specified. Otherwise, the aspect of the entity has the default
1210 value for that aspect.]}
1211
1212 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
1213 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
1214 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[An @nt{aspect_specification}
1215 or ],Old=[A]}representation
1216 item that specifies @Chg{Version=[3],New=[a],Old=[an aspect of]}
1217 representation@Chg{Version=[3],New=[ aspect],Old=[]}
1218 that would have been chosen in the absence of the
1219 @Chg{Version=[3],New=[@nt{aspect_specification} or ],Old=[]}
1220 representation item is said to be
1221 @i{confirming}.@Defn2{Term=[confirming], Sec=(representation item)}@Chg{Version=[3],New=[
1222 The aspect value specified in this case is said to be a
1223 @i<confirming> representation aspect value. Other values of the aspect
1224 are said to be @i<nonconfirming>, as are the
1225 @nt{aspect_specification}s and representation items that specified
1226 them.@Defn2{Term=[confirming], Sec=(representation value)}
1227 @Defn2{Term=[confirming], Sec=(aspect specification)}
1228 @Defn2{Term=[nonconfirming], Sec=(representation value)}
1229 @Defn2{Term=[nonconfirming], Sec=(representation item)}
1230 @Defn2{Term=[nonconfirming], Sec=(aspect specification)}],Old=[]}]}
1231 @end{StaticSem}
1232
1233 @begin{RunTime}
1234 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1235 @Chg{New=[@PDefn2{Term=[elaboration], Sec=(aspect_clause)}],
1236 Old=[@PDefn2{Term=[elaboration], Sec=(representation_clause)}]}
1237 For the elaboration of @Chg{New=[an @nt{aspect_clause}],
1238 Old=[a @nt{representation_clause}]},
1239 any evaluable constructs within it are evaluated.
1240 @begin{Ramification}
1241 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1242 Elaboration of representation pragmas is covered by the
1243 general rules for pragmas in @Chg{Version=[3],New=[@RefSecNum{Pragmas}],Old=[Section 2]}.
1244 @end{Ramification}
1245 @end{RunTime}
1246
1247 @begin{ImplPerm}
1248 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1249 An implementation may interpret
1250 @Chg{Version=[3],New=[],Old=[aspects of
1251 ]}representation@Chg{Version=[3],New=[ aspects],Old=[]}
1252 in an implementation-defined manner.
1253 An implementation may place implementation-defined restrictions on
1254 @Chg{Version=[3],New=[the specification of ],Old=[]}representation
1255 @Chg{Version=[3],New=[aspects],Old=[items]}.
1256 @RootDefn{recommended level of support}
1257 A @i{recommended level of support} is
1258 @Chg{Version=[3],New=[defined],Old=[specified]} for
1259 @Chg{Version=[3],New=[the specification of ],Old=[]}representation
1260 @Chg{Version=[3],New=[aspects],Old=[items]}
1261 and related features in each subclause.
1262 These recommendations are changed to requirements
1263 for implementations that support the Systems Programming Annex
1264 (see @RefSec{Required Representation Support}).
1265
1266 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[0],Text=[The
1267 interpretation of each @Chg{Version=[3],New=[],Old=[aspect of
1268 ]}representation@Chg{Version=[3],New=[ aspect],Old=[]}.]}
1269
1270 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[0],Text=[Any restrictions
1271 placed upon @Chg{Version=[3],New=[the specification of ],Old=[]}representation
1272 @Chg{Version=[3],New=[aspects],Old=[items]}.]}
1273
1274 @begin{Ramification}
1275 Implementation-defined restrictions may be enforced either at compile
1276 time or at run time.
1277 There is no requirement that an implementation justify any such
1278 restrictions.
1279 They can be based on avoiding implementation complexity,
1280 or on avoiding excessive inefficiency, for example.
1281
1282 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
1283 @ChgAdded{Version=[1],Text=[There is no such permission for operational aspects.]}
1284 @end{Ramification}
1285 @end{ImplPerm}
1286
1287 @begin{ImplAdvice}
1288 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1289 @PDefn2{Term=[recommended level of support], Sec=(with respect to
1290 nonstatic expressions)}
1291 The recommended level of support for
1292 @Chg{Version=[3],New=[the specification of ],Old=[]}all representation
1293 @Chg{Version=[3],New=[aspects],Old=[items]}
1294 is qualified as follows:
1295 @begin{Itemize}
1296 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
1297 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0295-1]}
1298 @ChgAdded{Version=[2],Text=[A confirming
1299 @Chg{Version=[3],New=[specification for a ],Old=[]}representation
1300 @Chg{Version=[3],New=[aspect],Old=[item]}
1301 should be supported.]}
1302 @begin{Honest}
1303 @ChgRef{Version=[2],Kind=[AddedNormal]}
1304 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1305 @ChgAdded{Version=[2],Text=[A confirming representation
1306 @Chg{Version=[3],New=[aspect value],Old=[item]} might not be possible for some
1307 entities. For instance, consider an unconstrained array. The size of such a
1308 type is implementation-defined, and might not actually be a representable
1309 value, or might not be static.]}
1310 @end{Honest}
1311
1312 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1313 An implementation need not support @Chg{Version=[3],New=[the specification for
1314 a ],Old=[]}representation
1315 @Chg{Version=[3],New=[aspect that contains],Old=[items containing]}
1316 nonstatic expressions,
1317 @Chg{Version=[3],New=[unless],Old=[except that an implementation should
1318 support a representation item for a given entity if]} each nonstatic
1319 expression@Chg{Version=[3],New=[],Old=[ in the representation item]}
1320 is a @Chg{Version=[3],New=[@nt{name}],Old=[name]} that statically denotes
1321 a constant declared before the entity.
1322 @begin{Reason}
1323 @Leading@;This is to avoid the following sort of thing:
1324 @begin{Example}
1325 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
1326 X : Integer := F(...)@Chg{Version=[5],New=[
1327 @key[with] Address => Y],Old=[]};
1328 Y : Address := G(...);@Chg{Version=[5],New=[],Old=[
1329 @key[for] X'Address @key[use] Y;]}
1330 @end{Example}
1331
1332 In the above, we have to evaluate the initialization expression for X
1333 before we know where to put the result.
1334 This seems like an unreasonable implementation burden.
1335
1336 @Leading@;The above code should instead be written like this:
1337 @begin{Example}
1338 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]}
1339 Y : @key[constant] Address := G(...);
1340 X : Integer := F(...)@Chg{Version=[5],New=[
1341 @key[with] Address =>],Old=[;
1342 @key[for] X'Address @key[use]]} Y;
1343 @end{Example}
1344
1345 This allows the expression @lquotes@;Y@rquotes@; to be safely evaluated before X is
1346 created.
1347
1348 The constant could be a formal parameter of mode @key[in].
1349
1350 An implementation can support other nonstatic expressions if it wants
1351 to. Expressions of type Address are hardly ever static,
1352 but their value might be known at compile time anyway
1353 in many cases.
1354 @end{Reason}
1355
1356 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
1357 An implementation need not support a specification for the
1358 @Chg{Version=[5],New=[Object_Size or ],Old=[]}Size for a given composite
1359 subtype, nor the size or storage place for an object
1360 (including a component) of a given composite subtype, unless the constraints
1361 on the subtype and its composite subcomponents (if any)
1362 are all static constraints.
1363
1364 @begin{Reason}
1365 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
1366 @ChgAdded{Version=[5],Text=[We don't want to require that Object_Size or Size
1367 be supported on types that might have a representation not completely
1368 specified at compile time, or are represented discontiguously, or are
1369 represented differently for different constraints.]}
1370 @end{Reason}
1371
1372 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
1373 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1374 @Chg{Version=[2],New=[An implementation need not support
1375 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1376 representation @Chg{Version=[3],New=[aspect value],Old=[item]}
1377 if it could cause an aliased object or an object of a
1378 by-reference type to be allocated at a nonaddressable location or, when the
1379 alignment attribute of the subtype of such an object is nonzero, at an address
1380 that is not an integral multiple of that alignment.],Old=[An aliased component,
1381 or a component whose type is by-reference, should always be allocated at an
1382 addressable location.]}
1383 @begin{Reason}
1384 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-0079}
1385 The intent is that access types, type System.Address,
1386 and the pointer used for a by-reference parameter should
1387 be implementable as a single machine address @em bit-field pointers
1388 should not be required.
1389 (There is no requirement that this implementation be used @em we just
1390 want to make sure @Chg{New=[it's],Old=[its]} feasible.)
1391 @end{Reason}
1392 @begin{ImplNote}
1393 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
1394 @Chg{Version=[2],New=[We want subprograms to be able to assume the properties
1395 of the types of their parameters inside of subprograms. While many objects
1396 can be copied to allow this
1397 (and thus do not need limitations), aliased or by-reference objects cannot
1398 be copied (their memory location is part of their identity). Thus,],
1399 Old=[Note that]}
1400 the above rule does not apply to types that merely allow
1401 by-reference parameter passing;
1402 for such types, a copy typically needs to be made at the call site
1403 when a bit-aligned component is passed as a parameter.
1404 @end{ImplNote}
1405
1406 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1407 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1408 @ChgAdded{Version=[2],Text=[An implementation need not support
1409 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1410 representation @Chg{Version=[3],New=[aspect value],Old=[item]}
1411 if it could cause an aliased object of an elementary type
1412 to have a size other than that which would have been chosen by default.]}
1413 @begin{Reason}
1414 @ChgRef{Version=[2],Kind=[AddedNormal]}
1415 @ChgAdded{Version=[2],Text=[Since all bits of elementary objects participate
1416 in operations, aliased objects must not have a different size than that
1417 assumed by users of the access type.]}
1418 @end{Reason}
1419
1420 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1421 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1422 @ChgAdded{Version=[2],Text=[An implementation need not support
1423 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1424 representation @Chg{Version=[3],New=[aspect value],Old=[item]}
1425 if it could cause an aliased object of a composite type, or
1426 an object whose type is by-reference, to have a size smaller than that which
1427 would have been chosen by default.]}
1428 @begin{Reason}
1429 @ChgRef{Version=[2],Kind=[AddedNormal]}
1430 @ChgAdded{Version=[2],Text=[Unlike elementary objects, there is no
1431 requirement that all bits of a composite object participate in operations.
1432 Thus, as long as the object is the same or larger in size than that expected
1433 by the access type, all is well.]}
1434 @end{Reason}
1435 @begin{Ramification}
1436 @ChgRef{Version=[2],Kind=[AddedNormal]}
1437 @ChgAdded{Version=[2],Text=[This rule presumes that the implementation
1438 allocates an object of a size specified to be larger than the default size in
1439 such a way that access of the default size suffices to correctly read and
1440 write the value of the object.]}
1441 @end{Ramification}
1442
1443 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1444 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1445 @ChgAdded{Version=[2],Text=[An implementation need not support
1446 @Chg{Version=[3],New=[specifying ],Old=[]}a nonconfirming
1447 subtype-specific representation @Chg{Version=[3],New=[aspect value
1448 for],Old=[item specifying an aspect of representation of]}
1449 an indefinite or abstract subtype.]}
1450 @begin{Reason}
1451 @ChgRef{Version=[2],Kind=[AddedNormal]}
1452 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1453 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Representation aspects],
1454 Old=[Aspects of representations]} are often not
1455 well-defined for such types.]}
1456 @end{Reason}
1457
1458 @begin{Ramification}
1459 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00075}
1460 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
1461 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1462 @Chg{Version=[3],New=[A type with the Pack aspect specified],Old=[A pragma Pack]}
1463 will typically not @Chg{Version=[3],New=[be packed],Old=[pack]} so tightly as to
1464 disobey the above
1465 @Chg{Version=[2],New=[rules],Old=[rule]}. A Component_Size clause or
1466 @nt{record_representation_clause} will typically @Chg{New=[be],Old=[by]}
1467 illegal if it disobeys the above @Chg{Version=[2],New=[rules],Old=[rule]}.
1468 Atomic components have similar restrictions
1469 (see @RefSec{Shared Variable Control}).
1470 @end{Ramification}
1471 @end{Itemize}
1472
1473 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1474 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0295-1]}
1475 @ChgAdded{Version=[2],Text=[For purposes of these rules, the determination of
1476 whether @Chg{Version=[3],New=[specifying ],Old=[]}a
1477 representation @Chg{Version=[3],New=[aspect value for],Old=[item applied to]}
1478 a type @i{could cause} an object to have
1479 some property is based solely on the properties of the type itself, not on any
1480 available information about how the type is used. In particular, it presumes
1481 that minimally aligned objects of this type might be declared at some point.]}
1482 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1483 Text=[The recommended level of support for all representation items should be
1484 followed.]}]}
1485 @end{ImplAdvice}
1486
1487 @begin{Notes}
1488 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1489 @ChgAdded{Version=[3],Text=[Aspects that can be specified are defined
1490 throughout this International Standard, and are summarized in
1491 @RefSecNum{Language-Defined Aspects}.]}
1492 @end{Notes}
1493
1494
1495 @begin{Incompatible83}
1496 @Defn{incompatibilities with Ada 83}
1497 It is now illegal for a representation item to cause a derived
1498 by-reference type to have a different record layout from its
1499 parent.
1500 This is necessary for by-reference parameter passing to be feasible.
1501 This only affects programs that specify the representation of types
1502 derived from types containing tasks;
1503 most by-reference types are new to Ada 95.
1504 For example, if A1 is an array of tasks, and A2 is derived from A1,
1505 it is illegal to apply a @nt{pragma} Pack to A2.
1506 @end{Incompatible83}
1507
1508 @begin{Extend83}
1509 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1510 @Defn{extensions to Ada 83}
1511 Ada 95 allows additional @Chg{New=[@nt{aspect_clause}s],
1512 Old=[@nt{representation_clause}s]} for objects.
1513 @end{Extend83}
1514
1515 @begin{DiffWord83}
1516 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1517 The syntax rule for @ntf{type_representation_clause} is removed;
1518 the right-hand side of that rule is moved up to where it was used,
1519 in @Chg{New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]}.
1520 There are two references to @lquotes@;type representation clause@rquotes@; in RM83,
1521 both in Section 13; these have been reworded.
1522 @Chg{New=[Also, the @ntf{representation_clause} has been renamed the
1523 @nt{aspect_clause} to reflect that it can be used to control more than just
1524 representation aspects.],Old=[]}
1525
1526 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1527 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1528 We have defined a new term @lquotes@;representation item,@rquotes@;
1529 which includes @Chg{New=[all representation clauses],
1530 Old=[@nt{representation_clause}s]} and representation pragmas, as well as
1531 @nt<component_clause>s.
1532 This is convenient because the rules are almost identical for all @Chg{New=[of them],
1533 Old=[three]}. @Chg{New=[We have also defined the new terms
1534 @lquotes@;operational item@rquotes@; and @lquotes@;operational aspects@rquotes@;
1535 in order to conveniently handle new types of @Chg{Version=[2],New=[specifiable],Old=[specifable]} entities.],Old=[]}
1536
1537 All of the forcing occurrence stuff has been moved into its own
1538 subclause (see @RefSecNum{Freezing Rules}),
1539 and rewritten to use the term @lquotes@;freezing@rquotes@;.
1540
1541 RM83-13.1(10) requires implementation-defined restrictions on
1542 representation items to be enforced at compile time.
1543 However, that is impossible in some cases.
1544 If the user specifies a junk (nonstatic) address in an address
1545 clause, and the implementation chooses to detect the error (for example,
1546 using hardware memory management with protected pages), then it's
1547 clearly going to be a run-time error.
1548 It seems silly to call that @lquotes@;semantics@rquotes@; rather than
1549 @lquotes@;a restriction.@rquotes@;
1550
1551 RM83-13.1(10) tries to pretend that @ntf{representation_clause}s don't affect
1552 the semantics of the program.
1553 One counter-example is the Small clause.
1554 Ada 95 has more counter-examples.
1555 We have noted the opposite above.
1556
1557 Some of the more stringent requirements are moved to
1558 @RefSec{Required Representation Support}.
1559 @end{DiffWord83}
1560
1561 @begin{Extend95}
1562 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1563 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1564 @b[Amendment Correction:] Confirming representation items are
1565 defined, and the recommended level of support is now that they always
1566 be supported.]}
1567 @end{Extend95}
1568
1569 @begin{DiffWord95}
1570 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
1571 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added operational items
1572 in order to eliminate unnecessary restrictions and permissions on
1573 stream attributes. As part of this, @ntf{representation_clause} was
1574 renamed to @nt{aspect_clause}.]}
1575
1576 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01],ARef=[AI95-00326-01]}
1577 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to say that the
1578 partial and full views have the same operational and representation aspects.
1579 Ada 2005 extends this to cover all views, including the incomplete view.]}
1580
1581 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]}
1582 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed operational items
1583 to have inheritance specified for each such aspect.]}
1584
1585 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1586 @ChgAdded{Version=[2],Text=[Added wording to allow the rejection of
1587 types with progenitors that have conflicting representation items.]}
1588
1589 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
1590 @ChgAdded{Version=[2],Text=[The description of the representation of an
1591 object was clarified (with great difficulty reaching agreement). Added
1592 wording to say that representation items on aliased and by-reference objects
1593 never need be supported if they would not be implementable without
1594 distributed overhead even if other recommended level of support says
1595 otherwise. This wording matches the rules with reality.]}
1596
1597 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00444-01]}
1598 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
1599 @ChgAdded{Version=[2],Text=[Added wording so that inheritance depends on
1600 whether operational items are visible rather than whether they occur before
1601 the declaration (we don't want to look into private parts).
1602 @Chg{Version=[3],New=[Also limited],Old=[Limited]}
1603 operational inheritance to untagged types to avoid
1604 @Chg{Version=[3],New=[anomalies],Old=[anomolies]} with private extensions
1605 (this is not incompatible, no existing operational attribute used this
1606 capability). Also added wording to clearly define that subprogram inheritance
1607 works like derivation of subprograms.]}
1608 @end{DiffWord95}
1609
1610 @begin{Incompatible2005}
1611 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0106-1]}
1612 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
1613 Specifying a language-defined aspect for a generic formal parameter is no
1614 longer allowed. Most aspects could not be specified on these anyway; moreover,
1615 this was not allowed in Ada 83, so it is unlikely that compilers are
1616 supporting this as a capability (and it is not likely that they have a
1617 consistent definition of what it means if it is allowed). Thus, we expect
1618 this to occur rarely in existing programs.]}
1619 @end{Incompatible2005}
1620
1621 @begin{DiffWord2005}
1622 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1]}
1623 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined that overriding of
1624 an representation aspect only happens for a nonconfirming representation
1625 item. This prevents a derived type from being considered to have
1626 only a confirming representation item when the value would be nonconfirming
1627 if given on a type that does not inherit any aspects of representation.
1628 This change just eliminates a wording confusion and ought not change any
1629 behavior.]}
1630
1631 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0112-1]}
1632 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined a default naming for
1633 representation aspects that are representation pragmas.]}
1634
1635 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1636 @ChgAdded{Version=[3],Text=[Added text ensuring that the rules for
1637 representational and operational items also apply appropriately to
1638 @nt{aspect_specification}s; generalized operational aspects so that they
1639 can be defined for entities other than types. Any extensions are documented
1640 elsewhere.]}
1641
1642 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0295-1]}
1643 @ChgAdded{Version=[3],Text=[Rewrote many rules to be in terms of
1644 "specifying a representation aspect" rather than use of
1645 a "representation item". This better separates @i<how> an aspect is
1646 specified from @i<what> rules apply to the value of the aspect.]}
1647 @end{DiffWord2005}
1648
1649 @begin{Incompatible2012}
1650 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0109-1]}
1651 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
1652 Added a rule that makes it illegal to specify a representation value after
1653 a type is derived from an untagged by-reference type. This restriction is
1654 incompatible, but since the implementation would have had to copy an object
1655 that does not allow copying in order to change the representation for any
1656 implicit or explicit conversion between the original and the derived type,
1657 it is unlikely that any program could exist without running into internal
1658 compiler errors or bogus results.]}
1659
1660 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0181-1]}
1661 @ChgAdded{Version=[5],Text=[@b<Correction:> Added a rule preventing
1662 self-referencing representation or operational aspects. This is technically
1663 incompatible, but since the similar representation or operational item has
1664 been illegal since they've existed, and they don't make any sense, it's
1665 unlikely that any implementation accepted them or that they appear in any
1666 program.]}
1667
1668 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0222-1]}
1669 @ChgAdded{Version=[5],Text=[@b<Correction:> Added a rule preventing
1670 giving a representation aspect on a partial view. Since this has always
1671 been prohibited for other kinds of representation items, it's unlikely
1672 that any implementation accepted them or that they appear in any program.]}
1673 @end{Incompatible2012}
1674
1675 @begin{Extend2012}
1676 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0376-1]}
1677 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
1678 It is now allowed to specify type-related representation aspects for an
1679 untagged derived type that has primitive operations, so long as the type is
1680 not a by-reference type.]}
1681 @end{Extend2012}
1682
1683 @begin{DiffWord2012}
1684 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0116-1]}
1685 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that an aspect
1686 (any aspect) can be specified only once for an entity, no matter what
1687 means of specifying it are used. We did not document this as an
1688 incompatibility as only aspects that are neither operational nor
1689 representation could change behavior and there is no known implementation
1690 of these new aspects that allows multiple definitions.]}
1691
1692 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
1693 @ChgAdded{Version=[5],Text=[Added wording changes to support Object_Size.]}
1694 @end{DiffWord2012}
1695
1696
1697 @LabeledAddedSubClause{Version=[3],Name=[Aspect Specifications]}
1698
1699 @begin{Intro}
1700 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1701 @ChgAdded{Version=[3],Text=[@Redundant[Certain representation or operational
1702 aspects of an entity may be specified as part of its declaration using an
1703 @nt{aspect_specification}, rather than using a separate representation or
1704 operational item.] The declaration with the @nt{aspect_specification} is termed
1705 the @i{associated declaration}.@Defn2{Term=[associated declaration],Sec=[of an
1706 aspect specification]}]}
1707 @end{Intro}
1708
1709 @begin{Syntax}
1710 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1711 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<aspect_specification>,Old=<>}>,
1712 rhs=`@Chg{Version=[3],New="
1713 @key[with] @Syn2{aspect_mark} [=> @Syn2{aspect_definition}] {,
1714 @Syn2{aspect_mark} [=> @Syn2{aspect_definition}] }",Old=<>}'}
1715
1716 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1717 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<aspect_mark>,Old=<>}>,
1718 rhs="@Chg{Version=[3],New=<@SynI<aspect_>@Syn2<identifier>['Class]>,Old=<>}"}
1719
1720 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1721 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0187-1],ARef=[AI12-0285-1],ARef=[AI12-0373-1]}
1722 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<aspect_definition>,Old=<>}>,
1723 rhs="@Chg{Version=[5],New=[
1724 ],Old=[]}@Chg{Version=[3],New=<@Syn2<name> | @Syn2<expression> | @Syn2<identifier>@Chg{Version=[5],New=[
1725 | @Syn2<aggregate> | @Syn2<global_aspect_definition>],Old=[]}>,Old=<>}"}
1726
1727 @end{Syntax}
1728
1729 @begin{Metarules}
1730 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1731 @ChgAdded{Version=[3],Text=[The @nt{aspect_specification} is an
1732 optional element in most kinds of declarations. Here is a list
1733 of all kinds of declarations and an indication
1734 of whether or not they allow aspect clauses, and in some cases
1735 a short discussion of why (* = allowed, NO = not allowed). Kinds
1736 of declarations with no indication are followed by their subdivisions
1737 (which have indications).]}
1738
1739 @begin{Display}
1740 @ChgRef{Version=[3],Kind=[AddedNormal]}
1741 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
1742 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0061-1]}
1743 @ChgAdded{Version=[3],Text=[@nt{basic_declaration}
1744 @nt{type_declaration}
1745 @nt{full_type_declaration}
1746 @i<type declaration syntax>*
1747 @nt{task_type_declaration}*
1748 @nt{protected_type_declaration}*
1749 @nt{incomplete_type_declaration} -- NO
1750 -- @Examcom{Incomplete type aspects cannot be read by an attribute or specified by @nt{attribute_definition_clause}s }
1751 -- @Examcom{(the attribute name is illegal), so it would not make sense to allow this in another way.}
1752 @nt{private_type_declaration}*
1753 @nt{private_extension_declaration}*
1754 @nt{subtype_declaration}*
1755 @nt{object_declaration}
1756 @i<object declaration syntax>*
1757 @nt{single_task_declaration}*
1758 @nt{single_protected_declaration}*
1759 @nt{number_declaration} -- NO@Chg{Version=[5],New=[
1760 @nt{iterated_component_association} -- NO],Old=[]}
1761 @nt{subprogram_declaration}*
1762 @nt{abstract_subprogram_declaration}*
1763 @nt{null_procedure_declaration}*@Chg{Version=[4],New=[
1764 @nt{expression_function_declaration}*],Old=[]}
1765 @nt{package_declaration}* -- @Examcom{via} @nt{package_specification}
1766 @nt{renaming_declaration}*
1767 -- @Examcom{There are no language-defined aspects that may be specified}
1768 -- @Examcom{on renames, but implementations might support some.}
1769 @nt{exception_declaration}*
1770 @nt{generic_declaration}
1771 @nt{generic_subprogram_declaration}*
1772 @nt{generic_package_declaration}* -- @Examcom{via} @nt{package_specification}
1773 @nt{generic_instantiation}*
1774 @nt{enumeration_literal_specification} -- NO
1775 @nt{discriminant_specification} -- NO
1776 @nt{component_declaration}*
1777 @nt{loop_parameter_specification} -- NO@Chg{Version=[5],New=[
1778 @nt{chunk_specification} -- NO],Old=[]}
1779 @nt{iterator_specification} -- NO@Chg{Version=[5],New=[
1780 @nt{iterator_parameter_specification} -- NO],Old=[]}
1781 @nt{parameter_specification} -- NO
1782 @nt{subprogram_body}* -- @Examcom{ - but language-defined aspects only if there is no explicit specification}
1783 @nt{entry_declaration}*
1784 @nt{entry_index_specification} -- NO
1785 @nt{subprogram_body_stub}* -- @Examcom{ - but language-defined aspects only if there is no explicit specification}
1786 @nt{choice_parameter_specification} -- NO
1787 @nt{generic_formal_parameter_declaration}
1788 -- @Examcom{There are no language-defined aspects that may be specified}
1789 -- @Examcom{on generic formals, but implementations might support some.}
1790 @nt{formal_object_declaration}*
1791 @nt{formal_type_declaration}*
1792 @nt{formal_subprogram_declaration}
1793 @nt{formal_concrete_subprogram_declaration}*
1794 @nt{formal_abstract_subprogram_declaration}*
1795 @nt{formal_package_declaration}*
1796 @nt{extended_return_statement} -- NO]}
1797
1798 @ChgRef{Version=[3],Kind=[AddedNormal]}
1799 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0169-1]}
1800 @ChgAdded{Version=[3],Text=[-- @Examcom{We also allow @nt{aspect_specification}s on all kinds of bodies, but are no language-defined aspects}
1801 -- @Examcom{that may be specified on a body. These are allowed for implementation-defined aspects.}
1802 -- @Examcom{See above for subprogram bodies and stubs (as these can be declarations).}
1803 @nt{package_body}*
1804 @nt{task_body}*
1805 @nt{protected_body}*@Chg{Version=[5],New=[
1806 @nt{entry_body}*],Old=[]}
1807 @nt{package_body_stub}*
1808 @nt{task_body_stub}*
1809 @nt{protected_body_stub}*]}
1810 @end{Display}
1811
1812 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0267-1]}
1813 @ChgAdded{Version=[3],Text=[Syntactically, @nt{aspect_specification}s
1814 generally are located at the end of declarations. When a declaration is all in
1815 one piece such as a @nt{null_procedure_declaration}, @nt{object_declaration},
1816 or @nt{generic_instantiation} the @nt{aspect_specification} goes at the end of
1817 the declaration; it is then more visible and less likely to interfere with the
1818 layout of the rest of the structure. However, we make an exception for program
1819 units (other than subprogram specifications) and bodies, in which the
1820 @nt{aspect_specification} goes before the @key[is]. In these cases, the entity
1821 could be large and could contain other declarations that also have
1822 @nt{aspect_specification}s, so it is better to put the
1823 @nt{aspect_specification} toward the top of the declaration. (Some aspects @en
1824 such as Pure @en also affect the legality of the contents of a unit, so it
1825 would be annoying to only see those after reading the entire unit.)]}
1826
1827 @end{Metarules}
1828
1829 @begin{Resolution}
1830
1831 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1832 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0212-1]}
1833 @ChgAdded{Version=[3],Type=[Leading],Text=[An @nt{aspect_mark} identifies an
1834 aspect of the entity defined by the associated declaration (the @i<associated
1835 entity>@Defn2{Term=[associated entity],Sec=[of an aspect specification]}); the
1836 aspect denotes an object, a value, an expression, @Chg{Version=[5],New=[an
1837 @nt{aggregate}, ],Old=[]}a subprogram, or some other
1838 kind of entity. If the @nt{aspect_mark} identifies:]}
1839 @begin{Itemize}
1840
1841 @ChgRef{Version=[3],Kind=[AddedNormal]}
1842 @ChgAdded{Version=[3],Text=[an aspect that denotes an
1843 object, the @nt{aspect_definition} shall be a @nt{name}. The expected type for
1844 the @nt{name} is the type of the identified aspect of the associated
1845 entity;@PDefn2{Term=[expected type], Sec=[object in an @nt{aspect_specification}]}
1846 @Defn2{Term=[object],Sec=(required)}]}
1847
1848 @ChgRef{Version=[3],Kind=[AddedNormal]}
1849 @ChgAdded{Version=[3],Text=[an aspect that is
1850 a value or an expression, the @nt{aspect_definition} shall be an @nt{expression}.
1851 The expected type for the @nt{expression} is the type of the identified aspect
1852 of the associated
1853 entity;@PDefn2{Term=[expected type],
1854 Sec=[@nt{name} in an @nt{aspect_specification}]}@PDefn2{Term=[expected type],
1855 Sec=[@nt{expression} in an @nt{aspect_specification}]}]}
1856
1857 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1]}
1858 @ChgAdded{Version=[5],Text=[an aspect that is an @nt{aggregate}, the aspect
1859 definition shall be an @nt{expression} that is an @nt{aggregate}, with the form
1860 of the @nt{aggregate} determined by the identified aspect;]}
1861
1862 @begin{Ramification}
1863 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
1864 @ChgAdded{Version=[5],Text=[The only requirement here is that the
1865 @nt{expression} is syntactically an @nt{aggregate}; there is no requirement
1866 that it resolve to some particular type or even that it should resolve
1867 like an @nt{aggregate}. Each aspect that uses an @nt{aggregate} is responsible
1868 for specifying how the choice(s), component(s), and other contents of the
1869 @nt{aggregate} are resolved and interpreted.]}
1870 @end{Ramification}
1871
1872 @ChgRef{Version=[3],Kind=[AddedNormal]}
1873 @ChgAdded{Version=[3],Text=[an aspect that denotes a subprogram, the
1874 @nt{aspect_definition} shall be a @nt{name}; the expected profile for the @nt{name}
1875 is the profile required for the aspect of the associated
1876 entity;@PDefn2{Term=[expected profile], Sec=[@nt{name} in an @nt{aspect_specification}]}]}
1877
1878 @ChgRef{Version=[3],Kind=[AddedNormal]}
1879 @ChgAdded{Version=[3],Text=[an aspect that
1880 denotes some other kind of entity, the @nt{aspect_definition} shall be a
1881 @nt{name}, and the name shall resolve to denote an entity of the appropriate
1882 kind;]}
1883
1884 @ChgRef{Version=[3],Kind=[AddedNormal]}
1885 @ChgAdded{Version=[3],Text=[an aspect that is given by an identifier specific to
1886 the aspect, the @nt{aspect_definition} shall be an @nt{identifier}, and the
1887 @nt{identifier} shall be one of the identifiers specific to the identified
1888 aspect.]}
1889 @end{Itemize}
1890
1891 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1892 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0373-1]}
1893 @ChgAdded{Version=[3],Text=[The usage names in an @nt{aspect_definition}
1894 @Redundant[ are not resolved at the point of the associated declaration, but
1895 rather] are resolved at the end of the immediately enclosing declaration
1896 list@Chg{Version=[5],New=[, or in the case of the declaration of a library
1897 unit, at the end of the visible part of the entity],Old=[]}.]}
1898
1899 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1900 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0180-1],ARef=[AI12-0220-1]}
1901 @ChgAdded{Version=[3],Text=[If the associated declaration is for a
1902 subprogram@Chg{Version=[5],New=[,],Old=[ or]} entry, @Chg{Version=[5],New=[ or
1903 access-to-subprogram type,],Old=[]} the names of the formal parameters are
1904 directly visible within the
1905 @nt{aspect_definition}, as are certain attributes, as specified elsewhere in
1906 this International Standard for the identified aspect. If the associated
1907 declaration is a @nt{type_declaration}, within the @nt{aspect_definition} the
1908 names of any @Chg{Version=[5],New=[visible ],Old=[]}components@Chg{Version=[5],New=[,
1909 protected subprograms, and entries],Old=[]} are directly visible, and the name
1910 of the first subtype denotes the current instance of the type (see
1911 @RefSecNum{The Context of Overload Resolution}). If the associated declaration
1912 is a @nt{subtype_declaration}, within the @nt{aspect_definition} the name of
1913 the new subtype denotes the current instance of the subtype.]}
1914 @end{Resolution}
1915
1916 @begin{Legality}
1917 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1918 @ChgAdded{Version=[3],Text=[If the first freezing point of the associated entity
1919 comes before the end of the immediately enclosing declaration list, then each
1920 usage name in the @nt{aspect_definition} shall resolve to the same entity at the
1921 first freezing point as it does at the end of the immediately enclosing
1922 declaration list.]}
1923
1924 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1925 @ChgAdded{Version=[3],Text=[At most one occurrence of each @nt{aspect_mark} is
1926 allowed within a single @nt{aspect_specification}. The aspect identified by the
1927 @nt{aspect_mark} shall be an aspect that can be specified for the associated
1928 entity (or view of the entity defined by the associated declaration).]}
1929
1930 @begin{Ramification}
1931 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0116-1]}
1932 @ChgAdded{Version=[4],Text=[This rule prevents multiple specifications in the same
1933 @nt{aspect_specification}. Rules in @RefSecNum{Operational and Representation Aspects} prevent multiple specifications in
1934 different @nt{aspect_specification}s (on different views of the same type,
1935 for instance) or between operational or representation items and
1936 an @nt{aspect_specification}, even for aspects that are neither operational
1937 nor representation aspects.]}
1938
1939 @end{Ramification}
1940
1941 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1942 @ChgAdded{Version=[3],Text=[The @nt{aspect_definition} associated with a given
1943 @nt{aspect_mark} may be omitted only when the @nt{aspect_mark} identifies an
1944 aspect of a boolean type, in which case it is equivalent to the
1945 @nt{aspect_definition} being specified as True.]}
1946
1947 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
1948 @ChgAdded{Version=[3],Text=[If the @nt{aspect_mark} includes
1949 'Class, then the associated entity shall be a tagged type or a primitive
1950 subprogram of a tagged type.]}
1951
1952 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1953 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0064-2],ARef=[AI12-0194-1]}
1954 @ChgAdded{Version=[3],Text=[There are no language-defined aspects that
1955 may be specified on a @nt{renaming_declaration},
1956 @Chg{Version=[5],New=[],Old=[a @nt{generic_formal_parameter_declaration}, ]}a
1957 @nt{subunit}, a @nt{package_body}, a @nt{task_body}, a @nt{protected_body},
1958 @Chg{Version=[5],New=[an @nt{entry_body}, ],Old=[]}or a @nt{body_stub} other
1959 than a @nt{subprogram_body_stub}.]}
1960 @begin{Discussion}
1961 @ChgRef{Version=[3],Kind=[AddedNormal]}
1962 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0064-2]}
1963 @ChgAdded{Version=[3],Text=[Implementation-defined aspects can be allowed on
1964 these, of course; the implementation will need to define the semantics. In
1965 @Chg{Version=[5],New=[addition],Old=[particular]},
1966 @Chg{Version=[5],New=[the language does not define default aspect matching
1967 rules for generic formals; only the handful of aspects allowed on formals
1968 have such rules. Therefore, ],Old=[]}the implementation will need to define
1969 actual type matching rules for any aspects allowed on formal
1970 types@Chg{Version=[5],New=[],Old=[; there are no default matching
1971 rules defined by the language]}.]}
1972 @end{Discussion}
1973
1974 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1975 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0105-1]}
1976 @ChgAdded{Version=[3],Text=[A language-defined aspect shall not be specified in
1977 an @nt{aspect_specification} given on a
1978 @Chg{Version=[4],New=[],Old=[@nt{subprogram_body} or
1979 @nt{subprogram_body_stub} that is a ]}completion of @Chg{Version=[4],New=[a
1980 subprogram or generic subprogram],Old=[another declaration]}.]}
1981
1982 @begin{Reason}
1983 @ChgRef{Version=[3],Kind=[AddedNormal]}
1984 @ChgAdded{Version=[3],Text=[Most language-defined aspects (for example,
1985 preconditions) are intended to be available to callers, and specifying them
1986 on a body that has a separate declaration hides them from callers. Specific
1987 language-defined aspects may allow this, but they have to do so explicitly
1988 (by defining an alternative @LegalityName), and provide any needed rules
1989 about visibility. Note that this rule does not apply to
1990 implementation-defined aspects, so implementers need to carefully define
1991 whether such aspects can be applied to bodies and stubs, and what happens
1992 if they are specified on both the declaration and body of a unit.]}
1993 @end{Reason}
1994
1995 @ChgRef{Version=[4],Kind=[Added],ARef=[AI05-0183-1],ARef=[AI12-0138-1]}
1996 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0374-1]}
1997 @ChgAdded{Version=[4],Text=[If an aspect of a derived
1998 type@Chg{Version=[5],New=[ (or its first subtype)],Old=[]} is inherited from
1999 an ancestor @Chg{Version=[5],New=[(sub)type],Old=[type]} and has the boolean
2000 value True, the inherited value shall not be
2001 overridden to have the value False for the derived
2002 type@Chg{Version=[5],New=[ (or its first subtype)],Old=[]}, unless otherwise
2003 specified in this International Standard.@Chg{Version=[5],New=[ If an aspect
2004 of a nonfirst subtype is inherited from the subtype in the
2005 @nt{subtype_indication} that defines it, and has the value True, the
2006 inherited value shall not be overridden to have the value False for the
2007 nonfirst subtype, unless otherwise specified in this International Standard.],Old=[]}]}
2008
2009 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
2010 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0206-1]}
2011 @ChgAdded{Version=[4],Text=[Certain type-related aspects are defined to be
2012 @i<nonoverridable>@Chg{Version=[5],New=[],Old=[; all such aspects are specified
2013 using an @nt{aspect_definition} that is a
2014 @nt{name}]}.@Defn2{Term=[nonoverridable],Sec=[aspect]}]}
2015
2016 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
2017 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0206-1],ARef=[AI12-0211-1]}
2018 @ChgAdded{Version=[4],Text=[If a nonoverridable aspect is directly specified
2019 for a type @i<T>, then any explicit specification of that aspect for any
2020 @Chg{Version=[5],New=[],Old=[other ]}descendant of @i<T>
2021 @Chg{Version=[5],New=[(other than @i<T> itself) ],Old=[]}shall be
2022 @PDefn2{Term=[confirming],Sec=[nonoverridable aspect]}@i<confirming>@Chg{Version=[5],New=[.
2023 In the case of an aspect whose value is a @nt{name}, this means that],Old=[; that is,]}
2024 the specified @nt{name} shall @i<match>@Defn2{Term=[match],Sec=[value of nonoverridable aspect]}
2025 the inherited aspect@Chg{Version=[5],New=[ in the sense that it],Old=[, meaning that
2026 the specified @nt{name}]} shall denote the
2027 same declarations as would the inherited @nt{name}.]}
2028
2029 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
2030 @ChgAdded{Version=[4],Text=[If a full type has a partial view, and a given
2031 nonoverridable aspect is allowed for both the full view and the partial view,
2032 then the given aspect for the partial view and the full view shall be the same:
2033 the aspect shall be directly specified only on the partial view; if the full
2034 type inherits the aspect, then a matching definition shall be specified
2035 (directly or by inheritance) for the partial view.]}
2036
2037 @begin{Ramification}
2038 @ChgRef{Version=[4],Kind=[AddedNormal]}
2039 @ChgAdded{Version=[4],Text=[In order to enforce these rules without breaking
2040 privacy, we cannot allow a private type that could have a particular
2041 overridable aspect to have a hidden definition of that aspect. There is no
2042 problem if the private type does not allow the aspect (as the
2043 aspect could not be specified on descendants in that case).]}
2044 @end{Ramification}
2045
2046 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0211-1]}
2047 @ChgAdded{Version=[5],Text=[If a type inherits a nonoverridable aspect from
2048 multiple ancestors, the value of the aspect inherited from any given ancestor
2049 shall be confirming of the values inherited from all other ancestors.]}
2050
2051 @begin{Reason}
2052 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0005-1],ARef=[AI12-0211-1]}
2053 @ChgAdded{Version=[5],Text=[If more than one progenitor of a type @i<T>
2054 specifies a nonoverridable aspect, they all have to specify the same
2055 or matching values for that aspect. Otherwise, we'd have two different
2056 values for the aspect that depend on the view of the type; that would
2057 violate the definition of type aspects being the same for all views of
2058 a type.]}
2059 @end{Reason}
2060
2061 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
2062 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0211-1]}@Comment{Just to change the paragraph number}
2063 @ChgAdded{Version=[4],Text=[@PDefn{generic contract issue}
2064 In addition to the places where
2065 @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
2066 these rules about nonoverridable aspects also apply in the private part
2067 of an instance of a generic unit.]}
2068
2069 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
2070 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0206-1],ARef=[AI12-0256-1],ARef=[AI12-0373-1]}
2071 @ChgAdded{Version=[4],Text=[@Redundant[The Default_Iterator, Iterator_Element,
2072 Implicit_Dereference, Constant_Indexing, @Chg{Version=[5],New=[],Old=[and
2073 ]}Variable_Indexing@Chg{Version=[5],New=[, Aggregate, Max_Entry_Queue_Length, and
2074 No_Controlled_Parts],Old=[]} aspects are nonoverridable.]]}
2075
2076 @begin{Discussion}
2077 @ChgRef{Version=[4],Kind=[AddedNormal]}
2078 @ChgRef{Version=[5],Kind=[Revised]}
2079 @ChgAdded{Version=[4],Text=[We don't need an assume-the-worst rule for most
2080 nonoverridable aspects as they only work on tagged types and deriving from
2081 formal tagged types is not allowed in generic bodies. In the case of
2082 Implicit_Dereference, a derivation in a generic body does not cause problems
2083 (the ancestor necessarily cannot have the aspect, else specifying the aspect
2084 would be illegal), as there could be no place with visibility on both
2085 aspects.@Chg{Version=[5],New=[ In the case of Max_Entry_Queue_Length, it is
2086 only allowed on task and protected types, and on entries, and there are
2087 not formal versions of any of those things. In the case of
2088 No_Controlled_Parts, we defined an assume-the-worst rule with the aspect.],Old=[]}]}
2089 @end{Discussion}
2090
2091 @end{Legality}
2092
2093 @begin{StaticSem}
2094
2095 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2096 @ChgAdded{Version=[3],Type=[Leading],Text=[Depending on which aspect is
2097 identified by the @nt{aspect_mark}, an @nt{aspect_definition} specifies:]}
2098 @begin{Itemize}
2099 @ChgRef{Version=[3],Kind=[AddedNormal]}
2100 @ChgAdded{Version=[3],Text=[a @nt{name} that denotes a subprogram, object, or
2101 other kind of entity;]}
2102
2103 @ChgRef{Version=[3],Kind=[AddedNormal]}
2104 @ChgAdded{Version=[3],Text=[an @nt{expression}, which is either evaluated to
2105 produce a single value, or which (as in a precondition) is to be evaluated at
2106 particular points during later execution; or]}
2107
2108 @ChgRef{Version=[3],Kind=[AddedNormal]}
2109 @ChgAdded{Version=[3],Text=[an @nt{identifier} specific to the aspect.]}
2110 @end{Itemize}
2111
2112 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2113 @ChgAdded{Version=[3],Type=[Leading],Text=[The identified aspect of the
2114 associated entity, or in some cases, the view of the entity defined by the
2115 declaration, is as specified by the @nt{aspect_definition} (or by the default of
2116 True when boolean). Whether an @nt{aspect_specification} @i<applies> to an entity or
2117 only to the particular view of the entity defined by the declaration is
2118 determined by the @nt{aspect_mark} and the kind of entity. The following aspects
2119 are view specific:@PDefn2{Term=[applies],Sec=[aspect]}]}
2120
2121 @begin{Itemize}
2122
2123 @ChgRef{Version=[3],Kind=[AddedNormal]}
2124 @ChgAdded{Version=[3],Text=[An aspect specified on an @nt{object_declaration};]}
2125
2126 @ChgRef{Version=[3],Kind=[AddedNormal]}
2127 @ChgAdded{Version=[3],Text=[An aspect specified on a @nt{subprogram_declaration};]}
2128
2129 @ChgRef{Version=[3],Kind=[AddedNormal]}
2130 @ChgAdded{Version=[3],Text=[An aspect specified on a @nt{renaming_declaration}.]}
2131
2132 @end{Itemize}
2133
2134 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2135 @ChgAdded{Version=[3],Text=[All other @nt{aspect_specification}s are associated
2136 with the entity, and @i<apply> to all views of the entity, unless otherwise
2137 specified in this International Standard.@PDefn2{Term=[applies],Sec=[aspect]}]}
2138
2139 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2140 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0106-1]}
2141 @ChgAdded{Version=[3],Type=[Leading],Text=[If the @nt{aspect_mark} includes
2142 'Class@Chg{Version=[4],New=[ (a @i<class-wide
2143 aspect>)@Defn{class-wide aspect}@Defn2{Term=[aspect],Sec=[class-wide]}],Old=[]},
2144 then@Chg{Version=[4],New=[, unless specified otherwise for a particular
2145 class-wide aspect],Old=[]}:]}
2146 @begin{Itemize}
2147
2148 @ChgRef{Version=[3],Kind=[AddedNormal]}
2149 @ChgAdded{Version=[3],Text=[if the associated entity is a tagged type, the
2150 specification @i<applies> to all descendants of the type;@PDefn2{Term=[applies],Sec=[aspect]}]}
2151
2152 @ChgRef{Version=[3],Kind=[AddedNormal]}
2153 @ChgAdded{Version=[3],Text=[if the associated entity is a primitive subprogram
2154 of a tagged type @i<T>, the specification @i<applies> to the corresponding primitive
2155 subprogram of all descendants of @i<T>.@PDefn2{Term=[applies],Sec=[aspect]}]}
2156 @end{Itemize}
2157
2158 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0229-1]}
2159 @ChgAdded{Version=[3],Text=[All specifiable operational and representation
2160 attributes may be specified with an @nt{aspect_specification} instead of an
2161 @nt{attribute_definition_clause} (see
2162 @RefSecNum{Operational and Representation Attributes}).]}
2163
2164 @begin{Ramification}
2165 @ChgRef{Version=[3],Kind=[AddedNormal]}
2166 @ChgAdded{Version=[3],Text=[The name of the aspect is the same as that of the attribute
2167 (see @RefSecNum{Operational and Representation Attributes}), so the @nt{aspect_mark}
2168 is the @nt{attribute_designator} of the attribute.]}
2169
2170 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0005-1]}
2171 @ChgAdded{Version=[5],Text=[Unless specified otherwise, all of the
2172 requirements for specifying a particular aspect with an
2173 @nt{attribute_definition_clause} also apply to an @nt{aspect_specification}
2174 for the aspect. These are enforced at the freezing point of the entity. For
2175 example, when specifying the Size aspect of a subtype, the expression
2176 has to be a static expression with an integer type and a nonnegative
2177 value, all of the recommended level of support requirements apply if
2178 @RefSecNum{Systems Programming} is supported
2179 (see @RefSecNum{Required Representation Support}), and so on.]}
2180 @end{Ramification}
2181
2182 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
2183 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0154-1]}
2184 @ChgAdded{Version=[3],Text=[Any aspect specified by a representation pragma
2185 or library unit pragma that has a @nt{local_name} as its single argument
2186 may be specified by an @nt{aspect_specification}, with the entity being the
2187 @nt{local_name}. The @nt{aspect_definition} is expected to be of type Boolean.
2188 The expression shall be static.@Chg{Version=[4],New=[ Notwithstanding what
2189 this International Standard says elsewhere, the expression of an aspect that
2190 can be specified by a library unit pragma is resolved and evaluated at the
2191 point where it occurs in the @nt{aspect_specification}@Redundant[, rather
2192 than the first freezing point of the associated
2193 package].@Defn{Notwithstanding}],Old=[]}]}
2194
2195 @begin{Ramification}
2196 @ChgRef{Version=[3],Kind=[AddedNormal]}
2197 @ChgAdded{Version=[3],Text=[The name of the aspect is the same as that of the
2198 pragma (see @RefSecNum{Operational and Representation Aspects}), so the
2199 @nt{aspect_mark} is the name of the pragma.]}
2200 @end{Ramification}
2201
2202 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
2203 @ChgAdded{Version=[3],Text=[In addition,
2204 other operational and representation aspects not associated with specifiable
2205 attributes or representation pragmas may be specified, as specified elsewhere
2206 in this International Standard.]}
2207
2208 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2209 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0138-1]}
2210 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[],Old=[If an aspect of a
2211 derived type is inherited from an ancestor type and has the boolean value True,
2212 the inherited value shall not be overridden to have the value False for the
2213 derived type, unless otherwise specified in this International Standard.]}]}
2214
2215 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2216 @ChgAdded{Version=[3],Text=[If a @LegalityName or @StaticSemTitle rule only
2217 applies when a particular aspect has been specified, the aspect is considered to
2218 have been specified only when the @nt{aspect_specification} or
2219 @nt{attribute_definition_clause} is visible (see @RefSecNum{Visibility}) at the point
2220 of the application of the rule.]}
2221
2222 @begin{Reason}
2223 @ChgRef{Version=[3],Kind=[AddedNormal]}
2224 @ChgAdded{Version=[3],Text=[Some rules only apply when an aspect has been
2225 specified (for instance, an indexable type is one that has aspect
2226 Variable_Indexing specified). In order to prevent privacy breaking, this can
2227 only be true when the specification of the aspect is visible. In particular,
2228 if the Variable_Indexing aspect is specified on the full view of a private
2229 type, the private type is not considered an indexable type.]}
2230 @end{Reason}
2231
2232 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2233 @ChgAdded{Version=[3],Text=[Alternative legality and semantics rules may apply
2234 for particular aspects, as specified elsewhere in this International Standard.]}
2235
2236 @end{StaticSem}
2237
2238 @begin{Runtime}
2239 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2240 @ChgAdded{Version=[3],Text=[At the freezing point of the associated entity, the
2241 @nt{aspect_specification} is elaborated. The elaboration of the
2242 @nt{aspect_specification} includes the evaluation of the @nt{name} or
2243 @nt{expression}, if any, unless the aspect itself is an expression. If the
2244 corresponding aspect represents an expression (as in a precondition), the
2245 elaboration has no effect; the expression is evaluated later at points
2246 within the execution as specified elsewhere in this International Standard for
2247 the particular aspect.]}
2248 @end{Runtime}
2249
2250 @begin{ImplPerm}
2251 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
2252 @ChgAdded{Version=[3],Text=[Implementations may support implementation-defined
2253 aspects. The @nt{aspect_specification} for an implementation-defined aspect may
2254 use an implementation-defined syntax for the @nt{aspect_definition}, and may
2255 follow implementation-defined legality and semantics rules.]}
2256 @begin{Discussion}
2257 @ChgRef{Version=[3],Kind=[AddedNormal]}
2258 @ChgAdded{Version=[3],Text=[The intent is to allow implementations to support
2259 aspects that are defined, for example, by a @nt{subtype_indication} rather
2260 than an @nt{expression} or a @nt{name}. We chose not to try to enumerate all
2261 possible @nt{aspect_definition} syntaxes, but to give implementations maximum
2262 freedom. Unrecognized aspects are illegal whether or not they use custom
2263 syntax, so this freedom does not reduce portability.]}
2264 @end{Discussion}
2265 @ChgImplDef{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
2266 Text=[Implementation-defined aspects, including the syntax for specifying
2267 such aspects and the legality rules for such aspects.]}]}
2268 @end{ImplPerm}
2269
2270 @begin{Extend2005}
2271 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0229-1],ARef=[AI05-0267-1]}
2272 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2273 Aspect specifications are new.]}
2274 @end{Extend2005}
2275
2276 @begin{Inconsistent2012}
2277 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0180-1]}
2278 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@b<Correction:>
2279 Names of protected subprograms and entries are now directly visible in an
2280 aspect of a type declaration. This was always intended to be the case, but it
2281 was omitted from the Standard by an editing error. In the unlikely case that
2282 a parameterless protected function has the same name and type as an entity
2283 used in a type invariant expression, the meaning would change from the outside
2284 entity which would now be hidden by the protected function. It is much more
2285 likely that a conflict (itself rather unlikely) would cause a resolution
2286 failure.]}
2287 @end{Inconsistent2012}
2288
2289 @begin{Incompatible2012}
2290 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0154-1]}
2291 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
2292 Added a clarification that aspects that correspond to library unit pragmas
2293 are resolved and evaluated immediately. This is incompatible, as a
2294 reference to an entity defined after the aspect will now be illegal.
2295 However, this would have
2296 required retroactive enforcement of such aspects, which is a new
2297 capability not available from the associated pragma, and moreover
2298 no known Ada 2012 implementation has ever allowed late evaluation of
2299 such aspects. As such, there should be no practical incompatibility.]}
2300
2301 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0220-1]}
2302 @ChgAdded{Version=[5],Text=[Parameters of access-to-subprogram types are
2303 now visible in aspect specifications. This can be incompatible if some
2304 entity with the same name as a parameter is used in an existing aspect
2305 specification. We believe that all such aspects require either static
2306 expressions or statically denoting of a subprogram; since a parameter
2307 can be neither of these and hides everything else, all such cases will be
2308 caught at compile-time. In addition, we expect such cases to be very rare.]}
2309 @end{Incompatible2012}
2310
2311 @begin{Extend2012}
2312 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
2313 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2314 An aspect can be an unresolved @nt{aggregate}, these can be used to
2315 specify a list of entities, or to set a group of different but related
2316 properties with a single aspect.]}
2317 @end{Extend2012}
2318
2319 @begin{Diffword2012}
2320 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0105-1]}
2321 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the wording so that the restriction
2322 against language-defined aspects on subprogram completions includes
2323 completions that are expressions functions and null procedures.]}
2324
2325 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0106-1]}
2326 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Defined class-wide aspect
2327 for use in rules in @RefSecNum{Stream-oriented attributes}.]}
2328
2329 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0138-1]}
2330 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added a definition of
2331 nonoverridable aspects. This is necessary to prevent generic contract
2332 problems with formal derived types.]}
2333
2334 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0194-1]}
2335 @ChgAdded{Version=[5],Text=[@b<Correction:> Added @nt{entry_body} to the
2336 list of entities that don't allow any language-defined aspects. This was
2337 an oversight in @AILink{AI=[AI12-0169-1],Text=[AI12-0169-1]} which allowed @nt{aspect_specification}s on
2338 an @nt{entry_body} in the first place.]}
2339
2340 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0206-1]}
2341 @ChgAdded{Version=[5],Text=[@b<Correction:> Extended the definition of
2342 nonoverridable aspects to cover most kinds of aspects.]}
2343
2344 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0211-1]}
2345 @ChgAdded{Version=[5],Text=[@b<Correction:> Added a rule so that the
2346 a nonoverridable aspect has to be the same for every ancestor of a type.]}
2347
2348 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2349 @ChgAdded{Version=[5],Text=[Removed formal parameters from the list of
2350 entities that don't have any language-defined aspects, since Nonblocking
2351 (see @RefSecNum{Intertask Communication}) is language-defined.]}
2352
2353 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0373-1]}
2354 @ChgAdded{Version=[5],Text=[Added the missing definition for resolution of
2355 entities found in aspects of library units.]}
2356 @end{Diffword2012}
2357
2358
2359 @LabeledRevisedClause{Version=[3],New=[Packed Types],Old=[Pragma Pack]}
2360
2361 @begin{Intro}
2362 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2363 @redundant[@Chg{Version=[3],New=[The Pack aspect having the value True],Old=[A
2364 @nt{pragma} Pack]} specifies that storage minimization should be the main
2365 criterion when selecting the representation of a composite type.]
2366 @end{Intro}
2367
2368 @begin{NotIso}
2369 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2
2370 through 4 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
2371 should be deleted if the paragraphs are ever renumbered.}
2372 @end{NotIso}
2373
2374 @begin{MetaRules}
2375 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
2376 @ChgAdded{Version=[4],Text=[If the default representation already uses
2377 minimal storage for a particular type, aspect Pack might not cause any
2378 representation change. It follows that aspect Pack should always be allowed,
2379 even when it has no effect on representation.]}
2380
2381 @ChgRef{Version=[4],Kind=[AddedNormal]}
2382 @ChgAdded{Version=[4],Text=[As a consequence, the chosen representation for a
2383 packed type may change during program maintenance even if the type is
2384 unchanged (in particular, if other representation aspects change on a part of
2385 the type). This is different than the behavior of most other representation
2386 aspects, whose properties remain guaranteed no matter what changes are made to
2387 other aspects.]}
2388
2389 @ChgRef{Version=[4],Kind=[AddedNormal]}
2390 @ChgAdded{Version=[4],Text=[Therefore, aspect Pack should not be used to
2391 achieve a representation required by external criteria. For instance, setting
2392 Component_Size to 1 should be preferred over using aspect Pack to ensure an
2393 array of bits. If future maintenance would make the array components aliased,
2394 independent, or atomic, the program would become illegal if Component_Size is
2395 used (immediately identifying a problem) while the aspect Pack version would
2396 simply change representations (probably causing a hard-to-find bug).]}
2397 @end{MetaRules}
2398
2399 @begin{Syntax}
2400 @begin{SyntaxText}
2401 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
2402 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
2403 @nt{pragma} Pack is as follows:]}
2404 @end{SyntaxText}
2405
2406 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
2407 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
2408 Text=[@key{pragma} @prag(Pack)(@SynI{first_subtype_}@Syn2{local_name});]}>
2409 @end{Syntax}
2410
2411 @begin{Legality}
2412 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
2413 @ChgDeleted{Version=[3],Text=[The @SynI{first_subtype_}@nt{local_name} of a
2414 @nt{pragma} Pack shall denote a composite subtype.]}
2415 @end{Legality}
2416
2417 @begin{StaticSem}
2418 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2419 @ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{A fake to get a conditional Leading}
2420 @Chg{Version=[3],New=[For a full type declaration of a composite type, the
2421 following language-defined representation aspect may be specified:],
2422 Old=[@PDefn2{Term=[representation pragma], Sec=(Pack)}
2423 @PDefn2{Term=[pragma, representation], Sec=(Pack)}
2424 @Chg{Version=[3],New=[@PDefn2{Term=[representation aspect], Sec=(packing)}],
2425 Old=[@PDefn2{Term=[aspect of representation], Sec=(packing)}
2426 @Defn2{Term=[packing], Sec=(aspect of representation)}]}
2427 @Defn{packed}
2428 A @nt{pragma} Pack specifies the @i{packing} aspect of representation;
2429 the type (or the extension part) is said to be @i{packed}.
2430 For a type extension, the parent part is packed as for the parent
2431 type, and a @nt{pragma} Pack causes packing only of the extension part.]}
2432
2433 @begin{Description}
2434 @ChgRef{Version=[3],Kind=[Added]}
2435 @ChgAdded{Version=[3],Text=[Pack@\The type of aspect Pack is Boolean. When
2436 aspect Pack is True for a type, the type (or the extension part) is said to be
2437 @i{packed}. For a type extension, the parent part is packed as for the parent
2438 type, and specifying Pack causes packing only of the extension part.
2439 @Defn{packed}@AspectDefn{Pack}]}
2440
2441 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pack],
2442 Text=[@ChgAdded{Version=[3],Text=[Minimize storage when laying out records
2443 and arrays.]}]}
2444
2445 @ChgRef{Version=[3],Kind=[Added]}
2446 @ChgAdded{Version=[3],NoPrefix=[T],Text=[If directly specified, the
2447 @nt{aspect_definition} shall be a static expression. If not specified
2448 (including by inheritance), the aspect is False.]}
2449 @end{Description}
2450
2451 @begin{Ramification}
2452 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2453 The only high level semantic effect of @Chg{Version=[3],New=[specifying the],Old=[a @nt{pragma}]
2454 Pack@Chg{Version=[3],New=[ aspect],Old=[]}
2455 is @Chg{Version=[3],New=[potential loss of ],Old=[]}independent
2456 addressability (see @RefSec{Shared Variables}).]}
2457 @end{Ramification}
2458 @end{StaticSem}
2459
2460 @begin{ImplAdvice}
2461 If a type is packed, then the implementation should try to minimize
2462 storage allocated to objects of the type,
2463 possibly at the expense of speed of accessing components,
2464 subject to reasonable complexity in addressing calculations.
2465 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2466 Text=[Storage allocated to objects of a packed type should be minimized.]}]}
2467 @begin{Ramification}
2468 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2469 @Chg{Version=[3],New=[Specifying the],Old=[A @nt{pragma}]}
2470 Pack@Chg{Version=[3],New=[ aspect],Old=[]} is for gaining space efficiency,
2471 possibly at the expense of time.
2472 If more explicit control over representation is desired,
2473 then a @nt{record_representation_clause},
2474 a Component_Size clause,
2475 or a Size clause should be used instead of,
2476 or in addition to,
2477 @Chg{Version=[3],New=[the],Old=[a @nt{pragma}]}
2478 Pack@Chg{Version=[3],New=[ aspect],Old=[]}.
2479 @end{Ramification}
2480
2481 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
2482 @ChgRef{Version=[4],Kind=[DeletedAdded],ARef=[AI12-0001-1]}
2483 @ChgDeleted{Version=[4],Text=[@Chg{Version=[2],New=[If a packed type has a
2484 component that is not of a by-reference type and has no aliased part, then such
2485 a component need not be aligned according to the Alignment of its subtype; in
2486 particular it need not be allocated on a storage element
2487 boundary.@Comment{No "should" here; thus no ImplAdvice entry. This really
2488 qualifies the item above}],Old=[]}]}
2489
2490 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2491 @Chg{Version=[3],New=[@PDefn2{Term=[recommended level of support], Sec=(aspect Pack)}],
2492 Old=[@PDefn2{Term=[recommended level of support], Sec=(pragma Pack)}]}
2493 The recommended level of support for
2494 @Chg{Version=[3],New=[the],Old=[@nt{pragma}]}
2495 Pack@Chg{Version=[3],New=[ aspect],Old=[]} is:
2496 @begin{Itemize}
2497 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0001-1]}
2498 @ChgAdded{Version=[4],Text=[Any component of a packed type that is of a
2499 by-reference type, that is specified as independently addressable, or that
2500 contains an aliased part, shall be aligned according to the alignment of its
2501 subtype.]}
2502
2503 @begin{Ramification}
2504 @ChgRef{Version=[4],Kind=[AddedNormal]}
2505 @ChgAdded{Version=[4],Text=[This also applies to atomic components. "Atomic"
2506 implies "specified as independently addressable", so we don't need to mention
2507 atomic here.]}
2508
2509 @ChgRef{Version=[4],Kind=[AddedNormal]}
2510 @ChgAdded{Version=[4],Text=[Other components do not have to respect the
2511 alignment of the subtype when packed; in many cases, the Recommended Level of
2512 Support will require the alignment to be ignored.]}
2513 @end{Ramification}
2514
2515 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
2516 For a packed record type, the components should be packed as tightly as
2517 possible subject to @Chg{Version=[4],New=[the above alignment
2518 requirements, ],Old=[]}the Sizes of the component subtypes, and
2519 @Chg{Version=[4],New=[],Old=[subject to ]}any
2520 @nt{record_representation_clause} that applies to the type; the implementation
2521 may, but need not, reorder components or cross aligned word boundaries to
2522 improve the packing. A component whose Size is greater than the word size may
2523 be allocated an integral number of words.
2524
2525 @begin{Ramification}
2526 The implementation can always allocate an integral number of words for a
2527 component that will not fit in a word. The rule also allows small component
2528 sizes to be rounded up if such rounding does not waste space. For example,
2529 if Storage_Unit = 8, then a component of size 8 is probably more efficient
2530 than a component of size 7 plus a 1-bit gap (assuming the gap is needed
2531 anyway).
2532 @end{Ramification}
2533
2534 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
2535 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
2536 For a packed array type, if the @Chg{Version=[3],New=[], Old=[component
2537 subtype's ]}Size@Chg{Version=[3],New=[ of the component subtype],Old=[]} is
2538 less than or equal to the word size@Chg{Version=[3],New=[],Old=[, and
2539 Component_Size is not specified for the type]}, Component_Size should be less
2540 than or equal to the Size of the component subtype, rounded up to the nearest
2541 factor of the word size@Chg{Version=[4],New=[, unless this would violate
2542 the above alignment requirements],Old=[]}.
2543
2544 @begin{Ramification}
2545 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0001-1]}
2546 @ChgDeleted{Version=[4],Text=[If a component subtype is aliased,
2547 its Size will generally be a multiple of Storage_Unit,
2548 so it probably won't get packed very tightly.]}
2549 @end{Ramification}
2550 @end{Itemize}
2551 @ChgImplAdvice{Version=[3],Kind=[Revised],InitialVersion=[2],
2552 Text=[@ChgAdded{Version=[2],
2553 Text=[The recommended level of support for @Chg{Version=[3],New=[the],Old=[pragma]}
2554 Pack@Chg{Version=[3],New=[ aspect],Old=[]} should be
2555 followed.]}]}
2556 @end{ImplAdvice}
2557
2558 @begin{DiffWord95}
2559 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
2560 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2561 @ChgAdded{Version=[2],Text=[Added clarification that
2562 @Chg{Version=[3],New=[the],Old=[pragma]} Pack@Chg{Version=[3],New=[ aspect],Old=[]} can
2563 ignore alignment requirements on types that don't have by-reference or
2564 aliased parts. This was always intended, but there was no wording to that
2565 effect.]}
2566 @end{DiffWord95}
2567
2568 @begin{Extend2005}
2569 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
2570 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2571 Aspect Pack is new; @nt{pragma} Pack is now obsolescent.]}
2572 @end{Extend2005}
2573
2574 @begin{DiffWord2005}
2575 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1]}
2576 @ChgAdded{Version=[3],Text=[@b<Correction:> Fixed so that the
2577 presence or absence of a confirming Component_Size representation
2578 clause does not change the meaning of the Pack aspect.]}
2579 @end{DiffWord2005}
2580
2581 @begin{DiffWord2012}
2582 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
2583 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Fixed so that the
2584 Recommended Level of Support does not require packing of
2585 components for which such packing would violate other representation
2586 items or aspects. This is not incompatible, as either such Pack
2587 aspects were treated as illegal or the Recommended Level of Support
2588 was ignored as impractical, neither of which would change the
2589 behavior of any working programs. (Other behavior cannot be justifed
2590 from the Standard.)]}
2591 @end{DiffWord2012}
2592
2593
2594
2595 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
2596 @LabeledRevisedClause{Version=[1],New=[Operational and Representation Attributes], Old=[Representation Attributes]}
2597
2598 @begin{Intro}
2599 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
2600 @redundant[@Defn{representation attribute}
2601 @Defn2{Term=[attribute], Sec=(representation)}
2602 The values of certain implementation-dependent characteristics can be
2603 obtained by interrogating appropriate
2604 @Chg{New=[operational or ],Old=[]}representation attributes.
2605 @RootDefn2{Term=[attribute], Sec=(specifying)}
2606 Some of these attributes are specifiable via an
2607 @nt{attribute_definition_clause}.]
2608 @end{Intro}
2609
2610 @begin{MetaRules}
2611 In general, the meaning of a given attribute should not depend on
2612 whether the attribute was specified via an
2613 @nt{attribute_definition_clause},
2614 or chosen by default by the implementation.
2615 @end{MetaRules}
2616
2617 @begin{Syntax}
2618 @Syn{lhs=<attribute_definition_clause>,rhs="
2619 @key{for} @Syn2{local_name}@SingleQuote@Syn2{attribute_designator} @key{use} @Syn2{expression};
2620 | @key{for} @Syn2{local_name}@SingleQuote@Syn2{attribute_designator} @key{use} @Syn2{name};"}
2621 @end{Syntax}
2622
2623 @begin{Resolution}
2624 For an @nt{attribute_definition_clause} that specifies
2625 an attribute that denotes a value,
2626 the form with an @nt{expression} shall be used.
2627 Otherwise, the form with a @nt{name} shall be used.
2628
2629 @PDefn2{Term=[expected type],
2630 Sec=(attribute_definition_clause expression or name)}
2631 For an @nt{attribute_definition_clause} that specifies
2632 an attribute that denotes a value or an object,
2633 the expected type for the expression or @nt{name}
2634 is that of the attribute.
2635 @PDefn2{Term=[expected profile],
2636 Sec=(attribute_definition_clause name)}
2637 For an @nt{attribute_definition_clause} that specifies
2638 an attribute that denotes a subprogram,
2639 the expected profile for the @nt{name}
2640 is the profile required for the attribute.
2641 For an @nt{attribute_definition_clause} that specifies
2642 an attribute that denotes some other kind of entity,
2643 the @nt{name} shall resolve to denote an entity of the appropriate
2644 kind.
2645 @begin{Ramification}
2646 For example, the Size attribute is of type @i{universal_integer}.
2647 Therefore, the expected type for Y in @lquotes@;@key[for] X'Size @key[use] Y;@rquotes@; is
2648 @i{universal_integer},
2649 which means that Y can be of any integer type.
2650 @end{Ramification}
2651 @begin{Discussion}
2652 For attributes that denote subprograms, the required profile is indicated
2653 separately for the individual attributes.
2654 @end{Discussion}
2655 @begin{Ramification}
2656 @Leading@;For an @nt{attribute_definition_clause} with a @nt{name},
2657 the @nt{name} need not statically denote the entity it denotes.
2658 For example, the following kinds of things are allowed:
2659 @begin{Example}
2660 @key[for] Some_Access_Type'Storage_Pool @key[use] Storage_Pool_Array(I);
2661 @key[for] Some_Type'Read @key[use] Subprogram_Pointer.@key[all];
2662 @end{Example}
2663 @end{Ramification}
2664 @end{Resolution}
2665
2666 @begin{Legality}
2667 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
2668 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
2669 @RootDefn{specifiable (of an attribute and for an entity)}
2670 @RootDefn2{Term=[attribute], Sec=(specifiable)}
2671 An @nt{attribute_designator} is allowed in an
2672 @nt{attribute_definition_clause} only if this International Standard
2673 explicitly allows it,
2674 or for an implementation-defined attribute
2675 if the implementation allows it.
2676 @Chg{Version=[3],New=[@PDefn2{Term=[representation aspect], Sec=(specifiable attributes)}],
2677 Old=[@PDefn2{Term=[aspect of representation], Sec=(specifiable attributes)}]}
2678 Each specifiable attribute constitutes an
2679 @Chg{New=[@PDefn2{Term=[operational aspect], Sec=(specifiable attributes)}
2680 operational aspect or ],Old=[]}aspect of representation@Chg{Version=[3],New=[;
2681 the name of the aspect is that of the attribute],Old=[]}.
2682 @begin{Discussion}
2683 For each specifiable attribute,
2684 we generally say something like,
2685 @lquotes@;The ... attribute may be specified for ... via
2686 an @nt{attribute_definition_clause}.@rquotes@;
2687
2688 The above wording allows for
2689 T'Class'Alignment, T'Class'Size, T'Class'Input, and T'Class'Output
2690 to be specifiable.
2691
2692 A specifiable attribute is not necessarily
2693 specifiable for all entities for which it is defined.
2694 For example, one is allowed to ask T'Component_Size for an array
2695 subtype T, but @lquotes@;@key[for] T'Component_Size @key[use] ...@rquotes@;
2696 is only allowed if T is a first subtype,
2697 because Component_Size is a type-related aspect.
2698 @end{Discussion}
2699
2700 For an @nt{attribute_definition_clause} that specifies
2701 an attribute that denotes a subprogram,
2702 the profile shall be mode conformant with the one
2703 required for the attribute,
2704 and the convention shall be Ada.
2705 Additional requirements are defined for particular attributes.
2706 @Defn2{Term=[mode conformance],Sec=(required)}
2707 @begin{Ramification}
2708 @Leading@;This implies, for example, that if one writes:
2709 @begin{Example}
2710 @key[for] T'Read @key[use] R;
2711 @end{Example}
2712
2713 R has to be a procedure with two parameters with the appropriate
2714 subtypes and modes as shown in
2715 @RefSecNum{Stream-Oriented Attributes}.
2716 @end{Ramification}
2717 @end{Legality}
2718
2719 @begin{StaticSem}
2720 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00270-01]}
2721 @Defn{Address clause}
2722 @Defn{Alignment clause}
2723 @Defn{Size clause}
2724 @Defn{Component_Size clause}
2725 @Defn{External_Tag clause}
2726 @Defn{Small clause}
2727 @Defn{Bit_Order clause}
2728 @Defn{Storage_Pool clause}
2729 @Defn{Storage_Size clause}@Chg{Version=[2],New=[
2730 @Defn{Stream_Size clause}],Old=[]}
2731 @Defn{Read clause}
2732 @Defn{Write clause}
2733 @Defn{Input clause}
2734 @Defn{Output clause}
2735 @Defn{Machine_Radix clause}
2736 A @i{Size clause} is an @nt{attribute_definition_clause} whose
2737 @nt{attribute_designator} is Size.
2738 Similar definitions apply to the other specifiable attributes.
2739 @begin{Honest}
2740 @PDefn2{Term=[type-related], Sec=(attribute_definition_clause)}
2741 @PDefn2{Term=[subtype-specific], Sec=(attribute_definition_clause)}
2742 An @nt{attribute_definition_clause}
2743 is type-related or subtype-specific if the @nt{attribute_designator}
2744 denotes a type-related or subtype-specific attribute, respectively.
2745 @end{Honest}
2746
2747 @Defn{storage element}
2748 @IndexSee{Term=[byte],See=(storage element)}
2749 A @i{storage element} is
2750 an addressable element of storage in the machine.
2751 @Defn{word}
2752 A @i{word} is the largest amount of storage that can be conveniently and
2753 efficiently manipulated by the hardware,
2754 given the implementation's run-time model.
2755 A word consists of an integral number of storage elements.
2756 @begin{Discussion}
2757 A storage element is not intended to be a single bit,
2758 unless the machine can efficiently address individual bits.
2759 @end{Discussion}
2760 @begin{Ramification}
2761 For example, on a machine with 8-bit storage elements,
2762 if there exist 32-bit integer registers,
2763 with a full set of arithmetic and logical instructions to manipulate those
2764 registers, a word ought to be 4 storage elements @em that is, 32 bits.
2765 @end{Ramification}
2766 @begin{Discussion}
2767 The @lquotes@;given the implementation's run-time model@rquotes@; part is
2768 intended to imply that, for example, on an 80386 running MS-DOS,
2769 the word might be 16 bits, even though the hardware can support 32
2770 bits.
2771
2772 A word is what ACID refers to as a @lquotes@;natural hardware
2773 boundary@rquotes@;.
2774
2775 Storage elements may, but need not be, independently addressable
2776 (see @RefSec{Shared Variables}).
2777 Words are expected to be independently addressable.
2778 @end{Discussion}
2779
2780 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
2781 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1]}
2782 @ChgAdded{Version=[2],Text=[@Defn{machine scalar}
2783 A @i{machine scalar} is an amount of storage that can be conveniently and
2784 efficiently loaded, stored, or operated upon by the hardware. Machine scalars
2785 consist of an integral number of storage elements. The set of machine scalars
2786 is implementation defined, but @Chg{Version=[3],New=[includes],Old=[must include]}
2787 at least the storage element and
2788 the word. Machine scalars are used to interpret @nt{component_clause}s when the
2789 nondefault bit ordering applies.]}
2790 @ChgImplDef{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2791 Text=[The set of machine scalars.]}]}
2792 @begin{Ramification}
2793 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0092-1]}
2794 @ChgAdded{Version=[3],Text=[A single storage element is a machine scalar
2795 in all Ada implementations. Similarly, a word is a machine scalar in
2796 all implementations (although it might be the same as a storage element).
2797 An implementation may define other machine scalars that make sense on the
2798 target (a half-word, for instance).]}
2799 @end{Ramification}
2800
2801 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
2802 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0191-1]}
2803 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
2804 @Chg{New=[The following representation attributes are defined: Address,
2805 Alignment, Size, @Chg{Version=[3],New=[Object_Size, ],Old=[]}Storage_Size,
2806 @Chg{Version=[3],New=[],Old=[and ]}Component_Size@Chg{Version=[3],New=[,
2807 Has_Same_Storage, and Overlaps_Storage],Old=[]}.],
2808 Old=[@Leading@;The following attributes are defined:]}
2809
2810 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
2811 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
2812 @Chg{New=[@nt{prefix}],Old=[prefix]} X that
2813 denotes an object, program unit, or label]}:
2814 @begin{Description}
2815 @Attribute{Prefix=<X>, AttrName=<Address>,
2816 Text=<Denotes the address of the first of the storage elements
2817 allocated to X. For a program unit or
2818 label, this value refers to the machine code associated with
2819 the corresponding body or @nt{statement}.
2820 The value of this attribute is of type System.Address.>}
2821
2822 @begin{Ramification}
2823 Here, the @lquotes@;first of the storage elements@rquotes@; is intended
2824 to mean the one with the lowest address;
2825 the endianness of the machine doesn't matter.
2826 @end{Ramification}
2827
2828 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0095-1]}
2829 @ChgAdded{Version=[3],NoPrefix=[T],Text=[The prefix of X'Address shall not statically denote
2830 a subprogram that has convention Intrinsic. X'Address raises Program_Error if X
2831 denotes a subprogram that has convention
2832 Intrinsic.@Defn2{Term=[Program_Error],Sec=(raised by Address of an intrinsic subprogram)}]}]}
2833
2834 @NoPrefix@PDefn2{Term=[specifiable], Sec=(of Address for stand-alone
2835 objects and for program units)}
2836 @Defn{Address clause}
2837 @ChgNote{Removed Redundant here, as per AI-00114. Did not mark change, as it is
2838 AARM-only, not to the text of the item.}Address may be specified for
2839 stand-alone objects and for program units via an
2840 @nt{attribute_definition_clause}.@Chg{Version=[3],New=[@AspectDefn{Address}],Old=[]}
2841 @begin{Ramification}
2842 Address is not allowed for enumeration literals,
2843 predefined operators, derived task types,
2844 or derived protected types, since they are not program units.
2845
2846 @ChgRef{Version=[3],Kind=[AddedNormal]}
2847 @ChgAdded{Version=[3],Text=[Address is not allowed for intrinsic subprograms,
2848 either. That can be checked statically unless the prefix is a generic formal
2849 subprogram and the attribute reference is in the body of a generic unit.
2850 We define that case to raise Program_Error, in order that the compiler
2851 does not have to build a wrapper for intrinsic subprograms.]}
2852
2853 The validity of a given address depends on the run-time model;
2854 thus, in order to use Address clauses correctly,
2855 one needs intimate knowledge of the run-time model.
2856
2857 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2858 If the Address of an object is specified,
2859 any explicit or implicit initialization takes place as usual,
2860 unless @Chg{Version=[3],New=[the],Old=[a @nt{pragma}]} Import
2861 @Chg{Version=[3],New=[aspect ],Old=[]}is also specified for the object
2862 (in which case any necessary initialization is presumably
2863 done in the foreign language).
2864
2865 Any compilation unit containing an @nt<attribute_reference> of
2866 a given type depends semantically on the declaration of the package
2867 in which the type is declared, even if not mentioned
2868 in an applicable @nt<with_clause>
2869 @em see @RefSecNum{Compilation Units - Library Units}.
2870 In this case, it means that if a compilation unit contains
2871 X'Address, then it depends on the declaration of System.
2872 Otherwise, the fact that the value of Address is of
2873 a type in System wouldn't make sense;
2874 it would violate the @lquotes@;legality determinable via semantic
2875 dependences@rquotes@; @MetaRulesName.
2876
2877 AI83-00305 @em If X is a task type,
2878 then within the body of X,
2879 X denotes the current task object;
2880 thus, X'Address denotes the object's address.
2881
2882 Interrupt entries and their addresses are
2883 described in @RefSec{Interrupt Entries}.
2884
2885 If X is not allocated on a storage element boundary,
2886 X'Address points at the first of the storage elements
2887 that contains any part of X.
2888 This is important for the definition of the Position
2889 attribute to be sensible.
2890 @end{Ramification}
2891
2892 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Address],
2893 Text=[@ChgAdded{Version=[3],Text=[Machine address of an entity.]}]}
2894
2895 @end{Description}
2896 @EndPrefixType{}
2897 @end{StaticSem}
2898
2899 @begin{Erron}
2900 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
2901 @PDefn2{Term=(erroneous execution),Sec=(cause)}If an Address is specified,
2902 it is the programmer's responsibility to ensure that
2903 the address is valid@Chg{Version=[3],New=[ and appropriate for the entity and
2904 its use],Old=[]}; otherwise, program execution is erroneous.
2905
2906 @begin{Discussion}
2907 @ChgAdded{Version=[3],Text=[@ldquote@;Appropriate for the entity and its
2908 use@rdquote covers cases such as
2909 misaligned addresses, read-only code addresses for variable data objects (and
2910 nonexecutable data addresses for code units), and addresses which would
2911 force objects that are supposed to be independently addressable to not be.
2912 Such addresses may be @ldquote@;valid@rdquote as they designate locations that
2913 are accessible to the program, but the program execution is still erroneous
2914 (meaning that implementations do not have to worry about these cases).]}
2915 @end{Discussion}
2916 @end{Erron}
2917
2918 @begin{ImplAdvice}
2919 For an array X, X'Address should point at the first component of the
2920 array, and not at the array bounds.
2921 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2922 Text=[For an array X, X'Address should point at the first component of the
2923 array rather than the array bounds.]}]}
2924 @begin{Ramification}
2925 On the other hand, we have no advice to offer about
2926 discriminants and tag fields;
2927 whether or not the address points at them is
2928 not specified by the language.
2929 If discriminants are stored separately,
2930 then the Position of a discriminant might be negative,
2931 or might raise an exception.
2932 @end{Ramification}
2933
2934 @PDefn2{Term=[recommended level of support], Sec=(Address attribute)}
2935 @Leading@;The recommended level of support for the Address attribute is:
2936 @begin{Itemize}
2937 X'Address should produce a useful result if X is an
2938 object that is aliased or of a by-reference
2939 type, or is an entity whose Address has been specified.
2940 @begin{Reason}
2941 Aliased objects are the ones for which the
2942 Unchecked_Access attribute is allowed;
2943 hence, these have to be allocated on an addressable
2944 boundary anyway. Similar considerations apply to objects
2945 of a by-reference type.
2946
2947 An implementation need not go to any trouble
2948 to make Address work in other cases.
2949 For example, if an object X is not aliased and not of a by-reference type,
2950 and the implementation chooses to store it in a register,
2951 X'Address might return System.Null_Address
2952 (assuming registers are not addressable).
2953 For a subprogram whose calling convention is Intrinsic,
2954 or for a package,
2955 the implementation need not generate an out-of-line
2956 piece of code for it.
2957 @end{Reason}
2958
2959 An implementation should support Address clauses for
2960 imported subprograms.
2961
2962 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]}
2963 @ChgDeleted{Version=[2],Text=[Objects (including subcomponents) that are
2964 aliased or of a by-reference type
2965 should be allocated on storage element boundaries.]}
2966 @Comment{There is a now a blanket permission to this effect}
2967 @begin{Reason}
2968 @ChgRef{Version=[2],Kind=[Deleted]}
2969 @ChgDeleted{Version=[2],Text=[This is necessary for the Address attribute to be
2970 useful (since First_Bit and Last_Bit apply only to components). Implementations
2971 generally need to do this anyway, for tasking to work properly.]}
2972 @end{Reason}
2973
2974 If the Address of an object is specified,
2975 or it is imported or exported,
2976 then the implementation should not perform optimizations based on
2977 assumptions of no aliases.
2978 @end{Itemize}
2979 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2980 Text=[The recommended level of support for the Address attribute should be
2981 followed.]}]}
2982 @end{ImplAdvice}
2983
2984 @begin{Notes}
2985 The specification of a link name @Chg{Version=[3],New=[with the Link_Name
2986 aspect],Old=[in a @nt{pragma} Export]}
2987 (see @RefSecNum{Interfacing Aspects})
2988 for a subprogram or object is an alternative to explicit
2989 specification of its link-time address, allowing a link-time directive
2990 to place the subprogram or object within memory.
2991
2992 The rules for the Size attribute imply,
2993 for an aliased object X, that if X'Size = Storage_Unit,
2994 then X'Address points at a storage element containing all
2995 of the bits of X, and only the bits of X.
2996 @end{Notes}
2997
2998 @begin{DiffWord83}
2999 The intended meaning of the various attributes,
3000 and their @nt{attribute_definition_clause}s,
3001 is more explicit.
3002
3003 The @ntf{address_clause} has been renamed to @nt{at_clause} and moved
3004 to @RefSec{Obsolescent Features}.
3005 One can use an Address clause
3006 (@lquotes@;for T'Address @key[use] ...;@rquotes@;)
3007 instead.
3008
3009 The attributes defined in RM83-13.7.3 are moved to
3010 @RefSecNum{Numerics},
3011 @RefSecNum{Attributes of Floating Point Types}, and
3012 @RefSecNum{Attributes of Fixed Point Types}.
3013 @end{DiffWord83}
3014
3015 @begin{DiffWord2005}
3016 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1]}
3017 @ChgAdded{Version=[3],Text=[Defined that the names of aspects are the same as
3018 the name of the attribute; that gives a name to use in @nt{aspect_specification}s
3019 (see @RefSecNum{Aspect Specifications}).]}
3020 @end{DiffWord2005}
3021
3022 @begin{MetaRules}
3023 By default, the Alignment of a subtype should
3024 reflect the @lquotes@;natural@rquotes@; alignment for objects of the
3025 subtype on the machine.
3026 The Alignment, whether specified or default,
3027 should be known at compile time, even though
3028 Addresses are generally not known at compile
3029 time.
3030 (The generated code should never need to check
3031 at run time the number of zero bits at the end
3032 of an address to determine an alignment).
3033
3034 There are two symmetric purposes of Alignment clauses, depending on
3035 whether or not the implementation has control over object
3036 allocation.
3037 If the implementation allocates an object,
3038 the implementation should ensure that
3039 the Address and Alignment are consistent with
3040 each other.
3041 If something outside the implementation allocates an
3042 object, the implementation should be allowed to
3043 assume that the Address and Alignment are
3044 consistent, but should not assume stricter alignments
3045 than that.
3046 @end{MetaRules}
3047
3048 @begin{StaticSem}
3049 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3050 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
3051 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
3052 @Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes @Chg{Version=[2],New=[an],
3053 Old=[a subtype or]} object]}:
3054 @begin{Description}
3055 @ChgAttribute{Version=[2], Kind=[Revised], ChginAnnex=[T], Leading=[F],
3056 Prefix=<X>, AttrName=<Alignment>, ARef=[AI95-00291-02], InitialVersion=[0],
3057 Text=[@Chg{Version=[2],New=[The value of this attribute is of type
3058 @i{universal_integer}, and nonnegative; zero means that the object is not
3059 necessarily aligned on a storage element boundary. If X'Alignment is not
3060 zero, then X is aligned on a storage unit boundary and X'Address],
3061 Old=[The Address of an object that is allocated under
3062 control of the implementation]} is an integral multiple of
3063 @Chg{Version=[2],New=[X'Alignment],Old=[the Alignment of the object]}
3064 (that is, the Address modulo the Alignment is zero).@Chg{Version=[2],
3065 New=[],Old=[The offset of a record component is a multiple of the
3066 Alignment of the component.
3067 For an object that is not allocated under control of
3068 the implementation
3069 (that is, one that is imported,
3070 that is allocated by a user-defined allocator,
3071 whose Address has been specified,
3072 or is designated by an access value returned by an
3073 instance of Unchecked_Conversion),
3074 the implementation may assume that the Address is
3075 an integral multiple of its Alignment.
3076 The implementation shall not assume a stricter alignment.]}
3077
3078 @Comment{Deleted below causes trouble in the generated text for attributes,
3079 but no fix appears to be possible. And the trouble is much worse in the
3080 RTF version than the HTML version, so for now we're making a hand fix.}
3081 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]}
3082 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The value of this attribute
3083 is of type @i{universal_integer}, and nonnegative;
3084 zero means that the object is not necessarily
3085 aligned on a storage element boundary.]}]}@Comment{End X'Alignment}
3086 @EndPrefixType{}
3087 @begin{Ramification}
3088 The Alignment is passed by an @nt{allocator} to the Allocate operation;
3089 the implementation has to choose a value such that if the address
3090 returned by Allocate is aligned as requested,
3091 the generated code can correctly access the object.
3092
3093 The above mention of @lquotes@;modulo@rquotes@; is referring to the "@key[mod]"
3094 operator declared in System.Storage_Elements;
3095 if X @key[mod] N = 0, then X is by definition aligned on an
3096 N-storage-element boundary.
3097 @end{Ramification}
3098
3099 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
3100 @NoPrefix@Chg{Version=[2],New=[@PDefn2{Term=[specifiable], Sec=(of Alignment for objects)}],
3101 Old=[@PDefn2{Term=[specifiable], Sec=(of Alignment for first subtypes and objects)}]}
3102 @Defn{Alignment clause}
3103 Alignment may be specified for@Chg{Version=[2],New=[],Old=[ first subtypes and]}
3104 @Redundant[stand-alone] objects via an @nt{attribute_@!definition_@!clause};
3105 the expression of such a clause shall be static, and its value
3106 nonnegative.@Chg{Version=[2],New=[],Old=[If the Alignment of a subtype is
3107 specified, then the Alignment of an object of the subtype is at least as
3108 strict, unless the object's Alignment is also specified.
3109 The Alignment of an object created by an allocator is that of the
3110 designated subtype.@Chg{Version=[3],New=[@AspectDefn{Alignment (object)}],Old=[]}]}
3111
3112 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Alignment (object)],
3113 Text=[@ChgAdded{Version=[3],Text=[Alignment of an object.]}]}
3114
3115 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00247-01]}
3116 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[If an Alignment is specified
3117 for a composite subtype or object, this
3118 Alignment shall be equal to the least common multiple of any
3119 specified Alignments of the subcomponent subtypes, or an integer
3120 multiple thereof.]}
3121 @end{Description}
3122
3123 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3124 @ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],
3125 Text=[For @PrefixType{every subtype S}:]}
3126 @begin{Description}
3127 @ChgAttribute{Version=[2], Kind=[Added], ChginAnnex=[T], Leading=[F],
3128 Prefix=<S>, AttrName=<Alignment>, ARef=[AI95-00291-02], InitialVersion=[2],
3129 Text=[@Chg{Version=[2],New=[The value of this attribute is of type
3130 @i{universal_integer}, and nonnegative.],Old=[]}
3131
3132 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02],ARef=[AI95-00291-02]}
3133 @ChgAdded{Version=[2],NoPrefix=[T], Text=[For an object X of subtype S,
3134 if S'Alignment is not zero, then X'Alignment is a nonzero integral multiple
3135 of S'Alignment unless specified otherwise by a representation
3136 item.]}]}@Comment{End S'Alignment}
3137
3138 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3139 @ChgAdded{Version=[2],NoPrefix=[T], Text=[@PDefn2{Term=[specifiable], Sec=(of Alignment for first subtypes)}
3140 @Defn{Alignment clause}
3141 Alignment may be specified for first subtypes via an
3142 @nt{attribute_@!definition_@!clause};
3143 the expression of such a clause shall be static, and its value
3144 nonnegative.@Chg{Version=[3],New=[@AspectDefn{Alignment (subtype)}],Old=[]}]}
3145
3146 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Alignment (subtype)],
3147 Text=[@ChgAdded{Version=[3],Text=[Alignment of a subtype.]}]}
3148
3149 @end{Description}
3150
3151 @end{StaticSem}
3152
3153 @begin{Erron}
3154 @PDefn2{Term=(erroneous execution),Sec=(cause)}
3155 Program execution is erroneous if an Address clause is given that
3156 conflicts with the Alignment.
3157 @begin{Ramification}
3158 The user has to either give an Alignment clause also,
3159 or else know what Alignment the implementation will choose by default.
3160 @end{Ramification}
3161
3162 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02],ARef=[AI95-00291-02]}
3163 @PDefn2{Term=(erroneous execution),Sec=(cause)}
3164 @Chg{Version=[2],New=[For],Old=[If the Alignment is specified for]} an
3165 object that is not allocated under control of the implementation,
3166 execution is erroneous if the object is not aligned according to
3167 @Chg{Version=[2],New=[its],Old=[the]} Alignment.
3168
3169 @end{Erron}
3170
3171 @begin{ImplAdvice}
3172 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0116-1]}
3173 @ChgAdded{Version=[3],Text=[For any tagged specific subtype @i<S>,
3174 @i<S>'Class'Alignment should equal @i<S>'Alignment.]}
3175
3176 @begin{Reason}
3177 @ChgRef{Version=[3],Kind=[AddedNormal]}
3178 @ChgAdded{Version=[3],Text=[A tagged object should never be less aligned than
3179 the alignment of the type of its view, so for a class-wide type T'Class, the
3180 alignment should be no greater than that of any type covered by T'Class. If the
3181 implementation only supports alignments that are required by the recommended
3182 level of support (and this is most likely), then the alignment of any covered
3183 type has to be the same or greater than that of T @em which leaves the only
3184 reasonable value of T'Class'Alignment being T'Alignment. Thus we recommend this,
3185 but don't require it so that in the unlikely case that the implementation does
3186 support smaller alignments for covered types, it can select a smaller value
3187 for T'Class'Alignment.]}
3188 @end{Reason}
3189 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3190 Text=[For any tagged specific subtype @i<S>,
3191 @i<S>'Class'Alignment should equal @i<S>'Alignment.]}]}
3192
3193 @PDefn2{Term=[recommended level of support], Sec=(Alignment attribute
3194 for subtypes)}
3195 @Leading@;The recommended level of support for the Alignment attribute for
3196 subtypes is:
3197 @begin{Itemize}
3198 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
3199 An implementation should support @Chg{Version=[2],New=[an Alignment clause
3200 for a discrete type, fixed point type, record type, or
3201 array type, specifying an Alignment value that is zero or
3202 a power of two],Old=[specified Alignments that are factors and multiples of
3203 the number of storage elements per word]}, subject to the following:
3204
3205 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
3206 An implementation need not support
3207 @Chg{Version=[2], New=[an Alignment clause for a signed
3208 integer type specifying an Alignment greater than the largest
3209 Alignment value that is ever chosen by default by the implementation
3210 for any signed integer type. A corresponding limitation may be
3211 imposed for modular integer types, fixed point types, enumeration types,
3212 record types, and array types],Old=[specified Alignments for combinations
3213 of Sizes and Alignments that cannot be easily loaded and
3214 stored by available machine instructions]}.
3215
3216 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
3217 An implementation need not support
3218 @Chg{Version=[2],New=[a nonconfirming Alignment clause which could enable the
3219 creation of an object of an elementary type which cannot be easily loaded and
3220 stored by available machine instructions.],
3221 Old=[specified Alignments that are greater than the maximum
3222 Alignment the implementation ever returns
3223 by default.]}
3224
3225 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3226 @ChgAdded{Version=[2],Text=[An implementation need not support an
3227 Alignment specified for a derived tagged type which is not a multiple of the
3228 Alignment of the parent type. An implementation need not support a
3229 nonconfirming Alignment specified for a derived untagged by-reference type.]}
3230 @begin{Ramification}
3231 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
3232 @ChgAdded{Version=[2],Text=[There is no recommendation to support any
3233 nonconfirming Alignment clauses for types not mentioned above.
3234 Remember that
3235 @RefSecNum{Operational and Representation Aspects} requires support for
3236 confirming Alignment clauses for all types.]}
3237 @end{Ramification}
3238 @begin{ImplNote}
3239 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0116-1]}
3240 @ChgAdded{Version=[3],Text=[An implementation that tries to support other
3241 alignments for derived tagged types will need to allow inherited subprograms
3242 to be passed objects that are less aligned than expected by the parent
3243 subprogram and type. This is unlikely to work if alignment has any effect on
3244 code selection. Similar issues arise for untagged derived types whose
3245 parameters are passed by reference.]}
3246 @end{ImplNote}
3247 @end{Itemize}
3248
3249 @Leading@PDefn2{Term=[recommended level of support], Sec=(Alignment attribute
3250 for objects)}
3251 The recommended level of support for the Alignment attribute for
3252 objects is:
3253 @begin{Itemize}
3254 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00291-02]}
3255 @ChgDeleted{Version=[2],Text=[Same as above, for subtypes, but in addition:]}
3256
3257 For stand-alone library-level objects of statically constrained
3258 subtypes, the implementation should support all Alignments
3259 supported by the target linker. For example, page alignment
3260 is likely to be supported for such objects, but not for subtypes.
3261
3262 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3263 @ChgAdded{Version=[2],Text=[For other objects, an implementation should at
3264 least support the alignments supported for their
3265 subtype, subject to the following:]}
3266
3267 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3268 @ChgAdded{Version=[2],Text=[An implementation need not support Alignments
3269 specified for objects of a by-reference type or for objects of types containing
3270 aliased subcomponents if the specified Alignment is not a multiple of the
3271 Alignment of the subtype of the object.]}
3272 @end{Itemize}
3273 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3274 Text=[The recommended level of support for the Alignment attribute should be
3275 followed.]}]}
3276 @end{ImplAdvice}
3277
3278 @begin{Notes}
3279 Alignment is a subtype-specific attribute.
3280
3281 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00247-01]}
3282 @ChgDeleted{Version=[2],Text=[The Alignment of a composite object is always
3283 equal to the least common multiple of the Alignments of its components, or a
3284 multiple thereof.]}
3285 @begin{Discussion}
3286 @ChgRef{Version=[2],Kind=[Deleted]}
3287 @ChgDeleted{Version=[2],Text=[For default Alignments, this follows from the
3288 semantics of Alignment. For specified Alignments, it follows from a
3289 @LegalityName stated above.]}
3290 @end{Discussion}
3291
3292 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1],ARef=[AI05-0269-1]}
3293 A @nt{component_clause}, Component_Size clause, or
3294 @Chg{Version=[3],New=[specifying the],Old=[a @nt{pragma}]} Pack
3295 @Chg{Version=[3],New=[aspect as True ],Old=[]}can override a specified
3296 Alignment.
3297 @begin{Discussion}
3298 Most objects are allocated by the implementation; for these, the
3299 implementation obeys the Alignment. The implementation is of course
3300 allowed to make an object @i{more} aligned than its Alignment requires
3301 @em an object whose Alignment is 4 might just happen to land at an
3302 address that's a multiple of 4096.
3303 For formal parameters, the implementation might
3304 want to force an Alignment stricter than the parameter's subtype.
3305 For example, on some systems, it is customary to always align
3306 parameters to 4 storage elements.
3307
3308 Hence, one might initially assume that the implementation could
3309 evilly make all Alignments 1 by default, even though integers, say,
3310 are normally aligned on a 4-storage-element boundary. However, the
3311 implementation cannot get away with that @em if the Alignment is 1,
3312 the generated code cannot assume an Alignment of 4, at least not for
3313 objects allocated outside the control of the implementation.
3314
3315 Of course implementations can assume anything they can prove, but
3316 typically an implementation will be unable to prove much about the
3317 alignment of, say, an imported object. Furthermore, the information
3318 about where an address @lquotes@;came from@rquotes@; can be lost to the compiler due to
3319 separate compilation.
3320
3321 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3322 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3323 The Alignment of an object that is a component of a packed
3324 composite object will usually be 0, to indicate that the component is
3325 not necessarily aligned on a storage element boundary.
3326 For a subtype, an Alignment of 0 means that objects of the subtype are
3327 not normally aligned on a storage element boundary at all.
3328 For example, an implementation might choose to make Component_Size be
3329 @Chg{Version=[2],New=[1],Old=[0]}
3330 for an array of Booleans, even
3331 when @Chg{Version=[3],New=[the],Old=[@nt{pragma}]} Pack
3332 @Chg{Version=[3],New=[aspect ],Old=[]}has not been
3333 specified for the array.
3334 In this case, Boolean'Alignment would be 0.
3335 (In the presence of tasking, this would in general be feasible only on a
3336 machine that had atomic test-bit and set-bit instructions.)
3337
3338 If the machine has no particular natural alignments, then all subtype
3339 Alignments will probably be 1 by default.
3340
3341 Specifying an Alignment of 0 in an @nt{attribute_definition_clause} does
3342 not require the implementation to do anything (except return 0 when the
3343 Alignment is queried).
3344 However, it might be taken as advice on some implementations.
3345
3346 It is an error for an Address clause to disobey the object's Alignment.
3347 The error cannot be detected at compile time, in general, because the
3348 Address is not necessarily known at compile time (and is almost
3349 certainly not static). We do not require a runtime check, since
3350 efficiency seems paramount here, and Address clauses are treading on
3351 thin ice anyway. Hence, this misuse of Address clauses is just like any
3352 other misuse of Address clauses @em it's erroneous.
3353
3354 A type extension can have a stricter Alignment than its parent.
3355 This can happen, for example, if the Alignment of the parent is 4,
3356 but the extension contains a component with Alignment 8.
3357 The Alignment of a class-wide type or object will have to be the
3358 maximum possible Alignment of any extension.
3359
3360 The recommended level of support for the Alignment attribute is
3361 intended to reflect a minimum useful set of capabilities. An
3362 implementation can assume that all Alignments are multiples of each
3363 other @em 1, 2, 4, and 8 might be the only supported Alignments for
3364 subtypes. An Alignment of 3 or 6 is unlikely to be useful.
3365 For objects that can be allocated statically, we recommend that
3366 the implementation support larger alignments, such as 4096. We do
3367 not recommend such large alignments for subtypes, because the maximum
3368 subtype alignment will also have to be used as the alignment of stack
3369 frames, heap objects, and class-wide objects. Similarly, we do not
3370 recommend such large alignments for stack-allocated objects.
3371
3372 If the maximum default Alignment is 8
3373 (say, Long_Float'Alignment = 8),
3374 then the implementation can refuse to accept stricter alignments
3375 for subtypes. This simplifies the generated code, since the compiler
3376 can align the stack and class-wide types to this maximum without a
3377 substantial waste of space (or time).
3378
3379 Note that the recommended level of support takes into account
3380 interactions between Size and Alignment. For example, on a 32-bit
3381 machine with 8-bit storage elements, where load and store
3382 instructions have to be aligned according to the size of the thing
3383 being loaded or stored, the implementation might accept an Alignment
3384 of 1 if the Size is 8, but might reject an Alignment of 1 if the Size
3385 is 32. On a machine where unaligned loads and stores are merely
3386 inefficient (as opposed to causing hardware traps),
3387 we would expect an Alignment of 1 to be supported for any Size.
3388 @end{Discussion}
3389 @end{Notes}
3390
3391 @begin{DiffWord83}
3392 The nonnegative part is missing from RM83
3393 (for @nt{mod_clause}s, nee @ntf{alignment_clause}s,
3394 which are an obsolete version of Alignment clauses).
3395 @end{DiffWord83}
3396
3397 @begin{StaticSem}
3398 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3399 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
3400 @Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes an object]}:
3401 @begin{Description}
3402 @Attribute{Prefix=<X>, AttrName=<Size>,
3403 Text=<Denotes the size in bits of
3404 the representation of the object.
3405 The value of this attribute is of the type
3406 @i{universal_integer}.>}
3407 @EndPrefixType{}
3408 @begin{Ramification}
3409 Note that Size is in bits even if Machine_Radix is 10.
3410 Each decimal digit (and the sign) is presumably represented
3411 as some number of bits.
3412 @end{Ramification}
3413
3414 @NoPrefix@PDefn2{Term=[specifiable], Sec=(of Size for stand-alone objects)}
3415 @Defn{Size clause}
3416 Size may be specified for @Redundant[stand-alone] objects
3417 via an @nt{attribute_definition_clause};
3418 the expression of such a clause shall be static and its
3419 value nonnegative.@Chg{Version=[3],New=[@AspectDefn{Size (object)}],Old=[]}
3420
3421 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Size (object)],
3422 Text=[@ChgAdded{Version=[3],Text=[Size in bits of an object.]}]}
3423
3424 @end{Description}
3425 @end{StaticSem}
3426
3427 @begin{ImplAdvice}
3428 @ChgNote{Moved from 13.9}
3429 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]}
3430 @ChgAdded{Version=[2],Text=[The size of an array object should not include
3431 its bounds.]}
3432 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
3433 Text=[The Size of an array object should not include its bounds.]}]}
3434
3435 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02],ARef=[AI95-00291-02]}
3436 @ChgDeleted{Version=[2],Type=[Leading],Text=[]}@Comment{A fake to get a conditional Leading}
3437 @PDefn2{Term=[recommended level of support], Sec=(Size attribute)}
3438 The recommended level of support for the Size attribute
3439 of objects is@Chg{Version=[2],New=[ the same as for subtypes (see below),
3440 except that only a confirming Size clause need be supported for an aliased
3441 elementary object.],Old=[:]}
3442 @begin{Itemize}
3443 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00051-02]}
3444 @ChgDeleted{Version=[2],Text=[A Size clause should be supported for an object
3445 if the specified Size is at least as large as its subtype's Size, and
3446 corresponds to a size in storage elements that is a multiple of the object's
3447 Alignment (if the Alignment is nonzero).]}
3448 @Comment{No ImplDef summary here; there is no reason to separately mention it}
3449 @end{Itemize}
3450 @end{ImplAdvice}
3451
3452 @begin{StaticSem}
3453 @Leading@Keepnext@;For @PrefixType{every subtype S}:
3454 @begin{Description}
3455 @AttributeLeading{Prefix=<S>, AttrName=<Size>,
3456 Text=<If S is definite,
3457 denotes the size @Redundant{(in bits)}
3458 that the implementation would choose for
3459 the following objects of subtype S:
3460 @begin{Itemize}
3461 A record component of subtype S
3462 when the record type is packed.
3463
3464 The formal parameter of an instance of Unchecked_Conversion
3465 that converts from subtype S to some other subtype.
3466 @end{Itemize}
3467
3468 @NoPrefix@;If S is indefinite,
3469 the meaning is implementation defined.
3470 The value of this attribute is of the type
3471 @i{universal_integer}.>}
3472 @PDefn2{Term=[specifiable], Sec=(of Size for first subtypes)}
3473 @Defn{Size clause}
3474 The Size of an object is at least as large as that of its subtype,
3475 unless the object's Size is determined by a Size clause,
3476 a component_clause, or a Component_Size clause.
3477 Size may be specified for first subtypes
3478 via an @nt{attribute_@!definition_@!clause};
3479 the expression of such a clause shall be static
3480 and its value nonnegative.@Chg{Version=[3],New=[@AspectDefn{Size (subtype)}],Old=[]}
3481 @ImplDef{The meaning of Size for indefinite subtypes.}
3482 @begin{Reason}
3483 @Leading@;The effects of specifying the Size of a subtype are:
3484 @begin{Itemize}
3485 Unchecked_Conversion works in a predictable manner.
3486
3487 A composite type cannot be packed so tightly as to override
3488 the specified Size of a component's subtype.
3489
3490 Assuming the @ImplAdviceName is obeyed,
3491 if the specified Size allows independent addressability,
3492 then the Size of certain objects of the subtype
3493 should be equal to the subtype's Size.
3494 This applies to stand-alone objects and to components
3495 (unless a @nt{component_clause} or a Component_Size clause applies).
3496 @end{Itemize}
3497
3498 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3499 A @nt{component_clause} or a Component_Size clause can cause an object
3500 to be smaller than its subtype's specified size.
3501 @Chg{Version=[3],New=[The aspect],Old=[A @nt{pragma}]}
3502 Pack cannot; if a component subtype's size is specified,
3503 this limits how tightly the composite object can be packed.
3504
3505 The Size of a class-wide (tagged) subtype is unspecified,
3506 because it's not clear what it should mean;
3507 it should certainly not depend on all of the descendants that happen
3508 to exist in a given program.
3509 Note that this cannot be detected at compile time,
3510 because in a generic unit, it is not necessarily known
3511 whether a given subtype is class-wide.
3512 It might raise an exception on some implementations.
3513 @end{Reason}
3514 @begin{Ramification}
3515 @Leading@;A Size clause for a numeric subtype need not
3516 affect the underlying numeric type.
3517 For example, if I say:
3518 @begin{Example}
3519 @key[type] S @key[is] @key[range] 1..2;
3520 @key[for] S'Size @key[use] 64;
3521 @end{Example}
3522
3523 I am not guaranteed that S'Base'Last >= 2**63@en@;1,
3524 nor that intermediate results will be represented in 64 bits.
3525 @end{Ramification}
3526 @begin{Reason}
3527 There is no need to complicate implementations for this sort of
3528 thing, because the right way to affect the base range of a type
3529 is to use the normal way of declaring the base range:
3530 @begin{Example}
3531 @key[type] Big @key[is] @key[range] -2**63 .. 2**63 - 1;
3532 @key[subtype] Small @key[is] Big @key[range] 1..1000;
3533 @end{Example}
3534 @end{Reason}
3535 @begin{Ramification}
3536 The Size of a large unconstrained subtype (e.g. String'Size)
3537 is likely to raise Constraint_Error,
3538 since it is a nonstatic expression of type @i{universal_integer}
3539 that might overflow the largest signed integer type.
3540 There is no requirement that the largest integer type be able to
3541 represent the size in bits of the largest possible object.
3542 @end{Ramification}
3543
3544 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Size (subtype)],
3545 Text=[@ChgAdded{Version=[3],Text=[Size in bits of a subtype.]}]}
3546
3547 @end{Description}
3548 @EndPrefixType{}
3549 @end{StaticSem}
3550
3551 @begin{ImplReq}
3552 In an implementation, Boolean'Size shall be 1.
3553 @end{ImplReq}
3554
3555 @begin{ImplAdvice}
3556 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
3557 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0059-1]}
3558 @ChgDeleted{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional "Leading".}
3559 If the Size of a subtype @Chg{Version=[2],New=[@Chg{Version=[5],New=[is
3560 nonconfirming and ],Old=[]}],Old=[is specified,
3561 and ]}allows for efficient independent addressability
3562 (see @RefSecNum{Shared Variables}) on the target architecture,
3563 then the @Chg{Version=[5],New=[Object_Size],Old=[Size of the following objects]}
3564 of the subtype should @Chg{Version=[5],New=[have the
3565 same value in the absence of an explicit specification of a different
3566 value.],Old=[equal the Size of the subtype:]}
3567 @begin{NotIso}
3568 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 51
3569 and 52 were moved to the @ImplAdviceTitle for attribute Object_Size.>}]}@Comment{This
3570 message should be deleted if the paragraphs are ever renumbered.}
3571 @end{NotIso}
3572
3573 @begin{Itemize}
3574 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0059-1]}
3575 @ChgDeleted{Version=[5],Text=[Aliased objects (including components).]}
3576
3577 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0059-1]}
3578 @ChgDeleted{Version=[5],Text=[Unaliased components, unless the Size of the
3579 component is determined by a @nt{component_clause} or Component_Size
3580 clause.]}
3581 @end{Itemize}
3582 @ChgImplAdvice{Version=[5],Kind=[RevisedAdded],InitialVersion=[2],
3583 Text=[@ChgAdded{Version=[2],
3584 Text=[If the Size of a subtype @Chg{Version=[5],New=[ is nonconfirming
3585 and],Old=[]}allows for efficient independent
3586 addressability, then the @Chg{Version=[5],New=[Object_Size of the subtype
3587 (unless otherwise specified)],Old=[Size of most objects of the subtype]} should
3588 equal the Size of the subtype.]}]}
3589 @begin{Ramification}
3590 Thus, on a typical 32-bit machine,
3591 @lquotes@;@key[for] S'Size @key[use] 32;@rquotes@;
3592 will guarantee that aliased objects of subtype S,
3593 and components whose subtype is S, will have Size
3594 = 32 (assuming the implementation chooses to obey this @ImplAdviceTitle).
3595 On the other hand, if one writes,
3596 @lquotes@;@key[for] S2'Size @key[use] 5;@rquotes@;
3597 then stand-alone objects of subtype S2 will typically have their Size
3598 rounded up to ensure independent addressability.
3599
3600 Note that @lquotes@;@key[for] S'Size @key[use] 32;@rquotes@;
3601 does not cause things like formal parameters to have Size = 32 @em
3602 the implementation is allowed to make all parameters be at least 64
3603 bits, for example.
3604
3605 Note that
3606 @lquotes@;@key[for] S2'Size @key[use] 5;@rquotes@;
3607 requires record components whose subtype is S2 to be exactly 5 bits
3608 if the record type is packed.
3609 The same is not true of array components;
3610 their Size may be rounded up to the nearest factor of the word size.
3611 @end{Ramification}
3612 @begin{ImplNote}
3613 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
3614 @Defn{gaps}
3615 On most machines, arrays don't contain gaps between @Chg{Version=[2],
3616 New=[elementary ],Old=[]}components;
3617 if the Component_Size is greater than the Size of the component subtype,
3618 the extra bits are generally considered part of each component,
3619 rather than gaps between components.
3620 On the other hand,
3621 a record might contain gaps between @Chg{Version=[2],
3622 New=[elementary ],Old=[]}components,
3623 depending on what sorts of loads, stores, and masking operations
3624 are generally done by the generated code.
3625
3626 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00291-02]}
3627 For an array,
3628 any extra bits stored for each @Chg{Version=[2],
3629 New=[elementary ],Old=[]}component will generally be part
3630 of the component @em the whole point of storing extra bits is to
3631 make loads and stores more efficient by avoiding the need to mask out
3632 extra bits.
3633 The PDP-10 is one counter-example;
3634 since the hardware supports byte strings with a gap at the end of
3635 each word,
3636 one would want to pack in that manner.
3637 @end{ImplNote}
3638
3639 @begin{Reason}
3640 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
3641 @ChgAdded{Version=[5],Text=[We talk about the explicit specification of
3642 Object_Size so that we have specified what happens if both Object_Size and
3643 Size are specified incompatibly; we give priority to Object_Size. Note
3644 that the value of Size no longer has any direct effect on the Size of
3645 objects; what happens instead is that the value of Size can have an effect
3646 on the value of Object_Size in the absence of a specification for Object_Size,
3647 and it is always the value of Object_Size that determines the size of an
3648 object.]}
3649 @end{Reason}
3650
3651
3652 A Size clause on a composite subtype should not affect
3653 the internal layout of components.
3654 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
3655 Text=[A Size clause on a composite subtype should not affect
3656 the internal layout of components.]}]}
3657 @begin{Reason}
3658 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3659 That's what Pack @Chg{Version=[3],New=[aspects],Old=[@nt{pragma}s]},
3660 @nt{record_representation_clause}s,
3661 and Component_Size clauses are for.
3662 @end{Reason}
3663
3664 @Leading@PDefn2{Term=[recommended level of support], Sec=(Size attribute)}
3665 The recommended level of support for the Size attribute
3666 of subtypes is:
3667 @begin{Itemize}
3668
3669 The Size (if not specified) of a static discrete or fixed point subtype
3670 should be the number of bits needed to represent each value belonging to
3671 the subtype using an unbiased representation,
3672 leaving space for a sign bit only if the subtype contains negative
3673 values.
3674 If such a subtype is a first subtype,
3675 then an implementation should support a specified Size for it that
3676 reflects this representation.
3677
3678 @begin{ImplNote}
3679 This applies to static enumeration subtypes,
3680 using the internal codes used to represent the values.
3681
3682 For a two's-complement machine, this implies that
3683 for a static signed integer subtype S,
3684 if all values of S are in the range 0 .. 2@+{@i{n}}@en@;1,
3685 or all values of S are in the range @en@;2@+{@i{n@en@;1}} .. 2@+{@i{n@en@;1}}@en@;1,
3686 for some @i{n} less than or equal to the word size,
3687 then S'Size should be <= the smallest such @i{n}.
3688 For a one's-complement machine,
3689 it is the same except that in the second range,
3690 the lower bound @lquotes@;@en@;2@+{@i{n@en@;1}}@rquotes@; is replaced by @lquotes@;@en@;2@+{@i{n@en@;1}}+1@rquotes@;.
3691
3692
3693 If an integer subtype (whether signed or unsigned)
3694 contains no negative values, the Size should not include space
3695 for a sign bit.
3696
3697
3698 Typically, the implementation will choose to make the Size of a
3699 subtype be exactly the smallest such @i{n}.
3700 However, it might, for example, choose a biased representation,
3701 in which case it could choose a smaller value.
3702
3703 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3704 On most machines, it is in general not a good idea to pack (parts of)
3705 multiple stand-alone objects into the same storage element,
3706 because (1) it usually doesn't save much space,
3707 and (2) it requires locking to prevent tasks from interfering with each
3708 other, since separate stand-alone objects are independently
3709 addressable.
3710 Therefore, if S'Size = 2
3711 on a machine with 8-bit storage elements,
3712 the size of a stand-alone object of subtype S will probably not be 2.
3713 It might, for example, be 8, 16 or 32, depending on the availability
3714 and efficiency of various machine instructions.
3715 The same applies to components of composite types,
3716 unless @Chg{Version=[3],New=[Pack],Old=[packing]},
3717 Component_Size, or record layout is specified.
3718
3719 For an unconstrained discriminated object,
3720 if the implementation allocates the maximum
3721 possible size,
3722 then the Size attribute should return that maximum
3723 possible size.
3724 @end{ImplNote}
3725 @begin{Ramification}
3726 The Size of an object X is not usually the same as that of
3727 its subtype S.
3728 If X is a stand-alone object or a parameter, for example,
3729 most implementations will round X'Size up to a storage
3730 element boundary, or more, so X'Size might be greater than S'Size.
3731 On the other hand,
3732 X'Size cannot be less than S'Size, even
3733 if the implementation can prove, for example,
3734 that the range of values actually taken on by X during execution
3735 is smaller than the range of S.
3736
3737 For example, if S is a first integer subtype whose range
3738 is 0..3, S'Size will be probably be 2 bits, and components of
3739 packed composite types of this subtype will be 2 bits
3740 (assuming Storage_Unit is a multiple of 2),
3741 but stand-alone objects and parameters will probably
3742 not have a size of 2 bits; they might be rounded up to
3743 32 bits, for example.
3744 On the other hand, Unchecked_Conversion will use the 2-bit size,
3745 even when converting a stand-alone object,
3746 as one would expect.
3747
3748 Another reason for making the Size of an object bigger than
3749 its subtype's Size is to support the run-time detection of
3750 uninitialized variables.
3751 @PDefn{uninitialized variables}
3752 The implementation might add an extra value to a discrete subtype
3753 that represents the uninitialized state,
3754 and check for this value on use.
3755 In some cases, the extra value will require an extra bit in the
3756 representation of the object.
3757 Such detection is not required by the language.
3758 If it is provided, the implementation has to be able to turn it off.
3759 For example, if the programmer gives a
3760 @nt{record_representation_clause} or Component_Size clause that makes
3761 a component too small to allow the extra bit,
3762 then the implementation will not be able to perform the checking
3763 (not using this method, anyway).
3764
3765 @Leading@;The fact that the size of an object is not necessarily the same
3766 as its subtype can be confusing:
3767 @begin{Example}
3768 @key[type] Device_Register @key[is] @key[range] 0..2**8 - 1;
3769 @key[for] Device_Register'Size @key[use] 8; --@RI{ Confusing!}
3770 My_Device : Device_Register;
3771 @key[for] My_Device'Address @key[use] To_Address(16#FF00#);
3772 @end{Example}
3773
3774 The programmer might think that My_Device'Size is 8,
3775 and that My_Device'Address points at an 8-bit location.
3776 However, this is not true.
3777 In Ada 83 (and in Ada 95), My_Device'Size might well be 32,
3778 and My_Device'Address might well point at the high-order 8 bits of
3779 the 32-bit object, which are always all zero bits.
3780 If My_Device'Address is passed to an assembly language subprogram,
3781 based on the programmer's assumption,
3782 the program will not work properly.
3783 @end{Ramification}
3784 @begin{Reason}
3785 It is not reasonable to require that an implementation allocate
3786 exactly 8 bits to all objects of subtype Device_Register.
3787 For example, in many run-time models, stand-alone objects
3788 and parameters are always aligned to a word boundary.
3789 Such run-time models are generally based on hardware considerations
3790 that are beyond the control of the implementer.
3791 (It is reasonable to require that an implementation allocate exactly
3792 8 bits to all components of subtype Device_Register, if packed.)
3793 @end{Reason}
3794 @begin{Ramification}
3795 @Leading@;The correct way to write the above code is like this:
3796 @begin{Example}
3797 @key[type] Device_Register @key[is] @key[range] 0..2**8 - 1;
3798 My_Device : Device_Register;
3799 @key[for] My_Device'Size @key[use] 8;
3800 @key[for] My_Device'Address @key[use] To_Address(16#FF00#);
3801 @end{Example}
3802
3803 If the implementation cannot accept 8-bit stand-alone objects,
3804 then this will be illegal.
3805 However, on a machine where an 8-bit device register exists,
3806 the implementation will probably be able to accept 8-bit stand-alone
3807 objects. Therefore, My_Device'Size will be 8,
3808 and My_Device'Address will point at those 8 bits,
3809 as desired.
3810
3811 If an object of subtype Device_Register is passed to a foreign
3812 language subprogram, it will be passed according to that subprogram's
3813 conventions. Most foreign language implementations have similar
3814 run-time model restrictions.
3815 For example, when passing to a C function,
3816 where the argument is of
3817 the C type char* (that is, pointer to char),
3818 the C compiler will generally expect a full word value,
3819 either on the stack, or in a register.
3820 It will @i{not} expect a single byte.
3821 Thus, Size clauses for subtypes really have nothing to do with
3822 passing parameters to foreign language subprograms.
3823 @end{Ramification}
3824
3825 For a subtype implemented with levels of indirection,
3826 the Size should include the size of the pointers,
3827 but not the size of what they point at.
3828 @begin{Ramification}
3829 For example, if a task object is represented as a pointer to some
3830 information (including a task stack), then the size of the object
3831 should be the size of the pointer.
3832 The Storage_Size, on the other hand,
3833 should include the size of the stack.
3834 @end{Ramification}
3835
3836 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]}
3837 @ChgAdded{Version=[2],Type=[Leading],Text=[An implementation should support a
3838 Size clause for a discrete type, fixed point type, record type, or array type,
3839 subject to the following:]}
3840 @begin{InnerItemize}
3841
3842 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00051-02]}
3843 @ChgAdded{Version=[2],Text=[An implementation need not support a Size clause
3844 for a signed integer type specifying a Size greater than that of the largest
3845 signed integer type supported by the implementation in the absence of a size
3846 clause (that is, when the size is chosen by default). A corresponding
3847 limitation may be imposed for modular integer types, fixed point types,
3848 enumeration types, record types, and array types.]}
3849
3850 @begin{Discussion}
3851 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-02]}
3852 @ChgAdded{Version=[2],Text=[Note that the @lquotes@;corresponding
3853 limitation@rquotes for a record or array type implies that an implementation
3854 may impose some reasonable maximum size for records and arrays (e.g. 2**32
3855 bits), which is an upper bound (@lquotes@;capacity@rquotes limit) on the
3856 size, whether chosen by default or by being specified by the user. The
3857 largest size supported for records need not be the same as the largest
3858 size supported for arrays.]}
3859 @end{Discussion}
3860
3861 @begin{Ramification}
3862 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0155-1]}
3863 @ChgAdded{Version=[3],Text=[Only Size clauses with a size greater than or
3864 equal to the Size that would be chosen by default may be safely presumed to be
3865 supported on nonstatic elementary subtypes. Implementations may choose to
3866 support smaller sizes, but only if the Size allows any value of the subtype to
3867 be represented, for any possible value of the bounds.]}
3868 @end{Ramification}
3869
3870 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00291-02]}
3871 @ChgAdded{Version=[2],Text=[A nonconfirming size clause for the first subtype
3872 of a derived untagged by-reference type need not be supported.]}
3873 @end{InnerItemize}
3874 @end{Itemize}
3875 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3876 Text=[The recommended level of support for the Size attribute should be
3877 followed.]}]}
3878 @begin{Ramification}
3879 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
3880 @ChgAdded{Version=[2],Text=[There is no recommendation to support any
3881 nonconfirming Size clauses for types not mentioned above.
3882 Remember that
3883 @RefSecNum{Operational and Representation Aspects} requires support for
3884 confirming Size clauses for all types.]}
3885 @end{Ramification}
3886 @end{ImplAdvice}
3887
3888 @begin{Notes}
3889 Size is a subtype-specific attribute.
3890
3891 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3892 A @nt{component_clause} or Component_Size clause
3893 can override a specified Size.
3894 @Chg{Version=[3],New=[Aspect],Old=[A @nt{pragma}]} Pack cannot.
3895 @end{Notes}
3896
3897 @begin{Inconsistent83}
3898 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00114-01]}
3899 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 83}We specify
3900 the meaning of Size in much more
3901 detail than Ada 83. This is not technically an inconsistency, but it is in
3902 practice, as most Ada 83 compilers use a different definition for Size than
3903 is required here. This should have been documented more explicitly during
3904 the Ada 9X process.]}
3905 @end{Inconsistent83}
3906
3907 @begin{DiffWord83}
3908 The requirement for a nonnegative value in a Size clause
3909 was not in RM83, but it's hard to see how it would make sense.
3910 For uniformity, we forbid negative sizes,
3911 rather than letting implementations define their meaning.
3912 @end{DiffWord83}
3913
3914
3915 @begin{StaticSem}
3916 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0059-1]}
3917 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{every subtype S}:]}
3918 @begin(description)
3919 @ChgAttribute{Version=[5],Kind=[Added],ChginAnnex=[T],
3920 Leading=<F>, Prefix=<S>, AttrName=<Object_Size>, ARef=[AI12-0059-1],
3921 InitialVersion=[5], Text=[@Chg{Version=[5],New=[If S is definite, denotes
3922 the size (in bits) of a stand-alone aliased object, or a component of subtype
3923 S in the absence of an @nt{aspect_specification} or representation item that
3924 specifies the size of the object or component. If S is indefinite, the meaning
3925 is implementation-defined. The value of this attribute is of the type
3926 @i<universal_integer>.],Old=[]}]}@Comment{End of Annex text here.}
3927 @Chg{Version=[5],New=[If not specified otherwise, the Object_Size of a
3928 subtype is at least as large as the Size of the subtype. Object_Size may be
3929 specified via an @nt{attribute_definition_clause}; the expression of such a
3930 clause shall be static and its value nonnegative. All aliased objects with
3931 nominal subtype S have the size S'Object_Size. In the absence of an explicit
3932 specification, the Object_Size of a subtype S defined by a
3933 @nt{subtype_indication} without a constraint, is that of the value of the
3934 Object_Size of the subtype denoted by the @nt{subtype_mark} of the
3935 @nt{subtype_indication}, at the point of this definition.],Old=[]}
3936
3937 @ChgImplDef{Version=[5],Kind=[Added],InitialVersion=[5],Text=[@ChgAdded{Version=[5],Text=[The
3938 meaning of Object_Size for indefinite subtypes.]}]}
3939
3940 @begin{Ramification}
3941 @ChgRef{Version=[5],Kind=[AddedNormal]}
3942 @ChgAdded{Version=[5],Text=[We allow the specification of Object_Size
3943 for any subtype (@i<not> just first subtypes, as with other aspects). An
3944 implementation can, of course, put restrictions on which subtypes allow
3945 specification of Object_Size (as with any representation attribute).]}
3946 @end{Ramification}
3947 @end(description)
3948 @end{StaticSem}
3949
3950 @begin{ImplAdvice}
3951 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0059-1]}
3952 @ChgAdded{Version=[5],Text=[If S is a definite first subtype and S'Object_Size
3953 is not specified, S'Object_Size should be the smallest multiple of the storage
3954 element size larger than or equal to S'Size that is consistent with the
3955 alignment of S.]}
3956
3957 @ChgImplAdvice{Version=[5],Kind=[Added],Text=[@ChgAdded{Version=[5],
3958 Text=[If S is a definite first subtype for which Object_Size
3959 is not specified, S'Object_Size should be the smallest multiple of the storage
3960 element size larger than or equal to S'Size that is consistent with the
3961 alignment of S.]}]}
3962
3963 @begin{Reason}
3964 @ChgRef{Version=[5],Kind=[AddedNormal]}
3965 @ChgAdded{Version=[5],Type=[Leading],Text=[Many implementations @ldquote@;round up@rdquote
3966 allocations to the nearest multiple of the alignment. For instance, this
3967 example appears in the GNAT documentation:]}
3968
3969 @begin{Indent}
3970 @ChgRef{Version=[5],Kind=[AddedNormal]}
3971 @ChgAdded{Version=[5],Type=[Leading],Text=<[Given] a record containing
3972 an integer and a character:>}
3973 @begin{Example}
3974 @ChgRef{Version=[5],Kind=[AddedNormal]}
3975 @ChgAdded{Version=[5],Text=[@key[type] Rec @key[is record]
3976 I : Integer;
3977 C : Character;
3978 @key[end record];]}
3979 @end{Example}
3980 @ChgRef{Version=[5],Kind=[AddedNormal]}
3981 @ChgAdded{Version=[5],Text=[will have a size of 40 (that is Rec'Size will
3982 be 40). The alignment will be 4, because of the integer field, and so the
3983 default size of record objects for this type will be 64 (8 bytes).]}
3984 @end{Indent}
3985
3986 @ChgRef{Version=[5],Kind=[AddedNormal]}
3987 @ChgAdded{Version=[5],Text=[We purposely used the vague phrase
3988 @ldquote@;consistent with the alignment of S@rdquote so
3989 that implementations that do not round up allocations (just using padding
3990 to provide alignment) are not required to do any rounding up.]}
3991 @end{Reason}
3992
3993 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0059-1]}
3994 @ChgAdded{Version=[5],Type=[Leading],Text=[If X denotes an object (including
3995 a component) of subtype S, X'Size should equal S'Object_Size, unless:]}
3996 @begin{Itemize}
3997 @ChgRef{Version=[5],Kind=[Added]}
3998 @ChgAdded{Version=[5],Text=[X'Size is specified; or]}
3999
4000 @ChgRef{Version=[5],Kind=[Added]}
4001 @ChgAdded{Version=[5],Text=[X is a nonaliased stand-alone object; or]}
4002
4003 @ChgRef{Version=[5],Kind=[Added]}
4004 @ChgAdded{Version=[5],Text=[The size of X is determined by a
4005 @nt{component_clause} or Component_Size clause; or]}
4006
4007 @ChgRef{Version=[5],Kind=[Added]}
4008 @ChgAdded{Version=[5],Text=[The type containing component X is packed.]}
4009 @end{Itemize}
4010
4011 @ChgImplAdvice{Version=[5],Kind=[Added],Text=[@ChgAdded{Version=[5],
4012 Text=[The Size of most objects of a subtype should equal the Object_Size of
4013 the subtype.]}]}
4014
4015 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0059-1]}
4016 @ChgAdded{Version=[5],Text=[An Object_Size clause on a composite type
4017 should not affect the internal layout of components.]}
4018
4019 @ChgImplAdvice{Version=[5],Kind=[Added],Text=[@ChgAdded{Version=[5],
4020 Text=[An Object_Size clause on a composite type
4021 should not affect the internal layout of components.]}]}
4022
4023 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0059-1]}
4024 @ChgAdded{Version=[5],Type=[Leading],Text=[The recommended level of support for
4025 the Object_Size attribute of subtypes is:]}
4026
4027 @begin{Itemize}
4028 @ChgRef{Version=[5],Kind=[Added]}
4029 @ChgAdded{Version=[5],Text=[If S is a static signed integer subtype, the
4030 implementation should support the specification of S'Object_Size to match the
4031 size of any signed integer base subtype provided by the implementation that is
4032 no smaller than S'Size. Corresponding support is expected for modular integer
4033 subtypes, fixed point subtypes, and enumeration subtypes.]}
4034
4035 @begin{Ramification}
4036 @ChgRef{Version=[5],Kind=[AddedNormal]}
4037 @ChgAdded{Version=[5],Text=[The intent is that a compiler need support only
4038 those Object_Sizes for integer subtypes that it might select for an integer
4039 type declaration. Similarly for the other kinds of subtypes listed.]}
4040 @end{Ramification}
4041
4042 @ChgRef{Version=[5],Kind=[Added]}
4043 @ChgAdded{Version=[5],Text=[If S is an array or record subtype with static
4044 constraints and S is not a first subtype of a derived untagged by-reference
4045 type, the implementation should support the specification of S'Object_Size to
4046 be any multiple of the storage element size that is consistent with the
4047 alignment of S, that is no smaller than S'Size, and that is no larger than
4048 that of the largest composite subtype supported by the implementation.]}
4049
4050 @begin{Discussion}
4051 @ChgRef{Version=[5],Kind=[AddedNormal]}
4052 @ChgAdded{Version=[5],Text=[Any extra bits required this way will be padding
4053 bits. Unlike elementary objects, padding bits can be considered part of
4054 composite objects.]}
4055 @end{Discussion}
4056
4057 @ChgRef{Version=[5],Kind=[Added]}
4058 @ChgAdded{Version=[5],Text=[If S is some other subtype, only confirming
4059 specifications of Object_Size need be supported.]}
4060 @end{Itemize}
4061
4062 @ChgImplAdvice{Version=[5],Kind=[Added],Text=[@ChgAdded{Version=[5],
4063 Text=[The recommended level of support for the Object_Size attribute should
4064 be followed.]}]}
4065 @end{ImplAdvice}
4066
4067
4068 @begin{StaticSem}
4069 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
4070 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
4071 @Chg{New=[@nt{prefix}],Old=[prefix]} T that denotes a task
4072 object @Redundant[(after any implicit dereference)]]}:
4073 @begin{Description}
4074 @ChgAttribute{Version=[3], Kind=[Revised], ChginAnnex=[F], Leading=[F],
4075 Prefix=<T>, AttrName=<Storage_Size>, ARef=[AI05-0229-1],
4076 Text=<Denotes the number of storage elements reserved for
4077 the task.
4078 The value of this attribute is of the type
4079 @i{universal_integer}.
4080 The Storage_Size includes the size of the task's stack,
4081 if any. The language does not specify whether or
4082 not it includes other storage associated with the task
4083 (such as the @lquotes@;task control block@rquotes@; used by some
4084 implementations.)>}
4085 If @Chg{Version=[3],New=[the aspect],Old=[a @nt{pragma}]} Storage_Size is
4086 @Chg{Version=[3],New=[specified for the type of the object],Old=[given]},
4087 the value of the Storage_Size attribute is at least
4088 the value @Chg{Version=[3],New=[determined by the aspect],Old=[specified
4089 in the @nt{pragma}]}.
4090 @EndPrefixType{}
4091 @begin{Ramification}
4092 The value of this attribute is never negative,
4093 since it is impossible to @lquotes@;reserve@rquotes@; a negative number
4094 of storage elements.
4095
4096 If the implementation chooses to allocate an initial amount of
4097 storage, and then increase this as needed,
4098 the Storage_Size cannot include the additional amounts
4099 (assuming the allocation of the additional amounts can raise
4100 Storage_Error); this is inherent in the meaning of @lquotes@;reserved.@rquotes@;
4101
4102 The implementation is allowed to allocate different amounts of
4103 storage for different tasks of the same subtype.
4104
4105 Storage_Size is also defined for access subtypes
4106 @em see @RefSecNum{Storage Management}.
4107 @end{Ramification}
4108 @end{Description}
4109 @end{StaticSem}
4110
4111 @begin{Intro}
4112 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI95-0229-1]}
4113 @redundant[@Chg{Version=[3],New=[Aspect],Old=[@IndexSeeAlso{Term=[Storage_Size clause],See=[pragma Storage_Size]}
4114 A @nt{pragma}]} Storage_Size specifies the amount of storage to be
4115 reserved for the execution of a task.]
4116 @end{Intro}
4117
4118 @begin{NotIso}
4119 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 62
4120 through 65 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
4121 should be deleted if the paragraphs are ever renumbered.}
4122 @end{NotIso}
4123
4124 @begin{Syntax}
4125 @begin{SyntaxText}
4126 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
4127 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
4128 @nt{pragma} Storage_Size is as follows:]}
4129 @end{SyntaxText}
4130
4131 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
4132 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
4133 Text=[@key{pragma} @prag(Storage_Size)(@Syn2{expression});]}>
4134
4135 @begin{SyntaxText}
4136 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
4137 @ChgDeleted{Version=[3],Text=[A @nt{pragma} Storage_Size is allowed only
4138 immediately within a @nt{task_definition}.]}
4139 @end{SyntaxText}
4140 @end{Syntax}
4141
4142 @begin{Resolution}
4143 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
4144 @ChgDeleted{Version=[3],Text=[@PDefn2{Term=[expected type],
4145 Sec=(Storage_Size pragma argument)}
4146 The @nt{expression} of a @nt<pragma> Storage_Size
4147 is expected to be of any integer type.]}
4148 @end{Resolution}
4149
4150 @begin{StaticSem}
4151 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1],ARef=[AI05-0269-1]}
4152 @ChgAdded{Version=[3],Type=[Leading],Text=[For a task type (including the
4153 anonymous type of a @nt{single_task_declaration}),
4154 the following language-defined representation aspect may be specified:]}
4155
4156 @begin{Description}
4157 @ChgRef{Version=[3],Kind=[Added]}
4158 @ChgAdded{Version=[3],Text=[Storage_Size@\The Storage_Size aspect is
4159 an @nt{expression}, which shall be of any integer
4160 type.@AspectDefn{Storage_Size (task)}]}
4161
4162 @begin{Honest}
4163 @ChgRef{Version=[3],Kind=[AddedNormal]}
4164 @ChgAdded{Version=[3],Text=[This definition somewhat conflicts with the
4165 "automatic" one for the obsolescent attribute Storage_Size (which can be
4166 specified). The only difference is where the given expression is evaluated.
4167 We intend for the above definition to supersede that "automatic"
4168 definition for this attribute.]}
4169 @end{Honest}
4170 @begin{Ramification}
4171 @ChgRef{Version=[3],Kind=[AddedNormal]}
4172 @ChgAdded{Version=[3],Text=[Note that the value of the Storage_Size aspect
4173 @i<is> an @nt{expression}; it is not the @i<value> of an @nt{expression}.
4174 The @nt{expression} is evaluated for each object of the type (see below).]}
4175 @end{Ramification}
4176
4177 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Storage_Size (task)],
4178 Text=[@ChgAdded{Version=[3],Text=[Size in storage elements reserved for a task
4179 type or single task object.]}]}
4180
4181 @end{Description}
4182 @end{StaticSem}
4183
4184 @begin{Legality}
4185 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
4186 @ChgAdded{Version=[3],Text=[The Storage_Size aspect shall not be specified for a
4187 task interface type.]}
4188 @end{Legality}
4189
4190 @begin{RunTime}
4191 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
4192 @Chg{Version=[3],New=[When a task object is created, the @nt{expression}
4193 (if any) associated with the Storage_Size aspect of its
4194 type],Old=[A @nt<pragma> Storage_Size is elaborated when an object
4195 of the type defined by the immediately enclosing @nt<task_definition>
4196 is created.
4197 @PDefn2{Term=[elaboration],Sec=(Storage_Size pragma)}
4198 For the elaboration of a @nt<pragma> Storage_Size, the @nt<expression>]}
4199 is evaluated; the Storage_Size attribute of the newly created task object
4200 is at least the value of the @nt<expression>.
4201
4202 @begin{Ramification}
4203 The implementation is allowed to round up a specified Storage_Size
4204 amount.
4205 For example, if the implementation always allocates in
4206 chunks of 4096 bytes, the number 200 might be rounded
4207 up to 4096. Also, if the user specifies a negative
4208 number, the implementation has to normalize this to 0,
4209 or perhaps to a positive number.
4210
4211 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
4212 @ChgAdded{Version=[3],Text=[If the Storage_Size aspect is not specified for
4213 the type of the task object, the value of the Storage_Size attribute is
4214 unspecified.]}
4215 @end{Ramification}
4216
4217 @IndexCheck{Storage_Check}
4218 @Defn2{Term=[Storage_Error],Sec=(raised by failure of runtime check)}
4219 At the point of task object creation, or upon task activation,
4220 Storage_Error is raised if there is insufficient free storage to
4221 accommodate the requested Storage_Size.
4222 @end{RunTime}
4223
4224 @begin{StaticSem}
4225 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
4226 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
4227 @Chg{New=[@nt{prefix}],Old=[prefix]} X that denotes an array subtype or
4228 array object @Redundant[(after any implicit dereference)]]}:
4229 @begin{Description}
4230 @Attribute{Prefix=<X>, AttrName=<Component_Size>,
4231 Text=<Denotes the size in bits of
4232 components of the type of X.
4233 The value of this attribute is of type @i{universal_integer}.>}
4234 @EndPrefixType{}
4235
4236 @NoPrefix@PDefn2{Term=[specifiable], Sec=(of Component_Size for
4237 array types)}@Defn{Component_Size clause}
4238 Component_Size may be specified for array types
4239 via an @nt{attribute_@!definition_@!clause};
4240 the expression of such a clause shall be static,
4241 and its value nonnegative.@Chg{Version=[3],New=[@AspectDefn{Component_Size}],Old=[]}
4242
4243 @begin{ImplNote}
4244 The intent is that the value of X'Component_Size is always nonnegative.
4245 If the array is stored @lquotes@;backwards@rquotes@; in memory
4246 (which might be caused by an implementation-defined pragma),
4247 X'Component_Size is still positive.
4248 @end{ImplNote}
4249 @begin{Ramification}
4250 For an array object A, A'Component_Size = A(I)'Size for any index I.
4251 @end{Ramification}
4252
4253 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Component_Size],
4254 Text=[@ChgAdded{Version=[3],Text=[Size in bits of a component of an array type.]}]}
4255
4256 @end{Description}
4257 @end{StaticSem}
4258
4259 @begin{ImplAdvice}
4260 @Leading@PDefn2{Term=[recommended level of support], Sec=(Component_Size attribute)}
4261 The recommended level of support for the Component_Size attribute is:
4262 @begin{Itemize}
4263 An implementation need not support specified Component_Sizes that
4264 are less than the Size of the component subtype.
4265
4266 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
4267 An implementation should support specified Component_Sizes that
4268 are factors and multiples of the word size.
4269 For such Component_Sizes, the array should contain no gaps between
4270 components.
4271 For other Component_Sizes (if supported), the array should
4272 contain no gaps between components when
4273 @Chg{Version=[3],New=[Pack],Old=[packing]} is also specified;
4274 the implementation should forbid this combination in cases where it
4275 cannot support a no-gaps representation.
4276 @begin{Ramification}
4277 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
4278 For example, if Storage_Unit = 8, and Word_Size = 32,
4279 then the user is allowed to specify a Component_Size of
4280 1, 2, 4, 8, 16, and 32, with no gaps.
4281 In addition, @i{n}*32 is allowed for positive integers @i{n},
4282 again with no gaps.
4283 If the implementation accepts Component_Size = 3,
4284 then it might allocate 10 components per word,
4285 with a 2-bit gap at the end of each word
4286 (unless @Chg{Version=[3],New=[Pack],Old=[packing]} is also specified),
4287 or it might not have any internal gaps at all.
4288 (There can be gaps at either end of the array.)
4289 @end{Ramification}
4290 @end{Itemize}
4291 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4292 Text=[The recommended level of support for the Component_Size attribute should
4293 be followed.]}]}
4294 @end{ImplAdvice}
4295
4296 @begin{StaticSem}
4297 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
4298 @ChgAdded{Version=[3],Type=[Leading],Text=[For
4299 @ChgPrefixType{Version=[3],Kind=[Added],Text=[a @nt{prefix} X that denotes
4300 an object]}:]}
4301 @begin(description)
4302 @ChgNote{ Original Version=[3],Kind=[Added]}
4303 @ChgAttribute{Version=[4],Kind=[RevisedAdded],ChginAnnex=[T],
4304 Leading=<F>, Prefix=<X>, AttrName=<Has_Same_Storage>, ARef=[AI05-0191-1],
4305 InitialVersion=[3], Text=[@Chg{Version=[3],New=[X'Has_Same_Storage denotes
4306 a function with the following specification:],Old=[]}
4307
4308 @begin(Descexample)
4309 @ChgRef{Version=[3],Kind=[Added]}
4310 @ChgAdded{Version=[3],Text=[@key(function) X'Has_Same_Storage (@RI{Arg} : @RI{any_type})
4311 @key(return) Boolean]}
4312 @end(Descexample)
4313
4314 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1],ARef=[AI05-0264-1]}
4315 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0077-1]}
4316 @ChgAdded{Version=[3],NoPrefix=[T],Text=[The actual parameter shall be a name
4317 that denotes an object. The object denoted by the actual parameter can be of
4318 any type. This function evaluates the names of the objects
4319 involved@Chg{Version=[4],New=[. It],Old=[ and]}
4320 returns True if the representation of the object denoted by the actual
4321 parameter occupies exactly the same bits as the representation of the object
4322 denoted by X@Chg{Version=[4],New=[ and the objects occupy at least
4323 one bit],Old=[]}; otherwise, it returns False.]}]}@Comment{End of Annex text here.}
4324
4325 @begin{Discussion}
4326 @ChgRef{Version=[3],Kind=[AddedNormal]}
4327 @ChgAdded{Version=[3],Text=[Has_Same_Storage means that, if the representation
4328 is contiguous, the objects sit at the same address and occupy the same length
4329 of memory.]}
4330 @end{Discussion}
4331 @end(description)
4332
4333 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
4334 @ChgAdded{Version=[3],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} X that
4335 denotes an object}:]}
4336 @begin(description)
4337 @ChgAttribute{Version=[3],Kind=[Added],ChginAnnex=[T],
4338 Leading=<F>, Prefix=<X>, AttrName=<Overlaps_Storage>, ARef=[AI05-0191-1],
4339 InitialVersion=[3], Text=[@Chg{Version=[3],New=[X'Overlaps_Storage denotes
4340 a function with the following specification:],Old=[]}
4341
4342 @begin(Descexample)
4343 @ChgRef{Version=[3],Kind=[Added]}
4344 @ChgAdded{Version=[3],Text=[@key(function) X'Overlaps_Storage (@RI{Arg} : @RI{any_type})
4345 @key(return) Boolean]}
4346 @end(Descexample)
4347
4348 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1],ARef=[AI05-0264-1]}
4349 @ChgAdded{Version=[3],NoPrefix=[T],Text=[The actual parameter shall be a name
4350 that denotes an object. The object denoted by the actual parameter can be of
4351 any type. This function evaluates the names of the objects involved and
4352 returns True if the representation of the object denoted by the actual
4353 parameter shares at least one bit with the representation of the object
4354 denoted by X; otherwise, it returns False.]}]}@Comment{End of Annex text here.}
4355 @end(description)
4356 @end{StaticSem}
4357
4358 @begin{Notes}
4359 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
4360 @ChgAdded{Version=[3],Text=[X'Has_Same_Storage(Y) implies X'Overlaps_Storage(Y).]}
4361
4362 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0191-1]}
4363 @ChgAdded{Version=[3],Text=[X'Has_Same_Storage(Y) and X'Overlaps_Storage(Y) are
4364 not considered to be reads of X and Y.]}
4365 @end{Notes}
4366
4367 @begin{StaticSem}
4368
4369 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0009],ARef=[AI95-00137-01]}
4370 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0183-1]}
4371 @ChgAdded{Version=[1],Text=[The following
4372 @Chg{Version=[3],New=[type-related ],Old=[]}operational attribute is
4373 defined: External_Tag.]}
4374
4375 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4376 @Leading@;For @PrefixType{every subtype S of a tagged type @i(T)
4377 (specific or class-wide)}@Chg{New=[],Old=[, the following
4378 attribute is defined]}:
4379
4380 @begin{Description}
4381 @Comment{Original. @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
4382 Prefix=<S>, AttrName=<External_Tag>, Ref=[8652/0040], ARef=[AI95-00108-01], ...}
4383 We don't have a way to change multiple versions for attributes.}
4384 @ChgAttribute{Version=[3], Kind=[Revised], ChginAnnex=[F], Leading=[F],
4385 Prefix=<S>, AttrName=<External_Tag>, Ref=[8652/0040], ARef=[AI95-00108-01], ARef=[AI05-0092-1],
4386 InitialVersion=[0], Text=[@Defn{External_Tag clause}
4387 @PDefn2{Term=(specifiable), Sec=(of External_Tag for a tagged type)}
4388 S'External_Tag denotes an external string representation
4389 for S'Tag; it is of the predefined type String.
4390 External_Tag may be specified for a specific tagged type
4391 via an @nt{attribute_definition_clause};
4392 the expression of such a clause shall be static.@Chg{Version=[3],New=[@AspectDefn{External_Tag}],Old=[]}
4393 The default external tag representation is implementation defined.
4394 See @Chg{Version=[3],New=[],Old=[@RefSecNum{Dispatching Operations of Tagged Types}
4395 and ]}@RefSecNum{Stream-Oriented Attributes}.]}
4396 @Chg{New=[The value of External_Tag is never inherited@Redundant[; the
4397 default value is always used unless a new value is directly specified
4398 for a type].],Old=[]}
4399 @ImplDef{The default external representation for a type tag.}
4400 @end{Description}
4401 @EndPrefixType()
4402
4403 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[External_Tag],
4404 Text=[@ChgAdded{Version=[3],Text=[Unique identifier for a tagged type in
4405 streams.]}]}
4406
4407 @end{StaticSem}
4408
4409 @begin{RunTime}
4410 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0113-1]}
4411 @ChgAdded{Version=[3],Text=[If a user-specified external tag S'External_Tag is
4412 the same as T'External_Tag for some other tagged type declared by a different
4413 declaration in the partition, Program_Error is raised by the elaboration of the
4414 @nt{attribute_definition_clause}.@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}@IndexCheck{Program_Error_Check}]}
4415
4416 @begin{Ramification}
4417 @ChgRef{Version=[3],Kind=[AddedNormal]}
4418 @ChgAdded{Version=[3],Text=[This rule does not depend on the visibility of the
4419 other tagged type, but it does depend on the existence of the other tagged
4420 type. The other tagged type could have the default external tag or a
4421 user-specified external tag.]}
4422
4423 @ChgRef{Version=[3],Kind=[AddedNormal]}
4424 @ChgAdded{Version=[3],Text=[This rule allows the same declaration to be
4425 elaborated multiple times. In that case, different types could have the same
4426 external tag. If that happens, Internal_Tag would return some unspecified tag,
4427 and Descendant_Tag probably would return the intended tag (using the given
4428 ancestor to determine which type is intended). However, in some cases (such as
4429 multiple instantiations of a derived tagged type declared in a generic body),
4430 Tag_Error might be raised by Descendant_Tag if multiple types are identified.]}
4431
4432 @ChgRef{Version=[3],Kind=[AddedNormal]}
4433 @ChgAdded{Version=[3],Text=[Note that while there is a race condition inherent
4434 in this definition (which @nt{attribute_definition_clause} raises Program_Error
4435 depends on the order of elaboration), it doesn't matter as a program with two
4436 such clauses is simply wrong. Two types that both come from the same
4437 declaration are allowed, as noted previously.]}
4438 @end{Ramification}
4439 @end{RunTime}
4440
4441 @begin{ImplReq}
4442 In an implementation, the default external tag for each specific tagged type
4443 declared in a partition
4444 shall be distinct, so long as the type is declared outside an
4445 instance of a generic body.
4446 If the compilation unit in which
4447 a given tagged type is declared, and all compilation units on which it
4448 semantically depends, are the same in two different partitions,
4449 then the external tag for the type shall be the same in the
4450 two partitions.
4451 What it means for a compilation unit to be the same in
4452 two different partitions is implementation defined.
4453 At a minimum, if the compilation unit is not recompiled
4454 between building the two different partitions that include it, the compilation
4455 unit is considered the same in the two partitions.
4456 @ImplDef{What determines whether a compilation unit is the
4457 same in two different partitions.}
4458 @begin{Reason}
4459 These requirements are important because external tags are used
4460 for input/output of class-wide types. These requirements ensure
4461 that what is written by one program can be read back by some other
4462 program so long as they share the same declaration for the
4463 type (and everything it depends on).
4464
4465 The user may specify the external tag if (s)he wishes its value
4466 to be stable even across changes to the compilation unit
4467 in which the type is declared (or changes in some unit on which it
4468 depends).
4469
4470 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4471 We use a String rather than a @Chg{Version=[2],
4472 New=[Stream_Element_Array],Old=[Storage_Array]} to represent an
4473 external tag for portability.
4474 @end{Reason}
4475 @begin{Ramification}
4476 Note that the characters
4477 of an external tag need not all be graphic characters.
4478 In other words, the external tag can be a sequence of arbitrary
4479 8-bit bytes.
4480 @end{Ramification}
4481 @end{ImplReq}
4482
4483 @begin{ImplPerm}
4484 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0113-1]}
4485 @ChgAdded{Version=[3],Text=[If a user-specified external tag S'External_Tag is
4486 the same as T'External_Tag for some other tagged type declared by a different
4487 declaration in the partition, the partition may be rejected.]}
4488
4489 @begin{Ramification}
4490 @ChgRef{Version=[3],Kind=[AddedNormal]}
4491 @ChgAdded{Version=[3],Text=[This is, in general, a post-compilation check.
4492 This permission is intended for implementations that do link-time construction
4493 of the external tag lookup table; implementations that dynamically construct
4494 the table will likely prefer to raise Program_Error upon elaboration of the
4495 problem construct. We don't want this check to require any implementation
4496 complexity, as it will be very rare that there would be a problem.]}
4497 @end{Ramification}
4498 @end{ImplPerm}
4499
4500 @begin{Notes}
4501 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00270-01]}
4502 The following language-defined attributes are specifiable,
4503 at least for some of the kinds of entities to which they apply:
4504 Address,
4505 @Chg{Version=[2],New=[],Old=[Size, Component_Size, ]}Alignment,
4506 @Chg{Version=[2],New=[Bit_Order, Component_Size, ],Old=[]}
4507 External_Tag,
4508 @Chg{Version=[2],New=[Input, Machine_Radix, Output, Read, Size, ],Old=[]}
4509 Small, @Chg{Version=[2],New=[],Old=[Bit_Order, ]}
4510 Storage_Pool, Storage_Size,
4511 @Chg{Version=[2],New=[Stream_Size, and ],Old=[]}
4512 Write@Chg{Version=[2],New=[],Old=[, Output, Read,
4513 Input, and Machine_Radix]}.
4514
4515 It follows from the general rules in @RefSecNum{Operational and Representation Aspects}
4516 that if one writes @lquotes@;@key[for] X'Size @key[use] Y;@rquotes@; then
4517 the X'Size @nt{attribute_reference} will return Y
4518 (assuming the implementation allows the Size clause).
4519 The same is true for all of the specifiable attributes except Storage_Size.
4520 @begin{Ramification}
4521 An implementation may specify that an implementation-defined attribute is
4522 specifiable for certain entities.
4523 This follows from the fact that the semantics of
4524 implementation-defined attributes is implementation defined.
4525 An implementation is not allowed to make a language-defined attribute
4526 specifiable if it isn't.
4527 @end{Ramification}
4528 @end{Notes}
4529
4530 @begin{Examples}
4531 @leading@keepnext@i{Examples of attribute definition clauses:}
4532 @begin{Example}
4533 Byte : @key[constant] := 8;
4534 Page : @key[constant] := 2**12;
4535
4536 @key[type] Medium @key[is] @key[range] 0 .. 65_000;
4537 @key[for] Medium'Size @key[use] 2*Byte;
4538 @key[for] Medium'Alignment @key[use] 2;
4539 Device_Register : Medium;
4540 @key[for] Device_Register'Size @key[use] Medium'Size;
4541 @key[for] Device_Register'Address @key[use] System.Storage_Elements.To_Address(16#FFFF_0020#);
4542
4543 @key[type] Short @key[is] @key[delta] 0.01 @key[range] -100.0 .. 100.0;
4544 @key[for] Short'Size @key[use] 15;
4545
4546 @key[for] Car_Name'Storage_Size @key[use] --@RI{ specify access type's storage pool size}
4547 2000*((Car'Size/System.Storage_Unit) +1); --@RI{ approximately 2000 cars}
4548
4549 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
4550 @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)
4551 @key[return] T;
4552 @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}}
4553 @end{Example}
4554 @end{Examples}
4555
4556 @begin{Notes}
4557 @i{Notes on the examples:}
4558 In the Size clause for Short,
4559 fifteen bits is the minimum necessary,
4560 since the type definition requires Short'Small <= 2**(@en@;7).
4561 @end{Notes}
4562
4563 @begin{Extend83}
4564 @Defn{extensions to Ada 83}
4565 The syntax rule for @ntf{length_clause} is replaced with the new syntax rule
4566 for @nt{attribute_definition_clause}, and it is modified to allow a
4567 @nt{name} (as well as an expression).
4568 @end{Extend83}
4569
4570 @begin{DiffWord83}
4571 The syntax rule for @nt{attribute_definition_clause} now requires that the
4572 prefix of the attribute be a @nt{local_name};
4573 in Ada 83 this rule was stated in the text.
4574
4575 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4576 In Ada 83, the relationship between a @Chg{Version=[2],New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]}
4577 specifying a certain aspect and an attribute that queried that
4578 aspect was unclear.
4579 In Ada 95, they are the same,
4580 except for certain explicit exceptions.
4581 @end{DiffWord83}
4582
4583 @begin{DiffWord95}
4584 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
4585 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify for
4586 each attribute whether it is an operational or representation attribute.]}
4587
4588 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]}
4589 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that
4590 External_Tag is never inherited.]}
4591
4592 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-01],ARef=[AI95-00291-01]}
4593 @ChgAdded{Version=[2],Text=[Adjusted the Recommended Level of Support for
4594 Alignment to eliminate nonsense requirements and to ensure that useful
4595 capabilities are required.]}
4596
4597 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-01],ARef=[AI95-00291-01]}
4598 @ChgAdded{Version=[2],Text=[Adjusted the Recommended Level of Support for
4599 Size to eliminate nonsense requirements and to ensure that useful
4600 capabilities are required. Also eliminated any dependence on whether an
4601 aspect was specified (a confirming representation item should not affect the
4602 semantics).]}
4603
4604 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
4605 @ChgAdded{Version=[2],Text=[Added the definition of machine scalar.]}
4606
4607 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00247-01]}
4608 @ChgAdded{Version=[2],Text=[Removed the requirement that specified
4609 alignments for a composite type cannot override those for their components,
4610 because it was never intended to apply to components whose location was
4611 specified with a representation item. Moreover, it causes a difference in
4612 legality when a confirming alignment is specified for one of the composite
4613 types.]}
4614
4615 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
4616 @ChgAdded{Version=[2],Text=[Removed recommended level of support rules about
4617 types with by-reference and aliased parts, because there are now blanket
4618 rules covering all recommended level of support rules.]}
4619
4620 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00291-02]}
4621 @ChgAdded{Version=[2],Text=[Split the definition of Alignment for subtypes
4622 and for objects. This simplified the wording and eliminated confusion about
4623 which rules applied to objects, which applied to subtypes, and which applied
4624 to both.]}
4625 @end{DiffWord95}
4626
4627 @begin{Inconsistent2005}
4628 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0095-1]}
4629 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
4630 @b<Correction:> An address attribute with a prefix of a generic formal
4631 subprogram whose actual parameter has convention Intrinsic now raises
4632 Program_Error. Since it is unlikely that such an attribute would have done
4633 anything useful (a subprogram with convention Intrinsic is not expected to
4634 have a normal subprogram body), it is highly unlikely that any existing
4635 programs would notice the difference, and any that do probably are buggy.]}
4636
4637 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0113-1]}
4638 @ChgAdded{Version=[3],Text=[@b<Correction:> User-specified
4639 external tags that conflict with other external tags raise Program_Error
4640 (or are optionally illegal). This was legal and did not raise an exception
4641 in the past, although the effects were not defined. So while a program
4642 might depend on such behavior, the results were not portable (even to
4643 different versions of the same implementation). Such programs should be
4644 rare.]}
4645 @end{Inconsistent2005}
4646
4647 @begin{Incompatible2005}
4648 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0095-1]}
4649 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b[Correction:]
4650 An address attribute with a prefix of a subprogram with convention Intrinsic is
4651 now illegal. Such attributes are very unlikely to have provided a useful
4652 answer (the intended meaning
4653 of convention Intrinsic is that there is no actual subprogram body for
4654 the operation), so this is highly unlikely to affect any existing programs
4655 unless they have a hidden bug.]}
4656 @end{Incompatible2005}
4657
4658 @begin{Extend2005}
4659 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0191-1]}
4660 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4661 Attributes Has_Same_Storage and Overlaps_Storage are new.]}
4662
4663 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
4664 @ChgAdded{Version=[3],Text=[Aspect Storage_Size is new;
4665 @nt{pragma} Storage_Size is now obsolescent, joining attribute
4666 Storage_Size for task types.]}
4667 @end{Extend2005}
4668
4669 @begin{DiffWord2005}
4670 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1]}
4671 @ChgAdded{Version=[3],Text=[@b<Correction:> Improved the description
4672 of erroneous execution for address clauses to make it clear that
4673 specifying an address inappropriate for the entity will lead to
4674 erroneous execution.]}
4675
4676 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0116-1]}
4677 @ChgAdded{Version=[3],Text=[@b<Correction:> Added @ImplAdviceTitle for
4678 the alignment of class-wide types.]}
4679 @end{DiffWord2005}
4680
4681 @begin{Extend2012}
4682 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0059-1]}
4683 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
4684 Attribute Object_Size is new.]}
4685 @end{Extend2012}
4686
4687 @begin{DiffWord2012}
4688 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0070-1]}
4689 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the behavior of
4690 Has_Same_Storage when 'Size = 0.]}
4691 @end{DiffWord2012}
4692
4693
4694
4695 @LabeledClause{Enumeration Representation Clauses}
4696
4697 @begin{Intro}
4698 @redundant[An @nt{enumeration_representation_clause} specifies the internal
4699 codes for enumeration literals.]
4700 @end{Intro}
4701
4702 @begin{Syntax}
4703 @Syn{lhs=<enumeration_representation_clause>,rhs="
4704 @key{for} @SynI{first_subtype_}@Syn2{local_name} @key{use} @Syn2{enumeration_aggregate};"}
4705 @Syn{lhs=<enumeration_aggregate>,rhs="@Syn2{array_aggregate}"}
4706 @end{Syntax}
4707
4708 @begin{Resolution}
4709 @PDefn2{Term=[expected type],
4710 Sec=(enumeration_representation_clause expressions)}
4711 The @nt<enumeration_aggregate> shall be written as a one-dimensional
4712 @nt<array_aggregate>, for which the index subtype is the unconstrained
4713 subtype of the enumeration type, and each component expression
4714 is expected to be of any integer type.
4715 @begin{Ramification}
4716 The @lquotes@;full coverage rules@rquotes@; for @nt<aggregate>s applies.
4717 An @key{others} is not allowed @em there is no applicable index
4718 constraint in this context.
4719 @end{Ramification}
4720 @end{Resolution}
4721
4722 @begin{Legality}
4723 The @SynI{first_subtype_}@nt{local_name} of an
4724 @nt{enumeration_representation_clause} shall denote an
4725 enumeration subtype.
4726 @begin{Ramification}
4727 As for all type-related representation items,
4728 the @nt{local_name} is required to denote a first subtype.
4729 @end{Ramification}
4730
4731 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
4732 @Chg{Version=[2],New=[Each component of the @nt{array_aggregate} shall be
4733 given by an @nt{expression} rather than a <>. ],Old=[]}The
4734 @Chg{Version=[2],New=[@nt{expression}s],Old=[expressions]} given in the
4735 @nt{array_aggregate} shall be static,
4736 and shall specify distinct integer codes for each value
4737 of the enumeration type; the associated integer codes shall
4738 satisfy the predefined ordering relation of the type.
4739 @begin{Reason}
4740 Each value of the enumeration type has to be given an internal code,
4741 even if the first subtype of the enumeration type is constrained
4742 to only a subrange (this is only possible if the enumeration type
4743 is a derived type). This @lquotes@;full coverage@rquotes@; requirement
4744 is important because one may refer to Enum'Base'First and Enum'Base'Last,
4745 which need to have defined representations.
4746 @end{Reason}
4747 @end{Legality}
4748
4749 @begin{StaticSem}
4750 @Chg{Version=[3],New=[@PDefn2{Term=[representation aspect], Sec=(coding)}],
4751 Old=[@PDefn2{Term=[aspect of representation], Sec=(coding)}
4752 @Defn2{Term=[coding], Sec=(aspect of representation)}]}
4753 An @nt{enumeration_representation_clause} specifies the
4754 @i{coding} aspect of representation.
4755 @Defn{internal code}
4756 The coding consists of the @i{internal code} for each enumeration
4757 literal, that is, the integral value used internally to
4758 represent each literal.@Chg{Version=[3],New=[@AspectDefn{Coding}],Old=[]}
4759
4760 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Coding],
4761 Text=[@ChgAdded{Version=[3],Text=[Internal representation of enumeration
4762 literals. Specified by an @nt{enumeration_representation_clause}, not
4763 by an @nt{aspect_specification}.]}]}
4764
4765 @end{StaticSem}
4766
4767 @begin{ImplReq}
4768 For nonboolean enumeration types,
4769 if the coding is not specified for the type, then
4770 for each value of the type, the internal code shall be equal to
4771 its position number.
4772 @begin{Reason}
4773 This default representation is already used by all known
4774 Ada compilers for nonboolean enumeration types. Therefore,
4775 we make it a requirement so users can depend on it, rather
4776 than feeling obliged to supply for every enumeration type
4777 an enumeration representation clause that is equivalent
4778 to this default rule.
4779 @end{Reason}
4780 @begin{Discussion}
4781 For boolean types, it is relatively common to use all ones for
4782 True, and all zeros for False, since some hardware supports
4783 that directly. Of course, for a one-bit Boolean object
4784 (like in a packed array), False is presumably zero and True
4785 is presumably one (choosing the reverse would be extremely
4786 unfriendly!).
4787 @end{Discussion}
4788 @end{ImplReq}
4789
4790 @begin{ImplAdvice}
4791 @Leading@PDefn2{Term=[recommended level of support], Sec=(@nt{enumeration_representation_clause})}
4792 The recommended level of support for @nt{enumeration_representation_clause}s is:
4793 @begin{Itemize}
4794 An implementation should support at least the internal codes in the
4795 range System.Min_Int..System.Max_Int. An implementation need not support
4796 @nt{enumeration_@!representation_@!clause}s for boolean types.
4797 @begin{Ramification}
4798 The implementation may support numbers outside the above
4799 range, such as numbers greater than System.Max_Int.
4800 See AI83-00564.
4801 @end{Ramification}
4802 @begin{Reason}
4803 The benefits of specifying the internal coding of a boolean type do
4804 not outweigh the implementation costs.
4805 Consider, for example, the implementation of the logical operators on
4806 a packed array of booleans with strange internal codes.
4807 It's implementable, but not worth it.
4808 @end{Reason}
4809 @end{Itemize}
4810 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4811 Text=[The recommended level of support for
4812 @nt{enumeration_representation_clause}s should be followed.]}]}
4813 @end{ImplAdvice}
4814
4815 @begin{StaticSem}
4816
4817 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0237-1]}
4818 @Comment{We use inserted paragraphs here, even though we're directly in front
4819 of a note, because the Annex K.1 version needs to be inserted, and there's no
4820 value to having everything except the first paragraph being inserted.}
4821 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{every discrete
4822 subtype S}, the following attributes are defined:]}
4823 @begin(description)
4824 @ChgAttribute{Version=[5],Kind=[Added],ChginAnnex=[T],
4825 Leading=<T>, Prefix=<S>, AttrName=<Enum_Rep>, ARef=[AI12-0237-1],
4826 InitialVersion=[5], Text=[@Chg{Version=[5],New=[S'Enum_Rep denotes a
4827 function with the following specification:],Old=[]}
4828 @begin{Descexample}
4829 @ChgRef{Version=[5],Kind=[Added]}
4830 @ChgAdded{Version=[5],Text=[@key[function] S'Enum_Rep (Arg : S'Base) @key[return] @i<universal_integer>]}
4831 @end{Descexample}
4832
4833 @ChgRef{Version=[5],Kind=[Added]}
4834 @ChgAdded{Version=[5],NoPrefix=[T],Text=[This function returns the
4835 representation value of the value of Arg, as a value of type
4836 @i<universal_integer>. The @i<representation value>@Defn{representation value}
4837 is@Defn2{Term=[value],Sec=[representation]} the internal code specified in an
4838 enumeration representation clause, if any, for the type corresponding to the
4839 value of Arg, and otherwise is the position number of the
4840 value.]}]}@Comment{End of Annex text here.}
4841
4842 @ChgAttribute{Version=[5],Kind=[Added],ChginAnnex=[T],
4843 Leading=<T>, Prefix=<S>, AttrName=<Enum_Val>, ARef=[AI12-0237-1],
4844 InitialVersion=[5], Text=[@Chg{Version=[5],New=[S'Enum_Val denotes a
4845 function with the following specification:],Old=[]}
4846 @begin{Descexample}
4847 @ChgRef{Version=[5],Kind=[Added]}
4848 @ChgAdded{Version=[5],Text=[@key[function] S'Enum_Val (Arg : @i<universal_integer>) @key[return] S'Base]}
4849 @end{Descexample}
4850
4851 @ChgRef{Version=[5],Kind=[Added]}
4852 @ChgAdded{Version=[5],NoPrefix=[T],Text=[This function returns a value of the
4853 type of S whose representation value equals the value of Arg. For the
4854 evaluation of a call on
4855 S'Enum_Val, if there is no value in the base range of its type
4856 with the given representation value, Constraint_Error is raised.]}]}@Comment{End of Annex text here.}
4857
4858 @begin{Reason}
4859 @ChgRef{Version=[5],Kind=[AddedNormal]}
4860 @ChgAdded{Version=[5],Text=[We define these on all discrete types so that they
4861 can be used inside of a generic unit on a subtype of a generic formal discrete
4862 type. They're not useful on integer types (they have the same effect as S'Pos
4863 and S'Val).]}
4864 @end{Reason}
4865 @end{Description}
4866 @end{StaticSem}
4867
4868 @begin{Notes}
4869 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4870 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
4871 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI12-0237-1]}
4872 @Chg{Version=[5],New=[Attribute Enum_Rep],Old=[Unchecked_Conversion]}
4873 may be used to query the internal codes used
4874 for an enumeration type@Chg{Version=[5],New=[; attribute Enum_Val may be used
4875 to convert from an internal code to an enumeration value],Old=[]}. The
4876 @Chg{Version=[5],New=[other ],Old=[]}attributes of the type, such as Succ, Pred,
4877 and Pos, are unaffected by the
4878 @Chg{New=[@nt{enumeration_representation_clause}],Old=[@nt{representation_clause}]}.
4879 For example, Pos always returns the position number, @i{not} the internal
4880 integer code that might have been specified in @Chg{New=[an
4881 @nt{enumeration_representation_clause}],
4882 Old=[a @nt{representation_clause}]}@Chg<Version=[3],New=[],Old=[}]>.
4883 @begin{Discussion}
4884 @Leading@;Suppose the enumeration type in question is derived:
4885 @begin{Example}
4886 @key[type] T1 @key[is] (Red, Green, Blue);
4887 @key[subtype] S1 @key[is] T1 @key[range] Red .. Green;
4888 @key[type] S2 @key[is] @key[new] S1;
4889 @key[for] S2 @key[use] (Red => 10, Green => 20, Blue => 30);
4890 @end{Example}
4891
4892 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4893 @Leading@;The @Chg{New=[@nt{enumeration_representation_clause}],Old=[@nt{representation_clause}]}
4894 has to specify values for all enumerals, even ones that are not in S2 (such as
4895 Blue). The Base attribute can be used to get at these values.
4896 For example:
4897 @begin{Example}
4898 @key[for] I @key[in] S2'Base @key[loop]
4899 ... --@RI{ When I equals Blue, the internal code is 30.}
4900 @key[end] @key[loop];
4901 @end{Example}
4902
4903 We considered allowing or requiring
4904 @lquotes@;@key[for] S2'Base @key[use] ...@rquotes@; in cases like this,
4905 but it didn't seem worth the trouble.
4906 @end{Discussion}
4907 @end{Notes}
4908
4909 @begin{Examples}
4910 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0312-1]}
4911 @leading@keepnext@i{@Chg{Version=[5],New=[Examples],Old=[Example]} of
4912 @Chg{Version=[5],New=[],Old=[an ]}enumeration representation
4913 @Chg{Version=[5],New=[clauses],Old=[clause]}:}
4914 @begin{Example}
4915 @key[type] Mix_Code @key[is] (ADD, SUB, MUL, LDA, STA, STZ);
4916
4917 @key[for] Mix_Code @key[use]
4918 (ADD => 1, SUB => 2, MUL => 3, LDA => 8, STA => 24, STZ =>33);
4919
4920 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
4921 @ChgAdded{Version=[5],Text=[--@Examcom{ See @RefSecNum{Character Types}.}
4922 @key<for> Roman_Digit @key<use> ('I' => 1,
4923 'V' => 5,
4924 'X' => 10,
4925 'L' => 50,
4926 'C' => 100,
4927 'D' => 500,
4928 'M' => 1000);]}
4929
4930 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
4931 @ChgAdded{Version=[5],Text=[--@Examcom{ For an example of the use of attribute Enum_Rep, see @RefSecNum{User-defined Literals}.}]}
4932 @end{Example}
4933 @end{Examples}
4934
4935 @begin{Extend83}
4936 @Defn{extensions to Ada 83}
4937 As in other similar contexts, Ada 95 allows expressions of any integer type,
4938 not just expressions of type @i{universal_integer}, for the component
4939 expressions in the @nt<enumeration_aggregate>. The preference rules
4940 for the predefined operators of @i{root_integer} eliminate
4941 any ambiguity.
4942
4943 For portability, we now require that the default coding for an enumeration
4944 type be the @lquotes@;obvious@rquotes@; coding using position numbers.
4945 This is satisfied by all known implementations.
4946 @end{Extend83}
4947
4948 @begin{DiffWord95}
4949 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
4950 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Updated to reflect that we
4951 no longer have something called @ntf{representation_clause}.]}
4952
4953 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
4954 @ChgAdded{Version=[2],Text=[Added wording to prevent the use of <> in a
4955 @nt{enumeration_representation_clause}. (<> is newly added to
4956 @nt{array_aggregate}s.)]}
4957 @end{DiffWord95}
4958
4959 @begin{Extend2012}
4960 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0237-1]}
4961 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
4962 Attributes Enum_Rep and Enum_Val are new.]}
4963 @end{Extend2012}
4964
4965
4966
4967 @LabeledClause{Record Layout}
4968
4969 @begin{Intro}
4970 @Chg{Version=[3],New=[@AspectDefn{Layout}
4971 @PDefn2{Term=[representation aspect], Sec=(layout)}
4972 @PDefn2{Term=[representation aspect], Sec=(record layout)}
4973 @AspectDefn{Record layout}
4974 @PDefn2{Term=[representation aspect], Sec=(storage place)}
4975 @Defn2{Term=[storage place], Sec=(representation aspect)}
4976 @Defn2{Term=[storage place], Sec=(of a component)}],
4977 Old=[@PDefn2{Term=[aspect of representation], Sec=(layout)}
4978 @Defn2{Term=[layout], Sec=(aspect of representation)}
4979 @PDefn2{Term=[aspect of representation], Sec=(record layout)}
4980 @Defn2{Term=[record layout], Sec=(aspect of representation)}
4981 @PDefn2{Term=[aspect of representation], Sec=(storage place)}
4982 @Defn2{Term=[storage place], Sec=(of a component)}]}
4983 The @i{(record) layout} aspect of representation
4984 consists of the @i{storage places} for some or all components,
4985 that is, storage place attributes of the components.
4986 The layout can be specified with a @nt{record_@!representation_@!clause}.
4987 @end{Intro}
4988
4989
4990 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
4991 @LabeledSubClause{Record Representation Clauses}
4992
4993 @begin{Intro}
4994 @redundant[A @nt{record_representation_clause} specifies the storage representation
4995 of records and record extensions, that is, the order, position, and size
4996 of components (including discriminants, if any).
4997 @IndexSee{Term=[bit field],See=(record_representation_clause)}]
4998 @end{Intro}
4999
5000 @begin{MetaRules}
5001 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
5002 It should be feasible for an implementation to use negative offsets
5003 in the representation of composite types.
5004 However, no implementation should be forced to support negative
5005 offsets.
5006 Therefore@Chg{Version=[2],New=[, in the interest of uniformity],Old=[]},
5007 negative offsets should be disallowed in
5008 @nt{record_representation_clause}s.
5009 @end{MetaRules}
5010
5011 @begin{Syntax}
5012 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0213-1]}
5013 @Syn{lhs=<record_representation_clause>,rhs="
5014 @key{for} @SynI{first_subtype_}@Syn2{local_name} @key{use}
5015 @key{record} [@Syn2{mod_clause}]
5016 {@Syn2{component_clause}}
5017 @key{end} @key{record}@Chg{Version=[5],New=< [@Syn2[local_name]]>,Old=<>};"}
5018
5019 @Syn{lhs=<component_clause>,rhs="
5020 @SynI{component_}@Syn2{local_name} @key{at} @Syn2{position} @key{range} @Syn2{first_bit} .. @Syn2{last_bit};"}
5021
5022 @Syn{lhs=<position>,rhs="@SynI{static_}@Syn2{expression}"}
5023 @Syn{lhs=<first_bit>,rhs="@SynI{static_}@Syn2{simple_expression}"}
5024 @Syn{lhs=<last_bit>,rhs="@SynI{static_}@Syn2{simple_expression}"}
5025 @begin{Reason}
5026 @nt{First_bit} and @nt{last_bit} need to be @nt{simple_expression}
5027 instead of @nt{expression} for the same reason as in @nt{range}
5028 (see @RefSec{Scalar Types}).
5029 @end{Reason}
5030 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0213-1]}
5031 @ChgAdded{Version=[5],Text=[If a @nt{local_name} appears at the end of
5032 the @nt{record_representation_clause}, it
5033 shall repeat the @Syni{first_subtype_}@nt{local_name}.]}
5034 @end{Syntax}
5035
5036 @begin{Resolution}
5037 @PDefn2{Term=[expected type],
5038 Sec=(component_clause expressions)}
5039 @PDefn2{Term=[expected type],
5040 Sec=(position)}
5041 @PDefn2{Term=[expected type],
5042 Sec=(first_bit)}
5043 @PDefn2{Term=[expected type],
5044 Sec=(last_bit)}
5045 Each @nt{position}, @nt{first_bit}, and @nt{last_bit} is expected to
5046 be of any integer type.
5047 @begin{Ramification}
5048 These need not have the same integer type.
5049 @end{Ramification}
5050 @end{Resolution}
5051
5052 @begin{Legality}
5053 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00436-01]}
5054 The @SynI{first_subtype_}@nt{local_name} of a
5055 @nt{record_representation_clause} shall denote a specific
5056 @Chg{Version=[2],New=[],Old=[nonlimited ]}record or record extension subtype.
5057 @begin{Ramification}
5058 As for all type-related representation items,
5059 the @nt{local_name} is required to denote a first subtype.
5060 @end{Ramification}
5061
5062 If the @i{component_}@nt<local_name> is a @nt<direct_name>,
5063 the @nt{local_name} shall denote a component of the type.
5064 For a record extension, the component shall not be inherited,
5065 and shall not be a discriminant that corresponds to a discriminant of
5066 the parent type.
5067 If the @i{component_}@!@nt<local_@!name> has an @nt{attribute_@!designator},
5068 the @nt{direct_@!name} of the @nt<local_@!name> shall denote either
5069 the declaration of the type or a component of the type,
5070 and the @nt{attribute_@!designator} shall denote an
5071 implementation-defined implicit component of the type.
5072
5073 The @nt{position}, @nt{first_bit}, and @nt{last_bit} shall be
5074 static expressions.
5075 The value of @nt{position} and @nt{first_bit} shall be nonnegative.
5076 The value of @nt{last_bit} shall be no less than
5077 @nt{first_bit} @en 1.
5078 @begin{Ramification}
5079 A @nt{component_clause} such as
5080 @lquotes@;X @key{at} 4 @key{range} 0..@en@;1;@rquotes@;
5081 is allowed if X can fit in zero bits.
5082 @end{Ramification}
5083
5084 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
5085 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[If the
5086 nondefault bit ordering applies to the type, then either:]}
5087 @begin{Itemize}
5088 @ChgRef{Version=[2],Kind=[Added]}
5089 @ChgAdded{Version=[2],Text=[the value of @nt{last_bit} shall be
5090 less than the size of the largest machine scalar; or]}
5091
5092 @ChgRef{Version=[2],Kind=[Added]}
5093 @ChgAdded{Version=[2],Text=[the value of @nt{first_bit} shall be zero and the
5094 value of @nt{last_bit} + 1 shall be a multiple of System.Storage_Unit.]}
5095 @end{Itemize}
5096
5097 At most one @nt{component_clause} is allowed for each component of
5098 the type, including for each discriminant
5099 (@nt{component_clause}s may be given for some, all, or none of the
5100 components).
5101 Storage places within a @nt{component_list} shall not overlap,
5102 unless they are for components in distinct @nt{variant}s of the same
5103 @nt{variant_part}.
5104
5105 A name that denotes a component of a type is not allowed within
5106 a @nt{record_representation_clause} for the type,
5107 except as the @SynI{component_}@nt<local_name>
5108 of a @nt{component_clause}.
5109 @begin{Reason}
5110 @Leading@;It might seem strange to make the
5111 @nt{record_representation_clause} part of the declarative region,
5112 and then disallow mentions of the components within almost all of
5113 the @nt{record_representation_clause}.
5114 The alternative would be to treat the
5115 @SynI{component_}@nt<local_name> like a formal parameter name in
5116 a subprogram call (in terms of visibility).
5117 However, this rule would imply slightly different semantics,
5118 because (given the actual rule)
5119 the components can hide other declarations.
5120 This was the rule in Ada 83, and we see no reason to change it.
5121 The following, for example, was and is illegal:
5122 @begin{Example}
5123 @key[type] T @key[is]
5124 @key[record]
5125 X : Integer;
5126 @key[end] @key[record];
5127 X : @key[constant] := 31; --@RI{ Same defining name as the component.}
5128 @key[for] T @key[use]
5129 @key[record]
5130 X @key[at] 0 @key[range] 0..X; --@RI{ Illegal!}
5131 @key[end] @key[record];
5132 @end{Example}
5133
5134 The component X hides the named number X throughout
5135 the @nt{record_representation_clause}.
5136 @end{Reason}
5137 @end{Legality}
5138
5139 @begin{StaticSem}
5140 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5141 A @nt{record_representation_clause}
5142 (without the @nt{mod_clause})
5143 specifies the layout.@Chg{Version=[2],New=[],Old=[
5144 The storage place
5145 attributes (see @RefSecNum{Storage Place Attributes})
5146 are taken from the
5147 values of the @nt{position}, @nt{first_bit},
5148 and @nt{last_bit} expressions
5149 after normalizing those values so that
5150 @nt{first_bit} is less than
5151 Storage_Unit.@Chg{Version=[3],New=[@AspectDefn{Layout (record)}],Old=[]}]}
5152
5153 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Layout (record)],
5154 Text=[@ChgAdded{Version=[3],Text=[Layout of record components. Specified by
5155 a @nt{record_representation_clause}, not by an @nt{aspect_specification}.]}]}
5156
5157 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Record layout],
5158 Text=[@ChgAdded{Version=[3],Text=[See Layout.]}]}
5159
5160 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
5161 @ChgAdded{Version=[2],Text=[If the default bit ordering applies to the type,
5162 the @nt{position}, @nt{first_bit}, and @nt{last_bit} of each
5163 @nt{component_clause} directly specify
5164 the position and size of the corresponding component.]}
5165
5166 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
5167 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
5168 @ChgAdded{Version=[2],Type=[Leading],Text=[If the nondefault bit ordering
5169 applies to the type@Chg{Version=[3],New=[,],Old=[]} then
5170 the layout is determined as follows:]}
5171 @begin{Itemize}
5172 @ChgRef{Version=[2],Kind=[Added]}
5173 @ChgAdded{Version=[2],Text=[the @nt{component_clause}s for which the value of
5174 @nt{last_bit} is greater than or equal to the size of the largest machine scalar
5175 directly specify the position and size of the corresponding component;]}
5176
5177 @ChgRef{Version=[2],Kind=[Added]}
5178 @ChgAdded{Version=[2],Text=[for other @nt{component_clause}s, all of the
5179 components having the same value of @nt{position} are considered to be part of
5180 a single machine scalar, located at that @nt{position}; this machine scalar
5181 has a size which is the smallest machine scalar size larger than the largest
5182 @nt{last_bit} for all @nt{component_clause}s at that @nt{position}; the
5183 @nt{first_bit} and @nt{last_bit} of each @nt{component_clause} are then
5184 interpreted as bit offsets in this machine scalar.]}
5185 @end{Itemize}
5186
5187 @begin{Ramification}
5188 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00133-01]}
5189 @ChgNote{We want the header title to remain, so we use @Chg instead if @ChgDeleted.}
5190 @Chg{Version=[2],New=[],Old=[For example,
5191 if Storage_Unit is 8, then
5192 @lquotes@;C @key[at] 0 @key[range] 24..31;@rquotes@;
5193 defines C'Position = 3, C'First_Bit = 0, and C'Last_Bit = 7.
5194 This is true of machines with either bit ordering.]}
5195
5196 A @nt{component_clause} also determines the value of the Size
5197 attribute of the component,
5198 since this attribute is related to First_Bit and Last_Bit.
5199 @end{Ramification}
5200
5201 @Redundant[A @nt{record_representation_clause} for a record extension
5202 does not override the layout of the parent part;]
5203 if the layout was specified for the parent type,
5204 it is inherited by the record extension.
5205 @end{StaticSem}
5206
5207 @begin{ImplPerm}
5208 An implementation may generate implementation-defined components (for
5209 example, one containing the offset of another component).
5210 An implementation may generate names that denote
5211 such implementation-defined components;
5212 such names shall be implementation-defined @nt{attribute_reference}s.
5213 An implemen@!tation may allow such implementation-defined names to be
5214 used in @nt{record_@!representation_@!clause}s.
5215 An implementation can restrict such @nt{component_@!clause}s in any
5216 manner it sees fit.
5217 @ImplDef{Implementation-defined components.}
5218 @begin{Ramification}
5219 Of course, since the semantics of implementation-defined
5220 attributes is implementation defined, the implementation need not
5221 support these names in all situations.
5222 They might be purely for the purpose of @nt{component_clause}s,
5223 for example.
5224 The visibility rules for such names are up to the implementation.
5225
5226 We do not allow such component names to be normal identifiers
5227 @em that would constitute blanket permission to do all kinds of evil
5228 things.
5229 @end{Ramification}
5230 @begin{Discussion}
5231 @Defn{dope}
5232 Such implementation-defined components are known in the
5233 vernacular as @lquotes@;dope.@rquotes@;
5234 Their main purpose is for storing offsets of components that depend
5235 on discriminants.
5236 @end{Discussion}
5237
5238 If a @nt<record_representation_clause> is given for an untagged derived type,
5239 the storage place attributes for all of the components of the derived
5240 type may differ
5241 from those of the corresponding components of the parent type,
5242 even for components whose storage
5243 place is not specified explicitly in the @nt<record_@!representation_@!clause>.
5244 @begin{Reason}
5245 This is clearly necessary, since the whole record may need to be
5246 laid out differently.
5247 @end{Reason}
5248 @end{ImplPerm}
5249
5250 @begin{ImplAdvice}
5251 @Leading@PDefn2{Term=[recommended level of support], Sec=(@nt{record_representation_clause})}
5252 The recommended level of support for @nt{record_representation_clause}s is:
5253 @begin{Itemize}
5254 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00133-01]}
5255 @ChgAdded{Version=[2],Text=[An implementation should support machine scalars
5256 that correspond to all of the integer, floating point, and address formats
5257 supported by the machine.]}
5258
5259 An implementation should support storage places that can be extracted
5260 with a load, mask, shift sequence of machine code,
5261 and set with a load, shift, mask, store sequence,
5262 given the available machine instructions and run-time model.
5263
5264 A storage place should be supported if its size is equal to the Size
5265 of the component subtype,
5266 and it starts and ends on a boundary that obeys the Alignment of the
5267 component subtype.
5268
5269 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5270 @Chg{Version=[2],New=[For],Old=[If the default bit ordering applies to
5271 the declaration of a given type, then for]} a component
5272 @Chg{Version=[2],New=[with a subtype ],Old=[]}whose
5273 @Chg{Version=[2],New=[],Old=[subtype's ]}Size is less than the word size, any
5274 storage place that does not cross an aligned word boundary should be supported.
5275
5276 @begin{Reason}
5277 The above recommendations are sufficient to
5278 define interfaces to most interesting hardware.
5279 This causes less implementation burden than the definition in ACID,
5280 which requires arbitrary bit alignments of arbitrarily large
5281 components.
5282 Since the ACID definition is neither enforced by the ACVC,
5283 nor supported by all implementations,
5284 it seems OK for us to weaken it.
5285 @end{Reason}
5286
5287 An implementation may reserve a storage place for the tag
5288 field of a tagged type, and disallow other components from overlapping
5289 that place.
5290 @begin{Ramification}
5291 Similar permission for other dope is not granted.
5292 @end{Ramification}
5293
5294 An implementation need not support a
5295 @nt{component_clause} for a component of an extension part
5296 if the storage place is not after the storage places of all components
5297 of the parent type, whether or not those storage places had been specified.
5298 @begin{Reason}
5299 These restrictions are probably necessary if block equality
5300 operations are to be feasible for class-wide types.
5301 For block comparison to work, the implementation typically has to fill
5302 in any gaps with zero (or one) bits.
5303 If a @lquotes@;gap@rquotes@; in the parent type is filled in with a component in a
5304 type extension, then this won't work when a class-wide object is
5305 passed by reference, as is required.
5306 @end{Reason}
5307 @end{Itemize}
5308 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
5309 Text=[The recommended level of support for @nt{record_representation_clause}s
5310 should be followed.]}]}
5311 @end{ImplAdvice}
5312
5313 @begin{Notes}
5314 If no @nt{component_clause} is given for a component, then the
5315 choice of the storage place for the component is left to the
5316 implementation. If @nt{component_clause}s are given for all components,
5317 the @nt{record_representation_clause} completely specifies the
5318 representation of the type and will be obeyed exactly by the
5319 implementation.
5320 @begin{Ramification}
5321 The
5322 visibility rules prevent the name of a component of the type from
5323 appearing in a @nt{record_representation_clause} at any place
5324 @i{except} for the @SynI{component_}@nt<local_name> of a
5325 @nt{component_clause}.
5326 However, since the @nt{record_representation_clause} is part of the
5327 declarative region of the type declaration,
5328 the component names hide outer homographs throughout.
5329
5330 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
5331 A @nt{record_representation_clause} cannot be given for a protected type,
5332 even though protected types, like record types, have components.
5333 The primary reason for this rule is that there is likely to be too
5334 much dope in a protected type @em entry queues,
5335 bit maps for barrier values, etc.
5336 In order to control the representation of the user-defined components, simply
5337 declare a record type, give it a
5338 @Chg{New=[@nt{record_@!representation_@!clause}],Old=[@nt{representation_clause}]},
5339 and give the protected type one component whose type is the record type.
5340 Alternatively, if the protected object is protecting something like a
5341 device register, it makes more sense to keep the thing being
5342 protected outside the protected object (possibly with a pointer to it
5343 in the protected object), in order to keep implementation-defined
5344 components out of the way.
5345 @end{Ramification}
5346 @end{Notes}
5347
5348 @begin{Examples}
5349 @leading@keepnext@i{Example of specifying the layout of a record type:}
5350 @begin{Example}
5351 Word : @key[constant] := 4; --@RI{ storage element is byte, 4 bytes per word}
5352
5353 @key[type] State @key[is] (A,M,W,P);
5354 @key[type] Mode @key[is] (Fix, Dec, Exp, Signif);
5355
5356 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
5357 @key[type] Byte_Mask @key[is] @key[array] (0..7) @key[of] Boolean@Chg{Version=[5],New=[ @key[with] Component_Size => 1],Old=[]};
5358 @key[type] State_Mask @key[is] @key[array] (State) @key[of] Boolean@Chg{Version=[5],New=[ @key[with] Component_Size => 1],Old=[]};
5359 @key[type] Mode_Mask @key[is] @key[array] (Mode) @key[of] Boolean@Chg{Version=[5],New=[ @key[with] Component_Size => 1],Old=[]};
5360
5361 @key[type] Program_Status_Word @key[is]
5362 @key[record]
5363 System_Mask : Byte_Mask;
5364 Protection_Key : Integer @key[range] 0 .. 3;
5365 Machine_State : State_Mask;
5366 Interrupt_Cause : Interruption_Code;
5367 Ilc : Integer @key[range] 0 .. 3;
5368 Cc : Integer @key[range] 0 .. 3;
5369 Program_Mask : Mode_Mask;
5370 Inst_Address : Address;
5371 @key[end] @key[record];
5372
5373 @key[for] Program_Status_Word @key[use]
5374 @key[record]
5375 System_Mask @key[at] 0*Word @key[range] 0 .. 7;
5376 Protection_Key @key[at] 0*Word @key[range] 10 .. 11; --@RI{ bits 8,9 unused}
5377 Machine_State @key[at] 0*Word @key[range] 12 .. 15;
5378 Interrupt_Cause @key[at] 0*Word @key[range] 16 .. 31;
5379 Ilc @key[at] 1*Word @key[range] 0 .. 1; --@RI{ second word}
5380 Cc @key[at] 1*Word @key[range] 2 .. 3;
5381 Program_Mask @key[at] 1*Word @key[range] 4 .. 7;
5382 Inst_Address @key[at] 1*Word @key[range] 8 .. 31;
5383 @key[end] @key[record];
5384
5385 @key[for] Program_Status_Word'Size @key[use] 8*System.Storage_Unit;
5386 @key[for] Program_Status_Word'Alignment @key[use] 8;
5387 @end{Example}
5388 @end{Examples}
5389
5390 @begin{Notes}
5391 @i{Note on the example:}
5392 The @nt{record_representation_clause} defines the record layout. The
5393 Size clause guarantees that (at least) eight storage elements are used
5394 for objects of the type. The Alignment clause guarantees that
5395 aliased, imported, or exported objects of the type will have
5396 addresses divisible by eight.
5397 @end{Notes}
5398
5399
5400 @begin{DiffWord83}
5401 The @ntf{alignment_clause} has been renamed to @nt{mod_clause} and moved
5402 to @RefSec{Obsolescent Features}.
5403
5404 We have clarified that implementation-defined component names have to be
5405 in the form of an @nt{attribute_reference} of a component or of the
5406 first subtype itself;
5407 surely Ada 83 did not intend to allow arbitrary identifiers.
5408
5409 The RM83-13.4(7) wording incorrectly allows components in
5410 nonvariant records to overlap.
5411 We have corrected that oversight.
5412 @end{DiffWord83}
5413
5414 @begin{Incompatible95}
5415 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
5416 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
5417 @b[Amendment Correction:] The meaning of a @nt{record_representation_clause}
5418 for the nondefault
5419 bit order is now clearly defined. Thus, such clauses can be portably
5420 written. In order to do that though, the equivalence of bit 1 in word 1 to
5421 bit 9 in word 0 (for a machine with Storage_Unit = 8) had to be dropped for
5422 the nondefault bit order. Any @nt{record_representation_clause}s which
5423 depends on that equivalence will break (although such code would imply a
5424 noncontiguous representation for a component, and it seems unlikely that
5425 compilers were supporting that anyway).]}
5426 @end{Incompatible95}
5427
5428 @begin{Extend95}
5429 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00436-01]}
5430 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
5431 @b[Amendment Correction:] The undocumented (and
5432 likely unintentional) incompatibility with Ada 83 caused by not allowing
5433 @nt{record_representation_clause}s on limited record types is removed.]}
5434 @end{Extend95}
5435
5436 @begin{Extend2012}
5437 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0213-1]}
5438 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}The
5439 @nt{local_name} following @key[end record] is new.]}
5440 @end{Extend2012}
5441
5442
5443 @LabeledSubClause{Storage Place Attributes}
5444
5445 @begin{StaticSem}
5446 @Leading@Defn2{Term=[storage place attributes], Sec=(of a component)}
5447 For @PrefixType{a component C of a composite, non-array
5448 object R},
5449 the @i{storage place attributes} are defined:
5450 @begin{Ramification}
5451 The storage place attributes are not (individually) specifiable,
5452 but the user may control their values by giving a
5453 @nt{record_representation_clause}.
5454 @end{Ramification}
5455 @begin{Description}
5456 @ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T],
5457 Leading=<F>, Prefix=<R.C>, AttrName=<Position>,
5458 ARef=[AI95-00133-01], InitialVersion=[0],
5459 Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the
5460 composite type, and if a @nt{component_clause} specifies the placement of C,
5461 denotes the value given for the @nt{position} of the @nt{component_clause};
5462 otherwise, denotes],Old=[Denotes]} the same value as R.C'Address @en@;
5463 R'Address. The value of this attribute is of the type
5464 @i{universal_integer}.>}
5465 @begin{Ramification}
5466 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5467 Thus, @Chg{Version=[2],New=[for the default bit order, ],Old=[]}R.C'Position
5468 is the offset of C in storage
5469 elements from the beginning of the object,
5470 where the first storage element of an object is numbered zero.
5471 R'Address + R.C'Position = R.C'Address.
5472 For record extensions, the offset is not measured from
5473 the beginning of the extension part, but from the
5474 beginning of the whole object, as usual.
5475
5476 In @lquotes@;R.C'Address @en@; R'Address@rquotes@;,
5477 the "@en@;" operator is the one in System.Storage_Elements
5478 that takes two Addresses and returns a Storage_Offset.
5479 @end{Ramification}
5480
5481 @ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T],
5482 Leading=<F>, Prefix=<R.C>, AttrName=<First_Bit>,
5483 ARef=[AI95-00133-01], InitialVersion=[0],
5484 Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the
5485 composite type, and if a @nt{component_clause} specifies the placement of C,
5486 denotes the value given for the @nt{first_bit} of the @nt{component_clause};
5487 otherwise, denotes],Old=[Denotes]} the offset, from the start of the first
5488 of the storage elements occupied by C, of the first bit occupied by C.
5489 This offset is measured in bits.
5490 The first bit of a storage element is numbered zero.
5491 The value of this attribute is of the type
5492 @i{universal_integer}.>}
5493
5494 @ChgAttribute{Version=[2],Kind=[Revised],ChginAnnex=[T],
5495 Leading=<F>, Prefix=<R.C>, AttrName=<Last_Bit>,
5496 ARef=[AI95-00133-01], InitialVersion=[0],
5497 Text=<@Chg{Version=[2],New=[If the nondefault bit ordering applies to the
5498 composite type, and if a @nt{component_clause} specifies the placement of C,
5499 denotes the value given for the @nt{last_bit} of the @nt{component_clause};
5500 otherwise, denotes],Old=[Denotes]} the offset, from the start of the first
5501 of the storage elements occupied by C, of the last bit occupied by C.
5502 This offset is measured in bits. The value of this attribute
5503 is of the type @i{universal_integer}.>}
5504 @begin{Ramification}
5505 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
5506 The ordering of bits in a storage element is
5507 @Chg{Version=[2],New=[],Old=[is ]}defined in @RefSec{Bit Ordering}.
5508
5509 R.C'Size = R.C'Last_Bit @en@; R.C'First_Bit + 1.
5510 (Unless the implementation chooses an indirection
5511 representation.)
5512
5513 If a @nt{component_clause} applies to a component,
5514 then that component will be at the same relative storage place
5515 in all objects of the type.
5516 Otherwise, there is no such requirement.
5517 @end{Ramification}
5518 @end{Description}
5519 @EndPrefixType{}
5520 @end{StaticSem}
5521
5522 @begin{ImplAdvice}
5523 @PDefn{contiguous representation}
5524 @PDefn{discontiguous representation}
5525 If a component is represented using some form of pointer (such as an
5526 offset) to the actual data of the component, and this data is contiguous with
5527 the rest of the object, then the storage place attributes should reflect
5528 the place of the actual data, not the pointer.
5529 If a component is allocated discontiguously from the rest of the object,
5530 then a warning should be generated upon reference to one
5531 of its storage place attributes.
5532 @begin{Reason}
5533 For discontiguous components, these attributes make no sense.
5534 For example, an implementation might allocate dynamic-sized components
5535 on the heap.
5536 For another example, an implementation might allocate the discriminants
5537 separately from the other components, so that multiple objects of the
5538 same subtype can share discriminants.
5539 Such representations cannot happen if there is a @nt{component_clause}
5540 for that component.
5541 @end{Reason}
5542 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
5543 Text=[If a component is represented using a pointer to the actual data of
5544 the component which is contiguous with
5545 the rest of the object, then the storage place attributes should reflect
5546 the place of the actual data.
5547 If a component is allocated discontiguously from the rest of the object,
5548 then a warning should be generated upon reference to one
5549 of its storage place attributes.]}]}
5550 @end{ImplAdvice}
5551
5552 @begin{Incompatible95}
5553 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
5554 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
5555 @b[Amendment Correction:] The meaning of the storage place attributes for
5556 the nondefault
5557 bit order is now clearly defined, and can be different than that given by
5558 strictly following the Ada 95 wording. Any code which depends on the
5559 original Ada 95 values for a type using the nondefault bit order where
5560 they are different will break.]}
5561 @end{Incompatible95}
5562
5563
5564
5565 @LabeledSubClause{Bit Ordering}
5566
5567 @begin{Intro}
5568 @redundant[The Bit_Order attribute specifies the interpretation of the storage
5569 place attributes.]
5570 @begin{Reason}
5571 The intention is to provide uniformity in the
5572 interpretation of storage places across implementations on a
5573 particular machine by allowing the user to specify the Bit_Order.
5574 It is not intended to fully support data interoperability across
5575 different machines,
5576 although it can be used for that purpose in some situations.
5577
5578 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
5579 We can't require all implementations on a given machine to use the same
5580 bit ordering by default;
5581 if the user cares, a @Chg{Version=[2],New=[],Old=[@nt{pragma} ]}Bit_Order
5582 @Chg{Version=[2],New=[@nt{attribute_definition_clause} ],Old=[]}can be used
5583 to force all implementations to use the same bit ordering.
5584 @end{Reason}
5585 @end{Intro}
5586
5587 @begin{StaticSem}
5588 @Defn{bit ordering}
5589 A bit ordering is a method of interpreting the meaning of the
5590 storage place attributes.
5591 @Defn{High_Order_First}
5592 @Defn{big endian}
5593 @Defn2{Term=[endian], Sec=(big)}
5594 High_Order_First @Redundant[(known in the vernacular as @lquotes@;big endian@rquotes@;)]
5595 means that the first bit of a storage element
5596 (bit 0) is the most significant bit (interpreting the sequence of
5597 bits that represent a component as an unsigned integer value).
5598 @Defn{Low_Order_First}
5599 @Defn{little endian}
5600 @Defn2{Term=[endian], Sec=(little)}
5601 Low_Order_First @Redundant[(known in the vernacular as @lquotes@;little endian@rquotes@;)]
5602 means the opposite: the first bit is the least significant.
5603
5604 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0373-1]}
5605 @Leading@;For @PrefixType{every specific record subtype S},
5606 the following @Chg{Version=[5],New=[representation@PDefn2{Term=[representation attribute], Sec=(Bit_Order)} ],Old=[]}attribute is defined:
5607 @begin{Description}
5608 @Attribute{Prefix=<S>, AttrName=<Bit_Order>,
5609 Text=<Denotes the bit ordering for the type of S.
5610 The value of this attribute is of type System.Bit_Order.>}
5611 @EndPrefixType{}
5612 @PDefn2{Term=[specifiable], Sec=(of Bit_Order for record types and
5613 record extensions)}
5614 @Defn{Bit_Order clause}
5615 Bit_Order may be specified for specific record types
5616 via an @nt{attribute_definition_clause};
5617 the expression of such a clause shall be
5618 static.@Chg{Version=[3],New=[@AspectDefn{Bit_Order}],Old=[]}
5619
5620 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Bit_Order],
5621 Text=[@ChgAdded{Version=[3],Text=[Order of bit numbering in a
5622 @nt{record_representation_clause}.]}]}
5623
5624 @end{Description}
5625
5626 If Word_Size = Storage_Unit,
5627 the default bit ordering is implementation defined.
5628 If Word_Size > Storage_Unit,
5629 the default bit ordering is the same as the ordering of storage
5630 elements in a word, when interpreted as an
5631 integer.
5632 @IndexSee{Term=[byte sex],See=(ordering of storage elements in a word)}
5633 @ImplDef{If Word_Size = Storage_Unit,
5634 the default bit ordering.}
5635 @begin{Ramification}
5636 Consider machines whose Word_Size = 32,
5637 and whose Storage_Unit = 8.
5638 Assume the default bit ordering applies.
5639 On a machine with big-endian addresses,
5640 the most significant storage element of an integer is at the address of
5641 the integer.
5642 Therefore, bit zero of a storage element is the most significant bit.
5643 On a machine with little-endian addresses,
5644 the least significant storage element of an integer is at the address of
5645 the integer.
5646 Therefore, bit zero of a storage element is the least significant
5647 bit.
5648 @end{Ramification}
5649
5650 The storage place attributes of a
5651 component of a type are
5652 interpreted according to the bit ordering
5653 of the type.
5654 @begin{Ramification}
5655 This implies that the interpretation of the @nt{position},
5656 @nt{first_bit}, and @nt{last_bit} of a @nt{component_clause} of a
5657 @nt{record_representation_clause} obey the bit ordering given in a
5658 representation item.
5659 @end{Ramification}
5660 @end{StaticSem}
5661
5662 @begin{ImplAdvice}
5663 @Leading@PDefn2{Term=[recommended level of support], Sec=(bit ordering)}
5664 The recommended level of support for the nondefault bit ordering is:
5665 @begin{Itemize}
5666 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5667 @Chg{Version=[2],New=[The],Old=[If Word_Size = Storage_Unit, then
5668 the]} implementation should support the nondefault bit ordering
5669 in addition to the default bit ordering.
5670 @end{Itemize}
5671 @begin{Ramification}
5672 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00133-01]}
5673 @Chg{Version=[2],New=[The],Old=[If Word_Size = Storage_Unit,
5674 the]} implementation should support both bit orderings.
5675 @Chg{Version=[2],New=[Implementations],Old=[We don't push for support of
5676 the nondefault bit ordering when Word_Size > Storage_Unit (except
5677 of course for upward compatibility with a preexisting implementation
5678 whose Ada 83 bit order did not correspond to the required Ada 95
5679 default bit order), because
5680 implementations]} are required to support storage positions that cross
5681 storage element boundaries when Word_Size > Storage_Unit@Chg{Version=[2],
5682 New=[ but the definition of the storage place attributes for the nondefault
5683 bit order ensures that such],Old=[. Such]} storage positions will @Chg{Version=[2],
5684 New=[not ],Old=[]}be split into two or three pieces@Chg{Version=[2],New=[. Thus,
5685 there is no significant implementation burden to supporting the nondefault
5686 bit order, given that the set of machine scalars is implementation-defined],
5687 Old=[ if the nondefault bit ordering is used, which could be onerous to
5688 support. However, if Word_Size = Storage_Unit,
5689 there might not be a natural bit ordering,
5690 but the splitting problem need not occur]}.
5691 @end{Ramification}
5692 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
5693 Text=[The recommended level of support for the nondefault bit ordering
5694 should be followed.]}]}
5695 @end{ImplAdvice}
5696
5697 @begin{Notes}
5698 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
5699 @ChgAdded{Version=[2],Text=[Bit_Order clauses make it possible to write
5700 @nt{record_representation_clause}s that can be ported between machines having
5701 different bit ordering. They do not guarantee transparent exchange of data
5702 between such machines.]}
5703 @end{Notes}
5704
5705 @begin{Extend83}
5706 @Defn{extensions to Ada 83}
5707 The Bit_Order attribute is new to Ada 95.
5708 @end{Extend83}
5709
5710 @begin{DiffWord95}
5711 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00133-01]}
5712 @ChgAdded{Version=[2],Text=[We now suggest that all implementations
5713 support the nondefault bit order.]}
5714 @end{Diffword95}
5715
5716
5717
5718 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
5719 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
5720 @LabeledClause{Change of Representation}
5721
5722 @begin{Intro}
5723 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
5724 @redundant[@Defn{change of representation}
5725 @Defn2{Term=[representation], Sec=(change of)}
5726 A @nt{type_conversion} (see @RefSecNum{Type Conversions})
5727 can be used to convert between two different
5728 representations of the same array or record.
5729 To convert an array from one representation to another,
5730 two array types need to be declared with
5731 matching component subtypes, and convertible index types.
5732 If one type has @Chg{Version=[3],New=[Pack],Old=[packing]}
5733 specified and the other does not,
5734 then explicit conversion can be used to pack or unpack an array.
5735
5736 To convert a record from one representation to another,
5737 two record types with a common ancestor type need to be declared,
5738 with no inherited subprograms. Distinct representations can then
5739 be specified for the record types, and explicit conversion between
5740 the types can be used to effect a change in representation.]
5741 @begin{Ramification}
5742 This technique does not work if the first type is an
5743 untagged type with user-defined primitive subprograms.
5744 It does not work at all for tagged types.
5745 @end{Ramification}
5746 @end{Intro}
5747
5748 @begin{Examples}
5749 @leading@keepnext@i{Example of change of representation:}
5750 @begin{Example}
5751 --@RI{ Packed_Descriptor and Descriptor are two different types}
5752 --@RI{ with identical characteristics, apart from their}
5753 --@RI{ representation}
5754
5755 @key[type] Descriptor @key[is]
5756 @key[record]
5757 --@RI{ components of a descriptor}
5758 @key[end] @key[record];
5759
5760 @key[type] Packed_Descriptor @key[is] @key[new] Descriptor;
5761
5762 @key[for] Packed_Descriptor @key[use]
5763 @key[record]
5764 --@RI{ component clauses for some or for all components}
5765 @key[end] @key[record];
5766
5767 @RI{-- Change of representation can now be accomplished by explicit type conversions:}
5768
5769 D : Descriptor;
5770 P : Packed_Descriptor;
5771
5772 P := Packed_Descriptor(D); --@RI{ pack D}
5773 D := Descriptor(P); --@RI{ unpack P}
5774 @end{Example}
5775 @end{Examples}
5776