13.07.2015 Views

A Graph-Based Generic Type System for Object-Oriented Programs

A Graph-Based Generic Type System for Object-Oriented Programs

A Graph-Based Generic Type System for Object-Oriented Programs

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Type</strong> Operations 26other, we construct the graph of C〈α〉 and these instantiations C〈s i 〉 of C〈α〉 all together. Wefirst identify the nodes of the graph, each of which represents a type expression that C〈α〉 refersto, directly or indirectly. This can be done by using a function to associate each type expressionwith a unique node. Then, we add the edges between these nodes based on the relations betweentheir corresponding type expressions.Let F be an injective function from type expressions to N such that F (t) = t <strong>for</strong> t ∈ C ∪ X .For a list C of classes, containing a recursive generic class C 0 〈α〉 and all the classes that C 0 refersto, generic or non-generic, the graph of C is constructed by the following procedure through F ,– <strong>for</strong> a superclass extends Cc defined in a class C, we add an edge C ⊲ −→ F (Cc),– <strong>for</strong> an attribute Te a defined in a class C, we add an edge C a −→ F (Te),– <strong>for</strong> a parameter Te x of method m defined in a class C, we add a path C σ.m.x −−−→ Te,– <strong>for</strong> each edge C a −→ F (Te) and each instantiation C〈s〉 of C, we add an edge F (C〈s〉) a −→F (Te〈s〉),– <strong>for</strong> each path C −−−→ σ.m.x F (Te) and each instantiation C〈s〉 of C, we add an edge F (C〈s〉) −−−→σ.m.xF (Te〈s〉),– <strong>for</strong> each class conjunction Te = ⋓ Cc or type variable α with constraint implements ⋓ Cc,we construct the conjunction graph G by conj and change the root of G to F (Te) or α,– <strong>for</strong> each type variable α with constraint extends Cc, we add an edge α ⊲ −→ F (Cc),where C is a generic or non-generic class in C. An instantiation of a type expression Te〈s〉 isdefined as,⎧s(Te) if Te ∈ dom(s),⎪⎨C〈s ′ ◦ s〉 if Te = C〈s ′ 〉,Te〈s〉 ̂=⋓ Cc〈s〉 if Te = ⋓ Cc,⎪⎩Te otherwise.In fact, the above procedure can be generally used to construct the graph of any class, not onlyrecursive generic classes.Fig. 5 shows the graphs of three generic classes, Pair〈α, β〉, List〈γ〉 and Tree〈δ〉. Among thethree, List and Tree are recursive. A List of γ extends a Pair of an element type γ and a Listof γ. A Tree of δ extends a Pair of an element type δ and a List of Tree of δ. In the figure, thetype expression Te in the callout box of a structural node n indicates there is a mapping Te ↦→ nin F .The soundness of the above construction procedure can be proved by the type equivalence betweenan instantiation graph of a recursive generic class C〈α〉, and the subgraph of C〈α〉 correspondingto the class instantiation.Report No. 448, June 2011UNU-IIST, P.O. Box 3058, Macao

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!