summaryrefslogtreecommitdiff
path: root/tactics/tactic_option.ml
diff options
context:
space:
mode:
authorGravatar Stephane Glondu <steph@glondu.net>2010-08-06 16:15:08 -0400
committerGravatar Stephane Glondu <steph@glondu.net>2010-08-06 16:17:55 -0400
commitf18e6146f4fd6ed5b8ded10a3e602f5f64f919f4 (patch)
treec413c5bb42d20daf5307634ae6402526bb994fd6 /tactics/tactic_option.ml
parentb9f47391f7f259c24119d1de0a87839e2cc5e80c (diff)
Imported Upstream version 8.3~rc1+dfsgupstream/8.3.rc1.dfsg
Diffstat (limited to 'tactics/tactic_option.ml')
-rw-r--r--tactics/tactic_option.ml57
1 files changed, 57 insertions, 0 deletions
diff --git a/tactics/tactic_option.ml b/tactics/tactic_option.ml
new file mode 100644
index 00000000..df5a3283
--- /dev/null
+++ b/tactics/tactic_option.ml
@@ -0,0 +1,57 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+(* $Id: subtac.ml 12623 2010-01-04 17:50:38Z letouzey $ *)
+
+open Libobject
+open Proof_type
+open Pp
+
+let declare_tactic_option ?(default=Tacexpr.TacId []) name =
+ let default_tactic_expr : Tacexpr.glob_tactic_expr ref = ref default in
+ let default_tactic : Proof_type.tactic ref = ref (Tacinterp.eval_tactic !default_tactic_expr) in
+ let locality = ref false in
+ let set_default_tactic local t =
+ locality := local;
+ default_tactic_expr := t; default_tactic := Tacinterp.eval_tactic t
+ in
+ let cache (_, (local, tac)) = set_default_tactic local tac in
+ let load (_, (local, tac)) =
+ if not local then set_default_tactic local tac
+ in
+ let subst (s, (local, tac)) =
+ (local, Tacinterp.subst_tactic s tac)
+ in
+ let input, _output =
+ declare_object
+ { (default_object name) with
+ cache_function = cache;
+ load_function = (fun _ -> load);
+ open_function = (fun _ -> load);
+ classify_function = (fun (local, tac) ->
+ if local then Dispose else Substitute (local, tac));
+ subst_function = subst}
+ in
+ let put local tac =
+ set_default_tactic local tac;
+ Lib.add_anonymous_leaf (input (local, tac))
+ in
+ let get () = !locality, !default_tactic in
+ let print () =
+ Pptactic.pr_glob_tactic (Global.env ()) !default_tactic_expr ++
+ (if !locality then str" (locally defined)" else str" (globally defined)")
+ in
+ let freeze () = !locality, !default_tactic_expr in
+ let unfreeze (local, t) = set_default_tactic local t in
+ let init () = () in
+ Summary.declare_summary name
+ { Summary.freeze_function = freeze;
+ Summary.unfreeze_function = unfreeze;
+ Summary.init_function = init };
+ put, get, print
+