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> 30c ::= . . . other commands| var ⌈t⌋ x variable declaration| ⌈t⌋.new(le) object creatione ::= . . . other expressions| (⌈t⌋)e typecastextv ::= ⌈t⌋ x external variable decl.⌈t⌋type nodeThrough the type nodes stored in the environment dependent commands, we can lookup thetype in<strong>for</strong>mation in the corresponding environment graph.5.4 <strong>Type</strong> <strong>Graph</strong> CompletenessGiven a program, the type graph Γ of the program must include the graphs of all the possible typeexpressions used in the program. The graphs of the type expressions used in class attribute andmethod parameter definitions are constructed by the procedure described in §4.5. For the typeexpressions used in commands and expressions, we construct the conjunction and instantiationgraphs by applying the shlo, conj , inst and insg functions on the graphs of the operands ofthe type operations, and extend the type graph to include the resulted graphs. We do this byextending the type graph Γ to a new type graph Γ ′ . We only introduce new nodes with newedges pointing into the old graph Γ. The following lemma ensures that any existing rooted graphin Γ remains unchanged when the type graph is extended.Lemma 8 If a type graph Γ ′ is the result of an application of shlo, conj , inst or insg to a typegraph Γ, then Γ n = Γ ′ n <strong>for</strong> all nodes n ∈ Γ.Proof. By the definitions of shlo, conj , inst and insg.□Let f be one of the shlo, conj , inst and insg functions, Γ a type graph, and X the rest of thearguments of f. We can always extend Γ to Γ ′ without changing any rooted graphs in Γ, providedthat (Γ ′ , n ′ ) = f(Γ, X) is defined. To simplify the type-checking rules, we require all the rootedgraphs of type expressions to be already in Γ, and abbreviateas Γ ⊢ n ∼ f(X).let (Γ ′ , n ′ ) = f(Γ, X) in ∃n ∈ Γ • Γ ′ n ′ ∼ Γ n5.5 <strong>Type</strong> ContextsA type graph Γ itself is not enough to decide whether an expression or a command is well-typed.For example, a variable x is well-typed inside a local scope var T x; · · · ; end x, but it is likely toReport 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!