[7cfccc]: thys / FeatherweightJava / FJDefs.thy  Maximize  Restore  History

Download this file

517 lines (419 with data), 20.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
(* Title: A theory of Featherweight Java in Isabelle/HOL
Author: Nate Foster <jnfoster at cis.upenn.edu>,
Dimitrios Vytiniotis <dimitriv at cis.upenn.edu>, 2006
Maintainer: Nate Foster <jnfoster at cis.upenn.edu>,
Dimitrios Vytiniotis <dimitriv at cis.upenn.edu>
License: LGPL
*)
header {* {\tt FJDefs}: Basic Definitions *}
theory FJDefs
imports Main
begin
subsection {* Syntax *}
text {* We use a named representation for terms: variables, method
names, and class names, are all represented as {\tt nat}s. We use the
finite maps defined in {\tt Map.thy} to represent typing contexts and
the static class table. This section defines the representations of
each syntactic category (expressions, methods, constructors, classes,
class tables) and defines several constants ({\tt Object} and {\tt this}).
*}
subsubsection{* Type definitions *}
types varName = "nat"
types methodName = "nat"
types className = "nat"
record varDef =
vdName :: "varName"
vdType :: "className"
types varCtx = "varName \<rightharpoonup> className"
subsubsection{* Constants *}
definition
Object :: "className" where
"Object = 0"
definition
this :: "varName" where
"this == 0"
subsubsection {* Expressions *}
datatype exp =
Var "varName"
| FieldProj "exp" "varName"
| MethodInvk "exp" "methodName" "exp list"
| New "className" "exp list"
| Cast "className" "exp"
subsubsection {* Methods *}
record methodDef =
mReturn :: "className"
mName :: "methodName"
mParams :: "varDef list"
mBody :: "exp"
subsubsection {* Constructors *}
record constructorDef =
kName :: "className"
kParams :: "varDef list"
kSuper :: "varName list"
kInits :: "varName list"
subsubsection {* Classes *}
record classDef =
cName :: "className"
cSuper :: "className"
cFields :: "varDef list"
cConstructor :: "constructorDef"
cMethods :: "methodDef list"
subsubsection {* Class Tables *}
types classTable = "className \<rightharpoonup> classDef"
subsection {* Sub-expression Relation *}
text {* The sub-expression relation, written $t \in
\mathit{subexprs}(s)$, is defined as the reflexive and transitive
closure of the immediate subexpression relation.
*}
inductive_set
isubexprs :: "(exp * exp) set"
and isubexprs' :: "[exp,exp] \<Rightarrow> bool" ("_ \<in> isubexprs'(_')" [80,80] 80)
where
"e' \<in> isubexprs(e) \<equiv> (e',e) \<in> isubexprs"
| se_field : "e \<in> isubexprs(FieldProj e fi)"
| se_invkrecv : "e \<in> isubexprs(MethodInvk e m es)"
| se_invkarg : "\<lbrakk> ei \<in> set es \<rbrakk> \<Longrightarrow> ei \<in> isubexprs(MethodInvk e m es)"
| se_newarg : "\<lbrakk> ei \<in> set es \<rbrakk> \<Longrightarrow> ei \<in> isubexprs(New C es)"
| se_cast : "e \<in> isubexprs(Cast C e)"
abbreviation
subexprs :: "[exp,exp] \<Rightarrow> bool" ("_ \<in> subexprs'(_')" [80,80] 80) where
"e' \<in> subexprs(e) \<equiv> (e',e) \<in> isubexprs^*"
subsection {* Values *}
text{* A {\em value} is an expression of the form $\mathtt{new}\
\mathtt{C}(\mathit{overline{vs}})$, where $\mathit{\overline{vs}}$ is a list
of values. *}
inductive
vals :: "[exp list] \<Rightarrow> bool" ("vals'(_')" [80] 80)
and val :: "[exp] \<Rightarrow> bool" ("val'(_')" [80] 80)
where
vals_nil : "vals([])"
| vals_cons : "\<lbrakk> val(vh); vals(vt) \<rbrakk> \<Longrightarrow> vals((vh # vt))"
| val : "\<lbrakk> vals(vs) \<rbrakk> \<Longrightarrow> val(New C vs)"
subsection {* Substitution *}
text {* The substitutions of a list of expressions $\mathit{ds}$ for a
list of variables $\mathit{xs}$ in another expression $e$ or a list of
expressions $\mathit{es}$ are defined in the obvious way, and written
$(\mathit{ds}/\mathit{xs})e$ and $[\mathit{ds}/\mathit{xs}]es$
respecitvely.
*}
consts
substs :: "(varName \<rightharpoonup> exp) \<Rightarrow> exp \<Rightarrow> exp"
subst_list1 :: "(varName \<rightharpoonup> exp) \<Rightarrow> exp list \<Rightarrow> exp list"
subst_list2 :: "(varName \<rightharpoonup> exp) \<Rightarrow> exp list \<Rightarrow> exp list"
primrec
"substs \<sigma> (Var x) = (case (\<sigma>(x)) of None \<Rightarrow> (Var x) | Some p \<Rightarrow> p)"
"substs \<sigma> (FieldProj e f) = FieldProj (substs \<sigma> e) f"
"substs \<sigma> (MethodInvk e m es) = MethodInvk (substs \<sigma> e) m (subst_list1 \<sigma> es)"
"substs \<sigma> (New C es) = New C (subst_list2 \<sigma> es)"
"substs \<sigma> (Cast C e) = Cast C (substs \<sigma> e)"
"subst_list1 \<sigma> [] = []"
"subst_list1 \<sigma> (h # t) = (substs \<sigma> h) # (subst_list1 \<sigma> t)"
"subst_list2 \<sigma> [] = []"
"subst_list2 \<sigma> (h # t) = (substs \<sigma> h) # (subst_list2 \<sigma> t)"
abbreviation
substs_syn :: "[exp list] \<Rightarrow> [varName list] \<Rightarrow> [exp] \<Rightarrow> exp"
("'(_'/_')_" [80,80,80] 80) where
"(ds/xs)e \<equiv> substs (map_upds empty xs ds) e"
abbreviation
subst_list_syn :: "[exp list] \<Rightarrow> [varName list] \<Rightarrow> [exp list] \<Rightarrow> exp list"
("'[_'/_']_" [80,80,80] 80) where
"[ds/xs]es \<equiv> map (substs (map_upds empty xs ds)) es"
subsection {* Lookup *}
text {* The fuction $\mathit{lookup}\ f\ l$ function returns an option
containing the first element of $l$ satisfying $f$, or $\mathtt{None}$
if no such element exists
*}
primrec lookup :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'a option"
where
"lookup [] P = None"
| "lookup (h#t) P = (if P h then Some h else lookup t P)"
primrec lookup2 :: "'a list \<Rightarrow> 'b list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> 'b option"
where
"lookup2 [] l2 P = None"
| "lookup2 (h1#t1) l2 P = (if P h1 then Some(hd l2) else lookup2 t1 (tl l2) P)"
subsection {* Variable Definition Accessors *}
text{* This section contains several helper functions for reading off
the names and types of variable definitions (e.g., in field
and method parameter declarations). *}
definition
varDefs_names :: "varDef list \<Rightarrow> varName list" where
"varDefs_names = map vdName"
definition
varDefs_types :: "varDef list \<Rightarrow> className list" where
"varDefs_types = map vdType"
subsection {* Subtyping Relation *}
text {* The subtyping relation, written $\mathit{CT} \vdash C
\mathtt{\lt:} D$ is just the reflexive and transitive closure of the
immediate subclass relation. (For the sake of simplicity, we define
subtyping directly instead of using the reflexive and transitive
closure operator.) The subtyping relation is extended to lists of
classes, written $\mathit{CT} \vdash\mathtt{+} \mathit{Cs} \mathtt{\lt:}
\mathit{Ds}$. *}
inductive
subtyping :: "[classTable, className, className] \<Rightarrow> bool" ("_ \<turnstile> _ <: _" [80,80,80] 80)
where
s_refl : "CT \<turnstile> C <: C"
| s_trans : "\<lbrakk> CT \<turnstile> C <: D; CT \<turnstile> D <: E \<rbrakk> \<Longrightarrow> CT \<turnstile> C <: E"
| s_super : "\<lbrakk> CT(C) = Some(CDef); cSuper CDef = D \<rbrakk> \<Longrightarrow> CT \<turnstile> C <: D"
abbreviation
neg_subtyping :: "[classTable, className, className] \<Rightarrow> bool" ("_ \<turnstile> _ \<not><: _" [80,80,80] 80)
where "CT \<turnstile> S \<not><: T \<equiv> \<not> CT \<turnstile> S <: T"
inductive
subtypings :: "[classTable, className list, className list] \<Rightarrow> bool" ("_ \<turnstile>+ _ <: _" [80,80,80] 80)
where
ss_nil : "CT \<turnstile>+ [] <: []"
| ss_cons : "\<lbrakk> CT \<turnstile> C0 <: D0; CT \<turnstile>+ Cs <: Ds \<rbrakk> \<Longrightarrow> CT \<turnstile>+ (C0 # Cs) <: (D0 # Ds)"
subsection {* {\tt fields} Relation *}
text{* The {\tt fields} relation, written
$\mathtt{fields}(\mathit{CT},C) = \mathit{Cf}$, relates $\mathit{Cf}$
to $C$ when $\mathit{Cf}$ is the list of fields declared directly or
indirectly (i.e., by a superclass) in $C$.*}
inductive
fields :: "[classTable, className, varDef list] \<Rightarrow> bool" ("fields'(_,_') = _" [80,80,80] 80)
where
f_obj:
"fields(CT,Object) = []"
| f_class:
"\<lbrakk> CT(C) = Some(CDef); cSuper CDef = D; cFields CDef = Cf; fields(CT,D) = Dg; DgCf = Dg @ Cf \<rbrakk>
\<Longrightarrow> fields(CT,C) = DgCf"
subsection {* {\tt mtype } Relation *}
text{* The {\tt mtype} relation, written
$\mathtt{mtype}(\mathit{CT},m,C) = \mathit{Cs} \rightarrow C_0$ relates
a class $C$, method name $m$, and the arrow type $\mathit{Cs}
\rightarrow C_0$. It either returns the type of the declaration of $m$
in $C$, if any such declaration exists, and otherwise returning the
type of $m$ from $C$'s superclass.
*}
inductive
mtype :: "[classTable, methodName, className, className list, className] \<Rightarrow> bool" ("mtype'(_,_,_') = _ \<rightarrow> _" [80,80,80,80] 80)
where
mt_class:
"\<lbrakk> CT(C) = Some(CDef);
lookup (cMethods CDef) (\<lambda>md.(mName md = m)) = Some(mDef);
varDefs_types (mParams mDef) = Bs;
mReturn mDef = B \<rbrakk>
\<Longrightarrow> mtype(CT,m,C) = Bs \<rightarrow> B"
| mt_super:
"\<lbrakk> CT(C) = Some (CDef);
lookup (cMethods CDef) (\<lambda>md.(mName md = m)) = None;
cSuper CDef = D;
mtype(CT,m,D) = Bs \<rightarrow> B \<rbrakk>
\<Longrightarrow> mtype(CT,m,C) = Bs \<rightarrow> B"
subsection {* {\tt mbody} Relation *}
text{* The {\tt mtype} relation, written
$\mathtt{mbody}(\mathit{CT},m,C) = \mathit{xs} . e_0$ relates a class
$C$, method name $m$, and the names of the parameters $\mathit{xs}$
and the body of the method $e_0$. It either returns the parameter
names and body of the declaration of $m$ in $C$, if any such
declaration exists, and otherwise the parameter names and body of $m$
from $C$'s superclass.
*}
inductive
mbody :: "[classTable, methodName, className, varName list, exp] \<Rightarrow> bool" ("mbody'(_,_,_') = _ . _" [80,80,80,80] 80)
where
mb_class:
"\<lbrakk> CT(C) = Some(CDef);
lookup (cMethods CDef) (\<lambda>md.(mName md = m)) = Some(mDef);
varDefs_names (mParams mDef) = xs;
mBody mDef = e \<rbrakk>
\<Longrightarrow> mbody(CT,m,C) = xs . e"
| mb_super:
"\<lbrakk> CT(C) = Some(CDef);
lookup (cMethods CDef) (\<lambda>md.(mName md = m)) = None;
cSuper CDef = D;
mbody(CT,m,D) = xs . e \<rbrakk>
\<Longrightarrow> mbody(CT,m,C) = xs . e"
subsection {* Typing Relation *}
text {*
The typing relation, written $\mathit{CT};\Gamma \vdash e : C$
relates an expression $e$ to its type $C$, under the typing context
$\Gamma$. The multi-typing relation, written $\mathit{CT};\Gamma
\vdash\mathtt{+} \mathit{es}:\mathit{Cs}$ relates lists of expressions
to lists of types.
*}
inductive
typings :: "[classTable, varCtx, exp list, className list] \<Rightarrow> bool" ("_;_ \<turnstile>+ _ : _" [80,80,80,80] 80)
and typing :: "[classTable, varCtx, exp, className] \<Rightarrow> bool" ("_;_ \<turnstile> _ : _" [80,80,80,80] 80)
where
ts_nil : "CT;\<Gamma> \<turnstile>+ [] : []"
| ts_cons :
"\<lbrakk> CT;\<Gamma> \<turnstile> e0 : C0; CT;\<Gamma> \<turnstile>+ es : Cs \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile>+ (e0 # es) : (C0 # Cs)"
| t_var :
"\<lbrakk> \<Gamma>(x) = Some C \<rbrakk> \<Longrightarrow> CT;\<Gamma> \<turnstile> (Var x) : C"
| t_field :
"\<lbrakk> CT;\<Gamma> \<turnstile> e0 : C0;
fields(CT,C0) = Cf;
lookup Cf (\<lambda>fd.(vdName fd = fi)) = Some(fDef);
vdType fDef = Ci \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile> FieldProj e0 fi : Ci"
| t_invk :
"\<lbrakk> CT;\<Gamma> \<turnstile> e0 : C0;
mtype(CT,m,C0) = Ds \<rightarrow> C;
CT;\<Gamma> \<turnstile>+ es : Cs;
CT \<turnstile>+ Cs <: Ds;
length es = length Ds \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile> MethodInvk e0 m es : C"
| t_new :
"\<lbrakk> fields(CT,C) = Df;
length es = length Df;
varDefs_types Df = Ds;
CT;\<Gamma> \<turnstile>+ es : Cs;
CT \<turnstile>+ Cs <: Ds \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile> New C es : C"
| t_ucast :
"\<lbrakk> CT;\<Gamma> \<turnstile> e0 : D;
CT \<turnstile> D <: C \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile> Cast C e0 : C"
| t_dcast :
"\<lbrakk> CT;\<Gamma> \<turnstile> e0 : D;
CT \<turnstile> C <: D; C \<noteq> D \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile> Cast C e0 : C"
| t_scast :
"\<lbrakk> CT;\<Gamma> \<turnstile> e0 : D;
CT \<turnstile> C \<not><: D;
CT \<turnstile> D \<not><: C \<rbrakk>
\<Longrightarrow> CT;\<Gamma> \<turnstile> Cast C e0 : C"
text {* We occasionally find the following induction principle, which
only mentions the typing of a single expression, more useful than the
mutual induction principle generated by Isabelle, which mentions the
typings of single expressions and of lists of expressions.
*}
lemma typing_induct:
assumes "CT;\<Gamma> \<turnstile> e : C" (is ?T)
and "\<And>C CT \<Gamma> x. \<Gamma> x = Some C \<Longrightarrow> P CT \<Gamma> (Var x) C"
and "\<And>C0 CT Cf Ci \<Gamma> e0 fDef fi. \<lbrakk>CT;\<Gamma> \<turnstile> e0 : C0; P CT \<Gamma> e0 C0; fields(CT,C0) = Cf; lookup Cf (\<lambda>fd. vdName fd = fi) = Some fDef; vdType fDef = Ci\<rbrakk> \<Longrightarrow> P CT \<Gamma> (FieldProj e0 fi) Ci"
and "\<And>C C0 CT Cs Ds \<Gamma> e0 es m. \<lbrakk>CT;\<Gamma> \<turnstile> e0 : C0; P CT \<Gamma> e0 C0; mtype(CT,m,C0) = Ds \<rightarrow> C; CT;\<Gamma> \<turnstile>+ es : Cs; \<And>i . \<lbrakk> i < length es \<rbrakk> \<Longrightarrow> P CT \<Gamma> (es!i) (Cs!i); CT \<turnstile>+ Cs <: Ds; length es = length Ds\<rbrakk> \<Longrightarrow> P CT \<Gamma> (MethodInvk e0 m es) C"
and "\<And>C CT Cs Df Ds \<Gamma> es. \<lbrakk>fields(CT,C) = Df; length es = length Df; varDefs_types Df = Ds; CT;\<Gamma> \<turnstile>+ es : Cs; \<And>i. \<lbrakk> i < length es \<rbrakk> \<Longrightarrow> P CT \<Gamma> (es!i) (Cs!i); CT \<turnstile>+ Cs <: Ds\<rbrakk> \<Longrightarrow> P CT \<Gamma> (New C es) C"
and "\<And>C CT D \<Gamma> e0. \<lbrakk>CT;\<Gamma> \<turnstile> e0 : D; P CT \<Gamma> e0 D; CT \<turnstile> D <: C\<rbrakk> \<Longrightarrow> P CT \<Gamma> (Cast C e0) C"
and "\<And>C CT D \<Gamma> e0. \<lbrakk>CT;\<Gamma> \<turnstile> e0 : D; P CT \<Gamma> e0 D; CT \<turnstile> C <: D; C \<noteq> D\<rbrakk> \<Longrightarrow> P CT \<Gamma> (Cast C e0) C"
and "\<And>C CT D \<Gamma> e0. \<lbrakk>CT;\<Gamma> \<turnstile> e0 : D; P CT \<Gamma> e0 D; CT \<turnstile> C \<not><: D; CT \<turnstile> D \<not><: C\<rbrakk> \<Longrightarrow> P CT \<Gamma> (Cast C e0) C"
shows "P CT \<Gamma> e C" (is ?P)
proof -
fix es Cs
let ?IH="CT;\<Gamma> \<turnstile>+ es : Cs \<longrightarrow> (\<forall>i < length es. P CT \<Gamma> (es!i) (Cs!i))"
have "?IH \<and> (?T \<longrightarrow> ?P)"
proof(induct rule:typings_typing.induct)
case (ts_nil CT \<Gamma>) show ?case by auto
next
case (ts_cons CT \<Gamma> e0 C0 es Cs)
show ?case proof
fix i
show "i < length (e0#es) \<longrightarrow> P CT \<Gamma> ((e0#es)!i) ((C0#Cs)!i)" using ts_cons by(cases i, auto)
qed
next
case t_var then show ?case using assms by auto
next
case t_field then show ?case using assms by auto
next
case t_invk then show ?case using assms by auto
next
case t_new then show ?case using assms by auto
next
case t_ucast then show ?case using assms by auto
next
case t_dcast then show ?case using assms by auto
next
case t_scast then show ?case using assms by auto
qed
thus ?thesis using assms by auto
qed
subsection {* Method Typing Relation *}
text {* A method definition $\mathit{md}$, declared in a class $C$, is
well-typed, written $\mathit{CT} \vdash \mathit{md} \texttt{OK IN}\ C$
if its body is well-typed and it has the same type (i.e., overrides)
any method with the same name declared in the superclass of $C$. *}
inductive
method_typing :: "[classTable, methodDef, className] \<Rightarrow> bool" ("_ \<turnstile> _ OK IN _" [80,80,80] 80)
where
m_typing:
"\<lbrakk> CT(C) = Some(CDef);
cName CDef = C;
cSuper CDef = D;
mName mDef = m;
lookup (cMethods CDef) (\<lambda>md.(mName md = m)) = Some(mDef);
mReturn mDef = C0; mParams mDef = Cxs; mBody mDef = e0;
varDefs_types Cxs = Cs;
varDefs_names Cxs = xs;
\<Gamma> = (map_upds empty xs Cs)(this \<mapsto> C);
CT;\<Gamma> \<turnstile> e0 : E0;
CT \<turnstile> E0 <: C0;
\<forall>Ds D0. (mtype(CT,m,D) = Ds \<rightarrow> D0) \<longrightarrow> (Cs=Ds \<and> C0=D0) \<rbrakk>
\<Longrightarrow> CT \<turnstile> mDef OK IN C"
inductive
method_typings :: "[classTable, methodDef list, className] \<Rightarrow> bool" ("_ \<turnstile>+ _ OK IN _" [80,80,80] 80)
where
ms_nil :
"CT \<turnstile>+ [] OK IN C"
| ms_cons :
"\<lbrakk> CT \<turnstile> m OK IN C;
CT \<turnstile>+ ms OK IN C \<rbrakk>
\<Longrightarrow> CT \<turnstile>+ (m # ms) OK IN C"
subsection {* Class Typing Relation *}
text {* A class definition $\mathit{cd}$ is well-typed, written
$\mathit{CT}\vdash \mathit{cd} \texttt{OK}$ if its constructor
initializes each field, and all of its methods are well-typed. *}
inductive
class_typing :: "[classTable, classDef] \<Rightarrow> bool" ("_ \<turnstile> _ OK" [80,80] 80)
where
t_class: "\<lbrakk> cName CDef = C;
cSuper CDef = D;
cConstructor CDef = KDef;
cMethods CDef = M;
kName KDef = C;
kParams KDef = (Dg@Cf);
kSuper KDef = varDefs_names Dg;
kInits KDef = varDefs_names Cf;
fields(CT,D) = Dg;
CT \<turnstile>+ M OK IN C \<rbrakk>
\<Longrightarrow> CT \<turnstile> CDef OK"
subsection {* Class Table Typing Relation *}
text {* A class table is well-typed, written $\mathit{CT}\
\texttt{OK}$ if for every class name $C$, the class definition mapped
to by $\mathit{CT}$ is is well-typed and has name $C$. *}
inductive
ct_typing :: "classTable \<Rightarrow> bool" ("_ OK" 80)
where
ct_all_ok:
"\<lbrakk> Object \<notin> dom(CT);
\<forall>C CDef. CT(C) = Some(CDef) \<longrightarrow> (CT \<turnstile> CDef OK) \<and> (cName CDef = C) \<rbrakk>
\<Longrightarrow> CT OK"
subsection {* Evaluation Relation *}
text {* The single-step and multi-step evaluation relations are
written $\mathit{CT} \vdash e \rightarrow e'$ and $\mathit{CT} \vdash
e \rightarrow^* e'$ respectively. *}
inductive
reduction :: "[classTable, exp, exp] \<Rightarrow> bool" ("_ \<turnstile> _ \<rightarrow> _" [80,80,80] 80)
where
r_field:
"\<lbrakk> fields(CT,C) = Cf;
lookup2 Cf es (\<lambda>fd.(vdName fd = fi)) = Some(ei) \<rbrakk>
\<Longrightarrow> CT \<turnstile> FieldProj (New C es) fi \<rightarrow> ei"
| r_invk:
"\<lbrakk> mbody(CT,m,C) = xs . e0;
substs ((map_upds empty xs ds)(this \<mapsto> (New C es))) e0 = e0' \<rbrakk>
\<Longrightarrow> CT \<turnstile> MethodInvk (New C es) m ds \<rightarrow> e0'"
| r_cast:
"\<lbrakk> CT \<turnstile> C <: D \<rbrakk>
\<Longrightarrow> CT \<turnstile> Cast D (New C es) \<rightarrow> New C es"
| rc_field:
"\<lbrakk> CT \<turnstile> e0 \<rightarrow> e0' \<rbrakk>
\<Longrightarrow> CT \<turnstile> FieldProj e0 f \<rightarrow> FieldProj e0' f"
| rc_invk_recv:
"\<lbrakk> CT \<turnstile> e0 \<rightarrow> e0' \<rbrakk>
\<Longrightarrow> CT \<turnstile> MethodInvk e0 m es \<rightarrow> MethodInvk e0' m es"
| rc_invk_arg:
"\<lbrakk> CT \<turnstile> ei \<rightarrow> ei' \<rbrakk>
\<Longrightarrow> CT \<turnstile> MethodInvk e0 m (el@ei#er) \<rightarrow> MethodInvk e0 m (el@ei'#er)"
| rc_new_arg:
"\<lbrakk> CT \<turnstile> ei \<rightarrow> ei' \<rbrakk>
\<Longrightarrow> CT \<turnstile> New C (el@ei#er) \<rightarrow> New C (el@ei'#er)"
| rc_cast:
"\<lbrakk> CT \<turnstile> e0 \<rightarrow> e0' \<rbrakk>
\<Longrightarrow> CT \<turnstile> Cast C e0 \<rightarrow> Cast C e0'"
inductive
reductions :: "[classTable, exp, exp] \<Rightarrow> bool" ("_ \<turnstile> _ \<rightarrow>* _" [80,80,80] 80)
where
rs_refl: "CT \<turnstile> e \<rightarrow>* e"
| rs_trans: "\<lbrakk> CT \<turnstile> e \<rightarrow> e'; CT \<turnstile> e' \<rightarrow>* e'' \<rbrakk> \<Longrightarrow> CT \<turnstile> e \<rightarrow>* e''"
end

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks