8.1 Declarative Region
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
Static Semantics
1For each of the following constructs, there is a portion of the program text called its declarative region, [within which nested declarations can occur]:
- any declaration, other than that of an enumeration type, that is not a completion [of a previous declaration];
- an
access_definition
; 2.2/5 - an
iterated_component_association
; 2.3/5 - an
iterated_element_association
; 2.4/5 - a
quantified_expression
; 2.5/5 - a
declare_expression
; 3 - a
block_statement
; 4 - a
loop_statement
; 4.1/5 - This paragraph was deleted.
- an
extended_return_statement
; 5 - an
accept_statement
; 6 - an
exception_handler
.
The declarative region includes the text of the construct together with additional text determined [(recursively)], as follows:
- If a declaration is included, so is its completion, if any.
- If the declaration of a library unit [(including Standard — see 10.1.1)] is included, so are the declarations of any child units [(and their completions, by the previous rule)]. The child declarations occur after the declaration.
- If a
body_stub
is included, so is the correspondingsubunit
. 11 - If a
type_declaration
is included, then so is a correspondingrecord_representation_clause
, if any.
component_declaration
s can be directly visible in the record_representation_clause
. The declarative region of a declaration is also called the declarative region of any view or entity declared by the declaration.
parent_unit_name
s. context_clause
s. A declaration occurs immediately within a declarative region if this region is the innermost declarative region that encloses the declaration (the immediately enclosing declarative region), not counting the declarative region (if any) associated with the declaration itself.
[ A declaration is local to a declarative region if the declaration occurs immediately within the declarative region.] [An entity is local to a declarative region if the entity is declared by a declaration that is local to the declarative region.]
A declaration is global to a declarative region if the declaration occurs immediately within another declarative region that encloses the declarative region. An entity is global to a declarative region if the entity is declared by a declaration that is global to the declarative region.
subprogram_declaration
, subprogram_body
, entry_declaration
, subprogram_renaming_declaration
, formal_subprogram_declaration
, access-to-subprogram type_declaration
), anything that has a discriminant_part
(that is, various kinds of type_declaration
), anything that has a component_list
(that is, record type_declaration
and record extension type_declaration
), and finally the declarations of task and protected units and packages. Wording Changes from Ada 83
- Child library units.
- Derived types/type extensions — we need a declarative region for inherited components and also for new components.
- All the kinds of types that allow discriminants.
- Protected units.
- Entries that have bodies instead of accept statements.
- The
choice_parameter_specification
of anexception_handler
. 18.i - The formal parameters of access-to-subprogram types.
- Renamings-as-body.
accept_statement
has its own declarative region, rather than being part of the declarative region of the entry_declaration
, so that declarative regions are properly nested regions of text, so that it makes sense to talk about "inner declarative regions", and "...extends to the end of a declarative region". Inside an accept_statement
, the name
of one of the parameters denotes the parameter_specification
of the accept_statement
, not that of the entry_declaration
. If the accept_statement
is nested within a block_statement
, these parameter_specification
s can hide declarations of the block_statement
. The semantics of such cases was unclear in RM83. accept_statement
, but accept_statement
s are not declarations. They should be, and they should hide the entry from all visibility within themselves. entry_bodies
, or other bodies, because the declarative_part
of a body is not supposed to contain (explicit) homographs of things in the declaration. It works for accept_statement
s only because an accept_statement
does not have a declarative_part
.Wording Changes from Ada 95
Extended_return_statement
(see 6.5) is added to the list of constructs that have a declarative region. Extensions to Ada 2012
access_definition
is added to the list of constructs that have a declarative region. This allows parameter names declared in anonymous access type subprogram types to be the same as other names declared outside. For instance: type Foo is record
A : Natural;
B : access procedure (A : Boolean);
end record;
Wording Changes from Ada 2012
iterated_component_association
, iterated_element_association
, and declare_expression
to the rapidly expanding list of constructs that have a declarative region.