| 1 |
@Part(06, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2006/10/18 00:25:24 $} |
| 4 |
@LabeledSection{Subprograms} |
| 5 |
|
| 6 |
@Comment{$Source: e:\\cvsroot/ARM/Source/06.mss,v $} |
| 7 |
@Comment{$Revision: 1.77 $} |
| 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 |
@Defn{callable entity} |
| 39 |
A @i(callable entity) is a subprogram or entry (see Section 9). |
| 40 |
@Defn{call} |
| 41 |
A callable entity is invoked by a @i{call}; |
| 42 |
that is, a subprogram call or entry call. |
| 43 |
@Defn{callable construct} |
| 44 |
A @i(callable construct) is a construct |
| 45 |
that defines the action of a call upon a callable entity: |
| 46 |
a @nt{subprogram_body}, |
| 47 |
@nt{entry_body}, or @nt{accept_statement}. |
| 48 |
@begin{Ramification} |
| 49 |
Note that @lquotes@;callable entity@rquotes@; |
| 50 |
includes predefined operators, enumeration literals, |
| 51 |
and abstract subprograms. |
| 52 |
@lquotes@;Call@rquotes@; includes calls of these things. |
| 53 |
They do not have callable constructs, |
| 54 |
since they don't have completions. |
| 55 |
@end{Ramification} |
| 56 |
@end{Intro} |
| 57 |
|
| 58 |
@LabeledClause{Subprogram Declarations} |
| 59 |
|
| 60 |
@begin{Intro} |
| 61 |
@Redundant[A @nt{subprogram_declaration} declares a procedure or |
| 62 |
function.] |
| 63 |
@end{Intro} |
| 64 |
|
| 65 |
@begin{Syntax} |
| 66 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 67 |
@Syn{lhs=<subprogram_declaration>,rhs="@Chg{Version=[2],New=< |
| 68 |
[@Syn2{overriding_indicator}] |
| 69 |
>,Old=<>}@Syn2{subprogram_specification};"} |
| 70 |
|
| 71 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00348-01]} |
| 72 |
@DeletedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<>,Old=<abstract_subprogram_declaration>}>, |
| 73 |
rhs="@Chg{Version=[2],New=<>,Old=<@Syn2{subprogram_specification} @key{is} @key{abstract};>}"} |
| 74 |
|
| 75 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 76 |
@Syn{lhs=<subprogram_specification>,rhs="@Chg{Version=[2],New=[ |
| 77 |
@Syn2{procedure_specification} |
| 78 |
| @Syn2{function_specification}],Old=[ |
| 79 |
@key{procedure} @Syn2{defining_program_unit_name} @Syn2{parameter_profile} |
| 80 |
| @key{function} @Syn2{defining_designator} @Syn2{parameter_and_result_profile}]}"} |
| 81 |
|
| 82 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]} |
| 83 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<procedure_specification>,Old=<>}>, |
| 84 |
rhs="@Chg{Version=[2],New=<@key{procedure} @Syn2{defining_program_unit_name} @Syn2{parameter_profile}>,Old=<>}"} |
| 85 |
|
| 86 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]} |
| 87 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<function_specification>,Old=<>}>, |
| 88 |
rhs="@Chg{Version=[2],New=<@key{function} @Syn2{defining_designator} @Syn2{parameter_and_result_profile}>,Old=<>}"} |
| 89 |
|
| 90 |
@Syn{lhs=<designator>,rhs="[@Syn2{parent_unit_name} . ]@Syn2{identifier} | @Syn2{operator_symbol}"} |
| 91 |
|
| 92 |
@Syn{lhs=<defining_designator>, |
| 93 |
rhs="@Syn2{defining_program_unit_name} | @Syn2{defining_operator_symbol}"} |
| 94 |
|
| 95 |
@Syn{lhs=<defining_program_unit_name>,rhs="[@Syn2{parent_unit_name} . ]@Syn2{defining_identifier}"} |
| 96 |
|
| 97 |
@begin{SyntaxText} |
| 98 |
@Redundant[The optional @nt{parent_unit_name} is only allowed for |
| 99 |
library units (see @RefSecNum{Compilation Units - Library Units}).] |
| 100 |
@end{SyntaxText} |
| 101 |
|
| 102 |
@Syn{lhs=<operator_symbol>,rhs="@Syn2{string_literal}"} |
| 103 |
|
| 104 |
@begin{SyntaxText} |
| 105 |
|
| 106 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00395-01]} |
| 107 |
The sequence of characters in an @nt{operator_symbol} shall @Chg{Version=[2], |
| 108 |
New=[form a reserved |
| 109 |
word, a delimiter, or compound delimiter that corresponds],Old=[correspond]} to |
| 110 |
an operator belonging to one of the six @Chg{Version=[2],New=[categories], |
| 111 |
Old=[classes]} of operators |
| 112 |
defined in clause @RefSecNum{Operators and Expression Evaluation}@Chg{Version=[2], |
| 113 |
New=[],Old=[(spaces are not allowed and the case of letters |
| 114 |
is not significant)]}. |
| 115 |
|
| 116 |
@begin{Reason} |
| 117 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]} |
| 118 |
@ChgAdded{Version=[2],Text=[The @lquote@;sequence of characters@rquotes |
| 119 |
of the string literal of the operator is a technical term (see |
| 120 |
@RefSecNum{String Literals}), and does not include the surrounding quote |
| 121 |
characters. As defined in @RefSecNum{Lexical Elements, Separators, and Delimiters}, |
| 122 |
lexical elements are @lquotes@;formed@rquotes from a sequence of characters. |
| 123 |
Spaces are not allowed, and upper and lower case is not significant. See |
| 124 |
@RefSecNum{Lexical Elements, Separators, and Delimiters} and |
| 125 |
@RefSecNum{Reserved Words} for rules related to the use of @ntf{other_format} |
| 126 |
characters in delimiters and reserved words.]} |
| 127 |
@end{Reason} |
| 128 |
|
| 129 |
@end{SyntaxText} |
| 130 |
|
| 131 |
@Syn{lhs=<defining_operator_symbol>,rhs="@Syn2{operator_symbol}"} |
| 132 |
|
| 133 |
@Syn{lhs=<parameter_profile>,rhs="[@Syn2{formal_part}]"} |
| 134 |
|
| 135 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 136 |
@Syn{lhs=<parameter_and_result_profile>,rhs="@Chg{Version=[2],New=[ |
| 137 |
],Old=[]}[@Syn2{formal_part}] @key{return}@Chg{Version=[2],New=< [@Syn2{null_exclusion}]>,Old=<>} @Syn2{subtype_mark}@Chg{Version=[2],New=< |
| 138 |
| [@Syn2{formal_part}] @key{return} @Syn2{access_definition}>,Old=<>}"} |
| 139 |
|
| 140 |
@Syn{lhs=<formal_part>,rhs=" |
| 141 |
(@Syn2{parameter_specification} {; @Syn2{parameter_specification}})"} |
| 142 |
|
| 143 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 144 |
@Syn{lhs=<parameter_specification>,rhs=" |
| 145 |
@Syn2{defining_identifier_list} : @Syn2{mode} @Chg{Version=[2],New=<[@Syn2{null_exclusion}]>,Old=<>} @Syn2{subtype_mark} [:= @Syn2{default_expression}] |
| 146 |
| @Syn2{defining_identifier_list} : @Syn2{access_definition} [:= @Syn2{default_expression}]"} |
| 147 |
|
| 148 |
@Syn{lhs=<mode>,rhs="[@key{in}] | @key{in} @key{out} | @key{out}"} |
| 149 |
@end{Syntax} |
| 150 |
|
| 151 |
@begin{Resolution} |
| 152 |
@Defn2{Term=[formal parameter], Sec=(of a subprogram)} |
| 153 |
A @i(formal parameter) is an object |
| 154 |
@Redundant[directly visible within a @nt{subprogram_body}] |
| 155 |
that represents the actual parameter passed to the subprogram in a |
| 156 |
call; |
| 157 |
it is declared by a @nt{parameter_specification}. |
| 158 |
@PDefn2{Term=[expected type], |
| 159 |
Sec=(parameter @nt{default_expression})} |
| 160 |
For a formal parameter, |
| 161 |
the expected type for its @nt<default_expression>, |
| 162 |
if any, is that of the formal parameter. |
| 163 |
@IndexSee{Term=[parameter],See=[formal parameter]} |
| 164 |
@end{Resolution} |
| 165 |
|
| 166 |
@begin{Legality} |
| 167 |
@Defn{parameter mode} |
| 168 |
The @i(parameter mode) of a formal parameter conveys the direction of |
| 169 |
information transfer with the actual parameter: |
| 170 |
@key(in), @key(in out), or @key(out). |
| 171 |
Mode @key(in) is the default, |
| 172 |
and is the mode of a parameter defined by an @nt{access_definition}. |
| 173 |
The formal parameters of a function, if any, shall have |
| 174 |
the mode @key(in). |
| 175 |
@begin{Ramification} |
| 176 |
Access parameters are permitted. |
| 177 |
This restriction to @b(in) parameters is primarily a methodological |
| 178 |
restriction, though it also simplifies implementation for some compiler |
| 179 |
technologies. |
| 180 |
@end{Ramification} |
| 181 |
|
| 182 |
A @nt{default_expression} is only allowed in a @nt{parameter_specification} |
| 183 |
for a formal parameter of mode @key(in). |
| 184 |
|
| 185 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 186 |
@PDefn2{Term=[requires a completion], Sec=(@nt{subprogram_declaration})} |
| 187 |
@PDefn2{Term=[requires a completion], Sec=(@nt{generic_subprogram_declaration})} |
| 188 |
A @nt{subprogram_declaration} |
| 189 |
or a @nt{generic_subprogram_declaration} |
| 190 |
requires a completion: |
| 191 |
@Redundant[a body, a @nt<renaming_declaration> |
| 192 |
(see @RefSecNum(Renaming Declarations)), or a @Chg{Version=[2],New=[@nt{pragma}], |
| 193 |
Old=[@key(pragma)]} Import (see @RefSecNum{Interfacing Pragmas})]. |
| 194 |
@Redundant[A completion is not allowed |
| 195 |
for an @nt<abstract_subprogram_declaration>@Chg{Version=[2],New=[ (see |
| 196 |
@RefSecNum{Abstract Types and Subprograms}) or a |
| 197 |
@nt{null_procedure_declaration} (see @RefSecNum{Null Procedures})],Old=[]}.] |
| 198 |
@begin(Ramification) |
| 199 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 200 |
Abstract subprograms @Chg{Version=[2],New=[and null procedures ],Old=[]}are |
| 201 |
not declared by |
| 202 |
@nt{subprogram_declaration}s, and so do not require completion. |
| 203 |
Protected subprograms are declared by @nt{subprogram_declaration}s, |
| 204 |
and so require completion. |
| 205 |
Note that an abstract subprogram is a subprogram, |
| 206 |
and a protected subprogram is a subprogram, |
| 207 |
but a generic subprogram is not a subprogram. |
| 208 |
@end(Ramification) |
| 209 |
|
| 210 |
A @nt{name} that denotes a formal parameter |
| 211 |
is not allowed within the @nt{formal_part} in which it is declared, |
| 212 |
nor within the @nt{formal_part} of a corresponding body or |
| 213 |
@nt{accept_statement}. |
| 214 |
@begin{Ramification} |
| 215 |
By contrast, |
| 216 |
@nt<generic_formal_parameter_declaration>s are visible to subsequent |
| 217 |
declarations in the same @nt<generic_formal_part>. |
| 218 |
@end{Ramification} |
| 219 |
@end{Legality} |
| 220 |
|
| 221 |
@begin{StaticSem} |
| 222 |
@Defn{profile} |
| 223 |
The @i(profile) of (a view of) a callable entity |
| 224 |
is either a @nt{parameter_profile} or |
| 225 |
@nt{parameter_and_result_profile}@Redundant[; |
| 226 |
it embodies information about |
| 227 |
the interface to that entity @em for example, the profile includes |
| 228 |
information about parameters passed to the callable entity. |
| 229 |
All callable entities have a profile @em enumeration literals, |
| 230 |
other subprograms, and entries. |
| 231 |
An access-to-subprogram type has a designated profile.] |
| 232 |
Associated with a profile is a calling convention. |
| 233 |
A @nt<subprogram_declaration> declares a procedure or a function, as |
| 234 |
indicated by the initial reserved word, with name and profile as given by |
| 235 |
its specification. |
| 236 |
|
| 237 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 238 |
@PDefn2{Term=[nominal subtype], Sec=(of a formal parameter)} |
| 239 |
The nominal subtype of a formal parameter is |
| 240 |
the subtype @Chg{Version=[2],New=[determined],Old=[denoted]} by |
| 241 |
@Chg{Version=[2],New=[the optional @nt{null_exclusion} and ], Old=[]}the |
| 242 |
@nt{subtype_mark}, or defined by the @nt{access_definition}, in the |
| 243 |
@nt{parameter_specification}.@Chg{Version=[2],New=[ The nominal |
| 244 |
subtype of a function result is the subtype |
| 245 |
determined by the optional @nt{null_exclusion} and the @nt{subtype_mark}, or |
| 246 |
defined by the @nt{access_definition}, in the |
| 247 |
@nt{parameter_and_result_profile}. |
| 248 |
@PDefn2{Term=[nominal subtype], Sec=(of a function result)}], Old=[]} |
| 249 |
|
| 250 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00318-02]} |
| 251 |
@Defn{access parameter} |
| 252 |
An @i(access parameter) is a formal @key[in] parameter |
| 253 |
specified by an @nt{access_definition}. |
| 254 |
@Defn{access result type} |
| 255 |
@Chg{Version=[2],New=[An @i(access result type) is a function result type specified by |
| 256 |
an @nt{access_definition}.],Old=[]} |
| 257 |
An access parameter @Chg{Version=[2],New=[or result type ],Old=[]}is of an |
| 258 |
anonymous |
| 259 |
@Chg{Version=[2],New=[access],Old=[general access-to-variable]} type (see |
| 260 |
@RefSecNum{Access Types}). @Redundant[Access parameters |
| 261 |
@Chg{Version=[2],New=[of an access-to-object type],Old=[]} allow dispatching |
| 262 |
calls to be controlled by access values.@Chg{Version=[2],New=[ Access |
| 263 |
parameters of an access-to-subprogram type permit calls to subprograms passed |
| 264 |
as parameters irrespective of their accessibility level.],Old=[]}] |
| 265 |
|
| 266 |
@begin{Discussion} |
| 267 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 268 |
@ChgAdded{Version=[2],Text=[Access result types have normal accessibility and |
| 269 |
thus don't have any special properties worth noting here.]} |
| 270 |
@end{Discussion} |
| 271 |
|
| 272 |
@leading@keepnext@Defn2{Term=[subtypes], Sec=(of a profile)} |
| 273 |
The @i(subtypes of a profile) are: |
| 274 |
@begin{Itemize} |
| 275 |
For any non-access parameters, the nominal subtype of the parameter. |
| 276 |
|
| 277 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]} |
| 278 |
For any access parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}, |
| 279 |
the designated subtype of the parameter type. |
| 280 |
|
| 281 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]} |
| 282 |
@ChgAdded{Version=[2],Text=[For any access parameters of an access-to-subprogram |
| 283 |
type, the subtypes of the profile of the parameter type.]} |
| 284 |
|
| 285 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 286 |
@Chg{Version=[2],New=[For any non-access result, the nominal subtype of the |
| 287 |
function result.],Old=[For any result, the result subtype.]} |
| 288 |
|
| 289 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 290 |
@Chg{Version=[2],New=[For any access result type of an access-to-object type, |
| 291 |
the designated subtype of the result type.],Old=[]} |
| 292 |
|
| 293 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 294 |
@Chg{Version=[2],New=[For any access result type of an access-to-subprogram |
| 295 |
type, the subtypes of the profile of the result type.],Old=[]} |
| 296 |
|
| 297 |
@end{Itemize} |
| 298 |
|
| 299 |
@Redundant[@Defn2{Term=[types], Sec=(of a profile)} |
| 300 |
The @i{types of a profile} are the types of those subtypes.] |
| 301 |
|
| 302 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 303 |
@Redundant[A subprogram declared by an |
| 304 |
@nt<abstract_subprogram_declaration> |
| 305 |
is abstract; a subprogram declared by a @nt<subprogram_declaration> |
| 306 |
is not. See @RefSec{Abstract Types and Subprograms}.@Chg{Version=[2],New=[ |
| 307 |
Similarly, a procedure defined by a |
| 308 |
@nt{null_procedure_declaration} is a null procedure; a procedure declared by |
| 309 |
a @nt{subprogram_declaration} is not. See @RefSec{Null Procedures}.],Old=[]}] |
| 310 |
|
| 311 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00218-03]} |
| 312 |
@ChgAdded{Version=[2],Text=[@Redundant[An @nt{overriding_indicator} is used to |
| 313 |
indicate whether overriding is intended. See @RefSec{Overriding Indicators}.]]} |
| 314 |
@end{StaticSem} |
| 315 |
|
| 316 |
@begin{RunTime} |
| 317 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 318 |
@PDefn2{Term=[elaboration], Sec=(subprogram_declaration)}@Chg{Version=[2],New=[],Old=[ |
| 319 |
@PDefn2{Term=[elaboration], Sec=(abstract_subprogram_declaration)}]} |
| 320 |
The elaboration of a @nt{subprogram_declaration}@Chg{Version=[2],New=[],Old=[ |
| 321 |
or an @nt{abstract_subprogram_declaration}]} has no effect. |
| 322 |
@end{RunTime} |
| 323 |
|
| 324 |
@begin{Notes} |
| 325 |
A @nt{parameter_specification} with several identifiers is equivalent |
| 326 |
to a sequence of single @nt{parameter_specification}s, as explained |
| 327 |
in @RefSecNum{Objects and Named Numbers}. |
| 328 |
|
| 329 |
Abstract subprograms do not have bodies, and cannot be used |
| 330 |
in a nondispatching call (see @RefSec{Abstract Types and Subprograms}). |
| 331 |
|
| 332 |
The evaluation of @nt<default_expression>s is caused by certain |
| 333 |
calls, as described in @RefSecNum{Parameter Associations}. |
| 334 |
They are not evaluated during the elaboration of |
| 335 |
the subprogram declaration. |
| 336 |
|
| 337 |
Subprograms can be called recursively and can be called |
| 338 |
concurrently from multiple tasks. |
| 339 |
@end{Notes} |
| 340 |
|
| 341 |
@begin{Examples} |
| 342 |
@leading@keepnext@i{Examples of subprogram declarations:} |
| 343 |
@begin{Example} |
| 344 |
@key[procedure] Traverse_Tree; |
| 345 |
@key[procedure] Increment(X : @key[in] @key[out] Integer); |
| 346 |
@key[procedure] Right_Indent(Margin : @key[out] Line_Size); --@RI{ see @RefSecNum{Integer Types}} |
| 347 |
@key[procedure] Switch(From, To : @key[in] @key[out] Link); --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 348 |
|
| 349 |
@key[function] Random @key[return] Probability; --@RI{ see @RefSecNum{Floating Point Types}} |
| 350 |
|
| 351 |
@key[function] Min_Cell(X : Link) @key[return] Cell; --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 352 |
@key[function] Next_Frame(K : Positive) @key[return] Frame; --@RI{ see @RefSecNum{Access Types}} |
| 353 |
@key[function] Dot_Product(Left, Right : Vector) @key[return] Real; --@RI{ see @RefSecNum{Array Types}} |
| 354 |
|
| 355 |
@key[function] "*"(Left, Right : Matrix) @key[return] Matrix; --@RI{ see @RefSecNum{Array Types}} |
| 356 |
@end{Example} |
| 357 |
|
| 358 |
@begin{wide} |
| 359 |
@leading@keepnext@i{Examples of @key[in] parameters with default expressions:} |
| 360 |
@end{wide} |
| 361 |
@begin{Example} |
| 362 |
@key[procedure] Print_Header(Pages : @key[in] Natural; |
| 363 |
Header : @key[in] Line := (1 .. Line'Last => ' '); --@RI{ see @RefSecNum{Array Types}} |
| 364 |
Center : @key[in] Boolean := True); |
| 365 |
@end{Example} |
| 366 |
@end{Examples} |
| 367 |
|
| 368 |
@begin{Extend83} |
| 369 |
@Defn{extensions to Ada 83} |
| 370 |
The syntax for @nt{abstract_subprogram_declaration} is added. |
| 371 |
The syntax for @nt{parameter_specification} is revised to allow |
| 372 |
for access parameters (see @RefSecNum{Access Types}) |
| 373 |
|
| 374 |
Program units that are library units may have |
| 375 |
a @nt{parent_unit_name} to indicate the parent of a child |
| 376 |
(see Section 10). |
| 377 |
@end{Extend83} |
| 378 |
|
| 379 |
@begin{DiffWord83} |
| 380 |
We have incorporated the rules from |
| 381 |
RM83-6.5, @lquotes@;Function Subprograms@rquotes@; here and in |
| 382 |
@RefSec{Subprogram Bodies} |
| 383 |
|
| 384 |
We have incorporated the definitions of RM83-6.6, @lquotes@;Parameter and Result |
| 385 |
Type Profile - Overloading of Subprograms@rquotes@; here. |
| 386 |
|
| 387 |
The syntax rule for @nt{defining_operator_symbol} is new. |
| 388 |
It is used for the defining occurrence of an @nt{operator_symbol}, |
| 389 |
analogously to @nt{defining_identifier}. |
| 390 |
Usage occurrences use the @nt{direct_name} or @nt{selector_name} |
| 391 |
syntactic categories. |
| 392 |
The syntax rules for @nt{defining_designator} and |
| 393 |
@nt{defining_program_unit_name} are new. |
| 394 |
@end{DiffWord83} |
| 395 |
|
| 396 |
@begin{Extend95} |
| 397 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 398 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 399 |
Subprograms now allow @nt{overriding_indicator}s for better error checking |
| 400 |
of overriding.]} |
| 401 |
|
| 402 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]} |
| 403 |
@ChgAdded{Version=[2],Text=[An optional @nt{null_exclusion} can be used in a |
| 404 |
formal parameter declaration. Similarly, an optional @nt{null_exclusion} can |
| 405 |
be used in a function result.]} |
| 406 |
|
| 407 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 408 |
@ChgAdded{Version=[2],Text=[The return type of a function can be an |
| 409 |
anonymous access type.]} |
| 410 |
@end{Extend95} |
| 411 |
|
| 412 |
@begin{DiffWord95} |
| 413 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00254-01]} |
| 414 |
@ChgAdded{Version=[2],Text=[A description of the purpose of anonymous |
| 415 |
access-to-subprogram parameters and the definition of the profile of |
| 416 |
subprograms containing them was added.]} |
| 417 |
|
| 418 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 419 |
@ChgAdded{Version=[2],Text=[Split the production for |
| 420 |
@nt{subprogram_specification} in order to make the declaration |
| 421 |
of null procedures (see @RefSecNum{Null Procedures}) easier.]} |
| 422 |
|
| 423 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 424 |
@ChgAdded{Version=[2],Text=[Moved the @SyntaxTitle and |
| 425 |
@RuntimeTitle for @nt{abstract_subprogram_declaration} to |
| 426 |
@RefSecNum{Abstract Types and Subprograms}, so that the syntax |
| 427 |
and semantics are together. This also keeps abstract and null |
| 428 |
subprograms similar.]} |
| 429 |
|
| 430 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]} |
| 431 |
@ChgAdded{Version=[2],Text=[Revised to allow @ntf{other_format} characters |
| 432 |
in @nt{operator_symbol}s in the same way as the underlying constructs.]} |
| 433 |
@end{DiffWord95} |
| 434 |
|
| 435 |
|
| 436 |
@LabeledClause{Formal Parameter Modes} |
| 437 |
|
| 438 |
@begin{Intro} |
| 439 |
@Redundant[A @nt{parameter_specification} declares a formal parameter of |
| 440 |
mode @key[in], @key[in out], or @key[out].] |
| 441 |
@end{Intro} |
| 442 |
|
| 443 |
@begin{StaticSem} |
| 444 |
@Defn{pass by copy} |
| 445 |
@Defn{by copy parameter passing} |
| 446 |
@Defn{copy parameter passing} |
| 447 |
@Defn{pass by reference} |
| 448 |
@Defn{by reference parameter passing} |
| 449 |
@Defn{reference parameter passing} |
| 450 |
A parameter is passed either @i{by copy} or @i{by reference}. |
| 451 |
@Redundant[When a parameter is passed by copy, |
| 452 |
the formal parameter denotes a separate object from the |
| 453 |
actual parameter, and any information transfer between the two occurs |
| 454 |
only before and after executing the subprogram. |
| 455 |
When a parameter is passed by reference, |
| 456 |
the formal parameter denotes (a view of) the object denoted by the |
| 457 |
actual parameter; reads and updates of the formal parameter directly |
| 458 |
reference the actual parameter object.] |
| 459 |
|
| 460 |
@Defn{by-copy type} |
| 461 |
A type is a @i(by-copy type) if it is an elementary type, |
| 462 |
or if it is a descendant of a private type whose full type is a |
| 463 |
by-copy type. |
| 464 |
A parameter of a by-copy type is passed by copy. |
| 465 |
|
| 466 |
@leading@keepnext@Defn{by-reference type} |
| 467 |
A type is a @i(by-reference type) if it |
| 468 |
is a descendant of one of the following: |
| 469 |
@begin(itemize) |
| 470 |
a tagged type; |
| 471 |
|
| 472 |
a task or protected type; |
| 473 |
|
| 474 |
a nonprivate type with the reserved word @b(limited) in its declaration; |
| 475 |
@begin{Ramification} |
| 476 |
A limited private type is by-reference only if it falls |
| 477 |
under one of the other categories. |
| 478 |
@end{Ramification} |
| 479 |
|
| 480 |
a composite type with a subcomponent of a by-reference type; |
| 481 |
|
| 482 |
a private type |
| 483 |
whose full type is a by-reference type. |
| 484 |
@end(itemize) |
| 485 |
|
| 486 |
A parameter of a by-reference type is passed by reference. |
| 487 |
@Defn2{Term=[associated object], Sec=(of a value of a by-reference type)} |
| 488 |
Each value of a by-reference type has an associated object. |
| 489 |
For a parenthesized expression, @nt{qualified_expression}, |
| 490 |
or @nt{type_conversion}, this object is the one associated with the |
| 491 |
operand. |
| 492 |
|
| 493 |
@begin{Ramification} |
| 494 |
By-reference parameter passing makes sense only if there is an |
| 495 |
object to reference; hence, we define such an object for each |
| 496 |
case. |
| 497 |
|
| 498 |
Since tagged types are by-reference types, this implies that every value |
| 499 |
of a tagged type has an associated object. This simplifies things, |
| 500 |
because we can define the tag to be a property of the object, and not of |
| 501 |
the value of the object, which makes it clearer that object tags never |
| 502 |
change. |
| 503 |
|
| 504 |
We considered simplifying things even more by making every value (and |
| 505 |
therefore every expression) have an associated object. After all, |
| 506 |
there is little semantic difference between a constant object and a |
| 507 |
value. |
| 508 |
However, this would cause problems for untagged types. |
| 509 |
In particular, we would have to do a constraint check on every read of a |
| 510 |
type conversion (or a renaming thereof) in certain cases. |
| 511 |
|
| 512 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 513 |
We do not want this definition to depend on the view of the type; |
| 514 |
privateness is essentially ignored for this definition. |
| 515 |
Otherwise, things would be confusing (does the rule apply at the call |
| 516 |
site, at the site of the declaration of the subprogram, |
| 517 |
at the site of the |
| 518 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]}?), |
| 519 |
and requiring different calls to use different mechanisms would be an |
| 520 |
implementation burden. |
| 521 |
|
| 522 |
@RefSec{Shared Variable Control} says that a composite type with an |
| 523 |
atomic or volatile subcomponent is a by-reference type, |
| 524 |
among other things. |
| 525 |
|
| 526 |
@Defn2{Term=[associated object], Sec=(of a value of a limited type)} |
| 527 |
Every value of a limited by-reference type is the value of |
| 528 |
one and only one limited object. |
| 529 |
The @i{associated object} of a value of a limited by-reference type is |
| 530 |
the object whose value it represents. |
| 531 |
@Defn2{Term=[same value], Sec=(for a limited type)} |
| 532 |
Two values of a limited by-reference type are the @i{same} |
| 533 |
if and only if they represent the value of the same object. |
| 534 |
|
| 535 |
We say @lquotes@;by-reference@rquotes@; above because |
| 536 |
these statements are not always true for limited private types |
| 537 |
whose underlying type is nonlimited (unfortunately). |
| 538 |
@end{Ramification} |
| 539 |
|
| 540 |
@PDefn{unspecified} |
| 541 |
For parameters of other types, |
| 542 |
it is unspecified whether the parameter |
| 543 |
is passed by copy or by reference. |
| 544 |
@begin{Discussion} |
| 545 |
There is no need to incorporate the discussion of AI83-00178, |
| 546 |
which requires pass-by-copy for certain kinds of actual parameters, |
| 547 |
while allowing pass-by-reference for others. |
| 548 |
This is because we explicitly indicate that a function |
| 549 |
creates an anonymous constant object for its result, |
| 550 |
unless the type is a return-by-reference type |
| 551 |
(see @RefSecNum{Return Statements}). |
| 552 |
We also provide a special dispensation for |
| 553 |
instances of Unchecked_Conversion to return by reference, even |
| 554 |
if the result type is not a return-by-reference type |
| 555 |
(see @RefSecNum{Unchecked Type Conversions}). |
| 556 |
@end{Discussion} |
| 557 |
@end{StaticSem} |
| 558 |
|
| 559 |
@begin{Bounded} |
| 560 |
@Defn{distinct access paths} |
| 561 |
@Defn2{Term=[access paths],Sec=(distinct)} |
| 562 |
@IndexSee{Term=[aliasing],See=(distinct access paths)} |
| 563 |
@PDefn2{Term=(bounded error),Sec=(cause)} |
| 564 |
If one @nt<name> denotes a part of a formal parameter, |
| 565 |
and a second @nt<name> denotes a part of |
| 566 |
a distinct formal parameter or an object that is not |
| 567 |
part of a formal parameter, then the two @nt<name>s are |
| 568 |
considered @i(distinct access paths). |
| 569 |
If an object is of a type for which the parameter passing |
| 570 |
mechanism is not specified, then it is a bounded error to |
| 571 |
assign to the object via one access path, |
| 572 |
and then read the value of the object via a distinct access path, |
| 573 |
unless the first access path denotes a part of a formal parameter that |
| 574 |
no longer exists at the point of the second access |
| 575 |
@Redundant[(due to leaving the corresponding callable construct).] |
| 576 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 577 |
The possible consequences are that Program_Error is raised, |
| 578 |
or the newly assigned value is read, or some old value of the object is read. |
| 579 |
@begin{Discussion} |
| 580 |
For example, if we call @lquotes@;P(X => Global_Variable, Y => Global_Variable)@rquotes@;, |
| 581 |
then within P, the names @lquotes@;X@rquotes@;, @lquotes@;Y@rquotes@;, and @lquotes@;Global_Variable@rquotes@; |
| 582 |
are all distinct access paths. |
| 583 |
If Global_Variable's type is neither pass-by-copy nor pass-by-reference, |
| 584 |
then it is a bounded error to assign to Global_Variable and |
| 585 |
then read X or Y, since the language does not specify whether the |
| 586 |
old or the new value would be read. On the other hand, if |
| 587 |
Global_Variable's type is pass-by-copy, then the old value would |
| 588 |
always be read, and there is no error. Similarly, if Global_Variable's |
| 589 |
type is defined by the language to be pass-by-reference, then the |
| 590 |
new value would always be read, and again there is no error. |
| 591 |
@end{Discussion} |
| 592 |
@begin{Reason} |
| 593 |
We are saying @i(assign) here, not @i(update), |
| 594 |
because updating any subcomponent is considered |
| 595 |
to update the enclosing object. |
| 596 |
|
| 597 |
The @lquotes@;still exists@rquotes@; part is so that a read after the subprogram returns |
| 598 |
is OK. |
| 599 |
|
| 600 |
If the parameter is of a by-copy type, |
| 601 |
then there is no issue here |
| 602 |
@em the formal is not a view of the actual. |
| 603 |
If the parameter is of a by-reference type, |
| 604 |
then the programmer may depend on updates through one access path |
| 605 |
being visible through some other access path, |
| 606 |
just as if the parameter were of an access type. |
| 607 |
@end{Reason} |
| 608 |
@begin{ImplNote} |
| 609 |
The implementation can keep a copy in a register of a parameter |
| 610 |
whose parameter-passing mechanism is not specified. |
| 611 |
If a different access path is used to update the object (creating |
| 612 |
a bounded error situation), |
| 613 |
then the implementation can still use the value of the register, |
| 614 |
even though the in-memory version of the object has been changed. |
| 615 |
However, to keep the error properly bounded, |
| 616 |
if the implementation chooses to read the in-memory version, |
| 617 |
it has to be consistent -- it cannot then assume that something it has |
| 618 |
proven about the register is true of the memory location. |
| 619 |
For example, suppose the formal parameter is L, |
| 620 |
the value of L(6) is now in a register, and L(6) is used |
| 621 |
in an @nt{indexed_component} as in @lquotes@;A(L(6)) := 99;@rquotes@;, |
| 622 |
where A has bounds 1..3. |
| 623 |
If the implementation can prove that the value for L(6) in the register is in |
| 624 |
the range 1..3, then it need not perform the constraint check if it |
| 625 |
uses the register value. |
| 626 |
However, if the memory value of L(6) has been changed to 4, |
| 627 |
and the implementation uses that memory value, |
| 628 |
then it had better not alter memory outside of A. |
| 629 |
|
| 630 |
Note that the rule allows the implementation to pass a parameter by |
| 631 |
reference and then keep just part of it in a register, or, |
| 632 |
equivalently, to pass part of the parameter by reference and another |
| 633 |
part by copy. |
| 634 |
@end{ImplNote} |
| 635 |
@begin{Reason} |
| 636 |
@leading@;We do not want to go so far as to say that the mere presence |
| 637 |
of aliasing is wrong. |
| 638 |
We wish to be able to write the following sorts of things |
| 639 |
in standard Ada: |
| 640 |
@begin{Example} |
| 641 |
@key[procedure] Move ( Source : @key[in] String; |
| 642 |
Target : @key[out] String; |
| 643 |
Drop : @key[in] Truncation := Error; |
| 644 |
Justify : @key[in] Alignment := Left; |
| 645 |
Pad : @key[in] Character := Space); |
| 646 |
--@RI{ Copies elements from Source to Target (safely if they overlap)} |
| 647 |
@end{Example} |
| 648 |
|
| 649 |
This is from the standard string handling package. |
| 650 |
It would be embarrassing if this couldn't be written in Ada! |
| 651 |
|
| 652 |
The @lquotes@;then@rquotes@; before @lquotes@;read@rquotes@; in the rule implies that the implementation |
| 653 |
can move a read to an earlier place in the code, but not to a later |
| 654 |
place after a potentially aliased assignment. |
| 655 |
Thus, if the subprogram reads one of its parameters into a local |
| 656 |
variable, and then updates another potentially aliased one, |
| 657 |
the local copy is safe @em it is known to have the old value. |
| 658 |
For example, the above-mentioned Move subprogram can be implemented |
| 659 |
by copying Source into a local variable before assigning into Target. |
| 660 |
|
| 661 |
@leading@;For an @nt{assignment_statement} assigning one array parameter to another, |
| 662 |
the implementation has to check which direction to copy |
| 663 |
at run time, in general, in case the actual parameters are |
| 664 |
overlapping slices. |
| 665 |
For example: |
| 666 |
@begin{Example} |
| 667 |
@key[procedure] Copy(X : @key[in out] String; Y: String) @key[is] |
| 668 |
@key[begin] |
| 669 |
X := Y; |
| 670 |
@key[end] Copy; |
| 671 |
@end{Example} |
| 672 |
|
| 673 |
It would be wrong for the compiler to assume that X and Y |
| 674 |
do not overlap (unless, of course, it can prove otherwise). |
| 675 |
@end{Reason} |
| 676 |
@end{Bounded} |
| 677 |
|
| 678 |
@begin{Notes} |
| 679 |
A formal parameter of mode @key(in) is a constant |
| 680 |
view (see @RefSecNum{Objects and Named Numbers}); |
| 681 |
it cannot be updated within the @nt{subprogram_body}. |
| 682 |
@end{Notes} |
| 683 |
|
| 684 |
@begin{Extend83} |
| 685 |
@Defn{extensions to Ada 83} |
| 686 |
The value of an @key(out) parameter may be read. |
| 687 |
An @key(out) parameter is treated like a declared |
| 688 |
variable without an explicit initial expression. |
| 689 |
@end{Extend83} |
| 690 |
|
| 691 |
@begin{DiffWord83} |
| 692 |
Discussion of copy-in for parts of out parameters is now |
| 693 |
covered in @RefSec{Parameter Associations}. |
| 694 |
|
| 695 |
The concept of a by-reference type is new to Ada 95. |
| 696 |
|
| 697 |
We now cover in a general way in @RefSecNum{Operations of Discriminated Types} |
| 698 |
the rule regarding erroneous execution when a discriminant |
| 699 |
is changed and one of the parameters depends on the discriminant. |
| 700 |
@end{DiffWord83} |
| 701 |
|
| 702 |
|
| 703 |
@LabeledClause{Subprogram Bodies} |
| 704 |
|
| 705 |
@begin{Intro} |
| 706 |
@Redundant[A @nt{subprogram_body} specifies the execution of a |
| 707 |
subprogram.] |
| 708 |
@end{Intro} |
| 709 |
|
| 710 |
@begin{Syntax} |
| 711 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 712 |
@Syn{lhs=<subprogram_body>,rhs="@Chg{Version=[2],New=< |
| 713 |
[@Syn2{overriding_indicator}]>,Old=<>} |
| 714 |
@Syn2{subprogram_specification} @key{is} |
| 715 |
@Syn2{declarative_part} |
| 716 |
@key{begin} |
| 717 |
@Syn2{handled_sequence_of_statements} |
| 718 |
@key{end} [@Syn2{designator}];"} |
| 719 |
|
| 720 |
@begin{SyntaxText} |
| 721 |
If a @nt{designator} appears at the end of a @nt{subprogram_body}, |
| 722 |
it shall repeat the @nt{defining_designator} of the @nt{subprogram_specification}. |
| 723 |
@end{SyntaxText} |
| 724 |
@end{Syntax} |
| 725 |
|
| 726 |
@begin{Legality} |
| 727 |
@Redundant[In contrast to other bodies,] |
| 728 |
a @nt{subprogram_body} need not be the completion of a previous |
| 729 |
declaration@Redundant[, |
| 730 |
in which case the body declares the subprogram]. |
| 731 |
If the body is a completion, it shall be the completion of a |
| 732 |
@nt{subprogram_declaration} or @nt{generic_subprogram_declaration}. |
| 733 |
The profile of a @nt{subprogram_body} that completes a declaration |
| 734 |
shall conform fully to that of the declaration. |
| 735 |
@Defn2{Term=[full conformance],Sec=(required)} |
| 736 |
@end{Legality} |
| 737 |
|
| 738 |
@begin{StaticSem} |
| 739 |
A @nt{subprogram_body} is considered a declaration. |
| 740 |
It can either complete a previous declaration, |
| 741 |
or itself be the initial declaration of the subprogram. |
| 742 |
@end{StaticSem} |
| 743 |
|
| 744 |
@begin{RunTime} |
| 745 |
@PDefn2{Term=[elaboration], Sec=(non-generic subprogram_body)} |
| 746 |
The elaboration of a non-generic |
| 747 |
@nt{subprogram_body} has no other effect than to establish |
| 748 |
that the subprogram can from then on be called without |
| 749 |
failing the Elaboration_Check. |
| 750 |
@begin{Ramification} |
| 751 |
See @RefSecNum{Generic Bodies} for elaboration of a generic body. |
| 752 |
Note that protected @ntf{subprogram_bodies} never get elaborated; |
| 753 |
the elaboration of the containing @nt{protected_body} |
| 754 |
allows them to be called without failing the Elaboration_Check. |
| 755 |
@end{Ramification} |
| 756 |
|
| 757 |
@PDefn2{Term=[execution], Sec=(subprogram_body)} |
| 758 |
@Redundant[The execution of a @nt{subprogram_body} is invoked by a |
| 759 |
subprogram call.] |
| 760 |
For this execution the @nt{declarative_part} is elaborated, and the |
| 761 |
@nt{handled_sequence_of_statements} is then executed. |
| 762 |
@end{RunTime} |
| 763 |
|
| 764 |
@begin{Examples} |
| 765 |
@leading@keepnext@i{Example of procedure body:} |
| 766 |
@begin{Example} |
| 767 |
@key[procedure] Push(E : @key[in] Element_Type; S : @key[in] @key[out] Stack) @key[is] |
| 768 |
@key[begin] |
| 769 |
@key[if] S.Index = S.Size @key[then] |
| 770 |
@key[raise] Stack_Overflow; |
| 771 |
@key[else] |
| 772 |
S.Index := S.Index + 1; |
| 773 |
S.Space(S.Index) := E; |
| 774 |
@key[end] @key[if]; |
| 775 |
@key[end] Push; |
| 776 |
@end{Example} |
| 777 |
|
| 778 |
@begin{Wide} |
| 779 |
@leading@keepnext@i{Example of a function body:} |
| 780 |
@end{Wide} |
| 781 |
@begin{Example} |
| 782 |
@key[function] Dot_Product(Left, Right : Vector) @key[return] Real @key[is] |
| 783 |
Sum : Real := 0.0; |
| 784 |
@key[begin] |
| 785 |
Check(Left'First = Right'First @key[and] Left'Last = Right'Last); |
| 786 |
@key[for] J @key[in] Left'Range @key[loop] |
| 787 |
Sum := Sum + Left(J)*Right(J); |
| 788 |
@key[end] @key[loop]; |
| 789 |
@key[return] Sum; |
| 790 |
@key[end] Dot_Product; |
| 791 |
@end{Example} |
| 792 |
@end{Examples} |
| 793 |
|
| 794 |
@begin{Extend83} |
| 795 |
@Defn{extensions to Ada 83} |
| 796 |
A @nt{renaming_declaration} may be used instead of a @nt{subprogram_body}. |
| 797 |
@end{Extend83} |
| 798 |
|
| 799 |
@begin{DiffWord83} |
| 800 |
The syntax rule for @nt{subprogram_body} now uses the syntactic category |
| 801 |
@nt{handled_sequence_of_statements}. |
| 802 |
|
| 803 |
The @nt{declarative_part} of a @nt{subprogram_body} is now required; |
| 804 |
that doesn't make any real difference, |
| 805 |
because a @nt{declarative_part} can be empty. |
| 806 |
|
| 807 |
We have incorporated some rules from RM83-6.5 here. |
| 808 |
|
| 809 |
RM83 forgot to restrict the definition of elaboration of a |
| 810 |
@nt{subprogram_body} to non-generics. |
| 811 |
@end{DiffWord83} |
| 812 |
|
| 813 |
@begin{DiffWord95} |
| 814 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 815 |
@Chg{Version=[2],New=[@nt{Overriding_indicator} is added to |
| 816 |
@nt{subprogram_body}.],Old=[]} |
| 817 |
@end{DiffWord95} |
| 818 |
|
| 819 |
|
| 820 |
@LabeledSubClause{Conformance Rules} |
| 821 |
|
| 822 |
@begin{Intro} |
| 823 |
@Defn{conformance} |
| 824 |
@SeeAlso{Primary=[conformance],Other=(type conformance)} |
| 825 |
@SeeAlso{Primary=[conformance],Other=(mode conformance)} |
| 826 |
@SeeAlso{Primary=[conformance],Other=(subtype conformance)} |
| 827 |
@SeeAlso{Primary=[conformance],Other=(full conformance)} |
| 828 |
@Redundant[When subprogram profiles are given in more than one place, |
| 829 |
they are required to conform in one of four ways: type conformance, mode |
| 830 |
conformance, subtype conformance, or full conformance.] |
| 831 |
@end{Intro} |
| 832 |
|
| 833 |
@begin{StaticSem} |
| 834 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 835 |
@leading@Defn{convention} |
| 836 |
@Defn{calling convention} |
| 837 |
@Redundant[As explained in @RefSec{Interfacing Pragmas}, |
| 838 |
a @i{convention} can be specified for an entity.] |
| 839 |
@Chg{New=[Unless this International Standard states otherwise, the default |
| 840 |
convention of an entity is Ada.],Old=[]} |
| 841 |
@Redundant[For a callable entity or access-to-subprogram type, |
| 842 |
the convention is called the @i{calling convention}.] |
| 843 |
The following conventions are defined by the language: |
| 844 |
@begin{Itemize} |
| 845 |
@Defn{Ada calling convention} |
| 846 |
@Defn2{Term=[calling convention], Sec=(Ada)} |
| 847 |
The default calling convention for any subprogram not listed below is |
| 848 |
@i{Ada}. |
| 849 |
@Redundant[A @nt{pragma} Convention, Import, or Export may be used to override |
| 850 |
the default calling convention (see @RefSecNum{Interfacing Pragmas})]. |
| 851 |
@begin{Ramification} |
| 852 |
See also the rule about renamings-as-body |
| 853 |
in @RefSecNum{Subprogram Renaming Declarations}. |
| 854 |
@end{Ramification} |
| 855 |
|
| 856 |
@leading@Defn{Intrinsic calling convention} |
| 857 |
@Defn2{Term=[calling convention], Sec=(Intrinsic)} |
| 858 |
The @i{Intrinsic} calling convention represents |
| 859 |
subprograms that are @lquotes@;built in@rquotes@; to the compiler. |
| 860 |
The default calling convention is Intrinsic for the following: |
| 861 |
@begin{InnerItemize} |
| 862 |
an enumeration literal; |
| 863 |
|
| 864 |
a "/=" operator declared implicitly due to |
| 865 |
the declaration of "=" (see @RefSecNum{Overloading of Operators}); |
| 866 |
|
| 867 |
any other implicitly declared subprogram unless it is |
| 868 |
a dispatching operation of a tagged type; |
| 869 |
|
| 870 |
an inherited subprogram of a generic formal tagged type |
| 871 |
with unknown discriminants; |
| 872 |
@begin{Reason} |
| 873 |
@Comment{8652/0011 suggests that the reason for this rule be documented in |
| 874 |
the AARM.} |
| 875 |
@ChgRef{Version=[1],Kind=[Added]} |
| 876 |
@Chg{New=[Consider:],Old=[]} |
| 877 |
@begin{Example} |
| 878 |
@ChgRef{Version=[1],Kind=[Added]} |
| 879 |
@Chg{New=[@key[package] P @key[is] |
| 880 |
@key[type] Root @key[is tagged null record]; |
| 881 |
@key[procedure] Proc(X: Root); |
| 882 |
@key[end] P;],Old=[]} |
| 883 |
|
| 884 |
@ChgRef{Version=[1],Kind=[Added]} |
| 885 |
@Chg{New=[@key[generic] |
| 886 |
@key[type] Formal(<>) @key[is new] Root @key[with private]; |
| 887 |
@key[package] G @key[is] |
| 888 |
... |
| 889 |
@key[end] G;],Old=[]} |
| 890 |
|
| 891 |
@ChgRef{Version=[1],Kind=[Added]} |
| 892 |
@ChgAdded{Version=[1],Text=[@key[package body] G @key[is] |
| 893 |
... |
| 894 |
X: Formal := ...; |
| 895 |
... |
| 896 |
Proc(X); -- @RI[This is a dispatching call in Instance, because] |
| 897 |
-- @RI[the actual type for Formal is class-wide.] |
| 898 |
... |
| 899 |
-- @RI[Proc'Access would be illegal here, because it is of] |
| 900 |
-- @RI[convention Intrinsic, by the above rule.] |
| 901 |
@key[end] G;]} |
| 902 |
|
| 903 |
@ChgRef{Version=[1],Kind=[Added]} |
| 904 |
@ChgAdded{Version=[1],Text=[@key[type] Actual @key[is new] Root @key[with] ...; |
| 905 |
@key[procedure] Proc(X: Actual); |
| 906 |
@key[package] Instance @key[is new] G(Formal => Actual'Class); |
| 907 |
-- @RI[It is legal to pass in a class-wide actual, because Formal] |
| 908 |
-- @RI[has unknown discriminants.]]} |
| 909 |
@end{Example} |
| 910 |
|
| 911 |
@ChgRef{Version=[1],Kind=[Added]} |
| 912 |
@Chg{New=[Within Instance, all calls to Proc will be dispatching calls, so Proc doesn't |
| 913 |
really exist in machine code, so we wish to avoid taking 'Access of it. |
| 914 |
This rule applies to those cases where the actual type might be class-wide, |
| 915 |
and makes these Intrinsic, thus forbidding 'Access.],Old=[]} |
| 916 |
@end{Reason} |
| 917 |
|
| 918 |
|
| 919 |
an attribute that is a subprogram; |
| 920 |
|
| 921 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01]} |
| 922 |
a subprogram declared immediately |
| 923 |
within a @nt{protected_body}@Chg{Version=[2],New=[;],Old=[.]} |
| 924 |
|
| 925 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]} |
| 926 |
@ChgAdded{Version=[2],Text=[any prefixed view of a subprogram (see |
| 927 |
@RefSecNum{Selected Components}).]} |
| 928 |
@begin{Reason} |
| 929 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 930 |
@ChgAdded{Version=[2],Text=[The profile of a prefixed view is |
| 931 |
different than the @lquotes@;real@rquotes profile of the subprogram |
| 932 |
(it doesn't have the first parameter), so we don't want to be able |
| 933 |
to take 'Access of it, as that would require generating a wrapper of |
| 934 |
some sort.]} |
| 935 |
@end{Reason} |
| 936 |
|
| 937 |
@end{InnerItemize} |
| 938 |
|
| 939 |
@NoPrefix@Redundant[The Access attribute is not allowed |
| 940 |
for Intrinsic subprograms.] |
| 941 |
@begin{Ramification} |
| 942 |
The Intrinsic calling convention really represents any number of |
| 943 |
calling conventions at the machine code level; |
| 944 |
the compiler might have a different instruction sequence for |
| 945 |
each intrinsic. |
| 946 |
That's why the Access attribute is disallowed. |
| 947 |
We do not wish to require the implementation to generate |
| 948 |
an out of line body for an intrinsic. |
| 949 |
|
| 950 |
Whenever we wish to disallow the Access attribute in order to ease |
| 951 |
implementation, we make the subprogram Intrinsic. |
| 952 |
Several language-defined subprograms have |
| 953 |
@lquotes@;@key[pragma] Convention(Intrinsic, ...);@rquotes@;. |
| 954 |
An implementation might actually implement this |
| 955 |
as @lquotes@;@key[pragma] Import(Intrinsic, ...);@rquotes@;, |
| 956 |
if there is really no body, and the implementation of the subprogram |
| 957 |
is built into the code generator. |
| 958 |
|
| 959 |
Subprograms declared in @ntf{protected_bodies} will generally have a |
| 960 |
special calling |
| 961 |
convention so as to pass along the identification of the |
| 962 |
current instance of the protected type. |
| 963 |
The convention is not @i(protected) since such local subprograms |
| 964 |
need not contain any @lquotes@;locking@rquotes@; logic since they are |
| 965 |
not callable via @lquotes@;external@rquotes@; calls; |
| 966 |
this rule prevents an access value designating such a subprogram |
| 967 |
from being passed outside the protected unit. |
| 968 |
|
| 969 |
The @lquotes@;implicitly declared subprogram@rquotes@; above refers to |
| 970 |
predefined operators (other than the "=" of a tagged type) and |
| 971 |
the inherited subprograms of |
| 972 |
untagged types. |
| 973 |
@end{Ramification} |
| 974 |
|
| 975 |
@Defn{protected calling convention} |
| 976 |
@Defn2{Term=[calling convention], Sec=(protected)} |
| 977 |
The default calling convention is @i{protected} |
| 978 |
for a protected subprogram, |
| 979 |
and for an access-to-subprogram type with |
| 980 |
the reserved word @key(protected) in its definition. |
| 981 |
|
| 982 |
@Defn{entry calling convention} |
| 983 |
@Defn2{Term=[calling convention], Sec=(entry)} |
| 984 |
The default calling convention is @i{entry} for an entry. |
| 985 |
|
| 986 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01],ARef=[AI95-00409-01]} |
| 987 |
@ChgAdded{Version=[2],Text=[The calling convention for an |
| 988 |
anonymous access-to-subprogram parameter |
| 989 |
or anonymous access-to-subprogram result is @i<protected> if the reserved |
| 990 |
word @key{protected} appears in its definition and otherwise is the convention |
| 991 |
of the subprogram that contains the parameter.]} |
| 992 |
@begin{Ramification} |
| 993 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 994 |
@ChgAdded{Version=[2],Text=[The calling convention for other |
| 995 |
anonymous access-to-subprogram types is Ada.]} |
| 996 |
@end{Ramification} |
| 997 |
|
| 998 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 999 |
@Chg{Version=[1],New=[@Redundant[If not specified above as Intrinsic, the calling convention for any |
| 1000 |
inherited or overriding dispatching operation of a tagged type is that of the |
| 1001 |
corresponding subprogram of the parent type.] The default calling convention |
| 1002 |
for a new dispatching operation of a tagged type is the convention of the type.], |
| 1003 |
Old=[]} |
| 1004 |
@begin{Reason} |
| 1005 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1006 |
@ChgAdded{Version=[1],Text=[The first rule is officially stated in |
| 1007 |
@RefSecNum(Dispatching Operations of Tagged Types). The second is intended |
| 1008 |
to make interfacing to foreign OOP languages easier, by making the default |
| 1009 |
be that the type and operations all have the same convention.]} |
| 1010 |
@end{Reason} |
| 1011 |
@end{Itemize} |
| 1012 |
|
| 1013 |
Of these four conventions, only Ada and Intrinsic are |
| 1014 |
allowed as a @SynI{convention_}@nt{identifier} |
| 1015 |
in a @nt{pragma} Convention, Import, or Export. |
| 1016 |
@begin{Discussion} |
| 1017 |
The names of the @i{protected} and @i{entry} calling conventions |
| 1018 |
cannot be used in the interfacing pragmas. |
| 1019 |
Note that @key[protected] and @key[entry] are reserved words. |
| 1020 |
@end{Discussion} |
| 1021 |
|
| 1022 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00409-01]} |
| 1023 |
@Defn{type conformance} |
| 1024 |
@Defn2{Term=[profile],Sec=(type conformant)} |
| 1025 |
Two profiles |
| 1026 |
are @i{type conformant} if they have the same number of parameters, |
| 1027 |
and both have a result if either does, and corresponding |
| 1028 |
parameter and result types are the same, |
| 1029 |
or, for access parameters@Chg{Version=[2],New=[ or access results],Old=[]}, |
| 1030 |
corresponding designated types are the same@Chg{Version=[2],New=[, or |
| 1031 |
corresponding designated profiles are type conformant],Old=[]}. |
| 1032 |
@IndexSee{Term=[type profile],See=(profile, type conformant)} |
| 1033 |
@begin{Discussion} |
| 1034 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00409-01]} |
| 1035 |
For @Chg{Version=[2],New=[anonymous access-to-object],Old=[access]} |
| 1036 |
parameters, the designated types have to be the same for type |
| 1037 |
conformance, not the access types, |
| 1038 |
since in general each access parameter has its own anonymous access |
| 1039 |
type, created when the subprogram is called. |
| 1040 |
Of course, corresponding parameters have to be either both access |
| 1041 |
parameters or both not access parameters. |
| 1042 |
|
| 1043 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]} |
| 1044 |
@ChgAdded{Version=[2],Text=[Similarly, for anonymous access-to-subprogram |
| 1045 |
parameters, the designated profiles of the types, not the types themselves, |
| 1046 |
have to be conformant.]} |
| 1047 |
@end{Discussion} |
| 1048 |
|
| 1049 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00409-01]} |
| 1050 |
@Defn{mode conformance} |
| 1051 |
@Defn2{Term=[profile],Sec=(mode conformant)} |
| 1052 |
Two profiles are @i{mode conformant} if they are type-conformant, and |
| 1053 |
corresponding parameters have identical modes, and, for access |
| 1054 |
parameters@Chg{Version=[2],New=[ or access result types],Old=[]}, the |
| 1055 |
designated subtypes statically match@Chg{Version=[2],New=[, or the designated |
| 1056 |
profiles are subtype conformant.],Old=[]} |
| 1057 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 1058 |
|
| 1059 |
@Defn{subtype conformance} |
| 1060 |
@Defn2{Term=[profile],Sec=(subtype conformant)} |
| 1061 |
Two profiles are @i{subtype conformant} if they are mode-conformant, |
| 1062 |
corresponding subtypes of the profile statically match, |
| 1063 |
and the associated calling conventions are the same. |
| 1064 |
The profile of a generic formal subprogram is not subtype-conformant |
| 1065 |
with any other profile. |
| 1066 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 1067 |
|
| 1068 |
@begin{Ramification} |
| 1069 |
@PDefn{generic contract issue} |
| 1070 |
@end{Ramification} |
| 1071 |
|
| 1072 |
@Defn2{Term=[full conformance], Sec=(for profiles)} |
| 1073 |
@Defn2{Term=[profile],Sec=(fully conformant)} |
| 1074 |
Two profiles are @i{fully conformant} if they |
| 1075 |
are subtype-conformant, and corresponding parameters |
| 1076 |
have the same names and have @nt<default_expression>s that |
| 1077 |
are fully conformant with one another. |
| 1078 |
@begin{Ramification} |
| 1079 |
Full conformance requires subtype conformance, |
| 1080 |
which requires the same calling conventions. |
| 1081 |
However, the calling convention of the declaration and body of a |
| 1082 |
subprogram or entry are always the same by definition. |
| 1083 |
@end{Ramification} |
| 1084 |
|
| 1085 |
@leading@Defn2{Term=[full conformance], Sec=(for expressions)} |
| 1086 |
Two expressions are @i(fully conformant) if, |
| 1087 |
@Redundant[after replacing each use of an operator with the equivalent |
| 1088 |
@nt{function_call}:] |
| 1089 |
@begin{Itemize} |
| 1090 |
each constituent construct of one corresponds to an instance of the |
| 1091 |
same syntactic category in the other, |
| 1092 |
except that an expanded name may correspond |
| 1093 |
to a @nt{direct_name} |
| 1094 |
(or @nt{character_literal}) |
| 1095 |
or to a different expanded name in the other; and |
| 1096 |
|
| 1097 |
each @nt{direct_name}, @nt{character_literal}, and @nt{selector_name} |
| 1098 |
that is not part of the @nt{prefix} of an expanded name in one |
| 1099 |
denotes the same declaration as the corresponding |
| 1100 |
@nt{direct_name}, @nt{character_literal}, |
| 1101 |
or @nt{selector_name} in the other; and |
| 1102 |
@begin{Ramification} |
| 1103 |
Note that it doesn't say @lquotes@;respectively@rquotes@; |
| 1104 |
because a @nt{direct_name} can correspond to a @nt{selector_name}, |
| 1105 |
and vice-versa, by the previous bullet. |
| 1106 |
This rule allows the @nt{prefix} of an expanded name to be removed, |
| 1107 |
or replaced with a different @nt{prefix} that denotes a renaming of the |
| 1108 |
same entity. |
| 1109 |
However, it does not allow a @nt{direct_name} or @nt{selector_name} to |
| 1110 |
be replaced with one denoting a distinct renaming |
| 1111 |
(except for @nt{direct_name}s and @nt{selector_name}s in @nt{prefix}es |
| 1112 |
of expanded names). |
| 1113 |
Note that calls using operator notation |
| 1114 |
are equivalent to calls using prefix notation. |
| 1115 |
|
| 1116 |
@leading@keepnext@;Given the following declarations: |
| 1117 |
@begin{Example} |
| 1118 |
@key[package] A @key[is] |
| 1119 |
@key[function] F(X : Integer := 1) @key[return] Boolean; |
| 1120 |
@key[end] A; |
| 1121 |
|
| 1122 |
@key[with] A; |
| 1123 |
@key[package] B @key[is] |
| 1124 |
@key[package] A_View @key[renames] A; |
| 1125 |
@key[function] F_View(X : Integer := 9999) @key[return] Boolean @key[renames] F; |
| 1126 |
@key[end] B; |
| 1127 |
|
| 1128 |
@key[with] A, B; @key[use] A, B; |
| 1129 |
@key[procedure] Main @key[is] ... |
| 1130 |
@end{Example} |
| 1131 |
|
| 1132 |
Within Main, the expressions @lquotes@;F@rquotes@;, @lquotes@;A.F@rquotes@;, @lquotes@;B.A_View.F@rquotes@;, |
| 1133 |
and @lquotes@;A_View.F@rquotes@; are all fully conformant with one another. |
| 1134 |
However, @lquotes@;F@rquotes@; and @lquotes@;F_View@rquotes@; are not fully conformant. |
| 1135 |
If they were, it would be bad news, since the two denoted views have |
| 1136 |
different @nt{default_expression}s. |
| 1137 |
@end{Ramification} |
| 1138 |
|
| 1139 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0018],ARef=[AI95-00175-01]} |
| 1140 |
@Chg{New=[each @nt{attribute_designator} in one must be the same as the |
| 1141 |
corresponding @nt{attribute_designator} in the other; and],Old=[]} |
| 1142 |
|
| 1143 |
each @nt{primary} that is a literal in one |
| 1144 |
has the same value as the corresponding literal in the other. |
| 1145 |
@begin{Ramification} |
| 1146 |
The literals may be written differently. |
| 1147 |
@end{Ramification} |
| 1148 |
@end{Itemize} |
| 1149 |
@begin{Ramification} |
| 1150 |
Note that the above definition makes full conformance a transitive |
| 1151 |
relation. |
| 1152 |
@end{Ramification} |
| 1153 |
|
| 1154 |
@Defn2{Term=[full conformance], Sec=(for @nt{known_discriminant_part}s)} |
| 1155 |
Two @nt{known_discriminant_part}s are @i(fully conformant) if they have |
| 1156 |
the same number of discriminants, and |
| 1157 |
discriminants in the same positions |
| 1158 |
have the same names, statically matching subtypes, |
| 1159 |
and @nt{default_expression}s that are fully conformant with |
| 1160 |
one another. |
| 1161 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 1162 |
|
| 1163 |
@Defn2{Term=[full conformance], Sec=(for @nt{discrete_subtype_definition}s)} |
| 1164 |
Two @nt<discrete_subtype_definition>s are @i(fully conformant) if they |
| 1165 |
are both @nt<subtype_indication>s or are both @nt<range>s, |
| 1166 |
the @nt<subtype_mark>s (if any) denote the same subtype, and |
| 1167 |
the corresponding @nt<simple_expression>s of the @nt<range>s (if any) |
| 1168 |
fully conform. |
| 1169 |
@begin{Ramification} |
| 1170 |
In the @nt{subtype_indication} case, any ranges have to @i{be} |
| 1171 |
corresponding; that is, two @nt{subtype_indication}s cannot conform |
| 1172 |
unless both or neither has a @nt{range}. |
| 1173 |
@end{Ramification} |
| 1174 |
@begin{Discussion} |
| 1175 |
This definition is used in @RefSec(Entries and Accept Statements) |
| 1176 |
for the conformance required between the @nt<discrete_subtype_definition>s |
| 1177 |
of an @nt<entry_declaration> for a family of entries and the |
| 1178 |
corresponding @nt<entry_index_specification> of the @nt<entry_body>. |
| 1179 |
@end{Discussion} |
| 1180 |
|
| 1181 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01]} |
| 1182 |
@ChgAdded{Version=[2],Text=[@Defn{prefixed view profile} |
| 1183 |
The @i<prefixed view profile> of a subprogram is the profile obtained by |
| 1184 |
omitting the first parameter of that subprogram. There is no prefixed view |
| 1185 |
profile for a parameterless subprogram. For the purposes of defining subtype |
| 1186 |
and mode conformance, the convention of a prefixed view profile is considered |
| 1187 |
to match that of either an entry or a protected operation.]} |
| 1188 |
|
| 1189 |
@begin{Discussion} |
| 1190 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1191 |
@ChgAdded{Version=[2],Text=[This definition is used to define how |
| 1192 |
primitive subprograms of interfaces match operations in task and |
| 1193 |
protected type definitions (see @RefSecNum{Task Units and Task Objects} and |
| 1194 |
@RefSecNum{Protected Units and Protected Objects}).]} |
| 1195 |
@end{Discussion} |
| 1196 |
@begin{Reason} |
| 1197 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1198 |
@ChgAdded{Version=[2],Text=[The weird rule about conventions is pretty much |
| 1199 |
required for synchronized interfaces to make any sense. There will be |
| 1200 |
wrappers all over the place for interfaces anyway. Of course, this doesn't |
| 1201 |
imply that entries have the same convention as protected operations.]} |
| 1202 |
@end{Reason} |
| 1203 |
@end{StaticSem} |
| 1204 |
|
| 1205 |
@begin{ImplPerm} |
| 1206 |
|
| 1207 |
An implementation may declare an operator declared in a language-defined |
| 1208 |
library unit to be intrinsic. |
| 1209 |
|
| 1210 |
@end{ImplPerm} |
| 1211 |
|
| 1212 |
@begin{Extend83} |
| 1213 |
@Defn{extensions to Ada 83} |
| 1214 |
The rules for full conformance are relaxed @em they are now based on |
| 1215 |
the structure of constructs, rather than the sequence of lexical |
| 1216 |
elements. This implies, for example, that "(X, Y: T)" |
| 1217 |
conforms fully with "(X: T; Y: T)", |
| 1218 |
and "(X: T)" conforms fully with "(X: @key[in] T)". |
| 1219 |
@end{Extend83} |
| 1220 |
|
| 1221 |
@begin{DiffWord95} |
| 1222 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 1223 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the default |
| 1224 |
convention is Ada. Also clarified that the convention of a primitive |
| 1225 |
operation of a tagged type is the same as that of the type.]} |
| 1226 |
|
| 1227 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0018],ARef=[AI95-00175-01]} |
| 1228 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to ensure that two |
| 1229 |
attributes conform only if they have the same @nt{attribute_designator}.]} |
| 1230 |
|
| 1231 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00252-01],ARef=[AI95-00254-01],ARef=[AI95-00407-01]} |
| 1232 |
@ChgAdded{Version=[2],Text=[Defined the calling convention for anonymous |
| 1233 |
access-to-subprogram types and for prefixed views of subprograms (see |
| 1234 |
@RefSecNum{Selected Components}).]} |
| 1235 |
|
| 1236 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 1237 |
@ChgAdded{Version=[2],Text=[Defined the conformance of access result types |
| 1238 |
(see @RefSecNum{Subprogram Declarations}).]} |
| 1239 |
|
| 1240 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00397-01]} |
| 1241 |
@ChgAdded{Version=[2],Text=[Defined the prefixed view profile of subprograms |
| 1242 |
for later use.]} |
| 1243 |
|
| 1244 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]} |
| 1245 |
@ChgAdded{Version=[2],Text=[Defined the conformance of anonymous |
| 1246 |
access-to-subprogram parameters.]} |
| 1247 |
@end{DiffWord95} |
| 1248 |
|
| 1249 |
|
| 1250 |
@LabeledSubClause{Inline Expansion of Subprograms} |
| 1251 |
|
| 1252 |
@begin{Intro} |
| 1253 |
@Redundant[Subprograms may be expanded in line at the call site.] |
| 1254 |
@end{Intro} |
| 1255 |
|
| 1256 |
@begin{Syntax} |
| 1257 |
@begin{SyntaxText} |
| 1258 |
@leading@keepnext@PDefn2{Term=[program unit pragma], Sec=(Inline)} |
| 1259 |
@PDefn2{Term=[pragma, program unit], Sec=(Inline)} |
| 1260 |
The form of a @nt{pragma} Inline, |
| 1261 |
which is a program unit pragma (see @RefSecNum{Pragmas and Program Units}), |
| 1262 |
is as follows: |
| 1263 |
@end{SyntaxText} |
| 1264 |
|
| 1265 |
@PragmaSyn`@key{pragma} @prag(Inline)(@Syn2{name} {, @Syn2{name}});' |
| 1266 |
@end{Syntax} |
| 1267 |
|
| 1268 |
@begin{Legality} |
| 1269 |
The @nt{pragma} shall apply to one or more callable entities |
| 1270 |
or generic subprograms. |
| 1271 |
@end{Legality} |
| 1272 |
|
| 1273 |
@begin{StaticSem} |
| 1274 |
If a @nt{pragma} Inline applies to a callable entity, |
| 1275 |
this indicates that inline expansion is desired for all calls |
| 1276 |
to that entity. |
| 1277 |
If a @nt{pragma} Inline applies to a generic subprogram, |
| 1278 |
this indicates that inline expansion is desired for all calls |
| 1279 |
to all instances of that generic subprogram. |
| 1280 |
@begin{Ramification} |
| 1281 |
@leading@;Note that inline expansion is desired no matter what |
| 1282 |
name is used in the call. |
| 1283 |
This allows one to request inlining for only one of several |
| 1284 |
overloaded subprograms as follows: |
| 1285 |
@begin{Example} |
| 1286 |
@key[package] IO @key[is] |
| 1287 |
@key[procedure] Put(X : @key[in] Integer); |
| 1288 |
@key[procedure] Put(X : @key[in] String); |
| 1289 |
@key[procedure] Put(X : @key[in] Character); |
| 1290 |
@key[private] |
| 1291 |
@key[procedure] Character_Put(X : @key[in] Character) @key[renames] Put; |
| 1292 |
@key[pragma] Inline(Character_Put); |
| 1293 |
@key[end] IO; |
| 1294 |
|
| 1295 |
@key[with] IO; @key[use] IO; |
| 1296 |
@key[procedure] Main @key[is] |
| 1297 |
I : Integer; |
| 1298 |
C : Character; |
| 1299 |
@key[begin] |
| 1300 |
... |
| 1301 |
Put(C); --@RI{ Inline expansion is desired.} |
| 1302 |
Put(I); --@RI{ Inline expansion is NOT desired.} |
| 1303 |
@key[end] Main; |
| 1304 |
@end{Example} |
| 1305 |
@end{Ramification} |
| 1306 |
@begin{Ramification} |
| 1307 |
The meaning of a subprogram can be changed by a @nt{pragma} Inline only |
| 1308 |
in the presence of failing checks |
| 1309 |
(see @RefSecNum{Exceptions and Optimization}). |
| 1310 |
@end{Ramification} |
| 1311 |
@end{StaticSem} |
| 1312 |
|
| 1313 |
@begin{ImplPerm} |
| 1314 |
For each call, |
| 1315 |
an implementation is free to follow or to ignore the recommendation |
| 1316 |
expressed by the @nt{pragma}. |
| 1317 |
@begin{Ramification} |
| 1318 |
Note, in particular, that the recommendation |
| 1319 |
cannot always be followed for a recursive call, |
| 1320 |
and is often infeasible for entries. |
| 1321 |
Note also that the implementation can inline calls even |
| 1322 |
when no such desire was expressed by a pragma, |
| 1323 |
so long as the semantics of the program remains unchanged. |
| 1324 |
@end{Ramification} |
| 1325 |
|
| 1326 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00309-01]} |
| 1327 |
@Chg{Version=[2],New=[An implementation may allow a @nt{pragma} Inline that has |
| 1328 |
an argument which is a @nt{direct_name} denoting a @nt{subprogram_body} of the |
| 1329 |
same @nt{declarative_part}.],Old=[]} |
| 1330 |
@begin{Reason} |
| 1331 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1332 |
@ChgAdded{Version=[2],Text=[This is allowed for Ada 83 compatibility. This is |
| 1333 |
only a permission as this usage is considered obsolescent.]} |
| 1334 |
@end{Reason} |
| 1335 |
@begin{Discussion} |
| 1336 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1337 |
@ChgAdded{Version=[2],Text=[We only need to allow this in @nt{declarative_part}s, |
| 1338 |
because a body is only allowed in another body, and these all have |
| 1339 |
@nt{declarative_part}s.]} |
| 1340 |
@end{Discussion} |
| 1341 |
@end{ImplPerm} |
| 1342 |
|
| 1343 |
@begin{Notes} |
| 1344 |
The @nt{name} in a @nt{pragma} Inline can denote |
| 1345 |
more than one entity in the case of overloading. |
| 1346 |
Such a @nt{pragma} applies to all of the denoted entities. |
| 1347 |
@end{Notes} |
| 1348 |
|
| 1349 |
@begin{Incompatible83} |
| 1350 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00309-01]} |
| 1351 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 83} |
| 1352 |
A pragma Inline cannot refer to a @nt{subprogram_body} outside of that |
| 1353 |
body. The pragma can be given inside of the subprogram body. Ada 2005 |
| 1354 |
adds an @ImplPermName to allow this usage for compatibility (and |
| 1355 |
Ada 95 implementations also can use this permission), but |
| 1356 |
implementations do not have to allow such @nt{pragma}s.]} |
| 1357 |
@end{Incompatible83} |
| 1358 |
|
| 1359 |
@begin{Extend83} |
| 1360 |
@Defn{extensions to Ada 83} |
| 1361 |
A @nt{pragma} Inline is allowed inside a @nt{subprogram_body} if there |
| 1362 |
is no corresponding @nt{subprogram_declaration}. |
| 1363 |
This is for uniformity with other program unit pragmas. |
| 1364 |
@end{Extend83} |
| 1365 |
|
| 1366 |
@begin{Extend95} |
| 1367 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00309-01]} |
| 1368 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1369 |
@b[Amendment Correction:] Implementations are allowed to let @nt{Pragma} |
| 1370 |
Inline apply to a @nt{subprogram_body}.]} |
| 1371 |
@end{Extend95} |
| 1372 |
|
| 1373 |
|
| 1374 |
@RMNewPage@Comment{For printed RM Ada 2005 only} |
| 1375 |
@LabeledClause{Subprogram Calls} |
| 1376 |
|
| 1377 |
@begin{Intro} |
| 1378 |
@Defn{subprogram call} |
| 1379 |
A @i{subprogram call} is either a @nt{procedure_call_statement} |
| 1380 |
or a @nt{function_call}; |
| 1381 |
@Redundant[it invokes the execution of the @nt{subprogram_body}. |
| 1382 |
The call specifies the association of the actual parameters, if any, |
| 1383 |
with formal parameters of the subprogram.] |
| 1384 |
@end{Intro} |
| 1385 |
|
| 1386 |
@begin{Syntax} |
| 1387 |
@Syn{lhs=<procedure_call_statement>,rhs=" |
| 1388 |
@SynI{procedure_}@Syn2{name}; |
| 1389 |
| @SynI{procedure_}@Syn2{prefix} @Syn2{actual_parameter_part};"} |
| 1390 |
|
| 1391 |
|
| 1392 |
@Syn{lhs=<function_call>,rhs=" |
| 1393 |
@SynI{function_}@Syn2{name} |
| 1394 |
| @SynI{function_}@Syn2{prefix} @Syn2{actual_parameter_part}"} |
| 1395 |
|
| 1396 |
@Syn{lhs=<actual_parameter_part>,rhs=" |
| 1397 |
(@Syn2{parameter_association} {, @Syn2{parameter_association}})"} |
| 1398 |
|
| 1399 |
@Syn{lhs=<parameter_association>,rhs=" |
| 1400 |
[@SynI{formal_parameter_}@Syn2{selector_name} =>] @Syn2{explicit_actual_parameter}"} |
| 1401 |
|
| 1402 |
@Syn{lhs=<explicit_actual_parameter>,rhs="@Syn2{expression} | @SynI{variable_}@Syn2{name}"} |
| 1403 |
|
| 1404 |
@begin{SyntaxText} |
| 1405 |
@Defn{named association} |
| 1406 |
@Defn{positional association} |
| 1407 |
A @nt{parameter_association} is @i{named} or @i{positional} |
| 1408 |
according to whether or not the |
| 1409 |
@SynI{formal_@!parameter_}@!@nt{selector_@!name} is specified. |
| 1410 |
Any positional associations shall precede any named associations. |
| 1411 |
Named associations are not allowed if the @nt{prefix} in |
| 1412 |
a subprogram call is an @nt{attribute_@!reference}. |
| 1413 |
@begin{Ramification} |
| 1414 |
This means that the formal parameter names used in |
| 1415 |
describing predefined attributes are |
| 1416 |
to aid presentation of their semantics, but are not intended |
| 1417 |
for use in actual calls. |
| 1418 |
@end{Ramification} |
| 1419 |
@end{SyntaxText} |
| 1420 |
@end{Syntax} |
| 1421 |
|
| 1422 |
@begin{Resolution} |
| 1423 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]} |
| 1424 |
The @nt{name} or @nt{prefix} given in a @nt{procedure_call_statement} |
| 1425 |
shall resolve to denote |
| 1426 |
a callable entity that is a procedure, or an entry renamed |
| 1427 |
as (viewed as) a procedure. |
| 1428 |
The @nt{name} or @nt{prefix} given in a @nt{function_call} |
| 1429 |
shall resolve to denote |
| 1430 |
a callable entity that is a |
| 1431 |
function.@Chg{Version=[2],New=[ The @nt{name} or @nt{prefix} shall not |
| 1432 |
resolve to denote an abstract subprogram unless it is also a |
| 1433 |
dispatching subprogram.],Old=[]} |
| 1434 |
@Redundant[When there is an @nt<actual_@!parameter_@!part>, the @nt<prefix> |
| 1435 |
can be an @nt<implicit_@!dereference> of an access-to-subprogram |
| 1436 |
value.] |
| 1437 |
@begin{Discussion} |
| 1438 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00310-01]} |
| 1439 |
@ChgAdded{Version=[2],Text=[This rule is talking about dispatching operations |
| 1440 |
(which is a static concept) and not about dispatching calls (which is a |
| 1441 |
dynamic concept).]} |
| 1442 |
@end{Discussion} |
| 1443 |
@begin{Ramification} |
| 1444 |
The function can be an operator, |
| 1445 |
enumeration literal, attribute that is a function, etc. |
| 1446 |
@end{Ramification} |
| 1447 |
|
| 1448 |
A subprogram call shall contain at most one association for each |
| 1449 |
formal parameter. |
| 1450 |
Each formal parameter without an association shall have a |
| 1451 |
@nt{default_expression} (in the profile of the view denoted |
| 1452 |
by the @nt<name> or @nt<prefix>). |
| 1453 |
This rule is an overloading rule |
| 1454 |
(see @RefSecNum{The Context of Overload Resolution}). |
| 1455 |
@end{Resolution} |
| 1456 |
|
| 1457 |
@begin{RunTime} |
| 1458 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]} |
| 1459 |
@PDefn2{Term=[execution], Sec=(subprogram call)} |
| 1460 |
For the execution of a subprogram call, |
| 1461 |
the @nt{name} or @nt{prefix} of the call is evaluated, |
| 1462 |
and each @nt{parameter_@!association} is evaluated |
| 1463 |
(see @RefSecNum{Parameter Associations}). |
| 1464 |
If a @nt{default_@!expression} is used, |
| 1465 |
an implicit @nt{parameter_@!association} is assumed for this rule. |
| 1466 |
These evaluations are done in an arbitrary order. |
| 1467 |
The @nt{subprogram_@!body} is then executed@Chg{Version=[2],New=[, or a call |
| 1468 |
on an entry or protected subprogram is performed (see |
| 1469 |
@RefSecNum{Dispatching Operations of Tagged Types})],Old=[]}. |
| 1470 |
Finally, if the subprogram completes normally, then after it is left, |
| 1471 |
any necessary assigning back of formal to actual parameters occurs |
| 1472 |
(see @RefSecNum{Parameter Associations}). |
| 1473 |
|
| 1474 |
@begin{Discussion} |
| 1475 |
The implicit association for a default is only for this run-time rule. |
| 1476 |
At compile time, the visibility rules are applied to the default at |
| 1477 |
the place where it occurs, not at the place of a call. |
| 1478 |
@end{Discussion} |
| 1479 |
@begin{Honest} |
| 1480 |
If the subprogram is inherited, see @RefSec{Derived Types and Classes}. |
| 1481 |
|
| 1482 |
If the subprogram is protected, see @RefSec{Protected Subprograms and Protected Actions}. |
| 1483 |
|
| 1484 |
If the subprogram is really a renaming of an entry, see @RefSec{Entry Calls}. |
| 1485 |
|
| 1486 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]} |
| 1487 |
@ChgAdded{Version=[2],Text=[If the subprogram is implemented by an entry or |
| 1488 |
protected subprogram, it will be treated as a dispatching call to the |
| 1489 |
corresponding entry (see @RefSec{Entry Calls}) or protected subprogram (see |
| 1490 |
@RefSec{Protected Subprograms and Protected Actions}).]} |
| 1491 |
|
| 1492 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 1493 |
Normally, the @nt{subprogram_body} that is executed by the above rule |
| 1494 |
is the one for the subprogram being called. |
| 1495 |
For an enumeration literal, |
| 1496 |
implicitly declared (but noninherited) subprogram, |
| 1497 |
@Chg{Version=[2],New=[null procedure, ],Old=[]}or an attribute that is |
| 1498 |
a subprogram, an implicit body is assumed. |
| 1499 |
For a dispatching call, |
| 1500 |
@RefSec{Dispatching Operations of Tagged Types} |
| 1501 |
defines which @nt{subprogram_body} is executed. |
| 1502 |
@end{Honest} |
| 1503 |
|
| 1504 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00407-01]} |
| 1505 |
@ChgAdded{Version=[2],Text=[If the @nt{name} or @nt{prefix} of a subprogram |
| 1506 |
call denotes a prefixed view (see @RefSecNum{Selected Components}), the |
| 1507 |
subprogram call is equivalent to a call on the underlying subprogram, with the |
| 1508 |
first actual parameter being provided by the @nt{prefix} of the prefixed view |
| 1509 |
(or the Access attribute of this @nt{prefix} if the first formal parameter is |
| 1510 |
an access parameter), and the remaining actual parameters given by the |
| 1511 |
@nt{actual_parameter_part}, if any.]} |
| 1512 |
|
| 1513 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1514 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 1515 |
The exception Program_Error is raised at the point of a |
| 1516 |
@nt{function_call} if the function |
| 1517 |
completes normally without executing a |
| 1518 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}. |
| 1519 |
@begin{Discussion} |
| 1520 |
We are committing to raising the exception at the point |
| 1521 |
of call, for uniformity @em see AI83-00152. |
| 1522 |
This happens after the function is left, of course. |
| 1523 |
|
| 1524 |
Note that there is no name for suppressing this check, |
| 1525 |
since the check imposes no time overhead and minimal |
| 1526 |
space overhead (since it can usually be statically eliminated |
| 1527 |
as dead code). |
| 1528 |
@end{Discussion} |
| 1529 |
|
| 1530 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 1531 |
A @nt{function_call} denotes a constant, as defined in |
| 1532 |
@RefSecNum{Return Statements}; the nominal subtype of the constant is |
| 1533 |
given by the @Chg{Version=[2],New=[nominal],Old=[result]} subtype of the |
| 1534 |
function@Chg{Version=[2],New=[ result],Old=[]}. |
| 1535 |
@PDefn2{Term=[nominal subtype], Sec=(of the result of a @nt<function_call>)} |
| 1536 |
@PDefn2{Term=[constant], Sec=(result of a @nt<function_call>)} |
| 1537 |
@end{RunTime} |
| 1538 |
|
| 1539 |
@begin{Examples} |
| 1540 |
@leading@keepnext@i{Examples of procedure calls:} |
| 1541 |
@begin{Example} |
| 1542 |
Traverse_Tree; --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 1543 |
Print_Header(128, Title, True); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 1544 |
|
| 1545 |
Switch(From => X, To => Next); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 1546 |
Print_Header(128, Header => Title, Center => True); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 1547 |
Print_Header(Header => Title, Center => True, Pages => 128); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 1548 |
@end{Example} |
| 1549 |
|
| 1550 |
@begin{Wide} |
| 1551 |
@leading@keepnext@i{Examples of function calls:} |
| 1552 |
@end{Wide} |
| 1553 |
@begin{Example} |
| 1554 |
Dot_Product(U, V) --@RI{ see @RefSecNum{Subprogram Declarations} and @RefSecNum{Subprogram Bodies}} |
| 1555 |
Clock --@RI{ see @RefSecNum{Delay Statements, Duration, and Time}} |
| 1556 |
F.@key[all] --@RI{ presuming F is of an access-to-subprogram type @em see @RefSecNum{Access Types}} |
| 1557 |
@end{Example} |
| 1558 |
|
| 1559 |
@begin{Wide} |
| 1560 |
@leading@keepnext@i{Examples of procedures with default expressions:} |
| 1561 |
@end{Wide} |
| 1562 |
@begin{Example} |
| 1563 |
@key[procedure] Activate(Process : @key[in] Process_Name; |
| 1564 |
After : @key[in] Process_Name := No_Process; |
| 1565 |
Wait : @key[in] Duration := 0.0; |
| 1566 |
Prior : @key[in] Boolean := False); |
| 1567 |
|
| 1568 |
@key[procedure] Pair(Left, Right : @key[in] Person_Name := @key[new] Person); --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 1569 |
@end{Example} |
| 1570 |
|
| 1571 |
@begin{Wide} |
| 1572 |
@leading@keepnext@i{Examples of their calls:} |
| 1573 |
@end{Wide} |
| 1574 |
@begin{Example} |
| 1575 |
Activate(X); |
| 1576 |
Activate(X, After => Y); |
| 1577 |
Activate(X, Wait => 60.0, Prior => True); |
| 1578 |
Activate(X, Y, 10.0, False); |
| 1579 |
|
| 1580 |
Pair; |
| 1581 |
Pair(Left => @key[new] Person, Right => @key[new] Person); |
| 1582 |
@end{Example} |
| 1583 |
@end{Examples} |
| 1584 |
|
| 1585 |
@begin{Notes} |
| 1586 |
If a @nt{default_expression} is used for two or more parameters in a |
| 1587 |
multiple @nt{parameter_@!specification}, the @nt{default_@!expression} is |
| 1588 |
evaluated once for each omitted parameter. Hence in the above |
| 1589 |
examples, the two calls of Pair are equivalent. |
| 1590 |
@end{Notes} |
| 1591 |
|
| 1592 |
@begin{Examples} |
| 1593 |
@leading@keepnext@i{Examples of overloaded subprograms:} |
| 1594 |
@begin{Example} |
| 1595 |
@key[procedure] Put(X : @key[in] Integer); |
| 1596 |
@key[procedure] Put(X : @key[in] String); |
| 1597 |
|
| 1598 |
@key[procedure] Set(Tint : @key[in] Color); |
| 1599 |
@key[procedure] Set(Signal : @key[in] Light); |
| 1600 |
@end{Example} |
| 1601 |
|
| 1602 |
@begin{Wide} |
| 1603 |
@leading@keepnext@i{Examples of their calls:} |
| 1604 |
@end{Wide} |
| 1605 |
@begin{Example} |
| 1606 |
Put(28); |
| 1607 |
Put("no possible ambiguity here"); |
| 1608 |
|
| 1609 |
Set(Tint => Red); |
| 1610 |
Set(Signal => Red); |
| 1611 |
Set(Color'(Red)); |
| 1612 |
|
| 1613 |
--@RI{ Set(Red) would be ambiguous since Red may} |
| 1614 |
--@RI{ denote a value either of type Color or of type Light} |
| 1615 |
@end{Example} |
| 1616 |
@end{Examples} |
| 1617 |
|
| 1618 |
@begin{DiffWord83} |
| 1619 |
We have gotten rid of parameters @lquotes@;of the form of a type conversion@rquotes@; |
| 1620 |
(see RM83-6.4.1(3)). |
| 1621 |
The new view semantics of @nt{type_conversion}s allows us to use |
| 1622 |
normal @nt{type_conversion}s instead. |
| 1623 |
|
| 1624 |
We have moved wording about run-time semantics of parameter associations |
| 1625 |
to @RefSecNum{Parameter Associations}. |
| 1626 |
|
| 1627 |
We have moved wording about raising Program_Error for a function |
| 1628 |
that falls off the end to here from RM83-6.5. |
| 1629 |
@end{DiffWord83} |
| 1630 |
|
| 1631 |
@begin{Extend95} |
| 1632 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00310-01]} |
| 1633 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 1634 |
Nondispatching abstract operations are no longer considered when |
| 1635 |
resolving a subprogram call. That makes it possible to use @key{abstract} |
| 1636 |
to @lquotes@;undefine@rquotes@; a predefined operation for an untagged type. |
| 1637 |
That's especially helpful when defining custom arithmetic packages.]} |
| 1638 |
@end{Extend95} |
| 1639 |
|
| 1640 |
@begin{DiffWord95} |
| 1641 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]} |
| 1642 |
@ChgAdded{Version=[2],Text=[Changed the definition of the nominal subtype |
| 1643 |
of a @nt{function_call} to use the nominal subtype wording of |
| 1644 |
@RefSecNum{Subprogram Declarations}, to take into account |
| 1645 |
@nt{null_exclusion}s and access result types.]} |
| 1646 |
|
| 1647 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]} |
| 1648 |
@ChgAdded{Version=[2],Text=[Added wording to clarify that the meaning of |
| 1649 |
a call on a subprogram @lquotes@;implemented by@rquotes an entry or |
| 1650 |
protected operation is defined by |
| 1651 |
@RefSecNum{Dispatching Operations of Tagged Types}.]} |
| 1652 |
|
| 1653 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00407-01]} |
| 1654 |
@ChgAdded{Version=[2],Text=[Defined the meaning of a call on a prefixed |
| 1655 |
view of a subprogram (see @RefSecNum{Selected Components}).]} |
| 1656 |
@end{DiffWord95} |
| 1657 |
|
| 1658 |
|
| 1659 |
@LabeledSubClause{Parameter Associations} |
| 1660 |
|
| 1661 |
@begin{Intro} |
| 1662 |
@Redundant[@Defn{parameter passing} |
| 1663 |
A parameter association defines the association between an |
| 1664 |
actual parameter and a formal parameter.] |
| 1665 |
@end{Intro} |
| 1666 |
|
| 1667 |
@begin{MetaRules} |
| 1668 |
The parameter passing rules for @b(out) parameters |
| 1669 |
are designed to ensure that the parts of a type that have |
| 1670 |
implicit initial values (see @RefSecNum{Object Declarations}) |
| 1671 |
don't become @lquotes@;de-initialized@rquotes@; by |
| 1672 |
being passed as an @b(out) parameter. |
| 1673 |
@end{MetaRules} |
| 1674 |
|
| 1675 |
@begin{Resolution} |
| 1676 |
The @SynI{formal_parameter_}@nt{selector_name} of a |
| 1677 |
@nt{parameter_@!association} shall resolve to denote a |
| 1678 |
@nt{parameter_@!specification} of the view being called. |
| 1679 |
|
| 1680 |
@Defn2{Term=[actual parameter], Sec=(for a formal parameter)} |
| 1681 |
The @i(actual parameter) is either the @nt<explicit_actual_parameter> |
| 1682 |
given in a @nt<parameter_association> for a given |
| 1683 |
formal parameter, or the corresponding @nt<default_expression> |
| 1684 |
if no @nt<parameter_association> is given for the formal parameter. |
| 1685 |
@Defn2{Term=[expected type], Sec=(actual parameter)} |
| 1686 |
The expected type for an actual parameter is the |
| 1687 |
type of the corresponding formal parameter. |
| 1688 |
@begin{Honest} |
| 1689 |
The corresponding @nt<default_expression> is the one of the |
| 1690 |
corresponding formal parameter |
| 1691 |
in the profile of the view denoted by the @nt<name> or |
| 1692 |
@nt<prefix> of the call. |
| 1693 |
@end{Honest} |
| 1694 |
|
| 1695 |
If the mode is @key(in), |
| 1696 |
the actual is interpreted as an @nt{expression}; |
| 1697 |
otherwise, the actual is interpreted only as a @nt{name}, if possible. |
| 1698 |
@begin{Ramification} |
| 1699 |
This formally resolves the ambiguity present in the syntax rule |
| 1700 |
for @nt<explicit_actual_parameter>. Note that we don't actually require |
| 1701 |
that the actual be a @nt<name> if the mode is not @key(in); |
| 1702 |
we do that below. |
| 1703 |
@end{Ramification} |
| 1704 |
@end{Resolution} |
| 1705 |
|
| 1706 |
@begin{Legality} |
| 1707 |
If the mode is @key(in out) or @key(out), |
| 1708 |
the actual shall be a @nt<name> that denotes a variable. |
| 1709 |
@begin{Discussion} |
| 1710 |
We no longer need @lquotes@;or a |
| 1711 |
@nt{type_conversion} whose argument is the @nt{name} of a variable,@rquotes@; |
| 1712 |
because a @nt{type_conversion} is now a @nt{name}, and a |
| 1713 |
@nt{type_conversion} of a variable is a variable. |
| 1714 |
@end{Discussion} |
| 1715 |
@begin{Reason} |
| 1716 |
@leading@;The requirement that the actual be a (variable) @nt<name> is not |
| 1717 |
an overload resolution rule, since |
| 1718 |
we don't want the difference between @nt<expression> and |
| 1719 |
@nt{name} to be used to resolve overloading. |
| 1720 |
For example: |
| 1721 |
@begin{Example} |
| 1722 |
procedure Print(X : @key[in] Integer; Y : @key[in] Boolean := True); |
| 1723 |
procedure Print(Z : @key[in out] Integer); |
| 1724 |
. . . |
| 1725 |
Print(3); --@RI{ Ambiguous!} |
| 1726 |
@end{Example} |
| 1727 |
|
| 1728 |
The above call to Print is ambiguous even though the call is |
| 1729 |
not compatible with the second Print which requires an actual |
| 1730 |
that is a (variable) @nt<name> (@lquotes@;3@rquotes@; is an @nt<expression>, not |
| 1731 |
a @nt<name>). This requirement is a legality rule, so overload |
| 1732 |
resolution fails before it is considered, meaning that the call |
| 1733 |
is ambiguous. |
| 1734 |
@end{Reason} |
| 1735 |
|
| 1736 |
The type of the actual parameter associated with an access parameter |
| 1737 |
shall be convertible (see @RefSecNum{Type Conversions}) |
| 1738 |
to its anonymous access type. |
| 1739 |
@PDefn2{Term=[convertible],Sec=(required)} |
| 1740 |
@end{Legality} |
| 1741 |
|
| 1742 |
@begin{RunTime} |
| 1743 |
@leading@keepnext@PDefn2{Term=[evaluation], Sec=(parameter_association)} |
| 1744 |
For the evaluation of a @nt{parameter_association}: |
| 1745 |
@begin{Itemize} |
| 1746 |
The actual parameter is first evaluated. |
| 1747 |
|
| 1748 |
For an access parameter, |
| 1749 |
the @nt{access_definition} is elaborated, |
| 1750 |
which creates the anonymous access type. |
| 1751 |
|
| 1752 |
For a parameter @Redundant[(of any mode)] that is passed by reference |
| 1753 |
(see @RefSecNum{Formal Parameter Modes}), |
| 1754 |
a view conversion of the actual parameter to the nominal subtype |
| 1755 |
of the formal parameter is evaluated, |
| 1756 |
and the formal parameter denotes that conversion. |
| 1757 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 1758 |
@begin{Discussion} |
| 1759 |
We are always allowing sliding, even for [@key(in)[ @key(out) by-reference |
| 1760 |
parameters. |
| 1761 |
@end{Discussion} |
| 1762 |
|
| 1763 |
@Defn2{Term=[assignment operation], Sec=(during evaluation of a |
| 1764 |
@nt{parameter_association})} |
| 1765 |
For an @key(in) or @key(in out) parameter that is passed |
| 1766 |
by copy (see @RefSecNum{Formal Parameter Modes}), |
| 1767 |
the formal parameter object is created, |
| 1768 |
and the value of the actual parameter is converted to the |
| 1769 |
nominal subtype of the formal parameter |
| 1770 |
and assigned to the formal. |
| 1771 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 1772 |
@begin{Ramification} |
| 1773 |
The conversion mentioned here is a value conversion. |
| 1774 |
@end{Ramification} |
| 1775 |
|
| 1776 |
@leading@keepnext@;For an @key(out) parameter that is passed by copy, |
| 1777 |
the formal parameter object is created, and: |
| 1778 |
@begin(itemize) |
| 1779 |
For an access type, the formal parameter is initialized |
| 1780 |
from the value of the actual, without a constraint check; |
| 1781 |
@begin{Reason} |
| 1782 |
This preserves the @MetaRulesName that an object of an access type |
| 1783 |
is always initialized with a @lquotes@;reasonable@rquotes@; value. |
| 1784 |
@end{Reason} |
| 1785 |
|
| 1786 |
For a composite type with discriminants or |
| 1787 |
that has implicit initial values for any subcomponents |
| 1788 |
(see @RefSecNum{Object Declarations}), |
| 1789 |
the behavior is as for an @key[in out] parameter |
| 1790 |
passed by copy. |
| 1791 |
@begin{Reason} |
| 1792 |
This ensures that no part of an object of such a type |
| 1793 |
can become @lquotes@;de-initialized@rquotes@; by being part of an @b(out) |
| 1794 |
parameter. |
| 1795 |
@end{Reason} |
| 1796 |
@begin{Ramification} |
| 1797 |
This includes an array type whose component type is an access type, |
| 1798 |
and a record type with a component that has a @nt{default_expression}, |
| 1799 |
among other things. |
| 1800 |
@end{Ramification} |
| 1801 |
|
| 1802 |
For any other type, the formal parameter is uninitialized. |
| 1803 |
If composite, a view conversion of the actual |
| 1804 |
parameter to the nominal subtype of the formal is evaluated |
| 1805 |
@Redundant[(which might raise Constraint_Error)], |
| 1806 |
and the actual subtype of the formal is that of the |
| 1807 |
view conversion. If elementary, the actual subtype of the formal |
| 1808 |
is given by its nominal subtype. |
| 1809 |
@begin{Ramification} |
| 1810 |
This case covers scalar types, and composite types whose |
| 1811 |
subcomponent's subtypes do not have any implicit initial |
| 1812 |
values. |
| 1813 |
The view conversion for composite types ensures that if the lengths |
| 1814 |
don't match between an actual and a formal array parameter, |
| 1815 |
the Constraint_Error is raised before the call, rather than after. |
| 1816 |
@end{Ramification} |
| 1817 |
@end(itemize) |
| 1818 |
@end{Itemize} |
| 1819 |
|
| 1820 |
@PDefn2{Term=[constrained],Sec=(object)} |
| 1821 |
@PDefn2{Term=[unconstrained],Sec=(object)} |
| 1822 |
A formal parameter of mode @key[in out] or @key[out] with |
| 1823 |
discriminants is constrained if either its nominal subtype |
| 1824 |
or the actual parameter is constrained. |
| 1825 |
|
| 1826 |
@Defn{parameter copy back} |
| 1827 |
@Defn{copy back of parameters} |
| 1828 |
@Defn{parameter assigning back} |
| 1829 |
@Defn{assigning back of parameters} |
| 1830 |
@Defn2{Term=[assignment operation], Sec=(during parameter copy back)} |
| 1831 |
After normal completion and leaving of a subprogram, for each @key(in out) |
| 1832 |
or @key(out) parameter that is passed by copy, |
| 1833 |
the value of the formal parameter is converted to |
| 1834 |
the subtype of the variable given as the actual parameter |
| 1835 |
and assigned to it. |
| 1836 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 1837 |
These conversions and assignments occur in an arbitrary |
| 1838 |
order. |
| 1839 |
@begin{Ramification} |
| 1840 |
The conversions mentioned above during parameter passing might raise |
| 1841 |
Constraint_Error @em (see @RefSecNum{Type Conversions}). |
| 1842 |
@end{Ramification} |
| 1843 |
@begin{Ramification} |
| 1844 |
If any conversion or assignment as part of parameter passing |
| 1845 |
propagates an exception, the exception is raised at the place |
| 1846 |
of the subprogram call; |
| 1847 |
that is, it cannot be handled inside the @nt{subprogram_body}. |
| 1848 |
@end{Ramification} |
| 1849 |
@begin{TheProof} |
| 1850 |
Since these checks happen before or after executing the |
| 1851 |
@nt{subprogram_body}, the execution of the @nt{subprogram_body} does |
| 1852 |
not dynamically enclose them, so it can't handle the exceptions. |
| 1853 |
@end{TheProof} |
| 1854 |
@begin{Discussion} |
| 1855 |
The variable we're talking about is the one denoted by the |
| 1856 |
@i{variable_}@nt{name} given as the @nt{explicit_actual_parameter}. |
| 1857 |
If this @i{variable_}@nt{name} is a @nt{type_conversion}, |
| 1858 |
then the rules in @RefSecNum{Type Conversions} for assigning to a view |
| 1859 |
conversion apply. |
| 1860 |
That is, if X is of subtype S1, and the actual is S2(X), |
| 1861 |
the above-mentioned conversion will convert to S2, |
| 1862 |
and the one mentioned in @RefSecNum{Type Conversions} will convert to |
| 1863 |
S1. |
| 1864 |
@end{Discussion} |
| 1865 |
@end{RunTime} |
| 1866 |
|
| 1867 |
@begin{Extend83} |
| 1868 |
@Defn{extensions to Ada 83} |
| 1869 |
In Ada 95, a program can rely on the fact that passing an object as |
| 1870 |
an @key[out] parameter does not @lquotes@;de-initialize@rquotes@; any parts of the |
| 1871 |
object whose subtypes have implicit initial values. |
| 1872 |
(This generalizes the RM83 rule that required copy-in for parts that |
| 1873 |
were discriminants or of an access type.) |
| 1874 |
@end{Extend83} |
| 1875 |
|
| 1876 |
@begin{DiffWord83} |
| 1877 |
We have eliminated the subclause on Default Parameters, |
| 1878 |
as it is subsumed by earlier clauses and subclauses. |
| 1879 |
@end{DiffWord83} |
| 1880 |
|
| 1881 |
|
| 1882 |
@LabeledClause{Return Statements} |
| 1883 |
|
| 1884 |
@begin{Intro} |
| 1885 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1886 |
A @Chg{Version=[2],New=[@nt{simple_@!return_@!statement} or |
| 1887 |
@nt{extended_@!return_@!statement} (collectively called a @i<return statement>) |
| 1888 |
@Defn{return statement}],Old=[@nt{return_statement}]} is used to |
| 1889 |
complete the execution of the |
| 1890 |
innermost enclosing @nt{subprogram_@!body}, |
| 1891 |
@nt{entry_@!body}, or @nt{accept_@!statement}. |
| 1892 |
@end{Intro} |
| 1893 |
|
| 1894 |
@begin{Syntax} |
| 1895 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1896 |
@Syn{lhs=<@Chg{Version=[2],New=[simple_return_statement],Old=[return_statement]}>,rhs="@key{return} [@Syn2{expression}];"} |
| 1897 |
|
| 1898 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 1899 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[extended_return_statement],Old=[]}>, |
| 1900 |
rhs="@Chg{Version=[2],New=< |
| 1901 |
@key{return} @Syn2{defining_identifier} : [@Key{aliased}] @Syn2{return_subtype_indication} [:= @Syn2{expression}] [@Key{do} |
| 1902 |
@Syn2{handled_sequence_of_statements} |
| 1903 |
@key{end} @key{return}];>,Old=[]}"} |
| 1904 |
|
| 1905 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 1906 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[return_subtype_indication],Old=[]}>, |
| 1907 |
rhs="@Chg{Version=[2],New=<@Syn2{subtype_indication} | @Syn2{access_definition}>,Old=[]}"} |
| 1908 |
|
| 1909 |
@end{Syntax} |
| 1910 |
|
| 1911 |
@begin{Resolution} |
| 1912 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1913 |
@Chg{Version=[2],New=[@Defn2{Term=[result subtype], Sec=(of a function)} |
| 1914 |
The @i<result subtype> of a function is the subtype denoted by the |
| 1915 |
@nt<subtype_mark>, or defined by the @nt<access_definition>, after the reserved |
| 1916 |
word @key<return> in the profile of the function.@PDefn2{Term=[expected type], |
| 1917 |
Sec=(@nt{expression} of @nt<simple_@!return_@!statement>)}],Old=[@Defn{return expression} |
| 1918 |
The @nt{expression}, if any, of a @nt{return_statement} is called the |
| 1919 |
@i{return expression}. |
| 1920 |
@Defn2{Term=[result subtype], Sec=(of a function)} |
| 1921 |
The @i(result subtype) of a function is the subtype denoted by the |
| 1922 |
@nt{subtype_mark} after the reserved word @key(return) in the profile |
| 1923 |
of the function.@PDefn2{Term=[expected type], Sec=(return expression)}]} |
| 1924 |
The expected type for @Chg{Version=[2],New=[the @nt{expression}, if any, of a |
| 1925 |
@nt{simple_@!return_@!statement}],Old=[a return expression]} is the result type of |
| 1926 |
the corresponding function.@Chg{Version=[2],New=[ |
| 1927 |
@PDefn2{Term=[expected type], Sec=(@nt{expression} of @nt{extended_return_statement})} |
| 1928 |
The expected type for the |
| 1929 |
@nt{expression} of an @nt{extended_return_statement} is that of the |
| 1930 |
@nt{return_@!subtype_@!indication}.],Old=[]} |
| 1931 |
@begin{Honest} |
| 1932 |
The same applies to generic functions. |
| 1933 |
@end{Honest} |
| 1934 |
@end{Resolution} |
| 1935 |
|
| 1936 |
@begin{Legality} |
| 1937 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1938 |
@Chg{Version=[2],New=[@Defn2{Term=[apply], |
| 1939 |
Sec=(to a callable construct by a return statement)}], |
| 1940 |
Old=[@Defn2{Term=[apply], Sec=(to a callable construct by a @nt{return_statement})}]} |
| 1941 |
A @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 1942 |
shall be within a callable construct, |
| 1943 |
and it @i{applies to} the innermost @Chg{Version=[2],New=[callable construct |
| 1944 |
or @nt{extended_return_statement} that contains it],Old=[one]}. |
| 1945 |
A @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} shall |
| 1946 |
not be within a body that is within the construct to which the |
| 1947 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} applies. |
| 1948 |
|
| 1949 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1950 |
A function body shall contain at least one |
| 1951 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} that |
| 1952 |
applies to the function body, |
| 1953 |
unless the function contains @nt{code_statement}s. |
| 1954 |
A @Chg{Version=[2],New=[@nt{simple_@!return_@!statement}],Old=[@nt{return_@!statement}]} shall |
| 1955 |
include @Chg{Version=[2],New=[an @nt{expression}],Old=[a return expression]} |
| 1956 |
if and only if it applies to a function |
| 1957 |
body.@Chg{Version=[2],New=[ An @nt<extended_return_statement> shall apply to |
| 1958 |
a function body.],Old=[]} |
| 1959 |
@begin{Reason} |
| 1960 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1961 |
The requirement that a function body has to have at least one |
| 1962 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 1963 |
is a @lquotes@;helpful@rquotes@; restriction. |
| 1964 |
There @Chg{Version=[2],New=[has],Old=[was]} been some interest in lifting |
| 1965 |
this restriction, or allowing a raise statement to substitute for the |
| 1966 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}. |
| 1967 |
However, there was enough interest in leaving it as is |
| 1968 |
that we decided not to change it. |
| 1969 |
@end{Reason} |
| 1970 |
@begin{Ramification} |
| 1971 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 1972 |
@ChgAdded{Version=[2],Text=[A return statement can apply to an |
| 1973 |
@nt{extended_return_statement}, so a @nt{simple_@!return_@!statement} without |
| 1974 |
an @nt{expression} can be given in one. However, neither |
| 1975 |
@nt{simple_@!return_@!statement} with an @nt{expression} nor an |
| 1976 |
@nt{extended_return_statement} can be given inside an |
| 1977 |
@nt{extended_return_statement}, as they must apply (directly) to a |
| 1978 |
function body.]} |
| 1979 |
@end{Ramification} |
| 1980 |
|
| 1981 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 1982 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For an |
| 1983 |
@nt{extended_@!return_@!statement} that applies to a function body:]} |
| 1984 |
|
| 1985 |
@begin{Itemize} |
| 1986 |
|
| 1987 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 1988 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is defined by a |
| 1989 |
@nt{subtype_mark}, the @nt{return_@!subtype_@!indication} shall be a |
| 1990 |
@nt{subtype_indication}. The type of the @nt{subtype_indication} shall be the |
| 1991 |
result type of the function. If the result subtype of the function is |
| 1992 |
constrained, then the subtype defined by the @nt{subtype_indication} shall also |
| 1993 |
be constrained and shall statically match this result subtype. |
| 1994 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 1995 |
If the result subtype of the function is unconstrained, then the subtype |
| 1996 |
defined by the @nt{subtype_indication} shall be a definite subtype, or there |
| 1997 |
shall be an @nt{expression}.]} |
| 1998 |
|
| 1999 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 2000 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is defined |
| 2001 |
by an @nt{access_definition}, the @nt{return_@!subtype_@!indication} shall be an |
| 2002 |
@nt{access_definition}. The subtype defined by the @nt{access_definition} shall |
| 2003 |
statically match the result subtype of the function. The accessibility level of |
| 2004 |
this anonymous access subtype is that of the result subtype.]} |
| 2005 |
|
| 2006 |
@end{Itemize} |
| 2007 |
|
| 2008 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 2009 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For any return statement |
| 2010 |
that applies to a function body:]} |
| 2011 |
|
| 2012 |
@begin{Itemize} |
| 2013 |
|
| 2014 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 2015 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is limited, |
| 2016 |
then the @nt{expression} of the return statement (if any) shall be an |
| 2017 |
@nt{aggregate}, a function call (or equivalent use of an operator), or a |
| 2018 |
@nt{qualified_expression} or parenthesized expression whose operand is one of |
| 2019 |
these.]} |
| 2020 |
@begin{Discussion} |
| 2021 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2022 |
@ChgAdded{Version=[2],Text=[In other words, if limited, the @nt{expression} |
| 2023 |
must produce a @lquotes@;new@rquotes@; object, rather than being the name |
| 2024 |
of a preexisting object (which would imply copying).]} |
| 2025 |
@end{Discussion} |
| 2026 |
|
| 2027 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]} |
| 2028 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is class-wide, |
| 2029 |
the accessibility level of the type of the @nt{expression} of the return |
| 2030 |
statement shall not be statically deeper than that of the master that |
| 2031 |
elaborated the function body. If the result subtype has one or more |
| 2032 |
unconstrained access discriminants, the accessibility level of the anonymous |
| 2033 |
access type of each access discriminant, as determined by the |
| 2034 |
@nt{expression} of the @nt{simple_@!return_@!statement} or the |
| 2035 |
@nt{return_@!subtype_@!indication}, shall not be |
| 2036 |
statically deeper than that of the master that elaborated the function body.]} |
| 2037 |
|
| 2038 |
@begin{Discussion} |
| 2039 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2040 |
@ChgAdded{Version=[2],Text=[We know that if the result type is class wide, |
| 2041 |
then there must be an @nt{expression} of the return statement. Similarly, if |
| 2042 |
the result subtype is unconstrained, then either the |
| 2043 |
@nt{return_@!subtype_@!indication} (if any) is constrained, or there must be an |
| 2044 |
@nt{expression}.]} |
| 2045 |
@end{Discussion} |
| 2046 |
|
| 2047 |
@end{Itemize} |
| 2048 |
|
| 2049 |
@end{Legality} |
| 2050 |
|
| 2051 |
@begin{StaticSem} |
| 2052 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 2053 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[return object], Sec=(extended_return_statement)} |
| 2054 |
Within an @nt{extended_return_statement}, the @i{return object} is declared |
| 2055 |
with the given @nt{defining_identifier}, with the nominal subtype defined by |
| 2056 |
the @nt{return_@!subtype_@!indication}.]} |
| 2057 |
@end{StaticSem} |
| 2058 |
|
| 2059 |
@begin{RunTime} |
| 2060 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02],ARef=[AI95-00416-01]} |
| 2061 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[execution], Sec=(extended_return_statement)} |
| 2062 |
For the execution of an @nt{extended_return_statement}, the |
| 2063 |
@nt{subtype_indication} or @nt{access_definition} is elaborated. This creates |
| 2064 |
the nominal subtype of the return object. If there is an @nt{expression}, it |
| 2065 |
is evaluated and converted to the nominal subtype (which might raise |
| 2066 |
Constraint_Error @em see @RefSecNum{Type Conversions}@PDefn2{Term=[implicit subtype conversion],Sec=(function return)}); |
| 2067 |
the return object is created and the converted value is assigned to |
| 2068 |
the return object. Otherwise, the return object is created and initialized |
| 2069 |
by default as for a stand-alone object of its nominal subtype (see |
| 2070 |
@RefSecNum{Object Declarations}). If the nominal subtype is indefinite, the |
| 2071 |
return object is constrained by its initial value.@PDefn2{Term=[creation],Sec=[of a return object]}]} |
| 2072 |
|
| 2073 |
@begin{Ramification} |
| 2074 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2075 |
@ChgAdded{Version=[2],Text=[If the result type is controlled or has a |
| 2076 |
controlled part, appropriate calls on Initialize or Adjust are performed |
| 2077 |
prior to executing the @nt{handled_sequence_of_statements}, except when the |
| 2078 |
initial expression is an @nt{aggregate} (which requires build-in-place |
| 2079 |
with no call on Adjust).]} |
| 2080 |
|
| 2081 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2082 |
@ChgAdded{Version=[2],Text=[If the return statement is left without resulting |
| 2083 |
in a return (for example, due to an exception propagated from the |
| 2084 |
@nt{expression} or the @nt{handled_sequence_of_statements}, or a goto out of |
| 2085 |
the @nt{handled_sequence_of_statements}), the return object is finalized |
| 2086 |
prior to leaving the return statement.]} |
| 2087 |
@end{Ramification} |
| 2088 |
|
| 2089 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2090 |
@Chg{Version=[2],New=[@PDefn2{Term=[execution], Sec=(simple_@!return_@!statement)}], |
| 2091 |
Old=[@PDefn2{Term=[execution], Sec=(return_statement)}]} |
| 2092 |
For the execution of a @Chg{Version=[2],New=[@nt{simple_@!return_@!statement}], |
| 2093 |
Old=[@nt{return_statement}]}, the @nt{expression} |
| 2094 |
(if any) is first evaluated@Chg{Version=[2],New=[,],Old=[ and]} converted to |
| 2095 |
the result subtype@Chg{Version=[2], |
| 2096 |
New=[, and then is assigned to the anonymous @i{return object}. |
| 2097 |
@PDefn2{Term=[return object], Sec=(simple_@!return_@!statement)}],Old=[.]} |
| 2098 |
@PDefn2{Term=[implicit subtype conversion],Sec=(function return)} |
| 2099 |
@begin{Ramification} |
| 2100 |
The conversion might raise |
| 2101 |
Constraint_Error @em (see @RefSecNum{Type Conversions}). |
| 2102 |
@end{Ramification} |
| 2103 |
|
| 2104 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00416-01]} |
| 2105 |
@Chg{Version=[2],New=[@Redundant[If the return object has any parts that are tasks, the |
| 2106 |
activation of those tasks does not occur until after the function returns (see |
| 2107 |
@RefSecNum{Task Execution - Task Activation}).]], |
| 2108 |
Old=[If the result type is class-wide, then |
| 2109 |
the tag of the result is the tag of the value |
| 2110 |
of the @nt<expression>.]} |
| 2111 |
@begin{TheProof} |
| 2112 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2113 |
@ChgAdded{Version=[2],Text=[This is specified by the rules in |
| 2114 |
@RefSecNum{Task Execution - Task Activation}.]} |
| 2115 |
@end{TheProof} |
| 2116 |
@begin{Reason} |
| 2117 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2118 |
@ChgAdded{Version=[2],Text=[Only the caller can know when task activations |
| 2119 |
should take place, as it depends on the context of the call. If the function |
| 2120 |
is being used to initialize the component of some larger object, then that |
| 2121 |
entire object must be initialized before any task activations. Even after the |
| 2122 |
outer object is fully initialized, task activations are still postponed until |
| 2123 |
the @key{begin} at the end of the declarative part if the function is being |
| 2124 |
used to initialize part of a declared object.]} |
| 2125 |
@end{Reason} |
| 2126 |
|
| 2127 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01]} |
| 2128 |
@ChgDeleted{Version=[2],Type=[Leading],Keepnext=[T],Text=[]}@ChgNote{A dummy |
| 2129 |
ChgDeleted to get conditional "Leading".}If |
| 2130 |
the result type @Chg{Version=[2],New=[of a function ],Old=[]}is a specific |
| 2131 |
tagged type@Chg{Version=[2],New=[, the tag of the return object is that |
| 2132 |
of the result type. If the result type is class-wide, the tag of the |
| 2133 |
return object is that of the value of the expression. A check is made that |
| 2134 |
the accessibility level of the type identified by the tag of the result is |
| 2135 |
not deeper than that of the master that elaborated the function body. If |
| 2136 |
this check fails, Program_Error is raised.@Defn2{Term=[Program_Error], |
| 2137 |
Sec=(raised by failure of run-time check)} |
| 2138 |
@IndexCheck{Accessibility_Check}],Old=[:]} |
| 2139 |
|
| 2140 |
@begin{Ramification} |
| 2141 |
@ChgNote{Moved from after paragraph 10} |
| 2142 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2143 |
@ChgAdded{Version=[2],Text=[The first sentence is true even if the |
| 2144 |
tag of the @nt{expression} is different, which |
| 2145 |
could happen if the @nt{expression} were a view conversion or a |
| 2146 |
dereference of an access value. Note that for a limited type, because |
| 2147 |
of the restriction to @nt{aggregate}s and function calls (and no conversions), |
| 2148 |
the tag will already match]}. |
| 2149 |
@end{Ramification} |
| 2150 |
@begin{Reason} |
| 2151 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2152 |
@ChgAdded{Version=[2],Text=[The first rule ensures |
| 2153 |
that a function whose result type is |
| 2154 |
a specific tagged type always returns an object whose tag is that of the |
| 2155 |
result type. This is important for dispatching on controlling result, and |
| 2156 |
allows the caller to allocate the appropriate amount of space to hold |
| 2157 |
the value being returned (assuming there are no discriminants).]} |
| 2158 |
|
| 2159 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2160 |
@ChgAdded{Version=[2],Text=[The check prevents the returned object |
| 2161 |
from outliving its type. Note that this check cannot fail for a specific |
| 2162 |
tagged type, as the tag represents the function's type, which necessarily |
| 2163 |
must be declared outside of the function.]} |
| 2164 |
@end{Reason} |
| 2165 |
@begin{NotIso} |
| 2166 |
@ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 9 |
| 2167 |
through 20 were deleted.>}]}@Comment{This message should be deleted if the |
| 2168 |
paragraphs are ever renumbered.} |
| 2169 |
@end{NotIso} |
| 2170 |
|
| 2171 |
@begin(itemize) |
| 2172 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2173 |
@ChgDeleted{Version=[2],Text=[@IndexCheck{Tag_Check} |
| 2174 |
If it is limited, then |
| 2175 |
a check is made that the tag of the value of the return expression |
| 2176 |
identifies the result type. |
| 2177 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 2178 |
Constraint_Error is raised if this check fails.]} |
| 2179 |
|
| 2180 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2181 |
@ChgDeleted{Version=[2],Text=[If it is nonlimited, then |
| 2182 |
the tag of the result is that of the result type.]} |
| 2183 |
@begin{Ramification} |
| 2184 |
@ChgNote{These two notes were revised and moved up} |
| 2185 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2186 |
@ChgDeleted{Version=[2],Text=[This is true even if the |
| 2187 |
tag of the return expression is different.]} |
| 2188 |
@end{Ramification} |
| 2189 |
@begin{Reason} |
| 2190 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2191 |
@ChgDeleted{Version=[2],Text=[These rules ensure |
| 2192 |
that a function whose result type is |
| 2193 |
a specific tagged type always returns an object whose tag is that of the |
| 2194 |
result type. This is important for dispatching on controlling result, |
| 2195 |
and, if nonlimited, |
| 2196 |
allows the caller to allocate the appropriate amount of space to hold |
| 2197 |
the value being returned (assuming there are no discriminants).]} |
| 2198 |
@end{Reason} |
| 2199 |
@end(itemize) |
| 2200 |
|
| 2201 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2202 |
@ChgDeleted{Version=[2],Type=[Leading],Keepnext=[T], |
| 2203 |
Text=[@Defn{return-by-reference type} |
| 2204 |
A type is a @i(return-by-reference) type if it |
| 2205 |
is a descendant of one of the following:]} |
| 2206 |
@begin(itemize) |
| 2207 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2208 |
@ChgDeleted{Version=[2],Text=[a tagged limited type;]} |
| 2209 |
|
| 2210 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2211 |
@ChgDeleted{Version=[2],Text=[a task or protected type;]} |
| 2212 |
|
| 2213 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2214 |
@ChgDeleted{Version=[2],Text=[a nonprivate type with the reserved word |
| 2215 |
@b(limited) in its declaration;]} |
| 2216 |
|
| 2217 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2218 |
@ChgDeleted{Version=[2],Text=[a composite type with a subcomponent |
| 2219 |
of a return-by-reference type;]} |
| 2220 |
|
| 2221 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2222 |
@ChgDeleted{Version=[2],Text=[a private type |
| 2223 |
whose full type is a return-by-reference type.]} |
| 2224 |
@end(itemize) |
| 2225 |
@begin{Ramification} |
| 2226 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 2227 |
@ChgDeleted{Version=[2],Text=[ |
| 2228 |
The above rules are such that there are no "Ada 83" types other than |
| 2229 |
those containing tasks that are return-by-reference. This helps |
| 2230 |
to minimize upward incompatibilities relating to return-by-reference.]} |
| 2231 |
@end{Ramification} |
| 2232 |
|
| 2233 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2234 |
@ChgDeleted{Version=[2],Type=[Leading],Text=[@IndexCheck{Accessibility_Check} |
| 2235 |
If the result type is a return-by-reference type, |
| 2236 |
then a check is made that the return expression is one of the |
| 2237 |
following:]} |
| 2238 |
@begin(itemize) |
| 2239 |
|
| 2240 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2241 |
@ChgDeleted{Version=[2],Text=[a @nt{name} that denotes an object view |
| 2242 |
whose accessibility level is not deeper than that of the master that |
| 2243 |
elaborated the function body; or]} |
| 2244 |
@begin{Discussion} |
| 2245 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00316-01]} |
| 2246 |
@ChgNote{This really wasn't in the previous version, but we don't want it |
| 2247 |
in a version without deletions shown...} |
| 2248 |
@ChgDeleted{Version=[2],Text=[This rule was unnecessarily confusing, and the |
| 2249 |
parenthetical remark "(or a value with an associated object, see 6.2)" |
| 2250 |
was added @em and then the entire concept was deleted.]} |
| 2251 |
@end{Discussion} |
| 2252 |
|
| 2253 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2254 |
@ChgDeleted{Version=[2],Text=[a parenthesized expression or |
| 2255 |
@nt{qualified_expression} whose operand is one of these kinds of expressions.]} |
| 2256 |
|
| 2257 |
@end(itemize) |
| 2258 |
|
| 2259 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 2260 |
@ChgDeleted{Version=[2],Text=[@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 2261 |
The exception Program_Error is raised if this check fails.]} |
| 2262 |
@begin{Discussion} |
| 2263 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 2264 |
@ChgDeleted{Version=[2],Text=[Compare the definition of return-by-reference |
| 2265 |
with that of by-reference.]} |
| 2266 |
|
| 2267 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 2268 |
@ChgDeleted{Version=[2],Text=[The return-by-reference types are all limited types |
| 2269 |
except those that are limited only because of a limited |
| 2270 |
private type with a nonlimited untagged full type.]} |
| 2271 |
@end{Discussion} |
| 2272 |
@begin{Reason} |
| 2273 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 2274 |
@ChgDeleted{Version=[2],Text=[@PDefn{generic contract issue} |
| 2275 |
This check can often be performed at compile time. It is |
| 2276 |
defined to be a run-time check to avoid generic contract model |
| 2277 |
problems. In a future version of the standard, we anticipate |
| 2278 |
that function return of a local variable will be illegal for all |
| 2279 |
limited types, eliminating the need for the run-time check |
| 2280 |
except for dereferences of an access parameter.]} |
| 2281 |
@end{Reason} |
| 2282 |
|
| 2283 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00402-01],ARef=[AI95-00416-01]} |
| 2284 |
@Chg{Version=[2], |
| 2285 |
New=[If the result subtype of a function has one or more unconstrained access |
| 2286 |
discriminants, |
| 2287 |
a check is made that the accessibility level of the anonymous access type |
| 2288 |
of each access discriminant, as determined by the @nt{expression} or the |
| 2289 |
@nt{return_@!subtype_@!indication} of the function, |
| 2290 |
is not deeper than that of the master that elaborated the |
| 2291 |
function body. If this check fails, Program_Error is raised. |
| 2292 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 2293 |
@IndexCheck{Accessibility_Check}], |
| 2294 |
Old=[For a function with a return-by-reference result type |
| 2295 |
the result is returned by reference; |
| 2296 |
that is, the function call denotes a constant view of the |
| 2297 |
object associated |
| 2298 |
with the value of the return expression. |
| 2299 |
@Defn2{Term=[assignment operation], Sec=(during execution of a |
| 2300 |
@nt{return_statement})} |
| 2301 |
For any other function, the result is returned by copy; |
| 2302 |
that is, |
| 2303 |
the converted value is assigned into an anonymous constant created at |
| 2304 |
the point of the @nt{return_statement}, and the function call denotes |
| 2305 |
that object.]} |
| 2306 |
@begin{Ramification} |
| 2307 |
@ChgRef{Version=[2],Kind=[Deleted]} |
| 2308 |
@ChgDeleted{Version=[2],Text=[The assignment operation does the necessary |
| 2309 |
value adjustment, as described in |
| 2310 |
@RefSec{User-Defined Assignment and Finalization}. |
| 2311 |
@RefSecNum{Completion and Finalization} |
| 2312 |
describes when the anonymous constant is finalized.]} |
| 2313 |
@end{Ramification} |
| 2314 |
@begin{Reason} |
| 2315 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2316 |
@ChgAdded{Version=[2],Text=[The check prevents the returned |
| 2317 |
object (for a nonlimited type) from outliving the object designated by one |
| 2318 |
of its discriminants. The check is made on the values of the discriminants, |
| 2319 |
which may come from the @nt{return_@!subtype_@!indication} (if constrained), |
| 2320 |
or the @nt{expression}, but it is never necessary to check both.]} |
| 2321 |
@end{Reason} |
| 2322 |
|
| 2323 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2324 |
@Chg{Version=[2],New=[For the execution of an |
| 2325 |
@nt{extended_@!return_@!statement}, the |
| 2326 |
@nt{handled_@!sequence_@!of_@!statements} is executed. Within this |
| 2327 |
@nt{handled_@!sequence_@!of_@!statements}, the execution of a |
| 2328 |
@nt{simple_@!return_@!statement} that applies to the |
| 2329 |
@nt{extended_@!return_@!statement} causes a transfer of control that completes |
| 2330 |
the @nt{extended_@!return_@!statement}. Upon completion |
| 2331 |
of a return statement that applies to a callable construct],Old=[Finally]}, a |
| 2332 |
transfer of control is performed which completes the execution of the callable |
| 2333 |
construct@Chg{Version=[2],New=[], Old=[ to which the @nt{return_@!statement} |
| 2334 |
applies]}, and returns to the caller. |
| 2335 |
|
| 2336 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2337 |
@ChgAdded{Version=[2],Text=[In the case of a function, the @nt{function_call} |
| 2338 |
denotes a constant view of the return object.]} |
| 2339 |
@end{RunTime} |
| 2340 |
|
| 2341 |
@begin{ImplPerm} |
| 2342 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 2343 |
@ChgAdded{Version=[2],Text=[If the result subtype of a function is |
| 2344 |
unconstrained, and a call on the function is used to provide the initial value |
| 2345 |
of an object with a constrained nominal subtype, Constraint_Error may be raised |
| 2346 |
at the point of the call (after abandoning the execution of the function body) |
| 2347 |
if, while elaborating the @nt{return_@!subtype_@!indication} or |
| 2348 |
evaluating the @nt{expression} of a return statement that applies to the |
| 2349 |
function body, it |
| 2350 |
is determined that the value of the result will violate the constraint of the |
| 2351 |
subtype of this object.]} |
| 2352 |
@begin{Reason} |
| 2353 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2354 |
@ChgAdded{Version=[2],Text=[Without such a permission, it would be very |
| 2355 |
difficult to implement @lquotes@;build-in-place@rquotes semantics. Such an |
| 2356 |
exception is not handleable within the function, because in the |
| 2357 |
return-by-copy case, the constraint check to verify that the result satisfies |
| 2358 |
the constraints of the object being initialized happens after the function |
| 2359 |
returns, and we want the semantics to change as little as possible when |
| 2360 |
switching between return-by-copy and build-in-place. This implies further |
| 2361 |
that upon detecting such a situation, the implementation may need to simulate |
| 2362 |
a goto to a point outside any local exception handlers prior to raising the |
| 2363 |
exception.]} |
| 2364 |
@end{Reason} |
| 2365 |
@begin{Ramification} |
| 2366 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2367 |
@ChgAdded{Version=[2],Text=[This permission is allowed during the evaluation |
| 2368 |
of the @nt{expression} of an @nt{extended_return_statement}, because the |
| 2369 |
@nt{return_@!subtype_@!indication} may be unconstrained and the @nt{expression} |
| 2370 |
then would provide the constraints.]} |
| 2371 |
@end{Ramification} |
| 2372 |
@end{ImplPerm} |
| 2373 |
|
| 2374 |
@begin{Examples} |
| 2375 |
@leading@keepnext@i{Examples of return statements:} |
| 2376 |
@begin{Example} |
| 2377 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2378 |
@key[return]; --@RI{ in a procedure body, }@nt{entry_body}@RI{,}@Chg{Version=[2],New=[ |
| 2379 |
-- @nt{accept_statement}@RI{, or }@nt{extended_return_statement}],Old=[@RI{ or }@nt{accept_statement}]} |
| 2380 |
|
| 2381 |
@key[return] Key_Value(Last_Index); --@RI{ in a function body} |
| 2382 |
|
| 2383 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2384 |
@Chg{Version=[2],New=<@key[return] Node : Cell @key{do} --@RI{ in a function body, see @RefSecNum{Incomplete Type Declarations} for Cell} |
| 2385 |
Node.Value := Result; |
| 2386 |
Node.Succ := Next_Node; |
| 2387 |
@key{end} @key{return};>,Old=<>} |
| 2388 |
@end{Example} |
| 2389 |
@end{Examples} |
| 2390 |
|
| 2391 |
@begin{Incompatible83} |
| 2392 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2393 |
@Defn{incompatibilities with Ada 83} |
| 2394 |
In Ada 95, if the result type of a function has a part that is a task, |
| 2395 |
then an attempt to return a local variable will raise Program_Error. |
| 2396 |
@Chg{Version=[2],New=[This is illegal in Ada 2005, see below. ], |
| 2397 |
Old=[]}In Ada 83, if a function returns a local variable containing a task, |
| 2398 |
execution is erroneous according to AI83-00867. However, |
| 2399 |
there are other situations where functions that return tasks |
| 2400 |
(or that return a variant record only one of whose variants |
| 2401 |
includes a task) |
| 2402 |
are correct in Ada 83 but will raise Program_Error according |
| 2403 |
to the new rules. |
| 2404 |
|
| 2405 |
The rule change was made because there will be more types (protected types, |
| 2406 |
limited controlled types) in Ada 95 for which |
| 2407 |
it will be meaningless to return a local variable, and making |
| 2408 |
all of these erroneous is unacceptable. |
| 2409 |
The current rule was felt to be the simplest that kept |
| 2410 |
upward incompatibilities to situations involving returning tasks, |
| 2411 |
which are quite rare. |
| 2412 |
@end{Incompatible83} |
| 2413 |
|
| 2414 |
@begin{DiffWord83} |
| 2415 |
This clause has been moved here from chapter 5, |
| 2416 |
since it has mainly to do with subprograms. |
| 2417 |
|
| 2418 |
A function now creates an anonymous object. |
| 2419 |
This is necessary so that controlled types |
| 2420 |
will work. |
| 2421 |
|
| 2422 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2423 |
We have clarified that a |
| 2424 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]} |
| 2425 |
applies to a callable construct, not to a callable entity. |
| 2426 |
|
| 2427 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2428 |
There is no need to mention generics in the rules about where a |
| 2429 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]} |
| 2430 |
can appear and what it applies to; |
| 2431 |
the phrase @lquotes@;body of a subprogram or generic subprogram@rquotes@; is |
| 2432 |
syntactic, and refers exactly to @lquotes@;@nt{subprogram_body}@rquotes@;. |
| 2433 |
@end{DiffWord83} |
| 2434 |
|
| 2435 |
@begin{Incompatible95} |
| 2436 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2437 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} The entire |
| 2438 |
business about return-by-reference types has been dropped. Instead, the |
| 2439 |
@nt{expression} of a return statement of a limited type can only be an |
| 2440 |
@nt{aggregate} or @nt{function_call} (see @RefSecNum{Limited Types}). This |
| 2441 |
means that returning a global object or @nt{type_conversion}, legal in Ada |
| 2442 |
95, is now illegal. Such functions can be converted to use anonymous access |
| 2443 |
return types by adding @key{access} in the function definition and return |
| 2444 |
statement, adding .@key{all} in uses, and adding @key{aliased} in the object |
| 2445 |
declarations. This has the advantage of making the reference return semantics |
| 2446 |
much clearer to the casual reader.]} |
| 2447 |
|
| 2448 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2449 |
@ChgAdded{Version=[2],Text=[We changed these rules so that functions, |
| 2450 |
combined with the new rules for limited types (@RefSecnum{Limited Types}), |
| 2451 |
can be used as build-in-place constructors for limited types. This reduces |
| 2452 |
the differences between limited and nonlimited types, which will |
| 2453 |
make limited types useful in more circumstances.]} |
| 2454 |
@end{Incompatible95} |
| 2455 |
|
| 2456 |
@begin{Extend95} |
| 2457 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2458 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 2459 |
The @nt{extended_return_statement} is new. This provides a name for |
| 2460 |
the object being returned, which reduces the copying needed to return |
| 2461 |
complex objects (including no copying at all for limited objects). It also |
| 2462 |
allows component-by-component construction of the return object.]} |
| 2463 |
@end{Extend95} |
| 2464 |
|
| 2465 |
@begin{DiffWord95} |
| 2466 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2467 |
@ChgAdded{Version=[2],Text=[The wording was updated to support anonymous |
| 2468 |
access return subtypes.]} |
| 2469 |
|
| 2470 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2471 |
@ChgAdded{Version=[2],Text=[The term @lquotes@;return expression@rquotes@; |
| 2472 |
was dropped because reviewers found it confusing when applied to the default |
| 2473 |
@nt{expression} of an @nt{extended_return_statement}.]} |
| 2474 |
|
| 2475 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01],ARef=[AI95-00416-01]} |
| 2476 |
@ChgAdded{Version=[2],Text=[Added accessibility checks to class-wide |
| 2477 |
return statements. These checks could not fail in Ada 95 (as all of the |
| 2478 |
types had to be declared at the same level, so the tagged type would |
| 2479 |
necessarily have been at the same level as the type of the |
| 2480 |
object).]} |
| 2481 |
|
| 2482 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00402-01],ARef=[AI95-00416-01]} |
| 2483 |
@ChgAdded{Version=[2],Text=[Added accessibility checks to |
| 2484 |
return statements for types with access discriminants. Since such |
| 2485 |
types have to be limited in Ada 95, the @nt{expression} of a return statement |
| 2486 |
would have been illegal in order for this check to fail.]} |
| 2487 |
|
| 2488 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 2489 |
@ChgAdded{Version=[2],Text=[Added an @ImplPermName allowing |
| 2490 |
early raising of Constraint_Error if the result cannot fit in the ultimate |
| 2491 |
object. This gives implementations more flexibility to do built-in-place |
| 2492 |
returns, and is essential for limited types (which cannot be built in a |
| 2493 |
temporary).]} |
| 2494 |
@end{DiffWord95} |
| 2495 |
|
| 2496 |
|
| 2497 |
@LabeledAddedSubClause{Version=[2],Name=[Pragma No_Return]} |
| 2498 |
|
| 2499 |
@ChgNote{Putting @nt{pragma} in the syntax font is used for Assert and Pure, |
| 2500 |
at least.} |
| 2501 |
|
| 2502 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2503 |
@ChgAdded{Version=[2],Text=[A @nt{pragma} No_Return indicates that a |
| 2504 |
procedure cannot return normally@Redundant[; it may propagate an exception |
| 2505 |
or loop forever].]} |
| 2506 |
@begin{Discussion} |
| 2507 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2508 |
@ChgAdded{Version=[2],Text=[@nt{Pragma} No_Deposit will have to wait for Ada 2017. :-)]} |
| 2509 |
@end{Discussion} |
| 2510 |
|
| 2511 |
@begin{Syntax} |
| 2512 |
@begin{SyntaxText} |
| 2513 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2514 |
@ChgAdded{Version=[2],Text=[The form of a @nt{pragma} No_Return, which is a |
| 2515 |
representation pragma (see @RefSecNum{Operational and Representation Items}), |
| 2516 |
is as follows:]} |
| 2517 |
@end{SyntaxText} |
| 2518 |
|
| 2519 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2520 |
@ChgAdded{Version=[2],Text=`@AddedPragmaSyn`Version=[2],@key{pragma} @prag<No_Return>(@SynI{procedure_}@Syn2{local_name}{, @SynI{procedure_}@Syn2{local_name}});''} |
| 2521 |
@end{Syntax} |
| 2522 |
|
| 2523 |
@begin{Legality} |
| 2524 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2525 |
@ChgAdded{Version=[2],Text=[@Defn{non-returning}Each |
| 2526 |
@SynI{procedure_}@nt{local_name} shall denote one or |
| 2527 |
more procedures or generic procedures; the denoted entities are |
| 2528 |
@i<non-returning>. The @SynI{procedure_}@nt{local_name} shall not denote a |
| 2529 |
null procedure nor an instance of a generic unit.]} |
| 2530 |
|
| 2531 |
@begin{Reason} |
| 2532 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2533 |
@ChgAdded{Version=[2],Text=[A null procedure cannot have the appropriate |
| 2534 |
non-returning semantics, as it does not raise an exception or loop forever.]} |
| 2535 |
@end{Reason} |
| 2536 |
|
| 2537 |
@begin{Ramification} |
| 2538 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2539 |
@ChgAdded{Version=[2],Text=[The procedure can be abstract. The denoted |
| 2540 |
declaration can be a @nt{renaming_declaration} if it obeys the usual rules |
| 2541 |
for representation pragmas: the renaming has to occur immediately within the |
| 2542 |
same declarative region as the renamed subprogram. If a non-returning |
| 2543 |
procedure is renamed (anywhere) calls through the new name still have the |
| 2544 |
non-returning semantics.]} |
| 2545 |
@end{Ramification} |
| 2546 |
|
| 2547 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2548 |
@ChgAdded{Version=[2],Text=[A return statement shall not apply to a |
| 2549 |
non-returning procedure or generic procedure.]} |
| 2550 |
|
| 2551 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 2552 |
@ChgAdded{Version=[2],Text=[A procedure shall be non-returning if it overrides |
| 2553 |
a dispatching non-returning procedure. |
| 2554 |
@PDefn{generic contract issue} |
| 2555 |
In addition to the places where |
| 2556 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 2557 |
this rule applies also in the private part of an instance of a generic unit.]} |
| 2558 |
|
| 2559 |
@begin{Reason} |
| 2560 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2561 |
@ChgAdded{Version=[2],Text=[This ensures that dispatching calls to |
| 2562 |
non-returning procedures will, in fact, not return.]} |
| 2563 |
@end{Reason} |
| 2564 |
|
| 2565 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 2566 |
@ChgAdded{Version=[2],Text=[If a renaming-as-body completes a non-returning |
| 2567 |
procedure declaration, then the renamed procedure shall be non-returning.]} |
| 2568 |
|
| 2569 |
@begin{Reason} |
| 2570 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2571 |
@ChgAdded{Version=[2],Text=[This ensures that no extra code is needed to |
| 2572 |
implement the renames (that is, no wrapper is needed) as the body has |
| 2573 |
the same property.]} |
| 2574 |
@end{Reason} |
| 2575 |
|
| 2576 |
@end{Legality} |
| 2577 |
|
| 2578 |
@begin{StaticSem} |
| 2579 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2580 |
@ChgAdded{Version=[2],Text=[If a generic procedure is non-returning, then so |
| 2581 |
are its instances. If a procedure declared within a generic unit is |
| 2582 |
non-returning, then so are the corresponding copies of that procedure in |
| 2583 |
instances.]} |
| 2584 |
@end{StaticSem} |
| 2585 |
|
| 2586 |
@begin{RunTime} |
| 2587 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2588 |
@ChgAdded{Version=[2],Text=[If the body of a non-returning procedure completes |
| 2589 |
normally, Program_Error is raised at the point of the call. |
| 2590 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}]} |
| 2591 |
@end{RunTime} |
| 2592 |
@begin{Discussion} |
| 2593 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2594 |
@ChgAdded{Version=[2],Text=[Note that there is no name for suppressing |
| 2595 |
this check, since the check represents a bug, imposes no time overhead, |
| 2596 |
and minimal space overhead (since it can usually be statically eliminated |
| 2597 |
as dead code).]} |
| 2598 |
@end{Discussion} |
| 2599 |
@begin{ImplNote} |
| 2600 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2601 |
@ChgAdded{Version=[2],Text=[If a non-returning procedure tries to return, we |
| 2602 |
raise Program_Error. This is stated as happening at the call site, because we |
| 2603 |
do not wish to allow the procedure to handle the exception (and then, |
| 2604 |
perhaps, try to return again!). However, the expected run-time model is that |
| 2605 |
the compiler will generate @key{raise} Program_Error at the end of the |
| 2606 |
procedure body (but not handleable by the procedure itself), as opposed to |
| 2607 |
doing it at the call site. (This is just like the typical run-time model for |
| 2608 |
functions that fall off the end without returning a value). The reason is |
| 2609 |
indirect calls: in P.@key{all}(...);, the compiler cannot know whether P |
| 2610 |
designates a non-returning procedure or a normal one. Putting the @key{raise} |
| 2611 |
Program_Error in the procedure's generated code solves this problem neatly.]} |
| 2612 |
|
| 2613 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2614 |
@ChgAdded{Version=[2],Text=[Similarly, if one passes a non-returning |
| 2615 |
procedure to a generic formal parameter, the compiler cannot know this at |
| 2616 |
call sites (in shared code implementations); the raise-in-body solution |
| 2617 |
deals with this neatly.]} |
| 2618 |
@end{ImplNote} |
| 2619 |
|
| 2620 |
@begin{Examples} |
| 2621 |
@begin{Example} |
| 2622 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 2623 |
@ChgAdded{Version=[2],Text=[@key(procedure) Fail(Msg : String); --@RI[ raises Fatal_Error exception] |
| 2624 |
@key(pragma) No_Return(Fail); |
| 2625 |
--@RI[ Inform compiler and reader that procedure never returns normally]]} |
| 2626 |
@end{Example} |
| 2627 |
@end{Examples} |
| 2628 |
|
| 2629 |
@begin{Extend95} |
| 2630 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 2631 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 2632 |
@nt{Pragma} No_Return is new.]} |
| 2633 |
@end{Extend95} |
| 2634 |
|
| 2635 |
|
| 2636 |
@LabeledClause{Overloading of Operators} |
| 2637 |
|
| 2638 |
@begin{Intro} |
| 2639 |
@Defn{operator} |
| 2640 |
@Defn{user-defined operator} |
| 2641 |
@Defn2{Term=[operator], Sec=(user-defined)} |
| 2642 |
An @i{operator} is a function whose @nt{designator} is an |
| 2643 |
@nt<operator_symbol>. |
| 2644 |
@Redundant[Operators, like other functions, may be overloaded.] |
| 2645 |
@end{Intro} |
| 2646 |
|
| 2647 |
@begin{Resolution} |
| 2648 |
Each use of a unary or binary operator is equivalent to a |
| 2649 |
@nt{function_call} with @SynI{function_}@nt{prefix} being the |
| 2650 |
corresponding @nt{operator_symbol}, and with (respectively) one or |
| 2651 |
two positional actual parameters being the operand(s) of the operator |
| 2652 |
(in order). |
| 2653 |
@begin{Honest} |
| 2654 |
We also use the term operator |
| 2655 |
(in Section 4 and in @RefSecNum{Subprogram Declarations}) |
| 2656 |
to refer to one of the syntactic categories |
| 2657 |
defined in @RefSec{Operators and Expression Evaluation} |
| 2658 |
whose names end with @lquotes@;_operator:@rquotes@; |
| 2659 |
@nt<logical_@!operator>, |
| 2660 |
@nt<relational_@!operator>, |
| 2661 |
@nt<binary_@!adding_@!operator>, |
| 2662 |
@nt<unary_@!adding_@!operator>, |
| 2663 |
@nt<multiplying_@!operator>, and |
| 2664 |
@nt<highest_@!precedence_@!operator>. |
| 2665 |
@end{Honest} |
| 2666 |
@end{Resolution} |
| 2667 |
|
| 2668 |
@begin{Legality} |
| 2669 |
The @nt{subprogram_specification} of a unary or binary operator shall have |
| 2670 |
one or two parameters, respectively. |
| 2671 |
A generic function instantiation whose @nt{designator} is an |
| 2672 |
@nt{operator_symbol} is only allowed if the specification of the |
| 2673 |
generic function has the corresponding number of parameters. |
| 2674 |
|
| 2675 |
@nt{Default_expression}s are not allowed for the parameters of an operator |
| 2676 |
(whether the operator is declared with an explicit |
| 2677 |
@nt{subprogram_specification} or by a @nt{generic_instantiation}). |
| 2678 |
|
| 2679 |
An explicit declaration of "/=" shall not have a result |
| 2680 |
type of the predefined type Boolean. |
| 2681 |
@end{Legality} |
| 2682 |
|
| 2683 |
@begin{StaticSem} |
| 2684 |
A declaration of "=" whose result type is |
| 2685 |
Boolean implicitly declares a declaration of "/=" that |
| 2686 |
gives the complementary result. |
| 2687 |
@end{StaticSem} |
| 2688 |
|
| 2689 |
@begin{Notes} |
| 2690 |
The operators "+" and "@en@;" are both unary and binary operators, |
| 2691 |
and hence may be overloaded with both one- and two-parameter functions. |
| 2692 |
@end{Notes} |
| 2693 |
|
| 2694 |
@begin{Examples} |
| 2695 |
@leading@keepnext@i{Examples of user-defined operators:} |
| 2696 |
@begin{Example} |
| 2697 |
@key[function] "+" (Left, Right : Matrix) @key[return] Matrix; |
| 2698 |
@key[function] "+" (Left, Right : Vector) @key[return] Vector; |
| 2699 |
@Comment{Blank line} |
| 2700 |
--@RI{ assuming that A, B, and C are of the type Vector} |
| 2701 |
--@RI{ the following two statements are equivalent:} |
| 2702 |
@Comment{Blank line} |
| 2703 |
A := B + C; |
| 2704 |
A := "+"(B, C); |
| 2705 |
@end{Example} |
| 2706 |
@end{Examples} |
| 2707 |
|
| 2708 |
@begin{Extend83} |
| 2709 |
@Defn{extensions to Ada 83} |
| 2710 |
Explicit declarations of "=" are now permitted for any |
| 2711 |
combination of parameter and result types. |
| 2712 |
|
| 2713 |
Explicit declarations of "/=" are now permitted, so long |
| 2714 |
as the result type is not Boolean. |
| 2715 |
@end{Extend83} |
| 2716 |
|
| 2717 |
|
| 2718 |
@RMNewPage@Comment{For printed RM Ada 2005} |
| 2719 |
@LabeledAddedClause{Version=[2],Name=[Null Procedures]} |
| 2720 |
|
| 2721 |
@begin{Intro} |
| 2722 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 2723 |
@ChgAdded{Version=[2],Text=[A @nt<null_procedure_declaration> provides a shorthand |
| 2724 |
to declare a procedure with an empty body.]} |
| 2725 |
@end{Intro} |
| 2726 |
|
| 2727 |
@begin{Syntax} |
| 2728 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 2729 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<null_procedure_declaration>,Old=<>}>, |
| 2730 |
rhs="@Chg{Version=[2],New=< |
| 2731 |
[@Syn2{overriding_indicator}] |
| 2732 |
@Syn2{procedure_specification} @key{is} @key{null};>,Old=<>}"} |
| 2733 |
@end{Syntax} |
| 2734 |
|
| 2735 |
@begin{StaticSem} |
| 2736 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 2737 |
@ChgAdded{Version=[2],Text=[A @nt<null_procedure_declaration> declares a @i<null |
| 2738 |
procedure>.@Defn{null procedure}@Defn2{Term=[procedure],Sec=[null]} |
| 2739 |
A completion is not allowed for a @nt<null_procedure_declaration>.]} |
| 2740 |
@begin{Reason} |
| 2741 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2742 |
@ChgAdded{Version=[2],Text=[There are no null functions because the return |
| 2743 |
value has to be constructed somehow; a function that always raises |
| 2744 |
Program_Error doesn't seem very useful or worth the complication.]} |
| 2745 |
@end{Reason} |
| 2746 |
@end{StaticSem} |
| 2747 |
|
| 2748 |
@begin{RunTime} |
| 2749 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 2750 |
@ChgAdded{Version=[2],Text=[The execution of a null procedure is invoked by a subprogram call. |
| 2751 |
For the execution of a subprogram call on a null procedure, the execution of |
| 2752 |
the @nt<subprogram_body> has no effect.]} |
| 2753 |
@begin{Ramification} |
| 2754 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2755 |
@ChgAdded{Version=[2],Text=[Thus, a null procedure is equivalent to the body]} |
| 2756 |
@begin{Example} |
| 2757 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2758 |
@ChgAdded{Version=[2],Text=[@key{begin} |
| 2759 |
@key{null}; |
| 2760 |
@key{end};]} |
| 2761 |
@end{Example} |
| 2762 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2763 |
@ChgAdded{Version=[2],Text=[with the exception that a null procedure can be used in |
| 2764 |
place of a procedure specification.]} |
| 2765 |
@end{Ramification} |
| 2766 |
|
| 2767 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 2768 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[elaboration], Sec=(null_procedure_declaration)} |
| 2769 |
The elaboration of a @nt{null_procedure_declaration} has no effect.]} |
| 2770 |
@end{RunTime} |
| 2771 |
|
| 2772 |
@begin{Examples} |
| 2773 |
@begin{Example} |
| 2774 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 2775 |
@ChgAdded{Version=[2],Text=[@key(procedure) Simplify(Expr : @key(in out) Expression) @key(is null); --@RI[ see @RefSecNum{Tagged Types and Type Extensions}] |
| 2776 |
--@RI[ By default, Simplify does nothing, but it may be overridden in extensions of Expression]]} |
| 2777 |
@end{Example} |
| 2778 |
@end{Examples} |
| 2779 |
|
| 2780 |
@begin{Extend95} |
| 2781 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 2782 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 2783 |
Null procedures are new.]} |
| 2784 |
@end{Extend95} |
| 2785 |
|