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.

Execution Environment 42Table 9: Construction of Environment <strong>Graph</strong>sf e (P, Γ, R) ̂=(attributes) t σ −→ · ∈ Γ isCc(Γ, t) t /∈ R es = {t a −→ ini(n) | a −→ n ∈ clo(Γ t), a ≠ σ}f e (P, Γ, 〈R.ns ∪ {t} ∪ {l | t a −→ l ∈ es}, R.es ∪ es, R.sm〉)(static tables) t ∈ R t σ −→ s ∈ Γ t σ −→ s /∈ R ts = {t ′ | Γ ⊢ t t ′ }f e (P, Γ, 〈R.ns ∪ {s}, R.es ∪ {t σ −→ s}, R.sm ∪ {s ↦→ ts}〉)t −→ σ s ∈ R −−→ σ.m· ∈ clo(Γ t) t −−→ σ.m· /∈ R (Γ ′ , k) = insc(Γ, mk(P, Γ, t, m), ssj (Γ, t))(methods)f e (P, Γ ′ , 〈R.ns ∪ {k}, R.es ∪ {s −→ m k}, R.sm〉) R ,where isCc(Γ, t) ̂= t-var(Γ, t) = ∅ ∧ t ∈ U ∨ t-var(Γ, t) ≠ ∅ ∧ t ∈ S is a condition <strong>for</strong> t to be a concreteclass node.In (attributes), the function f e builds the class frame that represents the structure of the initialobject <strong>for</strong> each concrete class node t in Γ. It adds to the environment graph the type nodesrepresenting t, the default values of all attributes, and the edges labeled by attributes outgoingfrom t to the default values. We use ini(t ′ ) to denote the default value of a type node t ′ , i.e.,ini(Z) = 0, ini(B) = false, ini(S) = ε and ini(C) = null <strong>for</strong> any class type C. In (static tables),f e adds the static tables from Γ to the environment graph, and associates each static table withthe set of supertype nodes. Finally, f e constructs outgoing edges from static tables labeled bymethod names, targeting at the instantiated body commands of the methods respectively, asshown in (methods).In order to get the instantiated method body commands, we introduce two functions. First, <strong>for</strong>a class instantiation j ∈ Γ, when we instantiate a command <strong>for</strong> j, the type substitution can berecovered from the edges labeled by type variables in the generic static table of j. The functionssj returns the type substitution. Formally,ssj (Γ, j) ̂= 〈α ↦→ t | α ∈ X , j σ.α −−→ t ∈ Γ〉.Second, <strong>for</strong> method body commands, we define a function mk to lookup in program P <strong>for</strong> bodycommand c of method m of type t. If t is a class instantiation, we track <strong>for</strong> its template genericclass in Γ. Formally, mk(P, Γ, t, m) ̂= c, where⎧⎪⎨ k ′ if ∃t :: m{k ′ } ∈ P,c = mk(P, Γ, t⎪⎩′ , m) if ∃t ′ = gcls(Γ, t),mk(P, Γ, t ′ , m) otherwise, if ∃t −→ ⊲ t ′ ∈ Γ.When t is directly defined in P , mk returns the body command by the method definition, otherwiseit looks up the command in the template generic class or the superclass. Thus, <strong>for</strong> a typeReport 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!