DocAda(tm) is a productivity tool of KSCE
|
|
|
|
About DocAda Light:
Preface / Preliminary
/ Help
/ TOC
/ Copyright
DocAda Online at the Ada Home:
Complete RM95
/ Updates
/ News
A return_statement is used to complete the execution of the innermost enclosing subprogram_body, entry_body, or accept_statement.
Syntax
return_statement ::= return [expression];
Name Resolution Rules
The expression, if any, of a return_statement is called the return expression. The result subtype of a function is the subtype denoted by the subtype_mark after the reserved word return in the profile of the function. The expected type for a return expression is the result type of the corresponding function.
Legality Rules
A return_statement shall be within a callable construct, and it applies to the innermost one. A return_statement shall not be within a body that is within the construct to which the return_statement applies.
A function body shall contain at least one return_statement that applies to the function body, unless the function contains code_statements. A return_statement shall include a return expression if and only if it applies to a function body.
Dynamic Semantics
For the execution of a return_statement, the expression (if any) is first evaluated and converted to the result subtype.
If the result type is class-wide, then the tag of the result is the tag of the value of the expression.
If the result type is a specific tagged type:
A type is a return-by-reference type if it is a descendant of one of the following:
If the result type is a return-by-reference type, then a check is made that the return expression is one of the following:
The exception Program_Error is raised if this check fails.
For a function with a return-by-reference result type the result is returned by reference; that is, the function call denotes a constant view of the object associated with the value of the return expression. For any other function, the result is returned by copy; that is, the converted value is assigned into an anonymous constant created at the point of the return_statement, and the function call denotes that object.
Finally, a transfer of control is performed which completes the execution of the callable construct to which the return_statement applies, and returns to the caller.
Examples
Examples of return statements:
return; -- in a procedure body, entry_body, or accept_statement return Key_Value(Last_Index); -- in a function body
About DocAda Light:
Preface / Preliminary
/ Help
/ TOC
/ Copyright
DocAda Online at the Ada Home:
Complete RM95
/ Updates
/ News
|
|
|
|