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>System</strong> 31∆ 1 ∆ 2 = pop(∆ 1 ) push (∆ 2 , (y, z), (A, B))x zz$$lnk Blnk BlnkB ybxb ybx$b ybx$b y $CaA ZC A ZiaC A Zia iFigure 6: Stack Push and Popbe ill-typed (undefined) with respect to Γ. To address this issue, we introduce a graph notationof type context that describes the the scopes of local variables. A type context graph consistsof nodes representing scopes, and edges labeled by the variables from their scope nodes to thecorresponding type nodes in the underlying type graph.Let O be a new infinite set of nodes disjoint with N .Definition 15 (<strong>Type</strong> Context) A type context is a rooted, directed and labeled graph ∆ =〈N, E, r〉, where– N ⊆ N ∪ O is the set of nodes, containing type nodes N ∩ N and scope nodes N ∩ O,– E : N × (A ∪ {$, self }) → N is the set of edges,– r ∈ N ∩ O is the root of the graph.A type context ∆ = 〈N, E, r〉 is well-<strong>for</strong>med if the following conditions hold,1. each outgoing edge from a scope node is labeled by a variable (or self ), and targets at a typenode,2. all the scope nodes are on a path starting from the root r, with edges labeled by $, and3. except the root r, which has no incoming edge, each scope node has exactly one incomingedge.In Fig. 6, the dashed subgraphs are examples of type contexts.A type context represents a snapshot of the type environment at a time of type-checking, recordingthe types of variables, including self , declared in different scopes at that time. A type contexthas a stack structure. When the type-checking enters a new scope, a node with outgoing edgesrecording the variables in the scope is pushed onto the top of the stack. When the type-checkingexits a scope, the top node of the stack, together with its outgoing edges, is popped out, so thatthe type context recovers to the one exactly be<strong>for</strong>e entering the scope.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!