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 47The transition rules <strong>for</strong> assignment, object creation, variable declaration and undeclaration aredefined by the simple graph operations of edge swing, new instance adding, stack push and pop.By contrast, the rule <strong>for</strong> method invocation is more dedicate and deserves some explanation.In a method invocation, a result argument re is an l-expression. We have to remember the l-valueof re initially be<strong>for</strong>e it is possibly changed during the invocation. If re = e.a is a navigationpath, we call the object referred to by e the parent object of the attribute a. Our approach isto assign this parent object po(G, re) to an auxiliary variable x ∗ when entering a method. Andwhen exiting the method, we recover the initial l-value of re by spo(G, re, q) that returns theoutgoing edge labeled by a of the parent object q retrieved from x ∗ . For a variable w, the notionof parent object is not significant since its l-value cannot be changed. For unification, however,we define the parent object of w as the null object.7.5 <strong>Type</strong>-Safety of <strong>Programs</strong>The type-safety of a program ensures that a well-typed expression can be evaluated and a welltypedcommand can be executed. We reason about the type-safety by showing that given awell-typed state graph, there exists a semantic rule which applies, and that the resulted stategraph of the semantic rule is also well-typed.There are exceptional cases when an expression cannot be evaluated, or a command cannot beexecuted.1. Null reference: the evaluation of an expression e.a or the execution of a command e.m(. . .)fails, if e is evaluated to null.2. Illegal downcast: the evaluation of an expression (⌈t⌋)e fails, if e is evaluated to a node nand the type of n is not a subtype of t.These two cases can not be checked statically.Lemma 12 Let Γ be a type graph, ∆ a type context, e an expression, and G a well-typed stategraph w.r.t. (Γ, ∆). If Γ, ∆ ⊢ e : t, we have1. n = eval(G, e) exists and Γ ⊢ Γ(G, n) t, and2. if e is an l-expression, l-eval(G, e) exists,unless one of the exceptional cases happens.Proof. The proof is given by induction on the structure of the expression e. Suppose none of theexceptional cases happens.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!