DynBindModel: Difference between revisions

From EiffelStudio: an EiffelSoftware project
Jump to navigation Jump to search
Konradm (talk | contribs)
Konradm (talk | contribs)
Line 138: Line 138:
====Its structure====
====Its structure====
<math>\beta_S: \left( \mbox{TYPE} \times \mbox{TYPE} \right) \rightarrow\left( \mbox{NAME} \rightarrow\mbox{NAME} \right)</math>
<math>\beta_S: \left( \mbox{TYPE} \times \mbox{TYPE} \right) \rightarrow\left( \mbox{NAME} \rightarrow\mbox{NAME} \right)</math>
The range of <math>\beta_S\,</math> 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 <math>\beta_S\,</math>. Meaning that we will give <math>\beta_{ \left\{ C_1,\ldots C_m \right\} }</math> given that we already now <math>\beta_{ \left\{ C_1,\ldots C_{m-1} \right\} }</math>
We will give a recursive definition of <math>\beta_S\,</math>. Meaning that we will give <math>\beta_{ \left\{ C_1,\ldots C_m \right\} }</math> given that we already now <math>\beta_{ \left\{ C_1,\ldots C_{m-1} \right\} }</math>

Revision as of 16:22, 6 October 2006

Motivation:

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

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

Relation γ 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 we will show how to construct the relation γ based on any given valid Eiffel system.

Notation

This wiki uses the notation introduced in these slided 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).

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

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}}

Its definition

We introduce the shortcut Sm to denote the system {C1…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 | β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)

An Example

In the following we present, how β{B,C,D} can be constructed based on β{B,C}.

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

So the definition is:

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

An Example

We present the calculation of the function: δ{B,C,D}(B,D). Before we can do that we need to calculate δ{B,C}(B,)