Go to the first, previous, next, last section, table of contents.


7.1 Package Specifications and Declarations

  1. 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

  2. package_declaration ::= package_specification;
    
  3. package_specification ::=
       package defining_program_unit_name is
          {basic_declarative_item}
       [private
          {basic_declarative_item}]
       end [[parent_unit_name.]identifier]
    
    1. If 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

  1. A package_declaration or generic_package_declaration requires a completion (a body) if it contains any declarative_item that requires a completion, but whose completion is not in its package_specification.

    Static Semantics

  2. The first list of declarative_items 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 declarative_items 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.
  3. 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 section 10.1.1 Compilation Units - Library Units. 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_clauses, See section 4.1.3 Selected Components, and See section 8.4 Use Clauses.

    Dynamic Semantics

  4. The elaboration of a package_declaration consists of the elaboration of its basic_declarative_items in the given order.

    NOTES

  5. (1) The visible part of a package contains all the information that another program unit is able to know about the package.
  6. (2) If a declaration occurs immediately within the specification of a package, and the declaration has a corresponding completion that is a body, then that body has to occur immediately within the body of the package.

    Examples

  7. Example of a package declaration:
  8. package Rational_Numbers is
    
  9. type Rational is
       record
          Numerator   : Integer;
          Denominator : Positive;
       end record;
    
  10.    function "="(X,Y : Rational) return Boolean;
    
  11.    function "/"  (X,Y : Integer)  return Rational;
       --  to construct a rational number
    
  12.    function "+"  (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;
    
  13. There are also many examples of package declarations in the predefined language environment, See section A Predefined Language Environment (normative).


Go to the first, previous, next, last section, table of contents.