3.11 Declarative Parts
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[A declarative_part
contains declarative_item
s (possibly none).]
Syntax
2declarative_part
::=
{declarative_item
}
3declarative_item
::=
basic_declarative_item
| body
4/1{8652/0009} basic_declarative_item
::=
basic_declaration
| aspect_clause
| use_clause
5body
::=
proper_body
| body_stub
6proper_body
::=
subprogram_body
| package_body
| task_body
| protected_body
Static Semantics
6.1/2The list of declarative_item
s of a declarative_part
is called the declaration list of the declarative_part
.
Dynamic Semantics
7The elaboration of a declarative_part
consists of the elaboration of the declarative_item
s, if any, in the order in which they are given in the declarative_part
.
An elaborable construct is in the elaborated state after the normal completion of its elaboration. Prior to that, it is not yet elaborated.
For a construct that attempts to use a body, a check (Elaboration_Check) is performed, as follows:
- {8652/0014} For a call to a (non-protected) subprogram that has an explicit body, a check is made that the body is already elaborated. This check and the evaluations of any actual parameters of the call are done in an arbitrary order.
pragma
Interface (or equivalently, pragma
Import). AI83-00430 specifies that there is no elaboration check for an enumeration literal. AI83-00406 specifies that the evaluation of parameters and the elaboration check occur in an arbitrary order. AI83-00406 applies to generic instantiation as well (see below).null_procedure_declaration
, or an expression_function_declaration
, and we need to make an elaboration check on such a body, so we use “body” rather than subprogram_body
above. - For a call to a protected operation of a protected type (that has a body — no check is performed if the protected type is imported — see B.1), a check is made that the
protected_body
is already elaborated. This check and the evaluations of any actual parameters of the call are done in an arbitrary order.
protected_body
does not elaborate the enclosed bodies, since they are not considered independently elaborable.task_body
has been seen. Such calls are simply queued until the task is activated and reaches a corresponding accept_statement
. We considered a similar rule for protected entries — simply queuing all calls until the protected_body
was seen, but felt it was not worth the possible implementation overhead, particularly given that there might be multiple instances of the protected type. - For the activation of a task, a check is made by the activator that the
task_body
is already elaborated. If two or more tasks are being activated together (see 9.2), as the result of the elaboration of adeclarative_part
or the initialization for the object created by an allocator, this check is done for all of them before activating any of them.
- For the instantiation of a generic unit that has a body, a check is made that this body is already elaborated. This check and the evaluation of any
explicit_generic_actual_parameter
s of the instantiation are done in an arbitrary order.
The exception Program_Error is raised if any of these checks fails.
Extensions to Ada 83
declarative_part
is modified to remove the ordering restrictions of Ada 83; that is, the distinction between basic_declarative_item
s and later_declarative_item
s within declarative_part
s is removed. This means that things like use_clause
s and object_declaration
s can be freely intermixed with things like bodies.proper_body
now allows a protected_body
, and the rules for elaboration checks now cover calls on protected operations. Wording Changes from Ada 83
declarative_item
s here, and for other things in 3.1, “Declarations”. That's no longer necessary, since these terms are fully defined in 3.1.declarative_part
are optional (except for the one in block_statement
with a declare) which is sort of strange, since a declarative_part
can be empty, according to the syntax. That is, declarative_part
s are sort of “doubly optional”. In Ada 95, these declarative_part
s are always required (but can still be empty). To simplify description, we go further and say (see 5.6, “Block Statements”) that a block_statement
without an explicit declarative_part
is equivalent to one with an empty one. Wording Changes from Ada 95
3.11.1 Completions of Declarations
1/3{8652/0014} Declarations sometimes come in two parts. A declaration that requires a second part is said to require completion. The second part is called the completion of the declaration (and of the entity declared), and is either another declaration, a body, or a pragma
. A body is a body
, an entry_body
, a null_procedure_declaration
or an expression_function_declaration
that completes another declaration, or a renaming-as-body (see 8.5.4).
Name Resolution Rules
2A construct that can be a completion is interpreted as the completion of a prior declaration only if:
- The declaration and the completion occur immediately within the same declarative region;
- The defining name or
defining_program_unit_name
in the completion is the same as in the declaration, or in the case of apragma
, thepragma
applies to the declaration; 5 - If the declaration is overloadable, then the completion either has a type-conformant profile, or is a
pragma
.
Legality Rules
6/3An implicit declaration shall not have a completion. For any explicit declaration that is specified to require completion, there shall be a corresponding explicit completion, unless the declared entity is imported (see B.1).
subprogram_body
. That's because the completion rules are described in terms of constructs (subprogram_declaration
s) and not entities (subprograms). When a completion is required, it has to be explicit; the implicit null package_body
that Clause 7 talks about cannot serve as the completion of a package_declaration
if a completion is required. At most one completion is allowed for a given declaration. Additional requirements on completions appear where each kind of completion is defined.
A type is completely defined at a place that is after its full type definition (if it has one) and after all of its subcomponent types are completely defined. A type shall be completely defined before it is frozen (see 13.14 and 7.3).
Wording Changes from Ada 83
pragma
Import for any kind of entity. Wording Changes from Ada 95
body
or body.