src/HOL/MicroJava/Comp/Index.thy
author streckem
Wed, 23 Oct 2002 16:10:02 +0200
changeset 13673 2950128b8206
child 13737 e564c3d2d174
permissions -rw-r--r--
First checkin of compiler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/Comp/Index.thy
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     2
    ID:         $Id$
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     3
    Author:     Martin Strecker
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     4
    Copyright   GPL 2002
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     5
*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     6
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     7
(* Index of variable in list of parameter names and local variables *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     8
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     9
theory Index =  AuxLemmas + DefsComp:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    10
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    11
(*indexing a variable name among all variable declarations in a method body*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    12
constdefs
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    13
 index :: "java_mb => vname => nat"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    14
 "index ==  \<lambda> (pn,lv,blk,res) v.
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    15
  if v = This
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    16
  then 0 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    17
  else Suc (length (takeWhile (\<lambda> z. z~=v) (pn @ map fst lv)))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    18
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    19
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    20
lemma index_length_pns: "
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    21
  \<lbrakk> i = index (pns,lvars,blk,res) vn;
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    22
  wf_java_mdecl G C ((mn,pTs),rT, (pns,lvars,blk,res)); 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    23
  vn \<in> set pns\<rbrakk> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    24
  \<Longrightarrow> 0 < i \<and> i < Suc (length pns)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    25
apply (simp add: wf_java_mdecl_def index_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    26
apply (subgoal_tac "vn \<noteq> This")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    27
apply (auto intro: length_takeWhile)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    28
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    29
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    30
lemma index_length_lvars: "
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    31
  \<lbrakk> i = index (pns,lvars,blk,res) vn;
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    32
  wf_java_mdecl G C ((mn,pTs),rT, (pns,lvars,blk,res)); 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    33
  vn \<in> set (map fst lvars)\<rbrakk> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    34
  \<Longrightarrow> (length pns) < i \<and> i < Suc((length pns) + (length lvars))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    35
apply (simp add: wf_java_mdecl_def index_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    36
apply (subgoal_tac "vn \<noteq> This")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    37
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    38
apply (subgoal_tac "\<forall> x \<in> set pns. (\<lambda>z. z \<noteq> vn) x")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    39
apply (simp add: takeWhile_append2)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    40
apply (subgoal_tac "length (takeWhile (\<lambda>z. z \<noteq> vn) (map fst lvars)) < length (map fst lvars)")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    41
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    42
apply (rule length_takeWhile)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    43
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    44
apply (simp add: map_of_in_set)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    45
apply (intro strip notI) apply simp apply blast
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    46
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    47
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    48
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    49
(***  index  ***)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    50
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    51
lemma select_at_index : 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    52
  "x \<in> set (gjmb_plns (gmb G C S)) \<or> x = This 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    53
  \<Longrightarrow> (the (loc This) # glvs (gmb G C S) loc) ! (index (gmb G C S) x) = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    54
     the (loc x)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    55
apply (simp only: index_def gjmb_plns_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    56
apply (case_tac "(gmb G C S)")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    57
apply (simp add: galldefs del: set_append map_append)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    58
apply (case_tac b, simp add: gmb_def gjmb_lvs_def del: set_append map_append)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    59
apply (intro strip)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    60
apply (simp del: set_append map_append)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    61
apply (frule length_takeWhile)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    62
apply (frule_tac f = "(the \<circ> loc)" in nth_map)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    63
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    64
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    65
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    66
lemma update_at_index: "
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    67
  \<lbrakk> distinct (gjmb_plns (gmb G C S)); 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    68
  x \<in> set (gjmb_plns (gmb G C S)); x \<noteq> This \<rbrakk> \<Longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    69
  locvars_xstate G C S (Norm (h, l))[index (gmb G C S) x := val] =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    70
          locvars_xstate G C S (Norm (h, l(x\<mapsto>val)))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    71
apply (simp only: locvars_xstate_def locvars_locals_def index_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    72
apply (case_tac "(gmb G C S)", simp)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    73
apply (case_tac b, simp)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    74
apply (rule conjI)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    75
apply (simp add: gl_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    76
apply (intro strip, simp)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    77
apply (simp add: galldefs del: set_append map_append)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    78
apply (auto simp: the_map_upd)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    79
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    80
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    81
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    82
(* !!!! incomprehensible: why can't List.takeWhile_append2 be applied the same 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    83
  way in the second case as in the first case ? *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    84
lemma index_of_var: "\<lbrakk> xvar \<notin> set pns; xvar \<notin> set (map fst zs); xvar \<noteq> This \<rbrakk>
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    85
  \<Longrightarrow> index (pns, zs @ ((xvar, xval) # xys), blk, res) xvar = Suc (length pns + length zs)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    86
apply (simp add: index_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    87
apply (subgoal_tac "(\<And>x. ((x \<in> (set pns)) \<Longrightarrow> ((\<lambda>z. (z \<noteq> xvar))x)))")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    88
apply (simp add: List.takeWhile_append2)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    89
apply (subgoal_tac "(takeWhile (\<lambda>z. z \<noteq> xvar) (map fst zs @ xvar # map fst xys)) = map fst zs @ (takeWhile (\<lambda>z. z \<noteq> xvar) (xvar # map fst xys))")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    90
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    91
apply (rule List.takeWhile_append2)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    92
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    93
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    94
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    95
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    96
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    97
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    98
(* The following def should replace the conditions in WellType.thy / wf_java_mdecl
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    99
*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   100
constdefs 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   101
  disjoint_varnames :: "[vname list, (vname \<times> ty) list] \<Rightarrow> bool"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   102
(* This corresponds to the original def in wf_java_mdecl:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   103
  "disjoint_varnames pns lvars \<equiv> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   104
  nodups pns \<and> unique lvars \<and> This \<notin> set pns \<and> This \<notin> set (map fst lvars) \<and> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   105
	(\<forall>pn\<in>set pns. map_of lvars pn = None)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   106
*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   107
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   108
  "disjoint_varnames pns lvars \<equiv> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   109
  distinct pns \<and> unique lvars \<and> This \<notin> set pns \<and> This \<notin> set (map fst lvars) \<and> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   110
  (\<forall>pn\<in>set pns. pn \<notin> set (map fst lvars))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   111
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   112
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   113
lemma index_of_var2: "
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   114
  disjoint_varnames pns (lvars_pre @ (vn, ty) # lvars_post)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   115
  \<Longrightarrow> index (pns, lvars_pre @ (vn, ty) # lvars_post, blk, res) vn =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   116
  Suc (length pns + length lvars_pre)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   117
apply (simp add: disjoint_varnames_def index_def unique_def distinct_append)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   118
apply (subgoal_tac "vn \<noteq> This", simp)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   119
apply (subgoal_tac
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   120
  "takeWhile (\<lambda>z. z \<noteq> vn) (map fst lvars_pre @ vn # map fst lvars_post) =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   121
  map fst lvars_pre @ takeWhile (\<lambda>z. z \<noteq> vn) (vn # map fst lvars_post)")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   122
apply simp 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   123
apply (rule List.takeWhile_append2)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   124
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   125
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   126
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   127
lemma wf_java_mdecl_disjoint_varnames: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   128
  "wf_java_mdecl G C (S,rT,(pns,lvars,blk,res)) 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   129
  \<Longrightarrow> disjoint_varnames pns lvars"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   130
apply (case_tac S)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   131
apply (simp add: wf_java_mdecl_def disjoint_varnames_def  map_of_in_set)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   132
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   133
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   134
lemma wf_java_mdecl_length_pTs_pns: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   135
  "wf_java_mdecl G C ((mn, pTs), rT, pns, lvars, blk, res)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   136
  \<Longrightarrow> length pTs = length pns"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   137
by (simp add: wf_java_mdecl_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   138
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   139
end