DynBindModel: Difference between revisions

From EiffelStudio: an EiffelSoftware project
Jump to navigation Jump to search
Konradm (talk | contribs)
Konradm (talk | contribs)
Line 207: Line 207:
==The naming function==
==The naming function==


The naming function shows for two classes how their feature names are related to each other.
In this section the naming function of a system is shown:
In this section the naming function of a system is shown:



Revision as of 22:28, 16 November 2006

Author: Matthias Konrad

Related articles:


Motivation:

Eiffels dynamic binding is somewhat more complex than that of other languages. Its structure is still very simple and is described by the function:

γ:(TYPE×NAME)→(TYPE→FEATURE)

Function γ contains both the static and dynamic binding part of the language. In the following feature:

f (a: ANY)
   do
      print (a.out)
   end

The static binding part of call a.out can be decribed as:

γ(ANY↦out)

Namely an evaluation of γ with a tuple containing the static type of the call and the name. The result of this is a function. This function evaluated at runtime will yield the right feature according to the dynamic type of a.

In the rest of this text, the construction of the function γ is shown, based on any given valid Eiffel system.

There is a special wiki page that shows an example calculation of the dynamic binding function for a complete system: DynBindModelExamples

Notation

This wiki uses the notation introduced in these slides by Prof. Jean-Raymond Abrial (ETHZ): notation The only difference is the symbol for override which is ≪ (This will be changed as soon as possible). The function operator → is used for partial functions.

Some operators

We will give some rather informal definitions for the set-theoretic operators used here.

Operator: identity

id({e1,…,en}) ={e1↦e1,…,en↦en}

Operator: inverse

{l1↦r1,…,ln↦rn}−1={r1↦l1,…,rn↦ln}

Operator: domain

dom({l1↦r1,…,ln↦rn})={l1,…,ln}

Operator: range

ran({l1↦r1,…,ln↦rn})={r1,…,rn}

Operator: range restriction

E↦F∈r▹T is equivalent to: E↦F∈r∧F∈T

Example:

{1↦2,2↦3,3↦4}▹{3}={2↦3}

Operator: override

E↦F∈p≪q is equivalent to: E↦F∈q∨(E↦F∈p∧E∉dom(p))

Example:

{1↦2,2↦3}≪{1↦4,3↦6}={1↦4,2↦3,3↦6}

Operator: union

E∈UNION x⋅(x∈S | T) is equivalent to: ∃x⋅(x∈S ∧ E∈T)

Example:

UNION x⋅(x∈{1,2,3} | {x,x2}) is equivalent to: {1,2,3,4,9}

Some fundamentals

We introduce the operator > as the "ancestor of" and < as "descendant of" operator.

Without loss of generality we can say that any Eiffel system S is a set of classes {C1,C2…Cn} such that Cq<Cp if q<p. In practice class C1 will allways be class ANY but this is not of importance here.

The function:

  • τ:TYPE→(NAME→FEATURE)

Yields the features declared in a given class.

  • η:TYPE→(TYPE→(NAME→NAME))

Yields the renamings of the different parent parts by a class:

η(D)(B) gives the renamings in class D for the inherited class B.

  • α:TYPE→ℙ(TYPE)

Gives the classes from which a given class inherits:

α(A) Gives the base classes of the of class A.

  • σ:TYPE→(TYPE→ℙ(NAME))

Gives all the selected feature names of an inherited class of a class.

Furthermore we give the following shortcuts:

  • τn for τ(Cn)
  • ηn,b for η(Cn)(b)
  • αn for α(Cn)
  • σn,b for σ(Cn)(b)

An example

For the following System:

class
   B
feature
   f do ... end
end
class
   C
inherit
   B
      rename f as f1 redefine f1 end
feature
   f1 do ... end
end
class
   D
inherit
   C
      select f1 end
   B 
      rename f as f2 redefine f2 end
   B
      rename f as f3 redefine f3 end
feature
   f2 do ... end
   f3 do ... end
end

We get:

  • S={B,C,D}
  • τ={B↦{f↦B.f_},C↦{f1↦C.f1_},D↦{f2↦D.f2_,f3↦D.f3_}}
  • η={C↦{B↦{f↦f1}},D↦{B↦{f↦f2,f↦f3}}}
  • α={C↦{B},D↦{B,C}}
  • σ={D↦{C↦{f1}}}

The naming function

The naming function shows for two classes how their feature names are related to each other. In this section the naming function of a system is shown:

Its structure

βS:(TYPE×TYPE)→(NAME→NAME)

The range of βS is a function. This means, that every name is mapped to just one name. The naming function doesn't only reflect the renaming semantics of a system but also the selects.

We will give a recursive definition of βS. Meaning that we will give β{C1,…Cm} given that we already now β{C1,…Cm−1}

This is valid since:

β{C1}⊆β{C1,C2}⊆…βS

An example

Before we proceed to the definition we show how β{B,C,D} looks like for the example from the previous section:

β{B,C,D}={

(B↦B)↦{f↦f},(B↦C)↦{f↦f1},(B↦D)↦{f↦f1},

(C↦C)↦{f1↦f1},(C↦D)↦{f1↦f1},

(D↦D)↦{f1↦f1,f2↦f2,f3↦f3}}

Definition of the naming function

We introduce the shortcut Sm to denote the system {C1…Cm}. The trivial function S0 is just an empty set. It remains to define Sm for m>0 given that we know Sm−1. This is done by showing what βSm(Cq↦Cp) evaluates to for q≤m and p≤m. There are two trivial cases. When q>p it evaluates to the empty set and when both p and q are smaller than m, it is defined by βSm−1(Cq↦Cp).

A little more interesting is βSm(Cm↦Cm)

As a helper function we also need these functions:

  • βS′:(TYPE×TYPE)→(NAME↔NAME)
  • θS′:(TYPE×TYPE)→(NAME→NAME)

And finally the naming function:

βSm(Cq↦Cp)={∅if q>pβSm−1(Cq↦Cp)if q<=p<mid(dom(τm))∪UNION b⋅(b∈αm | id(ran(βSm−1(b↦b)≪ηm,b)))if q=p=mβSm′(Cq↦Cm)≪θSm(Cq↦Cm)otherwise 

Where

βSm′(Cq↦Cm)=UNION b ⋅ (b∈αm | βSm−1(Cq↦b);(id(ran(βSm−1(Cq↦b)))≪ηm,b))

And:

θSm(Cq↦Cm)=UNION b ⋅ (b∈αm | βSm−1(Cq↦b);(id(ran(βSm−1(Cq↦b)))≪ηm,b)▹σm,b)

The dynamic binding function

With the naming function defined it is surprisingly simple to give the dynamic binding function. To make it even easier we define the function: δ:(TYPE×TYPE)→(NAME→FEATURE)

With this function defined we can derive γ:

γ(S↦fn)={D↦f | δ(S↦D)(fn)=f}

What remains is to define δ. As with the naming function we do it recursively. We define δSm based on δSm−1 since the following holds:

δS1⊆δS2⊆…δS

The definition:

δSm(Cq↦Cp)={∅if q>pδSm−1(Cq↦Cp)if q<=p<mβS(Cq↦Cm);((UNIONb⋅(b∈αm|(βS(b↦b);ηm,b)−1;δSm−1(b↦b)))≪τm)otherwise