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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Type</strong> <strong>Graph</strong>s 16Lemma 1 If G ∼ G ′ and a −→ n ∈ G, there exists a −→ n ′ ∈ G ′ and G n ∼ G ′ n ′ .Proof. By induction on the length of a.□We extend the transitive closure of the ⊲ relation to type equivalent rooted graphs.Definition 7 (Subclass) A rooted graph G ′ is a subclass of a rooted graph G, denoted as G ′ G, if∃ ⊲ −→ ∗ n ∈ G ′ • G ′ n ∼ G.3.4 Checking <strong>Type</strong> EquivalenceGiven two rooted graphs X and Y , we check if X and Y are equivalent by using the functiont-eq(X, Y ). The function traverses the two graphs and generates a set Q = (s, t) of pairs. Each(s, t) of the pairs consists of two sets s and t of nodes of X and Y , respectively. Starting with({X.}, {Y.}), each next step checks the targets of the outgoing edges, that have identicallabels, of nodes in each pair of sets already generated. If the node of X (or Y ) being visitedwas visited be<strong>for</strong>e in step i, the corresponding nodes of Y (or X, respectively) being visited areadded to the set of nodes of Y (or X, respectively) in the pair generated in step i; otherwise, anew pair of sets containing these nodes respectively is generated. The traverse terminates whenthere exists a pair (s, t) <strong>for</strong> that the set of labels of the outgoing edges of s is different from thatof t. In this case, the checking function returns false. Otherwise, the checking terminates whenall nodes are visited and the checking function returns true along with the generated set Q ofpairs, if and only if, <strong>for</strong> any pair (s, t) in Q, s and t contain only structural nodes, or are bothsingletons and equal.Table 2 shows the definition of the auxiliary function t-eq 0 . The definition is given by a list ofinference rules, evaluated from the first one. If, <strong>for</strong> a rule, all the conditions above the line hold,the evaluation reduces to the part of the rule below the line, otherwise the next rule is furtherevaluated. We define the t-eq function based on t-eq 0 ast-eq(X, Y ) ̂= t-eq 0 (X, Y, {({X.}, {Y.})}) .If t-eq(X, Y ) returns (Q, true), X and Y are equivalent and we can construct the graph G r fromQ that both X and Y are reducible to. For a pair ({C}, {C}) in Q, where C is nominal, G r hasnode C. And <strong>for</strong> a pair of sets (s, t) of structural nodes in Q, G r has a corresponding structuralnode n that represents all the equivalent nodes in the pair. The outgoing edges of n correspondto the outgoing edges of the equivalent nodes in s and t.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!