Debian Codegraph @

source_2020/04a.mss

raw
1 @Part(04, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4 @LabeledSection{Names and Expressions}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/04a.mss,v $}
7 @Comment{$Revision: 1.158 $}
8
9 @begin{Intro}
10 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
11 @Redundant[The rules applicable to the different forms of @nt<name> and
12 expression, and to their evaluation, are given in this
13 @Chg{Version=[3],New=[clause],Old=[section]}.]
14 @end{Intro}
15
16 @LabeledClause{Names}
17
18 @begin{Intro}
19 @redundant[@nt<Name>s can denote declared entities, whether declared explicitly
20 or implicitly (see @RefSecNum(Declarations)). @nt<Name>s can also
21 denote objects or subprograms designated by access values; the
22 results of @nt<type_conversion>s or @nt<function_call>s; subcomponents
23 and slices of objects and values; protected subprograms,
24 single entries, entry families,
25 and entries in families of entries.
26 Finally, @nt<name>s can denote attributes of any of the foregoing.]
27 @end{Intro}
28
29 @begin{Syntax}
30 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0003-1],ARef=[AI05-0139-2]}
31 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0125-3]}
32 @Syn{tabs=[P22], lhs=<name>,rhs="
33 @Syn2{direct_name}@\| @Syn2{explicit_dereference}
34 | @Syn2{indexed_component}@\| @Syn2{slice}
35 | @Syn2{selected_component}@\| @Syn2{attribute_reference}
36 | @Syn2{type_conversion}@\| @Syn2{function_call}
37 | @Syn2{character_literal}@Chg{Version=[3],New=[@\| @Syn2{qualified_expression}
38 | @Syn2{generalized_reference}@\| @Syn2{generalized_indexing}@Chg{Version=[5],New=<
39 | @Syn2{target_name}>,Old=<>}],Old=[]}"}
40
41
42 @Syn{lhs=<direct_name>,
43 rhs="@Syn2{identifier} | @Syn2{operator_symbol}"}
44 @begin{Discussion}
45 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
46 @nt<character_literal> is no longer a @nt<direct_name>.
47 @nt<character_literal>s are usable even when the corresponding
48 @Chg{Version=[2],New=[enumeration type
49 declaration],Old=[@ntf<enumeration_type_declaration>]} is not visible. See
50 @RefSecNum(Literals).
51 @end{Discussion}
52
53 @Syn{lhs=<prefix>,rhs="@Syn2{name} | @Syn2{implicit_dereference}"}
54
55 @Syn{lhs=<explicit_dereference>,rhs="@Syn2{name}.@key{all}"}
56
57 @Syn{lhs=<implicit_dereference>,rhs="@Syn2{name}"}
58
59 @end{Syntax}
60
61 @begin{Intro}
62 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
63 @Redundant[Certain forms of @nt<name> (@nt<indexed_component>s,
64 @nt<selected_component>s, @nt<slice>s, and
65 @Chg{Version=[3],New=[@nt<attribute_reference>s],Old=[@ntf<attribute>s]})
66 include a @nt<prefix> that is either itself a @nt<name> that denotes
67 some related entity, or an @nt<implicit_dereference> of an access
68 value that designates some related entity.]
69 @end{Intro}
70
71 @begin{Resolution}
72 @Defn{dereference}
73 @PDefn2{Term=[expected type],
74 Sec=(dereference @nt{name})}
75 The @nt{name} in a @i(dereference) (either an
76 @nt<implicit_dereference> or an @nt<explicit_dereference>)
77 is expected to be of any access type.
78 @end{Resolution}
79
80 @begin{StaticSem}
81 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0008-1]}
82 @PDefn2{Term=[nominal subtype], Sec=(associated with a dereference)}
83 If the type of the @nt{name} in a dereference is some access-to-object
84 type @i(T), then the dereference denotes a view of an object, the
85 @i(nominal subtype) of the view being the designated subtype
86 of @i(T).@Chg{Version=[3],New=[ If the designated subtype has
87 unconstrained discriminants, the (actual) subtype of the view is constrained
88 by the values of the discriminants of the designated object, except when
89 there is a partial view of the type of the designated subtype that does not
90 have discriminants, in which case the dereference is not constrained by its
91 discriminant values.],Old=[]}
92 @begin{Ramification}
93 If the
94 value of the @nt<name> is the result of an access type conversion, the
95 dereference denotes a view created as part of the conversion.
96 The nominal subtype of the view is not necessarily
97 the same as that used to create the designated object.
98 See @RefSecNum{Type Conversions}.
99 @end{Ramification}
100 @begin{Honest}
101 @PDefn2{Term=[nominal subtype], Sec=(of a @nt<name>)}
102 We sometimes refer to the nominal subtype of a particular kind
103 of @nt<name> rather than the nominal subtype of the view denoted by
104 the @nt<name> (presuming the @nt<name> denotes a view of an object).
105 These two uses of nominal subtype are intended to mean the same
106 thing.
107 @end{Honest}
108
109 @begin{Reason}
110 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
111 @ChgAdded{Version=[3],Text=[The last sentence was not present in Ada 95;
112 it is necessary in Ada 2005 because general access types can designate
113 unconstrained objects, which was not possible in Ada 95. Thus, the rules
114 that had this effect in Ada 95 (the object being constrained by its initial
115 value) don't work in Ada 2005 and we have to say this explicitly.]}
116
117 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
118 @ChgAdded{Version=[3],Text=[The @ldquote@;except@rdquote@; part of the
119 last sentence prevents privacy
120 @ldquote@;breaking@rdquote@;, so that
121 if a private type has discriminants only in the full view, they don't
122 interfere with freely interassigning values between objects of the type,
123 even when the objects live in the heap.]}
124 @end{Reason}
125 @begin{ImplNote}
126 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
127 @ChgAdded{Version=[3],Text=[Since we don't depend on whether the designated
128 object is constrained, it is not necessary to include a constrained
129 bit in every object that could be designated by a general access type.]}
130 @end{ImplNote}
131
132 @PDefn2{Term=[profile], Sec=(associated with a dereference)}
133 If the type of the @nt<name> in a dereference is some access-to-subprogram
134 type @i(S), then the dereference denotes a view of a subprogram,
135 the @i(profile) of the view being the designated profile of @i(S).
136 @begin{Ramification}
137 This means
138 that the formal parameter names and default expressions to be used
139 in a call whose @nt<name> or @nt<prefix> is a dereference
140 are those of the designated profile, which need not be the same as those
141 of the subprogram designated by the access value, since 'Access
142 requires only subtype conformance, not full conformance.
143 @end{Ramification}
144 @end{StaticSem}
145
146 @begin{RunTime}
147 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00415-01]}
148 @PDefn2{Term=[evaluation], Sec=(name)}
149 The evaluation of a @nt<name> determines the entity denoted by the
150 @Chg{Version=[2],New=[@nt<name>],Old=[name]}. This evaluation has no other
151 effect for a @nt<name> that
152 is a @nt<direct_name> or a @nt<character_literal>.
153
154 @PDefn2{Term=[evaluation], Sec=(name that has a prefix)}
155 @Redundant[The evaluation of a @nt<name> that has a @nt<prefix> includes
156 the evaluation of the @nt<prefix>.]
157 @PDefn2{Term=[evaluation], Sec=(prefix)}
158 The evaluation of a @nt{prefix} consists of the evaluation of
159 the @nt{name} or the @nt{implicit_dereference}.
160 The @nt{prefix} denotes the entity denoted by the @nt{name} or the
161 @nt{implicit_dereference}.
162
163 @PDefn2{Term=[evaluation], Sec=(dereference)}
164 The evaluation of a dereference
165 consists of the evaluation of the @nt{name}
166 and the determination of the object or subprogram that is designated
167 by the value of the @nt{name}.
168 @IndexCheck{Access_Check}
169 A check is made that the value of the @nt{name} is not the null access
170 value.
171 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
172 Constraint_Error is raised if this check fails.
173 The dereference
174 denotes the object or subprogram designated by the value of the @nt{name}.
175 @end{RunTime}
176
177 @begin{Examples}
178 @Leading@keepnext@i(Examples of direct names:)
179 @begin(Example)
180 @tabclear()@tabset(P9, P47)
181 Pi @\@RI(-- the direct name of a number) @\(see @RefSecNum(Number Declarations))
182 Limit @\@RI(-- the direct name of a constant) @\(see @RefSecNum(Object Declarations))
183 Count @\@RI(-- the direct name of a scalar variable) @\(see @RefSecNum(Object Declarations))
184 Board @\@RI(-- the direct name of an array variable) @\(see @RefSecNum(Index Constraints and Discrete Ranges))
185 Matrix @\@RI(-- the direct name of a type) @\(see @RefSecNum(Array Types))
186 Random @\@RI(-- the direct name of a function) @\(see @RefSecNum(Subprogram Declarations))
187 Error @\@RI(-- the direct name of an exception) @\(see @RefSecNum(Exception Declarations))
188 @end(Example)
189
190 @begin{WideAbove}
191 @leading@keepnext@i{Examples of dereferences:}
192 @end{WideAbove}
193 @begin{Example}@tabclear()@tabset(P19)
194 Next_Car.@key[all]@\--@RI[ explicit dereference denoting the object designated by]
195 @\--@RI[ the access variable Next_Car (see @RefSecNum{Incomplete Type Declarations})]
196 Next_Car.Owner @\--@RI[ selected component with implicit dereference;]
197 @\--@RI[ same as Next_Car.@key[all].Owner]
198 @end{Example}
199 @end{Examples}
200
201 @begin{Extend83}
202 @Defn{extensions to Ada 83}
203 Type conversions and function calls are now considered names
204 that denote the result of the operation.
205 In the case of a type conversion used as an actual
206 parameter or that is of a tagged type, the type conversion is considered
207 a variable if the operand is a variable.
208 This simplifies the description of "parameters of the
209 form of a type conversion" as well as better supporting an
210 important OOP paradigm that requires the combination of a
211 conversion from a class-wide type to some specific
212 type followed immediately by component selection.
213 Function calls are considered names so that a type conversion
214 of a function call and the function call itself are treated
215 equivalently in the grammar.
216 A function call is considered the name of a constant,
217 and can be used anywhere such a name is permitted.
218 See @RefSecNum(Return Statements).
219
220 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
221 Type conversions of a tagged type are permitted anywhere
222 their operand is permitted. That is, if the operand
223 is a variable, then the type conversion can appear on the
224 left-hand side of an @nt{assignment_statement}.
225 If the operand is an object,
226 then the type conversion can appear in an object renaming
227 or as a @Chg{New=[@nt{prefix}],Old=[prefix]}.
228 See @RefSecNum(Type Conversions).
229 @end{Extend83}
230
231 @begin{DiffWord83}
232 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
233 Everything of the general syntactic form @nt{name}(...) is
234 now syntactically a @nt{name}. In any realistic parser,
235 this would be a necessity since distinguishing among the various
236 @nt{name}(...) constructs inevitably requires name resolution.
237 In cases where the construct yields a value rather than an object,
238 the name denotes @Chg{Version=[2],New=[a],Old=[the]} value rather than an
239 object. Names already denote values in Ada 83 with named numbers, components of
240 the result of a function call, etc. This is partly just a wording change, and
241 partly an extension of functionality (see Extensions heading above).
242
243 The syntax rule for @nt{direct_name} is new. It is used in places where
244 direct visibility is required.
245 It's kind of like Ada 83's @ntf{simple_name}, but @ntf{simple_name} applied
246 to both direct visibility and visibility by selection,
247 and furthermore, it didn't work right for @nt{operator_symbol}s.
248 The syntax rule for @ntf{simple_name} is removed,
249 since its use is covered by a combination of @nt{direct_name} and
250 @nt{selector_name}.
251 The syntactic categories @nt{direct_name} and @nt{selector_name} are similar;
252 it's mainly the visibility rules that distinguish the two.
253 The introduction of @nt{direct_name} requires the insertion of one new
254 explicit textual rule: to forbid @nt<statement_identifier>s from being
255 @nt<operator_symbol>s.
256 This is the only case where the explicit rule is needed,
257 because this is the only case where the declaration of the entity is
258 implicit.
259 For example, there is no need to syntactically forbid (say) @lquotes@;X: "Rem";@rquotes@;,
260 because it is impossible to declare a type whose name is an
261 @nt{operator_symbol} in the first place.
262
263 The syntax rules for @nt{explicit_dereference}
264 and @nt{implicit_dereference} are new;
265 this makes other rules simpler, since dereferencing an access value has
266 substantially different semantics from @nt{selected_component}s.
267 We also use @nt{name} instead of @nt{prefix} in the
268 @nt{explicit_dereference} rule
269 since that seems clearer. Note that these rules rely on the
270 fact that function calls are now names, so we don't need to
271 use prefix to allow functions calls in front of .@key{all}.
272 @begin{Discussion}
273 Actually, it would be reasonable to allow any @nt{primary} in front
274 of .@key{all}, since only the value is needed, but that would be a bit
275 radical.
276 @end{Discussion}
277
278 We no longer use the term @i(appropriate for a type)
279 since we now describe the semantics of a prefix in terms
280 of implicit dereference.
281 @end{DiffWord83}
282
283 @begin{Extend2005}
284 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
285 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}A
286 @nt{qualified_expression} is now a @nt{name} denoting a constant view;
287 this allows them to be used as a prefix and to be renamed as an object.
288 They are often used to remove ambiguity from function calls, and there
289 may be no other way to do that. Interestingly, a @nt{type_conversion} of
290 a @nt{qualified_expression} is already legal in these contexts, so this
291 change mainly reduces clutter by eliminating an otherwise unneeded
292 @nt{type_conversion} from some expressions.]}
293 @end{Extend2005}
294
295 @begin{DiffWord2005}
296 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]}
297 @ChgAdded{Version=[3],Text=[@b<Correction:> Added a missing rule so
298 that most dereferences are assumed constrained (without determining whether
299 the designated object is). This is just confirming the Ada 95 rules;
300 Ada 2005 failed to ensure that this property was unchanged.]}
301
302 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0299-1]}
303 @ChgAdded{Version=[3],Text=[Added @nt{generalized_reference} and
304 @nt{generalized_indexing} as types of @nt{name}; these are documented
305 as extensions in the appropriate subclauses.]}
306 @end{DiffWord2005}
307
308 @begin{DiffWord2012}
309 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0125-3]}
310 @ChgAdded{Version=[5],Text=[Added a @nt{target_name}
311 (see @RefSecNum{Target Name Symbols}) to the syntax of @nt{name}.]}
312 @end{DiffWord2012}
313
314
315 @LabeledSubClause{Indexed Components}
316
317 @begin{Intro}
318 @Redundant[An @nt<indexed_component> denotes either
319 a component of an array or an entry
320 in a family of entries.
321 @IndexSee{Term=[array indexing],See=(indexed_component)}]
322 @end{Intro}
323
324 @begin{Syntax}
325 @Syn{lhs=<indexed_component>,rhs="@Syn2{prefix}(@Syn2{expression} {, @Syn2{expression}})"}
326 @end{Syntax}
327
328 @begin{Resolution}
329 The @nt{prefix} of an @nt{indexed_component} with a given
330 number of @nt<expression>s
331 shall resolve to denote an array (after any implicit dereference)
332 with the corresponding number of index positions,
333 or shall resolve to denote an entry family of a task or protected object
334 (in which case there shall be only one @nt<expression>).
335
336 @PDefn2{Term=[expected type], Sec=(indexed_component expression)}
337 The expected type for each @nt{expression} is the corresponding index type.
338
339 @end{Resolution}
340
341 @begin{StaticSem}
342 When the @nt<prefix> denotes an array,
343 the @nt<indexed_component> denotes the component of the
344 array with the specified index value(s).
345 @PDefn2{Term=[nominal subtype],
346 Sec=(associated with an @nt<indexed_component>)}
347 The nominal subtype of the @nt<indexed_component> is the
348 component subtype of the array type.
349 @begin{Ramification}
350 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00363-01]}
351 @ChgDeleted{Version=[2],Text=[In the case of an array whose components are
352 aliased, and
353 of an unconstrained discriminated subtype, the components
354 are constrained even though their nominal subtype is unconstrained.
355 (This is because all aliased discriminated objects are constrained.
356 See @RefSecNum(Operations of Access Types).)
357 In all other cases, an array component is constrained if and only
358 if its nominal subtype is constrained.]}
359 @end{Ramification}
360
361 When the @nt<prefix> denotes an entry family,
362 the @nt<indexed_component> denotes
363 the individual entry of the entry family with the specified index value.
364
365 @end{StaticSem}
366
367 @begin{RunTime}
368 @PDefn2{Term=[evaluation], Sec=(indexed_component)}
369 For the evaluation of an @nt<indexed_component>, the @nt{prefix} and the
370 @nt{expression}s are evaluated in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
371 The value of
372 each @nt<expression> is converted to the corresponding index type.
373 @PDefn2{Term=[implicit subtype conversion],Sec=(array index)}
374 @IndexCheck{Index_Check}
375 A check is made that each index value
376 belongs to the corresponding index range of the array or entry family
377 denoted by the @nt<prefix>.
378 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
379 Constraint_Error is raised if this check fails.
380
381 @end{RunTime}
382
383 @begin{Examples}
384 @Leading@keepnext@i(Examples of indexed components:)
385 @begin{Example}
386 @tabclear()@tabset(P64)
387 My_Schedule(Sat) --@RI[ a component of a one-dimensional array @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
388 Page(10) --@RI[ a component of a one-dimensional array @\(see @RefSecNum{Array Types})]
389 Board(M, J + 1) --@RI[ a component of a two-dimensional array @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
390 Page(10)(20) --@RI[ a component of a component @\(see @RefSecNum{Array Types})]
391 Request(Medium) --@RI[ an entry in a family of entries @\(see @RefSecNum{Task Units and Task Objects})]
392 Next_Frame(L)(M, N) --@RI[ a component of a function call @\(see @RefSecNum{Subprogram Declarations})]
393 @end{Example}
394 @end{Examples}
395
396 @begin{Notes}
397 @i(Notes on the examples:)
398 Distinct notations are used for components of multidimensional arrays (such
399 as Board) and arrays of arrays (such as Page). The components of an array
400 of arrays are arrays and can therefore be indexed. Thus Page(10)(20)
401 denotes the 20th component of Page(10). In the last example Next_Frame(L)
402 is a function call returning an access value that designates a
403 two-dimensional array.
404
405 @end{Notes}
406
407 @LabeledSubClause{Slices}
408
409 @begin{Intro}
410 @redundant[@Defn{array slice}
411 A @nt<slice> denotes a one-dimensional array formed by a sequence of
412 consecutive components of a one-dimensional array. A @nt<slice> of
413 a variable is a variable; a @nt<slice> of a constant is a constant;]
414 a @nt<slice> of a value is a value.
415 @end{Intro}
416
417 @begin{Syntax}
418 @Syn{lhs=<slice>,rhs="@Syn2{prefix}(@Syn2{discrete_range})"}
419 @end{Syntax}
420
421 @begin{Resolution}
422 The @nt{prefix} of a @nt{slice}
423 shall resolve to denote a one-dimensional array
424 (after any implicit dereference).
425
426 @PDefn2{Term=[expected type], Sec=(slice discrete_range)}
427 The expected type for the @nt{discrete_range} of a @nt<slice>
428 is the index type of the array type.
429 @end{Resolution}
430
431 @begin{StaticSem}
432 A @nt<slice> denotes a one-dimensional array formed by the sequence of
433 consecutive components of the array denoted by the @nt<prefix>,
434 corresponding to the range of values
435 of the index given by the @nt<discrete_range>.
436
437 The type of the @nt<slice> is that of the @nt<prefix>.
438 Its bounds are those defined by the @nt{discrete_range}.
439
440 @end{StaticSem}
441
442 @begin{RunTime}
443 @PDefn2{Term=[evaluation], Sec=(slice)}
444 For the evaluation of a @nt{slice},
445 the @nt{prefix} and the @nt{discrete_range}
446 are evaluated in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
447 @IndexCheck{Index_Check}
448 @Defn{null slice}
449 If the @nt{slice} is not a @i(null slice)
450 (a @nt<slice> where the @nt<discrete_range> is a null range),
451 then a check is made that the bounds of the @nt{discrete_range}
452 belong to the index range of the array denoted by the @nt{prefix}.
453 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
454 Constraint_Error is raised if this check fails.
455
456 @end{RunTime}
457
458 @begin{Notes}
459 A @nt<slice> is not permitted as the @nt<prefix> of an
460 Access @nt<attribute_reference>,
461 even if the components or the array as a whole are aliased.
462 See @RefSecNum(Operations of Access Types).
463 @begin{TheProof}
464 Slices are not aliased, by @RefSec{Access Types}.
465 @end{TheProof}
466 @begin(Reason)
467 This is to ease implementation of general-access-to-array.
468 If slices were aliased, implementations would need to store
469 array dope with the access values, which is not always desirable
470 given access-to-incomplete types completed in a package body.
471 @end(Reason)
472
473 For a one-dimensional array A, the @nt<slice> A(N .. N) denotes
474 an array that has only one component;
475 its type is the type of A. On the other hand, A(N) denotes a
476 component of the array A and has the corresponding component type.
477 @end{Notes}
478
479 @begin{Examples}
480 @Leading@keepnext@i(Examples of slices:)
481 @begin{Example}
482 @tabclear()@tabset(P58)
483 Stars(1 .. 15) --@RI[ a slice of 15 characters @\(see @RefSecNum{String Types})]
484 Page(10 .. 10 + Size) --@RI[ a slice of 1 + Size components @\(see @RefSecNum{Array Types})]
485 Page(L)(A .. B) --@RI[ a slice of the array Page(L) @\(see @RefSecNum{Array Types})]
486 Stars(1 .. 0) --@RI[ a null slice @\(see @RefSecNum{String Types})]
487 My_Schedule(Weekday) --@RI[ bounds given by subtype @\(see @RefSecNum{Index Constraints and Discrete Ranges} and @RefSecNum{Enumeration Types})]
488 Stars(5 .. 15)(K) --@RI[ same as Stars(K) @\(see @RefSecNum{String Types})]
489 --@RI[ provided that K is in 5 .. 15]
490 @end{Example}
491 @end{Examples}
492
493 @LabeledSubClause{Selected Components}
494
495 @begin{Intro}
496 @redundant[@nt{Selected_component}s are used to denote components (including
497 discriminants),
498 entries, entry families, and protected subprograms; they are
499 also used as expanded names as described below.
500 @IndexSee{Term=[dot selection],See=(selected_component)}]
501 @end{Intro}
502
503 @begin{Syntax}
504 @Syn{lhs=<selected_component>,rhs="@Syn2{prefix} . @Syn2{selector_name}"}
505
506
507 @Syn{lhs=<selector_name>,rhs="@Syn2{identifier} | @Syn2{character_literal} | @Syn2{operator_symbol}"}
508 @end{Syntax}
509
510 @begin{Resolution}
511 @Defn{expanded name}
512 A @nt<selected_component> is called an @i(expanded name)
513 if, according to the visibility rules, at least one possible
514 interpretation of its @nt<prefix> denotes
515 a package or an enclosing named construct (directly, not through
516 a @nt<subprogram_renaming_declaration>
517 or @nt<generic_renaming_declaration>).
518 @begin{Discussion}
519 See AI83-00187.
520 @end{Discussion}
521
522 @Leading@;A @nt{selected_component} that is not an expanded name
523 shall resolve to denote one of the following:
524 @begin(Ramification)
525 If the @nt<prefix> of a @nt<selected_component> denotes
526 an enclosing named construct, then the @nt<selected_component> is interpreted
527 only as an expanded name, even if the named construct
528 is a function that could be called without parameters.
529 @end(Ramification)
530 @begin{Itemize}
531 A component @Redundant[(including a discriminant)]:
532
533 @NoPrefix@;The @nt{prefix} shall resolve to denote an object or value of some
534 non-array composite type
535 (after any implicit dereference).
536 The @nt{selector_name} shall resolve to denote a
537 @nt{discriminant_specification} of the type, or, unless the type is
538 a protected type, a @nt<component_declaration>
539 of the type. The @nt{selected_component} denotes the
540 corresponding component of the object or value.
541 @begin{Reason}
542 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00015}
543 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
544 The components of a protected object cannot be named except
545 by an expanded name, even from within the corresponding protected body.
546 The protected body @Chg{Version=[3],New=[cannot],Old=[may not]} reference
547 @Chg{New=[],Old=[the ]}the private
548 components of some arbitrary object of the protected
549 type; the protected body may reference components of the current
550 instance only (by an expanded name or a @nt<direct_name>).
551 @end{Reason}
552 @begin{Ramification}
553 Only the discriminants and components visible at the place of the
554 @nt<selected_component> can be selected, since a @nt<selector_name>
555 can only denote declarations that are visible (see @RefSecNum{Visibility}).
556 @end{Ramification}
557
558 A single entry, an entry family, or a protected subprogram:
559
560 @NoPrefix@;The @nt{prefix} shall resolve to denote an object or value of some
561 task or protected type (after any implicit dereference).
562 The @nt{selector_name} shall resolve to denote an @nt{entry_declaration}
563 or @nt{subprogram_declaration} occurring (implicitly or explicitly)
564 within the visible part of that type.
565 The @nt{selected_component} denotes the
566 corresponding entry, entry family, or protected subprogram.
567 @begin{Reason}
568 This explicitly says @lquotes@;visible part@rquotes@; because even though the body
569 has visibility on the private part, it cannot call the
570 private operations of some arbitrary object of the task or protected
571 type, only those of the current instance (and expanded name notation
572 has to be used for that).
573 @end{Reason}
574
575 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
576 @ChgAdded{Version=[2],Text=[A view of a subprogram whose first formal parameter is of
577 a tagged type or is an access parameter whose designated type is tagged:]}
578
579 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
580 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0090-1]}
581 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The @nt<prefix> (after any implicit
582 dereference) shall resolve to denote an object or value of a specific tagged
583 type @i<T> or class-wide type @i<T>'Class. The @nt<selector_name> shall resolve
584 to denote a view of a subprogram declared immediately within the declarative
585 region in which an ancestor of the type @i<T> is declared. The first formal
586 parameter of the subprogram shall be of type @i<T>, or a class-wide type that
587 covers @i<T>, or an access parameter designating one of these types. The
588 designator of the subprogram shall not be the same as that of a component of
589 the tagged type visible at the point of the @nt<selected_component>.
590 @Chg{Version=[3],New=[The subprogram shall not
591 be an implicitly declared primitive operation of type @i<T> that overrides
592 an inherited subprogram implemented by an entry or protected subprogram
593 visible at the point of the @nt{selected_component}. ],Old=[]}The
594 @nt<selected_component> denotes a view of this subprogram that omits the first
595 formal parameter. This view is called a @i{prefixed view} of the subprogram,
596 and the @nt{prefix} of the @nt<selected_component> (after any implicit
597 dereference) is called the @i<prefix> of the prefixed view.
598 @Defn{prefixed view}@Defn2{Term=[prefix],Sec=[of a prefixed view]}]}
599
600 @begin{Discussion}
601 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0090-1]}
602 @ChgAdded{Version=[3],Text=[The part of the rule that excludes a primitive
603 overriding subprogram as a selector applies only to the wrapper subprogram
604 that is implicitly declared to override a subprogram inherited from a
605 synchronized interface that is implemented by an operation of a task or
606 protected type (see @RefSecNum{Task Units and Task Objects} and
607 @RefSecNum{Protected Units and Protected Objects}). We don't want
608 calls that use a prefixed view to be ambiguous between the wrapper
609 subprogram and the implementing entry or protected operation. Note that
610 it is illegal to declare an explicit primitive that has a prefixed view
611 that is homographic with one of the type's operations, so
612 in normal cases it isn't possible to have an ambiguity in a prefix call.
613 However, a class-wide operation of an ancestor type that is declared in the
614 same declaration list with the ancestor type is also considered, and that
615 can still make a call ambiguous.]}
616 @end{Discussion}
617 @end{Itemize}
618
619 @Leading@;An expanded name shall resolve to denote a declaration that
620 occurs immediately within a named declarative region, as follows:
621 @begin(itemize)
622 The @nt<prefix> shall resolve to denote either a package @Redundant[(including
623 the current instance of a generic package, or a rename of a package)], or
624 an enclosing named construct.
625
626 The @nt{selector_name}
627 shall resolve to denote a declaration that occurs
628 immediately within the declarative region of the
629 package or enclosing construct @Redundant[(the declaration shall be visible
630 at the place of the expanded name @em see @RefSecNum(Visibility))].
631 The expanded name denotes that declaration.
632 @begin{Ramification}
633 Hence, a library unit or subunit can use an expanded
634 name to refer to the declarations within the private part of its
635 parent unit, as well as to other children that have been mentioned in
636 @nt<with_clause>s.
637 @end{Ramification}
638
639 If the @nt<prefix> does not denote a package, then it
640 shall be a @nt<direct_name> or an expanded name,
641 and it shall resolve to denote a program unit (other than a package),
642 the current instance of a type, a @nt{block_statement}, a @nt{loop_statement},
643 or an @nt{accept_@!statement}
644 (in the case of an @nt<accept_@!statement> or @nt<entry_@!body>,
645 no family index is allowed);
646 the expanded name shall occur within the
647 declarative region of this construct.
648 Further, if this construct is a callable construct
649 and the @nt<prefix> denotes more than one such enclosing callable construct,
650 then the expanded name is ambiguous, independently of the @nt<selector_name>.
651
652 @end(itemize)
653
654 @end{Resolution}
655
656 @begin{Legality}
657 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
658 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0204-1]}
659 @ChgAdded{Version=[2],Text=[For@Chg{Version=[5],New=[ a prefixed view of],Old=[]}
660 a subprogram whose first parameter is an access parameter, the
661 prefix@Chg{Version=[5],New=[],Old=[ of any prefixed view]}
662 shall @Chg{Version=[5],New=[be legal as the prefix of an
663 Access attribute reference],Old=[enote an aliased view of an object]}.]}
664
665 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00407-01]}
666 @ChgAdded{Version=[2],Text=[For a subprogram whose first parameter is of mode
667 @b<in out> or @b<out>, or of an anonymous access-to-variable type, the prefix
668 of any prefixed view shall denote a variable.]}
669
670 @begin{Reason}
671 @ChgRef{Version=[2],Kind=[AddedNormal]}
672 @ChgAdded{Version=[2],Text=[We want calls through a prefixed view and through
673 a normal view to have the same legality. Thus, the implicit 'Access in
674 this new notation needs the same legality check that an explicit 'Access
675 would have. Similarly, we need to prohibit the object from being constant
676 if the first parameter of the subprogram is @key{in out}, because that is
677 (obviously) prohibited for passing a normal parameter.]}
678 @end{Reason}
679 @end{Legality}
680
681 @begin{RunTime}
682 @PDefn2{Term=[evaluation], Sec=(selected_component)}
683 The evaluation of a @nt{selected_component} includes the
684 evaluation of the @nt{prefix}.
685
686 @IndexCheck{Discriminant_Check}
687 For a @nt{selected_component} that denotes a component of a @nt{variant},
688 a check is made that the values of the discriminants are such that
689 the value or object denoted by the @nt<prefix> has this component.
690 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
691 The exception Constraint_Error is raised if this check fails.
692
693 @end{RunTime}
694
695 @begin{Examples}
696 @Leading@keepnext@i(Examples of selected components:)
697 @begin{Example}
698 @tabclear()@tabset(P60)
699 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01],ARef=[AI95-00407-01]}
700 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178]}
701 Tomorrow.Month --@RI[ a record component @\(see @RefSecNum{Record Types})]
702 Next_Car.Owner --@RI[ a record component @\(see @RefSecNum{Incomplete Type Declarations})]
703 Next_Car.Owner.Age --@RI[ a record component @\(see @RefSecNum{Incomplete Type Declarations})]
704 --@RI[ the previous two lines involve implicit dereferences]
705 Writer.Unit --@RI[ a record component (a discriminant) @\(see @RefSecNum{Variant Parts and Discrete Choices})]
706 Min_Cell(H).Value --@RI[ a record component of the result @\(see @RefSecNum{Subprogram Declarations})]
707 --@RI[ of the function call Min_Cell(H)]
708 @Chg{Version=[2],New=< Cashier.Append --@RI[ a prefixed view of a procedure @\(see @RefSecNum{Interface Types})]
709 >,Old=<>} Control.Seize --@RI[ an entry of a protected object @\(see @RefSecNum{Protected Units and Protected Objects})]
710 Pool(K).Write --@RI[ an entry of the task Pool(K) @\(see @Chg{Version=[5],New=[@RefSecNum{Task Units and Task Objects}],Old=[@RefSecNum{Protected Units and Protected Objects}]})]
711 @end{Example}
712
713 @begin{WideAbove}
714 @leading@keepnext@i(Examples of expanded names:)
715 @end{WideAbove}
716 @begin{Example}
717 @tabclear()@tabset(P67)
718 Key_Manager."<" --@RI[ an operator of the visible part of a package @\(see @RefSecNum{Private Operations})]
719 Dot_Product.Sum --@RI[ a variable declared in a function body @\(see @RefSecNum{Subprogram Declarations})]
720 Buffer.Pool --@RI[ a variable declared in a protected unit @\(see @RefSecNum{Example of Tasking and Synchronization})]
721 Buffer.Read --@RI[ an entry of a protected unit @\(see @RefSecNum{Example of Tasking and Synchronization})]
722 Swap.Temp --@RI[ a variable declared in a block statement @\(see @RefSecNum{Block Statements})]
723 Standard.Boolean --@RI[ the name of a predefined type @\(see @RefSecNum{The Package Standard})]
724 @end{Example}
725 @end{Examples}
726
727 @begin{Extend83}
728 @Defn{extensions to Ada 83}
729 We now allow an expanded name to use a prefix
730 that denotes a rename of a package, even if the
731 selector is for an entity local to the body or private
732 part of the package, so long as the entity is visible
733 at the place of the reference. This eliminates
734 a preexisting anomaly where references in a package
735 body may refer to declarations of its visible part
736 but not those of its private part or body when the
737 prefix is a rename of the package.
738 @end{Extend83}
739
740 @begin{DiffWord83}
741 The syntax rule for @nt{selector_name} is new. It is used in places where
742 visibility, but not necessarily direct visibility, is required.
743 See @RefSec{Names} for more information.
744
745 The description of dereferencing an access type has been moved
746 to @RefSec{Names}; @nt<name>.@key(all) is no longer considered
747 a @nt<selected_component>.
748
749 The rules have been restated to be consistent with our
750 new terminology, to accommodate class-wide types, etc.
751 @end{DiffWord83}
752
753 @begin{Extend95}
754 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00252-01]}
755 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}The prefixed view notation
756 for tagged objects is new. This provides a similar notation to that used in other
757 popular languages, and also reduces the need for @nt{use_clause}s. This
758 is sometimes known as @lquotes@;distinguished receiver notation@rquotes@;.
759 @Defn{distinguished receiver notation}]}
760
761 @ChgRef{Version=[2],Kind=[AddedNormal]}
762 @ChgAdded{Version=[2],Type=[Leading],Text=[Given the following
763 definitions for a tagged type T:]}
764 @begin{Example}
765 @ChgRef{Version=[2],Kind=[AddedNormal]}
766 @ChgAdded{Version=[2],Text=[@key{procedure} Do_Something (Obj : @key{in out} T; Count : @key{in} Natural);
767 @key{procedure} Do_Something_Else (Obj : @key{access} T; Flag : @key{in} Boolean);
768 My_Object : @key{aliased} T;]}
769 @end{Example}
770 @ChgRef{Version=[2],Kind=[AddedNormal]}
771 @ChgAdded{Version=[2],Type=[Leading],Text=[the following calls are equivalent:]}
772 @begin{Example}
773 @ChgRef{Version=[2],Kind=[AddedNormal]}
774 @ChgAdded{Version=[2],Text=[Do_Something (My_Object, Count => 10);
775 My_Object.Do_Something (Count => 10);]}
776 @end{Example}
777 @ChgRef{Version=[2],Kind=[AddedNormal]}
778 @ChgAdded{Version=[2],Type=[Leading],Text=[as are the following calls:]}
779 @begin{Example}
780 @ChgRef{Version=[2],Kind=[AddedNormal]}
781 @ChgAdded{Version=[2],Text=[Do_Something_Else (My_Object'Access, Flag => True);
782 My_Object.Do_Something_Else (Flag => True);]}
783 @end{Example}
784 @end{Extend95}
785
786 @begin{DiffWord2005}
787 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0090-1]}
788 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the definition of
789 a prefixed view to ignore the implicit subprograms declared for
790 @ldquote@;implemented by@rdquote entries and protected subprograms.]}
791 @end{DiffWord2005}
792
793 @begin{Incompatible2012}
794 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0204-1]}
795 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@b<Correction:>
796 Added a rule to ensure that all reasons that the prefix of an Access
797 attribute can be illegal are covered by the rule for the implicit Access
798 attribute of a prefixed view. If the object is a subcomponent
799 that depends on discriminants or fails a static accessibility check, Ada 2012
800 would have allowed the prefix while Ada 202x would not. This violated the
801 principle that a prefixed view and a normal call have the same semantics;
802 practically, the code may not have worked anyway if a compiler implemented
803 generalized indexing by code expansion into the canonical form. Thus, such
804 code wasn't practically portable.]}
805 @end{Incompatible2012}
806
807
808 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
809 @LabeledSubClause{Attributes}
810
811 @begin{Intro}
812 @Defn{attribute}
813 @Redundant[An @i(attribute) is a characteristic of an entity that can be
814 queried via an @nt{attribute_@!reference}
815 or a @nt<range_@!attribute_@!reference>.]
816 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Attribute>,
817 Text=<@ChgAdded{Version=[5],Text=[A characteristic or property of an entity that
818 can be queried, and in some cases specified.]}>}
819 @end{Intro}
820
821 @begin{Syntax}
822 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0262-1]}
823 @Syn{lhs=<attribute_reference>,rhs="@Chg{Version=[5],New=[
824 ],Old=[]}@Syn2{prefix}@SingleQuote@Syn2{attribute_designator}@Chg{Version=[5],New=[
825 | @Syn2{reduction_attribute_reference}],Old=[]}"}
826
827 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI05-0004-1]}
828 @Syn{lhs=<attribute_designator>,rhs="
829 @Syn2{identifier}[(@SynI{static_}@Syn2{expression})]
830 | Access | Delta | Digits@Chg{Version=[3],New=[ | Mod],Old=[]}"}
831
832
833 @Syn{lhs=<range_attribute_reference>,
834 rhs="@Syn2{prefix}@SingleQuote@Syn2{range_attribute_designator}"}
835
836 @Syn{lhs=<range_attribute_designator>,
837 rhs="Range[(@SynI{static_}@Syn2{expression})]"}
838 @end{Syntax}
839
840 @begin{Resolution}
841 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0242-1],ARef=[AI12-0262-1]}
842 In an @nt<attribute_reference>@Chg{Version=[5],New=[ that is not a @nt{reduction_attribute_reference}],Old=[]},
843 if the @nt<attribute_designator> is for an attribute defined
844 for (at least some) objects of an access type, then the @nt<prefix> is never
845 interpreted as an @nt<implicit_dereference>; otherwise (and for all
846 @nt<range_attribute_reference>s@Chg{Version=[5],New=[ and
847 @nt{reduction_attribute_reference}s],Old=[]}), if @Chg{Version=[5],New=[there is
848 a @nt{prefix} and ],Old=[]}the type of the @nt<name> within the @nt<prefix> is of
849 an access type, the @nt<prefix> is interpreted as an @nt<implicit_dereference>.
850 Similarly, if the @nt{attribute_designator} is for an attribute defined for (at
851 least some) functions, then the @nt<prefix> is never interpreted as a
852 parameterless @nt{function_call}; otherwise (and for all
853 @nt<range_attribute_reference>s@Chg{Version=[5],New=[ and
854 @nt{reduction_attribute_reference}s],Old=[]}), if @Chg{Version=[5],New=[there is
855 a @nt{prefix} and ],Old=[]}the @nt<prefix> consists of a @nt<name> that denotes a
856 function, it is interpreted as a parameterless @nt<function_call>.
857
858 @begin{Discussion}
859
860 The first part of this rule is essentially a "preference" against implicit
861 dereference, so that it is possible to ask for, say, 'Size of an access
862 object, without automatically getting the size of the object designated by the
863 access object. This rule applies to 'Access, 'Unchecked_Access, 'Size, and
864 'Address, and any other attributes that are defined for at least some access
865 objects.
866
867 The second part of this rule implies that, for a parameterless function F,
868 F'Address is the address of F, whereas
869 F'Size is the size of the anonymous constant returned by F.
870
871 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
872 We normally talk in terms of expected type or profile for
873 name resolution rules, but we don't do this for attributes
874 because certain attributes are legal independent of the type
875 or the profile of the @Chg{New=[@nt{prefix}],Old=[prefix]}.
876
877 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
878 @ChgAdded{Version=[2],Type=[Leading],Text=[Other than the rules given above,
879 the @ResolutionName@;s for the @nt{prefix} of each attribute are defined as
880 @ResolutionTitle for that attribute. If no such rules are defined, then no
881 context at all should be used when resolving
882 the @nt{prefix}. In particular, any knowledge about the kind of entities
883 required must not be used for resolution unless that is required by
884 @ResolutionTitle. This matters in obscure cases;
885 for instance, given the following declarations:]}
886 @begin{Example}
887 @ChgRef{Version=[2],Kind=[AddedNormal]}
888 @ChgAdded{Version=[2],Text=[ @key[function] Get_It @key[return] Integer @key[is] ... -- @RI[(1)]
889 @key[function] Get_It @key[return] Some_Record_Type @key[is] ... -- @RI[(2)]]}
890 @end{Example}
891 @ChgRef{Version=[2],Kind=[AddedNormal]}
892 @ChgAdded{Version=[2],Type=[Leading],Text=[the following @nt{attribute_reference} cannot be
893 resolved and is illegal:]}
894 @begin{Example}
895 @ChgRef{Version=[2],Kind=[AddedNormal]}
896 @ChgAdded{Version=[2],Text=[ @key[if] Get_It'Valid @key[then]]}
897 @end{Example}
898 @ChgRef{Version=[2],Kind=[AddedNormal]}
899 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
900 @ChgAdded{Version=[2],Text=[even though the Valid attribute is only defined
901 for objects of scalar types, and thus cannot be applied to the result of
902 function (2). That information cannot be used to resolve the @nt{prefix}.
903 The same would be true if (2) @Chg{Version=[3],New=[had],Old=[was]} been
904 a procedure; even though the procedure does not denote an object, the
905 @nt{attribute_reference} is still illegal.]}
906 @end{Discussion}
907
908 @PDefn2{Term=[expected type],
909 Sec=(attribute_designator expression)}
910 @PDefn2{Term=[expected type],
911 Sec=(range_attribute_designator expression)}
912 The @nt{expression}, if any, in an
913 @nt{attribute_designator} or @nt{range_attribute_designator}
914 is expected to be of any integer type.
915 @end{Resolution}
916
917 @begin{Legality}
918 The @nt{expression}, if any, in an @nt{attribute_designator}
919 or @nt{range_attribute_designator} shall be static.
920 @end{Legality}
921
922 @begin{StaticSem}
923 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0006-1]}
924 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0032-1],ARef=[AI12-0159-1]}
925 An @nt{attribute_reference} denotes a
926 value, an object, a subprogram, or some
927 other kind of program entity.@Chg{Version=[3],New=[
928 @Chg{Version=[4],New=[Unless explicitly specified otherwise, for],Old=[For]}
929 an @nt{attribute_reference} that denotes a value or an object, if
930 its type is scalar, then its nominal subtype is the base subtype of
931 the type; if its type is tagged, its nominal subtype is the first
932 subtype of the type; otherwise, its nominal subtype is a subtype of the type
933 without any constraint@Chg{Version=[4],New=[,],Old=[ or]}
934 @nt{null_exclusion}@Chg{Version=[4],New=[, or predicate],Old=[]}.
935 Similarly, unless explicitly specified otherwise, for an
936 @nt{attribute_reference} that denotes a function, when its result
937 type is scalar, its result subtype is the base subtype of the type,
938 when its result type is tagged, the result subtype is the first
939 subtype of the type, and when the result type is some other type,
940 the result subtype is a subtype of the type without any
941 constraint@Chg{Version=[4],New=[,],Old=[ or]}
942 @nt{null_exclusion}@Chg{Version=[4],New=[, or predicate],Old=[]}.],Old=[]}
943 @begin{Ramification}
944 The attributes defined by the language are summarized in
945 @RefSecNum{Language-Defined Attributes}.
946 Implementations can define additional attributes.
947 @end{Ramification}
948 @begin{Discussion}
949 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
950 @ChgAdded{Version=[3],Text=[The nominal subtype is primarily
951 a concern when an @nt{attribute_reference}, or
952 a call on an @nt{attribute_reference}, is used as the @nt{expression}
953 of a case statement, due to the full coverage requirement based on
954 the nominal subtype. For nondiscrete cases, we define the
955 nominal subtype mainly for completeness. Implementations may
956 specify otherwise for implementation-defined attribute functions.]}
957
958 @ChgRef{Version=[3],Kind=[AddedNormal]}
959 @ChgAdded{Version=[3],Text=[The rule is written to match the meaning
960 of the italicized @i{T} in the definition of attributes such as Input;
961 see @RefSecNum{Logical Operators and Short-circuit Control Forms}.]}
962 @end{Discussion}
963 @begin{Honest}
964 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
965 @ChgAdded{Version=[3],Text=[We don't worry about the fact that
966 @ldquote@;base subtype@rdquote is not explicitly defined for the
967 universal types. Since it is
968 not possible to constrain a universal numeric type, all subtypes
969 are unconstrained, and hence can be considered base subtypes.
970 The wording above could be altered to bypass this issue, but it
971 doesn't seem necessary, since universal integer is handled
972 specially in the rules for case expression full coverage, and
973 we don't allow user-defined functions for attribute functions
974 whose result type is universal.]}
975 @end{Honest}
976
977 @Redundant[A @nt{range_attribute_reference}
978 X'Range(N) is equivalent to the @nt<range> X'First(N) ..
979 X'Last(N), except that the @nt{prefix} is only evaluated once.
980 Similarly,
981 X'Range is equivalent to X'First .. X'Last, except that the @nt{prefix}
982 is only evaluated once.]
983
984 @end{StaticSem}
985
986 @begin{RunTime}
987 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0262-1]}
988 @PDefn2{Term=[evaluation], Sec=(attribute_reference)}
989 @PDefn2{Term=[evaluation], Sec=(range_attribute_reference)}
990 The evaluation of @Chg{Version=[5],New=[a],Old=[an @nt{attribute_reference}
991 (or]} @nt{range_attribute_reference}@Chg{Version=[5],New=[ or an
992 @nt{attribute_reference} that is not a
993 @nt{reduction_attribute_reference}],Old=[)]} consists
994 of the evaluation of the @nt{prefix}.@Redundant[@Chg{Version=[5],New=[ The
995 evaluation of a @nt{reduction_attribute_reference} is defined in
996 @RefSecNum{Reduction Expressions}.],Old=[]}]
997 @end{RunTime}
998
999 @begin{ImplPerm}
1000 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0015],ARef=[AI95-00093-01]}
1001 An implementation may provide implementation-defined attributes;
1002 the @nt{identifier} for an implementation-defined
1003 attribute shall differ from those of the language-defined
1004 attributes@Chg{New=[ unless supplied for compatibility with a previous edition of
1005 this International Standard],Old=[]}.
1006 @ImplDef{Implementation-defined attributes.}
1007 @begin{Ramification}
1008 They cannot be reserved words because reserved words are not legal
1009 identifiers.
1010
1011 The semantics of implementation-defined attributes,
1012 and any associated rules, are, of course, implementation defined.
1013 For example, the implementation defines whether a given
1014 implementation-defined attribute can be used in a static expression.
1015
1016 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0015],ARef=[AI95-00093-01]}
1017 @Chg{New=[Implementations are allowed to support the Small attribute for
1018 floating types, as this was defined in Ada 83, even though the name would
1019 conflict with a language-defined attribute.],Old=[]}
1020 @end{Ramification}
1021 @end{ImplPerm}
1022
1023 @begin{Notes}
1024 Attributes are defined throughout this International Standard,
1025 and are summarized in
1026 @RefSecNum{Language-Defined Attributes}.
1027
1028 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
1029 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235]}
1030 In general, the @nt<name> in a @nt<prefix> of an @nt<attribute_reference>
1031 (or a @nt<range_attribute_reference>) has to be resolved
1032 without using any context.
1033 However, in the case of the Access attribute,
1034 the expected type for the @Chg{Version=[2],New=[@nt{attribute_reference}],
1035 Old=[@Chg{New=[@nt{prefix}],Old=[prefix]}]} has to be a
1036 single access type, and@Chg{Version=[2],New=[],Old=[ if it is an
1037 access-to-subprogram type (see @RefSecNum(Operations of Access Types)) then]}
1038 the resolution of the @nt<name> can use the fact that
1039 the@Chg{Version=[2],New=[ type of the object or the],Old=[]} profile of the
1040 callable entity denoted by the @nt<prefix>
1041 has to @Chg{Version=[2],New=[match the designated type or ],Old=[]}be type
1042 conformant with the designated profile of the access type.
1043 @Defn2{Term=[type conformance],Sec=(required)}
1044 @begin(TheProof)
1045 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235]}
1046 In the general case, there is no @lquotes@;expected type@rquotes@; for
1047 the @nt<prefix> of an @nt<attribute_reference>.
1048 In the special case of 'Access,
1049 there is an @Chg{Version=[2],New=[@lquotes@;expected type@rquotes@; or ],
1050 Old=[]}@lquotes@;expected profile@rquotes@; for the @nt<prefix>.
1051 @end(TheProof)
1052 @begin(Reason)
1053 'Access is a special case, because without it,
1054 it would be very difficult to take 'Access of an overloaded
1055 subprogram.
1056 @end(Reason)
1057 @end{Notes}
1058
1059 @begin{Examples}
1060 @Leading@keepnext@i(Examples of attributes:)
1061 @begin{Example}
1062 @tabclear()@tabset(P64)
1063 Color'First --@RI[ minimum value of the enumeration type Color @\(see @RefSecNum{Enumeration Types})]
1064 Rainbow'Base'First --@RI[ same as Color'First @\(see @RefSecNum{Enumeration Types})]
1065 Real'Digits --@RI[ precision of the type Real @\(see @RefSecNum{Floating Point Types})]
1066 Board'Last(2) --@RI[ upper bound of the second dimension of Board @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
1067 Board'Range(1) --@RI[ index range of the first dimension of Board @\(see @RefSecNum{Index Constraints and Discrete Ranges})]
1068 Pool(K)'Terminated --@RI[ True if task Pool(K) is terminated @\(see @RefSecNum{Task Units and Task Objects})]
1069 Date'Size --@RI[ number of bits for records of type Date @\(see @RefSecNum{Record Types})]
1070 Message'Address --@RI[ address of the record variable Message @\(see @RefSecNum{Discriminant Constraints})]
1071 @end{Example}
1072 @end{Examples}
1073
1074 @begin{Extend83}
1075 @Defn{extensions to Ada 83}
1076 We now uniformly treat X'Range as X'First..X'Last,
1077 allowing its use with scalar subtypes.
1078
1079 We allow any integer type in the @SynI{static_}@nt{expression}
1080 of an attribute designator, not
1081 just a value of @i(universal_integer). The preference rules
1082 ensure upward compatibility.
1083 @end{Extend83}
1084
1085 @begin{DiffWord83}
1086 We use the syntactic category @nt{attribute_reference} rather
1087 than simply "attribute" to avoid confusing the name of something with
1088 the thing itself.
1089
1090 The syntax rule for @nt{attribute_reference}
1091 now uses @nt{identifier} instead of
1092 @ntf{simple_name}, because attribute @nt{identifier}s are not required to
1093 follow the normal visibility rules.
1094
1095 We now separate @nt{attribute_reference}
1096 from @nt{range_attribute_reference},
1097 and enumerate the reserved words that are legal attribute or range attribute
1098 designators.
1099 We do this because @nt{identifier} no longer includes reserved
1100 words.
1101
1102 The Ada 95 name resolution rules are a bit more explicit than in Ada 83.
1103 The Ada 83 rule said that the
1104 "meaning of the prefix of an attribute must be determinable
1105 independently of the attribute designator and independently
1106 of the fact that it is the prefix of an attribute." That isn't
1107 quite right since the meaning even in Ada 83 embodies whether or not
1108 the prefix is interpreted as a parameterless function call,
1109 and in Ada 95, it also embodies whether or not the prefix is interpreted
1110 as an implicit_dereference. So the attribute designator does
1111 make a difference @em just not much.
1112
1113 Note however that if the attribute designator is Access,
1114 it makes a big difference in the interpretation of the
1115 prefix (see @RefSecNum(Operations of Access Types)).
1116 @end{DiffWord83}
1117
1118 @begin{DiffWord95}
1119 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0015],ARef=[AI95-00093-01]}
1120 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> The wording
1121 was changed to allow implementations to continue to implement the Ada 83
1122 Small attribute. This was always intended to be allowed.]}
1123
1124 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]}
1125 @ChgAdded{Version=[2],Text=[The note about resolving prefixes of attributes
1126 was updated to reflect that the prefix of an Access attribute now has an
1127 expected type (see @RefSecNum{Operations of Access Types}).]}
1128 @end{DiffWord95}
1129
1130 @begin{DiffWord2005}
1131 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0006-1]}
1132 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined the nominal
1133 subtype of an @nt{attribute_reference} to close a minor language hole.]}
1134 @end{DiffWord2005}
1135
1136 @begin{DiffWord2012}
1137 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]}
1138 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Allowed overriding the
1139 nominal subtype of an @nt{attribute_reference} for an object; that is used
1140 elsewhere in this standard.]}
1141
1142 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0159-1]}
1143 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added wording so it is clear that
1144 predicates don't apply to the result of an attribute.]}
1145
1146 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1],ARef=[AI12-0262-1]}
1147 @ChgAdded{Version=[5],Text=[Added @nt{reduction_attribute_reference} and
1148 cleaned up the rules here to avoid trampling the definition of those in
1149 @RefSecNum{Reduction Expressions}.]}
1150 @end{DiffWord2012}
1151
1152
1153 @LabeledAddedSubClause{Version=[3],Name=[User-Defined References]}
1154
1155 @begin{StaticSem}
1156 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1157 @ChgAdded{Version=[3],Type=[Leading],Text=[Given a discriminated type @i<T>,
1158 the following type-related operational aspect may be specified:]}
1159
1160 @begin{Description}
1161 @ChgRef{Version=[3],Kind=[AddedNormal]}
1162 @ChgAdded{Version=[3],Text=[Implicit_Dereference@\This aspect is specified by a
1163 @nt{name} that denotes an access discriminant declared for the
1164 type @i<T>.@AspectDefn{Implicit_Dereference}]}
1165
1166 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Implicit_Dereference],
1167 Text=[@ChgAdded{Version=[3],Text=[Mechanism for user-defined implicit .@key[all].]}]}
1168
1169 @end{Description}
1170
1171 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1172 @ChgAdded{Version=[3],Text=[A (view of a) type with a specified
1173 Implicit_Dereference aspect is a @i{reference type}.@Defn{reference type}
1174 A @i{reference object} is an object of a reference type.@Defn{reference object}
1175 The discriminant named by the Implicit_Dereference aspect is the @i{reference
1176 discriminant} of the reference type or reference object.@Defn{reference discriminant}
1177 @Redundant[A @nt{generalized_reference} is a @nt{name} that identifies a
1178 reference object, and denotes the object or subprogram designated by the
1179 reference discriminant of the reference object.]]}
1180
1181 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Reference type>,
1182 Text=<@ChgAdded{Version=[3],Text=[A reference type is one that has user-defined
1183 behavior for @ldquote.@key[all]@rdquote, defined by the
1184 Implicit_Dereference aspect.]}>}
1185 @end{StaticSem}
1186
1187 @begin{Syntax}
1188
1189 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1190 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<generalized_reference>,Old=<>}>,
1191 rhs="@Chg{Version=[3],New=<@SynI{reference_object_}@Syn2{name}>,Old=<>}"}
1192
1193 @end{Syntax}
1194
1195 @begin{Resolution}
1196
1197 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0269-1]}
1198 @ChgAdded{Version=[3],Text=[The expected type for the @SynI{reference_object_}@nt{name}
1199 in a @nt{generalized_reference} is any reference type.@PDefn2{Term=[expected type],
1200 Sec=(@SynI{reference_object_}@nt{name})}]}
1201 @end{Resolution}
1202
1203 @begin{StaticSem}
1204
1205 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1206 @ChgAdded{Version=[4],Text=[The Implicit_Dereference aspect
1207 is nonoverridable (see @RefSecNum{Aspect Specifications}).]}
1208
1209 @begin{Reason}
1210 @ChgRef{Version=[4],Kind=[AddedNormal]}
1211 @ChgAdded{Version=[4],Text=[This ensures that all descendants of a
1212 reference type have the same reference discriminant. This prevents
1213 generic contract problems with formal derived types.]}
1214 @end{Reason}
1215
1216
1217 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1218 @ChgAdded{Version=[3],Text=[A @nt{generalized_reference} denotes a view
1219 equivalent to that of a dereference of the reference discriminant of the
1220 reference object.]}
1221
1222 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1223 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0203-1]}
1224 @ChgAdded{Version=[3],Text=[Given a reference type @i<T>, the
1225 Implicit_Dereference aspect is inherited by descendants of type @i<T> if not
1226 overridden@Chg{Version=[5],New=[ @Redundant[(which is only permitted if
1227 confirming)]],Old=[]}. If a descendant type constrains the value of the reference
1228 discriminant of @i<T> by a new discriminant, that new discriminant is the
1229 reference discriminant of the descendant. @Redundant[If the descendant type
1230 constrains the value of the reference discriminant of @i<T> by an
1231 @nt{expression} other than the @nt{name} of a new discriminant, a
1232 @nt{generalized_reference} that identifies an object of the descendant type
1233 denotes the object or subprogram designated by the value of this constraining
1234 expression.]]}
1235
1236 @end{StaticSem}
1237
1238 @begin{RunTime}
1239
1240 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1241 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[evaluation], Sec=(generalized_reference)}
1242 The evaluation of a @nt{generalized_reference}
1243 consists of the evaluation of the @SynI{reference_object_}@nt{name} and
1244 a determination of the object or subprogram designated by the
1245 reference discriminant of the named reference object.
1246 @IndexCheck{Access_Check}
1247 A check is made that the value of the reference
1248 discriminant is not the null access value.
1249 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
1250 Constraint_Error is raised if this check fails. The
1251 @nt{generalized_reference} denotes the object or
1252 subprogram designated by the value of the reference discriminant of the
1253 named reference object.]}
1254
1255 @end{RunTime}
1256
1257 @begin{Examples}
1258 @begin{Example}
1259 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1260 @ChgAdded{Version=[3],Text=[@key[type] Barrel @key[is tagged] ... -- @Examcom{holds objects of type Element}]}
1261
1262 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0299-1]}
1263 @ChgAdded{Version=[3],Text=[@key[type] Ref_Element(Data : @key[access] Element) @key[is limited private]
1264 @key[with] Implicit_Dereference => Data;
1265 -- @Examcom{This Ref_Element type is a "reference" type.}
1266 -- @ExamCom{"Data" is its reference discriminant.}]}
1267
1268 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0268-1]}
1269 @ChgAdded{Version=[3],Text=[@key[function] Find (B : @key[aliased in out] Barrel; Key : String) @key[return] Ref_Element;
1270 -- @Examcom{Return a reference to an element of a barrel.}]}
1271
1272 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1],ARef=[AI05-0299-1]}
1273 @ChgAdded{Version=[3],Text=[B: @key[aliased] Barrel;]}
1274
1275 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1276 @ChgAdded{Version=[3],Text=[...]}
1277
1278 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0268-1]}
1279 @ChgAdded{Version=[3],Text=[Find (B, "grape") := Element'(...); -- @Examcom{Assign through a reference.}]}
1280
1281 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0268-1]}
1282 @ChgAdded{Version=[3],Text=[-- @Examcom{This is equivalent to:}
1283 Find (B, "grape").Data.@key[all] := Element'(...);]}
1284
1285 @end{Example}
1286 @end{Examples}
1287
1288 @begin{Extend2005}
1289 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1290 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}The aspect
1291 Implicit_Dereference and the @nt{generalized_reference} are new.]}
1292 @end{Extend2005}
1293
1294 @begin{Incompatible2012}
1295 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0138-1]}
1296 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
1297 Defined Implicit_Dereference to be nonoveridable, which makes redefinitions
1298 and hiding of the aspect illegal. It's possible that some program could
1299 violate one of these new restrictions, but this is not very likely as
1300 reference types are not likely to be used in a hierarchy.]}
1301 @end{Incompatible2012}
1302
1303
1304 @LabeledAddedSubClause{Version=[3],Name=[User-Defined Indexing]}
1305
1306 @begin{StaticSem}
1307
1308 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1309 @ChgAdded{Version=[3],Type=[Leading],Text=[Given a tagged type @i<T>,
1310 the following type-related, operational aspects
1311 may be specified:]}
1312
1313 @begin{Description}
1314 @ChgRef{Version=[3],Kind=[AddedNormal]}
1315 @ChgAdded{Version=[3],Text=[Constant_Indexing@\This aspect shall be specified by
1316 a @nt{name} that denotes one or more functions declared immediately within the
1317 same declaration list in which @i<T> is declared. All such functions shall
1318 have at least two parameters, the first of which is of type @i<T> or
1319 @i<T>'Class, or is an access-to-constant parameter with designated type @i<T> or
1320 @i<T>'Class.@AspectDefn{Constant_Indexing}]}
1321
1322 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Constant_Indexing],
1323 Text=[@ChgAdded{Version=[3],Text=[Defines function(s) to implement
1324 user-defined @nt{indexed_component}s.]}]}
1325
1326 @ChgRef{Version=[3],Kind=[AddedNormal]}
1327 @ChgAdded{Version=[3],Text=[Variable_Indexing@\This aspect shall be specified
1328 by a @nt{name} that denotes one or more functions declared immediately within
1329 the same declaration list in which @i<T> is declared. All such functions
1330 shall have at least two parameters, the first of which is of type @i<T> or
1331 @i<T>'Class, or is an access parameter with designated type @i<T> or @i<T>'Class.
1332 All such functions shall have a return type that is a reference
1333 type (see @RefSecNum{User-Defined References}), whose reference discriminant
1334 is of an access-to-variable type.@AspectDefn{Variable_Indexing}]}
1335 @begin{Reason}
1336 @ChgRef{Version=[3],Kind=[AddedNormal]}
1337 @ChgAdded{Version=[3],Text=[We require these functions to return a reference
1338 type so that the object returned from the function can act like a variable.
1339 We need no similar rule for Constant_Indexing, since all functions return
1340 constant objects.]}
1341 @end{Reason}
1342
1343 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Variable_Indexing],
1344 Text=[@ChgAdded{Version=[3],Text=[Defines function(s) to implement
1345 user-defined @nt{indexed_component}s.]}]}
1346
1347 @end{Description}
1348
1349 @ChgRef{Version=[3],Kind=[AddedNormal]}
1350 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0104-1]}
1351 @ChgAdded{Version=[3],Text=[These aspects are inherited by descendants of @i<T>
1352 (including the class-wide type @i<T>'Class).@Chg{Version=[4],New=[],Old=[
1353 @Redundant[The aspects shall not be overridden, but the functions they denote
1354 may be.]]}]}
1355
1356 @begin{Ramification}
1357 @ChgRef{Version=[3],Kind=[AddedNormal]}
1358 @ChgAdded{Version=[3],Text=[Indexing can be provided for multiple index types
1359 by overloading routines with different parameter profiles. For instance, the
1360 map containers provide indexing on both cursors and keys by providing
1361 pairs of overloaded routines to the Constant_Indexing and Variable_Indexing
1362 aspects.]}
1363 @end{Ramification}
1364
1365 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1366 @ChgAdded{Version=[3],Text=[An @i<indexable container type> is (a view of) a
1367 tagged type with at least one of the aspects Constant_Indexing or
1368 Variable_Indexing specified.@Defn{indexable container type}
1369 An @i<indexable container object> is an object of an indexable container
1370 type.@Defn{indexable container object} @Redundant[A @nt{generalized_indexing} is
1371 a @nt{name} that denotes the result of calling a function named by a
1372 Constant_Indexing or Variable_Indexing aspect.]]}
1373
1374 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Indexable container type>,
1375 Text=<@ChgAdded{Version=[3],Text=[An indexable container type is one that has
1376 user-defined behavior for indexing, via the Constant_Indexing or
1377 Variable_Indexing aspects.]}>}
1378
1379 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0138-1]}
1380 @ChgAdded{Version=[4],Text=[The Constant_Indexing and Variable_Indexing aspects
1381 are nonoverridable (see @RefSecNum{Aspect Specifications}).]}
1382
1383 @begin{Reason}
1384 @ChgRef{Version=[4],Kind=[AddedNormal]}
1385 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0160-1]}
1386 @ChgAdded{Version=[4],Text=[This @Chg{Version=[5],New=[(and the following
1387 @LegalityTitle) ],Old=[]}ensures that all descendants of an
1388 indexable container type have aspects with the same properties. This prevents
1389 generic contract problems with formal derived types.]}
1390
1391 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0104-1],ARef=[AI12-0138-1]}
1392 @ChgAdded{Version=[4],Text=[A nonoverridable aspect allows the replacement
1393 of the implementation of an indexing function and the addition of a
1394 new indexing function for a derived type, but not the removal of an
1395 indexing function. This is necessary so that indexing can be used on
1396 objects of T'Class. So long as the tag of O is that of its nominal
1397 subtype, we do not want T'Class(O)(I) to mean something different
1398 than O(I). Thus we cannot allow a change in the function identified.
1399 As T'Class(O)(I) expands into a dispatching call, we need to ensure that
1400 there is a body for each such function -- but it is OK for that body to be
1401 changed from the original body (that's just normal dispatching).]}
1402 @end{Reason}
1403
1404 @begin{NotIso}
1405 @ChgAdded{Version=[4],Noparanum=[T],
1406 Text=[@Chg{Version=[5],New=[],Old=[@Shrink{@i<Paragraphs 6 through 9
1407 were deleted.>}]}]}@Comment{This message should be
1408 deleted if the paragraphs are ever renumbered. Note that this is under the
1409 wrong heading, so that the heading can also be eliminated.}
1410 @end{NotIso}
1411
1412 @end{StaticSem}
1413
1414 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
1415 @begin{Legality}
1416 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1417 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg],ARef=[AI12-0138-1]}
1418 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0160-1]}
1419 @ChgDeleted{Version=[4],Type=[Leading],Text=[@Chg{Version=[3],New=[The
1420 Constant_Indexing or Variable_Indexing aspect shall not be
1421 specified:],Old=[]}]}@ChgAdded{Version=[5],Text=[If an ancestor of a
1422 type @i<T> is an indexable container type, then any explicit
1423 specification of the Constant_Indexing or Variable_Indexing aspects shall be
1424 confirming; that is, the specified @nt{name} shall match the inherited aspect
1425 (see @RefSecNum{Aspect Specifications}).]}
1426 @begin{Itemize}
1427 @ChgRef{Version=[3],Kind=[AddedNormal]}
1428 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1429 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[on a derived type
1430 if the parent type has the
1431 corresponding aspect specified or inherited; or],Old=[]}]}
1432
1433 @ChgRef{Version=[3],Kind=[AddedNormal]}
1434 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1435 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[on a
1436 @nt{full_type_declaration} if the type has
1437 a tagged partial view.],Old=[]}]}
1438 @end{Itemize}
1439 @begin{NotIso}
1440 @ChgAdded{Version=[5],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 7 through 8
1441 were deleted.>}]}@Comment{This message should be
1442 deleted if the paragraphs are ever renumbered.}
1443 @end{NotIso}
1444
1445 @ChgRef{Version=[3],Kind=[AddedNormal]}
1446 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1447 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0160-1]}
1448 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[@PDefn{generic contract issue}
1449 In addition to the places where @LegalityTitle normally apply
1450 (see @RefSecNum{Generic Instantiation}),
1451 these rules apply also in the private part of an instance of a
1452 generic unit.],Old=[]}]}
1453 @ChgAdded{Version=[5],Text=[@PDefn{generic contract issue}
1454 In addition to the places where @LegalityTitle normally apply
1455 (see @RefSecNum{Generic Instantiation}),
1456 this rule applies also in the private part of an instance of a
1457 generic unit.]}
1458
1459 @begin{Ramification}
1460 @ChgNote{The following notes were moved to @RefSecNum{Aspect Specifications}
1461 along with the rules (now part of the definition of "nonoverridable aspect").}
1462 @ChgRef{Version=[3],Kind=[AddedNormal]}
1463 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1464 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[In order to enforce
1465 these rules without breaking privacy, we cannot allow a tagged private type
1466 to have hidden indexing aspects. There is no problem if the private type
1467 is not tagged (as the indexing aspects cannot be specified on
1468 descendants in that case).],Old=[]}]}
1469
1470 @ChgRef{Version=[3],Kind=[AddedNormal]}
1471 @ChgRef{Version=[4],Kind=[DeletedNoDelMsg]}
1472 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[We don't need
1473 an assume-the-worst rule as deriving from formal tagged types is not
1474 allowed in generic bodies.],Old=[]}]}
1475 @end{Ramification}
1476
1477 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0204-1]}
1478 @ChgAdded{Version=[5],Text=[A @nt{generalized_indexing} is illegal if the
1479 equivalent prefixed view (see below) is illegal.]}
1480 @end{Legality}
1481
1482 @begin{Syntax}
1483
1484 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1485 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<generalized_indexing>,Old=<>}>,
1486 rhs="@Chg{Version=[3],New=<@SynI{indexable_container_object_}@Syn2{prefix} @Syn2{actual_parameter_part}>,Old=<>}"}
1487
1488 @end{Syntax}
1489
1490 @begin{Resolution}
1491
1492 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1493 @ChgAdded{Version=[3],Text=[The expected type for the
1494 @Syni{indexable_container_object_}@nt{prefix} of a @nt{generalized_indexing}
1495 is any indexable container type.@PDefn2{Term=[expected type],
1496 Sec=(@SynI{indexable_container_object_}@nt{prefix})}]}
1497
1498 @begin{Ramification}
1499 @ChgRef{Version=[5],Kind=[AddedNormal]}
1500 @ChgAdded{Version=[5],Text=[A @nt{prefix} can be an @nt{implicit_dereference}
1501 (see @RefSecNum{Names}), so an access-to-@SynI{indexable_container_object}
1502 can be the prefix (English meaning!) of a @nt{generalized_indexing}.]}
1503 @end{Ramification}
1504
1505 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2],ARef=[AI05-0292-1]}
1506 @ChgAdded{Version=[3],Type=[Leading],Text=[If the Constant_Indexing aspect is
1507 specified for the type of the @SynI{indexable_container_object_}@nt{prefix} of a
1508 @nt{generalized_indexing}, then the @nt{generalized_indexing} is interpreted as
1509 a @i<constant indexing> under the following
1510 circumstances:@Defn{constant indexing}@Defn2{Term=[indexing],Sec=[constant]}]}
1511
1512 @begin{Itemize}
1513
1514 @ChgRef{Version=[3],Kind=[AddedNormal]}
1515 @ChgAdded{Version=[3],Text=[when the Variable_Indexing aspect is not specified
1516 for the type of the @SynI{indexable_container_object_}@nt{prefix};]}
1517
1518 @ChgRef{Version=[3],Kind=[AddedNormal]}
1519 @ChgAdded{Version=[3],Text=[when the @SynI{indexable_container_object_}@nt{prefix}
1520 denotes a constant;]}
1521
1522 @ChgRef{Version=[3],Kind=[AddedNormal]}
1523 @ChgAdded{Version=[3],Text=[when the @nt{generalized_indexing} is used within
1524 a @nt{primary} where a @nt{name} denoting a constant is permitted.]}
1525
1526 @begin{Ramification}
1527 @ChgRef{Version=[3],Kind=[AddedNormal]}
1528 @ChgAdded{Version=[3],Text=[This means it is not interpreted as a
1529 constant indexing for the @SynI{variable_}@nt{name} in the LHS of an
1530 assignment (not inside a @nt{primary}), nor for the @nt{name} used
1531 for an @key[out] or @key[in out] parameter (not allowed to be
1532 a constant), nor for the @nt{name} in an object renaming
1533 (not inside a primary), unless
1534 there is no Variable_Indexing aspect defined.]}
1535 @end{Ramification}
1536
1537 @end{Itemize}
1538
1539 @ChgRef{Version=[3],Kind=[AddedNormal]}
1540 @ChgAdded{Version=[3],Text=[Otherwise, the @nt{generalized_indexing} is
1541 interpreted as a
1542 @i{variable indexing}.@Defn{variable indexing}@Defn2{Term=[indexing],Sec=[variable]}]}
1543
1544 @ChgRef{Version=[3],Kind=[AddedNormal]}
1545 @ChgAdded{Version=[3],Text=[When a @nt{generalized_indexing} is interpreted as a
1546 constant (or variable) indexing, it is equivalent to a call on a prefixed view
1547 of one of the functions named by the Constant_Indexing (or Variable_Indexing)
1548 aspect of the type of the @Syni{indexable_container_object_}@nt{prefix} with the given
1549 @nt{actual_parameter_part}, and with the @Syni{indexable_container_object_}@nt{prefix} as
1550 the @nt{prefix} of the prefixed view.]}
1551
1552 @begin{Ramification}
1553 @ChgRef{Version=[3],Kind=[AddedNormal]}
1554 @ChgAdded{Version=[3],Type=[Leading],Text=[In other words, the
1555 @nt{generalized_indexing} is equivalent to:]}
1556
1557 @begin{Example}
1558 @ChgRef{Version=[3],Kind=[AddedNormal]}
1559 @ChgAdded{Version=[3],Text=[@SynI{indexable_container_object_}@nt{prefix}.Indexing @nt{actual_parameter_part}]}
1560 @end{Example}
1561
1562 @ChgRef{Version=[3],Kind=[AddedNormal]}
1563 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
1564 @ChgAdded{Version=[3],Type=[Trailing],Text=[where Indexing is the @nt{name}
1565 specified for the Constant_Indexing or Variable_Indexing
1566 aspect.@Chg{Version=[4],New=[ This equivalence is then resolved in the
1567 normal way; the aspect specifies a @nt{name}, it does not denote
1568 declarations.],Old=[]}]}
1569 @end{Ramification}
1570
1571 @end{Resolution}
1572
1573 @begin{Notes}
1574 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0104-1]}
1575 @ChgAdded{Version=[4],Text=[The Constant_Indexing and Variable_Indexing
1576 aspects cannot be redefined when inherited for a derived type, but the
1577 functions that they denote can be modified by overriding or overloading.]}
1578 @end{Notes}
1579
1580 @begin{Examples}
1581 @begin{Example}
1582
1583 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1],ARef=[AI05-0292-1]}
1584 @ChgAdded{Version=[3],Text=[@key[type] Indexed_Barrel @key[is tagged] ...
1585 @key[with] Variable_Indexing => Find;
1586 -- @Examcom{Indexed_Barrel is an indexable container type,}
1587 -- @Examcom{Find is the generalized indexing operation.}]}
1588
1589 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1590 @ChgAdded{Version=[3],Text=[@key[function] Find (B : @key[aliased in out] Indexed_Barrel; Key : String) @key[return] Ref_Element;
1591 -- @Examcom{Return a reference to an element of a barrel (see @RefSecNum{User-Defined References}).}]}
1592
1593 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1594 @ChgAdded{Version=[3],Text=[IB: @key[aliased] Indexed_Barrel;]}
1595
1596 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0268-1]}
1597 @ChgAdded{Version=[3],Text=[-- @Examcom{All of the following calls are then equivalent:}
1598 Find (IB,"pear").Data.@key[all] := Element'(...); -- @Examcom{Traditional call}
1599 IB.Find ("pear").Data.@key[all] := Element'(...); -- @Examcom{Call of prefixed view}
1600 IB.Find ("pear") := Element'(...); -- @Examcom{Implicit dereference (see @RefSecNum{User-Defined References})}
1601 IB ("pear") := Element'(...); -- @Examcom{Implicit indexing and dereference}
1602 IB ("pear").Data.@key[all] := Element'(...); -- @Examcom{Implicit indexing only}]}
1603
1604 @end{Example}
1605 @end{Examples}
1606
1607 @begin{Extend2005}
1608 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
1609 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Aspects
1610 Constant_Indexing and Variable_Indexing, and the @nt{generalized_indexing}
1611 syntax are new.]}
1612 @end{Extend2005}
1613
1614 @begin{Incompatible2012}
1615 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0160-1]}
1616 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@b<Correction:>
1617 Prevented a derived type from specifying Constant_Indexing if the
1618 ancestor specified Variable_Indexing (and vice versa). This is necessary
1619 to preserve the intent that for an object Obj whose tag is that of its
1620 nominal subtype, T'Class(Obj)(I) always has the same meaning as Obj(I).
1621 Situations like this should be rare in practice; most types will either
1622 define both aspects or neither.]}
1623
1624 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0204-1]}
1625 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@b<Correction:>
1626 Added a rule that a generalized indexing is illegal if the equivalent
1627 prefixed view would be illegal. If the prefixed view would be illegal for
1628 any reason, Ada 2012 would have allowed the generalized indexing while
1629 Ada 202x does not. This violated the principle that a generalized indexing
1630 and the equivalent prefixed view have the same semantics; practically, the
1631 code may not have worked anyway if a compiler implemented generalized
1632 indexing by code expansion into the canonical form. Thus, such code wasn't
1633 practically portable.]}
1634 @end{Incompatible2012}
1635
1636 @begin{DiffWord2012}
1637 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0104-1]}
1638 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Converted confusing and
1639 unnecessary normative wording about "overriding an aspect" into a note.]}
1640
1641 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0138-1]}
1642 @ChgAdded{Version=[4],Text=[@b<Corrigendum:>
1643 Defined Constant_Indexing and Variable_Indexing to be nonoveridable.
1644 This is merely a new description for @LegalityTitle which already applied
1645 to these aspects.]}
1646 @end{DiffWord2012}
1647
1648
1649 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
1650 @LabeledClause{Literals}
1651
1652 @begin{Intro}
1653 @Redundant[@Defn{literal}
1654 A @i(literal) represents a value literally, that is, by means
1655 of notation suited to its kind.]
1656 A literal is either a @nt<numeric_literal>, a @nt<character_literal>,
1657 the literal @key(null), or a @nt<string_literal>.
1658 @IndexSeeAlso{Term=[constant],See=(literal)}
1659 @begin(Discussion)
1660 An enumeration literal that is an @nt<identifier>
1661 rather than a @nt<character_literal> is not considered a @i(literal)
1662 in the above sense, because it involves no special notation
1663 @lquotes@;suited to its kind.@rquotes@;
1664 It might more properly be called an @ntf<enumeration_identifier>,
1665 except for historical reasons.
1666 @end(Discussion)
1667 @end{Intro}
1668
1669 @begin{Resolution}
1670 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]}
1671 @ChgDeleted{Version=[2],Text=[@PDefn2{Term=[expected type],Sec=(null literal)}
1672 The expected type for a literal @key(null) shall be a single
1673 access type.]}
1674 @begin{Discussion}
1675 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
1676 @ChgDeleted{Version=[2],Text=[This new wording ("expected type ... shall be a
1677 single ... type") replaces the old "shall be determinable" stuff. It reflects
1678 an attempt to simplify and unify the description of the rules for resolving
1679 aggregates, literals, type conversions, etc. See
1680 @RefSec{The Context of Overload Resolution} for the details.]}
1681 @end{Discussion}
1682
1683 @PDefn2{Term=[expected type],Sec=(character_literal)}
1684 @PDefn2{Term=[expected profile],Sec=(character_literal)}
1685 For a @nt<name> that consists of a @nt<character_literal>,
1686 either its expected type shall be a single character type, in which case
1687 it is interpreted as a parameterless @nt<function_call> that yields
1688 the corresponding value of the character type,
1689 or its expected profile shall correspond to a parameterless
1690 function with a character result type, in which case it
1691 is interpreted as the name of the corresponding parameterless
1692 function declared as part of the character type's definition
1693 (see @RefSecNum(Enumeration Types)).
1694 In either case, the @nt{character_literal} denotes the
1695 @nt{enumeration_literal_specification}.
1696 @begin{Discussion}
1697 See @RefSecNum(Selected Components) for the resolution rules for a
1698 @nt<selector_name> that is a @nt<character_literal>.
1699 @end{Discussion}
1700
1701 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0325-1],ARef=[AI12-0373-1]}
1702 @PDefn2{Term=[expected type],Sec=(string_literal)}
1703 The expected type for a @nt{primary} that is a @nt<string_literal>
1704 shall be a single string type@Chg{Version=[5],New=[ or a type with a
1705 specified String_Literal aspect (see @RefSecNum{User-Defined Literals}).
1706 In either case, the @nt{string_literal} is interpreted to be of its
1707 expected type. If the expected type of an integer literal is a type with a
1708 specified Integer_Literal aspect (see @RefSecNum{User-Defined Literals}),
1709 the literal is interpreted to@PDefn2{Term=[expected type],Sec=(integer_literal)}
1710 be of its expected type; otherwise it is interpreted to be of type
1711 @i<universal_integer>. If the expected type of a real literal is a type with
1712 a specified Real_Literal aspect (see @RefSecNum{User-Defined Literals}),
1713 it is interpreted to be of its@PDefn2{Term=[expected type],Sec=(real_literal)}
1714 expected type; otherwise, it is interpreted to be of type @i<universal_real>.],Old=[]}.
1715 @end{Resolution}
1716
1717 @begin{Legality}
1718 A @nt{character_literal} that is a @nt<name> shall correspond to a
1719 @nt<defining_character_literal> of the expected type, or
1720 of the result type of the expected profile.
1721
1722 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0295-1],ARef=[AI12-0325-1]}
1723 @Chg{Version=[5],New=[If the expected type for a string_literal is a
1724 string type, then for],Old=[For]} each character
1725 of @Chg{Version=[5],New=[the],Old=[a]}
1726 @nt{string_literal} @Chg{Version=[5],New=[],Old=[with a given expected string
1727 type, ]}there shall be a corresponding @nt<defining_character_literal> of the
1728 component type of the expected string type.
1729
1730 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
1731 @ChgDeleted{Version=[2],Text=[A literal @s<null>@ChgNote{We use @S since this
1732 isn't a nonterminal, and since it is deleted we don't want to fix it.} shall
1733 not be of an anonymous
1734 access type@Redundant[, since such types do not have a null value
1735 (see @RefSecNum{Access Types})].]}
1736 @begin{Reason}
1737 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
1738 @ChgDeleted{Version=[2],Text=[This is a legality rule rather than an overloading
1739 rule, to simplify implementations.]}
1740 @end{Reason}
1741 @end{Legality}
1742
1743 @begin{StaticSem}
1744 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1745 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0373-1]}
1746 @Chg{Version=[5],New=[],Old=[An integer literal is of type @i{universal_integer}.
1747 A real literal is of type @i{universal_real}.]}@Chg{Version=[2],New=[@Chg{Version=[5],New=[],Old=[ ]}The literal
1748 @key<null> is of type @i<universal_access>.@Chg{Version=[3],
1749 New=[@PDefn{universal_integer}@PDefn{universal_real}@PDefn{universal_access}],Old=[]}],Old=[]}
1750 @end{StaticSem}
1751
1752 @begin{RunTime}
1753 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0249-1]}
1754 @PDefn2{Term=[evaluation], Sec=(numeric literal)}
1755 @PDefn2{Term=[evaluation], Sec=(null literal)}
1756 @Defn{null access value}
1757 @IndexSee{Term=[null pointer],See=(null access value)}
1758 @Chg{Version=[5],New=[If its expected type is a numeric type, the],Old=[The]}
1759 evaluation of a numeric literal@Chg{Version=[5],New=[],Old=[, or the literal
1760 @key(null),]} yields the represented value.@Chg{Version=[5],New=[ @Redundant[In
1761 other cases, the effect of evaluating a numeric literal is determined by the
1762 Integer_Literal or Real_Literal aspect that applies
1763 (see @RefSecNum{User-Defined Literals}).]],Old=[]}
1764
1765 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0249-1]}
1766 @ChgAdded{Version=[5],Text=[The evaluation
1767 of the literal @key(null) yields the null value of the
1768 expected type.]}
1769
1770 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0295-1],ARef=[AI12-0325-1]}
1771 @PDefn2{Term=[evaluation], Sec=(string_literal)}
1772 The evaluation of a @nt{string_literal} that is a @nt<primary>
1773 @Chg{Version=[5],New=[and has an expected type that is a string
1774 type, ],Old=[]}yields
1775 an array value containing the value of each character of the
1776 sequence of characters of the @nt<string_literal>,
1777 as defined in @RefSecNum{String Literals}.
1778 The bounds of this array value are determined according to the rules for
1779 @nt<positional_array_aggregate>s (see @RefSecNum{Array Aggregates}),
1780 except that for a null string literal, the upper bound is the predecessor
1781 of the lower bound.@Chg{Version=[5],New=[ @Redundant[In
1782 other cases, the effect of evaluating a @nt{string_literal} is determined
1783 by the String_Literal aspect that applies
1784 (see @RefSecNum{User-Defined Literals}).]],Old=[]}
1785
1786 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0295-1],ARef=[AI12-0325-1]}
1787 @IndexCheck{Range_Check}
1788 For the evaluation of a @nt<string_literal> of
1789 @Chg{Version=[5],New=[a string ],Old=[]}type @i(T),
1790 a check is made that the value of each
1791 character of the @nt<string_literal> belongs to the component
1792 subtype of @i(T).
1793 For the evaluation of a null string literal@Chg{Version=[5],New=[ of a string
1794 type],Old=[]}, a check is made that its
1795 lower bound is greater than the lower bound of the base range
1796 of the index type.
1797 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
1798 The exception Constraint_Error is raised if either of these checks fails.
1799 @begin{Ramification}
1800 The checks on the characters need not involve more than two
1801 checks altogether, since one need only check the characters
1802 of the string with the
1803 lowest and highest position numbers against the range of the
1804 component subtype.
1805 @end{Ramification}
1806 @end{RunTime}
1807
1808 @begin{Notes}
1809 Enumeration literals that are @nt<identifier>s rather than
1810 @nt<character_literal>s follow the normal rules for @nt<identifier>s
1811 when used in a @nt<name>
1812 (see @RefSecNum{Names} and @RefSecNum{Selected Components}).
1813 @nt<Character_literal>s used as @nt<selector_name>s follow the normal
1814 rules for expanded names (see @RefSecNum{Selected Components}).
1815 @end{Notes}
1816
1817 @begin{Examples}
1818 @Leading@keepnext@i(Examples of literals:)
1819 @begin{Example}
1820 @tabclear()@tabset(P16)
1821 3.14159_26536 @\--@RI[ a real literal]
1822 1_345 @\--@RI[ an integer literal]
1823 'A' @\--@RI[ a character literal]
1824 "Some Text" @\--@RI[ a string literal ]
1825 @end{Example}
1826 @end{Examples}
1827
1828 @begin{Incompatible83}
1829 @Defn{incompatibilities with Ada 83}
1830 Because @nt<character_literal>s are now treated like
1831 other literals, in that they are resolved using context
1832 rather than depending on direct visibility, additional
1833 qualification might be necessary when passing a @nt<character_literal>
1834 to an overloaded subprogram.
1835 @end{Incompatible83}
1836
1837 @begin{Extend83}
1838 @Defn{extensions to Ada 83}
1839 @nt<Character_literal>s are now treated
1840 analogously to @key(null) and @nt<string_literal>s, in that
1841 they are resolved using context, rather than their content;
1842 the declaration of the corresponding @nt<defining_character_literal>
1843 need not be directly visible.
1844 @end{Extend83}
1845
1846 @begin{DiffWord83}
1847 Name Resolution rules for enumeration literals that are not
1848 @nt<character_literal>s are not included anymore, since
1849 they are neither syntactically
1850 nor semantically "literals" but are rather names of parameterless
1851 functions.
1852 @end{DiffWord83}
1853
1854 @begin{Extend95}
1855 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01]}
1856 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@key{Null} now has
1857 type @i<universal_access>, which is similar to other literals. @key{Null}
1858 can be used with anonymous access types.]}
1859 @end{Extend95}
1860
1861 @begin{DiffWord2012}
1862 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0295-1]}
1863 @ChgAdded{Version=[5],Text=[The rules in this subclause are adjusted to allow
1864 for the possibility of user-defined literals. These are fully documented
1865 in the next subclause.]}
1866 @end{DiffWord2012}
1867
1868
1869 @LabeledAddedSubclause{Version=[5],Name=[User-Defined Literals]}
1870
1871 @begin{Intro}
1872 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1]}
1873 @ChgAdded{Version=[5],Text=[Using one or more of the aspects defined below, a
1874 type may be specified to allow the use of one or more kinds of literals as
1875 values of the type.]}
1876 @end{Intro}
1877
1878 @begin{StaticSem}
1879
1880 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0342-1]}
1881 @ChgAdded{Version=[5],Type=[Leading],Text=[The following
1882 type-related operational aspects
1883 (collectively known
1884 as @i<user-defined literal aspects>)@Defn{user-defined literal aspect}
1885 @Defn2{Term={aspect},Sec=[{user-defined literal]}
1886 may be specified for any type @i<T>:]}
1887
1888 @begin{Description}
1889 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0342-1],ARef=[AI12-0373-1]}
1890 @ChgAdded{Version=[5],Text=[Integer_Literal@\This aspect is specified by a
1891 @SynI{function_}@nt{name} that statically denotes a function with a result type
1892 of @i<T> and one @key[in] parameter that is of type String and is
1893 not explictly aliased.@AspectDefn{Integer_Literal}]}
1894
1895 @ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Integer_Literal],
1896 Text=[@ChgAdded{Version=[5],Text=[Defines a function to implement user-defined integer literals.]}]}
1897
1898 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0342-1],ARef=[AI12-0373-1]}
1899 @ChgAdded{Version=[5],Text=[Real_Literal@\This aspect is specified by a
1900 @SynI{function_}@nt{name} that statically denotes a function with a result type
1901 of @i<T> and one @key[in] parameter that is of type String and is
1902 not explictly aliased.@AspectDefn{Real_Literal}]}
1903
1904 @ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Real_Literal],
1905 Text=[@ChgAdded{Version=[5],Text=[Defines a function to implement user-defined real literals.]}]}
1906
1907 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0295-1],ARef=[AI12-0342-1],ARef=[AI12-0373-1]}
1908 @ChgAdded{Version=[5],Text=[String_Literal@\This aspect is specified by a
1909 @SynI{function_}@nt{name} that statically denotes a function with a result type
1910 of @i<T> and one @key[in] parameter that is of type Wide_Wide_String and is
1911 not explictly aliased.@AspectDefn{String_Literal}]}
1912
1913 @ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[String_Literal],
1914 Text=[@ChgAdded{Version=[5],Text=[Defines a function to implement user-defined string literals.]}]}
1915
1916 @end{Description}
1917 @begin{Ramification}
1918 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
1919 @ChgAdded{Version=[5],Type=[Leading],Text=[The following example is legal
1920 because the preceding rules are @ResolutionTitle
1921 (see @RefSecNum{Aspect Specifications}):]}
1922 @begin{Example}
1923 @ChgRef{Version=[5],Kind=[AddedNormal]}
1924 @ChgAdded{Version=[5],Text=[@key[package] Pkg1 @key[is]
1925 @key[type] T @key[is record] X, Y : Integer; @key[end record]
1926 @key[with] Integer_Literal => Int_Lit;
1927 @key[function] Int_Lit (X, Y : T) @key[return] Duration; -- @Examcom{Wrong profile.}
1928 @key[function] Int_Lit (Lit_Image : String) @key[return] T; -- @Examcom{Right profile.}
1929 @key[end] Pkg1;]}
1930 @end{Example}
1931 @end{Ramification}
1932
1933 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
1934 @ChgAdded{Version=[5],Text=[User-defined literal aspects are inherited according
1935 to the rules given in @RefSecNum{Operational and Representation Aspects}.]}
1936
1937 @begin{Discussion}
1938 @ChgRef{Version=[5],Kind=[AddedNormal]}
1939 @ChgAdded{Version=[5],Type=[Leading],Text=[This means that in this example]}
1940
1941 @begin{Example}
1942 @ChgRef{Version=[5],Kind=[AddedNormal]}
1943 @ChgAdded{Version=[5],Text=[@key[package] Pkg2 @key[is]
1944 @key[type T1 is record]
1945 X, Y : Integer;
1946 @key[end record with] Integer_Literal => I_L;]}
1947
1948 @ChgRef{Version=[5],Kind=[AddedNormal]}
1949 @ChgAdded{Version=[5],Text=[ @key[function] I_L (S : String) @key[return] T1 @key[is] ((0, 0));]}
1950
1951 @ChgRef{Version=[5],Kind=[AddedNormal]}
1952 @ChgAdded{Version=[5],Text=[ @key[type] T2 @key[is new] T1;
1953 @key[function] I_L (S : String) @key[return] T2 is ((1, 1));
1954 X : T2 := 123;
1955 @key[end] Pkg2;]}
1956 @end{Example}
1957
1958 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
1959 @ChgAdded{Version=[5],Type=[Trailing],Text=[the initial value of Pkg.X
1960 is (0,0), not (1,1).]}
1961 @end{Discussion}
1962
1963 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
1964 @ChgAdded{Version=[5],Text=[When a numeric literal is interpreted as a value of
1965 a non-numeric type @i<T> or a @nt{string_literal} is interpreted a value of
1966 a type @i<T> that is not a string type (see @RefSecNum{Literals}), it is
1967 equivalent to a call to the subprogram denoted by the corresponding aspect of
1968 @i<T>: the Integer_Literal aspect for an integer literal, the Real_Literal
1969 aspect for a real literal, and the String_Literal aspect for a
1970 @nt{string_literal}. The actual parameter of this notional call is a
1971 @nt{string_literal} having the textual representation of the original (numeric
1972 or string) literal.]}
1973
1974 @begin{Discussion}
1975 @ChgRef{Version=[5],Kind=[AddedNormal]}
1976 @ChgAdded{Version=[5],Text=[This equivalence defines, for example, the nominal
1977 type, the nominal subtype, and the accessibility level of a user-defined
1978 literal. It also has the consequence that a user-defined literal shall not be
1979 of an abstract type (because that would be equivalent to a nondispatching call
1980 to an abstract function). This equivalence also defines the @RunTimeTitle
1981 of evaluating a user-defined literal.]}
1982
1983 @ChgRef{Version=[5],Kind=[AddedNormal]}
1984 @ChgAdded{Version=[5],Text=[The (sub)type of the actual parameter to this call
1985 is determined by the profile of the appropriate aspect, and the bounds of the
1986 @nt{string_literal} are defined by the usual rules for the bounds of a
1987 @nt{string_literal}.]}
1988 @end{Discussion}
1989
1990 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
1991 @ChgAdded{Version=[5],Text=[Such a literal is said to be a
1992 @i<user-defined literal>.@Defn{user-defined literal}]}
1993
1994 @end{StaticSem}
1995
1996 @begin{Legality}
1997 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0295-1],ARef=[AI12-0325-1],ARef=[AI12-0342-1]}
1998 @ChgAdded{Version=[5],Text=[The Integer_Literal or Real_Literal aspect shall not
1999 be specified for a type @i<T> if the full view of @i<T> is a numeric type.
2000 The String_Literal aspect shall not be specified for a type @i<T> if the
2001 full view of @i<T> is a string type.]}
2002
2003 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
2004 @ChgAdded{Version=[5],Text=[For a nonabstract type, the function directly
2005 specified for a user-defined literal aspect shall not be abstract.]}
2006
2007 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
2008 @ChgAdded{Version=[5],Text=[For a tagged type with a partial view, a
2009 user-defined literal aspect shall not be directly specified on the full type.]}
2010
2011 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]}
2012 @ChgAdded{Version=[5],Text=[If a nonabstract tagged type inherits any
2013 user-defined literal aspect, then each inherited aspect shall be directly
2014 specified as a nonabstract function for the type unless the inherited aspect
2015 denotes a nonabstract function and the type is a null extension.]}
2016
2017 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0342-1]}
2018 @ChgAdded{Version=[5],Text=[In addition to the places where @LegalityTitle
2019 normally apply (see @RefSecNum{Generic Instantiation}), these rules also apply
2020 in the private part of an instance of a generic unit.@PDefn{generic contract issue}]}
2021
2022 @end{Legality}
2023
2024 @begin{Bounded}
2025 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0325-1],ARef=[AI12-0342-1]}
2026 @ChgAdded{Version=[5],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}It
2027 is a bounded error if the evaluation of a literal that has an expected
2028 type with a specified user-defined literal aspect propagates an exception.
2029 Either Program_Error or the exception
2030 propagated by the evaluation is raised at the point of use of the value
2031 of the literal. If it is recognized prior to run time that evaluation
2032 of such a literal will inevitably (if executed) result in such a
2033 bounded error, then this may be reported as an error prior to run
2034 time.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
2035
2036 @begin{ImplNote}
2037 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1]}
2038 @ChgAdded{Version=[5],Text=[As always, an implementation may apply "as-if"
2039 optimizations (those that result in the same external effects in the absence
2040 of erroneous execution) to the function calls associated with user-defined
2041 literals. In particular, if the function associated with a user-defined
2042 literal aspect has a Global aspect that indicates no references to global
2043 variables, then a number of optimizations are available to the
2044 implementation:]}
2045 @begin{Itemize}
2046 @ChgRef{Version=[5],Kind=[AddedNormal]}
2047 @ChgAdded{Version=[5],Text=[The implementation can evaluate a user-defined
2048 literal function at compile-time if it has access to the body of the
2049 function (for example, if it is inlined), and that body doesn't reference
2050 anything evaluated at runtime. If the compile-time evaluation results in an
2051 exception, this bounded error allows the compilation unit to be rejected.]}
2052
2053 @ChgRef{Version=[5],Kind=[AddedNormal]}
2054 @ChgAdded{Version=[5],Text=[Implementations can use existing permissions
2055 (see @RefSecNum{The Global and Global'Class Aspects}) to avoid evaluating
2056 the function associated with a user-defined literal more than once for a
2057 particular literal value. This evaluation can be "hoisted" (done once per
2058 compilation unit during the elaboration of the unit) if the compiler can
2059 prove that the function doesn't depend on any constants or locals with a
2060 runtime value not yet elaborated.]}
2061
2062 @ChgRef{Version=[5],Kind=[AddedNormal]}
2063 @ChgAdded{Version=[5],Text=[If the literal value is not needed by the
2064 execution of the program, the function call can be omitted even if it might
2065 have side-effects (again, see @RefSecNum{The Global and Global'Class Aspects}).]}
2066 @end{Itemize}
2067 @end{ImplNote}
2068 @end{Bounded}
2069
2070 @begin{Examples}
2071 @begin{Example}
2072 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
2073 @ChgAdded{Version=[5],Text=[@key[subtype] Roman_Character @key[is] Character
2074 @key[with] Static_Predicate =>
2075 Roman_Character @key[in] 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M';]}
2076
2077 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
2078 @ChgAdded{Version=[5],Text=[Max_Roman_Number : @key[constant] := 3_999; --@Examcom{ MMMCMXCIX}]}
2079
2080 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
2081 @ChgAdded{Version=[5],Text=[@key[type] Roman_Number @key[is] @key[range] 1 .. Max_Roman_Number
2082 @key[with] String_Literal => To_Roman_Number;]}
2083
2084 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
2085 @ChgAdded{Version=[5],Text=[@key[function] To_Roman_Number (S : String) @key[return] Roman_Number
2086 @key[with] Pre => S'Length > 0 @key[and then]
2087 (@key[for all] Char @key[of] S => Char @key[in] Roman_Character);]}
2088
2089 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
2090 @ChgAdded{Version=[5],Text={@key[function] To_Roman_Number (S : String) @key[return] Roman_Number @key[is]
2091 (@key[declare]
2092 R : @key[constant array] (Integer @key[range] <>) @key[of] Integer :=
2093 (@key[for] D @key[in] S'Range => Roman_Digit'Enum_Rep
2094 (Roman_Digit'Value (''' & S(D) & '''))); --@Examcom{ See @RefSecNum{Character Types} and @RefSecNum{Enumeration Representation Clauses}}
2095 @key[begin]
2096 [@key[for] I @key[in] R'Range =>
2097 (@key[if] I < R'Last @key[and then] R(I) < R(I + 1) @key[then] -1 @key[else] 1) * R(I))]
2098 'Reduce("+", 0)
2099 );}}
2100
2101 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
2102 @ChgAdded{Version=[5],Text=[X : Roman_Number := "III" * "IV" * "XII"; --@Examcom{ 144 (that is, CXLIV)}]}
2103
2104
2105 @end{Example}
2106 @end{Examples}
2107
2108 @begin{Extend2012}
2109 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0249-1],ARef=[AI12-0295-1],ARef=[AI12-0325-1],ARef=[AI12-0342-1]}
2110 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}The user-defined
2111 literal aspects Integer_Literal, Real_Literal, and String_Literal are new.]}
2112 @end{Extend2012}
2113
2114
2115 @LabeledClause{Aggregates}
2116
2117 @begin{Intro}
2118 @Redundant[@Defn{aggregate}
2119 An @i(aggregate) combines component values
2120 into a composite value of an array type, record type, or record extension.]
2121 @IndexSeeAlso{Term={literal},See=(aggregate)}
2122
2123 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Aggregate>,
2124 Text=<@ChgAdded{Version=[5],Text=[A construct used to define a value of
2125 a composite type by specifying the values of the components of the
2126 type.]}>}
2127 @end{Intro}
2128
2129 @begin{Syntax}
2130 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1],ARef=[AI12-0212-1]}
2131 @Syn{lhs=<aggregate>,rhs="@Chg<Version=[5],New=[
2132 ],Old=[]>@Syn2{record_aggregate} | @Syn2{extension_aggregate} | @Syn2{array_aggregate}@Chg<Version=[5],New=[
2133 | @Syn2{delta_aggregate} | @Syn2{container_aggregate}],Old=[]>"}
2134 @end{Syntax}
2135
2136 @begin{Resolution}
2137 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2138 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1],ARef=[AI12-0212-1],ARef=[AI12-0307-1]}
2139 @PDefn2{Term=[expected type],Sec=(aggregate)}
2140 The expected type for an @nt{aggregate} shall be a single
2141 @Chg{Version=[2],New=[],Old=[nonlimited ]}array type,
2142 @Chg{Version=[5],New=[a single type with the Aggregate aspect specified,
2143 or a single descendant of a ],Old=[]}record type@Chg{Version=[5],New=[],Old=[,]} or
2144 @Chg{Version=[5],New=[of a ],Old=[]}record extension.
2145 @begin{Discussion}
2146 See @RefSec{The Context of Overload Resolution}
2147 for the meaning of @lquotes@;shall be a single ... type.@rquotes@;
2148 @end{Discussion}
2149 @begin{Ramification}
2150 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2151 @ChgAdded{Version=[3],Text=[There are additional rules for each kind of
2152 aggregate. These aggregate rules are additive; a legal expression needs to
2153 satisfy all of the applicable rules. That means the rule given here must be
2154 satisfied even when it is syntactically possible to tell which specific kind
2155 of aggregate is being used.]}
2156 @end{Ramification}
2157 @begin{Reason}
2158 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0212-1],ARef=[AI12-0307-1]}
2159 @ChgAdded{Version=[5],Text=[Generally, we don't want to look in
2160 @nt{aggregate}s to resolve them. For instance, Ada 95 allowed array types
2161 to match @nt{extension_aggregate}s, even though those have to be record
2162 types. Thus, we allow any record type with any visible
2163 (nondiscriminant) components to match an @nt{aggregate}, even though
2164 only @nt{delta_aggregate}s allow private types or extensions. Similarly,
2165 we allow any container type to match an @nt{aggregate}, even though
2166 only @nt{container_aggregate}s allow container types. ]}
2167 @end{Reason}
2168 @end{Resolution}
2169
2170 @begin{Legality}
2171 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1]}
2172 @Chg{Version=[5],New=[A @nt{record_aggregate} or
2173 @nt{extension_aggregate}],Old=[An @nt{aggregate}]}
2174 shall not be of a class-wide type.
2175 @begin{Ramification}
2176 When the
2177 expected type in some context is class-wide, an aggregate has to
2178 be explicitly qualified by the specific type of value to be created,
2179 so that the expected type for the aggregate itself is specific.
2180 @end{Ramification}
2181 @begin{Discussion}
2182 We used to disallow @nt<aggregate>s of a type with unknown
2183 discriminants. However, that was unnecessarily restrictive
2184 in the case of an extension aggregate, and irrelevant to
2185 a record aggregate (since a type that is legal for a record
2186 aggregate could not possibly have unknown discriminants) and
2187 to an array aggregate (the only specific types that can
2188 have unknown discriminants are private types, private extensions,
2189 and types derived from them).
2190 @end{Discussion}
2191 @begin{Reason}
2192 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
2193 @ChgAdded{Version=[5],Text=[We don't mention @nt{delta_aggregate}s, as those
2194 can get the specific type from the object represented by the
2195 @Syni{base_}@nt{expression} (possibly at run time). We don't mention
2196 @nt{array_aggregate}s, as those cannot even be of a tagged type, so
2197 being class-wide is impossible.]}
2198 @end{Reason}
2199
2200 @end{Legality}
2201
2202 @begin{RunTime}
2203 @PDefn2{Term=[evaluation], Sec=(aggregate)}
2204 For the evaluation of an @nt<aggregate>, an anonymous object
2205 is created and values for the components or ancestor part
2206 are obtained (as described in the subsequent subclause for each
2207 kind of the @nt<aggregate>) and assigned into the corresponding
2208 components or ancestor part of the anonymous object.
2209 @Defn2{Term=[assignment operation],
2210 Sec=(during evaluation of an @nt{aggregate})}
2211 Obtaining the values and the assignments occur in an
2212 arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
2213 The value of the @nt{aggregate} is the value of this object.
2214 @begin{Discussion}
2215 The ancestor part is the set of components inherited from the
2216 ancestor type. The syntactic category @nt<ancestor_part> is
2217 the @nt<expression> or @nt<subtype_mark> that specifies
2218 how the ancestor part of the anonymous object should be initialized.
2219 @end{Discussion}
2220 @begin{Ramification}
2221 The assignment operations do the necessary
2222 value adjustment, as described in
2223 @RefSecNum{Assignment and Finalization}.
2224 Note that the value as a whole is not adjusted
2225 @em just the subcomponents (and ancestor part, if any).
2226 @RefSecNum{Assignment and Finalization} also describes
2227 when this anonymous object is finalized.
2228
2229 If the @nt<ancestor_part> is a @nt<subtype_mark>
2230 the Initialize procedure for the ancestor type is applied
2231 to the ancestor part after default-initializing it,
2232 unless the procedure is abstract, as described
2233 in @RefSecNum{Assignment and Finalization}.
2234 The Adjust procedure for the ancestor type is not called
2235 in this case, since there is no assignment to the ancestor
2236 part as a whole.
2237 @end{Ramification}
2238
2239 @IndexCheck{Discriminant_Check}
2240 If an @nt{aggregate} is of a tagged type, a check is made that
2241 its value belongs to the first subtype of the type.
2242 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
2243 Constraint_Error is raised if this check fails.
2244 @begin{Ramification}
2245 This check ensures that no values of a tagged type are
2246 ever outside the first subtype, as required
2247 for inherited dispatching operations to work properly
2248 (see @RefSecNum(Derived Types and Classes)). This check will always
2249 succeed if the first subtype is unconstrained.
2250 This check is not extended to untagged types
2251 to preserve upward compatibility.
2252 @end{Ramification}
2253 @end{RunTime}
2254
2255 @begin{Extend83}
2256 @Defn{extensions to Ada 83}
2257 We now allow @nt{extension_aggregate}s.
2258 @end{Extend83}
2259
2260 @begin{DiffWord83}
2261 We have adopted new wording
2262 for expressing the
2263 rule that the type of an aggregate shall be determinable
2264 from the outside, though using the fact that
2265 it is nonlimited record (extension) or array.
2266
2267 An @nt{aggregate} now creates an anonymous object.
2268 This is necessary so that controlled types
2269 will work (see @RefSecNum{Assignment and Finalization}).
2270 @end{DiffWord83}
2271
2272 @begin{Incompatible95}
2273 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2274 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95}
2275 In Ada 95, a limited type is not considered when resolving an @nt{aggregate}.
2276 Since Ada 2005 now allows limited @nt{aggregate}s, we can have
2277 incompatibilities. For example:]}
2278 @begin{Example}
2279 @ChgRef{Version=[2],Kind=[AddedNormal]}
2280 @Chg{Version=[2],New=[@key{type} Lim @key{is} @key{limited}
2281 @key{record}
2282 Comp: Integer;
2283 @key{end} @key{record};],Old=[]}
2284
2285 @ChgRef{Version=[2],Kind=[AddedNormal]}
2286 @Chg{Version=[2],New=[@key{type} Not_Lim @key{is}
2287 @key{record}
2288 Comp: Integer;
2289 @key{end} @key{record};],Old=[]}
2290
2291 @ChgRef{Version=[2],Kind=[AddedNormal]}
2292 @Chg{Version=[2],New=[@key{procedure} P(X: Lim);
2293 @key{procedure} P(X: Not_Lim);],Old=[]}
2294
2295 @ChgRef{Version=[2],Kind=[AddedNormal]}
2296 @ChgAdded{Version=[2],Text=[P((Comp => 123)); -- @RI[Illegal in Ada 2005, legal in Ada 95]]}
2297 @end{Example}
2298
2299 @ChgRef{Version=[2],Kind=[AddedNormal]} @ChgAdded{Version=[2],Text=[The call
2300 to P is ambiguous in Ada 2005, while it would not be ambiguous in Ada 95 as
2301 the @nt{aggregate} could not have a limited type. Qualifying the
2302 @nt{aggregate} will eliminate any ambiguity. This construction would be
2303 rather confusing to a maintenance programmer, so it should be avoided, and
2304 thus we expect it to be rare.]}
2305 @end{Incompatible95}
2306
2307 @begin{Extend95}
2308 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2309 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@nt{Aggregate}s can
2310 be of a limited type.]}
2311 @end{Extend95}
2312
2313 @begin{Incompatible2012}
2314 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0212-1]}
2315 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}
2316 We now allow types with the Aggregate aspect specified ("container types"),
2317 as well as private types and extensions descended from a record type or
2318 extension, to match all forms of @nt{aggregate}. These types are only allowed
2319 for new types of @nt{aggregate} (@nt{container_aggregate}s for the Aggregate
2320 aspect, and @nt{delta_aggregate}s for private types), but, consistent with
2321 other forms of @nt{aggregate}, we do not look at the form of the
2322 @nt{aggregate} to determine resolution. This can be incompatible in unlikely
2323 cases, where overloading of a container or private type with a type that
2324 was previously allowed in @nt{aggregate}s makes an existing call ambiguous.
2325 (For an example, replace type Lim in the example given above under
2326 @Incompatible95Title with a Vector from an instance of
2327 Ada.Containers.Vector. The call of P in that case will be illegal in Ada 202x
2328 and legal in Ada 2012.) This can easily be fixed by qualifying the
2329 @nt{aggregate} with the correct type.]}
2330 @end{Incompatible2012}
2331
2332
2333 @LabeledSubClause{Record Aggregates}
2334
2335 @begin{Intro}
2336 @Redundant[In a @nt<record_aggregate>, a value is specified for
2337 each component of the record or record extension value,
2338 using either a named or a positional association.]
2339 @end{Intro}
2340
2341 @begin{Syntax}
2342 @Syn{lhs=<record_aggregate>,rhs="(@Syn2{record_component_association_list})"}
2343
2344 @Syn{lhs=<record_component_association_list>,rhs="
2345 @Syn2{record_component_association} {, @Syn2{record_component_association}}
2346 | @key<null record>"}
2347
2348
2349 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2350 @Syn{lhs=<record_component_association>,rhs="
2351 [@Syn2{component_choice_list} =>] @Syn2{expression}@Chg{Version=[2],New=[
2352 | @Syn2{component_choice_list} => <>],Old=[]}"}
2353
2354 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0212-1]}
2355 @Syn{lhs=<component_choice_list>,rhs="
2356 @SynI{component_}@Syn2{selector_name} {@Chg{Version=[5],New=['|'],Old=[|]} @SynI{component_}@Syn2{selector_name}}
2357 | @key{others}"}
2358
2359 @begin(SyntaxText)
2360 @Defn{named component association}
2361 A @nt<record_@!component_@!association> is a @i(named component association)
2362 if it has a @nt<component_choice_list>;
2363 @Defn{positional component association}
2364 otherwise, it is a @i(positional component association).
2365 Any positional component associations shall precede any
2366 named component associations.
2367 If there is a named association with a @nt<component_choice_list>
2368 of @key(others), it shall come last.
2369 @begin{Discussion}
2370 These rules were
2371 implied by the BNF in an early version of the RM9X, but it
2372 made the grammar harder to read, and was inconsistent
2373 with how we handle discriminant constraints.
2374 Note that for array aggregates we still express
2375 some of the rules in the grammar, but array aggregates
2376 are significantly different because an array aggregate
2377 is either all positional (with a possible @key(others) at the
2378 end), or all named.
2379 @end{Discussion}
2380
2381 In the @nt<record_@!component_@!association_@!list> for a @nt<record_@!aggregate>,
2382 if there is only one association, it shall be a named association.
2383 @begin{Reason}
2384 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2385 Otherwise@Chg{Version=[3],New=[,],Old=[]} the construct would be interpreted
2386 as a parenthesized expression.
2387 This is considered a syntax rule, since it is relevant to
2388 overload resolution. We choose not to express it with BNF so we
2389 can share the definition of @nt<record_component_association_list>
2390 in both @nt<record_aggregate> and @nt<extension_aggregate>.
2391 @end{Reason}
2392 @begin{Ramification}
2393 The @nt<record_component_association_list> of an @nt<extension_aggregate>
2394 does not have such a restriction.
2395 @end{Ramification}
2396 @end(SyntaxText)
2397 @end{Syntax}
2398
2399 @begin{Resolution}
2400 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2401 @PDefn2{Term=[expected type],Sec=(record_aggregate)}
2402 The expected type for a @nt{record_aggregate} shall be
2403 a single @Chg{Version=[2],New=[],Old=[nonlimited ]}record
2404 type or record extension.
2405 @begin{Ramification}
2406 This rule is used to resolve whether an @nt{aggregate} is
2407 an @nt{array_aggregate} or a @nt{record_aggregate}.
2408 The presence of a @key(with) is used to resolve between
2409 a @nt{record_aggregate} and an @nt{extension_aggregate}.
2410 @end{Ramification}
2411
2412 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1]}
2413 @Defn2{Term=[needed component],
2414 Sec=(@nt<record_aggregate> @nt<record_component_association_list>)}
2415 For the @nt<record_@!component_@!association_@!list>
2416 of a @nt<record_@!aggregate>,
2417 all components of the composite value defined by
2418 the aggregate are @i(needed)@Redundant[; for the association list of
2419 an @nt<extension_aggregate>,
2420 only those components not determined by the ancestor expression or
2421 subtype are needed
2422 (see @RefSecNum{Extension Aggregates}).]
2423 Each @Chg{Version=[5],New=[@Syni<component_>@nt{selector_@!name}],
2424 Old=[@nt{selector_@!name}]} in a
2425 @nt{record_@!component_@!association}@Chg{Version=[5],New=[
2426 of a @nt{record_aggregate} or @nt{extension_aggregate}],Old=[]} shall denote
2427 a needed component @Redundant[(including possibly a
2428 discriminant)].@Chg{Version=[5],New=[ Each @Syni{component_}@nt{selector_name}
2429 in a @nt{record_component_association} of a @nt{record_delta_aggregate}
2430 (see @RefSecNum{Delta Aggregates}) shall
2431 denote a nondiscriminant component of the type of the @nt{aggregate}.],Old=[]}
2432
2433 @begin{Ramification}
2434 For the association list of a @nt{record_aggregate},
2435 @lquotes@;needed components@rquotes@; includes every component of the composite value, but
2436 does not include those in unchosen @nt{variant}s (see AI83-309).
2437 If there are @nt<variant>s, then
2438 the value specified for
2439 the discriminant that governs them
2440 determines which @nt<variant> is chosen, and hence which components
2441 are needed.
2442
2443 If an extension defines a new @nt{known_discriminant_part}, then all of
2444 its discriminants are needed in the component association list of an extension
2445 aggregate for that type, even if the discriminants have the same
2446 names and types as discriminants of the type of the ancestor
2447 expression.
2448 This is necessary to ensure that the positions in
2449 the @nt<record_@!component_@!association_@!list>
2450 are well defined, and that discriminants that govern @nt{variant_part}s
2451 can be given by static expressions.
2452 @end{Ramification}
2453
2454 @begin{Reason}
2455 @ChgRef{Version=[5],Kind=[AddedNormal]}
2456 @ChgAdded{Version=[5],Text=[We don't define @ldquote@;needed@rdquote
2457 for @nt{record_delta_aggregate}s so that there is no completeness requirement.
2458 But that means that we need to ensure that the rules using
2459 @ldquote@;needed@rdquote doesn't appear to apply to
2460 @nt{record_delta_aggregate}s, and we also need @LegalityTitle to prevent
2461 giving the same component twice and giving components from two different
2462 variants.]}
2463 @end{Reason}
2464
2465 @Leading@Keepnext@PDefn2{Term=[expected type],
2466 Sec=(record_component_association expression)}
2467 The expected type for the @nt<expression> of a
2468 @nt<record_@!component_@!association> is the type
2469 of the @i(associated) component(s);
2470 @Defn2{Term=[associated components],
2471 Sec=(of a @nt<record_component_association>)}
2472 the associated component(s) are as follows:
2473 @begin(itemize)
2474 For a positional association,
2475 the component @Redundant[(including possibly a discriminant)]
2476 in the corresponding relative position (in the declarative region of
2477 the type), counting only the
2478 needed components;
2479 @begin{Ramification}
2480 This means that for
2481 an association list of an @nt<extension_aggregate>,
2482 only noninherited components are counted to determine
2483 the position.
2484
2485 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2486 @ChgAdded{Version=[3],Text=[For a derived type (including type extensions),
2487 the order of declaration is defined in @RefSec{Derived Types and Classes}.
2488 In particular, all discriminants come first, regardless of whether they are
2489 defined for the parent type or are newly added to the derived type.]}
2490 @end{Ramification}
2491
2492 For a named association with one or more
2493 @i(component_)@nt<selector_name>s,
2494 the named component(s);
2495
2496 For a named association with the reserved word @key(others),
2497 all needed components
2498 that are not associated with some previous association.
2499 @end(itemize)
2500 @end{Resolution}
2501
2502 @begin{Legality}
2503
2504 If the type of a @nt{record_aggregate} is a record extension,
2505 then it shall be a descendant of a record type, through one
2506 or more record extensions (and no private extensions).
2507
2508 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0016-1]}
2509 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1]}
2510 @Chg{Version=[3],New=[@Chg{Version=[5],New=[A @nt{record_component_association_list} shall
2511 be],Old=[The reserved words]} @key[null record] @Chg{Version=[5],New=[only if
2512 the list occurs in a @nt{record_aggregate} or @nt{extension_aggregate}, and],
2513 Old=[only if]}],Old=[If]} there are no components needed
2514 @Chg{Version=[5],New=[for that list],Old=[in a given
2515 @nt<record_@!component_@!association_@!list>@Chg{Version=[3],New=[],Old=[,
2516 then the reserved words @key(null record) shall appear rather
2517 than a list of @nt<record_@!component_@!association>s]}]}.
2518
2519 @begin{Ramification}
2520 For example, "(@key(null record))" is a @nt<record_aggregate>
2521 for a null record type. Similarly, "(T'(A) @key(with null record))" is
2522 an @nt<extension_aggregate> for a type defined as a null
2523 record extension of T.
2524
2525 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0016-1]}
2526 @ChgAdded{Version=[3],Text=[If no components are needed and @key[null record]
2527 is not used, the @nt{record_@!component_@!association} must necessarily be
2528 @key[others] => <>, as that is the only
2529 @nt{record_@!component_@!association} that does not require an associated
2530 component.]}
2531 @end{Ramification}
2532
2533 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2534 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0199-1]}
2535 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0046-1]}
2536 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1]}
2537 @Chg{Version=[5],New=[For a @nt{record_aggregate} or @nt{extension_aggregate},
2538 each],Old=[Each]} @nt<record_component_association>@Chg{Version=[2],New=[ other
2539 than an @key{others} choice with a <>],Old=[]} shall have at least
2540 one associated component, and each needed component
2541 shall be associated with exactly
2542 one @nt<record_@!component_@!association>. @Chg{Version=[5],New=[For a
2543 @nt{record_delta_aggregate}, each @SynI{component_}@nt{selector_name} of each
2544 @nt{component_choice_list} shall denote a distinct nondiscriminant component of
2545 the type of the aggregate.],Old=[
2546 If a @nt<record_@!component_@!association> @Chg{Version=[2],New=[with an
2547 @nt{expression} ],Old=[]}has two or more associated components, all of them
2548 shall be of the same type@Chg{Version=[3],New=[, or all of them shall be of
2549 anonymous access types whose subtypes
2550 statically match],Old=[]}.@Chg{Version=[4],New=[
2551 In addition, @LegalityTitle are enforced separately for each associated
2552 component.],Old=[]}]}
2553
2554 @begin{Ramification}
2555 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2556 These rules apply to an association with an @key(others)
2557 choice@Chg{Version=[2],New=[ with an expression. An @key(others) choice with
2558 a <> can match zero components or several components with different
2559 types],Old=[]}.
2560 @end{Ramification}
2561 @begin{Reason}
2562 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2563 Without these rules, there would be no way to know what
2564 was the expected type for the @nt<expression> of the association.
2565 @Chg{Version=[2],New=[Note that some of the rules do not apply to <>
2566 associations, as we do not need to resolve anything. We allow @key{others}
2567 => <> to match no components as this is similar to array aggregates.
2568 That means that (@key{others} => <>) always represents a default-initialized
2569 record or array value.],Old=[]}
2570 @end{Reason}
2571
2572 @begin{Discussion}
2573 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0046-1]}
2574 @ChgDeleted{Version=[4],Text=[AI83-00244 also requires that the
2575 @nt{expression} shall
2576 be legal for each associated component. This is
2577 because even though two components have the same type, they might have
2578 different subtypes. Therefore, the legality of the
2579 @nt<expression>, particularly if it is an array aggregate,
2580 might differ depending on the associated component's subtype.
2581 However, we have relaxed the rules on array aggregates slightly for Ada 95,
2582 so the staticness of an applicable index constraint has no
2583 effect on the legality of the array aggregate to which it applies.
2584 See @RefSecNum{Array Aggregates}. This was the only case (that we know of)
2585 where a subtype provided by context affected the legality
2586 of an @nt{expression}.]}
2587 @end{Discussion}
2588 @begin{Ramification}
2589 The rule that requires at least one associated component for
2590 each @nt<record_component_association>
2591 implies that there can be no extra associations for
2592 components that don't exist in the composite value, or that
2593 are already determined by the ancestor expression or subtype of
2594 an @nt<extension_aggregate>.
2595
2596 The second part of the first sentence ensures that no
2597 needed components are left out,
2598 nor specified twice.
2599 @end{Ramification}
2600
2601 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0046-1],ARef=[AI12-0127-1]}
2602 @ChgAdded{Version=[5],Text=[If a @nt{record_component_association} with an
2603 @nt{expression} has two or more associated components, all of them shall be of
2604 the same type, or all of them shall be of anonymous access types whose
2605 subtypes statically match. In addition, @LegalityTitle are enforced separately
2606 for each associated component.]}
2607
2608 @begin{Discussion}
2609 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0046-1]}
2610 @ChgAdded{Version=[4],Type=[Leading],Text=[AI83-00244 also requires that the @nt{expression} shall
2611 be legal for each associated component. Ada 95
2612 omitted this wording, as it was thought that all cases of
2613 difference had been eliminated. That probably was true, but Ada 2005
2614 reintroduced cases where the types match but the legality differs.
2615 For example:]}
2616
2617 @begin{Example}
2618 @ChgRef{Version=[4],Kind=[AddedNormal]}
2619 @ChgAdded{Version=[4],Text=[@key[type] Rec (D : @key[access] Integer) @key[is record]
2620 F : @key[access] Integer;
2621 @key[end record];]}
2622
2623 @ChgRef{Version=[4],Kind=[AddedNormal]}
2624 @ChgAdded{Version=[4],Text=[...
2625 X : @key[aliased] Integer;
2626 R : Rec := (D | F => X'Access); -- @examcom<Legal for D, illegal for F>]}
2627 @end{Example}
2628
2629 @ChgRef{Version=[4],Kind=[AddedNormal]}
2630 @ChgAdded{Version=[4],Text=[There are additional ways for this to happen;
2631 because of cases like the above we require that the @LegalityTitle are checked
2632 individually for each associated component.]}
2633 @end{Discussion}
2634
2635 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0220-1]}
2636 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0086-1],ARef=[AI12-0127-1]}
2637 @Chg{Version=[5],New=[For a @nt{record_aggregate} or @nt{extension_aggregate},
2638 if a @nt{variant_part} @i{P} is nested within a
2639 @nt{variant} @i{V} that is not selected by the discriminant value governing
2640 the @nt{variant_part} enclosing @i{V}, then there is no restriction on the
2641 discriminant governing @i{P}. Otherwise, the value of the],
2642 Old=[@Chg{Version=[3],New=[The],Old=[If the components of a @nt{variant_part}
2643 are needed, then the]} value of a]}
2644 discriminant that governs @Chg{Version=[5],New=[],Old=[@Chg{Version=[3],New=[a],Old=[the]}
2645 @nt{variant_part}]}
2646 @Chg{Version=[3],New=[@i<P> ],Old=[]}shall be given by a static
2647 expression@Chg{Version=[3],New=[, ],Old=[]}@Chg{Version=[5],New=[or by a
2648 nonstatic expression having a constrained static nominal subtype. In
2649 this latter case of a nonstatic expression, there shall be exactly one
2650 @nt{discrete_choice_list} of @i{P} that covers each value that belongs to the
2651 nominal subtype and satisfies the predicates of the subtype, and there
2652 shall be at least one such value.],
2653 Old=[@Chg{Version=[3],New=[unless @i<P> is nested within
2654 a @nt{variant} @i<V> that is not selected by the discriminant value
2655 governing the @nt{variant_part} enclosing @i<V>],Old=[]}.]}
2656 @begin{Ramification}
2657 This expression might either be given within the aggregate itself,
2658 or in a constraint on the parent subtype in a @nt<derived_type_definition>
2659 for some ancestor of the type of the aggregate.
2660
2661 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0086-1]}
2662 @ChgAdded{Version=[5],Text=[This means that in the nonstatic value case,
2663 the (static) subtype cannot have a null range.]}
2664 @end{Ramification}
2665
2666 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]}
2667 @ChgAdded{Version=[2],Text=[A @nt<record_component_association> for a discriminant
2668 without a @nt<default_expression> shall have an @nt<expression> rather
2669 than <>.]}
2670 @begin{Reason}
2671 @ChgRef{Version=[2],Kind=[AddedNormal]}
2672 @ChgAdded{Version=[2],Text=[A discriminant must always have a defined value,
2673 but <> means uninitialized for a discrete type unless the component has a
2674 default value.]}
2675 @end{Reason}
2676
2677 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0127-1]}
2678 @ChgAdded{Version=[5],Type=[Leading],Text=[A @nt{record_component_association}
2679 of the @nt{record_component_association_list}
2680 of a @nt{record_delta_aggregate} shall not:]}
2681
2682 @begin{Itemize}
2683
2684 @ChgRef{Version=[5],Kind=[Added]}
2685 @ChgAdded{Version=[5],Text=[use the compound delimiter <> (box) rather than
2686 an @nt{expression};]}
2687
2688 @ChgRef{Version=[5],Kind=[Added]}
2689 @ChgAdded{Version=[5],Text=[have an @nt{expression} of a limited type;]}
2690
2691 @ChgRef{Version=[5],Kind=[Added]}
2692 @ChgAdded{Version=[5],Text=[omit the @nt{component_choice_list}; or]}
2693
2694 @begin{Ramification}
2695 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
2696 @ChgAdded{Version=[5],Text=[A @nt{record_delta_aggregate} cannot use
2697 positional notation; all choices shall be named choices.]}
2698 @end{Ramification}
2699
2700 @ChgRef{Version=[5],Kind=[Added]}
2701 @ChgAdded{Version=[5],Text=[have a @nt{component_choice_list} that is an
2702 @key[others] choice.]}
2703 @end{Itemize}
2704
2705 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0127-1]}
2706 @ChgAdded{Version=[5],Text=[For a @nt{record_delta_aggregate}, no two
2707 @SynI{component_}@nt{selector_name}s shall denote components declared within
2708 different @nt{variant}s of the same @nt{variant_part}.]}
2709
2710 @end{Legality}
2711
2712 @begin{RunTime}
2713 @PDefn2{Term=[evaluation], Sec=(record_aggregate)}
2714 The evaluation of a @nt<record_aggregate> consists of the
2715 evaluation of the @nt<record_@!component_@!association_@!list>.
2716
2717 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0086-1]}
2718 @PDefn2{Term=[evaluation], Sec=(record_component_association_list)}
2719 For the evaluation of a @nt{record_@!component_@!association_@!list},
2720 any per-object constraints (see @RefSecNum(Record Types))
2721 for components specified in the association list are elaborated and
2722 any @nt<expression>s are evaluated and converted to the subtype of the
2723 associated component.
2724 @PDefn2{Term=[implicit subtype conversion],Sec=(expressions in aggregate)}
2725 Any constraint elaborations and @nt{expression} evaluations (and conversions)
2726 occur in an arbitrary order, except that the @nt<expression>
2727 for a discriminant is evaluated (and converted) prior to the
2728 elaboration of any per-object constraint that depends on it, which in
2729 turn occurs prior to the evaluation and conversion of the @nt{expression} for
2730 the component with the per-object
2731 constraint.@PDefn2{Term=[arbitrary order],Sec=[allowed]}@Chg{Version=[5],New=[
2732 If the value of a discriminant that governs a selected @nt{variant_part} @i{P}
2733 is given by a nonstatic @nt{expression}, and the evaluation of that
2734 @nt{expression} yields a value that does not belong to the nominal subtype of
2735 the @nt{expression}, then Constraint_Error is
2736 raised.@Defn2{Term=[Constraint_Error],Sec=(raised by discriminant-dependent aggregate)}],Old=[]}
2737
2738 @begin{Ramification}
2739 The conversion in the first rule might raise Constraint_Error.
2740 @end{Ramification}
2741 @begin{Discussion}
2742 This check in the first rule presumably happened as part of the dependent
2743 compatibility check in Ada 83.
2744 @end{Discussion}
2745 @begin{Ramification}
2746 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0086-1]}
2747 @ChgAdded{Version=[5],Text=[The test on the value of the discriminant
2748 can only fail if the value is outside the base range of its type, does not
2749 satisfy the (static) predicates of the subtype (possible when the predicate
2750 is disabled), or is an invalid representation. This is a rule similar to
2751 that used for case statements. As with case statements, this is not a
2752 @ldquote@;check@rdquote; it cannot be Suppressed.]}
2753 @end{Ramification}
2754
2755 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]}
2756 @ChgAdded{Version=[2],Text=[For a @nt<record_component_association> with an
2757 @nt<expression>, the @nt<expression> defines the value for the associated
2758 component(s). For a @nt<record_component_association> with <>, if the
2759 @nt<component_declaration> has a @nt<default_expression>, that
2760 @nt<default_expression> defines the value for the associated component(s);
2761 otherwise, the associated component(s) are initialized by default as for a
2762 stand-alone object of the component subtype
2763 (see @RefSecNum{Object Declarations}).]}
2764
2765 The @nt<expression> of a @nt{record_component_association}
2766 is evaluated (and converted) once for each associated component.
2767
2768 @begin{Ramification}
2769 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2770 @ChgAdded{Version=[3],Text=[We don't need similar language for <>,
2771 as we're considering the value of <> for each individual component.
2772 Each component has its own default expression or its own
2773 default initialization (they can be different for each component;
2774 the components even could have different types), and each one
2775 has to be evaluated. So there is no need to repeat that.]}
2776 @end{Ramification}
2777
2778 @end{RunTime}
2779
2780 @begin{Notes}
2781 For a @nt<record_aggregate> with positional associations, expressions
2782 specifying discriminant
2783 values appear first since the @nt<known_discriminant_part>
2784 is given first in the declaration of the type; they have to
2785 be in the same order as in the @nt<known_discriminant_part>.
2786 @end{Notes}
2787
2788 @begin{Examples}
2789 @Leading@keepnext@i(Example of a record aggregate with positional associations:)
2790 @begin{Example}
2791 (4, July, 1776) --@RI[ see @RefSecNum{Record Types} ]
2792 @end{Example}
2793
2794 @begin{WideAbove}
2795 @leading@keepnext@i(Examples of record aggregates with named associations:)
2796 @end{WideAbove}
2797 @begin{Example}
2798 (Day => 4, Month => July, Year => 1776)
2799 (Month => July, Day => 4, Year => 1776)
2800
2801 (Disk, Closed, Track => 5, Cylinder => 12) --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}]
2802 (Unit => Disk, Status => Closed, Cylinder => 9, Track => 1)
2803 @end{Example}
2804
2805 @begin{WideAbove}
2806 @leading@keepnext@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2807 @i(@Chg{Version=[2],New=[Examples],Old=[Example]} of component
2808 @Chg{Version=[2],New=[associations],Old=[association]} with
2809 several choices:)
2810 @end{WideAbove}
2811 @begin{Example}
2812 @tabclear()@tabset(P50)
2813 (Value => 0, Succ|Pred => @key(new) Cell'(0, @key(null), @key(null))) @\--@RI[ see @RefSecNum{Incomplete Type Declarations}]
2814
2815 --@RI[ The allocator is evaluated twice: Succ and Pred designate different cells]
2816
2817 @ChgRef{Version=[2],Kind=[Added]}
2818 @Chg{Version=[2],New=[(Value => 0, Succ|Pred => <>) @\--@RI[ see @RefSecNum{Incomplete Type Declarations}]],Old=[]}
2819
2820 @ChgRef{Version=[2],Kind=[Added]}
2821 @Chg{Version=[2],New=[ --@RI[ Succ and Pred will be set to @key{null}]],Old=[]}
2822
2823 @end{Example}
2824
2825 @begin{WideAbove}
2826 @leading@keepnext@i{Examples of record aggregates for tagged types
2827 (see @RefSecNum(Tagged Types and Type Extensions)
2828 and @RefSecNum{Type Extensions}):}
2829 @end{WideAbove}
2830 @begin{Example}
2831 Expression'(@key{null record})
2832 Literal'(Value => 0.0)
2833 Painted_Point'(0.0, Pi/2.0, Paint => Red)
2834 @end{Example}
2835
2836 @end{Examples}
2837
2838 @begin{Extend83}
2839 @Defn{extensions to Ada 83}
2840 Null record aggregates may now be specified, via "(@key(null record))".
2841 However, this syntax is more useful for null record extensions in
2842 extension aggregates.
2843 @end{Extend83}
2844
2845 @begin{DiffWord83}
2846 Various AIs have been incorporated (AI83-00189, AI83-00244, and AI83-00309).
2847 In particular, Ada 83 did not explicitly disallow extra values in
2848 a record aggregate. Now we do.
2849 @end{DiffWord83}
2850
2851 @begin{Extend95}
2852 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2853 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}<> can be used in
2854 place of an @nt{expression} in a @nt{record_aggregate}, default
2855 initializing the component.]}
2856 @end{Extend95}
2857
2858 @begin{DiffWord95}
2859 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2860 @ChgAdded{Version=[2],Text=[Limited @nt{record_aggregate}s are allowed (since
2861 all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]}
2862 @end{DiffWord95}
2863
2864 @begin{Incompatible2005}
2865 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0220-1]}
2866 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2867 Corrected wording so that the rule for discriminants governing @nt{variant_part}s
2868 was not effectively circular. The change makes a few @nt{aggregate}s where a
2869 nonstatic discriminant governs an empty @nt{variant_part} illegal. However,
2870 most Ada implementations already enforce some version of the new rule and
2871 already reject these @nt{aggregate}s. So it is unlikely that any
2872 incompatibility will be noticed in practice.]}
2873 @end{Incompatible2005}
2874
2875 @begin{Extend2005}
2876 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0016-1]}
2877 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:> Fixed the wording so that
2878 @key[others] => <> can be used in place of @key[null record].
2879 This is needed to avoid a generic contract issue for generic bodies:
2880 we do not want to have to assume the worst to disallow @key[others] => <>
2881 if the record type @i{might} be a null record.]}
2882
2883 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0199-1]}
2884 @ChgAdded{Version=[3],Text=[@b<Correction:> We now allow multiple components
2885 with anonymous access types to be specified with a single component
2886 association. This is to be consistent with the capabilities of a named
2887 access type.]}
2888 @end{Extend2005}
2889
2890 @begin{Extend2012}
2891 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0086-1]}
2892 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}The value of a
2893 discriminant that governs a @nt{variant_part} in an @nt{aggregate} can
2894 be nonstatic if the nominal subtype of the discriminant expression
2895 is static and all possible values select a single @nt{variant}.]}
2896 @end{Extend2012}
2897
2898 @begin{DiffWord2012}
2899 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0046-1]}
2900 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> We explicitly say that the
2901 @LegalityTitle have to be rechecked for each component individually.
2902 This @i<seems> obvious, but as the AARM note @RefSecNum{Record Aggregates}
2903 (16.c) appeared to say that this was not necessary, and since we explicitly
2904 state this sort of thing for generic instances, it seemed better to be
2905 explicit.]}
2906
2907 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
2908 @ChgAdded{Version=[5],Text=[Made wording changes for @nt{delta_aggregate}s.]}
2909
2910 @end{DiffWord2012}
2911
2912
2913 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
2914 @LabeledSubClause{Extension Aggregates}
2915
2916 @begin{Intro}
2917 @Redundant[An @nt<extension_aggregate> specifies a value
2918 for a type that is a record extension by specifying a value
2919 or subtype
2920 for an ancestor of the type,
2921 followed by associations for
2922 any components not determined by the @nt<ancestor_part>.]
2923 @end{Intro}
2924
2925 @begin{MetaRules}
2926 The model underlying this syntax is that a record extension
2927 can also be viewed as a regular record type with an ancestor "prefix."
2928 The @nt<record_@!component_@!association_@!list> corresponds to
2929 exactly what would be needed
2930 if there were no ancestor/prefix type.
2931 The @nt{ancestor_part}
2932 determines the value of the ancestor/prefix.
2933 @end{MetaRules}
2934
2935 @begin{Syntax}
2936 @Syn{lhs=<extension_aggregate>,rhs="
2937 (@Syn2{ancestor_part} @key(with) @Syn2{record_component_association_list})"}
2938
2939 @Syn{lhs=<ancestor_part>,
2940 rhs="@Syn2{expression} | @Syn2{subtype_mark}"}
2941 @end{Syntax}
2942
2943 @begin{Resolution}
2944 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
2945 @PDefn2{Term=[expected type], Sec=(extension_aggregate)}
2946 The expected type for an @nt{extension_aggregate} shall be
2947 a single @Chg{Version=[2],New=[],Old=[nonlimited ]}type that is a
2948 record extension.
2949 @PDefn2{Term=[expected type],
2950 Sec=(extension_aggregate ancestor expression)}
2951 If the @nt<ancestor_part> is an @nt<expression>,
2952 it is expected to be of any @Chg{Version=[2],New=[],Old=[nonlimited ]}tagged
2953 type.
2954 @begin{Reason}
2955 We could have made
2956 the expected type @i(T')Class where @i(T) is the ultimate ancestor of
2957 the type of the aggregate, or we could have made it even more
2958 specific than that. However, if the overload resolution rules
2959 get too complicated, the implementation gets more difficult and
2960 it becomes harder to produce good error messages.
2961 @end{Reason}
2962 @begin{Ramification}
2963 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2964 @ChgAdded{Version=[3],Text=[This rule is additive with the rule given in
2965 @RefSecNum{Aggregates}. That means the @RefSecNum{Aggregates} rule must be
2966 satisfied even though it is always syntactically possible to tell that
2967 something is an extension aggregate rather than another kind of aggregate.
2968 Specifically, that means that an extension aggregate is ambiguous if the
2969 context is overloaded on array and/or untagged record types, even though
2970 those are never legal contexts for an extension aggregate. Thus, this rule
2971 acts more like a @LegalityName than a @ResolutionName.]}
2972 @end{Ramification}
2973 @end{Resolution}
2974
2975 @begin{Legality}
2976 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00306-01]}
2977 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0115-1]}
2978 If the @nt<ancestor_part> is a @nt<subtype_mark>, it shall
2979 denote a specific tagged subtype.
2980 @Chg{Version=[2],New=[If the @nt{ancestor_part} is an @nt{expression}, it
2981 shall not be dynamically tagged. ],Old=[]}
2982 The type of the @nt{extension_aggregate} shall be
2983 @Chg{Version=[3],New=[a descendant of],Old=[derived from]} the type of the
2984 @nt<ancestor_part>@Chg{Version=[3],New=[ (the @i<ancestor> type)@Defn2{Term=[ancestor type],
2985 Sec=<of an @nt<extension_aggregate>>}],Old=[]},
2986 through one or more record extensions (and no private
2987 extensions).@Chg{Version=[3],New=[ If the @nt{ancestor_part} is a
2988 @nt{subtype_mark}, the view of the ancestor type from which the type
2989 is descended (see @RefSecNum{Private Operations})
2990 shall not have unknown discriminants.],Old=[]}
2991 @begin{Reason}
2992 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00306-01]}
2993 @ChgAdded{Version=[2],Text=[The expression cannot be dynamically tagged to
2994 prevent implicit "truncation" of a dynamically-tagged value to the specific
2995 ancestor type. This is similar to the
2996 rules in @RefSecNum{Dispatching Operations of Tagged Types}.]}
2997 @end{Reason}
2998
2999 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0067-1],ARef=[AI05-0244-1]}
3000 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0236-1],ARef=[AI12-0317-1]}
3001 @ChgAdded{Version=[3],Text=[If the type of@Comment{Version 3 and 4 need "Type=[Leading]"}
3002 the @nt{ancestor_part} is limited and at least one component is needed
3003 in the @nt{record_component_association_list}, then the @nt{ancestor_part}
3004 shall not @Chg{Version=[5],New=[have an operative constituent expression (see
3005 @RefSecNum{Expressions}) that is a call to a function with an
3006 unconstrained result subtype.],Old=[be:]}]}
3007 @begin{Itemize}
3008 @ChgRef{Version=[3],Kind=[Added]}
3009 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg],ARef=[AI12-0317-1]}
3010 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[a call to a
3011 function with an unconstrained result subtype; nor]}]}
3012
3013 @ChgRef{Version=[3],Kind=[Added]}
3014 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg],ARef=[AI12-0317-1]}
3015 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[a parenthesized
3016 or qualified expression whose operand would violate this rule; nor]}]}
3017
3018 @ChgRef{Version=[3],Kind=[Added]}
3019 @ChgRef{Version=[5],Kind=[DeletedAddedNoDelMsg],ARef=[AI12-0317-1]}
3020 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[a
3021 @nt{conditional_expression} (see
3022 @RefSecNum{Conditional Expressions}) having at least one
3023 @SynI{dependent_}@nt{expression} that would violate this
3024 rule.]}]}
3025 @end{Itemize}
3026 @begin{Reason}
3027 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0067-1],ARef=[AI05-0244-1]}
3028 @ChgAdded{Version=[3],Text=[This restriction simplifies implementation,
3029 because it ensures that either the caller or the callee knows the size to
3030 allocate for the aggregate. Without this restriction, information from both
3031 caller and callee would have to be combined to determine the appropriate
3032 size.]}
3033
3034 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0067-1]}
3035 @ChgAdded{Version=[3],Text=[The (F(...) with null record) case is exempt from
3036 this rule, because such extension
3037 aggregates are created internally for inherited functions returning
3038 null-extension types @em we can't very well make those illegal. Moreover, we
3039 don't need the rule for null extensions, as the result can simply use
3040 the space returned by the function call.]}
3041
3042 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0317-1]}
3043 @ChgAdded{Version=[5],Text=[The mention of @ldquote@;operative
3044 constituents@rdquote means that constructs like parenthesized expressions,
3045 @nt{qualified_expression}s, and @nt{conditional_expression}s are ignored
3046 when enforcing this rule.]}
3047 @end{Reason}
3048 @end{Legality}
3049
3050 @begin{StaticSem}
3051 @Defn2{Term=[needed component],
3052 Sec=(@nt<extension_aggregate> @nt<record_component_association_list>)}
3053 For the @nt{record_@!component_@!association_@!list}
3054 of an @nt{extension_@!aggregate},
3055 the only components @i(needed) are those of the composite value defined
3056 by the aggregate that are not inherited from the type of
3057 the @nt<ancestor_@!part>, plus any inherited discriminants
3058 if the @nt<ancestor_@!part> is a @nt<subtype_@!mark> that
3059 denotes an unconstrained subtype.
3060 @end{StaticSem}
3061
3062 @begin{RunTime}
3063 @PDefn2{Term=[evaluation], Sec=(extension_aggregate)}
3064 For the evaluation of an @nt{extension_aggregate},
3065 the @nt{record_@!component_@!association_@!list} is evaluated.
3066 If the @nt<ancestor_part> is an @nt<expression>, it is also evaluated;
3067 if the @nt<ancestor_part> is a @nt<subtype_mark>,
3068 the components of the value of the aggregate not given by the
3069 @nt<record_@!component_@!association_@!list> are initialized by default
3070 as for an object of the ancestor type.
3071 Any implicit initializations or evaluations are performed
3072 in an arbitrary order, except that the @nt<expression>
3073 for a discriminant is evaluated prior to any other evaluation
3074 or initialization that depends on it.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
3075
3076 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0282-1]}
3077 @IndexCheck{Discriminant_Check}
3078 If the type of the @nt<ancestor_part> has
3079 discriminants @Chg{Version=[3],New=[and],Old=[that are not inherited by the
3080 type of the @nt{extension_aggregate},
3081 then, unless]} the @nt<ancestor_part> is@Chg{Version=[3],New=[ not],Old=[]}
3082 a @nt<subtype_mark> that
3083 denotes an unconstrained subtype,@Chg{Version=[3],New=[ then],Old=[]}
3084 a check is made that each discriminant @Chg{Version=[3],New=[determined by the
3085 @nt{ancestor_part}],Old=[of the ancestor]}
3086 has the value specified for a corresponding discriminant,@Chg{Version=[3],New=[ if any,],Old=[]}
3087 either in the @nt{record_@!component_@!association_@!list}, or in
3088 the @nt<derived_type_definition> for some ancestor of the type of
3089 the @nt{extension_aggregate}.
3090 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
3091 Constraint_Error is raised if this check fails.
3092 @begin{Ramification}
3093 Corresponding and specified
3094 discriminants are defined in @RefSecNum{Discriminants}.
3095 The rules requiring static compatibility between
3096 new discriminants of a derived type
3097 and the parent discriminant(s) they constrain
3098 ensure that at most one check is required per discriminant
3099 of the ancestor expression.
3100
3101 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0282-1]}
3102 @ChgAdded{Version=[3],Text=[The check needs to be made any time that the
3103 ancestor is constrained; the source of the discriminants or the constraints
3104 is irrelevant.]}
3105 @end{Ramification}
3106 @end{RunTime}
3107
3108 @begin{Notes}
3109 If all components of the value of the @nt<extension_aggregate>
3110 are determined by the @nt<ancestor_part>, then
3111 the @nt<record_@!component_@!association_@!list> is required to be
3112 simply @key(null record).
3113
3114 If the @nt<ancestor_part> is a @nt<subtype_mark>,
3115 then its type can be abstract. If its type is controlled,
3116 then as the last step of evaluating the aggregate,
3117 the Initialize procedure of the ancestor type is called,
3118 unless the Initialize procedure is abstract
3119 (see @RefSecNum{Assignment and Finalization}).
3120 @end{Notes}
3121
3122 @begin{Examples}
3123 @Leading@keepnext@i{Examples of extension aggregates (for types defined in @RefSecNum{Type Extensions}):}
3124 @begin(example)
3125 Painted_Point'(Point @key{with} Red)
3126 (Point'(P) @key{with} Paint => Black)
3127
3128 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
3129 (Expression @key{with} Left => @Chg{Version=[5],New=[ @key{new} Literal'(Value => ],Old=[]}1.2@Chg{Version=[5],New=[)],Old=[]},@Chg{Version=[5],New=[
3130 ],Old=[]} Right => @Chg{Version=[5],New=[@key{new} Literal'(Value => ],Old=[]}3.4@Chg{Version=[5],New=[)],Old=[]})
3131 Addition'(Binop @key{with null record})
3132 --@RI[ presuming Binop is of type Binary_Operation]
3133 @end(example)
3134
3135 @end{Examples}
3136
3137 @begin{Extend83}
3138 @Defn{extensions to Ada 83}
3139 The extension aggregate syntax is new.
3140 @end{Extend83}
3141
3142 @begin{Incompatible95}
3143 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00306-01]}
3144 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
3145 @b[Amendment Correction:] Eliminated implicit @lquotes@;truncation@rquotes
3146 of a dynamically tagged value when it is used as an ancestor
3147 @nt{expression}. If an @nt{aggregate} includes such an @nt{expression},
3148 it is illegal in Ada 2005. Such @nt{aggregate}s are thought to be rare;
3149 the problem can be fixed with a type conversion to the appropriate
3150 specific type if it occurs.]}
3151 @end{Incompatible95}
3152
3153 @begin{DiffWord95}
3154 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
3155 @ChgAdded{Version=[2],Text=[Limited @nt{extension_aggregate}s are allowed (since
3156 all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]}
3157 @end{DiffWord95}
3158
3159 @begin{Inconsistent2005}
3160 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0282-1]}
3161 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b[Correction:]
3162 An @nt{extension_aggregate} with an @nt{ancestor_part} whose discriminants
3163 are constrained and inherited might now raise Constraint_Error if the
3164 @nt{aggregate}'s type is constrained, while it was OK in Ada 2005. In almost
3165 all cases, this will make no difference as the constraint will be checked
3166 by the immediately following use of the @nt{aggregate}, but it is possible to
3167 compare such an aggregate for equality;
3168 in this case, no exception would be raised by Ada 2005, while Ada 2012 will
3169 raise Constraint_Error. This should be very rare, and having the possibility
3170 means that the representation of the aggregate type has to be able to support
3171 unconstrained values of the type, even if the first subtype is constrained
3172 and no such objects can be created any other way.]}
3173 @end{Inconsistent2005}
3174
3175 @begin{Incompatible2005}
3176 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0067-1]}
3177 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b[Correction:]
3178 A limited unconstrained ancestor expression that is a function call is now
3179 illegal unless the extension part is null.
3180 Such @nt{aggregate}s were first introduced in Ada 2005 and are very complex
3181 to implement as they must be built-in-place with an unknown size; as such,
3182 it is unlikely that they are implemented correctly in existing compilers and
3183 thus not often used in existing code.]}
3184
3185 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0115-1]}
3186 @ChgAdded{Version=[3],Text=[@b[Correction:] An @nt{ancestor_part} that is a
3187 subtype with unknown discriminants is now explicitly illegal. Such a
3188 subtype should not be used to declare an object, and the @nt{ancestor_part}
3189 acts like an object. The Ada 95 rules did not disallow such cases, so it
3190 is possible that code exists that uses such an ancestor, but this should
3191 be rare.]}
3192 @end{Incompatible2005}
3193
3194
3195 @begin{DiffWord2012}
3196 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0317-1]}
3197 @ChgAdded{Version=[5],Text=[Rewrote a @LegalityName to use the new term
3198 @ldquote@;operative constituent@rdquote in order to reduce duplication of text
3199 about ignoring parenthesized expressions and similar constructs.]}
3200 @end{DiffWord2012}
3201
3202
3203
3204 @LabeledSubClause{Array Aggregates}
3205
3206 @begin{Intro}
3207
3208 @Redundant[In an @nt<array_aggregate>, a value is specified
3209 for each component of an array, either positionally or by
3210 its index.]
3211 For a @nt{positional_array_aggregate},
3212 the components are given in increasing-index order,
3213 with a final @key[others], if any,
3214 representing any remaining components.
3215 For a @nt{named_array_aggregate},
3216 the components are identified by the values covered by the
3217 @nt{discrete_choice}s.
3218
3219 @end{Intro}
3220
3221 @begin{MetaRules}
3222 @ChgRef{Version=[1],Kind=[Revised]}
3223 The rules in this subclause are based on
3224 terms and rules for @nt{discrete_choice_list}s
3225 defined in @RefSec{Variant Parts and Discrete Choices}.
3226 @Chg{New=[For example, the requirements that @key(others) come last and stand
3227 alone are found there.],Old=[]}@Comment{This question is asked periodically, so
3228 we answer it explicitly.}
3229 @end{MetaRules}
3230
3231 @begin{Syntax}
3232 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0306-1]}
3233 @Syn{lhs=<array_aggregate>,rhs="
3234 @Syn2{positional_array_aggregate} | @Chg{Version=[5],New="@Syn2{null_array_aggregate} | ",Old=[]}@Syn2{named_array_aggregate}"}
3235
3236
3237 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
3238 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0212-1],ARef=[AI12-0306-1]}
3239 @Syn{lhs=<positional_array_aggregate>,rhs="
3240 (@Syn2{expression}, @Syn2{expression} {, @Syn2{expression}})
3241 | (@Syn2{expression} {, @Syn2{expression}}, @key(others) => @Syn2{expression})@Chg{Version=[2],New=[
3242 | (@Syn2{expression} {, @Syn2{expression}}, @key(others) => <>)@Chg{Version=[5],New="
3243 | '[' @Syn2{expression} {, @Syn2{expression}}[, @key(others) => @Syn2{expression}] ']'
3244 | '[' @Syn2{expression} {, @Syn2{expression}}, @key(others) => <> ']'",Old=[]}],Old=[]}"}
3245
3246 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0306-1]}
3247 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<null_array_aggregate>,Old=<>}>,
3248 rhs="@Chg{Version=[5],New="'[' ']'",Old=[]}"}
3249
3250 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0127-1],ARef=[AI12-0212-1]}
3251 @Syn{lhs=<named_array_aggregate>,rhs="
3252 @Chg{Version=[5],New="(@Syn2{array_component_association_list})
3253 | '[' @Syn2{array_component_association_list} ']'",
3254 Old=[@Syn2{array_component_association} {, @Syn2{array_component_association}})]}"}
3255
3256 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0127-1]}
3257 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<array_component_association_list>,Old=<>}>,
3258 rhs="@Chg{Version=[5],New=[
3259 @Syn2{array_component_association} {, @Syn2{array_component_association}}],Old=<>}"}
3260
3261 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
3262 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0061-1]}
3263 @Syn{lhs=<array_component_association>,rhs="
3264 @Syn2{discrete_choice_list} => @Syn2{expression}@Chg{Version=[2],New=[
3265 | @Syn2{discrete_choice_list} => <>@Chg{Version=[5],New=[
3266 | @Syn2{iterated_component_association}],Old=[]}],Old=[]}"}
3267
3268 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1],ARef=[AI12-0212-1]}
3269 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<iterated_component_association>,Old=<>}>,
3270 rhs="@Chg{Version=[5],New=[
3271 @key[for] @Syn2{defining_identifier} @key[in] @Syn2{discrete_choice_list} => @Syn2{expression}
3272 | @key[for] @Syn2{iterator_specification} => @Syn2{expression}],Old=<>}"}
3273
3274 @end{Syntax}
3275
3276 @begin{Intro}
3277 @Defn{n-dimensional @nt<array_aggregate>}
3278 An @i(n-dimensional) @nt<array_aggregate> is one that is written as
3279 n levels of nested @nt{array_aggregate}s (or at the bottom level,
3280 equivalent @nt{string_literal}s).
3281 @Defn2{Term=[subaggregate], Sec=(of an @nt{array_aggregate})}
3282 For the multidimensional case (n >= 2) the @nt<array_aggregate>s
3283 (or equivalent @nt<string_literal>s)
3284 at the n@en@;1 lower levels are called @i(subaggregate)s of the
3285 enclosing n-dimensional @nt<array_aggregate>.
3286 @Defn{array component expression}
3287 The @nt<expression>s of the bottom level subaggregates (or of the
3288 @nt<array_aggregate> itself if one-dimensional)
3289 are called the @i(array component expressions) of the enclosing
3290 n-dimensional @nt<array_aggregate>.
3291 @begin(Ramification)
3292 Subaggregates do not have a type. They correspond to part of
3293 an array. For example, with a matrix, a subaggregate would correspond to
3294 a single row of the matrix.
3295 The definition of "n-dimensional" @nt<array_aggregate>
3296 applies to subaggregates as well
3297 as @nt<aggregate>s that have a type.
3298 @end(Ramification)
3299 @begin(Honest)
3300 @Defn{others choice}
3301 An @i(@key(others) choice) is
3302 the reserved word @key(others) as it appears in
3303 a @nt{positional_array_aggregate} or as the
3304 @nt{discrete_choice} of the @nt{discrete_choice_list}
3305 in an @nt{array_component_association}.
3306 @end(Honest)
3307
3308 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1]}
3309 @ChgAdded{Version=[5],Text=[The @nt{defining_identifier} of an
3310 @nt{iterated_component_association} declares an @i<index parameter>,
3311 an object of the corresponding index
3312 type.@Defn2{Term=[index parameter],Sec=[of an array aggregate]}@Defn2{Term=[aggregate],Sec=[index parameter]}]}
3313
3314 @end{Intro}
3315
3316 @begin{Resolution}
3317 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
3318 @PDefn2{Term=[expected type], Sec=(array_aggregate)}
3319 The expected type for an @nt{array_aggregate} (that is not
3320 a subaggregate) shall be a
3321 single @Chg{Version=[2],New=[],Old=[nonlimited ]}array type.
3322 @PDefn2{Term=[expected type],
3323 Sec=(array_aggregate component expression)}
3324 The component type of this array type is the
3325 expected type for each array component expression of
3326 the @nt<array_aggregate>.
3327 @begin{Ramification}
3328 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
3329 We already require a single array or record type or
3330 record extension for an @nt{aggregate}.
3331 The above rule requiring a single @Chg{Version=[2],New=[],
3332 Old=[nonlimited ]}array type
3333 (and similar ones for record and extension aggregates)
3334 resolves which kind of aggregate you have.
3335 @end{Ramification}
3336
3337 @PDefn2{Term=[expected type],
3338 Sec=(array_aggregate discrete_choice)}
3339 The expected type for each
3340 @nt{discrete_choice} in any @nt{discrete_choice_list} of
3341 a @nt{named_array_aggregate} is the type of the @i(corresponding index);
3342 @Defn2{Term=[corresponding index], Sec=(for an @nt{array_aggregate})}
3343 the corresponding index for an @nt<array_aggregate> that is not
3344 a subaggregate is the first index of its type; for an (n@en@;m)-dimensional
3345 subaggregate within an @nt<array_aggregate> of an n-dimensional type,
3346 the corresponding index is the index in position m+1.
3347 @end{Resolution}
3348
3349 @begin{Legality}
3350 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0212-1]}
3351 An @nt<array_aggregate> of an n-dimensional array type shall be
3352 written as an n-dimensional @nt<array_aggregate>@Chg{Version=[5],New=<, or as
3353 a @nt{null_array_aggregate}>,Old=<>}.
3354 @begin(Ramification)
3355 In an m-dimensional @nt<array_aggregate> @Redundant[(including a subaggregate)],
3356 where m >= 2, each of the @nt<expression>s
3357 has to be an (m@en@;1)-dimensional subaggregate.
3358 @end(Ramification)
3359
3360 @Leading@;An @key(others) choice is allowed for an @nt<array_aggregate>
3361 only if an @i(applicable index
3362 constraint) applies to the @nt{array_aggregate}.
3363 @Defn{applicable index constraint}
3364 @Redundant[An applicable index constraint is
3365 a constraint provided by certain contexts where an @nt{array_aggregate}
3366 is permitted that can be used
3367 to determine the bounds of the array value specified by the aggregate.]
3368 Each of the following contexts (and none other)
3369 defines an applicable index constraint:
3370 @begin(itemize)
3371 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
3372 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]}
3373 For an @nt{explicit_actual_parameter},
3374 an @nt{explicit_generic_actual_parameter},
3375 the @nt{expression} of a
3376 @Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]},
3377 @Chg{Version=[4],New=[the return expression of an expression
3378 function, ],Old=[]}the initialization expression
3379 in an @nt{object_@!declaration}, or a @nt{default_@!expression}
3380 @Redundant[(for a parameter or a component)],
3381 when the nominal subtype
3382 of the corresponding formal parameter, generic formal parameter,
3383 function @Chg{Version=[2],New=[return object],Old=[result]},
3384 @Chg{Version=[4],New=[expression function return object, ],Old=[]}object, or
3385 component is a constrained array subtype, the
3386 applicable index constraint is the constraint of the subtype;
3387
3388 For the @nt{expression} of an @nt{assignment_statement} where
3389 the @nt{name} denotes an array variable, the
3390 applicable index constraint is the constraint of the array variable;
3391 @begin{Reason}
3392 This case is broken out because the constraint comes from the actual
3393 subtype of the variable (which is always constrained)
3394 rather than its nominal subtype (which might be unconstrained).
3395 @end{Reason}
3396
3397 For the operand of a @nt{qualified_expression}
3398 whose @nt{subtype_mark}
3399 denotes a constrained array subtype, the applicable index constraint
3400 is the constraint of the subtype;
3401
3402 For a component @nt{expression} in an @nt{aggregate},
3403 if the component's nominal subtype is a constrained
3404 array subtype, the applicable index constraint is the constraint
3405 of the subtype;
3406 @begin{Discussion}
3407 Here, the @nt{array_aggregate} with @key[others]
3408 is being used within a larger aggregate.
3409 @end{Discussion}
3410
3411 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0127-1]}
3412 @ChgAdded{Version=[5],Text=[For the @SynI<base_>@nt{expression} of a
3413 @nt{delta_aggregate}, if the nominal subtype of the @nt{delta_aggregate} is
3414 a constrained array subtype, the applicable index constraint is the
3415 constraint of the subtype;]}
3416
3417 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0147-1]}
3418 For a parenthesized @nt{expression}, the
3419 applicable index constraint is that, if any, defined for the
3420 @nt{expression}@Chg{Version=[3],New=[;],Old=[.]}
3421 @begin{Discussion}
3422 RM83 omitted this
3423 case, presumably as an oversight. We want to minimize situations
3424 where an @nt{expression} becomes illegal if parenthesized.
3425 @end{Discussion}
3426 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0147-1]}
3427 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0236-1]}
3428 @ChgAdded{Version=[3],Text=[For a @nt{conditional_expression}@Chg{Version=[5],New=[
3429 (see @RefSecNum{Conditional Expressions})],Old=[]}, the
3430 applicable index constraint for each @SynI<dependent_>@nt{expression} is that,
3431 if any, defined for the @nt{conditional_expression}@Chg{Version=[5],New=[;],Old=[.]}]}
3432
3433 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0147-1]}
3434 @ChgAdded{Version=[5],Text=[For a @nt{declare_expression} (see @RefSecNum{Declare Expressions}),
3435 the applicable index constraint for the @SynI<body_>@nt{expression} is that,
3436 if any, defined for the @nt{declare_expression}.]}
3437 @end(itemize)
3438
3439 The applicable index constraint @i(applies) to an @nt{array_aggregate}
3440 that appears in such a context, as well as to any subaggregates thereof.
3441 In the case of an @nt<explicit_actual_parameter> (or @nt<default_expression>)
3442 for a call on a generic formal subprogram,
3443 no applicable index constraint is defined.
3444 @begin(Reason)
3445 This avoids generic contract model problems,
3446 because only mode conformance is required when matching
3447 actual subprograms with generic formal subprograms.
3448 @end(Reason)
3449
3450 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3]}
3451 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0061-1],ARef=[AI12-0127-1]}
3452 The @nt{discrete_choice_list} of an
3453 @nt{array_component_association} @Chg{Version=[5],New=[(including an
3454 @nt{iterated_component_association}) ],Old=[]}is allowed to
3455 have a @nt{discrete_choice} that is a nonstatic
3456 @Chg{Version=[3],New=[@nt<choice_expression>],Old=[@nt<expression>]}
3457 or that is a @Chg{Version=[3],New=[@nt{subtype_indication} or @nt{range}],
3458 Old=[@nt{discrete_range}]} that defines a nonstatic or
3459 null range, only if it is the single @nt{discrete_choice} of
3460 its @nt{discrete_choice_list}, and @Chg{Version=[5],New=[either ],Old=[]}there
3461 is only one @nt{array_component_association} in the
3462 @Chg{Version=[5],New=[enclosing @nt{array_component_association_list} or the
3463 enclosing @nt{aggregate} is an @nt{array_delta_aggregate}@Redundant[, not an
3464 @nt{array_aggregate}]],Old=[@nt<array_aggregate>]}.
3465
3466 @begin{Discussion}
3467 We now allow a nonstatic @key(others) choice even if there are
3468 other array component expressions as well.
3469 @end{Discussion}
3470 @begin{Ramification}
3471 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
3472 @ChgAdded{Version=[5],Text=[We allow multiple dynamic choices in
3473 @nt{array_delta_aggregate}s, but only one dynamic choice per association even
3474 in that case.]}
3475 @end{Ramification}
3476
3477 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1]}
3478 @ChgAdded{Version=[5],Text=[Either all or none of the @nt{array_component_association}s of an
3479 @nt{array_component_association_list} shall be @nt{iterated_component_association}s
3480 with an @nt{iterator_specification}.]}
3481
3482 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
3483 In a @nt<named_array_aggregate>
3484 @Chg{Version=[3],New=[where all @nt{discrete_choice}s are
3485 static],Old=[with more than one @nt<discrete_choice>]},
3486 no two @nt<discrete_choice>s are allowed to
3487 cover the same value (see @RefSecNum{Variant Parts and Discrete Choices});
3488 if there is no @key[others] choice, the @nt<discrete_choice>s taken
3489 together shall
3490 exactly cover a contiguous sequence of values of the corresponding index type.
3491 @begin{Ramification}
3492 This implies that each component must be
3493 specified exactly once. See AI83-309.
3494 @end{Ramification}
3495 @begin{Reason}
3496 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]}
3497 @ChgAdded{Version=[3],Text=[This has to apply even if there is only one
3498 static @nt{discrete_choice}; a single choice has to represent a contiguous
3499 range (a @nt{subtype_mark} with a static predicate might represent a
3500 discontiguous set of values). If the (single) choice is a dynamic subtype, we
3501 don't need to make this check as no predicates are allowed (see
3502 @RefSecNum{Subtype Predicates}) and
3503 thus the range has to be contiguous.]}
3504 @end{Reason}
3505
3506 A bottom level subaggregate of a multidimensional @nt<array_aggregate>
3507 of a given array type
3508 is allowed to be a @nt<string_literal> only if the component type of the
3509 array type is a character type;
3510 each character of such a @nt{string_literal} shall correspond to
3511 a @nt<defining_character_literal> of the component type.
3512 @end{Legality}
3513
3514 @begin{StaticSem}
3515 A subaggregate that is a @nt<string_literal> is equivalent
3516 to one that is a @nt<positional_array_aggregate> of the same length,
3517 with each @nt<expression> being the @nt<character_literal>
3518 for the corresponding character of the @nt<string_literal>.
3519
3520 @begin{Honest}
3521 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0306-1]}
3522 @ChgAdded{Version=[5],Text=[This is true even in cases where there is no
3523 corresponding legal @nt{positional_array_aggregate}.]}
3524 @end{Honest}
3525
3526 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1]}
3527 @ChgAdded{Version=[5],Text=[The subtype (and nominal subtype) of
3528 an index parameter is the corresponding index subtype.]}
3529 @end{StaticSem}
3530
3531 @begin{RunTime}
3532 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1]}
3533 @ChgAdded{Version=[5],Type=[Leading],Text=[For an @nt{array_aggregate} that
3534 contains only @nt{array_component_association}s that are
3535 @nt{iterated_component_association}s with @nt{iterator_specification}s,
3536 evaluation proceeds in two steps:]}
3537 @begin(enumerate)
3538 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1],ARef=[AI12-0250-1]}
3539 @ChgAdded{Version=[5],Text=[Each @nt{iterator_specification} is elaborated
3540 (in an arbitrary order)@PDefn2{Term=[arbitrary order],Sec=[allowed]}
3541 and an iteration is performed solely to determine a maximum count
3542 for the number of values produced by the iteration; all of these
3543 counts are combined to determine the overall length of the array, and
3544 ultimately the limits on the bounds of the array (defined below);]}
3545
3546 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1],ARef=[AI12-0250-1],ARef=[AI12-0327-1]}
3547 @ChgAdded{Version=[5],Text=[A second iteration is performed for each of the
3548 @nt{iterator_specification}s, in the order given in the @nt{aggregate},
3549 and for each value conditionally produced by the iteration (see
3550 @RefSecNum{Loop Statements} and @RefSecNum{Generalized Loop Iteration}), the
3551 associated @nt{expression} is evaluated,
3552 its value is converted to the component subtype of the array type, and used
3553 to define the value of the next component of the array starting at the
3554 low bound and proceeding sequentially toward the high bound. A check is made
3555 that the second iteration results in an array length no greater than the
3556 maximum determined by the first iteration;
3557 Constraint_Error is raised if this check@IndexCheck{Index_Check}
3558 fails.@Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}]}
3559
3560 @begin{Honest}
3561 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1],ARef=[AI12-0250-1]}
3562 @ChgAdded{Version=[5],Text=[Constraint_Error should be raised no later than
3563 when the iterations exceed the maximum array length; memory that
3564 doesn't belong to the aggregate temporary should not be overwritten.]}
3565 @end{Honest}
3566 @end{enumerate}
3567
3568 @Leading@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0212-1]}
3569 @PDefn2{Term=[evaluation], Sec=(array_aggregate)}
3570 The evaluation of @Chg{Version=[5],New=[any other],Old=[an]}
3571 @nt{array_aggregate} of a given array type proceeds in two steps:
3572 @begin(enumerate)
3573 Any @nt{discrete_choice}s of this aggregate and of its subaggregates
3574 are evaluated in an arbitrary order, and converted to the corresponding
3575 index type;@PDefn2{Term=[arbitrary order],Sec=[allowed]}
3576 @PDefn2{Term=[implicit subtype conversion],Sec=(choices of aggregate)}
3577
3578 The array component expressions of the aggregate
3579 are evaluated in an arbitrary order and
3580 their values are converted to the component subtype of
3581 the array type; an array component expression
3582 is evaluated once for each associated component.
3583 @PDefn2{Term=[implicit subtype conversion],Sec=(expressions of aggregate)}
3584 @PDefn2{Term=[arbitrary order],Sec=[allowed]}
3585 @end(enumerate)
3586 @begin(Ramification)
3587 Subaggregates are not separately evaluated.
3588 The conversion of the value of the component expressions
3589 to the component subtype might raise Constraint_Error.
3590
3591 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
3592 @ChgAdded{Version=[3],Text=[We don't need to say that <> is
3593 evaluated once for each component, as <> means that each component
3594 is @i{initialized by default}. That means that the actions defined
3595 for default initialization are applied to each component individually.
3596 Initializing one component by default and copying
3597 that to the others would be an incorrect implementation in general
3598 (although it might be OK if the default initialization is known
3599 to be constant).]}
3600 @end(Ramification)
3601
3602 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]}
3603 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0084-1]}
3604 @ChgAdded{Version=[2],Text=[Each @nt<expression> in an
3605 @nt<array_component_association> defines the value for the associated
3606 component(s). For an @nt<array_component_association> with <>, the associated
3607 component(s) are initialized @Chg{Version=[4],New=[to the Default_Component_Value
3608 of the array type if this aspect has been specified for the array type;
3609 otherwise, they are initialized ],Old=[]}by default
3610 as for a stand-alone object of the
3611 component subtype (see @RefSecNum{Object Declarations}).]}
3612
3613 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0061-1],ARef=[AI12-0212-1]}
3614 @ChgAdded{Version=[5],Text=[During an evaluation of the @nt{expression}
3615 of an @nt{iterated_component_association} with a @nt{discrete_choice_list},
3616 the value of the corresponding index parameter is that of the corresponding
3617 index of the corresponding array component. During an evaluation of the
3618 @nt{expression} of an @nt{iterated_component_association} with an
3619 @nt{iterator_specification}, the value of the loop parameter
3620 of the @nt{iterator_specification} is the value produced by the iteration
3621 (as described in @RefSecNum{Generalized Loop Iteration}).]}
3622
3623 @begin{Ramification}
3624 @ChgRef{Version=[5],Kind=[AddedNormal]}
3625 @ChgAdded{Version=[5],Text=[Taken together with the preceding rule that
3626 @ldquote@;The array component expressions of the aggregate are evaluated in
3627 an arbitrary order@rdquote, this implies that an index parameter of an
3628 @nt{iterated_component_association} can take on its values in an
3629 arbitrary order. This is different from other constructs, such as a
3630 @nt{loop_statement}. In contrast, a loop parameter of an
3631 @nt{iterated_component_association} takes its values in the order defined
3632 by the iteration, the same as a @nt{loop_statement}.]}
3633 @end{Ramification}
3634
3635 @Leading@Defn2{Term=[bounds],
3636 Sec=(of the index range of an @nt{array_aggregate})}
3637 The bounds of the index range of an @nt{array_aggregate} @Redundant[(including
3638 a subaggregate)]
3639 are determined as follows:
3640 @begin(itemize)
3641 For an @nt{array_aggregate} with an @key(others) choice, the bounds are
3642 those of the corresponding index range from the applicable
3643 index constraint;
3644
3645 For a @nt{positional_array_aggregate} @Redundant[(or equivalent
3646 @nt<string_literal>)]
3647 without an @key(others) choice, the
3648 lower bound is that of the corresponding index range in the
3649 applicable index constraint, if defined, or that of the corresponding
3650 index subtype, if not; in either case, the upper bound is
3651 determined from the lower bound and the number of @nt<expression>s
3652 @Redundant[(or the length of the @nt<string_literal>)];
3653
3654 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1],ARef=[AI12-0306-1]}
3655 @ChgAdded{Version=[5],Text=[For a @nt{null_array_aggregate}, bounds for each
3656 dimension are determined as for a @nt{positional_array_aggregate} without
3657 an @key(others) choice that has no expressions for each dimension;]}
3658
3659 @begin{Reason}
3660 @ChgRef{Version=[5],Kind=[AddedNormal]}
3661 @ChgAdded{Version=[5],Text=[We need a separate rule to describe what
3662 happens for a multidimensional @nt{null_array_aggregate}; we could've
3663 combined the single-dimension case with the @nt{positional_array_aggregate}
3664 rule.]}
3665 @end{Reason}
3666
3667 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0212-1],ARef=[AI12-0250-1]}
3668 @ChgAdded{Version=[5],Text=[For a @nt{named_array_aggregate} containing only
3669 @nt{iterated_component_association}s with an @nt{iterator_specification}, the
3670 lower bound is determined as for a @nt{positional_array_aggregate} without
3671 an @b<others> choice, and the upper bound is determined from the lower
3672 bound and the total number of values produced by the second set of
3673 iterations;]}
3674
3675 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0212-1]}
3676 For @Chg{Version=[5],New=[any other],Old=[a]} @nt{named_array_aggregate}
3677 without an @key(others) choice, the bounds are determined by the smallest
3678 and largest index values covered by any @nt{discrete_choice_list}.
3679 @begin{Reason}
3680 We don't need to say that each index value has to be covered exactly
3681 once, since that is a ramification of the general rule
3682 on @nt{aggregate}s that each component's value has to be specified
3683 exactly once.
3684 @end{Reason}
3685 @end(itemize)
3686
3687 @IndexCheck{Range_Check}
3688 For an @nt<array_aggregate>, a check is made
3689 that the index range defined by its bounds
3690 is compatible with the corresponding index subtype.
3691 @begin{Discussion}
3692 In RM83, this was
3693 phrased more explicitly, but once we define "compatibility"
3694 between a range and a subtype, it seems to make sense to
3695 take advantage of that definition.
3696 @end{Discussion}
3697 @begin(Ramification)
3698 The definition of compatibility handles the special case
3699 of a null range, which is always compatible with
3700 a subtype. See AI83-00313.
3701 @end(Ramification)
3702
3703 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0037-1]}
3704 @IndexCheck{Index_Check}
3705 For an @nt{array_aggregate} with an @key(others) choice,
3706 a check is made that no @nt<expression>@Chg{Version=[3],New=[ or <>],Old=[]}
3707 is specified for an index value outside the bounds determined by the
3708 applicable index constraint.
3709 @begin{Discussion}
3710 RM83 omitted this case,
3711 apparently through an oversight. AI83-00309 defines this
3712 as a dynamic check, even though other Ada 83 rules ensured
3713 that this check could be performed statically. We now allow
3714 an @key(others) choice to be dynamic, even if
3715 it is not the only choice, so this check now needs to be
3716 dynamic, in some cases. Also, within a generic unit,
3717 this would be a nonstatic check in some cases.
3718 @end{Discussion}
3719
3720 @IndexCheck{Index_Check}
3721 For a multidimensional @nt{array_aggregate}, a check is made
3722 that all subaggregates that correspond to the same index have the same
3723 bounds.
3724 @begin{Ramification}
3725 No array bounds @lquotes@;sliding@rquotes@; is performed on subaggregates.
3726 @end{Ramification}
3727 @begin{Reason}
3728 If sliding were performed, it would not be obvious which
3729 subaggregate would determine the bounds of the corresponding index.
3730 @end{Reason}
3731
3732 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
3733 The exception Constraint_Error is raised if any of the above
3734 checks fail.
3735 @end{RunTime}
3736
3737 @begin{ImplPerm}
3738 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1],ARef=[AI12-0250-1]}
3739 @ChgAdded{Version=[5],Text=[When evaluating
3740 @nt{iterated_component_association}s for an @nt{array_aggregate}
3741 that contains only @nt{iterated_component_association}s with
3742 @nt{iterator_specification}s, the first step of evaluating an
3743 @nt{iterated_component_association} can be omitted if the implementation can
3744 determine the maximum number of values by some other means.]}
3745
3746 @begin{Discussion}
3747 @ChgRef{Version=[5],Kind=[AddedNormal]}
3748 @ChgAdded{Version=[5],Text=[For instance, if the type of the aggregate is
3749 constrained, the implementation can (but does not have to) calculate the
3750 expected length from the constraint.]}
3751 @end{Discussion}
3752 @end{ImplPerm}
3753
3754 @begin{Notes}
3755 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
3756 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0306-1]}
3757 In an @nt<array_aggregate>@Chg{Version=[5],New=[ delimited by
3758 parentheses],Old=[]}, positional notation may only be used
3759 with two or more @nt<expression>s; a single @nt<expression>
3760 in parentheses is interpreted as a
3761 @Chg{Version=[3],New=[parenthesized expression],Old=[@ntf{parenthesized_expression}]}.
3762 @Chg{Version=[5],New=[An @nt{array_aggregate} delimited by square
3763 brackets],Old=[A @nt<named_array_aggregate>, such as (1 => X),]} may be used to
3764 specify an array with a single component.
3765
3766 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0061-1]}
3767 @ChgAdded{Version=[5],Text=[An index parameter is a constant object (see
3768 @refSecNum{Objects and Named Numbers}).]}
3769 @end{Notes}
3770
3771 @begin{Examples}
3772 @Leading@keepnext@i(Examples of array aggregates with positional associations:)
3773 @begin{Example}
3774 (7, 9, 5, 1, 3, 2, 4, 8, 6, 0)
3775 Table'(5, 8, 4, 1, @key(others) => 0) --@RI[ see @RefSecNum{Array Types} ]
3776 @end{Example}
3777
3778 @begin{WideAbove}
3779 @leading@keepnext@i(Examples of array aggregates with named associations:)
3780 @end{WideAbove}
3781 @begin{Example}
3782 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0306-1]}
3783 (1 .. 5 => (1 .. 8 => 0.0)) --@RI[ two-dimensional]
3784 @Chg{Version=[5],New=<[>,Old=<(>}1 .. N => @key(new) Cell@Chg{Version=[5],New=<]>,Old=<)>} --@RI[ N new cells, in particular for N = 0]
3785
3786 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0306-1]}
3787 Table'(2 | 4 | 10 => 1, @key(others) => 0)
3788 Schedule'(Mon .. Fri => True, @key(others) => False) --@RI[ see @RefSecNum{Array Types}]
3789 Schedule'@Chg{Version=[5],New=<[>,Old=<(>}Wed | Sun => False, @key(others) => True@Chg{Version=[5],New=<]>,Old=<)>}
3790 Vector'(1 => 2.5) --@RI[ single-component vector]
3791 @end{Example}
3792
3793 @begin{WideAbove}
3794 @leading@keepnext@i(Examples of two-dimensional array aggregates:)
3795 @end{WideAbove}
3796 @begin{Example}
3797 --@RI[ Three aggregates for the same value of subtype Matrix(1..2,1..3) (see @RefSecNum{Array Types}):]
3798
3799 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0306-1]}
3800 ((1.1, 1.2, 1.3), (2.1, 2.2, 2.3))
3801 (1 => @Chg{Version=[5],New=<[>,Old=<(>}1.1, 1.2, 1.3@Chg{Version=[5],New=<]>,Old=<)>}, 2 => @Chg{Version=[5],New=<[>,Old=<(>}2.1, 2.2, 2.3@Chg{Version=[5],New=<]>,Old=<)>})
3802 @Chg{Version=[5],New=<[>,Old=<(>}1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3)@Chg{Version=[5],New=<]>,Old=<)>}
3803 @end{Example}
3804
3805 @begin{WideAbove}
3806 @leading@keepnext@i(Examples of aggregates as initial values:)
3807 @end{WideAbove}
3808 @begin{Example}
3809 A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0); --@RI[ A(1)=7, A(10)=0]
3810 B : Table := (2 | 4 | 10 => 1, @key(others) => 0); --@RI[ B(1)=0, B(10)=1]
3811 C : @key(constant) Matrix := (1 .. 5 => (1 .. 8 => 0.0)); --@RI[ C'Last(1)=5, C'Last(2)=8]
3812
3813 D : Bit_Vector(M .. N) := (M .. N => True); --@RI[ see @RefSecNum{Array Types}]
3814 E : Bit_Vector(M .. N) := (@key(others) => True);
3815 F : String(1 .. 1) := (1 => 'F'); --@RI[ a one component aggregate: same as "F"]
3816
3817 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0061-1]}
3818 @ChgAdded{Version=[5],Text=[G : @key[constant] Matrix :=
3819 (@key[for] I @key[in] 1 .. 4 =>
3820 (@key[for] J @key[in] 1 .. 4 =>
3821 (@key[if] I=J @key[then] 1.0 @key[else] 0.0))); --@RI[ Identity matrix]]}
3822
3823 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
3824 @ChgAdded{Version=[5],Text=<Empty_Matrix : @b<constant> Matrix := []; --@RI[ A matrix without elements]>}
3825 @end{Example}
3826
3827 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
3828 @ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],Text=[@i{Example of an array
3829 aggregate with defaulted others choice and with an applicable index constraint
3830 provided by an enclosing record aggregate:}]}
3831
3832 @begin{Example}
3833 @ChgRef{Version=[2],Kind=[AddedNormal]}
3834 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
3835 @ChgAdded{Version=[2],Text=[Buffer'(Size => 50, Pos => 1, Value => @Chg{Version=[5],New=[],Old=[String']}('x', @key(others) => <>)) --@RI[ see @RefSecNum{Discriminants}]]}
3836 @end{Example}
3837 @end{Examples}
3838
3839 @begin{Incompatible83}
3840 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016}
3841 @ChgAdded{Version=[1],Type=[Leading],Text=[@Defn{incompatibilities with Ada 83}
3842 In Ada 95, no applicable index constraint is defined for a parameter
3843 in a call to a generic formal subprogram; thus, some aggregates that are
3844 legal in Ada 83 are illegal in Ada 95. For example:]}
3845 @begin{Example}
3846 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016}
3847 @Chg{New=[@key[subtype] S3 @key[is] String (1 .. 3);
3848 ...
3849 @key[generic]
3850 @key[with function] F (The_S3 : @key[in] S3) @key[return] Integer;
3851 @key[package] Gp @key[is]
3852 I : constant Integer := F ((1 => '!', others => '?'));
3853 -- @RI{The aggregate is legal in Ada 83, illegal in Ada 95.}
3854 @key[end] Gp;],Old=[]}
3855 @end{Example}
3856 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016}
3857 @Chg{New=[This change eliminates generic contract model problems.],Old=[]}
3858 @end{Incompatible83}
3859
3860 @begin{Extend83}
3861 @Defn{extensions to Ada 83}
3862 We now allow "named with others" aggregates in all contexts
3863 where there is an applicable index constraint, effectively
3864 eliminating what was RM83-4.3.2(6). Sliding never occurs
3865 on an aggregate with others, because its bounds come from
3866 the applicable index constraint, and therefore already match
3867 the bounds of the target.
3868
3869 The legality of an @key(others) choice is no longer affected
3870 by the staticness of the applicable index constraint.
3871 This substantially simplifies several rules, while being slightly
3872 more flexible for the user. It obviates the rulings
3873 of AI83-00244 and AI83-00310, while taking advantage of the dynamic nature
3874 of the "extra values" check required by AI83-00309.
3875
3876 Named array aggregates are permitted even if the
3877 index type is descended from a formal scalar type.
3878 See @RefSecNum(Static Expressions and Static Subtypes) and AI83-00190.
3879 @end{Extend83}
3880
3881 @begin{DiffWord83}
3882 We now separate named and positional array aggregate syntax,
3883 since, unlike other aggregates, named and positional
3884 associations cannot be mixed in array aggregates (except
3885 that an @key(others) choice is allowed in a positional array aggregate).
3886
3887 We have also reorganized the presentation to handle
3888 multidimensional and one-dimensional aggregates more uniformly,
3889 and to incorporate the rulings of AI83-00019, AI83-00309, etc.
3890 @end{DiffWord83}
3891
3892
3893 @begin{Extend95}
3894 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
3895 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}<> can be used in
3896 place of an @nt{expression} in an @nt{array_aggregate}, default-initializing
3897 the component.]}
3898 @end{Extend95}
3899
3900 @begin{DiffWord95}
3901 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
3902 @ChgAdded{Version=[2],Text=[Limited @nt{array_aggregate}s are allowed (since
3903 all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]}
3904
3905 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
3906 @ChgAdded{Version=[2],Text=[Fixed @nt{aggregate}s to use the subtype of
3907 the return object of a function, rather than the result subtype, because
3908 they can be different for an @nt{extended_return_statement}, and we want
3909 to use the subtype that's explicitly in the code at the point of the
3910 @nt{expression}.]}
3911 @end{DiffWord95}
3912
3913 @begin{Inconsistent2005}
3914 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0037-1]}
3915 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b<Correction:>
3916 Fixed so the check
3917 for components outside of the array applies to both @nt<expression>s and
3918 <>s. As <> was a new feature in Ada 2005, there should be little existing
3919 code that depends on a <> component that is specified outside of the array
3920 (and that is nonsense anyway, that a compiler is likely to detect even
3921 without an explicit language rule disallowing it).]}
3922 @end{Inconsistent2005}
3923
3924 @begin{DiffWord2005}
3925 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
3926 @ChgAdded{Version=[3],Text=[Added a definition of the applicable index
3927 constraint for @nt{conditional_expression}s (which are new).]}
3928 @end{DiffWord2005}
3929
3930 @begin{Inconsistent2012}
3931 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0084-1]}
3932 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
3933 Fixed so that the Default_Component_Value (if any) is used to initialize
3934 components specified with <>. This is what users would expect, and all
3935 Ada 2012 implementation known at the time of this writing initialize with
3936 the Default_Component_Value, so it is unlikely that anyone will be affected
3937 by this inconsistency.]}
3938 @end{Inconsistent2012}
3939
3940 @begin{Extend2012}
3941 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0061-1],ARef=[AI12-0212-1],ARef=[AI12-0250-1]}
3942 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}The
3943 @nt{iterated_component_association} is new (more than 25 years after it
3944 was originally proposed). It has been extended to allow container iterators
3945 as well as the basic index iterators.]}
3946
3947 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
3948 @ChgAdded{Version=[5],Text=[An @nt{array_aggregate} can be surrounded by
3949 brackets rather than parentheses. This allows consistent writing of zero-
3950 and one-component positional array aggregates, and is consistent with the
3951 syntax for writing container aggregates.]}
3952
3953 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1],ARef=[AI12-0306-1]}
3954 @ChgAdded{Version=[5],Text=[A @nt{null_array_aggregate} is new.]}
3955 @end{Extend2012}
3956
3957 @begin{DiffWord2012}
3958 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0157-1]}
3959 @ChgAdded{Version=[4],Text=[@b<Corrigendum:>
3960 Added expression functions to the contexts that provide an applicable
3961 index constraint, because expression functions are handled separately in
3962 static semantics and legality rules.]}
3963
3964 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
3965 @ChgAdded{Version=[5],Text=[Made syntax and wording changes for
3966 @nt{delta_aggregate}s.]}
3967
3968 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
3969 @ChgAdded{Version=[5],Text=[Added a definition of the applicable index
3970 constraint for @nt{declare_expression}s (which are new). This allows
3971 @key[others] in array aggregates inside of @nt{declare_expression}s.]}
3972 @end{DiffWord2012}
3973
3974
3975 @LabeledAddedSubClause{Version=[5],Name=[Delta Aggregates]}
3976
3977 @begin{Intro}
3978 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0324-1]}
3979 @ChgAdded{Version=[5],Text=[Evaluating a (record or array) delta aggregate
3980 yields a composite value that starts with a copy of another value of the same
3981 type and then assigns to some (but typically not all) components
3982 of the copy.@Defn{delta aggregate}]}
3983 @end{Intro}
3984
3985 @begin{Syntax}
3986 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
3987 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<delta_aggregate>,Old=<>}>,
3988 rhs="@Chg{Version=[5],New=[@Syn2{record_delta_aggregate} | @Syn2{array_delta_aggregate}],Old=<>}"}
3989
3990 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
3991 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<record_delta_aggregate>,Old=<>}>,
3992 rhs="@Chg{Version=[5],New=[
3993 (@SynI<base_>@Syn2{expression} @key[with] @key[delta] @Syn2{record_component_association_list})],Old=<>}"}
3994
3995 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0212-1]}
3996 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<array_delta_aggregate>,Old=<>}>,
3997 rhs="@Chg{Version=[5],New=<
3998 (@SynI<base_>@Syn2{expression} @key[with] @key[delta] @Syn2{array_component_association_list})
3999 | '[' @SynI<base_>@Syn2{expression} @key[with] @key[delta] @Syn2{array_component_association_list} ']'>,Old=<>}"}
4000 @end{Syntax}
4001
4002 @begin{Resolution}
4003
4004 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4005 @ChgAdded{Version=[5],Text=[The expected type for a @nt{record_delta_aggregate}
4006 shall be a single descendant of a record type or record
4007 extension.@PDefn2{Term=[expected type],Sec=(record delta aggregate)}]}
4008
4009 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4010 @ChgAdded{Version=[5],Text=[The expected type for an @nt{array_delta_aggregate}
4011 shall be a single array type.@PDefn2{Term=[expected type],Sec=(array delta aggregate)}]}
4012
4013 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4014 @ChgAdded{Version=[5],Text=[The expected type for the
4015 @SynI[base_]@nt{expression} of any @nt{delta_aggregate} is the type of the
4016 enclosing @nt{delta_aggregate}.@PDefn2{Term=[expected type],Sec=(base expression of a delta aggregate)}
4017 @PDefn2{Term=[expected type],Sec=(delta aggregate base expression)}]}
4018
4019 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4020 @ChgAdded{Version=[5],Text=[@Redundant[The @ResolutionTitle and
4021 @LegalityTitle for each @nt{record_component_association} of a
4022 @nt{record_delta_aggregate} are as defined in @RefSecNum{Record Aggregates}.]]}
4023
4024 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4025 @ChgAdded{Version=[5],Text=[For an @nt{array_delta_aggregate}, the expected
4026 type for each @nt{discrete_choice} in an @nt{array_component_association} is
4027 the index type of the type of the @nt{delta_aggregate}.]}
4028
4029 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4030 @ChgAdded{Version=[5],Text=[The expected type of the
4031 @nt{expression} in an @nt{array_component_association} is defined as for
4032 an @nt{array_component_association} occurring within an @nt{array_aggregate}
4033 of the type of the @nt{delta_aggregate}.]}
4034
4035 @end{Resolution}
4036
4037 @begin{Legality}
4038
4039 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4040 @ChgAdded{Version=[5],Text=[For an @nt{array_delta_aggregate}, the
4041 @nt{array_component_association} shall not use the box symbol <>, and the
4042 @nt{discrete_choice} shall not be @key[others].]}
4043
4044 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4045 @ChgAdded{Version=[5],Text=[For an @nt{array_delta_aggregate}, the
4046 dimensionality of the type of the @nt{delta_aggregate} shall be 1.]}
4047
4048 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4049 @ChgAdded{Version=[5],Text=[For an @nt{array_delta_aggregate}, the
4050 @SynI<base_>@nt{expression} and each @nt{expression} in
4051 every @nt{array_component_association} shall be of a nonlimited type.]}
4052
4053 @begin(Ramification)
4054 @ChgRef{Version=[5],Kind=[AddedNormal]}
4055 @ChgAdded{Version=[5],Text=[The @SynI{base_}@nt{expression} of a
4056 @nt{record_delta_aggregate} may be of a limited type (for example a record
4057 with limited components), as it is not restricted. A rule in
4058 @RefSecNum{Record Aggregates} ensures that we do not assign to a limited
4059 component. We do not allow any part of an @nt{array_delta_aggregate} to be
4060 of a limited type, even the @SynI{base_}@nt{expression}, as this is a useless
4061 construct (you would not be able to update anything because the components
4062 necessarily are also limited except in pathological cases).]}
4063 @end(Ramification)
4064 @end{Legality}
4065
4066 @begin{Runtime}
4067
4068 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0324-1]}
4069 @ChgAdded{Version=[5],Text=[The evaluation of a @nt{delta_aggregate} begins with
4070 the evaluation of the @SynI<base_>@nt{expression} of the @nt{delta_aggregate};
4071 then that value is used to create and initialize the anonymous object of
4072 the @nt{aggregate}. The bounds of the anonymous object of an
4073 @nt{array_delta_aggregate} and the discriminants and tag (if any) of the
4074 anonymous object of a @nt{record_delta_aggregate} are those of the
4075 @SynI{base_}@nt{expression}.]}
4076
4077 @begin{Ramification}
4078 @ChgRef{Version=[5],Kind=[AddedNormal]}
4079 @ChgAdded{Version=[5],Text=[This is the same anonymous object as described in
4080 @RefSec{Assignment and Finalization}; in particular, it might be required
4081 to be built in place.]}
4082
4083 @ChgRef{Version=[5],Kind=[AddedNormal]}
4084 @ChgAdded{Version=[5],Text=[This requires that the underlying tag (if any)
4085 associated with the @nt{delta_aggregate} is that of the
4086 @SynI{base_}@nt{expression} in the @nt{delta_aggregate} and not that of the
4087 nominal type of the @SynI{base_}@nt{expression} in the
4088 @nt{delta_aggregate}.]}
4089 @end{Ramification}
4090
4091 @begin{Honest}
4092 @ChgRef{Version=[5],Kind=[AddedNormal]}
4093 @ChgAdded{Version=[5],Text=[The anonymous object associated with the
4094 evaluation of a @nt{delta_aggregate} begins its life as a variable, not a
4095 constant (@RefSecNum{Objects and Named Numbers} notwithstanding). This must be
4096 the case because the object is initialized and then subsequently modified.
4097 After evaluation of the @nt{delta_aggregate} is complete, the object is a
4098 constant object. This is similar to the way that an extended return statement
4099 can provide a variable view of an object that will eventually be a constant
4100 object after the function returns its result.]}
4101 @end{Honest}
4102
4103 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4104 @ChgAdded{Version=[5],Type=[Leading],Text=[For a @nt{record_delta_aggregate},
4105 for each component associated with each @nt{record_component_association}
4106 (in an unspecified order):]}
4107 @begin{Itemize}
4108 @ChgRef{Version=[5],Kind=[AddedNormal]}
4109 @ChgAdded{Version=[5],Text=[if the associated component belongs to a
4110 @nt{variant}, a check is made that the values of the discriminants are such
4111 that the anonymous object has this component.
4112 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
4113 The exception Constraint_Error is raised if this check
4114 fails.@IndexCheck{Discriminant_Check}]}
4115
4116 @ChgRef{Version=[5],Kind=[AddedNormal]}
4117 @ChgAdded{Version=[5],Text=[the @nt{expression} of the
4118 @nt{record_component_association} is evaluated, converted to the nominal
4119 subtype of the associated component, and assigned to the component of the
4120 anonymous object.]}
4121
4122 @end{Itemize}
4123
4124 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4125 @ChgAdded{Version=[5],Type=[Leading],Text=[For an @nt{array_delta_aggregate},
4126 for each @nt{discrete_choice} of each @nt{array_component_association} (in the
4127 order given in the enclosing @nt{discrete_choice_list} and
4128 @nt{array_component_association_list}, respectively) the
4129 @nt{discrete_choice} is evaluated; for each represented index value (in
4130 ascending order, if the @nt{discrete_choice} represents a range):]}
4131 @begin{Itemize}
4132 @ChgRef{Version=[5],Kind=[AddedNormal]}
4133 @ChgAdded{Version=[5],Text=[the index value is converted to the index type
4134 of the array type.]}
4135
4136 @ChgRef{Version=[5],Kind=[AddedNormal]}
4137 @ChgAdded{Version=[5],Text=[a check is made that the index value belongs to
4138 the index range of the anonymous object of the @nt{aggregate};
4139 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
4140 Constraint_Error is raised if this check fails.@IndexCheck{Index_Check}]}
4141
4142 @ChgRef{Version=[5],Kind=[AddedNormal]}
4143 @ChgAdded{Version=[5],Text=[the component @nt{expression} is evaluated,
4144 converted to the array component subtype, and assigned to the component
4145 of the anonymous object identified by the index value.]}
4146 @end{Itemize}
4147
4148 @begin{Reason}
4149 @ChgRef{Version=[5],Kind=[AddedNormal]}
4150 @ChgAdded{Version=[5],Text=[Unlike other @nt{aggregate}s, an
4151 @nt{array_delta_aggregate} is evaluated in the order that it is written.
4152 This is necessary to get deterministic behavior, as (unlike other
4153 @nt{aggregate}s, including @nt{record_delta_aggregate}s) there is no
4154 requirement that the specified components be distinct. As such, the
4155 order requirement ensures that every @nt{array_delta_aggregate} has
4156 a well-defined result, even if the same component is specified multiple
4157 times.]}
4158 @end{Reason}
4159
4160 @end{Runtime}
4161
4162 @begin{Examples}
4163
4164 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4165 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[Simple use in a
4166 postcondition:]}
4167
4168 @begin{Example}
4169 @ChgRef{Version=[5],Kind=[AddedNormal]}
4170 @ChgAdded{Version=[5],Text=[@key[procedure] Twelfth (D : @key[in out] Date) --@Examcom{ see @RefSecNum{Record Types} for type Date}
4171 @key[with] Post => D = (D'Old @key[with delta] Day => 12);]}
4172
4173 @ChgRef{Version=[5],Kind=[AddedNormal]}
4174 @ChgAdded{Version=[5],Text=[@key[procedure] The_Answer (V : @key[in out] Vector; A, B : @key[in] Integer) --@Examcom{ see @RefSecNum{Array Types} for type Vector}
4175 @key[with] Post => V = (V'Old @key[with delta] A .. B => 42.0, V'First => 0.0);]}
4176 @end{Example}
4177
4178 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0324-1],ARef=[AI12-0379-1]}
4179 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[The base expression can
4180 be nontrivial:]}
4181
4182 @begin{Example}
4183 @ChgRef{Version=[5],Kind=[AddedNormal]}
4184 @ChgAdded{Version=[5],Text=[New_Cell : Cell := (Min_Cell (Head) @key[with delta] Value => 42);
4185 --@Examcom{ see @RefSecNum{Incomplete Type Declarations} for Cell and Head; @RefSecNum{Subprogram Declarations} for Min_Cell}]}
4186
4187 @ChgRef{Version=[5],Kind=[AddedNormal]}
4188 @ChgAdded{Version=[5],Text=[A1 : Vector := ((0 => 1.0, 1 => 2.0, 2 => 3.0)
4189 @key[with delta] Integer(Random * 2.0) => 14.2);
4190 --@Examcom{ see @RefSecNum{Array Types} for declaration of type Vector}
4191 --@Examcom{ see @RefSecNum{Subprogram Declarations} for declaration of Random}]}
4192
4193 @ChgRef{Version=[5],Kind=[AddedNormal]}
4194 @ChgAdded{Version=[5],Text=[Tomorrow := ((Yesterday @key[with delta] Day => 12) @key[with delta] Month => Apr); --@Examcom{ see @RefSecNum{Record Types}}]}
4195 @end{Example}
4196
4197 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1],ARef=[AI12-0379-1]}
4198 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[The base expression may
4199 also be class-wide:]}
4200
4201 @begin{Example}
4202 @ChgRef{Version=[5],Kind=[AddedNormal]}
4203 @ChgAdded{Version=[5],Text=[@key[function] Translate (P : Point'Class; X, Y : Real) @key[return] Point'Class @key[is]
4204 (P @key[with delta] X => P.X + X,
4205 Y => P.Y + Y); --@Examcom{ see @RefSecNum{Tagged Types and Type Extensions} for declaration of type Point}]}
4206 @end{Example}
4207 @end{Examples}
4208
4209 @begin{Extend2012}
4210 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0127-1]}
4211 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Delta aggregates
4212 are new.]}
4213 @end{Extend2012}
4214
4215
4216 @LabeledAddedSubClause{Version=[5],Name=[Container Aggregates]}
4217
4218 @begin{Intro}
4219 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4220 @ChgAdded{Version=[5],Text=[In a @nt{container_aggregate}, values are
4221 specified for elements of a
4222 container; for a @nt{positional_container_aggregate}, the elements are given
4223 sequentially; for a @nt{named_container_aggregate}, the elements are
4224 specified by a sequence of key/value pairs, or using an iterator.
4225 The Aggregate aspect of the type of the @nt{aggregate} determines how the
4226 elements are combined to form the container.@Defn{container aggregate}]}
4227
4228 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Container Aggregate>,
4229 Text=<@ChgAdded{Version=[5],Text=[A construct used to define a value of a
4230 type that represents a collection of elements, by explicitly specifying the
4231 elements in the collection.]}>}
4232 @end{Intro}
4233
4234 @Comment{@begin{StaticSem} - This is not in any section, weird,
4235 but it matches Pre and Type_Invariant.}
4236 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4237 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[For a type other
4238 than an array type, the following type-related operational aspect may be
4239 specified:]}
4240
4241 @begin{Description}
4242 @ChgRef{Version=[5],Kind=[AddedNormal]}
4243 @ChgAdded{Version=[5],Type=[Leading],Text=[Aggregate@\This aspect is
4244 an @nt{aggregate} of the form:@AspectDefn{Aggregate}]}
4245
4246 @ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Aggregate],
4247 Text=[@ChgAdded{Version=[5],Text=[Mechanism to define user-defined aggregates.]}]}
4248
4249 @begin{Display}
4250 @ChgRef{Version=[5],Kind=[AddedNormal]}
4251 @ChgAdded{Version=[5],Text=" (Empty => @nt{name}[,
4252 Add_Named => @SynI{procedure_}@nt{name}][,
4253 Add_Unnamed => @SynI{procedure_}@nt{name}][,
4254 New_Indexed => @SynI{function_}@nt{name},
4255 Assign_Indexed => @SynI{procedure_}@nt{name}])"}
4256 @end{Display}
4257
4258 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4259 @ChgAdded{Version=[5],NoPrefix=[T],Text=[The type for which this aspect is
4260 specified is known as the @i<container type> of the Aggregate
4261 aspect.@Defn2{Term=<container type>,Sec=<aggregate aspect>}
4262 A @SynI{procedure_}@nt{name} shall be
4263 specified for at least one of Add_Named, Add_Unnamed, or Assign_Indexed. If
4264 Add_Named is specified, neither Add_Unnamed nor Assign_Indexed shall be
4265 specified. Either both or neither of New_Indexed and Assign_Indexed shall be
4266 specified.]}
4267
4268 @end{Description}
4269 @Comment{@end{StaticSem} - Not in any section.}
4270
4271 @begin{Resolution}
4272
4273 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4274 @ChgAdded{Version=[5],Text=[The @nt{name} specified for Empty for an Aggregate
4275 aspect shall denote a constant of the container type, or denote a function with
4276 a result type of the container type that has no parameters, or that has one
4277 @key[in] parameter of type Integer.]}
4278
4279 @begin{Reason}
4280 @ChgRef{Version=[5],Kind=[AddedNormal]}
4281 @ChgAdded{Version=[5],Text=[In the function case, the parameter, if present
4282 may be used to specify an initial size for the container, in anticipation of
4283 adding elements to it. For a positional aggregate, or a named aggregate that
4284 doesn't use an iterator, it will be initialized with the number of elements.
4285 For a named aggregate that uses an iterator, the implementation is permitted
4286 to estimate the number of elements that the iterator will produce, but it is
4287 not required to do so.]}
4288 @end{Reason}
4289
4290 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4291 @ChgAdded{Version=[5],Text=[The @SynI{procedure_}@nt{name} specified for
4292 Add_Unnamed for an Aggregate aspect shall denote a procedure that has
4293 two parameters, the first
4294 an @key[in out] parameter of the container type, and the second an @key[in] parameter of
4295 some nonlimited type, called the @i<element type> of the container
4296 type.@PDefn2{Term=[element type],Sec=[container aggregate]}]}
4297
4298
4299 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4300 @ChgAdded{Version=[5],Text=[The @SynI{function_}@nt{name} specified for
4301 New_Indexed for an Aggregate aspect shall denote a function with a result
4302 type of the container type, and
4303 two parameters of the same discrete type, with that type being the @i<key type>
4304 of the container type.@PDefn2{Term=[key type],Sec=[container aggregate]}]}
4305
4306 @begin{Reason}
4307 @ChgRef{Version=[5],Kind=[AddedNormal]}
4308 @ChgAdded{Version=[5],Text=[The New_Indexed function is used instead of Empty
4309 as the first step of creating an aggregate that is initialized
4310 using the Assign_Indexed procedure.]}
4311 @end{Reason}
4312
4313 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4314 @ChgAdded{Version=[5],Text=[The @SynI{procedure_}@nt{name} specified for
4315 Add_Named or Assign_Indexed for an Aggregate aspect shall denote a procedure
4316 that has three parameters, the first an @key[in out] parameter of the container
4317 type, the second an @key[in] parameter of a nonlimited type (the @i<key type> of
4318 the container type), and the third, an @key[in] parameter of a nonlimited type
4319 that is called the @i<element type> of the container
4320 type.@PDefn2{Term=[key type],Sec=[container aggregate]}@PDefn2{Term=[element type],Sec=[container aggregate]}]}
4321
4322 @end{Resolution}
4323
4324 @begin{Legality}
4325
4326 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4327 @ChgAdded{Version=[5],Text=[If the container type of an Aggregate aspect is a
4328 private type, the full type of the container type shall not be an array type. If
4329 the container type is limited, the name specified for Empty shall denote a
4330 function rather than a constant object.]}
4331
4332 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4333 @ChgAdded{Version=[5],Text=[For an Aggregate aspect, the key type of
4334 Assign_Indexed shall be the same type as that of the parameters of New_Indexed.
4335 Additionally, if both Add_Unnamed and Assign_Indexed are specified, the final
4336 parameters shall be of the same type @em the element type of the container
4337 type.]}
4338
4339 @end{Legality}
4340
4341
4342
4343 @begin{StaticSem}
4344 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4345 @ChgAdded{Version=[5],Text=[The Aggregate aspect is nonoverridable.]}
4346 @end{StaticSem}
4347
4348 @begin{Syntax}
4349 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4350 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<container_aggregate>,Old=<>}>,
4351 rhs="@Chg{Version=[5],New=[
4352 @Syn2{null_container_aggregate}
4353 | @Syn2{positional_container_aggregate}
4354 | @Syn2{named_container_aggregate}],Old=<>}"}
4355
4356 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4357 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<null_container_aggregate>,Old=<>}>,
4358 rhs="@Chg{Version=[5],New=<'[' ']'>,Old=<>}"}
4359
4360 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4361 @AddedSyn<Version=[5],lhs=<@Chg{Version=[5],New=<positional_container_aggregate>,Old=<>}>,
4362 rhs="@Chg<Version=[5],New=<'[' @Syn2<expression>{, @Syn2<expression>} ']'>,Old=<>>">
4363
4364 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4365 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<named_container_aggregate>,Old=<>}>,
4366 rhs="@Chg{Version=[5],New=<'[' @Syn2<container_element_association_list> ']'>,Old=<>}"}
4367
4368 @begin{Reason}
4369 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4370 @ChgAdded{Version=[5],Text=[Unlike other @nt{aggregate}s, container aggregates
4371 have to be surrounded with brackets rather than parentheses. Using brackets
4372 allows writing zero- and one-element positional @nt{aggregate}s. (Were we to
4373 use parentheses, a one-element positional aggregate would look the same as
4374 and would always be interpreted
4375 as a parenthesized expression.) Unlike the case for arrays, where it is
4376 always possible to give bounds to work around this gap, such an @nt{aggregate}
4377 could not be written at all for a sequence type (such as a list) where there
4378 is no index or key to use.]}
4379 @end{Reason}
4380
4381 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4382 @AddedSyn<Version=[5],lhs=<@Chg{Version=[5],New=<container_element_association_list>,Old=<>}>,
4383 rhs="@Chg<Version=[5],New=<
4384 @Syn2<container_element_association> {, @Syn2<container_element_association>}>,Old=<>>">
4385
4386 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4387 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<container_element_association>,Old=<>}>,
4388 rhs="@Chg{Version=[5],New="
4389 @Syn2{key_choice_list} => @Syn2{expression}
4390 | @Syn2{key_choice_list} => <>
4391 | @Syn2{iterated_element_association}",Old=<>}"}
4392
4393 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4394 @AddedSyn<Version=[5],lhs=<@Chg{Version=[5],New=<key_choice_list>,Old=<>}>,
4395 rhs="@Chg<Version=[5],New="@Syn2<key_choice> {'|' @Syn2<key_choice>}",Old=<>>">
4396
4397 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4398 @AddedSyn<Version=[5],lhs=<@Chg{Version=[5],New=<key_choice>,Old=<>}>,
4399 rhs="@Chg{Version=[5],New="@SynI{key_}@Syn2<expression> | @Syn2<discrete_range>",Old=<>}">
4400
4401 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4402 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<iterated_element_association>,Old=<>}>,
4403 rhs="@Chg{Version=[5],New="
4404 @key[for] @Syn2<loop_parameter_specification>[ @key[use] @SynI{key_}@Syn2<expression>] => @Syn2{expression}
4405 | @key[for] @Syn2<iterator_specification>[ @key[use] @SynI{key_}@Syn2<expression>] => @Syn2{expression}",Old=<>}"}
4406 @end{Syntax}
4407
4408 @begin{Resolution}
4409
4410 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4411 @ChgAdded{Version=[5],Text=[The expected type for a @nt{container_aggregate}
4412 shall be a type for which the Aggregate aspect has been specified. The
4413 expected type for each @nt{expression} of a @nt{container_aggregate} is the
4414 element type of the expected type.]}
4415
4416 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4417 @ChgAdded{Version=[5],Text=[The expected type for a @SynI[key_]@nt{expression},
4418 or a @nt{discrete_range} of a @nt{key_choice}, is the key type of the
4419 expected type of the @nt{aggregate}.]}
4420
4421 @end{Resolution}
4422
4423 @begin{Legality}
4424
4425 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4426 @ChgAdded{Version=[5],Text=[The expected type for a
4427 @nt{positional_container_aggregate} shall have an
4428 Aggregate aspect that includes a specification for an Add_Unnamed
4429 procedure or an Assign_Indexed procedure. The expected type for a
4430 @nt{named_container_aggregate} that contains one or more
4431 @nt{iterated_element_association}s with a @SynI[key_]@nt{expression} shall have an
4432 Aggregate aspect that includes a specification for the Add_Named
4433 procedure. The expected type for a @nt{named_container_aggregate} that
4434 contains one or more @nt{key_choice_list}s shall have an Aggregate aspect
4435 that includes a specification for the Add_Named or Assign_Indexed
4436 procedure. @Redundant[A @nt{null_container_aggregate} can be of any type
4437 with an Aggregate aspect.]]}
4438
4439 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4440 @ChgAdded{Version=[5],Text=[A non-null container aggregate is called an
4441 @i<indexed aggregate> if the@Defn{indexed aggregate}
4442 expected type @i<T> of the aggregate specifies an Assign_Indexed procedure
4443 in its Aggregate aspect, and either there is no Add_Unnamed procedure
4444 specified for the type, or the aggregate is a @nt{named_container_aggregate}
4445 with a @nt{container_element_association} that contains a @nt{key_choice_list}
4446 or a @nt{loop_parameter_specification}. The key type of an indexed aggregate
4447 is also called the @i<index type> of the
4448 aggregate.@Defn2{Term=[index type],Sec=[indexed aggregate]}@Defn2{Term=[index type],Sec=[container aggregate]}]}
4449
4450 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4451 @ChgAdded{Version=[5],Text=[A @nt{container_element_association} with a <>
4452 rather than an @nt{expression}, or with a @nt{key_choice} that is a
4453 @nt{discrete_range}, is permitted only in an indexed aggregate.]}
4454
4455 @begin{Reason}
4456 @ChgRef{Version=[5],Kind=[AddedNormal]}
4457 @ChgAdded{Version=[5],Text=[Only an element of an indexed aggregate can be
4458 left uninitialized, because the compiler can simply omit producing an
4459 Assign_Indexed operation for the given index. For other kinds of
4460 aggregates, there are no operations that add an element without giving
4461 it a value. We could have defined such (optional) operations, but they would
4462 have added significant complication to an already complex feature without
4463 adding much additional expressive power. Note that, to be consistent with
4464 array aggregates, we do not support specifying <> in an
4465 @nt{iterated_element_association}.]}
4466 @end{Reason}
4467
4468 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4469 @ChgAdded{Version=[5],Type=[Leading],Text=[For an
4470 @nt{iterated_element_association} without a @SynI[key_]@nt{expression}, if the
4471 @nt{aggregate} is an indexed aggregate or the expected type of the
4472 @nt{aggregate} specifies an Add_Named procedure in its Aggregate aspect, then
4473 the type of the loop parameter of the @nt{iterated_element_association} shall
4474 be the same as the key type of the @nt{aggregate}.]}
4475
4476 @begin{Ramification}
4477 @ChgRef{Version=[5],Kind=[AddedNormal]}
4478 @ChgAdded{Version=[5],Text=[If there is a @SynI[key_]@nt{expression} in an
4479 @nt{iterated_element_association}, it determines the key of each added
4480 key/value pair, rather than the loop parameter. But if there is no
4481 @SynI[key_]@nt{expression}, the loop parameter itself is used as the key.]}
4482 @end{Ramification}
4483
4484 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1],ARef=[AI12-0250-1]}
4485 @ChgAdded{Version=[5],Type=[Leading],Text=[For a @nt{named_container_aggregate}
4486 that is an indexed aggregate, all @nt{container_element_association}s shall
4487 contain either a @nt{key_choice_list}, or a @nt{loop_parameter_specification}
4488 without a @Syni{key_}@nt{expression} or @nt{iterator_filter}. Furthermore,
4489 for such an aggregate, either:]}
4490 @begin{Itemize}
4491 @ChgRef{Version=[5],Kind=[AddedNormal]}
4492 @ChgAdded{Version=[5],Text=[all @nt{key_choice}s shall be static expressions
4493 or static ranges, and every @nt{loop_parameter_specification} shall have a
4494 @nt{discrete_subtype_definition} that defines a non-null static range,
4495 and the set of values of the index type covered by the
4496 @nt{key_choice}s and the @nt{discrete_subtype_definition}s shall form a
4497 contiguous range of values with no duplications; or]}
4498
4499 @ChgRef{Version=[5],Kind=[AddedNormal]}
4500 @ChgAdded{Version=[5],Text=[there shall be exactly one
4501 @nt{container_element_association}, and if
4502 it has a @nt{key_choice_list}, the list shall have exactly one @nt{key_choice}.]}
4503 @end{Itemize}
4504 @begin{Reason}
4505 @ChgRef{Version=[5],Kind=[AddedNormal]}
4506 @ChgAdded{Version=[5],Text=[The above is trying to mimic the rules for
4507 @nt{named_array_aggregate}s, without @key[others].]}
4508 @end{Reason}
4509
4510 @end{Legality}
4511
4512 @begin{Runtime}
4513
4514 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4515 @ChgAdded{Version=[5],Type=[Leading],Text=[The
4516 evaluation of a @nt{container_aggregate} starts by creating an anonymous
4517 object @i<A> of the expected type @i<T> initialized as follows:]}
4518
4519 @begin{Itemize}
4520
4521 @ChgRef{Version=[5],Kind=[AddedNormal]}
4522 @ChgAdded{Version=[5],Type=[Leading],Text=[if the @nt{aggregate} is an
4523 indexed aggregate, from the result of a call on the New_Indexed function;
4524 the actual parameters in this call represent the lower and upper bound of
4525 the @nt{aggregate}, and are determined as follows:]}
4526 @begin{Itemize} @Comment{2nd level}
4527 @ChgRef{Version=[5],Kind=[AddedNormal]}
4528 @ChgAdded{Version=[5],Text=[if the @nt{aggregate} is a
4529 @nt{positional_container_aggregate}, the lower bound is the low bound of
4530 the subtype of the key parameter of the Add_Indexed procedure, and the
4531 upper bound has a position number that is the sum of the position number
4532 of the lower bound and one less than the number of @nt{expression}s in the
4533 @nt{aggregate};]}
4534
4535 @ChgRef{Version=[5],Kind=[AddedNormal]}
4536 @ChgAdded{Version=[5],Text=[if the @nt{aggregate} is a
4537 @nt{named_container_aggregate}, the lower bound is the lowest value
4538 covered by a @nt{key_choice_list} or is the low bound of a range defined
4539 by a @nt{discrete_subtype_definition} of a
4540 @nt{loop_parameter_specification}; the upper bound is the highest value
4541 covered by a @nt{key_choice_list} or is the high bound of a range defined
4542 by a @nt{discrete_subtype_definition} of a
4543 @nt{loop_parameter_specification}.]}
4544 @end{Itemize} @Comment{2nd level}
4545
4546 @ChgRef{Version=[5],Kind=[AddedNormal]}
4547 @ChgAdded{Version=[5],Type=[Leading],Text=[if the @nt{aggregate} is not an
4548 indexed aggregate, by assignment from the Empty constant, or from a call on
4549 the Empty function specified in the Aggregate aspect. In the case of an
4550 Empty function with a formal parameter, the actual parameter has the
4551 following value:]}
4552
4553 @begin{Itemize} @Comment{2nd level}
4554 @ChgRef{Version=[5],Kind=[AddedNormal]}
4555 @ChgAdded{Version=[5],Text=[for a @nt{null_container_aggregate}, the
4556 value zero;]}
4557
4558 @ChgRef{Version=[5],Kind=[AddedNormal]}
4559 @ChgAdded{Version=[5],Text=[for a @nt{positional_container_aggregate}, the
4560 number of @nt{expression}s;]}
4561
4562 @ChgRef{Version=[5],Kind=[AddedNormal]}
4563 @ChgAdded{Version=[5],Text=[for a @nt{named_container_aggregate} without
4564 an @nt{iterated_element_association}, the number of
4565 @SynI{key_}@nt{expression}s;]}
4566
4567 @ChgRef{Version=[5],Kind=[AddedNormal]}
4568 @ChgAdded{Version=[5],Text=[for a @nt{named_container_aggregate} where
4569 every @nt{iterated_element_association} contains a
4570 @nt{loop_parameter_specification}, the total number of elements specified
4571 by all of the @nt{container_element_association}s;]}
4572
4573 @ChgRef{Version=[5],Kind=[AddedNormal]}
4574 @ChgAdded{Version=[5],Text=[otherwise, to an implementation-defined
4575 value.]}
4576
4577 @begin{ImplNote}
4578 @ChgRef{Version=[5],Kind=[AddedNormal]}
4579 @ChgAdded{Version=[5],Text=[This value ought to be an estimate for the
4580 number of elements in the @nt{aggregate}, if one is available. If not,
4581 it is suggested to use the default value for the parameter
4582 if one exists, and zero otherwise.]}
4583 @end{ImplNote}
4584
4585 @ChgImplDef{Version=[5],Kind=[AddedNormal],InitialVersion=[5],
4586 Text=[@ChgAdded{Version=[5],Text=[The value of the parameter to Empty
4587 for some @nt{container_aggregate}s.]}]}
4588
4589 @end{Itemize} @Comment{2nd level}
4590 @end{Itemize}
4591
4592 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4593 @ChgAdded{Version=[5],Type=[Leading],Text=[The evaluation then proceeds as
4594 follows:]}
4595
4596 @begin{Itemize}
4597 @ChgRef{Version=[5],Kind=[AddedNormal]}
4598 @ChgAdded{Version=[5],Text=[for a @nt{null_container_aggregate}, the
4599 anonymous object @i<A> is the result;]}
4600
4601 @ChgRef{Version=[5],Kind=[AddedNormal]}
4602 @ChgAdded{Version=[5],Text=[for a @nt{positional_container_aggregate} of
4603 a type with a specified Add_Unnamed procedure, each @nt{expression} is
4604 evaluated in an arbitrary order,@PDefn2{Term=[arbitrary order],Sec=[allowed]}
4605 and the Add_Unnamed procedure is invoked in sequence with the
4606 anonymous object @i<A> as the first parameter and the result of
4607 evaluating each @nt{expression} as the second parameter, in the order of
4608 the @nt{expression}s;]}
4609
4610 @ChgRef{Version=[5],Kind=[AddedNormal]}
4611 @ChgAdded{Version=[5],Text=[for a @nt{positional_container_aggregate} that
4612 is an indexed aggregate, each @nt{expression} is evaluated in an arbitrary
4613 order,@PDefn2{Term=[arbitrary order],Sec=[allowed]}
4614 and the Assign_Indexed procedure is invoked in sequence with the
4615 anonymous object @i<A> as the first parameter, the key value as the second
4616 parameter, computed by starting with the low bound of the subtype of
4617 the key formal parameter of the Assign_Indexed procedure and taking
4618 the successor of this value for each successive @nt{expression}, and the
4619 result of evaluating each @nt{expression} as the third parameter;]}
4620
4621 @ChgRef{Version=[5],Kind=[AddedNormal]}
4622 @ChgAdded{Version=[5],Type=[Leading],Text=[for a
4623 @nt{named_container_aggregate} for a type with an Add_Named procedure in its
4624 Aggregate aspect, the @nt{container_element_association}s are evaluated in
4625 an arbitrary order:@PDefn2{Term=[arbitrary order],Sec=[allowed]}]}
4626 @begin{Itemize} @Comment{2nd level}
4627 @ChgRef{Version=[5],Kind=[AddedNormal]}
4628 @ChgAdded{Version=[5],Text=[for a @nt{container_element_association} with
4629 a @nt{key_choice_list}, for each @nt{key_choice} of the list in an
4630 arbitrary order, the @nt{key_choice} is evaluated as is the
4631 @nt{expression} of the @nt{container_element_association} (in an
4632 arbitrary order),@PDefn2{Term=[arbitrary order],Sec=[allowed]}
4633 and the Add_Named procedure is invoked once for each
4634 value covered by the @nt{key_choice}, with the anonymous object @i<A>
4635 as the first parameter, the value from the @nt{key_choice} as the second
4636 parameter, and the result of evaluating the @nt{expression} as the third
4637 parameter;]}
4638
4639 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1],ARef=[AI12-0327-1]}
4640 @ChgAdded{Version=[5],Type=[Leading],Text=[for a
4641 @nt{container_element_association} with an
4642 @nt{iterated_element_association}, first the @nt{iterated_element_association}
4643 is elaborated, then an iteration is performed, and for each value
4644 conditionally produced by the iteration (see
4645 @RefSecNum{Loop Statements} and @RefSecNum{Generalized Loop Iteration})
4646 the Add_Named rocedure is invoked with the anonymous object @i<A> as
4647 the first parameter, the result of evaluating the @nt{expression} as
4648 the third parameter, and:]}
4649
4650 @begin{Itemize} @Comment{3rd level}
4651 @ChgRef{Version=[5],Kind=[AddedNormal]}
4652 @ChgAdded{Version=[5],Text=[if there is a @SynI{key_}@nt{expression}, the
4653 result of evaluating the @SynI{key_}@nt{expression}
4654 as the second parameter;]}
4655
4656 @ChgRef{Version=[5],Kind=[AddedNormal]}
4657 @ChgAdded{Version=[5],Text=[otherwise, with the loop parameter as the
4658 second parameter;]}
4659
4660 @end{Itemize} @Comment{3rd level}
4661 @end{Itemize} @Comment{2nd level}
4662 @ChgRef{Version=[5],Kind=[AddedNormal]}
4663 @ChgAdded{Version=[5],Text=[for a @nt{named_container_aggregate} that is
4664 an indexed aggregate, the evaluation proceeds as above for the case of
4665 Add_Named, but with the Assign_Indexed procedure being invoked in its stead;
4666 in the case of a @nt{container_element_association} with a <> rather than an
4667 @nt{expression}, the corresponding call on Assign_Indexed is not performed,
4668 leaving the component as it was upon return from the New_Indexed function;]}
4669
4670 @ChgRef{Version=[5],Kind=[AddedNormal]}
4671 @ChgAdded{Version=[5],Type=[Leading],Text=[for any other
4672 @nt{named_container_aggregate}, the @nt{container_element_association}s
4673 (which are necessarily @nt{iterated_element_association}s) are evaluated in
4674 the order given; each such evaluation comprises two steps:]}
4675 @begin{Enumerate} @Comment{2nd level}
4676 @ChgRef{Version=[5],Kind=[AddedNormal]}
4677 @ChgAdded{Version=[5],Text=[the @nt{iterated_element_association} is
4678 elaborated;]}
4679
4680 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1],ARef=[AI12-0327-1]}
4681 @ChgAdded{Version=[5],Text=[an iteration is performed, and for each value
4682 conditionally produced by the iteration (see
4683 @RefSecNum{Loop Statements} and @RefSecNum{Generalized Loop Iteration})
4684 the Add_Unnamed
4685 procedure is invoked, with the anonymous object @i<A> as the first
4686 parameter and the result of evaluating the @nt{expression} as the second
4687 parameter.]}
4688
4689 @begin{Ramification}
4690 @ChgRef{Version=[5],Kind=[AddedNormal]}
4691 @ChgAdded{Version=[5],Text=[In this case, the value of the loop parameter
4692 is not directly relevant, though presumably it appears within
4693 the @nt{expression} of the @nt{iterated_element_association}.]}
4694 @end{Ramification}
4695
4696 @end{Enumerate} @Comment{2nd level}
4697 @end{Itemize}
4698
4699 @end{Runtime}
4700
4701
4702 @begin{Examples}
4703
4704 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4705 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[Declarations of
4706 Set_Type, Map_Type, and Vector_Type:]}
4707
4708 @begin{Example}
4709 @ChgRef{Version=[5],Kind=[AddedNormal]}
4710 @ChgAdded{Version=[5],Text=[ -- @Examcom<Set_Type is a set-like container type.>
4711 @key[type] Set_Type @key[is private]
4712 @key[with] Aggregate => (Empty => Empty_Set,
4713 Add_Unnamed => Include);
4714 @key[function] Empty_Set @key[return] Set_Type;]}
4715
4716 @ChgRef{Version=[5],Kind=[AddedNormal]}
4717 @ChgAdded{Version=[5],Text=[ @key[subtype] Small_Natural @key[is] Natural @key[range] 0..1000;]}
4718
4719 @ChgRef{Version=[5],Kind=[AddedNormal]}
4720 @ChgAdded{Version=[5],Text=[ @key[procedure] Include (S : @key[in out] Set_Type; N : @key[in] Small_Natural);]}
4721
4722 @ChgRef{Version=[5],Kind=[AddedNormal]}
4723 @ChgAdded{Version=[5],Text=[ -- @Examcom<Map_Type is a map-like container type.>
4724 @key[type] Map_Type @key[is private]
4725 @key[with] Aggregate => (Empty => Empty_Map,
4726 Add_Named => Add_To_Map);]}
4727
4728 @ChgRef{Version=[5],Kind=[AddedNormal]}
4729 @ChgAdded{Version=[5],Text=[ @key[procedure] Add_To_Map (M : @key[in out] Map_Type; Key : @key[in] Integer; Value : @key[in] String);]}
4730
4731 @ChgRef{Version=[5],Kind=[AddedNormal]}
4732 @ChgAdded{Version=[5],Text=[ Empty_Map : @key[constant] Map_Type;]}
4733
4734 @ChgRef{Version=[5],Kind=[AddedNormal]}
4735 @ChgAdded{Version=[5],Text=[ -- @examcom<Vector_Type is an extensible array-like container type.>
4736 @key[type] Vector_Type @key[is private]
4737 @key[with] Aggregate => (Empty => Empty_Vector,
4738 Add_Unnamed => Append_One,
4739 New_Indexed => New_Vector,
4740 Assign_Indexed => Assign_Element);]}
4741
4742 @ChgRef{Version=[5],Kind=[AddedNormal]}
4743 @ChgAdded{Version=[5],Text=[ @key[function] Empty_Vector (Capacity : Count_Type := 0) @key[return] Vector_Type;]}
4744
4745 @ChgRef{Version=[5],Kind=[AddedNormal]}
4746 @ChgAdded{Version=[5],Text=[ @key[procedure] Append_One (V : @key[in out] Vector_Type; New_Item : @key[in] String);]}
4747
4748 @ChgRef{Version=[5],Kind=[AddedNormal]}
4749 @ChgAdded{Version=[5],Text=[ @key[procedure] Assign_Element (V : @key[in out] Vector_Type;
4750 Index : @key[in] Positive;
4751 Item : @key[in] String);]}
4752
4753 @ChgRef{Version=[5],Kind=[AddedNormal]}
4754 @ChgAdded{Version=[5],Text=[ @key[function] New_Vector (First, Last : Positive) @key[return] Vector_Type
4755 @key[with] Pre => First = Positive'First;
4756 -- @examcom<Vectors are always indexed starting at the>
4757 -- @examcom<lower bound of their index subtype.>]}
4758
4759 @ChgRef{Version=[5],Kind=[AddedNormal]}
4760 @ChgAdded{Version=[5],Text=[-- @examcom{Private part not shown.}]}
4761
4762 @end{Example}
4763
4764 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4765 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[Examples of
4766 container aggregates for Set_Type, Map_Type, and Vector_Type:]}
4767
4768 @begin{Example}
4769 @ChgRef{Version=[5],Kind=[AddedNormal]}
4770 @ChgAdded{Version=[5],Text=[-- @examcom<Example aggregates using Set_Type.>
4771 S : Set_Type;]}
4772
4773 @ChgRef{Version=[5],Kind=[AddedNormal]}
4774 @ChgAdded{Version=[5],Text=<-- @examcom<Assign the empty set to S:>
4775 S := [];>}
4776
4777 @ChgRef{Version=[5],Kind=[AddedNormal]}
4778 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4779 S := Empty_Set;]}
4780
4781 @ChgRef{Version=[5],Kind=[AddedNormal]}
4782 @ChgAdded{Version=[5],Text=<-- @examcom<A positional set aggregate:>
4783 S := [1, 2];>}
4784
4785 @ChgRef{Version=[5],Kind=[AddedNormal]}
4786 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4787 S := Empty_Set;
4788 Include (S, 1);
4789 Include (S, 2);]}
4790
4791 @ChgRef{Version=[5],Kind=[AddedNormal]}
4792 @ChgAdded{Version=[5],Text="-- @examcom<A set aggregate with an >@nt{iterated_element_association}@examcom<:>
4793 S := [@key[for] Item @key[in] 1 .. 5 => Item * 2];"}
4794
4795 @ChgRef{Version=[5],Kind=[AddedNormal]}
4796 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4797 S := Empty_Set;
4798 @key[for] Item @key[in] 1 .. 5 @key[loop]
4799 Include (S, Item * 2);
4800 @key[end loop];]}
4801
4802 @ChgRef{Version=[5],Kind=[AddedNormal]}
4803 @ChgAdded{Version=[5],Text="-- @examcom<A set aggregate consisting of two >@nt{iterated_element_association}@examcom<s:>
4804 S := [@key[for] Item @key[in] 1 .. 5 => Item,
4805 @key[for] Item @key[in] 1 .. 5 => -Item];"}
4806
4807 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0379-1]}
4808 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent (assuming set semantics) to:>
4809 S := Empty_Set;
4810 @key[for] Item @key[in] -5 .. 5 @key[loop]
4811 @key[if] Item /= 0 @key[then]
4812 Include (S, Item);
4813 @key[end if];
4814 @key[end loop];]}
4815
4816 @ChgRef{Version=[5],Kind=[AddedNormal]}
4817 @ChgAdded{Version=[5],Text=[-- @examcom<Example aggregates using Map_Type.>
4818 M : Map_Type;]}
4819
4820 @ChgRef{Version=[5],Kind=[AddedNormal]}
4821 @ChgAdded{Version=[5],Text=`-- @examcom<A simple named map aggregate:>
4822 M := [12 => "house", 14 => "beige"];'}
4823
4824 @ChgRef{Version=[5],Kind=[AddedNormal]}
4825 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4826 M := Empty_Map;
4827 Add_To_Map (M, 12, "house");
4828 Add_To_Map (M, 14, "beige");]}
4829
4830 @ChgRef{Version=[5],Kind=[AddedNormal]}
4831 @ChgAdded{Version=[5],Text=[-- @examcom<Define a table of pairs:>
4832 @key[type] Pair @key[is record]
4833 Key : Integer;
4834 Value : @key[access constant] String;
4835 @key[end record];]}
4836
4837 @ChgRef{Version=[5],Kind=[AddedNormal]}
4838 @ChgAdded{Version=[5],Text={Table : @key[constant array](Positive @key[range] <>) @key[of] Pair :=
4839 [(Key => 33, Value => @key[new] String'("a nice string")),
4840 (Key => 44, Value => @key[new] String'("an even better string"))];}}
4841
4842 @ChgRef{Version=[5],Kind=[AddedNormal]}
4843 @ChgAdded{Version=[5],Text="-- @examcom<A map aggregate using an >@nt<iterated_element_association>
4844 -- @examcom<and a key_>@nt{expression}@examcom<, built from from a table of key/value pairs:>
4845 M := [@key[for] P @key[of] Table @key[use] P.Key => P.Value.@key[all]];"}
4846
4847 @ChgRef{Version=[5],Kind=[AddedNormal]}
4848 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4849 M := Empty_Map;
4850 @key[for] P @key[of] Table @key[loop]
4851 Add_To_Map (M, P.Key, P.Value.@key[all]);
4852 @key[end loop];]}
4853
4854 @ChgRef{Version=[5],Kind=[AddedNormal]}
4855 @ChgAdded{Version=[5],Text="-- @examcom<Create an image table for an array of integers:>
4856 Keys : @key[constant array](Positive @key[range] <>) @key[of] Integer := [2, 3, 5, 7, 11];"}
4857
4858 @ChgRef{Version=[5],Kind=[AddedNormal]}
4859 @ChgAdded{Version=[5],Text="-- @examcom<A map aggregate where the values produced by the>
4860 -- @nt{iterated_element_association}@examcom< are of the same type as the key>
4861 -- @examcom<(eliminating the need for a separate key_>@nt{expression}@examcom<):>
4862 M := [@key[for] Key @key[of] Keys => Integer'Image (Key)];"}
4863
4864 @ChgRef{Version=[5],Kind=[AddedNormal]}
4865 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4866 M := Empty_Map;
4867 @key[for] Key @key[of] Keys @key[loop]
4868 Add_To_Map (M, Key, Integer'Image (Key));
4869 @key[end loop];]}
4870
4871 @ChgRef{Version=[5],Kind=[AddedNormal]}
4872 @ChgAdded{Version=[5],Text=[-- @examcom<Example aggregates using Vector_Type.>
4873 V : Vector_Type;]}
4874
4875 @ChgRef{Version=[5],Kind=[AddedNormal]}
4876 @ChgAdded{Version=[5],Text=`-- @examcom<A positional vector aggregate:>
4877 V := ["abc", "def"];'}
4878
4879 @ChgRef{Version=[5],Kind=[AddedNormal]}
4880 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4881 V := Empty_Vector (2);
4882 Append_One (V, "abc");
4883 Append_One (V, "def");]}
4884
4885 @ChgRef{Version=[5],Kind=[AddedNormal]}
4886 @ChgAdded{Version=[5],Text=`-- @examcom<An indexed vector aggregate:>
4887 V := [1 => "this", 2 => "is", 3 => "a", 4 => "test"];'}
4888
4889 @ChgRef{Version=[5],Kind=[AddedNormal]}
4890 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4891 V := New_Vector (1, 4);
4892 Assign_Element (V, 1, "this");
4893 Assign_Element (V, 2, "is");
4894 Assign_Element (V, 3, "a");
4895 Assign_Element (V, 4, "test");]}
4896
4897 @ChgRef{Version=[5],Kind=[AddedNormal]}
4898 @ChgAdded{Version=[5],Text="-- @examcom<A vector made from the elements of a map:>
4899 V := [@key[for] Elem @key[of] M => Elem];"}
4900
4901 @ChgRef{Version=[5],Kind=[AddedNormal]}
4902 @ChgAdded{Version=[5],Text=[-- @examcom<Is equivalent to:>
4903 V := Empty_Vector (<estimate of size of M>);
4904 @key[for] Elem @key[of] M @key[loop]
4905 Add_Positional (V, Elem);
4906 @key[end loop];]}
4907 @end{Example}
4908
4909 @end{Examples}
4910
4911
4912
4913
4914 @begin{Extend2012}
4915 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0212-1]}
4916 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Container aggregates
4917 are new.]}
4918 @end{Extend2012}
4919
4920
4921 @LabeledClause{Expressions}
4922
4923 @begin{Intro}
4924 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0147-1],ARef=[AI05-0158-1],ARef=[AI05-0176-1]}
4925 @Defn{expression}
4926 An @i(expression) is a formula that defines the computation or retrieval
4927 of a value.
4928 In this International Standard, the term @lquotes@;expression@rquotes@; refers to a construct
4929 of the syntactic category @nt<expression> or of any of the
4930 @Chg{Version=[3],New=[following categories: @nt{choice_expression}, @nt{choice_relation},
4931 @nt{relation}, @nt{simple_expression}, @nt{term}, @nt{factor}, @nt{primary},
4932 @nt{conditional_expression}, @nt{quantified_expression}],Old=[other five syntactic categories defined
4933 below]}.
4934 @Defn{and operator}@Defn2{Term=[operator],Sec=(and)}
4935 @Defn{or operator}@Defn2{Term=[operator],Sec=(or)}
4936 @Defn{xor operator}@Defn2{Term=[operator],Sec=(xor)}
4937 @Defn{and then (short-circuit control form)}
4938 @Defn{or else (short-circuit control form)}
4939 @Defn{= operator}@Defn2{Term=[operator],Sec=(=)}
4940 @Defn{equal operator}@Defn2{Term=[operator],Sec=(equal)}
4941 @Defn{/= operator}@Defn2{Term=[operator],Sec=(/=)}
4942 @Defn{not equal operator}@Defn2{Term=[operator],Sec=(not equal)}
4943 @Defn{< operator}@Defn2{Term=[operator],Sec=(<)}
4944 @Defn{less than operator}@Defn2{Term=[operator],Sec=(less than)}
4945 @Defn{<= operator}@Defn2{Term=[operator],Sec=(<=)}
4946 @Defn{less than or equal operator}@Defn2{Term=[operator],Sec=(less than or equal)}
4947 @Defn{> operator}@Defn2{Term=[operator],Sec=(>)}
4948 @Defn{greater than operator}@Defn2{Term=[operator],Sec=(greater than)}
4949 @Defn{>= operator}@Defn2{Term=[operator],Sec=(>=)}
4950 @Defn{greater than or equal operator}@Defn2{Term=[operator],Sec=(greater than or equal)}
4951 @Defn{in (membership test)}
4952 @Defn{not in (membership test)}
4953 @Defn{+ operator}@Defn2{Term=[operator],Sec=(+)}
4954 @Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)}
4955 @Defn{- operator}@Defn2{Term=[operator],Sec=(-)}
4956 @Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)}
4957 @Defn{& operator}@Defn2{Term=[operator],Sec=(&)}
4958 @Defn{ampersand operator}@Defn2{Term=[operator],Sec=(ampersand)}
4959 @Defn{concatenation operator}@Defn2{Term=[operator],Sec=(concatenation)}
4960 @IndexSee{Term=[catenation operator],See=(concatenation operator)}
4961 @Defn{* operator}@Defn2{Term=[operator],Sec=(*)}
4962 @Defn{multiply operator}@Defn2{Term=[operator],Sec=(multiply)}
4963 @Defn{times operator}@Defn2{Term=[operator],Sec=(times)}
4964 @Defn{/ operator}@Defn2{Term=[operator],Sec=(/)}
4965 @Defn{divide operator}@Defn2{Term=[operator],Sec=(divide)}
4966 @Defn{mod operator}@Defn2{Term=[operator],Sec=(mod)}
4967 @Defn{rem operator}@Defn2{Term=[operator],Sec=(rem)}
4968 @Defn{** operator}@Defn2{Term=[operator],Sec=(**)}
4969 @Defn{exponentiation operator}@Defn2{Term=[operator],Sec=(exponentiation)}
4970 @Defn{abs operator}@Defn2{Term=[operator],Sec=(abs)}
4971 @Defn{absolute value}
4972 @Defn{not operator}@Defn2{Term=[operator],Sec=(not)}
4973 @end{Intro}
4974
4975 @begin{Syntax}
4976 @Syn{tabs=[P23], lhs=<expression>,rhs="
4977 @Syn2{relation} {@key{and} @Syn2{relation}} @\| @Syn2{relation} {@key{and} @key{then} @Syn2{relation}}
4978 | @Syn2{relation} {@key{or} @Syn2{relation}} @\| @Syn2{relation} {@key{or} @key{else} @Syn2{relation}}
4979 | @Syn2{relation} {@key{xor} @Syn2{relation}}"}
4980
4981 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
4982 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<choice_expression>,Old=<>}>,
4983 rhs="@Chg{Version=[3],New=<
4984 @Syn2[choice_relation] {@key[and] @Syn2[choice_relation]}
4985 | @Syn2[choice_relation] {@key[or] @Syn2[choice_relation]}
4986 | @Syn2[choice_relation] {@key[xor] @Syn2[choice_relation]}
4987 | @Syn2[choice_relation] {@key[and then] @Syn2[choice_relation]}
4988 | @Syn2[choice_relation] {@key[or else] @Syn2[choice_relation]}>,Old=<>}"}
4989
4990 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
4991 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<choice_relation>,Old=<>}>,
4992 rhs="@Chg{Version=[3],New=<
4993 @Syn2{simple_expression} [@Syn2{relational_operator} @Syn2{simple_expression}]>,Old=<>}"}
4994
4995 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
4996 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0022-1],ARef=[AI12-0039-1]}
4997 @Syn{lhs=<relation>,rhs="
4998 @Syn2{simple_expression} [@Syn2{relational_operator} @Syn2{simple_expression}]
4999 | @Chg{Version=[4],New=[@SynI{tested_}@Syn2{simple_expression}],Old=[@Syn2{simple_expression}]} [@key{not}] @key{in} @Chg{Version=[3],New=[@Syn2{membership_choice_list}@Chg{Version=[4],New=[
5000 | @Syn2{raise_expression}],Old=[]}],Old="@Syn2{range}
5001 | @Syn2{simple_expression} [@key{not}] @key{in} @Syn2{subtype_mark}"}"}
5002
5003 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
5004 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0212-1]}
5005 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<membership_choice_list>,Old=<>}>,
5006 rhs="@Chg{Version=[3],New=<@Syn2{membership_choice} {@Chg{Version=[5],New=['|'],Old=[|]} @Syn2{membership_choice}}>,Old=<>}"}
5007
5008 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
5009 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
5010 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<membership_choice>,Old=<>}>,
5011 rhs="@Chg{Version=[3],New=<@Chg{Version=[4],New=<@SynI{choice_}@Syn2{simple_expression}>,Old=<@Syn2{choice_expression}>} | @Syn2{range} | @Syn2{subtype_mark}>,Old=<>}"}
5012
5013 @Syn{lhs=<simple_expression>,rhs="[@Syn2{unary_adding_operator}] @Syn2{term} {@Syn2{binary_adding_operator} @Syn2{term}}"}
5014
5015
5016 @Syn{lhs=<term>,rhs="@Syn2{factor} {@Syn2{multiplying_operator} @Syn2{factor}}"}
5017
5018
5019 @Syn{lhs=<factor>,rhs="@Syn2{primary} [** @Syn2{primary}] | @key{abs} @Syn2{primary} | @key{not} @Syn2{primary}"}
5020
5021 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0003-1],ARef=[AI05-0147-1],ARef=[AI05-0176-1]}
5022 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0236-1]}
5023 @Syn{lhs=<primary>,rhs="
5024 @Syn2{numeric_literal} | @key{null} | @Syn2{string_literal} | @Syn2{aggregate}
5025 | @Syn2{name} | @Chg{Version=[3],New=[],Old=[@Syn2{qualified_expression} | ]}@Syn2{allocator} | (@Syn2{expression})@Chg{Version=[3],New=[
5026 | (@Syn2{conditional_expression}) | (@Syn2{quantified_expression})],Old=[]}@Chg{Version=[5],New=[
5027 | (@Syn2{declare_expression})],Old=[]}"}
5028 @end{Syntax}
5029
5030 @begin{Resolution}
5031 A @nt<name> used as a @nt<primary> shall resolve to denote an object
5032 or a value.
5033 @begin{Discussion}
5034 This replaces RM83-4.4(3). We don't need to mention named numbers
5035 explicitly, because the name of a named number denotes a value.
5036 We don't need to mention attributes explicitly, because
5037 attributes now denote (rather than yield) values in general.
5038 Also, the new wording allows attributes that denote objects,
5039 which should always have been allowed (in case the implementation chose to
5040 have such a thing).
5041 @end{Discussion}
5042 @begin{Reason}
5043 It might seem odd that this is an overload resolution rule,
5044 but it is relevant during overload resolution. For example,
5045 it helps ensure that a @nt<primary> that consists of only
5046 the identifier of a parameterless function is interpreted as a
5047 @nt<function_call> rather than directly as a @nt<direct_name>.
5048 @end{Reason}
5049 @end{Resolution}
5050
5051 @begin{StaticSem}
5052 Each expression has a type; it specifies the
5053 computation or retrieval of a value of that type.
5054
5055 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0317-1]}
5056 @ChgAdded{Version=[5],Text=[A @nt{primary} that is an @nt{expression}
5057 surrounded by ( and ) is known as a
5058 @i{parenthesized expression}.@Defn{parenthesized expression}@Defn2{Term=[expression],Sec=[parenthesized]}]}
5059
5060 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0317-1]}
5061 @ChgAdded{Version=[5],Type=[Leading],Text=[Every @nt{name} or @nt{expression}
5062 consists of one or more @i<operative constituent> @nt{name}s or @nt{expression}s, only
5063 one of which is evaluated as part of evaluating the @nt{name} or
5064 @nt{expression} (the @i<evaluated operative constituent>). The operative
5065 constituents are determined as follows, according to the form of the @nt{expression}
5066 (or@Defn{operative constituent}@Defn{evaluated operative constituent}
5067 @Defn2{Term=[constituent],Sec=[operative]}@nt{name}):]}
5068
5069 @begin{Itemize}
5070 @ChgRef{Version=[5],Kind=[Added]}
5071 @ChgAdded{Version=[5],Text=[if the @nt{expression} is a
5072 @nt{conditional_expression}, the operative constituents of its
5073 @SynI{dependent_}@nt{expression}s;]}
5074
5075 @ChgRef{Version=[5],Kind=[Added]}
5076 @ChgAdded{Version=[5],Text=[if the @nt{expression} (or @nt{name}) is a
5077 parenthesized expression, a @nt{qualified_expression}, or a view conversion,
5078 the operative constituent(s) of its operand;]}
5079
5080 @ChgRef{Version=[5],Kind=[Added]}
5081 @ChgAdded{Version=[5],Text=[if the @nt{expression} is a
5082 @nt{declare_expression}, the operative constituent(s) of its
5083 @Syni{body_}@nt{expression};]}
5084
5085 @ChgRef{Version=[5],Kind=[Added]}
5086 @ChgAdded{Version=[5],Text=[otherwise, the @nt{expression} (or @nt{name})
5087 itself.]}
5088 @end{Itemize}
5089
5090 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0317-1]}
5091 @ChgAdded{Version=[5],Text=[In certain contexts, we specify that an operative
5092 constituent
5093 shall (or shall not) be @i{newly constructed}.@Defn{newly constructed} This
5094 means the operative constituent shall (or shall not) be an @nt{aggregate} or a
5095 @nt{function_call}; in either case, a @nt{raise_expression} is permitted.]}
5096
5097 @begin{Honest}
5098 @ChgRef{Version=[5],Kind=[AddedNormal]}
5099 @ChgAdded{Version=[5],Text=[If an @nt{if_expression} does not have an
5100 @key[else] clause, "True" is a opertive constituent of the @nt{expression} and
5101 it can be the evaluated operative constituent.]}
5102 @end{Honest}
5103
5104 @end{StaticSem}
5105
5106 @begin{RunTime}
5107 @PDefn2{Term=[evaluation], Sec=(primary that is a name)}
5108 The value of a @nt<primary> that is a @nt{name} denoting an object
5109 is the value of the object.
5110
5111 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0227-1]}
5112 @ChgAdded{Version=[5],Text=[An expression of a numeric universal type is
5113 evaluated as if it has type @i<root_integer> (for @i<universal_integer>) or
5114 @i<root_real> (otherwise) unless the context identifies a specific type (in
5115 which case that type is used).]}
5116
5117 @begin{Ramification}
5118 @ChgRef{Version=[5],Kind=[AddedNormal]}
5119 @ChgAdded{Version=[5],Text=[This has no effect for a static expression; its
5120 value may be arbitrarily small or large since no specific type is expected
5121 for any expression for which this rule specifies one of the root types. The
5122 only effect of this rule is to allow Constraint_Error to be raised if the
5123 value is outside of the base range of @i<root_integer> or @i<root_real> when
5124 the expression is not static.]}
5125 @end{Ramification}
5126
5127 @begin{Reason}
5128 @ChgRef{Version=[5],Kind=[AddedNormal]}
5129 @ChgAdded{Version=[5],Text=[This rule means that implementations don't have
5130 to support unlimited range math at run time for universal expressions. Note
5131 that universal expressions for which the context doesn't specify a specific
5132 type are quite rare; attribute prefixes and results are the only known
5133 cases. (For operators, @RefSecNum{The Context of Overload Resolution}
5134 already specifies that the operator of a root type be used, which provides
5135 a specific type.)]}
5136 @end{Reason}
5137 @end{RunTime}
5138
5139 @begin{ImplPerm}
5140 @IndexCheck{Overflow_Check}
5141 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
5142 For the evaluation of
5143 a @nt<primary> that is a @nt<name> denoting an object of an
5144 unconstrained numeric subtype,
5145 if the value of the object is outside the base range of its type,
5146 the implementation may either raise Constraint_Error
5147 or return the value of the object.
5148 @begin{Ramification}
5149 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
5150 This means that if extra-range intermediates are used to
5151 hold the value of an object of an unconstrained numeric subtype,
5152 a Constraint_Error can be raised on a read of the object, rather than
5153 only on an assignment to it. Similarly, it means that
5154 computing the value of an object of such a subtype
5155 can be deferred until the first read of the object
5156 (presuming no side effects other than failing an Overflow_Check
5157 are possible). This permission is over and above that provided
5158 by @Chg{Version=[3],New=[subclause],Old=[clause]}
5159 @RefSecNum(Exceptions and Optimization), since
5160 this allows the Constraint_Error to move to a different handler.
5161 @end{Ramification}
5162 @begin{Reason}
5163 This permission is intended to allow extra-range registers
5164 to be used efficiently to hold parameters and local variables,
5165 even if they might need to be transferred into smaller registers
5166 for performing certain predefined operations.
5167 @end{Reason}
5168 @begin{Discussion}
5169 There is no need to mention other kinds of @nt<primary>s, since any
5170 Constraint_Error to be raised can be @lquotes@;charged@rquotes@; to the evaluation
5171 of the particular kind of @nt<primary>.
5172 @end{Discussion}
5173 @end{ImplPerm}
5174
5175 @begin{Examples}
5176 @Leading@keepnext@i(Examples of primaries:)
5177 @begin{Example}
5178 @Trailing@;4.0 --@RI[ real literal]
5179 Pi --@RI[ named number]
5180 (1 .. 10 => 0) --@RI[ array aggregate]
5181 Sum --@RI[ variable]
5182 Integer'Last --@RI[ attribute]
5183 Sine(X) --@RI[ function call]
5184 Color'(Blue) --@RI[ qualified expression]
5185 Real(M*N) --@RI[ conversion]
5186 (Line_Count + 10) --@RI[ parenthesized expression ]
5187 @end{Example}
5188
5189 @leading@keepnext@i(Examples of expressions:)
5190 @begin{Example}
5191 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
5192 Volume --@RI[ primary]
5193 @key(not) Destroyed --@RI[ factor]
5194 2*Line_Count --@RI[ term]
5195 -4.0 --@RI[ simple expression]
5196 -4.0 + A --@RI[ simple expression]
5197 B**2 - 4.0*A*C --@RI[ simple expression]@Chg{Version=[2],New=[
5198 R*Sin(@unicode<952>)*Cos(@unicode<966>) --@RI[ simple expression]],Old=[]}
5199 Password(1 .. 3) = "Bwv" --@RI[ relation]
5200 Count @key(in) Small_Int --@RI[ relation]
5201 Count @key(not) @key(in) Small_Int --@RI[ relation]
5202 Index = 0 @key(or) Item_Hit --@RI[ expression]
5203 (Cold @key(and) Sunny) @key(or) Warm --@RI[ expression (parentheses are required)]
5204 A**(B**C) --@RI[ expression (parentheses are required)]
5205 @end{Example}
5206 @end{Examples}
5207
5208 @begin{Extend83}
5209 @Defn{extensions to Ada 83}
5210 In Ada 83, @key{out} parameters and their nondiscriminant
5211 subcomponents are not allowed as @ntf{primaries}.
5212 These restrictions are eliminated in Ada 95.
5213
5214 In various contexts throughout the language where Ada 83 syntax rules
5215 had @nt<simple_expression>, the corresponding Ada 95 syntax
5216 rule has @nt<expression> instead. This reflects the inclusion
5217 of modular integer types, which makes the logical operators
5218 "@key[and]", "@key[or]", and "@key[xor]" more useful in expressions of
5219 an integer type.
5220 Requiring parentheses to use these operators in such contexts
5221 seemed unnecessary and potentially confusing.
5222 Note that the bounds of a @nt<range> still have to be
5223 specified by @nt<simple_expression>s, since otherwise @nt<expression>s
5224 involving membership tests might be ambiguous.
5225 Essentially, the operation ".." is of higher precedence than the
5226 logical operators, and hence uses of logical operators
5227 still have to be parenthesized when used in a bound of a range.
5228 @end{Extend83}
5229
5230 @begin{DiffWord2005}
5231 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0003-1]}
5232 @ChgAdded{Version=[3],Text=[Moved @nt{qualified_expression}
5233 from @nt{primary} to @nt{name} (see @RefSecNum{Names}). This allows the
5234 use of @nt{qualified_expression}s in more places.]}
5235
5236 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0176-1]}
5237 @ChgAdded{Version=[3],Text=[Added @nt{conditional_expression} and
5238 @nt{quantified_expression} to @nt{primary}.]}
5239
5240 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
5241 @ChgAdded{Version=[3],Text=[Expanded membership test syntax (see
5242 @RefSecNum{Relational Operators and Membership Tests}).]}
5243 @end{DiffWord2005}
5244
5245 @begin{Inconsistent2012}
5246 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0039-1]}
5247 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
5248 Revised membership syntax to eliminate ambiguities. In some cases,
5249 previously ambiguous membership expressions will now have an unambiguous
5250 meaning. If an Ada 2012 implementation chose the "wrong" meaning, the
5251 expression could silently change meaning. Virtually all such expressions
5252 will become illegal because of type mismatches (and thus be incompatible,
5253 not inconsistent). However, if the choices
5254 are all of a Boolean type, resolution might succeed. For instance, @exam{A
5255 @key[in] B | C @key[and] D} now always means @exam{(A @key[in] B | C)
5256 @key[and] D}, but the original Ada 2012 syntax would have allowed it to mean
5257 @exam{A @key[in] B | (C @key[and] D)}. If a compiler allowed the expression
5258 and interpreted it as the latter, the meaning of the expression would silently
5259 change. We expect this to be extremely rare as membership operations on
5260 Boolean types are unlikely (and this can happen only in code written for Ada
5261 2012).]}
5262 @end{Inconsistent2012}
5263
5264 @begin{Incompatible2012}
5265 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0039-1]}
5266 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
5267 The revised membership syntax will require
5268 parentheses in @nt{membership_choice_list}s in some cases where the
5269 Ada 2012 grammar did not require them. For instance,
5270 @exam{A @key[in] B @key[in] C | D}
5271 is now illegal. However, such expressions can be interpreted in multiple ways
5272 (either @exam{A @key[in] (B @key[in] C) | D} or
5273 @exam{A @key[in] (B @key[in] C | D)} for this example), so using such
5274 expressions is likely to be dangerous (another compiler might interpret the
5275 expression differently). In addition, all such expressions occur only in
5276 Ada 2012 syntax; so they should be rare.]}
5277 @end{Incompatible2012}
5278
5279 @begin{Diffword2012}
5280 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0227-1]}
5281 @ChgAdded{Version=[5],Text=[@b<Correction:> Added wording so that universal
5282 expressions evaluated at run time can raise Constraint_Error if the value is
5283 outside of the range of @i<root_integer> or @i<root_real>. We don't document
5284 this as an inconsistency because the rule requires no implementation to change
5285 (as Constraint_Error is not required); it just allows implementations that
5286 already raise Constraint_Error (which is all of them surveyed) to be
5287 considered correct.]}
5288
5289 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
5290 @ChgAdded{Version=[5],Text=[Added @nt{declare_expression} to @nt{primary}.
5291 It shares the rules about parentheses with @nt{conditional_expression}s.]}
5292
5293 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0317-1]}
5294 @ChgAdded{Version=[5],Text=[Added the definitions of
5295 @ldquote@;operative constituent@rdquote and @ldquote@;newly constructed@rdquote
5296 to centralize definitions that are needed for various rules and definitions
5297 across the Standard. In particular, @i<operative constituent> is often used
5298 when we want the semantics or legality to be unchanged by the presence
5299 of parens, qualification, or view conversions. Examples are found in
5300 @RefSecNum{Extension Aggregates}, @RefSecNum{Formal Parameter Modes},
5301 and @RefSecNum{Limited Types}.]}
5302 @end{Diffword2012}
5303
5304
5305 @LabeledClause{Operators and Expression Evaluation}
5306
5307 @begin{Intro}
5308 @Redundant[@Defn{precedence of operators}
5309 @Defn{operator precedence}
5310 The language defines the following six categories
5311 of operators (given in order of increasing
5312 precedence). The corresponding @nt<operator_symbol>s,
5313 and only those, can be used as @nt<designator>s in declarations
5314 of functions for user-defined operators. See @RefSec(Overloading of Operators).]
5315 @end{Intro}
5316
5317 @begin{Syntax}
5318 @Syn{tabs=[P36], lhs=<logical_operator>,
5319 rhs="@\ @key{and} | @key{or} | @key{xor}"}
5320 @Syn{tabs=[P36], lhs=<relational_operator>,rhs="@\ = | /= | < | <= | > | >="}
5321 @Syn{tabs=[P36], lhs=<binary_adding_operator>,rhs="@\ + | @en | &"}
5322 @Syn{tabs=[P36], lhs=<unary_adding_operator>,rhs="@\ + | @en"}
5323 @Syn{tabs=[P36], lhs=<multiplying_operator>,rhs="@\ * | / | @key{mod} | @key{rem}"}
5324 @Syn{tabs=[P36], lhs=<highest_precedence_operator>,rhs="@\ ** | @key{abs} | @key{not}"}
5325 @begin(Discussion)
5326 Some of the above syntactic categories are not used in other
5327 syntax rules. They are just used for classification.
5328 The others are used for both classification and parsing.
5329 @end(Discussion)
5330 @end{Syntax}
5331
5332 @begin{StaticSem}
5333 For a sequence of operators of the same precedence level, the
5334 operators are associated with their operands
5335 in textual order from left to right.
5336 Parentheses can be used to impose specific associations.
5337 @begin{Discussion}
5338 The left-associativity is not directly inherent in the grammar of
5339 @RefSecNum{Expressions},
5340 though in @RefSecNum{Method of Description and Syntax Notation}
5341 the definition of the metasymbols @b({}) implies left
5342 associativity. So this could be seen as redundant, depending on
5343 how literally one interprets the definition of the @b({}) metasymbols.
5344
5345 See the Implementation Permissions below regarding flexibility
5346 in reassociating operators of the same precedence.
5347 @end{Discussion}
5348
5349 @Defn{predefined operator}@Defn2{Term=[operator],Sec=(predefined)}
5350 For each form of type definition, certain of the above operators are
5351 @i(predefined);
5352 that is, they are implicitly declared immediately after the type definition.
5353 @Defn{binary operator}@Defn2{Term=[operator],Sec=(binary)}
5354 @Defn{unary operator}@Defn2{Term=[operator],Sec=(unary)}
5355 For each such implicit operator declaration, the
5356 parameters are called Left and Right for @i(binary) operators;
5357 the single parameter is called Right for @i(unary) operators.
5358 @redundant[An expression of the form X op Y,
5359 where op is a binary operator,
5360 is equivalent to a @nt<function_call> of the form "op"(X, Y).
5361 An expression of the form op Y,
5362 where op is a unary operator,
5363 is equivalent to a @nt<function_call> of the form "op"(Y).
5364 The predefined operators and their effects are described
5365 in subclauses @RefSecNum(Logical Operators and Short-Circuit Control Forms)
5366 through @RefSecNum(Highest Precedence Operators).]
5367 @end{StaticSem}
5368
5369 @begin{RunTime}
5370 @redundant[@Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
5371 The predefined operations on integer types either yield the mathematically
5372 correct result or raise the exception Constraint_Error.
5373 For implementations that support the Numerics Annex,
5374 the predefined operations on real types yield results whose
5375 accuracy is defined in @RefSecNum(Numerics), or
5376 raise the exception Constraint_Error.
5377 ]
5378 @begin{Honest}
5379 Predefined operations on real types can @lquotes@;silently@rquotes@; give wrong results
5380 when the Machine_Overflows attribute is false, and the
5381 computation overflows.
5382 @end{Honest}
5383 @begin{TheProof}
5384 @ChgRef{Version=[5],Kind=[AddedNormal]}
5385 @ChgAdded{Version=[5],Text=[For integer types, this is normatively stated in
5386 the @RunTimeTitle of @RefSecNum{Integer Types}. For floating point types,
5387 this is normatively stated at the end of the @ImplReqTitle of
5388 @RefSecNum{Model of Floating Point Arithmetic}. For fixed point types,
5389 this is normatively stated at the end of the @ImplReqTitle of
5390 @RefSecNum{Model of Fixed Point Arithmetic}.]}
5391 @end{TheProof}
5392
5393
5394 @end{RunTime}
5395
5396 @begin{ImplReq}
5397 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
5398 The implementation of a predefined operator
5399 that delivers a result of an integer or fixed point type may
5400 raise Constraint_Error only if the result is outside
5401 the base range of the result type.
5402
5403 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
5404 The implementation of a predefined operator
5405 that delivers a result of a floating point type may raise Constraint_Error
5406 only if the result is outside the safe range of the
5407 result type.
5408 @begin{Honest}
5409
5410 An exception is made for exponentiation by a negative exponent in
5411 @RefSecNum{Highest Precedence Operators}.
5412
5413 @end{Honest}
5414 @end{ImplReq}
5415
5416 @begin{ImplPerm}
5417 For a sequence of predefined operators of the same precedence
5418 level (and in the absence of parentheses imposing a specific association),
5419 an implementation may impose any association of the operators with
5420 operands so long as the result produced is
5421 an allowed result for the left-to-right association, but ignoring
5422 the potential for failure of language-defined checks in either the
5423 left-to-right or chosen order of association.
5424 @begin{Discussion}
5425 Note that the permission to reassociate the operands in
5426 any way subject to producing a result allowed for
5427 the left-to-right association is not much help
5428 for most floating point operators, since reassociation may
5429 introduce significantly different round-off errors, delivering
5430 a result that is outside the model interval for the left-to-right
5431 association. Similar problems arise for division with
5432 integer or fixed point operands.
5433
5434 Note that this permission does not apply to user-defined
5435 operators.
5436 @end{Discussion}
5437 @end{ImplPerm}
5438
5439 @begin{Notes}
5440 The two operands of an expression of the form X op Y, where
5441 op is a binary operator, are evaluated in an arbitrary order,
5442 as for any @nt<function_call> (see @RefSecNum(Subprogram Calls)).
5443
5444 @end{Notes}
5445
5446 @begin{Examples}
5447 @Leading@keepnext@i(Examples of precedence:)
5448 @begin{Example}
5449 @key(not) Sunny @key(or) Warm --@RI[ same as (not Sunny) or Warm]
5450 X > 4.0 @key(and) Y > 0.0 --@RI[ same as (X > 4.0) and (Y > 0.0)]
5451
5452 -4.0*A**2 --@RI[ same as @en@;(4.0 * (A**2))]
5453 @key(abs)(1 + A) + B --@RI[ same as (abs (1 + A)) + B]
5454 Y**(-3) --@RI[ parentheses are necessary]
5455 A / B * C --@RI[ same as (A/B)*C]
5456 A + (B + C) --@RI[ evaluate B + C before adding it to A ]
5457 @end{Example}
5458 @end{Examples}
5459
5460 @begin{DiffWord83}
5461 We don't give a detailed definition of precedence, since
5462 it is all implicit in the syntax rules anyway.
5463
5464 The permission to reassociate is moved here from RM83-11.6(5), so
5465 it is closer to the rules defining operator association.
5466 @end{DiffWord83}
5467
5468
5469 @LabeledSubClause{Logical Operators and Short-circuit Control Forms}
5470
5471 @begin{Resolution}
5472 @Defn{short-circuit control form}
5473 @Defn{and then (short-circuit control form)}
5474 @Defn{or else (short-circuit control form)}
5475 An @nt<expression> consisting of two @nt<relation>s
5476 connected by @key(and then) or @key(or else)
5477 (a @i(short-circuit control form))
5478 shall resolve to be of some boolean type;
5479 @PDefn2{Term=[expected type],Sec=(short-circuit control form relation)}
5480 the expected type for both @nt<relation>s
5481 is that same boolean type.
5482 @begin(Reason)
5483 This rule is written this way so that overload resolution treats
5484 the two operands symmetrically; the resolution of overloading
5485 present in either one can benefit from the resolution of the other.
5486 Furthermore, the type expected by context can help.
5487 @end(Reason)
5488 @end{Resolution}
5489
5490 @begin{StaticSem}
5491 @Leading@Defn{logical operator}@Defn2{Term=[operator],Sec=(logical)}
5492 @Defn{and operator}@Defn2{Term=[operator],Sec=(and)}
5493 @Defn{or operator}@Defn2{Term=[operator],Sec=(or)}
5494 @Defn{xor operator}@Defn2{Term=[operator],Sec=(xor)}
5495 The following logical operators are predefined for every
5496 boolean type @i(T),
5497 for every modular type @i(T), and
5498 for every one-dimensional array type @i(T) whose
5499 component type is a boolean type:
5500 @IndexSee{Term=[bit string],See=(logical operators on boolean arrays)}
5501 @begin{example}
5502 @tabclear()
5503 @key[function] "@key(and)"(Left, Right : @RI(T)) @key[return] @RI(T)
5504 @key[function] "@key(or)" (Left, Right : @RI(T)) @key[return] @RI(T)
5505 @key[function] "@key(xor)"(Left, Right : @RI(T)) @key[return] @RI(T)
5506 @end{example}
5507 @begin{Honest}
5508 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00145-01]}
5509 @ChgDeleted{Version=[2],Text=[For predefined operators, the parameter
5510 and result subtypes shown as @i(T) are actually the unconstrained
5511 subtype of the type.]}
5512 @ChgNote{Sorry, Bob, but there is no "honesty" issue here. And
5513 "unconstrained" is wrong.}
5514 @end{Honest}
5515 @begin{Ramification}
5516 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00145-01]}
5517 @ChgAdded{Version=[2],Text=[For these operators, we are talking about
5518 the type without any (interesting) subtype, and not some subtype with a
5519 constraint or exclusion. Since it's possible that there is no name for
5520 the @lquotes@;uninteresting@rquotes subtype, we denote the type
5521 with an italicized @i(T).
5522 This applies to the italicized @i(T) in many other predefined operators and
5523 attributes as well.@Defn2{Term=[T],Sec=[italicized]}]}
5524
5525 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00145-01]}
5526 @ChgAdded{Version=[2],Type=[Leading],Text=[In many cases, there is a subtype
5527 with the correct properties available. The italicized @i(T) means:]}
5528 @begin{Itemize}
5529 @ChgRef{Version=[2],Kind=[AddedNormal]}
5530 @ChgAdded{Version=[2],Text=[@i(T)'Base, for scalars;]}
5531
5532 @ChgRef{Version=[2],Kind=[AddedNormal]}
5533 @ChgAdded{Version=[2],Text=[the first subtype of @i(T), for tagged types;]}
5534
5535 @ChgRef{Version=[2],Kind=[AddedNormal]}
5536 @ChgAdded{Version=[2],Text=[a subtype of the type @i(T) without any
5537 constraint or null exclusion, in other cases.]}
5538 @end{Itemize}
5539
5540 @ChgRef{Version=[2],Kind=[AddedNormal]}
5541 @ChgAdded{Version=[2],Text=[Note that @lquotes@;without a constraint@rquotes
5542 is not the same as unconstrained. For instance, a record type with no
5543 discriminant part is considered constrained; no subtype of it has a
5544 constraint, but the subtype is still constrained.]}
5545
5546 @ChgRef{Version=[2],Kind=[AddedNormal]}
5547 @ChgAdded{Version=[2],Text=[Thus, the last case often is the same as
5548 the first subtype of @i(T), but that isn't the case for constrained array
5549 types (where the correct subtype is unconstrained) and for access types
5550 with a @nt{null_exclusion} (where the correct subtype does not
5551 exclude null).]}
5552
5553 @ChgRef{Version=[2],Kind=[AddedNormal]}
5554 @ChgAdded{Version=[2],Text=[This italicized @i(T) is used for defining
5555 operators and attributes of the language. The meaning is intended to be
5556 as described here.]}
5557 @end{Ramification}
5558
5559 For boolean types, the predefined logical operators
5560 @key{and}, @key{or}, and @key{xor}
5561 perform the conventional operations of conjunction, inclusive
5562 disjunction, and exclusive disjunction, respectively.
5563
5564 For modular types, the predefined logical operators
5565 are defined on a bit-by-bit basis, using the binary
5566 representation of the value of the operands to
5567 yield a binary representation for the result,
5568 where zero represents False and one represents True.
5569 If this result is outside the base range of the type,
5570 a final subtraction by the modulus is performed to bring the
5571 result into the base range of the type.
5572
5573 The logical operators on arrays are performed on a
5574 component-by-component basis on
5575 matching components (as for equality @em
5576 see @RefSecNum{Relational Operators and Membership Tests}),
5577 using the predefined logical operator for the component type. The bounds of
5578 the resulting array are those of the left operand.
5579
5580 @end{StaticSem}
5581
5582 @begin{RunTime}
5583 @PDefn2{Term=[evaluation], Sec=(short-circuit control form)}
5584 The short-circuit control forms @key{and then} and @key{or else}
5585 deliver the same result as the corresponding predefined @key{and} and @key{or}
5586 operators for boolean types, except that the left operand is always
5587 evaluated first, and the right operand is not evaluated if the
5588 value of the left operand determines the result.
5589
5590 @IndexCheck{Length_Check}
5591 For the logical operators on arrays,
5592 a check is made that
5593 for each component of the left operand there is a matching component of the
5594 right operand, and vice versa.
5595 @IndexCheck{Range_Check}
5596 Also, a check is made that each component
5597 of the result belongs to the component subtype.
5598 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
5599 The exception Constraint_Error is raised if
5600 either of the above checks fails.
5601 @begin{Discussion}
5602 The check against the component subtype is per AI83-00535.
5603 @end{Discussion}
5604
5605 @end{RunTime}
5606
5607 @begin{Notes}
5608 @Leading@;The conventional meaning of the logical operators is given by the
5609 following truth table:
5610 @begin(Display)
5611 @TabClear()
5612 @TabSet(P4, P20, P36, P52, P68)
5613 @\@ @ A@\@ @ B@\(A @key(and) B)@\(A @key(or) B)@\(A @key(xor) B)@*
5614 @\True @\True @\True @\True @\False
5615 @\True @\False @\False @\True @\True
5616 @\False @\True @\False @\True @\True
5617 @\False @\False @\False @\False @\False
5618 @end(Display)
5619 @end{Notes}
5620
5621 @begin{Examples}
5622 @Leading@keepnext@i(Examples of logical operators:)
5623 @begin{Example}
5624 Sunny @key(or) Warm
5625 Filter(1 .. 10) @key(and) Filter(15 .. 24) --@RI[ see @RefSecNum{Index Constraints and Discrete Ranges} ]
5626 @end{Example}
5627
5628 @begin{WideAbove}
5629 @leading@keepnext@i(Examples of short-circuit control forms:)
5630 @end{WideAbove}
5631 @begin{Example}
5632 Next_Car.Owner /= @key(null) @key(and) @key(then) Next_Car.Owner.Age > 25 --@RI[ see @RefSecNum{Incomplete Type Declarations}]
5633 N = 0 @key(or) @key(else) A(N) = Hit_Value
5634 @end{Example}
5635 @end{Examples}
5636
5637
5638 @LabeledSubClause{Relational Operators and Membership Tests}
5639
5640 @begin{Intro}
5641 @redundant[@Defn{relational operator}@Defn2{Term=[operator],Sec=(relational)}
5642 @IndexSee{Term=[comparison operator],See=(relational operator)}
5643 @Defn{equality operator}@Defn2{Term=[operator],Sec=(equality)}
5644 The @i(equality operators)
5645 = (equals) and /= (not equals) are predefined for nonlimited types.
5646 @Defn{ordering operator}@Defn2{Term=[operator],Sec=(ordering)}
5647 The other @nt<relational_operator>s are the @i(ordering operators)
5648 < (less than), <= (less than or
5649 equal), > (greater than), and >= (greater than or equal).
5650 @Defn{= operator}@Defn2{Term=[operator],Sec=(=)}
5651 @Defn{equal operator}@Defn2{Term=[operator],Sec=(equal)}
5652 @Defn{/= operator}@Defn2{Term=[operator],Sec=(/=)}
5653 @Defn{not equal operator}@Defn2{Term=[operator],Sec=(not equal)}
5654 @Defn{< operator}@Defn2{Term=[operator],Sec=(<)}
5655 @Defn{less than operator}@Defn2{Term=[operator],Sec=(less than)}
5656 @Defn{<= operator}@Defn2{Term=[operator],Sec=(<=)}
5657 @Defn{less than or equal operator}@Defn2{Term=[operator],Sec=(less than or equal)}
5658 @Defn{> operator}@Defn2{Term=[operator],Sec=(>)}
5659 @Defn{greater than operator}@Defn2{Term=[operator],Sec=(greater than)}
5660 @Defn{>= operator}@Defn2{Term=[operator],Sec=(>=)}
5661 @Defn{greater than or equal operator}@Defn2{Term=[operator],Sec=(greater than or equal)}
5662 @Defn{discrete array type}
5663 The ordering operators are predefined for scalar
5664 types, and for @i(discrete array types), that is,
5665 one-dimensional array types whose components are of
5666 a discrete type.
5667 @begin{Ramification}
5668 The equality operators are not defined for @i{every} nonlimited
5669 type @em see below for the exact rule.
5670 @end{Ramification}
5671
5672 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
5673 @Defn{membership test}
5674 @Defn{in (membership test)}
5675 @Defn{not in (membership test)}
5676 A @i(membership test), using @key(in) or @key(not in),
5677 determines whether or not a value
5678 belongs to @chg{Version=[3],New=[any],Old=[a]} given subtype or range,
5679 @chg{Version=[3],New=[is equal to any given value,],Old=[or]} has a tag
5680 that identifies a type that is covered by a given type@chg{Version=[3],New=[,
5681 or is convertible to and has an accessibility level appropriate for a given
5682 access type],Old=[]}. Membership tests are allowed for all types.]
5683
5684 @end{Intro}
5685
5686 @begin{Resolution}
5687
5688 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
5689 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
5690 @PDefn2{Term=[expected type],
5691 Sec=(membership test simple_expression)}
5692 @Defn2{Term=[tested type], Sec=(of a membership test)}
5693 The @i(tested type) of a membership test
5694 is@Chg{Version=[3],New=[],Old=[ the type of the @nt<range> or the type]}
5695 determined by the @Chg{Version=[3],New=[@nt<membership_choice>s of the
5696 @nt<membership_choice_list>. Either all @nt{membership_choice}s of the
5697 @nt{membership_choice_list} shall resolve to the same type, which is the tested
5698 type; or each @nt{membership_choice} shall be of an elementary type, and the
5699 tested type shall be covered by each of these elementary
5700 types.],Old=[@nt<subtype_mark>. If the tested type is tagged, then the
5701 @nt<simple_expression> shall resolve to be of a type that
5702 @Chg{Version=[2],New=[is convertible (see @RefSecNum{Type Conversions})
5703 to],Old=[covers or is covered by]} the tested type; if untagged, the expected
5704 type for the @nt<simple_expression> is the tested type.]}
5705
5706 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
5707 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
5708 @ChgAdded{Version=[3],Text=[If the tested type is tagged, then the
5709 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
5710 shall resolve to be of a type that is
5711 convertible (see @RefSecNum{Type Conversions}) to the tested
5712 type; if untagged, the expected type for the
5713 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
5714 is the tested type. The expected type of a
5715 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}],Old=[@nt{choice_expression}]}
5716 in a @nt{membership_choice}, and of a @nt{simple_expression} of a @nt{range} in
5717 a @nt{membership_choice}, is the tested type of the membership operation.]}
5718
5719 @begin{Reason}
5720 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
5721 The part of the rule for untagged types is stated in a way
5722 that ensures that operands
5723 like @Chg{Version=[2],New=[a string literal],Old=[@key(null)]} are still
5724 legal as operands of a membership test.
5725
5726 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
5727 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
5728 The significance of @lquotes@;@Chg{Version=[2],New=[is convertible to],
5729 Old=[covers or is covered by]}@rquotes@; is that we allow the
5730 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
5731 to be of any class-wide type that @Chg{Version=[2],
5732 New=[could be converted to],Old=[covers]} the tested type, not just the
5733 one rooted at the tested type.@Chg{Version=[2],New=[ This includes any
5734 class-wide type that covers the tested type, along with class-wide interfaces
5735 in some cases.],Old=[]}
5736
5737 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
5738 @ChgAdded{Version=[3],Text=[The special rule for determining the tested type for
5739 elementary types is to allow numeric literals in @nt{membership_choice_list}s.
5740 Without the rule, @exam{A @key[in] B | 1} would be illegal as B and 1 would
5741 have different types (the literal having type @i<universal integer>).]}
5742 @end{Reason}
5743
5744 @end{Resolution}
5745
5746 @begin{Legality}
5747 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
5748 For a membership test, if the
5749 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
5750 is of a tagged class-wide type,
5751 then the tested type shall be (visibly) tagged.
5752 @begin{Ramification}
5753 Untagged types covered by the tagged class-wide type
5754 are not permitted. Such types can exist if they are
5755 descendants of a private type whose full type is tagged.
5756 This rule is intended to avoid confusion since such derivatives
5757 don't have their @lquotes@;own@rquotes@; tag, and hence are indistinguishable
5758 from one another at run time once converted to a covering
5759 class-wide type.
5760 @end{Ramification}
5761
5762 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
5763 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
5764 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0328-1]}
5765 @ChgAdded{Version=[3],Text=[If a membership test includes one or more
5766 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}s],Old=[@nt{choice_expression}s]}
5767 and the tested type of the membership test is limited, then the
5768 tested type of the membership test shall have a visible primitive equality
5769 operator@Chg{Version=[5],New=[; if the tested type of the membership test is
5770 nonlimited with a user-defined primitive equality operator that is defined
5771 at a point where the type is limited, the tested type shall be a record type or
5772 record extension],Old=[]}.]}
5773 @begin{Reason}
5774 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
5775 @ChgAdded{Version=[3],Text=[A visible equality operator is required in order
5776 to avoid breaking privacy; that is, we don't want to depend on a hidden
5777 equality operator.]}
5778
5779 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0328-1]}
5780 @ChgAdded{Version=[5],Text=[We make the membership test on the nonlimited
5781 view of a type illegal if it would use a different equality operator than what
5782 would be used for a limited view of the same type (and such a limited view is
5783 known to exist).]}
5784 @end{Reason}
5785 @end{Legality}
5786
5787 @begin{StaticSem}
5788 The result type of a membership test is the predefined type Boolean.
5789
5790 @Leading@;The equality operators are predefined for every specific
5791 type @i(T) that is not limited,
5792 and not an anonymous access type,
5793 with the following specifications:
5794 @begin(example)
5795 @key(function) "=" (Left, Right : @RI(T)) @key(return) Boolean
5796 @key(function) "/="(Left, Right : @RI(T)) @key(return) Boolean
5797 @end(example)
5798
5799 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
5800 @ChgAdded{Version=[2],Type=[Leading],Text=[The following additional equality
5801 operators for the
5802 @i<universal_access> type are declared in package Standard for use with
5803 anonymous access types:]}
5804 @begin(example)
5805 @ChgRef{Version=[2],Kind=[Added]}
5806 @ChgAdded{Version=[2],Text=[@key<function> "=" (Left, Right : @i<universal_access>) @key<return> Boolean
5807 @key<function> "/="(Left, Right : @i<universal_access>) @key<return> Boolean]}
5808 @end(example)
5809
5810 @Leading@;The ordering operators are predefined for every specific
5811 scalar type @i(T), and for every discrete array type
5812 @i(T), with the following specifications:
5813 @begin(example)
5814 @key(function) "<" (Left, Right : @RI(T)) @key(return) Boolean
5815 @key(function) "<="(Left, Right : @RI(T)) @key(return) Boolean
5816 @key(function) ">" (Left, Right : @RI(T)) @key(return) Boolean
5817 @key(function) ">="(Left, Right : @RI(T)) @key(return) Boolean
5818 @end(example)
5819 @end{StaticSem}
5820
5821 @begin{Resolution}
5822 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00420-01]}
5823 @ChgAdded{Version=[2],Type=[Leading],Text=[At least one of the operands of an equality
5824 operator for @i<universal_access> shall be of a specific anonymous access type.
5825 Unless the predefined equality operator is identified using an expanded name
5826 with @nt{prefix} denoting the package Standard, neither operand shall be of an
5827 access-to-object type whose designated type is @i<D> or @i<D>'Class, where
5828 @i<D> has a user-defined primitive equality operator such that:]}
5829 @begin{Itemize}
5830 @ChgRef{Version=[2],Kind=[Added]}
5831 @ChgAdded{Version=[2],Text=[its result type is Boolean;]}
5832
5833 @ChgRef{Version=[2],Kind=[Added]}
5834 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0020-1]}
5835 @ChgAdded{Version=[2],Text=[it is declared immediately within the same
5836 declaration list as @i<D>@Chg{Version=[3],New=[ or any partial or incomplete
5837 view of @i<D>],Old=[]}; and]}
5838
5839 @ChgRef{Version=[2],Kind=[Added]}
5840 @ChgAdded{Version=[2],Text=[at least one of its operands is an
5841 access parameter with designated type @i<D>.]}
5842 @end{Itemize}
5843
5844 @begin{Reason}
5845 @ChgRef{Version=[2],Kind=[AddedNormal]}
5846 @ChgAdded{Version=[2],Text=[The first sentence prevents compatibility
5847 problems by ensuring that these operators are not used for named access
5848 types. Also, universal access types do not count for the purposes of this
5849 rule. Otherwise, equality expressions like (X = @key{null}) would be
5850 ambiguous for normal access types.]}
5851
5852 @ChgRef{Version=[2],Kind=[AddedNormal]}
5853 @ChgAdded{Version=[2],Text=[The rest of the rule makes it possible to
5854 call (including a dispatching call) user-defined "=" operators for anonymous
5855 access-to-object types (they'd be hidden
5856 otherwise), and to write user-defined "=" operations for anonymous access
5857 types (by making it possible to see the universal operator using the
5858 Standard prefix).]}
5859 @end{Reason}
5860 @begin{Ramification}
5861 @ChgRef{Version=[2],Kind=[AddedNormal]}
5862 @ChgAdded{Version=[2],Text=[We don't need a similar rule for anonymous
5863 access-to-subprogram types because they can't be primitive for any type.
5864 Note that any nonprimitive user-defined equality operators still are hidden
5865 by the universal operators; they'll have to be called with a package
5866 prefix, but they are likely to be very uncommon.]}
5867 @end{Ramification}
5868 @end{Resolution}
5869
5870 @begin{Legality}
5871 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
5872 @ChgAdded{Version=[2],Text=[At least one of the operands of the equality
5873 operators for @i<universal_access> shall be of type @i<universal_access>, or
5874 both shall be of access-to-object types, or both shall be of
5875 access-to-subprogram types. Further:]}
5876 @begin{Itemize}
5877 @ChgRef{Version=[2],Kind=[Added]}
5878 @ChgAdded{Version=[2],Text=[When both are of access-to-object types, the
5879 designated types shall be the same or one shall cover the
5880 other, and if the designated types are elementary or array types,
5881 then the designated subtypes shall statically match;]}
5882
5883 @ChgRef{Version=[2],Kind=[Added]}
5884 @ChgAdded{Version=[2],Text=[When both are of access-to-subprogram types,
5885 the designated profiles shall be subtype conformant.]}
5886 @end{Itemize}
5887 @begin{Reason}
5888 @ChgRef{Version=[2],Kind=[AddedNormal]}
5889 @ChgAdded{Version=[2],Text=[We don't want to allow completely arbitrary
5890 comparisons, as we don't want to insist that all access types are represented
5891 in ways that are convertible to one another. For instance, a compiler could
5892 use completely separate address spaces or incompatible representations.
5893 Instead, we allow compares if there exists an access parameter to which both
5894 operands could be converted. Since the user could write such an subprogram,
5895 and any reasonable meaning for "=" would allow using it in such a subprogram,
5896 this doesn't impose any further restrictions on Ada implementations.]}
5897 @end{Reason}
5898
5899 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
5900 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0101-1]}
5901 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0352-1]}
5902 @ChgAdded{Version=[3],Text=[If the profile of an explicitly declared primitive
5903 equality operator of an untagged record type is type conformant with that of the
5904 corresponding predefined equality operator, the declaration shall occur before
5905 the type is frozen.@Chg{Version=[4],New=[],Old=[ In addition, if the untagged
5906 record type has a nonlimited partial view, then the declaration shall occur
5907 in the visible part of the enclosing package.]}@Chg{Version=[5],New=[ In
5908 addition, no type shall have been derived from the untagged
5909 record type before the declaration of the primitive equality operator.],Old=[]}
5910 @PDefn{generic contract issue}
5911 In addition to the places where @LegalityTitle normally apply
5912 (see @RefSecNum{Generic Instantiation}),
5913 this rule applies also in the private part of an instance of a generic unit.]}
5914 @end{Legality}
5915
5916 @begin{RunTime}
5917 For discrete types, the predefined relational operators are
5918 defined in terms of corresponding mathematical operations on
5919 the position numbers of the values of the operands.
5920
5921 For real types, the predefined relational operators are
5922 defined in terms of the corresponding mathematical operations
5923 on the values of the operands, subject to the accuracy of the
5924 type.
5925 @begin{Ramification}
5926 For floating point types, the results of comparing
5927 @i(nearly) equal values depends on the accuracy of
5928 the implementation
5929 (see @RefSec{Model of Floating Point Arithmetic}
5930 for implementations that support the Numerics Annex).
5931 @end{Ramification}
5932 @begin{ImplNote}
5933 On a machine with signed zeros,
5934 if the generated code generates both plus zero and minus zero,
5935 plus and minus zero must be equal
5936 by the predefined equality operators.
5937 @end{ImplNote}
5938
5939 Two access-to-object values are equal if they designate the same
5940 object, or if both are equal to the null value of the access type.
5941
5942 Two access-to-subprogram values are equal if they are the
5943 result of the same evaluation of an Access @nt<attribute_reference>,
5944 or if both
5945 are equal to the null value of the access type. Two
5946 access-to-subprogram values are unequal if they designate
5947 different subprograms.
5948 @PDefn{unspecified}
5949 @Redundant[It is unspecified whether
5950 two access values that designate the same subprogram but are
5951 the result of distinct evaluations of
5952 Access @nt<attribute_reference>s are equal
5953 or unequal.]
5954 @begin{Reason}
5955 This allows each Access @nt<attribute_reference>
5956 for a subprogram to designate a distinct @lquotes@;wrapper@rquotes@; subprogram
5957 if necessary to support an indirect call.
5958 @end{Reason}
5959
5960 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
5961 @Defn2{Term=[equality operator],Sec=(special inheritance rule for tagged types)}
5962 For a type extension, predefined equality
5963 is defined in terms of the primitive @Redundant[(possibly
5964 user-defined)] equals operator
5965 @Chg{Version=[3],New=[for],Old=[of]} the parent type and
5966 @Chg{Version=[3],New=[for],Old=[of]} any @Chg{Version=[3],New=[],Old=[tagged ]}components
5967 @Chg{Version=[3],New=[that have a record type in],Old=[of]} the extension part, and
5968 predefined equality
5969 for any other components not inherited from the parent type.
5970 @begin{Ramification}
5971 Two values of a type extension are not equal if there is
5972 a @nt<variant_part> in the extension part and the two
5973 values have different @nt<variant>s present.
5974 This is a ramification of the requirement that a
5975 discriminant governing such a @nt<variant_part> has to be a @lquotes@;new@rquotes@;
5976 discriminant, and so has to be equal in the two values for
5977 the values to be equal. Note that @nt<variant_part>s in
5978 the parent part need not match if the primitive equals operator
5979 for the parent type considers them equal.
5980
5981 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00349-01]}
5982 @ChgAdded{Version=[2],Type=[Leading],Text=[The full type extension's operation
5983 is used for a private extension. This follows as only full types have parent types;
5984 the type specified in a private extension is an ancestor, but not necessarily
5985 the parent type. For instance, in:]}
5986 @begin(Example)
5987 @ChgRef{Version=[2],Kind=[AddedNormal]}
5988 @Chg{Version=[2],New=[@key{with} Pak1;
5989 @key{package} Pak2 @key{is}
5990 @key{type} Typ3 @key{is} @key{new} Pak1.Typ1 @key{with} @key{private};
5991 @key{private}
5992 @key{type} Typ3 @key{is} @key{new} Pak1.Typ2 @key{with} @key{null} @key{record};
5993 @key{end} Pak2;],Old=[]}
5994 @end(Example)
5995 @ChgRef{Version=[2],Kind=[AddedNormal]}
5996 @Chg{Version=[2],New=[the parent type is Pak1.Typ2, not Pak1.Typ1, and the
5997 equality operator of Pak1.Typ2 is used to create predefined equality for
5998 Typ3.],Old=[]}
5999 @end{Ramification}
6000
6001 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
6002 @ChgAdded{Version=[3],Text=[For a derived type whose parent is an untagged
6003 record type, predefined equality is defined in terms of the primitive (possibly
6004 user-defined) equals operator of the parent type.]}
6005 @begin{Reason}
6006 @ChgRef{Version=[3],Kind=[AddedNormal]}
6007 @ChgAdded{Version=[3],Text=[This prevents predefined equality from
6008 reemerging in generic units for untagged record types. For other uses
6009 the primitive equality is inherited and the inherited routine is primitive.]}
6010 @end{Reason}
6011
6012 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
6013 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0328-1]}
6014 For a private type, if its full type is
6015 @Chg{Version=[3],New=[a record type@Chg{Version=[5],New=[ or a record
6016 extension],Old=[]}],Old=[tagged]}, predefined
6017 equality is defined in terms of the primitive equals operator of the
6018 full type; @Chg{Version=[3],New=[otherwise],Old=[if the full type is untagged]},
6019 predefined equality for the private type is that of its full type.
6020
6021 @Leading@Defn{matching components}
6022 For other composite types, the predefined equality operators
6023 @Redundant[(and
6024 certain other predefined operations on composite types @em
6025 see @RefSecNum(Logical Operators and Short-circuit Control Forms)
6026 and @RefSecNum(Type Conversions))] are defined
6027 in terms of the corresponding operation on
6028 @i(matching components), defined as follows:
6029 @begin(itemize)
6030 For two composite objects or values of the same non-array type,
6031 matching components are those that correspond to the
6032 same @nt<component_declaration> or @nt<discriminant_specification>;
6033
6034 For two one-dimensional arrays of the same type, matching components are
6035 those (if any) whose index values match in the following sense: the
6036 lower bounds of the index ranges are defined to match, and the successors
6037 of matching indices are defined to match;
6038
6039 For two multidimensional arrays of the same type, matching components
6040 are those whose index values match in successive index positions.
6041 @end(itemize)
6042
6043 The analogous definitions apply if the types of the two objects or values
6044 are convertible, rather than being the same.
6045 @begin{Discussion}
6046 Ada 83 seems to
6047 omit this part of the definition, though it is used in array type
6048 conversions. See @RefSecNum{Type Conversions}.
6049 @end{Discussion}
6050
6051 @Leading@;Given the above definition of matching components,
6052 the result of the predefined equals operator for composite types (other than
6053 for those composite types covered earlier) is defined as follows:
6054 @begin(Itemize)
6055 If there are no components, the result is defined to be True;
6056
6057 If there are unmatched components, the result is defined to be False;
6058
6059 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
6060 Otherwise, the result is defined in terms of
6061 the primitive equals operator for any
6062 matching @Chg{Version=[3],New=[],Old=[tagged ]}components@Chg{Version=[3],New=[ that
6063 are records],Old=[]}, and
6064 the predefined equals for any @Chg{Version=[3],New=[other ],Old=[]}matching
6065 @Chg{Version=[3],New=[],Old=[untagged ]}components.
6066 @begin{Reason}
6067 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
6068 This asymmetry between @Chg{Version=[3],New=[],Old=[tagged and
6069 untagged ]}components @Chg{Version=[3],New=[with and without a record type ],Old=[]}is
6070 necessary to preserve @Chg{Version=[3],New=[most ],Old=[]}upward compatibility and corresponds
6071 with the corresponding situation with generics, where the
6072 predefined operations @lquotes@;reemerge@rquotes@; in a generic for
6073 @Chg{Version=[3],New=[non-record],Old=[untagged]} types, but do not
6074 for @Chg{Version=[3],New=[record],Old=[tagged]} types. Also, only
6075 tagged types support user-defined assignment
6076 (see @RefSecNum{Assignment and Finalization}),
6077 so only tagged types
6078 can fully handle levels of indirection in the implementation
6079 of the type. For untagged types, one reason for
6080 a user-defined equals operator might be to allow values with different
6081 bounds or discriminants to compare equal in certain cases.
6082 When such values are matching components, the bounds or discriminants
6083 will necessarily match anyway if the
6084 discriminants of the enclosing values match.
6085 @end{Reason}
6086 @end(Itemize)
6087 @begin{Ramification}
6088 Two null arrays of the same type are always equal;
6089 two null records of the same type are always equal.
6090
6091 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
6092 Note that if a composite object has a component
6093 of a floating point type, and the floating point type
6094 has both a plus and minus zero, which are considered
6095 equal by the predefined equality, then a block compare
6096 cannot be used for the predefined composite equality.
6097 Of course, with user-defined equals operators for
6098 @Chg{Version=[3],New=[],Old=[tagged ]}components@Chg{Version=[3],New=[ that
6099 are records],Old=[]},
6100 a block compare breaks down anyway, so this is not the only
6101 special case that requires component-by-component comparisons.
6102 On a one's complement machine, a similar situation might
6103 occur for integer types, since one's complement machines
6104 typically have both a plus and minus (integer) zero.
6105 @end{Ramification}
6106 @begin{Honest}
6107 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
6108 @ChgAdded{Version=[2],Text=[For a component with an anonymous access type,
6109 @lquotes@;predefined equality@rquotes@; is that defined for the
6110 @i<universal_access> type (anonymous access types have no equality operators
6111 of their own).]}
6112
6113 @ChgRef{Version=[2],Kind=[AddedNormal]}
6114 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0123-1]}
6115 @ChgAdded{Version=[2],Text=[For a component with a @Chg{Version=[3],New=[record],
6116 Old=[tagged]} type @i{T},
6117 @lquotes@;the primitive equals operator@rquotes@; is the one with two
6118 parameters of @i(T) which returns Boolean. We're not talking about some
6119 random other primitive function named "=".]}
6120 @end{Honest}
6121
6122 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0123-1]}
6123 @ChgAdded{Version=[3],Text=[If the primitive equals operator for an untagged
6124 record type is abstract, then Program_Error is raised at the point of any
6125 (implicit) call to that abstract subprogram.]}
6126 @begin{Reason}
6127 @ChgRef{Version=[3],Kind=[AddedNormal]}
6128 @ChgAdded{Version=[3],Text=[An explicit call to an abstract subprogram is
6129 illegal. This rule is needed in order to define the effect of an implicit call
6130 such as a call that is part of the predefined equality operation for an
6131 enclosing composite type that has a component of an untagged record type that
6132 has an abstract primitive equals operator. For tagged types, an abstract
6133 primitive equals operator is only allowed for an abstract type, and abstract
6134 types cannot be components, so this case does not occur.]}
6135 @end{Reason}
6136
6137 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0016],ARef=[AI95-00123-01]}
6138 @ChgAdded{Version=[1],Text=[For any composite type, the order in which "="
6139 is called for components is unspecified. Furthermore, if the result can be
6140 determined before calling "=" on some components, it is unspecified whether
6141 "=" is called on those components.@PDefn{Unspecified}]}
6142
6143 The predefined "/=" operator gives the complementary result
6144 to the predefined "=" operator.
6145 @begin{Ramification}
6146 Furthermore,
6147 if the user defines an "=" operator that returns Boolean,
6148 then a "/=" operator is implicitly declared in terms of
6149 the user-defined "=" operator so as to give the complementary
6150 result. See @RefSecNum(Overloading of Operators).
6151 @end{Ramification}
6152
6153 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
6154 @Defn{lexicographic order}
6155 For a discrete array type, the predefined ordering operators
6156 correspond to @i(lexicographic order) using the predefined order
6157 relation of the component type: A null array is lexicographically
6158 less than any array having at least one component.
6159 In the case of nonnull arrays, the left operand is lexicographically
6160 less than the right operand if the first component of
6161 the left operand is less than that of the right; otherwise@Chg{Version=[3],New=[,],Old=[]}
6162 the left operand is lexicographically less than the right operand
6163 only if their first components are equal and the tail of the
6164 left operand is lexicographically less than that of the right (the
6165 @i(tail) consists of the remaining components beyond the first and
6166 can be null).
6167
6168 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0269-1]}
6169 @ChgAdded{Version=[3],Text=[An @i<individual membership test> is the
6170 membership test of a single @nt{membership_choice}.@Defn{individual membership test}]}
6171
6172 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
6173 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
6174 @PDefn2{Term=[evaluation], Sec=(membership test)}
6175 For the evaluation of a membership test@Chg{Version=[3],New=[ using @key[in]
6176 whose @nt{membership_choice_list} has a single @nt{membership_choice}],Old=[]},
6177 the
6178 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6179 and the @Chg{Version=[3],New=[@nt{membership_choice}],Old=[@nt<range> (if any)]}
6180 are evaluated in an arbitrary order@Chg{Version=[3],New=[; the result is the
6181 result of the individual membership test for
6182 the @nt{membership_choice}],Old=[]}.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6183
6184 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
6185 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
6186 @ChgAdded{Version=[3],Text=[For the evaluation of a membership test using
6187 @key[in] whose @nt{membership_choice_list} has more than one
6188 @nt{membership_choice}, the
6189 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6190 of the membership test is evaluated first and the
6191 result of the operation is equivalent to that of a sequence consisting
6192 of an individual membership test on each @nt{membership_choice}
6193 combined with the short-circuit control form @b[or else].]}
6194
6195 @begin{Ramification}
6196 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1]}
6197 @ChgAdded{Version=[3],Text=[This equivalence includes the evaluation of the
6198 @nt{membership_choice}s; evaluation stops as soon as an individual choice
6199 evaluates to True.]}
6200 @end{Ramification}
6201
6202 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1],ARef=[AI05-0269-1]}
6203 @Leading@;@Chg{Version=[3],New=[An individual membership test],Old=[A
6204 membership test using @key(in)]} yields the result True if:
6205 @begin(itemize)
6206 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0158-1],ARef=[AI05-0264-1]}
6207 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
6208 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0328-1]}
6209 @ChgAdded{Version=[3],Text=[The @nt{membership_choice} is a
6210 @Chg{Version=[4],New=[@SynI{choice_}@nt{simple_expression}],Old=[@nt{choice_expression}]},
6211 and the
6212 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6213 is equal to the value of the @nt{membership_choice}.
6214 If the tested type is a record type or a @Chg{Version=[5],New=[record
6215 extension, or is ],Old=[]}limited @Chg{Version=[5],New=[at the point where
6216 the membership test occurs],Old=[type]}, the test uses the
6217 primitive equality for the type; otherwise, the test uses predefined equality.]}
6218
6219 @begin{Reason}
6220 @ChgAdded{Version=[5],Text=[We use the predefined equality operator
6221 if the membership test occurs where the type is nonlimited if the type
6222 is not a record type or record extension. However, to avoid confusion,
6223 cases where a membership test could use different equality operators
6224 based on the view are illegal.]}
6225 @end{Reason}
6226
6227 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0153-3],ARef=[AI05-0158-1]}
6228 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
6229 @ChgAdded{Version=[3],Text=[The @nt{membership_choice} is a @nt{range}
6230 and the value of the
6231 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6232 belongs to the given @nt<range>.]}
6233
6234 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0158-1]}
6235 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1],ARef=[AI12-0071-1]}
6236 @Chg{Version=[3],New=[The @nt{membership_choice} is a @nt{subtype_mark},
6237 the],Old=[The]} tested type is scalar, @Chg{Version=[3],New=[],Old=[and ]}the
6238 value of the
6239 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6240 belongs to the
6241 @Chg{Version=[3],New=[],Old=[given @nt<range>, or the ]}range of the
6242 named subtype@Chg{Version=[3],New=[, and the @Chg{Version=[4],New=[value
6243 satisfies the predicates],Old=[predicate]} of the named
6244 subtype@Chg{Version=[4],New=[],Old=[ evaluates to True]}.@Chg{Version=[4],
6245 New=[@Defn2{Term=[predicates satisfied required],Sec=[membership]}],Old=[@Defn2{Term=[predicate evaluated],Sec=[membership]}]}],Old=[; or]}
6246 @begin{Ramification}
6247 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3]}
6248 The scalar membership test only does a range check@Chg{Version=[3],New=[
6249 and a predicate check],Old=[]}.
6250 It does not perform any other check, such as whether
6251 a value falls in a @lquotes@;hole@rquotes@; of a @lquotes@;holey@rquotes@; enumeration type.
6252 The Pos attribute function can be used for that purpose.
6253
6254 Even though Standard.Float is an unconstrained subtype,
6255 the test @lquotes@;X in Float@rquotes@; will still return False
6256 (presuming the evaluation of X does not raise Constraint_Error)
6257 when X is outside Float'Range.
6258 @end{Ramification}
6259
6260 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
6261 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0158-1]}
6262 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1],ARef=[AI12-0071-1]}
6263 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@ChgNote{To get conditional Leading}
6264 @Chg{Version=[3],New=[The @nt<membership_choice> is a
6265 @nt<subtype_mark>, the],Old=[The]} tested type is not scalar, @Chg{Version=[3],New=[],Old=[and ]}
6266 the value of the
6267 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6268 satisfies any constraints
6269 of the named subtype, @Chg{Version=[3],New=[the @Chg{Version=[4],New=[value
6270 satisfies the predicates],Old=[predicate]} of the named
6271 subtype@Chg{Version=[4],New=[],Old=[ evaluates to
6272 True]}, ],Old=[]}and@Chg{Version=[2],New=[:],Old=[, if the type of
6273 the @nt{simple_expression} is class-wide, the value has a tag that
6274 identifies a type covered by the tested type.]}
6275 @begin{Inneritemize}
6276 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
6277 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
6278 @ChgAdded{Version=[2],Text=[if the type of the
6279 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6280 is class-wide, the value has a tag that identifies a type covered by the
6281 tested type;]}
6282 @begin{Ramification}
6283 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
6284 Note that the tag is not checked if the
6285 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6286 is of a specific type.
6287 @end{Ramification}
6288 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
6289 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0149-1]}
6290 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
6291 @ChgAdded{Version=[2],Text=[if the tested type is an access type and the
6292 named subtype excludes null, the value of the
6293 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6294 is not null@Chg{Version=[3],New=[;],Old=[.]}]}
6295
6296 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0149-1]}
6297 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0039-1]}
6298 @ChgAdded{Version=[3],Text=[if the tested type is a general access-to-object
6299 type, the type of the
6300 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6301 is convertible to the tested
6302 type and its accessibility level is no deeper than that of the tested type;
6303 further, if the designated type of the tested type is tagged and the
6304 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6305 is nonnull, the tag of the object designated by the
6306 value of the
6307 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6308 is covered by the designated type of the tested type.]}
6309 @end{Inneritemize}
6310
6311 @begin{Honest}
6312 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0005-1]}
6313 @ChgAdded{Version=[5],Type=[Leading],Text=[In some of these cases, the
6314 bulleted checks need to pass before any predicate check is executed.
6315 Otherwise, a predicate check could be performed on an object of the
6316 wrong type. Consider:]}
6317
6318 @begin{Example}
6319 @ChgRef{Version=[5],Kind=[AddedNormal]}
6320 @ChgAdded{Version=[5],Text=[@key[type] Root @key[is tagged null record];
6321 @key[type] Ext @key[is new] Root @key[with record] Data : Integer; @key[end record];
6322 @key[function] Is_Even (Param : Ext) @key[return] Boolean @key[is]
6323 (Param.Data @key[mod] 2 = 0);
6324 @key[subtype] Even_Ext @key[is] Ext
6325 @key[with] Dynamic_Predicate => Is_Even (Even_Ext);
6326 @key[function] F (X : Root'Class) @key[return] Boolean @key[is]
6327 (X @key[in] Even_Ext);
6328 Flag : Boolean := F (Root'(@key[null record]));]}
6329 @end{Example}
6330
6331 @ChgRef{Version=[5],Kind=[AddedNormal]}
6332 @ChgAdded{Version=[5],Text=[If the predicate check is performed before
6333 the tag check or regardless of the result of that check, Is_Even would
6334 be called on an object that does not have a Data component. Similar
6335 cases can be constructed for general access types.]}
6336 @end{Honest}
6337
6338 @end(itemize)
6339
6340 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
6341 Otherwise@Chg{Version=[3],New=[,],Old=[]} the test yields the result False.
6342
6343 A membership test using @key(not in) gives the complementary result to
6344 the corresponding membership test using @key(in).
6345
6346 @begin{Honest}
6347 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
6348 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0039-1]}
6349 @ChgAdded{Version=[3],Text=[@exam{@i<X> @key[not in] @i<A> | @i<B> | @i<C>}
6350 is intended to be exactly equivalent to @exam{@key[not] (@i<X> @key[in] @i<A> | @i<B> | @i<C>)},
6351 including the order of evaluation of the
6352 @Chg{Version=[4],New=[@SynI{tested_}@nt{simple_expression}],Old=[@nt{simple_expression}]}
6353 and @nt{membership_choice}s.]}
6354 @end{Honest}
6355 @end{RunTime}
6356
6357 @begin{ImplReq}
6358 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0016],ARef=[AI95-00123-01]}
6359 @ChgAdded{Version=[1],Text=[For all nonlimited types declared in
6360 language-defined packages, the "=" and "/=" operators of the type shall behave
6361 as if they were the predefined equality operators for the purposes of the
6362 equality of composite types and generic formal types.]}
6363 @begin{Ramification}
6364 @ChgRef{Version=[1],Kind=[Added],ARef=[AI95-00123-01]}
6365 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0123-1]}
6366 @ChgAdded{Version=[1],Text=[If any language-defined types are implemented with
6367 a user-defined "=" operator, then either the full type must be @Chg{Version=[3],
6368 New=[a record type],Old=[tagged]}, or the compiler must
6369 use @lquotes@;magic@rquotes@; to implement equality for this type. A normal
6370 user-defined "=" operator for @Chg{Version=[3],New=[a non-record],Old=[an untagged]}
6371 type does @i{not} meet this requirement.]}
6372 @end{Ramification}
6373 @end{ImplReq}
6374
6375 @begin{Notes}
6376 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]}
6377 @ChgDeleted{Version=[2],Text=[No exception is ever raised by a membership test,
6378 by a predefined ordering operator, or by a predefined equality operator for an
6379 elementary type, but an exception can be raised by the evaluation of the
6380 operands. A predefined equality operator for a composite type can only raise an
6381 exception if the type has a tagged part whose primitive equals operator
6382 propagates an exception.]}
6383
6384 If a composite type has components that depend on discriminants, two values
6385 of this type have matching components if and only if their
6386 discriminants are equal. Two nonnull arrays have matching components
6387 if and only if the length of each dimension is the same for both.
6388 @end{Notes}
6389
6390 @begin{Examples}
6391 @Leading@keepnext@i(Examples of expressions involving relational operators and
6392 membership tests:)
6393 @begin{Example}
6394 X /= Y
6395
6396 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
6397 @Chg{Version=[5],New=[S : String := "A";
6398 ],Old=[]}"" < @Chg{Version=[5],New=[S],Old=["A"]} @key(and) @Chg{Version=[5],New=[S],Old=["A"]} < "Aa" @Chg{Version=[5],New=[ ],Old=[]}--@RI[ True]
6399 @Chg{Version=[5],New=[S],Old=["A"]} < @Chg{Version=[5],New=["Bb"],Old=["B"]} @key(and) @Chg{Version=[5],New=[S],Old=["A"]} < "A " @Chg{Version=[5],New=[ ],Old=[]}--@RI[ True]
6400
6401 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
6402 My_Car = @key(null) --@RI[ @Chg{Version=[3],New=[True],Old=[true]} if My_Car has been set to null (see @RefSecNum{Incomplete Type Declarations})]
6403 My_Car = Your_Car --@RI[ @Chg{Version=[3],New=[True],Old=[true]} if we both share the same car]
6404 My_Car.@key[all] = Your_Car.@key[all] --@RI[ @Chg{Version=[3],New=[True],Old=[true]} if the two cars are identical]
6405
6406 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0158-1]}
6407 N @key(not) @key(in) 1 .. 10 --@RI[ range membership test]
6408 Today @key(in) Mon .. Fri --@RI[ range membership test]
6409 Today @key(in) Weekday --@RI[ subtype membership test (see @RefSecNum{Enumeration Types})]@Chg{Version=[3],New=[
6410 Card @key(in) Clubs | Spades --@RI[ list membership test (see @RefSecNum{Enumeration Types})]],Old=[]}
6411 Archive @key(in) Disk_Unit --@RI[ subtype membership test (see @RefSecNum{Variant Parts and Discrete Choices})]
6412 Tree.@key(all) @key(in) Addition'Class --@RI[ class membership test (see @RefSecNum{Type Extensions})]
6413 @end{Example}
6414 @end{Examples}
6415
6416 @begin{Extend83}
6417 @Defn{extensions to Ada 83}
6418 Membership tests can be used to test the tag of a class-wide value.
6419
6420 Predefined equality for a composite type
6421 is defined in terms of the primitive equals operator
6422 for tagged components or the parent part.
6423 @end{Extend83}
6424
6425 @begin{DiffWord83}
6426 The term @lquotes@;membership test@rquotes@; refers to the @nt<relation> "X in S" rather
6427 to simply the reserved word @key(in) or @key(not in).
6428
6429 We use the term @lquotes@;equality operator@rquotes@; to refer to both
6430 the = (equals) and /= (not equals) operators.
6431 Ada 83 referred to = as @i(the) equality operator, and
6432 /= as the inequality operator. The new wording is more
6433 consistent with the ISO 10646 name for "=" (equals sign) and provides a
6434 category similar to @lquotes@;ordering operator@rquotes@; to refer to both
6435 = and /=.
6436
6437 We have changed the term @lquotes@;catenate@rquotes@; to @lquotes@;concatenate@rquotes@;.
6438 @end{DiffWord83}
6439
6440 @begin{Extend95}
6441 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00420-01]}
6442 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}The @i{universal_access}
6443 equality operators are new. They provide equality operations (most
6444 importantly, testing against @key{null}) for anonymous access types.]}
6445 @end{Extend95}
6446
6447 @begin{DiffWord95}
6448 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0016],ARef=[AI95-00123-01]}
6449 @Chg{Version=[2],New=[@b<Corrigendum:> Wording was added to clarify that
6450 the order of calls (and whether the calls are made at all) on "=" for
6451 components is unspecified. Also clarified that "=" must compose properly for
6452 language-defined types.],Old=[]}
6453
6454 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
6455 @Chg{Version=[2],New=[Memberships were adjusted to allow interfaces which don't
6456 cover the tested type, in order to be consistent with type
6457 conversions.],Old=[]}
6458 @end{DiffWord95}
6459
6460 @begin{Inconsistent2005}
6461 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0123-1]}
6462 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}
6463 User-defined untagged record equality is now defined to compose and be used in
6464 generics. Any code which assumes that the predefined equality reemerges
6465 in generics and in predefined equals for composite types could fail.
6466 However, it is much more likely that this change will fix bugs, as the
6467 behavior that would be expected (the user-defined "=" is used) will be
6468 true in more cases.]}
6469
6470 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0123-1]}
6471 @ChgAdded{Version=[3],Text=[If a composite type contains
6472 a component of an untagged record type with an abstract equality operation,
6473 calling "=" on the composite type will raise Program_Error, while in the
6474 past a result will be returned using the predefined equality. This is
6475 quite possible in ASIS programs; it will detect a bug in such programs but
6476 of course the programs will need to be fixed before they will work.]}
6477 @end{Inconsistent2005}
6478
6479 @begin{Incompatible2005}
6480 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0123-1]}
6481 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
6482 Late and hidden overriding of equality for untagged record types is now
6483 prohibited. This is necessary to make composition of equality predictable.
6484 It should always be possible to move the overriding to an earlier spot
6485 where it will be legal.]}
6486 @end{Incompatible2005}
6487
6488 @begin{Extend2005}
6489 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0149-1]}
6490 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Membership tests
6491 for valid accessibility levels and tag coverage by the designated type
6492 for general access types are new.]}
6493
6494 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
6495 @ChgAdded{Version=[3],Text=[Membership tests now include a predicate check.]}
6496
6497 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0158-1]}
6498 @ChgAdded{Version=[3],Text=[Membership tests now allow multiple choices.]}
6499 @end{Extend2005}
6500
6501 @begin{DiffWord2005}
6502 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0020-1]}
6503 @ChgAdded{Version=[3],Text=[@b<Correction:> Wording was added to clarify
6504 that @i{universal_access} "=" does not apply if an appropriate operator is
6505 declared for a partial or incomplete view of the designated type.
6506 Otherwise, adding a partial or incomplete view could make some "=" operators
6507 ambiguous.]}
6508 @end{DiffWord2005}
6509
6510 @begin{Inconsistent2012}
6511 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0101-1]}
6512 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b{Corrigendum:}
6513 Removed the incompatible rule preventing the declaration of "=" in the
6514 private part of a package specification for an untagged record type that
6515 completes a private type. Any code that calls the
6516 predefined "=" on the private type will now execute the body for the
6517 redefined "=" instead for the predefined "=". Eliminating the rule eliminates
6518 an unnecessary incompatibility (especially for programs that never call the
6519 predefined "="). Moreover, (like the composition of untagged record "=" in
6520 Ada 2012) this is more likely to fix bugs than cause
6521 them (who defines an "=" with a presumably different result and does not want
6522 clients to use it?).]}
6523 @end{Inconsistent2012}
6524
6525 @begin{Incompatible2012}
6526 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0328-1]}
6527 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}A membership
6528 test is now illegal if all of the following are True:]}
6529 @begin{Itemize}
6530 @ChgRef{Version=[5],Kind=[AddedNormal]}
6531 @ChgAdded{Version=[5],Text=[The membership test has one or more @SynI{choice_}@nt{simple_expression}s;]}
6532
6533 @ChgRef{Version=[5],Kind=[AddedNormal]}
6534 @ChgAdded{Version=[5],Text=[The membership test occurs in a place where the tested type is nonlimited;]}
6535
6536 @ChgRef{Version=[5],Kind=[AddedNormal]}
6537 @ChgAdded{Version=[5],Text=[The tested type has a limited view with a primitive "=" operator;]}
6538
6539 @ChgRef{Version=[5],Kind=[AddedNormal]}
6540 @ChgAdded{Version=[5],Text=[The full type of the tested type is not a record type or a record extension.]}
6541 @end{Itemize}
6542
6543 @ChgRef{Version=[5],Kind=[AddedNormal]}
6544 @ChgAdded{Version=[5],Text=[In such a case, the limited and nonlimited views
6545 would use different equality operators, which would be confusing and would
6546 various semantic difficulties. We believe such cases to be quite rare,
6547 especially as such membership tests are new to Ada 2012. The workaround is
6548 to replace such memberships with equality tests (assuming that the
6549 primitive "=" is intended; the predefined "=" is hidden in such cases and
6550 an extra type is needed to make it accessible).]}
6551 @end{Incompatible2012}
6552
6553 @begin{DiffWord2012}
6554 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0039-1]}
6555 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Reworded membership tests to use
6556 the syntax items @SynI{tested_}@nt{simple_expression} and
6557 @SynI{choice_}@nt{simple_expression}. This was necessary to eliminate
6558 wording ambiguities introduced when the grammar was corrected to eliminate
6559 syntax ambiguities. (Both of the above are now @nt{simple_expression}s, so
6560 merely talking about a @nt{simple_expression} is insufficient.)]}
6561
6562 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
6563 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of the
6564 membership tests to use the new term "satisfies the predicates"
6565 (see @RefSecNum{Subtype Predicates}).]}
6566 @end{DiffWord2012}
6567
6568
6569
6570 @LabeledSubClause{Binary Adding Operators}
6571
6572 @begin{StaticSem}
6573 @Leading@Defn{binary adding operator}@Defn2{Term=[operator],Sec=(binary adding)}
6574 @Defn{+ operator}@Defn2{Term=[operator],Sec=(+)}
6575 @Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)}
6576 @Defn{- operator}@Defn2{Term=[operator],Sec=(-)}
6577 @Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)}
6578 The binary adding operators + (addition) and @en (subtraction) are predefined
6579 for every specific numeric type @i(T) with their
6580 conventional meaning.
6581 They have the following specifications:
6582 @begin(example)
6583 @key(function) "+"(Left, Right : @RI(T)) @key(return) @RI(T)
6584 @key(function) "-"(Left, Right : @RI(T)) @key(return) @RI(T)
6585 @end(example)
6586
6587 @Leading@Defn{& operator}@Defn2{Term=[operator],Sec=(&)}
6588 @Defn{ampersand operator}@Defn2{Term=[operator],Sec=(ampersand)}
6589 @Defn{concatenation operator}@Defn2{Term=[operator],Sec=(concatenation)}
6590 @IndexSee{Term=[catenation operator],See=(concatenation operator)}
6591 The concatenation operators & are predefined for
6592 every nonlimited,
6593 one-dimensional array type @i(T) with component type @i(C).
6594 They have the following specifications:
6595 @begin(example)
6596 @key(function) "&"(Left : @RI(T); Right : @RI(T)) @key(return) @RI(T)
6597 @key(function) "&"(Left : @RI(T); Right : @RI(C)) @key(return) @RI(T)
6598 @key(function) "&"(Left : @RI(C); Right : @RI(T)) @key(return) @RI(T)
6599 @key(function) "&"(Left : @RI(C); Right : @RI(C)) @key(return) @RI(T)
6600 @end(example)
6601 @end{StaticSem}
6602
6603 @begin{RunTime}
6604
6605 @Leading@PDefn2{Term=[evaluation], Sec=(concatenation)}
6606 For the evaluation of a concatenation with result type @i(T),
6607 if both operands are of type @i(T), the result of the concatenation
6608 is a one-dimensional array whose length is the sum of the lengths
6609 of its operands, and whose components comprise the components of
6610 the left operand followed by the components of the right operand.
6611 If the left operand is a null array, the result of the
6612 concatenation is the right operand.
6613 Otherwise, the lower bound of the result is determined as
6614 follows:
6615 @begin(Itemize)
6616 If the ultimate ancestor of the array type was defined
6617 by a @nt<constrained_array_definition>, then
6618 the lower bound of the result is that of the index subtype;
6619 @begin(Reason)
6620 This rule avoids Constraint_Error when using concatenation
6621 on an array type whose first subtype is constrained.
6622 @end(Reason)
6623
6624 If the ultimate ancestor of the array type was defined
6625 by an @nt<unconstrained_array_definition>, then
6626 the lower bound of the result is that of the left operand.
6627 @end(Itemize)
6628
6629 @Redundant[The upper bound is determined by the lower bound and the length.]
6630 @IndexCheck{Index_Check}
6631 A check is made that the upper bound of the result of the
6632 concatenation belongs to the range of the index subtype, unless the
6633 result is a null array.
6634 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
6635 Constraint_Error is raised if this check fails.
6636
6637 If either operand is of the component type @i(C), the result of the
6638 concatenation is given by the above rules, using in place of such an operand
6639 an array having this operand as its only component (converted
6640 to the component subtype)
6641 and having the lower bound
6642 of the index subtype of the array type as its lower bound.
6643 @PDefn2{Term=[implicit subtype conversion],Sec=(operand of concatenation)}
6644 @begin{Ramification}
6645 The conversion might raise Constraint_Error.
6646 The conversion provides @lquotes@;sliding@rquotes@;
6647 for the component in the case of an array-of-arrays, consistent with
6648 the normal Ada 95 rules that allow sliding during parameter passing.
6649 @end{Ramification}
6650
6651 @Defn2{Term=[assignment operation], Sec=(during evaluation of concatenation)}
6652 The result of a concatenation is defined in terms of an
6653 assignment to an anonymous object,
6654 as for any function call (see @RefSecNum{Return Statements}).
6655 @begin{Ramification}
6656 This implies that value adjustment is performed as appropriate
6657 @em see @RefSecNum{Assignment and Finalization}.
6658 We don't bother saying this for other predefined operators,
6659 even though they are all function calls,
6660 because this is the only one where it matters.
6661 It is the only one that can return a value having controlled parts.
6662 @end{Ramification}
6663 @end{RunTime}
6664
6665 @begin{Notes}
6666 As for all predefined operators on modular types, the binary adding
6667 operators + and @en on modular types include a final
6668 reduction modulo the modulus if the result is outside
6669 the base range of the type.
6670 @begin{ImplNote}
6671 A full "modulus" operation need not be performed after
6672 addition or subtraction of modular types. For binary moduli,
6673 a simple mask is sufficient. For nonbinary moduli, a check after
6674 addition to see if the value is greater than the high bound of
6675 the base range can be followed by a conditional subtraction of the modulus.
6676 Conversely, a check after subtraction to see if a "borrow" was
6677 performed can be followed by a conditional addition of the modulus.
6678 @end{ImplNote}
6679 @end{Notes}
6680
6681 @begin{Examples}
6682 @Leading@keepnext@i(Examples of expressions involving binary adding operators:)
6683 @begin{Example}
6684 Z + 0.1 --@RI[ Z has to be of a real type ]
6685
6686 "A" & "BCD" --@RI[ concatenation of two string literals]
6687 'A' & "BCD" --@RI[ concatenation of a character literal and a string literal]
6688 'A' & 'A' --@RI[ concatenation of two character literals ]
6689 @end{Example}
6690 @end{Examples}
6691
6692 @begin{Inconsistent83}
6693 @Defn{inconsistencies with Ada 83}
6694 The lower bound of the result of concatenation,
6695 for a type whose first subtype is constrained, is
6696 now that of the index subtype. This is inconsistent with Ada 83,
6697 but generally only for Ada 83 programs that raise Constraint_Error.
6698 For example, the concatenation operator in
6699 @begin(Example)
6700 X : @key(array)(1..10) @key(of) Integer;
6701 @key(begin)
6702 X := X(6..10) & X(1..5);
6703 @end(Example)
6704
6705 would raise Constraint_Error in Ada 83 (because
6706 the bounds of the result of the concatenation would be 6..15, which is outside
6707 of 1..10),
6708 but would succeed and swap the halves of X (as expected) in Ada 95.
6709 @end{Inconsistent83}
6710
6711 @begin{Extend83}
6712 @Defn{extensions to Ada 83}
6713 Concatenation is now useful for array types whose
6714 first subtype is constrained.
6715 When the result type of a concatenation
6716 is such an array type,
6717 Constraint_Error is avoided by effectively
6718 first sliding the left operand (if nonnull) so that
6719 its lower bound is that of the index subtype.
6720 @end{Extend83}
6721
6722 @LabeledSubClause{Unary Adding Operators}
6723
6724 @begin{StaticSem}
6725 @Leading@Defn{unary adding operator}@Defn2{Term=[operator],Sec=(unary adding)}
6726 @Defn{+ operator}@Defn2{Term=[operator],Sec=(+)}
6727 @Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)}
6728 @Defn{- operator}@Defn2{Term=[operator],Sec=(-)}
6729 @Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)}
6730 The unary adding operators + (identity) and @en (negation) are predefined
6731 for every specific numeric type @i(T) with their
6732 conventional meaning.
6733 They have the following specifications:
6734 @begin(example)
6735 @key(function) "+"(Right : @RI(T)) @key(return) @RI(T)
6736 @key(function) "-"(Right : @RI(T)) @key(return) @RI(T)
6737 @end(example)
6738 @end{StaticSem}
6739
6740 @begin{Notes}
6741 For modular integer types, the unary adding operator @en, when
6742 given a nonzero operand, returns the result of subtracting
6743 the value of the operand from the modulus;
6744 for a zero operand, the result is zero.
6745 @end{Notes}
6746
6747 @LabeledSubClause{Multiplying Operators}
6748
6749 @begin{StaticSem}
6750 @Leading@Defn{multiplying operator}@Defn2{Term=[operator],Sec=(multiplying)}
6751 @Defn{* operator}@Defn2{Term=[operator],Sec=(*)}
6752 @Defn{multiply operator}@Defn2{Term=[operator],Sec=(multiply)}
6753 @Defn{times operator}@Defn2{Term=[operator],Sec=(times)}
6754 @Defn{/ operator}@Defn2{Term=[operator],Sec=(/)}
6755 @Defn{divide operator}@Defn2{Term=[operator],Sec=(divide)}
6756 @Defn{mod operator}@Defn2{Term=[operator],Sec=(mod)}
6757 @Defn{rem operator}@Defn2{Term=[operator],Sec=(rem)}
6758 The multiplying operators * (multiplication), / (division),
6759 @key(mod) (modulus), and @key(rem) (remainder)
6760 are predefined for every specific integer type @i(T):
6761 @begin(example)
6762 @key(function) "*" (Left, Right : @RI(T)) @key(return) @RI(T)
6763 @key(function) "/" (Left, Right : @RI(T)) @key(return) @RI(T)
6764 @key(function) "@key(mod)"(Left, Right : @RI(T)) @key(return) @RI(T)
6765 @key(function) "@key(rem)"(Left, Right : @RI(T)) @key(return) @RI(T)
6766 @end(example)
6767
6768 Signed integer multiplication has its conventional meaning.
6769
6770 @Leading@keepnext@;Signed integer division and remainder are defined by the relation:
6771 @begin(example)
6772 A = (A/B)*B + (A @key(rem) B)
6773 @end(example)
6774
6775 @Leading@;where (A @key(rem) B) has the sign of A and an absolute value less than
6776 the absolute value of B. Signed integer division satisfies the identity:
6777 @begin(example)
6778 (-A)/B = -(A/B) = A/(-B)
6779 @end(example)
6780
6781 @begin{WideAbove}
6782 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0260-1]}
6783 The signed integer modulus operator is defined such
6784 that the result of A @key(mod) B @Chg{Version=[3],New=[is either zero,
6785 or ],Old=[]}has the sign of B and an absolute value less than the
6786 absolute value of B; in addition, for some signed integer value N, this result
6787 satisfies the relation:
6788 @begin(example)
6789 A = B*N + (A @key(mod) B)
6790 @end(example)
6791
6792 The multiplying operators on modular types are defined in terms
6793 of the corresponding signed integer operators@Redundant[, followed by a reduction
6794 modulo the modulus if the result is outside
6795 the base range of the type] @Redundant[(which is only possible for the "*"
6796 operator)].
6797 @begin{Ramification}
6798 The above identity satisfied by signed integer
6799 division is not satisfied by modular division
6800 because of the difference in effect of negation.
6801 @end{Ramification}
6802 @end{WideAbove}
6803
6804 @Leading@;Multiplication and division operators are predefined for
6805 every specific floating point type @i(T):
6806 @begin(example)
6807 @key(function) "*"(Left, Right : @RI(T)) @key(return) @RI(T)
6808 @key(function) "/"(Left, Right : @RI(T)) @key(return) @RI(T)
6809 @end(example)
6810
6811 @Leading@;The following multiplication and division operators, with
6812 an operand of the predefined type Integer, are predefined
6813 for every specific fixed point type @i(T):
6814 @begin(example)
6815 @key(function) "*"(Left : @RI(T); Right : Integer) @key(return) @RI(T)
6816 @key(function) "*"(Left : Integer; Right : @RI(T)) @key(return) @RI(T)
6817 @key(function) "/"(Left : @RI(T); Right : Integer) @key(return) @RI(T)
6818 @end(example)
6819
6820 @Leading@Redundant[All of the above multiplying operators
6821 are usable with an operand
6822 of an appropriate universal numeric type.] The following additional
6823 multiplying operators for @i(root_real) are predefined@Redundant[,
6824 and are usable when both operands are of an appropriate universal or
6825 root numeric type, and the result is allowed to be of
6826 type @i(root_real), as in a @nt<number_declaration>]:
6827 @begin{Ramification}
6828 These operators
6829 are analogous to the multiplying operators
6830 involving fixed or floating point types
6831 where @i(root_real) substitutes for the
6832 fixed or floating point type,
6833 and @i(root_integer) substitutes for Integer.
6834 Only values of the corresponding universal numeric types are
6835 implicitly convertible to these root numeric types,
6836 so these operators are really restricted to use with
6837 operands of a universal type, or the specified
6838 root numeric types.
6839 @end{Ramification}
6840 @begin(example)
6841 @key(function) "*"(Left, Right : @RI(root_real)) @key(return) @RI(root_real)
6842 @key(function) "/"(Left, Right : @RI(root_real)) @key(return) @RI(root_real)
6843
6844 @key(function) "*"(Left : @RI(root_real); Right : @RI(root_integer)) @key(return) @RI(root_real)
6845 @key(function) "*"(Left : @RI(root_integer); Right : @RI(root_real)) @key(return) @RI(root_real)
6846 @key(function) "/"(Left : @RI(root_real); Right : @RI(root_integer)) @key(return) @RI(root_real)
6847 @end(example)
6848
6849 @Leading@;Multiplication and division between any two fixed point types are
6850 provided by the following two predefined operators:
6851 @begin{Ramification}
6852 @i(Universal_fixed) is the universal type for the class of
6853 fixed point types, meaning that these operators take operands
6854 of any fixed point types (not necessarily the same)
6855 and return a result that is implicitly (or explicitly) convertible to
6856 any fixed point type.
6857 @end{Ramification}
6858 @begin(example)
6859 @key(function) "*"(Left, Right : @RI(universal_fixed)) @key(return) @RI(universal_fixed)
6860 @key(function) "/"(Left, Right : @RI(universal_fixed)) @key(return) @RI(universal_fixed)
6861 @end(example)
6862 @end{StaticSem}
6863
6864 @begin{Resolution}
6865 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
6866 @ChgAdded{Version=[2],Type=[Leading],Text=[The above two fixed-fixed
6867 multiplying operators shall
6868 not be used in a context where the expected type for the result is itself
6869 @i(universal_fixed) @Redundant[@em the context has to identify some other
6870 numeric type to which the result is to be converted, either explicitly or
6871 implicitly]. Unless the predefined universal operator is identified using an
6872 expanded name with @nt{prefix} denoting the package Standard, an explicit
6873 conversion is required on the result when using the above fixed-fixed
6874 multiplication operator if either operand is of a type having a user-defined
6875 primitive multiplication operator such that:]}
6876 @begin{Itemize}
6877 @ChgRef{Version=[2],Kind=[Added]}
6878 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0020-1],ARef=[AI05-0209-1]}
6879 @ChgAdded{Version=[2],Text=[it is declared immediately within the same
6880 declaration list as the type@Chg{Version=[3],New=[ or any partial
6881 or incomplete view thereof],Old=[]}; and]}
6882
6883 @ChgRef{Version=[2],Kind=[Added]}
6884 @ChgAdded{Version=[2],Text=[both of its formal parameters are of a
6885 fixed-point type.]}
6886 @end{Itemize}
6887 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
6888 @ChgAdded{Version=[2],Text=[A corresponding requirement applies to the
6889 universal fixed-fixed division operator.]}
6890
6891 @begin(Discussion)
6892 @ChgRef{Version=[2],Kind=[AddedNormal]}
6893 @ChgAdded{Version=[2],Text=[The @i(small) of @i(universal_fixed) is
6894 infinitesimal; no loss of precision is permitted.
6895 However, fixed-fixed division is impractical to implement when
6896 an exact result is required,
6897 and multiplication will sometimes result in unanticipated overflows
6898 in such circumstances,
6899 so we require an explicit conversion to be inserted in
6900 expressions like A * B * C if A, B, and C are each of some fixed point
6901 type.]}
6902
6903 @ChgRef{Version=[2],Kind=[AddedNormal]}
6904 @ChgAdded{Version=[2],Text=[On the other hand, X := A * B; is permitted by
6905 this rule, even if X, A, and B
6906 are all of different fixed point types, since the expected type
6907 for the result of the multiplication is the type of X, which is necessarily
6908 not @i(universal_fixed).]}
6909
6910 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
6911 @ChgAdded{Version=[2],Text=[We have made these into Name Resolution rules to
6912 ensure that user-defined primitive fixed-fixed operators are not made unusable
6913 due to the presence of these universal fixed-fixed operators. But we do allow
6914 these operators to be used if prefixed by package Standard, so that they can be
6915 used in the definitions of user-defined operators.]}
6916 @end(Discussion)
6917 @end{Resolution}
6918
6919 @begin{Legality}
6920 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00364-01]}
6921 @ChgDeleted{Version=[2],Text=[The above two fixed-fixed multiplying operators
6922 shall not be used in a context where the expected type for the result
6923 is itself @i(universal_fixed) @em @Redundant[the context has to
6924 identify some other numeric type to which the result is to be converted,
6925 either explicitly or implicitly].]}
6926 @begin(Discussion)
6927 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
6928 @ChgDeleted{Version=[2],Text=[The @i(small) of @i(universal_fixed) is infinitesimal; no loss
6929 of precision is permitted.
6930 However, fixed-fixed division is impractical to implement when
6931 an exact result is required,
6932 and multiplication will sometimes result in unanticipated overflows
6933 in such circumstances,
6934 so we require an explicit conversion to be inserted in
6935 expressions like A * B * C if A, B, and C are each of some fixed point
6936 type.]}
6937
6938 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
6939 @ChgDeleted{Version=[2],Text=[On the other hand, X := A * B; is permitted by this rule, even if X, A, and B
6940 are all of different fixed point types, since the expected type
6941 for the result of the multiplication is the type of X, which is necessarily
6942 not @i(universal_fixed).]}
6943 @end(Discussion)
6944 @end{Legality}
6945 @begin{NotIso}
6946 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Paragraph 20 was
6947 deleted.>}]}@Comment{This message should be deleted if the paragraphs
6948 are ever renumbered.}
6949 @end{NotIso}
6950
6951 @begin{RunTime}
6952 The multiplication and division operators for real types have
6953 their conventional meaning.
6954 @redundant[For floating point types, the accuracy of the result is
6955 determined by the precision of the result type.
6956 For decimal fixed point types, the result is truncated toward zero
6957 if the mathematical result is between two multiples of the @i(small)
6958 of the specific result type (possibly determined by context);
6959 for ordinary fixed point types, if the mathematical result is
6960 between two multiples of the @i(small), it is unspecified
6961 which of the two is the result.
6962 @PDefn{unspecified}]
6963
6964 @IndexCheck{Division_Check}
6965 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
6966 The exception Constraint_Error is raised by
6967 integer division, @key(rem),
6968 and @key(mod) if the right operand is zero.
6969 @Redundant[Similarly, for a real type @i(T) with @i(T')Machine_Overflows
6970 True, division by zero raises Constraint_Error.]
6971 @end{RunTime}
6972
6973 @begin{Notes}
6974 @Leading@Keepnext@;For positive A and B, A/B is the quotient and A @key(rem) B is
6975 the remainder when A is divided by B. The following relations are satisfied
6976 by the rem operator:
6977 @begin{Example}
6978 A @key(rem) (-B) = A @key(rem) B
6979 (-A) @key(rem) B = -(A @key(rem) B)
6980 @end{Example}
6981
6982 @Leading@keepnext@;For any signed integer K, the following identity holds:
6983 @begin{Example}
6984 A @key(mod) B = (A + K*B) @key(mod) B
6985 @end{Example}
6986 @begin{Bundle}
6987 @NoPrefix@Leading@;The relations between signed integer
6988 division, remainder, and modulus are
6989 illustrated by the following table:
6990 @begin{Example}
6991 A B A/B A @key(rem) B A @key(mod) B A B A/B A @key(rem) B A @key(mod) B
6992
6993 10 5 2 0 0 -10 5 -2 0 0
6994 11 5 2 1 1 -11 5 -2 -1 4
6995 12 5 2 2 2 -12 5 -2 -2 3
6996 13 5 2 3 3 -13 5 -2 -3 2
6997 14 5 2 4 4 -14 5 -2 -4 1
6998
6999 A B A/B A @key(rem) B A @key(mod) B A B A/B A @key(rem) B A @key(mod) B@*
7000 10 -5 -2 0 0 -10 -5 2 0 0
7001 11 -5 -2 1 -4 -11 -5 2 -1 -1
7002 12 -5 -2 2 -3 -12 -5 2 -2 -2
7003 13 -5 -2 3 -2 -13 -5 2 -3 -3
7004 14 -5 -2 4 -1 -14 -5 2 -4 -4
7005 @end{Example}
7006 @end{Bundle}
7007 @end{Notes}
7008
7009 @begin{Examples}
7010 @Leading@keepnext@i(Examples of expressions involving multiplying operators:)
7011 @begin{Example}
7012 I : Integer := 1;
7013 J : Integer := 2;
7014 K : Integer := 3;
7015
7016 X : Real := 1.0; --@RI[ see @RefSecNum{Floating Point Types}]
7017 Y : Real := 2.0;
7018
7019 F : Fraction := 0.25; --@RI[ see @RefSecNum{Fixed Point Types}]
7020 G : Fraction := 0.5;
7021 @end{Example}
7022 @begin{Example}
7023 @tabclear()@tabset(P19, P31)
7024 @RI(Expression) @\@RI(Value) @\@RI(Result Type)@*
7025 @R{I*J} @\@R{2} @\@RI(same as I and J, that is, Integer)
7026 @R{K/J} @\@R{1} @\@RI(same as K and J, that is, Integer)
7027 @R{K @key(mod) J} @\@R{1} @\@RI(same as K and J, that is, Integer)@*
7028 @R{X/Y} @\@R{0.5} @\@RI(same as X and Y, that is, Real)
7029 @R{F/2} @\@R{0.125} @\@RI(same as F, that is, Fraction)@*
7030 @R{3*F} @\@R{0.75} @\@RI(same as F, that is, Fraction)
7031 @R{0.75*G} @\@R{0.375} @\@RI(universal_fixed, implicitly convertible)
7032 @\ @\@RI(to any fixed point type)
7033 @R{Fraction(F*G)} @\@R{0.125} @\@RI(Fraction, as stated by the conversion)
7034 @R{Real(J)*Y} @\@R{4.0} @\@RI(Real, the type of both operands after)
7035 @\ @\@RI(conversion of J)
7036 @end{Example}
7037 @end{Examples}
7038
7039 @begin{Incompatible83}
7040 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]}
7041 @Chg{Version=[2],New=[@Defn{incompatibilities with Ada 83}The universal
7042 fixed-fixed multiplying operators are now directly available (see below).
7043 Any attempt to use user-defined fixed-fixed multiplying operators
7044 will be ambiguous with the universal ones. The only way to use the user-defined
7045 operators is to fully qualify them in a prefix call. This problem was not
7046 documented during the design of Ada 95, and has been mitigated by
7047 Ada 2005.],Old=[]}
7048 @end{Incompatible83}
7049
7050 @begin{Extend83}
7051 @Defn{extensions to Ada 83}
7052 Explicit conversion of the result of multiplying
7053 or dividing two fixed point numbers is no longer required,
7054 provided the context uniquely determines some specific
7055 fixed point result type.
7056 This is to improve support for decimal fixed point, where
7057 requiring explicit conversion on every fixed-fixed multiply
7058 or divide was felt to be inappropriate.
7059
7060 The type @i(universal_fixed) is covered by @i(universal_real),
7061 so real literals and fixed point operands may be multiplied
7062 or divided directly, without any explicit conversions required.
7063 @end{Extend83}
7064
7065 @begin{DiffWord83}
7066 We have used the normal syntax for function definition
7067 rather than a tabular format.
7068 @end{DiffWord83}
7069
7070
7071 @begin{Incompatible95}
7072 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00364-01]}
7073 @Chg{Version=[2],New=[@Defn{incompatibilities with Ada 95}We have changed the
7074 resolution rules for the universal fixed-fixed multiplying operators to remove
7075 the incompatibility with Ada 83 discussed above. The solution is to hide
7076 the universal operators in some circumstances. As a result, some legal Ada 95
7077 programs will require the insertion of an explicit conversion around a
7078 fixed-fixed multiply operator. This change is likely to catch as many bugs as
7079 it causes, since it is unlikely that the user wanted to use predefined
7080 operators when they had defined user-defined versions.],Old=[]}
7081 @end{Incompatible95}
7082
7083 @begin{DiffWord2005}
7084 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0020-1],ARef=[AI05-0209-1]}
7085 @ChgAdded{Version=[3],Text=[@b<Correction:> Wording was added to clarify
7086 that @i{universal_fixed} "*" and "/" does not apply if an appropriate
7087 operator is declared for a partial (or incomplete) view of the designated type.
7088 Otherwise, adding a partial (or incomplete) view could make some
7089 "*" and "/" operators ambiguous.]}
7090
7091 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0260-1]}
7092 @ChgAdded{Version=[3],Text=[@b<Correction:> The wording for the @key[mod]
7093 operator was corrected so that a result of 0 does not have to have
7094 "the sign of B" (which is impossible if B is negative).]}
7095 @end{DiffWord2005}
7096
7097
7098 @LabeledSubClause{Highest Precedence Operators}
7099
7100 @begin{StaticSem}
7101 @Leading@Defn{highest precedence operator}@Defn2{Term=[operator],Sec=(highest precedence)}
7102 @Defn{abs operator}@Defn2{Term=[operator],Sec=(abs)}
7103 @Defn{absolute value}
7104 The highest precedence unary operator @key(abs) (absolute value)
7105 is predefined for every specific numeric type @i(T),
7106 with the following specification:
7107 @begin(example)
7108 @key(function) "@key(abs)"(Right : @RI(T)) @key(return) @RI(T)
7109 @end(example)
7110
7111 @Leading@Defn{not operator}@Defn2{Term=[operator],Sec=(not)}
7112 @IndexSeeAlso{Term=[logical operator],See=(not operator)}
7113 The highest precedence unary operator @key(not) (logical negation) is
7114 predefined for every boolean type @i(T),
7115 every modular type @i(T),
7116 and for every one-dimensional array type @i(T) whose
7117 components are of a boolean type,
7118 with the following specification:
7119 @begin(example)
7120 @key(function) "@key(not)"(Right : @RI(T)) @key(return) @RI(T)
7121 @end(example)
7122
7123 The result of the operator @key(not) for a modular type is
7124 defined as the difference between the high bound of the base range
7125 of the type and the value of the operand. @Redundant[For
7126 a binary modulus, this corresponds to a bit-wise complement
7127 of the binary
7128 representation of the value
7129 of the operand.]
7130
7131 The operator @key(not) that applies
7132 to a one-dimensional array of boolean
7133 components yields a one-dimensional boolean array with the same bounds;
7134 each component of the result is obtained by logical negation of the
7135 corresponding component of the operand (that is, the component that
7136 has the same index value).
7137 @IndexCheck{Range_Check}
7138 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
7139 A check is made that each component of the result belongs to the
7140 component subtype; the exception Constraint_Error is raised if this
7141 check fails.
7142 @begin{Discussion}
7143 The check against the component subtype is per AI83-00535.
7144 @end{Discussion}
7145
7146 @Leading@Defn{exponentiation operator}@Defn2{Term=[operator],Sec=(exponentiation)}
7147 @Defn{** operator}@Defn2{Term=[operator],Sec=(**)}
7148 The highest precedence @i(exponentiation) operator ** is predefined
7149 for every specific integer type @i(T)
7150 with the following specification:
7151 @begin(example)
7152 @key(function) "**"(Left : @RI(T); Right : Natural) @key(return) @RI(T)
7153 @end(example)
7154
7155 @Leading@;Exponentiation is also predefined for
7156 every specific floating point type
7157 as well as @i{root_real},
7158 with the following specification (where @i(T) is @i{root_real}
7159 or the floating point type):
7160 @begin(example)
7161 @key(function) "**"(Left : @RI(T); Right : Integer'Base) @key(return) @RI(T)
7162 @end(example)
7163
7164 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0088-1]}
7165 @Defn{exponent}
7166 The right operand of an exponentiation is the @i(exponent).
7167 The @Chg{Version=[3],New=[value of],Old=[expression]} X**N with the value of
7168 the exponent N positive is @Chg{Version=[3],New=[the same as the value of],
7169 Old=[equivalent to the expression]} X*X*...X (with N@en@;1 multiplications)
7170 except that the multiplications
7171 are associated in an arbitrary order. With N equal to zero, the result is one.
7172 With the value of N negative
7173 @Redundant[(only defined for a floating point operand)],
7174 the result is the reciprocal of the result using the absolute value of
7175 N as the exponent.
7176 @begin{Ramification}
7177 The language does not specify the order of association of the multiplications
7178 inherent in an exponentiation. For a floating point type,
7179 the accuracy of the result might depend on the particular
7180 association order chosen.
7181 @end{Ramification}
7182
7183 @end{StaticSem}
7184
7185 @begin{ImplPerm}
7186 The implementation of
7187 exponentiation for the case of a negative exponent
7188 is allowed to raise Constraint_Error
7189 if the intermediate result of the repeated multiplications
7190 is outside the safe range of the type, even though the final
7191 result (after taking the reciprocal)
7192 would not be.
7193 (The best machine approximation to the
7194 final result in this case would generally be 0.0.)
7195 @end{ImplPerm}
7196
7197 @begin{Notes}
7198 @IndexCheck{Range_Check}
7199 As implied by the specification given above
7200 for exponentiation of an integer type, a check is made that
7201 the exponent is not negative.
7202 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)}
7203 Constraint_Error is raised if this check fails.
7204 @end{Notes}
7205
7206 @begin{Inconsistent83}
7207 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0100],ARef=[AI95-00018-01]}
7208 @ChgAdded{Version=[1],Text=[@Defn{inconsistencies with Ada 83}
7209 The definition of "**" allows arbitrary association of the
7210 multiplications which make up the result. Ada 83 required left-to-right
7211 associations (confirmed by AI83-00137). Thus it is possible that "**"
7212 would provide a slightly different (and more potentially accurate) answer in
7213 Ada 95 than in the same Ada 83 program.]}
7214 @end{Inconsistent83}
7215
7216 @begin{DiffWord83}
7217 We now show the specification for "**" for integer types
7218 with a parameter subtype of Natural rather than Integer for the exponent.
7219 This reflects the fact that Constraint_Error is raised if
7220 a negative value is provided for the exponent.
7221 @end{DiffWord83}
7222
7223 @begin{DiffWord2005}
7224 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0088-1]}
7225 @ChgAdded{Version=[3],Text=[@b<Correction:> The equivalence definition
7226 for "**" was corrected so that it does not imply that the operands
7227 are evaluated multiple times.]}
7228 @end{DiffWord2005}
7229
7230
7231 @LabeledAddedSubclause{Version=[3],Name=[Conditional Expressions]}
7232
7233 @begin{Intro}
7234 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1],ARef=[AI05-0262-1]}
7235 @ChgAdded{Version=[3],Text=[A @nt{conditional_expression} selects for evaluation
7236 at most one of the enclosed @SynI<dependent_>@nt{expression}s, depending on
7237 a decision among the alternatives. One
7238 kind of @nt{conditional_expression} is the @nt{if_expression}, which selects for
7239 evaluation a @SynI<dependent_>@nt{expression} depending on the value of one or more
7240 corresponding conditions. The other kind of @nt{conditional_expression} is the
7241 @nt{case_expression}, which selects for evaluation one of a number of alternative
7242 @SynI<dependent_>@nt{expression}s; the chosen alternative is determined by the
7243 value of a @SynI<selecting_>@nt{expression}.@defn{conditional expression}@defn{if expression}@defn{case expression}
7244 @Defn2{Term=[expression],Sec=[if]}@Defn2{Term=[expression],Sec=[case]}@Defn2{Term=[expression],Sec=[conditional]}]}
7245 @end{Intro}
7246
7247 @begin{MetaRules}
7248 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
7249 @ChgAdded{Version=[3],Text=[As previously noted, there are two kinds of
7250 @nt{conditional_expression}, @nt{if_expression}s and @nt{case_expression}s.
7251 Whenever possible, we have written the rules in terms of
7252 @nt{conditional_expression}s to avoid duplication.]}
7253
7254 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7255 @ChgAdded{Version=[3],Text=[The rules for @nt{conditional_expression}s
7256 have been designed as much as possible to work similarly to a parenthesized
7257 expression. The intent is that as much as possible, wherever a parenthesized
7258 expression would be allowed, a @nt{conditional_expression} would be allowed,
7259 and it should work the same way.]}
7260 @end{MetaRules}
7261
7262 @begin{Syntax}
7263 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
7264 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<conditional_expression>,Old=<>}>,
7265 rhs="@Chg{Version=[3],New=<@Syn2{if_expression} | @Syn2{case_expression}>,Old=<>}"}
7266
7267 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
7268 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<if_expression>,Old=<>}>,
7269 rhs="
7270 @Chg{Version=[3],New=<@key[if] @Syn2{condition} @key[then] @SynI{dependent_}@Syn2{expression}
7271 {@key[elsif] @Syn2{condition} @key[then] @SynI{dependent_}@Syn2{expression}}
7272 [@key[else] @SynI{dependent_}@Syn2{expression}]>,Old=<>}"}
7273
7274 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7275 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<condition>,Old=<>}>,
7276 rhs="@Chg{Version=[3],New=<@SynI{boolean_}@Syn2{expression}>,Old=<>}"}
7277 @Comment{Moved from "If Statements"}
7278
7279 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
7280 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<case_expression>,Old=<>}>,
7281 rhs="@Chg{Version=[3],New=<
7282 @key[case] @SynI{selecting_}@Syn2{expression} @key[is]
7283 @Syn2[case_expression_alternative] {,
7284 @Syn2[case_expression_alternative]}>,Old=<>}"}
7285
7286 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
7287 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<case_expression_alternative>,Old=<>}>,
7288 rhs="@Chg{Version=[3],New=[
7289 @key[when] @Syn2{discrete_choice_list} =>
7290 @SynI{dependent_}@Syn2{expression}],Old=<>}"}
7291
7292 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7293 @ChgAdded{Version=[3],Text=[Wherever the Syntax Rules allow an @nt{expression},
7294 a @nt{conditional_expression} may be used in place of the @nt{expression}, so
7295 long as it is immediately surrounded by parentheses.]}
7296
7297 @begin{Discussion}
7298 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7299 @ChgAdded{Version=[3],Text=[The syntactic category @nt{conditional_expression}
7300 appears only as a primary that is parenthesized. The above rule allows it to
7301 additionally be used in other contexts where it would be directly surrounded
7302 by parentheses.]}
7303
7304 @ChgRef{Version=[3],Kind=[AddedNormal]}
7305 @ChgAdded{Version=[3],Type=[Leading],Text=[The grammar makes the following directly legal:]}
7306
7307 @begin{Example}
7308 @ChgRef{Version=[3],Kind=[AddedNormal]}
7309 @ChgAdded{Version=[3],Text=[A := (@key[if] X @key[then] Y @key[else] Z); --@examcom{ parentheses required}
7310 A := B + (@key[if] X @key[then] Y @key[else] Z) + C; --@examcom{ parentheses required}]}
7311 @end{Example}
7312
7313 @ChgRef{Version=[3],Kind=[AddedNormal]}
7314 @ChgAdded{Version=[3],Type=[Leading],Text=[The following procedure calls are
7315 syntactically legal; the first uses the above rule to eliminate the redundant
7316 parentheses found in the second:]}
7317
7318 @begin{Example}
7319 @ChgRef{Version=[3],Kind=[AddedNormal]}
7320 @ChgAdded{Version=[3],Text=[P(@key[if] X @key[then] Y @key[else] Z);
7321 P((@key[if] X @key[then] Y @key[else] Z)); --@Examcom{ redundant parentheses}]}
7322
7323 @ChgRef{Version=[3],Kind=[AddedNormal]}
7324 @ChgAdded{Version=[3],Text=[P((@key[if] X @key[then] Y @key[else] Z), Some_Other_Param);
7325 P(Some_Other_Param, (@key[if] X @key[then] Y @key[else] Z));
7326 P(Formal => (@key[if] X @key[then] Y @key[else] Z));]}
7327 @end{Example}
7328
7329 @ChgRef{Version=[3],Kind=[AddedNormal]}
7330 @ChgAdded{Version=[3],Type=[Leading],Text=[whereas the following are illegal:]}
7331
7332 @begin{Example}
7333 @ChgRef{Version=[3],Kind=[AddedNormal]}
7334 @ChgAdded{Version=[3],Text=[P(@key[if] X @key[then] Y @key[else] Z, Some_Other_Param);
7335 P(Some_Other_Param, @key[if] X @key[then] Y @key[else] Z);
7336 P(Formal => @key[if] X @key[then] Y @key[else] Z);]}
7337 @end{Example}
7338
7339 @ChgRef{Version=[3],Kind=[AddedNormal]}
7340 @ChgAdded{Version=[3],Text=[because in these latter cases, the
7341 @nt{conditional_expression} is not immediately surrounded by parentheses (which
7342 means on both sides!).]}
7343
7344 @ChgRef{Version=[3],Kind=[AddedNormal]}
7345 @ChgAdded{Version=[3],Text=[The English-language rule applies in all places
7346 that could surround an expression with parentheses, including pragma
7347 arguments, type conversion and qualified expression operands, and array index
7348 expressions.]}
7349
7350 @ChgRef{Version=[3],Kind=[AddedNormal]}
7351 @ChgAdded{Version=[3],Text=[This English-language rule could have been
7352 implemented instead by adding a nonterminal
7353 @ntf{expression_within_parentheses}, which would consist of @nt{expression}s
7354 and @nt{conditional_expression}s. Then, that could be used in all of the
7355 syntax which could consist of parens directly around an @nt{expression}. We
7356 did not do that because of the large amount of change required. A complete
7357 grammar is given in @AILink{AI=[AI05-0147-1],Text=[AI05-0147-1]}.]}
7358 @end{Discussion}
7359
7360 @begin{ImplNote}
7361 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7362 @ChgAdded{Version=[3],Text=[Implementers are cautioned to consider error
7363 detection when implementing the syntax for @nt{conditional_expression}s. An
7364 @nt{if_expression} and an @nt{if_statement} are very similar syntactically, (as
7365 are a @nt{case_expression} and a @nt{case_statement}) and simple mistakes can
7366 appear to change one into the other, potentially causing errors to be moved
7367 far away from their actual location. The absence of @key[end if] to terminate
7368 an @nt{if_expression} (and @key[end case] for a @nt{case_expression}) also
7369 may make error handling harder.]}
7370 @end{ImplNote}
7371
7372 @end{Syntax}
7373
7374 @begin{Resolution}
7375 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7376 @ChgAdded{Version=[3],Type=[Leading],Text=[If a @nt{conditional_expression} is
7377 expected to be of a type @i<T>, then each @SynI{dependent_}@nt{expression} of
7378 the @nt{conditional_expression} is expected to be of type @i<T>. Similarly, if a
7379 @nt{conditional_expression} is expected to be of some class of types, then each
7380 @SynI{dependent_}@nt{expression} of the @nt{conditional_expression} is subject
7381 to the same expectation. If a @nt{conditional_expression} shall resolve to be of
7382 a type @i<T>, then each @SynI{dependent_}@nt{expression} shall resolve to be of
7383 type @i<T>.@PDefn2{Term=[expected type],Sec=[dependent_expression]}]}
7384
7385 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7386 @ChgAdded{Version=[3],Type=[Leading],Text=[The possible types of a
7387 @nt{conditional_expression} are further determined as follows:]}
7388
7389 @begin{Itemize}
7390 @ChgRef{Version=[3],Kind=[AddedNormal]}
7391 @ChgAdded{Version=[3],Text=[If the @nt{conditional_expression} is the operand
7392 of a type conversion, the type of the @nt{conditional_expression} is the
7393 target type of the conversion; otherwise,]}
7394
7395 @begin{Reason}
7396 @ChgRef{Version=[3],Kind=[AddedNormal]}
7397 @ChgAdded{Version=[3],Type=[Leading],Text=[This rule distributes an enclosing
7398 type conversion to the @SynI{dependent_}@nt{expression}s. This means that]}
7399 @begin{Example}
7400 @ChgRef{Version=[3],Kind=[AddedNormal]}
7401 @ChgAdded{Version=[3],Text=[T(@key[if] C @key[then] A @key[else] B)]}
7402 @end{Example}
7403 @ChgRef{Version=[3],Kind=[AddedNormal]}
7404 @ChgAdded{Version=[3],Type=[Leading],Text=[has the same semantics as]}
7405 @begin{Example}
7406 @ChgRef{Version=[3],Kind=[AddedNormal]}
7407 @ChgAdded{Version=[3],Text=[(@key[if] C @key[then] T(A) @key[else] T(B))]}
7408 @end{Example}
7409 @end{Reason}
7410
7411 @ChgRef{Version=[3],Kind=[AddedNormal]}
7412 @ChgAdded{Version=[3],Text=[If all of the @SynI{dependent_}@nt{expression}s
7413 are of the same type, the type of the @nt{conditional_expression} is that
7414 type; otherwise,]}
7415
7416 @ChgRef{Version=[3],Kind=[AddedNormal]}
7417 @ChgAdded{Version=[3],Text=[If a @SynI{dependent_}@nt{expression} is of an
7418 elementary type, the type of the @nt{conditional_expression} shall be covered
7419 by that type; otherwise,]}
7420
7421 @begin{Reason}
7422 @ChgRef{Version=[3],Kind=[AddedNormal]}
7423 @ChgAdded{Version=[3],Text=[This rule supports the use of
7424 numeric literals and universal expressions within a
7425 @nt{conditional_expression}.]}
7426 @end{Reason}
7427
7428 @ChgRef{Version=[3],Kind=[AddedNormal]}
7429 @ChgAdded{Version=[3],Text=[If the @nt{conditional_expression} is expected to
7430 be of type @i<T> or shall resolve to type @i<T>, then the
7431 @nt{conditional_expression} is of type @i<T>.]}
7432
7433 @begin{Ramification}
7434 @ChgRef{Version=[3],Kind=[AddedNormal]}
7435 @ChgAdded{Version=[3],Text=[If the type of the @nt{conditional_expression}
7436 cannot be determined by one of these rules, then Name Resolution has failed for
7437 that expression, even if the @SynI{dependent_}@nt{expression}s would
7438 resolve individually.]}
7439 @end{Ramification}
7440 @end{Itemize}
7441
7442 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7443 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[expected type], Sec=(condition)}
7444 A @nt{condition} is expected to be of any boolean type.]}
7445 @Comment{Moved from "If Statements"}
7446
7447 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
7448 @ChgAdded{Version=[3],Text=[The expected type for the
7449 @SynI<selecting_>@nt{expression} and the @nt{discrete_choice}s are as for case
7450 statements
7451 (see @RefSecNum{Case Statements}).@PDefn2{Term=[expected type],Sec=[case_expression selecting_expression]}
7452 @PDefn2{Term=[expected type],Sec=[case_expression_alternative discrete_choice]}
7453 @PDefn2{Term=[expected type],Sec=[selecting_expression case_expression]}]}
7454
7455 @end{Resolution}
7456
7457 @begin{Legality}
7458 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
7459 @ChgAdded{Version=[3],Text=[All of the @SynI{dependent_}@nt{expression}s
7460 shall be convertible (see @RefSecNum{Type Conversions}) to the type of the
7461 @nt{conditional_expression}.]}
7462
7463 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1],ARef=[AI05-0269-1]}
7464 @ChgAdded{Version=[3],Text=[If the expected type of a
7465 @nt{conditional_expression} is a specific tagged type, all of the
7466 @SynI{dependent_}@nt{expression}s of the @nt{conditional_expression} shall be
7467 dynamically tagged, or none shall be dynamically tagged. In this case, the
7468 @nt{conditional_expression} is dynamically tagged if all of the
7469 @SynI{dependent_}@nt{expression}s are dynamically tagged, is tag-indeterminate
7470 if all of the @SynI{dependent_}@nt{expression}s are tag-indeterminate, and is
7471 statically tagged otherwise.]}
7472
7473 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0262-1]}
7474 @ChgAdded{Version=[3],Text=[If there is no @key[else]
7475 @SynI{dependent_}@nt{expression}, the @nt{if_expression} shall be of
7476 a boolean type.]}
7477
7478 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1],ARef=[AI05-0269-1]}
7479 @ChgAdded{Version=[3],Text=[All @LegalityTitle that apply to the
7480 @nt{discrete_choice}s of a @nt{case_statement} (see @RefSecNum{Case Statements})
7481 also apply to the @nt{discrete_choice}s of a @nt{case_expression} except
7482 within an instance of a generic unit.]}
7483 @begin{Reason}
7484 @ChgRef{Version=[3],Kind=[AddedNormal]}
7485 @ChgAdded{Version=[3],Type=[Leading],Text=[The exemption for a case expression
7486 that occurs in an instance allows the following example:]}
7487 @begin{Example}
7488 @ChgRef{Version=[3],Kind=[AddedNormal]}
7489 @ChgAdded{Version=[3],Text=[@key[generic]
7490 @key[with function] Int_Func @key[return] Integer;
7491 @key[package] G @key[is]
7492 X : Float := (@key[case] Int_Func @key[is]
7493 @key[when] Integer'First .. -1 => -1.0,
7494 @key[when] 0 => 0.0,
7495 @key[when] Positive => 1.0);
7496 @key[end] G;]}
7497
7498 @ChgRef{Version=[3],Kind=[AddedNormal]}
7499 @ChgAdded{Version=[3],Text=[@key[function] Nat_Func @key[return] Natural @key[is] (123);]}
7500
7501 @ChgRef{Version=[3],Kind=[AddedNormal]}
7502 @ChgAdded{Version=[3],Text=[@key[package] I @key[is new] G (Int_Func => Nat_Func); -- @Examcom{Legal}]}
7503 @end{Example}
7504 @ChgRef{Version=[3],Kind=[AddedNormal]}
7505 @ChgAdded{Version=[3],Text=[Note that the @LegalityTitle still apply in the
7506 generic unit itself; they are just not enforced in an instance of the unit.]}
7507 @end{Reason}
7508 @end{Legality}
7509
7510 @begin{Runtime}
7511 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1],ARef=[AI05-0188-1]}
7512 @ChgAdded{Version=[3],Text=[For the evaluation of an @nt{if_expression}, the
7513 @nt{condition} specified after @key[if], and any @nt{condition}s specified
7514 after @key[elsif], are evaluated in succession (treating a final @key[else]
7515 as @key[elsif] True @key[then]), until one evaluates to True or
7516 all @nt{condition}s are evaluated and yield False. If a @nt{condition}
7517 evaluates to True, the associated @synI{dependent_}@nt{expression} is evaluated,
7518 converted to the type of the @nt{if_expression}, and the resulting value is the
7519 value of the @nt{if_expression}. Otherwise (when there is no @key[else] clause),
7520 the value of the @nt{if_expression} is True.@PDefn2{Term=[evaluation],Sec=[if_expression]}]}
7521
7522 @begin{Ramification}
7523 @ChgRef{Version=[3],Kind=[AddedNormal]}
7524 @ChgAdded{Version=[3],Text=[@key[Else] is required unless the
7525 @nt{if_expression} has a boolean type, so the last sentence can only apply to
7526 @nt{if_expression}s with a boolean type.]}
7527 @end{Ramification}
7528
7529 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0188-1]}
7530 @ChgAdded{Version=[3],Text=[For the evaluation of a
7531 @nt{case_expression},
7532 the @SynI<selecting_>@nt{expression} is first evaluated.
7533 If the value of the @SynI<selecting_>@nt{expression}
7534 is covered by the @nt{discrete_choice_list} of some
7535 @nt{case_expression_alternative}, then the @SynI<dependent_>@nt{expression} of
7536 the @nt{case_expression_alternative} is evaluated, converted to the type of the
7537 @nt{case_expression}, and the resulting value is the value of the
7538 @nt{case_expression}.@Defn2{Term=[Constraint_Error],Sec=(raised by case expression)}
7539 Otherwise (the value is not covered by any
7540 @nt{discrete_choice_list}, perhaps due to being outside the base range),
7541 Constraint_Error is raised.@PDefn2{Term=[evaluation],Sec=[case_expression]}]}
7542 @end{Runtime}
7543
7544 @begin{Examples}
7545 @begin{Example}
7546 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
7547 @ChgAdded{Version=[5],Text=[Put_Line ("Casey is " & (@b<if> Casey.Sex = M @b<then> "Male" @b<else> "Female")); --@RI[ see @RefSecNum{Incomplete Type Declarations}]]}
7548
7549 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
7550 @ChgAdded{Version=[5],Text=[@key[function] Card_Color (Card : Suit) @key[return] Color @key[is] --@RI[ see @RefSecNum{Enumeration Types}]
7551 (@key[case] Card @key[is]
7552 @key[when] Clubs | Spades => Black,
7553 @key[when] Hearts | Diamonds => Red);]}
7554 @end{Example}
7555 @end{Examples}
7556
7557 @begin{Extend2005}
7558 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0147-1]}
7559 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}If expressions
7560 and case expressions are new.]}
7561 @end{Extend2005}
7562
7563
7564 @LabeledAddedSubclause{Version=[3],Name=[Quantified Expressions]}
7565
7566 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0158-1]}
7567 @ChgAdded{Version=[4],Text=[Quantified expressions provide a way to write
7568 universally and existentially quantified predicates over containers and
7569 arrays.@defn{quantified expression}@Defn2{Term=[expression],Sec=[quantified]}]}
7570
7571 @begin{Syntax}
7572 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7573 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<quantified_expression>,Old=<>}>,
7574 rhs="@Chg{Version=[3],New=[@key[for] @Syn2{quantifier} @Syn2{loop_parameter_specification} => @Syn2{predicate}
7575 | @key[for] @Syn2{quantifier} @Syn2{iterator_specification} => @Syn2{predicate}],Old=<>}"}
7576
7577 @ChgRef{Version=[3],Kind=[AddedNormal]}
7578 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<quantifier>,Old=<>}>,
7579 rhs="@Chg{Version=[3],New=<@key[all] | @key[some]>,Old=<>}"}
7580
7581 @ChgRef{Version=[3],Kind=[AddedNormal]}
7582 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<predicate>,Old=<>}>,
7583 rhs="@Chg{Version=[3],New=<@SynI<boolean_>@Syn2{expression}>,Old=<>}"}
7584
7585 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7586 @ChgAdded{Version=[3],Text=[Wherever the Syntax Rules allow an @nt{expression}, a
7587 @nt{quantified_expression} may be used in place of the @nt{expression}, so
7588 long as it is immediately surrounded by parentheses.]}
7589
7590 @begin{Discussion}
7591 @ChgRef{Version=[3],Kind=[AddedNormal]}
7592 @ChgAdded{Version=[3],Text=[The syntactic category @nt{quantified_expression}
7593 appears only as a @nt{primary} that is parenthesized. The above rule allows it to additionally
7594 be used in other contexts where it would be directly surrounded by
7595 parentheses. This is the same rule that is used for @nt{conditional_expression}s;
7596 see @RefSecNum{Conditional Expressions} for a detailed discussion of the
7597 meaning and effects of this rule.]}
7598 @end{Discussion}
7599 @end{Syntax}
7600
7601 @begin{Resolution}
7602 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7603 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[expected type],Sec=[quantified_expression]}
7604 The expected type of a @nt{quantified_expression} is
7605 any Boolean type. The @nt{predicate} in a @nt{quantified_expression} is
7606 expected to be of the same type.]}
7607 @end{Resolution}
7608
7609 @begin{Runtime}
7610
7611 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7612 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0158-1]}
7613 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0327-1]}
7614 @ChgAdded{Version=[3],Text=[For the evaluation of a @nt{quantified_expression},
7615 the @nt{loop_parameter_specification} or @nt{iterator_specification} is first elaborated. The evaluation of a
7616 @nt{quantified_expression} then @Chg{Version=[5],New=[performs an iteration,
7617 and ],Old=[]}evaluates the @nt{predicate} for @Chg{Version=[5],New=[each value
7618 conditionally produced by the iteration],Old=[@Chg{Version=[4],New=[the
7619 values],Old=[each value]} of the loop
7620 parameter@Chg{Version=[4],New=[],Old=[. These values are examined]} in the
7621 order specified by the @nt{loop_parameter_specification}]} (see
7622 @RefSecNum{Loop Statements}@Chg{Version=[5],New=[ and],Old=[) or
7623 @nt{iterator_specification} (see]} @RefSecNum{Generalized Loop Iteration}).@PDefn2{Term=[evaluation],Sec=[quantified_expression]}]}
7624
7625 @begin{Ramification}
7626 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0327-1]}
7627 @ChgAdded{Version=[5],Text=[The order of evaluation of the predicates is
7628 that in which the values are produced, as specified in
7629 @RefSecNum{Loop Statements} or @RefSecNum{Generalized Loop Iteration}.]}
7630 @end{Ramification}
7631
7632 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7633 @ChgAdded{Version=[3],Type=[Leading],Text=[The value of the
7634 @nt{quantified_expression} is determined as follows:]}
7635
7636 @begin{Itemize}
7637 @ChgRef{Version=[3],Kind=[AddedNormal]}
7638 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0158-1]}
7639 @ChgAdded{Version=[3],Text=[If the @nt{quantifier} is @key[all], the
7640 expression is @Chg{Version=[4],New=[False],Old=[True]} if the evaluation
7641 of @Chg{Version=[4],New=[any],Old=[the]} @nt{predicate} yields
7642 @Chg{Version=[4],New=[False; evaluation of the
7643 @nt{quantified_expression} stops at that point. Otherwise (every
7644 predicate has been evaluated and yielded True), the expression is
7645 True],Old=[True for
7646 each value of the loop parameter. It is False otherwise. Evaluation of
7647 the @nt{quantified_expression} stops when all values of the domain have been
7648 examined, or when the @nt{predicate} yields False for a given value]}. Any
7649 exception raised by evaluation of the @nt{predicate} is propagated.]}
7650
7651 @begin{Ramification}
7652 @ChgRef{Version=[3],Kind=[AddedNormal]}
7653 @ChgAdded{Version=[3],Text=[The @nt{expression} is True if the domain
7654 contains no values.]}
7655 @end{Ramification}
7656
7657 @ChgRef{Version=[3],Kind=[AddedNormal]}
7658 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0158-1]}
7659 @ChgAdded{Version=[3],Text=[If the @nt{quantifier} is @key[some], the
7660 expression is True if the evaluation of
7661 @Chg{Version=[4],New=[any],Old=[the]} @nt{predicate} yields
7662 True@Chg{Version=[4],New=[; evaluation of the
7663 @nt{quantified_expression} stops at that point. Otherwise (every
7664 predicate has been evaluated and yielded False), the expression is
7665 False],Old=[ for
7666 some value of the loop parameter. It is False otherwise. Evaluation of
7667 the @nt{quantified_expression} stops when all values of the domain have been
7668 examined, or when the @nt{predicate} yields True for a given value]}. Any
7669 exception raised by evaluation of the @nt{predicate} is propagated.]}
7670
7671 @begin{Ramification}
7672 @ChgRef{Version=[3],Kind=[AddedNormal]}
7673 @ChgAdded{Version=[3],Text=[The @nt{expression} is False if the domain
7674 contains no values.]}
7675 @end{Ramification}
7676 @end{Itemize}
7677 @end{Runtime}
7678
7679 @begin{Examples}
7680
7681 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7682 @ChgAdded{Version=[3],Type=[Leading],Text=[The postcondition for a sorting
7683 routine on an array A with an index subtype T can be written:]}
7684
7685 @begin{Example}
7686 @ChgRef{Version=[3],Kind=[AddedNormal]}
7687 @ChgAdded{Version=[3],Text=[Post => (A'Length < 2 @key[or else]
7688 (@key[for all] I @key[in] A'First .. T'Pred(A'Last) => A (I) <= A (T'Succ (I))))]}
7689 @end{Example}
7690
7691 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7692 @ChgAdded{Version=[3],Type=[Leading],Text=[The assertion that a positive number
7693 is composite (as opposed to prime) can be written:]}
7694
7695 @begin{Example}
7696 @ChgRef{Version=[3],Kind=[AddedNormal]}
7697 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0312-1]}
7698 @ChgAdded{Version=[3],Text=[@key[pragma] Assert (@key[for some] X @key[in] 2 .. N @Chg{Version=[5],New=[@key[when] X * X <= N],Old=[ / 2]} => N @key[mod] X = 0);@Chg{Version=[5],New=[
7699 --@RI[ see ]@nt{iterator_filter}@RI[ in @RefSecNum{Loop Statements}]],Old=[]}]}
7700 @end{Example}
7701
7702 @end{Examples}
7703
7704 @begin{Extend2005}
7705 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0176-1]}
7706 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Quantified
7707 expressions are new.]}
7708 @end{Extend2005}
7709
7710 @begin{DiffWord2012}
7711 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0158-1]}
7712 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Revised the wording to make it
7713 clear that the semantics is short-circuited, and what the result is when
7714 there are no values for the loop parameter.]}
7715 @end{DiffWord2012}
7716
7717
7718 @LabeledAddedSubclause{Version=[5],Name=[Declare Expressions]}
7719
7720 @begin{Intro}
7721 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7722 @ChgAdded{Version=[5],Text=[Declare expressions@defn{declare expression}@Defn2{Term=[expression],Sec=[declare]}
7723 provide a way to declare local constants and object renamings in an expression
7724 context.]}
7725 @end{Intro}
7726
7727 @begin{Syntax}
7728 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7729 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<declare_expression>,Old=<>}>,
7730 rhs="@Chg{Version=[5],New=<
7731 @key[declare] {@Syn2<declare_item>}
7732 @key[begin] @SynI{body_}@Syn2{expression}>,Old=<>}"}
7733
7734 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7735 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<declare_item>,Old=<>}>,
7736 rhs="@Chg{Version=[5],New=<@Syn2{object_declaration} | @Syn2{object_renaming_declaration}>,Old=<>}"}
7737
7738 @begin{Reason}
7739 @ChgRef{Version=[5],Kind=[AddedNormal]}
7740 @ChgAdded{Version=[5],Text=[We allow @exam{(@key[declare begin]
7741 @nt{expression})} with no @nt{declare_item}s, for uniformity with block
7742 statements, which also allow a pointless @key[declare].]}
7743 @end{Reason}
7744
7745 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7746 @ChgAdded{Version=[5],Text=[Wherever the Syntax Rules allow an @nt{expression},
7747 a @nt{declare_expression} may be used in place of the @nt{expression}, so long
7748 as it is immediately surrounded by parentheses.]}
7749
7750 @begin{Discussion}
7751 @ChgRef{Version=[5],Kind=[AddedNormal]}
7752 @ChgAdded{Version=[5],Text=[The syntactic category @nt{declare_expression}
7753 appears only as a @nt{primary} that is parenthesized. The above rule allows it to additionally
7754 be used in other contexts where it would be directly surrounded by
7755 parentheses. This is the same rule that is used for @nt{conditional_expression}s;
7756 see @RefSecNum{Conditional Expressions} for a detailed discussion of the
7757 meaning and effects of this rule.]}
7758 @end{Discussion}
7759 @end{Syntax}
7760
7761 @begin{Legality}
7762 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7763 @ChgAdded{Version=[5],Text=[A @nt{declare_item} that is an
7764 @nt{object_declaration} shall declare a constant of a nonlimited type.]}
7765
7766 @begin{Reason}
7767 @ChgRef{Version=[5],Kind=[AddedNormal]}
7768 @ChgAdded{Version=[5],Text=[We disallow limited objects to avoid
7769 the horror of task waiting in the middle of an expression. The solution used
7770 for controlled objects (wait until the entire expression is finished) isn't
7771 appropriate for tasks. This restriction also eliminates build-in-place
7772 complexities and the need to activate tasks found in a @nt{declare_item}.]}
7773 @end{Reason}
7774
7775 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1],ARef=[AI12-0317-1]}
7776 @ChgAdded{Version=[5],Text=[A @nt{declare_item} that is an
7777 @nt{object_renaming_declaration} (see @RefSecNum{Object Renaming Declarations})
7778 shall not rename an object of a limited type if any operative constituent
7779 of the @SynI{object_}@nt{name} is a value conversion or is newly constructed
7780 (see @RefSecNum{Expressions}).]}
7781
7782 @begin{Reason}
7783 @ChgRef{Version=[5],Kind=[AddedNormal]}
7784 @ChgAdded{Version=[5],Text=[We disallow renaming limited temporary objects
7785 (like the result of a function call) for the same reasons as for stand-alone
7786 objects. We do allow renaming existing limited objects because these don't
7787 cause any problems. Note that one cannot directly rename an @nt{aggregate},
7788 parenthesized expression, @nt{conditional_expression}, or
7789 @nt{declare_expression} (these are not @nt{name}s), but any of these can
7790 appear inside of a @nt{qualified_expression} or @nt{type_conversion} (which
7791 are @nt{name}s and thus can be renamed).]}
7792 @end{Reason}
7793
7794 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7795 @ChgAdded{Version=[5],Text=[The following are not allowed within a
7796 @nt{declare_expression}: a declaration containing the reserved word
7797 @key[aliased]; the @nt{attribute_designator} Access or Unchecked_Access;
7798 or an anonymous access type.]}
7799
7800 @begin{Reason}
7801 @ChgRef{Version=[5],Kind=[AddedNormal]}
7802 @ChgAdded{Version=[5],Text=[We do not want to define accessibility rules for
7803 @nt{declare_item}s, as nested @nt{declare_expression}s cause complexities or
7804 usage warts. We want to keep this feature simple to use, understand, and
7805 implement. Thus, we do not allow any of the features that would require
7806 accessibility rules.]}
7807 @end{Reason}
7808 @end{Legality}
7809
7810 @begin{Resolution}
7811 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7812 @ChgAdded{Version=[5],Text=[If a @nt{declare_expression} is expected to be of a
7813 type @i{T}, then the @SynI{body_}@nt{expression} is expected to be of type
7814 @i{T}. Similarly, if a @nt{declare_expression} is expected to be of some class
7815 of types, then the @SynI{body_}@nt{expression} is subject to the same
7816 expectation. If a @nt{declare_expression} shall resolve to be of a type @i{T},
7817 then the @SynI{body_}@nt{expression} shall resolve to be of type @i{T}.]}
7818
7819 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7820 @ChgAdded{Version=[5],Text=[The type of a @nt{declare_expression} is the type of
7821 the @SynI{body_}@nt{expression}.]}
7822 @end{Resolution}
7823
7824 @begin{Runtime}
7825 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7826 @ChgAdded{Version=[5],Text=[For the evaluation of a @nt{declare_expression},
7827 the @nt{declare_item}s are elaborated in order, and then
7828 the @SynI{body_}@nt{expression} is evaluated. The value of the
7829 @nt{declare_expression} is that of the @SynI{body_}@nt{expression}.]}
7830 @end{Runtime}
7831
7832 @begin{Examples}
7833
7834 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7835 @ChgAdded{Version=[5],Type=[Leading],Text=[The postcondition for
7836 Ada.Containers.Vectors."&" (see
7837 @RefSecNum{The Generic Package Containers.Vectors}) could have been written:]}
7838
7839 @begin{Example}
7840 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7841 @ChgAdded{Version=[5],Type=[Leading],Text=[@key[with] Post =>
7842 (@key[declare]
7843 Result @key[renames] Vectors."&"'Result;
7844 Length : @key[constant] Count_Type := Left.Length + Right.Length;
7845 @key[begin]
7846 Result.Length = Length @key[and then]
7847 @key[not] Tampering_With_Elements_Prohibited (Result) @key[and then]
7848 @key[not] Tampering_With_Cursors_Prohibited (Result) @key[and then]
7849 Result.Capacity >= Length)]}
7850 @end{Example}
7851 @end{Examples}
7852
7853 @begin{Extend2012}
7854 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0236-1]}
7855 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Declare
7856 expressions are new.]}
7857 @end{Extend2012}
7858
7859
7860 @LabeledAddedSubclause{Version=[5],Name=[Reduction Expressions]}
7861
7862 @begin{Intro}
7863 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1],ARef=[AI12-0262-1]}
7864 @ChgAdded{Version=[5],Text=[Reduction expressions@defn{reduction expression}@Defn2{Term=[expression],Sec=[reduction]}
7865 provide a way to map or transform a collection of values into a new set of
7866 values, and then summarize the values produced by applying an operation to
7867 reduce the set to a single value result. A reduction expression is represented
7868 as an @nt{attribute_reference} of the reduction attributes Reduce or
7869 Parallel_Reduce.]}
7870
7871 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Reduction Expression>,
7872 Text=<@ChgAdded{Version=[5],Text=[An expression that defines how to map or
7873 transform a collection of values into a new set of values, and then summarize
7874 the values by applying an operation to reduce the set to a single value.]}>}
7875 @end{Intro}
7876
7877 @begin{Syntax}
7878 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1],ARef=[AI12-0262-1]}
7879 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<reduction_attribute_reference>,Old=<>}>,
7880 rhs="@Chg{Version=[5],New=<
7881 @Syn2{value_sequence}'@Syn2{reduction_attribute_designator}
7882 | @Syn2{prefix}'@Syn2{reduction_attribute_designator}>,Old=<>}"}
7883
7884 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7885 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<value_sequence>,Old=<>}>,
7886 rhs="@Chg{Version=[5],New=<
7887 '[' [@key[parallel][(@Syn2{chunk_specification})]] @Syn2{iterated_element_association} ']'>,Old=<>}"}
7888
7889 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7890 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<reduction_attribute_designator>,Old=<>}>,
7891 rhs="@Chg{Version=[5],New=<@SynI{reduction_}@Syn2{identifier}(@Syn2{reduction_specification})>,Old=<>}"}
7892
7893 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
7894 @AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<reduction_specification>,Old=<>}>,
7895 rhs="@Chg{Version=[5],New=<@SynI{reducer_}@Syn2{name}, @SynI{initial_value_}@Syn2{expression}>,Old=<>}"}
7896
7897 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0250-1],ARef=[AI12-0262-1]}
7898 @ChgAdded{Version=[5],Text=[The @nt{iterated_element_association} of a
7899 @nt{value_sequence} shall not have a @SynI{key_}@nt{expression},
7900 nor shall it have a @nt{loop_parameter_specification} that has the reserved
7901 word @key{reverse}.]}
7902
7903 @begin{Reason}
7904 @ChgRef{Version=[5],Kind=[AddedNormal]}
7905 @ChgAdded{Version=[5],Text=[The intent is that the syntax matches as closely
7906 as possible array or container aggregate notation. Syntax that matches a
7907 @nt{loop_parameter_specification} with the @key{reverse} reserved word would
7908 not be permitted in an array aggregate, so we disallow that here.]}
7909 @end{Reason}
7910
7911 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7912 @ChgAdded{Version=[5],Text=[The @nt{chunk_specification}, if any, of a
7913 @nt{value_sequence} shall be an @SynI{integer_}@nt{simple_expression}.]}
7914
7915 @end{Syntax}
7916
7917 @begin{Resolution}
7918 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7919 @ChgAdded{Version=[5],Text=[The expected type for a
7920 @nt{reduction_attribute_reference} shall be a single nonlimited type.]}
7921
7922 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7923 @ChgAdded{Version=[5],Type=[Leading],Text=[In the remainder of this subclause,
7924 we will refer to nonlimited subtypes @i<Value_Type> and @i<Accum_Type> of a
7925 @nt{reduction_attribute_reference}. These subtypes and interpretations of
7926 the @nt{name}s and @nt{expression}s of a @nt{reduction_attribute_reference} are
7927 determined by the following rules:]}
7928
7929 @begin{Discussion}
7930 @ChgRef{Version=[5],Kind=[AddedNormal]}
7931 @ChgAdded{Version=[5],Text=[@i<Accum_Type> represents the result of the
7932 reduction (the @i<accumulator> type), and @i<Value_Type> represents the
7933 type of the input values to the reduction.]}
7934 @end{Discussion}
7935
7936 @begin{Itemize}
7937 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7938 @ChgAdded{Version=[5],Text=[@i<Accum_Type> is a subtype of the expected type of
7939 the @nt{reduction_attribute_reference}.]}
7940
7941 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7942 @ChgAdded{Version=[5],Type=[Leading],Text=[A @i<reducer subprogram>@Defn{reducer subprogram}
7943 is either subtype conformant with the following specification:]}
7944
7945 @begin{Example}
7946 @ChgRef{Version=[5],Kind=[AddedNormal]}
7947 @ChgAdded{Version=[5],Text=[ @key[function] Reducer(Accumulator : @i<Accum_Type>; Value : @i<Value_Type>) @key[return] @i<Accum_Type>;]}
7948 @end{Example}
7949
7950 @ChgRef{Version=[5],Kind=[AddedNormal]}
7951 @ChgAdded{Version=[5],Type=[Leading],NoPrefix=[T],Text=[or is
7952 subtype conformant with the following specification:]}
7953
7954 @begin{Example}
7955 @ChgRef{Version=[5],Kind=[AddedNormal]}
7956 @ChgAdded{Version=[5],Text=[ @key[procedure] Reducer(Accumulator : @key[in out] @i<Accum_Type>; Value : @key[in] @i<Value_Type>);]}
7957 @end{Example}
7958
7959 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7960 @ChgAdded{Version=[5],Text=[The @SynI{reducer_}@nt{name} of a @nt{reduction_specification}
7961 denotes a reducer subprogram.]}
7962
7963 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
7964 @ChgAdded{Version=[5],Text=[The expected type of an
7965 @SynI{initial_value_}@nt{expression} of a @nt{reduction_specification}
7966 is that of subtype @i<Accum_Type>.]}
7967
7968 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0250-1],ARef=[AI12-0262-1]}
7969 @ChgAdded{Version=[5],Text=[The expected type of the @nt{expression} of the
7970 @nt{iterated_element_association} of a @nt{value_sequence} is that of
7971 subtype @i<Value_Type>.]}
7972 @end{Itemize}
7973
7974 @end{Resolution}
7975
7976 @begin{Legality}
7977 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
7978 @ChgAdded{Version=[5],Text=[If the @nt{reduction_attribute_reference} has a
7979 @nt{value_sequence} with the reserved word @key[parallel], the subtypes
7980 @i<Accum_Type> and @i<Value_Type> shall statically match.]}
7981
7982 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
7983 @ChgAdded{Version=[5],Text=[If the @nt{identifier} of a
7984 @nt{reduction_attribute_designator} is Parallel_Reduce, the subtypes
7985 @i<Accum_Type> and @i<Value_Type> shall statically match.]}
7986
7987 @begin{Reason}
7988 @ChgRef{Version=[5],Kind=[AddedNormal]}
7989 @ChgAdded{Version=[5],Text=[For a @nt{reduction_attribute_reference} with a
7990 @nt{value_sequence} that does not have the reserved word @key[parallel] or has
7991 a @nt{prefix} and the @nt{identifier} of the
7992 @nt{reduction_attribute_designator} is Reduce, the subtypes
7993 @i<Accum_Type> and @i<Value_Type> can be different because only one logical
7994 thread of control is presumed so there is no need to combine multiple
7995 results.]}
7996 @end{Reason}
7997 @end{Legality}
7998
7999 @begin{StaticSem}
8000 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8001 @ChgAdded{Version=[5],Text=[A @nt{reduction_attribute_reference} denotes a
8002 value, with nominal subtype being the subtype of the first parameter of the
8003 subprogram denoted by the @SynI{reducer_}@nt{name}.]}
8004 @end{StaticSem}
8005
8006 @begin{Runtime}
8007 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0250-1],ARef=[AI12-0262-1],ARef=[AI12-0327-1]}
8008 @ChgAdded{Version=[5],Text=[@PDefn2{Term=[evaluation], Sec=(value_sequence)}
8009 For the evaluation of a @nt{value_sequence}, the
8010 @nt{iterated_element_association} is elaborated, then an iteration is
8011 performed, and for each value conditionally produced by the iteration (see
8012 @RefSecNum{Loop Statements} and @RefSecNum{Generalized Loop Iteration}),
8013 the associated @nt{expression} is evaluated with the loop parameter
8014 having this value, to produce a result that is converted to Value_Type,
8015 and used to define the next value in the sequence.]}
8016
8017 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8018 @ChgAdded{Version=[5],Text=[If the @nt{value_sequence} does not have the
8019 reserved word @key[parallel], it is
8020 produced as a single sequence of values by a single logical thread of
8021 control. If the reserved word @key[parallel] is present in the
8022 @nt{value_sequence},
8023 the enclosing @nt{reduction_attribute_reference} is a parallel construct, and
8024 the sequence of values is generated by a parallel iteration (as defined
8025 in @RefSecNum{Loop Statements}, @RefSecNum{User-Defined Iterator Types},
8026 and @RefSecNum{Generalized Loop Iteration}), as a set of
8027 non-empty, non-overlapping contiguous
8028 chunks (@i<subsequences>)@Defn2{Term=[subsequence],Sec=[reduction attribute]}
8029 with one logical thread of control (see clause
8030 @RefSecNum{Tasks and Synchronization}) associated with each subsequence.
8031 If there is a @nt{chunk_specification},
8032 it determines the maximum number of chunks, as defined in
8033 @RefSecNum{Loop Statements}; otherwise
8034 the maximum number of chunks is implementation defined.]}
8035
8036 @ChgImplDef{Version=[5],Kind=[AddedNormal],InitialVersion=[5],
8037 Text=[@ChgAdded{Version=[5],Text=[The maximum number of chunks for a parallel
8038 reduction expression without a @nt{chunk_specification}.]}]}
8039
8040 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8041 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[For @PrefixType{a
8042 @nt{value_sequence} V}, the following attribute is defined:]}
8043
8044 @begin(description)
8045 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
8046 Leading=<T>, Prefix=<V>, AttrName=<Reduce(Reducer, Initial_Value)>,
8047 InitialVersion=[5], ARef=[AI12-0262-1], ARef=[AI12-0348-1],
8048 Text=[@Chg{Version=[5],New=[This attribute represents a @i<reduction expression>,
8049 and is in the form of a @nt{reduction_attribute_reference}.],Old=[]}]}@Comment{End of Annex text here.}
8050 @EndPrefixType{}
8051
8052 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8053 @ChgAdded{Version=[5],NoPrefix=[T],Text=[@PDefn2{Term=[evaluation], Sec=(reduction_attribute_reference)}
8054 The evaluation of a use of this attribute begins by evaluating the parts
8055 of the
8056 @nt{reduction_attribute_designator} (the @SynI{reducer_}@nt{name} Reducer
8057 and the @SynI{initial_value_}@nt{expression} Initial_Value), in
8058 an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]} It then
8059 initializes the @i<accumulator> of the reduction expression to the value of
8060 the @SynI{initial_value_}@nt{expression} (the @i<initial
8061 value>).@Defn2{Term=[accumulator],Sec=[reduction attribute]}
8062 @Defn2{Term=[initial value],Sec=[reduction attribute]} The
8063 @nt{value_sequence} V is then evaluated.]}
8064
8065 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8066 @ChgAdded{Version=[5],NoPrefix=[T],Text=[If the @nt{value_sequence} does not
8067 have the reserved word @key[parallel], each value of the @nt{value_sequence}
8068 is passed, in order, as the second (Value) parameter to a call on Reducer,
8069 with the first (Accumulator) parameter being the prior value of the
8070 accumulator, saving the result as the new value of the accumulator. The
8071 reduction expression yields the final value of the accumulator.]}
8072
8073 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8074 @ChgAdded{Version=[5],NoPrefix=[T],Text=[If the reserved word @key[parallel]
8075 is present in a @nt{value_sequence}, then the (parallel) reduction
8076 expression is a parallel construct and the
8077 sequence has been partitioned into one or more subsequences (see
8078 above) each with its own separate logical thread of control.]}
8079
8080 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8081 @ChgAdded{Version=[5],NoPrefix=[T],Text=[Each logical thread of control
8082 creates a local accumulator for processing its subsequence. The accumulator
8083 for a subsequence is initialized to the first value of the subsequence, and
8084 calls on Reducer start with the second value of the subsequence (if any).
8085 The result for the subsequence is the final value of its local accumulator.]}
8086
8087 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8088 @ChgAdded{Version=[5],NoPrefix=[T],Text=[After all logical threads of control
8089 of a parallel reduction expression have completed, Reducer is called
8090 for each subsequence, in the original
8091 sequence order, passing the local accumulator for that subsequence as the
8092 second (Value) parameter, and the overall accumulator
8093 @Redundant[(initialized above to the initial value)] as the first
8094 (Accumulator) parameter, with the result saved back in the overall
8095 accumulator. The parallel reduction expression yields the final value of the
8096 overall accumulator.]}
8097
8098 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8099 @ChgAdded{Version=[5],NoPrefix=[T],Text=[If the evaluation of the
8100 @nt{value_sequence} yields an empty sequence of values, the reduction
8101 expression yields the initial value.]}
8102
8103 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8104 @ChgAdded{Version=[5],NoPrefix=[T],Text=[If an exception is propagated by one
8105 of the calls on Reducer, that exception is propagated from the
8106 reduction expression. If different exceptions are propagated in different
8107 logical threads of control, one is chosen arbitrarily to be propagated from
8108 the reduction expression as a whole.]}
8109
8110 @begin{ImplNote}
8111 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8112 @ChgAdded{Version=[5],Text=[For a @nt{reduction_attribute_reference} that
8113 has a @nt{value_sequence} without the reserved word @key[parallel] or a
8114 @nt{prefix} where the @nt{identifier} of the
8115 @nt{reduction_attribute_designator} is Reduce (see below), generally the
8116 compiler can still choose to execute the reduction in parallel, presuming
8117 doing so would not change the results. However
8118 sequential execution is necessary if the subtypes of the parameters of
8119 Reducer do not statically match, since there is no subprogram identified in
8120 the construct that could be used for combining the results in parallel.]}
8121 @end{ImplNote}
8122
8123 @begin{Discussion}
8124 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8125 @ChgAdded{Version=[5],Text=[We say the calls to Reducer that combine the
8126 results of parallel execution are sequentially
8127 ordered in increasing order because certain reductions, such as vector
8128 concatenation, can be non-commutative (but still associative) operations.
8129 In order to return a deterministic result for parallel execution that is
8130 consistent with sequential execution, we need to specify an order for the
8131 iteration, and for the combination of results from the logical threads of
8132 control. It is also necessary that combining calls to Reducer are issued
8133 sequentially with respect to each other, which may require extra
8134 synchronization if the calls to Reducer are being executed by different
8135 logical threads of control.]}
8136 @end{Discussion}
8137
8138 @end(description)
8139
8140 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1]}
8141 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[For @PrefixType{a
8142 @nt{prefix} X of an array type@Redundant[ (after
8143 any implicit dereference)], or that denotes an iterable container
8144 object (see @RefSecNum{User-Defined Iterator Types})}, the following attributes
8145 are defined:]}
8146
8147 @begin(description)
8148 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
8149 Leading=<T>, Prefix=<X>, AttrName=<Reduce(Reducer, Initial_Value)>,
8150 InitialVersion=[5], ARef=[AI12-0242-1], ARef=[AI12-0348-1],
8151 Text=[@Chg{Version=[5],New=[X'Reduce is a reduction expression that yields
8152 a result equivalent to replacing the @nt{prefix} of the attribute with the
8153 @nt{value_sequence}:],Old=[]}
8154 @begin{DescExample}
8155 @ChgRef{Version=[5],Kind=[Added]}@Comment{Can't use AddedNormal here, or the attribute Annex will have misnumbered paragraphs.}
8156 @ChgAdded{Version=[5],Text="[@key[for] Item @key[of] X => Item]"}
8157 @end{DescExample}]}@Comment{End of Annex text here.}
8158
8159 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
8160 Leading=<T>, Prefix=<X>, AttrName=<Parallel_Reduce(Reducer, Initial_Value)>,
8161 InitialVersion=[5], ARef=[AI12-0242-1], ARef=[AI12-0348-1],
8162 Text=[@Chg{Version=[5],New=[X'Parallel_Reduce is a reduction expression that
8163 yields a result equivalent to replacing the attribute @nt{identifier} with
8164 Reduce and the @nt{prefix} of the attribute with the
8165 @nt{value_sequence}:],Old=[]}
8166 @begin{DescExample}
8167 @ChgRef{Version=[5],Kind=[Added]}@Comment{Can't use AddedNormal here, or the attribute Annex will have misnumbered paragraphs.}
8168 @ChgAdded{Version=[5],Text="[@key[parallel for] Item @key[of] X => Item]"}
8169 @end{DescExample}]}@Comment{End of Annex text here.}
8170
8171 @EndPrefixType{}
8172 @end(description)
8173 @end{Runtime}
8174
8175 @begin{Bounded}
8176 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8177 @ChgAdded{Version=[5],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
8178 For a parallel reduction expression, it is a bounded error if the reducer
8179 subprogram is not associative. That is, for any arbitrary values of subtype
8180 @i<Value_Type> @i<A>, @i<B>, @i<C> and a reducer function @i<R>, the result of
8181 @i<R> (@i<A>, @i<R> (@i<B>, @i<C>)) should produce a result equal to
8182 @i<R> (@i<R> (@i<A>, @i<B>), @i<C>)). The possible consequences
8183 are Program_Error, or a result that does not match the equivalent sequential
8184 reduction expression due to the order of calls on the reducer subprogram being
8185 unspecified in the overall reduction. Analogous rules apply in the case of a
8186 reduction procedure.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
8187
8188 @begin{Reason}
8189 @ChgRef{Version=[5],Kind=[AddedNormal]}
8190 @ChgAdded{Version=[5],Text=[In a sequential reduction expression, the reducer
8191 subprogram is called in a left-to-right order, whereas in a parallel
8192 reduction expression, the reducer subprogram is called in an order that
8193 depends on the number of logical threads of control that execute the
8194 reduction and on the elements/components given to each chunk. If the
8195 reducer is associative, this order does not matter, but in other cases,
8196 very different results are possible. While one can specify the @i<maximum>
8197 number of chunks, the actual number of chunks is unspecified. Similarly,
8198 the split of elements has only weak requirements. Thus, to get a consistent
8199 and portable result, an associative reducer is required for a parallel
8200 reduction. We define this as a @BoundedTitle
8201 to provide a stern warning about the required nature of the reducer
8202 subprogram and to let compilers detect the problem when possible.]}
8203 @end{Reason}
8204
8205 @begin{Honest}
8206 @ChgRef{Version=[5],Kind=[AddedNormal]}
8207 @ChgAdded{Version=[5],Text=[In this rule, @ldquote@;equal@rdquote means
8208 semantically equal. We don't care if the bit patterns differ but that the
8209 results mean the same thing. In particular, if the primitive equal is
8210 user-defined, that equality would be the one used to determine if this
8211 rule is violated.]}
8212 @end{Honest}
8213 @end{Bounded}
8214
8215 @begin{Examples}
8216 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8217 @ChgAdded{Version=[5],Type=[Leading],Text=[An expression function that returns
8218 its result as a Reduction Expression:]}
8219
8220 @begin{Example}
8221 @ChgRef{Version=[5],Kind=[AddedNormal]}
8222 @ChgAdded{Version=[5],Text={@key[function] Factorial(N : Natural) @key[return] Natural @key[is]
8223 ([@key[for] J @key[in] 1..N => J]'Reduce("*", 1));}}
8224 @end{Example}
8225
8226 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1]}
8227 @ChgAdded{Version=[5],Type=[Leading],Text=[An expression function that computes
8228 the Sine of X using a Taylor expansion:]}
8229
8230 @begin{Example}
8231 @ChgRef{Version=[5],Kind=[AddedNormal]}
8232 @ChgAdded{Version=[5],Text={@key[function] Sine (X : Float; Num_Terms : Positive := 5) @key[return] Float @key[is]
8233 ([@key[for] I @key[in] 1..Num_Terms => (-1.0)**(I-1) * X**(2*I-1)/Float(Factorial(2*I-1))]
8234 'Reduce("+", 0.0));}}
8235 @end{Example}
8236
8237 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0379-1]}
8238 @ChgAdded{Version=[5],Type=[Leading],Text=[A reduction expression that outputs
8239 the sum of squares:]}
8240
8241 @begin{Example}
8242 @ChgRef{Version=[5],Kind=[AddedNormal]}
8243 @ChgAdded{Version=[5],Text={Put_Line ("Sum of Squares is" &
8244 Integer'Image([@key[for] I @key[in] 1 .. 10 => I**2]'Reduce("+", 0)));}}
8245 @end{Example}
8246
8247 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0262-1],ARef=[AI12-0379-1]}
8248 @ChgAdded{Version=[5],Type=[Leading],Text=[An expression function to compute the
8249 value of Pi:]}
8250
8251 @begin{Example}
8252 @ChgRef{Version=[5],Kind=[AddedNormal]}
8253 @ChgAdded{Version=[5],Text={-- @Examcom{See @RefSecNum{Floating Point Types}.}
8254 @key[function] Pi (Number_Of_Steps : Natural := 10_000) @key[return] Real @key[is]
8255 (1.0 / Real (Number_Of_Steps) *
8256 [@key[for] I @key[in] 1 .. Number_Of_Steps =>
8257 (4.0 / (1.0 + ((Real (I) - 0.5) *
8258 (1.0 / Real (Number_Of_Steps)))**2))]
8259 'Reduce("+", 0.0));}}
8260 @end{Example}
8261
8262 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1]}
8263 @ChgAdded{Version=[5],Type=[Leading],Text=[Calculate the sum of elements of an
8264 array of integers:]}
8265
8266 @begin{Example}
8267 @ChgRef{Version=[5],Kind=[AddedNormal]}
8268 @ChgAdded{Version=[5],Text=[A'Reduce("+",0) -- @Examcom{See @RefSecNum{Array Aggregates}.}]}
8269 @end{Example}
8270
8271 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1]}
8272 @ChgAdded{Version=[5],Type=[Leading],Text=[Determine if all elements in a
8273 two-dimensional array of booleans are set to true:]}
8274
8275 @begin{Example}
8276 @ChgRef{Version=[5],Kind=[AddedNormal]}
8277 @ChgAdded{Version=[5],Text=[Grid'Reduce("and", True) -- @Examcom{See @RefSecNum{Array Types}.}]}
8278 @end{Example}
8279
8280 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1]}
8281 @ChgAdded{Version=[5],Type=[Leading],Text=[Calculate the minimum value
8282 of an array of integers in parallel:]}
8283
8284 @begin{Example}
8285 @ChgRef{Version=[5],Kind=[AddedNormal]}
8286 @ChgAdded{Version=[5],Text=[A'Parallel_Reduce(Integer'Min, Integer'Last)]}
8287 @end{Example}
8288
8289 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]}
8290 @ChgAdded{Version=[5],Type=[Leading],Text=[A parallel reduction expression used
8291 to calculate the mean of the elements of a two-dimensional array of
8292 subtype Matrix (see @RefSecNum{Array Types}) that are greater than 100.0:]}
8293
8294 @begin{Example}
8295 @ChgRef{Version=[5],Kind=[AddedNormal]}
8296 @ChgAdded{Version=[5],Text=[@key[type] Accumulator @key[is record]
8297 Sum : Real; --@RI[ See @RefSecNum{Floating Point Types}.]
8298 Count : Integer;
8299 @key[end record];]}
8300
8301 @ChgRef{Version=[5],Kind=[AddedNormal]}
8302 @ChgAdded{Version=[5],Text=[@key[function] Accumulate (L, R : Accumulator) @key[return] Accumulator @key[is]
8303 (Sum => L.Sum + R.Sum,
8304 Count => L.Count + R.Count);]}
8305
8306 @ChgRef{Version=[5],Kind=[AddedNormal]}
8307 @ChgAdded{Version=[5],Text={@key[function] Average_of_Values_Greater_Than_100 (M : Matrix) @key[return] Real @key[is]
8308 (@key[declare]
8309 Acc : @key[constant] Accumulator :=
8310 [@key[parallel for] Val @key[of] M @key[when] Val > 100.0 => (Val, 1)]
8311 'Reduce(Accumulate, (Sum => 0, Count => 0));
8312 @key[begin]
8313 Acc.Sum / Real(Acc.Count));}}
8314 @end{Example}
8315 @end{Examples}
8316
8317
8318 @begin{Extend2012}
8319 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0242-1],ARef=[AI12-0262-1],ARef=[AI12-0348-1]}
8320 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}Reduction
8321 expressions attributes are new.]}
8322 @end{Extend2012}
8323