1 (* Copyright (C) 2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
31 let clearbody ~hyp (proof, goal) =
33 let curi,metasenv,pbo,pty = proof in
34 let metano,_,_ = CicUtil.lookup_meta goal metasenv in
43 (m,canonical_context,ty) when m = metano ->
44 let canonical_context' =
48 Some (C.Name hyp',C.Def (term,ty)) when hyp = hyp' ->
55 (CicTypeChecker.type_of_aux' metasenv context term
56 CicUniv.empty_ugraph) (* TASSI: FIXME *)
58 Some (C.Name hyp, Cic.Decl ty)
60 cleared_entry::context
61 | None -> None::context
63 | Some (n,C.Def (t,None)) ->
66 CicTypeChecker.type_of_aux' metasenv context t
67 CicUniv.empty_ugraph (* TASSI: FIXME *)
72 (lazy ("The correctness of hypothesis " ^
74 " relies on the body of " ^ hyp)
78 | Some (_,Cic.Def (_,Some _)) -> assert false
79 ) canonical_context []
83 CicTypeChecker.type_of_aux' metasenv canonical_context' ty
84 CicUniv.empty_ugraph (* TASSI: FIXME *)
89 (lazy ("The correctness of the goal relies on the body of " ^
92 m,canonical_context',ty
96 (curi,metasenv',pbo,pty), [goal]
98 mk_tactic (clearbody ~hyp)
101 let clear_one ~hyp (proof, goal) =
102 let module C = Cic in
103 let curi,metasenv,pbo,pty = proof in
104 let metano,context,ty =
105 CicUtil.lookup_meta goal metasenv
115 (m,canonical_context,ty) when m = metano ->
116 let context_changed, canonical_context' =
118 (fun entry (b, context) ->
120 Some (Cic.Name hyp',_) when hyp' = hyp ->
121 (true, None::context)
122 | None -> (b, None::context)
124 | Some (n,Cic.Def (t,Some _))
125 | Some (n,C.Def (t,None)) ->
129 CicTypeChecker.type_of_aux' metasenv context t
134 (lazy ("Hypothesis " ^ string_of_name n ^
135 " uses hypothesis " ^ hyp)))
140 ) canonical_context (false, [])
142 if not context_changed then
143 raise (Fail (lazy ("Hypothesis " ^ hyp ^ " does not exist")));
146 CicTypeChecker.type_of_aux' metasenv canonical_context' ty
149 raise (Fail (lazy ("Hypothesis " ^ hyp ^ " occurs in the goal")))
151 m,canonical_context',ty
155 (curi,metasenv',pbo,pty), [goal]
157 mk_tactic (clear_one ~hyp)
160 let clear hyps status =
162 match apply_tactic (clear_one ~hyp) status with
163 | proof, [g] -> proof, g
164 | _ -> raise (Fail (lazy "clear: internal error"))
166 let proof, g = List.fold_left aux status hyps in
169 mk_tactic (clear hyps)
171 (* Warning: this tactic has no effect on the proof term.
172 It just changes the name of an hypothesis in the current sequent *)
173 let rename ~from ~to_ =
174 let rename ~from ~to_ (proof, goal) =
175 let module C = Cic in
176 let curi,metasenv,pbo,pty = proof in
177 let metano,context,ty =
178 CicUtil.lookup_meta goal metasenv
183 (m,canonical_context,ty) when m = metano ->
184 let canonical_context' =
187 Some (Cic.Name hyp,decl_or_def) when hyp = from ->
188 Some (Cic.Name to_,decl_or_def)
192 m,canonical_context',ty
196 (curi,metasenv',pbo,pty), [goal]
198 mk_tactic (rename ~from ~to_)
201 ProofEngineTypes.mk_tactic
202 (fun (proof, goal) ->
203 let (_, metasenv, _, _) = proof in
204 if CicUtil.exists_meta n metasenv then
207 raise (ProofEngineTypes.Fail (lazy ("no such meta: " ^ string_of_int n))))