10.1.6 Environment-Level Visibility Rules
[The normal visibility rules do not apply within
a
parent_unit_name
or a
context_clause,
nor within a
pragma
that appears at the place of a compilation unit. The special visibility
rules for those contexts are given here.]
Static Semantics
{
AI95-00217-06}
{
AI95-00312-01}
Within
the
parent_unit_name
at the beginning of an explicit
library_item,
and within a
nonlimited_with_clause,
the only declarations that are visible are those that are explicit
library_items
of the environment, and the only declarations that are directly visible
are those that are explicit root
library_items
of the environment. Within a
limited_with_clause,
the only declarations that are visible are those that are the implicit
declaration of the limited view of a library package of the environment,
and the only declarations that are directly visible are those that are
the implicit declaration of the limited view of a root library package.
Ramification: In “package
P.Q.R is ... end P.Q.R;”, this rule requires P to
be a root library unit, and Q to be a library unit (because those are
the things that are directly visible and visible). Note that visibility
does not apply between the “end” and the “;”.
Physically nested declarations are not visible
at these places.
Although Standard is visible at these places,
it is impossible to name it, since it is not directly visible, and it
has no parent.
{
AI95-00217-06}
Only compilation units defining limited views can be mentioned in a
limited_with_clause,
while only compilation units defining full views (that is, the explicit
declarations) can be mentioned in a
nonlimited_with_clause.
This resolves the conflict inherent in having two compilation units with
the same defining name.
Within
a
use_clause
or
pragma
that is within a
context_clause,
each
library_item
mentioned in a previous
with_clause
of the same
context_clause
is visible, and each root
library_item
so mentioned is directly visible. In addition, within such a
use_clause,
if a given declaration is visible or directly visible, each declaration
that occurs immediately within the given declaration's visible part is
also visible. No other declarations are visible or directly visible.
Discussion: Note the word “same”.
For example, if a
with_clause
on a declaration mentions X, this does not make X visible in
use_clauses
and
pragmas
that are on the body. The reason for this rule is the one-pass
context_clauses
Language Design Principle.
Note that the second part of the rule does not
mention
pragmas.
Within a
pragma that
appears at the place of a compilation unit, the immediately preceding
library_item
and each of its ancestors is visible. The ancestor root
library_item
is directly visible.
Reason: This rule allows with
A.B; and pragma Elaborate(A.B); where A is a generic library package
and B is one of its (generic) children. This is necessary because it
is not normally legal to use an expanded name to reach inside a generic
package.
Wording Changes from Ada 83
We considered making the visibility rules within
parent_unit_names
and
context_clauses
follow from the context of compilation. However, this attempt failed
for various reasons. For example, it would require
use_clauses
in
context_clauses
to be within the declarative region of Standard, which sounds suspiciously
like a kludge. And we would still need a special rule to prevent seeing
things (in our own
context_clause)
that were with-ed by our parent, etc.
Wording Changes from Ada 95
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe