| 1 |
@Part(04, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2006/10/18 00:25:24 $} |
| 4 |
@LabeledSection{Names and Expressions} |
| 5 |
|
| 6 |
@Comment{$Source: e:\\cvsroot/ARM/Source/04a.mss,v $} |
| 7 |
@Comment{$Revision: 1.83 $} |
| 8 |
|
| 9 |
@begin{Intro} |
| 10 |
@Redundant[The rules applicable to the different forms of @nt<name> and |
| 11 |
expression, and to their evaluation, are given in this section.] |
| 12 |
@end{Intro} |
| 13 |
|
| 14 |
@LabeledClause{Names} |
| 15 |
|
| 16 |
@begin{Intro} |
| 17 |
@redundant[@nt<Name>s can denote declared entities, whether declared explicitly |
| 18 |
or implicitly (see @RefSecNum(Declarations)). @nt<Name>s can also |
| 19 |
denote objects or subprograms designated by access values; the |
| 20 |
results of @nt<type_conversion>s or @nt<function_call>s; subcomponents |
| 21 |
and slices of objects and values; protected subprograms, |
| 22 |
single entries, entry families, |
| 23 |
and entries in families of entries. |
| 24 |
Finally, @nt<name>s can denote attributes of any of the foregoing.] |
| 25 |
@end{Intro} |
| 26 |
|
| 27 |
@begin{Syntax} |
| 28 |
@Syn{tabs=[P22], lhs=<name>,rhs=" |
| 29 |
@Syn2{direct_name}@\| @Syn2{explicit_dereference} |
| 30 |
| @Syn2{indexed_component}@\| @Syn2{slice} |
| 31 |
| @Syn2{selected_component}@\| @Syn2{attribute_reference} |
| 32 |
| @Syn2{type_conversion}@\| @Syn2{function_call} |
| 33 |
| @Syn2{character_literal}"} |
| 34 |
|
| 35 |
|
| 36 |
@Syn{lhs=<direct_name>, |
| 37 |
rhs="@Syn2{identifier} | @Syn2{operator_symbol}"} |
| 38 |
@begin{Discussion} |
| 39 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 40 |
@nt<character_literal> is no longer a @nt<direct_name>. |
| 41 |
@nt<character_literal>s are usable even when the corresponding |
| 42 |
@Chg{Version=[2],New=[enumeration type |
| 43 |
declaration],Old=[@ntf<enumeration_type_declaration>]} is not visible. See |
| 44 |
@RefSecNum(Literals). |
| 45 |
@end{Discussion} |
| 46 |
|
| 47 |
@Syn{lhs=<prefix>,rhs="@Syn2{name} | @Syn2{implicit_dereference}"} |
| 48 |
|
| 49 |
@Syn{lhs=<explicit_dereference>,rhs="@Syn2{name}.@key{all}"} |
| 50 |
|
| 51 |
@Syn{lhs=<implicit_dereference>,rhs="@Syn2{name}"} |
| 52 |
|
| 53 |
@end{Syntax} |
| 54 |
|
| 55 |
@begin{Intro} |
| 56 |
@ChgRef{Version=[2],Kind=[Revised]} |
| 57 |
@Redundant[Certain forms of @nt<name> (@nt<indexed_component>s, |
| 58 |
@nt<selected_component>s, @nt<slice>s, and |
| 59 |
@Chg{Version=[2],New=[@nt<attribute_reference>s],Old=[@ntf<attribute>s]}) |
| 60 |
include a @nt<prefix> that is either itself a @nt<name> that denotes |
| 61 |
some related entity, or an @nt<implicit_dereference> of an access |
| 62 |
value that designates some related entity.] |
| 63 |
@end{Intro} |
| 64 |
|
| 65 |
@begin{Resolution} |
| 66 |
@Defn{dereference} |
| 67 |
@PDefn2{Term=[expected type], |
| 68 |
Sec=(dereference @nt{name})} |
| 69 |
The @nt{name} in a @i(dereference) (either an |
| 70 |
@nt<implicit_dereference> or an @nt<explicit_dereference>) |
| 71 |
is expected to be of any access type. |
| 72 |
@end{Resolution} |
| 73 |
|
| 74 |
@begin{StaticSem} |
| 75 |
@PDefn2{Term=[nominal subtype], Sec=(associated with a dereference)} |
| 76 |
If the type of the @nt{name} in a dereference is some access-to-object |
| 77 |
type @i(T), then the dereference denotes a view of an object, the |
| 78 |
@i(nominal subtype) of the view being the designated subtype of @i(T). |
| 79 |
@begin{Ramification} |
| 80 |
If the |
| 81 |
value of the @nt<name> is the result of an access type conversion, the |
| 82 |
dereference denotes a view created as part of the conversion. |
| 83 |
The nominal subtype of the view is not necessarily |
| 84 |
the same as that used to create the designated object. |
| 85 |
See @RefSecNum{Type Conversions}. |
| 86 |
@end{Ramification} |
| 87 |
@begin{Honest} |
| 88 |
@PDefn2{Term=[nominal subtype], Sec=(of a @nt<name>)} |
| 89 |
We sometimes refer to the nominal subtype of a particular kind |
| 90 |
of @nt<name> rather than the nominal subtype of the view denoted by |
| 91 |
the @nt<name> (presuming the @nt<name> denotes a view of an object). |
| 92 |
These two uses of nominal subtype are intended to mean the same |
| 93 |
thing. |
| 94 |
|
| 95 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]} |
| 96 |
@ChgAdded{Version=[2],Text=[If an @nt{allocator} for the access-to-object |
| 97 |
type @i(T) is one that creates objects that are constrained by their |
| 98 |
initial value (see @RefSecNum{Allocators}), the subtype of the dereference is |
| 99 |
constrained even if the designated subtype of @i(T) is not. We don't want |
| 100 |
the effect of the dereference to depend on the |
| 101 |
designated object. This matters because general access-to-unconstrained |
| 102 |
can designate both allocated objects (which are constrained at birth) and |
| 103 |
aliased stack objects (which aren't necessarily constrained). |
| 104 |
This is a wording bug that was discovered after the completion of |
| 105 |
Amendment 1 when it was too late to fix it; we expect that it will |
| 106 |
be corrected by an early Ada 2005 AI.]} |
| 107 |
@end{Honest} |
| 108 |
@begin{ImplNote} |
| 109 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]} |
| 110 |
@ChgAdded{Version=[2],Text=[Since we don't depend on whether the designated |
| 111 |
object is constrained, it is not necessary to include a constrained |
| 112 |
bit in every object that could be designated by a general access type.]} |
| 113 |
@end{ImplNote} |
| 114 |
|
| 115 |
@PDefn2{Term=[profile], Sec=(associated with a dereference)} |
| 116 |
If the type of the @nt<name> in a dereference is some access-to-subprogram |
| 117 |
type @i(S), then the dereference denotes a view of a subprogram, |
| 118 |
the @i(profile) of the view being the designated profile of @i(S). |
| 119 |
@begin{Ramification} |
| 120 |
This means |
| 121 |
that the formal parameter names and default expressions to be used |
| 122 |
in a call whose @nt<name> or @nt<prefix> is a dereference |
| 123 |
are those of the designated profile, which need not be the same as those |
| 124 |
of the subprogram designated by the access value, since 'Access |
| 125 |
requires only subtype conformance, not full conformance. |
| 126 |
@end{Ramification} |
| 127 |
@end{StaticSem} |
| 128 |
|
| 129 |
@begin{RunTime} |
| 130 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00415-01]} |
| 131 |
@PDefn2{Term=[evaluation], Sec=(name)} |
| 132 |
The evaluation of a @nt<name> determines the entity denoted by the |
| 133 |
@Chg{Version=[2],New=[@nt<name>],Old=[name]}. This evaluation has no other |
| 134 |
effect for a @nt<name> that |
| 135 |
is a @nt<direct_name> or a @nt<character_literal>. |
| 136 |
|
| 137 |
@PDefn2{Term=[evaluation], Sec=(name that has a prefix)} |
| 138 |
@Redundant[The evaluation of a @nt<name> that has a @nt<prefix> includes |
| 139 |
the evaluation of the @nt<prefix>.] |
| 140 |
@PDefn2{Term=[evaluation], Sec=(prefix)} |
| 141 |
The evaluation of a @nt{prefix} consists of the evaluation of |
| 142 |
the @nt{name} or the @nt{implicit_dereference}. |
| 143 |
The @nt{prefix} denotes the entity denoted by the @nt{name} or the |
| 144 |
@nt{implicit_dereference}. |
| 145 |
|
| 146 |
@PDefn2{Term=[evaluation], Sec=(dereference)} |
| 147 |
The evaluation of a dereference |
| 148 |
consists of the evaluation of the @nt{name} |
| 149 |
and the determination of the object or subprogram that is designated |
| 150 |
by the value of the @nt{name}. |
| 151 |
@IndexCheck{Access_Check} |
| 152 |
A check is made that the value of the @nt{name} is not the null access |
| 153 |
value. |
| 154 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 155 |
Constraint_Error is raised if this check fails. |
| 156 |
The dereference |
| 157 |
denotes the object or subprogram designated by the value of the @nt{name}. |
| 158 |
@end{RunTime} |
| 159 |
|
| 160 |
@begin{Examples} |
| 161 |
@Leading@keepnext@i(Examples of direct names:) |
| 162 |
@begin(Example) |
| 163 |
@tabclear()@tabset(P9, P47) |
| 164 |
Pi @\@RI(-- the direct name of a number) @\(see @RefSecNum(Number Declarations)) |
| 165 |
Limit @\@RI(-- the direct name of a constant) @\(see @RefSecNum(Object Declarations)) |
| 166 |
Count @\@RI(-- the direct name of a scalar variable) @\(see @RefSecNum(Object Declarations)) |
| 167 |
Board @\@RI(-- the direct name of an array variable) @\(see @RefSecNum(Index Constraints and Discrete Ranges)) |
| 168 |
Matrix @\@RI(-- the direct name of a type) @\(see @RefSecNum(Array Types)) |
| 169 |
Random @\@RI(-- the direct name of a function) @\(see @RefSecNum(Subprogram Declarations)) |
| 170 |
Error @\@RI(-- the direct name of an exception) @\(see @RefSecNum(Exception Declarations)) |
| 171 |
@end(Example) |
| 172 |
|
| 173 |
@begin{Wide} |
| 174 |
@leading@keepnext@i{Examples of dereferences:} |
| 175 |
@end{Wide} |
| 176 |
@begin{Example}@tabclear()@tabset(P19) |
| 177 |
Next_Car.@key[all]@\--@RI[ explicit dereference denoting the object designated by] |
| 178 |
@\--@RI[ the access variable Next_Car (see @RefSecNum{Incomplete Type Declarations})] |
| 179 |
Next_Car.Owner @\--@RI[ selected component with implicit dereference;] |
| 180 |
@\--@RI[ same as Next_Car.@key[all].Owner] |
| 181 |
@end{Example} |
| 182 |
@end{Examples} |
| 183 |
|
| 184 |
@begin{Extend83} |
| 185 |
@Defn{extensions to Ada 83} |
| 186 |
Type conversions and function calls are now considered names |
| 187 |
that denote the result of the operation. |
| 188 |
In the case of a type conversion used as an actual |
| 189 |
parameter or that is of a tagged type, the type conversion is considered |
| 190 |
a variable if the operand is a variable. |
| 191 |
This simplifies the description of "parameters of the |
| 192 |
form of a type conversion" as well as better supporting an |
| 193 |
important OOP paradigm that requires the combination of a |
| 194 |
conversion from a class-wide type to some specific |
| 195 |
type followed immediately by component selection. |
| 196 |
Function calls are considered names so that a type conversion |
| 197 |
of a function call and the function call itself are treated |
| 198 |
equivalently in the grammar. |
| 199 |
A function call is considered the name of a constant, |
| 200 |
and can be used anywhere such a name is permitted. |
| 201 |
See @RefSecNum(Return Statements). |
| 202 |
|
| 203 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 204 |
Type conversions of a tagged type are permitted anywhere |
| 205 |
their operand is permitted. That is, if the operand |
| 206 |
is a variable, then the type conversion can appear on the |
| 207 |
left-hand side of an @nt{assignment_statement}. |
| 208 |
If the operand is an object, |
| 209 |
then the type conversion can appear in an object renaming |
| 210 |
or as a @Chg{New=[@nt{prefix}],Old=[prefix]}. |
| 211 |
See @RefSecNum(Type Conversions). |
| 212 |
@end{Extend83} |
| 213 |
|
| 214 |
@begin{DiffWord83} |
| 215 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]} |
| 216 |
Everything of the general syntactic form @nt{name}(...) is |
| 217 |
now syntactically a @nt{name}. In any realistic parser, |
| 218 |
this would be a necessity since distinguishing among the various |
| 219 |
@nt{name}(...) constructs inevitably requires name resolution. |
| 220 |
In cases where the construct yields a value rather than an object, |
| 221 |
the name denotes @Chg{Version=[2],New=[a],Old=[the]} value rather than an |
| 222 |
object. Names already denote values in Ada 83 with named numbers, components of |
| 223 |
the result of a function call, etc. This is partly just a wording change, and |
| 224 |
partly an extension of functionality (see Extensions heading above). |
| 225 |
|
| 226 |
The syntax rule for @nt{direct_name} is new. It is used in places where |
| 227 |
direct visibility is required. |
| 228 |
It's kind of like Ada 83's @ntf{simple_name}, but @ntf{simple_name} applied |
| 229 |
to both direct visibility and visibility by selection, |
| 230 |
and furthermore, it didn't work right for @nt{operator_symbol}s. |
| 231 |
The syntax rule for @ntf{simple_name} is removed, |
| 232 |
since its use is covered by a combination of @nt{direct_name} and |
| 233 |
@nt{selector_name}. |
| 234 |
The syntactic categories @nt{direct_name} and @nt{selector_name} are similar; |
| 235 |
it's mainly the visibility rules that distinguish the two. |
| 236 |
The introduction of @nt{direct_name} requires the insertion of one new |
| 237 |
explicit textual rule: to forbid @nt<statement_identifier>s from being |
| 238 |
@nt<operator_symbol>s. |
| 239 |
This is the only case where the explicit rule is needed, |
| 240 |
because this is the only case where the declaration of the entity is |
| 241 |
implicit. |
| 242 |
For example, there is no need to syntactically forbid (say) @lquotes@;X: "Rem";@rquotes@;, |
| 243 |
because it is impossible to declare a type whose name is an |
| 244 |
@nt{operator_symbol} in the first place. |
| 245 |
|
| 246 |
The syntax rules for @nt{explicit_dereference} |
| 247 |
and @nt{implicit_dereference} are new; |
| 248 |
this makes other rules simpler, since dereferencing an access value has |
| 249 |
substantially different semantics from @nt{selected_component}s. |
| 250 |
We also use @nt{name} instead of @nt{prefix} in the |
| 251 |
@nt{explicit_dereference} rule |
| 252 |
since that seems clearer. Note that these rules rely on the |
| 253 |
fact that function calls are now names, so we don't need to |
| 254 |
use prefix to allow functions calls in front of .@key{all}. |
| 255 |
@begin{Discussion} |
| 256 |
Actually, it would be reasonable to allow any @nt{primary} in front |
| 257 |
of .@key{all}, since only the value is needed, but that would be a bit |
| 258 |
radical. |
| 259 |
@end{Discussion} |
| 260 |
|
| 261 |
We no longer use the term @i(appropriate for a type) |
| 262 |
since we now describe the semantics of a prefix in terms |
| 263 |
of implicit dereference. |
| 264 |
@end{DiffWord83} |
| 265 |
|
| 266 |
@LabeledSubClause{Indexed Components} |
| 267 |
|
| 268 |
@begin{Intro} |
| 269 |
@Redundant[An @nt<indexed_component> denotes either |
| 270 |
a component of an array or an entry |
| 271 |
in a family of entries. |
| 272 |
@IndexSee{Term=[array indexing],See=(indexed_component)}] |
| 273 |
@end{Intro} |
| 274 |
|
| 275 |
@begin{Syntax} |
| 276 |
@Syn{lhs=<indexed_component>,rhs="@Syn2{prefix}(@Syn2{expression} {, @Syn2{expression}})"} |
| 277 |
@end{Syntax} |
| 278 |
|
| 279 |
@begin{Resolution} |
| 280 |
The @nt{prefix} of an @nt{indexed_component} with a given |
| 281 |
number of @nt<expression>s |
| 282 |
shall resolve to denote an array (after any implicit dereference) |
| 283 |
with the corresponding number of index positions, |
| 284 |
or shall resolve to denote an entry family of a task or protected object |
| 285 |
(in which case there shall be only one @nt<expression>). |
| 286 |
|
| 287 |
@PDefn2{Term=[expected type], Sec=(indexed_component expression)} |
| 288 |
The expected type for each @nt{expression} is the corresponding index type. |
| 289 |
|
| 290 |
@end{Resolution} |
| 291 |
|
| 292 |
@begin{StaticSem} |
| 293 |
When the @nt<prefix> denotes an array, |
| 294 |
the @nt<indexed_component> denotes the component of the |
| 295 |
array with the specified index value(s). |
| 296 |
@PDefn2{Term=[nominal subtype], |
| 297 |
Sec=(associated with an @nt<indexed_component>)} |
| 298 |
The nominal subtype of the @nt<indexed_component> is the |
| 299 |
component subtype of the array type. |
| 300 |
@begin{Ramification} |
| 301 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00363-01]} |
| 302 |
@ChgDeleted{Version=[2],Text=[In the case of an array whose components are |
| 303 |
aliased, and |
| 304 |
of an unconstrained discriminated subtype, the components |
| 305 |
are constrained even though their nominal subtype is unconstrained. |
| 306 |
(This is because all aliased discriminated objects are constrained. |
| 307 |
See @RefSecNum(Operations of Access Types).) |
| 308 |
In all other cases, an array component is constrained if and only |
| 309 |
if its nominal subtype is constrained.]} |
| 310 |
@end{Ramification} |
| 311 |
|
| 312 |
When the @nt<prefix> denotes an entry family, |
| 313 |
the @nt<indexed_component> denotes |
| 314 |
the individual entry of the entry family with the specified index value. |
| 315 |
|
| 316 |
@end{StaticSem} |
| 317 |
|
| 318 |
@begin{RunTime} |
| 319 |
@PDefn2{Term=[evaluation], Sec=(indexed_component)} |
| 320 |
For the evaluation of an @nt<indexed_component>, the @nt{prefix} and the |
| 321 |
@nt{expression}s are evaluated in an arbitrary order. The value of |
| 322 |
each @nt<expression> is converted to the corresponding index type. |
| 323 |
@PDefn2{Term=[implicit subtype conversion],Sec=(array index)} |
| 324 |
@IndexCheck{Index_Check} |
| 325 |
A check is made that each index value |
| 326 |
belongs to the corresponding index range of the array or entry family |
| 327 |
denoted by the @nt<prefix>. |
| 328 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 329 |
Constraint_Error is raised if this check fails. |
| 330 |
|
| 331 |
@end{RunTime} |
| 332 |
|
| 333 |
@begin{Examples} |
| 334 |
@Leading@keepnext@i(Examples of indexed components:) |
| 335 |
@begin{Example} |
| 336 |
@tabclear()@tabset(P64) |
| 337 |
My_Schedule(Sat) --@RI[ a component of a one-dimensional array @\(see @RefSecNum{Index Constraints and Discrete Ranges})] |
| 338 |
Page(10) --@RI[ a component of a one-dimensional array @\(see @RefSecNum{Array Types})] |
| 339 |
Board(M, J + 1) --@RI[ a component of a two-dimensional array @\(see @RefSecNum{Index Constraints and Discrete Ranges})] |
| 340 |
Page(10)(20) --@RI[ a component of a component @\(see @RefSecNum{Array Types})] |
| 341 |
Request(Medium) --@RI[ an entry in a family of entries @\(see @RefSecNum{Task Units and Task Objects})] |
| 342 |
Next_Frame(L)(M, N) --@RI[ a component of a function call @\(see @RefSecNum{Subprogram Declarations})] |
| 343 |
@end{Example} |
| 344 |
@end{Examples} |
| 345 |
|
| 346 |
@begin{Notes} |
| 347 |
@i(Notes on the examples:) |
| 348 |
Distinct notations are used for components of multidimensional arrays (such |
| 349 |
as Board) and arrays of arrays (such as Page). The components of an array |
| 350 |
of arrays are arrays and can therefore be indexed. Thus Page(10)(20) |
| 351 |
denotes the 20th component of Page(10). In the last example Next_Frame(L) |
| 352 |
is a function call returning an access value that designates a |
| 353 |
two-dimensional array. |
| 354 |
|
| 355 |
@end{Notes} |
| 356 |
|
| 357 |
@LabeledSubClause{Slices} |
| 358 |
|
| 359 |
@begin{Intro} |
| 360 |
@redundant[@Defn{array slice} |
| 361 |
A @nt<slice> denotes a one-dimensional array formed by a sequence of |
| 362 |
consecutive components of a one-dimensional array. A @nt<slice> of |
| 363 |
a variable is a variable; a @nt<slice> of a constant is a constant;] |
| 364 |
a @nt<slice> of a value is a value. |
| 365 |
@end{Intro} |
| 366 |
|
| 367 |
@begin{Syntax} |
| 368 |
@Syn{lhs=<slice>,rhs="@Syn2{prefix}(@Syn2{discrete_range})"} |
| 369 |
@end{Syntax} |
| 370 |
|
| 371 |
@begin{Resolution} |
| 372 |
The @nt{prefix} of a @nt{slice} |
| 373 |
shall resolve to denote a one-dimensional array |
| 374 |
(after any implicit dereference). |
| 375 |
|
| 376 |
@PDefn2{Term=[expected type], Sec=(slice discrete_range)} |
| 377 |
The expected type for the @nt{discrete_range} of a @nt<slice> |
| 378 |
is the index type of the array type. |
| 379 |
@end{Resolution} |
| 380 |
|
| 381 |
@begin{StaticSem} |
| 382 |
A @nt<slice> denotes a one-dimensional array formed by the sequence of |
| 383 |
consecutive components of the array denoted by the @nt<prefix>, |
| 384 |
corresponding to the range of values |
| 385 |
of the index given by the @nt<discrete_range>. |
| 386 |
|
| 387 |
The type of the @nt<slice> is that of the @nt<prefix>. |
| 388 |
Its bounds are those defined by the @nt{discrete_range}. |
| 389 |
|
| 390 |
@end{StaticSem} |
| 391 |
|
| 392 |
@begin{RunTime} |
| 393 |
@PDefn2{Term=[evaluation], Sec=(slice)} |
| 394 |
For the evaluation of a @nt{slice}, |
| 395 |
the @nt{prefix} and the @nt{discrete_range} |
| 396 |
are evaluated in an arbitrary order. |
| 397 |
@IndexCheck{Index_Check} |
| 398 |
@Defn{null slice} |
| 399 |
If the @nt{slice} is not a @i(null slice) |
| 400 |
(a @nt<slice> where the @nt<discrete_range> is a null range), |
| 401 |
then a check is made that the bounds of the @nt{discrete_range} |
| 402 |
belong to the index range of the array denoted by the @nt{prefix}. |
| 403 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 404 |
Constraint_Error is raised if this check fails. |
| 405 |
|
| 406 |
@end{RunTime} |
| 407 |
|
| 408 |
@begin{Notes} |
| 409 |
A @nt<slice> is not permitted as the @nt<prefix> of an |
| 410 |
Access @nt<attribute_reference>, |
| 411 |
even if the components or the array as a whole are aliased. |
| 412 |
See @RefSecNum(Operations of Access Types). |
| 413 |
@begin{TheProof} |
| 414 |
Slices are not aliased, by @RefSec{Access Types}. |
| 415 |
@end{TheProof} |
| 416 |
@begin(Reason) |
| 417 |
This is to ease implementation of general-access-to-array. |
| 418 |
If slices were aliased, implementations would need to store |
| 419 |
array dope with the access values, which is not always desirable |
| 420 |
given access-to-incomplete types completed in a package body. |
| 421 |
@end(Reason) |
| 422 |
|
| 423 |
For a one-dimensional array A, the @nt<slice> A(N .. N) denotes |
| 424 |
an array that has only one component; |
| 425 |
its type is the type of A. On the other hand, A(N) denotes a |
| 426 |
component of the array A and has the corresponding component type. |
| 427 |
@end{Notes} |
| 428 |
|
| 429 |
@begin{Examples} |
| 430 |
@Leading@keepnext@i(Examples of slices:) |
| 431 |
@begin{Example} |
| 432 |
@tabclear()@tabset(P58) |
| 433 |
Stars(1 .. 15) --@RI[ a slice of 15 characters @\(see @RefSecNum{String Types})] |
| 434 |
Page(10 .. 10 + Size) --@RI[ a slice of 1 + Size components @\(see @RefSecNum{Array Types})] |
| 435 |
Page(L)(A .. B) --@RI[ a slice of the array Page(L) @\(see @RefSecNum{Array Types})] |
| 436 |
Stars(1 .. 0) --@RI[ a null slice @\(see @RefSecNum{String Types})] |
| 437 |
My_Schedule(Weekday) --@RI[ bounds given by subtype @\(see @RefSecNum{Index Constraints and Discrete Ranges} and @RefSecNum{Enumeration Types})] |
| 438 |
Stars(5 .. 15)(K) --@RI[ same as Stars(K) @\(see @RefSecNum{String Types})] |
| 439 |
--@RI[ provided that K is in 5 .. 15] |
| 440 |
@end{Example} |
| 441 |
@end{Examples} |
| 442 |
|
| 443 |
@LabeledSubClause{Selected Components} |
| 444 |
|
| 445 |
@begin{Intro} |
| 446 |
@redundant[@nt{Selected_component}s are used to denote components (including |
| 447 |
discriminants), |
| 448 |
entries, entry families, and protected subprograms; they are |
| 449 |
also used as expanded names as described below. |
| 450 |
@IndexSee{Term=[dot selection],See=(selected_component)}] |
| 451 |
@end{Intro} |
| 452 |
|
| 453 |
@begin{Syntax} |
| 454 |
@Syn{lhs=<selected_component>,rhs="@Syn2{prefix} . @Syn2{selector_name}"} |
| 455 |
|
| 456 |
|
| 457 |
@Syn{lhs=<selector_name>,rhs="@Syn2{identifier} | @Syn2{character_literal} | @Syn2{operator_symbol}"} |
| 458 |
@end{Syntax} |
| 459 |
|
| 460 |
@begin{Resolution} |
| 461 |
@Defn{expanded name} |
| 462 |
A @nt<selected_component> is called an @i(expanded name) |
| 463 |
if, according to the visibility rules, at least one possible |
| 464 |
interpretation of its @nt<prefix> denotes |
| 465 |
a package or an enclosing named construct (directly, not through |
| 466 |
a @nt<subprogram_renaming_declaration> |
| 467 |
or @nt<generic_renaming_declaration>). |
| 468 |
@begin{Discussion} |
| 469 |
See AI83-00187. |
| 470 |
@end{Discussion} |
| 471 |
|
| 472 |
@Leading@;A @nt{selected_component} that is not an expanded name |
| 473 |
shall resolve to denote one of the following: |
| 474 |
@begin(Ramification) |
| 475 |
If the @nt<prefix> of a @nt<selected_component> denotes |
| 476 |
an enclosing named construct, then the @nt<selected_component> is interpreted |
| 477 |
only as an expanded name, even if the named construct |
| 478 |
is a function that could be called without parameters. |
| 479 |
@end(Ramification) |
| 480 |
@begin{Itemize} |
| 481 |
A component @Redundant[(including a discriminant)]: |
| 482 |
|
| 483 |
@NoPrefix@;The @nt{prefix} shall resolve to denote an object or value of some |
| 484 |
non-array composite type |
| 485 |
(after any implicit dereference). |
| 486 |
The @nt{selector_name} shall resolve to denote a |
| 487 |
@nt{discriminant_specification} of the type, or, unless the type is |
| 488 |
a protected type, a @nt<component_declaration> |
| 489 |
of the type. The @nt{selected_component} denotes the |
| 490 |
corresponding component of the object or value. |
| 491 |
@begin{Reason} |
| 492 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00015} |
| 493 |
The components of a protected object cannot be named except |
| 494 |
by an expanded name, even from within the corresponding protected body. |
| 495 |
The protected body may not reference @Chg{New=[],Old=[the ]}the private |
| 496 |
components of some arbitrary object of the protected |
| 497 |
type; the protected body may reference components of the current |
| 498 |
instance only (by an expanded name or a @nt<direct_name>). |
| 499 |
@end{Reason} |
| 500 |
@begin{Ramification} |
| 501 |
Only the discriminants and components visible at the place of the |
| 502 |
@nt<selected_component> can be selected, since a @nt<selector_name> |
| 503 |
can only denote declarations that are visible (see @RefSecNum{Visibility}). |
| 504 |
@end{Ramification} |
| 505 |
|
| 506 |
A single entry, an entry family, or a protected subprogram: |
| 507 |
|
| 508 |
@NoPrefix@;The @nt{prefix} shall resolve to denote an object or value of some |
| 509 |
task or protected type (after any implicit dereference). |
| 510 |
The @nt{selector_name} shall resolve to denote an @nt{entry_declaration} |
| 511 |
or @nt{subprogram_declaration} occurring (implicitly or explicitly) |
| 512 |
within the visible part of that type. |
| 513 |
The @nt{selected_component} denotes the |
| 514 |
corresponding entry, entry family, or protected subprogram. |
| 515 |
@begin{Reason} |
| 516 |
This explicitly says @lquotes@;visible part@rquotes@; because even though the body |
| 517 |
has visibility on the private part, it cannot call the |
| 518 |
private operations of some arbitrary object of the task or protected |
| 519 |
type, only those of the current instance (and expanded name notation |
| 520 |
has to be used for that). |
| 521 |
@end{Reason} |
| 522 |
|
| 523 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]} |
| 524 |
@ChgAdded{Version=[2],Text=[A view of a subprogram whose first formal parameter is of |
| 525 |
a tagged type or is an access parameter whose designated type is tagged:]} |
| 526 |
|
| 527 |
@ChgRef{Version=[2],Kind=[Added]} |
| 528 |
@ChgAdded{Version=[2],NoPrefix=[T],Text=[The @nt<prefix> (after any implicit |
| 529 |
dereference) shall resolve to denote an object or value of a specific tagged |
| 530 |
type @i<T> or class-wide type @i<T>'Class. The @nt<selector_name> shall resolve |
| 531 |
to denote a view of a subprogram declared immediately within the declarative |
| 532 |
region in which an ancestor of the type @i<T> is declared. The first formal |
| 533 |
parameter of the subprogram shall be of type @i<T>, or a class-wide type that |
| 534 |
covers @i<T>, or an access parameter designating one of these types. The |
| 535 |
designator of the subprogram shall not be the same as that of a component of |
| 536 |
the tagged type visible at the point of the @nt<selected_component>. The |
| 537 |
@nt<selected_component> denotes a view of this subprogram that omits the first |
| 538 |
formal parameter. This view is called a @i{prefixed view} of the subprogram, |
| 539 |
and the @nt{prefix} of the @nt<selected_component> (after any implicit |
| 540 |
dereference) is called the @i<prefix> of the prefixed view. |
| 541 |
@Defn{prefixed view}@Defn2{Term=[prefix],Sec=[of a prefixed view]}]} |
| 542 |
|
| 543 |
@end{Itemize} |
| 544 |
|
| 545 |
@Leading@;An expanded name shall resolve to denote a declaration that |
| 546 |
occurs immediately within a named declarative region, as follows: |
| 547 |
@begin(itemize) |
| 548 |
The @nt<prefix> shall resolve to denote either a package @Redundant[(including |
| 549 |
the current instance of a generic package, or a rename of a package)], or |
| 550 |
an enclosing named construct. |
| 551 |
|
| 552 |
The @nt{selector_name} |
| 553 |
shall resolve to denote a declaration that occurs |
| 554 |
immediately within the declarative region of the |
| 555 |
package or enclosing construct @Redundant[(the declaration shall be visible |
| 556 |
at the place of the expanded name @em see @RefSecNum(Visibility))]. |
| 557 |
The expanded name denotes that declaration. |
| 558 |
@begin{Ramification} |
| 559 |
Hence, a library unit or subunit can use an expanded |
| 560 |
name to refer to the declarations within the private part of its |
| 561 |
parent unit, as well as to other children that have been mentioned in |
| 562 |
@nt<with_clause>s. |
| 563 |
@end{Ramification} |
| 564 |
|
| 565 |
If the @nt<prefix> does not denote a package, then it |
| 566 |
shall be a @nt<direct_name> or an expanded name, |
| 567 |
and it shall resolve to denote a program unit (other than a package), |
| 568 |
the current instance of a type, a @nt{block_statement}, a @nt{loop_statement}, |
| 569 |
or an @nt{accept_@!statement} |
| 570 |
(in the case of an @nt<accept_@!statement> or @nt<entry_@!body>, |
| 571 |
no family index is allowed); |
| 572 |
the expanded name shall occur within the |
| 573 |
declarative region of this construct. |
| 574 |
Further, if this construct is a callable construct |
| 575 |
and the @nt<prefix> denotes more than one such enclosing callable construct, |
| 576 |
then the expanded name is ambiguous, independently of the @nt<selector_name>. |
| 577 |
|
| 578 |
@end(itemize) |
| 579 |
|
| 580 |
@end{Resolution} |
| 581 |
|
| 582 |
@begin{Legality} |
| 583 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]} |
| 584 |
@ChgAdded{Version=[2],Text=[For a subprogram whose first parameter is an |
| 585 |
access parameter, the prefix of any prefixed view shall denote an aliased |
| 586 |
view of an object.]} |
| 587 |
|
| 588 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00407-01]} |
| 589 |
@ChgAdded{Version=[2],Text=[For a subprogram whose first parameter is of mode |
| 590 |
@b<in out> or @b<out>, or of an anonymous access-to-variable type, the prefix |
| 591 |
of any prefixed view shall denote a variable.]} |
| 592 |
|
| 593 |
@begin{Reason} |
| 594 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 595 |
@ChgAdded{Version=[2],Text=[We want calls through a prefixed view and through |
| 596 |
a normal view to have the same legality. Thus, the implicit 'Access in |
| 597 |
this new notation needs the same legality check that an explicit 'Access |
| 598 |
would have. Similarly, we need to prohibit the object from being constant |
| 599 |
if the first parameter of the subprogram is @key{in out}, because that is |
| 600 |
(obviously) prohibited for passing a normal parameter.]} |
| 601 |
@end{Reason} |
| 602 |
@end{Legality} |
| 603 |
|
| 604 |
@begin{RunTime} |
| 605 |
@PDefn2{Term=[evaluation], Sec=(selected_component)} |
| 606 |
The evaluation of a @nt{selected_component} includes the |
| 607 |
evaluation of the @nt{prefix}. |
| 608 |
|
| 609 |
@IndexCheck{Discriminant_Check} |
| 610 |
For a @nt{selected_component} that denotes a component of a @nt{variant}, |
| 611 |
a check is made that the values of the discriminants are such that |
| 612 |
the value or object denoted by the @nt<prefix> has this component. |
| 613 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 614 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 615 |
The exception Constraint_Error is raised if this check fails. |
| 616 |
|
| 617 |
@end{RunTime} |
| 618 |
|
| 619 |
@begin{Examples} |
| 620 |
@Leading@keepnext@i(Examples of selected components:) |
| 621 |
@begin{Example} |
| 622 |
@tabclear()@tabset(P60) |
| 623 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01],ARef=[AI95-00407-01]} |
| 624 |
Tomorrow.Month --@RI[ a record component @\(see @RefSecNum{Record Types})] |
| 625 |
Next_Car.Owner --@RI[ a record component @\(see @RefSecNum{Incomplete Type Declarations})] |
| 626 |
Next_Car.Owner.Age --@RI[ a record component @\(see @RefSecNum{Incomplete Type Declarations})] |
| 627 |
--@RI[ the previous two lines involve implicit dereferences] |
| 628 |
Writer.Unit --@RI[ a record component (a discriminant) @\(see @RefSecNum{Variant Parts and Discrete Choices})] |
| 629 |
Min_Cell(H).Value --@RI[ a record component of the result @\(see @RefSecNum{Subprogram Declarations})] |
| 630 |
--@RI[ of the function call Min_Cell(H)] |
| 631 |
@Chg{Version=[2],New=< Cashier.Append --@RI[ a prefixed view of a procedure @\(see @RefSecNum{Interface Types})] |
| 632 |
>,Old=<>} Control.Seize --@RI[ an entry of a protected object @\(see @RefSecNum{Protected Units and Protected Objects})] |
| 633 |
Pool(K).Write --@RI[ an entry of the task Pool(K) @\(see @RefSecNum{Protected Units and Protected Objects})] |
| 634 |
@end{Example} |
| 635 |
|
| 636 |
@begin{Wide} |
| 637 |
@leading@keepnext@i(Examples of expanded names:) |
| 638 |
@end{Wide} |
| 639 |
@begin{Example} |
| 640 |
@tabclear()@tabset(P67) |
| 641 |
Key_Manager."<" --@RI[ an operator of the visible part of a package @\(see @RefSecNum{Private Operations})] |
| 642 |
Dot_Product.Sum --@RI[ a variable declared in a function body @\(see @RefSecNum{Subprogram Declarations})] |
| 643 |
Buffer.Pool --@RI[ a variable declared in a protected unit @\(see @RefSecNum{Example of Tasking and Synchronization})] |
| 644 |
Buffer.Read --@RI[ an entry of a protected unit @\(see @RefSecNum{Example of Tasking and Synchronization})] |
| 645 |
Swap.Temp --@RI[ a variable declared in a block statement @\(see @RefSecNum{Block Statements})] |
| 646 |
Standard.Boolean --@RI[ the name of a predefined type @\(see @RefSecNum{The Package Standard})] |
| 647 |
@end{Example} |
| 648 |
@end{Examples} |
| 649 |
|
| 650 |
@begin{Extend83} |
| 651 |
@Defn{extensions to Ada 83} |
| 652 |
We now allow an expanded name to use a prefix |
| 653 |
that denotes a rename of a package, even if the |
| 654 |
selector is for an entity local to the body or private |
| 655 |
part of the package, so long as the entity is visible |
| 656 |
at the place of the reference. This eliminates |
| 657 |
a preexisting anomaly where references in a package |
| 658 |
body may refer to declarations of its visible part |
| 659 |
but not those of its private part or body when the |
| 660 |
prefix is a rename of the package. |
| 661 |
@end{Extend83} |
| 662 |
|
| 663 |
@begin{DiffWord83} |
| 664 |
The syntax rule for @nt{selector_name} is new. It is used in places where |
| 665 |
visibility, but not necessarily direct visibility, is required. |
| 666 |
See @RefSec{Names} for more information. |
| 667 |
|
| 668 |
The description of dereferencing an access type has been moved |
| 669 |
to @RefSec{Names}; @nt<name>.@key(all) is no longer considered |
| 670 |
a @nt<selected_component>. |
| 671 |
|
| 672 |
The rules have been restated to be consistent with our |
| 673 |
new terminology, to accommodate class-wide types, etc. |
| 674 |
@end{DiffWord83} |
| 675 |
|
| 676 |
@begin{Extend95} |
| 677 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00252-01]} |
| 678 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}The prefixed view notation |
| 679 |
for tagged objects is new. This provides a similar notation to that used in other |
| 680 |
popular languages, and also reduces the need for @nt{use_clause}s. This |
| 681 |
is sometimes known as @lquotes@;distinguished receiver notation@rquotes@;. |
| 682 |
@Defn{distinguished receiver notation}]} |
| 683 |
|
| 684 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 685 |
@ChgAdded{Version=[2],Type=[Leading],Text=[Given the following |
| 686 |
definitions for a tagged type T:]} |
| 687 |
@begin{Example} |
| 688 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 689 |
@ChgAdded{Version=[2],Text=[@key{procedure} Do_Something (Obj : @key{in out} T; Count : @key{in} Natural); |
| 690 |
@key{procedure} Do_Something_Else (Obj : @key{access} T; Flag : @key{in} Boolean); |
| 691 |
My_Object : @key{aliased} T;]} |
| 692 |
@end{Example} |
| 693 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 694 |
@ChgAdded{Version=[2],Type=[Leading],Text=[the following calls are equivalent:]} |
| 695 |
@begin{Example} |
| 696 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 697 |
@ChgAdded{Version=[2],Text=[Do_Something (My_Object, Count => 10); |
| 698 |
My_Object.Do_Something (Count => 10);]} |
| 699 |
@end{Example} |
| 700 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 701 |
@ChgAdded{Version=[2],Type=[Leading],Text=[as are the following calls:]} |
| 702 |
@begin{Example} |
| 703 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 704 |
@ChgAdded{Version=[2],Text=[Do_Something_Else (My_Object'Access, Flag => True); |
| 705 |
My_Object.Do_Something_Else (Flag => True);]} |
| 706 |
@end{Example} |
| 707 |
@end{Extend95} |
| 708 |
|
| 709 |
|
| 710 |
@RMNewPage@ChgNote{Only needed for Ada 2005 version} |
| 711 |
@LabeledSubClause{Attributes} |
| 712 |
|
| 713 |
@begin{Intro} |
| 714 |
@Defn{attribute} |
| 715 |
@Redundant[An @i(attribute) is a characteristic of an entity that can be |
| 716 |
queried via an @nt{attribute_@!reference} |
| 717 |
or a @nt<range_@!attribute_@!reference>.] |
| 718 |
@end{Intro} |
| 719 |
|
| 720 |
@begin{Syntax} |
| 721 |
@Syn{lhs=<attribute_reference>, |
| 722 |
rhs="@Syn2{prefix}@SingleQuote@Syn2{attribute_designator}"} |
| 723 |
|
| 724 |
@Syn{lhs=<attribute_designator>,rhs=" |
| 725 |
@Syn2{identifier}[(@SynI{static_}@Syn2{expression})] |
| 726 |
| Access | Delta | Digits"} |
| 727 |
|
| 728 |
|
| 729 |
@Syn{lhs=<range_attribute_reference>, |
| 730 |
rhs="@Syn2{prefix}@SingleQuote@Syn2{range_attribute_designator}"} |
| 731 |
|
| 732 |
@Syn{lhs=<range_attribute_designator>, |
| 733 |
rhs="Range[(@SynI{static_}@Syn2{expression})]"} |
| 734 |
@end{Syntax} |
| 735 |
|
| 736 |
@begin{Resolution} |
| 737 |
In an @nt<attribute_reference>, |
| 738 |
if the @nt<attribute_designator> is for an attribute defined |
| 739 |
for (at least some) objects of an access type, then the @nt<prefix> is never |
| 740 |
interpreted as an @nt<implicit_dereference>; |
| 741 |
otherwise (and for all @nt<range_attribute_reference>s), |
| 742 |
if the type of the @nt<name> within the @nt<prefix> |
| 743 |
is of an access type, the @nt<prefix> is interpreted as an |
| 744 |
@nt<implicit_dereference>. |
| 745 |
Similarly, if the @nt{attribute_designator} is for an attribute defined for (at |
| 746 |
least some) functions, then the @nt<prefix> is never interpreted as a |
| 747 |
parameterless @nt{function_call}; otherwise |
| 748 |
(and for all @nt<range_attribute_reference>s), if the @nt<prefix> |
| 749 |
consists of a @nt<name> that denotes a function, it is interpreted |
| 750 |
as a parameterless @nt<function_call>. |
| 751 |
@begin{Discussion} |
| 752 |
The first part of this rule is essentially a "preference" |
| 753 |
against implicit dereference, so that it is possible |
| 754 |
to ask for, say, 'Size of an access object, |
| 755 |
without automatically getting the size of the object designated |
| 756 |
by the access object. |
| 757 |
This rule applies to 'Access, 'Unchecked_Access, 'Size, and 'Address, |
| 758 |
and any other attributes that are defined for at least some |
| 759 |
access objects. |
| 760 |
|
| 761 |
The second part of this rule implies that, for a parameterless function F, |
| 762 |
F'Address is the address of F, whereas |
| 763 |
F'Size is the size of the anonymous constant returned by F. |
| 764 |
|
| 765 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 766 |
We normally talk in terms of expected type or profile for |
| 767 |
name resolution rules, but we don't do this for attributes |
| 768 |
because certain attributes are legal independent of the type |
| 769 |
or the profile of the @Chg{New=[@nt{prefix}],Old=[prefix]}. |
| 770 |
|
| 771 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]} |
| 772 |
@ChgAdded{Version=[2],Type=[Leading],Text=[Other than the rules given above, |
| 773 |
the @ResolutionName@;s for the @nt{prefix} of each attribute are defined as |
| 774 |
@ResolutionTitle for that attribute. If no such rules are defined, then no |
| 775 |
context at all should be used when resolving |
| 776 |
the @nt{prefix}. In particular, any knowledge about the kind of entities |
| 777 |
required must not be used for resolution unless that is required by |
| 778 |
@ResolutionTitle. This matters in obscure cases; |
| 779 |
for instance, given the following declarations:]} |
| 780 |
@begin{Example} |
| 781 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 782 |
@ChgAdded{Version=[2],Text=[ @key[function] Get_It @key[return] Integer @key[is] ... -- @RI[(1)] |
| 783 |
@key[function] Get_It @key[return] Some_Record_Type @key[is] ... -- @RI[(2)]]} |
| 784 |
@end{Example} |
| 785 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 786 |
@ChgAdded{Version=[2],Type=[Leading],Text=[the following @nt{attribute_reference} cannot be |
| 787 |
resolved and is illegal:]} |
| 788 |
@begin{Example} |
| 789 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 790 |
@ChgAdded{Version=[2],Text=[ @key[if] Get_It'Valid @key[then]]} |
| 791 |
@end{Example} |
| 792 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 793 |
@ChgAdded{Version=[2],Text=[even though the Valid attribute is only defined |
| 794 |
for objects of scalar types, and thus cannot be applied to the result of |
| 795 |
function (2). That information cannot be used to resolve the @nt{prefix}. |
| 796 |
The same would be true if (2) was been a procedure; even though the |
| 797 |
procedure does not denote an object, the @nt{attribute_reference} is |
| 798 |
still illegal.]} |
| 799 |
@end{Discussion} |
| 800 |
|
| 801 |
@PDefn2{Term=[expected type], |
| 802 |
Sec=(attribute_designator expression)} |
| 803 |
@PDefn2{Term=[expected type], |
| 804 |
Sec=(range_attribute_designator expression)} |
| 805 |
The @nt{expression}, if any, in an |
| 806 |
@nt{attribute_designator} or @nt{range_attribute_designator} |
| 807 |
is expected to be of any integer type. |
| 808 |
@end{Resolution} |
| 809 |
|
| 810 |
@begin{Legality} |
| 811 |
The @nt{expression}, if any, in an @nt{attribute_designator} |
| 812 |
or @nt{range_attribute_designator} shall be static. |
| 813 |
@end{Legality} |
| 814 |
|
| 815 |
@begin{StaticSem} |
| 816 |
An @nt{attribute_reference} denotes a |
| 817 |
value, an object, a subprogram, or some |
| 818 |
other kind of program entity. |
| 819 |
@begin{Ramification} |
| 820 |
The attributes defined by the language are summarized in |
| 821 |
@RefSecNum{Language-Defined Attributes}. |
| 822 |
Implementations can define additional attributes. |
| 823 |
@end{Ramification} |
| 824 |
|
| 825 |
@Redundant[A @nt{range_attribute_reference} |
| 826 |
X'Range(N) is equivalent to the @nt<range> X'First(N) .. |
| 827 |
X'Last(N), except that the @nt{prefix} is only evaluated once. |
| 828 |
Similarly, |
| 829 |
X'Range is equivalent to X'First .. X'Last, except that the @nt{prefix} |
| 830 |
is only evaluated once.] |
| 831 |
|
| 832 |
@end{StaticSem} |
| 833 |
|
| 834 |
@begin{RunTime} |
| 835 |
@PDefn2{Term=[evaluation], Sec=(attribute_reference)} |
| 836 |
@PDefn2{Term=[evaluation], Sec=(range_attribute_reference)} |
| 837 |
The evaluation of an @nt{attribute_reference} |
| 838 |
(or @nt{range_attribute_reference}) consists |
| 839 |
of the evaluation of the @nt{prefix}. |
| 840 |
@end{RunTime} |
| 841 |
|
| 842 |
@begin{ImplPerm} |
| 843 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0015],ARef=[AI95-00093-01]} |
| 844 |
An implementation may provide implementation-defined attributes; |
| 845 |
the @nt{identifier} for an implementation-defined |
| 846 |
attribute shall differ from those of the language-defined |
| 847 |
attributes@Chg{New=[ unless supplied for compatibility with a previous edition of |
| 848 |
this International Standard],Old=[]}. |
| 849 |
@ImplDef{Implementation-defined attributes.} |
| 850 |
@begin{Ramification} |
| 851 |
They cannot be reserved words because reserved words are not legal |
| 852 |
identifiers. |
| 853 |
|
| 854 |
The semantics of implementation-defined attributes, |
| 855 |
and any associated rules, are, of course, implementation defined. |
| 856 |
For example, the implementation defines whether a given |
| 857 |
implementation-defined attribute can be used in a static expression. |
| 858 |
|
| 859 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0015],ARef=[AI95-00093-01]} |
| 860 |
@Chg{New=[Implementations are allowed to support the Small attribute for |
| 861 |
floating types, as this was defined in Ada 83, even though the name would |
| 862 |
conflict with a language-defined attribute.],Old=[]} |
| 863 |
@end{Ramification} |
| 864 |
@end{ImplPerm} |
| 865 |
|
| 866 |
@begin{Notes} |
| 867 |
Attributes are defined throughout this International Standard, |
| 868 |
and are summarized in |
| 869 |
@RefSecNum{Language-Defined Attributes}. |
| 870 |
|
| 871 |
@ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006} |
| 872 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235]} |
| 873 |
In general, the @nt<name> in a @nt<prefix> of an @nt<attribute_reference> |
| 874 |
(or a @nt<range_attribute_reference>) has to be resolved |
| 875 |
without using any context. |
| 876 |
However, in the case of the Access attribute, |
| 877 |
the expected type for the @Chg{Version=[2],New=[@nt{attribute_reference}], |
| 878 |
Old=[@Chg{New=[@nt{prefix}],Old=[prefix]}]} has to be a |
| 879 |
single access type, and@Chg{Version=[2],New=[],Old=[ if it is an |
| 880 |
access-to-subprogram type (see @RefSecNum(Operations of Access Types)) then]} |
| 881 |
the resolution of the @nt<name> can use the fact that |
| 882 |
the@Chg{Version=[2],New=[ type of the object or the],Old=[]} profile of the |
| 883 |
callable entity denoted by the @nt<prefix> |
| 884 |
has to @Chg{Version=[2],New=[match the designated type or ],Old=[]}be type |
| 885 |
conformant with the designated profile of the access type. |
| 886 |
@Defn2{Term=[type conformance],Sec=(required)} |
| 887 |
@begin(TheProof) |
| 888 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00235]} |
| 889 |
In the general case, there is no @lquotes@;expected type@rquotes@; for |
| 890 |
the @nt<prefix> of an @nt<attribute_reference>. |
| 891 |
In the special case of 'Access, |
| 892 |
there is an @Chg{Version=[2],New=[@lquotes@;expected type@rquotes@; or ], |
| 893 |
Old=[]}@lquotes@;expected profile@rquotes@; for the @nt<prefix>. |
| 894 |
@end(TheProof) |
| 895 |
@begin(Reason) |
| 896 |
'Access is a special case, because without it, |
| 897 |
it would be very difficult to take 'Access of an overloaded |
| 898 |
subprogram. |
| 899 |
@end(Reason) |
| 900 |
@end{Notes} |
| 901 |
|
| 902 |
@begin{Examples} |
| 903 |
@Leading@keepnext@i(Examples of attributes:) |
| 904 |
@begin{Example} |
| 905 |
@tabclear()@tabset(P64) |
| 906 |
Color'First --@RI[ minimum value of the enumeration type Color @\(see @RefSecNum{Enumeration Types})] |
| 907 |
Rainbow'Base'First --@RI[ same as Color'First @\(see @RefSecNum{Enumeration Types})] |
| 908 |
Real'Digits --@RI[ precision of the type Real @\(see @RefSecNum{Floating Point Types})] |
| 909 |
Board'Last(2) --@RI[ upper bound of the second dimension of Board @\(see @RefSecNum{Index Constraints and Discrete Ranges})] |
| 910 |
Board'Range(1) --@RI[ index range of the first dimension of Board @\(see @RefSecNum{Index Constraints and Discrete Ranges})] |
| 911 |
Pool(K)'Terminated --@RI[ True if task Pool(K) is terminated @\(see @RefSecNum{Task Units and Task Objects})] |
| 912 |
Date'Size --@RI[ number of bits for records of type Date @\(see @RefSecNum{Record Types})] |
| 913 |
Message'Address --@RI[ address of the record variable Message @\(see @RefSecNum{Discriminant Constraints})] |
| 914 |
@end{Example} |
| 915 |
@end{Examples} |
| 916 |
|
| 917 |
@begin{Extend83} |
| 918 |
@Defn{extensions to Ada 83} |
| 919 |
We now uniformly treat X'Range as X'First..X'Last, |
| 920 |
allowing its use with scalar subtypes. |
| 921 |
|
| 922 |
We allow any integer type in the @SynI{static_}@nt{expression} |
| 923 |
of an attribute designator, not |
| 924 |
just a value of @i(universal_integer). The preference rules |
| 925 |
ensure upward compatibility. |
| 926 |
@end{Extend83} |
| 927 |
|
| 928 |
@begin{DiffWord83} |
| 929 |
We use the syntactic category @nt{attribute_reference} rather |
| 930 |
than simply "attribute" to avoid confusing the name of something with |
| 931 |
the thing itself. |
| 932 |
|
| 933 |
The syntax rule for @nt{attribute_reference} |
| 934 |
now uses @nt{identifier} instead of |
| 935 |
@ntf{simple_name}, because attribute @nt{identifier}s are not required to |
| 936 |
follow the normal visibility rules. |
| 937 |
|
| 938 |
We now separate @nt{attribute_reference} |
| 939 |
from @nt{range_attribute_reference}, |
| 940 |
and enumerate the reserved words that are legal attribute or range attribute |
| 941 |
designators. |
| 942 |
We do this because @nt{identifier} no longer includes reserved |
| 943 |
words. |
| 944 |
|
| 945 |
The Ada 95 name resolution rules are a bit more explicit than in Ada 83. |
| 946 |
The Ada 83 rule said that the |
| 947 |
"meaning of the prefix of an attribute must be determinable |
| 948 |
independently of the attribute designator and independently |
| 949 |
of the fact that it is the prefix of an attribute." That isn't |
| 950 |
quite right since the meaning even in Ada 83 embodies whether or not |
| 951 |
the prefix is interpreted as a parameterless function call, |
| 952 |
and in Ada 95, it also embodies whether or not the prefix is interpreted |
| 953 |
as an implicit_dereference. So the attribute designator does |
| 954 |
make a difference @em just not much. |
| 955 |
|
| 956 |
Note however that if the attribute designator is Access, |
| 957 |
it makes a big difference in the interpretation of the |
| 958 |
prefix (see @RefSecNum(Operations of Access Types)). |
| 959 |
@end{DiffWord83} |
| 960 |
|
| 961 |
@begin{DiffWord95} |
| 962 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0015],ARef=[AI95-00093-01]} |
| 963 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> The wording |
| 964 |
was changed to allow implementations to continue to implement the Ada 83 |
| 965 |
Small attribute. This was always intended to be allowed.]} |
| 966 |
|
| 967 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00235-01]} |
| 968 |
@ChgAdded{Version=[2],Text=[The note about resolving prefixes of attributes |
| 969 |
was updated to reflect that the prefix of an Access attribute now has an |
| 970 |
expected type (see @RefSecNum{Operations of Access Types}).]} |
| 971 |
@end{DiffWord95} |
| 972 |
|
| 973 |
|
| 974 |
@LabeledClause{Literals} |
| 975 |
|
| 976 |
@begin{Intro} |
| 977 |
@Redundant[@Defn{literal} |
| 978 |
A @i(literal) represents a value literally, that is, by means |
| 979 |
of notation suited to its kind.] |
| 980 |
A literal is either a @nt<numeric_literal>, a @nt<character_literal>, |
| 981 |
the literal @key(null), or a @nt<string_literal>. |
| 982 |
@IndexSeeAlso{Term=[constant],See=(literal)} |
| 983 |
@begin(Discussion) |
| 984 |
An enumeration literal that is an @nt<identifier> |
| 985 |
rather than a @nt<character_literal> is not considered a @i(literal) |
| 986 |
in the above sense, because it involves no special notation |
| 987 |
@lquotes@;suited to its kind.@rquotes@; |
| 988 |
It might more properly be called an @ntf<enumeration_identifier>, |
| 989 |
except for historical reasons. |
| 990 |
@end(Discussion) |
| 991 |
@end{Intro} |
| 992 |
|
| 993 |
@begin{Resolution} |
| 994 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]} |
| 995 |
@ChgDeleted{Version=[2],Text=[@PDefn2{Term=[expected type],Sec=(null literal)} |
| 996 |
The expected type for a literal @key(null) shall be a single |
| 997 |
access type.]} |
| 998 |
@begin{Discussion} |
| 999 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 1000 |
@ChgDeleted{Version=[2],Text=[This new wording ("expected type ... shall be a |
| 1001 |
single ... type") replaces the old "shall be determinable" stuff. It reflects |
| 1002 |
an attempt to simplify and unify the description of the rules for resolving |
| 1003 |
aggregates, literals, type conversions, etc. See |
| 1004 |
@RefSec{The Context of Overload Resolution} for the details.]} |
| 1005 |
@end{Discussion} |
| 1006 |
|
| 1007 |
@PDefn2{Term=[expected type],Sec=(character_literal)} |
| 1008 |
@PDefn2{Term=[expected profile],Sec=(character_literal)} |
| 1009 |
For a @nt<name> that consists of a @nt<character_literal>, |
| 1010 |
either its expected type shall be a single character type, in which case |
| 1011 |
it is interpreted as a parameterless @nt<function_call> that yields |
| 1012 |
the corresponding value of the character type, |
| 1013 |
or its expected profile shall correspond to a parameterless |
| 1014 |
function with a character result type, in which case it |
| 1015 |
is interpreted as the name of the corresponding parameterless |
| 1016 |
function declared as part of the character type's definition |
| 1017 |
(see @RefSecNum(Enumeration Types)). |
| 1018 |
In either case, the @nt{character_literal} denotes the |
| 1019 |
@nt{enumeration_literal_specification}. |
| 1020 |
@begin{Discussion} |
| 1021 |
See @RefSecNum(Selected Components) for the resolution rules for a |
| 1022 |
@nt<selector_name> that is a @nt<character_literal>. |
| 1023 |
@end{Discussion} |
| 1024 |
|
| 1025 |
@PDefn2{Term=[expected type],Sec=(string_literal)} |
| 1026 |
The expected type for a @nt{primary} that is a @nt<string_literal> |
| 1027 |
shall be a single string type. |
| 1028 |
@end{Resolution} |
| 1029 |
|
| 1030 |
@begin{Legality} |
| 1031 |
A @nt{character_literal} that is a @nt<name> shall correspond to a |
| 1032 |
@nt<defining_character_literal> of the expected type, or |
| 1033 |
of the result type of the expected profile. |
| 1034 |
|
| 1035 |
For each character of a @nt{string_literal} with a given |
| 1036 |
expected string type, there shall be |
| 1037 |
a corresponding @nt<defining_character_literal> of |
| 1038 |
the component type of the expected string type. |
| 1039 |
|
| 1040 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01],ARef=[AI95-00231-01]} |
| 1041 |
@ChgDeleted{Version=[2],Text=[A literal @s<null>@ChgNote{We use @S since this |
| 1042 |
isn't a non-terminal, and since it is deleted we don't want to fix it.} shall |
| 1043 |
not be of an anonymous |
| 1044 |
access type@Redundant[, since such types do not have a null value |
| 1045 |
(see @RefSecNum{Access Types})].]} |
| 1046 |
@begin{Reason} |
| 1047 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 1048 |
@ChgDeleted{Version=[2],Text=[This is a legality rule rather than an overloading |
| 1049 |
rule, to simplify implementations.]} |
| 1050 |
@end{Reason} |
| 1051 |
@end{Legality} |
| 1052 |
|
| 1053 |
@begin{StaticSem} |
| 1054 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]} |
| 1055 |
An integer literal is of type @i{universal_integer}. |
| 1056 |
A real literal is of type @i{universal_real}.@Chg{Version=[2],New=[ The literal |
| 1057 |
@key<null> is of type @i<universal_access>.],Old=[]} |
| 1058 |
@end{StaticSem} |
| 1059 |
|
| 1060 |
@begin{RunTime} |
| 1061 |
@PDefn2{Term=[evaluation], Sec=(numeric literal)} |
| 1062 |
@PDefn2{Term=[evaluation], Sec=(null literal)} |
| 1063 |
@Defn{null access value} |
| 1064 |
@IndexSee{Term=[null pointer],See=(null access value)} |
| 1065 |
The evaluation of a numeric literal, or the literal @key(null), |
| 1066 |
yields the represented value. |
| 1067 |
|
| 1068 |
@PDefn2{Term=[evaluation], Sec=(string_literal)} |
| 1069 |
The evaluation of a @nt{string_literal} that is a @nt<primary> |
| 1070 |
yields an array value containing the value of each character of the |
| 1071 |
sequence of characters of the @nt<string_literal>, |
| 1072 |
as defined in @RefSecNum{String Literals}. |
| 1073 |
The bounds of this array value are determined according to the rules for |
| 1074 |
@nt<positional_array_aggregate>s (see @RefSecNum{Array Aggregates}), |
| 1075 |
except that for a null string literal, the upper bound is the predecessor |
| 1076 |
of the lower bound. |
| 1077 |
|
| 1078 |
@IndexCheck{Range_Check} |
| 1079 |
For the evaluation of a @nt<string_literal> of type @i(T), |
| 1080 |
a check is made that the value of each |
| 1081 |
character of the @nt<string_literal> belongs to the component |
| 1082 |
subtype of @i(T). |
| 1083 |
For the evaluation of a null string literal, a check is made that its |
| 1084 |
lower bound is greater than the lower bound of the base range |
| 1085 |
of the index type. |
| 1086 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 1087 |
The exception Constraint_Error is raised if either of these checks fails. |
| 1088 |
@begin{Ramification} |
| 1089 |
The checks on the characters need not involve more than two |
| 1090 |
checks altogether, since one need only check the characters |
| 1091 |
of the string with the |
| 1092 |
lowest and highest position numbers against the range of the |
| 1093 |
component subtype. |
| 1094 |
@end{Ramification} |
| 1095 |
@end{RunTime} |
| 1096 |
|
| 1097 |
@begin{Notes} |
| 1098 |
Enumeration literals that are @nt<identifier>s rather than |
| 1099 |
@nt<character_literal>s follow the normal rules for @nt<identifier>s |
| 1100 |
when used in a @nt<name> |
| 1101 |
(see @RefSecNum{Names} and @RefSecNum{Selected Components}). |
| 1102 |
@nt<Character_literal>s used as @nt<selector_name>s follow the normal |
| 1103 |
rules for expanded names (see @RefSecNum{Selected Components}). |
| 1104 |
@end{Notes} |
| 1105 |
|
| 1106 |
@begin{Examples} |
| 1107 |
@Leading@keepnext@i(Examples of literals:) |
| 1108 |
@begin{Example} |
| 1109 |
@tabclear()@tabset(P16) |
| 1110 |
3.14159_26536 @\--@RI[ a real literal] |
| 1111 |
1_345 @\--@RI[ an integer literal] |
| 1112 |
'A' @\--@RI[ a character literal] |
| 1113 |
"Some Text" @\--@RI[ a string literal ] |
| 1114 |
@end{Example} |
| 1115 |
@end{Examples} |
| 1116 |
|
| 1117 |
@begin{Incompatible83} |
| 1118 |
@Defn{incompatibilities with Ada 83} |
| 1119 |
Because @nt<character_literal>s are now treated like |
| 1120 |
other literals, in that they are resolved using context |
| 1121 |
rather than depending on direct visibility, additional |
| 1122 |
qualification might be necessary when passing a @nt<character_literal> |
| 1123 |
to an overloaded subprogram. |
| 1124 |
@end{Incompatible83} |
| 1125 |
|
| 1126 |
@begin{Extend83} |
| 1127 |
@Defn{extensions to Ada 83} |
| 1128 |
@nt<Character_literal>s are now treated |
| 1129 |
analogously to @key(null) and @nt<string_literal>s, in that |
| 1130 |
they are resolved using context, rather than their content; |
| 1131 |
the declaration of the corresponding @nt<defining_character_literal> |
| 1132 |
need not be directly visible. |
| 1133 |
@end{Extend83} |
| 1134 |
|
| 1135 |
@begin{DiffWord83} |
| 1136 |
Name Resolution rules for enumeration literals that are not |
| 1137 |
@nt<character_literal>s are not included anymore, since |
| 1138 |
they are neither syntactically |
| 1139 |
nor semantically "literals" but are rather names of parameterless |
| 1140 |
functions. |
| 1141 |
@end{DiffWord83} |
| 1142 |
|
| 1143 |
@begin{Extend95} |
| 1144 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01]} |
| 1145 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@key{Null} now has |
| 1146 |
type @i<universal_access>, which is similar to other literals. @key{Null} |
| 1147 |
can be used with anonymous access types.]} |
| 1148 |
@end{Extend95} |
| 1149 |
|
| 1150 |
|
| 1151 |
@LabeledClause{Aggregates} |
| 1152 |
|
| 1153 |
@begin{Intro} |
| 1154 |
@Redundant[@Defn{aggregate} |
| 1155 |
An @i(aggregate) combines component values |
| 1156 |
into a composite value of an array type, record type, or record extension.] |
| 1157 |
@IndexSeeAlso{Term={literal},See=(aggregate)} |
| 1158 |
@end{Intro} |
| 1159 |
|
| 1160 |
@begin{Syntax} |
| 1161 |
@Syn{lhs=<aggregate>,rhs="@Syn2{record_aggregate} | @Syn2{extension_aggregate} | @Syn2{array_aggregate}"} |
| 1162 |
@end{Syntax} |
| 1163 |
|
| 1164 |
@begin{Resolution} |
| 1165 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1166 |
@PDefn2{Term=[expected type],Sec=(aggregate)} |
| 1167 |
The expected type for an @nt{aggregate} shall be a |
| 1168 |
single @Chg{Version=[2],New=[],Old=[nonlimited ]}array |
| 1169 |
type, record type, or record extension. |
| 1170 |
@begin{Discussion} |
| 1171 |
See @RefSec{The Context of Overload Resolution} |
| 1172 |
for the meaning of @lquotes@;shall be a single ... type.@rquotes@; |
| 1173 |
@end{Discussion} |
| 1174 |
@end{Resolution} |
| 1175 |
|
| 1176 |
@begin{Legality} |
| 1177 |
An @nt{aggregate} shall not be of a class-wide type. |
| 1178 |
@begin{Ramification} |
| 1179 |
When the |
| 1180 |
expected type in some context is class-wide, an aggregate has to |
| 1181 |
be explicitly qualified by the specific type of value to be created, |
| 1182 |
so that the expected type for the aggregate itself is specific. |
| 1183 |
@end{Ramification} |
| 1184 |
@begin{Discussion} |
| 1185 |
We used to disallow @nt<aggregate>s of a type with unknown |
| 1186 |
discriminants. However, that was unnecessarily restrictive |
| 1187 |
in the case of an extension aggregate, and irrelevant to |
| 1188 |
a record aggregate (since a type that is legal for a record |
| 1189 |
aggregate could not possibly have unknown discriminants) and |
| 1190 |
to an array aggregate (the only specific types that can |
| 1191 |
have unknown discriminants are private types, private extensions, |
| 1192 |
and types derived from them). |
| 1193 |
@end{Discussion} |
| 1194 |
|
| 1195 |
@end{Legality} |
| 1196 |
|
| 1197 |
@begin{RunTime} |
| 1198 |
@PDefn2{Term=[evaluation], Sec=(aggregate)} |
| 1199 |
For the evaluation of an @nt<aggregate>, an anonymous object |
| 1200 |
is created and values for the components or ancestor part |
| 1201 |
are obtained (as described in the subsequent subclause for each |
| 1202 |
kind of the @nt<aggregate>) and assigned into the corresponding |
| 1203 |
components or ancestor part of the anonymous object. |
| 1204 |
@Defn2{Term=[assignment operation], |
| 1205 |
Sec=(during evaluation of an @nt{aggregate})} |
| 1206 |
Obtaining the values and the assignments occur in an |
| 1207 |
arbitrary order. |
| 1208 |
The value of the @nt{aggregate} is the value of this object. |
| 1209 |
@begin{Discussion} |
| 1210 |
The ancestor part is the set of components inherited from the |
| 1211 |
ancestor type. The syntactic category @nt<ancestor_part> is |
| 1212 |
the @nt<expression> or @nt<subtype_mark> that specifies |
| 1213 |
how the ancestor part of the anonymous object should be initialized. |
| 1214 |
@end{Discussion} |
| 1215 |
@begin{Ramification} |
| 1216 |
The assignment operations do the necessary |
| 1217 |
value adjustment, as described in |
| 1218 |
@RefSecNum{User-Defined Assignment and Finalization}. |
| 1219 |
Note that the value as a whole is not adjusted |
| 1220 |
@em just the subcomponents (and ancestor part, if any). |
| 1221 |
@RefSecNum{User-Defined Assignment and Finalization} also describes |
| 1222 |
when this anonymous object is finalized. |
| 1223 |
|
| 1224 |
If the @nt<ancestor_part> is a @nt<subtype_mark> |
| 1225 |
the Initialize procedure for the ancestor type is applied |
| 1226 |
to the ancestor part after default-initializing it, |
| 1227 |
unless the procedure is abstract, as described |
| 1228 |
in @RefSecNum{User-Defined Assignment and Finalization}. |
| 1229 |
The Adjust procedure for the ancestor type is not called |
| 1230 |
in this case, since there is no assignment to the ancestor |
| 1231 |
part as a whole. |
| 1232 |
@end{Ramification} |
| 1233 |
|
| 1234 |
@IndexCheck{Discriminant_Check} |
| 1235 |
If an @nt{aggregate} is of a tagged type, a check is made that |
| 1236 |
its value belongs to the first subtype of the type. |
| 1237 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 1238 |
Constraint_Error is raised if this check fails. |
| 1239 |
@begin{Ramification} |
| 1240 |
This check ensures that no values of a tagged type are |
| 1241 |
ever outside the first subtype, as required |
| 1242 |
for inherited dispatching operations to work properly |
| 1243 |
(see @RefSecNum(Derived Types and Classes)). This check will always |
| 1244 |
succeed if the first subtype is unconstrained. |
| 1245 |
This check is not extended to untagged types |
| 1246 |
to preserve upward compatibility. |
| 1247 |
@end{Ramification} |
| 1248 |
@end{RunTime} |
| 1249 |
|
| 1250 |
@begin{Extend83} |
| 1251 |
@Defn{extensions to Ada 83} |
| 1252 |
We now allow @nt{extension_aggregate}s. |
| 1253 |
@end{Extend83} |
| 1254 |
|
| 1255 |
@begin{DiffWord83} |
| 1256 |
We have adopted new wording |
| 1257 |
for expressing the |
| 1258 |
rule that the type of an aggregate shall be determinable |
| 1259 |
from the outside, though using the fact that |
| 1260 |
it is nonlimited record (extension) or array. |
| 1261 |
|
| 1262 |
An @nt{aggregate} now creates an anonymous object. |
| 1263 |
This is necessary so that controlled types |
| 1264 |
will work (see @RefSecNum{User-Defined Assignment and Finalization}). |
| 1265 |
@end{DiffWord83} |
| 1266 |
|
| 1267 |
@begin{Incompatible95} |
| 1268 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 1269 |
@ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95} |
| 1270 |
In Ada 95, a limited type is not considered when resolving an @nt{aggregate}. |
| 1271 |
Since Ada 2005 now allows limited @nt{aggregate}s, we can have |
| 1272 |
incompatibilities. For example:]} |
| 1273 |
@begin{Example} |
| 1274 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1275 |
@Chg{Version=[2],New=[@key{type} Lim @key{is} @key{limited} |
| 1276 |
@key{record} |
| 1277 |
Comp: Integer; |
| 1278 |
@key{end} @key{record};],Old=[]} |
| 1279 |
|
| 1280 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1281 |
@Chg{Version=[2],New=[@key{type} Not_Lim @key{is} |
| 1282 |
@key{record} |
| 1283 |
Comp: Integer; |
| 1284 |
@key{end} @key{record};],Old=[]} |
| 1285 |
|
| 1286 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1287 |
@Chg{Version=[2],New=[@key{procedure} P(X: Lim); |
| 1288 |
@key{procedure} P(X: Not_Lim);],Old=[]} |
| 1289 |
|
| 1290 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1291 |
@ChgAdded{Version=[2],Text=[P((Comp => 123)); -- @RI[Illegal in Ada 2005, legal in Ada 95]]} |
| 1292 |
@end{Example} |
| 1293 |
|
| 1294 |
@ChgRef{Version=[2],Kind=[AddedNormal]} @ChgAdded{Version=[2],Text=[The call |
| 1295 |
to P is ambiguous in Ada 2005, while it would not be ambiguous in Ada 95 as |
| 1296 |
the @nt{aggregate} could not have a limited type. Qualifying the |
| 1297 |
@nt{aggregate} will eliminate any ambiguity. This construction would be |
| 1298 |
rather confusing to a maintenance programmer, so it should be avoided, and |
| 1299 |
thus we expect it to be rare.]} |
| 1300 |
@end{Incompatible95} |
| 1301 |
|
| 1302 |
@begin{Extend95} |
| 1303 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 1304 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}@nt{Aggregate}s can |
| 1305 |
be of a limited type.]} |
| 1306 |
@end{Extend95} |
| 1307 |
|
| 1308 |
|
| 1309 |
@LabeledSubClause{Record Aggregates} |
| 1310 |
|
| 1311 |
@begin{Intro} |
| 1312 |
@Redundant[In a @nt<record_aggregate>, a value is specified for |
| 1313 |
each component of the record or record extension value, |
| 1314 |
using either a named or a positional association.] |
| 1315 |
@end{Intro} |
| 1316 |
|
| 1317 |
@begin{Syntax} |
| 1318 |
@Syn{lhs=<record_aggregate>,rhs="(@Syn2{record_component_association_list})"} |
| 1319 |
|
| 1320 |
@Syn{lhs=<record_component_association_list>,rhs=" |
| 1321 |
@Syn2{record_component_association} {, @Syn2{record_component_association}} |
| 1322 |
| @key<null record>"} |
| 1323 |
|
| 1324 |
|
| 1325 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1326 |
@Syn{lhs=<record_component_association>,rhs=" |
| 1327 |
[@Syn2{component_choice_list} =>] @Syn2{expression}@Chg{Version=[2],New=[ |
| 1328 |
| @Syn2{component_choice_list} => <>],Old=[]}"} |
| 1329 |
|
| 1330 |
@Syn{lhs=<component_choice_list>,rhs=" |
| 1331 |
@SynI{component_}@Syn2{selector_name} {| @SynI{component_}@Syn2{selector_name}} |
| 1332 |
| @key{others}"} |
| 1333 |
|
| 1334 |
@begin(SyntaxText) |
| 1335 |
@Defn{named component association} |
| 1336 |
A @nt<record_@!component_@!association> is a @i(named component association) |
| 1337 |
if it has a @nt<component_choice_list>; |
| 1338 |
@Defn{positional component association} |
| 1339 |
otherwise, it is a @i(positional component association). |
| 1340 |
Any positional component associations shall precede any |
| 1341 |
named component associations. |
| 1342 |
If there is a named association with a @nt<component_choice_list> |
| 1343 |
of @key(others), it shall come last. |
| 1344 |
@begin{Discussion} |
| 1345 |
These rules were |
| 1346 |
implied by the BNF in an early version of the RM9X, but it |
| 1347 |
made the grammar harder to read, and was inconsistent |
| 1348 |
with how we handle discriminant constraints. |
| 1349 |
Note that for array aggregates we still express |
| 1350 |
some of the rules in the grammar, but array aggregates |
| 1351 |
are significantly different because an array aggregate |
| 1352 |
is either all positional (with a possible @key(others) at the |
| 1353 |
end), or all named. |
| 1354 |
@end{Discussion} |
| 1355 |
|
| 1356 |
In the @nt<record_@!component_@!association_@!list> for a @nt<record_@!aggregate>, |
| 1357 |
if there is only one association, it shall be a named association. |
| 1358 |
@begin{Reason} |
| 1359 |
Otherwise the construct would be interpreted as a parenthesized |
| 1360 |
expression. |
| 1361 |
This is considered a syntax rule, since it is relevant to |
| 1362 |
overload resolution. We choose not to express it with BNF so we |
| 1363 |
can share the definition of @nt<record_component_association_list> |
| 1364 |
in both @nt<record_aggregate> and @nt<extension_aggregate>. |
| 1365 |
@end{Reason} |
| 1366 |
@begin{Ramification} |
| 1367 |
The @nt<record_component_association_list> of an @nt<extension_aggregate> |
| 1368 |
does not have such a restriction. |
| 1369 |
@end{Ramification} |
| 1370 |
@end(SyntaxText) |
| 1371 |
@end{Syntax} |
| 1372 |
|
| 1373 |
@begin{Resolution} |
| 1374 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1375 |
@PDefn2{Term=[expected type],Sec=(record_aggregate)} |
| 1376 |
The expected type for a @nt{record_aggregate} shall be |
| 1377 |
a single @Chg{Version=[2],New=[],Old=[nonlimited ]}record |
| 1378 |
type or record extension. |
| 1379 |
@begin{Ramification} |
| 1380 |
This rule is used to resolve whether an @nt{aggregate} is |
| 1381 |
an @nt{array_aggregate} or a @nt{record_aggregate}. |
| 1382 |
The presence of a @key(with) is used to resolve between |
| 1383 |
a @nt{record_aggregate} and an @nt{extension_aggregate}. |
| 1384 |
@end{Ramification} |
| 1385 |
|
| 1386 |
@Defn2{Term=[needed component], |
| 1387 |
Sec=(@nt<record_aggregate> @nt<record_component_association_list>)} |
| 1388 |
For the @nt<record_@!component_@!association_@!list> |
| 1389 |
of a @nt<record_@!aggregate>, |
| 1390 |
all components of the composite value defined by |
| 1391 |
the aggregate are @i(needed)@Redundant[; for the association list of |
| 1392 |
an @nt<extension_aggregate>, |
| 1393 |
only those components not determined by the ancestor expression or |
| 1394 |
subtype are needed |
| 1395 |
(see @RefSecNum{Extension Aggregates}).] |
| 1396 |
Each @nt{selector_@!name} in a @nt{record_@!component_@!association} shall denote |
| 1397 |
a needed component @Redundant[(including possibly a discriminant)]. |
| 1398 |
@begin{Ramification} |
| 1399 |
For the association list of a @nt{record_aggregate}, |
| 1400 |
@lquotes@;needed components@rquotes@; includes every component of the composite value, but |
| 1401 |
does not include those in unchosen @nt{variant}s (see AI83-309). |
| 1402 |
If there are @nt<variant>s, then |
| 1403 |
the value specified for |
| 1404 |
the discriminant that governs them |
| 1405 |
determines which @nt<variant> is chosen, and hence which components |
| 1406 |
are needed. |
| 1407 |
|
| 1408 |
If an extension defines a new @nt{known_discriminant_part}, then all of |
| 1409 |
its discriminants are needed in the component association list of |
| 1410 |
an extension |
| 1411 |
aggregate for that type, even if the discriminants have the same |
| 1412 |
names and types as discriminants of the type of the ancestor |
| 1413 |
expression. |
| 1414 |
This is necessary to ensure that the positions in |
| 1415 |
the @nt<record_@!component_@!association_@!list> |
| 1416 |
are well defined, and that discriminants that govern @nt{variant_part}s |
| 1417 |
can be given by static expressions. |
| 1418 |
@end{Ramification} |
| 1419 |
|
| 1420 |
@Leading@Keepnext@PDefn2{Term=[expected type], |
| 1421 |
Sec=(record_component_association expression)} |
| 1422 |
The expected type for the @nt<expression> of a |
| 1423 |
@nt<record_@!component_@!association> is the type |
| 1424 |
of the @i(associated) component(s); |
| 1425 |
@Defn2{Term=[associated components], |
| 1426 |
Sec=(of a @nt<record_component_association>)} |
| 1427 |
the associated component(s) are as follows: |
| 1428 |
@begin(itemize) |
| 1429 |
For a positional association, |
| 1430 |
the component @Redundant[(including possibly a discriminant)] |
| 1431 |
in the corresponding relative position (in the declarative region of |
| 1432 |
the type), counting only the |
| 1433 |
needed components; |
| 1434 |
@begin{Ramification} |
| 1435 |
This means that for |
| 1436 |
an association list of an @nt<extension_aggregate>, |
| 1437 |
only noninherited components are counted to determine |
| 1438 |
the position. |
| 1439 |
@end{Ramification} |
| 1440 |
|
| 1441 |
For a named association with one or more |
| 1442 |
@i(component_)@nt<selector_name>s, |
| 1443 |
the named component(s); |
| 1444 |
|
| 1445 |
For a named association with the reserved word @key(others), |
| 1446 |
all needed components |
| 1447 |
that are not associated with some previous association. |
| 1448 |
@end(itemize) |
| 1449 |
@end{Resolution} |
| 1450 |
|
| 1451 |
@begin{Legality} |
| 1452 |
|
| 1453 |
If the type of a @nt{record_aggregate} is a record extension, |
| 1454 |
then it shall be a descendant of a record type, through one |
| 1455 |
or more record extensions (and no private extensions). |
| 1456 |
|
| 1457 |
If there are no components needed in a given |
| 1458 |
@nt<record_@!component_@!association_@!list>, |
| 1459 |
then the reserved words @key(null record) shall appear rather |
| 1460 |
than a list of @nt<record_@!component_@!association>s. |
| 1461 |
@begin{Ramification} |
| 1462 |
For example, "(@key(null record))" is a @nt<record_aggregate> |
| 1463 |
for a null record type. Similarly, "(T'(A) @key(with null record))" is |
| 1464 |
an @nt<extension_aggregate> for a type defined as a null |
| 1465 |
record extension of T. |
| 1466 |
@end{Ramification} |
| 1467 |
|
| 1468 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1469 |
Each @nt<record_component_association>@Chg{Version=[2],New=[ other than an |
| 1470 |
@key{others} choice with a <>],Old=[]} shall have at least |
| 1471 |
one associated component, and each needed component |
| 1472 |
shall be associated with exactly |
| 1473 |
one @nt<record_@!component_@!association>. |
| 1474 |
If a @nt<record_@!component_@!association> @Chg{Version=[2],New=[with an |
| 1475 |
@nt{expression} ],Old=[]}has two or more associated components, all of them |
| 1476 |
shall be of the same type. |
| 1477 |
@begin{Ramification} |
| 1478 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1479 |
These rules apply to an association with an @key(others) |
| 1480 |
choice@Chg{Version=[2],New=[ with an expression. An @key(others) choice with |
| 1481 |
a <> can match zero components or several components with different |
| 1482 |
types.],Old=[]}. |
| 1483 |
@end{Ramification} |
| 1484 |
@begin{Reason} |
| 1485 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1486 |
Without these rules, there would be no way to know what |
| 1487 |
was the expected type for the @nt<expression> of the association. |
| 1488 |
@Chg{Version=[2],New=[Note that some of the rules do not apply to <> |
| 1489 |
associations, as we do not need to resolve anything. We allow @key{others} |
| 1490 |
=> <> to match no components as this is similar to array aggregates. |
| 1491 |
That means that (@key{others} => <>) always represents a default-initialized |
| 1492 |
record or array value.],Old=[]} |
| 1493 |
@end{Reason} |
| 1494 |
@begin{Discussion} |
| 1495 |
AI83-00244 also requires that the @nt{expression} shall |
| 1496 |
be legal for each associated component. This is because |
| 1497 |
even though two components have the same type, they might have |
| 1498 |
different subtypes. Therefore, the legality of the |
| 1499 |
@nt<expression>, particularly if it is an array aggregate, |
| 1500 |
might differ depending on the associated component's subtype. |
| 1501 |
However, we have relaxed the rules on array aggregates slightly for Ada 95, |
| 1502 |
so the staticness of an applicable index constraint has no |
| 1503 |
effect on the legality of the array aggregate to which it applies. |
| 1504 |
See @RefSecNum{Array Aggregates}. This was the only case (that we know of) |
| 1505 |
where a subtype provided by context affected the legality |
| 1506 |
of an @nt{expression}. |
| 1507 |
@end{Discussion} |
| 1508 |
@begin{Ramification} |
| 1509 |
The rule that requires at least one associated component for |
| 1510 |
each @nt<record_component_association> |
| 1511 |
implies that there can be no extra associations for |
| 1512 |
components that don't exist in the composite value, or that |
| 1513 |
are already determined by the ancestor expression or subtype of |
| 1514 |
an @nt<extension_aggregate>. |
| 1515 |
|
| 1516 |
The second part of the first sentence ensures that no |
| 1517 |
needed components are left out, |
| 1518 |
nor specified twice. |
| 1519 |
@end{Ramification} |
| 1520 |
|
| 1521 |
If the components of a @nt{variant_part} are needed, then the value |
| 1522 |
of a discriminant that governs the @nt{variant_part} shall be given |
| 1523 |
by a static expression. |
| 1524 |
@begin{Ramification} |
| 1525 |
This expression might either be given within the aggregate itself, |
| 1526 |
or in a constraint on the parent subtype in a @nt<derived_type_definition> |
| 1527 |
for some ancestor of the type of the aggregate. |
| 1528 |
@end{Ramification} |
| 1529 |
|
| 1530 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]} |
| 1531 |
@ChgAdded{Version=[2],Text=[A @nt<record_component_association> for a discriminant |
| 1532 |
without a @nt<default_expression> shall have an @nt<expression> rather |
| 1533 |
than <>.]} |
| 1534 |
@begin{Reason} |
| 1535 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1536 |
@ChgAdded{Version=[2],Text=[A discriminant must always have a defined value, |
| 1537 |
but <> means uninitialized for a discrete type unless the component has a |
| 1538 |
default value.]} |
| 1539 |
@end{Reason} |
| 1540 |
|
| 1541 |
@end{Legality} |
| 1542 |
|
| 1543 |
@begin{RunTime} |
| 1544 |
@PDefn2{Term=[evaluation], Sec=(record_aggregate)} |
| 1545 |
The evaluation of a @nt<record_aggregate> consists of the |
| 1546 |
evaluation of the @nt<record_@!component_@!association_@!list>. |
| 1547 |
|
| 1548 |
@PDefn2{Term=[evaluation], Sec=(record_component_association_list)} |
| 1549 |
For the evaluation of a @nt{record_@!component_@!association_@!list}, |
| 1550 |
any per-object constraints (see @RefSecNum(Record Types)) |
| 1551 |
for components specified in the association list are elaborated and |
| 1552 |
any @nt<expression>s are evaluated and converted to the subtype of the |
| 1553 |
associated component. |
| 1554 |
@PDefn2{Term=[implicit subtype conversion],Sec=(expressions in aggregate)} |
| 1555 |
Any constraint elaborations and @nt{expression} evaluations (and conversions) |
| 1556 |
occur in an arbitrary order, except that the @nt<expression> |
| 1557 |
for a discriminant is evaluated (and converted) prior to the |
| 1558 |
elaboration of any per-object constraint that depends on it, which in |
| 1559 |
turn occurs prior to the evaluation and conversion of the @nt{expression} for |
| 1560 |
the component with the per-object constraint. |
| 1561 |
@begin{Ramification} |
| 1562 |
The conversion in the first rule might raise Constraint_Error. |
| 1563 |
@end{Ramification} |
| 1564 |
@begin{Discussion} |
| 1565 |
This check in the first rule presumably happened as part of the dependent |
| 1566 |
compatibility check in Ada 83. |
| 1567 |
@end{Discussion} |
| 1568 |
|
| 1569 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]} |
| 1570 |
@ChgAdded{Version=[2],Text=[For a @nt<record_component_association> with an |
| 1571 |
@nt<expression>, the @nt<expression> defines the value for the associated |
| 1572 |
component(s). For a @nt<record_component_association> with <>, if the |
| 1573 |
@nt<component_declaration> has a @nt<default_expression>, that |
| 1574 |
@nt<default_expression> defines the value for the associated component(s); |
| 1575 |
otherwise, the associated component(s) are initialized by default as for a |
| 1576 |
stand-alone object of the component subtype |
| 1577 |
(see @RefSecNum{Object Declarations}).]} |
| 1578 |
|
| 1579 |
The @nt<expression> of a @nt{record_component_association} |
| 1580 |
is evaluated (and converted) once for each associated component. |
| 1581 |
|
| 1582 |
@end{RunTime} |
| 1583 |
|
| 1584 |
@begin{Notes} |
| 1585 |
For a @nt<record_aggregate> with positional associations, expressions |
| 1586 |
specifying discriminant |
| 1587 |
values appear first since the @nt<known_discriminant_part> |
| 1588 |
is given first in the declaration of the type; they have to |
| 1589 |
be in the same order as in the @nt<known_discriminant_part>. |
| 1590 |
@end{Notes} |
| 1591 |
|
| 1592 |
@begin{Examples} |
| 1593 |
@Leading@keepnext@i(Example of a record aggregate with positional associations:) |
| 1594 |
@begin{Example} |
| 1595 |
(4, July, 1776) --@RI[ see @RefSecNum{Record Types} ] |
| 1596 |
@end{Example} |
| 1597 |
|
| 1598 |
@begin{Wide} |
| 1599 |
@leading@keepnext@i(Examples of record aggregates with named associations:) |
| 1600 |
@end{Wide} |
| 1601 |
@begin{Example} |
| 1602 |
(Day => 4, Month => July, Year => 1776) |
| 1603 |
(Month => July, Day => 4, Year => 1776) |
| 1604 |
|
| 1605 |
(Disk, Closed, Track => 5, Cylinder => 12) --@RI[ see @RefSecNum{Variant Parts and Discrete Choices}] |
| 1606 |
(Unit => Disk, Status => Closed, Cylinder => 9, Track => 1) |
| 1607 |
@end{Example} |
| 1608 |
|
| 1609 |
@begin{Wide} |
| 1610 |
@leading@keepnext@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1611 |
@i(@Chg{Version=[2],New=[Examples],Old=[Example]} of component |
| 1612 |
@Chg{Version=[2],New=[associations],Old=[association]} with |
| 1613 |
several choices:) |
| 1614 |
@end{Wide} |
| 1615 |
@begin{Example} |
| 1616 |
@tabclear()@tabset(P50) |
| 1617 |
(Value => 0, Succ|Pred => @key(new) Cell'(0, @key(null), @key(null))) @\--@RI[ see @RefSecNum{Incomplete Type Declarations}] |
| 1618 |
|
| 1619 |
--@RI[ The allocator is evaluated twice: Succ and Pred designate different cells] |
| 1620 |
|
| 1621 |
@ChgRef{Version=[2],Kind=[Added]} |
| 1622 |
@Chg{Version=[2],New=[(Value => 0, Succ|Pred => <>) @\--@RI[ see @RefSecNum{Incomplete Type Declarations}]],Old=[]} |
| 1623 |
|
| 1624 |
@ChgRef{Version=[2],Kind=[Added]} |
| 1625 |
@Chg{Version=[2],New=[ --@RI[ Succ and Pred will be set to @key{null}]],Old=[]} |
| 1626 |
|
| 1627 |
@end{Example} |
| 1628 |
|
| 1629 |
@begin{Wide} |
| 1630 |
@leading@keepnext@i{Examples of record aggregates for tagged types |
| 1631 |
(see @RefSecNum(Tagged Types and Type Extensions) |
| 1632 |
and @RefSecNum{Type Extensions}):} |
| 1633 |
@end{Wide} |
| 1634 |
@begin{Example} |
| 1635 |
Expression'(@key{null record}) |
| 1636 |
Literal'(Value => 0.0) |
| 1637 |
Painted_Point'(0.0, Pi/2.0, Paint => Red) |
| 1638 |
@end{Example} |
| 1639 |
|
| 1640 |
@end{Examples} |
| 1641 |
|
| 1642 |
@begin{Extend83} |
| 1643 |
@Defn{extensions to Ada 83} |
| 1644 |
Null record aggregates may now be specified, via "(@key(null record))". |
| 1645 |
However, this syntax is more useful for null record extensions in |
| 1646 |
extension aggregates. |
| 1647 |
@end{Extend83} |
| 1648 |
|
| 1649 |
@begin{DiffWord83} |
| 1650 |
Various AIs have been incorporated (AI83-00189, AI83-00244, and AI83-00309). |
| 1651 |
In particular, Ada 83 did not explicitly disallow extra values in |
| 1652 |
a record aggregate. Now we do. |
| 1653 |
@end{DiffWord83} |
| 1654 |
|
| 1655 |
@begin{Extend95} |
| 1656 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 1657 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}<> can be used in |
| 1658 |
place of an @nt{expression} in a @nt{record_aggregate}, default |
| 1659 |
initializing the component.]} |
| 1660 |
@end{Extend95} |
| 1661 |
|
| 1662 |
@begin{DiffWord95} |
| 1663 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 1664 |
@ChgAdded{Version=[2],Text=[Limited @nt{record_aggregate}s are allowed (since |
| 1665 |
all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]} |
| 1666 |
@end{DiffWord95} |
| 1667 |
|
| 1668 |
|
| 1669 |
@RmNewPage |
| 1670 |
@LabeledSubClause{Extension Aggregates} |
| 1671 |
|
| 1672 |
@begin{Intro} |
| 1673 |
@Redundant[An @nt<extension_aggregate> specifies a value |
| 1674 |
for a type that is a record extension by specifying a value |
| 1675 |
or subtype |
| 1676 |
for an ancestor of the type, |
| 1677 |
followed by associations for |
| 1678 |
any components not determined by the @nt<ancestor_part>.] |
| 1679 |
@end{Intro} |
| 1680 |
|
| 1681 |
@begin{MetaRules} |
| 1682 |
The model underlying this syntax is that a record extension |
| 1683 |
can also be viewed as a regular record type with an ancestor "prefix." |
| 1684 |
The @nt<record_@!component_@!association_@!list> corresponds to |
| 1685 |
exactly what would be needed |
| 1686 |
if there were no ancestor/prefix type. |
| 1687 |
The @nt{ancestor_part} |
| 1688 |
determines the value of the ancestor/prefix. |
| 1689 |
@end{MetaRules} |
| 1690 |
|
| 1691 |
@begin{Syntax} |
| 1692 |
@Syn{lhs=<extension_aggregate>,rhs=" |
| 1693 |
(@Syn2{ancestor_part} @key(with) @Syn2{record_component_association_list})"} |
| 1694 |
|
| 1695 |
@Syn{lhs=<ancestor_part>, |
| 1696 |
rhs="@Syn2{expression} | @Syn2{subtype_mark}"} |
| 1697 |
@end{Syntax} |
| 1698 |
|
| 1699 |
@begin{Resolution} |
| 1700 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1701 |
@PDefn2{Term=[expected type], Sec=(extension_aggregate)} |
| 1702 |
The expected type for an @nt{extension_aggregate} shall be |
| 1703 |
a single @Chg{Version=[2],New=[],Old=[nonlimited ]}type that is a |
| 1704 |
record extension. |
| 1705 |
@PDefn2{Term=[expected type], |
| 1706 |
Sec=(extension_aggregate ancestor expression)} |
| 1707 |
If the @nt<ancestor_part> is an @nt<expression>, |
| 1708 |
it is expected to be of any @Chg{Version=[2],New=[],Old=[nonlimited ]}tagged |
| 1709 |
type. |
| 1710 |
@begin{Reason} |
| 1711 |
We could have made |
| 1712 |
the expected type @i(T')Class where @i(T) is the ultimate ancestor of |
| 1713 |
the type of the aggregate, or we could have made it even more |
| 1714 |
specific than that. However, if the overload resolution rules |
| 1715 |
get too complicated, the implementation gets more difficult and |
| 1716 |
it becomes harder to produce good error messages. |
| 1717 |
@end{Reason} |
| 1718 |
@end{Resolution} |
| 1719 |
|
| 1720 |
@begin{Legality} |
| 1721 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00306-01]} |
| 1722 |
If the @nt<ancestor_part> is a @nt<subtype_mark>, it shall |
| 1723 |
denote a specific tagged subtype. |
| 1724 |
@Chg{Version=[2],New=[If the @nt{ancestor_part} is an @nt{expression}, it |
| 1725 |
shall not be dynamically tagged. ],Old=[]} |
| 1726 |
The type of the @nt{extension_aggregate} shall be derived from the type of the |
| 1727 |
@nt<ancestor_part>, through one |
| 1728 |
or more record extensions (and no private extensions). |
| 1729 |
@begin{Reason} |
| 1730 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00306-01]} |
| 1731 |
@ChgAdded{Version=[2],Text=[The expression cannot be dynamically tagged to |
| 1732 |
prevent implicit "truncation" of a dynamically-tagged value to the specific |
| 1733 |
ancestor type. This is similar to the |
| 1734 |
rules in @RefSecNum{Dispatching Operations of Tagged Types}.]} |
| 1735 |
@end{Reason} |
| 1736 |
@end{Legality} |
| 1737 |
|
| 1738 |
@begin{StaticSem} |
| 1739 |
@Defn2{Term=[needed component], |
| 1740 |
Sec=(@nt<extension_aggregate> @nt<record_component_association_list>)} |
| 1741 |
For the @nt{record_@!component_@!association_@!list} |
| 1742 |
of an @nt{extension_@!aggregate}, |
| 1743 |
the only components @i(needed) are those of the composite value defined |
| 1744 |
by the aggregate that are not inherited from the type of |
| 1745 |
the @nt<ancestor_@!part>, plus any inherited discriminants |
| 1746 |
if the @nt<ancestor_@!part> is a @nt<subtype_@!mark> that |
| 1747 |
denotes an unconstrained subtype. |
| 1748 |
@end{StaticSem} |
| 1749 |
|
| 1750 |
@begin{RunTime} |
| 1751 |
@PDefn2{Term=[evaluation], Sec=(extension_aggregate)} |
| 1752 |
For the evaluation of an @nt{extension_aggregate}, |
| 1753 |
the @nt{record_@!component_@!association_@!list} is evaluated. |
| 1754 |
If the @nt<ancestor_part> is an @nt<expression>, it is also evaluated; |
| 1755 |
if the @nt<ancestor_part> is a @nt<subtype_mark>, |
| 1756 |
the components of the value of the aggregate not given by the |
| 1757 |
@nt<record_@!component_@!association_@!list> are initialized by default |
| 1758 |
as for an object of the ancestor type. |
| 1759 |
Any implicit initializations or evaluations are performed |
| 1760 |
in an arbitrary order, except that the @nt<expression> |
| 1761 |
for a discriminant is evaluated prior to any other evaluation |
| 1762 |
or initialization that depends on it. |
| 1763 |
|
| 1764 |
@IndexCheck{Discriminant_Check} |
| 1765 |
If the type of the @nt<ancestor_part> has |
| 1766 |
discriminants that are not inherited by the |
| 1767 |
type of the @nt{extension_aggregate}, |
| 1768 |
then, unless the @nt<ancestor_part> is a @nt<subtype_mark> that |
| 1769 |
denotes an unconstrained subtype, |
| 1770 |
a check is made that each discriminant of the ancestor |
| 1771 |
has the value specified for a corresponding discriminant, |
| 1772 |
either in the @nt{record_@!component_@!association_@!list}, or in |
| 1773 |
the @nt<derived_type_definition> for some ancestor of the type of |
| 1774 |
the @nt{extension_aggregate}. |
| 1775 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 1776 |
Constraint_Error is raised if this check fails. |
| 1777 |
@begin{Ramification} |
| 1778 |
Corresponding and specified |
| 1779 |
discriminants are defined in @RefSecNum{Discriminants}. |
| 1780 |
The rules requiring static compatibility between |
| 1781 |
new discriminants of a derived type |
| 1782 |
and the parent discriminant(s) they constrain |
| 1783 |
ensure that at most one check is required per discriminant |
| 1784 |
of the ancestor expression. |
| 1785 |
@end{Ramification} |
| 1786 |
@end{RunTime} |
| 1787 |
|
| 1788 |
@begin{Notes} |
| 1789 |
If all components of the value of the @nt<extension_aggregate> |
| 1790 |
are determined by the @nt<ancestor_part>, then |
| 1791 |
the @nt<record_@!component_@!association_@!list> is required to be |
| 1792 |
simply @key(null record). |
| 1793 |
|
| 1794 |
If the @nt<ancestor_part> is a @nt<subtype_mark>, |
| 1795 |
then its type can be abstract. If its type is controlled, |
| 1796 |
then as the last step of evaluating the aggregate, |
| 1797 |
the Initialize procedure of the ancestor type is called, |
| 1798 |
unless the Initialize procedure is abstract |
| 1799 |
(see @RefSecNum{User-Defined Assignment and Finalization}). |
| 1800 |
@end{Notes} |
| 1801 |
|
| 1802 |
@begin{Examples} |
| 1803 |
@Leading@keepnext@i{Examples of extension aggregates (for types defined in @RefSecNum{Type Extensions}):} |
| 1804 |
@begin(example) |
| 1805 |
Painted_Point'(Point @key{with} Red) |
| 1806 |
(Point'(P) @key{with} Paint => Black) |
| 1807 |
|
| 1808 |
(Expression @key{with} Left => 1.2, Right => 3.4) |
| 1809 |
Addition'(Binop @key{with null record}) |
| 1810 |
--@RI[ presuming Binop is of type Binary_Operation] |
| 1811 |
@end(example) |
| 1812 |
|
| 1813 |
@end{Examples} |
| 1814 |
|
| 1815 |
@begin{Extend83} |
| 1816 |
@Defn{extensions to Ada 83} |
| 1817 |
The extension aggregate syntax is new. |
| 1818 |
@end{Extend83} |
| 1819 |
|
| 1820 |
@begin{Incompatible95} |
| 1821 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00306-01]} |
| 1822 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} |
| 1823 |
@b[Amendment Correction:] Eliminated implicit @lquotes@;truncation@rquotes |
| 1824 |
of a dynamically tagged value when it is used as an ancestor |
| 1825 |
@nt{expression}. If an @nt{aggregate} includes such an @nt{expression}, |
| 1826 |
it is illegal in Ada 2005. Such @nt{aggregate}s are thought to be rare; |
| 1827 |
the problem can be fixed with a type conversion to the appropriate |
| 1828 |
specific type if it occurs.]} |
| 1829 |
@end{Incompatible95} |
| 1830 |
|
| 1831 |
@begin{DiffWord95} |
| 1832 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 1833 |
@ChgAdded{Version=[2],Text=[Limited @nt{extension_aggregate}s are allowed (since |
| 1834 |
all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]} |
| 1835 |
@end{DiffWord95} |
| 1836 |
|
| 1837 |
|
| 1838 |
@LabeledSubClause{Array Aggregates} |
| 1839 |
|
| 1840 |
@begin{Intro} |
| 1841 |
|
| 1842 |
@Redundant[In an @nt<array_aggregate>, a value is specified |
| 1843 |
for each component of an array, either positionally or by |
| 1844 |
its index.] |
| 1845 |
For a @nt{positional_array_aggregate}, |
| 1846 |
the components are given in increasing-index order, |
| 1847 |
with a final @key[others], if any, |
| 1848 |
representing any remaining components. |
| 1849 |
For a @nt{named_array_aggregate}, |
| 1850 |
the components are identified by the values covered by the |
| 1851 |
@nt{discrete_choice}s. |
| 1852 |
|
| 1853 |
@end{Intro} |
| 1854 |
|
| 1855 |
@begin{MetaRules} |
| 1856 |
@ChgRef{Version=[1],Kind=[Revised]} |
| 1857 |
The rules in this subclause are based on |
| 1858 |
terms and rules for @nt{discrete_choice_list}s |
| 1859 |
defined in @RefSec{Variant Parts and Discrete Choices}. |
| 1860 |
@Chg{New=[For example, the requirements that @key(others) come last and stand |
| 1861 |
alone are found there.],Old=[]}@Comment{This question is asked periodically, so |
| 1862 |
we answer it explicitly.} |
| 1863 |
@end{MetaRules} |
| 1864 |
|
| 1865 |
@begin{Syntax} |
| 1866 |
@Syn{lhs=<array_aggregate>,rhs=" |
| 1867 |
@Syn2{positional_array_aggregate} | @Syn2{named_array_aggregate}"} |
| 1868 |
|
| 1869 |
|
| 1870 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1871 |
@Syn{lhs=<positional_array_aggregate>,rhs=" |
| 1872 |
(@Syn2{expression}, @Syn2{expression} {, @Syn2{expression}}) |
| 1873 |
| (@Syn2{expression} {, @Syn2{expression}}, @key(others) => @Syn2{expression})@Chg{Version=[2],New=[ |
| 1874 |
| (@Syn2{expression} {, @Syn2{expression}}, @key(others) => <>)],Old=[]}"} |
| 1875 |
|
| 1876 |
|
| 1877 |
@Syn{lhs=<named_array_aggregate>,rhs=" |
| 1878 |
(@Syn2{array_component_association} {, @Syn2{array_component_association}})"} |
| 1879 |
|
| 1880 |
|
| 1881 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1882 |
@Syn{lhs=<array_component_association>,rhs=" |
| 1883 |
@Syn2{discrete_choice_list} => @Syn2{expression}@Chg{Version=[2],New=[ |
| 1884 |
| @Syn2{discrete_choice_list} => <>],Old=[]}"} |
| 1885 |
|
| 1886 |
@end{Syntax} |
| 1887 |
|
| 1888 |
@begin{Intro} |
| 1889 |
@Defn{n-dimensional @nt<array_aggregate>} |
| 1890 |
An @i(n-dimensional) @nt<array_aggregate> is one that is written as |
| 1891 |
n levels of nested @nt{array_aggregate}s (or at the bottom level, |
| 1892 |
equivalent @nt{string_literal}s). |
| 1893 |
@Defn2{Term=[subaggregate], Sec=(of an @nt{array_aggregate})} |
| 1894 |
For the multidimensional case (n >= 2) the @nt<array_aggregate>s |
| 1895 |
(or equivalent @nt<string_literal>s) |
| 1896 |
at the n@en@;1 lower levels are called @i(subaggregate)s of the |
| 1897 |
enclosing n-dimensional @nt<array_aggregate>. |
| 1898 |
@Defn{array component expression} |
| 1899 |
The @nt<expression>s of the bottom level subaggregates (or of the |
| 1900 |
@nt<array_aggregate> itself if one-dimensional) |
| 1901 |
are called the @i(array component expressions) of the enclosing |
| 1902 |
n-dimensional @nt<array_aggregate>. |
| 1903 |
@begin(Ramification) |
| 1904 |
Subaggregates do not have a type. They correspond to part of |
| 1905 |
an array. For example, with a matrix, a subaggregate would correspond to |
| 1906 |
a single row of the matrix. |
| 1907 |
The definition of "n-dimensional" @nt<array_aggregate> |
| 1908 |
applies to subaggregates as well |
| 1909 |
as @nt<aggregate>s that have a type. |
| 1910 |
@end(Ramification) |
| 1911 |
@begin(Honest) |
| 1912 |
@Defn{others choice} |
| 1913 |
An @i(@key(others) choice) is |
| 1914 |
the reserved word @key(others) as it appears in |
| 1915 |
a @nt{positional_array_aggregate} or as the |
| 1916 |
@nt{discrete_choice} of the @nt{discrete_choice_list} |
| 1917 |
in an @nt{array_component_association}. |
| 1918 |
@end(Honest) |
| 1919 |
|
| 1920 |
@end{Intro} |
| 1921 |
|
| 1922 |
@begin{Resolution} |
| 1923 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1924 |
@PDefn2{Term=[expected type], Sec=(array_aggregate)} |
| 1925 |
The expected type for an @nt{array_aggregate} (that is not |
| 1926 |
a subaggregate) shall be a |
| 1927 |
single @Chg{Version=[2],New=[],Old=[nonlimited ]}array type. |
| 1928 |
@PDefn2{Term=[expected type], |
| 1929 |
Sec=(array_aggregate component expression)} |
| 1930 |
The component type of this array type is the |
| 1931 |
expected type for each array component expression of |
| 1932 |
the @nt<array_aggregate>. |
| 1933 |
@begin{Ramification} |
| 1934 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]} |
| 1935 |
We already require a single array or record type or |
| 1936 |
record extension for an @nt{aggregate}. |
| 1937 |
The above rule requiring a single @Chg{Version=[2],New=[], |
| 1938 |
Old=[nonlimited ]}array type |
| 1939 |
(and similar ones for record and extension aggregates) |
| 1940 |
resolves which kind of aggregate you have. |
| 1941 |
@end{Ramification} |
| 1942 |
|
| 1943 |
@PDefn2{Term=[expected type], |
| 1944 |
Sec=(array_aggregate discrete_choice)} |
| 1945 |
The expected type for each |
| 1946 |
@nt{discrete_choice} in any @nt{discrete_choice_list} of |
| 1947 |
a @nt{named_array_aggregate} is the type of the @i(corresponding index); |
| 1948 |
@Defn2{Term=[corresponding index], Sec=(for an @nt{array_aggregate})} |
| 1949 |
the corresponding index for an @nt<array_aggregate> that is not |
| 1950 |
a subaggregate is the first index of its type; for an (n@en@;m)-dimensional |
| 1951 |
subaggregate within an @nt<array_aggregate> of an n-dimensional type, |
| 1952 |
the corresponding index is the index in position m+1. |
| 1953 |
@end{Resolution} |
| 1954 |
|
| 1955 |
@begin{Legality} |
| 1956 |
An @nt<array_aggregate> of an n-dimensional array type shall be |
| 1957 |
written as an n-dimensional @nt<array_aggregate>. |
| 1958 |
@begin(Ramification) |
| 1959 |
In an m-dimensional @nt<array_aggregate> @Redundant[(including a subaggregate)], |
| 1960 |
where m >= 2, each of the @nt<expression>s |
| 1961 |
has to be an (m@en@;1)-dimensional subaggregate. |
| 1962 |
@end(Ramification) |
| 1963 |
|
| 1964 |
@Leading@;An @key(others) choice is allowed for an @nt<array_aggregate> |
| 1965 |
only if an @i(applicable index |
| 1966 |
constraint) applies to the @nt{array_aggregate}. |
| 1967 |
@Defn{applicable index constraint} |
| 1968 |
@Redundant[An applicable index constraint is |
| 1969 |
a constraint provided by certain contexts where an @nt{array_aggregate} |
| 1970 |
is permitted that can be used |
| 1971 |
to determine the bounds of the array value specified by the aggregate.] |
| 1972 |
Each of the following contexts (and none other) |
| 1973 |
defines an applicable index constraint: |
| 1974 |
@begin(itemize) |
| 1975 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1976 |
For an @nt{explicit_actual_parameter}, |
| 1977 |
an @nt{explicit_generic_actual_parameter}, |
| 1978 |
the @nt{expression} of a |
| 1979 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]}, the |
| 1980 |
initialization expression |
| 1981 |
in an @nt{object_@!declaration}, or a @nt{default_@!expression} |
| 1982 |
@Redundant[(for a parameter or a component)], |
| 1983 |
when the nominal subtype |
| 1984 |
of the corresponding formal parameter, generic formal parameter, |
| 1985 |
function @Chg{Version=[2],New=[return object],Old=[result]}, object, or |
| 1986 |
component is a constrained array subtype, the |
| 1987 |
applicable index constraint is the constraint of the subtype; |
| 1988 |
|
| 1989 |
For the @nt{expression} of an @nt{assignment_statement} where |
| 1990 |
the @nt{name} denotes an array variable, the |
| 1991 |
applicable index constraint is the constraint of the array variable; |
| 1992 |
@begin{Reason} |
| 1993 |
This case is broken out because the constraint comes from the actual |
| 1994 |
subtype of the variable (which is always constrained) |
| 1995 |
rather than its nominal subtype (which might be unconstrained). |
| 1996 |
@end{Reason} |
| 1997 |
|
| 1998 |
For the operand of a @nt{qualified_expression} |
| 1999 |
whose @nt{subtype_mark} |
| 2000 |
denotes a constrained array subtype, the applicable index constraint |
| 2001 |
is the constraint of the subtype; |
| 2002 |
|
| 2003 |
For a component @nt{expression} in an @nt{aggregate}, |
| 2004 |
if the component's nominal subtype is a constrained |
| 2005 |
array subtype, the applicable index constraint is the constraint |
| 2006 |
of the subtype; |
| 2007 |
@begin{Discussion} |
| 2008 |
Here, the @nt{array_aggregate} with @key[others] |
| 2009 |
is being used within a larger aggregate. |
| 2010 |
@end{Discussion} |
| 2011 |
|
| 2012 |
For a parenthesized @nt{expression}, the |
| 2013 |
applicable index constraint is that, if any, defined for the |
| 2014 |
@nt{expression}. |
| 2015 |
@begin{Discussion} |
| 2016 |
RM83 omitted this |
| 2017 |
case, presumably as an oversight. We want to minimize situations |
| 2018 |
where an @nt{expression} becomes illegal if parenthesized. |
| 2019 |
@end{Discussion} |
| 2020 |
@end(itemize) |
| 2021 |
|
| 2022 |
The applicable index constraint @i(applies) to an @nt{array_aggregate} |
| 2023 |
that appears in such a context, as well as to any subaggregates thereof. |
| 2024 |
In the case of an @nt<explicit_actual_parameter> (or @nt<default_expression>) |
| 2025 |
for a call on a generic formal subprogram, |
| 2026 |
no applicable index constraint is defined. |
| 2027 |
@begin(Reason) |
| 2028 |
This avoids generic contract model problems, |
| 2029 |
because only mode conformance is required when matching |
| 2030 |
actual subprograms with generic formal subprograms. |
| 2031 |
@end(Reason) |
| 2032 |
|
| 2033 |
The @nt{discrete_choice_list} of an |
| 2034 |
@nt{array_component_association} is allowed to |
| 2035 |
have a @nt{discrete_choice} that is a nonstatic @nt<expression> |
| 2036 |
or that is a @nt{discrete_range} that defines a nonstatic or |
| 2037 |
null range, only if it is the single @nt{discrete_choice} of |
| 2038 |
its @nt{discrete_choice_list}, and there is only one |
| 2039 |
@nt{array_component_association} in the @nt<array_aggregate>. |
| 2040 |
@begin{Discussion} |
| 2041 |
We now |
| 2042 |
allow a nonstatic @key(others) choice even if there are |
| 2043 |
other array component expressions as well. |
| 2044 |
@end{Discussion} |
| 2045 |
|
| 2046 |
In a @nt<named_array_aggregate> with more than one @nt<discrete_choice>, |
| 2047 |
no two @nt<discrete_choice>s are allowed to |
| 2048 |
cover the same value (see @RefSecNum{Variant Parts and Discrete Choices}); |
| 2049 |
if there is no @key[others] choice, the @nt<discrete_choice>s taken |
| 2050 |
together shall |
| 2051 |
exactly cover a contiguous sequence of values of the corresponding index type. |
| 2052 |
@begin{Ramification} |
| 2053 |
This implies that each component must be |
| 2054 |
specified exactly once. See AI83-309. |
| 2055 |
@end{Ramification} |
| 2056 |
|
| 2057 |
A bottom level subaggregate of a multidimensional @nt<array_aggregate> |
| 2058 |
of a given array type |
| 2059 |
is allowed to be a @nt<string_literal> only if the component type of the |
| 2060 |
array type is a character type; |
| 2061 |
each character of such a @nt{string_literal} shall correspond to |
| 2062 |
a @nt<defining_character_literal> of the component type. |
| 2063 |
@end{Legality} |
| 2064 |
|
| 2065 |
@begin{StaticSem} |
| 2066 |
A subaggregate that is a @nt<string_literal> is equivalent |
| 2067 |
to one that is a @nt<positional_array_aggregate> of the same length, |
| 2068 |
with each @nt<expression> being the @nt<character_literal> |
| 2069 |
for the corresponding character of the @nt<string_literal>. |
| 2070 |
@end{StaticSem} |
| 2071 |
|
| 2072 |
@begin{RunTime} |
| 2073 |
@Leading@PDefn2{Term=[evaluation], Sec=(array_aggregate)} |
| 2074 |
The evaluation of an @nt{array_aggregate} of a given array type |
| 2075 |
proceeds in two steps: |
| 2076 |
@begin(enumerate) |
| 2077 |
Any @nt{discrete_choice}s of this aggregate and of its subaggregates |
| 2078 |
are evaluated in an arbitrary order, and converted to the corresponding |
| 2079 |
index type; |
| 2080 |
@PDefn2{Term=[implicit subtype conversion],Sec=(choices of aggregate)} |
| 2081 |
|
| 2082 |
The array component expressions of the aggregate |
| 2083 |
are evaluated in an arbitrary order and |
| 2084 |
their values are converted to the component subtype of |
| 2085 |
the array type; an array component expression |
| 2086 |
is evaluated once for each associated component. |
| 2087 |
@PDefn2{Term=[implicit subtype conversion],Sec=(expressions of aggregate)} |
| 2088 |
@end(enumerate) |
| 2089 |
@begin(Ramification) |
| 2090 |
Subaggregates are not separately evaluated. |
| 2091 |
The conversion of the value of the component expressions |
| 2092 |
to the component subtype might raise Constraint_Error. |
| 2093 |
@end(Ramification) |
| 2094 |
|
| 2095 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00287-01]} |
| 2096 |
@ChgAdded{Version=[2],Text=[Each @nt<expression> in an |
| 2097 |
@nt<array_component_association> defines the value for the associated |
| 2098 |
component(s). For an @nt<array_component_association> with <>, the associated |
| 2099 |
component(s) are initialized by default as for a stand-alone object of the |
| 2100 |
component subtype (see @RefSecNum{Object Declarations}).]} |
| 2101 |
|
| 2102 |
@Leading@Defn2{Term=[bounds], |
| 2103 |
Sec=(of the index range of an @nt{array_aggregate})} |
| 2104 |
The bounds of the index range of an @nt{array_aggregate} @Redundant[(including |
| 2105 |
a subaggregate)] |
| 2106 |
are determined as follows: |
| 2107 |
@begin(itemize) |
| 2108 |
For an @nt{array_aggregate} with an @key(others) choice, the bounds are |
| 2109 |
those of the corresponding index range from the applicable |
| 2110 |
index constraint; |
| 2111 |
|
| 2112 |
For a @nt{positional_array_aggregate} @Redundant[(or equivalent |
| 2113 |
@nt<string_literal>)] |
| 2114 |
without an @key(others) |
| 2115 |
choice, the lower bound is that of the corresponding index range in the |
| 2116 |
applicable index constraint, if defined, or that of the corresponding |
| 2117 |
index subtype, if not; in either case, the upper bound is |
| 2118 |
determined from the lower bound and the number of @nt<expression>s |
| 2119 |
@Redundant[(or the length of the @nt<string_literal>)]; |
| 2120 |
|
| 2121 |
For a @nt{named_array_aggregate} without an @key(others) choice, |
| 2122 |
the bounds are determined by the smallest and largest index values |
| 2123 |
covered by any @nt{discrete_choice_list}. |
| 2124 |
@begin{Reason} |
| 2125 |
We don't need to say that each index value has to be covered exactly |
| 2126 |
once, since that is a ramification of the general rule |
| 2127 |
on @nt{aggregate}s that each component's value has to be specified |
| 2128 |
exactly once. |
| 2129 |
@end{Reason} |
| 2130 |
@end(itemize) |
| 2131 |
|
| 2132 |
@IndexCheck{Range_Check} |
| 2133 |
For an @nt<array_aggregate>, a check is made |
| 2134 |
that the index range defined by its bounds |
| 2135 |
is compatible with the corresponding index subtype. |
| 2136 |
@begin{Discussion} |
| 2137 |
In RM83, this was |
| 2138 |
phrased more explicitly, but once we define "compatibility" |
| 2139 |
between a range and a subtype, it seems to make sense to |
| 2140 |
take advantage of that definition. |
| 2141 |
@end{Discussion} |
| 2142 |
@begin(Ramification) |
| 2143 |
The definition of compatibility handles the special case |
| 2144 |
of a null range, which is always compatible with |
| 2145 |
a subtype. See AI83-00313. |
| 2146 |
@end(Ramification) |
| 2147 |
|
| 2148 |
@IndexCheck{Index_Check} |
| 2149 |
For an @nt{array_aggregate} with an @key(others) choice, |
| 2150 |
a check is made that no @nt<expression> is specified |
| 2151 |
for an index value outside the bounds determined by the |
| 2152 |
applicable index constraint. |
| 2153 |
@begin{Discussion} |
| 2154 |
RM83 omitted this case, |
| 2155 |
apparently through an oversight. AI83-00309 defines this |
| 2156 |
as a dynamic check, even though other Ada 83 rules ensured |
| 2157 |
that this check could be performed statically. We now allow |
| 2158 |
an @key(others) choice to be dynamic, even if |
| 2159 |
it is not the only choice, so this check now needs to be |
| 2160 |
dynamic, in some cases. Also, within a generic unit, |
| 2161 |
this would be a nonstatic check in some cases. |
| 2162 |
@end{Discussion} |
| 2163 |
|
| 2164 |
@IndexCheck{Index_Check} |
| 2165 |
For a multidimensional @nt{array_aggregate}, a check is made |
| 2166 |
that all subaggregates that correspond to the same index have the same bounds. |
| 2167 |
@begin{Ramification} |
| 2168 |
No array bounds @lquotes@;sliding@rquotes@; is performed on subaggregates. |
| 2169 |
@end{Ramification} |
| 2170 |
@begin{Reason} |
| 2171 |
If sliding were performed, it would not be obvious which |
| 2172 |
subaggregate would determine the bounds of the corresponding index. |
| 2173 |
@end{Reason} |
| 2174 |
|
| 2175 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2176 |
The exception Constraint_Error is raised if any of the above |
| 2177 |
checks fail. |
| 2178 |
@end{RunTime} |
| 2179 |
|
| 2180 |
@begin{Notes} |
| 2181 |
@ChgRef{Version=[2],Kind=[Revised]} |
| 2182 |
In an @nt<array_aggregate>, positional notation may only be used |
| 2183 |
with two or more @nt<expression>s; a single @nt<expression> |
| 2184 |
in parentheses is interpreted as a |
| 2185 |
@Chg{Version=[2],New=[parenthesized expression],Old=[@ntf{parenthesized_expression}]}. |
| 2186 |
A @nt<named_array_aggregate>, such as (1 => X), may be used to specify |
| 2187 |
an array with a single component. |
| 2188 |
@end{Notes} |
| 2189 |
|
| 2190 |
@begin{Examples} |
| 2191 |
@Leading@keepnext@i(Examples of array aggregates with positional associations:) |
| 2192 |
@begin{Example} |
| 2193 |
(7, 9, 5, 1, 3, 2, 4, 8, 6, 0) |
| 2194 |
Table'(5, 8, 4, 1, @key(others) => 0) --@RI[ see @RefSecNum{Array Types} ] |
| 2195 |
@end{Example} |
| 2196 |
|
| 2197 |
@begin{Wide} |
| 2198 |
@leading@keepnext@i(Examples of array aggregates with named associations:) |
| 2199 |
@end{Wide} |
| 2200 |
@begin{Example} |
| 2201 |
(1 .. 5 => (1 .. 8 => 0.0)) --@RI[ two-dimensional] |
| 2202 |
(1 .. N => @key(new) Cell) --@RI[ N new cells, in particular for N = 0] |
| 2203 |
|
| 2204 |
Table'(2 | 4 | 10 => 1, @key(others) => 0) |
| 2205 |
Schedule'(Mon .. Fri => True, @key(others) => False) --@RI[ see @RefSecNum{Array Types}] |
| 2206 |
Schedule'(Wed | Sun => False, @key(others) => True) |
| 2207 |
Vector'(1 => 2.5) --@RI[ single-component vector] |
| 2208 |
@end{Example} |
| 2209 |
|
| 2210 |
@begin{Wide} |
| 2211 |
@leading@keepnext@i(Examples of two-dimensional array aggregates:) |
| 2212 |
@end{Wide} |
| 2213 |
@begin{Example} |
| 2214 |
--@RI[ Three aggregates for the same value of subtype Matrix(1..2,1..3) (see @RefSecNum{Array Types}):] |
| 2215 |
|
| 2216 |
((1.1, 1.2, 1.3), (2.1, 2.2, 2.3)) |
| 2217 |
(1 => (1.1, 1.2, 1.3), 2 => (2.1, 2.2, 2.3)) |
| 2218 |
(1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3)) |
| 2219 |
@end{Example} |
| 2220 |
|
| 2221 |
@begin{Wide} |
| 2222 |
@leading@keepnext@i(Examples of aggregates as initial values:) |
| 2223 |
@end{Wide} |
| 2224 |
@begin{Example} |
| 2225 |
A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0); --@RI[ A(1)=7, A(10)=0] |
| 2226 |
B : Table := (2 | 4 | 10 => 1, @key(others) => 0); --@RI[ B(1)=0, B(10)=1] |
| 2227 |
C : @key(constant) Matrix := (1 .. 5 => (1 .. 8 => 0.0)); --@RI[ C'Last(1)=5, C'Last(2)=8] |
| 2228 |
|
| 2229 |
D : Bit_Vector(M .. N) := (M .. N => True); --@RI[ see @RefSecNum{Array Types}] |
| 2230 |
E : Bit_Vector(M .. N) := (@key(others) => True); |
| 2231 |
F : String(1 .. 1) := (1 => 'F'); --@RI[ a one component aggregate: same as "F"] |
| 2232 |
@end{Example} |
| 2233 |
|
| 2234 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 2235 |
@ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],Text=[@i{Example of an array |
| 2236 |
aggregate with defaulted others choice and with an applicable index constraint |
| 2237 |
provided by an enclosing record aggregate:}]} |
| 2238 |
|
| 2239 |
@begin{Example} |
| 2240 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2241 |
@ChgAdded{Version=[2],Text=[Buffer'(Size => 50, Pos => 1, Value => String'('x', @key(others) => <>)) --@RI[ see @RefSecNum{Discriminants}]]} |
| 2242 |
@end{Example} |
| 2243 |
@end{Examples} |
| 2244 |
|
| 2245 |
@begin{Incompatible83} |
| 2246 |
@ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016} |
| 2247 |
@ChgAdded{Version=[1],Type=[Leading],Text=[@Defn{incompatibilities with Ada 83} |
| 2248 |
In Ada 95, no applicable index constraint is defined for a parameter |
| 2249 |
in a call to a generic formal subprogram; thus, some aggregates that are |
| 2250 |
legal in Ada 83 are illegal in Ada 95. For example:]} |
| 2251 |
@begin{Example} |
| 2252 |
@ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016} |
| 2253 |
@Chg{New=[@key[subtype] S3 @key[is] String (1 .. 3); |
| 2254 |
... |
| 2255 |
@key[generic] |
| 2256 |
@key[with function] F (The_S3 : @key[in] S3) @key[return] Integer; |
| 2257 |
@key[package] Gp @key[is] |
| 2258 |
I : constant Integer := F ((1 => '!', others => '?')); |
| 2259 |
-- @RI{The aggregate is legal in Ada 83, illegal in Ada 95.} |
| 2260 |
@key[end] Gp;],Old=[]} |
| 2261 |
@end{Example} |
| 2262 |
@ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00016} |
| 2263 |
@Chg{New=[This change eliminates generic contract model problems.],Old=[]} |
| 2264 |
@end{Incompatible83} |
| 2265 |
|
| 2266 |
@begin{Extend83} |
| 2267 |
@Defn{extensions to Ada 83} |
| 2268 |
We now allow "named with others" aggregates in all contexts |
| 2269 |
where there is an applicable index constraint, effectively |
| 2270 |
eliminating what was RM83-4.3.2(6). Sliding never occurs |
| 2271 |
on an aggregate with others, because its bounds come from |
| 2272 |
the applicable index constraint, and therefore already match |
| 2273 |
the bounds of the target. |
| 2274 |
|
| 2275 |
The legality of an @key(others) choice is no longer affected |
| 2276 |
by the staticness of the applicable index constraint. |
| 2277 |
This substantially simplifies several rules, while being slightly |
| 2278 |
more flexible for the user. It obviates the rulings |
| 2279 |
of AI83-00244 and AI83-00310, while taking advantage of the dynamic nature |
| 2280 |
of the "extra values" check required by AI83-00309. |
| 2281 |
|
| 2282 |
Named array aggregates are permitted even if the |
| 2283 |
index type is descended from a formal scalar type. |
| 2284 |
See @RefSecNum(Static Expressions and Static Subtypes) and AI83-00190. |
| 2285 |
@end{Extend83} |
| 2286 |
|
| 2287 |
@begin{DiffWord83} |
| 2288 |
We now separate named and positional array aggregate syntax, |
| 2289 |
since, unlike other aggregates, named and positional |
| 2290 |
associations cannot be mixed in array aggregates (except |
| 2291 |
that an @key(others) choice is allowed in a positional array aggregate). |
| 2292 |
|
| 2293 |
We have also reorganized the presentation to handle |
| 2294 |
multidimensional and one-dimensional aggregates more uniformly, |
| 2295 |
and to incorporate the rulings of AI83-00019, AI83-00309, etc. |
| 2296 |
@end{DiffWord83} |
| 2297 |
|
| 2298 |
@begin{Extend95} |
| 2299 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 2300 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}<> can be used in |
| 2301 |
place of an @nt{expression} in an @nt{array_aggregate}, default-initializing |
| 2302 |
the component.]} |
| 2303 |
@end{Extend95} |
| 2304 |
|
| 2305 |
@begin{DiffWord95} |
| 2306 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]} |
| 2307 |
@ChgAdded{Version=[2],Text=[Limited @nt{array_aggregate}s are allowed (since |
| 2308 |
all kinds of aggregates can now be limited, see @RefSecNum{Aggregates}).]} |
| 2309 |
|
| 2310 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2311 |
@ChgAdded{Version=[2],Text=[Fixed @nt{aggregate}s to use the subtype of |
| 2312 |
the return object of a function, rather than the result subtype, because |
| 2313 |
they can be different for an @nt{extended_return_statement}, and we want |
| 2314 |
to use the subtype that's explicitly in the code at the point of the |
| 2315 |
@nt{expression}.]} |
| 2316 |
@end{DiffWord95} |
| 2317 |
|
| 2318 |
|
| 2319 |
@LabeledClause{Expressions} |
| 2320 |
|
| 2321 |
@begin{Intro} |
| 2322 |
@Defn{expression} |
| 2323 |
An @i(expression) is a formula that defines the computation or retrieval |
| 2324 |
of a value. |
| 2325 |
In this International Standard, the term @lquotes@;expression@rquotes@; refers to a construct |
| 2326 |
of the syntactic category @nt<expression> or |
| 2327 |
of any of the other five syntactic categories defined below. |
| 2328 |
@Defn{and operator}@Defn2{Term=[operator],Sec=(and)} |
| 2329 |
@Defn{or operator}@Defn2{Term=[operator],Sec=(or)} |
| 2330 |
@Defn{xor operator}@Defn2{Term=[operator],Sec=(xor)} |
| 2331 |
@Defn{and then (short-circuit control form)} |
| 2332 |
@Defn{or else (short-circuit control form)} |
| 2333 |
@Defn{= operator}@Defn2{Term=[operator],Sec=(=)} |
| 2334 |
@Defn{equal operator}@Defn2{Term=[operator],Sec=(equal)} |
| 2335 |
@Defn{/= operator}@Defn2{Term=[operator],Sec=(/=)} |
| 2336 |
@Defn{not equal operator}@Defn2{Term=[operator],Sec=(not equal)} |
| 2337 |
@Defn{< operator}@Defn2{Term=[operator],Sec=(<)} |
| 2338 |
@Defn{less than operator}@Defn2{Term=[operator],Sec=(less than)} |
| 2339 |
@Defn{<= operator}@Defn2{Term=[operator],Sec=(<=)} |
| 2340 |
@Defn{less than or equal operator}@Defn2{Term=[operator],Sec=(less than or equal)} |
| 2341 |
@Defn{> operator}@Defn2{Term=[operator],Sec=(>)} |
| 2342 |
@Defn{greater than operator}@Defn2{Term=[operator],Sec=(greater than)} |
| 2343 |
@Defn{>= operator}@Defn2{Term=[operator],Sec=(>=)} |
| 2344 |
@Defn{greater than or equal operator}@Defn2{Term=[operator],Sec=(greater than or equal)} |
| 2345 |
@Defn{in (membership test)} |
| 2346 |
@Defn{not in (membership test)} |
| 2347 |
@Defn{+ operator}@Defn2{Term=[operator],Sec=(+)} |
| 2348 |
@Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)} |
| 2349 |
@Defn{- operator}@Defn2{Term=[operator],Sec=(-)} |
| 2350 |
@Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)} |
| 2351 |
@Defn{& operator}@Defn2{Term=[operator],Sec=(&)} |
| 2352 |
@Defn{ampersand operator}@Defn2{Term=[operator],Sec=(ampersand)} |
| 2353 |
@Defn{concatenation operator}@Defn2{Term=[operator],Sec=(concatenation)} |
| 2354 |
@IndexSee{Term=[catenation operator],See=(concatenation operator)} |
| 2355 |
@Defn{* operator}@Defn2{Term=[operator],Sec=(*)} |
| 2356 |
@Defn{multiply operator}@Defn2{Term=[operator],Sec=(multiply)} |
| 2357 |
@Defn{times operator}@Defn2{Term=[operator],Sec=(times)} |
| 2358 |
@Defn{/ operator}@Defn2{Term=[operator],Sec=(/)} |
| 2359 |
@Defn{divide operator}@Defn2{Term=[operator],Sec=(divide)} |
| 2360 |
@Defn{mod operator}@Defn2{Term=[operator],Sec=(mod)} |
| 2361 |
@Defn{rem operator}@Defn2{Term=[operator],Sec=(rem)} |
| 2362 |
@Defn{** operator}@Defn2{Term=[operator],Sec=(**)} |
| 2363 |
@Defn{exponentiation operator}@Defn2{Term=[operator],Sec=(exponentiation)} |
| 2364 |
@Defn{abs operator}@Defn2{Term=[operator],Sec=(abs)} |
| 2365 |
@Defn{absolute value} |
| 2366 |
@Defn{not operator}@Defn2{Term=[operator],Sec=(not)} |
| 2367 |
@end{Intro} |
| 2368 |
|
| 2369 |
@begin{Syntax} |
| 2370 |
@Syn{tabs=[P23], lhs=<expression>,rhs=" |
| 2371 |
@Syn2{relation} {@key{and} @Syn2{relation}} @\| @Syn2{relation} {@key{and} @key{then} @Syn2{relation}} |
| 2372 |
| @Syn2{relation} {@key{or} @Syn2{relation}} @\| @Syn2{relation} {@key{or} @key{else} @Syn2{relation}} |
| 2373 |
| @Syn2{relation} {@key{xor} @Syn2{relation}}"} |
| 2374 |
|
| 2375 |
|
| 2376 |
@Syn{lhs=<relation>,rhs=" |
| 2377 |
@Syn2{simple_expression} [@Syn2{relational_operator} @Syn2{simple_expression}] |
| 2378 |
| @Syn2{simple_expression} [@key{not}] @key{in} @Syn2{range} |
| 2379 |
| @Syn2{simple_expression} [@key{not}] @key{in} @Syn2{subtype_mark}"} |
| 2380 |
|
| 2381 |
|
| 2382 |
@Syn{lhs=<simple_expression>,rhs="[@Syn2{unary_adding_operator}] @Syn2{term} {@Syn2{binary_adding_operator} @Syn2{term}}"} |
| 2383 |
|
| 2384 |
|
| 2385 |
@Syn{lhs=<term>,rhs="@Syn2{factor} {@Syn2{multiplying_operator} @Syn2{factor}}"} |
| 2386 |
|
| 2387 |
|
| 2388 |
@Syn{lhs=<factor>,rhs="@Syn2{primary} [** @Syn2{primary}] | @key{abs} @Syn2{primary} | @key{not} @Syn2{primary}"} |
| 2389 |
|
| 2390 |
@Syn{lhs=<primary>,rhs=" |
| 2391 |
@Syn2{numeric_literal} | @key{null} | @Syn2{string_literal} | @Syn2{aggregate} |
| 2392 |
| @Syn2{name} | @Syn2{qualified_expression} | @Syn2{allocator} | (@Syn2{expression})"} |
| 2393 |
@end{Syntax} |
| 2394 |
|
| 2395 |
@begin{Resolution} |
| 2396 |
A @nt<name> used as a @nt<primary> shall resolve to denote an object |
| 2397 |
or a value. |
| 2398 |
@begin{Discussion} |
| 2399 |
This replaces RM83-4.4(3). We don't need to mention named numbers |
| 2400 |
explicitly, because the name of a named number denotes a value. |
| 2401 |
We don't need to mention attributes explicitly, because |
| 2402 |
attributes now denote (rather than yield) values in general. |
| 2403 |
Also, the new wording allows attributes that denote objects, |
| 2404 |
which should always have been allowed (in case the implementation chose to |
| 2405 |
have such a thing). |
| 2406 |
@end{Discussion} |
| 2407 |
@begin{Reason} |
| 2408 |
It might seem odd that this is an overload resolution rule, |
| 2409 |
but it is relevant during overload resolution. For example, |
| 2410 |
it helps ensure that a @nt<primary> that consists of only |
| 2411 |
the identifier of a parameterless function is interpreted as a |
| 2412 |
@nt<function_call> rather than directly as a @nt<direct_name>. |
| 2413 |
@end{Reason} |
| 2414 |
@end{Resolution} |
| 2415 |
|
| 2416 |
@begin{StaticSem} |
| 2417 |
Each expression has a type; it specifies the |
| 2418 |
computation or retrieval of a value of that type. |
| 2419 |
@end{StaticSem} |
| 2420 |
|
| 2421 |
@begin{RunTime} |
| 2422 |
@PDefn2{Term=[evaluation], Sec=(primary that is a name)} |
| 2423 |
The value of a @nt<primary> that is a @nt{name} denoting an object |
| 2424 |
is the value of the object. |
| 2425 |
@end{RunTime} |
| 2426 |
|
| 2427 |
@begin{ImplPerm} |
| 2428 |
@IndexCheck{Overflow_Check} |
| 2429 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2430 |
For the evaluation of |
| 2431 |
a @nt<primary> that is a @nt<name> denoting an object of an |
| 2432 |
unconstrained numeric subtype, |
| 2433 |
if the value of the object is outside the base range of its type, |
| 2434 |
the implementation may either raise Constraint_Error |
| 2435 |
or return the value of the object. |
| 2436 |
@begin{Ramification} |
| 2437 |
This means that if extra-range intermediates are used to |
| 2438 |
hold the value of an object of an unconstrained numeric subtype, |
| 2439 |
a Constraint_Error can be raised on a read of the object, rather than |
| 2440 |
only on an assignment to it. Similarly, it means that |
| 2441 |
computing the value of an object of such a subtype |
| 2442 |
can be deferred until the first read of the object |
| 2443 |
(presuming no side-effects other than failing an Overflow_Check |
| 2444 |
are possible). This permission is over and above that provided |
| 2445 |
by clause @RefSecNum(Exceptions and Optimization), since |
| 2446 |
this allows the Constraint_Error to move to a different handler. |
| 2447 |
@end{Ramification} |
| 2448 |
@begin{Reason} |
| 2449 |
This permission is intended to allow extra-range registers |
| 2450 |
to be used efficiently to hold parameters and local variables, |
| 2451 |
even if they might need to be transferred into smaller registers |
| 2452 |
for performing certain predefined operations. |
| 2453 |
@end{Reason} |
| 2454 |
@begin{Discussion} |
| 2455 |
There is no need to mention other kinds of @nt<primary>s, since any |
| 2456 |
Constraint_Error to be raised can be @lquotes@;charged@rquotes@; to the evaluation |
| 2457 |
of the particular kind of @nt<primary>. |
| 2458 |
@end{Discussion} |
| 2459 |
@end{ImplPerm} |
| 2460 |
|
| 2461 |
@begin{Examples} |
| 2462 |
@Leading@keepnext@i(Examples of primaries:) |
| 2463 |
@begin{Example} |
| 2464 |
@Trailing@;4.0 --@RI[ real literal] |
| 2465 |
Pi --@RI[ named number] |
| 2466 |
(1 .. 10 => 0) --@RI[ array aggregate] |
| 2467 |
Sum --@RI[ variable] |
| 2468 |
Integer'Last --@RI[ attribute] |
| 2469 |
Sine(X) --@RI[ function call] |
| 2470 |
Color'(Blue) --@RI[ qualified expression] |
| 2471 |
Real(M*N) --@RI[ conversion] |
| 2472 |
(Line_Count + 10) --@RI[ parenthesized expression ] |
| 2473 |
@end{Example} |
| 2474 |
|
| 2475 |
@leading@keepnext@i(Examples of expressions:) |
| 2476 |
@begin{Example} |
| 2477 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]} |
| 2478 |
Volume --@RI[ primary] |
| 2479 |
@key(not) Destroyed --@RI[ factor] |
| 2480 |
2*Line_Count --@RI[ term] |
| 2481 |
-4.0 --@RI[ simple expression] |
| 2482 |
-4.0 + A --@RI[ simple expression] |
| 2483 |
B**2 - 4.0*A*C --@RI[ simple expression]@Chg{Version=[2],New=[ |
| 2484 |
R*Sin(@unicode<952>)*Cos(@unicode<966>) --@RI[ simple expression]],Old=[]} |
| 2485 |
Password(1 .. 3) = "Bwv" --@RI[ relation] |
| 2486 |
Count @key(in) Small_Int --@RI[ relation] |
| 2487 |
Count @key(not) @key(in) Small_Int --@RI[ relation] |
| 2488 |
Index = 0 @key(or) Item_Hit --@RI[ expression] |
| 2489 |
(Cold @key(and) Sunny) @key(or) Warm --@RI[ expression (parentheses are required)] |
| 2490 |
A**(B**C) --@RI[ expression (parentheses are required)] |
| 2491 |
@end{Example} |
| 2492 |
@end{Examples} |
| 2493 |
|
| 2494 |
@begin{Extend83} |
| 2495 |
@Defn{extensions to Ada 83} |
| 2496 |
In Ada 83, @key{out} parameters and their nondiscriminant |
| 2497 |
subcomponents are not allowed as @ntf{primaries}. |
| 2498 |
These restrictions are eliminated in Ada 95. |
| 2499 |
|
| 2500 |
In various contexts throughout the language where Ada 83 syntax rules |
| 2501 |
had @nt<simple_expression>, the corresponding Ada 95 syntax |
| 2502 |
rule has @nt<expression> instead. This reflects the inclusion |
| 2503 |
of modular integer types, which makes the logical operators |
| 2504 |
"@key[and]", "@key[or]", and "@key[xor]" more useful in expressions of |
| 2505 |
an integer type. |
| 2506 |
Requiring parentheses to use these operators in such contexts |
| 2507 |
seemed unnecessary and potentially confusing. |
| 2508 |
Note that the bounds of a @nt<range> still have to be |
| 2509 |
specified by @nt<simple_expression>s, since otherwise @nt<expression>s |
| 2510 |
involving membership tests might be ambiguous. |
| 2511 |
Essentially, the operation ".." is of higher precedence than the |
| 2512 |
logical operators, and hence uses of logical operators |
| 2513 |
still have to be parenthesized when used in a bound of a range. |
| 2514 |
@end{Extend83} |
| 2515 |
|
| 2516 |
|
| 2517 |
@LabeledClause{Operators and Expression Evaluation} |
| 2518 |
|
| 2519 |
@begin{Intro} |
| 2520 |
@Redundant[@Defn{precedence of operators} |
| 2521 |
@Defn{operator precedence} |
| 2522 |
The language defines the following six categories |
| 2523 |
of operators (given in order of increasing |
| 2524 |
precedence). The corresponding @nt<operator_symbol>s, |
| 2525 |
and only those, can be used as @nt<designator>s in declarations |
| 2526 |
of functions for user-defined operators. See @RefSec(Overloading of Operators).] |
| 2527 |
@end{Intro} |
| 2528 |
|
| 2529 |
@begin{Syntax} |
| 2530 |
@Syn{tabs=[P36], lhs=<logical_operator>, |
| 2531 |
rhs="@\ @key{and} | @key{or} | @key{xor}"} |
| 2532 |
@Syn{tabs=[P36], lhs=<relational_operator>,rhs="@\ = | /= | < | <= | > | >="} |
| 2533 |
@Syn{tabs=[P36], lhs=<binary_adding_operator>,rhs="@\ + | @en | &"} |
| 2534 |
@Syn{tabs=[P36], lhs=<unary_adding_operator>,rhs="@\ + | @en"} |
| 2535 |
@Syn{tabs=[P36], lhs=<multiplying_operator>,rhs="@\ * | / | @key{mod} | @key{rem}"} |
| 2536 |
@Syn{tabs=[P36], lhs=<highest_precedence_operator>,rhs="@\ ** | @key{abs} | @key{not}"} |
| 2537 |
@begin(Discussion) |
| 2538 |
Some of the above syntactic categories are not used in other |
| 2539 |
syntax rules. They are just used for classification. |
| 2540 |
The others are used for both classification and parsing. |
| 2541 |
@end(Discussion) |
| 2542 |
@end{Syntax} |
| 2543 |
|
| 2544 |
@begin{StaticSem} |
| 2545 |
For a sequence of operators of the same precedence level, the |
| 2546 |
operators are associated with their operands |
| 2547 |
in textual order from left to right. |
| 2548 |
Parentheses can be used to impose specific associations. |
| 2549 |
@begin{Discussion} |
| 2550 |
The left-associativity is not directly inherent in the grammar of |
| 2551 |
@RefSecNum{Expressions}, |
| 2552 |
though in @RefSecNum{Method of Description and Syntax Notation} |
| 2553 |
the definition of the metasymbols @b({}) implies left |
| 2554 |
associativity. So this could be seen as redundant, depending on |
| 2555 |
how literally one interprets the definition of the @b({}) metasymbols. |
| 2556 |
|
| 2557 |
See the Implementation Permissions below regarding flexibility |
| 2558 |
in reassociating operators of the same precedence. |
| 2559 |
@end{Discussion} |
| 2560 |
|
| 2561 |
@Defn{predefined operator}@Defn2{Term=[operator],Sec=(predefined)} |
| 2562 |
For each form of type definition, certain of the above operators are |
| 2563 |
@i(predefined); |
| 2564 |
that is, they are implicitly declared immediately after the type definition. |
| 2565 |
@Defn{binary operator}@Defn2{Term=[operator],Sec=(binary)} |
| 2566 |
@Defn{unary operator}@Defn2{Term=[operator],Sec=(unary)} |
| 2567 |
For each such implicit operator declaration, the |
| 2568 |
parameters are called Left and Right for @i(binary) operators; |
| 2569 |
the single parameter is called Right for @i(unary) operators. |
| 2570 |
@redundant[An expression of the form X op Y, |
| 2571 |
where op is a binary operator, |
| 2572 |
is equivalent to a @nt<function_call> of the form "op"(X, Y). |
| 2573 |
An expression of the form op Y, |
| 2574 |
where op is a unary operator, |
| 2575 |
is equivalent to a @nt<function_call> of the form "op"(Y). |
| 2576 |
The predefined operators and their effects are described |
| 2577 |
in subclauses @RefSecNum(Logical Operators and Short-Circuit Control Forms) |
| 2578 |
through @RefSecNum(Highest Precedence Operators).] |
| 2579 |
@end{StaticSem} |
| 2580 |
|
| 2581 |
@begin{RunTime} |
| 2582 |
@redundant[@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2583 |
The predefined operations on integer types either yield the mathematically |
| 2584 |
correct result or raise the exception Constraint_Error. |
| 2585 |
For implementations that support the Numerics Annex, |
| 2586 |
the predefined operations on real types yield results whose |
| 2587 |
accuracy is defined in @RefSecNum(Numerics), or |
| 2588 |
raise the exception Constraint_Error. |
| 2589 |
] |
| 2590 |
@begin{Honest} |
| 2591 |
Predefined operations on real types can @lquotes@;silently@rquotes@; give wrong results |
| 2592 |
when the Machine_Overflows attribute is false, and the |
| 2593 |
computation overflows. |
| 2594 |
@end{Honest} |
| 2595 |
|
| 2596 |
@end{RunTime} |
| 2597 |
|
| 2598 |
@begin{ImplReq} |
| 2599 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2600 |
The implementation of a predefined operator |
| 2601 |
that delivers a result of an integer or fixed point type may |
| 2602 |
raise Constraint_Error only if the result is outside |
| 2603 |
the base range of the result type. |
| 2604 |
|
| 2605 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2606 |
The implementation of a predefined operator |
| 2607 |
that delivers a result of a floating point type may raise Constraint_Error |
| 2608 |
only if the result is outside the safe range of the |
| 2609 |
result type. |
| 2610 |
@begin{Honest} |
| 2611 |
|
| 2612 |
An exception is made for exponentiation by a negative exponent in |
| 2613 |
@RefSecNum{Highest Precedence Operators}. |
| 2614 |
|
| 2615 |
@end{Honest} |
| 2616 |
@end{ImplReq} |
| 2617 |
|
| 2618 |
@begin{ImplPerm} |
| 2619 |
For a sequence of predefined operators of the same precedence |
| 2620 |
level (and in the absence of parentheses imposing a specific association), |
| 2621 |
an implementation may impose any association of the operators with |
| 2622 |
operands so long as the result produced is |
| 2623 |
an allowed result for the left-to-right association, but ignoring |
| 2624 |
the potential for failure of language-defined checks in either the |
| 2625 |
left-to-right or chosen order of association. |
| 2626 |
@begin{Discussion} |
| 2627 |
Note that the permission to reassociate the operands in |
| 2628 |
any way subject to producing a result allowed for |
| 2629 |
the left-to-right association is not much help |
| 2630 |
for most floating point operators, since reassociation may |
| 2631 |
introduce significantly different round-off errors, delivering |
| 2632 |
a result that is outside the model interval for the left-to-right |
| 2633 |
association. Similar problems arise for division with |
| 2634 |
integer or fixed point operands. |
| 2635 |
|
| 2636 |
Note that this permission does not apply to user-defined |
| 2637 |
operators. |
| 2638 |
@end{Discussion} |
| 2639 |
@end{ImplPerm} |
| 2640 |
|
| 2641 |
@begin{Notes} |
| 2642 |
The two operands of an expression of the form X op Y, where |
| 2643 |
op is a binary operator, are evaluated in an arbitrary order, |
| 2644 |
as for any @nt<function_call> (see @RefSecNum(Subprogram Calls)). |
| 2645 |
@end{Notes} |
| 2646 |
|
| 2647 |
@begin{Examples} |
| 2648 |
@Leading@keepnext@i(Examples of precedence:) |
| 2649 |
@begin{Example} |
| 2650 |
@key(not) Sunny @key(or) Warm --@RI[ same as (not Sunny) or Warm] |
| 2651 |
X > 4.0 @key(and) Y > 0.0 --@RI[ same as (X > 4.0) and (Y > 0.0)] |
| 2652 |
|
| 2653 |
-4.0*A**2 --@RI[ same as @en@;(4.0 * (A**2))] |
| 2654 |
@key(abs)(1 + A) + B --@RI[ same as (abs (1 + A)) + B] |
| 2655 |
Y**(-3) --@RI[ parentheses are necessary] |
| 2656 |
A / B * C --@RI[ same as (A/B)*C] |
| 2657 |
A + (B + C) --@RI[ evaluate B + C before adding it to A ] |
| 2658 |
@end{Example} |
| 2659 |
@end{Examples} |
| 2660 |
|
| 2661 |
@begin{DiffWord83} |
| 2662 |
We don't give a detailed definition of precedence, since |
| 2663 |
it is all implicit in the syntax rules anyway. |
| 2664 |
|
| 2665 |
The permission to reassociate is moved here from RM83-11.6(5), so |
| 2666 |
it is closer to the rules defining operator association. |
| 2667 |
@end{DiffWord83} |
| 2668 |
|
| 2669 |
|
| 2670 |
@LabeledSubClause{Logical Operators and Short-circuit Control Forms} |
| 2671 |
|
| 2672 |
@begin{Resolution} |
| 2673 |
@Defn{short-circuit control form} |
| 2674 |
@Defn{and then (short-circuit control form)} |
| 2675 |
@Defn{or else (short-circuit control form)} |
| 2676 |
An @nt<expression> consisting of two @nt<relation>s |
| 2677 |
connected by @key(and then) or @key(or else) |
| 2678 |
(a @i(short-circuit control form)) |
| 2679 |
shall resolve to be of some boolean type; |
| 2680 |
@PDefn2{Term=[expected type],Sec=(short-circuit control form relation)} |
| 2681 |
the expected type for both @nt<relation>s |
| 2682 |
is that same boolean type. |
| 2683 |
@begin(Reason) |
| 2684 |
This rule is written this way so that overload resolution treats |
| 2685 |
the two operands symmetrically; the resolution of overloading |
| 2686 |
present in either one can benefit from the resolution of the other. |
| 2687 |
Furthermore, the type expected by context can help. |
| 2688 |
@end(Reason) |
| 2689 |
@end{Resolution} |
| 2690 |
|
| 2691 |
@begin{StaticSem} |
| 2692 |
@Leading@Defn{logical operator}@Defn2{Term=[operator],Sec=(logical)} |
| 2693 |
@Defn{and operator}@Defn2{Term=[operator],Sec=(and)} |
| 2694 |
@Defn{or operator}@Defn2{Term=[operator],Sec=(or)} |
| 2695 |
@Defn{xor operator}@Defn2{Term=[operator],Sec=(xor)} |
| 2696 |
The following logical operators are predefined for every |
| 2697 |
boolean type @i(T), |
| 2698 |
for every modular type @i(T), and |
| 2699 |
for every one-dimensional array type @i(T) whose |
| 2700 |
component type is a boolean type: |
| 2701 |
@IndexSee{Term=[bit string],See=(logical operators on boolean arrays)} |
| 2702 |
@begin{example} |
| 2703 |
@tabclear() |
| 2704 |
@key[function] "@key(and)"(Left, Right : @RI(T)) @key[return] @RI(T) |
| 2705 |
@key[function] "@key(or)" (Left, Right : @RI(T)) @key[return] @RI(T) |
| 2706 |
@key[function] "@key(xor)"(Left, Right : @RI(T)) @key[return] @RI(T) |
| 2707 |
@end{example} |
| 2708 |
@begin{Honest} |
| 2709 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00145-01]} |
| 2710 |
@ChgDeleted{Version=[2],Text=[For predefined operators, the parameter |
| 2711 |
and result subtypes shown as @i(T) are actually the unconstrained |
| 2712 |
subtype of the type.]} |
| 2713 |
@ChgNote{Sorry, Bob, but there is no "honesty" issue here. And |
| 2714 |
"unconstrained" is wrong.} |
| 2715 |
@end{Honest} |
| 2716 |
@begin{Ramification} |
| 2717 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00145-01]} |
| 2718 |
@ChgAdded{Version=[2],Text=[For these operators, we are talking about |
| 2719 |
the type without any (interesting) subtype, and not some subtype with a |
| 2720 |
constraint or exclusion. Since it's possible that there is no name for |
| 2721 |
the @lquotes@;uninteresting@rquotes subtype, we denote the type |
| 2722 |
with an italicized @i(T). |
| 2723 |
This applies to the italicized @i(T) in many other predefined operators and |
| 2724 |
attributes as well.@Defn2{Term=[T],Sec=[italicized]}]} |
| 2725 |
|
| 2726 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00145-01]} |
| 2727 |
@ChgAdded{Version=[2],Type=[Leading],Text=[In many cases, there is a subtype |
| 2728 |
with the correct properties available. The italicized @i(T) means:]} |
| 2729 |
@begin{Itemize} |
| 2730 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2731 |
@ChgAdded{Version=[2],Text=[@i(T)'Base, for scalars;]} |
| 2732 |
|
| 2733 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2734 |
@ChgAdded{Version=[2],Text=[the first subtype of @i(T), for tagged types;]} |
| 2735 |
|
| 2736 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2737 |
@ChgAdded{Version=[2],Text=[a subtype of the type @i(T) without any |
| 2738 |
constraint or null exclusion, in other cases.]} |
| 2739 |
@end{Itemize} |
| 2740 |
|
| 2741 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2742 |
@ChgAdded{Version=[2],Text=[Note that @lquotes@;without a constraint@rquotes |
| 2743 |
is not the same as unconstrained. For instance, a record type with no |
| 2744 |
discriminant part is considered constrained; no subtype of it has a |
| 2745 |
constraint, but the subtype is still constrained.]} |
| 2746 |
|
| 2747 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2748 |
@ChgAdded{Version=[2],Text=[Thus, the last case often is the same as |
| 2749 |
the first subtype of @i(T), but that isn't the case for constrained array |
| 2750 |
types (where the correct subtype is unconstrained) and for access types |
| 2751 |
with a @nt{null_exclusion} (where the correct subtype does not |
| 2752 |
exclude null).]} |
| 2753 |
|
| 2754 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2755 |
@ChgAdded{Version=[2],Text=[This italicized @i(T) is used for defining |
| 2756 |
operators and attributes of the language. The meaning is intended to be |
| 2757 |
as described here.]} |
| 2758 |
@end{Ramification} |
| 2759 |
|
| 2760 |
For boolean types, the predefined logical operators |
| 2761 |
@key{and}, @key{or}, and @key{xor} |
| 2762 |
perform the conventional operations of conjunction, inclusive |
| 2763 |
disjunction, and exclusive disjunction, respectively. |
| 2764 |
|
| 2765 |
For modular types, the predefined logical operators |
| 2766 |
are defined on a bit-by-bit basis, using the binary |
| 2767 |
representation of the value of the operands to |
| 2768 |
yield a binary representation for the result, |
| 2769 |
where zero represents False and one represents True. |
| 2770 |
If this result is outside the base range of the type, |
| 2771 |
a final subtraction by the modulus is performed to bring the |
| 2772 |
result into the base range of the type. |
| 2773 |
|
| 2774 |
The logical operators on arrays are performed on a |
| 2775 |
component-by-component basis on |
| 2776 |
matching components (as for equality @em |
| 2777 |
see @RefSecNum{Relational Operators and Membership Tests}), |
| 2778 |
using the predefined logical operator for the component type. The bounds of |
| 2779 |
the resulting array are those of the left operand. |
| 2780 |
|
| 2781 |
@end{StaticSem} |
| 2782 |
|
| 2783 |
@begin{RunTime} |
| 2784 |
@PDefn2{Term=[evaluation], Sec=(short-circuit control form)} |
| 2785 |
The short-circuit control forms @key{and then} and @key{or else} |
| 2786 |
deliver the same result as the corresponding predefined @key{and} and @key{or} |
| 2787 |
operators for boolean types, except that the left operand is always |
| 2788 |
evaluated first, and the right operand is not evaluated if the |
| 2789 |
value of the left operand determines the result. |
| 2790 |
|
| 2791 |
@IndexCheck{Length_Check} |
| 2792 |
For the logical operators on arrays, |
| 2793 |
a check is made that |
| 2794 |
for each component of the left operand there is a matching component of the |
| 2795 |
right operand, and vice versa. |
| 2796 |
@IndexCheck{Range_Check} |
| 2797 |
Also, a check is made that each component |
| 2798 |
of the result belongs to the component subtype. |
| 2799 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2800 |
The exception Constraint_Error is raised if |
| 2801 |
either of the above checks fails. |
| 2802 |
@begin{Discussion} |
| 2803 |
The check against the component subtype is per AI83-00535. |
| 2804 |
@end{Discussion} |
| 2805 |
|
| 2806 |
@end{RunTime} |
| 2807 |
|
| 2808 |
@begin{Notes} |
| 2809 |
@Leading@;The conventional meaning of the logical operators is given by the |
| 2810 |
following truth table: |
| 2811 |
@begin(Display) |
| 2812 |
@TabClear() |
| 2813 |
@TabSet(P4, P20, P36, P52, P68) |
| 2814 |
@\@ @ A@\@ @ B@\(A @key(and) B)@\(A @key(or) B)@\(A @key(xor) B)@* |
| 2815 |
@\True @\True @\True @\True @\False |
| 2816 |
@\True @\False @\False @\True @\True |
| 2817 |
@\False @\True @\False @\True @\True |
| 2818 |
@\False @\False @\False @\False @\False |
| 2819 |
@end(Display) |
| 2820 |
@end{Notes} |
| 2821 |
|
| 2822 |
@begin{Examples} |
| 2823 |
@Leading@keepnext@i(Examples of logical operators:) |
| 2824 |
@begin{Example} |
| 2825 |
Sunny @key(or) Warm |
| 2826 |
Filter(1 .. 10) @key(and) Filter(15 .. 24) --@RI[ see @RefSecNum{Index Constraints and Discrete Ranges} ] |
| 2827 |
@end{Example} |
| 2828 |
|
| 2829 |
@begin{Wide} |
| 2830 |
@leading@keepnext@i(Examples of short-circuit control forms:) |
| 2831 |
@end{Wide} |
| 2832 |
@begin{Example} |
| 2833 |
Next_Car.Owner /= @key(null) @key(and) @key(then) Next_Car.Owner.Age > 25 --@RI[ see @RefSecNum{Incomplete Type Declarations}] |
| 2834 |
N = 0 @key(or) @key(else) A(N) = Hit_Value |
| 2835 |
@end{Example} |
| 2836 |
@end{Examples} |
| 2837 |
|
| 2838 |
|
| 2839 |
@LabeledSubClause{Relational Operators and Membership Tests} |
| 2840 |
|
| 2841 |
@begin{Intro} |
| 2842 |
@redundant[@Defn{relational operator}@Defn2{Term=[operator],Sec=(relational)} |
| 2843 |
@IndexSee{Term=[comparison operator],See=(relational operator)} |
| 2844 |
@Defn{equality operator}@Defn2{Term=[operator],Sec=(equality)} |
| 2845 |
The @i(equality operators) |
| 2846 |
= (equals) and /= (not equals) are predefined for nonlimited types. |
| 2847 |
@Defn{ordering operator}@Defn2{Term=[operator],Sec=(ordering)} |
| 2848 |
The other @nt<relational_operator>s are the @i(ordering operators) |
| 2849 |
< (less than), <= (less than or |
| 2850 |
equal), > (greater than), and >= (greater than or equal). |
| 2851 |
@Defn{= operator}@Defn2{Term=[operator],Sec=(=)} |
| 2852 |
@Defn{equal operator}@Defn2{Term=[operator],Sec=(equal)} |
| 2853 |
@Defn{/= operator}@Defn2{Term=[operator],Sec=(/=)} |
| 2854 |
@Defn{not equal operator}@Defn2{Term=[operator],Sec=(not equal)} |
| 2855 |
@Defn{< operator}@Defn2{Term=[operator],Sec=(<)} |
| 2856 |
@Defn{less than operator}@Defn2{Term=[operator],Sec=(less than)} |
| 2857 |
@Defn{<= operator}@Defn2{Term=[operator],Sec=(<=)} |
| 2858 |
@Defn{less than or equal operator}@Defn2{Term=[operator],Sec=(less than or equal)} |
| 2859 |
@Defn{> operator}@Defn2{Term=[operator],Sec=(>)} |
| 2860 |
@Defn{greater than operator}@Defn2{Term=[operator],Sec=(greater than)} |
| 2861 |
@Defn{>= operator}@Defn2{Term=[operator],Sec=(>=)} |
| 2862 |
@Defn{greater than or equal operator}@Defn2{Term=[operator],Sec=(greater than or equal)} |
| 2863 |
@Defn{discrete array type} |
| 2864 |
The ordering operators are predefined for scalar |
| 2865 |
types, and for @i(discrete array types), that is, |
| 2866 |
one-dimensional array types whose components are of |
| 2867 |
a discrete type. |
| 2868 |
@begin{Ramification} |
| 2869 |
The equality operators are not defined for @i{every} nonlimited |
| 2870 |
type @em see below for the exact rule. |
| 2871 |
@end{Ramification} |
| 2872 |
|
| 2873 |
@Defn{membership test} |
| 2874 |
@Defn{in (membership test)} |
| 2875 |
@Defn{not in (membership test)} |
| 2876 |
A @i(membership test), using @key(in) or @key(not in), |
| 2877 |
determines whether or not a value |
| 2878 |
belongs to a given subtype or range, or has a tag that identifies |
| 2879 |
a type that is covered by a given type. |
| 2880 |
Membership tests are allowed for all types.] |
| 2881 |
|
| 2882 |
@end{Intro} |
| 2883 |
|
| 2884 |
@begin{Resolution} |
| 2885 |
|
| 2886 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]} |
| 2887 |
@PDefn2{Term=[expected type], |
| 2888 |
Sec=(membership test simple_expression)} |
| 2889 |
@Defn2{Term=[tested type], Sec=(of a membership test)} |
| 2890 |
The @i(tested type) of a membership test |
| 2891 |
is the type of the @nt<range> or the type |
| 2892 |
determined by the @nt<subtype_mark>. |
| 2893 |
If the tested type is tagged, then the @nt<simple_expression> shall resolve to |
| 2894 |
be of a type that @Chg{Version=[2],New=[is convertible (see |
| 2895 |
@RefSecNum{Type Conversions}) to],Old=[covers or is covered by]} the tested |
| 2896 |
type; if untagged, the expected type for the @nt<simple_expression> is |
| 2897 |
the tested type. |
| 2898 |
|
| 2899 |
@begin{Reason} |
| 2900 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]} |
| 2901 |
The part of the rule for untagged types is stated in a way |
| 2902 |
that ensures that operands |
| 2903 |
like @Chg{Version=[2],New=[a string literal],Old=[@key(null)]} are still |
| 2904 |
legal as operands of a membership test. |
| 2905 |
|
| 2906 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]} |
| 2907 |
The significance of @lquotes@;@Chg{Version=[2],New=[is convertible to], |
| 2908 |
Old=[covers or is covered by]}@rquotes@; is that we allow the |
| 2909 |
@nt<simple_expression> to be of any class-wide type that @Chg{Version=[2], |
| 2910 |
New=[could be converted to],Old=[covers]} the tested type, not just the |
| 2911 |
one rooted at the tested type.@Chg{Version=[2],New=[ This includes any |
| 2912 |
class-wide type that covers the tested type, along with class-wide interfaces |
| 2913 |
in some cases.],Old=[]} |
| 2914 |
@end{Reason} |
| 2915 |
|
| 2916 |
@end{Resolution} |
| 2917 |
|
| 2918 |
@begin{Legality} |
| 2919 |
For a membership test, |
| 2920 |
if the @nt<simple_expression> is of a tagged class-wide type, |
| 2921 |
then the tested type shall be (visibly) tagged. |
| 2922 |
@begin{Ramification} |
| 2923 |
Untagged types covered by the tagged class-wide type |
| 2924 |
are not permitted. Such types can exist if they are |
| 2925 |
descendants of a private type whose full type is tagged. |
| 2926 |
This rule is intended to avoid confusion since such derivatives |
| 2927 |
don't have their @lquotes@;own@rquotes@; tag, and hence are indistinguishable |
| 2928 |
from one another at run time once converted to a covering |
| 2929 |
class-wide type. |
| 2930 |
@end{Ramification} |
| 2931 |
@end{Legality} |
| 2932 |
|
| 2933 |
@begin{StaticSem} |
| 2934 |
The result type of a membership test is the predefined type Boolean. |
| 2935 |
|
| 2936 |
@Leading@;The equality operators are predefined for every specific |
| 2937 |
type @i(T) that is not limited, |
| 2938 |
and not an anonymous access type, |
| 2939 |
with the following specifications: |
| 2940 |
@begin(example) |
| 2941 |
@key(function) "=" (Left, Right : @RI(T)) @key(return) Boolean |
| 2942 |
@key(function) "/="(Left, Right : @RI(T)) @key(return) Boolean |
| 2943 |
@end(example) |
| 2944 |
|
| 2945 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]} |
| 2946 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The following additional equality |
| 2947 |
operators for the |
| 2948 |
@i<universal_access> type are declared in package Standard for use with |
| 2949 |
anonymous access types:]} |
| 2950 |
@begin(example) |
| 2951 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2952 |
@ChgAdded{Version=[2],Text=[@key<function> "=" (Left, Right : @i<universal_access>) @key<return> Boolean |
| 2953 |
@key<function> "/="(Left, Right : @i<universal_access>) @key<return> Boolean]} |
| 2954 |
@end(example) |
| 2955 |
|
| 2956 |
@Leading@;The ordering operators are predefined for every specific |
| 2957 |
scalar type @i(T), and for every discrete array type |
| 2958 |
@i(T), with the following specifications: |
| 2959 |
@begin(example) |
| 2960 |
@key(function) "<" (Left, Right : @RI(T)) @key(return) Boolean |
| 2961 |
@key(function) "<="(Left, Right : @RI(T)) @key(return) Boolean |
| 2962 |
@key(function) ">" (Left, Right : @RI(T)) @key(return) Boolean |
| 2963 |
@key(function) ">="(Left, Right : @RI(T)) @key(return) Boolean |
| 2964 |
@end(example) |
| 2965 |
@end{StaticSem} |
| 2966 |
|
| 2967 |
@begin{Resolution} |
| 2968 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00420-01]} |
| 2969 |
@ChgAdded{Version=[2],Type=[Leading],Text=[At least one of the operands of an equality |
| 2970 |
operator for @i<universal_access> shall be of a specific anonymous access type. |
| 2971 |
Unless the predefined equality operator is identified using an expanded name |
| 2972 |
with @nt{prefix} denoting the package Standard, neither operand shall be of an |
| 2973 |
access-to-object type whose designated type is @i<D> or @i<D>'Class, where |
| 2974 |
@i<D> has a user-defined primitive equality operator such that:]} |
| 2975 |
@begin{Itemize} |
| 2976 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2977 |
@ChgAdded{Version=[2],Text=[its result type is Boolean;]} |
| 2978 |
|
| 2979 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2980 |
@ChgAdded{Version=[2],Text=[it is declared immediately within the same |
| 2981 |
declaration list as @i<D>; and]} |
| 2982 |
|
| 2983 |
@ChgRef{Version=[2],Kind=[Added]} |
| 2984 |
@ChgAdded{Version=[2],Text=[at least one of its operands is an |
| 2985 |
access parameter with designated type @i<D>.]} |
| 2986 |
@end{Itemize} |
| 2987 |
|
| 2988 |
@begin{Reason} |
| 2989 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2990 |
@ChgAdded{Version=[2],Text=[The first sentence prevents compatibility |
| 2991 |
problems by ensuring that these operators are not used for named access |
| 2992 |
types. Also, universal access types do not count for the purposes of this |
| 2993 |
rule. Otherwise, equality expressions like (X = @key{null}) would be |
| 2994 |
ambiguous for normal access types.]} |
| 2995 |
|
| 2996 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2997 |
@ChgAdded{Version=[2],Text=[The rest of the rule makes it possible to |
| 2998 |
call (including a dispatching call) user-defined "=" operators for anonymous |
| 2999 |
access-to-object types (they'd be hidden |
| 3000 |
otherwise), and to write user-defined "=" operations for anonymous access |
| 3001 |
types (by making it possible to see the universal operator using the |
| 3002 |
Standard prefix).]} |
| 3003 |
@end{Reason} |
| 3004 |
@begin{Ramification} |
| 3005 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3006 |
@ChgAdded{Version=[2],Text=[We don't need a similar rule for anonymous |
| 3007 |
access-to-subprogram types because they can't be primitive for any type. |
| 3008 |
Note that any non-primitive user-defined equality operators still are hidden |
| 3009 |
by the universal operators; they'll have to be called with a package |
| 3010 |
prefix, but they are likely to be very uncommon.]} |
| 3011 |
@end{Ramification} |
| 3012 |
@end{Resolution} |
| 3013 |
|
| 3014 |
@begin{Legality} |
| 3015 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]} |
| 3016 |
@ChgAdded{Version=[2],Text=[At least one of the operands of the equality |
| 3017 |
operators for @i<universal_access> shall be of type @i<universal_access>, or |
| 3018 |
both shall be of access-to-object types, or both shall be of |
| 3019 |
access-to-subprogram types. Further:]} |
| 3020 |
@begin{Itemize} |
| 3021 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3022 |
@ChgAdded{Version=[2],Text=[When both are of access-to-object types, the |
| 3023 |
designated types shall be the same or one shall cover the |
| 3024 |
other, and if the designated types are elementary or array types, |
| 3025 |
then the designated subtypes shall statically match;]} |
| 3026 |
|
| 3027 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3028 |
@ChgAdded{Version=[2],Text=[When both are of access-to-subprogram types, |
| 3029 |
the designated profiles shall be subtype conformant.]} |
| 3030 |
@end{Itemize} |
| 3031 |
@begin{Reason} |
| 3032 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3033 |
@ChgAdded{Version=[2],Text=[We don't want to allow completely arbitrary |
| 3034 |
comparisons, as we don't want to insist that all access types are represented |
| 3035 |
in ways that are convertible to one another. For instance, a compiler could |
| 3036 |
use completely separate address spaces or incompatible representations. |
| 3037 |
Instead, we allow compares if there exists an access parameter to which both |
| 3038 |
operands could be converted. Since the user could write such an subprogram, |
| 3039 |
and any reasonable meaning for "=" would allow using it in such a subprogram, |
| 3040 |
this doesn't impose any further restrictions on Ada implementations.]} |
| 3041 |
@end{Reason} |
| 3042 |
@end{Legality} |
| 3043 |
|
| 3044 |
@begin{RunTime} |
| 3045 |
For discrete types, the predefined relational operators are |
| 3046 |
defined in terms of corresponding mathematical operations on |
| 3047 |
the position numbers of the values of the operands. |
| 3048 |
|
| 3049 |
For real types, the predefined relational operators are |
| 3050 |
defined in terms of the corresponding mathematical operations |
| 3051 |
on the values of the operands, subject to the accuracy of the |
| 3052 |
type. |
| 3053 |
@begin{Ramification} |
| 3054 |
For floating point types, the results of comparing |
| 3055 |
@i(nearly) equal values depends on the accuracy of |
| 3056 |
the implementation |
| 3057 |
(see @RefSec{Model of Floating Point Arithmetic} |
| 3058 |
for implementations that support the Numerics Annex). |
| 3059 |
@end{Ramification} |
| 3060 |
@begin{ImplNote} |
| 3061 |
On a machine with signed zeros, |
| 3062 |
if the generated code generates both plus zero and minus zero, |
| 3063 |
plus and minus zero must be equal |
| 3064 |
by the predefined equality operators. |
| 3065 |
@end{ImplNote} |
| 3066 |
|
| 3067 |
Two access-to-object values are equal if they designate the same |
| 3068 |
object, or if both are equal to the null value of the access type. |
| 3069 |
|
| 3070 |
Two access-to-subprogram values are equal if they are the |
| 3071 |
result of the same evaluation of an Access @nt<attribute_reference>, |
| 3072 |
or if both |
| 3073 |
are equal to the null value of the access type. Two |
| 3074 |
access-to-subprogram values are unequal if they designate |
| 3075 |
different subprograms. |
| 3076 |
@PDefn{unspecified} |
| 3077 |
@Redundant[It is unspecified whether |
| 3078 |
two access values that designate the same subprogram but are |
| 3079 |
the result of distinct evaluations of |
| 3080 |
Access @nt<attribute_reference>s are equal |
| 3081 |
or unequal.] |
| 3082 |
@begin{Reason} |
| 3083 |
This allows each Access @nt<attribute_reference> |
| 3084 |
for a subprogram to designate a distinct @lquotes@;wrapper@rquotes@; subprogram |
| 3085 |
if necessary to support an indirect call. |
| 3086 |
@end{Reason} |
| 3087 |
|
| 3088 |
@Defn2{Term=[equality operator],Sec=(special inheritance rule for tagged types)} |
| 3089 |
For a type extension, predefined equality |
| 3090 |
is defined in terms of the primitive @Redundant[(possibly |
| 3091 |
user-defined)] equals operator |
| 3092 |
of the parent type and of any tagged components of the |
| 3093 |
extension part, and predefined equality |
| 3094 |
for any other components not inherited from the parent type. |
| 3095 |
@begin{Ramification} |
| 3096 |
Two values of a type extension are not equal if there is |
| 3097 |
a @nt<variant_part> in the extension part and the two |
| 3098 |
values have different @nt<variant>s present. |
| 3099 |
This is a ramification of the requirement that a |
| 3100 |
discriminant governing such a @nt<variant_part> has to be a @lquotes@;new@rquotes@; |
| 3101 |
discriminant, and so has to be equal in the two values for |
| 3102 |
the values to be equal. Note that @nt<variant_part>s in |
| 3103 |
the parent part need not match if the primitive equals operator |
| 3104 |
for the parent type considers them equal. |
| 3105 |
|
| 3106 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00349-01]} |
| 3107 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The full type extension's operation |
| 3108 |
is used for a private extension. This follows as only full types have parent types; |
| 3109 |
the type specified in a private extension is an ancestor, but not necessarily |
| 3110 |
the parent type. For instance, in:]} |
| 3111 |
@begin(Example) |
| 3112 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3113 |
@Chg{Version=[2],New=[@key{with} Pak1; |
| 3114 |
@key{package} Pak2 @key{is} |
| 3115 |
@key{type} Typ3 @key{is} @key{new} Pak1.Typ1 @key{with} @key{private}; |
| 3116 |
@key{private} |
| 3117 |
@key{type} Typ3 @key{is} @key{new} Pak1.Typ2 @key{with} @key{null} @key{record}; |
| 3118 |
@key{end} Pak2;],Old=[]} |
| 3119 |
@end(Example) |
| 3120 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3121 |
@Chg{Version=[2],New=[the parent type is Pak1.Typ2, not Pak1.Typ1, and the |
| 3122 |
equality operator of Pak1.Typ2 is used to create predefined equality for |
| 3123 |
Typ3.],Old=[]} |
| 3124 |
@end{Ramification} |
| 3125 |
|
| 3126 |
For a private type, if its full type is tagged, predefined |
| 3127 |
equality is defined in terms of the primitive equals operator of the |
| 3128 |
full type; if the full type is untagged, predefined equality |
| 3129 |
for the private type is that of its full type. |
| 3130 |
|
| 3131 |
@Leading@Defn{matching components} |
| 3132 |
For other composite types, the predefined equality operators |
| 3133 |
@Redundant[(and |
| 3134 |
certain other predefined operations on composite types @em |
| 3135 |
see @RefSecNum(Logical Operators and Short-circuit Control Forms) |
| 3136 |
and @RefSecNum(Type Conversions))] are defined |
| 3137 |
in terms of the corresponding operation on |
| 3138 |
@i(matching components), defined as follows: |
| 3139 |
@begin(itemize) |
| 3140 |
For two composite objects or values of the same non-array type, |
| 3141 |
matching components are those that correspond to the |
| 3142 |
same @nt<component_declaration> or @nt<discriminant_specification>; |
| 3143 |
|
| 3144 |
For two one-dimensional arrays of the same type, matching components are |
| 3145 |
those (if any) whose index values match in the following sense: the |
| 3146 |
lower bounds of the index ranges are defined to match, and the successors |
| 3147 |
of matching indices are defined to match; |
| 3148 |
|
| 3149 |
For two multidimensional arrays of the same type, matching components |
| 3150 |
are those whose index values match in successive index positions. |
| 3151 |
@end(itemize) |
| 3152 |
|
| 3153 |
The analogous definitions apply if the types of the two objects or values |
| 3154 |
are convertible, rather than being the same. |
| 3155 |
@begin{Discussion} |
| 3156 |
Ada 83 seems to |
| 3157 |
omit this part of the definition, though it is used in array type |
| 3158 |
conversions. See @RefSecNum{Type Conversions}. |
| 3159 |
@end{Discussion} |
| 3160 |
|
| 3161 |
@Leading@;Given the above definition of matching components, |
| 3162 |
the result of the predefined equals operator for composite types (other than |
| 3163 |
for those composite types covered earlier) is defined as follows: |
| 3164 |
@begin(Itemize) |
| 3165 |
If there are no components, the result is defined to be True; |
| 3166 |
|
| 3167 |
If there are unmatched components, the result is defined to be False; |
| 3168 |
|
| 3169 |
Otherwise, the result is defined in terms of |
| 3170 |
the primitive equals operator for any |
| 3171 |
matching tagged components, and the predefined equals for any |
| 3172 |
matching untagged components. |
| 3173 |
@begin{Reason} |
| 3174 |
This asymmetry between tagged and untagged components is |
| 3175 |
necessary to preserve upward compatibility and corresponds |
| 3176 |
with the corresponding situation with generics, where the |
| 3177 |
predefined operations @lquotes@;reemerge@rquotes@; in a generic for |
| 3178 |
untagged types, but do not for tagged types. Also, only |
| 3179 |
tagged types support user-defined assignment |
| 3180 |
(see @RefSecNum{User-Defined Assignment and Finalization}), |
| 3181 |
so only tagged types |
| 3182 |
can fully handle levels of indirection in the implementation |
| 3183 |
of the type. For untagged types, one reason for |
| 3184 |
a user-defined equals operator might be to allow values with different |
| 3185 |
bounds or discriminants to compare equal in certain cases. |
| 3186 |
When such values are matching components, the bounds or discriminants |
| 3187 |
will necessarily match anyway if the |
| 3188 |
discriminants of the enclosing values match. |
| 3189 |
@end{Reason} |
| 3190 |
@end(Itemize) |
| 3191 |
@begin{Ramification} |
| 3192 |
Two null arrays of the same type are always equal; |
| 3193 |
two null records of the same type are always equal. |
| 3194 |
|
| 3195 |
Note that if a composite object has a component |
| 3196 |
of a floating point type, and the floating point type |
| 3197 |
has both a plus and minus zero, which are considered |
| 3198 |
equal by the predefined equality, then a block compare |
| 3199 |
cannot be used for the predefined composite equality. |
| 3200 |
Of course, with user-defined equals operators for tagged components, |
| 3201 |
a block compare breaks down anyway, so this is not the only |
| 3202 |
special case that requires component-by-component comparisons. |
| 3203 |
On a one's complement machine, a similar situation might |
| 3204 |
occur for integer types, since one's complement machines |
| 3205 |
typically have both a plus and minus (integer) zero. |
| 3206 |
@end{Ramification} |
| 3207 |
@begin{Honest} |
| 3208 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]} |
| 3209 |
@ChgAdded{Version=[2],Text=[For a component with an anonymous access type, |
| 3210 |
@lquotes@;predefined equality@rquotes@; is that defined for the |
| 3211 |
@i<universal_access> type (anonymous access types have no equality operators |
| 3212 |
of their own).]} |
| 3213 |
|
| 3214 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3215 |
@ChgAdded{Version=[2],Text=[For a component with a tagged type @i{T}, |
| 3216 |
@lquotes@;the primitive equals operator@rquotes@; is the one with two |
| 3217 |
parameters of @i(T) which returns Boolean. We're not talking about some |
| 3218 |
random other primitive function named "=".]} |
| 3219 |
@end{Honest} |
| 3220 |
|
| 3221 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0016],ARef=[AI95-00123-01]} |
| 3222 |
@ChgAdded{Version=[1],Text=[For any composite type, the order in which "=" |
| 3223 |
is called for components is unspecified. Furthermore, if the result can be |
| 3224 |
determined before calling "=" on some components, it is unspecified whether |
| 3225 |
"=" is called on those components.@PDefn{Unspecified}]} |
| 3226 |
|
| 3227 |
The predefined "/=" operator gives the complementary result |
| 3228 |
to the predefined "=" operator. |
| 3229 |
@begin{Ramification} |
| 3230 |
Furthermore, |
| 3231 |
if the user defines an "=" operator that returns Boolean, |
| 3232 |
then a "/=" operator is implicitly declared in terms of |
| 3233 |
the user-defined "=" operator so as to give the complementary |
| 3234 |
result. See @RefSecNum(Overloading of Operators). |
| 3235 |
@end{Ramification} |
| 3236 |
|
| 3237 |
@Defn{lexicographic order} |
| 3238 |
For a discrete array type, the predefined ordering operators |
| 3239 |
correspond to @i(lexicographic order) using the predefined order |
| 3240 |
relation of the component type: A null array is lexicographically |
| 3241 |
less than any array having at least one component. |
| 3242 |
In the case of nonnull arrays, the left operand is lexicographically |
| 3243 |
less than the right operand if the first component of |
| 3244 |
the left operand is less than that of the right; otherwise |
| 3245 |
the left operand is lexicographically less than the right operand |
| 3246 |
only if their first components are equal and the tail of the |
| 3247 |
left operand is lexicographically less than that of the right (the |
| 3248 |
@i(tail) consists of the remaining components beyond the first and |
| 3249 |
can be null). |
| 3250 |
|
| 3251 |
@PDefn2{Term=[evaluation], Sec=(membership test)} |
| 3252 |
For the evaluation of a membership test, |
| 3253 |
the @nt<simple_expression> and the @nt<range> (if any) are evaluated |
| 3254 |
in an arbitrary order. |
| 3255 |
|
| 3256 |
@Leading@;A membership test using |
| 3257 |
@key(in) yields the result True if: |
| 3258 |
@begin(itemize) |
| 3259 |
The tested type is scalar, and the value of |
| 3260 |
the @nt<simple_expression> belongs to the given @nt<range>, or |
| 3261 |
the range of the named subtype; or |
| 3262 |
@begin{Ramification} |
| 3263 |
The scalar membership test only does a range check. |
| 3264 |
It does not perform any other check, such as whether |
| 3265 |
a value falls in a @lquotes@;hole@rquotes@; of a @lquotes@;holey@rquotes@; enumeration type. |
| 3266 |
The Pos attribute function can be used for that purpose. |
| 3267 |
|
| 3268 |
Even though Standard.Float is an unconstrained subtype, |
| 3269 |
the test @lquotes@;X in Float@rquotes@; will still return False |
| 3270 |
(presuming the evaluation of X does not raise Constraint_Error) |
| 3271 |
when X is outside Float'Range. |
| 3272 |
@end{Ramification} |
| 3273 |
|
| 3274 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 3275 |
@ChgAdded{Version=[2],Type=[Leading],Text=[]}@ChgNote{To get conditional Leading} |
| 3276 |
The tested type is not scalar, and |
| 3277 |
the value of the @nt<simple_expression> satisfies any constraints |
| 3278 |
of the named subtype, and@Chg{Version=[2],New=[:],Old=[, if the type of |
| 3279 |
the @nt{simple_expression} |
| 3280 |
is class-wide, the value has a tag that identifies a type covered by |
| 3281 |
the tested type.]} |
| 3282 |
@begin{Inneritemize} |
| 3283 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]} |
| 3284 |
@ChgAdded{Version=[2],Text=[if the type of the @nt{simple_expression} is |
| 3285 |
class-wide, the value has a tag that identifies a type covered by the |
| 3286 |
tested type;]} |
| 3287 |
@begin{Ramification} |
| 3288 |
Note that the tag is not checked if the @nt{simple_expression} is of a |
| 3289 |
specific type. |
| 3290 |
@end{Ramification} |
| 3291 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]} |
| 3292 |
@ChgAdded{Version=[2],Text=[if the tested type is an access type and the |
| 3293 |
named subtype excludes null, the value of the @nt{simple_expression} is |
| 3294 |
not null.]} |
| 3295 |
@end{Inneritemize} |
| 3296 |
@end(itemize) |
| 3297 |
|
| 3298 |
Otherwise the test yields the result False. |
| 3299 |
|
| 3300 |
A membership test using @key(not in) gives the complementary result to |
| 3301 |
the corresponding membership test using @key(in). |
| 3302 |
@end{RunTime} |
| 3303 |
|
| 3304 |
@begin{ImplReq} |
| 3305 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0016],ARef=[AI95-00123-01]} |
| 3306 |
@ChgAdded{Version=[1],Text=[For all nonlimited types declared in |
| 3307 |
language-defined packages, the "=" and "/=" operators of the type shall behave |
| 3308 |
as if they were the predefined equality operators for the purposes of the |
| 3309 |
equality of composite types and generic formal types.]} |
| 3310 |
@begin{Ramification} |
| 3311 |
@ChgRef{Version=[1],Kind=[Added]} |
| 3312 |
@ChgAdded{Version=[1],Text=[If any language-defined types are implemented with |
| 3313 |
a user-defined "=" operator, then either the full type must be tagged, or |
| 3314 |
the compiler must |
| 3315 |
use @lquotes@;magic@rquotes@; to implement equality for this type. A normal |
| 3316 |
user-defined "=" operator for an untagged type does @i{not} meet this |
| 3317 |
requirement.]} |
| 3318 |
@end{Ramification} |
| 3319 |
@end{ImplReq} |
| 3320 |
|
| 3321 |
@begin{Notes} |
| 3322 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00230-01]} |
| 3323 |
@ChgDeleted{Version=[2],Text=[No exception is ever raised by a membership test, |
| 3324 |
by a predefined ordering operator, or by a predefined equality operator for an |
| 3325 |
elementary type, but an exception can be raised by the evaluation of the |
| 3326 |
operands. A predefined equality operator for a composite type can only raise an |
| 3327 |
exception if the type has a tagged part whose primitive equals operator |
| 3328 |
propagates an exception.]} |
| 3329 |
|
| 3330 |
If a composite type has components that depend on discriminants, two values |
| 3331 |
of this type have matching components if and only if their |
| 3332 |
discriminants are equal. Two nonnull arrays have matching components |
| 3333 |
if and only if the length of each dimension is the same for both. |
| 3334 |
@end{Notes} |
| 3335 |
|
| 3336 |
@begin{Examples} |
| 3337 |
@Leading@keepnext@i(Examples of expressions involving relational operators and |
| 3338 |
membership tests:) |
| 3339 |
@begin{Example} |
| 3340 |
X /= Y |
| 3341 |
|
| 3342 |
"" < "A" @key(and) "A" < "Aa" --@RI[ True] |
| 3343 |
"Aa" < "B" @key(and) "A" < "A " --@RI[ True] |
| 3344 |
|
| 3345 |
My_Car = @key(null) --@RI[ true if My_Car has been set to null (see @RefSecNum{Incomplete Type Declarations})] |
| 3346 |
My_Car = Your_Car --@RI[ true if we both share the same car] |
| 3347 |
My_Car.@key[all] = Your_Car.@key[all] --@RI[ true if the two cars are identical] |
| 3348 |
|
| 3349 |
N @key(not) @key(in) 1 .. 10 --@RI[ range membership test] |
| 3350 |
Today @key(in) Mon .. Fri --@RI[ range membership test] |
| 3351 |
Today @key(in) Weekday --@RI[ subtype membership test (see @RefSecNum{Enumeration Types})] |
| 3352 |
Archive @key(in) Disk_Unit --@RI[ subtype membership test (see @RefSecNum{Variant Parts and Discrete Choices})] |
| 3353 |
Tree.@key(all) @key(in) Addition'Class --@RI[ class membership test (see @RefSecNum{Type Extensions})] |
| 3354 |
@end{Example} |
| 3355 |
@end{Examples} |
| 3356 |
|
| 3357 |
@begin{Extend83} |
| 3358 |
@Defn{extensions to Ada 83} |
| 3359 |
Membership tests can be used to test the tag of a class-wide value. |
| 3360 |
|
| 3361 |
Predefined equality for a composite type |
| 3362 |
is defined in terms of the primitive equals operator |
| 3363 |
for tagged components or the parent part. |
| 3364 |
@end{Extend83} |
| 3365 |
|
| 3366 |
@begin{DiffWord83} |
| 3367 |
The term @lquotes@;membership test@rquotes@; refers to the @nt<relation> "X in S" rather |
| 3368 |
to simply the reserved word @key(in) or @key(not in). |
| 3369 |
|
| 3370 |
We use the term @lquotes@;equality operator@rquotes@; to refer to both |
| 3371 |
the = (equals) and /= (not equals) operators. |
| 3372 |
Ada 83 referred to = as @i(the) equality operator, and |
| 3373 |
/= as the inequality operator. The new wording is more |
| 3374 |
consistent with the ISO 10646 name for "=" (equals sign) and provides a |
| 3375 |
category similar to @lquotes@;ordering operator@rquotes@; to refer to both |
| 3376 |
= and /=. |
| 3377 |
|
| 3378 |
We have changed the term @lquotes@;catenate@rquotes@; to @lquotes@;concatenate@rquotes@;. |
| 3379 |
@end{DiffWord83} |
| 3380 |
|
| 3381 |
@begin{Extend95} |
| 3382 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00420-01]} |
| 3383 |
@Chg{Version=[2],New=[@Defn{extensions to Ada 95}The @i{universal_access} |
| 3384 |
equality operators are new. They provide equality operations (most importantly, |
| 3385 |
testing against @key{null}) for anonymous access types.],Old=[]} |
| 3386 |
@end{Extend95} |
| 3387 |
|
| 3388 |
@begin{DiffWord95} |
| 3389 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0016],ARef=[AI95-00123-01]} |
| 3390 |
@Chg{Version=[2],New=[@b<Corrigendum:> Wording was added to clarify that |
| 3391 |
the order of calls (and whether the calls are made at all) on "=" for |
| 3392 |
components is unspecified. Also clarified that "=" must compose properly for |
| 3393 |
language-defined types.],Old=[]} |
| 3394 |
|
| 3395 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]} |
| 3396 |
@Chg{Version=[2],New=[Memberships were adjusted to allow interfaces which don't |
| 3397 |
cover the tested type, in order to be consistent with type |
| 3398 |
conversions.],Old=[]} |
| 3399 |
@end{DiffWord95} |
| 3400 |
|
| 3401 |
|
| 3402 |
@LabeledSubClause{Binary Adding Operators} |
| 3403 |
|
| 3404 |
@begin{StaticSem} |
| 3405 |
@Leading@Defn{binary adding operator}@Defn2{Term=[operator],Sec=(binary adding)} |
| 3406 |
@Defn{+ operator}@Defn2{Term=[operator],Sec=(+)} |
| 3407 |
@Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)} |
| 3408 |
@Defn{- operator}@Defn2{Term=[operator],Sec=(-)} |
| 3409 |
@Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)} |
| 3410 |
The binary adding operators + (addition) and @en (subtraction) are predefined |
| 3411 |
for every specific numeric type @i(T) with their |
| 3412 |
conventional meaning. |
| 3413 |
They have the following specifications: |
| 3414 |
@begin(example) |
| 3415 |
@key(function) "+"(Left, Right : @RI(T)) @key(return) @RI(T) |
| 3416 |
@key(function) "-"(Left, Right : @RI(T)) @key(return) @RI(T) |
| 3417 |
@end(example) |
| 3418 |
|
| 3419 |
@Leading@Defn{& operator}@Defn2{Term=[operator],Sec=(&)} |
| 3420 |
@Defn{ampersand operator}@Defn2{Term=[operator],Sec=(ampersand)} |
| 3421 |
@Defn{concatenation operator}@Defn2{Term=[operator],Sec=(concatenation)} |
| 3422 |
@IndexSee{Term=[catenation operator],See=(concatenation operator)} |
| 3423 |
The concatenation operators & are predefined for |
| 3424 |
every nonlimited, |
| 3425 |
one-dimensional array type @i(T) with component type @i(C). |
| 3426 |
They have the following specifications: |
| 3427 |
@begin(example) |
| 3428 |
@key(function) "&"(Left : @RI(T); Right : @RI(T)) @key(return) @RI(T) |
| 3429 |
@key(function) "&"(Left : @RI(T); Right : @RI(C)) @key(return) @RI(T) |
| 3430 |
@key(function) "&"(Left : @RI(C); Right : @RI(T)) @key(return) @RI(T) |
| 3431 |
@key(function) "&"(Left : @RI(C); Right : @RI(C)) @key(return) @RI(T) |
| 3432 |
@end(example) |
| 3433 |
@end{StaticSem} |
| 3434 |
|
| 3435 |
@begin{RunTime} |
| 3436 |
|
| 3437 |
@Leading@PDefn2{Term=[evaluation], Sec=(concatenation)} |
| 3438 |
For the evaluation of a concatenation with result type @i(T), |
| 3439 |
if both operands are of type @i(T), the result of the concatenation |
| 3440 |
is a one-dimensional array whose length is the sum of the lengths |
| 3441 |
of its operands, and whose components comprise the components of |
| 3442 |
the left operand followed by the components of the right operand. |
| 3443 |
If the left operand is a null array, the result of the |
| 3444 |
concatenation is the right operand. |
| 3445 |
Otherwise, the lower bound of the result is determined as |
| 3446 |
follows: |
| 3447 |
@begin(Itemize) |
| 3448 |
If the ultimate ancestor of the array type was defined |
| 3449 |
by a @nt<constrained_array_definition>, then |
| 3450 |
the lower bound of the result is that of the index subtype; |
| 3451 |
@begin(Reason) |
| 3452 |
This rule avoids Constraint_Error when using concatenation |
| 3453 |
on an array type whose first subtype is constrained. |
| 3454 |
@end(Reason) |
| 3455 |
|
| 3456 |
If the ultimate ancestor of the array type was defined |
| 3457 |
by an @nt<unconstrained_array_definition>, then |
| 3458 |
the lower bound of the result is that of the left operand. |
| 3459 |
@end(Itemize) |
| 3460 |
|
| 3461 |
@Redundant[The upper bound is determined by the lower bound and the length.] |
| 3462 |
@IndexCheck{Index_Check} |
| 3463 |
A check is made that the upper bound of the result of the |
| 3464 |
concatenation belongs to the range of the index subtype, unless the |
| 3465 |
result is a null array. |
| 3466 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 3467 |
Constraint_Error is raised if this check fails. |
| 3468 |
|
| 3469 |
If either operand is of the component type @i(C), the result of the |
| 3470 |
concatenation is given by the above rules, using in place of such an operand |
| 3471 |
an array having this operand as its only component (converted |
| 3472 |
to the component subtype) |
| 3473 |
and having the lower bound |
| 3474 |
of the index subtype of the array type as its lower bound. |
| 3475 |
@PDefn2{Term=[implicit subtype conversion],Sec=(operand of concatenation)} |
| 3476 |
@begin{Ramification} |
| 3477 |
The conversion might raise Constraint_Error. |
| 3478 |
The conversion provides @lquotes@;sliding@rquotes@; |
| 3479 |
for the component in the case of an array-of-arrays, consistent with |
| 3480 |
the normal Ada 95 rules that allow sliding during parameter passing. |
| 3481 |
@end{Ramification} |
| 3482 |
|
| 3483 |
@Defn2{Term=[assignment operation], Sec=(during evaluation of concatenation)} |
| 3484 |
The result of a concatenation is defined in terms of an |
| 3485 |
assignment to an anonymous object, |
| 3486 |
as for any function call (see @RefSecNum{Return Statements}). |
| 3487 |
@begin{Ramification} |
| 3488 |
This implies that value adjustment is performed as appropriate |
| 3489 |
@em see @RefSecNum{User-Defined Assignment and Finalization}. |
| 3490 |
We don't bother saying this for other predefined operators, |
| 3491 |
even though they are all function calls, |
| 3492 |
because this is the only one where it matters. |
| 3493 |
It is the only one that can return a value having controlled parts. |
| 3494 |
@end{Ramification} |
| 3495 |
@end{RunTime} |
| 3496 |
|
| 3497 |
@begin{Notes} |
| 3498 |
As for all predefined operators on modular types, the binary adding |
| 3499 |
operators + and @en on modular types include a final |
| 3500 |
reduction modulo the modulus if the result is outside |
| 3501 |
the base range of the type. |
| 3502 |
@begin{ImplNote} |
| 3503 |
A full "modulus" operation need not be performed after |
| 3504 |
addition or subtraction of modular types. For binary moduli, |
| 3505 |
a simple mask is sufficient. For nonbinary moduli, a check after |
| 3506 |
addition to see if the value is greater than the high bound of |
| 3507 |
the base range can be followed by a conditional subtraction of the modulus. |
| 3508 |
Conversely, a check after subtraction to see if a "borrow" was |
| 3509 |
performed can be followed by a conditional addition of the modulus. |
| 3510 |
@end{ImplNote} |
| 3511 |
@end{Notes} |
| 3512 |
|
| 3513 |
@begin{Examples} |
| 3514 |
@Leading@keepnext@i(Examples of expressions involving binary adding operators:) |
| 3515 |
@begin{Example} |
| 3516 |
Z + 0.1 --@RI[ Z has to be of a real type ] |
| 3517 |
|
| 3518 |
"A" & "BCD" --@RI[ concatenation of two string literals] |
| 3519 |
'A' & "BCD" --@RI[ concatenation of a character literal and a string literal] |
| 3520 |
'A' & 'A' --@RI[ concatenation of two character literals ] |
| 3521 |
@end{Example} |
| 3522 |
@end{Examples} |
| 3523 |
|
| 3524 |
@begin{Inconsistent83} |
| 3525 |
@Defn{inconsistencies with Ada 83} |
| 3526 |
The lower bound of the result of concatenation, |
| 3527 |
for a type whose first subtype is constrained, is |
| 3528 |
now that of the index subtype. This is inconsistent with Ada 83, |
| 3529 |
but generally only for Ada 83 programs that raise Constraint_Error. |
| 3530 |
For example, the concatenation operator in |
| 3531 |
@begin(Example) |
| 3532 |
X : @key(array)(1..10) @key(of) Integer; |
| 3533 |
@key(begin) |
| 3534 |
X := X(6..10) & X(1..5); |
| 3535 |
@end(Example) |
| 3536 |
|
| 3537 |
would raise Constraint_Error in Ada 83 (because |
| 3538 |
the bounds of the result of the concatenation would be 6..15, which is outside |
| 3539 |
of 1..10), |
| 3540 |
but would succeed and swap the halves of X (as expected) in Ada 95. |
| 3541 |
@end{Inconsistent83} |
| 3542 |
|
| 3543 |
@begin{Extend83} |
| 3544 |
@Defn{extensions to Ada 83} |
| 3545 |
Concatenation is now useful for array types whose |
| 3546 |
first subtype is constrained. |
| 3547 |
When the result type of a concatenation |
| 3548 |
is such an array type, |
| 3549 |
Constraint_Error is avoided by effectively |
| 3550 |
first sliding the left operand (if nonnull) so that |
| 3551 |
its lower bound is that of the index subtype. |
| 3552 |
@end{Extend83} |
| 3553 |
|
| 3554 |
@LabeledSubClause{Unary Adding Operators} |
| 3555 |
|
| 3556 |
@begin{StaticSem} |
| 3557 |
@Leading@Defn{unary adding operator}@Defn2{Term=[operator],Sec=(unary adding)} |
| 3558 |
@Defn{+ operator}@Defn2{Term=[operator],Sec=(+)} |
| 3559 |
@Defn{plus operator}@Defn2{Term=[operator],Sec=(plus)} |
| 3560 |
@Defn{- operator}@Defn2{Term=[operator],Sec=(-)} |
| 3561 |
@Defn{minus operator}@Defn2{Term=[operator],Sec=(minus)} |
| 3562 |
The unary adding operators + (identity) and @en (negation) are predefined |
| 3563 |
for every specific numeric type @i(T) with their |
| 3564 |
conventional meaning. |
| 3565 |
They have the following specifications: |
| 3566 |
@begin(example) |
| 3567 |
@key(function) "+"(Right : @RI(T)) @key(return) @RI(T) |
| 3568 |
@key(function) "-"(Right : @RI(T)) @key(return) @RI(T) |
| 3569 |
@end(example) |
| 3570 |
@end{StaticSem} |
| 3571 |
|
| 3572 |
@begin{Notes} |
| 3573 |
For modular integer types, the unary adding operator @en, when |
| 3574 |
given a nonzero operand, returns the result of subtracting |
| 3575 |
the value of the operand from the modulus; |
| 3576 |
for a zero operand, the result is zero. |
| 3577 |
@end{Notes} |
| 3578 |
|
| 3579 |
@LabeledSubClause{Multiplying Operators} |
| 3580 |
|
| 3581 |
@begin{StaticSem} |
| 3582 |
@Leading@Defn{multiplying operator}@Defn2{Term=[operator],Sec=(multiplying)} |
| 3583 |
@Defn{* operator}@Defn2{Term=[operator],Sec=(*)} |
| 3584 |
@Defn{multiply operator}@Defn2{Term=[operator],Sec=(multiply)} |
| 3585 |
@Defn{times operator}@Defn2{Term=[operator],Sec=(times)} |
| 3586 |
@Defn{/ operator}@Defn2{Term=[operator],Sec=(/)} |
| 3587 |
@Defn{divide operator}@Defn2{Term=[operator],Sec=(divide)} |
| 3588 |
@Defn{mod operator}@Defn2{Term=[operator],Sec=(mod)} |
| 3589 |
@Defn{rem operator}@Defn2{Term=[operator],Sec=(rem)} |
| 3590 |
The multiplying operators * (multiplication), / (division), |
| 3591 |
@key(mod) (modulus), and @key(rem) (remainder) |
| 3592 |
are predefined for every specific integer type @i(T): |
| 3593 |
@begin(example) |
| 3594 |
@key(function) "*" (Left, Right : @RI(T)) @key(return) @RI(T) |
| 3595 |
@key(function) "/" (Left, Right : @RI(T)) @key(return) @RI(T) |
| 3596 |
@key(function) "@key(mod)"(Left, Right : @RI(T)) @key(return) @RI(T) |
| 3597 |
@key(function) "@key(rem)"(Left, Right : @RI(T)) @key(return) @RI(T) |
| 3598 |
@end(example) |
| 3599 |
|
| 3600 |
Signed integer multiplication has its conventional meaning. |
| 3601 |
|
| 3602 |
@Leading@keepnext@;Signed integer division and remainder are defined by the relation: |
| 3603 |
@begin(example) |
| 3604 |
A = (A/B)*B + (A @key(rem) B) |
| 3605 |
@end(example) |
| 3606 |
|
| 3607 |
@Leading@;where (A @key(rem) B) has the sign of A and an absolute value less than |
| 3608 |
the absolute value of B. Signed integer division satisfies the identity: |
| 3609 |
@begin(example) |
| 3610 |
(-A)/B = -(A/B) = A/(-B) |
| 3611 |
@end(example) |
| 3612 |
|
| 3613 |
@begin{Wide} |
| 3614 |
@Leading@;The signed integer modulus operator is defined such |
| 3615 |
that the result of A @key(mod) B has |
| 3616 |
the sign of B and an absolute value less than the absolute value |
| 3617 |
of B; in addition, for some signed integer value N, this result |
| 3618 |
satisfies the relation: |
| 3619 |
@begin(example) |
| 3620 |
A = B*N + (A @key(mod) B) |
| 3621 |
@end(example) |
| 3622 |
|
| 3623 |
The multiplying operators on modular types are defined in terms |
| 3624 |
of the corresponding signed integer operators@Redundant[, followed by a reduction |
| 3625 |
modulo the modulus if the result is outside |
| 3626 |
the base range of the type] @Redundant[(which is only possible for the "*" |
| 3627 |
operator)]. |
| 3628 |
@begin{Ramification} |
| 3629 |
The above identity satisfied by signed integer |
| 3630 |
division is not satisfied by modular division |
| 3631 |
because of the difference in effect of negation. |
| 3632 |
@end{Ramification} |
| 3633 |
@end{Wide} |
| 3634 |
|
| 3635 |
@Leading@;Multiplication and division operators are predefined for |
| 3636 |
every specific floating point type @i(T): |
| 3637 |
@begin(example) |
| 3638 |
@key(function) "*"(Left, Right : @RI(T)) @key(return) @RI(T) |
| 3639 |
@key(function) "/"(Left, Right : @RI(T)) @key(return) @RI(T) |
| 3640 |
@end(example) |
| 3641 |
|
| 3642 |
@Leading@;The following multiplication and division operators, with |
| 3643 |
an operand of the predefined type Integer, are predefined |
| 3644 |
for every specific fixed point type @i(T): |
| 3645 |
@begin(example) |
| 3646 |
@key(function) "*"(Left : @RI(T); Right : Integer) @key(return) @RI(T) |
| 3647 |
@key(function) "*"(Left : Integer; Right : @RI(T)) @key(return) @RI(T) |
| 3648 |
@key(function) "/"(Left : @RI(T); Right : Integer) @key(return) @RI(T) |
| 3649 |
@end(example) |
| 3650 |
|
| 3651 |
@Leading@Redundant[All of the above multiplying operators |
| 3652 |
are usable with an operand |
| 3653 |
of an appropriate universal numeric type.] The following additional |
| 3654 |
multiplying operators for @i(root_real) are predefined@Redundant[, |
| 3655 |
and are usable when both operands are of an appropriate universal or |
| 3656 |
root numeric type, and the result is allowed to be of |
| 3657 |
type @i(root_real), as in a @nt<number_declaration>]: |
| 3658 |
@begin{Ramification} |
| 3659 |
These operators |
| 3660 |
are analogous to the multiplying operators |
| 3661 |
involving fixed or floating point types |
| 3662 |
where @i(root_real) substitutes for the |
| 3663 |
fixed or floating point type, |
| 3664 |
and @i(root_integer) substitutes for Integer. |
| 3665 |
Only values of the corresponding universal numeric types are |
| 3666 |
implicitly convertible to these root numeric types, |
| 3667 |
so these operators are really restricted to use with |
| 3668 |
operands of a universal type, or the specified |
| 3669 |
root numeric types. |
| 3670 |
@end{Ramification} |
| 3671 |
@begin(example) |
| 3672 |
@key(function) "*"(Left, Right : @RI(root_real)) @key(return) @RI(root_real) |
| 3673 |
@key(function) "/"(Left, Right : @RI(root_real)) @key(return) @RI(root_real) |
| 3674 |
|
| 3675 |
@key(function) "*"(Left : @RI(root_real); Right : @RI(root_integer)) @key(return) @RI(root_real) |
| 3676 |
@key(function) "*"(Left : @RI(root_integer); Right : @RI(root_real)) @key(return) @RI(root_real) |
| 3677 |
@key(function) "/"(Left : @RI(root_real); Right : @RI(root_integer)) @key(return) @RI(root_real) |
| 3678 |
@end(example) |
| 3679 |
|
| 3680 |
@Leading@;Multiplication and division between any two fixed point types are |
| 3681 |
provided by the following two predefined operators: |
| 3682 |
@begin{Ramification} |
| 3683 |
@i(Universal_fixed) is the universal type for the class of |
| 3684 |
fixed point types, meaning that these operators take operands |
| 3685 |
of any fixed point types (not necessarily the same) |
| 3686 |
and return a result that is implicitly (or explicitly) convertible to |
| 3687 |
any fixed point type. |
| 3688 |
@end{Ramification} |
| 3689 |
@begin(example) |
| 3690 |
@key(function) "*"(Left, Right : @RI(universal_fixed)) @key(return) @RI(universal_fixed) |
| 3691 |
@key(function) "/"(Left, Right : @RI(universal_fixed)) @key(return) @RI(universal_fixed) |
| 3692 |
@end(example) |
| 3693 |
@end{StaticSem} |
| 3694 |
|
| 3695 |
@begin{Resolution} |
| 3696 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]} |
| 3697 |
@ChgAdded{Version=[2],Type=[Leading],Text=[The above two fixed-fixed |
| 3698 |
multiplying operators shall |
| 3699 |
not be used in a context where the expected type for the result is itself |
| 3700 |
@i(universal_fixed) @Redundant[@em the context has to identify some other |
| 3701 |
numeric type to which the result is to be converted, either explicitly or |
| 3702 |
implicitly]. Unless the predefined universal operator is identified using an |
| 3703 |
expanded name with @nt{prefix} denoting the package Standard, an explicit |
| 3704 |
conversion is required on the result when using the above fixed-fixed |
| 3705 |
multiplication operator if either operand is of a type having a user-defined |
| 3706 |
primitive multiplication operator such that:]} |
| 3707 |
@begin{Itemize} |
| 3708 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3709 |
@ChgAdded{Version=[2],Text=[it is declared immediately within the same |
| 3710 |
declaration list as the type; and]} |
| 3711 |
|
| 3712 |
@ChgRef{Version=[2],Kind=[Added]} |
| 3713 |
@ChgAdded{Version=[2],Text=[both of its formal parameters are of a |
| 3714 |
fixed-point type.]} |
| 3715 |
@end{Itemize} |
| 3716 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]} |
| 3717 |
@ChgAdded{Version=[2],Text=[A corresponding requirement applies to the |
| 3718 |
universal fixed-fixed division operator.]} |
| 3719 |
|
| 3720 |
@begin(Discussion) |
| 3721 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3722 |
@ChgAdded{Version=[2],Text=[The @i(small) of @i(universal_fixed) is |
| 3723 |
infinitesimal; no loss of precision is permitted. |
| 3724 |
However, fixed-fixed division is impractical to implement when |
| 3725 |
an exact result is required, |
| 3726 |
and multiplication will sometimes result in unanticipated overflows |
| 3727 |
in such circumstances, |
| 3728 |
so we require an explicit conversion to be inserted in |
| 3729 |
expressions like A * B * C if A, B, and C are each of some fixed point |
| 3730 |
type.]} |
| 3731 |
|
| 3732 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3733 |
@ChgAdded{Version=[2],Text=[On the other hand, X := A * B; is permitted by |
| 3734 |
this rule, even if X, A, and B |
| 3735 |
are all of different fixed point types, since the expected type |
| 3736 |
for the result of the multiplication is the type of X, which is necessarily |
| 3737 |
not @i(universal_fixed).]} |
| 3738 |
|
| 3739 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00364-01],ARef=[AI95-00420-01]} |
| 3740 |
@ChgAdded{Version=[2],Text=[We have made these into Name Resolution rules to |
| 3741 |
ensure that user-defined primitive fixed-fixed operators are not made unusable |
| 3742 |
due to the presence of these universal fixed-fixed operators. But we do allow |
| 3743 |
these operators to be used if prefixed by package Standard, so that they can be |
| 3744 |
used in the definitions of user-defined operators.]} |
| 3745 |
@end(Discussion) |
| 3746 |
@end{Resolution} |
| 3747 |
|
| 3748 |
@begin{Legality} |
| 3749 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00364-01]} |
| 3750 |
@ChgDeleted{Version=[2],Text=[The above two fixed-fixed multiplying operators |
| 3751 |
shall not be used in a context where the expected type for the result |
| 3752 |
is itself @i(universal_fixed) @em @Redundant[the context has to |
| 3753 |
identify some other numeric type to which the result is to be converted, |
| 3754 |
either explicitly or implicitly].]} |
| 3755 |
@begin(Discussion) |
| 3756 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 3757 |
@ChgDeleted{Version=[2],Text=[The @i(small) of @i(universal_fixed) is infinitesimal; no loss |
| 3758 |
of precision is permitted. |
| 3759 |
However, fixed-fixed division is impractical to implement when |
| 3760 |
an exact result is required, |
| 3761 |
and multiplication will sometimes result in unanticipated overflows |
| 3762 |
in such circumstances, |
| 3763 |
so we require an explicit conversion to be inserted in |
| 3764 |
expressions like A * B * C if A, B, and C are each of some fixed point |
| 3765 |
type.]} |
| 3766 |
|
| 3767 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 3768 |
@ChgDeleted{Version=[2],Text=[On the other hand, X := A * B; is permitted by this rule, even if X, A, and B |
| 3769 |
are all of different fixed point types, since the expected type |
| 3770 |
for the result of the multiplication is the type of X, which is necessarily |
| 3771 |
not @i(universal_fixed).]} |
| 3772 |
@end(Discussion) |
| 3773 |
@end{Legality} |
| 3774 |
|
| 3775 |
@begin{RunTime} |
| 3776 |
The multiplication and division operators for real types have |
| 3777 |
their conventional meaning. |
| 3778 |
@redundant[For floating point types, the accuracy of the result is |
| 3779 |
determined by the precision of the result type. |
| 3780 |
For decimal fixed point types, the result is truncated toward zero |
| 3781 |
if the mathematical result is between two multiples of the @i(small) |
| 3782 |
of the specific result type (possibly determined by context); |
| 3783 |
for ordinary fixed point types, if the mathematical result is |
| 3784 |
between two multiples of the @i(small), it is unspecified |
| 3785 |
which of the two is the result. |
| 3786 |
@PDefn{unspecified}] |
| 3787 |
|
| 3788 |
@IndexCheck{Division_Check} |
| 3789 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 3790 |
The exception Constraint_Error is raised by |
| 3791 |
integer division, @key(rem), |
| 3792 |
and @key(mod) if the right operand is zero. |
| 3793 |
@Redundant[Similarly, for a real type @i(T) with @i(T')Machine_Overflows |
| 3794 |
True, division by zero raises Constraint_Error.] |
| 3795 |
@end{RunTime} |
| 3796 |
|
| 3797 |
@begin{Notes} |
| 3798 |
@Leading@;For positive A and B, A/B is the quotient and A @key(rem) B is |
| 3799 |
the remainder when A is divided by B. The following relations are satisfied |
| 3800 |
by the rem operator: |
| 3801 |
@begin{Example} |
| 3802 |
A @key(rem) (-B) = A @key(rem) B |
| 3803 |
(-A) @key(rem) B = -(A @key(rem) B) |
| 3804 |
@end{Example} |
| 3805 |
|
| 3806 |
@Leading@keepnext@;For any signed integer K, the following identity holds: |
| 3807 |
@begin{Example} |
| 3808 |
A @key(mod) B = (A + K*B) @key(mod) B |
| 3809 |
@end{Example} |
| 3810 |
@begin{Bundle} |
| 3811 |
@NoPrefix@Leading@;The relations between signed integer |
| 3812 |
division, remainder, and modulus are |
| 3813 |
illustrated by the following table: |
| 3814 |
@begin{Example} |
| 3815 |
A B A/B A @key(rem) B A @key(mod) B A B A/B A @key(rem) B A @key(mod) B |
| 3816 |
|
| 3817 |
10 5 2 0 0 -10 5 -2 0 0 |
| 3818 |
11 5 2 1 1 -11 5 -2 -1 4 |
| 3819 |
12 5 2 2 2 -12 5 -2 -2 3 |
| 3820 |
13 5 2 3 3 -13 5 -2 -3 2 |
| 3821 |
14 5 2 4 4 -14 5 -2 -4 1 |
| 3822 |
|
| 3823 |
A B A/B A @key(rem) B A @key(mod) B A B A/B A @key(rem) B A @key(mod) B@* |
| 3824 |
10 -5 -2 0 0 -10 -5 2 0 0 |
| 3825 |
11 -5 -2 1 -4 -11 -5 2 -1 -1 |
| 3826 |
12 -5 -2 2 -3 -12 -5 2 -2 -2 |
| 3827 |
13 -5 -2 3 -2 -13 -5 2 -3 -3 |
| 3828 |
14 -5 -2 4 -1 -14 -5 2 -4 -4 |
| 3829 |
@end{Example} |
| 3830 |
@end{Bundle} |
| 3831 |
@end{Notes} |
| 3832 |
|
| 3833 |
@begin{Examples} |
| 3834 |
@Leading@keepnext@i(Examples of expressions involving multiplying operators:) |
| 3835 |
@begin{Example} |
| 3836 |
I : Integer := 1; |
| 3837 |
J : Integer := 2; |
| 3838 |
K : Integer := 3; |
| 3839 |
|
| 3840 |
X : Real := 1.0; --@RI[ see @RefSecNum{Floating Point Types}] |
| 3841 |
Y : Real := 2.0; |
| 3842 |
|
| 3843 |
F : Fraction := 0.25; --@RI[ see @RefSecNum{Fixed Point Types}] |
| 3844 |
G : Fraction := 0.5; |
| 3845 |
@end{Example} |
| 3846 |
@begin{Example} |
| 3847 |
@tabclear()@tabset(P19, P31) |
| 3848 |
@RI(Expression) @\@RI(Value) @\@RI(Result Type)@* |
| 3849 |
@R{I*J} @\@R{2} @\@RI(same as I and J, that is, Integer) |
| 3850 |
@R{K/J} @\@R{1} @\@RI(same as K and J, that is, Integer) |
| 3851 |
@R{K @key(mod) J} @\@R{1} @\@RI(same as K and J, that is, Integer)@* |
| 3852 |
@R{X/Y} @\@R{0.5} @\@RI(same as X and Y, that is, Real) |
| 3853 |
@R{F/2} @\@R{0.125} @\@RI(same as F, that is, Fraction)@* |
| 3854 |
@R{3*F} @\@R{0.75} @\@RI(same as F, that is, Fraction) |
| 3855 |
@R{0.75*G} @\@R{0.375} @\@RI(universal_fixed, implicitly convertible) |
| 3856 |
@\ @\@RI(to any fixed point type) |
| 3857 |
@R{Fraction(F*G)} @\@R{0.125} @\@RI(Fraction, as stated by the conversion) |
| 3858 |
@R{Real(J)*Y} @\@R{4.0} @\@RI(Real, the type of both operands after) |
| 3859 |
@\ @\@RI(conversion of J) |
| 3860 |
@end{Example} |
| 3861 |
@end{Examples} |
| 3862 |
|
| 3863 |
@begin{Incompatible83} |
| 3864 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00364-01],ARef=[AI95-00420-01]} |
| 3865 |
@Chg{Version=[2],New=[@Defn{incompatibilities with Ada 83}The universal |
| 3866 |
fixed-fixed multiplying operators are now directly available (see below). |
| 3867 |
Any attempt to use user-defined fixed-fixed multiplying operators |
| 3868 |
will be ambiguous with the universal ones. The only way to use the user-defined |
| 3869 |
operators is to fully qualify them in a prefix call. This problem was not |
| 3870 |
documented during the design of Ada 95, and has been mitigated by |
| 3871 |
Ada 2005.],Old=[]} |
| 3872 |
@end{Incompatible83} |
| 3873 |
|
| 3874 |
@begin{Extend83} |
| 3875 |
@Defn{extensions to Ada 83} |
| 3876 |
Explicit conversion of the result of multiplying |
| 3877 |
or dividing two fixed point numbers is no longer required, |
| 3878 |
provided the context uniquely determines some specific |
| 3879 |
fixed point result type. |
| 3880 |
This is to improve support for decimal fixed point, where |
| 3881 |
requiring explicit conversion on every fixed-fixed multiply |
| 3882 |
or divide was felt to be inappropriate. |
| 3883 |
|
| 3884 |
The type @i(universal_fixed) is covered by @i(universal_real), |
| 3885 |
so real literals and fixed point operands may be multiplied |
| 3886 |
or divided directly, without any explicit conversions required. |
| 3887 |
@end{Extend83} |
| 3888 |
|
| 3889 |
@begin{DiffWord83} |
| 3890 |
We have used the normal syntax for function definition |
| 3891 |
rather than a tabular format. |
| 3892 |
@end{DiffWord83} |
| 3893 |
|
| 3894 |
|
| 3895 |
@begin{Incompatible95} |
| 3896 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00364-01]} |
| 3897 |
@Chg{Version=[2],New=[@Defn{incompatibilities with Ada 95}We have changed the |
| 3898 |
resolution rules for the universal fixed-fixed multiplying operators to remove |
| 3899 |
the incompatibility with Ada 83 discussed above. The solution is to hide |
| 3900 |
the universal operators in some circumstances. As a result, some legal Ada 95 |
| 3901 |
programs will require the insertion of an explicit conversion around a |
| 3902 |
fixed-fixed multiply operator. This change is likely to catch as many bugs as |
| 3903 |
it causes, since it is unlikely that the user wanted to use predefined |
| 3904 |
operators when they had defined user-defined versions.],Old=[]} |
| 3905 |
@end{Incompatible95} |
| 3906 |
|
| 3907 |
|
| 3908 |
@LabeledSubClause{Highest Precedence Operators} |
| 3909 |
|
| 3910 |
@begin{StaticSem} |
| 3911 |
@Leading@Defn{highest precedence operator}@Defn2{Term=[operator],Sec=(highest precedence)} |
| 3912 |
@Defn{abs operator}@Defn2{Term=[operator],Sec=(abs)} |
| 3913 |
@Defn{absolute value} |
| 3914 |
The highest precedence unary operator @key(abs) (absolute value) |
| 3915 |
is predefined for every specific numeric type @i(T), |
| 3916 |
with the following specification: |
| 3917 |
@begin(example) |
| 3918 |
@key(function) "@key(abs)"(Right : @RI(T)) @key(return) @RI(T) |
| 3919 |
@end(example) |
| 3920 |
|
| 3921 |
@Leading@Defn{not operator}@Defn2{Term=[operator],Sec=(not)} |
| 3922 |
@IndexSeeAlso{Term=[logical operator],See=(not operator)} |
| 3923 |
The highest precedence unary operator @key(not) (logical negation) is |
| 3924 |
predefined for every boolean type @i(T), |
| 3925 |
every modular type @i(T), |
| 3926 |
and for every one-dimensional array type @i(T) whose |
| 3927 |
components are of a boolean type, |
| 3928 |
with the following specification: |
| 3929 |
@begin(example) |
| 3930 |
@key(function) "@key(not)"(Right : @RI(T)) @key(return) @RI(T) |
| 3931 |
@end(example) |
| 3932 |
|
| 3933 |
The result of the operator @key(not) for a modular type is |
| 3934 |
defined as the difference between the high bound of the base range |
| 3935 |
of the type and the value of the operand. @Redundant[For |
| 3936 |
a binary modulus, this corresponds to a bit-wise complement |
| 3937 |
of the binary |
| 3938 |
representation of the value |
| 3939 |
of the operand.] |
| 3940 |
|
| 3941 |
The operator @key(not) that applies |
| 3942 |
to a one-dimensional array of boolean |
| 3943 |
components yields a one-dimensional boolean array with the same bounds; |
| 3944 |
each component of the result is obtained by logical negation of the |
| 3945 |
corresponding component of the operand (that is, the component that |
| 3946 |
has the same index value). |
| 3947 |
@IndexCheck{Range_Check} |
| 3948 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 3949 |
A check is made that each component of the result belongs to the |
| 3950 |
component subtype; the exception Constraint_Error is raised if this |
| 3951 |
check fails. |
| 3952 |
@begin{Discussion} |
| 3953 |
The check against the component subtype is per AI83-00535. |
| 3954 |
@end{Discussion} |
| 3955 |
|
| 3956 |
@Leading@Defn{exponentiation operator}@Defn2{Term=[operator],Sec=(exponentiation)} |
| 3957 |
@Defn{** operator}@Defn2{Term=[operator],Sec=(**)} |
| 3958 |
The highest precedence @i(exponentiation) operator ** is predefined |
| 3959 |
for every specific integer type @i(T) |
| 3960 |
with the following specification: |
| 3961 |
@begin(example) |
| 3962 |
@key(function) "**"(Left : @RI(T); Right : Natural) @key(return) @RI(T) |
| 3963 |
@end(example) |
| 3964 |
|
| 3965 |
@Leading@;Exponentiation is also predefined for |
| 3966 |
every specific floating point type |
| 3967 |
as well as @i{root_real}, |
| 3968 |
with the following specification (where @i(T) is @i{root_real} |
| 3969 |
or the floating point type): |
| 3970 |
@begin(example) |
| 3971 |
@key(function) "**"(Left : @RI(T); Right : Integer'Base) @key(return) @RI(T) |
| 3972 |
@end(example) |
| 3973 |
|
| 3974 |
@Defn{exponent} |
| 3975 |
The right operand of an exponentiation is the @i(exponent). |
| 3976 |
The expression X**N with the value of the exponent |
| 3977 |
N positive is equivalent to the |
| 3978 |
expression X*X*...X (with N@en@;1 multiplications) except that the multiplications |
| 3979 |
are associated in an arbitrary order. With N equal to zero, the result is one. |
| 3980 |
With the value of N negative |
| 3981 |
@Redundant[(only defined for a floating point operand)], |
| 3982 |
the result is the reciprocal of the result using the absolute value of |
| 3983 |
N as the exponent. |
| 3984 |
@begin{Ramification} |
| 3985 |
The language does not specify the order of association of the multiplications |
| 3986 |
inherent in an exponentiation. For a floating point type, |
| 3987 |
the accuracy of the result might depend on the particular |
| 3988 |
association order chosen. |
| 3989 |
@end{Ramification} |
| 3990 |
|
| 3991 |
@end{StaticSem} |
| 3992 |
|
| 3993 |
@begin{ImplPerm} |
| 3994 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 3995 |
The implementation of |
| 3996 |
exponentiation for the case of a negative exponent |
| 3997 |
is allowed to raise Constraint_Error |
| 3998 |
if the intermediate result of the repeated multiplications |
| 3999 |
is outside the safe range of the type, even though the final |
| 4000 |
result (after taking the reciprocal) |
| 4001 |
would not be. |
| 4002 |
(The best machine approximation to the |
| 4003 |
final result in this case would generally be 0.0.) |
| 4004 |
@end{ImplPerm} |
| 4005 |
|
| 4006 |
@begin{Notes} |
| 4007 |
@IndexCheck{Range_Check} |
| 4008 |
As implied by the specification given above |
| 4009 |
for exponentiation of an integer type, a check is made that |
| 4010 |
the exponent is not negative. |
| 4011 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 4012 |
Constraint_Error is raised if this check fails. |
| 4013 |
@end{Notes} |
| 4014 |
|
| 4015 |
@begin{Inconsistent83} |
| 4016 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0100],ARef=[AI95-00018-01]} |
| 4017 |
@ChgAdded{Version=[1],Text=[@Defn{inconsistencies with Ada 83} |
| 4018 |
The definition of "**" allows arbitrary association of the |
| 4019 |
multiplications which make up the result. Ada 83 required left-to-right |
| 4020 |
associations (confirmed by AI83-00137). Thus it is possible that "**" |
| 4021 |
would provide a slightly different (and more potentially accurate) answer in |
| 4022 |
Ada 95 than in the same Ada 83 program.]} |
| 4023 |
@end{Inconsistent83} |
| 4024 |
|
| 4025 |
@begin{DiffWord83} |
| 4026 |
We now show the specification for "**" for integer types |
| 4027 |
with a parameter subtype of Natural rather than Integer for the exponent. |
| 4028 |
This reflects the fact that Constraint_Error is raised if |
| 4029 |
a negative value is provided for the exponent. |
| 4030 |
@end{DiffWord83} |
| 4031 |
|