src/Pure/sign.ML
changeset 26939 1035c89b4c02
parent 26929 bad4e1819b42
child 26978 fd4b4ecf935e
equal deleted inserted replaced
26938:64e850c3da9e 26939:1035c89b4c02
    59   val intern_typ: theory -> typ -> typ
    59   val intern_typ: theory -> typ -> typ
    60   val extern_typ: theory -> typ -> typ
    60   val extern_typ: theory -> typ -> typ
    61   val intern_term: theory -> term -> term
    61   val intern_term: theory -> term -> term
    62   val extern_term: (string -> xstring) -> theory -> term -> term
    62   val extern_term: (string -> xstring) -> theory -> term -> term
    63   val intern_tycons: theory -> typ -> typ
    63   val intern_tycons: theory -> typ -> typ
    64   val is_pretty_global: Proof.context -> bool
       
    65   val set_pretty_global: bool -> Proof.context -> Proof.context
       
    66   val init_pretty_global: theory -> Proof.context
       
    67   val pretty_term: theory -> term -> Pretty.T
       
    68   val pretty_typ: theory -> typ -> Pretty.T
       
    69   val pretty_sort: theory -> sort -> Pretty.T
       
    70   val string_of_term: theory -> term -> string
       
    71   val string_of_typ: theory -> typ -> string
       
    72   val string_of_sort: theory -> sort -> string
       
    73   val pp: theory -> Pretty.pp
       
    74   val arity_number: theory -> string -> int
    64   val arity_number: theory -> string -> int
    75   val arity_sorts: theory -> string -> sort -> sort list
    65   val arity_sorts: theory -> string -> sort -> sort list
    76   val certify_class: theory -> class -> class
    66   val certify_class: theory -> class -> class
    77   val certify_sort: theory -> sort -> sort
    67   val certify_sort: theory -> sort -> sort
    78   val certify_typ: theory -> typ -> typ
    68   val certify_typ: theory -> typ -> typ
   327 
   317 
   328 end;
   318 end;
   329 
   319 
   330 
   320 
   331 
   321 
   332 (** pretty printing of terms, types etc. **)
       
   333 
       
   334 structure PrettyGlobal = ProofDataFun(type T = bool fun init _ = false);
       
   335 val is_pretty_global = PrettyGlobal.get;
       
   336 val set_pretty_global = PrettyGlobal.put;
       
   337 val init_pretty_global = set_pretty_global true o ProofContext.init;
       
   338 
       
   339 val pretty_term = Syntax.pretty_term o init_pretty_global;
       
   340 val pretty_typ = Syntax.pretty_typ o init_pretty_global;
       
   341 val pretty_sort = Syntax.pretty_sort o init_pretty_global;
       
   342 
       
   343 val string_of_term = Syntax.string_of_term o init_pretty_global;
       
   344 val string_of_typ = Syntax.string_of_typ o init_pretty_global;
       
   345 val string_of_sort = Syntax.string_of_sort o init_pretty_global;
       
   346 
       
   347 (*pp operations -- deferred evaluation*)
       
   348 fun pp thy = Pretty.pp
       
   349  (fn x => pretty_term thy x,
       
   350   fn x => pretty_typ thy x,
       
   351   fn x => pretty_sort thy x,
       
   352   fn x => Syntax.pretty_classrel (init_pretty_global thy) x,
       
   353   fn x => Syntax.pretty_arity (init_pretty_global thy) x);
       
   354 
       
   355 
       
   356 
       
   357 (** certify entities **)    (*exception TYPE*)
   322 (** certify entities **)    (*exception TYPE*)
   358 
   323 
   359 (* certify wrt. type signature *)
   324 (* certify wrt. type signature *)
   360 
   325 
   361 val arity_number = Type.arity_number o tsig_of;
   326 val arity_number = Type.arity_number o tsig_of;
   362 fun arity_sorts thy = Type.arity_sorts (pp thy) (tsig_of thy);
   327 fun arity_sorts thy = Type.arity_sorts (Syntax.pp_global thy) (tsig_of thy);
   363 
   328 
   364 val certify_class         = Type.cert_class o tsig_of;
   329 val certify_class         = Type.cert_class o tsig_of;
   365 val certify_sort          = Type.cert_sort o tsig_of;
   330 val certify_sort          = Type.cert_sort o tsig_of;
   366 val certify_typ           = Type.cert_typ o tsig_of;
   331 val certify_typ           = Type.cert_typ o tsig_of;
   367 fun certify_typ_mode mode = Type.cert_typ_mode mode o tsig_of;
   332 fun certify_typ_mode mode = Type.cert_typ_mode mode o tsig_of;
   414     val T = type_check pp tm';
   379     val T = type_check pp tm';
   415     val _ = if prop andalso T <> propT then err "Term not of type prop" else ();
   380     val _ = if prop andalso T <> propT then err "Term not of type prop" else ();
   416     val tm'' = Consts.certify pp (tsig_of thy) do_expand consts tm';
   381     val tm'' = Consts.certify pp (tsig_of thy) do_expand consts tm';
   417   in (if tm = tm'' then tm else tm'', T, Term.maxidx_of_term tm'') end;
   382   in (if tm = tm'' then tm else tm'', T, Term.maxidx_of_term tm'') end;
   418 
   383 
   419 fun certify_term thy = certify' false (pp thy) true (consts_of thy) thy;
   384 fun certify_term thy = certify' false (Syntax.pp_global thy) true (consts_of thy) thy;
   420 fun certify_prop thy = certify' true (pp thy) true (consts_of thy) thy;
   385 fun certify_prop thy = certify' true (Syntax.pp_global thy) true (consts_of thy) thy;
   421 
   386 
   422 fun cert_term_abbrev thy = #1 o certify' false (pp thy) false (consts_of thy) thy;
   387 fun cert_term_abbrev thy = #1 o certify' false (Syntax.pp_global thy) false (consts_of thy) thy;
   423 val cert_term = #1 oo certify_term;
   388 val cert_term = #1 oo certify_term;
   424 val cert_prop = #1 oo certify_prop;
   389 val cert_prop = #1 oo certify_prop;
   425 
   390 
   426 end;
   391 end;
   427 
   392 
   458 
   423 
   459 (* type arities *)
   424 (* type arities *)
   460 
   425 
   461 fun prep_arity prep_tycon prep_sort thy (t, Ss, S) =
   426 fun prep_arity prep_tycon prep_sort thy (t, Ss, S) =
   462   let val arity = (prep_tycon thy t, map (prep_sort thy) Ss, prep_sort thy S)
   427   let val arity = (prep_tycon thy t, map (prep_sort thy) Ss, prep_sort thy S)
   463   in Type.add_arity (pp thy) arity (tsig_of thy); arity end;
   428   in Type.add_arity (Syntax.pp_global thy) arity (tsig_of thy); arity end;
   464 
   429 
   465 val read_arity = prep_arity intern_type Syntax.read_sort_global;
   430 val read_arity = prep_arity intern_type Syntax.read_sort_global;
   466 val cert_arity = prep_arity (K I) certify_sort;
   431 val cert_arity = prep_arity (K I) certify_sort;
   467 
   432 
   468 
   433 
   545     |> infer
   510     |> infer
   546   end;
   511   end;
   547 
   512 
   548 fun read_def_terms (thy, types, sorts) used freeze sTs =
   513 fun read_def_terms (thy, types, sorts) used freeze sTs =
   549   let
   514   let
   550     val pp = pp thy;
   515     val pp = Syntax.pp_global thy;
   551     val consts = consts_of thy;
   516     val consts = consts_of thy;
   552     val cert_consts = Consts.certify pp (tsig_of thy) true consts;
   517     val cert_consts = Consts.certify pp (tsig_of thy) true consts;
   553     fun map_free x = if is_some (types (x, ~1)) then SOME x else NONE;
   518     fun map_free x = if is_some (types (x, ~1)) then SOME x else NONE;
   554     val (ts, inst) =
   519     val (ts, inst) =
   555       read_def_terms' pp (is_logtype thy) (syn_of thy) consts map_free
   520       read_def_terms' pp (is_logtype thy) (syn_of thy) consts map_free
   676 
   641 
   677 (* abbreviations *)
   642 (* abbreviations *)
   678 
   643 
   679 fun add_abbrev mode tags (c, raw_t) thy =
   644 fun add_abbrev mode tags (c, raw_t) thy =
   680   let
   645   let
   681     val pp = pp thy;
   646     val pp = Syntax.pp_global thy;
   682     val prep_tm = no_frees pp o Term.no_dummy_patterns o cert_term_abbrev thy;
   647     val prep_tm = no_frees pp o Term.no_dummy_patterns o cert_term_abbrev thy;
   683     val t = (prep_tm raw_t handle TYPE (msg, _, _) => error msg | TERM (msg, _) => error msg)
   648     val t = (prep_tm raw_t handle TYPE (msg, _, _) => error msg | TERM (msg, _) => error msg)
   684       handle ERROR msg => cat_error msg ("in constant abbreviation " ^ quote c);
   649       handle ERROR msg => cat_error msg ("in constant abbreviation " ^ quote c);
   685     val (res, consts') = consts_of thy
   650     val (res, consts') = consts_of thy
   686       |> Consts.abbreviate pp (tsig_of thy) (naming_of thy) mode tags (c, t);
   651       |> Consts.abbreviate pp (tsig_of thy) (naming_of thy) mode tags (c, t);
   704 
   669 
   705 fun primitive_class (bclass, classes) thy =
   670 fun primitive_class (bclass, classes) thy =
   706   thy |> map_sign (fn (naming, syn, tsig, consts) =>
   671   thy |> map_sign (fn (naming, syn, tsig, consts) =>
   707     let
   672     let
   708       val syn' = Syntax.update_consts [bclass] syn;
   673       val syn' = Syntax.update_consts [bclass] syn;
   709       val tsig' = Type.add_class (pp thy) naming (bclass, classes) tsig;
   674       val tsig' = Type.add_class (Syntax.pp_global thy) naming (bclass, classes) tsig;
   710     in (naming, syn', tsig', consts) end)
   675     in (naming, syn', tsig', consts) end)
   711   |> add_consts_i [(Logic.const_of_class bclass, Term.a_itselfT --> propT, NoSyn)];
   676   |> add_consts_i [(Logic.const_of_class bclass, Term.a_itselfT --> propT, NoSyn)];
   712 
   677 
   713 fun primitive_classrel arg thy = thy |> map_tsig (Type.add_classrel (pp thy) arg);
   678 fun primitive_classrel arg thy = thy |> map_tsig (Type.add_classrel (Syntax.pp_global thy) arg);
   714 fun primitive_arity arg thy = thy |> map_tsig (Type.add_arity (pp thy) arg);
   679 fun primitive_arity arg thy = thy |> map_tsig (Type.add_arity (Syntax.pp_global thy) arg);
   715 
   680 
   716 
   681 
   717 (* add translation functions *)
   682 (* add translation functions *)
   718 
   683 
   719 local
   684 local