paulson@1591: (* Title: Pure/display.ML paulson@1591: ID: $Id$ paulson@1591: Author: Lawrence C Paulson, Cambridge University Computer Laboratory paulson@1591: Copyright 1993 University of Cambridge paulson@1591: paulson@1591: Printing of theories, theorems, etc. paulson@1591: *) paulson@1591: paulson@1591: signature DISPLAY = wenzelm@4950: sig wenzelm@4950: val show_hyps : bool ref wenzelm@6087: val show_tags : bool ref wenzelm@6976: val pretty_thm_no_quote: thm -> Pretty.T wenzelm@6926: val pretty_thm : thm -> Pretty.T wenzelm@6087: val pretty_thms : thm list -> Pretty.T wenzelm@4950: val string_of_thm : thm -> string wenzelm@4950: val pprint_thm : thm -> pprint_args -> unit paulson@1591: val print_thm : thm -> unit wenzelm@6087: val print_thms : thm list -> unit paulson@1591: val prth : thm -> thm wenzelm@4270: val prthq : thm Seq.seq -> thm Seq.seq paulson@1591: val prths : thm list -> thm list wenzelm@4950: val pretty_ctyp : ctyp -> Pretty.T wenzelm@4950: val pprint_ctyp : ctyp -> pprint_args -> unit paulson@1591: val string_of_ctyp : ctyp -> string wenzelm@4950: val print_ctyp : ctyp -> unit wenzelm@4950: val pretty_cterm : cterm -> Pretty.T wenzelm@4950: val pprint_cterm : cterm -> pprint_args -> unit wenzelm@4950: val string_of_cterm : cterm -> string wenzelm@4950: val print_cterm : cterm -> unit wenzelm@4950: val pretty_theory : theory -> Pretty.T wenzelm@4950: val pprint_theory : theory -> pprint_args -> unit wenzelm@4950: val print_syntax : theory -> unit wenzelm@4950: val print_theory : theory -> unit wenzelm@4950: val pretty_name_space : string * NameSpace.T -> Pretty.T wenzelm@4950: val show_consts : bool ref wenzelm@4950: end; paulson@1591: wenzelm@4950: structure Display: DISPLAY = paulson@1591: struct paulson@1591: wenzelm@6087: (** print thm **) wenzelm@6087: wenzelm@6087: val show_hyps = ref true; (*false: print meta-hypotheses as dots*) wenzelm@6087: val show_tags = ref false; (*false: suppress tags*) wenzelm@6087: wenzelm@6889: local wenzelm@6889: wenzelm@6087: fun pretty_tag (name, args) = Pretty.strs (name :: args); wenzelm@6087: val pretty_tags = Pretty.list "[" "]" o map pretty_tag; paulson@1591: wenzelm@6889: fun is_oracle (Thm.Oracle _) = true wenzelm@6889: | is_oracle _ = false; wenzelm@6889: wenzelm@6889: fun ex_oracle (Join (der, ders)) = is_oracle der orelse exists ex_oracle ders; wenzelm@6889: wenzelm@6314: fun pretty_thm_aux quote th = paulson@1591: let wenzelm@6889: val {sign, hyps, prop, der, ...} = rep_thm th; wenzelm@6087: val xshyps = Thm.extra_shyps th; wenzelm@6087: val (_, tags) = Thm.get_name_tags th; wenzelm@6087: wenzelm@6314: val prt_term = (if quote then Pretty.quote else I) o Sign.pretty_term sign; wenzelm@6279: paulson@1591: val hlen = length xshyps + length hyps; wenzelm@6894: val ex_ora = ex_oracle der; paulson@1591: val hsymbs = wenzelm@6894: if hlen = 0 andalso not ex_ora then [] paulson@1591: else if ! show_hyps then paulson@1591: [Pretty.brk 2, Pretty.list "[" "]" wenzelm@6889: (map prt_term hyps @ map (Sign.pretty_sort sign) xshyps @ wenzelm@6894: (if ex_ora then [Pretty.str "!"] else []))] wenzelm@6889: else [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ wenzelm@6894: (if ex_ora then "!" else "") ^ "]")]; wenzelm@6087: val tsymbs = wenzelm@6087: if null tags orelse not (! show_tags) then [] wenzelm@6087: else [Pretty.brk 1, pretty_tags tags]; wenzelm@6279: in Pretty.block (prt_term prop :: (hsymbs @ tsymbs)) end; paulson@1591: wenzelm@6889: in wenzelm@6889: wenzelm@6926: val pretty_thm = pretty_thm_aux true; wenzelm@6314: val pretty_thm_no_quote = pretty_thm_aux false; wenzelm@6314: wenzelm@6889: end; wenzelm@6889: wenzelm@6889: paulson@1591: val string_of_thm = Pretty.string_of o pretty_thm; wenzelm@6279: val pprint_thm = Pretty.pprint o pretty_thm; paulson@1591: wenzelm@6087: fun pretty_thms [th] = pretty_thm th wenzelm@6087: | pretty_thms ths = Pretty.block (Pretty.fbreaks (map pretty_thm ths)); paulson@1591: wenzelm@6087: wenzelm@6087: (* top-level commands for printing theorems *) wenzelm@6087: wenzelm@6087: val print_thm = Pretty.writeln o pretty_thm; wenzelm@6087: val print_thms = Pretty.writeln o pretty_thms; paulson@1591: paulson@1591: fun prth th = (print_thm th; th); paulson@1591: paulson@1591: (*Print and return a sequence of theorems, separated by blank lines. *) paulson@1591: fun prthq thseq = wenzelm@4270: (Seq.print (fn _ => print_thm) 100000 thseq; thseq); paulson@1591: paulson@1591: (*Print and return a list of theorems, separated by blank lines. *) wenzelm@4210: fun prths ths = (seq (fn th => (print_thm th; writeln "")) ths; ths); paulson@1591: paulson@1591: paulson@1591: (* other printing commands *) paulson@1591: wenzelm@4126: fun pretty_ctyp cT = wenzelm@4126: let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end; wenzelm@4126: paulson@1591: fun pprint_ctyp cT = paulson@1591: let val {sign, T} = rep_ctyp cT in Sign.pprint_typ sign T end; paulson@1591: paulson@1591: fun string_of_ctyp cT = paulson@1591: let val {sign, T} = rep_ctyp cT in Sign.string_of_typ sign T end; paulson@1591: paulson@1591: val print_ctyp = writeln o string_of_ctyp; paulson@1591: wenzelm@3547: fun pretty_cterm ct = wenzelm@3547: let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end; wenzelm@3547: paulson@1591: fun pprint_cterm ct = paulson@1591: let val {sign, t, ...} = rep_cterm ct in Sign.pprint_term sign t end; paulson@1591: paulson@1591: fun string_of_cterm ct = paulson@1591: let val {sign, t, ...} = rep_cterm ct in Sign.string_of_term sign t end; paulson@1591: paulson@1591: val print_cterm = writeln o string_of_cterm; paulson@1591: paulson@1591: wenzelm@4250: wenzelm@4250: (** print theory **) paulson@1591: wenzelm@6390: val pretty_theory = Sign.pretty_sg o Theory.sign_of; wenzelm@6390: val pprint_theory = Sign.pprint_sg o Theory.sign_of; paulson@1591: wenzelm@6390: val print_syntax = Syntax.print_syntax o Theory.syn_of; paulson@1591: wenzelm@4250: wenzelm@4498: (* pretty_name_space *) wenzelm@4498: wenzelm@4498: fun pretty_name_space (kind, space) = wenzelm@4498: let wenzelm@4498: fun prt_entry (name, accs) = Pretty.block wenzelm@4498: (Pretty.str (quote name ^ " =") :: Pretty.brk 1 :: wenzelm@4498: Pretty.commas (map (Pretty.str o quote) accs)); wenzelm@4498: in wenzelm@4498: Pretty.fbreaks (Pretty.str (kind ^ ":") :: map prt_entry (NameSpace.dest space)) wenzelm@4498: |> Pretty.block wenzelm@4498: end; wenzelm@4498: wenzelm@4498: wenzelm@4498: wenzelm@4250: (* print signature *) wenzelm@4250: wenzelm@4250: fun print_sign sg = wenzelm@4250: let wenzelm@4250: fun prt_cls c = Sign.pretty_sort sg [c]; wenzelm@4250: fun prt_sort S = Sign.pretty_sort sg S; wenzelm@4250: fun prt_arity t (c, Ss) = Sign.pretty_arity sg (t, Ss, [c]); wenzelm@4250: fun prt_typ ty = Pretty.quote (Sign.pretty_typ sg ty); wenzelm@4250: wenzelm@4250: wenzelm@4250: fun pretty_classes cs = Pretty.block wenzelm@4250: (Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs)); wenzelm@4250: wenzelm@4250: fun pretty_classrel (c, cs) = Pretty.block wenzelm@4250: (prt_cls c :: Pretty.str " <" :: Pretty.brk 1 :: wenzelm@4250: Pretty.commas (map prt_cls cs)); wenzelm@4250: wenzelm@4250: fun pretty_default S = Pretty.block wenzelm@4250: [Pretty.str "default:", Pretty.brk 1, prt_sort S]; wenzelm@4250: wenzelm@4250: fun pretty_ty (t, n) = Pretty.block wenzelm@7067: [Pretty.str t, Pretty.spc 1, Pretty.str (string_of_int n)]; wenzelm@4250: wenzelm@7635: fun pretty_log_types ts = Pretty.block wenzelm@7635: (Pretty.breaks (Pretty.str "logical types:" :: map Pretty.str ts)); wenzelm@7635: wenzelm@7635: fun pretty_witness None = Pretty.str "universal non-emptiness witness: --" wenzelm@7635: | pretty_witness (Some (T, S)) = Pretty.block wenzelm@7635: [Pretty.str "universal non-emptiness witness:", Pretty.brk 1, prt_typ T, Pretty.brk 1, prt_sort S]; wenzelm@7635: wenzelm@4250: fun pretty_abbr (t, (vs, rhs)) = Pretty.block wenzelm@4250: [prt_typ (Type (t, map (fn v => TVar ((v, 0), [])) vs)), wenzelm@4250: Pretty.str " =", Pretty.brk 1, prt_typ rhs]; wenzelm@4250: wenzelm@4250: fun pretty_arities (t, ars) = map (prt_arity t) ars; wenzelm@4250: wenzelm@4250: fun pretty_const (c, ty) = Pretty.block wenzelm@4250: [Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ ty]; wenzelm@4250: wenzelm@4250: val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg; wenzelm@6846: val spaces' = Library.sort_wrt fst spaces; wenzelm@7635: val {classes, classrel, default, tycons = type_tab, log_types, univ_witness, abbrs, arities} = wenzelm@4250: Type.rep_tsig tsig; wenzelm@7067: val tycons = Sign.cond_extern_table sg Sign.typeK type_tab; wenzelm@6846: val consts = Sign.cond_extern_table sg Sign.constK const_tab; wenzelm@4250: in wenzelm@4250: Pretty.writeln (Pretty.strs ("stamps:" :: Sign.stamp_names_of sg)); wenzelm@4256: Pretty.writeln (Pretty.strs ("data:" :: Sign.data_kinds data)); wenzelm@4782: Pretty.writeln (Pretty.strs ["name prefix:", NameSpace.pack path]); wenzelm@4498: Pretty.writeln (Pretty.big_list "name spaces:" (map pretty_name_space spaces')); wenzelm@4250: Pretty.writeln (pretty_classes classes); wenzelm@7067: Pretty.writeln (Pretty.big_list "class relation:" (map pretty_classrel (Symtab.dest classrel))); wenzelm@4250: Pretty.writeln (pretty_default default); wenzelm@7635: Pretty.writeln (pretty_log_types log_types); wenzelm@7635: Pretty.writeln (pretty_witness univ_witness); wenzelm@4250: Pretty.writeln (Pretty.big_list "type constructors:" (map pretty_ty tycons)); wenzelm@7067: Pretty.writeln (Pretty.big_list "type abbreviations:" (map pretty_abbr (Symtab.dest abbrs))); wenzelm@7067: Pretty.writeln (Pretty.big_list "type arities:" (flat (map pretty_arities (Symtab.dest arities)))); wenzelm@4250: Pretty.writeln (Pretty.big_list "consts:" (map pretty_const consts)) wenzelm@4250: end; wenzelm@4250: wenzelm@4250: wenzelm@4250: (* print axioms, oracles, theorems *) wenzelm@4250: wenzelm@3811: fun print_thy thy = paulson@1591: let wenzelm@6390: val {sign, axioms, oracles, ...} = Theory.rep_theory thy; wenzelm@6846: fun cond_externs kind = Sign.cond_extern_table sign kind; paulson@1591: wenzelm@3936: fun prt_axm (a, t) = Pretty.block wenzelm@6846: [Pretty.str (a ^ ":"), Pretty.brk 1, Pretty.quote (Sign.pretty_term sign t)]; paulson@1591: in wenzelm@6846: Pretty.writeln (Pretty.big_list "axioms:" (map prt_axm (cond_externs Theory.axiomK axioms))); wenzelm@6846: Pretty.writeln (Pretty.strs ("oracles:" :: (map #1 (cond_externs Theory.oracleK oracles)))) paulson@1591: end; paulson@1591: wenzelm@6390: fun print_theory thy = (print_sign (Theory.sign_of thy); print_thy thy); paulson@1591: wenzelm@4250: (*also show consts in case of showing types?*) wenzelm@3851: val show_consts = ref false; wenzelm@3851: paulson@1591: paulson@1591: end; paulson@1591: paulson@1591: open Display;