src/HOL/MicroJava/Comp/TypeInf.thy
changeset 60304 3f429b7d8eb5
parent 58860 fee7cfa69c50
child 61076 bdc1e2f0a86a
equal deleted inserted replaced
60303:00c06f1315d0 60304:3f429b7d8eb5
     2     Author:     Martin Strecker
     2     Author:     Martin Strecker
     3 *)
     3 *)
     4 
     4 
     5 (* Exact position in theory hierarchy still to be determined *)
     5 (* Exact position in theory hierarchy still to be determined *)
     6 theory TypeInf
     6 theory TypeInf
     7 imports "../J/WellType"
     7 imports "../J/WellType" "~~/src/HOL/Eisbach/Eisbach"
     8 begin
     8 begin
     9 
     9 
    10 
    10 
    11 
    11 
    12 (**********************************************************************)
    12 (**********************************************************************)
   100 
   100 
   101 
   101 
   102 declare split_paired_All [simp del]
   102 declare split_paired_All [simp del]
   103 declare split_paired_Ex [simp del]
   103 declare split_paired_Ex [simp del]
   104 
   104 
       
   105 method ty_case_simp = ((erule ty_exprs.cases ty_expr.cases; simp)+)[]
       
   106 method strip_case_simp = (intro strip, ty_case_simp)
       
   107 
   105 (* Uniqueness of types property *)
   108 (* Uniqueness of types property *)
   106 
   109 
   107 lemma uniqueness_of_types: "
   110 lemma uniqueness_of_types: "
   108   (\<forall> (E\<Colon>'a prog \<times> (vname \<Rightarrow> ty option)) T1 T2. 
   111   (\<forall> (E\<Colon>'a prog \<times> (vname \<Rightarrow> ty option)) T1 T2. 
   109   E\<turnstile>e :: T1 \<longrightarrow> E\<turnstile>e :: T2 \<longrightarrow> T1 = T2) \<and>
   112   E\<turnstile>e :: T1 \<longrightarrow> E\<turnstile>e :: T2 \<longrightarrow> T1 = T2) \<and>
   110   (\<forall> (E\<Colon>'a prog \<times> (vname \<Rightarrow> ty option)) Ts1 Ts2. 
   113   (\<forall> (E\<Colon>'a prog \<times> (vname \<Rightarrow> ty option)) Ts1 Ts2. 
   111   E\<turnstile>es [::] Ts1 \<longrightarrow> E\<turnstile>es [::] Ts2 \<longrightarrow> Ts1 = Ts2)"
   114   E\<turnstile>es [::] Ts1 \<longrightarrow> E\<turnstile>es [::] Ts2 \<longrightarrow> Ts1 = Ts2)"
   112 apply (rule compat_expr_expr_list.induct)
   115   apply (rule compat_expr_expr_list.induct)
       
   116             (* NewC *)
       
   117             apply strip_case_simp
   113 
   118 
   114 (* NewC *)
   119            (* Cast *)
   115 apply (intro strip)
   120            apply strip_case_simp
   116 apply (erule ty_expr.cases) apply simp+
       
   117 apply (erule ty_expr.cases) apply simp+
       
   118 
   121 
   119 (* Cast *)
   122           (* Lit *)
   120 apply (intro strip) 
   123           apply strip_case_simp
   121 apply (erule ty_expr.cases) apply simp+
       
   122 apply (erule ty_expr.cases) apply simp+
       
   123 
   124 
   124 (* Lit *)
   125          (* BinOp *)
   125 apply (intro strip) 
   126          apply (intro strip)
   126 apply (erule ty_expr.cases) apply simp+
   127          apply (rename_tac binop x2 x3 E T1 T2, case_tac binop)
   127 apply (erule ty_expr.cases) apply simp+
   128           (* Eq *)
       
   129           apply ty_case_simp
       
   130          (* Add *)
       
   131          apply ty_case_simp
   128 
   132 
   129 (* BinOp *)
   133         (* LAcc *)
   130 apply (intro strip)
   134         apply (strip_case_simp)
   131 apply (rename_tac binop x2 x3 E T1 T2, case_tac binop)
       
   132 (* Eq *)
       
   133 apply (erule ty_expr.cases) apply simp+
       
   134 apply (erule ty_expr.cases) apply simp+
       
   135 (* Add *)
       
   136 apply (erule ty_expr.cases) apply simp+
       
   137 apply (erule ty_expr.cases) apply simp+
       
   138 
   135 
   139 (* LAcc *)
   136        (* LAss *)
   140 apply (intro strip) 
   137        apply (strip_case_simp)
   141 apply (erule ty_expr.cases) apply simp+
       
   142 apply (erule ty_expr.cases) apply simp+
       
   143 
   138 
   144 (* LAss *)
   139       (* FAcc *)
   145 apply (intro strip) 
   140       apply (intro strip)
   146 apply (erule ty_expr.cases) apply simp+
   141       apply (drule FAcc_invers)+
   147 apply (erule ty_expr.cases) apply simp+
   142       apply fastforce
   148 
   143 
       
   144      (* FAss *)
       
   145      apply (intro strip)
       
   146      apply (drule FAss_invers)+
       
   147      apply (elim conjE exE)
       
   148      apply (drule FAcc_invers)+
       
   149      apply fastforce
   149 
   150 
   150 (* FAcc *)
   151     (* Call *)
   151 apply (intro strip)
   152     apply (intro strip)
   152 apply (drule FAcc_invers)+ apply (erule exE)+ 
   153     apply (drule Call_invers)+
   153   apply (subgoal_tac "C = Ca", simp) apply blast
   154     apply fastforce
   154 
   155 
       
   156    (* expression lists *)
       
   157    apply (strip_case_simp)
   155 
   158 
   156 (* FAss *)
   159   apply (strip_case_simp)
   157 apply (intro strip)
   160   done
   158 apply (drule FAss_invers)+ apply (erule exE)+ apply (erule conjE)+
       
   159 apply (drule FAcc_invers)+ apply (erule exE)+ apply blast 
       
   160 
       
   161 
       
   162 (* Call *)
       
   163 apply (intro strip)
       
   164 apply (drule Call_invers)+ apply (erule exE)+ apply (erule conjE)+
       
   165 apply (subgoal_tac "pTs = pTsa", simp) apply blast
       
   166 
       
   167 (* expression lists *)
       
   168 apply (intro strip)
       
   169 apply (erule ty_exprs.cases)+ apply simp+
       
   170 
       
   171 apply (intro strip)
       
   172 apply (erule ty_exprs.cases, simp)
       
   173 apply (erule ty_exprs.cases, simp)
       
   174 apply (subgoal_tac "e = ea", simp) apply simp
       
   175 done
       
   176 
   161 
   177 
   162 
   178 lemma uniqueness_of_types_expr [rule_format (no_asm)]: "
   163 lemma uniqueness_of_types_expr [rule_format (no_asm)]: "
   179   (\<forall> E T1 T2. E\<turnstile>e :: T1 \<longrightarrow> E\<turnstile>e :: T2 \<longrightarrow> T1 = T2)"
   164   (\<forall>E T1 T2. E\<turnstile>e :: T1 \<longrightarrow> E\<turnstile>e :: T2 \<longrightarrow> T1 = T2)"
   180 by (rule uniqueness_of_types [THEN conjunct1])
   165   by (rule uniqueness_of_types [THEN conjunct1])
   181 
   166 
   182 lemma uniqueness_of_types_exprs [rule_format (no_asm)]: "
   167 lemma uniqueness_of_types_exprs [rule_format (no_asm)]: "
   183   (\<forall> E Ts1 Ts2. E\<turnstile>es [::] Ts1 \<longrightarrow> E\<turnstile>es [::] Ts2 \<longrightarrow> Ts1 = Ts2)"
   168   (\<forall>E Ts1 Ts2. E\<turnstile>es [::] Ts1 \<longrightarrow> E\<turnstile>es [::] Ts2 \<longrightarrow> Ts1 = Ts2)"
   184 by (rule uniqueness_of_types [THEN conjunct2])
   169   by (rule uniqueness_of_types [THEN conjunct2])
   185 
   170 
   186 
       
   187   
       
   188 
   171 
   189 definition inferred_tp :: "[java_mb env, expr] \<Rightarrow> ty" where
   172 definition inferred_tp :: "[java_mb env, expr] \<Rightarrow> ty" where
   190   "inferred_tp E e == (SOME T. E\<turnstile>e :: T)"
   173   "inferred_tp E e == (SOME T. E\<turnstile>e :: T)"
   191 
   174 
   192 definition inferred_tps :: "[java_mb env, expr list] \<Rightarrow> ty list" where
   175 definition inferred_tps :: "[java_mb env, expr list] \<Rightarrow> ty list" where
   193   "inferred_tps E es == (SOME Ts. E\<turnstile>es [::] Ts)"
   176   "inferred_tps E es == (SOME Ts. E\<turnstile>es [::] Ts)"
   194 
   177 
   195 (* get inferred type(s) for well-typed term *)
   178 (* get inferred type(s) for well-typed term *)
   196 lemma inferred_tp_wt: "E\<turnstile>e :: T \<Longrightarrow> (inferred_tp E e) = T"
   179 lemma inferred_tp_wt: "E\<turnstile>e :: T \<Longrightarrow> (inferred_tp E e) = T"
   197 by (auto simp: inferred_tp_def intro: uniqueness_of_types_expr)
   180   by (auto simp: inferred_tp_def intro: uniqueness_of_types_expr)
   198 
   181 
   199 lemma inferred_tps_wt: "E\<turnstile>es [::] Ts \<Longrightarrow> (inferred_tps E es) = Ts"
   182 lemma inferred_tps_wt: "E\<turnstile>es [::] Ts \<Longrightarrow> (inferred_tps E es) = Ts"
   200 by (auto simp: inferred_tps_def intro: uniqueness_of_types_exprs)
   183   by (auto simp: inferred_tps_def intro: uniqueness_of_types_exprs)
   201 
       
   202 
   184 
   203 end
   185 end
   204