equal
deleted
inserted
replaced
3 theory Sec_Typing imports Sec_Type_Expr |
3 theory Sec_Typing imports Sec_Type_Expr |
4 begin |
4 begin |
5 |
5 |
6 subsection "Syntax Directed Typing" |
6 subsection "Syntax Directed Typing" |
7 |
7 |
|
8 text_raw{*\snip{sectypeDef}{0}{2}{% *} |
8 inductive sec_type :: "nat \<Rightarrow> com \<Rightarrow> bool" ("(_/ \<turnstile> _)" [0,0] 50) where |
9 inductive sec_type :: "nat \<Rightarrow> com \<Rightarrow> bool" ("(_/ \<turnstile> _)" [0,0] 50) where |
9 Skip: |
10 Skip: |
10 "l \<turnstile> SKIP" | |
11 "l \<turnstile> SKIP" | |
11 Assign: |
12 Assign: |
12 "\<lbrakk> sec x \<ge> sec a; sec x \<ge> l \<rbrakk> \<Longrightarrow> l \<turnstile> x ::= a" | |
13 "\<lbrakk> sec x \<ge> sec a; sec x \<ge> l \<rbrakk> \<Longrightarrow> l \<turnstile> x ::= a" | |
14 "\<lbrakk> l \<turnstile> c\<^isub>1; l \<turnstile> c\<^isub>2 \<rbrakk> \<Longrightarrow> l \<turnstile> c\<^isub>1;c\<^isub>2" | |
15 "\<lbrakk> l \<turnstile> c\<^isub>1; l \<turnstile> c\<^isub>2 \<rbrakk> \<Longrightarrow> l \<turnstile> c\<^isub>1;c\<^isub>2" | |
15 If: |
16 If: |
16 "\<lbrakk> max (sec b) l \<turnstile> c\<^isub>1; max (sec b) l \<turnstile> c\<^isub>2 \<rbrakk> \<Longrightarrow> l \<turnstile> IF b THEN c\<^isub>1 ELSE c\<^isub>2" | |
17 "\<lbrakk> max (sec b) l \<turnstile> c\<^isub>1; max (sec b) l \<turnstile> c\<^isub>2 \<rbrakk> \<Longrightarrow> l \<turnstile> IF b THEN c\<^isub>1 ELSE c\<^isub>2" | |
17 While: |
18 While: |
18 "max (sec b) l \<turnstile> c \<Longrightarrow> l \<turnstile> WHILE b DO c" |
19 "max (sec b) l \<turnstile> c \<Longrightarrow> l \<turnstile> WHILE b DO c" |
|
20 text_raw{*}%endsnip*} |
19 |
21 |
20 code_pred (expected_modes: i => i => bool) sec_type . |
22 code_pred (expected_modes: i => i => bool) sec_type . |
21 |
23 |
22 value "0 \<turnstile> IF Less (V ''x1'') (V ''x'') THEN ''x1'' ::= N 0 ELSE SKIP" |
24 value "0 \<turnstile> IF Less (V ''x1'') (V ''x'') THEN ''x1'' ::= N 0 ELSE SKIP" |
23 value "1 \<turnstile> IF Less (V ''x1'') (V ''x'') THEN ''x'' ::= N 0 ELSE SKIP" |
25 value "1 \<turnstile> IF Less (V ''x1'') (V ''x'') THEN ''x'' ::= N 0 ELSE SKIP" |
179 text{* The predicate @{prop"l \<turnstile> c"} is nicely intuitive and executable. The |
181 text{* The predicate @{prop"l \<turnstile> c"} is nicely intuitive and executable. The |
180 standard formulation, however, is slightly different, replacing the maximum |
182 standard formulation, however, is slightly different, replacing the maximum |
181 computation by an antimonotonicity rule. We introduce the standard system now |
183 computation by an antimonotonicity rule. We introduce the standard system now |
182 and show the equivalence with our formulation. *} |
184 and show the equivalence with our formulation. *} |
183 |
185 |
|
186 text_raw{*\snip{sectypepDef}{0}{2}{% *} |
184 inductive sec_type' :: "nat \<Rightarrow> com \<Rightarrow> bool" ("(_/ \<turnstile>'' _)" [0,0] 50) where |
187 inductive sec_type' :: "nat \<Rightarrow> com \<Rightarrow> bool" ("(_/ \<turnstile>'' _)" [0,0] 50) where |
185 Skip': |
188 Skip': |
186 "l \<turnstile>' SKIP" | |
189 "l \<turnstile>' SKIP" | |
187 Assign': |
190 Assign': |
188 "\<lbrakk> sec x \<ge> sec a; sec x \<ge> l \<rbrakk> \<Longrightarrow> l \<turnstile>' x ::= a" | |
191 "\<lbrakk> sec x \<ge> sec a; sec x \<ge> l \<rbrakk> \<Longrightarrow> l \<turnstile>' x ::= a" | |
192 "\<lbrakk> sec b \<le> l; l \<turnstile>' c\<^isub>1; l \<turnstile>' c\<^isub>2 \<rbrakk> \<Longrightarrow> l \<turnstile>' IF b THEN c\<^isub>1 ELSE c\<^isub>2" | |
195 "\<lbrakk> sec b \<le> l; l \<turnstile>' c\<^isub>1; l \<turnstile>' c\<^isub>2 \<rbrakk> \<Longrightarrow> l \<turnstile>' IF b THEN c\<^isub>1 ELSE c\<^isub>2" | |
193 While': |
196 While': |
194 "\<lbrakk> sec b \<le> l; l \<turnstile>' c \<rbrakk> \<Longrightarrow> l \<turnstile>' WHILE b DO c" | |
197 "\<lbrakk> sec b \<le> l; l \<turnstile>' c \<rbrakk> \<Longrightarrow> l \<turnstile>' WHILE b DO c" | |
195 anti_mono': |
198 anti_mono': |
196 "\<lbrakk> l \<turnstile>' c; l' \<le> l \<rbrakk> \<Longrightarrow> l' \<turnstile>' c" |
199 "\<lbrakk> l \<turnstile>' c; l' \<le> l \<rbrakk> \<Longrightarrow> l' \<turnstile>' c" |
|
200 text_raw{*}%endsnip*} |
197 |
201 |
198 lemma sec_type_sec_type': "l \<turnstile> c \<Longrightarrow> l \<turnstile>' c" |
202 lemma sec_type_sec_type': "l \<turnstile> c \<Longrightarrow> l \<turnstile>' c" |
199 apply(induction rule: sec_type.induct) |
203 apply(induction rule: sec_type.induct) |
200 apply (metis Skip') |
204 apply (metis Skip') |
201 apply (metis Assign') |
205 apply (metis Assign') |
213 apply (metis min_max.sup_absorb2 While) |
217 apply (metis min_max.sup_absorb2 While) |
214 by (metis anti_mono) |
218 by (metis anti_mono) |
215 |
219 |
216 subsection "A Bottom-Up Typing System" |
220 subsection "A Bottom-Up Typing System" |
217 |
221 |
|
222 text_raw{*\snip{sectypebDef}{0}{2}{% *} |
218 inductive sec_type2 :: "com \<Rightarrow> level \<Rightarrow> bool" ("(\<turnstile> _ : _)" [0,0] 50) where |
223 inductive sec_type2 :: "com \<Rightarrow> level \<Rightarrow> bool" ("(\<turnstile> _ : _)" [0,0] 50) where |
219 Skip2: |
224 Skip2: |
220 "\<turnstile> SKIP : l" | |
225 "\<turnstile> SKIP : l" | |
221 Assign2: |
226 Assign2: |
222 "sec x \<ge> sec a \<Longrightarrow> \<turnstile> x ::= a : sec x" | |
227 "sec x \<ge> sec a \<Longrightarrow> \<turnstile> x ::= a : sec x" | |
225 If2: |
230 If2: |
226 "\<lbrakk> sec b \<le> min l\<^isub>1 l\<^isub>2; \<turnstile> c\<^isub>1 : l\<^isub>1; \<turnstile> c\<^isub>2 : l\<^isub>2 \<rbrakk> |
231 "\<lbrakk> sec b \<le> min l\<^isub>1 l\<^isub>2; \<turnstile> c\<^isub>1 : l\<^isub>1; \<turnstile> c\<^isub>2 : l\<^isub>2 \<rbrakk> |
227 \<Longrightarrow> \<turnstile> IF b THEN c\<^isub>1 ELSE c\<^isub>2 : min l\<^isub>1 l\<^isub>2" | |
232 \<Longrightarrow> \<turnstile> IF b THEN c\<^isub>1 ELSE c\<^isub>2 : min l\<^isub>1 l\<^isub>2" | |
228 While2: |
233 While2: |
229 "\<lbrakk> sec b \<le> l; \<turnstile> c : l \<rbrakk> \<Longrightarrow> \<turnstile> WHILE b DO c : l" |
234 "\<lbrakk> sec b \<le> l; \<turnstile> c : l \<rbrakk> \<Longrightarrow> \<turnstile> WHILE b DO c : l" |
|
235 text_raw{*}%endsnip*} |
230 |
236 |
231 |
237 |
232 lemma sec_type2_sec_type': "\<turnstile> c : l \<Longrightarrow> l \<turnstile>' c" |
238 lemma sec_type2_sec_type': "\<turnstile> c : l \<Longrightarrow> l \<turnstile>' c" |
233 apply(induction rule: sec_type2.induct) |
239 apply(induction rule: sec_type2.induct) |
234 apply (metis Skip') |
240 apply (metis Skip') |