| 1 |
@Part(06, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2020/06/03 00:09:00 $} |
| 4 |
@LabeledSection{Subprograms} |
| 5 |
|
| 6 |
@Comment{$Source: e:\\cvsroot/ARM/Source/06.mss,v $} |
| 7 |
@Comment{$Revision: 1.155 $} |
| 8 |
|
| 9 |
@begin{Intro} |
| 10 |
@Defn{subprogram} |
| 11 |
@Defn{procedure} |
| 12 |
@Defn{function} |
| 13 |
A subprogram is a program unit or intrinsic operation whose execution |
| 14 |
is invoked by a subprogram call. |
| 15 |
There are two forms of subprogram: procedures and functions. |
| 16 |
A procedure call is a @nt{statement}; a function call is an expression and |
| 17 |
returns a value. |
| 18 |
The definition of a subprogram can be given in two parts: |
| 19 |
a subprogram declaration defining its interface, |
| 20 |
and a @nt{subprogram_body} defining its execution. |
| 21 |
@Redundant[Operators and enumeration literals are functions.] |
| 22 |
@begin{Honest} |
| 23 |
A function call is an expression, but more specifically it is a @nt<name>. |
| 24 |
@end{Honest} |
| 25 |
@ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Subprogram>, |
| 26 |
Text=<@ChgAdded{Version=[2],Text=[A subprogram is a section of a program that |
| 27 |
can be executed in various contexts. It is invoked by a subprogram call that |
| 28 |
may qualify the effect of the subprogram through the passing of parameters. |
| 29 |
There are two forms of subprograms: functions, which return values, and |
| 30 |
procedures, which do not.]}>} |
| 31 |
@ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Function>, |
| 32 |
Text=<@ChgAdded{Version=[2],Text=[A function is a form of subprogram that |
| 33 |
returns a result and can be called as part of an expression.]}>} |
| 34 |
@ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Procedure>, |
| 35 |
Text=<@ChgAdded{Version=[2],Text=[A procedure is a form of subprogram that |
| 36 |
does not return a result and can only be called by a @nt{statement}.]}>} |
| 37 |
|
| 38 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 39 |
@Defn{callable entity} |
| 40 |
A @i(callable entity) is a subprogram or entry (see |
| 41 |
@Chg{Version=[3],New=[Section 9],Old=[@RefSecNum{Entries and Accept Statements}]}). |
| 42 |
@Defn{call} |
| 43 |
A callable entity is invoked by a @i{call}; |
| 44 |
that is, a subprogram call or entry call. |
| 45 |
@Defn{callable construct} |
| 46 |
A @i(callable construct) is a construct |
| 47 |
that defines the action of a call upon a callable entity: |
| 48 |
a @nt{subprogram_body}, |
| 49 |
@nt{entry_body}, or @nt{accept_statement}. |
| 50 |
@begin{Ramification} |
| 51 |
Note that @lquotes@;callable entity@rquotes@; |
| 52 |
includes predefined operators, enumeration literals, |
| 53 |
and abstract subprograms. |
| 54 |
@lquotes@;Call@rquotes@; includes calls of these things. |
| 55 |
They do not have callable constructs, |
| 56 |
since they don't have completions. |
| 57 |
@end{Ramification} |
| 58 |
@end{Intro} |
| 59 |
|
| 60 |
@LabeledClause{Subprogram Declarations} |
| 61 |
|
| 62 |
@begin{Intro} |
| 63 |
@Redundant[A @nt{subprogram_declaration} declares a procedure or |
| 64 |
function.] |
| 65 |
@end{Intro} |
| 66 |
|
| 67 |
@begin{Syntax} |
| 68 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 69 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]} |
| 70 |
@Syn{lhs=<subprogram_declaration>,rhs="@Chg{Version=[2],New=< |
| 71 |
[@Syn2{overriding_indicator}] |
| 72 |
>,Old=<>}@Syn2{subprogram_specification}@Chg{Version=[3],New=< |
| 73 |
[@Syn2{aspect_specification}]>,Old=[]};"} |
| 74 |
|
| 75 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00348-01]} |
| 76 |
@DeletedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<>,Old=<abstract_subprogram_declaration>}>, |
| 77 |
rhs="@Chg{Version=[2],New=<>,Old=<@Syn2{subprogram_specification} @key{is} @key{abstract};>}"} |
| 78 |
|
| 79 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 80 |
@Syn{lhs=<subprogram_specification>,rhs="@Chg{Version=[2],New=[ |
| 81 |
@Syn2{procedure_specification} |
| 82 |
| @Syn2{function_specification}],Old=[ |
| 83 |
@key{procedure} @Syn2{defining_program_unit_name} @Syn2{parameter_profile} |
| 84 |
| @key{function} @Syn2{defining_designator} @Syn2{parameter_and_result_profile}]}"} |
| 85 |
|
| 86 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]} |
| 87 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<procedure_specification>,Old=<>}>, |
| 88 |
rhs="@Chg{Version=[2],New=<@key{procedure} @Syn2{defining_program_unit_name} @Syn2{parameter_profile}>,Old=<>}"} |
| 89 |
|
| 90 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]} |
| 91 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<function_specification>,Old=<>}>, |
| 92 |
rhs="@Chg{Version=[2],New=<@key{function} @Syn2{defining_designator} @Syn2{parameter_and_result_profile}>,Old=<>}"} |
| 93 |
|
| 94 |
@Syn{lhs=<designator>,rhs="[@Syn2{parent_unit_name} . ]@Syn2{identifier} | @Syn2{operator_symbol}"} |
| 95 |
|
| 96 |
@Syn{lhs=<defining_designator>, |
| 97 |
rhs="@Syn2{defining_program_unit_name} | @Syn2{defining_operator_symbol}"} |
| 98 |
|
| 99 |
@Syn{lhs=<defining_program_unit_name>,rhs="[@Syn2{parent_unit_name} . ]@Syn2{defining_identifier}"} |
| 100 |
|
| 101 |
@begin{SyntaxText} |
| 102 |
@Redundant[The optional @nt{parent_unit_name} is only allowed for |
| 103 |
library units (see @RefSecNum{Compilation Units - Library Units}).] |
| 104 |
@end{SyntaxText} |
| 105 |
|
| 106 |
@Syn{lhs=<operator_symbol>,rhs="@Syn2{string_literal}"} |
| 107 |
|
| 108 |
@begin{SyntaxText} |
| 109 |
|
| 110 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00395-01]} |
| 111 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 112 |
The sequence of characters in an @nt{operator_symbol} shall @Chg{Version=[2], |
| 113 |
New=[form a reserved |
| 114 |
word, a delimiter, or compound delimiter that corresponds],Old=[correspond]} to |
| 115 |
an operator belonging to one of the six @Chg{Version=[2],New=[categories], |
| 116 |
Old=[classes]} of operators |
| 117 |
defined in @Chg{Version=[3],New=[subclause],Old=[clause]} @RefSecNum{Operators and Expression Evaluation}@Chg{Version=[2], |
| 118 |
New=[],Old=[(spaces are not allowed and the case of letters |
| 119 |
is not significant)]}. |
| 120 |
|
| 121 |
@begin{Reason} |
| 122 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]} |
| 123 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0090-1]} |
| 124 |
@ChgAdded{Version=[2],Text=[The @ldquote@;sequence of characters@rdquote |
| 125 |
of the string literal of the operator is a technical term (see |
| 126 |
@RefSecNum{String Literals}), and does not include the surrounding quote |
| 127 |
characters. As defined in @RefSecNum{Lexical Elements, Separators, and Delimiters}, |
| 128 |
lexical elements are @lquotes@;formed@rquotes from a sequence of characters. |
| 129 |
Spaces are not allowed, and upper and lower case is |
| 130 |
not significant.@Chg{Version=[3],New=[],Old=[ See |
| 131 |
@RefSecNum{Lexical Elements, Separators, and Delimiters} and |
| 132 |
@RefSecNum{Reserved Words} for rules related to the use of @ntf{other_format} |
| 133 |
characters in delimiters and reserved words.]}]} |
| 134 |
@end{Reason} |
| 135 |
|
| 136 |
@end{SyntaxText} |
| 137 |
|
| 138 |
@Syn{lhs=<defining_operator_symbol>,rhs="@Syn2{operator_symbol}"} |
| 139 |
|
| 140 |
@Syn{lhs=<parameter_profile>,rhs="[@Syn2{formal_part}]"} |
| 141 |
|
| 142 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 143 |
@Syn{lhs=<parameter_and_result_profile>,rhs="@Chg{Version=[2],New=[ |
| 144 |
],Old=[]}[@Syn2{formal_part}] @key{return}@Chg{Version=[2],New=< [@Syn2{null_exclusion}]>,Old=<>} @Syn2{subtype_mark}@Chg{Version=[2],New=< |
| 145 |
| [@Syn2{formal_part}] @key{return} @Syn2{access_definition}>,Old=<>}"} |
| 146 |
|
| 147 |
@Syn{lhs=<formal_part>,rhs=" |
| 148 |
(@Syn2{parameter_specification} {; @Syn2{parameter_specification}})"} |
| 149 |
|
| 150 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 151 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4]} |
| 152 |
@Syn{lhs=<parameter_specification>,rhs=" |
| 153 |
@Syn2{defining_identifier_list} : @Chg{Version=[3],New=<[@key[aliased]] >,Old=<>}@Syn2{mode} @Chg{Version=[2],New=<[@Syn2{null_exclusion}]>,Old=<>} @Syn2{subtype_mark} [:= @Syn2{default_expression}] |
| 154 |
| @Syn2{defining_identifier_list} : @Syn2{access_definition} [:= @Syn2{default_expression}]"} |
| 155 |
|
| 156 |
@Syn{lhs=<mode>,rhs="[@key{in}] | @key{in} @key{out} | @key{out}"} |
| 157 |
@end{Syntax} |
| 158 |
|
| 159 |
@begin{Resolution} |
| 160 |
@Defn2{Term=[formal parameter], Sec=(of a subprogram)} |
| 161 |
A @i(formal parameter) is an object |
| 162 |
@Redundant[directly visible within a @nt{subprogram_body}] |
| 163 |
that represents the actual parameter passed to the subprogram in a |
| 164 |
call; |
| 165 |
it is declared by a @nt{parameter_specification}. |
| 166 |
@PDefn2{Term=[expected type], |
| 167 |
Sec=(parameter @nt{default_expression})} |
| 168 |
For a formal parameter, |
| 169 |
the expected type for its @nt<default_expression>, |
| 170 |
if any, is that of the formal parameter. |
| 171 |
@IndexSee{Term=[parameter],See=[formal parameter]} |
| 172 |
@end{Resolution} |
| 173 |
|
| 174 |
@begin{Legality} |
| 175 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0143-1]} |
| 176 |
@Defn{parameter mode} |
| 177 |
The @i(parameter mode) of a formal parameter conveys the direction of |
| 178 |
information transfer with the actual parameter: |
| 179 |
@key(in), @key(in out), or @key(out). |
| 180 |
Mode @key(in) is the default, |
| 181 |
and is the mode of a parameter defined by an |
| 182 |
@nt{access_definition}.@Chg{Version=[3],New=[],Old=[ The formal parameters |
| 183 |
of a function, if any, shall have the mode @key(in).]} |
| 184 |
@begin{Ramification} |
| 185 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0143-1]} |
| 186 |
@ChgDeleted{Version=[3],Text=[Access parameters are permitted. |
| 187 |
This restriction to @b(in) parameters is primarily a methodological |
| 188 |
restriction, though it also simplifies implementation for some compiler |
| 189 |
technologies.]} |
| 190 |
@end{Ramification} |
| 191 |
|
| 192 |
A @nt{default_expression} is only allowed in a @nt{parameter_specification} |
| 193 |
for a formal parameter of mode @key(in). |
| 194 |
|
| 195 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 196 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1],ARef=[AI05-0229-1]} |
| 197 |
@PDefn2{Term=[requires a completion], Sec=(@nt{subprogram_declaration})} |
| 198 |
@PDefn2{Term=[requires a completion], Sec=(@nt{generic_subprogram_declaration})} |
| 199 |
A @nt{subprogram_declaration} |
| 200 |
or a @nt{generic_subprogram_declaration} |
| 201 |
requires a completion@Chg{Version=[3],New=[],Old=[:]} |
| 202 |
@Redundant[@Chg{Version=[3],New=[unless the Import aspect (see |
| 203 |
@RefSecNum{Interfacing Aspects}) is True for the declaration; the |
| 204 |
completion shall be ],Old=[]}a body@Chg{Version=[3],New=[ or],Old=[,]} |
| 205 |
a @nt<renaming_declaration> |
| 206 |
(see @RefSecNum(Renaming Declarations))@Chg{Version=[3],New=[],Old=[, or |
| 207 |
a @Chg{Version=[2],New=[@nt{pragma}], |
| 208 |
Old=[@key(pragma)]} Import (see @RefSecNum{Interfacing Aspects})]}]. |
| 209 |
@Redundant[A completion is not allowed |
| 210 |
for an @nt<abstract_subprogram_declaration>@Chg{Version=[2],New=[ (see |
| 211 |
@RefSecNum{Abstract Types and Subprograms})@Chg{Version=[3],New=[,],Old=[ or]} a |
| 212 |
@nt{null_procedure_declaration} (see @RefSecNum{Null Procedures})@Chg{Version=[3],New=[, |
| 213 |
or an @nt{expression_function_declaration} (see @RefSecNum{Expression Functions})],Old=[]}],Old=[]}.] |
| 214 |
@begin(Ramification) |
| 215 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 216 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]} |
| 217 |
Abstract subprograms @Chg{Version=[2],New=[@Chg{Version=[3],New=[,],Old=[and]} |
| 218 |
null procedures@Chg{Version=[3],New=[, and expression functions],Old=[]} ],Old=[]}are |
| 219 |
not declared by @nt{subprogram_declaration}s, and so do not require |
| 220 |
completion@Chg{Version=[3],New=[ (although the latter two can @i<be> completions)],Old=[]}. |
| 221 |
Protected subprograms are declared by @nt{subprogram_declaration}s, |
| 222 |
and so require completion. |
| 223 |
Note that an abstract subprogram is a subprogram, |
| 224 |
@Chg{Version=[3],New=[a null procedure is a subprogram, an expression function |
| 225 |
is a subprogram, ],Old=[]}and a protected subprogram is a subprogram, |
| 226 |
but a generic subprogram is not a subprogram.@Comment{Who's the idiot that |
| 227 |
came up with that??} |
| 228 |
@end(Ramification) |
| 229 |
@begin(TheProof) |
| 230 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 231 |
@ChgAdded{Version=[3],Text=[When the Import aspect is True for any entity, |
| 232 |
no completion is allowed (see @RefSecNum{Interfacing Aspects}).]} |
| 233 |
@end{TheProof} |
| 234 |
|
| 235 |
|
| 236 |
A @nt{name} that denotes a formal parameter |
| 237 |
is not allowed within the @nt{formal_part} in which it is declared, |
| 238 |
nor within the @nt{formal_part} of a corresponding body or |
| 239 |
@nt{accept_statement}. |
| 240 |
@begin{Ramification} |
| 241 |
By contrast, |
| 242 |
@nt<generic_formal_parameter_declaration>s are visible to subsequent |
| 243 |
declarations in the same @nt<generic_formal_part>. |
| 244 |
@end{Ramification} |
| 245 |
@end{Legality} |
| 246 |
|
| 247 |
@begin{StaticSem} |
| 248 |
@Defn{profile} |
| 249 |
The @i(profile) of (a view of) a callable entity |
| 250 |
is either a @nt{parameter_profile} or |
| 251 |
@nt{parameter_and_result_profile}@Redundant[; |
| 252 |
it embodies information about |
| 253 |
the interface to that entity @em for example, the profile includes |
| 254 |
information about parameters passed to the callable entity. |
| 255 |
All callable entities have a profile @em enumeration literals, |
| 256 |
other subprograms, and entries. |
| 257 |
An access-to-subprogram type has a designated profile.] |
| 258 |
Associated with a profile is a calling convention. |
| 259 |
A @nt<subprogram_declaration> declares a procedure or a function, as |
| 260 |
indicated by the initial reserved word, with name and profile as given by |
| 261 |
its specification. |
| 262 |
|
| 263 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 264 |
@PDefn2{Term=[nominal subtype], Sec=(of a formal parameter)} |
| 265 |
The nominal subtype of a formal parameter is |
| 266 |
the subtype @Chg{Version=[2],New=[determined],Old=[denoted]} by |
| 267 |
@Chg{Version=[2],New=[the optional @nt{null_exclusion} and ], Old=[]}the |
| 268 |
@nt{subtype_mark}, or defined by the @nt{access_definition}, in the |
| 269 |
@nt{parameter_specification}.@Chg{Version=[2],New=[ The nominal |
| 270 |
subtype of a function result is the subtype |
| 271 |
determined by the optional @nt{null_exclusion} and the @nt{subtype_mark}, or |
| 272 |
defined by the @nt{access_definition}, in the |
| 273 |
@nt{parameter_and_result_profile}. |
| 274 |
@PDefn2{Term=[nominal subtype], Sec=(of a function result)}], Old=[]} |
| 275 |
|
| 276 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4]} |
| 277 |
@ChgAdded{Version=[3],Text=[@Defn{explicitly aliased parameter}@Defn2{Term=[parameter],Sec=(explicitly aliased)}An |
| 278 |
@i(explicitly aliased parameter) is a formal parameter whose |
| 279 |
@nt{parameter_specification} includes the reserved word @key[aliased].]} |
| 280 |
|
| 281 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00318-02]} |
| 282 |
@Defn{access parameter} |
| 283 |
An @i(access parameter) is a formal @key[in] parameter |
| 284 |
specified by an @nt{access_definition}. |
| 285 |
@Defn{access result type} |
| 286 |
@Chg{Version=[2],New=[An @i(access result type) is a function result type specified by |
| 287 |
an @nt{access_definition}.],Old=[]} |
| 288 |
An access parameter @Chg{Version=[2],New=[or result type ],Old=[]}is of an |
| 289 |
anonymous |
| 290 |
@Chg{Version=[2],New=[access],Old=[general access-to-variable]} type (see |
| 291 |
@RefSecNum{Access Types}). @Redundant[Access parameters |
| 292 |
@Chg{Version=[2],New=[of an access-to-object type],Old=[]} allow dispatching |
| 293 |
calls to be controlled by access values.@Chg{Version=[2],New=[ Access |
| 294 |
parameters of an access-to-subprogram type permit calls to subprograms passed |
| 295 |
as parameters irrespective of their accessibility level.],Old=[]}] |
| 296 |
|
| 297 |
@begin{Discussion} |
| 298 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 299 |
@ChgAdded{Version=[2],Text=[Access result types have normal accessibility and |
| 300 |
thus don't have any special properties worth noting here.]} |
| 301 |
@end{Discussion} |
| 302 |
|
| 303 |
@leading@keepnext@Defn2{Term=[subtypes], Sec=(of a profile)} |
| 304 |
The @i(subtypes of a profile) are: |
| 305 |
@begin{Itemize} |
| 306 |
For any non-access parameters, the nominal subtype of the parameter. |
| 307 |
|
| 308 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]} |
| 309 |
For any access parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}, |
| 310 |
the designated subtype of the parameter type. |
| 311 |
|
| 312 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]} |
| 313 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0164-1]} |
| 314 |
@ChgAdded{Version=[2],Text=[For any access parameters of an access-to-subprogram |
| 315 |
type, the subtypes of the @Chg{Version=[3],New=[designated ],Old=[]}profile |
| 316 |
of the parameter type.]} |
| 317 |
|
| 318 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 319 |
@Chg{Version=[2],New=[For any non-access result, the nominal subtype of the |
| 320 |
function result.],Old=[For any result, the result subtype.]} |
| 321 |
|
| 322 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 323 |
@Chg{Version=[2],New=[For any access result type of an access-to-object type, |
| 324 |
the designated subtype of the result type.],Old=[]} |
| 325 |
|
| 326 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 327 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0164-1]} |
| 328 |
@Chg{Version=[2],New=[For any access result type of an access-to-subprogram |
| 329 |
type, the subtypes of the @Chg{Version=[3],New=[designated ],Old=[]}profile |
| 330 |
of the result type.],Old=[]} |
| 331 |
|
| 332 |
@end{Itemize} |
| 333 |
|
| 334 |
@Redundant[@Defn2{Term=[types], Sec=(of a profile)} |
| 335 |
The @i{types of a profile} are the types of those subtypes.] |
| 336 |
|
| 337 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 338 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]} |
| 339 |
@Redundant[A subprogram declared by an |
| 340 |
@nt<abstract_subprogram_declaration> |
| 341 |
is abstract; a subprogram declared by a @nt<subprogram_declaration> |
| 342 |
is not. See @RefSec{Abstract Types and Subprograms}.@Chg{Version=[2],New=[ |
| 343 |
Similarly, a procedure @Chg{Version=[3],New=[declared],Old=[defined]} by a |
| 344 |
@nt{null_procedure_declaration} is a null procedure; a procedure declared by |
| 345 |
a @nt{subprogram_declaration} is not. See @RefSec{Null Procedures}.@Chg{Version=[3],New=[ |
| 346 |
Finally, a function declared by an @nt{expression_function_declaration} is |
| 347 |
an expression function; a function declared by |
| 348 |
a @nt{subprogram_declaration} is not. See @RefSec{Expression Functions}.],Old=[]}],Old=[]}] |
| 349 |
|
| 350 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00218-03]} |
| 351 |
@ChgAdded{Version=[2],Text=[@Redundant[An @nt{overriding_indicator} is used to |
| 352 |
indicate whether overriding is intended. See @RefSec{Overriding Indicators}.]]} |
| 353 |
@end{StaticSem} |
| 354 |
|
| 355 |
@begin{RunTime} |
| 356 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 357 |
@PDefn2{Term=[elaboration], Sec=(subprogram_declaration)}@Chg{Version=[2],New=[],Old=[ |
| 358 |
@PDefn2{Term=[elaboration], Sec=(abstract_subprogram_declaration)}]} |
| 359 |
The elaboration of a @nt{subprogram_declaration}@Chg{Version=[2],New=[],Old=[ |
| 360 |
or an @nt{abstract_subprogram_declaration}]} has no effect. |
| 361 |
@end{RunTime} |
| 362 |
|
| 363 |
@begin{Notes} |
| 364 |
A @nt{parameter_specification} with several identifiers is equivalent |
| 365 |
to a sequence of single @nt{parameter_specification}s, as explained |
| 366 |
in @RefSecNum{Objects and Named Numbers}. |
| 367 |
|
| 368 |
Abstract subprograms do not have bodies, and cannot be used |
| 369 |
in a nondispatching call (see @RefSec{Abstract Types and Subprograms}). |
| 370 |
|
| 371 |
The evaluation of @nt<default_expression>s is caused by certain |
| 372 |
calls, as described in @RefSecNum{Parameter Associations}. |
| 373 |
They are not evaluated during the elaboration of |
| 374 |
the subprogram declaration. |
| 375 |
|
| 376 |
Subprograms can be called recursively and can be called |
| 377 |
concurrently from multiple tasks. |
| 378 |
@end{Notes} |
| 379 |
|
| 380 |
@begin{Examples} |
| 381 |
@leading@keepnext@i{Examples of subprogram declarations:} |
| 382 |
@begin{Example} |
| 383 |
@key[procedure] Traverse_Tree; |
| 384 |
@key[procedure] Increment(X : @key[in] @key[out] Integer); |
| 385 |
@key[procedure] Right_Indent(Margin : @key[out] Line_Size); --@RI{ see @RefSecNum{Integer Types}} |
| 386 |
@key[procedure] Switch(From, To : @key[in] @key[out] Link); --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 387 |
|
| 388 |
@key[function] Random @key[return] Probability; --@RI{ see @RefSecNum{Floating Point Types}} |
| 389 |
|
| 390 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0056-1]} |
| 391 |
@key[function] Min_Cell(X : Link) @key[return] Cell; --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 392 |
@key[function] Next_Frame(K : Positive) @key[return] Frame; --@RI{ see @RefSecNum{Access Types}} |
| 393 |
@key[function] Dot_Product(Left, Right : Vector) @key[return] Real; --@RI{ see @RefSecNum{Array Types}}@Chg{Version=[4],New=[ |
| 394 |
@key[function] Find(B : @key[aliased in out] Barrel; Key : String) @key[return] Real; |
| 395 |
--@RI{ see @RefSecNum{User-Defined References}}],Old=[]} |
| 396 |
|
| 397 |
@key[function] "*"(Left, Right : Matrix) @key[return] Matrix; --@RI{ see @RefSecNum{Array Types}} |
| 398 |
@end{Example} |
| 399 |
|
| 400 |
@begin{WideAbove} |
| 401 |
@leading@keepnext@i{Examples of @key[in] parameters with default expressions:} |
| 402 |
@end{WideAbove} |
| 403 |
@begin{Example} |
| 404 |
@key[procedure] Print_Header(Pages : @key[in] Natural; |
| 405 |
Header : @key[in] Line := (1 .. Line'Last => ' '); --@RI{ see @RefSecNum{Array Types}} |
| 406 |
Center : @key[in] Boolean := True); |
| 407 |
@end{Example} |
| 408 |
@end{Examples} |
| 409 |
|
| 410 |
@begin{Extend83} |
| 411 |
@Defn{extensions to Ada 83} |
| 412 |
The syntax for @nt{abstract_subprogram_declaration} is added. |
| 413 |
The syntax for @nt{parameter_specification} is revised to allow |
| 414 |
for access parameters (see @RefSecNum{Access Types}) |
| 415 |
|
| 416 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 417 |
Program units that are library units may have |
| 418 |
a @nt{parent_unit_name} to indicate the parent of a child |
| 419 |
(see @Chg{Version=[3],New=[@RefSecNum{Compilation Units - Library Units}],Old=[Section 10]}). |
| 420 |
@end{Extend83} |
| 421 |
|
| 422 |
@begin{DiffWord83} |
| 423 |
We have incorporated the rules from |
| 424 |
RM83-6.5, @lquotes@;Function Subprograms@rquotes@; here and in |
| 425 |
@RefSec{Subprogram Bodies} |
| 426 |
|
| 427 |
We have incorporated the definitions of RM83-6.6, @lquotes@;Parameter and Result |
| 428 |
Type Profile - Overloading of Subprograms@rquotes@; here. |
| 429 |
|
| 430 |
The syntax rule for @nt{defining_operator_symbol} is new. |
| 431 |
It is used for the defining occurrence of an @nt{operator_symbol}, |
| 432 |
analogously to @nt{defining_identifier}. |
| 433 |
Usage occurrences use the @nt{direct_name} or @nt{selector_name} |
| 434 |
syntactic categories. |
| 435 |
The syntax rules for @nt{defining_designator} and |
| 436 |
@nt{defining_program_unit_name} are new. |
| 437 |
@end{DiffWord83} |
| 438 |
|
| 439 |
@begin{Extend95} |
| 440 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 441 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 442 |
Subprograms now allow @nt{overriding_indicator}s for better error checking |
| 443 |
of overriding.]} |
| 444 |
|
| 445 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]} |
| 446 |
@ChgAdded{Version=[2],Text=[An optional @nt{null_exclusion} can be used in a |
| 447 |
formal parameter declaration. Similarly, an optional @nt{null_exclusion} can |
| 448 |
be used in a function result.]} |
| 449 |
|
| 450 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 451 |
@ChgAdded{Version=[2],Text=[The return type of a function can be an |
| 452 |
anonymous access type.]} |
| 453 |
@end{Extend95} |
| 454 |
|
| 455 |
@begin{DiffWord95} |
| 456 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00254-01]} |
| 457 |
@ChgAdded{Version=[2],Text=[A description of the purpose of anonymous |
| 458 |
access-to-subprogram parameters and the definition of the profile of |
| 459 |
subprograms containing them was added.]} |
| 460 |
|
| 461 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 462 |
@ChgAdded{Version=[2],Text=[Split the production for |
| 463 |
@nt{subprogram_specification} in order to make the declaration |
| 464 |
of null procedures (see @RefSecNum{Null Procedures}) easier.]} |
| 465 |
|
| 466 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 467 |
@ChgAdded{Version=[2],Text=[Moved the @SyntaxTitle and |
| 468 |
@RuntimeTitle for @nt{abstract_subprogram_declaration} to |
| 469 |
@RefSecNum{Abstract Types and Subprograms}, so that the syntax |
| 470 |
and semantics are together. This also keeps abstract and null |
| 471 |
subprograms similar.]} |
| 472 |
|
| 473 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]} |
| 474 |
@ChgAdded{Version=[2],Text=[Revised to allow @ntf{other_format} characters |
| 475 |
in @nt{operator_symbol}s in the same way as the underlying constructs.]} |
| 476 |
@end{DiffWord95} |
| 477 |
|
| 478 |
@begin{Extend2005} |
| 479 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 480 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Parameters can |
| 481 |
now be explicitly aliased, allowing parts of function results to |
| 482 |
designate parameters and forcing by-reference parameter passing.]} |
| 483 |
|
| 484 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0143-1]} |
| 485 |
@ChgAdded{Version=[3],Text=[The parameters |
| 486 |
of a function can now have any mode.]} |
| 487 |
|
| 488 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 489 |
@ChgAdded{Version=[3],Text=[An optional @nt{aspect_specification} can be |
| 490 |
used in a @nt{subprogram_declaration}. |
| 491 |
This is described in @RefSecNum{Aspect Specifications}.]} |
| 492 |
@end{Extend2005} |
| 493 |
|
| 494 |
@begin{DiffWord2005} |
| 495 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 496 |
@ChgAdded{Version=[3],Text=[Added expression functions (see |
| 497 |
@RefSecNum{Expression Functions}) to the wording.]} |
| 498 |
@end{DiffWord2005} |
| 499 |
|
| 500 |
|
| 501 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 502 |
@LabeledAddedSubClause{Version=[3],Name=[Preconditions and Postconditions]} |
| 503 |
|
| 504 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1]} |
| 505 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0045-1]} |
| 506 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0220-1],ARef=[AI12-0272-1]} |
| 507 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For a |
| 508 |
@Chg{Version=[4],New=[noninstance ],Old=[]}subprogram@Chg{Version=[5],New=[ |
| 509 |
@Redundant[(including a generic formal |
| 510 |
subprogram)]],Old=[]}@Chg{Version=[4],New=[, |
| 511 |
a generic subprogram,],Old=[]} @Chg{Version=[5],New=[],Old=[or |
| 512 |
]}@Chg{Version=[4],New=[an ],Old=[]}entry,@Chg{Version=[5],New=[ or an |
| 513 |
access-to-subprogram type,],Old=[]} the following language-defined aspects |
| 514 |
may be specified with an |
| 515 |
@nt{aspect_specification} (see @RefSecNum{Aspect Specifications}):]} |
| 516 |
|
| 517 |
@begin{Ramification} |
| 518 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0045-1]} |
| 519 |
@ChgAdded{Version=[4],Text=[@ldquote@;Noninstance subprogram@rdquote excludes |
| 520 |
a subprogram that is an instance of a generic subprogram. In that case, the |
| 521 |
aspects should be specified on the generic subprogram. If preconditions or |
| 522 |
postconditions need to be added to an instance of a generic subprogram, it |
| 523 |
can be accomplished by creating a separate subprogram specification and then |
| 524 |
completing that specification with a renames-as-body of the instance.]} |
| 525 |
@end{Ramification} |
| 526 |
|
| 527 |
@begin{TheProof} |
| 528 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0272-1]} |
| 529 |
@ChgAdded{Version=[5],Text=[A generic formal subprogram is a subprogram, and |
| 530 |
there are no rules to prevent using these attributes on it.]} |
| 531 |
@end{TheProof} |
| 532 |
|
| 533 |
@begin{Description} |
| 534 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 535 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0220-1]} |
| 536 |
@ChgAdded{Version=[3],Text=[Pre@\This aspect |
| 537 |
specifies a specific precondition for a callable |
| 538 |
entity@Chg{Version=[5],New=[ or an access-to-subprogram type],Old=[]}; it |
| 539 |
shall be specified by an @nt{expression}, called a |
| 540 |
@i<specific precondition |
| 541 |
expression>.@Defn{specific precondition expression}@Defn2{Term=[precondition expression],Sec=[specific]} |
| 542 |
If not specified for an entity, the specific precondition |
| 543 |
expression for the entity is the enumeration literal |
| 544 |
True.@AspectDefn{Pre}]} |
| 545 |
|
| 546 |
@begin{Honest} |
| 547 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 548 |
@ChgAdded{Version=[3],Text=[In this and the following rules, we are talking |
| 549 |
about the enumeration literal True declared in package Standard (see |
| 550 |
@RefSecNum{The Package Standard}), and not some |
| 551 |
other value or identifier True. That matters as some rules depend on full |
| 552 |
conformance of these expressions, which depends on the specific declarations |
| 553 |
involved.]} |
| 554 |
@end{Honest} |
| 555 |
|
| 556 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pre], |
| 557 |
Text=[@ChgAdded{Version=[3],Text=[Precondition; a condition that must hold |
| 558 |
true before a call.]}]} |
| 559 |
|
| 560 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0254-1],ARef=[AI05-0262-1]} |
| 561 |
@ChgAdded{Version=[3],Text=[Pre'Class@\This aspect |
| 562 |
specifies a class-wide precondition for an operation of a tagged type and its |
| 563 |
descendants; it shall be specified by an @nt{expression}, called a |
| 564 |
@i<class-wide precondition expression>.@Defn{class-wide precondition expression}@Defn2{Term=[precondition expression],Sec=[class-wide]} |
| 565 |
If not specified for an entity, then if no other |
| 566 |
class-wide precondition applies to the entity, the class-wide precondition |
| 567 |
expression for the entity is the enumeration literal |
| 568 |
True.@AspectDefn{Pre'Class}]} |
| 569 |
|
| 570 |
@begin{Ramification} |
| 571 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0254-1]} |
| 572 |
@ChgAdded{Version=[3],Text=[If other class-wide preconditions apply to the |
| 573 |
entity and no class-wide precondition is specified, no class-wide precondition |
| 574 |
is defined for the entity; of course, the class-wide preconditions (of |
| 575 |
ancestors) that apply are still going to be checked. We need subprograms that |
| 576 |
don't have ancestors and don't specify a class-wide precondition to have a |
| 577 |
class-wide precondition of True, so that adding such a precondition to a |
| 578 |
descendant has no effect (necessary as a dispatching call through the root |
| 579 |
routine would not check any precondition).]} |
| 580 |
|
| 581 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0220-1]} |
| 582 |
@ChgAdded{Version=[5],Text=[Pre'Class cannot be specified on an |
| 583 |
access-to-subprogram type because of a @LegalityName found in |
| 584 |
@RefSecNum{Aspect Specifications} that limits 'Class aspects to |
| 585 |
tagged types and primitive subprograms of tagged types. The same is true for |
| 586 |
Post'Class (below).]} |
| 587 |
@end{Ramification} |
| 588 |
|
| 589 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pre'Class], |
| 590 |
Text=[@ChgAdded{Version=[3],Text=[Precondition inherited on type |
| 591 |
derivation.]}]} |
| 592 |
|
| 593 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 594 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0220-1]} |
| 595 |
@ChgAdded{Version=[3],Text=[Post@\This aspect |
| 596 |
specifies a specific postcondition for a callable |
| 597 |
entity@Chg{Version=[5],New=[ or an access-to-subprogram type],Old=[]}; it |
| 598 |
shall be specified by an @nt{expression}, called a @i<specific postcondition |
| 599 |
expression>.@Defn{specific postcondition expression}@Defn2{Term=[postcondition expression],Sec=[specific]} |
| 600 |
If not specified for an entity, the specific postcondition |
| 601 |
expression for the entity is the enumeration literal True.@AspectDefn{Post}]} |
| 602 |
|
| 603 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Post], |
| 604 |
Text=[@ChgAdded{Version=[3],Text=[Postcondition; a condition that must hold |
| 605 |
true after a call.]}]} |
| 606 |
|
| 607 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]} |
| 608 |
@ChgAdded{Version=[3],Text=[Post'Class@\This aspect |
| 609 |
specifies a class-wide postcondition for an operation of a tagged type and its |
| 610 |
descendants; it shall be specified by an @nt{expression}, called a |
| 611 |
@i<class-wide postcondition expression>.@Defn{class-wide postcondition expression}@Defn2{Term=[postcondition expression],Sec=[class-wide]} |
| 612 |
If not specified for an entity, the class-wide postcondition |
| 613 |
expression for the entity is the enumeration literal True.@AspectDefn{Post'Class}]} |
| 614 |
@end{Description} |
| 615 |
|
| 616 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Post'Class], |
| 617 |
Text=[@ChgAdded{Version=[3],Text=[Postcondition inherited on type |
| 618 |
derivation.]}]} |
| 619 |
|
| 620 |
@begin{Resolution} |
| 621 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 622 |
@ChgAdded{Version=[3],Text=[The expected type for a precondition or |
| 623 |
postcondition expression is any boolean type.@PDefn2{Term=[expected type], |
| 624 |
Sec=(precondition expression)}@PDefn2{Term=[expected type], |
| 625 |
Sec=(postcondition expression)}]} |
| 626 |
|
| 627 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1]} |
| 628 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 629 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0170-1]} |
| 630 |
@ChgAdded{Version=[3],Text=[Within the expression for a Pre'Class or Post'Class aspect for a primitive |
| 631 |
subprogram @Chg{Version=[4],New=[@i<S> ],Old=[]}of a tagged type @i<T>, a |
| 632 |
@Chg{Version=[4],New=[@nt<name>],Old=[name]} that denotes a formal parameter |
| 633 |
@Chg{Version=[4],New=[(or @i<S>'Result) ],Old=[]}of type |
| 634 |
@i<T> is interpreted as @Chg{Version=[4],New=[though it had a (notional) |
| 635 |
@Chg{Version=[4],New=[nonabstract ],Old=[]} type |
| 636 |
@i<NT> that is a formal derived type whose ancestor type is @i<T>, with directly |
| 637 |
visible primitive operations],Old=[having type @i<T>'Class]}. Similarly, a |
| 638 |
@Chg{Version=[4],New=[@nt<name>],Old=[name]} that denotes a |
| 639 |
formal access parameter @Chg{Version=[4],New=[(or @i<S>'Result) ],Old=[]}of |
| 640 |
type access-to-@i<T> is interpreted as having type |
| 641 |
@Chg{Version=[4],New=[access-to-@i<NT>],Old=[access-to-@i<T>'Class]}. |
| 642 |
@Redundant[@Chg{Version=[4],New=[The result of this interpretation |
| 643 |
is that the only operations that can be applied to such @nt{name}s are those |
| 644 |
defined for such a formal derived type.],Old=[This ensures that the |
| 645 |
expression is well-defined for a primitive subprogram of a type descended |
| 646 |
from @i<T>.]}]]} |
| 647 |
|
| 648 |
@begin{Reason} |
| 649 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0159-1]} |
| 650 |
@ChgAdded{Version=[4],Text=[This ensures that the |
| 651 |
expression is well-defined for any primitive |
| 652 |
subprogram of a type descended from @i<T>.]} |
| 653 |
@end{Reason} |
| 654 |
|
| 655 |
@begin{Ramification} |
| 656 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0170-1]} |
| 657 |
@ChgAdded{Version=[5],Text=[The operations of @i<NT> are also nonabstract, |
| 658 |
so the rule against a call of an abstract subprogram does not trigger for a |
| 659 |
class-wide precondition or postcondition.]} |
| 660 |
@end{Ramification} |
| 661 |
|
| 662 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0264-1]} |
| 663 |
@ChgAdded{Version=[3],Text=[For an attribute_reference with attribute_designator |
| 664 |
Old, if the attribute reference has an expected type or shall resolve to a given |
| 665 |
type, the same applies to the @nt{prefix}; otherwise, the @nt{prefix} shall be |
| 666 |
resolved independently of context.]} |
| 667 |
|
| 668 |
@end{Resolution} |
| 669 |
|
| 670 |
@begin{Legality} |
| 671 |
|
| 672 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0230-1]} |
| 673 |
@ChgAdded{Version=[3],Text=[The Pre or Post aspect shall not be specified for an |
| 674 |
abstract subprogram or a null procedure. @Redundant[Only the Pre'Class and |
| 675 |
Post'Class aspects may be specified for such a subprogram.]]} |
| 676 |
|
| 677 |
@begin{Discussion} |
| 678 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 679 |
@ChgAdded{Version=[3],Text=[Pre'Class and Post'Class can only be specified |
| 680 |
on primitive routines of tagged types, by a blanket rule found in |
| 681 |
@RefSecNum{Aspect Specifications}.]} |
| 682 |
@end{Discussion} |
| 683 |
|
| 684 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 685 |
@ChgAdded{Version=[3],Type=[Leading],Text=[If a type @i<T> has an implicitly |
| 686 |
declared subprogram @i<P> inherited from a parent type @i<T1> and |
| 687 |
a homograph (see @RefSecNum{Visibility}) of @i<P> from a progenitor type |
| 688 |
@i<T2>, and]} |
| 689 |
|
| 690 |
@begin{Itemize} |
| 691 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 692 |
@ChgAdded{Version=[3],Text=[the corresponding primitive subprogram @i<P1> of |
| 693 |
type @i<T1> is neither null nor abstract; and]} |
| 694 |
|
| 695 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 696 |
@ChgAdded{Version=[3],Text=[the class-wide precondition expression True does |
| 697 |
not apply to @i<P1> (implicitly or explicitly); and]} |
| 698 |
|
| 699 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 700 |
@ChgAdded{Version=[3],Text=[there is a class-wide precondition expression that |
| 701 |
applies to the corresponding primitive subprogram @i<P2> of @i<T2> that does |
| 702 |
not fully conform to any class-wide precondition expression that applies to |
| 703 |
@i<P1>,]} |
| 704 |
@end{Itemize} |
| 705 |
|
| 706 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 707 |
@ChgAdded{Version=[3],Type=[Leading],Text=[then:]} |
| 708 |
|
| 709 |
@begin{Itemize} |
| 710 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 711 |
@ChgAdded{Version=[3],Text=[If the type @i<T> is abstract, the implicitly |
| 712 |
declared subprogram @i<P> is @i<abstract>.]} |
| 713 |
|
| 714 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 715 |
@ChgAdded{Version=[3],Text=[Otherwise, the subprogram @i<P> |
| 716 |
@i{requires overriding} and shall be overridden with a |
| 717 |
nonabstract subprogram.@PDefn{requires overriding}]} |
| 718 |
|
| 719 |
@begin{Discussion} |
| 720 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 721 |
@ChgAdded{Version=[3],Text=[We use the term "requires overriding" here so that |
| 722 |
this rule is taken into account when calculating visibility in |
| 723 |
@RefSecNum{Visibility}; otherwise we would have a mess when this routine is |
| 724 |
overridden.]} |
| 725 |
@end{Discussion} |
| 726 |
@end{Itemize} |
| 727 |
|
| 728 |
@begin{Reason} |
| 729 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 730 |
@ChgAdded{Version=[3],Text=[Such an inherited subprogram would necessarily |
| 731 |
violate the Liskov Substitutability Principle (LSP) if called via a |
| 732 |
dispatching call from an ancestor other than the one that provides the |
| 733 |
called body. In such a case, the class-wide precondition of the actual body |
| 734 |
is stronger than the class-wide precondition of the ancestor. If we did not |
| 735 |
enforce that precondition for the body, the body could be called when the |
| 736 |
precondition it knows about is False @em such "counterfeiting" of |
| 737 |
preconditions has to be avoided. But enforcing the precondition violates |
| 738 |
LSP. We do not want the language to be implicitly creating bodies that |
| 739 |
violate LSP; the programmer can still write an explicit body that calls the |
| 740 |
appropriate parent subprogram. In that case, the violation of LSP is |
| 741 |
explicitly in the code and obvious to code reviewers (both human and |
| 742 |
automated).]} |
| 743 |
|
| 744 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 745 |
@ChgAdded{Version=[3],Text=[We have to say that the subprogram is abstract for |
| 746 |
an abstract type in this case, so that the next concrete type has to |
| 747 |
override it for the reasons above. Otherwise, inserting an extra level of |
| 748 |
abstract types would eliminate the requirement to override (as there is only |
| 749 |
one declared operation for the concrete type), and that would be bad for the |
| 750 |
reasons given above.]} |
| 751 |
@end{Reason} |
| 752 |
|
| 753 |
@begin{Ramification} |
| 754 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 755 |
@ChgAdded{Version=[3],Text=[This requires the set of class-wide preconditions |
| 756 |
that apply to the interface routine to be strictly stronger than those that |
| 757 |
apply to the concrete routine. Since full conformance |
| 758 |
requires each name to denote the same declaration, it is unlikely that |
| 759 |
independently declared preconditions would conform. This rule does allow |
| 760 |
"diamond inheritance" of preconditions, and of course no preconditions at |
| 761 |
all match.]} |
| 762 |
|
| 763 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 764 |
@ChgAdded{Version=[3],Text=[We considered adopting a rule that would allow |
| 765 |
examples where the expressions would conform after all inheritance has been |
| 766 |
applied, but this is complex and is not likely to be common in practice. |
| 767 |
Since the penalty here is just that an explicit overriding is required, the |
| 768 |
complexity is too much.]} |
| 769 |
@end{Ramification} |
| 770 |
|
| 771 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0247-1]} |
| 772 |
@ChgAdded{Version=[3],Text=[If a renaming of a subprogram or entry @i<S1> |
| 773 |
overrides an inherited subprogram @i<S2>, then the overriding is illegal unless |
| 774 |
each class-wide precondition expression that applies to @i<S1> fully conforms to |
| 775 |
some class-wide precondition expression that applies to @i<S2> and each |
| 776 |
class-wide precondition expression that applies to @i<S2> fully conforms to some |
| 777 |
class-wide precondition expression that applies to @i<S1>.]} |
| 778 |
|
| 779 |
@begin{Reason} |
| 780 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 781 |
@ChgAdded{Version=[3],Text=[Such an overriding subprogram would violate LSP, |
| 782 |
as the precondition of @i<S1> would usually be different (and thus stronger) |
| 783 |
than the one known to a dispatching call through an ancestor routine of @i<S2>. |
| 784 |
This is always OK if the preconditions match, so we always allow that.]} |
| 785 |
@end{Reason} |
| 786 |
|
| 787 |
@begin{Ramification} |
| 788 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 789 |
@ChgAdded{Version=[3],Text=[This only applies to primitives of tagged types; |
| 790 |
other routines cannot have class-wide preconditions.]} |
| 791 |
@end{Ramification} |
| 792 |
|
| 793 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0131-1]} |
| 794 |
@ChgAdded{Version=[4],Text=[Pre'Class shall not be specified for an overriding |
| 795 |
primitive subprogram of a tagged type @i<T> unless the Pre'Class aspect is |
| 796 |
specified for the corresponding primitive subprogram of some ancestor of @i<T>.]} |
| 797 |
|
| 798 |
@begin{Reason} |
| 799 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 800 |
@ChgAdded{Version=[4],Text=[Any such Pre'Class will have no effect, as it |
| 801 |
will be @key[or]ed with True. As such, it is highly misleading for readers, |
| 802 |
especially for those who are determining the assumptions that can |
| 803 |
be made in the body of the primitive subprogram. Note that in this |
| 804 |
case there is nothing explicit that might indicate that the |
| 805 |
class-wide precondition is ineffective. This rule does not prevent |
| 806 |
explicitly writing an ineffective class-wide precondition (for |
| 807 |
instance, if the parent subprogram has explicitly specified a |
| 808 |
precondition of True).]} |
| 809 |
@end{Reason} |
| 810 |
|
| 811 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0131-1]} |
| 812 |
@ChgAdded{Version=[4],Text=[@PDefn{generic contract issue} |
| 813 |
In addition to the places where |
| 814 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 815 |
these rules also apply in the private part of an instance of a generic unit.]} |
| 816 |
@end{Legality} |
| 817 |
|
| 818 |
@begin{StaticSem} |
| 819 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 820 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0131-1]} |
| 821 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0170-1]} |
| 822 |
@ChgAdded{Version=[4],Type=[Leading],Text=[]}@Comment{Conditional Leading} |
| 823 |
@ChgAdded{Version=[3],Text=[If a Pre'Class or Post'Class aspect is specified for |
| 824 |
a primitive subprogram @Chg{Version=[4],New=[@i<S> ],Old=[]}of a tagged type |
| 825 |
@i<T>, @Chg{Version=[4],New=[or such an aspect defaults to True, ],Old=[]}then |
| 826 |
@Chg{Version=[4],New=[a corresponding],Old=[the associated]} expression |
| 827 |
also applies to the corresponding primitive subprogram |
| 828 |
@Chg{Version=[4],New=[@i<S> ],Old=[]}of each descendant of |
| 829 |
@i<T>@Chg{Version=[5],New=[ @Redundant[(including @i<T> |
| 830 |
itself)]],Old=[]}.@Chg{Version=[4],New=[ The @i<corresponding expression> is constructed |
| 831 |
from the associated expression as follows:@Defn2{Term=[corresponding expresssion],Sec=[class-wide precondition]} |
| 832 |
@Defn2{Term=[corresponding expresssion],Sec=[class-wide postcondition]}],Old=[]}]} |
| 833 |
|
| 834 |
@begin{Ramification} |
| 835 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 836 |
@ChgAdded{Version=[4],Text=[A Pre'Class defaults to True only if no class-wide |
| 837 |
preconditions are inherited for the subprogram. The same is true for |
| 838 |
Post'Class.]} |
| 839 |
@end{Ramification} |
| 840 |
|
| 841 |
@begin{Reason} |
| 842 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 843 |
@ChgAdded{Version=[4],Text=[We have to inherit precondition expressions that |
| 844 |
default to True, so that later overridings don't strengthen the |
| 845 |
precondition (a violation of LSP). We do the same for postconditions |
| 846 |
for consistency.]} |
| 847 |
@end{Reason} |
| 848 |
|
| 849 |
@begin{Itemize} |
| 850 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0113-1]} |
| 851 |
@ChgAdded{Version=[4],Text=[References to formal parameters of @i<S> (or to |
| 852 |
@i<S> itself) are replaced with references to the corresponding formal |
| 853 |
parameters of the corresponding inherited or overriding subprogram |
| 854 |
@i<S> (or to the corresponding subprogram @i<S> itself).]} |
| 855 |
|
| 856 |
@begin{Reason} |
| 857 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 858 |
@ChgAdded{Version=[4],Text=[We have to define the corresponding expression |
| 859 |
this way as overriding routines are only required to be subtype conformant; in |
| 860 |
particular, the parameter names can be different. So we have to talk about |
| 861 |
corresponding parameters without mentioning any names.]} |
| 862 |
@end{Reason} |
| 863 |
@end{Itemize} |
| 864 |
|
| 865 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0113-1]} |
| 866 |
@ChgAdded{Version=[4],Text=[The primitive subprogram @i<S> is illegal if it is |
| 867 |
not abstract and the corresponding expression for a Pre'Class or Post'Class |
| 868 |
aspect would be illegal.]} |
| 869 |
|
| 870 |
@begin{Ramification} |
| 871 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 872 |
@ChgAdded{Version=[4],Text=[This can happen, for instance, if one of the |
| 873 |
subprograms called in the corresponding expression is abstract. We made the |
| 874 |
rule general so that we don't have to worry about exactly which cases |
| 875 |
can cause this to happen, both now and in the future.]} |
| 876 |
@end{Ramification} |
| 877 |
|
| 878 |
@begin{Reason} |
| 879 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 880 |
@ChgAdded{Version=[4],Text=[We allow illegal corresponding expressions |
| 881 |
on abstract subprograms as they could never be evaluated, and we need to |
| 882 |
allow such expressions to contain calls to abstract subprograms.]} |
| 883 |
@end{Reason} |
| 884 |
|
| 885 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1],ARef=[AI05-0290-1]} |
| 886 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0220-1]} |
| 887 |
@ChgAdded{Version=[3],Text=[If performing checks is required by the Pre, |
| 888 |
Pre'Class, Post, or Post'Class assertion policies (see |
| 889 |
@RefSecNum{Pragmas Assert and Assertion_Policy}) in effect at the point of a |
| 890 |
corresponding aspect specification applicable to a given subprogram@Chg{Version=[5],New=[,],Old=[ or]} |
| 891 |
entry,@Chg{Version=[5],New=[ or access-to-subprogram type,],Old=[]} |
| 892 |
then the respective precondition or postcondition expressions are considered |
| 893 |
@i<enabled>.@Defn2{Term=[enabled],Sec=[precondition expression]}@Defn2{Term=[enabled],Sec=[postcondition expression]}]} |
| 894 |
|
| 895 |
@begin{Ramification} |
| 896 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0290-1]} |
| 897 |
@ChgAdded{Version=[3],Text=[If a class-wide precondition or postcondition |
| 898 |
expression is enabled, it remains enabled when inherited by an overriding |
| 899 |
subprogram, even if the policy |
| 900 |
in effect is Ignore for the inheriting subprogram.]} |
| 901 |
@end{Ramification} |
| 902 |
|
| 903 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0273-1]} |
| 904 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0280-2]} |
| 905 |
@ChgAdded{Version=[3],Type=[Leading],Text=[@Chg{Version=[5],New=[A subexpression of a postcondition expression is @i<known on entry> if it is any |
| 906 |
of:@Defn{Term=[known on entry],Sec=[postcondition]}],Old=[An @nt{expression} is |
| 907 |
@i{potentially unevaluated} if it occurs within:@Defn{potentially unevaluated expression}]}]} |
| 908 |
|
| 909 |
@begin{Itemize} |
| 910 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 911 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0280-2]} |
| 912 |
@ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[a static subexpression |
| 913 |
(see @RefSecNum{Static Expressions and Static Subtypes})],Old=[any part |
| 914 |
of an @nt{if_expression} other than the first @nt{condition}]};]} |
| 915 |
|
| 916 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 917 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0280-2]} |
| 918 |
@ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[a literal whose type does |
| 919 |
not have any Integer_Literal, Real_Literal, or String_Literal aspect |
| 920 |
specified, or the function specified by such an attribute has aspect Global |
| 921 |
specified to be @key[null]],Old=[a @SynI{dependent_}@nt{expression} of a |
| 922 |
@nt{case_expression}]};]} |
| 923 |
|
| 924 |
@begin{Reason} |
| 925 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0280-2]} |
| 926 |
@ChgAdded{Version=[5],Text=[We mention literals explicitly in case they |
| 927 |
are not static (as when their subtype is not static, they are the literal |
| 928 |
@key[null], and so on). We exclude literals of types with the aspects that |
| 929 |
are not Global => @key[null] as those cause a |
| 930 |
user-written subprogram with possible side effects to be called.]} |
| 931 |
@end{Reason} |
| 932 |
|
| 933 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 934 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0280-2]} |
| 935 |
@ChgAdded{Version=[4],Text=[@Chg{Version=[5],New=[a name statically denoting a |
| 936 |
full constant declaration of a type for which all views are constant (see |
| 937 |
@RefSecNum{Objects and Named Numbers})],Old=[a @nt{predicate} of a |
| 938 |
@nt{quantified_expression}]};]} |
| 939 |
|
| 940 |
@begin{Ramification} |
| 941 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 942 |
@ChgAdded{Version=[5],Text=[Constants of types with immutably limited or |
| 943 |
controlled parts are not allowed by this rule. Generic formal in objects |
| 944 |
are allowed by this rule (as they are defined to be full constant |
| 945 |
declarations).]} |
| 946 |
@end{Ramification} |
| 947 |
@begin{Reason} |
| 948 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 949 |
@ChgAdded{Version=[5],Text=[We only want things that cannot be changed. We |
| 950 |
can't just say @ldquote@;constant@rdquote since that includes views of |
| 951 |
variables in some cases (for instance, a dereference of an access to |
| 952 |
constant object can be a view of a variable). There are other things we |
| 953 |
could have allowed (like a loop parameter), but having a subprogram |
| 954 |
declaration where those could be used (like inside of a loop) seems |
| 955 |
unusual enough to not be worth defining.]} |
| 956 |
@end{Reason} |
| 957 |
|
| 958 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 959 |
@ChgAdded{Version=[5],Text=[a name statically denoting a nonaliased @key[in] |
| 960 |
parameter of an elementary type;]} |
| 961 |
|
| 962 |
@begin{Ramification} |
| 963 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 964 |
@ChgAdded{Version=[5],Text=[All such parameters are by-copy, so the value |
| 965 |
won't change during the execution of the subprogram.]} |
| 966 |
@end{Ramification} |
| 967 |
|
| 968 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 969 |
@ChgAdded{Version=[5],Text=[an Old @nt{attribute_reference};]} |
| 970 |
|
| 971 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 972 |
@ChgAdded{Version=[5],Text=[an invocation of a predefined operator where |
| 973 |
all of the operands are known on entry;]} |
| 974 |
|
| 975 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 976 |
@ChgAdded{Version=[5],Text=[a function call where the function has aspect |
| 977 |
Global => @key[null] where all of the actual parameters are known on entry;]} |
| 978 |
|
| 979 |
@begin{Reason} |
| 980 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 981 |
@ChgAdded{Version=[5],Text=[Such a function can only depend on the values of |
| 982 |
its parameters.]} |
| 983 |
@end{Reason} |
| 984 |
|
| 985 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 986 |
@ChgAdded{Version=[5],Text=[a @nt{selected_component} of a |
| 987 |
known-on-entry @nt{prefix};]} |
| 988 |
|
| 989 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 990 |
@ChgAdded{Version=[5],Text=[an @nt{indexed_component} of a known-on-entry |
| 991 |
@nt{prefix} where all index @nt{expression}s are known on entry;]} |
| 992 |
|
| 993 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 994 |
@ChgAdded{Version=[5],Text=[a parenthesized known-on-entry @nt{expression};]} |
| 995 |
|
| 996 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 997 |
@ChgAdded{Version=[5],Text=[a @nt{qualified_expression} or @nt{type_conversion} |
| 998 |
whose operand is a known-on-entry expression;]} |
| 999 |
|
| 1000 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1001 |
@ChgAdded{Version=[5],Text=[a @nt{conditional_expression} where all of |
| 1002 |
the @nt{condition}s, @Syni{selecting_}@nt{expression}s, |
| 1003 |
and @Syni{dependent_}@nt{expression}s are known on entry.]} |
| 1004 |
|
| 1005 |
@begin{Discussion} |
| 1006 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1007 |
@ChgAdded{Version=[5],Text=[It's OK if such an expression raises an |
| 1008 |
exception, so long as every evaluation of the expression raises |
| 1009 |
the same exception.]} |
| 1010 |
@end{Discussion} |
| 1011 |
|
| 1012 |
@end{Itemize} |
| 1013 |
|
| 1014 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0198-1],ARef=[AI12-0280-2]} |
| 1015 |
@ChgAdded{Version=[5],Type=[Leading],Text=[A subexpression of a postcondition |
| 1016 |
expression is |
| 1017 |
@i<unconditionally evaluated>,@Defn2{Term=[unconditionally evaluated],Sec=[subexpression]} |
| 1018 |
conditionally evaluated, or |
| 1019 |
@i<repeatedly evaluated>.@Defn2{Term=[repeatedly evaluated],Sec=[subexpression]} |
| 1020 |
The following subexpressions are repeatedly evaluated:]} |
| 1021 |
|
| 1022 |
@begin{Itemize} |
| 1023 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1024 |
@ChgAdded{Version=[5],Text=[A subexpression of a predicate of |
| 1025 |
a @nt{quantified_expression};]} |
| 1026 |
|
| 1027 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1028 |
@ChgAdded{Version=[5],Text=[A subexpression of |
| 1029 |
the expression of an @nt{array_component_association};]} |
| 1030 |
|
| 1031 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1032 |
@ChgAdded{Version=[5],Text=[A subexpression of |
| 1033 |
the expression of a @nt{container_element_association}.]} |
| 1034 |
@end{Itemize} |
| 1035 |
|
| 1036 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1037 |
@ChgAdded{Version=[5],Type=[Leading],Text=[If a subexpression is not repeatedly |
| 1038 |
evaluated, and not evaluated unconditionally, then it is @i<conditionally |
| 1039 |
evaluated>,@Defn2{Term=[conditionally evaluated],Sec=[subexpression]} and |
| 1040 |
there is a set of @i<determining expressions>@Defn{determining expression} that |
| 1041 |
determine whether the subexpression is actually evaluated at run time. Such |
| 1042 |
subexpressions and their determining expressions are as follows:]} |
| 1043 |
|
| 1044 |
@begin{Itemize} |
| 1045 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1046 |
@ChgAdded{Version=[5],Text=[For an @nt{if_expression} that is not repeatedly |
| 1047 |
evaluated, a subexpression of any part other than the first condition is |
| 1048 |
conditionally evaluated, and its determining expressions include all |
| 1049 |
@nt{condition}s of the @nt{if_expression} that precede the subexpression |
| 1050 |
textually;]} |
| 1051 |
|
| 1052 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1053 |
@ChgAdded{Version=[5],Text=[For a @nt{case_expression} that is not repeatedly |
| 1054 |
evaluated, a subexpression of any @SynI[dependent_]@nt{expression} is |
| 1055 |
conditionally evaluated, and its determining expressions include the |
| 1056 |
@Syni{selecting_}@nt{expression} of the @nt{case_expression};]} |
| 1057 |
|
| 1058 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1059 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0280-2]} |
| 1060 |
@ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[For],Old=[the right operand |
| 1061 |
of]} a short-circuit control form@Chg{Version=[5],New=[ that is not |
| 1062 |
repeatedly evaluated, a subexpression of the right-hand operand is |
| 1063 |
conditionally evaluated, and its determining expressions include the left-hand |
| 1064 |
operand of the short-circuit control form;],Old=[; or]}]} |
| 1065 |
|
| 1066 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1067 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0280-2]} |
| 1068 |
@ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[For a membership test that |
| 1069 |
is not repeatedly evaluated, a subexpression of ],Old=[]} |
| 1070 |
a @nt{membership_choice} other than the first @Chg{Version=[5],New=[is |
| 1071 |
conditionally evaluated, and its determining expressions include the |
| 1072 |
@Syni<tested_>@nt{simple_expression} and the preceding |
| 1073 |
@nt{membership_choice}s of the membership test],Old=[of |
| 1074 |
a membership operation]}.]} |
| 1075 |
@end{Itemize} |
| 1076 |
|
| 1077 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0280-2]} |
| 1078 |
@ChgAdded{Version=[5],Text=[A conditionally evaluated subexpression is @i<determined to be |
| 1079 |
unevaluated> at run time if its set of determining expressions are all |
| 1080 |
known on entry, and when evaluated on entry their values are such that |
| 1081 |
the given subexpression is not evaluated.@Defn{determined to be unevaluated} |
| 1082 |
@Defn2{Term=[unevaluated],Sec=[determined to be]}]} |
| 1083 |
|
| 1084 |
@begin{Ramification} |
| 1085 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1086 |
@ChgAdded{Version=[5],Type=[Leading],Text=[To be precise, a conditionally |
| 1087 |
evaluated expression is determined to be unevaluated (including all of |
| 1088 |
its subexpressions) under the following circumstances:]} |
| 1089 |
@begin{Itemize} |
| 1090 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1091 |
@ChgAdded{Version=[5],Text=[Within an @nt{if_expression}, a |
| 1092 |
@Syni{dependent_}@nt{expression} with an |
| 1093 |
associated @nt{condition} that evaluates to False, or a @nt{condition} or |
| 1094 |
@Syni{dependent_}@nt{expression} where a condition of a preceding part |
| 1095 |
of the @nt{if_expression} evaluates to True;]} |
| 1096 |
|
| 1097 |
@ChgAdded{Version=[5],Text=[Within a @nt{case_expression}, a |
| 1098 |
@Syni{dependent_}@nt{expression} with an |
| 1099 |
@nt{discrete_choice_list} that is not covered by the value of the |
| 1100 |
@Syni{selecting_}@nt{expression};]} |
| 1101 |
|
| 1102 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1103 |
@ChgAdded{Version=[5],Text=[The right-hand |
| 1104 |
operand of a short-circuit control form where the |
| 1105 |
left-hand operand evaluates to False for @b<and then> or True for @b<or |
| 1106 |
else>;]} |
| 1107 |
|
| 1108 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1109 |
@ChgAdded{Version=[5],Text=[A |
| 1110 |
@nt{membership_choice} of a membership test where the |
| 1111 |
individual membership test defined by any prior @nt{membership_choice} |
| 1112 |
evaluates to True.]} |
| 1113 |
@end{Itemize} |
| 1114 |
@end{Ramification} |
| 1115 |
|
| 1116 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 1117 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} X that |
| 1118 |
denotes an object of a nonlimited type}, the following attribute is defined:]} |
| 1119 |
@begin(description) |
| 1120 |
@ChgNote{For Version=[3], Kind=[AddedNormal].} |
| 1121 |
@ChgAttribute{Version=[5],Kind=[Revised],ChginAnnex=[T], |
| 1122 |
Leading=<F>, Prefix=<X>, AttrName=<Old>, ARef=[AI05-0145-2], ARef=[AI05-0262-1], ARef=[AI05-0273-1], ARef=[AI12-0032-1], ARef=[AI12-0280-2], |
| 1123 |
InitialVersion=[3],Text=[@Chg{Version=[3],New=[@Chg{Version=[4],New=[Each],Old=[For each]} |
| 1124 |
X'Old in a postcondition expression that |
| 1125 |
is enabled@Chg{Version=[5],New=[, other than |
| 1126 |
those that occur in subexpressions that are determined to be |
| 1127 |
unevaluated,],Old=[]}@Chg{Version=[4],New=[ denotes],Old=[,]} a constant |
| 1128 |
@Chg{Version=[4],New=[that ],Old=[]}is implicitly |
| 1129 |
declared at the beginning of the subprogram |
| 1130 |
@Chg{Version=[4],New=[body,],Old=[or]} |
| 1131 |
entry@Chg{Version=[4],New=[ body, or accept statement],Old=[]}.@Chg{Version=[4],New=[],Old=[ |
| 1132 |
The constant is of the type of X and is initialized to the result |
| 1133 |
of evaluating X (as an expression) at the point of the constant declaration. |
| 1134 |
The value of X'Old in the postcondition expression is the value of this |
| 1135 |
constant; the type of X'Old is the type of X. These implicit constant |
| 1136 |
declarations occur in an |
| 1137 |
arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}]}],Old=[]}]}@Comment{End of Annex text here.} |
| 1138 |
|
| 1139 |
@begin{Ramification} |
| 1140 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0280-2]} |
| 1141 |
@ChgAdded{Version=[5],Text=[If X'Old occurs in a subexpression that is |
| 1142 |
determined to be unevaluated, then there is no associated constant, |
| 1143 |
and no evaluation of the prefix takes place. In general, this will |
| 1144 |
require evaluating one or more known-on-entry subexpressions before |
| 1145 |
creating and initializing any X'Old constants. Note that any 'Old in |
| 1146 |
a known-on-entry subexpression evaluated this way represents the |
| 1147 |
current value of the prefix (the 'Old itself can be ignored).]} |
| 1148 |
|
| 1149 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0193-1]} |
| 1150 |
@ChgAdded{Version=[5],Text=[In the case of an accept statement, the |
| 1151 |
constant is declared inside of the rendezvous. It is considered part of |
| 1152 |
the initialization of the postcondition check, which is part of the |
| 1153 |
rendezvous by definition (see @RefSecNum{Entries and Accept Statements}).]} |
| 1154 |
@end{Ramification} |
| 1155 |
|
| 1156 |
|
| 1157 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1],ARef=[AI12-0159-1]} |
| 1158 |
@ChgAdded{Version=[4],Type=[Leading],NoPrefix=[T],Text=[The implicitly declared |
| 1159 |
entity denoted by each occurrence of X'Old is declared as follows:]} |
| 1160 |
|
| 1161 |
@begin{Itemize} |
| 1162 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1163 |
@ChgAdded{Version=[4],Type=[Leading],Text=[If X is of an anonymous access |
| 1164 |
type defined by an @nt{access_definition} @i<A> then]} |
| 1165 |
@begin{ChildExample} |
| 1166 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1167 |
@ChgAdded{Version=[4],Text=[@i<X'Old> : @key[constant] @i<A> := X;]} |
| 1168 |
@end{ChildExample} |
| 1169 |
|
| 1170 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1171 |
@ChgAdded{Version=[4],Type=[Leading],Text=[If X is of a specific tagged type @i<T> then]} |
| 1172 |
@begin{ChildExample} |
| 1173 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1174 |
@ChgAdded{Version=[4],Text=[@examcom<anonymous> : @key[constant] @i<T>'Class := @i<T>'Class(X); |
| 1175 |
@i<X'Old> : @i<T> @key[renames] @i<T>(@examcom<anonymous>);]} |
| 1176 |
@end{ChildExample} |
| 1177 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1178 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[where the name X'Old denotes |
| 1179 |
the object renaming.]} |
| 1180 |
@begin{Ramification} |
| 1181 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1182 |
@ChgAdded{Version=[4],Text=[This means that the underlying tag associated |
| 1183 |
with X'Old is that of X and not that of the nominal type of X.]} |
| 1184 |
@end{Ramification} |
| 1185 |
|
| 1186 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1187 |
@ChgAdded{Version=[4],Type=[Leading],Text=[Otherwise]} |
| 1188 |
@begin{ChildExample} |
| 1189 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1190 |
@ChgAdded{Version=[4],Text=[@i<X'Old> : @key[constant] @i<S> := X;]} |
| 1191 |
@end{ChildExample} |
| 1192 |
@ChgRef{Version=[4],Kind=[Added]} |
| 1193 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[where @i<S> is the nominal subtype |
| 1194 |
of X. This includes the case where the type of @i<S> is an anonymous array |
| 1195 |
type or a universal type.]} |
| 1196 |
@end{Itemize} |
| 1197 |
|
| 1198 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 1199 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0185-1]} |
| 1200 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[The @Chg{Version=[5],New=[type |
| 1201 |
and ],Old=[]}nominal subtype of X'Old is as |
| 1202 |
implied by the above definitions.@Chg{Version=[5],New=[],Old=[ The expected |
| 1203 |
type of the prefix of an Old |
| 1204 |
attribute is that of the attribute. Similarly, if an Old attribute shall |
| 1205 |
resolve to be of some type, then the prefix of the attribute shall resolve to |
| 1206 |
be of that type.]}]} |
| 1207 |
|
| 1208 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2], ARef=[AI05-0262-1], ARef=[AI05-0273-1]} |
| 1209 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0217-1],ARef=[AI12-0280-2]} |
| 1210 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[Reference to this attribute is only |
| 1211 |
allowed within a postcondition expression. The @nt{prefix} of an Old |
| 1212 |
@nt{attribute_reference} shall not contain a Result @nt{attribute_reference}, |
| 1213 |
nor an Old @nt{attribute_reference}, nor a use of an entity declared within |
| 1214 |
the postcondition expression but not within @nt{prefix} itself (for example, |
| 1215 |
the loop parameter of an enclosing @nt{quantified_expression}). |
| 1216 |
The @nt{prefix} of an Old @nt{attribute_reference} |
| 1217 |
@Chg{Version=[5],New=[],Old=[that is |
| 1218 |
potentially unevaluated ]}shall statically |
| 1219 |
@Chg{Version=[5],New=[name (see @RefSecNum{Static Expressions and Static Subtypes})], |
| 1220 |
Old=[denote]} an entity@Chg{Version=[5],New=[, |
| 1221 |
unless the @nt{attribute_reference} is |
| 1222 |
unconditionally evaluated, or is conditionally evaluated where all of |
| 1223 |
the determining expressions are known on entry],Old=[]}.]} |
| 1224 |
|
| 1225 |
@begin{Discussion} |
| 1226 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1227 |
@ChgAdded{Version=[3],Text=<The @nt{prefix} X can be any |
| 1228 |
nonlimited object that obeys the syntax for prefix other than the few |
| 1229 |
exceptions given above (discussed below). Useful cases are: the @nt{name} |
| 1230 |
of a formal parameter of mode [@key[in]] @key[out], the @nt{name} of a global |
| 1231 |
variable updated by the subprogram, a function call passing those as |
| 1232 |
parameters, a subcomponent of those things, etc.>} |
| 1233 |
|
| 1234 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1235 |
@ChgAdded{Version=[3],Text=[A qualified expression can be used to make an |
| 1236 |
arbitrary expression into a valid prefix, so T'(X + Y)'Old is legal, even |
| 1237 |
though (X + Y)'Old is not. The value being saved here is the sum of X and Y (a |
| 1238 |
function result is an object). Of course, in this case "+"(X, Y)'Old is also |
| 1239 |
legal, but the qualified expression is arguably more readable.]} |
| 1240 |
|
| 1241 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1242 |
@ChgAdded{Version=[3],Text=[Note that F(X)'Old and F(X'Old) are not |
| 1243 |
necessarily equal. The former calls F(X) and saves that value for later use |
| 1244 |
during the postcondition. The latter saves the value of X, and during the |
| 1245 |
postcondition, passes that saved value to F. In most cases, the former is what |
| 1246 |
one wants (but it is not always legal, see below).]} |
| 1247 |
|
| 1248 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1249 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0032-1]} |
| 1250 |
@ChgAdded{Version=[3],Text=[If X has controlled parts, adjustment and |
| 1251 |
finalization are implied by the implicit constant |
| 1252 |
declaration.@Chg{Version=[4],New=[ Similarly, the implicit constant |
| 1253 |
declaration defines the accessibility level of X'Old.],Old=[]}]} |
| 1254 |
|
| 1255 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1256 |
@ChgAdded{Version=[3],Text=[If postconditions are disabled, we want the |
| 1257 |
compiler to avoid any overhead associated with saving 'Old values.]} |
| 1258 |
|
| 1259 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1260 |
@ChgAdded{Version=[3],Text=['Old makes no sense for limited types, because its |
| 1261 |
implementation involves copying. It might make semantic sense to allow |
| 1262 |
build-in-place, but it's not worth the trouble.]} |
| 1263 |
@end{Discussion} |
| 1264 |
|
| 1265 |
@begin{Reason} |
| 1266 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0273-1]} |
| 1267 |
@ChgAdded{Version=[3],Text=[Since the @nt{prefix} is evaluated unconditionally |
| 1268 |
when the subprogram is called, we cannot allow it to include values that do |
| 1269 |
not exist at that time (like 'Result and loop parameters of @nt{quantified_expression}s). |
| 1270 |
We also do not allow it to include 'Old references, as those would be |
| 1271 |
redundant (the entire @nt{prefix} is evaluated when the subprogram is called), |
| 1272 |
and allowing them would require some sort of order to the implicit constant |
| 1273 |
declarations (because in A(I'Old)'Old, we surely would want the value of |
| 1274 |
I'Old evaluated before the A(I'Old) is evaluated).]} |
| 1275 |
|
| 1276 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0273-1]} |
| 1277 |
@ChgAdded{Version=[3],Type=[Leading],Text=[In addition, we only allow simple names as the |
| 1278 |
@nt{prefix} of the Old attribute if the @nt{attribute_reference} might not |
| 1279 |
be evaluated when the postcondition expression is evaluated. This is necessary because |
| 1280 |
the Old @nt{prefix}es have to be unconditionally evaluated when the subprogram |
| 1281 |
is called; the compiler cannot in general know whether they will be needed |
| 1282 |
in the postcondition expression. To see the problem, consider:]} |
| 1283 |
|
| 1284 |
@begin{Example} |
| 1285 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1286 |
@ChgAdded{Version=[3],Text=[Table : @key[array] (1..10) @key[of] Integer := ... |
| 1287 |
@key[procedure] Bar (I : @key[in out] Natural) |
| 1288 |
@key[with] Post => I > 0 @key[and then] Table(I)'Old = 1; -- @Examcom{Illegal}]} |
| 1289 |
@end{Example} |
| 1290 |
|
| 1291 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1292 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]} |
| 1293 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[In this example, the compiler |
| 1294 |
cannot know the value of I when the subprogram returns (since the subprogram |
| 1295 |
execution can change it), and thus it does not know whether Table(I)'Old will |
| 1296 |
be needed then. Thus it has to always create an implicit constant |
| 1297 |
and evaluate Table(I) when Bar is called (because not having the value when |
| 1298 |
it is needed is not acceptable). But if I = 0 when the subprogram is called, |
| 1299 |
that evaluation will raise Constraint_Error, and that will happen even if I |
| 1300 |
is unchanged by the subprogram and the value of Table(I)'Old is not ultimately |
| 1301 |
needed. It's easy to see how a similar problem could occur for a dereference |
| 1302 |
of an access type. This would be mystifying (since the point of the short |
| 1303 |
circuit is to eliminate this possibility, but it cannot do so). Therefore, we |
| 1304 |
require the @nt{prefix} of any Old attribute in such a context to statically |
| 1305 |
denote an object, which eliminates anything that could change |
| 1306 |
@Chg{Version=[5],New=[],Old=[at ]}during execution.]} |
| 1307 |
|
| 1308 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1309 |
@ChgAdded{Version=[3],Text=[It is easy to work around most errors that occur |
| 1310 |
because of this rule. Just move the 'Old to the outer object, before any |
| 1311 |
indexing, dereferences, or components. (That does not work for function calls, |
| 1312 |
however, nor does it work for array indexing if the index can change during |
| 1313 |
the execution of the subprogram.)]} |
| 1314 |
@end{Reason} |
| 1315 |
|
| 1316 |
@begin{Ramification} |
| 1317 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1318 |
@ChgAdded{Version=[4],Type=[Leading],Text=[An accept statement for a task |
| 1319 |
entry with enabled postconditions such as]} |
| 1320 |
@begin{Example} |
| 1321 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1322 |
@ChgAdded{Version=[4],Text=[@key[accept] E @key[do] |
| 1323 |
@examcom<statements> |
| 1324 |
@key[exception] |
| 1325 |
@examcom<handlers> |
| 1326 |
@key[end];]} |
| 1327 |
@end{Example} |
| 1328 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1329 |
@ChgAdded{Version=[4],Type=[Leading],Text=[behaves (at runtime) as follows:]} |
| 1330 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1331 |
@begin{Example} |
| 1332 |
@ChgAdded{Version=[4],Text=[@key[accept] E @key[do] |
| 1333 |
@key[declare] |
| 1334 |
@examcom<declarations, if any, of 'Old constants> |
| 1335 |
@key[begin] |
| 1336 |
@key[begin] |
| 1337 |
@examcom<statements> |
| 1338 |
@key[exception] |
| 1339 |
@examcom<handlers> |
| 1340 |
@key[end]; |
| 1341 |
@examcom<postcondition checks> |
| 1342 |
@key[end]; |
| 1343 |
@key[end];]} |
| 1344 |
@end{Example} |
| 1345 |
|
| 1346 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1347 |
@ChgAdded{Version=[4],Text=[Preconditions are checked by the caller before the |
| 1348 |
rendezvous begins. Postcondition expressions might, of course, reference 'Old |
| 1349 |
constants.]} |
| 1350 |
|
| 1351 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1352 |
@ChgAdded{Version=[4],Text=[In the case of a protected operation with |
| 1353 |
enabled postconditions, 'Old constant declarations (if any) are |
| 1354 |
elaborated after the start of the protected action. Postcondition checks |
| 1355 |
(which might reference these constants) are performed before the end of |
| 1356 |
the protected action as described below.]} |
| 1357 |
|
| 1358 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0280-2]} |
| 1359 |
@ChgAdded{Version=[5],Text=[The @nt{prefix} of an Old @nt{attribute_reference} |
| 1360 |
has to statically name an entity if it appears within a repeatedly |
| 1361 |
evaluated expression.]} |
| 1362 |
@end{Ramification} |
| 1363 |
@end(description) |
| 1364 |
@EndPrefixType{} |
| 1365 |
|
| 1366 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 1367 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI05-0220-1]} |
| 1368 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} F that |
| 1369 |
denotes a function declaration@Chg{Version=[5],New=[ or an access-to-function |
| 1370 |
type],Old=[]}}, the following attribute is defined:]} |
| 1371 |
@begin(description) |
| 1372 |
@ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T], |
| 1373 |
Leading=<F>, Prefix=<F>, AttrName=<Result>, ARef=[AI05-0145-2], |
| 1374 |
ARef=[AI05-0262-1], ARef=[AI12-0185-1], ARef=[AI12-0220-1], |
| 1375 |
InitialVersion=[3], |
| 1376 |
Text=[@Chg{Version=[3],New=[Within a postcondition expression for |
| 1377 |
@Chg{Version=[5],New=[],Old=[function ]}F, |
| 1378 |
denotes the @Chg{Version=[5],New=[return],Old=[result]} object of the |
| 1379 |
function@Chg{Version=[5],New=[ call for which the postcondition expression is |
| 1380 |
evaluated],Old=[]}. The type of this attribute is that |
| 1381 |
of the @Chg{Version=[5],New=[result subtype of the ],Old=[]}function |
| 1382 |
@Chg{Version=[5],New=[or access-to-function type ],Old=[result]} except |
| 1383 |
within a Post'Class postcondition expression for |
| 1384 |
a function with a controlling result or with a controlling access |
| 1385 |
result@Chg{Version=[5],New=[; in those cases the type of the attribute was |
| 1386 |
described previously],Old=[. For |
| 1387 |
a controlling result, the type of the attribute is @i<T>'Class, where @i<T> is |
| 1388 |
the function result type. For a controlling access result, the type of the |
| 1389 |
attribute is an anonymous access type whose designated type is @i<T>'Class, |
| 1390 |
where @i<T> is the designated type of the function result type]}.],Old=[]}]}@Comment{End of Annex text here.} |
| 1391 |
|
| 1392 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]} |
| 1393 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[Use of this |
| 1394 |
attribute is allowed only within a postcondition expression |
| 1395 |
for F.]} |
| 1396 |
@end(description) |
| 1397 |
@EndPrefixType{} |
| 1398 |
|
| 1399 |
@begin{Honest} |
| 1400 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0220-1]} |
| 1401 |
@ChgAdded{Version=[5],Text=[An @ldquote@;access-to-function type@rdquote |
| 1402 |
is an access-to-subprogram type whose designated profile is a function |
| 1403 |
profile.]} |
| 1404 |
@end{Honest} |
| 1405 |
|
| 1406 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0143-1]} |
| 1407 |
@ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} E that |
| 1408 |
denotes an entry declaration of an entry family} |
| 1409 |
(see @RefSecNum{Entries and Accept Statements}), the following attribute is |
| 1410 |
defined:]} |
| 1411 |
@begin(description) |
| 1412 |
@ChgAttribute{Version=[5],Kind=[Added],ChginAnnex=[T], |
| 1413 |
Leading=<F>, Prefix=<E>, AttrName=<Index>, ARef=[AI12-0143-1], |
| 1414 |
InitialVersion=[5], |
| 1415 |
Text=[@Chg{Version=[5],New=[Within a precondition or postcondition expression |
| 1416 |
for entry family E, denotes the value of the entry index for the call of E. |
| 1417 |
The nominal subtype of this attribute is the entry index subtype.],Old=[]}]}@Comment{End of Annex text here.} |
| 1418 |
|
| 1419 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0143-1]} |
| 1420 |
@ChgAdded{Version=[5],NoPrefix=[T],Text=[Use of this attribute is allowed |
| 1421 |
only within a precondition or postcondition expression for E.]} |
| 1422 |
@end(description) |
| 1423 |
@EndPrefixType{} |
| 1424 |
|
| 1425 |
@end{StaticSem} |
| 1426 |
|
| 1427 |
@begin{Runtime} |
| 1428 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0290-1]} |
| 1429 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Upon a call of the subprogram or |
| 1430 |
entry, after evaluating any actual parameters, precondition checks are performed |
| 1431 |
as follows:]} |
| 1432 |
|
| 1433 |
@begin{Itemize} |
| 1434 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1435 |
@ChgAdded{Version=[3],Text=[The specific precondition check begins with the |
| 1436 |
evaluation of the specific precondition expression that applies to the |
| 1437 |
subprogram or entry, if it is enabled; if the expression evaluates to False, |
| 1438 |
Assertions.Assertion_Error is raised; if the expression is not enabled, |
| 1439 |
the check succeeds.@Defn2{Term=(Assertion_Error), |
| 1440 |
Sec=(raised by failure of runtime check)}@Defn2{Term=[check, language-defined], |
| 1441 |
Sec=[controlled by assertion policy]}@Defn2{Term=[precondition check],Sec=[specific]}]} |
| 1442 |
|
| 1443 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1444 |
@ChgAdded{Version=[3],Text=[The class-wide precondition check begins with the |
| 1445 |
evaluation of any enabled class-wide precondition expressions that apply |
| 1446 |
to the subprogram or entry. If and only if all the class-wide precondition |
| 1447 |
expressions evaluate to False, Assertions.Assertion_Error is raised.@Defn2{Term=(Assertion_Error), |
| 1448 |
Sec=(raised by failure of runtime check)}@Defn2{Term=[check, language-defined], |
| 1449 |
Sec=[controlled by assertion policy]}@Defn2{Term=[precondition check],Sec=[class-wide]}]} |
| 1450 |
|
| 1451 |
@begin{Ramification} |
| 1452 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1453 |
@ChgAdded{Version=[3],Text=[The class-wide precondition expressions of the |
| 1454 |
entity itself as well as those of any parent or progenitor operations are |
| 1455 |
evaluated, as these expressions apply to the corresponding operations |
| 1456 |
of all descendants.]} |
| 1457 |
|
| 1458 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1459 |
@ChgAdded{Version=[3],Text=[Class-wide precondition checks are performed for |
| 1460 |
all appropriate calls, but only enabled precondition expressions are |
| 1461 |
evaluated. Thus, the check would be trivial if no precondition expressions |
| 1462 |
are enabled.]} |
| 1463 |
@end{Ramification} |
| 1464 |
@end{Itemize} |
| 1465 |
|
| 1466 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0269-1]} |
| 1467 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0166-1]} |
| 1468 |
@ChgAdded{Version=[3],Text=[The precondition checks are performed in an |
| 1469 |
arbitrary order, |
| 1470 |
and if any of the class-wide precondition expressions evaluate to True, it is |
| 1471 |
not specified whether the other class-wide precondition expressions are |
| 1472 |
evaluated. The precondition checks and any check for elaboration of the |
| 1473 |
subprogram body are performed in an arbitrary order. @Chg{Version=[5],New=[In], |
| 1474 |
Old=[It is not specified whether in]} a call on a protected operation, the |
| 1475 |
checks are performed before @Chg{Version=[5],New=[],Old=[or after ]}starting |
| 1476 |
the protected action. For an entry call, the checks are performed prior to |
| 1477 |
checking whether the entry is open.@PDefn2{Term=(arbitrary order), |
| 1478 |
Sec=(allowed)}@PDefn{unspecified}]} |
| 1479 |
|
| 1480 |
@begin{Reason} |
| 1481 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1482 |
@ChgAdded{Version=[3],Text=[We need to explicitly allow short-circuiting |
| 1483 |
of the evaluation of the class-wide precondition check if any expression |
| 1484 |
fails, as it consists of multiple expressions; we don't need a similar |
| 1485 |
permission for the specific precondition check as it consists only of a |
| 1486 |
single expression. Nothing is evaluated for the call after a check fails, |
| 1487 |
as the failed check propagates an exception.]} |
| 1488 |
@end{Reason} |
| 1489 |
|
| 1490 |
|
| 1491 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0262-1],ARef=[AI05-0290-1]} |
| 1492 |
@ChgAdded{Version=[3],Text=[Upon successful return from a call of the subprogram |
| 1493 |
or entry, prior to copying back any by-copy @key[in out] |
| 1494 |
or @key[out] parameters, the postcondition check is performed. This consists of |
| 1495 |
the evaluation of any enabled specific and class-wide postcondition expressions that |
| 1496 |
apply to the subprogram or entry. If any of the postcondition expressions |
| 1497 |
evaluate to False, then Assertions.Assertion_Error is raised. The |
| 1498 |
postcondition expressions are evaluated in an arbitrary order, and if any |
| 1499 |
postcondition expression evaluates to False, it is not specified whether any |
| 1500 |
other postcondition expressions are evaluated. The postcondition check, and any |
| 1501 |
constraint or predicate checks associated with |
| 1502 |
@key[in out] or @key[out] parameters are performed in |
| 1503 |
an arbitrary order.@Defn{postcondition check}@Defn2{Term=[check, language-defined], |
| 1504 |
Sec=[controlled by assertion policy]}@Defn2{Term=(Assertion_Error), |
| 1505 |
Sec=(raised by failure of runtime check)}@PDefn2{Term=(arbitrary order), |
| 1506 |
Sec=(allowed)}@PDefn{unspecified}]} |
| 1507 |
|
| 1508 |
@begin{Ramification} |
| 1509 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1510 |
@ChgAdded{Version=[3],Text=[The class-wide postcondition expressions of the |
| 1511 |
entity itself as well as those of any parent or progenitor operations are |
| 1512 |
evaluated, as these apply to all descendants; in contrast, only the specific |
| 1513 |
postcondition of the entity applies. Postconditions can always be evaluated |
| 1514 |
inside the invoked body.]} |
| 1515 |
@end{Ramification} |
| 1516 |
|
| 1517 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 1518 |
@ChgAdded{Version=[4],Text=[For a call to a task entry, the postcondition check |
| 1519 |
is performed before the end of the rendezvous; for a call to a protected |
| 1520 |
operation, the postcondition check is performed before the end of the protected |
| 1521 |
action of the call. The postcondition check for any call is performed before the |
| 1522 |
finalization of any implicitly-declared constants associated (as described |
| 1523 |
above) with Old @nt{attribute_reference}s but after the finalization of any |
| 1524 |
other entities whose accessibility level is that of the execution of the |
| 1525 |
callable construct.]} |
| 1526 |
@begin{Reason} |
| 1527 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 1528 |
@ChgAdded{Version=[4],Text=[If a postcondition references the implicitly-declared constant associated |
| 1529 |
with an Old attribute, the postcondition must be evaluated before the |
| 1530 |
constant is finalized. One way to think of this is to imagine |
| 1531 |
declaring a controlled object between any implicit "'Old" |
| 1532 |
constant declarations and any explicit declarations, then |
| 1533 |
performing postcondition checks during the finalization of |
| 1534 |
this object.]} |
| 1535 |
@end{Reason} |
| 1536 |
|
| 1537 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1]} |
| 1538 |
@ChgAdded{Version=[3],Text=[If a precondition or postcondition check fails, the |
| 1539 |
exception is raised at the point of the call@Redundant[; the exception cannot |
| 1540 |
be handled inside the called subprogram or entry]. Similarly, any exception |
| 1541 |
raised by the evaluation of a precondition or postcondition expression is |
| 1542 |
raised at the point of call.]} |
| 1543 |
|
| 1544 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0262-1]} |
| 1545 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 1546 |
@ChgAdded{Version=[3],Text=[For any@Chg{Version=[4],New=[ call to a],Old=[]} |
| 1547 |
subprogram or entry @Chg{Version=[4],New=[@i<S>],Old=[call]} (including |
| 1548 |
dispatching calls), the checks |
| 1549 |
that are performed to verify specific precondition expressions and specific |
| 1550 |
and class-wide postcondition expressions are determined by those for the subprogram |
| 1551 |
or entry actually invoked. Note that the class-wide postcondition expressions |
| 1552 |
verified by the postcondition check that is part of a call on a primitive |
| 1553 |
subprogram of type @i<T> includes all class-wide postcondition expressions |
| 1554 |
originating in any progenitor of @i<T>@Redundant[, even if the primitive |
| 1555 |
subprogram called is inherited from a type @i<T1> and some of the postcondition |
| 1556 |
expressions do not apply to the corresponding primitive subprogram of |
| 1557 |
@i<T1>].@Chg{Version=[4],New=[ Any operations within a class-wide |
| 1558 |
postcondition expression that were resolved as primitive operations of the |
| 1559 |
(notional) formal derived type @i<NT>, are in the evaluation of the |
| 1560 |
postcondition bound to the corresponding operations of the type identified |
| 1561 |
by the controlling tag of the call on @i<S>.@Redundant[ This applies to both |
| 1562 |
dispatching and non-dispatching calls on @i<S>.]],Old=[]}]} |
| 1563 |
|
| 1564 |
@begin{Ramification} |
| 1565 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1566 |
@ChgAdded{Version=[3],Text=[This applies to access-to-subprogram calls, |
| 1567 |
dispatching calls, and to statically bound calls. We need this rule to cover |
| 1568 |
statically bound calls as well, as specific pre- and postconditions are not |
| 1569 |
inherited, but the subprogram might be.]} |
| 1570 |
|
| 1571 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1572 |
@ChgAdded{Version=[3],Text=[For concrete subprograms, we require the original |
| 1573 |
specific postcondition to be evaluated as well as the inherited class-wide |
| 1574 |
postconditions in order that the semantics of an explicitly defined wrapper |
| 1575 |
that does nothing but call the original subprogram is the same as that of |
| 1576 |
an inherited subprogram.]} |
| 1577 |
|
| 1578 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1579 |
@ChgAdded{Version=[3],Text=[Note that this rule does not apply to class-wide |
| 1580 |
preconditions; they have their own rules mentioned below.]} |
| 1581 |
@end{Ramification} |
| 1582 |
|
| 1583 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 1584 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 1585 |
@ChgAdded{Version=[3],Text=[The class-wide precondition check for a call to a |
| 1586 |
subprogram or entry @Chg{Version=[4],New=[@i<S> ],Old=[]}consists solely of |
| 1587 |
checking the class-wide precondition expressions that apply to the denoted |
| 1588 |
callable entity (not necessarily @Chg{Version=[4],New=[to ],Old=[]}the one |
| 1589 |
that is invoked).@Chg{Version=[4],New=[ Any operations within |
| 1590 |
such an expression that were resolved as primitive operations of the |
| 1591 |
(notional) formal derived type @i<NT> are in the evaluation of the |
| 1592 |
precondition bound to the corresponding operations of the type |
| 1593 |
identified by the controlling tag of the call on @i<S>.@Redundant[ This |
| 1594 |
applies to both dispatching and non-dispatching calls on @i<S>.]],Old=[]}]} |
| 1595 |
|
| 1596 |
@begin{Ramification} |
| 1597 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1598 |
@ChgAdded{Version=[3],Text=[For a dispatching call, we are talking about the |
| 1599 |
Pre'Class(es) that apply to the subprogram that the dispatching call is |
| 1600 |
resolving to, not the Pre'Class(es) for the subprogram that is ultimately |
| 1601 |
dispatched to. The class-wide precondition of the resolved call is |
| 1602 |
necessarily the same or stronger than that of the invoked call. For a |
| 1603 |
statically bound call, these are the same; for an access-to-subprogram, |
| 1604 |
(which has no class-wide preconditions of its own), we check the |
| 1605 |
class-wide preconditions of the invoked routine.]} |
| 1606 |
|
| 1607 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0233-1]} |
| 1608 |
@ChgAdded{Version=[5],Text=[Since this check is based on the |
| 1609 |
@ldquote@;callable entity@rdquote, it does not depend on the view of |
| 1610 |
the entity. This matters any time the ancestor type (if any) of the partial |
| 1611 |
view differs from the parent type of the full view. In such a case, |
| 1612 |
the view of the callable entity associated with the full view might inherit |
| 1613 |
a Pre'Class while the view of the same callable entity associated with the |
| 1614 |
partial view does not.]} |
| 1615 |
@end{Ramification} |
| 1616 |
|
| 1617 |
@begin{ImplNote} |
| 1618 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1619 |
@ChgAdded{Version=[3],Text=[These rules imply that logically, class-wide |
| 1620 |
preconditions of routines must be checked at the point of call (other |
| 1621 |
than for access-to-subprogram calls, which must be checked in the body, |
| 1622 |
probably using a wrapper). Specific preconditions that might be called with |
| 1623 |
a dispatching call or via an access-to-subprogram value must be checked |
| 1624 |
inside of the subprogram body. In contrast, the postcondition checks always |
| 1625 |
need to be checked inside the body of the routine. Of course, an |
| 1626 |
implementation can evaluate all of these at the point of call for statically |
| 1627 |
bound calls if the implementation uses wrappers for dispatching bodies and |
| 1628 |
for 'Access values.]} |
| 1629 |
|
| 1630 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1631 |
@ChgAdded{Version=[3],Text=[There is no requirement for an implementation |
| 1632 |
to generate special code for routines that are imported from outside of |
| 1633 |
the Ada program. That's because there is a requirement on the programmer |
| 1634 |
that the use of interfacing aspects do not violate Ada semantics (see |
| 1635 |
@RefSecNum{Interfacing Aspects}). That includes making pre- and |
| 1636 |
postcondition checks. For instance, if the implementation expects routines |
| 1637 |
to make their own postcondition checks in the body before returning, |
| 1638 |
C code can be assumed to do this |
| 1639 |
(even though that is highly unlikely). That's even though the formal |
| 1640 |
definition of those checks is that they are evaluated at the call site. |
| 1641 |
Note that pre- and postconditions can be very useful for verification |
| 1642 |
tools (even if they aren't checked), because they tell the tool about the |
| 1643 |
expectations on the foreign code that it most likely cannot analyze.]} |
| 1644 |
@end{ImplNote} |
| 1645 |
|
| 1646 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0195-1]} |
| 1647 |
@ChgAdded{Version=[5],Text=[For the purposes of the above rules, a call on |
| 1648 |
an inherited subprogram is considered to involve a call on a subprogram @i<S>' |
| 1649 |
whose body consists only of a call (with appropriate conversions) on the |
| 1650 |
non-inherited subprogram @i<S> from which the inherited subprogram was |
| 1651 |
derived. It is not specified whether class-wide precondition or |
| 1652 |
postcondition expressions that are equivalent (with respect to which |
| 1653 |
non-inherited function bodies are executed) for @i<S> and @i<S>' are |
| 1654 |
evaluated once or twice. If evaluated only once, the value returned |
| 1655 |
is used for both associated checks.]} |
| 1656 |
|
| 1657 |
@begin{ImplNote} |
| 1658 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1659 |
@ChgAdded{Version=[5],Text=[If the class-wide pre- and postcondition |
| 1660 |
expressions are equivalent for @i<S> and @i<S>' because none of the |
| 1661 |
primitive subprograms called in those expressions were overridden, no |
| 1662 |
wrapper is needed. Otherwise, a wrapper is presumably needed to |
| 1663 |
provide the correct logic.]} |
| 1664 |
@end{ImplNote} |
| 1665 |
|
| 1666 |
|
| 1667 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 1668 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0220-1]} |
| 1669 |
@ChgAdded{Version=[3],Text=[For a call via an access-to-subprogram value, |
| 1670 |
@Chg{Version=[5],New=[],Old=[all ]}precondition and postcondition checks |
| 1671 |
performed are @Chg{Version=[5],New=[as ],Old=[]}determined by the subprogram |
| 1672 |
or entry denoted by the prefix of the Access attribute reference that produced |
| 1673 |
the value.@Chg{Version=[5],New=[ In addition, a precondition check of any |
| 1674 |
precondition expression associated with the access-to-subprogram type is |
| 1675 |
performed. Similarly, a postcondition check of any postcondition expression |
| 1676 |
associated with the access-to-subprogram type is performed.],Old=[]}]} |
| 1677 |
|
| 1678 |
@begin{ImplNote} |
| 1679 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0220-1]} |
| 1680 |
@ChgAdded{Version=[5],Text=[A call via an access-to-subprogram value can be |
| 1681 |
considered equivalent (with respect to dynamic semantics) to a call to a |
| 1682 |
notional "wrapper" subprogram which has the Pre and Post aspects and the |
| 1683 |
profile of the access-to-subprogram type and whose body contains (and |
| 1684 |
returns, in the case of a function) only a call to the designated |
| 1685 |
subprogram. However, other evaluation orders for the checks are allowed |
| 1686 |
beyond those allowed by strictly following this model. This equivalence |
| 1687 |
can be used to determine the appropriate point at which the constant |
| 1688 |
associated with an Old attribute reference in the Post aspect for an |
| 1689 |
access-to-subprogram type is elaborated and finalized.]} |
| 1690 |
@end{ImplNote} |
| 1691 |
|
| 1692 |
@begin{Ramification} |
| 1693 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0220-1]} |
| 1694 |
@ChgAdded{Version=[5],Text=[In the case of type conversion |
| 1695 |
between two access-to-subprogram types, the Pre and Post aspects of the |
| 1696 |
source type of the conversion play no role in any subsequent call via |
| 1697 |
the conversion result; only the Pre and Post aspects of the target type |
| 1698 |
of the conversion are relevant in that case. The same applies in the |
| 1699 |
case of a @ldquote@;conversion@rdquote (using the term loosely) which |
| 1700 |
is accomplished by combining a dereference and an Access attribute |
| 1701 |
reference, as in @exam{Some_Pointer.@key[all]'Access}.]} |
| 1702 |
@end{Ramification} |
| 1703 |
|
| 1704 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0272-1]} |
| 1705 |
@ChgAdded{Version=[5],Text=[@Redundant[For a call on a generic formal |
| 1706 |
subprogram, precondition and postcondition checks performed are as determined by |
| 1707 |
the subprogram or entry denoted by the actual subprogram, along with any |
| 1708 |
specific precondition and specific postcondition of the formal subprogram |
| 1709 |
itself.]]} |
| 1710 |
|
| 1711 |
@begin{TheProof} |
| 1712 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0272-1]} |
| 1713 |
@ChgAdded{Version=[5],Text=[This follows from the general @RunTimeTitle |
| 1714 |
rules given above, but we mention it explicitly so that there can be no |
| 1715 |
doubt that it is intended.]} |
| 1716 |
@end{TheProof} |
| 1717 |
|
| 1718 |
@begin{Honest} |
| 1719 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0371-1]} |
| 1720 |
@ChgAdded{Version=[5],Text=[The specific precondition and postcondition that |
| 1721 |
apply to a generic formal subprogram also apply to any renaming of that |
| 1722 |
subprogram, even if that renaming is visible in the instance and called from |
| 1723 |
outside of the generic instance.]} |
| 1724 |
@end{Honest} |
| 1725 |
|
| 1726 |
@end{Runtime} |
| 1727 |
|
| 1728 |
@begin{ImplPerm} |
| 1729 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0280-2],ARef=[AI12-0373-1]} |
| 1730 |
@ChgAdded{Version=[5],Text=[An implementation may evaluate a known-on-entry |
| 1731 |
subexpression of a postcondition expression of an entity at the place where |
| 1732 |
X'Old constants are created for the entity, with the normal evaluation of |
| 1733 |
the postcondition expression, or both.]} |
| 1734 |
|
| 1735 |
@begin{Reason} |
| 1736 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0280-2]} |
| 1737 |
@ChgAdded{Version=[5],Text=[We allow the evaluation of known-on-entry |
| 1738 |
subexpressions when they might be needed to determine whether to create a |
| 1739 |
particular 'Old constant. We allow them to be evaluated later as well, or for |
| 1740 |
the results to be saved somehow. This permission shouldn't matter, as the |
| 1741 |
results ought to be same wherever they are evaluated and there should not be |
| 1742 |
any side effects. The main effect of the permission is to determine when any |
| 1743 |
exceptions caused by such subexpressions may be raised. We never require |
| 1744 |
waiting to determine the value of such subexpressions, even if they aren't |
| 1745 |
used to determine the creation of a constant for 'Old.]} |
| 1746 |
@end{Reason} |
| 1747 |
|
| 1748 |
@end{ImplPerm} |
| 1749 |
|
| 1750 |
@begin{Notes} |
| 1751 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1]} |
| 1752 |
@ChgAdded{Version=[3],Text=[A precondition is checked just before the call. If |
| 1753 |
another task can change any value that the precondition expression depends on, |
| 1754 |
the precondition need not hold within the subprogram or entry body.]} |
| 1755 |
|
| 1756 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]} |
| 1757 |
@ChgAdded{Version=[5],Text=[For an example of the use of these aspects and |
| 1758 |
attributes, see the Streams Subsystem definitions in |
| 1759 |
@RefSecNum{The Streams Subsystem}.]} |
| 1760 |
@end{Notes} |
| 1761 |
|
| 1762 |
@begin{Extend2005} |
| 1763 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0230-1],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0262-1],ARef=[AI05-0273-1],ARef=[AI05-0274-1]} |
| 1764 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 1765 |
Pre and Post aspects are new.]} |
| 1766 |
@end{Extend2005} |
| 1767 |
|
| 1768 |
@begin{Inconsistent2012} |
| 1769 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1770 |
@ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:> |
| 1771 |
The Old attribute is defined more carefully. This changes the nominal subtype |
| 1772 |
and place of declaration of the attribute compared to the published Ada 2012 |
| 1773 |
Standard. In extreme cases, this could change the runtime behavior of the |
| 1774 |
attribute (for instance, the tag might be different). The changes are most |
| 1775 |
likely going to prevent bugs by being more intuitive, but it is possible that |
| 1776 |
a program that previously worked might fail.]} |
| 1777 |
|
| 1778 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 1779 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Eliminated unintentional |
| 1780 |
redispatching from class-wide preconditions and postconditions. This means |
| 1781 |
that a different body might be evaluated for a statically bound call to a |
| 1782 |
routine that has a class-wide precondition or postcondition. The change means |
| 1783 |
that the behavior of Pre and Pre'Class will be the same for a particular |
| 1784 |
subprogram, and that the known behavior of the operations can be assumed |
| 1785 |
within the body of that subprogram for Pre'Class. We expect that this change |
| 1786 |
will primarily fix bugs, as it will make Pre'Class and Post'Class work more |
| 1787 |
like expected. In the case where redispatching is desired, an explicit |
| 1788 |
conversion to a class-wide type can be used.]} |
| 1789 |
|
| 1790 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0166-1]} |
| 1791 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Specified that precondition |
| 1792 |
checks always take place before starting a protected action. Original Ada |
| 1793 |
2012 left this unspecified, so if an implementation made the checks after |
| 1794 |
starting the protected action, and a program depended upon that, the |
| 1795 |
program might fail in a different compiler. But such a program was depending |
| 1796 |
on unspecified behavior anyway, and thus was never portable; as such, |
| 1797 |
such programs should be rare.]} |
| 1798 |
|
| 1799 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0195-1]} |
| 1800 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Specified that an inherited |
| 1801 |
subprogram check both the original and new versions of a class-wide |
| 1802 |
precondition. If a call on an inherited subprogram fails the original |
| 1803 |
class-wide precondition when it passes the new class-wide precondition, |
| 1804 |
then the call will fail the precondition check wheras it would have passed |
| 1805 |
in original Ada 2012. (A similar possibility exists for class-wide |
| 1806 |
postconditions.) This can only happen if the overriding subprograms somehow |
| 1807 |
fail to follow the guidelines of LSP, so this should be rare (the entire |
| 1808 |
point of class-wide preconditions and postconditions is to use them in |
| 1809 |
cases where LSP is followed).]} |
| 1810 |
@end{Inconsistent2012} |
| 1811 |
|
| 1812 |
@begin{Incompatible2012} |
| 1813 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0045-1]} |
| 1814 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]} |
| 1815 |
@ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:> |
| 1816 |
Precondition and postcondition aspects cannot be specified on instances of |
| 1817 |
generic subprograms (they should be specified on the generic subprogram |
| 1818 |
instead). This was (unintentionally) allowed by the Ada 2012 standard. |
| 1819 |
These are not @Chg{Version=[5],New=[],Old=[be ]}allowed on instances as |
| 1820 |
there is no corresponding way to add |
| 1821 |
preconditions and postconditions to subprograms declared within the instance |
| 1822 |
of a generic package. Therefore, allowing specification on a subprogram |
| 1823 |
instance could present a maintenance problem in the future if the entity |
| 1824 |
needs to be converted to a generic package (a common conversion).]} |
| 1825 |
|
| 1826 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0131-1]} |
| 1827 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Pre'Class is no longer allowed |
| 1828 |
to be specified for an overriding primitive subprogram unless there are |
| 1829 |
also inherited class-wide precondittions. This incompatibility prevents |
| 1830 |
cases where the explicit Pre'Class is counterfeited by an implicit |
| 1831 |
class-wide precondition of True. This rule should catch more bugs than it |
| 1832 |
creates; the programmer should have written Pre rather than Pre'Class in |
| 1833 |
this case (or written Pre'Class on the original subprogram, not |
| 1834 |
an overriding). Note that this incompatibility eliminates what otherwise |
| 1835 |
would be an inconsistency with original Ada 2012, where precondition checks |
| 1836 |
that would have previously been made for a statically bound call would no |
| 1837 |
longer be made. That dynamic change was necessary to eliminate cases where |
| 1838 |
the evaluated class-wide precondition on a dispatching call would have been |
| 1839 |
weaker than the class-wide precondition of a statically bound call. (The |
| 1840 |
original Ada 2012 violated the LSP semantics that class-wide preconditions |
| 1841 |
were intended to model.)]} |
| 1842 |
|
| 1843 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0198-1]} |
| 1844 |
@ChgAdded{Version=[5],Text=[@b<Correction:> A component @nt{expression} |
| 1845 |
in an array aggregate can now be potentially unevaluated, requiring the |
| 1846 |
prefix to be statically determined. Existing code that uses the Old |
| 1847 |
attribute with a dynamic prefix in such contexts will now be illegal. |
| 1848 |
However, in many cases, the existing code will not do what the |
| 1849 |
programmer is expecting (as Old is evaluated textually, once per occurrence, |
| 1850 |
while array aggregate components are evaluated once per component). In |
| 1851 |
addition, Old is a new Ada 2012 feature, so most Ada legacy code will not |
| 1852 |
contain it. The problem is usually easily fixed by moving Old to an outer |
| 1853 |
object (such as the entire aggregate).]} |
| 1854 |
@end{Incompatible2012} |
| 1855 |
|
| 1856 |
@begin{Extend2012} |
| 1857 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0143-1]} |
| 1858 |
@ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012} |
| 1859 |
The Index attribute is new.]} |
| 1860 |
|
| 1861 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0217-1]} |
| 1862 |
@ChgAdded{Version=[5],Text=[@b<Correction:> The prefix of a statically |
| 1863 |
unevaluated Old attribute can be a @nt{selected_component} or |
| 1864 |
@nt{indexed_component}. This is considered a correction as the old rule |
| 1865 |
is unintentionally too fierce, rejecting safe cases.]} |
| 1866 |
|
| 1867 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0280-2]} |
| 1868 |
@ChgAdded{Version=[5],Text=[We make no restriction on the prefix of an |
| 1869 |
Old attribute if we can determine when the subprogram is entered (which |
| 1870 |
is the point when Old prefixes are evaluated) whether it will be needed |
| 1871 |
in the evaluation of the postcondition.]} |
| 1872 |
|
| 1873 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0220-1],ARef=[AI12-0272-1]} |
| 1874 |
@ChgAdded{Version=[5],Text=[Pre and Post can be given on an |
| 1875 |
access-to-subprogram type and on a generic formal subprogram.]} |
| 1876 |
@end{Extend2012} |
| 1877 |
|
| 1878 |
@begin{Diffword2012} |
| 1879 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0170-1]} |
| 1880 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Clarified the wording about |
| 1881 |
the meaning of the notional type @i<NT> and the corresponding expression. |
| 1882 |
Both changes follow from other rules but are nonobvious.]} |
| 1883 |
|
| 1884 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0185-1]} |
| 1885 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Removed redundant (and sometimes |
| 1886 |
incorrect) wording about the resolution of the Old and Result attributes.]} |
| 1887 |
@end{Diffword2012} |
| 1888 |
|
| 1889 |
|
| 1890 |
@LabeledAddedSubclause{Version=[5],Name=[The Global and Global'Class Aspects]} |
| 1891 |
|
| 1892 |
@Comment{There is no section around these, weird, but consistent with Pre and |
| 1893 |
Type_Invariant} |
| 1894 |
|
| 1895 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 1896 |
@ChgAdded{Version=[5],Type=[Leading],Text=[For a |
| 1897 |
subprogram, an entry, a named access-to-subprogram type, a task |
| 1898 |
unit, a protected unit, or a library package or generic library package, |
| 1899 |
the following language-defined aspect may be specified with an |
| 1900 |
@nt{aspect_specification} (see @RefSecNum{Aspect Specifications}):]} |
| 1901 |
|
| 1902 |
@begin{Description} |
| 1903 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 1904 |
@ChgAdded{Version=[5],Type=[Leading],Text=[Global@\The syntax for the |
| 1905 |
@nt{aspect_definition} used to define a Global aspect is as |
| 1906 |
follows:@AspectDefn{Global}]} |
| 1907 |
|
| 1908 |
@ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Global], |
| 1909 |
Text=[@ChgAdded{Version=[5],Text=[Global object usage contract.]}]} |
| 1910 |
|
| 1911 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1912 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<global_aspect_definition>,Old=<>}>, |
| 1913 |
rhs="@Chg{Version=[5],New=< |
| 1914 |
@key[null] |
| 1915 |
| Unspecified |
| 1916 |
| @Syn2{global_mode} @Syn2{global_designator} |
| 1917 |
| (@Syn2{global_aspect_element}{, @Syn2{global_aspect_element}}) |
| 1918 |
| @Syn2{extended_global_aspect_definition}>,Old=<>}"} |
| 1919 |
|
| 1920 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1921 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<global_aspect_element>,Old=<>}>, |
| 1922 |
rhs="@Chg{Version=[5],New=< |
| 1923 |
@Syn2{global_mode} @Syn2{global_set} |
| 1924 |
| @Syn2{extended_global_aspect_element}>,Old=<>}"} |
| 1925 |
|
| 1926 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1927 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<global_mode>,Old=<>}>, |
| 1928 |
rhs="@Chg{Version=[5],New=< |
| 1929 |
@Syn2{basic_global_mode} |
| 1930 |
| @Syn2{extended_global_mode}>,Old=<>}"} |
| 1931 |
|
| 1932 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1933 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<basic_global_mode>,Old=<>}>, |
| 1934 |
rhs="@Chg{Version=[5],New=<@key[in] | @key[in out] | @key[out]>,Old=<>}"} |
| 1935 |
|
| 1936 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1937 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<global_set>,Old=<>}>, |
| 1938 |
rhs="@Chg{Version=[5],New=<@Syn2{global_name} {, @Syn2{global_name}}>,Old=<>}"} |
| 1939 |
|
| 1940 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 1941 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<global_designator>,Old=<>}>, |
| 1942 |
rhs="@Chg{Version=[5],New=<@key[all] | @key[synchronized] | @Syn2[global_name]>,Old=<>}"} |
| 1943 |
|
| 1944 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-1],ARef=[AI12-0310-1]} |
| 1945 |
@noprefix@AddedSyn{Version=[5],lhs=<@Chg{Version=[5],New=<global_name>,Old=<>}>, |
| 1946 |
rhs="@Chg{Version=[5],New=<@SynI{object_}@Syn2{name} | @SynI{package_}@Syn2{name}>,Old=<>}"} |
| 1947 |
|
| 1948 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 1949 |
@ChgAdded{Version=[5],Noprefix=[T],Text=[The Global aspect identifies the set |
| 1950 |
of variables (which, for the purposes of this clause includes all constants |
| 1951 |
with some part being immutably limited, or of a controlled type, private |
| 1952 |
type, or private extension) that are global to a callable entity |
| 1953 |
or task body, and that are read or updated as part of the execution |
| 1954 |
of the callable entity or task body. If specified for a protected |
| 1955 |
unit, it refers to all of the protected operations of the protected |
| 1956 |
unit. Constants of any type may also be mentioned in a Global aspect.]} |
| 1957 |
|
| 1958 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 1959 |
@ChgAdded{Version=[5],Noprefix=[T],Text=[If not specified or otherwise defined |
| 1960 |
below, the aspect defaults to the Global aspect for the enclosing library unit |
| 1961 |
if the entity is declared at library level, and to Unspecified otherwise. If |
| 1962 |
not specified for a library unit, the aspect defaults to |
| 1963 |
@exam[Global => @key{null}] for a library unit that is declared Pure, and |
| 1964 |
to @exam[Global => Unspecified] otherwise.]} |
| 1965 |
@end{Description} |
| 1966 |
|
| 1967 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 1968 |
@ChgAdded{Version=[5],Type=[Leading],Text=[For a |
| 1969 |
dispatching subprogram, the following language-defined aspect may be |
| 1970 |
specified with an |
| 1971 |
@nt{aspect_specification} (see @RefSecNum{Aspect Specifications}):]} |
| 1972 |
|
| 1973 |
@begin{Description} |
| 1974 |
|
| 1975 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-1]} |
| 1976 |
@ChgAdded{Version=[5],Text=[Global'Class@\The syntax for |
| 1977 |
the @nt{aspect_definition} used to define a Global'Class |
| 1978 |
aspect is the same as that defined above for @nt{global_aspect_definition}. |
| 1979 |
This aspect identifies an upper bound on the |
| 1980 |
set of variables global to a dispatching operation that can be read |
| 1981 |
or updated as a result of a dispatching call on the operation. If not |
| 1982 |
specified, the aspect defaults to the Global aspect for the |
| 1983 |
dispatching subprogram.@AspectDefn{Global'Class}]} |
| 1984 |
|
| 1985 |
@ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Global'Class], |
| 1986 |
Text=[@ChgAdded{Version=[5],Text=[Global object usage contract inherited |
| 1987 |
on derivation.]}]} |
| 1988 |
|
| 1989 |
@end{Description} |
| 1990 |
|
| 1991 |
@begin{Resolution} |
| 1992 |
|
| 1993 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 1994 |
@ChgAdded{Version=[5],Text=[A @nt{global_name} shall resolve to statically |
| 1995 |
denote an object or a package (including a limited view of a package).]} |
| 1996 |
@end{Resolution} |
| 1997 |
|
| 1998 |
@begin{StaticSem} |
| 1999 |
|
| 2000 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2001 |
@ChgAdded{Version=[5],Text=[A @nt{global_aspect_definition} defines the |
| 2002 |
Global or Global'Class aspect of |
| 2003 |
some entity. The Global aspect identifies the sets of global variables |
| 2004 |
that can be read, written, or modified as a side effect of executing the |
| 2005 |
operation(s) associated with the entity. The Global'Class aspect |
| 2006 |
associated with a dispatching operation of type @i{T} represents a |
| 2007 |
restriction on the Global aspect on a corresponding operation of any |
| 2008 |
descendant of type @i{T}.]} |
| 2009 |
|
| 2010 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2011 |
@ChgAdded{Version=[5],Text=[The Global aspect for a callable entity defines the |
| 2012 |
global variables that might be referenced as part of a call on the entity, |
| 2013 |
including any assertion expressions that might be evaluated as part of the |
| 2014 |
call, including preconditions, postconditions, predicates, and type |
| 2015 |
invariants.]} |
| 2016 |
|
| 2017 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2018 |
@ChgAdded{Version=[5],Text=[The Global aspect for an access-to-subprogram |
| 2019 |
object (or subtype) identifies the global variables that might be referenced |
| 2020 |
when calling via the object (or any object of that subtype) including |
| 2021 |
assertion expressions that apply.]} |
| 2022 |
|
| 2023 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2024 |
@ChgAdded{Version=[5],Text=[For a predefined operator of an elementary type, |
| 2025 |
or the function representing an enumeration literal, the Global aspect is |
| 2026 |
@key{null}. For a predefined operator of a composite type, the Global aspect |
| 2027 |
of the operator defaults to that of the enclosing library unit (unless a Global |
| 2028 |
aspect is specified for the type @em see |
| 2029 |
@RefSecNum{Extensions to Global and Global'Class Aspects}).]} |
| 2030 |
|
| 2031 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2032 |
@ChgAdded{Version=[5],Text=[The following is defined in terms of operations; the |
| 2033 |
rules apply to all of the above kinds of entities.]} |
| 2034 |
|
| 2035 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2036 |
@ChgAdded{Version=[5],Text=[The global variables associated with any |
| 2037 |
@nt{global_mode} can be read as a side effect of an operation. The @key[in out] |
| 2038 |
and @key[out] @nt{global_mode}s together identify the set of global variables |
| 2039 |
that can be updated as a side effect of an operation. Creating an |
| 2040 |
access-to-variable value that designates an object is considered an update |
| 2041 |
of the designated object, and creating an access-to-constant value that |
| 2042 |
designates an object is considered a read of the designated object.]} |
| 2043 |
|
| 2044 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2045 |
@ChgAdded{Version=[5],Text=[The overall set of objects associated with each |
| 2046 |
@nt{global_mode} includes all objects identified for the mode in the |
| 2047 |
@nt{global_aspect_definition}.]} |
| 2048 |
|
| 2049 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2050 |
@ChgAdded{Version=[5],Type=[Leading],Text=[A @nt{global_set} identifies a |
| 2051 |
@i{global variable set} as follows:@Defn{global variable set}]} |
| 2052 |
|
| 2053 |
@begin{Itemize} |
| 2054 |
|
| 2055 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2056 |
@ChgAdded{Version=[5],Text=[@key[all] identifies the set of all global |
| 2057 |
variables;]} |
| 2058 |
|
| 2059 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2060 |
@ChgAdded{Version=[5],Text=[@key[synchronized] identifies the set of all |
| 2061 |
synchronized variables (see @RefSecNum{Shared Variables}), |
| 2062 |
as well as variables of a composite type all of whose |
| 2063 |
non-discriminant subcomponents are synchronized;]} |
| 2064 |
|
| 2065 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2066 |
@ChgAdded{Version=[5],Type=[Leading],Text=[@nt{global_name}{, @nt{global_name}} |
| 2067 |
identifies the union of the |
| 2068 |
sets of variables identified by the @nt{global_name}s in the list, |
| 2069 |
for the following forms of @nt{global_name}:]} |
| 2070 |
|
| 2071 |
@begin{Itemize} |
| 2072 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2073 |
@ChgAdded{Version=[5],Text=[@Syni{object_}@nt{name} identifies the |
| 2074 |
specified global variable (or constant);]} |
| 2075 |
|
| 2076 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2077 |
@ChgAdded{Version=[5],Text=[@Syni{package_}@nt{name} identifies the set |
| 2078 |
of all variables declared in the private part or body of the package, or |
| 2079 |
anywhere within a private descendant of the package.]} |
| 2080 |
@end{Itemize} |
| 2081 |
@end{Itemize} |
| 2082 |
|
| 2083 |
@end{StaticSem} |
| 2084 |
|
| 2085 |
@begin{Legality} |
| 2086 |
|
| 2087 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-1]} |
| 2088 |
@ChgAdded{Version=[5],Text=[Within a @nt{global_aspect_definition}, a |
| 2089 |
given @nt{global_mode} shall be specified at most once. Similarly, within a |
| 2090 |
@nt{global_aspect_definition}, a given entity shall be named at most |
| 2091 |
once by a @nt{global_name}.]} |
| 2092 |
|
| 2093 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2094 |
@ChgAdded{Version=[5],Type=[Leading],Text=[If an entity (other than a library |
| 2095 |
package or generic library package) has a Global aspect other than Unspecified |
| 2096 |
or @key[in out all], then the |
| 2097 |
associated operation(s) shall read only those variables global to the |
| 2098 |
entity that are within the global variable set associated with the @key[in], |
| 2099 |
@key[in out], or @key[out] @nt{global_mode}s, and the operation(s) shall update only those |
| 2100 |
variables global to the entity that are within the global variable set |
| 2101 |
associated with either the @key[in out] or @key[out] @nt{global_mode}s. In |
| 2102 |
the absence of the No_Hidden_Indirect_Globals restriction (see |
| 2103 |
@RefSecNum{High Integrity Restrictions}), |
| 2104 |
this ignores objects reached via a dereference of an access value. The |
| 2105 |
above rule includes any possible Global effects of calls occurring |
| 2106 |
during the execution of the operation, except for the following excluded |
| 2107 |
calls:]} |
| 2108 |
|
| 2109 |
@begin{Itemize} |
| 2110 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2111 |
@ChgAdded{Version=[5],Text=[calls to formal subprograms;]} |
| 2112 |
|
| 2113 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2114 |
@ChgAdded{Version=[5],Text=[calls associated with operations on |
| 2115 |
formal subtypes;]} |
| 2116 |
|
| 2117 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2118 |
@ChgAdded{Version=[5],Text=[calls through formal objects of |
| 2119 |
an access-to-subprogram type;]} |
| 2120 |
|
| 2121 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2122 |
@ChgAdded{Version=[5],Text=[calls through access-to-subprogram parameters;]} |
| 2123 |
|
| 2124 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2125 |
@ChgAdded{Version=[5],Text=[calls on operations with Global aspect |
| 2126 |
Unspecified.]} |
| 2127 |
|
| 2128 |
@end{Itemize} |
| 2129 |
|
| 2130 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2131 |
@ChgAdded{Version=[5],Text=[The possible Global effects of these excluded |
| 2132 |
calls (other than those that are Unspecified) are taken into account by the |
| 2133 |
caller of the original operation, by presuming they occur at least once |
| 2134 |
during its execution. For calls that are not excluded, the possible Global |
| 2135 |
effects of the call are those permitted by the Global aspect of the associated |
| 2136 |
entity, or by its Global'Class aspect if a dispatching call.]} |
| 2137 |
|
| 2138 |
@begin{Ramification} |
| 2139 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2140 |
@ChgAdded{Version=[5],Text=[For a predefined equality operator of a composite |
| 2141 |
type, the possible Global effects includes those of the equality |
| 2142 |
operations invoked as part of the evaluation of the operator (which |
| 2143 |
might not be predefined and thus might have a different Global |
| 2144 |
specification than the component types).]} |
| 2145 |
@end{Ramification} |
| 2146 |
|
| 2147 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2148 |
@ChgAdded{Version=[5],Text=[If a Global aspect other than Unspecified or |
| 2149 |
@key[in out all] applies to an access-to-subprogram type, then the @nt{prefix} |
| 2150 |
of an Access @nt{attribute_reference} producing a value of such a type shall denote |
| 2151 |
a subprogram whose Global aspect is not Unspecified and is |
| 2152 |
@i<covered>@Defn{Term=[covered],Sec=(global aspect)} by that of the result |
| 2153 |
type, where a global aspect @i<G1> is @i<covered> by a global aspect @i<G2> |
| 2154 |
if the set of variables that @i<G1> identifies as readable or updatable is |
| 2155 |
a subset of the corresponding set for @i<G2>. Similarly on a conversion to |
| 2156 |
such a type, the operand shall be of a named access-to-subprogram type whose |
| 2157 |
Global aspect is covered by that of the target type.]} |
| 2158 |
|
| 2159 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2160 |
@ChgAdded{Version=[5],Text=[If an implementation-defined |
| 2161 |
@nt{global_mode} applies to a given |
| 2162 |
set of variables, an implementation-defined rule determines what sort |
| 2163 |
of references to them are permitted.]}@Comment{The @ChgImplDef is provided |
| 2164 |
above.} |
| 2165 |
|
| 2166 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-1]} |
| 2167 |
@ChgAdded{Version=[5],Text=[For a subprogram that is a dispatching operation |
| 2168 |
of a tagged type @i<T>, |
| 2169 |
each mode of its Global aspect shall identify a subset of the variables |
| 2170 |
identified by the corresponding mode, or by the @key[in out] mode, of the |
| 2171 |
Global'Class aspect of a corresponding dispatching subprogram of any |
| 2172 |
ancestor of @i<T>, unless the aspect of that ancestor is Unspecified.]} |
| 2173 |
|
| 2174 |
@end{Legality} |
| 2175 |
|
| 2176 |
@begin{ImplPerm} |
| 2177 |
|
| 2178 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2179 |
@ChgAdded{Version=[5],Text=[Implementations need not require that references to |
| 2180 |
a constant object that are considered variables in the above rules, be |
| 2181 |
accounted for by the Global or Global'Class aspect, if the implementation can |
| 2182 |
determine that the constant object is immutable.]} |
| 2183 |
|
| 2184 |
@begin{Ramification} |
| 2185 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2186 |
@ChgAdded{Version=[5],Text=[In particular, this allows the implementation |
| 2187 |
to violate privacy in order to determine whether a constant needs to be |
| 2188 |
covered by a Global aspect.]} |
| 2189 |
@end{Ramification} |
| 2190 |
|
| 2191 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2192 |
@ChgAdded{Version=[5],Text=[Implementations may perform additional checks on |
| 2193 |
calls to operations with an Unspecified Global aspect to ensure that they |
| 2194 |
do not violate any limitations associated with the point of call.]} |
| 2195 |
|
| 2196 |
@begin{Discussion} |
| 2197 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2198 |
@ChgAdded{Version=[5],Text=[In this sense, @exam{Global => Unspecified} |
| 2199 |
is not permission to violate the caller's Global restrictions. It is rather |
| 2200 |
that the implementor of the subprogram is presuming other means are being |
| 2201 |
used to ensure safety. Note the No_Unspecified_Globals Restriction |
| 2202 |
(@RefSecNum{High Integrity Restrictions}), which prevents the use of |
| 2203 |
Unspecified with the Global aspect in a given partition.]} |
| 2204 |
@end{Discussion} |
| 2205 |
|
| 2206 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-3]} |
| 2207 |
@ChgAdded{Version=[5],Text=[Implementations may extend the syntax or semantics |
| 2208 |
of the Global aspect in an implementation-defined manner@Redundant[; for |
| 2209 |
example, supporting additional @nt{global_mode}s].]} |
| 2210 |
|
| 2211 |
@ChgImplDef{Version=[5],Kind=[AddedNormal],InitialVersion=[5], |
| 2212 |
Text=[@ChgAdded{Version=[5],Text=[Any extensions of the |
| 2213 |
Global aspect.]}]} |
| 2214 |
|
| 2215 |
@begin{Reason} |
| 2216 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 2217 |
@ChgAdded{Version=[5],Text=[This is intended to allow preexisting usages |
| 2218 |
from SPARK 2014 to remain acceptable in conforming implementations, as well |
| 2219 |
as to provide flexibility for future enhancements. Note the word |
| 2220 |
@ldquote@;extend@rdquote in this permission; we expect that any aspect usage |
| 2221 |
that conforms with the (other) rules of this clause will be accepted by |
| 2222 |
any Ada implementation, regardless of any implementation-defined extensions.]} |
| 2223 |
@end{Reason} |
| 2224 |
|
| 2225 |
@end{ImplPerm} |
| 2226 |
|
| 2227 |
@begin{Notes} |
| 2228 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0312-1]} |
| 2229 |
@ChgAdded{Version=[5],Text=[For an example of the use of these aspects and attributes, |
| 2230 |
see the Vector container definition in @RefSecNum{The Generic Package Containers.Vectors}.]} |
| 2231 |
@end{Notes} |
| 2232 |
|
| 2233 |
|
| 2234 |
@begin{Extend2012} |
| 2235 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0079-1],ARef=[AI12-0240-6],ARef=[AI12-0310-1]} |
| 2236 |
@ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012} |
| 2237 |
The Global and Global'Class aspects are new.]} |
| 2238 |
@end{Extend2012} |
| 2239 |
|
| 2240 |
|
| 2241 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 2242 |
@LabeledClause{Formal Parameter Modes} |
| 2243 |
|
| 2244 |
@begin{Intro} |
| 2245 |
@Redundant[A @nt{parameter_specification} declares a formal parameter of |
| 2246 |
mode @key[in], @key[in out], or @key[out].] |
| 2247 |
@end{Intro} |
| 2248 |
|
| 2249 |
@begin{StaticSem} |
| 2250 |
@Defn{pass by copy} |
| 2251 |
@Defn{by copy parameter passing} |
| 2252 |
@Defn{copy parameter passing} |
| 2253 |
@Defn{pass by reference} |
| 2254 |
@Defn{by reference parameter passing} |
| 2255 |
@Defn{reference parameter passing} |
| 2256 |
A parameter is passed either @i{by copy} or @i{by reference}. |
| 2257 |
@Redundant[When a parameter is passed by copy, |
| 2258 |
the formal parameter denotes a separate object from the |
| 2259 |
actual parameter, and any information transfer between the two occurs |
| 2260 |
only before and after executing the subprogram. |
| 2261 |
When a parameter is passed by reference, |
| 2262 |
the formal parameter denotes (a view of) the object denoted by the |
| 2263 |
actual parameter; reads and updates of the formal parameter directly |
| 2264 |
reference the actual parameter object.] |
| 2265 |
|
| 2266 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4],ARef=[AI05-0262-1]} |
| 2267 |
@Defn{by-copy type} |
| 2268 |
A type is a @i(by-copy type) if it is an elementary type, |
| 2269 |
or if it is a descendant of a private type whose full type is a |
| 2270 |
by-copy type. A parameter of a by-copy type is passed by |
| 2271 |
copy@Chg{Version=[3],New=[, unless the |
| 2272 |
formal parameter is explicitly aliased],Old=[]}. |
| 2273 |
|
| 2274 |
@leading@keepnext@Defn{by-reference type} |
| 2275 |
A type is a @i(by-reference type) if it |
| 2276 |
is a descendant of one of the following: |
| 2277 |
@begin(itemize) |
| 2278 |
a tagged type; |
| 2279 |
|
| 2280 |
a task or protected type; |
| 2281 |
|
| 2282 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0096-1]} |
| 2283 |
@Chg{Version=[3],New=[an explicitly limited record type],Old=[a |
| 2284 |
nonprivate type with the reserved word @key[limited] in its declaration]}; |
| 2285 |
@begin{Ramification} |
| 2286 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0096-1]} |
| 2287 |
@ChgDeleted{Version=[3],Text=[A limited private type is by-reference |
| 2288 |
only if it falls under one of the other categories.]} |
| 2289 |
@end{Ramification} |
| 2290 |
|
| 2291 |
a composite type with a subcomponent of a by-reference type; |
| 2292 |
|
| 2293 |
a private type |
| 2294 |
whose full type is a by-reference type. |
| 2295 |
@end(itemize) |
| 2296 |
|
| 2297 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4],ARef=[AI05-0188-1]} |
| 2298 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0027-1]} |
| 2299 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0236-1],ARef=[AI12-0317-1]} |
| 2300 |
A parameter of a by-reference type is passed by reference@Chg{Version=[3],New=[, as is an explicitly aliased parameter |
| 2301 |
of any type],Old=[]}. |
| 2302 |
@Defn2{Term=[associated object], Sec=(of a value of a by-reference type)} |
| 2303 |
Each value of a by-reference type has an associated |
| 2304 |
object.@Chg{Version=[5],New=[],Old=[ For a parenthesized expression, |
| 2305 |
@nt{qualified_expression}, |
| 2306 |
or @Chg{Version=[4],New=[view conversion],Old=[@nt{type_conversion}]}, this |
| 2307 |
object is the one associated with the operand.]}@Chg{Version=[4],New=[ For a value |
| 2308 |
conversion, the associated object is the anonymous result object if such an |
| 2309 |
object is created (see @RefSecNum{Type Conversions}); otherwise it is the |
| 2310 |
associated object of the operand.],Old=[]}@Chg{Version=[5],New=[ In |
| 2311 |
other cases, the object associated with the evaluated operative constituent of |
| 2312 |
the @nt{name} or @nt{expression} (see @RefSecNum{Expressions}) determines its |
| 2313 |
associated object.],Old=[@Chg{Version=[3],New=[ For a |
| 2314 |
@nt{conditional_expression}, this object is the one associated with the |
| 2315 |
evaluated @SynI{dependent_}@nt{expression}.],Old=[]}]} |
| 2316 |
|
| 2317 |
@begin{Ramification} |
| 2318 |
By-reference parameter passing makes sense only if there is an |
| 2319 |
object to reference; hence, we define such an object for each |
| 2320 |
case. |
| 2321 |
|
| 2322 |
Since tagged types are by-reference types, this implies that every value |
| 2323 |
of a tagged type has an associated object. This simplifies things, |
| 2324 |
because we can define the tag to be a property of the object, and not of |
| 2325 |
the value of the object, which makes it clearer that object tags never |
| 2326 |
change. |
| 2327 |
|
| 2328 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0317-1]} |
| 2329 |
@ChgAdded{Version=[5],Text=[A construct like parenthesized expression or |
| 2330 |
@nt{qualified_expression} is ignored for the purposes of determining the |
| 2331 |
associated object; for a @nt{conditional_expression}, it is relevant only |
| 2332 |
in that it determines which @SynI{dependent_}@nt{expression} defines |
| 2333 |
the associated object.]} |
| 2334 |
|
| 2335 |
We considered simplifying things even more by making every value (and |
| 2336 |
therefore every expression) have an associated object. After all, |
| 2337 |
there is little semantic difference between a constant object and a |
| 2338 |
value. |
| 2339 |
However, this would cause problems for untagged types. |
| 2340 |
In particular, we would have to do a constraint check on every read of a |
| 2341 |
type conversion (or a renaming thereof) in certain cases. |
| 2342 |
|
| 2343 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2344 |
We do not want this definition to depend on the view of the type; |
| 2345 |
privateness is essentially ignored for this definition. |
| 2346 |
Otherwise, things would be confusing (does the rule apply at the call |
| 2347 |
site, at the site of the declaration of the subprogram, |
| 2348 |
at the site of the |
| 2349 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]}?), |
| 2350 |
and requiring different calls to use different mechanisms would be an |
| 2351 |
implementation burden. |
| 2352 |
|
| 2353 |
@RefSec{Shared Variable Control} says that a composite type with an |
| 2354 |
atomic or volatile subcomponent is a by-reference type, |
| 2355 |
among other things. |
| 2356 |
|
| 2357 |
@Defn2{Term=[associated object], Sec=(of a value of a limited type)} |
| 2358 |
Every value of a limited by-reference type is the value of |
| 2359 |
one and only one limited object. |
| 2360 |
The @i{associated object} of a value of a limited by-reference type is |
| 2361 |
the object whose value it represents. |
| 2362 |
@Defn2{Term=[same value], Sec=(for a limited type)} |
| 2363 |
Two values of a limited by-reference type are the @i{same} |
| 2364 |
if and only if they represent the value of the same object. |
| 2365 |
|
| 2366 |
We say @lquotes@;by-reference@rquotes@; above because |
| 2367 |
these statements are not always true for limited private types |
| 2368 |
whose underlying type is nonlimited (unfortunately). |
| 2369 |
@end{Ramification} |
| 2370 |
|
| 2371 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0240-1]} |
| 2372 |
@PDefn{unspecified} |
| 2373 |
For @Chg{Version=[3],New=[other ],Old=[]}parameters@Chg{Version=[3],New=[],Old=[ of other types]}, |
| 2374 |
it is unspecified whether the parameter |
| 2375 |
is passed by copy or by reference. |
| 2376 |
@begin{Discussion} |
| 2377 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]} |
| 2378 |
There is no need to incorporate the discussion of AI83-00178, |
| 2379 |
which requires pass-by-copy for certain kinds of actual parameters, |
| 2380 |
while allowing pass-by-reference for others. |
| 2381 |
This is because we explicitly indicate that a function |
| 2382 |
creates an anonymous constant object for its result@Chg{Version=[3],New=[],Old=[, |
| 2383 |
unless the type is a return-by-reference type]} |
| 2384 |
(see @RefSecNum{Return Statements}). |
| 2385 |
We also provide a special dispensation for |
| 2386 |
instances of Unchecked_Conversion to return by reference@Chg{Version=[3],New=[],Old=[, even |
| 2387 |
if the result type is not a return-by-reference type]} |
| 2388 |
(see @RefSecNum{Unchecked Type Conversions}). |
| 2389 |
@end{Discussion} |
| 2390 |
@end{StaticSem} |
| 2391 |
|
| 2392 |
@begin{Bounded} |
| 2393 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0240-1]} |
| 2394 |
@Defn{distinct access paths} |
| 2395 |
@Defn2{Term=[access paths],Sec=(distinct)} |
| 2396 |
@IndexSee{Term=[aliasing],See=(distinct access paths)} |
| 2397 |
@PDefn2{Term=(bounded error),Sec=(cause)} |
| 2398 |
If one @nt<name> denotes a part of a formal parameter, |
| 2399 |
and a second @nt<name> denotes a part of |
| 2400 |
a distinct formal parameter or an object that is not |
| 2401 |
part of a formal parameter, then the two @nt<name>s are |
| 2402 |
considered @i(distinct access paths). |
| 2403 |
If an object is of a type for which the parameter passing |
| 2404 |
mechanism is not specified@Chg{Version=[3],New=[ and is not an |
| 2405 |
explicitly aliased parameter],Old=[]}, then it is a bounded error to |
| 2406 |
assign to the object via one access path, |
| 2407 |
and then read the value of the object via a distinct access path, |
| 2408 |
unless the first access path denotes a part of a formal parameter that |
| 2409 |
no longer exists at the point of the second access |
| 2410 |
@Redundant[(due to leaving the corresponding callable construct).] |
| 2411 |
The possible consequences are that Program_Error is raised, |
| 2412 |
or the newly assigned value is read, or some old value of the object is read. |
| 2413 |
@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)} |
| 2414 |
@begin{Discussion} |
| 2415 |
For example, if we call @lquotes@;P(X => Global_Variable, Y => Global_Variable)@rquotes@;, |
| 2416 |
then within P, the names @lquotes@;X@rquotes@;, @lquotes@;Y@rquotes@;, and @lquotes@;Global_Variable@rquotes@; |
| 2417 |
are all distinct access paths. |
| 2418 |
If Global_Variable's type is neither pass-by-copy nor pass-by-reference, |
| 2419 |
then it is a bounded error to assign to Global_Variable and |
| 2420 |
then read X or Y, since the language does not specify whether the |
| 2421 |
old or the new value would be read. On the other hand, if |
| 2422 |
Global_Variable's type is pass-by-copy, then the old value would |
| 2423 |
always be read, and there is no error. Similarly, if Global_Variable's |
| 2424 |
type is defined by the language to be pass-by-reference, then the |
| 2425 |
new value would always be read, and again there is no error. |
| 2426 |
@end{Discussion} |
| 2427 |
@begin{Reason} |
| 2428 |
We are saying @i(assign) here, not @i(update), |
| 2429 |
because updating any subcomponent is considered |
| 2430 |
to update the enclosing object. |
| 2431 |
|
| 2432 |
The @lquotes@;still exists@rquotes@; part is so that a read after the subprogram returns |
| 2433 |
is OK. |
| 2434 |
|
| 2435 |
If the parameter is of a by-copy type, |
| 2436 |
then there is no issue here |
| 2437 |
@em the formal is not a view of the actual. |
| 2438 |
If the parameter is of a by-reference type, |
| 2439 |
then the programmer may depend on updates through one access path |
| 2440 |
being visible through some other access path, |
| 2441 |
just as if the parameter were of an access type. |
| 2442 |
@end{Reason} |
| 2443 |
@begin{ImplNote} |
| 2444 |
The implementation can keep a copy in a register of a parameter |
| 2445 |
whose parameter-passing mechanism is not specified. |
| 2446 |
If a different access path is used to update the object (creating |
| 2447 |
a bounded error situation), |
| 2448 |
then the implementation can still use the value of the register, |
| 2449 |
even though the in-memory version of the object has been changed. |
| 2450 |
However, to keep the error properly bounded, |
| 2451 |
if the implementation chooses to read the in-memory version, |
| 2452 |
it has to be consistent -- it cannot then assume that something it has |
| 2453 |
proven about the register is true of the memory location. |
| 2454 |
For example, suppose the formal parameter is L, |
| 2455 |
the value of L(6) is now in a register, and L(6) is used |
| 2456 |
in an @nt{indexed_component} as in @lquotes@;A(L(6)) := 99;@rquotes@;, |
| 2457 |
where A has bounds 1..3. |
| 2458 |
If the implementation can prove that the value for L(6) in the register is in |
| 2459 |
the range 1..3, then it need not perform the constraint check if it |
| 2460 |
uses the register value. |
| 2461 |
However, if the memory value of L(6) has been changed to 4, |
| 2462 |
and the implementation uses that memory value, |
| 2463 |
then it had better not alter memory outside of A. |
| 2464 |
|
| 2465 |
Note that the rule allows the implementation to pass a parameter by |
| 2466 |
reference and then keep just part of it in a register, or, |
| 2467 |
equivalently, to pass part of the parameter by reference and another |
| 2468 |
part by copy. |
| 2469 |
@end{ImplNote} |
| 2470 |
@begin{Reason} |
| 2471 |
@leading@;We do not want to go so far as to say that the mere presence |
| 2472 |
of aliasing is wrong. |
| 2473 |
We wish to be able to write the following sorts of things |
| 2474 |
in standard Ada: |
| 2475 |
@begin{Example} |
| 2476 |
@key[procedure] Move ( Source : @key[in] String; |
| 2477 |
Target : @key[out] String; |
| 2478 |
Drop : @key[in] Truncation := Error; |
| 2479 |
Justify : @key[in] Alignment := Left; |
| 2480 |
Pad : @key[in] Character := Space); |
| 2481 |
--@RI{ Copies elements from Source to Target (safely if they overlap)} |
| 2482 |
@end{Example} |
| 2483 |
|
| 2484 |
This is from the standard string handling package. |
| 2485 |
It would be embarrassing if this couldn't be written in Ada! |
| 2486 |
|
| 2487 |
The @lquotes@;then@rquotes@; before @lquotes@;read@rquotes@; in the rule implies that the implementation |
| 2488 |
can move a read to an earlier place in the code, but not to a later |
| 2489 |
place after a potentially aliased assignment. |
| 2490 |
Thus, if the subprogram reads one of its parameters into a local |
| 2491 |
variable, and then updates another potentially aliased one, |
| 2492 |
the local copy is safe @em it is known to have the old value. |
| 2493 |
For example, the above-mentioned Move subprogram can be implemented |
| 2494 |
by copying Source into a local variable before assigning into Target. |
| 2495 |
|
| 2496 |
@leading@;For an @nt{assignment_statement} assigning one array parameter to another, |
| 2497 |
the implementation has to check which direction to copy |
| 2498 |
at run time, in general, in case the actual parameters are |
| 2499 |
overlapping slices. |
| 2500 |
For example: |
| 2501 |
@begin{Example} |
| 2502 |
@key[procedure] Copy(X : @key[in out] String; Y: String) @key[is] |
| 2503 |
@key[begin] |
| 2504 |
X := Y; |
| 2505 |
@key[end] Copy; |
| 2506 |
@end{Example} |
| 2507 |
|
| 2508 |
It would be wrong for the compiler to assume that X and Y |
| 2509 |
do not overlap (unless, of course, it can prove otherwise). |
| 2510 |
@end{Reason} |
| 2511 |
@end{Bounded} |
| 2512 |
|
| 2513 |
@begin{Notes} |
| 2514 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0056-1]} |
| 2515 |
@ChgAdded{Version=[4],Text=[The mode of a formal parameter describes the |
| 2516 |
direction of information transfer to or from the @nt{subprogram_body} (see |
| 2517 |
@RefSecNum{Subprogram Declarations}).]} |
| 2518 |
|
| 2519 |
A formal parameter of mode @key(in) is a constant |
| 2520 |
view (see @RefSecNum{Objects and Named Numbers}); |
| 2521 |
it cannot be updated within the @nt{subprogram_body}. |
| 2522 |
|
| 2523 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0056-1]} |
| 2524 |
@ChgAdded{Version=[4],Text=[A formal parameter of mode @key(out) |
| 2525 |
might be uninitialized at the start of the @nt{subprogram_body} (see |
| 2526 |
@RefSecNum{Parameter Associations}).]} |
| 2527 |
@end{Notes} |
| 2528 |
|
| 2529 |
@begin{Extend83} |
| 2530 |
@Defn{extensions to Ada 83} |
| 2531 |
The value of an @key(out) parameter may be read. |
| 2532 |
An @key(out) parameter is treated like a declared |
| 2533 |
variable without an explicit initial expression. |
| 2534 |
@end{Extend83} |
| 2535 |
|
| 2536 |
@begin{DiffWord83} |
| 2537 |
Discussion of copy-in for parts of out parameters is now |
| 2538 |
covered in @RefSec{Parameter Associations}. |
| 2539 |
|
| 2540 |
The concept of a by-reference type is new to Ada 95. |
| 2541 |
|
| 2542 |
We now cover in a general way in @RefSecNum{Operations of Discriminated Types} |
| 2543 |
the rule regarding erroneous execution when a discriminant |
| 2544 |
is changed and one of the parameters depends on the discriminant. |
| 2545 |
@end{DiffWord83} |
| 2546 |
|
| 2547 |
@begin{DiffWord2005} |
| 2548 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0096-1]} |
| 2549 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected so that |
| 2550 |
limited derived types are by-reference only if their parent is.]} |
| 2551 |
|
| 2552 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 2553 |
@ChgAdded{Version=[3],Text=[Defined that explicitly aliased parameters |
| 2554 |
(see @RefSecNum{Subprogram Declarations}) are always passed by reference.]} |
| 2555 |
@end{DiffWord2005} |
| 2556 |
|
| 2557 |
@begin{DiffWord2012} |
| 2558 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0027-1]} |
| 2559 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Corrected so that |
| 2560 |
value conversions that are copies are the @ldquote@;associated object@rdquote |
| 2561 |
for parameter passing of by-reference types. This can only happen if the |
| 2562 |
conversion is between unrelated non-limited types, and it is necessary just |
| 2563 |
so the correct object is defined.]} |
| 2564 |
@end{DiffWord2012} |
| 2565 |
|
| 2566 |
|
| 2567 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 2568 |
@LabeledClause{Subprogram Bodies} |
| 2569 |
|
| 2570 |
@begin{Intro} |
| 2571 |
@Redundant[A @nt{subprogram_body} specifies the execution of a |
| 2572 |
subprogram.] |
| 2573 |
@end{Intro} |
| 2574 |
|
| 2575 |
@begin{Syntax} |
| 2576 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 2577 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]} |
| 2578 |
@Syn{lhs=<subprogram_body>,rhs="@Chg{Version=[2],New=< |
| 2579 |
[@Syn2{overriding_indicator}]>,Old=<>} |
| 2580 |
@Syn2{subprogram_specification}@Chg{Version=[3],New=< |
| 2581 |
[@Syn2{aspect_specification}]>,Old=[]} @key{is} |
| 2582 |
@Syn2{declarative_part} |
| 2583 |
@key{begin} |
| 2584 |
@Syn2{handled_sequence_of_statements} |
| 2585 |
@key{end} [@Syn2{designator}];"} |
| 2586 |
|
| 2587 |
@begin{SyntaxText} |
| 2588 |
If a @nt{designator} appears at the end of a @nt{subprogram_body}, |
| 2589 |
it shall repeat the @nt{defining_designator} of the @nt{subprogram_specification}. |
| 2590 |
@end{SyntaxText} |
| 2591 |
@end{Syntax} |
| 2592 |
|
| 2593 |
@begin{Legality} |
| 2594 |
@Redundant[In contrast to other bodies,] |
| 2595 |
a @nt{subprogram_body} need not be the completion of a previous |
| 2596 |
declaration@Redundant[, |
| 2597 |
in which case the body declares the subprogram]. |
| 2598 |
If the body is a completion, it shall be the completion of a |
| 2599 |
@nt{subprogram_declaration} or @nt{generic_subprogram_declaration}. |
| 2600 |
The profile of a @nt{subprogram_body} that completes a declaration |
| 2601 |
shall conform fully to that of the declaration. |
| 2602 |
@Defn2{Term=[full conformance],Sec=(required)} |
| 2603 |
@end{Legality} |
| 2604 |
|
| 2605 |
@begin{StaticSem} |
| 2606 |
A @nt{subprogram_body} is considered a declaration. |
| 2607 |
It can either complete a previous declaration, |
| 2608 |
or itself be the initial declaration of the subprogram. |
| 2609 |
@end{StaticSem} |
| 2610 |
|
| 2611 |
@begin{RunTime} |
| 2612 |
@PDefn2{Term=[elaboration], Sec=(nongeneric subprogram_body)} |
| 2613 |
The elaboration of a nongeneric |
| 2614 |
@nt{subprogram_body} has no other effect than to establish |
| 2615 |
that the subprogram can from then on be called without |
| 2616 |
failing the Elaboration_Check. |
| 2617 |
@begin{Ramification} |
| 2618 |
See @RefSecNum{Generic Bodies} for elaboration of a generic body. |
| 2619 |
Note that protected @ntf{subprogram_bodies} never get elaborated; |
| 2620 |
the elaboration of the containing @nt{protected_body} |
| 2621 |
allows them to be called without failing the Elaboration_Check. |
| 2622 |
@end{Ramification} |
| 2623 |
|
| 2624 |
@PDefn2{Term=[execution], Sec=(subprogram_body)} |
| 2625 |
@Redundant[The execution of a @nt{subprogram_body} is invoked by a |
| 2626 |
subprogram call.] |
| 2627 |
For this execution the @nt{declarative_part} is elaborated, and the |
| 2628 |
@nt{handled_sequence_of_statements} is then executed. |
| 2629 |
@end{RunTime} |
| 2630 |
|
| 2631 |
@begin{Examples} |
| 2632 |
@leading@keepnext@i{Example of procedure body:} |
| 2633 |
@begin{Example} |
| 2634 |
@key[procedure] Push(E : @key[in] Element_Type; S : @key[in] @key[out] Stack) @key[is] |
| 2635 |
@key[begin] |
| 2636 |
@key[if] S.Index = S.Size @key[then] |
| 2637 |
@key[raise] Stack_Overflow; |
| 2638 |
@key[else] |
| 2639 |
S.Index := S.Index + 1; |
| 2640 |
S.Space(S.Index) := E; |
| 2641 |
@key[end] @key[if]; |
| 2642 |
@key[end] Push; |
| 2643 |
@end{Example} |
| 2644 |
|
| 2645 |
@begin{WideAbove} |
| 2646 |
@leading@keepnext@i{Example of a function body:} |
| 2647 |
@end{WideAbove} |
| 2648 |
@begin{Example} |
| 2649 |
@key[function] Dot_Product(Left, Right : Vector) @key[return] Real @key[is] |
| 2650 |
Sum : Real := 0.0; |
| 2651 |
@key[begin] |
| 2652 |
Check(Left'First = Right'First @key[and] Left'Last = Right'Last); |
| 2653 |
@key[for] J @key[in] Left'Range @key[loop] |
| 2654 |
Sum := Sum + Left(J)*Right(J); |
| 2655 |
@key[end] @key[loop]; |
| 2656 |
@key[return] Sum; |
| 2657 |
@key[end] Dot_Product; |
| 2658 |
@end{Example} |
| 2659 |
@end{Examples} |
| 2660 |
|
| 2661 |
@begin{Extend83} |
| 2662 |
@Defn{extensions to Ada 83} |
| 2663 |
A @nt{renaming_declaration} may be used instead of a @nt{subprogram_body}. |
| 2664 |
@end{Extend83} |
| 2665 |
|
| 2666 |
@begin{DiffWord83} |
| 2667 |
The syntax rule for @nt{subprogram_body} now uses the syntactic category |
| 2668 |
@nt{handled_sequence_of_statements}. |
| 2669 |
|
| 2670 |
The @nt{declarative_part} of a @nt{subprogram_body} is now required; |
| 2671 |
that doesn't make any real difference, |
| 2672 |
because a @nt{declarative_part} can be empty. |
| 2673 |
|
| 2674 |
We have incorporated some rules from RM83-6.5 here. |
| 2675 |
|
| 2676 |
RM83 forgot to restrict the definition of elaboration of a |
| 2677 |
@nt{subprogram_body} to nongenerics. |
| 2678 |
@end{DiffWord83} |
| 2679 |
|
| 2680 |
@begin{DiffWord95} |
| 2681 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 2682 |
@ChgAdded{Version=[2],Text=[@nt{Overriding_indicator} is added to |
| 2683 |
@nt{subprogram_body}.]} |
| 2684 |
@end{DiffWord95} |
| 2685 |
|
| 2686 |
@begin{Extend2005} |
| 2687 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 2688 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}An optional |
| 2689 |
@nt{aspect_specification} can be used in a @nt{subprogram_body}. |
| 2690 |
This is described in @RefSecNum{Aspect Specifications}.]} |
| 2691 |
@end{Extend2005} |
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
@LabeledSubClause{Conformance Rules} |
| 2696 |
|
| 2697 |
@begin{Intro} |
| 2698 |
@Defn{conformance} |
| 2699 |
@SeeAlso{Primary=[conformance],Other=(type conformance)} |
| 2700 |
@SeeAlso{Primary=[conformance],Other=(mode conformance)} |
| 2701 |
@SeeAlso{Primary=[conformance],Other=(subtype conformance)} |
| 2702 |
@SeeAlso{Primary=[conformance],Other=(full conformance)} |
| 2703 |
@Redundant[When subprogram profiles are given in more than one place, |
| 2704 |
they are required to conform in one of four ways: type conformance, mode |
| 2705 |
conformance, subtype conformance, or full conformance.] |
| 2706 |
@end{Intro} |
| 2707 |
|
| 2708 |
@begin{StaticSem} |
| 2709 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 2710 |
@leading@Defn{convention} |
| 2711 |
@Defn{calling convention} |
| 2712 |
@Redundant[As explained in @RefSec{Interfacing Aspects}, |
| 2713 |
a @i{convention} can be specified for an entity.] |
| 2714 |
@Chg{New=[Unless this International Standard states otherwise, the default |
| 2715 |
convention of an entity is Ada.],Old=[]} |
| 2716 |
@Redundant[For a callable entity or access-to-subprogram type, |
| 2717 |
the convention is called the @i{calling convention}.] |
| 2718 |
The following conventions are defined by the language: |
| 2719 |
@begin{Itemize} |
| 2720 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2721 |
@Defn{Ada calling convention} |
| 2722 |
@Defn2{Term=[calling convention], Sec=(Ada)} |
| 2723 |
The default calling convention for any subprogram not listed below is |
| 2724 |
@i{Ada}. |
| 2725 |
@Redundant[@Chg{Version=[3],New=[The],Old=[A @nt{pragma}]} |
| 2726 |
Convention@Chg{Version=[3],New=[ aspect],Old=[, Import, or Export]} |
| 2727 |
may be @Chg{Version=[3],New=[specified],Old=[used]} to override |
| 2728 |
the default calling convention (see @RefSecNum{Interfacing Aspects})]. |
| 2729 |
@begin{Ramification} |
| 2730 |
See also the rule about renamings-as-body |
| 2731 |
in @RefSecNum{Subprogram Renaming Declarations}. |
| 2732 |
@end{Ramification} |
| 2733 |
|
| 2734 |
@leading@Defn{Intrinsic calling convention} |
| 2735 |
@Defn2{Term=[calling convention], Sec=(Intrinsic)} |
| 2736 |
The @i{Intrinsic} calling convention represents |
| 2737 |
subprograms that are @lquotes@;built in@rquotes@; to the compiler. |
| 2738 |
The default calling convention is Intrinsic for the following: |
| 2739 |
@begin{InnerItemize} |
| 2740 |
an enumeration literal; |
| 2741 |
|
| 2742 |
a "/=" operator declared implicitly due to |
| 2743 |
the declaration of "=" (see @RefSecNum{Overloading of Operators}); |
| 2744 |
|
| 2745 |
any other implicitly declared subprogram unless it is |
| 2746 |
a dispatching operation of a tagged type; |
| 2747 |
|
| 2748 |
an inherited subprogram of a generic formal tagged type |
| 2749 |
with unknown discriminants; |
| 2750 |
@begin{Reason} |
| 2751 |
@Comment{8652/0011 suggests that the reason for this rule be documented in |
| 2752 |
the AARM.} |
| 2753 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2754 |
@Chg{New=[Consider:],Old=[]} |
| 2755 |
@begin{Example} |
| 2756 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2757 |
@Chg{New=[@key[package] P @key[is] |
| 2758 |
@key[type] Root @key[is tagged null record]; |
| 2759 |
@key[procedure] Proc(X: Root); |
| 2760 |
@key[end] P;],Old=[]} |
| 2761 |
|
| 2762 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2763 |
@Chg{New=[@key[generic] |
| 2764 |
@key[type] Formal(<>) @key[is new] Root @key[with private]; |
| 2765 |
@key[package] G @key[is] |
| 2766 |
... |
| 2767 |
@key[end] G;],Old=[]} |
| 2768 |
|
| 2769 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2770 |
@ChgAdded{Version=[1],Text=[@key[package body] G @key[is] |
| 2771 |
... |
| 2772 |
X: Formal := ...; |
| 2773 |
... |
| 2774 |
Proc(X); -- @RI[This is a dispatching call in Instance, because] |
| 2775 |
-- @RI[the actual type for Formal is class-wide.] |
| 2776 |
... |
| 2777 |
-- @RI[Proc'Access would be illegal here, because it is of] |
| 2778 |
-- @RI[convention Intrinsic, by the above rule.] |
| 2779 |
@key[end] G;]} |
| 2780 |
|
| 2781 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2782 |
@ChgAdded{Version=[1],Text=[@key[type] Actual @key[is new] Root @key[with] ...; |
| 2783 |
@key[procedure] Proc(X: Actual); |
| 2784 |
@key[package] Instance @key[is new] G(Formal => Actual'Class); |
| 2785 |
-- @RI[It is legal to pass in a class-wide actual, because Formal] |
| 2786 |
-- @RI[has unknown discriminants.]]} |
| 2787 |
@end{Example} |
| 2788 |
|
| 2789 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2790 |
@Chg{New=[Within Instance, all calls to Proc will be dispatching calls, so Proc doesn't |
| 2791 |
really exist in machine code, so we wish to avoid taking 'Access of it. |
| 2792 |
This rule applies to those cases where the actual type might be class-wide, |
| 2793 |
and makes these Intrinsic, thus forbidding 'Access.],Old=[]} |
| 2794 |
@end{Reason} |
| 2795 |
|
| 2796 |
|
| 2797 |
an attribute that is a subprogram; |
| 2798 |
|
| 2799 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01]} |
| 2800 |
a subprogram declared immediately |
| 2801 |
within a @nt{protected_body}@Chg{Version=[2],New=[;],Old=[.]} |
| 2802 |
|
| 2803 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]} |
| 2804 |
@ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0107-1]} |
| 2805 |
@ChgAdded{Version=[2],Text=[any prefixed view of a subprogram (see |
| 2806 |
@RefSecNum{Selected Components})@Chg{Version=[4],New=[ without |
| 2807 |
synchronization kind (see @RefSecNum{Intertask Communication}) By_Entry or |
| 2808 |
By_Protected_Procedure],Old=[]}.]} |
| 2809 |
@begin{Reason} |
| 2810 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2811 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0005-1]} |
| 2812 |
@ChgAdded{Version=[2],Text=[The profile of a prefixed view is different |
| 2813 |
@Chg{Version=[5],New=[from],Old=[than]} the @lquotes@;real@rquotes profile of the subprogram |
| 2814 |
(it doesn't have the first parameter), so we don't want to be able |
| 2815 |
to take 'Access of it, as that would require generating a wrapper of |
| 2816 |
some sort.]} |
| 2817 |
|
| 2818 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0107-1]} |
| 2819 |
@ChgAdded{Version=[4],Text=[We except prefixed views that have |
| 2820 |
synchronization kind By_Protected_Procedure so that they can be used |
| 2821 |
with an access-to-protected-procedure type. These don't require special |
| 2822 |
wrappers (this is the normal form for a protected subprogram call). The |
| 2823 |
By_Entry part is just for consistency (there is no access-to-entry type |
| 2824 |
in Ada).]} |
| 2825 |
@end{Reason} |
| 2826 |
|
| 2827 |
@end{InnerItemize} |
| 2828 |
|
| 2829 |
@NoPrefix@Redundant[The Access attribute is not allowed |
| 2830 |
for Intrinsic subprograms.] |
| 2831 |
@begin{Ramification} |
| 2832 |
The Intrinsic calling convention really represents any number of |
| 2833 |
calling conventions at the machine code level; |
| 2834 |
the compiler might have a different instruction sequence for |
| 2835 |
each intrinsic. |
| 2836 |
That's why the Access attribute is disallowed. |
| 2837 |
We do not wish to require the implementation to generate |
| 2838 |
an out of line body for an intrinsic. |
| 2839 |
|
| 2840 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2841 |
Whenever we wish to disallow the Access attribute in order to ease |
| 2842 |
implementation, we make the subprogram Intrinsic. |
| 2843 |
Several language-defined subprograms have |
| 2844 |
@lquotes@;@Chg{Version=[3],New=[@key[with]],Old=[@key[pragma]]} |
| 2845 |
Convention@Chg{Version=[3],New=[ => ],Old=[(]}Intrinsic@Chg{Version=[3],New=[],Old=[, ...)]};@rquotes@;. |
| 2846 |
An implementation might actually implement this |
| 2847 |
as @lquotes@;@Chg{Version=[3],New=[@key[with]],Old=[@key[pragma]]} |
| 2848 |
Import@Chg{Version=[3],New=[ => True, Convention |
| 2849 |
=> ],Old=[(]}Intrinsic@Chg{Version=[3],New=[],Old=[, ...)]};@rquotes@;, |
| 2850 |
if there is really no body, and the implementation of the subprogram |
| 2851 |
is built into the code generator. |
| 2852 |
|
| 2853 |
Subprograms declared in @ntf{protected_bodies} will generally have a |
| 2854 |
special calling |
| 2855 |
convention so as to pass along the identification of the |
| 2856 |
current instance of the protected type. |
| 2857 |
The convention is not @i(protected) since such local subprograms |
| 2858 |
need not contain any @lquotes@;locking@rquotes@; logic since they are |
| 2859 |
not callable via @lquotes@;external@rquotes@; calls; |
| 2860 |
this rule prevents an access value designating such a subprogram |
| 2861 |
from being passed outside the protected unit. |
| 2862 |
|
| 2863 |
The @lquotes@;implicitly declared subprogram@rquotes@; above refers to |
| 2864 |
predefined operators (other than the "=" of a tagged type) and |
| 2865 |
the inherited subprograms of |
| 2866 |
untagged types. |
| 2867 |
@end{Ramification} |
| 2868 |
|
| 2869 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0107-1],ARef=[AI12-0159-1]} |
| 2870 |
@Defn{protected calling convention} |
| 2871 |
@Defn2{Term=[calling convention], Sec=(protected)} |
| 2872 |
The default calling convention is @i{protected} |
| 2873 |
for a protected subprogram,@Chg{Version=[4],New=[ for a |
| 2874 |
prefixed view of a subprogram with a synchronization kind of |
| 2875 |
By_Protected_Procedure,],Old=[]} |
| 2876 |
and for an access-to-subprogram type with |
| 2877 |
the reserved word @key(protected) in its definition. |
| 2878 |
|
| 2879 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0107-1],ARef=[AI12-0159-1]} |
| 2880 |
@Defn{entry calling convention} |
| 2881 |
@Defn2{Term=[calling convention], Sec=(entry)} |
| 2882 |
The default calling convention is @i{entry} for an |
| 2883 |
entry@Chg{Version=[4],New=[ and for a prefixed view |
| 2884 |
of a subprogram with a synchronization kind of By_Entry],Old=[]}. |
| 2885 |
|
| 2886 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01],ARef=[AI95-00409-01]} |
| 2887 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]} |
| 2888 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0207-1]} |
| 2889 |
@ChgAdded{Version=[2],Text=[The calling convention for an |
| 2890 |
anonymous access-to-subprogram parameter |
| 2891 |
or anonymous access-to-subprogram result is @i<protected> if the reserved |
| 2892 |
word @key{protected} appears in its definition@Chg{Version=[3],New=[;],Old=[ and]} |
| 2893 |
otherwise@Chg{Version=[3],New=[, it],Old=[]} is the convention |
| 2894 |
of the @Chg{Version=[5],New=[entity],Old=[subprogram]} that |
| 2895 |
@Chg{Version=[5],New=[has],Old=[contains]} the parameter@Chg{Version=[5],New=[ |
| 2896 |
or result, unless that entity has convention @i<protected>, @i<entry>, or |
| 2897 |
Intrinsic, in which case the convention is Ada],Old=[]}.]} |
| 2898 |
@begin{Ramification} |
| 2899 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2900 |
@ChgAdded{Version=[2],Text=[The calling convention for other |
| 2901 |
anonymous access-to-subprogram types is Ada.]} |
| 2902 |
@end{Ramification} |
| 2903 |
|
| 2904 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 2905 |
@Chg{Version=[1],New=[@Redundant[If not specified above as Intrinsic, the calling convention for any |
| 2906 |
inherited or overriding dispatching operation of a tagged type is that of the |
| 2907 |
corresponding subprogram of the parent type.] The default calling convention |
| 2908 |
for a new dispatching operation of a tagged type is the convention of the type.], |
| 2909 |
Old=[]} |
| 2910 |
@begin{Reason} |
| 2911 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2912 |
@ChgAdded{Version=[1],Text=[The first rule is officially stated in |
| 2913 |
@RefSecNum(Dispatching Operations of Tagged Types). The second is intended |
| 2914 |
to make interfacing to foreign OOP languages easier, by making the default |
| 2915 |
be that the type and operations all have the same convention.]} |
| 2916 |
@end{Reason} |
| 2917 |
@end{Itemize} |
| 2918 |
|
| 2919 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2920 |
Of these four conventions, only Ada and Intrinsic are |
| 2921 |
allowed as a @SynI{convention_}@nt{identifier} |
| 2922 |
in @Chg{Version=[3],New=[the specification of a],Old=[a @nt{pragma}]} |
| 2923 |
Convention@Chg{Version=[3],New=[ aspect],Old=[, Import, or Export]}. |
| 2924 |
@begin{Discussion} |
| 2925 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2926 |
The names of the @i{protected} and @i{entry} calling conventions |
| 2927 |
cannot be used in the @Chg{Version=[3],New=[specification of Convention], |
| 2928 |
Old=[interfacing pragmas]}. |
| 2929 |
Note that @key[protected] and @key[entry] are reserved words. |
| 2930 |
@end{Discussion} |
| 2931 |
|
| 2932 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00409-01]} |
| 2933 |
@Defn{type conformance} |
| 2934 |
@Defn2{Term=[profile],Sec=(type conformant)} |
| 2935 |
Two profiles |
| 2936 |
are @i{type conformant} if they have the same number of parameters, |
| 2937 |
and both have a result if either does, and corresponding |
| 2938 |
parameter and result types are the same, |
| 2939 |
or, for access parameters@Chg{Version=[2],New=[ or access results],Old=[]}, |
| 2940 |
corresponding designated types are the same@Chg{Version=[2],New=[, or |
| 2941 |
corresponding designated profiles are type conformant],Old=[]}. |
| 2942 |
@IndexSee{Term=[type profile],See=(profile, type conformant)} |
| 2943 |
@begin{Discussion} |
| 2944 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00409-01]} |
| 2945 |
For @Chg{Version=[2],New=[anonymous access-to-object],Old=[access]} |
| 2946 |
parameters, the designated types have to be the same for type |
| 2947 |
conformance, not the access types, |
| 2948 |
since in general each access parameter has its own anonymous access |
| 2949 |
type, created when the subprogram is called. |
| 2950 |
Of course, corresponding parameters have to be either both access |
| 2951 |
parameters or both not access parameters. |
| 2952 |
|
| 2953 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]} |
| 2954 |
@ChgAdded{Version=[2],Text=[Similarly, for anonymous access-to-subprogram |
| 2955 |
parameters, the designated profiles of the types, not the types themselves, |
| 2956 |
have to be conformant.]} |
| 2957 |
@end{Discussion} |
| 2958 |
|
| 2959 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00409-01]} |
| 2960 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4]} |
| 2961 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{Dummy for conditional leading.} |
| 2962 |
@Defn{mode conformance} |
| 2963 |
@Defn2{Term=[profile],Sec=(mode conformant)} |
| 2964 |
Two profiles are @i{mode conformant} if@Chg{Version=[3],New=[:],Old=[ they are |
| 2965 |
type-conformant, and |
| 2966 |
corresponding parameters have identical |
| 2967 |
modes, and, for access |
| 2968 |
parameters@Chg{Version=[2],New=[ or access result types],Old=[]}, the |
| 2969 |
designated subtypes statically match@Chg{Version=[2],New=[, or the |
| 2970 |
designated profiles are subtype conformant.],Old=[]} |
| 2971 |
@PDefn2{Term=[statically matching],Sec=(required)}]} |
| 2972 |
|
| 2973 |
@begin{Itemize} |
| 2974 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0262-1]} |
| 2975 |
@ChgAdded{Version=[3],Text=[they are type conformant; and]} |
| 2976 |
|
| 2977 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4]} |
| 2978 |
@ChgAdded{Version=[3],Text=[corresponding parameters have identical modes and |
| 2979 |
both or neither are explicitly aliased parameters; and]} |
| 2980 |
|
| 2981 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0207-1]} |
| 2982 |
@ChgAdded{Version=[3],Text=[for corresponding access parameters and any access |
| 2983 |
result type, the designated subtypes statically match and either both or neither |
| 2984 |
are access-to-constant, or the designated profiles are subtype conformant. |
| 2985 |
@PDefn2{Term=[statically matching],Sec=(required)}]} |
| 2986 |
@end{Itemize} |
| 2987 |
|
| 2988 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0239-1]} |
| 2989 |
@Defn{subtype conformance} |
| 2990 |
@Defn2{Term=[profile],Sec=(subtype conformant)} |
| 2991 |
Two profiles are @i{subtype conformant} if they are |
| 2992 |
@Chg{Version=[3],New=[mode conformant],Old=[mode-conformant]}, |
| 2993 |
corresponding subtypes of the profile statically match, |
| 2994 |
and the associated calling conventions are the same. |
| 2995 |
The profile of a generic formal subprogram is not |
| 2996 |
@Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]} |
| 2997 |
with any other profile. |
| 2998 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 2999 |
|
| 3000 |
@begin{Ramification} |
| 3001 |
@PDefn{generic contract issue} |
| 3002 |
@end{Ramification} |
| 3003 |
|
| 3004 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0134-1],ARef=[AI05-0262-1]} |
| 3005 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{Dummy for conditional leading.} |
| 3006 |
@Defn2{Term=[full conformance], Sec=(for profiles)} |
| 3007 |
@Defn2{Term=[profile],Sec=(fully conformant)} |
| 3008 |
Two profiles are @i{fully conformant} if they |
| 3009 |
are @Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]}, |
| 3010 |
@Chg{Version=[3],New=[if they have |
| 3011 |
access-to-subprogram results whose designated profiles are fully |
| 3012 |
conformant, ],Old=[]}and @Chg{Version=[3],New=[for ],Old=[]} |
| 3013 |
corresponding parameters@Chg{Version=[3],New=[:], |
| 3014 |
Old=[ have the same names and have @nt<default_expression>s |
| 3015 |
that are fully conformant with one another.]} |
| 3016 |
@begin{Itemize} |
| 3017 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0262-1]} |
| 3018 |
@ChgAdded{Version=[3],Text=[they have the same names; and]} |
| 3019 |
|
| 3020 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0046-1]} |
| 3021 |
@ChgAdded{Version=[3],Text=[both or neither have @nt{null_exclusion}s; and]} |
| 3022 |
|
| 3023 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3024 |
@ChgAdded{Version=[3],Text=[neither have @nt{default_expression}s, or they both |
| 3025 |
have @nt{default_expression}s that are fully conformant with one another; and]} |
| 3026 |
|
| 3027 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0134-1]} |
| 3028 |
@ChgAdded{Version=[3],Text=[for access-to-subprogram parameters, the designated |
| 3029 |
profiles are fully conformant.]} |
| 3030 |
@end{Itemize} |
| 3031 |
@begin{Ramification} |
| 3032 |
Full conformance requires subtype conformance, |
| 3033 |
which requires the same calling conventions. |
| 3034 |
However, the calling convention of the declaration and body of a |
| 3035 |
subprogram or entry are always the same by definition. |
| 3036 |
@end{Ramification} |
| 3037 |
@begin{Reason} |
| 3038 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0046-1]} |
| 3039 |
@ChgAdded{Version=[3],Text=[The part about @nt{null_exclusion}s is |
| 3040 |
necessary to prevent controlling parameters from having different |
| 3041 |
exclusions, as such a parameter is defined to exclude |
| 3042 |
null whether or not an exclusion is given.]} |
| 3043 |
|
| 3044 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0134-1]} |
| 3045 |
@ChgAdded{Version=[3],Text=[The parts about access-to-subprogram parameters |
| 3046 |
and results is necessary to prevent such types from having different |
| 3047 |
@nt{default_expression}s in the specification and body of a subprogram. |
| 3048 |
If that was allowed, it would be undefined which @nt{default_expression} |
| 3049 |
was used in a call of an access-to-subprogram parameter.]} |
| 3050 |
@end{Reason} |
| 3051 |
|
| 3052 |
@leading@Defn2{Term=[full conformance], Sec=(for expressions)} |
| 3053 |
Two expressions are @i(fully conformant) if, |
| 3054 |
@Redundant[after replacing each use of an operator with the equivalent |
| 3055 |
@nt{function_call}:] |
| 3056 |
@begin{Itemize} |
| 3057 |
each constituent construct of one corresponds to an instance of the |
| 3058 |
same syntactic category in the other, |
| 3059 |
except that an expanded name may correspond |
| 3060 |
to a @nt{direct_name} |
| 3061 |
(or @nt{character_literal}) |
| 3062 |
or to a different expanded name in the other; and |
| 3063 |
|
| 3064 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0050-1]} |
| 3065 |
@ChgAdded{Version=[4],Text=[corresponding @nt{defining_identifier}s occurring |
| 3066 |
within the two expressions are the same; and]} |
| 3067 |
|
| 3068 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0050-1]} |
| 3069 |
each @nt{direct_name}, @nt{character_literal}, and @nt{selector_name} |
| 3070 |
that is not part of the @nt{prefix} of an expanded name in one |
| 3071 |
denotes the same declaration as the corresponding |
| 3072 |
@nt{direct_name}, @nt{character_literal}, |
| 3073 |
or @nt{selector_name} in the other@Chg{Version=[4],New=[, or they denote |
| 3074 |
corresponding declarations occurring within the two expressions],Old=[]}; and |
| 3075 |
@begin{Ramification} |
| 3076 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0300-1]} |
| 3077 |
Note that it doesn't say @lquotes@;respectively@rquotes@; |
| 3078 |
because a @nt{direct_name} can correspond to a @nt{selector_name}, |
| 3079 |
and vice@Chg{Version=[5],New=[ ],Old=[-]}versa, by the previous bullet. |
| 3080 |
This rule allows the @nt{prefix} of an expanded name to be removed, |
| 3081 |
or replaced with a different @nt{prefix} that denotes a renaming of the |
| 3082 |
same entity. |
| 3083 |
However, it does not allow a @nt{direct_name} or @nt{selector_name} to |
| 3084 |
be replaced with one denoting a distinct renaming |
| 3085 |
(except for @nt{direct_name}s and @nt{selector_name}s in @nt{prefix}es |
| 3086 |
of expanded names). |
| 3087 |
Note that calls using operator notation |
| 3088 |
are equivalent to calls using prefix notation. |
| 3089 |
|
| 3090 |
@leading@keepnext@;Given the following declarations: |
| 3091 |
@begin{Example} |
| 3092 |
@key[package] A @key[is] |
| 3093 |
@key[function] F(X : Integer := 1) @key[return] Boolean; |
| 3094 |
@key[end] A; |
| 3095 |
|
| 3096 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0005-1]} |
| 3097 |
@key[with] A; |
| 3098 |
@key[package] B @key[is] |
| 3099 |
@key[package] A_View @key[renames] A; |
| 3100 |
@key[function] F_View(X : Integer := 9999) @key[return] Boolean @key[renames] @Chg{Version=[3],New=[A.F],Old=[F]}; |
| 3101 |
@key[end] B; |
| 3102 |
|
| 3103 |
@key[with] A, B; @key[use] A, B; |
| 3104 |
@key[procedure] Main @key[is] ... |
| 3105 |
@end{Example} |
| 3106 |
|
| 3107 |
Within Main, the expressions @lquotes@;F@rquotes@;, @lquotes@;A.F@rquotes@;, @lquotes@;B.A_View.F@rquotes@;, |
| 3108 |
and @lquotes@;A_View.F@rquotes@; are all fully conformant with one another. |
| 3109 |
However, @lquotes@;F@rquotes@; and @lquotes@;F_View@rquotes@; are not fully conformant. |
| 3110 |
If they were, it would be bad news, since the two denoted views have |
| 3111 |
different @nt{default_expression}s. |
| 3112 |
@end{Ramification} |
| 3113 |
@begin{Discussion} |
| 3114 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0050-1]} |
| 3115 |
@ChgAdded{Version=[4],Text=[We talk about @nt{defining_identifier}s and |
| 3116 |
"corresponding declarations" because of the possibility of |
| 3117 |
@nt{iterator_specification}s occurring within the expressions; each |
| 3118 |
@nt{iterator_specification} is a separate declaration, which we need to |
| 3119 |
allow, but we do want to require that the @nt{defining_identifier}s are |
| 3120 |
the same.]} |
| 3121 |
@end{Discussion} |
| 3122 |
|
| 3123 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0018],ARef=[AI95-00175-01]} |
| 3124 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1]} |
| 3125 |
@ChgAdded{Version=[1],Text=[each @nt{attribute_designator} in one |
| 3126 |
@Chg{Version=[3],New=[is],Old=[must be]} the same as the |
| 3127 |
corresponding @nt{attribute_designator} in the other; and]} |
| 3128 |
|
| 3129 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0342-1]} |
| 3130 |
each @nt{primary} that is a literal in one |
| 3131 |
@Chg{Version=[5],New=[is a user-defined literal if and only if the |
| 3132 |
corresponding literal in the other is also a user-defined literal. |
| 3133 |
Furthermore, if neither are user-defined literals |
| 3134 |
then they shall have the same values@Redundant[, but they may have |
| 3135 |
differing textual representations]; if both are user-defined literals then |
| 3136 |
they shall have the same textual representation],Old=[has the same value as |
| 3137 |
the corresponding literal in the other]}. |
| 3138 |
|
| 3139 |
@begin{Ramification} |
| 3140 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0342-1]} |
| 3141 |
@Chg{Version=[5],New=[This rule applies to @nt{character_literal}s, so |
| 3142 |
even though other rules would allow a rename of a character literal to |
| 3143 |
conform to the literal, this rule prevents that],Old=[The literals |
| 3144 |
may be written differently]}. |
| 3145 |
@end{Ramification} |
| 3146 |
@end{Itemize} |
| 3147 |
@begin{Ramification} |
| 3148 |
Note that the above definition makes full conformance a transitive |
| 3149 |
relation. |
| 3150 |
@end{Ramification} |
| 3151 |
|
| 3152 |
@Defn2{Term=[full conformance], Sec=(for @nt{known_discriminant_part}s)} |
| 3153 |
Two @nt{known_discriminant_part}s are @i(fully conformant) if they have |
| 3154 |
the same number of discriminants, and |
| 3155 |
discriminants in the same positions |
| 3156 |
have the same names, statically matching subtypes, |
| 3157 |
and @nt{default_expression}s that are fully conformant with |
| 3158 |
one another. |
| 3159 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 3160 |
|
| 3161 |
@Defn2{Term=[full conformance], Sec=(for @nt{discrete_subtype_definition}s)} |
| 3162 |
Two @nt<discrete_subtype_definition>s are @i(fully conformant) if they |
| 3163 |
are both @nt<subtype_indication>s or are both @nt<range>s, |
| 3164 |
the @nt<subtype_mark>s (if any) denote the same subtype, and |
| 3165 |
the corresponding @nt<simple_expression>s of the @nt<range>s (if any) |
| 3166 |
fully conform. |
| 3167 |
@begin{Ramification} |
| 3168 |
In the @nt{subtype_indication} case, any ranges have to @i{be} |
| 3169 |
corresponding; that is, two @nt{subtype_indication}s cannot conform |
| 3170 |
unless both or neither has a @nt{range}. |
| 3171 |
@end{Ramification} |
| 3172 |
@begin{Discussion} |
| 3173 |
This definition is used in @RefSec(Entries and Accept Statements) |
| 3174 |
for the conformance required between the @nt<discrete_subtype_definition>s |
| 3175 |
of an @nt<entry_declaration> for a family of entries and the |
| 3176 |
corresponding @nt<entry_index_specification> of the @nt<entry_body>. |
| 3177 |
@end{Discussion} |
| 3178 |
|
| 3179 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01]} |
| 3180 |
@ChgAdded{Version=[2],Text=[@Defn{prefixed view profile} |
| 3181 |
The @i<prefixed view profile> of a subprogram is the profile obtained by |
| 3182 |
omitting the first parameter of that subprogram. There is no prefixed view |
| 3183 |
profile for a parameterless subprogram. For the purposes of defining subtype |
| 3184 |
and mode conformance, the convention of a prefixed view profile is considered |
| 3185 |
to match that of either an entry or a protected operation.]} |
| 3186 |
|
| 3187 |
@begin{Discussion} |
| 3188 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3189 |
@ChgAdded{Version=[2],Text=[This definition is used to define how |
| 3190 |
primitive subprograms of interfaces match operations in task and |
| 3191 |
protected type definitions (see @RefSecNum{Task Units and Task Objects} and |
| 3192 |
@RefSecNum{Protected Units and Protected Objects}).]} |
| 3193 |
@end{Discussion} |
| 3194 |
@begin{Reason} |
| 3195 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3196 |
@ChgAdded{Version=[2],Text=[The weird rule about conventions is pretty much |
| 3197 |
required for synchronized interfaces to make any sense. There will be |
| 3198 |
wrappers all over the place for interfaces anyway. Of course, this doesn't |
| 3199 |
imply that entries have the same convention as protected operations.]} |
| 3200 |
@end{Reason} |
| 3201 |
@end{StaticSem} |
| 3202 |
|
| 3203 |
@begin{ImplPerm} |
| 3204 |
|
| 3205 |
An implementation may declare an operator declared in a language-defined |
| 3206 |
library unit to be intrinsic. |
| 3207 |
|
| 3208 |
@end{ImplPerm} |
| 3209 |
|
| 3210 |
@begin{Extend83} |
| 3211 |
@Defn{extensions to Ada 83} |
| 3212 |
The rules for full conformance are relaxed @em they are now based on |
| 3213 |
the structure of constructs, rather than the sequence of lexical |
| 3214 |
elements. This implies, for example, that "(X, Y: T)" |
| 3215 |
conforms fully with "(X: T; Y: T)", |
| 3216 |
and "(X: T)" conforms fully with "(X: @key[in] T)". |
| 3217 |
@end{Extend83} |
| 3218 |
|
| 3219 |
@begin{DiffWord95} |
| 3220 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 3221 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the default |
| 3222 |
convention is Ada. Also clarified that the convention of a primitive |
| 3223 |
operation of a tagged type is the same as that of the type.]} |
| 3224 |
|
| 3225 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0018],ARef=[AI95-00175-01]} |
| 3226 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to ensure that two |
| 3227 |
attributes conform only if they have the same @nt{attribute_designator}.]} |
| 3228 |
|
| 3229 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00252-01],ARef=[AI95-00254-01],ARef=[AI95-00407-01]} |
| 3230 |
@ChgAdded{Version=[2],Text=[Defined the calling convention for anonymous |
| 3231 |
access-to-subprogram types and for prefixed views of subprograms (see |
| 3232 |
@RefSecNum{Selected Components}).]} |
| 3233 |
|
| 3234 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 3235 |
@ChgAdded{Version=[2],Text=[Defined the conformance of access result types |
| 3236 |
(see @RefSecNum{Subprogram Declarations}).]} |
| 3237 |
|
| 3238 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00397-01]} |
| 3239 |
@ChgAdded{Version=[2],Text=[Defined the prefixed view profile of subprograms |
| 3240 |
for later use.]} |
| 3241 |
|
| 3242 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]} |
| 3243 |
@ChgAdded{Version=[2],Text=[Defined the conformance of anonymous |
| 3244 |
access-to-subprogram parameters.]} |
| 3245 |
@end{DiffWord95} |
| 3246 |
|
| 3247 |
@begin{Incompatible2005} |
| 3248 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0046-1]} |
| 3249 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:> Now require |
| 3250 |
@nt{null_exclusion}s to match for full conformance. While this is |
| 3251 |
technically incompatible with Ada 2005 as defined by Amendment 1, |
| 3252 |
it is a new Ada 2005 feature and it is unlikely that users have |
| 3253 |
been intentionally taking advantage of the ability to write mismatching |
| 3254 |
exclusions. In any case, it is easy to fix: add a @nt{null_exclusion} |
| 3255 |
where needed for conformance.]} |
| 3256 |
|
| 3257 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0134-1]} |
| 3258 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Now require |
| 3259 |
full conformance of anonymous access-to-subprogram parameters and results |
| 3260 |
for full conformance. This is necessary so that there is no confusion about |
| 3261 |
the default expression that is used for a call. While this is technically |
| 3262 |
incompatible with Ada 2005 as defined by Amendment 1, it is a new Ada 2005 |
| 3263 |
feature and it is unlikely that users have been intentionally taking advantage |
| 3264 |
and writing different default expressions. In any case, it is |
| 3265 |
easy to fix: change any default expressions that don't conform so that they |
| 3266 |
do conform.]} |
| 3267 |
|
| 3268 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0207-1]} |
| 3269 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Now include |
| 3270 |
the presence or absence of @key[constant] in access parameters to be |
| 3271 |
considered when checking mode conformance. This is necessary to prevent |
| 3272 |
modification of constants. While this is technically incompatible with |
| 3273 |
Ada 2005 as defined by Amendment 1, it is a new Ada 2005 feature and it |
| 3274 |
is unlikely that users have been intentionally taking advantage and writing |
| 3275 |
mismatching access types.]} |
| 3276 |
@end{Incompatible2005} |
| 3277 |
|
| 3278 |
@begin{Diffword2005} |
| 3279 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 3280 |
@ChgAdded{Version=[3],Text=[Explicitly aliased parameters are included |
| 3281 |
as part of mode conformance (since it affects the parameter passing |
| 3282 |
mechanism).]} |
| 3283 |
@end{Diffword2005} |
| 3284 |
|
| 3285 |
@begin{Incompatible2012} |
| 3286 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0207-1]} |
| 3287 |
@ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}@b<Correction:> |
| 3288 |
The convention of an anonymous access-to-subprogram parameter of a protected |
| 3289 |
entry or subprogram is Ada; if one wants it to be @i<protected> it can be |
| 3290 |
declared with the keyword @key[protected]. This is incompatible, but only |
| 3291 |
in a very rare case; usually the intent is to pass a normal subprogram |
| 3292 |
to a protected subprogram (and this was impossible in Ada 2012).]} |
| 3293 |
@end{Incompatible2012} |
| 3294 |
|
| 3295 |
@begin{Extend2012} |
| 3296 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0107-1],ARef=[AI12-0159-1]} |
| 3297 |
@ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}@b<Corrigendum:> |
| 3298 |
We now define that a prefixed view of a subprogram with synchronization |
| 3299 |
kind By_Protected_Procedure can be used as the prefix of 'Access for an |
| 3300 |
access-to-protected type. We consider this a correction as it certainly |
| 3301 |
appears that it ought to work, but in original Ada 2012 it would have had |
| 3302 |
a convention mismatch.]} |
| 3303 |
@end{Extend2012} |
| 3304 |
|
| 3305 |
@begin{Diffword2012} |
| 3306 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0050-1]} |
| 3307 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> We now define how two |
| 3308 |
expressions containing quantified expressions can fully conform. This |
| 3309 |
isn't incompatible, as the original Ada 2012 never allowed such expressions |
| 3310 |
to conform (the declarations in each formally being different). Neither is |
| 3311 |
it an extension as one would expect these to conform.]} |
| 3312 |
|
| 3313 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0342-1]} |
| 3314 |
@ChgAdded{Version=[5],Text=[The conformance of literals is tightened up to |
| 3315 |
not assume anything about the value of a user-defined literal.]} |
| 3316 |
@end{Diffword2012} |
| 3317 |
|
| 3318 |
|
| 3319 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 3320 |
@LabeledSubClause{Inline Expansion of Subprograms} |
| 3321 |
|
| 3322 |
@begin{Intro} |
| 3323 |
@Redundant[Subprograms may be expanded in line at the call site.] |
| 3324 |
@end{Intro} |
| 3325 |
|
| 3326 |
@begin{NotIso} |
| 3327 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2 |
| 3328 |
through 4 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message |
| 3329 |
should be deleted if the paragraphs are ever renumbered.} |
| 3330 |
@end{NotIso} |
| 3331 |
|
| 3332 |
@begin{Syntax} |
| 3333 |
@begin{SyntaxText} |
| 3334 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 3335 |
@ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[@PDefn2{Term=[program unit pragma], Sec=(Inline)} |
| 3336 |
@PDefn2{Term=[pragma, program unit], Sec=(Inline)} |
| 3337 |
The form of a @nt{pragma} Inline, |
| 3338 |
which is a program unit pragma (see @RefSecNum{Pragmas and Program Units}), |
| 3339 |
is as follows:]} |
| 3340 |
@end{SyntaxText} |
| 3341 |
|
| 3342 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 3343 |
@DeletedPragmaSyn{Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3], |
| 3344 |
Text=[@key{pragma} @prag(Inline)(@Syn2{name} {, @Syn2{name}});]}} |
| 3345 |
@end{Syntax} |
| 3346 |
|
| 3347 |
@begin{Legality} |
| 3348 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 3349 |
@ChgDeleted{Version=[3],Text=[The @nt{pragma} shall apply to one or more |
| 3350 |
callable entities or generic subprograms.]} |
| 3351 |
@end{Legality} |
| 3352 |
|
| 3353 |
@begin{StaticSem} |
| 3354 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 3355 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@ChgNote{Conditional leading} |
| 3356 |
@Chg{Version=[3],New=[For],Old=[If a @nt{pragma} Inline applies to]} |
| 3357 |
a callable entity@Chg{Version=[3],New=[ or],Old=[, |
| 3358 |
this indicates that inline expansion is desired for all calls |
| 3359 |
to that entity. |
| 3360 |
If a @nt{pragma} Inline applies to]} a generic subprogram, |
| 3361 |
@Chg{Version=[3],New=[the following language-defined |
| 3362 |
representation aspect may be specified:],Old=[this indicates that |
| 3363 |
inline expansion is desired for all calls to all instances of that |
| 3364 |
generic subprogram.]} |
| 3365 |
|
| 3366 |
@begin{Description} |
| 3367 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3368 |
@ChgAdded{Version=[3],Text=[Inline@\The type of aspect Inline is Boolean. When |
| 3369 |
aspect Inline is True for a callable entity, inline expansion is desired for all |
| 3370 |
calls to that entity. When aspect Inline is True for a generic subprogram, |
| 3371 |
inline expansion is desired for all calls to all instances of that generic |
| 3372 |
subprogram.@AspectDefn{Inline}]} |
| 3373 |
|
| 3374 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3375 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[If directly specified, the |
| 3376 |
@nt{aspect_definition} shall be a static expression. |
| 3377 |
@Redundant[This aspect is never inherited;] if not directly specified, |
| 3378 |
the aspect is False.]} |
| 3379 |
|
| 3380 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Inline], |
| 3381 |
Text=[@ChgAdded{Version=[3],Text=[For efficiency, Inline calls are requested |
| 3382 |
for a subprogram.]}]} |
| 3383 |
|
| 3384 |
@end{Description} |
| 3385 |
|
| 3386 |
|
| 3387 |
@begin{Ramification} |
| 3388 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 3389 |
@ChgDeleted{Version=[3],Type=[Leading],Text=[Note that inline expansion is |
| 3390 |
desired no matter what name is used in the call. This allows one to request |
| 3391 |
inlining for only one of several overloaded subprograms as follows:]} |
| 3392 |
@begin{Example} |
| 3393 |
@ChgRef{Version=[3],Kind=[Deleted]} |
| 3394 |
@ChgDeleted{Version=[3],Text=[@key[package] IO @key[is] |
| 3395 |
@key[procedure] Put(X : @key[in] Integer); |
| 3396 |
@key[procedure] Put(X : @key[in] String); |
| 3397 |
@key[procedure] Put(X : @key[in] Character); |
| 3398 |
@key[private] |
| 3399 |
@key[procedure] Character_Put(X : @key[in] Character) @key[renames] Put; |
| 3400 |
@key[pragma] Inline(Character_Put); |
| 3401 |
@key[end] IO;]} |
| 3402 |
|
| 3403 |
@ChgRef{Version=[3],Kind=[Deleted]} |
| 3404 |
@ChgDeleted{Version=[3],Text=[@key[with] IO; @key[use] IO; |
| 3405 |
@key[procedure] Main @key[is] |
| 3406 |
I : Integer; |
| 3407 |
C : Character; |
| 3408 |
@key[begin] |
| 3409 |
... |
| 3410 |
Put(C); --@Examcom{ Inline expansion is desired.} |
| 3411 |
Put(I); --@Examcom{ Inline expansion is NOT desired.} |
| 3412 |
@key[end] Main;]} |
| 3413 |
@end{Example} |
| 3414 |
@end{Ramification} |
| 3415 |
@begin{Ramification} |
| 3416 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 3417 |
The meaning of a subprogram can be changed by @Chg{Version=[3],New=[inline |
| 3418 |
expansion as requested by aspect],Old=[a @nt{pragma}]} Inline only |
| 3419 |
in the presence of failing checks |
| 3420 |
(see @RefSecNum{Exceptions and Optimization}). |
| 3421 |
@end{Ramification} |
| 3422 |
@end{StaticSem} |
| 3423 |
|
| 3424 |
@begin{ImplPerm} |
| 3425 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 3426 |
For each call, |
| 3427 |
an implementation is free to follow or to ignore the recommendation |
| 3428 |
@Chg{Version=[3],New=[determined],Old=[expressed]} by the |
| 3429 |
@Chg{Version=[3],New=[Inline aspect],Old=[@nt{pragma}]}. |
| 3430 |
@begin{Ramification} |
| 3431 |
Note, in particular, that the recommendation |
| 3432 |
cannot always be followed for a recursive call, |
| 3433 |
and is often infeasible for entries. |
| 3434 |
Note also that the implementation can inline calls even |
| 3435 |
when no such desire was expressed @Chg{Version=[3],New=[via the |
| 3436 |
Inline aspect],Old=[by a pragma]}, |
| 3437 |
so long as the semantics of the program remains unchanged. |
| 3438 |
@end{Ramification} |
| 3439 |
|
| 3440 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00309-01]} |
| 3441 |
@ChgRef{Version=[3],Kind=[DeletedAddedNoDelMsg],ARef=[AI05-0229-1]} |
| 3442 |
@ChgDeleted{Version=[3],Text=[@Chg{Version=[2],New=[An implementation may allow |
| 3443 |
a @nt{pragma} Inline that has an argument which is a @nt{direct_name} denoting a |
| 3444 |
@nt{subprogram_body} of the same @nt{declarative_part}.],Old=[]}]} |
| 3445 |
@begin{Reason} |
| 3446 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3447 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 3448 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[This is allowed for |
| 3449 |
Ada 83 compatibility. This is only a permission as this usage is considered |
| 3450 |
obsolescent.]}]} |
| 3451 |
@end{Reason} |
| 3452 |
@begin{Discussion} |
| 3453 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3454 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 3455 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[We only need to allow |
| 3456 |
this in @nt{declarative_part}s, because a body is only allowed in another body, |
| 3457 |
and these all have @nt{declarative_part}s.]}]} |
| 3458 |
@end{Discussion} |
| 3459 |
@end{ImplPerm} |
| 3460 |
|
| 3461 |
@begin{Notes} |
| 3462 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 3463 |
@ChgDeleted{Version=[3],Text=[The @nt{name} in a @nt{pragma} Inline can denote |
| 3464 |
more than one entity in the case of overloading. |
| 3465 |
Such a @nt{pragma} applies to all of the denoted entities.]} |
| 3466 |
@end{Notes} |
| 3467 |
|
| 3468 |
@begin{Incompatible83} |
| 3469 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00309-01]} |
| 3470 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 3471 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[@Defn{incompatibilities with Ada 83} |
| 3472 |
A pragma Inline cannot refer to a @nt{subprogram_body} outside of that |
| 3473 |
body. The pragma can be given inside of the subprogram body. Ada 2005 |
| 3474 |
adds an @ImplPermName to allow this usage for compatibility (and |
| 3475 |
Ada 95 implementations also can use this permission), but |
| 3476 |
implementations do not have to allow such @nt{pragma}s.]}]} |
| 3477 |
@end{Incompatible83} |
| 3478 |
|
| 3479 |
@begin{Extend83} |
| 3480 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 3481 |
@ChgDeleted{Version=[3],Text=[@Defn{extensions to Ada 83} |
| 3482 |
A @nt{pragma} Inline is allowed inside a @nt{subprogram_body} if there |
| 3483 |
is no corresponding @nt{subprogram_declaration}. |
| 3484 |
This is for uniformity with other program unit pragmas.]} |
| 3485 |
@end{Extend83} |
| 3486 |
|
| 3487 |
@begin{Extend95} |
| 3488 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00309-01]} |
| 3489 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 3490 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[@Defn{extensions to Ada 95} |
| 3491 |
@b[Amendment Correction:] Implementations are allowed to let @nt{Pragma} |
| 3492 |
Inline apply to a @nt{subprogram_body}.]}]} |
| 3493 |
@end{Extend95} |
| 3494 |
|
| 3495 |
@begin{Extend2005} |
| 3496 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 3497 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 3498 |
Aspect Inline is new; @nt{pragma} Inline is now obsolescent.]} |
| 3499 |
@end{Extend2005} |
| 3500 |
|
| 3501 |
|
| 3502 |
@RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM} |
| 3503 |
@LabeledClause{Subprogram Calls} |
| 3504 |
|
| 3505 |
@begin{Intro} |
| 3506 |
@Defn{subprogram call} |
| 3507 |
A @i{subprogram call} is either a @nt{procedure_call_statement} |
| 3508 |
or a @nt{function_call}; |
| 3509 |
@Redundant[it invokes the execution of the @nt{subprogram_body}. |
| 3510 |
The call specifies the association of the actual parameters, if any, |
| 3511 |
with formal parameters of the subprogram.] |
| 3512 |
@end{Intro} |
| 3513 |
|
| 3514 |
@begin{Syntax} |
| 3515 |
@Syn{lhs=<procedure_call_statement>,rhs=" |
| 3516 |
@SynI{procedure_}@Syn2{name}; |
| 3517 |
| @SynI{procedure_}@Syn2{prefix} @Syn2{actual_parameter_part};"} |
| 3518 |
|
| 3519 |
|
| 3520 |
@Syn{lhs=<function_call>,rhs=" |
| 3521 |
@SynI{function_}@Syn2{name} |
| 3522 |
| @SynI{function_}@Syn2{prefix} @Syn2{actual_parameter_part}"} |
| 3523 |
|
| 3524 |
@begin{Honest} |
| 3525 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]} |
| 3526 |
@ChgAdded{Version=[3],Text=[For the purpose of non-syntax rules, |
| 3527 |
infix operator calls are considered @nt{function_call}s. |
| 3528 |
See @RefSecNum{Overloading of Operators}.]} |
| 3529 |
@end{Honest} |
| 3530 |
|
| 3531 |
@Syn{lhs=<actual_parameter_part>,rhs=" |
| 3532 |
(@Syn2{parameter_association} {, @Syn2{parameter_association}})"} |
| 3533 |
|
| 3534 |
@Syn{lhs=<parameter_association>,rhs=" |
| 3535 |
[@SynI{formal_parameter_}@Syn2{selector_name} =>] @Syn2{explicit_actual_parameter}"} |
| 3536 |
|
| 3537 |
@Syn{lhs=<explicit_actual_parameter>,rhs="@Syn2{expression} | @SynI{variable_}@Syn2{name}"} |
| 3538 |
|
| 3539 |
@begin{SyntaxText} |
| 3540 |
@Defn{named association} |
| 3541 |
@Defn{positional association} |
| 3542 |
A @nt{parameter_association} is @i{named} or @i{positional} |
| 3543 |
according to whether or not the |
| 3544 |
@SynI{formal_@!parameter_}@!@nt{selector_@!name} is specified. |
| 3545 |
Any positional associations shall precede any named associations. |
| 3546 |
Named associations are not allowed if the @nt{prefix} in |
| 3547 |
a subprogram call is an @nt{attribute_@!reference}. |
| 3548 |
@begin{Ramification} |
| 3549 |
This means that the formal parameter names used in |
| 3550 |
describing predefined attributes are |
| 3551 |
to aid presentation of their semantics, but are not intended |
| 3552 |
for use in actual calls. |
| 3553 |
@end{Ramification} |
| 3554 |
@end{SyntaxText} |
| 3555 |
@end{Syntax} |
| 3556 |
|
| 3557 |
@begin{Resolution} |
| 3558 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]} |
| 3559 |
The @nt{name} or @nt{prefix} given in a @nt{procedure_call_statement} |
| 3560 |
shall resolve to denote |
| 3561 |
a callable entity that is a procedure, or an entry renamed |
| 3562 |
as (viewed as) a procedure. |
| 3563 |
The @nt{name} or @nt{prefix} given in a @nt{function_call} |
| 3564 |
shall resolve to denote |
| 3565 |
a callable entity that is a |
| 3566 |
function.@Chg{Version=[2],New=[ The @nt{name} or @nt{prefix} shall not |
| 3567 |
resolve to denote an abstract subprogram unless it is also a |
| 3568 |
dispatching subprogram.],Old=[]} |
| 3569 |
@Redundant[When there is an @nt<actual_@!parameter_@!part>, the @nt<prefix> |
| 3570 |
can be an @nt<implicit_@!dereference> of an access-to-subprogram |
| 3571 |
value.] |
| 3572 |
@begin{Discussion} |
| 3573 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00310-01]} |
| 3574 |
@ChgAdded{Version=[2],Text=[This rule is talking about dispatching operations |
| 3575 |
(which is a static concept) and not about dispatching calls (which is a |
| 3576 |
dynamic concept).]} |
| 3577 |
@end{Discussion} |
| 3578 |
@begin{Ramification} |
| 3579 |
The function can be an operator, |
| 3580 |
enumeration literal, attribute that is a function, etc. |
| 3581 |
@end{Ramification} |
| 3582 |
|
| 3583 |
A subprogram call shall contain at most one association for each |
| 3584 |
formal parameter. |
| 3585 |
Each formal parameter without an association shall have a |
| 3586 |
@nt{default_expression} (in the profile of the view denoted |
| 3587 |
by the @nt<name> or @nt<prefix>). |
| 3588 |
@Redundant[This rule is an overloading rule |
| 3589 |
(see @RefSecNum{The Context of Overload Resolution}).] |
| 3590 |
@begin{TheProof} |
| 3591 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0240-1]} |
| 3592 |
@ChgAdded{Version=[3],Text=[All @ResolutionTitle are overloading rules, |
| 3593 |
see @RefSecNum{The Context of Overload Resolution}.]} |
| 3594 |
@end{TheProof} |
| 3595 |
@end{Resolution} |
| 3596 |
@begin{RunTime} |
| 3597 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]} |
| 3598 |
@PDefn2{Term=[execution], Sec=(subprogram call)} |
| 3599 |
For the execution of a subprogram call, |
| 3600 |
the @nt{name} or @nt{prefix} of the call is evaluated, |
| 3601 |
and each @nt{parameter_@!association} is evaluated |
| 3602 |
(see @RefSecNum{Parameter Associations}). |
| 3603 |
If a @nt{default_@!expression} is used, |
| 3604 |
an implicit @nt{parameter_@!association} is assumed for this rule. |
| 3605 |
These evaluations are done in an arbitrary order. |
| 3606 |
The @nt{subprogram_@!body} is then executed@Chg{Version=[2],New=[, or a call |
| 3607 |
on an entry or protected subprogram is performed (see |
| 3608 |
@RefSecNum{Dispatching Operations of Tagged Types})],Old=[]}. |
| 3609 |
Finally, if the subprogram completes normally, then after it is left, |
| 3610 |
any necessary assigning back of formal to actual parameters occurs |
| 3611 |
(see @RefSecNum{Parameter Associations}).@PDefn2{Term=[arbitrary order],Sec=[allowed]} |
| 3612 |
|
| 3613 |
@begin{Discussion} |
| 3614 |
The implicit association for a default is only for this run-time rule. |
| 3615 |
At compile time, the visibility rules are applied to the default at |
| 3616 |
the place where it occurs, not at the place of a call. |
| 3617 |
@end{Discussion} |
| 3618 |
@begin{Honest} |
| 3619 |
If the subprogram is inherited, see @RefSec{Derived Types and Classes}. |
| 3620 |
|
| 3621 |
If the subprogram is protected, see @RefSec{Protected Subprograms and Protected Actions}. |
| 3622 |
|
| 3623 |
If the subprogram is really a renaming of an entry, see @RefSec{Entry Calls}. |
| 3624 |
|
| 3625 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]} |
| 3626 |
@ChgAdded{Version=[2],Text=[If the subprogram is implemented by an entry or |
| 3627 |
protected subprogram, it will be treated as a dispatching call to the |
| 3628 |
corresponding entry (see @RefSec{Entry Calls}) or protected subprogram (see |
| 3629 |
@RefSec{Protected Subprograms and Protected Actions}).]} |
| 3630 |
|
| 3631 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 3632 |
Normally, the @nt{subprogram_body} that is executed by the above rule |
| 3633 |
is the one for the subprogram being called. |
| 3634 |
For an enumeration literal, |
| 3635 |
implicitly declared (but noninherited) subprogram, |
| 3636 |
@Chg{Version=[2],New=[null procedure, ],Old=[]}or an attribute that is |
| 3637 |
a subprogram, an implicit body is assumed. |
| 3638 |
For a dispatching call, |
| 3639 |
@RefSec{Dispatching Operations of Tagged Types} |
| 3640 |
defines which @nt{subprogram_body} is executed. |
| 3641 |
@end{Honest} |
| 3642 |
|
| 3643 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00407-01]} |
| 3644 |
@ChgAdded{Version=[2],Text=[If the @nt{name} or @nt{prefix} of a subprogram |
| 3645 |
call denotes a prefixed view (see @RefSecNum{Selected Components}), the |
| 3646 |
subprogram call is equivalent to a call on the underlying subprogram, with the |
| 3647 |
first actual parameter being provided by the @nt{prefix} of the prefixed view |
| 3648 |
(or the Access attribute of this @nt{prefix} if the first formal parameter is |
| 3649 |
an access parameter), and the remaining actual parameters given by the |
| 3650 |
@nt{actual_parameter_part}, if any.]} |
| 3651 |
|
| 3652 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3653 |
@Defn2{Term=[Program_Error],Sec=(raised for missing return statement)} |
| 3654 |
The exception Program_Error is raised at the point of a |
| 3655 |
@nt{function_call} if the function |
| 3656 |
completes normally without executing a |
| 3657 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}. |
| 3658 |
@begin{Discussion} |
| 3659 |
We are committing to raising the exception at the point |
| 3660 |
of call, for uniformity @em see AI83-00152. |
| 3661 |
This happens after the function is left, of course. |
| 3662 |
|
| 3663 |
Note that there is no name for suppressing this check, |
| 3664 |
since the check imposes no time overhead and minimal |
| 3665 |
space overhead (since it can usually be statically eliminated |
| 3666 |
as dead code). |
| 3667 |
@end{Discussion} |
| 3668 |
|
| 3669 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 3670 |
A @nt{function_call} denotes a constant, as defined in |
| 3671 |
@RefSecNum{Return Statements}; the nominal subtype of the constant is |
| 3672 |
given by the @Chg{Version=[2],New=[nominal],Old=[result]} subtype of the |
| 3673 |
function@Chg{Version=[2],New=[ result],Old=[]}. |
| 3674 |
@PDefn2{Term=[nominal subtype], Sec=(of the result of a @nt<function_call>)} |
| 3675 |
@PDefn2{Term=[constant], Sec=(result of a @nt<function_call>)} |
| 3676 |
@end{RunTime} |
| 3677 |
|
| 3678 |
@begin{Examples} |
| 3679 |
@leading@keepnext@i{Examples of procedure calls:} |
| 3680 |
@begin{Example} |
| 3681 |
Traverse_Tree; --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 3682 |
Print_Header(128, Title, True); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 3683 |
|
| 3684 |
Switch(From => X, To => Next); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 3685 |
Print_Header(128, Header => Title, Center => True); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 3686 |
Print_Header(Header => Title, Center => True, Pages => 128); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 3687 |
@end{Example} |
| 3688 |
|
| 3689 |
@begin{WideAbove} |
| 3690 |
@leading@keepnext@i{Examples of function calls:} |
| 3691 |
@end{WideAbove} |
| 3692 |
@begin{Example} |
| 3693 |
Dot_Product(U, V) --@RI{ see @RefSecNum{Subprogram Declarations} and @RefSecNum{Subprogram Bodies}} |
| 3694 |
Clock --@RI{ see @RefSecNum{Delay Statements, Duration, and Time}} |
| 3695 |
F.@key[all] --@RI{ presuming F is of an access-to-subprogram type @em see @RefSecNum{Access Types}} |
| 3696 |
@end{Example} |
| 3697 |
|
| 3698 |
@begin{WideAbove} |
| 3699 |
@leading@keepnext@i{Examples of procedures with default expressions:} |
| 3700 |
@end{WideAbove} |
| 3701 |
@begin{Example} |
| 3702 |
@key[procedure] Activate(Process : @key[in] Process_Name; |
| 3703 |
After : @key[in] Process_Name := No_Process; |
| 3704 |
Wait : @key[in] Duration := 0.0; |
| 3705 |
Prior : @key[in] Boolean := False); |
| 3706 |
|
| 3707 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 3708 |
@key[procedure] Pair(Left, Right : @key[in] Person_Name := @key[new] Person@Chg{Version=[3],New=[(M)],Old=[]}); --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 3709 |
@end{Example} |
| 3710 |
|
| 3711 |
@begin{WideAbove} |
| 3712 |
@leading@keepnext@i{Examples of their calls:} |
| 3713 |
@end{WideAbove} |
| 3714 |
@begin{Example} |
| 3715 |
Activate(X); |
| 3716 |
Activate(X, After => Y); |
| 3717 |
Activate(X, Wait => 60.0, Prior => True); |
| 3718 |
Activate(X, Y, 10.0, False); |
| 3719 |
|
| 3720 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 3721 |
Pair; |
| 3722 |
Pair(Left => @key[new] Person@Chg{Version=[3],New=[(F)],Old=[]}, Right => @key[new] Person@Chg{Version=[3],New=[(M)],Old=[]}); |
| 3723 |
@end{Example} |
| 3724 |
@end{Examples} |
| 3725 |
|
| 3726 |
@begin{Notes} |
| 3727 |
If a @nt{default_expression} is used for two or more parameters in a |
| 3728 |
multiple @nt{parameter_@!specification}, the @nt{default_@!expression} is |
| 3729 |
evaluated once for each omitted parameter. Hence in the above |
| 3730 |
examples, the two calls of Pair are equivalent. |
| 3731 |
@end{Notes} |
| 3732 |
|
| 3733 |
@begin{Examples} |
| 3734 |
@leading@keepnext@i{Examples of overloaded subprograms:} |
| 3735 |
@begin{Example} |
| 3736 |
@key[procedure] Put(X : @key[in] Integer); |
| 3737 |
@key[procedure] Put(X : @key[in] String); |
| 3738 |
|
| 3739 |
@key[procedure] Set(Tint : @key[in] Color); |
| 3740 |
@key[procedure] Set(Signal : @key[in] Light); |
| 3741 |
@end{Example} |
| 3742 |
|
| 3743 |
@begin{WideAbove} |
| 3744 |
@leading@keepnext@i{Examples of their calls:} |
| 3745 |
@end{WideAbove} |
| 3746 |
@begin{Example} |
| 3747 |
Put(28); |
| 3748 |
Put("no possible ambiguity here"); |
| 3749 |
|
| 3750 |
Set(Tint => Red); |
| 3751 |
Set(Signal => Red); |
| 3752 |
Set(Color'(Red)); |
| 3753 |
|
| 3754 |
--@RI{ Set(Red) would be ambiguous since Red may} |
| 3755 |
--@RI{ denote a value either of type Color or of type Light} |
| 3756 |
@end{Example} |
| 3757 |
@end{Examples} |
| 3758 |
|
| 3759 |
@begin{DiffWord83} |
| 3760 |
We have gotten rid of parameters @lquotes@;of the form of a type conversion@rquotes@; |
| 3761 |
(see RM83-6.4.1(3)). |
| 3762 |
The new view semantics of @nt{type_conversion}s allows us to use |
| 3763 |
normal @nt{type_conversion}s instead. |
| 3764 |
|
| 3765 |
We have moved wording about run-time semantics of parameter associations |
| 3766 |
to @RefSecNum{Parameter Associations}. |
| 3767 |
|
| 3768 |
We have moved wording about raising Program_Error for a function |
| 3769 |
that falls off the end to here from RM83-6.5. |
| 3770 |
@end{DiffWord83} |
| 3771 |
|
| 3772 |
@begin{Extend95} |
| 3773 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00310-01]} |
| 3774 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 3775 |
Nondispatching abstract operations are no longer considered when |
| 3776 |
resolving a subprogram call. That makes it possible to use @key{abstract} |
| 3777 |
to @lquotes@;undefine@rquotes@; a predefined operation for an untagged type. |
| 3778 |
That's especially helpful when defining custom arithmetic packages.]} |
| 3779 |
@end{Extend95} |
| 3780 |
|
| 3781 |
@begin{DiffWord95} |
| 3782 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]} |
| 3783 |
@ChgAdded{Version=[2],Text=[Changed the definition of the nominal subtype |
| 3784 |
of a @nt{function_call} to use the nominal subtype wording of |
| 3785 |
@RefSecNum{Subprogram Declarations}, to take into account |
| 3786 |
@nt{null_exclusion}s and access result types.]} |
| 3787 |
|
| 3788 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]} |
| 3789 |
@ChgAdded{Version=[2],Text=[Added wording to clarify that the meaning of |
| 3790 |
a call on a subprogram @lquotes@;implemented by@rquotes an entry or |
| 3791 |
protected operation is defined by |
| 3792 |
@RefSecNum{Dispatching Operations of Tagged Types}.]} |
| 3793 |
|
| 3794 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00407-01]} |
| 3795 |
@ChgAdded{Version=[2],Text=[Defined the meaning of a call on a prefixed |
| 3796 |
view of a subprogram (see @RefSecNum{Selected Components}).]} |
| 3797 |
@end{DiffWord95} |
| 3798 |
|
| 3799 |
|
| 3800 |
@LabeledSubClause{Parameter Associations} |
| 3801 |
|
| 3802 |
@begin{Intro} |
| 3803 |
@Redundant[@Defn{parameter passing} |
| 3804 |
A parameter association defines the association between an |
| 3805 |
actual parameter and a formal parameter.] |
| 3806 |
@end{Intro} |
| 3807 |
|
| 3808 |
@begin{MetaRules} |
| 3809 |
The parameter passing rules for @b(out) parameters |
| 3810 |
are designed to ensure that the parts of a type that have |
| 3811 |
implicit initial values (see @RefSecNum{Object Declarations}) |
| 3812 |
don't become @lquotes@;de-initialized@rquotes@; by |
| 3813 |
being passed as an @b(out) parameter. |
| 3814 |
|
| 3815 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 3816 |
@ChgAdded{Version=[3],Text=[For explicitly aliased parameters of functions, we |
| 3817 |
will ensure at the call site that a part of the parameter can be returned as |
| 3818 |
part of the function result without creating a dangling pointer. We do this with |
| 3819 |
accessibility checks at the call site that all actual objects of explicitly |
| 3820 |
aliased parameters live at least as long as the function result; then we can |
| 3821 |
allow them to be returned as access discriminants or anonymous access results, |
| 3822 |
as those have the master of the function result.]} |
| 3823 |
@end{MetaRules} |
| 3824 |
|
| 3825 |
@begin{Resolution} |
| 3826 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0118-1]} |
| 3827 |
The @SynI{formal_parameter_}@nt{selector_name} of |
| 3828 |
a@Chg{Version=[3],New=[ named],Old=[]} |
| 3829 |
@nt{parameter_@!association} shall resolve to denote a |
| 3830 |
@nt{parameter_@!specification} of the view being called@Chg{Version=[3],New=[; |
| 3831 |
@Defn{named association}@Defn{positional association}@Defn{named parameter association}@Defn{positional parameter association}this |
| 3832 |
is the formal parameter of the association. The formal parameter for a |
| 3833 |
positional @nt{parameter_@!association} is the parameter with the corresponding |
| 3834 |
position in the formal part of the view being called],Old=[]}. |
| 3835 |
|
| 3836 |
@begin{Honest} |
| 3837 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0118-1]} |
| 3838 |
@ChgAdded{Version=[3],Text=[For positional parameters, the |
| 3839 |
@ldquote@;corresponding position@rdquote is calculated after any |
| 3840 |
transformation of prefixed views.]} |
| 3841 |
@end{Honest} |
| 3842 |
|
| 3843 |
@Defn2{Term=[actual parameter], Sec=(for a formal parameter)} |
| 3844 |
The @i(actual parameter) is either the @nt<explicit_actual_parameter> |
| 3845 |
given in a @nt<parameter_association> for a given |
| 3846 |
formal parameter, or the corresponding @nt<default_expression> |
| 3847 |
if no @nt<parameter_association> is given for the formal parameter. |
| 3848 |
@Defn2{Term=[expected type], Sec=(actual parameter)} |
| 3849 |
The expected type for an actual parameter is the |
| 3850 |
type of the corresponding formal parameter. |
| 3851 |
@begin{Honest} |
| 3852 |
The corresponding @nt<default_expression> is the one of the |
| 3853 |
corresponding formal parameter |
| 3854 |
in the profile of the view denoted by the @nt<name> or |
| 3855 |
@nt<prefix> of the call. |
| 3856 |
@end{Honest} |
| 3857 |
|
| 3858 |
If the mode is @key(in), |
| 3859 |
the actual is interpreted as an @nt{expression}; |
| 3860 |
otherwise, the actual is interpreted only as a @nt{name}, if possible. |
| 3861 |
@begin{Ramification} |
| 3862 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]} |
| 3863 |
This formally resolves the ambiguity present in the syntax rule |
| 3864 |
for @nt<explicit_actual_parameter>. |
| 3865 |
@Chg{Version=[4],New=[This matters as an @nt{expression} that is a |
| 3866 |
@nt{name} is evaluated and represents a value while a @nt{name} by itself |
| 3867 |
can be an object; if the mode is not @key[in], we want the parameter to |
| 3868 |
interpreted as an object.],Old=[]} Note that we don't actually require |
| 3869 |
that the actual be a @nt<name> if the mode is not @key(in); |
| 3870 |
we do that below. |
| 3871 |
|
| 3872 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0005-1]} |
| 3873 |
@ChgAdded{Version=[4],Text=[This wording uses "interpreted as" rather than |
| 3874 |
"shall be" so that this rule is not used to resolve overloading; it is |
| 3875 |
solely about evaluation as described above. We definitely do not want |
| 3876 |
to allow oddities like the presence of parentheses requiring the selection of |
| 3877 |
an @key[in] formal parameter as opposed to an otherwise matching @key[in out] |
| 3878 |
parameter.]} |
| 3879 |
@end{Ramification} |
| 3880 |
@end{Resolution} |
| 3881 |
|
| 3882 |
@begin{Legality} |
| 3883 |
If the mode is @key(in out) or @key(out), |
| 3884 |
the actual shall be a @nt<name> that denotes a variable.@Defn2{Term=[variable],Sec=(required)}@Defn2{Term=[object],Sec=(required)} |
| 3885 |
@begin{Discussion} |
| 3886 |
We no longer need @lquotes@;or a |
| 3887 |
@nt{type_conversion} whose argument is the @nt{name} of a variable,@rquotes@; |
| 3888 |
because a @nt{type_conversion} is now a @nt{name}, and a |
| 3889 |
@nt{type_conversion} of a variable is a variable. |
| 3890 |
@end{Discussion} |
| 3891 |
@begin{Reason} |
| 3892 |
@leading@;The requirement that the actual be a (variable) @nt<name> is not |
| 3893 |
an overload resolution rule, since |
| 3894 |
we don't want the difference between @nt<expression> and |
| 3895 |
@nt{name} to be used to resolve overloading. |
| 3896 |
For example: |
| 3897 |
@begin{Example} |
| 3898 |
procedure Print(X : @key[in] Integer; Y : @key[in] Boolean := True); |
| 3899 |
procedure Print(Z : @key[in out] Integer); |
| 3900 |
. . . |
| 3901 |
Print(3); --@RI{ Ambiguous!} |
| 3902 |
@end{Example} |
| 3903 |
|
| 3904 |
The above call to Print is ambiguous even though the call is |
| 3905 |
not compatible with the second Print which requires an actual |
| 3906 |
that is a (variable) @nt<name> (@lquotes@;3@rquotes@; is an @nt<expression>, not |
| 3907 |
a @nt<name>). This requirement is a legality rule, so overload |
| 3908 |
resolution fails before it is considered, meaning that the call |
| 3909 |
is ambiguous. |
| 3910 |
@end{Reason} |
| 3911 |
|
| 3912 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 3913 |
@ChgAdded{Version=[4],Text=[If the mode is @key[out], the actual parameter is a |
| 3914 |
view conversion, and the type of the formal parameter is an access type or |
| 3915 |
a scalar type that has the Default_Value aspect specified, then]} |
| 3916 |
@begin{Itemize} |
| 3917 |
@ChgRef{Version=[4],Kind=[Added]} |
| 3918 |
@ChgAdded{Version=[4],Text=[there shall exist a type (other than a root |
| 3919 |
numeric type) that is an ancestor of both the target type and the operand |
| 3920 |
type; and]} |
| 3921 |
|
| 3922 |
@ChgRef{Version=[4],Kind=[Added]} |
| 3923 |
@ChgAdded{Version=[4],Text=[in the case of a scalar type, the type of the |
| 3924 |
operand of the conversion shall have the Default_Value aspect specified.]} |
| 3925 |
@end{Itemize} |
| 3926 |
|
| 3927 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 3928 |
@ChgAdded{Version=[4],Text=[@PDefn{generic contract issue} |
| 3929 |
In addition to the places where |
| 3930 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 3931 |
these rules also apply in the private part of an instance of a generic unit.]} |
| 3932 |
|
| 3933 |
@begin{Reason} |
| 3934 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 3935 |
@ChgAdded{Version=[4],Text=[These rules are needed in order to ensure that a |
| 3936 |
well-defined parameter value is passed.]} |
| 3937 |
@end{Reason} |
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0102-1],ARef=[AI05-0142-4]} |
| 3942 |
@leading@;@Chg{Version=[3],New=[If the formal parameter is an explicitly aliased |
| 3943 |
parameter, the type of the actual parameter shall be tagged or the actual |
| 3944 |
parameter shall be an aliased view of an object. Further, if the formal |
| 3945 |
parameter subtype @i{F} is untagged:], |
| 3946 |
Old=[The type of the actual parameter associated with an access parameter |
| 3947 |
shall be convertible (see @RefSecNum{Type Conversions}) |
| 3948 |
to its anonymous access type. |
| 3949 |
@PDefn2{Term=[convertible],Sec=(required)}]} |
| 3950 |
|
| 3951 |
@begin{Itemize} |
| 3952 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3953 |
@ChgAdded{Version=[3],Text=[the subtype @i{F} shall statically match the nominal |
| 3954 |
subtype of the actual object; or]} |
| 3955 |
|
| 3956 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3957 |
@ChgAdded{Version=[3],Text=[the subtype @i{F} shall be unconstrained, discriminated |
| 3958 |
in its full view, and unconstrained in any partial view.]} |
| 3959 |
@end{Itemize} |
| 3960 |
|
| 3961 |
@begin{Ramification} |
| 3962 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3963 |
@ChgAdded{Version=[3],Text=[Tagged objects (and tagged @nt{aggregate}s for @key[in] |
| 3964 |
parameters) do not need to be aliased. This matches the behavior of unaliased |
| 3965 |
formal parameters of tagged types, which allow 'Access to be taken of the |
| 3966 |
formal parameter regardless of the form of the actual parameter.]} |
| 3967 |
@end{Ramification} |
| 3968 |
|
| 3969 |
@begin{Reason} |
| 3970 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3971 |
@ChgAdded{Version=[3],Text=[We need the subtype check on untagged actual |
| 3972 |
parameters so that the requirements of 'Access are not lost. 'Access makes its |
| 3973 |
checks against the nominal subtype of its prefix, and parameter passing can |
| 3974 |
change that subtype. But we don't want this parameter passing to change the |
| 3975 |
objects that would be allowed as the prefix of 'Access. This is particularly |
| 3976 |
important for arrays, where we don't want to require any additional |
| 3977 |
implementation burden.]} |
| 3978 |
@end{Reason} |
| 3979 |
|
| 3980 |
@begin{Discussion} |
| 3981 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]} |
| 3982 |
@ChgAdded{Version=[4],Text=[We assume the worst in a generic body whether |
| 3983 |
or not a formal subtype has a constrained partial view; specifically, in a |
| 3984 |
generic body a discriminated subtype is considered to have a constrained |
| 3985 |
partial view if it is a descendant of an untagged generic formal private |
| 3986 |
or derived type (see @RefSecNum{Formal Private and Derived Types} for the |
| 3987 |
formal definition of this rule).]} |
| 3988 |
@end{Discussion} |
| 3989 |
|
| 3990 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]} |
| 3991 |
@ChgAdded{Version=[4],Text=[@PDefn{generic contract issue} |
| 3992 |
In addition to the places where |
| 3993 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 3994 |
these rules also apply in the private part of an instance of a generic unit.]} |
| 3995 |
|
| 3996 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0234-1]} |
| 3997 |
@ChgAdded{Version=[3],Text=[In a function call, the accessibility level of the |
| 3998 |
actual object for each explicitly aliased parameter shall not be statically |
| 3999 |
deeper than the accessibility level of the master of the call |
| 4000 |
(see @RefSecNum{Operations of Access Types}).]} |
| 4001 |
|
| 4002 |
@begin{Discussion} |
| 4003 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4004 |
@ChgAdded{Version=[3],Text=[Since explicitly aliased parameters are either |
| 4005 |
tagged or required to be objects, there is always an object (possibly |
| 4006 |
anonymous) to talk about. This is discussing the static accessibility level of |
| 4007 |
the actual object; it does not depend on any runtime information (for instance |
| 4008 |
when the actual object is a formal parameter of another subprogram, it does |
| 4009 |
not depend on the actual parameter of that other subprogram).]} |
| 4010 |
@end{Discussion} |
| 4011 |
|
| 4012 |
@begin{Ramification} |
| 4013 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4014 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0095-1]} |
| 4015 |
@ChgAdded{Version=[3],Text=[This accessibility check (and its dynamic cousin |
| 4016 |
as well) can only fail if the @Chg{Version=[4],New=[master of the function |
| 4017 |
call (which is defined in the Heart of Darkness, or |
| 4018 |
@RefSecNum{Operations of Access Types} if you prefer) is different than |
| 4019 |
the master directly enclosing the call],Old=[function call is used to directly initialize a |
| 4020 |
built-in-place object with a master different than that enclosing the call]}. |
| 4021 |
The @Chg{Version=[4],New=[most likely],Old=[only]} place |
| 4022 |
@Chg{Version=[4],New=[where this will occur],Old=[all of those conditions |
| 4023 |
exist]} is in the initializer of an @nt{allocator}; in |
| 4024 |
@Chg{Version=[4],New=[almost ],Old=[]}all other cases this check will always |
| 4025 |
pass.]} |
| 4026 |
@end{Ramification} |
| 4027 |
|
| 4028 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 4029 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Two @nt{name}s are |
| 4030 |
@i{known to denote the same object} if:@Defn{known to denote the same object}]} |
| 4031 |
|
| 4032 |
@begin{Itemize} |
| 4033 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4034 |
@ChgAdded{Version=[3],Text=[both @nt{name}s statically denote the same |
| 4035 |
stand-alone object or parameter; or]} |
| 4036 |
|
| 4037 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4038 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are @nt{selected_component}s, |
| 4039 |
their @nt{prefix}es are known to denote the same object, and their |
| 4040 |
@nt{selector_name}s denote the same component; or]} |
| 4041 |
|
| 4042 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4043 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are dereferences (implicit or |
| 4044 |
explicit) and the dereferenced @nt{name}s are known to denote the same object; |
| 4045 |
or]} |
| 4046 |
|
| 4047 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4048 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are @nt{indexed_component}s, their |
| 4049 |
@nt{prefix}es are known to denote the same object, and each of the pairs of |
| 4050 |
corresponding index values are either both static expressions with the same |
| 4051 |
static value or both @nt{name}s that are known to denote the same object; or]} |
| 4052 |
|
| 4053 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4054 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are @nt{slice}s, their |
| 4055 |
@nt{prefix}es are known to denote the same object, and the two @nt{slice}s have |
| 4056 |
statically matching index constraints; or]} |
| 4057 |
|
| 4058 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4059 |
@ChgAdded{Version=[3],Text=[one of the two @nt{name}s statically denotes a |
| 4060 |
renaming declaration whose renamed @SynI{object_}@nt{name} is known to denote |
| 4061 |
the same object as the other, the @nt{prefix} of any dereference within |
| 4062 |
the renamed @SynI{object_}@nt{name} is not a variable, and any @nt{expression} |
| 4063 |
within the renamed @SynI{object_}@nt{name} contains no references to variables |
| 4064 |
nor calls on nonstatic functions.]} |
| 4065 |
@begin{Reason} |
| 4066 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4067 |
@ChgAdded{Version=[3],Type=[Leading],Text=[This exposes known renamings of |
| 4068 |
slices, indexing, and so on to this definition. In particular, if we have]} |
| 4069 |
@begin{Example} |
| 4070 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4071 |
@ChgAdded{Version=[3],Type=[Leading],Text=[C : Character @key[renames] S(1);]} |
| 4072 |
@end{Example} |
| 4073 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4074 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[then C and S(1) are known to |
| 4075 |
denote the same object.]} |
| 4076 |
|
| 4077 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4078 |
@ChgAdded{Version=[3],Type=[Leading],Text=[We need the requirement that no |
| 4079 |
variables occur in the @nt{prefix}es of dereferences and in (index) |
| 4080 |
@nt{expression}s of the renamed object in order to avoid problems from later |
| 4081 |
changes to those parts of renamed names. Consider:]} |
| 4082 |
|
| 4083 |
@begin{Example} |
| 4084 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4085 |
@ChgAdded{Version=[3],Type=[Leading],Text=[ @key[type] Ref @key[is access] Some_Type; |
| 4086 |
Ptr : Ref := @key[new] Some_Type'(...); |
| 4087 |
X : Some_Type @key[renames] Ptr.@key[all]; |
| 4088 |
@key[begin] |
| 4089 |
Ptr := @key[new] Some_Type'(...); |
| 4090 |
P (Func_With_Out_Params (Ptr.@key[all]), X);]} |
| 4091 |
@end{Example} |
| 4092 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4093 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[X and Ptr.@key[all] should not be |
| 4094 |
known to denote the same object, since they denote different allocated objects |
| 4095 |
(and this is not an unreasonable thing to do).]} |
| 4096 |
@end{Reason} |
| 4097 |
|
| 4098 |
@begin{Honest} |
| 4099 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4100 |
@ChgAdded{Version=[3],Type=[Leading],Text=[The exclusion of variables from |
| 4101 |
renamed object_names is not enough to prevent altering the value of the name |
| 4102 |
or expression by another access path. For instance, both @key[in] parameters |
| 4103 |
passed by reference and access-to-constant values can designate variables. For |
| 4104 |
the intended use of "known to be the same object", this is OK; the |
| 4105 |
modification via another access path is very tricky and it is OK to reject |
| 4106 |
code that would be buggy except for the tricky code. Assuming Element is an |
| 4107 |
elementary type, consider the following example:]} |
| 4108 |
@begin{Example} |
| 4109 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4110 |
@ChgAdded{Version=[3],Text=[Global : Tagged_Type;]} |
| 4111 |
|
| 4112 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4113 |
@ChgAdded{Version=[3],Text=[@key{procedure} Foo (Param : @key{in} Tagged_Type := Global) @key{is} |
| 4114 |
X : Element @key{renames} Some_Global_Array (Param.C); |
| 4115 |
@key{begin} |
| 4116 |
Global.C := Global.C + 1; |
| 4117 |
Swap (X, Some_Global_Array (Param.C));]} |
| 4118 |
@end{Example} |
| 4119 |
|
| 4120 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4121 |
@ChgAdded{Version=[3],Text=[The rules will flag the call of procedure Swap |
| 4122 |
as illegal, since X and Some_Global_Array (Parameter.C) are known to denote |
| 4123 |
the same object (even though they will actually represent different objects if |
| 4124 |
Param = Global). But this is only incorrect if the parameter actually is |
| 4125 |
Global and not some other value; the error could exist for some calls. So this |
| 4126 |
flagging seems harmless.]} |
| 4127 |
|
| 4128 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4129 |
@ChgAdded{Version=[3],Text=[Similar examples can be constructed using |
| 4130 |
stand-alone composite constants with controlled or immutably limited |
| 4131 |
components, and (as previously noted) with dereferences of access-to-constant |
| 4132 |
values. Even when these examples flag a call incorrectly, that call depends |
| 4133 |
on very tricky code (modifying the value of a constant); the code is likely |
| 4134 |
to confuse future maintainers as well and thus we do not mind rejecting it.]} |
| 4135 |
@end{Honest} |
| 4136 |
|
| 4137 |
@end{Itemize} |
| 4138 |
|
| 4139 |
@begin{Discussion} |
| 4140 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4141 |
@ChgAdded{Version=[3],Text=[Whether or not @nt{name}s or @nt{prefix}es are |
| 4142 |
known to denote the same object is determined statically. If the name |
| 4143 |
contains some dynamic portion other than a dereference, @nt{indexed_component}, or |
| 4144 |
@nt{slice}, it is not "known to denote the same object".]} |
| 4145 |
|
| 4146 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4147 |
@ChgAdded{Version=[3],Text=[These rules make no attempt to handle slices of |
| 4148 |
objects that are known to be the same when the slices have dynamic bounds |
| 4149 |
(other than the trivial case of bounds being defined by the same subtype), |
| 4150 |
even when the bounds could be proven to be the same, as it is just too complex |
| 4151 |
to get right and these rules are intended to be conservative.]} |
| 4152 |
@end{Discussion} |
| 4153 |
|
| 4154 |
@begin{Ramification} |
| 4155 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4156 |
@ChgAdded{Version=[3],Type=[Leading],Text=["Known to denote the same object" |
| 4157 |
is intended to be an equivalence relationship, that is, it is reflexive, |
| 4158 |
symmetric, and transitive. We believe this follows from the rules. |
| 4159 |
For instance, given the following declarations:]} |
| 4160 |
@begin{Example} |
| 4161 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4162 |
@ChgAdded{Version=[3],Type=[Leading],Text=[S : String(1..10); |
| 4163 |
ONE : @key[constant] Natural := 1; |
| 4164 |
R : Character @key[renames] S(1);]} |
| 4165 |
@end{Example} |
| 4166 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4167 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[the names R and S(1) are known to |
| 4168 |
denote the same object by the sixth bullet, and S(1) and S(ONE) are known to |
| 4169 |
denote the same object by the fourth bullet, so using the sixth bullet on |
| 4170 |
R and S(ONE), we simply have to test S(1) vs. S(ONE), which we already know |
| 4171 |
denote the same object.]} |
| 4172 |
@end{Ramification} |
| 4173 |
|
| 4174 |
|
| 4175 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 4176 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Two @nt{name}s are @i{known to |
| 4177 |
refer to the same object} if @Defn{known to refer to the same object}]} |
| 4178 |
@begin{Itemize} |
| 4179 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4180 |
@ChgAdded{Version=[3],Text=[The two @nt{name}s are known to denote the same object; or]} |
| 4181 |
|
| 4182 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4183 |
@ChgAdded{Version=[3],Text=[One of the @nt{name}s is a @nt{selected_component}, |
| 4184 |
@nt{indexed_component}, or @nt{slice} and its @nt{prefix} is known to refer |
| 4185 |
to the same object as the other @nt{name}; or]} |
| 4186 |
|
| 4187 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4188 |
@ChgAdded{Version=[3],Text=[One of the two @nt{name}s statically denotes a |
| 4189 |
renaming declaration whose renamed @SynI{object_}@nt{name} is known to refer |
| 4190 |
to the same object as the other @nt{name}.]} |
| 4191 |
@end{Itemize} |
| 4192 |
|
| 4193 |
@begin{Reason} |
| 4194 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4195 |
@ChgAdded{Version=[3],Text=[This ensures that names Prefix.Comp and Prefix are |
| 4196 |
known to refer to the same object for the purposes of the rules below. This |
| 4197 |
intentionally does not include dereferences; we only want to worry about |
| 4198 |
accesses to the same object, and a dereference changes the object in question. |
| 4199 |
(There is nothing shared between an access value and the object it |
| 4200 |
designates.)]} |
| 4201 |
@end{Reason} |
| 4202 |
|
| 4203 |
|
| 4204 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 4205 |
@ChgAdded{Version=[3],Type=[Leading],Text=[ |
| 4206 |
If a call @i<C> has two or more parameters of mode @key[in out] or @key[out] that |
| 4207 |
are of an elementary type, then the call is legal only if:]} |
| 4208 |
|
| 4209 |
@begin{Itemize} |
| 4210 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4211 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0216-1],ARef=[AI12-0324-1]} |
| 4212 |
@ChgAdded{Version=[3],Text=[For each @nt{name} @i<N> |
| 4213 |
@Chg{Version=[5],New=[denoting an object of an elementary |
| 4214 |
type ],Old=[]}that is passed as a parameter of mode @key[in out] or |
| 4215 |
@key[out] to the call @i<C>, there is no other @nt{name} among the other |
| 4216 |
parameters of mode @key[in out] or @key[out] to @i<C> that is known to denote |
| 4217 |
the same object.]} |
| 4218 |
|
| 4219 |
@begin{Honest} |
| 4220 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4221 |
@ChgAdded{Version=[3],Text=[This means @i{visibly} an elementary type; it does |
| 4222 |
not include partial views of elementary types (partial views are always |
| 4223 |
composite). That's necessary to avoid having @LegalityTitle depend on the |
| 4224 |
contents of the private part.]} |
| 4225 |
@end{Honest} |
| 4226 |
@end{Itemize} |
| 4227 |
|
| 4228 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 4229 |
@ChgAdded{Version=[3],Type=[Leading],Text=[If a construct @i<C> has two or more |
| 4230 |
direct constituents that are @nt{name}s or @nt{expression}s whose evaluation may |
| 4231 |
occur in an arbitrary order, at least one of which contains a function call with |
| 4232 |
an @key[in out] or @key[out] parameter, then the construct is legal only if:]} |
| 4233 |
|
| 4234 |
@begin{Ramification} |
| 4235 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4236 |
@ChgAdded{Version=[3],Text=[All of the places where the language allows an |
| 4237 |
arbitrary order can be found by looking in the index under "arbitrary order, |
| 4238 |
allowed". Note that this listing includes places that don't involve |
| 4239 |
@nt{name}s or @nt{expression}s (such as checks or finalization).]} |
| 4240 |
@end{Ramification} |
| 4241 |
|
| 4242 |
@begin{Itemize} |
| 4243 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4244 |
@ChgAdded{Version=[3],Text=[For each name @i<N> that is passed as a parameter of mode @key[in out] or |
| 4245 |
@key[out] to some inner function call @i<C2> (not including the construct @i<C> |
| 4246 |
itself), there is no other @nt{name} anywhere within a direct constituent of the |
| 4247 |
construct @i<C> other than the one containing @i<C2>, that is known to refer to |
| 4248 |
the same object.]} |
| 4249 |
@end{Itemize} |
| 4250 |
|
| 4251 |
@begin{Ramification} |
| 4252 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4253 |
@ChgAdded{Version=[3],Text=[This requirement cannot fail for a procedure |
| 4254 |
or entry call alone; there must be at least one function with an @key[in out] |
| 4255 |
or @key[out] parameter called as part of a parameter expression of the call in |
| 4256 |
order for it to fail.]} |
| 4257 |
@end{Ramification} |
| 4258 |
|
| 4259 |
@begin{Reason} |
| 4260 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4261 |
@ChgAdded{Version=[3],Text=[These rules prevent obvious cases of dependence on |
| 4262 |
the order of evaluation of @nt{name}s or @nt{expression}s. Such dependence is |
| 4263 |
usually a bug, and in any case, is not portable to another implementation (or |
| 4264 |
even another optimization setting).]} |
| 4265 |
|
| 4266 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4267 |
@ChgAdded{Version=[3],Text=[In the case that the top-level construct C is a |
| 4268 |
call, these rules do not require checks for most @key[in out] parameters, as |
| 4269 |
the rules about evaluation of calls prevent problems. Similarly, we do not |
| 4270 |
need checks for short circuit operations or other operations with a defined |
| 4271 |
order of evaluation. The rules about arbitrary order (see |
| 4272 |
@RefSecNum{Method of Description and Syntax Notation}) allow evaluating |
| 4273 |
parameters and writing parameters back in an arbitrary order, but not |
| 4274 |
interleaving of evaluating |
| 4275 |
parameters of one call with writing parameters back from another @em that |
| 4276 |
would not correspond to any allowed sequential order.]} |
| 4277 |
@end{Reason} |
| 4278 |
|
| 4279 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 4280 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For the purposes of checking this rule:]} |
| 4281 |
|
| 4282 |
@begin{Itemize} |
| 4283 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4284 |
@ChgAdded{Version=[3],Text=[For an array @nt{aggregate}, an @nt{expression} |
| 4285 |
associated with a @nt{discrete_choice_list} that has two or more discrete |
| 4286 |
choices, or that has a nonstatic range, is considered as two or more separate |
| 4287 |
occurrences of the @nt{expression};]} |
| 4288 |
|
| 4289 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4290 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For a record @nt{aggregate}:]} |
| 4291 |
|
| 4292 |
@begin{InnerItemize} |
| 4293 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4294 |
@ChgAdded{Version=[3],Text=[The @nt{expression} of a |
| 4295 |
@nt{record_component_association} is considered to occur once for each |
| 4296 |
associated component; and]} |
| 4297 |
|
| 4298 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4299 |
@ChgAdded{Version=[3],Text=[The @nt{default_expression} for each |
| 4300 |
@nt{record_component_association} |
| 4301 |
with <> for which the associated component has a @nt{default_expression} |
| 4302 |
is considered part of the @nt{aggregate};]} |
| 4303 |
@end{InnerItemize} |
| 4304 |
|
| 4305 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4306 |
@ChgAdded{Version=[3],Text=[For a call, any @nt{default_expression} evaluated as |
| 4307 |
part of the call is considered part of the call.]} |
| 4308 |
@end{Itemize} |
| 4309 |
|
| 4310 |
@begin{Ramification} |
| 4311 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4312 |
@ChgAdded{Version=[3],Text=[We do not check expressions that are evaluated only because |
| 4313 |
of a component initialized by default in an aggregate (via <>).]} |
| 4314 |
@end{Ramification} |
| 4315 |
@end{Legality} |
| 4316 |
|
| 4317 |
@begin{RunTime} |
| 4318 |
@leading@keepnext@PDefn2{Term=[evaluation], Sec=(parameter_association)} |
| 4319 |
For the evaluation of a @nt{parameter_association}: |
| 4320 |
@begin{Itemize} |
| 4321 |
The actual parameter is first evaluated. |
| 4322 |
|
| 4323 |
For an access parameter, |
| 4324 |
the @nt{access_definition} is elaborated, |
| 4325 |
which creates the anonymous access type. |
| 4326 |
|
| 4327 |
For a parameter @Redundant[(of any mode)] that is passed by reference |
| 4328 |
(see @RefSecNum{Formal Parameter Modes}), |
| 4329 |
a view conversion of the actual parameter to the nominal subtype |
| 4330 |
of the formal parameter is evaluated, |
| 4331 |
and the formal parameter denotes that conversion. |
| 4332 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 4333 |
@begin{Discussion} |
| 4334 |
We are always allowing sliding, even for [@key(in)] @key(out) by-reference |
| 4335 |
parameters. |
| 4336 |
@end{Discussion} |
| 4337 |
|
| 4338 |
@Defn2{Term=[assignment operation], Sec=(during evaluation of a |
| 4339 |
@nt{parameter_association})} |
| 4340 |
For an @key(in) or @key(in out) parameter that is passed |
| 4341 |
by copy (see @RefSecNum{Formal Parameter Modes}), |
| 4342 |
the formal parameter object is created, |
| 4343 |
and the value of the actual parameter is converted to the |
| 4344 |
nominal subtype of the formal parameter |
| 4345 |
and assigned to the formal. |
| 4346 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 4347 |
@begin{Ramification} |
| 4348 |
The conversion mentioned here is a value conversion. |
| 4349 |
@end{Ramification} |
| 4350 |
|
| 4351 |
@leading@keepnext@;For an @key(out) parameter that is passed by copy, |
| 4352 |
the formal parameter object is created, and: |
| 4353 |
@begin(itemize) |
| 4354 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0196-1]} |
| 4355 |
For an access type, the formal parameter is initialized |
| 4356 |
from the value of the actual, without @Chg{Version=[3],New=[checking that the |
| 4357 |
value satisfies any constraint, any predicate, or any exclusion of the null |
| 4358 |
value],Old=[a constraint check]}; |
| 4359 |
@begin{Reason} |
| 4360 |
This preserves the @MetaRulesName that an object of an access type |
| 4361 |
is always initialized with a @lquotes@;reasonable@rquotes@; value. |
| 4362 |
@end{Reason} |
| 4363 |
|
| 4364 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0153-3],ARef=[AI05-0228-1]} |
| 4365 |
@ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 4366 |
@ChgAdded{Version=[4],Type=[Leading],Text=[]}@Comment{To add conditional leading} |
| 4367 |
@ChgAdded{Version=[3],Text=[For a scalar type that has the Default_Value aspect |
| 4368 |
specified, the formal parameter is initialized from the value of the actual, |
| 4369 |
without checking that the value satisfies any constraint or any |
| 4370 |
predicate@Chg{Version=[4],New=[. Furthermore, if the actual |
| 4371 |
parameter is a view conversion and either],Old=[;]}]} |
| 4372 |
|
| 4373 |
@begin{Itemize} |
| 4374 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1]} |
| 4375 |
@ChgAdded{Version=[4],Text=[there exists no type (other than a root |
| 4376 |
numeric type) that is an ancestor of both the target type and the type |
| 4377 |
of the operand of the conversion; or]} |
| 4378 |
|
| 4379 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1]} |
| 4380 |
@ChgAdded{Version=[4],Text=[the Default_Value aspect is unspecified for |
| 4381 |
the type of the operand of the conversion]} |
| 4382 |
@end{Itemize} |
| 4383 |
|
| 4384 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1]} |
| 4385 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[then Program_Error@IndexCheck{Program_Error_Check} |
| 4386 |
is raised;@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}]} |
| 4387 |
|
| 4388 |
@begin{Reason} |
| 4389 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4390 |
@ChgAdded{Version=[3],Text=[This preserves the @MetaRulesName that all objects |
| 4391 |
of a type with an implicit initial value are initialized. This is important so |
| 4392 |
that a programmer can guarantee that all objects of a scalar type have a valid |
| 4393 |
value with a carefully chosen Default_Value.]} |
| 4394 |
@end{Reason} |
| 4395 |
|
| 4396 |
@begin{ImplNote} |
| 4397 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4398 |
@ChgAdded{Version=[3],Text=[This rule means that @b<out> parameters of a |
| 4399 |
subtype @i<T> with a specified Default_Value need to be large enough to |
| 4400 |
support any possible value of the base type of @i<T>. In contrast, a type that |
| 4401 |
does not have a Default_Value only need support the size of the subtype (since |
| 4402 |
no values are passed in).]} |
| 4403 |
@end{ImplNote} |
| 4404 |
|
| 4405 |
@begin{Discussion} |
| 4406 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 4407 |
@ChgAdded{Version=[4],Text=[The Program_Error case can only occur in the |
| 4408 |
body of an instance of a generic unit. @LegalityTitle will catch all other |
| 4409 |
cases. Implementations that macro-expand generics |
| 4410 |
can always detect this case when the enclosing instance body is expanded.]} |
| 4411 |
@end{Discussion} |
| 4412 |
|
| 4413 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0333-1]} |
| 4414 |
For a composite type with discriminants or |
| 4415 |
that has implicit initial values for any subcomponents |
| 4416 |
(see @RefSecNum{Object Declarations}), |
| 4417 |
the behavior is as for an @key[in out] parameter |
| 4418 |
passed by copy@Chg{Version=[5],New=[@Redundant[, except that no predicate |
| 4419 |
check is performed]],Old=[]}. |
| 4420 |
@begin{Reason} |
| 4421 |
This ensures that no part of an object of such a type |
| 4422 |
can become @lquotes@;de-initialized@rquotes@; by being part of an @b(out) |
| 4423 |
parameter. |
| 4424 |
@end{Reason} |
| 4425 |
@begin{Ramification} |
| 4426 |
This includes an array type whose component type is an access type, |
| 4427 |
and a record type with a component that has a @nt{default_expression}, |
| 4428 |
among other things. |
| 4429 |
@end{Ramification} |
| 4430 |
@begin{TheProof} |
| 4431 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0333-1]} |
| 4432 |
@ChgAdded{Version=[5],Text=[No predicate check follows from the definition |
| 4433 |
of subtype conversion in @RefSecNum{Type Conversions}.]} |
| 4434 |
@end{TheProof} |
| 4435 |
|
| 4436 |
For any other type, the formal parameter is uninitialized. |
| 4437 |
If composite, a view conversion of the actual |
| 4438 |
parameter to the nominal subtype of the formal is evaluated |
| 4439 |
@Redundant[(which might raise Constraint_Error)], |
| 4440 |
and the actual subtype of the formal is that of the |
| 4441 |
view conversion. If elementary, the actual subtype of the formal |
| 4442 |
is given by its nominal subtype. |
| 4443 |
@begin{Ramification} |
| 4444 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0228-1]} |
| 4445 |
This case covers scalar types@Chg{Version=[3],New=[ that do not have |
| 4446 |
Default_Value specified],Old=[]}, and composite types whose |
| 4447 |
subcomponent's subtypes do not have any implicit initial values. |
| 4448 |
The view conversion for composite types ensures that if the lengths |
| 4449 |
don't match between an actual and a formal array parameter, |
| 4450 |
the Constraint_Error is raised before the call, rather than after. |
| 4451 |
@end{Ramification} |
| 4452 |
@end(itemize) |
| 4453 |
|
| 4454 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0234-1]} |
| 4455 |
@ChgAdded{Version=[3],Text=[In a function call, for each explicitly aliased |
| 4456 |
parameter, a check is made that the accessibility level of the master of the |
| 4457 |
actual object is not deeper than that of the master of the call |
| 4458 |
(see @RefSecNum{Operations of Access Types}).]} |
| 4459 |
@begin{Ramification} |
| 4460 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4461 |
@ChgAdded{Version=[3],Text=[If the actual object to a call @i<C> is a formal |
| 4462 |
parameter of some function call @i<F>, no dynamic check against the master of |
| 4463 |
the actual parameter of @i<F> is necessary. Any case which could fail the |
| 4464 |
dynamic check is already statically illegal (either at the call site of @i<F>, |
| 4465 |
or at the call site @i<C>). This is important, as it would require nasty |
| 4466 |
distributed overhead to accurately know the dynamic accessibility of a formal |
| 4467 |
parameter (all tagged and explicitly aliased parameters would have to carry |
| 4468 |
accessibility levels).]} |
| 4469 |
@end{Ramification} |
| 4470 |
@end{Itemize} |
| 4471 |
|
| 4472 |
@PDefn2{Term=[constrained],Sec=(object)} |
| 4473 |
@PDefn2{Term=[unconstrained],Sec=(object)} |
| 4474 |
A formal parameter of mode @key[in out] or @key[out] with |
| 4475 |
discriminants is constrained if either its nominal subtype |
| 4476 |
or the actual parameter is constrained. |
| 4477 |
|
| 4478 |
@Defn{parameter copy back} |
| 4479 |
@Defn{copy back of parameters} |
| 4480 |
@Defn{parameter assigning back} |
| 4481 |
@Defn{assigning back of parameters} |
| 4482 |
@Defn2{Term=[assignment operation], Sec=(during parameter copy back)} |
| 4483 |
After normal completion and leaving of a subprogram, for each @key(in out) |
| 4484 |
or @key(out) parameter that is passed by copy, |
| 4485 |
the value of the formal parameter is converted to |
| 4486 |
the subtype of the variable given as the actual parameter |
| 4487 |
and assigned to it. |
| 4488 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 4489 |
These conversions and assignments occur in an arbitrary |
| 4490 |
order.@PDefn2{Term=[arbitrary order],Sec=[allowed]} |
| 4491 |
@begin{Ramification} |
| 4492 |
The conversions mentioned above during parameter passing might raise |
| 4493 |
Constraint_Error @em (see @RefSecNum{Type Conversions}). |
| 4494 |
@end{Ramification} |
| 4495 |
@begin{Ramification} |
| 4496 |
If any conversion or assignment as part of parameter passing |
| 4497 |
propagates an exception, the exception is raised at the place |
| 4498 |
of the subprogram call; |
| 4499 |
that is, it cannot be handled inside the @nt{subprogram_body}. |
| 4500 |
@end{Ramification} |
| 4501 |
@begin{TheProof} |
| 4502 |
Since these checks happen before or after executing the |
| 4503 |
@nt{subprogram_body}, the execution of the @nt{subprogram_body} does |
| 4504 |
not dynamically enclose them, so it can't handle the exceptions. |
| 4505 |
@end{TheProof} |
| 4506 |
@begin{Discussion} |
| 4507 |
The variable we're talking about is the one denoted by the |
| 4508 |
@i{variable_}@nt{name} given as the @nt{explicit_actual_parameter}. |
| 4509 |
If this @i{variable_}@nt{name} is a @nt{type_conversion}, |
| 4510 |
then the rules in @RefSecNum{Type Conversions} for assigning to a view |
| 4511 |
conversion apply. |
| 4512 |
That is, if X is of subtype S1, and the actual is S2(X), |
| 4513 |
the above-mentioned conversion will convert to S2, |
| 4514 |
and the one mentioned in @RefSecNum{Type Conversions} will convert to |
| 4515 |
S1. |
| 4516 |
@end{Discussion} |
| 4517 |
@end{RunTime} |
| 4518 |
|
| 4519 |
@begin{Erron} |
| 4520 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]} |
| 4521 |
@ChgAdded{Version=[3],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}If |
| 4522 |
the nominal subtype of a formal parameter with discriminants is constrained or |
| 4523 |
indefinite, and the parameter is passed by reference, then the execution of the |
| 4524 |
call is erroneous if the value of any discriminant of the actual is changed |
| 4525 |
while the formal parameter exists (that is, before leaving the corresponding |
| 4526 |
callable construct).]} |
| 4527 |
@end{Erron} |
| 4528 |
|
| 4529 |
@begin{Extend83} |
| 4530 |
@Defn{extensions to Ada 83} |
| 4531 |
In Ada 95, a program can rely on the fact that passing an object as |
| 4532 |
an @key[out] parameter does not @lquotes@;de-initialize@rquotes@; any parts of the |
| 4533 |
object whose subtypes have implicit initial values. |
| 4534 |
(This generalizes the RM83 rule that required copy-in for parts that |
| 4535 |
were discriminants or of an access type.) |
| 4536 |
@end{Extend83} |
| 4537 |
|
| 4538 |
@begin{DiffWord83} |
| 4539 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 4540 |
We have eliminated the subclause on Default Parameters, |
| 4541 |
as it is subsumed by earlier @Chg{Version=[3],New=[],Old=[clauses and ]}subclauses. |
| 4542 |
@end{DiffWord83} |
| 4543 |
|
| 4544 |
@begin{Inconsistent2005} |
| 4545 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0196-1]} |
| 4546 |
@ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005} |
| 4547 |
@b<Correction:> Clarified that |
| 4548 |
@key[out] parameters of an access type are not checked for null exclusions |
| 4549 |
when they are passed in (which is similar to the behavior for constraints). |
| 4550 |
This was unspecified in Ada 2005, so a program which depends on the |
| 4551 |
behavior of an implementation which does check the exclusion may |
| 4552 |
malfunction. But a program depending on an exception being raised is unlikely.]} |
| 4553 |
@end{Inconsistent2005} |
| 4554 |
|
| 4555 |
@begin{Incompatible2005} |
| 4556 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0144-2]} |
| 4557 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005} |
| 4558 |
Additional rules have been added to make illegal passing the same elementary |
| 4559 |
object to more than one @key[in out] or @key[out] parameters of the same |
| 4560 |
call. In this case, the result in the object could depend on the compiler |
| 4561 |
version, optimization settings, and potentially the phase of the moon, so |
| 4562 |
this check will mostly reject programs that are nonportable and could |
| 4563 |
fail with any change. Even when the result is expected to be the same in both |
| 4564 |
parameters, the code is unnecessarily tricky. Programs which fail this |
| 4565 |
new check should be rare and are easily fixed by adding a temporary object.]} |
| 4566 |
@end{Incompatible2005} |
| 4567 |
|
| 4568 |
@begin{DiffWord2005} |
| 4569 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]} |
| 4570 |
@ChgAdded{Version=[3],Text=[@b<Correction:> A missing rule was |
| 4571 |
added to cover cases that were missed in Ada 95 and Ada 2005; specifically, |
| 4572 |
that an @key[in] parameter passed by reference might have its discriminants |
| 4573 |
changed via another path. Such cases are erroneous as requiring compilers |
| 4574 |
to detect such errors would be expensive, and requiring such cases to |
| 4575 |
work would be a major change of the user model (@key[in] parameters |
| 4576 |
with discriminants could no longer be assumed constant). This is not |
| 4577 |
an inconsistency, as compilers are not required to change any current |
| 4578 |
behavior.]} |
| 4579 |
|
| 4580 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0102-1]} |
| 4581 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Moved implicit conversion |
| 4582 |
@LegalityName to @RefSecNum{The Context of Overload Resolution}.]} |
| 4583 |
|
| 4584 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0118-1]} |
| 4585 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Added a definition for |
| 4586 |
positional parameters, as this is missing from Ada 95 and later.]} |
| 4587 |
|
| 4588 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 4589 |
@ChgAdded{Version=[3],Text=[Rules have been added defining the legality |
| 4590 |
and dynamic checks needed for explicitly aliased parameters (see |
| 4591 |
@RefSecNum{Subprogram Declarations}).]} |
| 4592 |
|
| 4593 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0144-2]} |
| 4594 |
@ChgAdded{Version=[3],Text=[Additional rules have been added such |
| 4595 |
that passing an object to an @key[in out] |
| 4596 |
or @key[out] parameter of a function is illegal if it is used elsewhere in a |
| 4597 |
construct which allows evaluation in an arbitrary order. Such calls are |
| 4598 |
not portable (since the results may depend on the evaluation order), and |
| 4599 |
the results could even vary because of optimization settings and the like. |
| 4600 |
Thus they've been banned.]} |
| 4601 |
@end{DiffWord2005} |
| 4602 |
|
| 4603 |
@begin{Incompatible2012} |
| 4604 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 4605 |
@ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2005}@b<Corrigendum:> |
| 4606 |
Added rules to ensure that the value passed into a @key[out] parameter |
| 4607 |
for elementary types is well-defined in the case of a view conversion. |
| 4608 |
The new rules can be incompatible. For a view conversion to an unrelated type |
| 4609 |
with the Default_Value aspect specified, the aspect is new in Ada 2012 so it |
| 4610 |
should be unlikely to occur in existing code. For a view conversion to an |
| 4611 |
unrelated access type, the incompatibility is possible as this could be |
| 4612 |
written in Ada 95, but such a view conversion is thought to be rare. In both |
| 4613 |
cases, declaring and passing a temporary rather than a view conversion |
| 4614 |
will eliminate the problem.]} |
| 4615 |
|
| 4616 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0095-1]} |
| 4617 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Because of a rule added in |
| 4618 |
@RefSecNum{Formal Private and Derived Types}, the checks for the |
| 4619 |
passing of an object to an explicitly aliased parameter in a generic body |
| 4620 |
were strengthened to use an assume the worst rule. This case is rather |
| 4621 |
unlikely as a formal private or derived type with discriminants is required |
| 4622 |
along with an explicitly aliased parameter whose type doesn't statically |
| 4623 |
match the formal type. Such a program is very unlikely, especially as |
| 4624 |
explicitly aliased parameters are a new Ada 2012 feature.]} |
| 4625 |
@end{Incompatible2012} |
| 4626 |
|
| 4627 |
@begin{DiffWord2012} |
| 4628 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0216-1]} |
| 4629 |
@ChgAdded{Version=[5],Text=[@b<Correction:> The @key[in out] parameter |
| 4630 |
rule only applies to actual parameters of elementary types. While this |
| 4631 |
allows additional programs (and thus could be considered an extension), |
| 4632 |
it is unlikely to change anything in a real program (it could only matter |
| 4633 |
in a call with 4 or more parameters, and then only if two composite |
| 4634 |
parameters have matching actuals). Thus we document it as a wording change.]} |
| 4635 |
|
| 4636 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0333-1]} |
| 4637 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Predicate checks are not made |
| 4638 |
for inbound @key{out} parameters. The actual rule change that has this |
| 4639 |
effect is found in @RefSecNum{Type Conversions} and is documented there.]} |
| 4640 |
@end{DiffWord2012} |
| 4641 |
|
| 4642 |
|
| 4643 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 4644 |
@LabeledClause{Return Statements} |
| 4645 |
|
| 4646 |
@begin{Intro} |
| 4647 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4648 |
A @Chg{Version=[2],New=[@nt{simple_@!return_@!statement} or |
| 4649 |
@nt{extended_@!return_@!statement} (collectively called a @i<return statement>) |
| 4650 |
@Defn{return statement}],Old=[@nt{return_statement}]} is used to |
| 4651 |
complete the execution of the |
| 4652 |
innermost enclosing @nt{subprogram_@!body}, |
| 4653 |
@nt{entry_@!body}, or @nt{accept_@!statement}. |
| 4654 |
@end{Intro} |
| 4655 |
|
| 4656 |
@begin{Syntax} |
| 4657 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4658 |
@Syn{lhs=<@Chg{Version=[2],New=[simple_return_statement],Old=[return_statement]}>,rhs="@key{return} [@Syn2{expression}];"} |
| 4659 |
|
| 4660 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0277-1]} |
| 4661 |
@AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=[extended_return_object_declaration],Old=[]}>, |
| 4662 |
rhs="@Chg{Version=[3],New=< |
| 4663 |
@Syn2{defining_identifier} : [@key{aliased}][@key{constant}] @Syn2{return_subtype_indication} [:= @Syn2{expression}]>,Old=[]}"} |
| 4664 |
|
| 4665 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4666 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0015-1],ARef=[AI05-0053-1],ARef=[AI05-0277-1],ARef=[AI05-0299-1]} |
| 4667 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[extended_return_statement],Old=[]}>, |
| 4668 |
rhs="@Chg{Version=[2],New=< |
| 4669 |
@key{return} @Chg{Version=[3],New=<@Syn2{extended_return_object_declaration}>,Old=<@Syn2{defining_identifier} : [@Chg{Version=[3],New=<@Key{constant}>,Old=[@Key{aliased}]}] @Syn2{return_subtype_indication} [:= @Syn2{expression}]>} [@Key{do} |
| 4670 |
@Syn2{handled_sequence_of_statements} |
| 4671 |
@key{end} @key{return}];>,Old=[]}"} |
| 4672 |
|
| 4673 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4674 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[return_subtype_indication],Old=[]}>, |
| 4675 |
rhs="@Chg{Version=[2],New=<@Syn2{subtype_indication} | @Syn2{access_definition}>,Old=[]}"} |
| 4676 |
|
| 4677 |
@end{Syntax} |
| 4678 |
|
| 4679 |
@begin{Resolution} |
| 4680 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4681 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0173-1]} |
| 4682 |
@Chg{Version=[2],New=[@Defn2{Term=[result subtype], Sec=(of a function)} |
| 4683 |
The @i<result subtype> of a function is the subtype denoted by the |
| 4684 |
@nt<subtype_mark>, or defined by the @nt<access_definition>, after the reserved |
| 4685 |
word @key<return> in the profile of the function.@PDefn2{Term=[expected type], |
| 4686 |
Sec=(@nt{expression} of @nt<simple_@!return_@!statement>)}],Old=[@Defn{return expression} |
| 4687 |
The @nt{expression}, if any, of a @nt{return_statement} is called the |
| 4688 |
@i{return expression}. |
| 4689 |
@Defn2{Term=[result subtype], Sec=(of a function)} |
| 4690 |
The @i(result subtype) of a function is the subtype denoted by the |
| 4691 |
@nt{subtype_mark} after the reserved word @key(return) in the profile |
| 4692 |
of the function.@PDefn2{Term=[expected type], Sec=(return expression)}]} |
| 4693 |
The expected type for @Chg{Version=[2],New=[the @nt{expression}, if any, of a |
| 4694 |
@nt{simple_@!return_@!statement}],Old=[a return expression]} is the result type of |
| 4695 |
the corresponding function.@Chg{Version=[2],New=[ |
| 4696 |
@Chg{Version=[5],New=[@PDefn2{Term=[expected type], Sec=(@nt{expression} of @nt{extended_return_object_declaration})}], |
| 4697 |
Old=[@PDefn2{Term=[expected type], Sec=(@nt{expression} of @nt{extended_return_statement})}]} |
| 4698 |
The expected type for the |
| 4699 |
@nt{expression} of an |
| 4700 |
@Chg{Version=[5],New=[@nt{extended_return_object_declaration}],Old=[@nt{extended_return_statement}]} is that of the |
| 4701 |
@nt{return_@!subtype_@!indication}.],Old=[]} |
| 4702 |
@begin{Honest} |
| 4703 |
The same applies to generic functions. |
| 4704 |
@end{Honest} |
| 4705 |
@end{Resolution} |
| 4706 |
|
| 4707 |
@begin{Legality} |
| 4708 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4709 |
@Chg{Version=[2],New=[@Defn2{Term=[apply], |
| 4710 |
Sec=(to a callable construct by a return statement)}], |
| 4711 |
Old=[@Defn2{Term=[apply], Sec=(to a callable construct by a @nt{return_statement})}]} |
| 4712 |
A @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 4713 |
shall be within a callable construct, |
| 4714 |
and it @i{applies to} the innermost @Chg{Version=[2],New=[callable construct |
| 4715 |
or @nt{extended_return_statement} that contains it],Old=[one]}. |
| 4716 |
A @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} shall |
| 4717 |
not be within a body that is within the construct to which the |
| 4718 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} applies. |
| 4719 |
|
| 4720 |
@begin{Honest} |
| 4721 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0089-1]} |
| 4722 |
@ChgAdded{Version=[4],Text=[The above also applies to generic subprograms, |
| 4723 |
even though they are not callable constructs. (An instance of a generic |
| 4724 |
subprogram is a callable construct, but not a generic subprogram itself.)]} |
| 4725 |
@end{Honest} |
| 4726 |
|
| 4727 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4728 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0015-1]} |
| 4729 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0173-1]} |
| 4730 |
A function body shall contain at least one |
| 4731 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} that |
| 4732 |
applies to the function body, |
| 4733 |
unless the function contains @nt{code_statement}s. |
| 4734 |
A @Chg{Version=[2],New=[@nt{simple_@!return_@!statement}],Old=[@nt{return_@!statement}]} shall |
| 4735 |
include @Chg{Version=[2],New=[an @nt{expression}],Old=[a return expression]} |
| 4736 |
if and only if it applies to a function |
| 4737 |
body.@Chg{Version=[2],New=[ An @nt<extended_return_statement> shall apply to |
| 4738 |
a function body.],Old=[]}@Chg{Version=[3],New=[ An |
| 4739 |
@Chg{Version=[5],New=[@nt{extended_return_object_declaration}],Old=[@nt{extended_return_statement}]} |
| 4740 |
with the reserved word @key[constant] shall include an @nt{expression}.],Old=[]} |
| 4741 |
|
| 4742 |
@begin{Reason} |
| 4743 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4744 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0022-1]} |
| 4745 |
The requirement that a function body has to have at least one |
| 4746 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 4747 |
is a @lquotes@;helpful@rquotes@; restriction. |
| 4748 |
There @Chg{Version=[2],New=[has],Old=[was]} been some interest in lifting |
| 4749 |
this restriction, or allowing a raise statement to substitute for the |
| 4750 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}. |
| 4751 |
However, there was enough interest in leaving it as is |
| 4752 |
that we decided not to change it.@Chg{Version=[4],New=[ Note that for |
| 4753 |
Ada 2012, Corrigendum 1, a return statement whose expression is a |
| 4754 |
@nt{raise_expression} can be given in @i<any> function body (the |
| 4755 |
@nt{raise_expression} will match any type), so there is |
| 4756 |
much less need to eliminate this rule.],Old=[]} |
| 4757 |
@end{Reason} |
| 4758 |
@begin{Ramification} |
| 4759 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4760 |
@ChgAdded{Version=[2],Text=[A return statement can apply to an |
| 4761 |
@nt{extended_return_statement}, so a @nt{simple_@!return_@!statement} without |
| 4762 |
an @nt{expression} can be given in one. However, neither |
| 4763 |
@nt{simple_@!return_@!statement} with an @nt{expression} nor an |
| 4764 |
@nt{extended_return_statement} can be given inside an |
| 4765 |
@nt{extended_return_statement}, as they must apply (directly) to a |
| 4766 |
function body.]} |
| 4767 |
|
| 4768 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0089-1]} |
| 4769 |
@ChgAdded{Version=[4],Text=[Since a "function body" includes a generic |
| 4770 |
function body, this rule and all of the following @LegalityTitle apply |
| 4771 |
to generic function bodies as well as non-generic function bodies. This is |
| 4772 |
true even though a generic function is not a function.]} |
| 4773 |
@end{Ramification} |
| 4774 |
|
| 4775 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0173-1]} |
| 4776 |
@ChgAdded{Version=[5],Text=[The @i<@nt{expression} of an |
| 4777 |
@nt{extended_return_statement}> is the |
| 4778 |
@nt{expression} of the @nt{extended_return_object_declaration} of the |
| 4779 |
@nt{extended_return_statement}.@Defn2{Term=(expression),Sec=(of an |
| 4780 |
@nt{extended_return_statement})}]} |
| 4781 |
|
| 4782 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4783 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For an |
| 4784 |
@nt{extended_@!return_@!statement} that applies to a function body:]} |
| 4785 |
|
| 4786 |
@begin{Itemize} |
| 4787 |
|
| 4788 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4789 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1],ARef=[AI05-0103-1]} |
| 4790 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4791 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is defined by a |
| 4792 |
@nt{subtype_mark}, the @nt{return_@!subtype_@!indication} shall be a |
| 4793 |
@nt{subtype_indication}. The type of the @nt{subtype_indication} |
| 4794 |
shall be@Chg{Version=[3],New=[ covered by],Old=[]} the |
| 4795 |
result type of the function. @Chg{Version=[3],New=[The],Old=[If the result |
| 4796 |
subtype of the function is constrained, then the]} subtype defined by the |
| 4797 |
@nt{subtype_indication} shall @Chg{Version=[3],New=[be statically compatible |
| 4798 |
with the result subtype of the function; if the result type of the |
| 4799 |
function is elementary, the two subtypes],Old=[also |
| 4800 |
be constrained and]} shall statically match@Chg{Version=[3],New=[],Old=[ this |
| 4801 |
result subtype]}.@PDefn2{Term=[statically matching],Sec=(required)} |
| 4802 |
If the result subtype of the function is @Chg{Version=[3],New=[indefinite], |
| 4803 |
Old=[unconstrained]}, then the subtype |
| 4804 |
defined by the @nt{subtype_indication} shall be a definite subtype, or there |
| 4805 |
shall be an @nt{expression}.]} |
| 4806 |
|
| 4807 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4808 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4809 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is defined |
| 4810 |
by an @nt{access_definition}, the @nt{return_@!subtype_@!indication} shall be an |
| 4811 |
@nt{access_definition}. The subtype defined by the @nt{access_definition} shall |
| 4812 |
statically match the result subtype of the function. @Redundant[The accessibility |
| 4813 |
level of this anonymous access subtype is that of the result subtype.]]} |
| 4814 |
@begin{TheProof} |
| 4815 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0070-1]} |
| 4816 |
@ChgAdded{Version=[4],Text=[The accessibility of such anonymous access |
| 4817 |
types is defined in the Heart of Darkness (aka |
| 4818 |
@RefSecnum{Operations of Access Types}).]} |
| 4819 |
@end{TheProof} |
| 4820 |
|
| 4821 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0032-1]} |
| 4822 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4823 |
@ChgAdded{Version=[3],Text=[If the result subtype of the function is class-wide, |
| 4824 |
the accessibility level of the type of the subtype defined by the |
| 4825 |
@nt{return_subtype_indication} |
| 4826 |
shall not be statically deeper than that of the master that elaborated |
| 4827 |
the function body.]} |
| 4828 |
@begin{Reason} |
| 4829 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4830 |
@ChgAdded{Version=[3],Text=[In this case, the @nt{return_subtype_indication} |
| 4831 |
could be a specific type initialized by default; in that case there is no |
| 4832 |
@nt{expression} to check.]} |
| 4833 |
@end{Reason} |
| 4834 |
@end{Itemize} |
| 4835 |
|
| 4836 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4837 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1]}@Comment{Paragraph number only change} |
| 4838 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4839 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For any return statement |
| 4840 |
that applies to a function body:]} |
| 4841 |
|
| 4842 |
@begin{Itemize} |
| 4843 |
|
| 4844 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4845 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0188-1]}@Comment{Paragraph number only change} |
| 4846 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4847 |
@ChgAdded{Version=[2],Text=[@Redundant[If the result subtype of the function is limited, |
| 4848 |
then the @nt{expression} of the return statement (if any) shall @Chg{Version=[3], |
| 4849 |
New=[meet the restrictions described in @RefSecNum{Limited Types}],Old=[be an |
| 4850 |
@nt{aggregate}, a function call (or equivalent use of an operator), or a |
| 4851 |
@nt{qualified_expression} or parenthesized expression whose operand is one of |
| 4852 |
these]}.]]} |
| 4853 |
@begin{Discussion} |
| 4854 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4855 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0188-1]} |
| 4856 |
@ChgDeleted{Version=[3],Text=[@Chg{Version=[2],New=[In other words, if limited, the @nt{expression} |
| 4857 |
must produce a @lquotes@;new@rquotes@; object, rather than being the name |
| 4858 |
of a preexisting object (which would imply copying).],Old=[]}]} |
| 4859 |
@end{Discussion} |
| 4860 |
|
| 4861 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]} |
| 4862 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1],ARef=[AI05-0051-1]} |
| 4863 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4864 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is class-wide, |
| 4865 |
the accessibility level of the type of the @nt{expression} |
| 4866 |
@Chg{Version=[3],New=[(if any) ],Old=[]}of the return |
| 4867 |
statement shall not be statically deeper than that of the master that |
| 4868 |
elaborated the function body.@Chg{Version=[3],New=[],Old=[ If the result subtype |
| 4869 |
has one or more |
| 4870 |
unconstrained access discriminants, the accessibility level of the anonymous |
| 4871 |
access type of each access discriminant, as determined by the |
| 4872 |
@nt{expression} of the @nt{simple_@!return_@!statement} or the |
| 4873 |
@nt{return_@!subtype_@!indication}, shall not be |
| 4874 |
statically deeper than that of the master that elaborated the function body.]}]} |
| 4875 |
|
| 4876 |
@begin{Discussion} |
| 4877 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4878 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0032-1],ARef=[AI05-0051-1]} |
| 4879 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]} |
| 4880 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[If],Old=[We know that if]} |
| 4881 |
the result type is @Chg{Version=[4],New=[class-wide],Old=[class wide]}, |
| 4882 |
then there must be an @nt{expression} of the |
| 4883 |
return statement@Chg{Version=[3],New=[ unless this is |
| 4884 |
an @nt{extended_return_statement} whose @nt{return_subtype_indication} is |
| 4885 |
a specific type. We have a separate rule to cover that case. Note that |
| 4886 |
if an @nt{extended_return_statement} has an @nt{expression}, then both this |
| 4887 |
rule and the next one must be satisfied],Old=[. Similarly, if |
| 4888 |
the result subtype is unconstrained, then either the |
| 4889 |
@nt{return_@!subtype_@!indication} (if any) is constrained, or |
| 4890 |
there must be an @nt{expression}]}.]} |
| 4891 |
@end{Discussion} |
| 4892 |
|
| 4893 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1]} |
| 4894 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4895 |
@ChgAdded{Version=[3],Text=[If the subtype determined by the @nt{expression} of the |
| 4896 |
@nt{simple_return_statement} or by the @nt{return_subtype_indication} has |
| 4897 |
one or more access discriminants, the accessibility level of the anonymous |
| 4898 |
access type of each access discriminant shall not be statically deeper than that |
| 4899 |
of the master that elaborated the function body.]} |
| 4900 |
|
| 4901 |
@begin{Discussion} |
| 4902 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4903 |
@ChgAdded{Version=[3],Text=[We use the type used by the return statement |
| 4904 |
rather than from the function return type since we want to check whenever |
| 4905 |
the return object has access discriminants, even if the function return type |
| 4906 |
doesn't have any (mostly for a class-wide type).]} |
| 4907 |
@end{Discussion} |
| 4908 |
@end{Itemize} |
| 4909 |
|
| 4910 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0277-1]} |
| 4911 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4912 |
@ChgAdded{Version=[3],Text=[If the keyword @key[aliased] is present in an |
| 4913 |
@nt{extended_return_object_declaration}, |
| 4914 |
the type of the extended return object shall be immutably limited.]} |
| 4915 |
@end{Legality} |
| 4916 |
|
| 4917 |
@begin{StaticSem} |
| 4918 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4919 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0015-1],ARef=[AI05-0144-2]} |
| 4920 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4921 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[return object], Sec=(extended_return_statement)} |
| 4922 |
Within an @nt{extended_return_statement}, the @i{return object} is declared |
| 4923 |
with the given @nt{defining_identifier}, with the nominal subtype defined by |
| 4924 |
the @nt{return_@!subtype_@!indication}.@Chg{Version=[3],New=[ An |
| 4925 |
@nt{extended_return_statement} with the reserved word @key[constant] |
| 4926 |
is a full constant declaration that declares the return object to be a |
| 4927 |
constant object.],Old=[]}]} |
| 4928 |
@end{StaticSem} |
| 4929 |
|
| 4930 |
@begin{RunTime} |
| 4931 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02],ARef=[AI95-00416-01]} |
| 4932 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1]} |
| 4933 |
@ChgRef{Version=[5],Kind=[RevisedAdded]}@Comment{Paragraph number changed by AI12-0173-1 insertion.} |
| 4934 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[execution], Sec=(extended_return_statement)} |
| 4935 |
For the execution of an @nt{extended_return_statement}, the |
| 4936 |
@nt{subtype_indication} or @nt{access_definition} is elaborated. This creates |
| 4937 |
the nominal subtype of the return object. If there is an @nt{expression}, it |
| 4938 |
is evaluated and converted to the nominal subtype (which might raise |
| 4939 |
Constraint_Error @em see @RefSecNum{Type Conversions}@PDefn2{Term=[implicit subtype conversion],Sec=(function return)}); |
| 4940 |
the return object is created and the converted value is assigned to |
| 4941 |
the return object. Otherwise, the return object is created and initialized |
| 4942 |
by default as for a stand-alone object of its nominal subtype (see |
| 4943 |
@RefSecNum{Object Declarations}). If the nominal subtype is indefinite, the |
| 4944 |
return object is constrained by its initial |
| 4945 |
value.@PDefn2{Term=[creation],Sec=[of a return object]}@PDefn{constrained by its initial value}@Chg{Version=[3],New=[ |
| 4946 |
A check is made that the value of the return object belongs to the function |
| 4947 |
result subtype. Constraint_Error is raised if this |
| 4948 |
check fails.@Defn2{Term=[Constraint_Error], |
| 4949 |
Sec=(raised by failure of runtime check)} |
| 4950 |
@IndexCheck{Discriminant_Check}],Old=[]}]} |
| 4951 |
|
| 4952 |
@begin{Ramification} |
| 4953 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4954 |
@ChgAdded{Version=[2],Text=[If the result type is controlled or has a |
| 4955 |
controlled part, appropriate calls on Initialize or Adjust are performed |
| 4956 |
prior to executing the @nt{handled_sequence_of_statements}, except when the |
| 4957 |
initial expression is an @nt{aggregate} (which requires build-in-place |
| 4958 |
with no call on Adjust).]} |
| 4959 |
|
| 4960 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4961 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]} |
| 4962 |
@ChgAdded{Version=[2],Text=[If the return statement is left without resulting |
| 4963 |
in a return (for example, due to an exception propagated from the |
| 4964 |
@nt{expression} or the @nt{handled_sequence_of_statements}, or a goto out of |
| 4965 |
the @nt{handled_sequence_of_statements}), @Chg{Version=[3],New=[if ],Old=[]}the |
| 4966 |
return object @Chg{Version=[3],New=[has been created, it ],Old=[]}is |
| 4967 |
finalized prior to leaving the return statement.@Chg{Version=[3],New=[ If |
| 4968 |
it has not been created when the return statement is left, it is not |
| 4969 |
created or finalized.],Old=[]}]} |
| 4970 |
|
| 4971 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0032-1]} |
| 4972 |
@ChgAdded{Version=[3],Text=[Other rules ensure that the check required by |
| 4973 |
this rule cannot fail unless the function has a class-wide result subtype |
| 4974 |
where the associated specific subtype is constrained. In other cases, |
| 4975 |
either the subtypes have to match or the function's subtype is |
| 4976 |
unconstrained and needs no checking.]} |
| 4977 |
@end{Ramification} |
| 4978 |
|
| 4979 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4980 |
@Chg{Version=[2],New=[@PDefn2{Term=[execution], Sec=(simple_@!return_@!statement)}], |
| 4981 |
Old=[@PDefn2{Term=[execution], Sec=(return_statement)}]} |
| 4982 |
For the execution of a @Chg{Version=[2],New=[@nt{simple_@!return_@!statement}], |
| 4983 |
Old=[@nt{return_statement}]}, the @nt{expression} |
| 4984 |
(if any) is first evaluated@Chg{Version=[2],New=[,],Old=[ and]} converted to |
| 4985 |
the result subtype@Chg{Version=[2], |
| 4986 |
New=[, and then is assigned to the anonymous @i{return object}. |
| 4987 |
@PDefn2{Term=[return object], Sec=(simple_@!return_@!statement)}],Old=[.]} |
| 4988 |
@PDefn2{Term=[implicit subtype conversion],Sec=(function return)} |
| 4989 |
@begin{Ramification} |
| 4990 |
The conversion might raise |
| 4991 |
Constraint_Error @em (see @RefSecNum{Type Conversions}). |
| 4992 |
@end{Ramification} |
| 4993 |
|
| 4994 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00416-01]} |
| 4995 |
@Chg{Version=[2],New=[@Redundant[If the return object has any parts that are tasks, the |
| 4996 |
activation of those tasks does not occur until after the function returns (see |
| 4997 |
@RefSecNum{Task Execution - Task Activation}).]], |
| 4998 |
Old=[If the result type is class-wide, then |
| 4999 |
the tag of the result is the tag of the value |
| 5000 |
of the @nt<expression>.]} |
| 5001 |
@begin{TheProof} |
| 5002 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5003 |
@ChgAdded{Version=[2],Text=[This is specified by the rules in |
| 5004 |
@RefSecNum{Task Execution - Task Activation}.]} |
| 5005 |
@end{TheProof} |
| 5006 |
@begin{Reason} |
| 5007 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5008 |
@ChgAdded{Version=[2],Text=[Only the caller can know when task activations |
| 5009 |
should take place, as it depends on the context of the call. If the function |
| 5010 |
is being used to initialize the component of some larger object, then that |
| 5011 |
entire object must be initialized before any task activations. Even after the |
| 5012 |
outer object is fully initialized, task activations are still postponed until |
| 5013 |
the @key{begin} at the end of the declarative part if the function is being |
| 5014 |
used to initialize part of a declared object.]} |
| 5015 |
@end{Reason} |
| 5016 |
|
| 5017 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01]} |
| 5018 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0024-1],ARef=[AI05-0032-1]} |
| 5019 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0097-1]} |
| 5020 |
@ChgDeleted{Version=[2],Type=[Leading],Keepnext=[T],Text=[]}@ChgNote{A dummy |
| 5021 |
ChgDeleted to get conditional "Leading".}If |
| 5022 |
the result type @Chg{Version=[2],New=[of a function ],Old=[]}is a specific |
| 5023 |
tagged type@Chg{Version=[2],New=[, the tag of the return object is that |
| 5024 |
of the result type. If the result type is class-wide, the tag of the |
| 5025 |
return object is that of @Chg{Version=[4],New=[the value of the @nt{expression}, |
| 5026 |
unless the return object is defined by |
| 5027 |
an @nt{extended_return_object_declaration} with a @nt{subtype_indication} that |
| 5028 |
is specific, in which case it is that of ],Old=[]}@Chg{Version=[3],New=[the |
| 5029 |
type of the @nt{subtype_indication}],Old=[]}@Chg{Version=[4],New=[], |
| 5030 |
Old=[@Chg{Version=[3],New=[ if it is |
| 5031 |
specific, or otherwise that of ],Old=[]}the |
| 5032 |
value of the @Chg{Version=[3],New=[@nt{expression}],Old=[expression]}]}. |
| 5033 |
A check is made that |
| 5034 |
the @Chg{Version=[3],New=[master],Old=[accessibility level]} of the type |
| 5035 |
identified by the tag of the result @Chg{Version=[3],New=[includes the |
| 5036 |
elaboration],Old=[is not deeper than that]} of the master that elaborated |
| 5037 |
the function body. If |
| 5038 |
this check fails, Program_Error is raised.@Defn2{Term=[Program_Error], |
| 5039 |
Sec=(raised by failure of runtime check)} |
| 5040 |
@IndexCheck{Accessibility_Check}],Old=[:]} |
| 5041 |
|
| 5042 |
@begin{Ramification} |
| 5043 |
@ChgNote{Moved from after paragraph 10} |
| 5044 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5045 |
@ChgAdded{Version=[2],Text=[The first sentence is true even if the |
| 5046 |
tag of the @nt{expression} is different, which |
| 5047 |
could happen if the @nt{expression} were a view conversion or a |
| 5048 |
dereference of an access value. Note that for a limited type, because |
| 5049 |
of the restriction to @nt{aggregate}s and function calls (and no conversions), |
| 5050 |
the tag will already match]}. |
| 5051 |
@end{Ramification} |
| 5052 |
@begin{Reason} |
| 5053 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5054 |
@ChgAdded{Version=[2],Text=[The first rule ensures |
| 5055 |
that a function whose result type is |
| 5056 |
a specific tagged type always returns an object whose tag is that of the |
| 5057 |
result type. This is important for dispatching on controlling result, and |
| 5058 |
allows the caller to allocate the appropriate amount of space to hold |
| 5059 |
the value being returned (assuming there are no discriminants).]} |
| 5060 |
|
| 5061 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5062 |
@ChgRef{Version=[3],Kind=[Revised]} |
| 5063 |
@ChgAdded{Version=[2],Text=[The @Chg{Version=[3],New=[master ],Old=[]}check |
| 5064 |
prevents the returned object |
| 5065 |
from outliving its type. Note that this check cannot fail for a specific |
| 5066 |
tagged type, as the tag represents the function's type, which necessarily |
| 5067 |
must be declared outside of the function.]} |
| 5068 |
|
| 5069 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5070 |
@ChgAdded{Version=[3],Text=[We can't use the normal accessibility level |
| 5071 |
@lquotes@;deeper than@rquotes@; check |
| 5072 |
here because we may have @lquotes@;incomparable@rquotes@; levels if |
| 5073 |
the masters belong to two different tasks. This can happen when an |
| 5074 |
accept statement calls a function declared in the enclosing task body, and |
| 5075 |
the function returns an object passed to it from the accept statement, and |
| 5076 |
this object was itself a parameter to the accept statement.]} |
| 5077 |
@end{Reason} |
| 5078 |
@begin{Honest} |
| 5079 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0097-1]} |
| 5080 |
@ChgAdded{Version=[4],Text=[The @nt{expression} here is the return expression |
| 5081 |
if the return statement is a @nt{simple_return_statement}, and the |
| 5082 |
initializing expression of the @nt{extended_return_object_declaration} if the |
| 5083 |
return statement is an @nt{extended_return_statement} (ignoring any inner |
| 5084 |
@nt{simple_return_statement}s, which necessarily cannot have an |
| 5085 |
@nt{expression}, and any other @nt{expression}s inside of the |
| 5086 |
@nt{extended_return_statement}).]} |
| 5087 |
@end{Honest} |
| 5088 |
|
| 5089 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI95-00318-02],ARef=[AI05-0058-1],ARef=[AI12-0343-1]}@Comment{Just moved this text from below.} |
| 5090 |
@ChgAdded{Version=[5],Text=[For the execution of an |
| 5091 |
@nt{extended_@!return_@!statement}, the |
| 5092 |
@nt{handled_@!sequence_@!of_@!statements} is executed. Within this |
| 5093 |
@nt{handled_@!sequence_@!of_@!statements}, the execution of a |
| 5094 |
@nt{simple_@!return_@!statement} that applies to the |
| 5095 |
@nt{extended_@!return_@!statement} causes a transfer of control that completes |
| 5096 |
the @nt{extended_@!return_@!statement}. Upon completion |
| 5097 |
of a return statement that applies to a callable construct by the |
| 5098 |
normal completion of a @nt{simple_@!return_@!statement} or |
| 5099 |
by reaching the @key[end return] of an @nt{extended_@!return_@!statement}, a |
| 5100 |
transfer of control is performed which completes the execution of the callable |
| 5101 |
construct, and returns to the caller.]} |
| 5102 |
|
| 5103 |
@begin{Ramification} |
| 5104 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0058-1]} |
| 5105 |
@ChgAdded{Version=[5],Text=[A transfer of control that completes an |
| 5106 |
@nt{extended_return_statement} (such as an exit or goto) does not cause |
| 5107 |
a return to the caller unless it is caused by @nt{simple_return_statement} |
| 5108 |
(that is, triggers the second sentence of this paragraph). The return to |
| 5109 |
the caller occurs for the @nt{simple_return_statement} that applies to an |
| 5110 |
@nt{extended_return_statement} because the last sentence says |
| 5111 |
@ldquote@;the normal completion of a @nt{simple_return_statement}@rdquote@;, |
| 5112 |
which includes the one nested in the @nt{extended_return_statement}.]} |
| 5113 |
|
| 5114 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0343-1]} |
| 5115 |
@ChgAdded{Version=[5],Text=[The check on the tag of the object occurs when |
| 5116 |
the object is created (before any @nt{sequence_of_statements}); the checks |
| 5117 |
which follow occur after the execution of any @nt{sequence_of_statements}. |
| 5118 |
This is implicit in the order of definition of these @RunTimeTitle@;.]} |
| 5119 |
@end{Ramification} |
| 5120 |
|
| 5121 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0073-1]} |
| 5122 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0343-1]}@Comment{Just a paragraph number change} |
| 5123 |
@ChgAdded{Version=[3],Text=[@IndexCheck{Tag_Check}If the result subtype |
| 5124 |
of the function is defined by |
| 5125 |
an @nt{access_definition} designating a specific tagged type @i<T>, a check |
| 5126 |
is made that the result value is null or the tag of the object designated |
| 5127 |
by the result value identifies @i<T>. |
| 5128 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)} |
| 5129 |
Constraint_Error is raised if this check fails.]} |
| 5130 |
@begin{Reason} |
| 5131 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5132 |
@ChgAdded{Version=[3],Text=[This check is needed so that dispatching |
| 5133 |
on controlling access results works for tag-indeterminate functions. |
| 5134 |
If it was not made, it would be possible for such functions to return |
| 5135 |
an access to a descendant type, meaning the function could return |
| 5136 |
an object with a tag different than the one assumed by the |
| 5137 |
dispatching rules.]} |
| 5138 |
@end{Reason} |
| 5139 |
|
| 5140 |
@begin{NotIso} |
| 5141 |
@ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 9 |
| 5142 |
through 20 were deleted.>}]}@Comment{This message should be deleted if the |
| 5143 |
paragraphs are ever renumbered.} |
| 5144 |
@end{NotIso} |
| 5145 |
|
| 5146 |
@begin(itemize) |
| 5147 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5148 |
@ChgDeleted{Version=[2],Text=[@IndexCheck{Tag_Check} |
| 5149 |
If it is limited, then |
| 5150 |
a check is made that the tag of the value of the return expression |
| 5151 |
identifies the result type. |
| 5152 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of runtime check)} |
| 5153 |
Constraint_Error is raised if this check fails.]} |
| 5154 |
|
| 5155 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5156 |
@ChgDeleted{Version=[2],Text=[If it is nonlimited, then |
| 5157 |
the tag of the result is that of the result type.]} |
| 5158 |
@begin{Ramification} |
| 5159 |
@ChgNote{These two notes were revised and moved up} |
| 5160 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5161 |
@ChgDeleted{Version=[2],Text=[This is true even if the |
| 5162 |
tag of the return expression is different.]} |
| 5163 |
@end{Ramification} |
| 5164 |
@begin{Reason} |
| 5165 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5166 |
@ChgDeleted{Version=[2],Text=[These rules ensure |
| 5167 |
that a function whose result type is |
| 5168 |
a specific tagged type always returns an object whose tag is that of the |
| 5169 |
result type. This is important for dispatching on controlling result, |
| 5170 |
and, if nonlimited, |
| 5171 |
allows the caller to allocate the appropriate amount of space to hold |
| 5172 |
the value being returned (assuming there are no discriminants).]} |
| 5173 |
@end{Reason} |
| 5174 |
@end(itemize) |
| 5175 |
|
| 5176 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5177 |
@ChgDeleted{Version=[2],Type=[Leading],Keepnext=[T], |
| 5178 |
Text=[@Defn{return-by-reference type} |
| 5179 |
A type is a @i(return-by-reference) type if it |
| 5180 |
is a descendant of one of the following:]} |
| 5181 |
@begin(itemize) |
| 5182 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5183 |
@ChgDeleted{Version=[2],Text=[a tagged limited type;]} |
| 5184 |
|
| 5185 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5186 |
@ChgDeleted{Version=[2],Text=[a task or protected type;]} |
| 5187 |
|
| 5188 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5189 |
@ChgDeleted{Version=[2],Text=[a nonprivate type with the reserved word |
| 5190 |
@b(limited) in its declaration;]} |
| 5191 |
|
| 5192 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5193 |
@ChgDeleted{Version=[2],Text=[a composite type with a subcomponent |
| 5194 |
of a return-by-reference type;]} |
| 5195 |
|
| 5196 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5197 |
@ChgDeleted{Version=[2],Text=[a private type |
| 5198 |
whose full type is a return-by-reference type.]} |
| 5199 |
@end(itemize) |
| 5200 |
@begin{Ramification} |
| 5201 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 5202 |
@ChgDeleted{Version=[2],Text=[ |
| 5203 |
The above rules are such that there are no "Ada 83" types other than |
| 5204 |
those containing tasks that are return-by-reference. This helps |
| 5205 |
to minimize upward incompatibilities relating to return-by-reference.]} |
| 5206 |
@end{Ramification} |
| 5207 |
|
| 5208 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5209 |
@ChgDeleted{Version=[2],Type=[Leading],Text=[@IndexCheck{Accessibility_Check} |
| 5210 |
If the result type is a return-by-reference type, |
| 5211 |
then a check is made that the return expression is one of the |
| 5212 |
following:]} |
| 5213 |
@begin(itemize) |
| 5214 |
|
| 5215 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5216 |
@ChgDeleted{Version=[2],Text=[a @nt{name} that denotes an object view |
| 5217 |
whose accessibility level is not deeper than that of the master that |
| 5218 |
elaborated the function body; or]} |
| 5219 |
@begin{Discussion} |
| 5220 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00316-01]} |
| 5221 |
@ChgNote{This really wasn't in the previous version, but we don't want it |
| 5222 |
in a version without deletions shown...} |
| 5223 |
@ChgDeleted{Version=[2],Text=[This rule was unnecessarily confusing, and the |
| 5224 |
parenthetical remark "(or a value with an associated object, see 6.2)" |
| 5225 |
was added @em and then the entire concept was deleted.]} |
| 5226 |
@end{Discussion} |
| 5227 |
|
| 5228 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5229 |
@ChgDeleted{Version=[2],Text=[a parenthesized expression or |
| 5230 |
@nt{qualified_expression} whose operand is one of these kinds of expressions.]} |
| 5231 |
|
| 5232 |
@end(itemize) |
| 5233 |
|
| 5234 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 5235 |
@ChgDeleted{Version=[2],Text=[@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)} |
| 5236 |
The exception Program_Error is raised if this check fails.]} |
| 5237 |
@begin{Discussion} |
| 5238 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 5239 |
@ChgDeleted{Version=[2],Text=[Compare the definition of return-by-reference |
| 5240 |
with that of by-reference.]} |
| 5241 |
|
| 5242 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 5243 |
@ChgDeleted{Version=[2],Text=[The return-by-reference types are all limited types |
| 5244 |
except those that are limited only because of a limited |
| 5245 |
private type with a nonlimited untagged full type.]} |
| 5246 |
@end{Discussion} |
| 5247 |
@begin{Reason} |
| 5248 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 5249 |
@ChgDeleted{Version=[2],Text=[@PDefn{generic contract issue} |
| 5250 |
This check can often be performed at compile time. It is |
| 5251 |
defined to be a runtime check to avoid generic contract model |
| 5252 |
problems. In a future version of the standard, we anticipate |
| 5253 |
that function return of a local variable will be illegal for all |
| 5254 |
limited types, eliminating the need for the runtime check |
| 5255 |
except for dereferences of an access parameter.]} |
| 5256 |
@end{Reason} |
| 5257 |
|
| 5258 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00402-01],ARef=[AI95-00416-01]} |
| 5259 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0051-1]} |
| 5260 |
@Chg{Version=[2], |
| 5261 |
New=[If @Chg{Version=[3],New=[any part of the specific type of the return object], |
| 5262 |
Old=[the result subtype]} of a function |
| 5263 |
@Chg{Version=[3],New=[(or coextension thereof) ],Old=[]}has one or more |
| 5264 |
@Chg{Version=[3],New=[],Old=[unconstrained ]}access |
| 5265 |
discriminants@Chg{Version=[3],New=[ whose value is not constrained by the |
| 5266 |
result subtype of the function],Old=[]}, |
| 5267 |
a check is made that the accessibility level of the anonymous access type |
| 5268 |
of each access discriminant, as determined by the @nt{expression} or the |
| 5269 |
@nt{return_@!subtype_@!indication} of the @Chg{Version=[3],New=[return |
| 5270 |
statement],Old=[function]}, |
| 5271 |
is not deeper than @Chg{Version=[3],New=[the level of the master of the call |
| 5272 |
(see @RefSecNum{Operations of Access Types})], |
| 5273 |
Old=[that of the master that elaborated the |
| 5274 |
function body]}. If this check fails, Program_Error is raised. |
| 5275 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)} |
| 5276 |
@IndexCheck{Accessibility_Check}], |
| 5277 |
Old=[For a function with a return-by-reference result type |
| 5278 |
the result is returned by reference; |
| 5279 |
that is, the function call denotes a constant view of the |
| 5280 |
object associated |
| 5281 |
with the value of the return expression. |
| 5282 |
@Defn2{Term=[assignment operation], Sec=(during execution of a |
| 5283 |
@nt{return_statement})} |
| 5284 |
For any other function, the result is returned by copy; |
| 5285 |
that is, |
| 5286 |
the converted value is assigned into an anonymous constant created at |
| 5287 |
the point of the @nt{return_statement}, and the function call denotes |
| 5288 |
that object.]} |
| 5289 |
@begin{Ramification} |
| 5290 |
@ChgRef{Version=[2],Kind=[Deleted]} |
| 5291 |
@ChgDeleted{Version=[2],Text=[The assignment operation does the necessary |
| 5292 |
value adjustment, as described in |
| 5293 |
@RefSec{Assignment and Finalization}. |
| 5294 |
@RefSecNum{Completion and Finalization} |
| 5295 |
describes when the anonymous constant is finalized.]} |
| 5296 |
@end{Ramification} |
| 5297 |
@begin{Reason} |
| 5298 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5299 |
@ChgAdded{Version=[2],Text=[The check prevents the returned |
| 5300 |
object (for a nonlimited type) from outliving the object designated by one |
| 5301 |
of its discriminants. The check is made on the values of the discriminants, |
| 5302 |
which may come from the @nt{return_@!subtype_@!indication} (if constrained), |
| 5303 |
or the @nt{expression}, but it is never necessary to check both.]} |
| 5304 |
@end{Reason} |
| 5305 |
@begin{ImplNote} |
| 5306 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]} |
| 5307 |
@ChgAdded{Version=[3],Text=[The reason for saying @ldquote@;any part of |
| 5308 |
the specific type@rdquote is to simplify implementation. In the case of |
| 5309 |
class-wide result objects, this allows the testing of a simple flag in the |
| 5310 |
tagged type descriptor that indicates whether the specific type has any parts with |
| 5311 |
access discriminants. By basing the test on the type of the object rather than |
| 5312 |
the object itself, we avoid concerns about whether subcomponents in variant |
| 5313 |
parts and of arrays (which might be empty) are present.]} |
| 5314 |
@end{ImplNote} |
| 5315 |
@begin{Discussion} |
| 5316 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]} |
| 5317 |
@ChgAdded{Version=[3],Text=[For a function with a class-wide result type, the |
| 5318 |
access values that need to be checked are determined by the tag of the return |
| 5319 |
object. In order to implement this accessibility check in the case where the |
| 5320 |
tag of the result is not known statically at the point of the return |
| 5321 |
statement, an implementation may need to somehow associate with the tag of a |
| 5322 |
specific tagged type an indication of whether the type has unconstrained |
| 5323 |
access discriminants (explicit or inherited) or has any subcomponents with |
| 5324 |
such discriminants. If an implementation is already maintaining a statically |
| 5325 |
initialized descriptor of some kind for each specific tagged type, then an |
| 5326 |
additional Boolean could be added to this descriptor.]} |
| 5327 |
|
| 5328 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0234-1]} |
| 5329 |
@ChgAdded{Version=[3],Text=[Note that the flag should only be queried in the |
| 5330 |
case where the result object might have access discriminants that might |
| 5331 |
have subtypes with "bad" accessibility levels (as determined by the rules of |
| 5332 |
@RefSecNum{Operations of Access Types} for determining the accessibility |
| 5333 |
level of the type of an access discriminant in the @nt{expression} or |
| 5334 |
@nt{return_subtype_indication} of a return statement).]} |
| 5335 |
|
| 5336 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5337 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Thus, in a case like]} |
| 5338 |
|
| 5339 |
@begin{Example} |
| 5340 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5341 |
@ChgAdded{Version=[3],Text=[@key[type] Global @key[is access] T'Class; |
| 5342 |
@key[function] F (Ptr : Global) @key[return] T'Class @key[is] |
| 5343 |
@key[begin] |
| 5344 |
@key[return] Ptr.@key[all]; |
| 5345 |
@key[end] F;]} |
| 5346 |
@end{Example} |
| 5347 |
|
| 5348 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5349 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[there is no need for a run-time |
| 5350 |
accessibility check. While an object of T'Class "might have" access |
| 5351 |
discriminants, the accessibility of those potential discriminants |
| 5352 |
cannot be bad. The setting of the bit doesn't matter and there is no |
| 5353 |
need to query it.]} |
| 5354 |
|
| 5355 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5356 |
@ChgAdded{Version=[3],Type=[Leading],Text=[On the other hand, given]} |
| 5357 |
@begin{Example} |
| 5358 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5359 |
@ChgAdded{Version=[3],Text=[@key[function] F @key[return] T'Class @key[is] |
| 5360 |
Local : T'Class := ... ; |
| 5361 |
@key[begin] |
| 5362 |
@key[return] Local; |
| 5363 |
@key[end] F;]} |
| 5364 |
@end{Example} |
| 5365 |
|
| 5366 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5367 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[In this case, a check would |
| 5368 |
typically be required.]} |
| 5369 |
|
| 5370 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5371 |
@ChgAdded{Version=[3],Type=[Leading],Text=[The need for including |
| 5372 |
subcomponents in this check is illustrated by the following example:]} |
| 5373 |
@begin{Example} |
| 5374 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5375 |
@ChgAdded{Version=[3],Text=[X : @key[aliased] Integer;]} |
| 5376 |
|
| 5377 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5378 |
@ChgAdded{Version=[3],Text=[@key[type] Component_Type (Discrim : @key[access] Integer := X'Access) |
| 5379 |
@key[is limited null record];]} |
| 5380 |
|
| 5381 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5382 |
@ChgAdded{Version=[3],Text=[@key[type] Undiscriminated @key[is record] |
| 5383 |
Fld : Component_Type; |
| 5384 |
@key[end record];]} |
| 5385 |
|
| 5386 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5387 |
@ChgAdded{Version=[3],Text=[@key[function] F @key[return] Undiscriminated @key[is] |
| 5388 |
Local : @key[aliased] Integer; |
| 5389 |
@key[begin] |
| 5390 |
@key[return] X : Undiscriminated := (Fld => (Discrim => Local'Access)) @key[do] |
| 5391 |
Foo; |
| 5392 |
@key[end return]; |
| 5393 |
--@Examcom{ raises Program_Error after calling Foo.} |
| 5394 |
@key[end] F;]} |
| 5395 |
@end{Example} |
| 5396 |
@end{Discussion} |
| 5397 |
@begin{Ramification} |
| 5398 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]} |
| 5399 |
@ChgAdded{Version=[3],Text=[In the case where the tag of the result is not |
| 5400 |
known statically at the point of the return statement and the run-time |
| 5401 |
accessibility check is needed, discriminant values and array bounds play no |
| 5402 |
role in performing this check. That is, array components are assumed to have |
| 5403 |
nonzero length and components declared within variant parts are assumed to be |
| 5404 |
present. Thus, the check may be implemented simply by testing the |
| 5405 |
aforementioned descriptor bit and conditionally raising Program_Error.]} |
| 5406 |
@end{Ramification} |
| 5407 |
|
| 5408 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 5409 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0058-1]} |
| 5410 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0343-1]} |
| 5411 |
@Chg{Version=[5],New=[A check is performed that the return value satisfies the |
| 5412 |
predicates of the return subtype. If this check fails, the effect is as defined in subclause |
| 5413 |
@RefSec{Subtype Predicates}.@Defn2{Term=[Assertion_Error],Sec=(raised by failure of runtime check)}],Old=[@Chg{Version=[2],New=[For |
| 5414 |
the execution of an @nt{extended_@!return_@!statement}, the |
| 5415 |
@nt{handled_@!sequence_@!of_@!statements} is executed. Within this |
| 5416 |
@nt{handled_@!sequence_@!of_@!statements}, the execution of a |
| 5417 |
@nt{simple_@!return_@!statement} that applies to the |
| 5418 |
@nt{extended_@!return_@!statement} causes a transfer of control that completes |
| 5419 |
the @nt{extended_@!return_@!statement}. Upon completion |
| 5420 |
of a return statement that applies to a callable construct@Chg{Version=[3], |
| 5421 |
New=[ by the normal completion of a @nt{simple_@!return_@!statement} or |
| 5422 |
by reaching the @key[end return] of an @nt{extended_@!return_@!statement}], |
| 5423 |
Old=[]}],Old=[Finally]}, a |
| 5424 |
transfer of control is performed which completes the execution of the callable |
| 5425 |
construct@Chg{Version=[2],New=[], Old=[ to which the @nt{return_@!statement} |
| 5426 |
applies]}, and returns to the caller.]} |
| 5427 |
|
| 5428 |
@begin{Ramification} |
| 5429 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0058-1]} |
| 5430 |
@ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0343-1]} |
| 5431 |
@ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[A transfer of |
| 5432 |
control that completes an |
| 5433 |
@nt{extended_return_statement} (such as an exit or goto) does not cause |
| 5434 |
a return to the caller unless it is caused by @nt{simple_return_statement} |
| 5435 |
(that is, triggers the second sentence of this paragraph). The return to |
| 5436 |
the caller occurs for the @nt{simple_return_statement} that applies to an |
| 5437 |
@nt{extended_return_statement} because the last sentence says |
| 5438 |
@ldquote@;the normal completion of a @nt{simple_return_statement}@rdquote@;, |
| 5439 |
which includes the one nested in the @nt{extended_return_statement}.]}]} |
| 5440 |
@end{Ramification} |
| 5441 |
|
| 5442 |
@begin{ImplNote} |
| 5443 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0343-1]} |
| 5444 |
@ChgAdded{Version=[5],Text=[The subtype conversion of the return |
| 5445 |
expression for a @nt{simple_return_statement} performs this same check. The |
| 5446 |
permissions of @RefSecNum{Pragmas Assert and Assertion_Policy} ensure |
| 5447 |
that duplicate evaluation of a predicate at a single point is never |
| 5448 |
required, so a single evaluation of the predicate is enough in this case.]} |
| 5449 |
@end{ImplNote} |
| 5450 |
|
| 5451 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5452 |
@ChgAdded{Version=[2],Text=[In the case of a function, the @nt{function_call} |
| 5453 |
denotes a constant view of the return object.]} |
| 5454 |
@end{RunTime} |
| 5455 |
|
| 5456 |
@begin{ImplPerm} |
| 5457 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 5458 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0050-1]} |
| 5459 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{This is a fake used to provide a conditional leading.} |
| 5460 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[For a function call used to |
| 5461 |
initialize a composite],Old=[If the result subtype of a function is |
| 5462 |
unconstrained, and a call on the function is used to provide the initial value |
| 5463 |
of an]} object with a constrained nominal subtype@Chg{Version=[3],New=[ or |
| 5464 |
used to initialize a return object that is built in place |
| 5465 |
into such an object:],Old=[, Constraint_Error may be raised |
| 5466 |
at the point of the call (after abandoning the execution of the function body) |
| 5467 |
if, while elaborating the @nt{return_@!subtype_@!indication} or |
| 5468 |
evaluating the @nt{expression} of a return statement that applies to the |
| 5469 |
function body, it |
| 5470 |
is determined that the value of the result will violate the constraint of the |
| 5471 |
subtype of this object.]}]} |
| 5472 |
|
| 5473 |
@begin{Itemize} |
| 5474 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0050-1]} |
| 5475 |
@ChgAdded{Version=[3],Text=[If the result subtype of the function is |
| 5476 |
constrained, and conversion of an object of this subtype to the subtype of the |
| 5477 |
object being initialized would raise Constraint_Error, then Constraint_Error |
| 5478 |
may be raised before calling the function.]} |
| 5479 |
|
| 5480 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0050-1]} |
| 5481 |
@ChgAdded{Version=[3],Text=[If the result subtype of the function is |
| 5482 |
unconstrained, and a return statement is executed such that the return object |
| 5483 |
is known to be constrained, and conversion of the return object to the subtype |
| 5484 |
of the object being initialized would raise Constraint_Error, then |
| 5485 |
Constraint_Error may be raised at the point of the call (after abandoning the |
| 5486 |
execution of the function body).]} |
| 5487 |
@end{Itemize} |
| 5488 |
|
| 5489 |
@begin{Reason} |
| 5490 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 5491 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0050-1]} |
| 5492 |
@ChgAdded{Version=[2],Text=[Without such a permission, it would be very |
| 5493 |
difficult to implement |
| 5494 |
@lquotes@;@Chg{Version=[3],New=[built-in-place],Old=[build-in-place]}@rquotes semantics. |
| 5495 |
@Chg{Version=[3],New=[The intention is that the exception is raised at the |
| 5496 |
same point that it would have been raised without the permission; it |
| 5497 |
should not change handlers if the implementation switches between |
| 5498 |
return-by-copy and built-in-place. This means that the],Old=[Such an]} |
| 5499 |
exception is not handleable within the function, because in the |
| 5500 |
return-by-copy case, the constraint check to verify that the result satisfies |
| 5501 |
the constraints of the object being initialized happens after the function |
| 5502 |
returns@Chg{Version=[3],New=[],Old=[, and we want the semantics to change as |
| 5503 |
little as possible when switching between return-by-copy and build-in-place]}. |
| 5504 |
This implies further that upon detecting such a situation, the implementation |
| 5505 |
may need to simulate a goto to a point outside any local exception handlers |
| 5506 |
prior to raising the exception.]} |
| 5507 |
@end{Reason} |
| 5508 |
|
| 5509 |
@begin{Ramification} |
| 5510 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 5511 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0050-1]} |
| 5512 |
@Chg{Version=[3],New=[These permissions do not apply in the case of an extended |
| 5513 |
return object with mutable discriminants. That's necessary because in that |
| 5514 |
case a return object can be created with the @ldquote@;wrong@rdquote |
| 5515 |
discriminants and then changed to the @ldquote@;right@rdquote discriminants |
| 5516 |
later (but before returning). We don't want this case raising an exception |
| 5517 |
when the canonical semantics will not do so.],Old=[@Chg{Version=[2],New=[This |
| 5518 |
permission is allowed during the evaluation of the @nt{expression} of an |
| 5519 |
@nt{extended_return_statement}, because the @nt{return_@!subtype_@!indication} |
| 5520 |
may be unconstrained and the @nt{expression} then would provide the |
| 5521 |
constraints.],Old=[]}]} |
| 5522 |
|
| 5523 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 5524 |
@ChgAdded{Version=[3],Text=[It's still possible to write a program that will |
| 5525 |
raise an exception using this permission that would not in the canonical |
| 5526 |
semantics. That could happen if a return statement with the |
| 5527 |
@ldquote@;wrong@rdquote discriminants or bounds is abandoned (via an |
| 5528 |
exception, or for an extended_return_statement, via an exit or goto |
| 5529 |
statement), and then a return statement with the @ldquote@;right@rdquote |
| 5530 |
discriminants or bounds is executed. The only solution for this problem is to |
| 5531 |
not have the permission at all, but this is too unusual of a case to worry about |
| 5532 |
the effects of the permission, especially given the implementation |
| 5533 |
difficulties for built-in-place objects that this permission is intended to |
| 5534 |
ease.]} |
| 5535 |
|
| 5536 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 5537 |
@ChgAdded{Version=[3],Text=[Note that the mutable-discriminant case only |
| 5538 |
happens when built-in-place initialization is optional. This means that any |
| 5539 |
difficulties associated with implementing built-in-place initialization |
| 5540 |
without these permissions can be sidestepped by not building in place.]} |
| 5541 |
|
| 5542 |
@end{Ramification} |
| 5543 |
|
| 5544 |
@end{ImplPerm} |
| 5545 |
|
| 5546 |
@begin{Examples} |
| 5547 |
@leading@keepnext@i{Examples of return statements:} |
| 5548 |
@begin{Example} |
| 5549 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 5550 |
@key[return]; --@ExamCom{ in a procedure body, }@nt{entry_body}@ExamCom{,}@Chg{Version=[2],New=[ |
| 5551 |
-- @nt{accept_statement}@ExamCom{, or }@nt{extended_return_statement}],Old=[@ExamCom{ or }@nt{accept_statement}]} |
| 5552 |
|
| 5553 |
@key[return] Key_Value(Last_Index); --@ExamCom{ in a function body} |
| 5554 |
|
| 5555 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5556 |
@Chg{Version=[2],New=<@key[return] Node : Cell @key{do} --@ExamCom{ in a function body, see @RefSecNum{Incomplete Type Declarations} for Cell} |
| 5557 |
Node.Value := Result; |
| 5558 |
Node.Succ := Next_Node; |
| 5559 |
@key{end} @key{return};>,Old=<>} |
| 5560 |
@end{Example} |
| 5561 |
@end{Examples} |
| 5562 |
|
| 5563 |
@begin{Incompatible83} |
| 5564 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 5565 |
@Defn{incompatibilities with Ada 83} |
| 5566 |
In Ada 95, if the result type of a function has a part that is a task, |
| 5567 |
then an attempt to return a local variable will raise Program_Error. |
| 5568 |
@Chg{Version=[2],New=[This is illegal in Ada 2005, see below. ], |
| 5569 |
Old=[]}In Ada 83, if a function returns a local variable containing a task, |
| 5570 |
execution is erroneous according to AI83-00867. However, |
| 5571 |
there are other situations where functions that return tasks |
| 5572 |
(or that return a variant record only one of whose variants |
| 5573 |
includes a task) |
| 5574 |
are correct in Ada 83 but will raise Program_Error according |
| 5575 |
to the new rules. |
| 5576 |
|
| 5577 |
The rule change was made because there will be more types (protected types, |
| 5578 |
limited controlled types) in Ada 95 for which |
| 5579 |
it will be meaningless to return a local variable, and making |
| 5580 |
all of these erroneous is unacceptable. |
| 5581 |
The current rule was felt to be the simplest that kept |
| 5582 |
upward incompatibilities to situations involving returning tasks, |
| 5583 |
which are quite rare. |
| 5584 |
@end{Incompatible83} |
| 5585 |
|
| 5586 |
@begin{DiffWord83} |
| 5587 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 5588 |
This @Chg{Version=[3],New=[subclause],Old=[clause]} has been moved here from |
| 5589 |
chapter 5, since it has mainly to do with subprograms. |
| 5590 |
|
| 5591 |
A function now creates an anonymous object. |
| 5592 |
This is necessary so that controlled types |
| 5593 |
will work. |
| 5594 |
|
| 5595 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 5596 |
We have clarified that a |
| 5597 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]} |
| 5598 |
applies to a callable construct, not to a callable entity. |
| 5599 |
|
| 5600 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 5601 |
There is no need to mention generics in the rules about where a |
| 5602 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]} |
| 5603 |
can appear and what it applies to; |
| 5604 |
the phrase @lquotes@;body of a subprogram or generic subprogram@rquotes@; is |
| 5605 |
syntactic, and refers exactly to @lquotes@;@nt{subprogram_body}@rquotes@;. |
| 5606 |
@end{DiffWord83} |
| 5607 |
|
| 5608 |
@begin{Inconsistent95} |
| 5609 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-0416-1]} |
| 5610 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0005-1],ARef=[AI05-0050-1]} |
| 5611 |
@ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95} |
| 5612 |
Added an @ImplPermName allowing early raising of Constraint_Error if the |
| 5613 |
result cannot fit in the ultimate object. This gives implementations more |
| 5614 |
flexibility to do built-in-place returns, and is essential for limited types |
| 5615 |
(which cannot be built in a temporary). However, it allows |
| 5616 |
raising @Chg{Version=[3],New=[],Old=[an ]} |
| 5617 |
Constraint_Error in some cases where it would not be raised if the |
| 5618 |
permission was not used. @Chg{Version=[3],New=[See @Inconsistent2005Title for |
| 5619 |
additional changes. ],Old=[]}This case is potentially inconsistent with Ada 95, but a compiler |
| 5620 |
does not have to take advantage of these permissions for any Ada 95 code, so |
| 5621 |
there should be little practical impact.]} |
| 5622 |
@end{Inconsistent95} |
| 5623 |
|
| 5624 |
@begin{Incompatible95} |
| 5625 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5626 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} The entire |
| 5627 |
business about return-by-reference types has been dropped. Instead, the |
| 5628 |
@nt{expression} of a return statement of a limited type can only be an |
| 5629 |
@nt{aggregate} or @nt{function_call} (see @RefSecNum{Limited Types}). This |
| 5630 |
means that returning a global object or @nt{type_conversion}, legal in Ada |
| 5631 |
95, is now illegal. Such functions can be converted to use anonymous access |
| 5632 |
return types by adding @key{access} in the function definition and return |
| 5633 |
statement, adding .@key{all} in uses, and adding @key{aliased} in the object |
| 5634 |
declarations. This has the advantage of making the reference return semantics |
| 5635 |
much clearer to the casual reader.]} |
| 5636 |
|
| 5637 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5638 |
@ChgAdded{Version=[2],Text=[We changed these rules so that functions, |
| 5639 |
combined with the new rules for limited types (@RefSecnum{Limited Types}), |
| 5640 |
can be used as build-in-place constructors for limited types. This reduces |
| 5641 |
the differences between limited and nonlimited types, which will |
| 5642 |
make limited types useful in more circumstances.]} |
| 5643 |
@end{Incompatible95} |
| 5644 |
|
| 5645 |
@begin{Extend95} |
| 5646 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5647 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 5648 |
The @nt{extended_return_statement} is new. This provides a name for |
| 5649 |
the object being returned, which reduces the copying needed to return |
| 5650 |
complex objects (including no copying at all for limited objects). It also |
| 5651 |
allows component-by-component construction of the return object.]} |
| 5652 |
@end{Extend95} |
| 5653 |
|
| 5654 |
@begin{DiffWord95} |
| 5655 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5656 |
@ChgAdded{Version=[2],Text=[The wording was updated to support anonymous |
| 5657 |
access return subtypes.]} |
| 5658 |
|
| 5659 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 5660 |
@ChgAdded{Version=[2],Text=[The term @lquotes@;return expression@rquotes@; |
| 5661 |
was dropped because reviewers found it confusing when applied to the default |
| 5662 |
@nt{expression} of an @nt{extended_return_statement}.]} |
| 5663 |
|
| 5664 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01],ARef=[AI95-00416-01]} |
| 5665 |
@ChgAdded{Version=[2],Text=[Added accessibility checks to class-wide |
| 5666 |
return statements. These checks could not fail in Ada 95 (as all of the |
| 5667 |
types had to be declared at the same level, so the tagged type would |
| 5668 |
necessarily have been at the same level as the type of the |
| 5669 |
object).]} |
| 5670 |
|
| 5671 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00402-01],ARef=[AI95-00416-01]} |
| 5672 |
@ChgAdded{Version=[2],Text=[Added accessibility checks to |
| 5673 |
return statements for types with access discriminants. Since such |
| 5674 |
types have to be limited in Ada 95, the @nt{expression} of a return statement |
| 5675 |
would have been illegal in order for this check to fail.]} |
| 5676 |
@end{DiffWord95} |
| 5677 |
|
| 5678 |
@begin{Inconsistent2005} |
| 5679 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 5680 |
@ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005} |
| 5681 |
@b<Correction:> The @ImplPermName allowing early raising of Constraint_Error was modified |
| 5682 |
to remove the most common of these cases from the permission (returning an |
| 5683 |
object with mutable discriminants, where the return object is created with |
| 5684 |
one set of discriminants and then changed to another). (The permission was |
| 5685 |
also widened to allow the early check for constrained functions when that |
| 5686 |
constraint is wrong.) However, there still is an unlikely case where the |
| 5687 |
permission would allow an exception to be raised when none would be raised by the canonical |
| 5688 |
semantics (when a return statement is abandoned). These changes can only |
| 5689 |
remove the raising of an exception (or change the place where it is raised) |
| 5690 |
compared to Ada 2005, so programs that depend on the previous behavior should |
| 5691 |
be very rare.]} |
| 5692 |
|
| 5693 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0051-1],ARef=[AI05-0234-1]} |
| 5694 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Accessibility checks for |
| 5695 |
access discriminants now depend on the master of the call rather than |
| 5696 |
the point of declaration of the function. This will result in cases |
| 5697 |
that used to raise Program_Error now running without raising any exception. |
| 5698 |
This is technically inconsistent with Ada 2005 (as defined by Amendment 1), |
| 5699 |
but it is unlikely that any real code depends on the raising of this |
| 5700 |
exception.]} |
| 5701 |
|
| 5702 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0073-1]} |
| 5703 |
@ChgAdded{Version=[3],Text=[@b<Correction:> |
| 5704 |
Added a tag check for functions returning anonymous access-to-tagged types, |
| 5705 |
so that dispatching of tag-indeterminate function works as expected. |
| 5706 |
This is technically inconsistent with Ada 2005 (as defined by Amendment 1), |
| 5707 |
but as the feature in question was newly added to Ada 2005, there should |
| 5708 |
be little code that depends on the behavior that now raises an exception.]} |
| 5709 |
@end{Inconsistent2005} |
| 5710 |
|
| 5711 |
@begin{Incompatible2005} |
| 5712 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0053-1],ARef=[AI05-0277-1]} |
| 5713 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:> |
| 5714 |
The @key{aliased} keyword can now only appear on extended return objects |
| 5715 |
with an immutably limited type. Other types would provide a way to get |
| 5716 |
an aliased view of an object that is not necessarily aliased, which would be |
| 5717 |
very bad. This is incompatible, but since the feature was added in |
| 5718 |
Ada 2005, the keyword had no defined meaning in Ada 2005 |
| 5719 |
(a significant oversight), and most sensible uses involve immutably limited |
| 5720 |
types, it is unlikely that it appears meaningfully in existing programs.]} |
| 5721 |
|
| 5722 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0103-1]} |
| 5723 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to require |
| 5724 |
static matching for unconstrained access types in extended return statements. |
| 5725 |
This disallows adding or omitting null exclusions, and adding access |
| 5726 |
constraints, in the declaration of the return object. While this is |
| 5727 |
incompatible, the incompatible cases in question are either useless (access |
| 5728 |
constraints @en the constraint can be given on an @nt{allocator} if necessary, |
| 5729 |
and still must be given there even if given on the return object) |
| 5730 |
or wrong (null exclusions @en null could be returned from a |
| 5731 |
function declared to be null excluding), so we expect them to be extremely |
| 5732 |
rare in practice.]} |
| 5733 |
@end{Incompatible2005} |
| 5734 |
|
| 5735 |
@begin{Extend2005} |
| 5736 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0015-1],ARef=[AI05-0144-2]} |
| 5737 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 5738 |
The return object of an @nt{extended_return_statement} can be declared |
| 5739 |
constant; this works similarly to a constant object declaration.]} |
| 5740 |
|
| 5741 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0032-1]} |
| 5742 |
@ChgAdded{Version=[3],Text=[Added wording to allow |
| 5743 |
the @nt{return_subtype_indication} to have a specific type if the return |
| 5744 |
subtype of the function is class-wide. Specifying the (specific) type of |
| 5745 |
the return object is awkward without this change, and this is consistent |
| 5746 |
with the way @nt{allocator}s work.]} |
| 5747 |
@end{Extend2005} |
| 5748 |
|
| 5749 |
@begin{DiffWord2005} |
| 5750 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0024-1]} |
| 5751 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the master check |
| 5752 |
for tags since the masters may be for different tasks and thus incomparable.]} |
| 5753 |
|
| 5754 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0058-1]} |
| 5755 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the wording |
| 5756 |
defining returns for @nt{extended_return_statement}s, since leaving by |
| 5757 |
an exit or goto is considered @ldquote@;normal@rdquote completion of the |
| 5758 |
statement.]} |
| 5759 |
|
| 5760 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0205-1],ARef=[AI05-0277-1]} |
| 5761 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Added the |
| 5762 |
@nt{extended_return_object_declaration} to make other rules easier to write |
| 5763 |
and eliminate the problem described in AI05-0205-1.]} |
| 5764 |
@end{DiffWord2005} |
| 5765 |
|
| 5766 |
@begin{Inconsistent2012} |
| 5767 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0343-1]} |
| 5768 |
@ChgAdded{Version=[5],Type=[Leading],Text=[@Defn{inconsistencies with Ada 2012}@b<Correction:> |
| 5769 |
Reordered the checks associated with return statements to clarify when |
| 5770 |
they happen relative to the @nt{sequence_of_statements} of an |
| 5771 |
@nt{extended_return_statement}, and to add an additional predicate check |
| 5772 |
on the returned value. This latter check can fail if the value to be |
| 5773 |
returned is changed in the statements of an extended return. Thus, the |
| 5774 |
following function now raises Assertion_Error, while no exception would be |
| 5775 |
raised in Ada 2012:]} |
| 5776 |
@begin{Example} |
| 5777 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 5778 |
@ChgAdded{Version=[5],Text=[@key[type] Rec @key[is record] |
| 5779 |
Count, Max : Natural; |
| 5780 |
@key[end record with] Dynamic_Predicate => Rec.Count <= Rec.Max;]} |
| 5781 |
|
| 5782 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 5783 |
@ChgAdded{Version=[5],Text=[@key[function] Foo @key[return] Rec @key[is] |
| 5784 |
@key[begin] |
| 5785 |
@key[return] Result : Rec := (Count => 5, Max => 10) @key[do] |
| 5786 |
Result.Max := 0; |
| 5787 |
@key[end return]; |
| 5788 |
@key[end] Foo;]} |
| 5789 |
@end{Example} |
| 5790 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 5791 |
@ChgAdded{Version=[5],Text=[This will detect a program bug (returning a |
| 5792 |
value that does not meet the predicate of the return subtype) rather than |
| 5793 |
leaving it hidden, so the inconsistency is tolerable.]} |
| 5794 |
@end{Inconsistent2012} |
| 5795 |
|
| 5796 |
@begin{DiffWord2012} |
| 5797 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0097-1]} |
| 5798 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the wording so that |
| 5799 |
it is clear where the tag of the return object comes from. While a literal |
| 5800 |
reading of the original Ada 2012 rule could have caused some weird results |
| 5801 |
(by using some nearby @nt{subtype_indication} to provide the tag in the |
| 5802 |
case of a @nt{simple_return_statement}, such a reading would be so unlike |
| 5803 |
the rest of the language that we do not believe anyone would ever have |
| 5804 |
thought it was intended. As such, we do not believe any implementation |
| 5805 |
ever did this wrong (at least because of the old wording), and thus do not |
| 5806 |
document this as a possible inconsistency.]} |
| 5807 |
|
| 5808 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0173-1]} |
| 5809 |
@ChgAdded{Version=[5],Text=[@b<Correction:> Added a definition of the |
| 5810 |
term @nt{expression} of an @nt{extended_return_statement}. That wording was |
| 5811 |
commonly used before the @nt{extended_return_object_declaration} was split |
| 5812 |
into a separate syntax production, leaving the @nt{extended_return_statement} |
| 5813 |
without any @nt{expression} of its own. Moreover, the wording often just |
| 5814 |
uses @lquotes@;@nt{expression} of a return statement@rquotes to cover both |
| 5815 |
kinds of return statement. Changing the wording in more than a |
| 5816 |
dozen places was unappealing, and some of the changes would be awkward to |
| 5817 |
read, so we defined the term and letf the majority of the wording unchanged.]} |
| 5818 |
@end{DiffWord2012} |
| 5819 |
|
| 5820 |
|
| 5821 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 5822 |
@LabeledRevisedSubClause{Version=[5],InitialVersion=[2],New=[Nonreturning Subprograms],Old=[Pragma No_Return]} |
| 5823 |
|
| 5824 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5825 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 5826 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0269-1]} |
| 5827 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Specifying aspect],Old=[A @nt{pragma}]} |
| 5828 |
No_Return @Chg{Version=[3],New=[to have the value True ],Old=[]}indicates |
| 5829 |
that a @Chg{Version=[5],New=[subprogram],Old=[procedure]} cannot return |
| 5830 |
normally@Redundant[; it may propagate an exception or loop forever].]} |
| 5831 |
@begin{Discussion} |
| 5832 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5833 |
@ChgRef{Version=[3],Kind=[Revised]} |
| 5834 |
@ChgRef{Version=[5],Kind=[Revised]} |
| 5835 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Aspect],Old=[@nt{Pragma}]} |
| 5836 |
No_Deposit@Defn{No_Deposit aspect} will have to wait for |
| 5837 |
Ada @Chg{Version=[3],New=[@Chg{Version=[5],New=[2028],Old=[2020]}],Old=[2017]}. :-)]} |
| 5838 |
@end{Discussion} |
| 5839 |
|
| 5840 |
@begin{NotIso} |
| 5841 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2 |
| 5842 |
and 3 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message |
| 5843 |
should be deleted if the paragraphs are ever renumbered.} |
| 5844 |
@end{NotIso} |
| 5845 |
|
| 5846 |
@begin{Syntax} |
| 5847 |
@begin{SyntaxText} |
| 5848 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5849 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 5850 |
@ChgAdded{Version=[2],Type=[Leading],Text=[@Chg{Version=[3],New=[],Old=[The form |
| 5851 |
of a @nt{pragma} No_Return, which is a |
| 5852 |
representation pragma (see @RefSecNum{Operational and Representation Aspects}), |
| 5853 |
is as follows:]}]} |
| 5854 |
@end{SyntaxText} |
| 5855 |
|
| 5856 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5857 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 5858 |
@DeletedPragmaSyn{Version=[3],InitialVersion=[2],@ChgAdded{Version=[2], |
| 5859 |
Text=`@Chg{Version=[3],New=[],Old=[@key{pragma} @prag<No_Return>(@SynI{procedure_}@Syn2{local_name}{, @SynI{procedure_}@Syn2{local_name}});]}'}} |
| 5860 |
@end{Syntax} |
| 5861 |
|
| 5862 |
@begin{StaticSem} |
| 5863 |
|
| 5864 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]} |
| 5865 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0269-1]} |
| 5866 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For a |
| 5867 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]} or generic |
| 5868 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]}, the following |
| 5869 |
language-defined representation aspect may be specified:]} |
| 5870 |
@begin{Description} |
| 5871 |
@ChgRef{Version=[3],Kind=[Added]} |
| 5872 |
@ChgAdded{Version=[3],Text=[No_Return@\The type of aspect No_Return is Boolean. |
| 5873 |
When aspect No_Return is True for an entity, the entity is said to be |
| 5874 |
@i<nonreturning>.@Defn{nonreturning}@AspectDefn{No_Return}]} |
| 5875 |
|
| 5876 |
@ChgRef{Version=[3],Kind=[Added]} |
| 5877 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[If directly specified, the |
| 5878 |
@nt{aspect_definition} shall be a static expression. @Redundant[This aspect is |
| 5879 |
never inherited;] if not directly specified, the aspect is False.]} |
| 5880 |
|
| 5881 |
@ChgAspectDesc{Version=[5],Kind=[Revised],Aspect=[No_Return], |
| 5882 |
InitialVersion=[3],Text=[@ChgAdded{Version=[3],Text=[A |
| 5883 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]} |
| 5884 |
will not return normally.]}]} |
| 5885 |
@end{Description} |
| 5886 |
|
| 5887 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}@ChgNote{Moved from below} |
| 5888 |
@ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0269-1]} |
| 5889 |
@ChgAdded{Version=[3],Text=[If a generic |
| 5890 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]} is nonreturning, then so are |
| 5891 |
its instances. If a @Chg{Version=[5],New=[subprogram],Old=[procedure]} declared |
| 5892 |
within a generic unit is nonreturning, |
| 5893 |
then so are the corresponding copies of that |
| 5894 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]} in instances.]} |
| 5895 |
|
| 5896 |
@end{StaticSem} |
| 5897 |
|
| 5898 |
|
| 5899 |
@begin{Legality} |
| 5900 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5901 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 5902 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Aspect No_Return], |
| 5903 |
Old=[@Defn{nonreturning}Each @SynI{procedure_}@nt{local_name} shall denote one |
| 5904 |
or more procedures or generic procedures; the denoted entities are |
| 5905 |
@i<nonreturning>. The @SynI{procedure_}@nt{local_name}]} shall not |
| 5906 |
@Chg{Version=[3],New=[be specified for],Old=[denote]} a |
| 5907 |
null procedure nor an instance of a generic unit.]} |
| 5908 |
|
| 5909 |
@begin{Reason} |
| 5910 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5911 |
@ChgAdded{Version=[2],Text=[A null procedure cannot have the appropriate |
| 5912 |
nonreturning semantics, as it does not raise an exception or loop forever.]} |
| 5913 |
@end{Reason} |
| 5914 |
|
| 5915 |
@begin{Ramification} |
| 5916 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5917 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 5918 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0269-1]} |
| 5919 |
@ChgAdded{Version=[2],Text=[The procedure can be abstract.@Chg{Version=[3],New=[], |
| 5920 |
Old=[ The denoted declaration can be a @nt{renaming_declaration} if it obeys the usual rules |
| 5921 |
for representation pragmas: the renaming has to occur immediately within the |
| 5922 |
same declarative region as the renamed subprogram.]} If a nonreturning |
| 5923 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]} is renamed (anywhere) calls |
| 5924 |
through the new name still have the nonreturning semantics.]} |
| 5925 |
@end{Ramification} |
| 5926 |
|
| 5927 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5928 |
@ChgAdded{Version=[2],Text=[A return statement shall not apply to a |
| 5929 |
nonreturning procedure or generic procedure.]} |
| 5930 |
|
| 5931 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0269-1]} |
| 5932 |
@ChgAdded{Version=[5],Text=[Any return statement that applies to a nonreturning |
| 5933 |
function or generic function shall be a @nt{simple_return_statement} with an |
| 5934 |
@nt{expression} that is a @nt{raise_expression}, a call on a nonreturning |
| 5935 |
function, or a parenthesized @nt{expression} of one of these.]} |
| 5936 |
|
| 5937 |
@begin{Ramification} |
| 5938 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 5939 |
@ChgAdded{Version=[5],Text=[We still require at least one return statement in |
| 5940 |
a function; we just require that all such return statements don't actually |
| 5941 |
return a value.]} |
| 5942 |
@end{Ramification} |
| 5943 |
|
| 5944 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 5945 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0269-1]} |
| 5946 |
@ChgAdded{Version=[2],Text=[A @Chg{Version=[5],New=[subprogram],Old=[procedure]} |
| 5947 |
shall be nonreturning if it overrides a dispatching nonreturning |
| 5948 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]}. |
| 5949 |
@PDefn{generic contract issue} |
| 5950 |
In addition to the places where |
| 5951 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 5952 |
this rule applies also in the private part of an instance of a generic unit.]} |
| 5953 |
|
| 5954 |
@begin{Reason} |
| 5955 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5956 |
@ChgRef{Version=[5],Kind=[Revised]} |
| 5957 |
@ChgAdded{Version=[2],Text=[This ensures that dispatching calls to |
| 5958 |
nonreturning @Chg{Version=[5],New=[subprograms],Old=[procedures]} will, in |
| 5959 |
fact, not return.]} |
| 5960 |
@end{Reason} |
| 5961 |
|
| 5962 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 5963 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0269-1]} |
| 5964 |
@ChgAdded{Version=[2],Text=[If a renaming-as-body completes a nonreturning |
| 5965 |
@Chg{Version=[5],New=[subprogram],Old=[procedure]} declaration, then the |
| 5966 |
renamed @Chg{Version=[5],New=[subprogram],Old=[procedure]} shall be |
| 5967 |
nonreturning.]} |
| 5968 |
|
| 5969 |
@begin{Reason} |
| 5970 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5971 |
@ChgAdded{Version=[2],Text=[This ensures that no extra code is needed to |
| 5972 |
implement the renames (that is, no wrapper is needed) as the body has |
| 5973 |
the same property.]} |
| 5974 |
@end{Reason} |
| 5975 |
|
| 5976 |
@end{Legality} |
| 5977 |
|
| 5978 |
@begin{NotIso} |
| 5979 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 8 |
| 5980 |
was deleted.>}]}@Comment{This message should be deleted if the paragraphs |
| 5981 |
are ever renumbered.}@ChgNote{This special message is needed to get rid of |
| 5982 |
the old, now unused, subheader} |
| 5983 |
@end{NotIso} |
| 5984 |
|
| 5985 |
@begin{StaticSem} |
| 5986 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5987 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 5988 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[If a generic procedure |
| 5989 |
is nonreturning, then so are its instances. If a procedure declared within |
| 5990 |
a generic unit is nonreturning, then so are the corresponding copies of |
| 5991 |
that procedure in instances.]}]} |
| 5992 |
@end{StaticSem} |
| 5993 |
|
| 5994 |
@begin{RunTime} |
| 5995 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5996 |
@ChgAdded{Version=[2],Text=[If the body of a nonreturning procedure completes |
| 5997 |
normally, Program_Error is raised at the point of the call. |
| 5998 |
@Defn2{Term=[Program_Error],Sec=(raised by a nonreturning procedure)}]} |
| 5999 |
@end{RunTime} |
| 6000 |
@begin{Discussion} |
| 6001 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6002 |
@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0269-1]} |
| 6003 |
@ChgAdded{Version=[2],Text=[Note that there is no name for suppressing |
| 6004 |
this check, since the check represents a bug, imposes no time overhead, |
| 6005 |
and minimal space overhead (since it can usually be statically eliminated |
| 6006 |
as dead code).@Chg{Version=[5],New=[ We don't need a similar rule for |
| 6007 |
nonreturning functions as this is standard semantics for all functions |
| 6008 |
that normally complete without a transfer of control (such as a return |
| 6009 |
statement).],Old=[]}]} |
| 6010 |
@end{Discussion} |
| 6011 |
@begin{ImplNote} |
| 6012 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6013 |
@ChgAdded{Version=[2],Text=[If a nonreturning procedure tries to return, we |
| 6014 |
raise Program_Error. This is stated as happening at the call site, because we |
| 6015 |
do not wish to allow the procedure to handle the exception (and then, |
| 6016 |
perhaps, try to return again!). However, the expected run-time model is that |
| 6017 |
the compiler will generate @key{raise} Program_Error at the end of the |
| 6018 |
procedure body (but not handleable by the procedure itself), as opposed to |
| 6019 |
doing it at the call site. (This is just like the typical run-time model for |
| 6020 |
functions that fall off the end without returning a value). The reason is |
| 6021 |
indirect calls: in P.@key{all}(...);, the compiler cannot know whether P |
| 6022 |
designates a nonreturning procedure or a normal one. Putting the @key{raise} |
| 6023 |
Program_Error in the procedure's generated code solves this problem neatly.]} |
| 6024 |
|
| 6025 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6026 |
@ChgAdded{Version=[2],Text=[Similarly, if one passes a nonreturning |
| 6027 |
procedure to a generic formal parameter, the compiler cannot know this at |
| 6028 |
call sites (in shared code implementations); the raise-in-body solution |
| 6029 |
deals with this neatly.]} |
| 6030 |
@end{ImplNote} |
| 6031 |
|
| 6032 |
@begin{Examples} |
| 6033 |
@begin{Example} |
| 6034 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 6035 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 6036 |
@ChgAdded{Version=[2],Text=[@key(procedure) Fail(Msg : String)@Chg{Version=[3],New=[],Old=[;]} --@ExamCom[ raises Fatal_Error exception] |
| 6037 |
@Chg{Version=[3],New=[ @key(with)],Old=[@key(pragma)]} No_Return@Chg{Version=[3],New=[],Old=[(Fail)]}; |
| 6038 |
--@ExamCom[ Inform compiler and reader that procedure never returns normally]]} |
| 6039 |
@end{Example} |
| 6040 |
@end{Examples} |
| 6041 |
|
| 6042 |
@begin{Extend95} |
| 6043 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 6044 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 6045 |
@nt{Pragma} No_Return is new.]} |
| 6046 |
@end{Extend95} |
| 6047 |
|
| 6048 |
@begin{Extend2005} |
| 6049 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 6050 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 6051 |
Aspect No_Return is new; @nt{pragma} No_Return is now obsolescent.]} |
| 6052 |
@end{Extend2005} |
| 6053 |
|
| 6054 |
@begin{Extend2012} |
| 6055 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0269-1]} |
| 6056 |
@ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012} |
| 6057 |
Aspect No_Return can now be applied to functions as well as procedures.]} |
| 6058 |
@end{Extend2012} |
| 6059 |
|
| 6060 |
|
| 6061 |
|
| 6062 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 6063 |
@LabeledClause{Overloading of Operators} |
| 6064 |
|
| 6065 |
@begin{Intro} |
| 6066 |
@Defn{operator} |
| 6067 |
@Defn{user-defined operator} |
| 6068 |
@Defn2{Term=[operator], Sec=(user-defined)} |
| 6069 |
An @i{operator} is a function whose @nt{designator} is an |
| 6070 |
@nt<operator_symbol>. |
| 6071 |
@Redundant[Operators, like other functions, may be overloaded.] |
| 6072 |
@end{Intro} |
| 6073 |
|
| 6074 |
@begin{Resolution} |
| 6075 |
Each use of a unary or binary operator is equivalent to a |
| 6076 |
@nt{function_call} with @SynI{function_}@nt{prefix} being the |
| 6077 |
corresponding @nt{operator_symbol}, and with (respectively) one or |
| 6078 |
two positional actual parameters being the operand(s) of the operator |
| 6079 |
(in order). |
| 6080 |
@begin{Honest} |
| 6081 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 6082 |
We also use the term operator |
| 6083 |
(in @Chg{Version=[3],New=[Clause],Old=[Section]} 4 and in |
| 6084 |
@RefSecNum{Subprogram Declarations}) |
| 6085 |
to refer to one of the syntactic categories |
| 6086 |
defined in @RefSec{Operators and Expression Evaluation} |
| 6087 |
whose names end with @lquotes@;_operator:@rquotes@; |
| 6088 |
@nt<logical_@!operator>, |
| 6089 |
@nt<relational_@!operator>, |
| 6090 |
@nt<binary_@!adding_@!operator>, |
| 6091 |
@nt<unary_@!adding_@!operator>, |
| 6092 |
@nt<multiplying_@!operator>, and |
| 6093 |
@nt<highest_@!precedence_@!operator>. |
| 6094 |
@end{Honest} |
| 6095 |
@begin{Discussion} |
| 6096 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]} |
| 6097 |
@ChgAdded{Version=[3],Text=[This equivalence extends to uses of |
| 6098 |
@nt{function_call} in most other language rules. However, as |
| 6099 |
often happens, the equivalence is not perfect, as operator |
| 6100 |
calls are not a @nt{name}, while a @nt{function_call} is a |
| 6101 |
@nt{name}. Thus, operator calls cannot be used in contexts |
| 6102 |
that require a @nt{name} (such as a rename of an object). |
| 6103 |
A direct fix for this problem would be very disruptive, and thus |
| 6104 |
we have not done that. However, qualifying an operator call |
| 6105 |
can be used as a workaround in contexts that require a @nt{name}.]} |
| 6106 |
@end{Discussion} |
| 6107 |
@end{Resolution} |
| 6108 |
|
| 6109 |
@begin{Legality} |
| 6110 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0143-1]} |
| 6111 |
The @nt{subprogram_specification} of a unary or binary operator shall have |
| 6112 |
one or two parameters, respectively.@Chg{Version=[3],New=[ The parameters |
| 6113 |
shall be of mode @key[in].],Old=[]} |
| 6114 |
A generic function instantiation whose @nt{designator} is an |
| 6115 |
@nt{operator_symbol} is only allowed if the specification of the |
| 6116 |
generic function has the corresponding number of |
| 6117 |
parameters@Chg{Version=[3],New=[, and they are all of mode @key[in]],Old=[]}. |
| 6118 |
|
| 6119 |
@nt{Default_expression}s are not allowed for the parameters of an operator |
| 6120 |
(whether the operator is declared with an explicit |
| 6121 |
@nt{subprogram_specification} or by a @nt{generic_instantiation}). |
| 6122 |
|
| 6123 |
An explicit declaration of "/=" shall not have a result |
| 6124 |
type of the predefined type Boolean. |
| 6125 |
@end{Legality} |
| 6126 |
|
| 6127 |
@begin{StaticSem} |
| 6128 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0128-1]} |
| 6129 |
@Chg{Version=[3],New=[An explicit],Old=[A]} declaration of "=" |
| 6130 |
whose result type is Boolean implicitly declares |
| 6131 |
@Chg{Version=[3],New=[an operator],Old=[a declaration of]} "/=" that |
| 6132 |
gives the complementary result.@Defn{/= operator} |
| 6133 |
@begin{Discussion} |
| 6134 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0128-1]} |
| 6135 |
@ChgAdded{Version=[3],Text=[A "/=" defined by this rule is considered |
| 6136 |
user-defined, which means that it will be inherited by a derived type. |
| 6137 |
@ldquote@;User-defined@rdquote means @ldquote@;not language-defined@rdquote for |
| 6138 |
the purposes of inheritance, that is anything other than predefined operators. |
| 6139 |
@Defn{Number of the Beast}@Comment{This is 6.6(6) :-)}]} |
| 6140 |
@end{Discussion} |
| 6141 |
@end{StaticSem} |
| 6142 |
|
| 6143 |
@begin{Notes} |
| 6144 |
The operators "+" and "@en@;" are both unary and binary operators, |
| 6145 |
and hence may be overloaded with both one- and two-parameter functions. |
| 6146 |
@end{Notes} |
| 6147 |
|
| 6148 |
@begin{Examples} |
| 6149 |
@leading@keepnext@i{Examples of user-defined operators:} |
| 6150 |
@begin{Example} |
| 6151 |
@key[function] "+" (Left, Right : Matrix) @key[return] Matrix; |
| 6152 |
@key[function] "+" (Left, Right : Vector) @key[return] Vector; |
| 6153 |
@Comment{Blank line} |
| 6154 |
--@ExamCom{ assuming that A, B, and C are of the type Vector} |
| 6155 |
--@ExamCom{ the following two statements are equivalent:} |
| 6156 |
@Comment{Blank line} |
| 6157 |
A := B + C; |
| 6158 |
A := "+"(B, C); |
| 6159 |
@end{Example} |
| 6160 |
@end{Examples} |
| 6161 |
|
| 6162 |
@begin{Extend83} |
| 6163 |
@Defn{extensions to Ada 83} |
| 6164 |
Explicit declarations of "=" are now permitted for any |
| 6165 |
combination of parameter and result types. |
| 6166 |
|
| 6167 |
Explicit declarations of "/=" are now permitted, so long |
| 6168 |
as the result type is not Boolean. |
| 6169 |
@end{Extend83} |
| 6170 |
|
| 6171 |
@begin{DiffWord2005} |
| 6172 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0128-1]} |
| 6173 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the wording |
| 6174 |
so that only explicit declarations of "=" cause an implicit declaration |
| 6175 |
of "/="; otherwise, we could get multiple implicit definitions of "/=" |
| 6176 |
without an obvious way to chose between them.]} |
| 6177 |
|
| 6178 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0143-1]} |
| 6179 |
@ChgAdded{Version=[3],Text=[Added wording so that operators only allow |
| 6180 |
parameters of mode @key[in]. This was made necessary by the elimination |
| 6181 |
elsewhere of the restriction that function parameters be only of |
| 6182 |
mode @key[in].]} |
| 6183 |
@end{DiffWord2005} |
| 6184 |
|
| 6185 |
|
| 6186 |
@RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM} |
| 6187 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 6188 |
@LabeledAddedClause{Version=[2],Name=[Null Procedures]} |
| 6189 |
|
| 6190 |
@begin{Intro} |
| 6191 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 6192 |
@ChgAdded{Version=[2],Text=[A @nt<null_procedure_declaration> provides a shorthand |
| 6193 |
to declare a procedure with an empty body.]} |
| 6194 |
@end{Intro} |
| 6195 |
|
| 6196 |
@begin{Syntax} |
| 6197 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 6198 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]} |
| 6199 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<null_procedure_declaration>,Old=<>}>, |
| 6200 |
rhs="@Chg{Version=[2],New=< |
| 6201 |
[@Syn2{overriding_indicator}] |
| 6202 |
@Syn2{procedure_specification} @key{is} @key{null}@Chg{Version=[3],New=< |
| 6203 |
[@Syn2{aspect_specification}]>,Old=[]};>,Old=<>}"} |
| 6204 |
@end{Syntax} |
| 6205 |
|
| 6206 |
@begin{Legality} |
| 6207 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0177-1]} |
| 6208 |
@ChgAdded{Version=[3],Text=[If a @nt{null_procedure_declaration} is a completion, |
| 6209 |
it shall be the completion of a @nt{subprogram_declaration} or |
| 6210 |
@nt{generic_subprogram_declaration}. The profile of a |
| 6211 |
@nt{null_procedure_declaration} that completes a declaration shall |
| 6212 |
conform fully to that of the declaration.@Defn2{Term=[full conformance],Sec=(required)}]} |
| 6213 |
@end{Legality} |
| 6214 |
|
| 6215 |
@begin{StaticSem} |
| 6216 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 6217 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1],ARef=[AI05-0264-1]} |
| 6218 |
@ChgAdded{Version=[2],Text=[A @nt<null_procedure_declaration> declares a @i<null |
| 6219 |
procedure>.@Defn{null procedure}@Defn2{Term=[procedure],Sec=[null]} |
| 6220 |
A completion is not allowed for a @nt<null_procedure_declaration>@Chg{Version=[3],New=[; |
| 6221 |
however, a @nt{null_procedure_declaration} can complete a previous declaration],Old=[]}.]} |
| 6222 |
@begin{Reason} |
| 6223 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6224 |
@ChgAdded{Version=[2],Text=[There are no null functions because the return |
| 6225 |
value has to be constructed somehow; a function that always raises |
| 6226 |
Program_Error doesn't seem very useful or worth the complication.]} |
| 6227 |
@end{Reason} |
| 6228 |
@end{StaticSem} |
| 6229 |
|
| 6230 |
@begin{RunTime} |
| 6231 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 6232 |
@ChgAdded{Version=[2],Text=[The execution of a null procedure is invoked by a subprogram call. |
| 6233 |
For the execution of a subprogram call on a null procedure, the execution of |
| 6234 |
the @nt<subprogram_body> has no effect.]} |
| 6235 |
@begin{Ramification} |
| 6236 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6237 |
@ChgAdded{Version=[2],Text=[Thus, a null procedure is equivalent to the body]} |
| 6238 |
@begin{Example} |
| 6239 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6240 |
@ChgAdded{Version=[2],Text=[@key{begin} |
| 6241 |
@key{null}; |
| 6242 |
@key{end};]} |
| 6243 |
@end{Example} |
| 6244 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 6245 |
@ChgAdded{Version=[2],Text=[with the exception that a null procedure can be used in |
| 6246 |
place of a procedure specification.]} |
| 6247 |
@end{Ramification} |
| 6248 |
|
| 6249 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 6250 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]} |
| 6251 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[elaboration], Sec=(null_procedure_declaration)} |
| 6252 |
The elaboration of a @nt{null_procedure_declaration} has no |
| 6253 |
@Chg{Version=[3],New=[other ],Old=[]}effect@Chg{Version=[3],New=[ than to |
| 6254 |
establish that the null procedure can be called without failing the |
| 6255 |
Elaboration_Check],Old=[]}.]} |
| 6256 |
@end{RunTime} |
| 6257 |
|
| 6258 |
@begin{Examples} |
| 6259 |
@begin{Example} |
| 6260 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 6261 |
@ChgAdded{Version=[2],Text=[@key(procedure) Simplify(Expr : @key(in out) Expression) @key(is null); --@ExamCom[ see @RefSecNum{Tagged Types and Type Extensions}] |
| 6262 |
--@ExamCom[ By default, Simplify does nothing, but it may be overridden in extensions of Expression]]} |
| 6263 |
@end{Example} |
| 6264 |
@end{Examples} |
| 6265 |
|
| 6266 |
@begin{Extend95} |
| 6267 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 6268 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 6269 |
Null procedures are new.]} |
| 6270 |
@end{Extend95} |
| 6271 |
|
| 6272 |
@begin{Extend2005} |
| 6273 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6274 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 6275 |
A @nt{null_procedure_declaration} can now be a completion.]} |
| 6276 |
|
| 6277 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 6278 |
@ChgAdded{Version=[3],Text=[An optional @nt{aspect_specification} |
| 6279 |
can be used in a @nt{null_procedure_declaration}. |
| 6280 |
This is described in @RefSecNum{Aspect Specifications}.]} |
| 6281 |
@end{Extend2005} |
| 6282 |
|
| 6283 |
|
| 6284 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 6285 |
@LabeledAddedClause{Version=[3],Name=[Expression Functions]} |
| 6286 |
|
| 6287 |
@begin{Intro} |
| 6288 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6289 |
@ChgAdded{Version=[3],Text=[An @nt{expression_function_declaration} provides a |
| 6290 |
shorthand to declare a function whose body consists of a single return |
| 6291 |
statement.]} |
| 6292 |
@end{Intro} |
| 6293 |
|
| 6294 |
@begin{Syntax} |
| 6295 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0177-1]} |
| 6296 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]} |
| 6297 |
@AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<expression_function_declaration>,Old=<>}>, |
| 6298 |
rhs="@Chg{Version=[3],New=< |
| 6299 |
[@Syn2{overriding_indicator}] |
| 6300 |
@Syn2{function_specification} @key{is} |
| 6301 |
(@Syn2{expression}) |
| 6302 |
[@Syn2{aspect_specification}];@Chg{Version=[4],New=< |
| 6303 |
| [@Syn2{overriding_indicator}] |
| 6304 |
@Syn2{function_specification} @key{is} |
| 6305 |
@Syn2{aggregate} |
| 6306 |
[@Syn2{aspect_specification}];>,Old=<>}>,Old=<>}"} |
| 6307 |
@end{Syntax} |
| 6308 |
|
| 6309 |
@begin{Resolution} |
| 6310 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6311 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]} |
| 6312 |
@ChgAdded{Version=[3],Text=[The expected type for the @nt{expression} |
| 6313 |
@Chg{Version=[4],New=[or @nt{aggregate} ],Old=[]}of an |
| 6314 |
@nt{expression_@!function_@!declaration} is the result type (see |
| 6315 |
@RefSecNum{Return Statements}) of the function.@PDefn2{Term=[expected type], |
| 6316 |
Sec=(expression of expression function)}]} |
| 6317 |
@end{Resolution} |
| 6318 |
|
| 6319 |
@begin{StaticSem} |
| 6320 |
|
| 6321 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0177-1],ARef=[AI05-0264-1],ARef=[AI12-0157-1],ARef=[AI12-0075-1]} |
| 6322 |
@ChgAdded{Version=[5],Text=[An @nt{expression_@!function_@!declaration} declares |
| 6323 |
an @i{expression function}.@Defn{expression function}@Defn2{Term=[function],Sec=[expression]} |
| 6324 |
The @i<return expression>@Defn2{Term=[return expression],Sec=[of expression function]} |
| 6325 |
of an expression function is the @nt{expression} or @nt{aggregate} of the |
| 6326 |
@nt{expression_function_declaration}. A completion |
| 6327 |
is not allowed for an @nt{expression_@!function_@!declaration}; however, an |
| 6328 |
@nt{expression_@!function_@!declaration} can complete a previous declaration.]} |
| 6329 |
|
| 6330 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0075-1]} |
| 6331 |
@ChgAdded{Version=[5],Type=[Leading],Text=[A @i<potentially static expression> |
| 6332 |
is defined in the same way as a static expression except |
| 6333 |
that@Defn{potentially static expression}]} |
| 6334 |
|
| 6335 |
@begin{Itemize} |
| 6336 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6337 |
@ChgAdded{Version=[5],Text=[a name denoting a formal parameter of an |
| 6338 |
expression function is a potentially static expression; and]} |
| 6339 |
|
| 6340 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6341 |
@ChgAdded{Version=[5],Text=[each use of @ldquote@;static expression@rdquote |
| 6342 |
in the definition of @ldquote@;static expression@rdquote is replaced with |
| 6343 |
a corresponding use of @ldquote@;potentially static expression@rdquote |
| 6344 |
in the definition of @ldquote@;potentially static expression@rdquote.]} |
| 6345 |
@end{Itemize} |
| 6346 |
|
| 6347 |
@begin{Discussion} |
| 6348 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 6349 |
@ChgAdded{Version=[5],Text=[These uses occur in the definition of |
| 6350 |
@ldquote@;static expression@rdquote in the cases of function calls, type |
| 6351 |
conversions, qualified expressions, membership tests, short circuit control |
| 6352 |
forms, conditional expressions, and parenthesized expressions.]} |
| 6353 |
@end{Discussion} |
| 6354 |
|
| 6355 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0075-1]} |
| 6356 |
@ChgAdded{Version=[5],Type=[Leading],Text=[The following language-defined |
| 6357 |
representation aspect may be specified for an expression function:]} |
| 6358 |
|
| 6359 |
@begin{Description} |
| 6360 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6361 |
@ChgAdded{Version=[5],Text=[Static@\The type of aspect Static is Boolean. When |
| 6362 |
aspect Static is True for an expression function, the function is a @i<static |
| 6363 |
expression function>. If directly specified, the @nt{aspect_definition} shall |
| 6364 |
be a static@AspectDefn{Static} |
| 6365 |
expression.@Defn{static expression function}@Defn2{Term=[expression function],Sec=(static)}]} |
| 6366 |
|
| 6367 |
@ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Static], |
| 6368 |
Text=[@ChgAdded{Version=[5],Text=[Specifies that an associated expression |
| 6369 |
function can be used in static expressions.]}]} |
| 6370 |
|
| 6371 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6372 |
@ChgAdded{Version=[5],Text=[@\The Static value for an inherited function is True |
| 6373 |
if some corresponding primitive function of the parent or progenitor type is a |
| 6374 |
static expression function; otherwise, if not directly specified, the aspect is |
| 6375 |
False.]} |
| 6376 |
@end{Description} |
| 6377 |
|
| 6378 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0075-1]} |
| 6379 |
@ChgAdded{Version=[5],Text=[@Redundant[A static expression function is a static |
| 6380 |
function; see @RefSecNum{Static Expressions and Static Subtypes}.]]} |
| 6381 |
@end{StaticSem} |
| 6382 |
|
| 6383 |
|
| 6384 |
@begin{Legality} |
| 6385 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6386 |
@ChgAdded{Version=[3],Text=[If an @nt{expression_@!function_@!declaration} is a |
| 6387 |
completion, it shall be the completion of a @nt{subprogram_declaration} or |
| 6388 |
@nt{generic_subprogram_declaration}. The profile of an |
| 6389 |
@nt{expression_@!function_@!declaration} that completes a declaration |
| 6390 |
shall conform fully to that of the declaration.@Defn2{Term=[full conformance],Sec=(required)}]} |
| 6391 |
|
| 6392 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6393 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]} |
| 6394 |
@ChgAdded{Version=[3],Text=[If the result subtype has one or more unconstrained |
| 6395 |
access discriminants, the accessibility level of the anonymous access type of |
| 6396 |
each access discriminant, as determined by the @nt{expression} |
| 6397 |
@Chg{Version=[4],New=[or @nt{aggregate} ],Old=[]}of the |
| 6398 |
@Chg{Version=[4],New=[@nt{expression_@!function_@!declaration}],Old=[expression |
| 6399 |
function]}, shall not be statically deeper than that of the master that |
| 6400 |
elaborated the @nt{expression_@!function_@!declaration}.]} |
| 6401 |
|
| 6402 |
@begin{Ramification} |
| 6403 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 6404 |
@ChgAdded{Version=[3],Text=[This can only fail if the discriminant is an |
| 6405 |
access to a part of a nonaliased parameter, as there can be no local |
| 6406 |
declarations here.]} |
| 6407 |
@end{Ramification} |
| 6408 |
|
| 6409 |
@begin{Discussion} |
| 6410 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 6411 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]} |
| 6412 |
@ChgAdded{Version=[3],Text=[We don't need to repeat any of the other |
| 6413 |
@LegalityTitle for return statements since none of them can fail here: the |
| 6414 |
implicit return statement has to apply to this function (and isn't nested in |
| 6415 |
something), there clearly is a return statement in this function, and the |
| 6416 |
static @Chg{Version=[4],New=[class-wide],Old=[classwide]} accessibility check |
| 6417 |
cannot fail as a tagged type cannot be |
| 6418 |
declared locally in an expression function.]} |
| 6419 |
@end{Discussion} |
| 6420 |
|
| 6421 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0075-1]} |
| 6422 |
@ChgAdded{Version=[5],Type=[Leading],Text=[Aspect Static shall be specified |
| 6423 |
to have the value True only if the associated |
| 6424 |
@nt{expression_@!function_@!declaration}:]} |
| 6425 |
|
| 6426 |
@begin{Itemize} |
| 6427 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6428 |
@ChgAdded{Version=[5],Text=[is not a completion;]} |
| 6429 |
|
| 6430 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6431 |
@ChgAdded{Version=[5],Text=[has an @nt{expression} that is a potentially |
| 6432 |
static expression;]} |
| 6433 |
|
| 6434 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6435 |
@ChgAdded{Version=[5],Text=[contains no calls to itself;]} |
| 6436 |
|
| 6437 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6438 |
@ChgAdded{Version=[5],Text=[each parameter (if any) is of mode @key[in] |
| 6439 |
and is of a static subtype;]} |
| 6440 |
|
| 6441 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6442 |
@ChgAdded{Version=[5],Text=[has a result subtype that is a static subtype;]} |
| 6443 |
|
| 6444 |
@ChgRef{Version=[5],Kind=[Added]} |
| 6445 |
@ChgAdded{Version=[5],Text=[has no applicable precondition or postcondition |
| 6446 |
expression; and]} |
| 6447 |
|
| 6448 |
@ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0075-1],ARef=[AI12-0191-1]} |
| 6449 |
@ChgAdded{Version=[5],Text=[for result type @i<R>, if the function is a |
| 6450 |
boundary entity for type @i<R> (see @RefSecNum{Type Invariants}), no type |
| 6451 |
invariant applies to type @i<R>; if @i<R> has a component type @i<C>, a |
| 6452 |
similar rule applies to @i<C>.]} |
| 6453 |
@end{Itemize} |
| 6454 |
|
| 6455 |
@begin{Ramification} |
| 6456 |
@ChgRef{Version=[5],Kind=[AddedNormal]} |
| 6457 |
@ChgAdded{Version=[5],Text=[Since a string subtype can be static, |
| 6458 |
this allows an expression function of a string type to be static.]} |
| 6459 |
@end{Ramification} |
| 6460 |
|
| 6461 |
@end{Legality} |
| 6462 |
|
| 6463 |
@begin{NotIso} |
| 6464 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 6 |
| 6465 |
was deleted.>}]}@Comment{This message should be deleted if the paragraphs |
| 6466 |
are ever renumbered.}@ChgNote{This special message is needed to get rid of |
| 6467 |
the old, now unused, subheader} |
| 6468 |
@end{NotIso} |
| 6469 |
@begin{StaticSem} |
| 6470 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1],ARef=[AI05-0264-1]} |
| 6471 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]} |
| 6472 |
@ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0075-1]} |
| 6473 |
@ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[An |
| 6474 |
@nt{expression_@!function_@!declaration} declares an @i{expression |
| 6475 |
function}.@Defn{expression function}@Defn2{Term=[function],Sec=[expression]} |
| 6476 |
@Chg{Version=[4],New=[The @i<return expression>@Defn2{Term=[return expression],Sec=[of expression function]} |
| 6477 |
of an expression function is the @nt{expression} or @nt{aggregate} of the |
| 6478 |
@nt{expression_function_declaration}. ],Old=[]}A completion |
| 6479 |
is not allowed for an @nt{expression_@!function_@!declaration}; however, an |
| 6480 |
@nt{expression_@!function_@!declaration} can complete a previous declaration.]}]} |
| 6481 |
@end{StaticSem} |
| 6482 |
|
| 6483 |
@begin{RunTime} |
| 6484 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1],ARef=[AI05-0262-1]} |
| 6485 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0157-1]} |
| 6486 |
@ChgAdded{Version=[3],Text=[ The execution of an expression function is invoked |
| 6487 |
by a subprogram call. For the execution of a subprogram call on an expression |
| 6488 |
function, the execution of the @nt{subprogram_body} executes an implicit |
| 6489 |
function body containing only a @nt{simple_return_statement} whose |
| 6490 |
@nt{expression} is @Chg{Version=[4],New=[the return expression],Old=[that]} |
| 6491 |
of the expression function.]} |
| 6492 |
|
| 6493 |
@begin{Discussion} |
| 6494 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 6495 |
@ChgAdded{Version=[3],Text=[The last sentence effectively means that all of |
| 6496 |
the dynamic wording in @RefSecNum{Return Statements} applies as needed, and we |
| 6497 |
don't have to repeat it here.]} |
| 6498 |
@end{Discussion} |
| 6499 |
|
| 6500 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6501 |
@ChgAdded{Version=[3],Text=[@PDefn2{Term=[elaboration], |
| 6502 |
Sec=(expression_function_declaration)}The elaboration of an |
| 6503 |
@nt{expression_@!function_@!declaration} has no other effect than to establish |
| 6504 |
that the expression function can be called without failing the |
| 6505 |
Elaboration_Check.]} |
| 6506 |
@end{RunTime} |
| 6507 |
|
| 6508 |
@begin{Examples} |
| 6509 |
@begin{Example} |
| 6510 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6511 |
@ChgAdded{Version=[3],Text=[@key(function) Is_Origin (P : @key[in] Point) @key[return] Boolean @key[is] -- @Examcom[see @RefSecNum{Tagged Types and Type Extensions}] |
| 6512 |
(P.X = 0.0 @key[and] P.Y = 0.0);]} |
| 6513 |
@end{Example} |
| 6514 |
@end{Examples} |
| 6515 |
|
| 6516 |
@begin{Extend2005} |
| 6517 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 6518 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 6519 |
Expression functions are new in Ada 2012.]} |
| 6520 |
@end{Extend2005} |
| 6521 |
|
| 6522 |
@begin{Extend2012} |
| 6523 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0157-1]} |
| 6524 |
@ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}@b<Corrigendum:> |
| 6525 |
A @nt{aggregate} can directly be the return expression of an expression |
| 6526 |
function. This eliminates the double parentheses that otherwise would be |
| 6527 |
necessary.]} |
| 6528 |
|
| 6529 |
@ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0075-1]} |
| 6530 |
@ChgAdded{Version=[5],Text=[Aspect Static is new; it allows using suitable |
| 6531 |
expression functions in static expressions.]} |
| 6532 |
@end{Extend2012} |
| 6533 |
|