Go to the first, previous, next, last section, table of contents.
-
For each declaration, the language rules define a certain portion of the
program text called the scope of the declaration. The scope of a
declaration is also called the scope of any view or entity declared by
the declaration. Within the scope of an entity, and only there, there
are places where it is legal to refer to the declared entity. These
places are defined by the rules of visibility and overloading.
Static Semantics
-
The immediate scope of a declaration is a portion of the declarative
region immediately enclosing the declaration. The immediate scope starts
at the beginning of the declaration, except in the case of an
overloadable declaration, in which case the immediate scope starts just
after the place where the profile of the callable entity is determined
(which is at the end of the _specification for the callable entity, or
at the end of the generic_instantiation if an instance). The immediate
scope extends to the end of the declarative region, with the following
exceptions:
-
The immediate scope of a library_item includes only its semantic
dependents.
-
The immediate scope of a declaration in the private part of a library
unit does not include the visible part of any public descendant of that
library unit.
-
The visible part of (a view of) an entity is a portion of the text of
its declaration containing declarations that are visible from outside.
The private part of (a view of) an entity that has a visible part
contains all declarations within the declaration of (the view of) the
entity, except those in the visible part; these are not visible from
outside. Visible and private parts are defined only for these kinds of
entities: callable entities, other program units, and composite types.
-
The visible part of a view of a callable entity is its profile.
-
The visible part of a composite type other than a task or protected type
consists of the declarations of all components declared (explicitly or
implicitly) within the type_declaration.
-
The visible part of a generic unit includes the generic_formal_part. For
a generic package, it also includes the first list of
basic_declarative_items of the package_specification. For a generic
subprogram, it also includes the profile.
-
The visible part of a package, task unit, or protected unit consists of
declarations in the program unit's declaration other than those
following the reserved word private, if any; See section 7.1 Package Specifications and Declarations, and
See section 12.7 Formal Packages, for packages, See section 9.1 Task Units and Task Objects, for task units, and See section 9.4 Protected Units and Protected Objects,
for protected units.
-
The scope of a declaration always contains the immediate scope of the
declaration. In addition, for a given declaration that occurs
immediately within the visible part of an outer declaration, or is a
public child of an outer declaration, the scope of the given declaration
extends to the end of the scope of the outer declaration, except that
the scope of a library_item includes only its semantic dependents.
-
The immediate scope of a declaration is also the immediate scope of the
entity or view declared by the declaration. Similarly, the scope of a
declaration is also the scope of the entity or view declared by the
declaration.
NOTES
-
(4) There are notations for denoting visible declarations that are not
directly visible. For example, parameter_specifications are in the
visible part of a subprogram_declaration so that they can be used in
named-notation calls appearing outside the called subprogram. For
another example, declarations of the visible part of a package can be
denoted by expanded names appearing outside the package, and can be made
directly visible by a use_clause.
Go to the first, previous, next, last section, table of contents.