Next: Class and Type Specifiers
Up: Programs
Previous: Classes and Types
The execution of a program consists of three steps:
- Establish types and classes: Collect all the class
declarations which are directly or indirectly referred to from the
main class K, transform them into classes and create the type
dependence graph TDG.
- Initialize: Allocate and initialize all shared attributes
within those classes, cf. 5.2.
- Execute: Call the procedure main in the main class K as
K::main.
Hint: Step 1 is usually part of program compilation whereas steps 2
and 3 constitute the program execution proper.
The required class declarations are given by class specifiers.
Establishing types and classes consists of:
- Determining the program text: Starting from a collection of
class declarations and a distinguished declaration of the main class
K, the transitive closure
of K is inductively determined:
- K belongs to
. - If a class specifier C or $C with or without
arguments occurs in a class declaration belonging to
then
the class declaration for C also belongs to
. There must be
exactly one such class declaration with the appropriated number of
parameters in the given collection. Hint: Some of the class
declarations may be predefined and a priori known to the language
processor. There are language constructs which are only meaningful
with respect to such predefined classes.
The classes belonging to
together form the text of the program. - Resolution of class parameters: If any of the class
declarations in
is generic, i.e. its heading
contains class parameters
with or without
type bounds, then it is replaced in
by a set of class
declarations obtained as follows: For each class specifier
occurring in any class declaration D
in
a copy of C is made in which all parameters
are
consistently replaced by the corresponding
. $symbols
contained in any of the class specifiers
are retained.
The number of parameters in the class declaration and the number of
arguments in the class specifier must agree. The replacements are
made in textual order,
is replaced first. If any
also
occurs (as part of) a type bound then it is treated according to the
same rules. The feature resolution restrictions given in 7.2
apply.
If initially a class specifier
is or contains a specifier which
itself is a class parameter of the class declaration D then D must
have been processed before C is considered. A program is illegal
if it is not possible to find an order of the class declarations
satisfying this requirement.
The identifiers of all the class parameters
must be pairwise
distinct.
Note: According to these rules class parameters
are local to the class declaration D and shadow any class
identifiers declared globally.
- Resolution of inheritance: The set
of class declaration is
transformed into a set
of classes as follows:
- The class declarations in
are topologically sorted such
that a class D which inherits a
class C appears after class C. A program is illegal
if such a topogical sort is not possible, i.e. if the inheritance
relation
contains cycles. - Any class declaration in
which does not contain
inheritances belongs to
. - The remaining classes in
are considered in an order
consistent with the topological sort in step (a). If a class
declaration D in
inherits the classes
then all the
must already belong to
. Then a class D is added
to
which is derived from the class declaration D by textually
replacing the inheritance clauses by possibly modified copies
of the bodies of their corresponding classes. The potential
modifications are described in 4.4. - If in step (c) a class C is inherited as a subtype then the
type dependence graph TDG is augmented by a dependence
.
- Checking of type conformance: For every class argument
which in step 2 replaced a class parameter P and for which P was
specified by P<T with a type bound T, it is checked that
structurally conforms to T as explained in 2.1.5,
where T is the type bound of P. A missing type bound means that
the minimal constraints for
are inferred from the body of the
generic class and that P must fulfill them all.
For every dependence
in the type dependence graph
it is checked that D conforms to C as explained in 2.1.5.
Hint: Steps 1-3 are textual substitutions which do not
require any semantic processing except for identifying class
declarations for a given class name.
Next: Class and Type Specifiers
Up: Programs
Previous: Classes and Types
Martin Trapp
Mon Feb 17 16:49:16 MET 1997