src/HOL/SPARK/Tools/spark_vcs.ML
changeset 58112 8081087096ad
parent 58111 82db9ad610b9
child 58130 5e9170812356
equal deleted inserted replaced
58111:82db9ad610b9 58112:8081087096ad
   171 
   171 
   172 (** generate properties of enumeration types **)
   172 (** generate properties of enumeration types **)
   173 
   173 
   174 fun add_enum_type tyname tyname' thy =
   174 fun add_enum_type tyname tyname' thy =
   175   let
   175   let
   176     val {case_name, ...} = the (Datatype_Data.get_info thy tyname');
   176     val {case_name, ...} = the (Old_Datatype_Data.get_info thy tyname');
   177     val cs = map Const (the (Datatype_Data.get_constrs thy tyname'));
   177     val cs = map Const (the (Old_Datatype_Data.get_constrs thy tyname'));
   178     val k = length cs;
   178     val k = length cs;
   179     val T = Type (tyname', []);
   179     val T = Type (tyname', []);
   180     val p = Const (@{const_name pos}, T --> HOLogic.intT);
   180     val p = Const (@{const_name pos}, T --> HOLogic.intT);
   181     val v = Const (@{const_name val}, HOLogic.intT --> T);
   181     val v = Const (@{const_name val}, HOLogic.intT --> T);
   182     val card = Const (@{const_name card},
   182     val card = Const (@{const_name card},
   207       (HOLogic.mk_Trueprop (HOLogic.mk_eq
   207       (HOLogic.mk_Trueprop (HOLogic.mk_eq
   208          (HOLogic.mk_UNIV T, HOLogic.mk_set T cs)))
   208          (HOLogic.mk_UNIV T, HOLogic.mk_set T cs)))
   209       (fn _ =>
   209       (fn _ =>
   210          rtac @{thm subset_antisym} 1 THEN
   210          rtac @{thm subset_antisym} 1 THEN
   211          rtac @{thm subsetI} 1 THEN
   211          rtac @{thm subsetI} 1 THEN
   212          Datatype_Aux.exh_tac (K (#exhaust (Datatype_Data.the_info
   212          Old_Datatype_Aux.exh_tac (K (#exhaust (Old_Datatype_Data.the_info
   213            (Proof_Context.theory_of lthy) tyname'))) 1 THEN
   213            (Proof_Context.theory_of lthy) tyname'))) 1 THEN
   214          ALLGOALS (asm_full_simp_tac lthy));
   214          ALLGOALS (asm_full_simp_tac lthy));
   215 
   215 
   216     val finite_UNIV = Goal.prove lthy [] []
   216     val finite_UNIV = Goal.prove lthy [] []
   217       (HOLogic.mk_Trueprop (Const (@{const_name finite},
   217       (HOLogic.mk_Trueprop (Const (@{const_name finite},
   318               let
   318               let
   319                 val tyb = Binding.name s;
   319                 val tyb = Binding.name s;
   320                 val tyname = Sign.full_name thy tyb
   320                 val tyname = Sign.full_name thy tyb
   321               in
   321               in
   322                 (thy |>
   322                 (thy |>
   323                  Datatype.add_datatype {strict = true, quiet = true}
   323                  Old_Datatype.add_datatype {strict = true, quiet = true}
   324                    [((tyb, [], NoSyn),
   324                    [((tyb, [], NoSyn),
   325                      map (fn s => (Binding.name s, [], NoSyn)) els)] |> snd |>
   325                      map (fn s => (Binding.name s, [], NoSyn)) els)] |> snd |>
   326                  add_enum_type s tyname,
   326                  add_enum_type s tyname,
   327                  tyname)
   327                  tyname)
   328               end
   328               end
   329           | SOME (T as Type (tyname, []), cmap) =>
   329           | SOME (T as Type (tyname, []), cmap) =>
   330               (case Datatype_Data.get_constrs thy tyname of
   330               (case Old_Datatype_Data.get_constrs thy tyname of
   331                  NONE => assoc_ty_err thy T s "is not a datatype"
   331                  NONE => assoc_ty_err thy T s "is not a datatype"
   332                | SOME cs =>
   332                | SOME cs =>
   333                    let val (prfx', _) = strip_prfx s
   333                    let val (prfx', _) = strip_prfx s
   334                    in
   334                    in
   335                      case check_enum (map (unprefix_pfun prfx') els)
   335                      case check_enum (map (unprefix_pfun prfx') els)
   336                          (invert_map cmap cs) of
   336                          (invert_map cmap cs) of
   337                        NONE => (thy, tyname)
   337                        NONE => (thy, tyname)
   338                      | SOME msg => assoc_ty_err thy T s msg
   338                      | SOME msg => assoc_ty_err thy T s msg
   339                    end)
   339                    end)
   340           | SOME (T, _) => assoc_ty_err thy T s "is not a datatype");
   340           | SOME (T, _) => assoc_ty_err thy T s "is not a datatype");
   341         val cs = map Const (the (Datatype_Data.get_constrs thy' tyname));
   341         val cs = map Const (the (Old_Datatype_Data.get_constrs thy' tyname));
   342       in
   342       in
   343         ((fold (Symtab.update_new o apsnd (rpair s)) (els ~~ cs) tab,
   343         ((fold (Symtab.update_new o apsnd (rpair s)) (els ~~ cs) tab,
   344           fold Name.declare els ctxt),
   344           fold Name.declare els ctxt),
   345          thy')
   345          thy')
   346       end
   346       end
   886                type_map = Symtab.update_new (s, (T, cmap')) type_map,
   886                type_map = Symtab.update_new (s, (T, cmap')) type_map,
   887                env = env}
   887                env = env}
   888                 handle Symtab.DUP _ => error ("SPARK type " ^ s ^
   888                 handle Symtab.DUP _ => error ("SPARK type " ^ s ^
   889                   " already associated with type")) |>
   889                   " already associated with type")) |>
   890         (fn thy' =>
   890         (fn thy' =>
   891            case Datatype_Data.get_constrs thy' tyname of
   891            case Old_Datatype_Data.get_constrs thy' tyname of
   892              NONE => (case get_record_info thy' T of
   892              NONE => (case get_record_info thy' T of
   893                NONE => thy'
   893                NONE => thy'
   894              | SOME {fields, ...} =>
   894              | SOME {fields, ...} =>
   895                  (check_mapping (assoc_ty_err thy' T s) "field"
   895                  (check_mapping (assoc_ty_err thy' T s) "field"
   896                     cmap' (map fst fields);
   896                     cmap' (map fst fields);