____ | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

10.1.1 Compilation Units - Library Units

A library_item is a compilation unit that is the declaration, body, or renaming of a library unit. Each library unit (except Standard) has a parent unit, which is a library package or generic library package. A library unit is a child of its parent unit. The root library units are the children of the predefined library package Standard.
       compilation ::= {compilation_unit}
       compilation_unit ::=
           context_clause library_item
         | context_clause subunit
       library_item ::= [private] library_unit_declaration
         | library_unit_body
         | [private] library_unit_renaming_declaration
       library_unit_declaration ::=
            subprogram_declaration | package_declaration
          | generic_declaration    | generic_instantiation
       library_unit_renaming_declaration ::=
        | generic_renaming_declaration
        | subprogram_renaming_declaration
       library_unit_body ::= subprogram_body | package_body
       parent_unit_name ::= name
A library unit is a program unit that is declared by a library_item. When a program unit is a library unit, the prefix ``library'' is used to refer to it (or ``generic library'' if generic), as well as to its declaration and body, as in ``library procedure'', ``library package_body'', or ``generic library package''. The term compilation unit is used to refer to a compilation_unit. When the meaning is clear from context, the term is also used to refer to the library_item of a compilation_unit or to the proper_body of a subunit (that is, the compilation_unit without the context_clause and the separate (parent_unit_name)).
The parent declaration of a library_item (and of the library unit) is the declaration denoted by the parent_unit_name, if any, of the defining_program_unit_name of the library_item. If there is no parent_unit_name, the parent declaration is the declaration of Standard, the library_item is a root library_item, and the library unit (renaming) is a root library unit (renaming). The declaration and body of Standard itself have no parent declaration. The parent unit of a library_item or library unit is the library unit declared by its parent declaration.
The children of a library unit occur immediately within the declarative region of the declaration of the library unit. The ancestors of a library unit are itself, its parent, its parent's parent, and so on. (Standard is an ancestor of every library unit.) The descendant relation is the inverse of the ancestor relation.
A library_unit_declaration or a library_unit_renaming_declaration is private if the declaration is immediately preceded by the reserved word private; it is otherwise public. A library unit is private or public according to its declaration. The public descendants of a library unit are the library unit itself, and the public descendants of its public children. Its other descendants are private descendants.
Legality Rules
The parent unit of a library_item shall be a library package or generic library package.
If a defining_program_unit_name of a given declaration or body has a parent_unit_name, then the given declaration or body shall be a library_item. The body of a program unit shall be a library_item if and only if the declaration of the program unit is a library_item. In a library_unit_renaming_declaration, the (old) name shall denote a library_item.
A parent_unit_name (which can be used within a defining_program_unit_name of a library_item and in the separate clause of a subunit), and each of its prefixes, shall not denote a renaming_declaration. On the other hand, a name that denotes a library_unit_renaming_declaration is allowed in a with_clause and other places where the name of a library unit is allowed.
If a library package is an instance of a generic package, then every child of the library package shall either be itself an instance or be a renaming of a library unit.
A child of a generic library package shall either be itself a generic unit or be a renaming of some other child of the same generic unit. The renaming of a child of a generic package shall occur only within the declarative region of the generic package.
A child of a parent generic package shall be instantiated or renamed only within the declarative region of the parent generic.
For each declaration or renaming of a generic unit as a child of some parent generic package, there is a corresponding declaration nested immediately within each instance of the parent. This declaration is visible only within the scope of a with_clause that mentions the child generic unit.
A library subprogram shall not override a primitive subprogram.
The defining name of a function that is a compilation unit shall not be an operator_symbol.
Static Semantics
A subprogram_renaming_declaration that is a library_unit_renaming_declaration is a renaming-as-declaration, not a renaming-as-body.
There are two kinds of dependences among compilation units:
A library_item depends semantically upon its parent declaration. A subunit depends semantically upon its parent body. A library_unit_body depends semantically upon the corresponding library_unit_declaration, if any. A compilation unit depends semantically upon each library_item mentioned in a with_clause of the compilation unit. In addition, if a given compilation unit contains an attribute_reference of a type defined in another compilation unit, then the given compilation unit depends semantically upon the other compilation unit. The semantic dependence relationship is transitive.

Examples of library units:
       package Rational_Numbers.IO is  -- public child of Rational_Numbers, see 7.1
          procedure Put(R : in  Rational);
          procedure Get(R : out Rational);
       end Rational_Numbers.IO;
       private procedure Rational_Numbers.Reduce(R : in out Rational);
                                       -- private child of Rational_Numbers
       with Rational_Numbers.Reduce;   -- refer to a private child
       package body Rational_Numbers is
       end Rational_Numbers;
       with Rational_Numbers.IO; use Rational_Numbers;
       with Ada.Text_io;               -- see A.10
       procedure Main is               -- a root library procedure
          R : Rational;
          R := 5/3;                    -- construct a rational number, see 7.1
          Ada.Text_IO.Put("The answer is: ");
       end Main;
       with Rational_Numbers.IO;
       package Rational_IO renames Rational_Numbers.IO;
                                       -- a library unit renaming declaration
Each of the above library_items can be submitted to the compiler separately.

____ | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12