(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
open Util open Tacexpr open Mod_subst open Genarg open Stdarg open Tacarg open Tactypes open Tactics open Globnames open Patternops
(** Substitution of tactics at module closing time *)
(** For generic arguments, we declare and store substitutions
in a table *)
let subst_quantified_hypothesis _ x = x
let subst_declared_or_quantified_hypothesis _ x = x
let subst_glob_with_bindings_arg subst (clear,c) =
(clear,subst_glob_with_bindings subst c)
let rec subst_intro_pattern subst = CAst.map (function
| IntroAction p -> IntroAction (subst_intro_pattern_action subst p)
| IntroNaming _ | IntroForthcoming _ as x -> x)
and subst_intro_pattern_action subst = letopen CAst in function
| IntroApplyOn ({loc;v=t},pat) ->
IntroApplyOn (make ?loc @@ subst_glob_constr subst t,subst_intro_pattern subst pat)
| IntroOrAndPattern l ->
IntroOrAndPattern (subst_intro_or_and_pattern subst l)
| IntroInjection l -> IntroInjection (List.map (subst_intro_pattern subst) l)
| IntroWildcard | IntroRewrite _ as x -> x
and subst_intro_or_and_pattern subst = function
| IntroAndPattern l ->
IntroAndPattern (List.map (subst_intro_pattern subst) l)
| IntroOrPattern ll ->
IntroOrPattern (List.map (List.map (subst_intro_pattern subst)) ll)
let subst_destruction_arg subst = function
| clear,ElimOnConstr c -> clear,ElimOnConstr (subst_glob_with_bindings subst c)
| clear,ElimOnAnonHyp n as x -> x
| clear,ElimOnIdent id as x -> x
let subst_and_short_name f (c,n) = (* assert (n=None); *)(* since tacdef are strictly globalized *)
(f c,None)
let subst_located f = Loc.map f
let subst_reference subst =
Locusops.or_var_map (subst_located (subst_kn subst))
(*CSC: subst_global_reference is used "only" for RefArgType, that propagates to the syntactic non-terminals "global", used in commands such as
Print. It is also used for non-evaluable references. *)
let subst_global_reference subst =
Locusops.or_var_map (subst_located (subst_global_reference subst))
let subst_evaluable subst = let subst_eval_ref = Tacred.subst_evaluable_reference subst in
Locusops.or_var_map (subst_and_short_name subst_eval_ref)
let subst_constr_with_occurrences subst (l,c) = (l,subst_glob_constr subst c)
let subst_glob_constr_or_pattern subst (bvars,c,p) = let env = Global.env () in let sigma = Evd.from_env env in
(bvars,subst_glob_constr subst c,subst_pattern env sigma subst p)
let subst_raw_may_eval subst = function
| ConstrEval (r,c) -> ConstrEval (subst_glob_red_expr subst r,subst_glob_constr subst c)
| ConstrContext (locid,c) -> ConstrContext (locid,subst_glob_constr subst c)
| ConstrTypeOf c -> ConstrTypeOf (subst_glob_constr subst c)
| ConstrTerm c -> ConstrTerm (subst_glob_constr subst c)
let subst_match_pattern subst = function
| Subterm (ido,pc) -> Subterm (ido,(subst_glob_constr_or_pattern subst pc))
| Term pc -> Term (subst_glob_constr_or_pattern subst pc)
(* Derived basic tactics *)
| TacInductionDestruct (isrec,ev,(l,el)) -> let l' = List.map (fun (c,ids,cls) ->
subst_destruction_arg subst c, ids, cls) l in let el' = Option.map (subst_glob_with_bindings subst) el in
TacInductionDestruct (isrec,ev,(l',el'))
(* For extensions *)
| TacAlias (s,l) -> let s = subst_kn subst s in
TacAlias (s,List.map (subst_tacarg subst) l)
| TacML (opn,l) -> TacML (opn,List.map (subst_tacarg subst) l)
)
and subst_tactic_fun subst (var,body) = (var,subst_tactic subst body)
and subst_tacarg subst = function
| Reference r -> Reference (subst_reference subst r)
| ConstrMayEval c -> ConstrMayEval (subst_raw_may_eval subst c)
| TacCall { CAst.loc; v=(f,l) } ->
TacCall CAst.(make ?loc (subst_reference subst f, List.map (subst_tacarg subst) l))
| TacFreshId _ as x -> x
| TacPretype c -> TacPretype (subst_glob_constr subst c)
| TacNumgoals -> TacNumgoals
| Tacexp t -> Tacexp (subst_tactic subst t)
| TacGeneric (isquot,arg) -> TacGeneric (isquot,subst_genarg subst arg)
(* Reads the rules of a Match Context or a Match *) and subst_match_rule subst = function
| (All tc)::tl ->
(All (subst_tactic subst tc))::(subst_match_rule subst tl)
| (Pat (rl,mp,tc))::tl -> let hyps = subst_match_goal_hyps subst rl in let pat = subst_match_pattern subst mp in
Pat (hyps,pat,subst_tactic subst tc)
::(subst_match_rule subst tl)
| [] -> []
and subst_genarg subst (GenArg (Glbwit wit, x)) = match wit with
| ListArg wit -> letmap x = let ans = subst_genarg subst (in_gen (glbwit wit) x) in
out_gen (glbwit wit) ans in
in_gen (glbwit (wit_list wit)) (List.mapmap x)
| OptArg wit -> let ans = match x with
| None -> in_gen (glbwit (wit_opt wit)) None
| Some x -> let s = out_gen (glbwit wit) (subst_genarg subst (in_gen (glbwit wit) x)) in
in_gen (glbwit (wit_opt wit)) (Some s) in
ans
| PairArg (wit1, wit2) -> let p, q = x in let p = out_gen (glbwit wit1) (subst_genarg subst (in_gen (glbwit wit1) p)) in let q = out_gen (glbwit wit2) (subst_genarg subst (in_gen (glbwit wit2) q)) in
in_gen (glbwit (wit_pair wit1 wit2)) (p, q)
| ExtraArg s ->
Gensubst.generic_substitute subst (in_gen (glbwit wit) x)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.