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.

Operational Semantics 48– Case e is w (either a variable or self ).A well-typed variable Γ, ∆ ⊢ w : t can only be deduced from (T-Var) and (T-Self). Thus wehave ∆(w) = t. Because G is well-typed w.r.t. (Γ, ∆), n = G(w) exists and Γ ⊢ Γ(G, n) t.Because ∆(w) = target(search(∆, w)) and G(w) = target(search(G, w)), search(G, w) alsoexists. Hence, by (L-Var), if w ≠ self , l-eval(G, w) exists.– Case e is e ′ .a.A well-typed attribute Γ, ∆ ⊢ e ′ .a : t can only be deduced from (T-Attr). Thus we haveΓ, ∆ ⊢ e ′ : u and u ⊲ −→ ∗ a −→ t ∈ Γ. By the induction hypothesis, eval(G, e ′ ) = q and Γ ⊢Γ(G, q) u. By the subtyping rules, Γ(G, q) ⊲ −→ ∗ a −→ t ∈ Γ. Because G is well-typed w.r.t.(Γ, ∆), there exists q a −→ n ∈ G such that Γ ⊢ Γ(G, n) t. Hence, by (L-Attr), l-eval(G, e ′ .a)exists.– Case e is l (either a literal or null).Since Γ, ∆ ⊢ l : B can only be resulted from (T-Lit), we have T(l) = B. Also by (Lit),eval(G, l) = l.– Case e is (⌈t⌋)e ′ .Since Γ, ∆ ⊢ (⌈t⌋)e ′ : t can only be resulted from (T-DCast), we have Γ, ∆ ⊢ e ′ : t ′ satisfyingΓ ⊢ t t ′ and also Γ ⊢ Ce → ⌈t⌋ <strong>for</strong> some class expression Ce. By induction hypothesis,n = eval(G, e ′ ) exists. If the exceptional case of illegal downcast does not happen, wemust have Γ ⊢ Γ(G, n) t and n must be an object node, since t is translated from aclass expression and cannot be a primitive type. By Condition 5 of the well-<strong>for</strong>mednessof state graphs, there exists a static table s such that n −→ σ s ∈ G. By (static tables) inthe construction of environment graphs, we have t ∈ R.sm(s). Hence, by (Cast), we haveeval(G, (⌈t⌋)e ′ ) = n.– Case e is f(e ′ ).Since Γ, ∆ ⊢ f(e ′ ) : B ′ can only be resulted from (T-Op), we know that f : B → B ′ andΓ, ∆ ⊢ e ′ : B <strong>for</strong> some primitive types B. By induction hypothesis, n = eval(G, e ′ ) existsatisfying T(n) = B. As a result, eval(G, f(e ′ )) = f(n) and T(f(n)) = B ′ .□Theorem 3 (<strong>Type</strong>-Safety of Commands) Let Γ be a type graph, R an environment graphderived from Γ, ∆ and ∆ ⋄ two type contexts, c a command, and G a well-typed state graph w.r.t.(Γ, ∆). Unless one of the exceptional cases happens, if Γ ⊢ u :: m{k} <strong>for</strong> all u −−→ σ.m k ∈ R, andΓ, ∆ → ∆ ⋄ ⊢ c, either1. there exists a well-typed state graph G ⋄ w.r.t. (Γ, ∆ ⋄ ) such that 〈c, G〉 → G ⋄ , or2. there exists a configuration 〈c ′ , G ′ 〉 and a type context ∆ ′ with G ′ being a well-typed state graphw.r.t. (Γ, ∆ ′ ) such that 〈c, G〉 → 〈c ′ , G ′ 〉 and Γ, ∆ ′ → ∆ ⋄ ⊢ c ′ .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!