7.1 Package Specifications and Declarations
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[A package is generally provided in two parts: a package_specification
and a package_body
. Every package has a package_specification
, but not all packages have a package_body
.]
Syntax
2package_declaration
::=
package_specification
;
3/3package_specification
::=
package defining_program_unit_name
[aspect_specification
] is
{basic_declarative_item
}
[private
{basic_declarative_item
}]
end [[parent_unit_name
.]identifier
]
4If an identifier
or parent_unit_name
.identifier
appears at the end of a package_specification
, then this sequence of lexical elements shall repeat the defining_program_unit_name
.
Legality Rules
5/2A package_declaration
or generic_package_declaration
requires a completion [(a body)] if it contains any basic_declarative_item
that requires a completion, but whose completion is not in its package_specification
.
Static Semantics
6/2The first list of basic_declarative_item
s of a package_specification
of a package other than a generic formal package is called the visible part of the package. [ The optional list of basic_declarative_item
s after the reserved word private (of any package_specification
) is called the private part of the package. If the reserved word private does not appear, the package has an implicit empty private part.] Each list of basic_declarative_item
s of a package_specification
forms a declaration list of the package.
[An entity declared in the private part of a package is visible only within the declarative region of the package itself (including any child units — see 10.1.1). In contrast, expanded names denoting entities declared in the visible part can be used even outside the package; furthermore, direct visibility of such entities can be achieved by means of use_clause
s (see 4.1.3 and 8.4).]
Dynamic Semantics
8The elaboration of a package_declaration
consists of the elaboration of its basic_declarative_item
s in the given order.
bodies
are disallowed (by the Syntax Rules) in package_specification
s. This does not apply to instances of generic units, whose bodies can occur in package_specification
s. Examples
11Example of a package declaration:
package Rational_Numbers is
13type Rational is
record
Numerator : Integer;
Denominator : Positive;
end record;
14function "="(X,Y : Rational) return Boolean;
15function "/" (X,Y : Integer) return Rational; -- to construct a rational number
16function "+" (X,Y : Rational) return Rational;
function "-" (X,Y : Rational) return Rational;
function "*" (X,Y : Rational) return Rational;
function "/" (X,Y : Rational) return Rational;
end Rational_Numbers;
17There are also many examples of package declarations in the predefined language environment (see Annex A).
Incompatibilities With Ada 83
Wording Changes from Ada 83
package_declaration
but completed in the body. In addition, RM83 forgot to make this rule apply to a generic package. We have corrected these rules. Finally, since we now allow a pragma
Import for any explicit declaration, the completion rules need to take this into account as well. Wording Changes from Ada 95
Extensions to Ada 2005
aspect_specification
can be used in a package_specification
. This is described in 13.1.1.