10.1 Compilation Units - Library Units (paragraph 6)10.1 Compilation Units - Library Units (paragraph 6)10.1 Compilation Units - Library Units (paragraph 6)
A subprogram body given in a compilation unit is interpreted as a secondary unit if the program
library already contains a library unit with the name of the subprogram; it is otherwise
interpreted both as a library unit and as the corresponding library unit body (that is, as a
secondary unit).
10.1 Compilation Units - Library Units (paragraph 11)10.1 Compilation Units - Library Units (paragraph 11)10.1 Compilation Units - Library Units (paragraph 11)
identifier 2.3, library unit 10.5, local declaration 8.1, must 1.6, name 4.1,
occur immediately within 8.1, operator 4.5, operator symbol 6.1, overloading
6.6 8.7, package body 7.1, package declaration 7.1, parameter of a subprogram
6.2, pragma 2.8, procedure 6.1, program unit 6, proper body 3.9, renaming
declaration 8.5, simple name 4.1, standard package 8.6, subprogram 6,
subprogram body 6.3, subprogram declaration 6.1, subunit 10.2, task 9,
visibility 8.3
10.1.1 Context Clauses - With Clauses (paragraph 9)10.1.1 Context Clauses - With Clauses (paragraph 9)10.1.1 Context Clauses - With Clauses (paragraph 9)
The following is an example of a main program consisting of a single compilation unit: a
procedure for printing the real roots of a quadratic equation. The predefined package TEXT_IO and
a user-defined package REAL_OPERATIONS (containing the definition of the type REAL and of the
packages REAL_IO and REAL_FUNCTIONS) are assumed to be already present in the program library.
Such packages may be used by other main programs.
10.1.1 Context Clauses - With Clauses (paragraph 11)10.1.1 Context Clauses - With Clauses (paragraph 11)10.1.1 Context Clauses - With Clauses (paragraph 11)
The with clauses of a compilation unit need only mention the names of those library subprograms
and packages whose visibility is actually necessary within the unit. They need not (and should
not) mention other library units that are used in turn by some of the units named in the with
clauses, unless these other library units are also used directly by the current compilation unit.
For example, the body of the package REAL_OPERATIONS may need elementary operations provided by
other packages. The latter packages should not be named by the with clause of QUADRATIC_EQUATION
since these elementary operations are not directly called within its body.
-1 Context Clauses - With Clauses (paragraph 11) 10.1.1
10.2 Subunits of Compilation Units (paragraphs 3 4)10.2 Subunits of Compilation Units (paragraphs 3 4)10.2 Subunits of Compilation Units (paragraphs 3 4)
A body stub is only allowed as the body of a program unit (a subprogram, a package, a task unit,
or a generic unit) if the body stub occurs immediately within either the specification of a
library package or the declarative part of another compilation unit.
If the body of a program unit is a body stub, a separately compiled subunit containing the
corresponding proper body is required. In the case of a subprogram, the subprogram specifications
given in the proper body and in the body stub must conform (see 6.3.1).
10.2.1 Examples of Subunits (paragraph 9)10.2.1 Examples of Subunits (paragraph 9)10.2.1 Examples of Subunits (paragraph 9)
In the above example TRANSFORM and FACILITY are subunits of TOP, and G is a subunit of FACILITY.
The visibility in the split version is the same as in the initial version except for one change:
since TEXT_IO is only used within G, the corresponding with clause is written for G instead of for
TOP. Apart from this change, the same identifiers are visible at corresponding program points in
the two versions. For example, all of the following are (directly) visible within the proper
body of the subunit G: the procedure TOP, the type REAL, the variables R and S, the package
FACILITY and the contained named number PI and subprograms F and G.
10.3 Order of Compilation (paragraphs 3 4)10.3 Order of Compilation (paragraphs 3 4)10.3 Order of Compilation (paragraphs 3 4)
If any error is detected while attempting to compile a compilation unit, then the attempted
compilation is rejected and it has no effect whatsoever on the program library; the same holds
for recompilations (no compilation unit can become obsolete because of such a recompilation).
The order in which the compilation units of a program are compiled must be consistent with the
partial ordering defined by the above rules.
10.3 Order of Compilation (paragraph 16)10.3 Order of Compilation (paragraph 16)10.3 Order of Compilation (paragraph 16)
For library packages, it follows from the recompilation rules that a package body is made obsolete
by the recompilation of the corresponding specification. If the new package specification is such
that a package body is not required (that is, if the package specification does not contain the
declaration of a program unit), then the recompilation of a body for this package is not required.
In any case, the obsolete package body must not be used and can therefore be deleted from the
program library.
10.4 The Program Library (paragraphs 1 2)10.4 The Program Library (paragraphs 1 2)10.4 The Program Library (paragraphs 1 2)
10.3 Order of Compilation (paragraph 16) -2
Compilers are required to enforce the language rules in the same manner for a program consisting
of several compilation units (and subunits) as for a program submitted as a single compilation.
Consequently, a library file containing information on the compilation units of the program
library must be maintained by the compiler or compiling environment. This information may include
symbol tables and other information pertaining to the order of previous compilations.
A normal submission to the compiler consists of the compilation unit(s) and the library file. The
latter is used for checks and is updated for each compilation unit successfully compiled.
10.5 Elaboration of Library Units (paragraph 2)10.5 Elaboration of Library Units (paragraph 2)10.5 Elaboration of Library Units (paragraph 2)
The elaboration of these library units and of the corresponding library unit bodies is performed
in an order consistent with the partial ordering defined by the with clauses (see 10.3). In
addition, a library unit mentioned by the context clause of a subunit must be elaborated before
the body of the ancestor library unit of the subunit.
10.6 Program Optimization (paragraph (1)10.6 Program Optimization (paragraph (1)10.6 Program Optimization (paragraph (1)
Optimization of the elaboration of declarations and the execution of statements may be performed
by compilers. In particular, a compiler may be able to optimize a program by evaluating certain
expressions, in addition to those that are static expressions. Should one of these expressions,
whether static or not, be such that an exception would be raised by its evaluation, then the code
in that path of the program can be replaced by code to raise the exception; the same holds for
exceptions raised by the evaluation of names and simple expressions. (See also section 11.6.)