General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tutorial on Name AnalysisClasses with Multiple Inheritance
Our previous examples of modules and To avoid confusion with the so far specified scope rules we introduce a new language construct for declaration of classes: Class.con[28]== Declaration: 'class' DefIdent Inheritances ClassBlock ';'. ClassBlock: Compound. Inheritances: Inheritance*. Inheritance: ':' InheritIdent. InheritIdent: Ident. This macro is attached to a product file. Applied identifier occurrences within the body of a class are bound to definitions of that range, or to definitions that are visible due to inheritances from other classes (or modules), or to definitions in the ranges that enclose the class declaration.
Hence, the scopes obtained from inheritances are inserted
into the environment hierarchy of the class body, as
in the case of our
Since classes that are used for inheritance may
inherit from other classes, the inheritance relation must form
a partial order. It must not be cyclic.
A class
That partial order governs hiding of definitions:
A definition of an identifier Hence, the scope property of a class is the scope of the class body embedded in the environment of the inheritance relation for that class.
Wherever the class identifier is visible it can be used for
qualified access, as introduced for modules:
A qualified access
These scope rules are specified using the techniques of the
last two examples:
A class has a scope property, as a module has; and
a class body inherits other scopes as our Class.lido[29]== SYMBOL ClassBlock INHERITS ExportRange, InhRange END; RULE: Declaration ::= 'class' DefIdent Inheritances ClassBlock ';' COMPUTE ClassBlock.ScopeKey = DefIdent.Key; ClassBlock.GotInh = Inheritances CONSTITUENTS InheritIdent.InheritOk; Inheritances.InnerScope = ClassBlock.Env; END; SYMBOL Inheritances: InnerScope: Environment; This macro is attached to a product file.
The
The role ClassInherit.lido[30]== SYMBOL InheritIdent INHERITS InheritScope, ChkInherit, IdUseEnv, ChkIdUse, IdentOcc COMPUTE SYNT.ScopeKey = THIS.Key; SYNT.InnerScope = INCLUDING Inheritances.InnerScope; END; This macro is attached to a product file.
It has also to be checked that the The library module for scope properties ensures that all relevant inheritances are considered, all relevant scope properties are associated, and all relevant definitions are encountered, before applied identifier occurrences are bound in the class body or in qualified accesses.
We now introduce an additional uniqueness requirement for inheritance:
If an applied identifier occurrence is bound to a definition
in an inherited environment there must not be a not hidden binding of
that identifier in another inherited environment.
Such an alternative binding is checked by UniqueInherit.lido[31]== SYMBOL UseIdent INHERITS ChkInhIdUse END; SYMBOL TypeUseIdent INHERITS ChkInhIdUse END; SYMBOL QualIdent INHERITS ChkInhQualIdUse END; SYMBOL SelectIdent INHERITS ChkInhQualIdUse END; This macro is attached to a product file.
|