author  wenzelm 
Tue, 05 Dec 2006 22:14:53 +0100  
changeset 21668  2d811ae6752a 
parent 21644  5154a7213d3c 
child 21691  826ab43d43f5 
permissions  rwrr 
20894  1 
(* Title: Pure/Isar/theory_target.ML 
2 
ID: $Id$ 

3 
Author: Makarius 

4 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

5 
Common theory/locale targets. 
20894  6 
*) 
7 

8 
signature THEORY_TARGET = 

9 
sig 

21006  10 
val peek: local_theory > string option 
20962  11 
val begin: bstring > Proof.context > local_theory 
20894  12 
val init: xstring option > theory > local_theory 
13 
val init_i: string option > theory > local_theory 

14 
end; 

15 

16 
structure TheoryTarget: THEORY_TARGET = 

17 
struct 

18 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

19 

20894  20 
(** locale targets **) 
21 

21006  22 
(* context data *) 
23 

24 
structure Data = ProofDataFun 

25 
( 

26 
val name = "Isar/theory_target"; 

27 
type T = string option; 

28 
fun init _ = NONE; 

29 
fun print _ _ = (); 

30 
); 

31 

32 
val _ = Context.add_setup Data.init; 

33 
val peek = Data.get; 

34 

35 

20894  36 
(* pretty *) 
37 

38 
fun pretty loc ctxt = 

39 
let 

40 
val thy = ProofContext.theory_of ctxt; 

41 
val fixes = map (fn (x, T) => (x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt)); 

21585  42 
val assumes = map (fn A => (("", []), [(A, [])])) (map Thm.term_of (Assumption.assms_of ctxt)); 
20894  43 
val elems = 
44 
(if null fixes then [] else [Element.Fixes fixes]) @ 

45 
(if null assumes then [] else [Element.Assumes assumes]); 

46 
in 

20984  47 
if loc = "" then 
48 
[Pretty.block 

49 
[Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy), 

50 
Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]] 

51 
else if null elems then [Pretty.str ("locale " ^ Locale.extern thy loc)] 

52 
else 

53 
[Pretty.big_list ("locale " ^ Locale.extern thy loc ^ " =") 

54 
(map (Pretty.chunks o Element.pretty_ctxt ctxt) elems)] 

20894  55 
end; 
56 

57 

58 
(* consts *) 

59 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

60 
fun consts is_loc depends decls lthy = 
20894  61 
let 
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

62 
val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy))); 
20894  63 

64 
fun const ((c, T), mx) thy = 

65 
let 

66 
val U = map #2 xs > T; 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

67 
val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs); 
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

68 
val thy' = Sign.add_consts_authentic [(c, U, Syntax.unlocalize_mixfix is_loc mx)] thy; 
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

69 
in (((c, mx), t), thy') end; 
20894  70 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

71 
val (abbrs, lthy') = lthy > LocalTheory.theory_result (fold_map const decls); 
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

72 
val defs = abbrs > map (fn (x, t) => (x, (("", []), t))); 
20894  73 
in 
74 
lthy' 

21570  75 
> is_loc ? LocalTheory.abbrevs Syntax.default_mode abbrs 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

76 
> LocalDefs.add_defs defs >> map (apsnd snd) 
20894  77 
end; 
78 

79 

80 
(* defs *) 

81 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

82 
local 
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

83 

21570  84 
infix also; 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

85 

21570  86 
fun eq1 also eq2 = 
87 
eq2 COMP (eq1 COMP (Drule.incr_indexes2 eq1 eq2 transitive_thm)); 

88 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

89 
fun expand_term ctxt t = 
21570  90 
let 
91 
val thy = ProofContext.theory_of ctxt; 

92 
val thy_ctxt = ProofContext.init thy; 

93 
val ct = Thm.cterm_of thy t; 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

94 
val (defs, ct') = LocalDefs.export ctxt thy_ctxt (Drule.mk_term ct) > Drule.dest_term; 
21570  95 
in (Thm.term_of ct', Tactic.rewrite true defs ct) end; 
96 

20894  97 
fun add_def (name, prop) = 
98 
Theory.add_defs_i false false [(name, prop)] #> 

99 
(fn thy => (Drule.unvarify (Thm.get_axiom_i thy (Sign.full_name thy name)), thy)); 

100 

101 
in 

102 

21570  103 
fun defs kind args lthy0 = 
20894  104 
let 
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

105 
fun def ((c, mx), ((name, atts), rhs)) lthy1 = 
20894  106 
let 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

107 
val (rhs', rhs_conv) = expand_term lthy0 rhs; 
21570  108 
val xs = Variable.add_fixed (LocalTheory.target_of lthy0) rhs' []; 
20894  109 

21570  110 
val ([(lhs, lhs_def)], lthy2) = lthy1 
111 
> LocalTheory.consts (member (op =) xs) [((c, Term.fastype_of rhs), mx)]; 

112 
val lhs' = #2 (Logic.dest_equals (Thm.prop_of lhs_def)); 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

113 

21570  114 
val name' = Thm.def_name_optional c name; 
115 
val (def, lthy3) = lthy2 

20894  116 
> LocalTheory.theory_result (add_def (name', Logic.mk_equals (lhs', rhs'))); 
117 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

118 
val eq = 
21570  119 
(*c == loc.c xs*) lhs_def 
120 
(*lhs' == rhs'*) also def 

121 
(*rhs' == rhs*) also Thm.symmetric rhs_conv; 

20894  122 
in ((lhs, ((name', atts), [([eq], [])])), lthy3) end; 
123 

21570  124 
val ((lhss, facts), lthy') = lthy0 > fold_map def args >> split_list; 
21433  125 
val (res, lthy'') = lthy' > LocalTheory.notes kind facts; 
20894  126 
in (lhss ~~ map (apsnd the_single) res, lthy'') end; 
127 

128 
end; 

129 

130 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

131 
(* axioms *) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

132 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

133 
local 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

134 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

135 
fun add_axiom hyps (name, prop) thy = 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

136 
let 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

137 
val name' = if name = "" then "axiom_" ^ serial_string () else name; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

138 
val prop' = Logic.list_implies (hyps, prop); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

139 
val thy' = thy > Theory.add_axioms_i [(name', prop')]; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

140 
val axm = Drule.unvarify (Thm.get_axiom_i thy' (Sign.full_name thy' name')); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

141 
val prems = map (Thm.assume o Thm.cterm_of thy') hyps; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

142 
in (Drule.implies_elim_list axm prems, thy') end; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

143 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

144 
in 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

145 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

146 
fun axioms kind specs lthy = 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

147 
let 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

148 
val hyps = map Thm.term_of (Assumption.assms_of lthy); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

149 
fun axiom ((name, atts), props) thy = thy 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

150 
> fold_map (add_axiom hyps) (PureThy.name_multi name props) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

151 
> (fn ths => pair ((name, atts), [(ths, [])])); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

152 
in 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

153 
lthy 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

154 
> fold (fold Variable.declare_term o snd) specs 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

155 
> LocalTheory.theory_result (fold_map axiom specs) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

156 
> LocalTheory.notes kind 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

157 
end; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

158 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

159 
end; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

160 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

161 

20894  162 
(* notes *) 
163 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

164 
fun import_export_proof ctxt (name, raw_th) = 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

165 
let 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

166 
val thy = ProofContext.theory_of ctxt; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

167 
val thy_ctxt = ProofContext.init thy; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

168 
val certT = Thm.ctyp_of thy; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

169 
val cert = Thm.cterm_of thy; 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

170 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

171 
(*export assumes/defines*) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

172 
val th = Goal.norm_result raw_th; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

173 
val (defs, th') = LocalDefs.export ctxt thy_ctxt th; 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

174 
val concl_conv = Tactic.rewrite true defs (Thm.cprop_of th); 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

175 
val assms = map (Tactic.rewrite_rule defs o Thm.assume) (Assumption.assms_of ctxt); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

176 
val nprems = Thm.nprems_of th'  Thm.nprems_of th; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

177 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

178 
(*export fixes*) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

179 
val tfrees = map TFree (Drule.fold_terms Term.add_tfrees th' []); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

180 
val frees = map Free (Drule.fold_terms Term.add_frees th' []); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

181 
val (th'' :: vs) = (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees)) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

182 
> Variable.export ctxt thy_ctxt 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

183 
> Drule.zero_var_indexes_list; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

184 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

185 
(*thm definition*) 
21644  186 
val result = th'' 
187 
> PureThy.name_thm true true "" 

188 
> Goal.close_result 

189 
> PureThy.name_thm true true name; 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

190 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

191 
(*import fixes*) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

192 
val (tvars, vars) = 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

193 
chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

194 
>> map Logic.dest_type; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

195 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

196 
val instT = map_filter (fn (TVar v, T) => SOME (v, T)  _ => NONE) (tvars ~~ tfrees); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

197 
val inst = filter (is_Var o fst) (vars ~~ frees); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

198 
val cinstT = map (pairself certT o apfst TVar) instT; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

199 
val cinst = map (pairself (cert o Term.map_types (TermSubst.instantiateT instT))) inst; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

200 
val result' = Thm.instantiate (cinstT, cinst) result; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

201 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

202 
(*import assumes/defines*) 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

203 
val assm_tac = FIRST' (map (fn assm => Tactic.compose_tac (false, assm, 0)) assms); 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

204 
val result'' = 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

205 
(case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

206 
NONE => raise THM ("Failed to reimport result", 0, [result']) 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

207 
 SOME res => res) COMP (concl_conv COMP_INCR Drule.equal_elim_rule2) 
21644  208 
> Goal.norm_result 
209 
> PureThy.name_thm false false name; 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

210 

fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

211 
in (result'', result) end; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

212 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

213 
fun notes loc kind facts lthy = 
21585  214 
let 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

215 
val is_loc = loc <> ""; 
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

216 
val thy = ProofContext.theory_of lthy; 
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset

217 
val full = LocalTheory.full_name lthy; 
21585  218 

21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

219 
val facts' = facts 
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset

220 
> map (fn (a, bs) => (a, PureThy.burrow_fact (PureThy.name_multi (full (fst a))) bs)) 
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset

221 
> PureThy.map_facts (import_export_proof lthy); 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

222 
val local_facts = PureThy.map_facts #1 facts' 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

223 
> Attrib.map_facts (Attrib.attribute_i thy); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

224 
val target_facts = PureThy.map_facts #1 facts' 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

225 
> is_loc ? Element.facts_map (Element.morph_ctxt (LocalTheory.target_morphism lthy)); 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

226 
val global_facts = PureThy.map_facts #2 facts' 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

227 
> Attrib.map_facts (if is_loc then K I else Attrib.attribute_i thy); 
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

228 
in 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

229 
lthy > LocalTheory.theory 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

230 
(Sign.qualified_names 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

231 
#> PureThy.note_thmss_i kind global_facts #> snd 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

232 
#> Sign.restore_naming thy) 
21585  233 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

234 
> is_loc ? LocalTheory.target (Locale.add_thmss loc kind target_facts) 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

235 

21433  236 
> ProofContext.set_stmt true 
20894  237 
> ProofContext.qualified_names 
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

238 
> ProofContext.note_thmss_i kind local_facts 
20894  239 
> ProofContext.restore_naming lthy 
21433  240 
> ProofContext.restore_stmt lthy 
20894  241 
end; 
242 

243 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

244 
(* target declarations *) 
20894  245 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

246 
fun target_decl _ "" f = 
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

247 
LocalTheory.theory (Context.theory_map (f Morphism.identity)) #> 
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

248 
LocalTheory.target (Context.proof_map (f Morphism.identity)) 
21668  249 
 target_decl add loc f = LocalTheory.target (add loc f); 
20894  250 

21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

251 
val type_syntax = target_decl Locale.add_type_syntax; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

252 
val term_syntax = target_decl Locale.add_term_syntax; 
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset

253 
val declaration = target_decl Locale.add_declaration; 
20894  254 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

255 
fun target_morphism loc lthy = 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

256 
ProofContext.export_morphism lthy (LocalTheory.target_of lthy) $> 
21613
ae3bb930b50f
notes: more careful treatment of Goal.close_result;
wenzelm
parents:
21611
diff
changeset

257 
Morphism.thm_morphism Goal.norm_result; 
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

258 

21668  259 
fun target_name loc lthy = 
260 
(if loc = "" then Sign.naming_of (ProofContext.theory_of lthy) 

261 
else ProofContext.naming_of (LocalTheory.target_of lthy)) 

262 
> NameSpace.qualified_names 

263 
> NameSpace.full; 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

264 

20894  265 

266 
(* init and exit *) 

267 

21293  268 
fun begin loc = 
269 
Data.put (if loc = "" then NONE else SOME loc) #> 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

270 
LocalTheory.init (NameSpace.base loc) 
21293  271 
{pretty = pretty loc, 
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset

272 
consts = consts (loc <> ""), 
21293  273 
axioms = axioms, 
274 
defs = defs, 

275 
notes = notes loc, 

21498
6382c3a1e7cf
uniform interface for type_syntax/term_syntax/declaration, dependent on morphism;
wenzelm
parents:
21467
diff
changeset

276 
type_syntax = type_syntax loc, 
21293  277 
term_syntax = term_syntax loc, 
278 
declaration = declaration loc, 

21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

279 
target_morphism = target_morphism loc, 
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

280 
target_name = target_name loc, 
21293  281 
reinit = fn _ => begin loc o (if loc = "" then ProofContext.init else Locale.init loc), 
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset

282 
exit = LocalTheory.target_of}; 
20894  283 

20962  284 
fun init_i NONE thy = begin "" (ProofContext.init thy) 
285 
 init_i (SOME loc) thy = begin loc (Locale.init loc thy); 

20894  286 

21276  287 
fun init (SOME "") thy = init_i NONE thy 
288 
 init loc thy = init_i (Option.map (Locale.intern thy) loc) thy; 

20894  289 

290 
end; 