Debian Codegraph @

interp/primNotations.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Glob_term
12 open Names
13
14 type rawnum = NumTok.Signed.t
15
16 (** The unique id string below will be used to refer to a particular
17 registered interpreter/uninterpreter of number or string notation.
18 Using the same uid for different (un)interpreters will fail.
19 If at most one interpretation of prim token is used per scope,
20 then the scope name could be used as unique id. *)
21
22 type prim_token_uid = private string
23
24 type 'a prim_token_interpreter = ?loc:Loc.t -> 'a -> glob_constr
25 type 'a prim_token_uninterpreter = any_glob_constr -> 'a option
26
27 type 'a prim_token_interpretation =
28 'a prim_token_interpreter * 'a prim_token_uninterpreter
29
30 val register_rawnumeral_interpretation :
31 ?allow_overwrite:bool -> string -> rawnum prim_token_interpretation -> prim_token_uid
32
33 val register_bignumeral_interpretation :
34 ?allow_overwrite:bool -> string -> Z.t prim_token_interpretation -> prim_token_uid
35
36 val register_string_interpretation :
37 ?allow_overwrite:bool -> string -> string prim_token_interpretation -> prim_token_uid
38
39 (** * Number notation *)
40
41 type prim_token_notation_error =
42 | UnexpectedTerm of Constr.t
43 | UnexpectedNonOptionTerm of Constr.t
44
45 exception PrimTokenNotationError of string * Environ.env * Evd.evar_map * prim_token_notation_error
46
47 type numnot_option =
48 | Nop
49 | Warning of NumTok.UnsignedNat.t
50 | Abstract of NumTok.UnsignedNat.t
51
52 type int_ty =
53 { dec_uint : Names.inductive;
54 dec_int : Names.inductive;
55 hex_uint : Names.inductive;
56 hex_int : Names.inductive;
57 uint : Names.inductive;
58 int : Names.inductive }
59
60 type z_pos_ty =
61 { z_ty : Names.inductive;
62 pos_ty : Names.inductive }
63
64 type number_ty =
65 { int : int_ty;
66 decimal : Names.inductive;
67 hexadecimal : Names.inductive;
68 number : Names.inductive }
69
70 type pos_neg_int63_ty =
71 { pos_neg_int63_ty : Names.inductive }
72
73 type target_kind =
74 | Int of int_ty (* Corelib.Init.Number.int + uint *)
75 | UInt of int_ty (* Corelib.Init.Number.uint *)
76 | Z of z_pos_ty (* Corelib.Numbers.BinNums.Z and positive *)
77 | Int63 of pos_neg_int63_ty (* Corelib.Numbers.Cyclic.Int63.PrimInt63.pos_neg_int63 *)
78 | Float64 (* Corelib.Floats.PrimFloat.float *)
79 | Number of number_ty (* Corelib.Init.Number.number + uint + int *)
80
81 type string_target_kind =
82 | ListByte
83 | Byte
84 | PString
85
86 type option_kind = Direct | Option | Error
87 type 'target conversion_kind = 'target * option_kind
88
89 (** A postprocessing translation [to_post] can be done after execution
90 of the [to_ty] interpreter. The reverse translation is performed
91 before the [of_ty] uninterpreter.
92
93 [to_post] is an array of [n] lists [l_i] of tuples [(f, t,
94 args)]. When the head symbol of the translated term matches one of
95 the [f] in the list [l_0] it is replaced by [t] and its arguments
96 are translated acording to [args] where [ToPostCopy] means that the
97 argument is kept unchanged and [ToPostAs k] means that the
98 argument is recursively translated according to [l_k].
99 [ToPostHole] introduces an additional implicit argument hole
100 (in the reverse translation, the corresponding argument is removed).
101 [ToPostCheck r] behaves as [ToPostCopy] except in the reverse
102 translation which fails if the copied term is not [r].
103 When [n] is null, no translation is performed. *)
104 type to_post_arg = ToPostCopy | ToPostAs of int | ToPostHole of Id.t | ToPostCheck of Constr.t
105 type ('target, 'warning) prim_token_notation_obj =
106 { to_kind : 'target conversion_kind;
107 to_ty : GlobRef.t;
108 to_post : ((GlobRef.t * GlobRef.t * to_post_arg list) list) array;
109 of_kind : 'target conversion_kind;
110 of_ty : GlobRef.t;
111 ty_name : Libnames.qualid; (* for warnings / error messages *)
112 warning : 'warning }
113
114 type number_notation_obj = (target_kind, numnot_option) prim_token_notation_obj
115 type string_notation_obj = (string_target_kind, unit) prim_token_notation_obj
116
117 type prim_token_interp_info =
118 | Uid of prim_token_uid
119 | NumberNotation of number_notation_obj
120 | StringNotation of string_notation_obj
121
122 val do_interp : ?loc:Loc.t -> prim_token_interp_info -> Constrexpr.prim_token -> Glob_term.glob_constr
123
124 val do_uninterp : print_float:bool -> prim_token_interp_info -> _ Glob_term.glob_constr_g -> Constrexpr.prim_token option
125
126 val can_interp : prim_token_interp_info -> Constrexpr.prim_token -> bool
127
128 (** Conversion from bigint to int63 *)
129 val int63_of_pos_bigint : Z.t -> Uint63.t