aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Roux2018-10-19 13:16:25 +0200
committerPierre Roux2019-04-01 22:17:41 +0200
commit1c8fd0f7134bcc295e31613c981ef4ef2c21af35 (patch)
tree8fb25126d146fa57793bb9ba9e1595d0bcfc60a0
parent424c1973e96dfbf3b2e3245d735853ffa9600373 (diff)
Replace type sign = bool with SPlus | SMinus
-rw-r--r--interp/constrexpr.ml4
-rw-r--r--interp/constrexpr_ops.ml5
-rw-r--r--interp/constrextern.ml8
-rw-r--r--interp/constrintern.ml12
-rw-r--r--interp/notation.ml49
-rw-r--r--interp/notation.mli2
-rw-r--r--parsing/g_constr.mlg10
-rw-r--r--plugins/ltac/g_tactic.mlg3
-rw-r--r--plugins/ssr/ssrparser.mlg4
-rw-r--r--printing/ppconstr.ml6
-rw-r--r--vernac/egramcoq.ml4
11 files changed, 57 insertions, 50 deletions
diff --git a/interp/constrexpr.ml b/interp/constrexpr.ml
index 757d186c8b..f3d0888fee 100644
--- a/interp/constrexpr.ml
+++ b/interp/constrexpr.ml
@@ -53,11 +53,11 @@ type proj_flag = int option (** [Some n] = proj of the n-th visible argument *)
sign flag. Note that this representation is not unique, due to possible
multiple leading zeros, and -0 = +0 *)
-type sign = bool
+type sign = SPlus | SMinus
type raw_natural_number = string
type prim_token =
- | Numeral of raw_natural_number * sign
+ | Numeral of sign * raw_natural_number
| String of string
type instance_expr = Glob_term.glob_level list
diff --git a/interp/constrexpr_ops.ml b/interp/constrexpr_ops.ml
index 95a0039b0a..338ffb706d 100644
--- a/interp/constrexpr_ops.ml
+++ b/interp/constrexpr_ops.ml
@@ -54,9 +54,10 @@ let names_of_local_binders bl =
numbers of leading zeros) are considered different here. *)
let prim_token_eq t1 t2 = match t1, t2 with
-| Numeral (n1,s1), Numeral (n2,s2) -> String.equal n1 n2 && s1 == s2
+| Numeral (SPlus,n1), Numeral (SPlus,n2)
+| Numeral (SMinus,n1), Numeral (SMinus,n2) -> NumTok.equal n1 n2
| String s1, String s2 -> String.equal s1 s2
-| _ -> false
+| (Numeral ((SPlus|SMinus),_) | String _), _ -> false
let explicitation_eq ex1 ex2 = match ex1, ex2 with
| ExplByPos (i1, id1), ExplByPos (i2, id2) ->
diff --git a/interp/constrextern.ml b/interp/constrextern.ml
index c2afa097bb..4866ff3db5 100644
--- a/interp/constrextern.ml
+++ b/interp/constrextern.ml
@@ -332,15 +332,15 @@ let is_zero s =
let make_notation_gen loc ntn mknot mkprim destprim l bl =
match snd ntn,List.map destprim l with
(* Special case to avoid writing "- 3" for e.g. (Z.opp 3) *)
- | "- _", [Some (Numeral (p,true))] when not (is_zero p) ->
+ | "- _", [Some (Numeral (SPlus,p))] when not (is_zero p) ->
assert (bl=[]);
mknot (loc,ntn,([mknot (loc,(InConstrEntrySomeLevel,"( _ )"),l,[])]),[])
| _ ->
match decompose_notation_key ntn, l with
| (InConstrEntrySomeLevel,[Terminal "-"; Terminal x]), [] when is_number x ->
- mkprim (loc, Numeral (x,false))
+ mkprim (loc, Numeral (SMinus,x))
| (InConstrEntrySomeLevel,[Terminal x]), [] when is_number x ->
- mkprim (loc, Numeral (x,true))
+ mkprim (loc, Numeral (SPlus,x))
| _ -> mknot (loc,ntn,l,bl)
let make_notation loc ntn (terms,termlists,binders,binderlists as subst) =
@@ -969,7 +969,7 @@ let rec extern inctx (custom,scopes as allscopes) vars r =
CCast (sub_extern true scopes vars c,
map_cast_type (extern_typ scopes vars) c')
| GInt i ->
- CPrim(Numeral (Uint63.to_string i,true))
+ CPrim(Numeral (SPlus, Uint63.to_string i))
in insert_coercion coercion (CAst.make ?loc c)
diff --git a/interp/constrintern.ml b/interp/constrintern.ml
index 7a3e9881ea..86fcf7fd56 100644
--- a/interp/constrintern.ml
+++ b/interp/constrintern.ml
@@ -1513,11 +1513,11 @@ let rec subst_pat_iterator y t = DAst.(map (function
| RCPatOr pl -> RCPatOr (List.map (subst_pat_iterator y t) pl)))
let is_non_zero c = match c with
-| { CAst.v = CPrim (Numeral (p, true)) } -> not (is_zero p)
+| { CAst.v = CPrim (Numeral (SPlus, p)) } -> not (is_zero p)
| _ -> false
let is_non_zero_pat c = match c with
-| { CAst.v = CPatPrim (Numeral (p, true)) } -> not (is_zero p)
+| { CAst.v = CPatPrim (Numeral (SPlus, p)) } -> not (is_zero p)
| _ -> false
let get_asymmetric_patterns = Goptions.declare_bool_option_and_ref
@@ -1628,8 +1628,8 @@ let drop_notations_pattern looked_for genv =
let (argscs1,_) = find_remaining_scopes expl_pl pl g in
DAst.make ?loc @@ RCPatCstr (g, List.map2 (in_pat_sc scopes) argscs1 expl_pl @ List.map (in_pat false scopes) pl, [])
| CPatNotation ((InConstrEntrySomeLevel,"- _"),([a],[]),[]) when is_non_zero_pat a ->
- let p = match a.CAst.v with CPatPrim (Numeral (p, _)) -> p | _ -> assert false in
- let pat, _df = Notation.interp_prim_token_cases_pattern_expr ?loc (ensure_kind false loc) (Numeral (p,false)) scopes in
+ let p = match a.CAst.v with CPatPrim (Numeral (_, p)) -> p | _ -> assert false in
+ let pat, _df = Notation.interp_prim_token_cases_pattern_expr ?loc (ensure_kind false loc) (Numeral (SMinus,p)) scopes in
rcp_of_glob scopes pat
| CPatNotation ((InConstrEntrySomeLevel,"( _ )"),([a],[]),[]) ->
in_pat top scopes a
@@ -1944,8 +1944,8 @@ let internalize globalenv env pattern_mode (_, ntnvars as lvar) c =
GLetIn (na.CAst.v, inc1, int,
intern (push_name_env ntnvars (impls_term_list inc1) env na) c2)
| CNotation ((InConstrEntrySomeLevel,"- _"), ([a],[],[],[])) when is_non_zero a ->
- let p = match a.CAst.v with CPrim (Numeral (p, _)) -> p | _ -> assert false in
- intern env (CAst.make ?loc @@ CPrim (Numeral (p,false)))
+ let p = match a.CAst.v with CPrim (Numeral (_, p)) -> p | _ -> assert false in
+ intern env (CAst.make ?loc @@ CPrim (Numeral (SMinus,p)))
| CNotation ((InConstrEntrySomeLevel,"( _ )"),([a],[],[],[])) -> intern env a
| CNotation (ntn,args) ->
intern_notation intern env ntnvars loc ntn args
diff --git a/interp/notation.ml b/interp/notation.ml
index 2765661749..2c8f5e3a96 100644
--- a/interp/notation.ml
+++ b/interp/notation.ml
@@ -476,7 +476,7 @@ let notation_constr_key = function (* Rem: NApp(NRef ref,[]) stands for @ref *)
(* Interpreting numbers (not in summary because functional objects) *)
type required_module = full_path * string list
-type rawnum = Constrexpr.raw_natural_number * Constrexpr.sign
+type rawnum = Constrexpr.sign * Constrexpr.raw_natural_number
type prim_token_uid = string
@@ -499,13 +499,14 @@ module InnerPrimToken = struct
| StringInterp f, StringInterp f' -> f == f'
| _ -> false
- let ofNumeral n s =
- if s then Bigint.of_string n else Bigint.neg (Bigint.of_string n)
+ let ofNumeral s n = match s with
+ | SPlus -> Bigint.of_string n
+ | SMinus -> Bigint.neg (Bigint.of_string n)
let do_interp ?loc interp primtok =
match primtok, interp with
- | Numeral (n,s), RawNumInterp interp -> interp ?loc (n,s)
- | Numeral (n,s), BigNumInterp interp -> interp ?loc (ofNumeral n s)
+ | Numeral (s,n), RawNumInterp interp -> interp ?loc (s,n)
+ | Numeral (s,n), BigNumInterp interp -> interp ?loc (ofNumeral s n)
| String s, StringInterp interp -> interp ?loc s
| _ -> raise Not_found
@@ -521,15 +522,15 @@ module InnerPrimToken = struct
| _ -> false
let mkNumeral n =
- if Bigint.is_pos_or_zero n then Numeral (Bigint.to_string n, true)
- else Numeral (Bigint.to_string (Bigint.neg n), false)
+ if Bigint.is_pos_or_zero n then Numeral (SPlus,Bigint.to_string n)
+ else Numeral (SMinus,Bigint.to_string (Bigint.neg n))
let mkString = function
| None -> None
| Some s -> if Unicode.is_utf8 s then Some (String s) else None
let do_uninterp uninterp g = match uninterp with
- | RawNumUninterp u -> Option.map (fun (n,s) -> Numeral (n,s)) (u g)
+ | RawNumUninterp u -> Option.map (fun (s,n) -> Numeral (s,n)) (u g)
| BigNumUninterp u -> Option.map mkNumeral (u g)
| StringUninterp u -> mkString (u g)
@@ -766,9 +767,10 @@ let coquint_of_rawnum uint str =
in
do_chars str (String.length str - 1) nil
-let coqint_of_rawnum inds (str,sign) =
+let coqint_of_rawnum inds (sign,str) =
let uint = coquint_of_rawnum inds.uint str in
- mkApp (mkConstruct (inds.int, if sign then 1 else 2), [|uint|])
+ let pos_neg = match sign with SPlus -> 1 | SMinus -> 2 in
+ mkApp (mkConstruct (inds.int, pos_neg), [|uint|])
let rawnum_of_coquint c =
let rec of_uint_loop c buf =
@@ -794,8 +796,8 @@ let rawnum_of_coqint c =
match Constr.kind c with
| App (c,[|c'|]) ->
(match Constr.kind c with
- | Construct ((_,1), _) (* Pos *) -> (rawnum_of_coquint c', true)
- | Construct ((_,2), _) (* Neg *) -> (rawnum_of_coquint c', false)
+ | Construct ((_,1), _) (* Pos *) -> (SPlus, rawnum_of_coquint c')
+ | Construct ((_,2), _) (* Neg *) -> (SMinus, rawnum_of_coquint c')
| _ -> raise NotAValidPrimToken)
| _ -> raise NotAValidPrimToken
@@ -885,21 +887,22 @@ let bigint_of_int63 c =
| _ -> raise NotAValidPrimToken
let big2raw n =
- if Bigint.is_pos_or_zero n then (Bigint.to_string n, true)
- else (Bigint.to_string (Bigint.neg n), false)
+ if Bigint.is_pos_or_zero n then (SPlus, Bigint.to_string n)
+ else (SMinus, Bigint.to_string (Bigint.neg n))
-let raw2big (n,s) =
- if s then Bigint.of_string n else Bigint.neg (Bigint.of_string n)
+let raw2big (s,n) = match s with
+ | SPlus -> Bigint.of_string n
+ | SMinus -> Bigint.neg (Bigint.of_string n)
let interp o ?loc n =
- begin match o.warning with
- | Warning threshold when snd n && rawnum_compare (fst n) threshold >= 0 ->
+ begin match o.warning, n with
+ | Warning threshold, (SPlus, n) when rawnum_compare n threshold >= 0 ->
warn_large_num o.ty_name
| _ -> ()
end;
let c = match fst o.to_kind with
| Int int_ty -> coqint_of_rawnum int_ty n
- | UInt uint_ty when snd n -> coquint_of_rawnum uint_ty (fst n)
+ | UInt uint_ty when fst n == SPlus -> coquint_of_rawnum uint_ty (snd n)
| UInt _ (* n <= 0 *) -> no_such_prim_token "number" ?loc o.ty_name
| Z z_pos_ty -> z_of_bigint z_pos_ty (raw2big n)
| Int63 -> interp_int63 ?loc (raw2big n)
@@ -909,7 +912,7 @@ let interp o ?loc n =
let sigma,to_ty = Evd.fresh_global env sigma o.to_ty in
let to_ty = EConstr.Unsafe.to_constr to_ty in
match o.warning, snd o.to_kind with
- | Abstract threshold, Direct when rawnum_compare (fst n) threshold >= 0 ->
+ | Abstract threshold, Direct when rawnum_compare (snd n) threshold >= 0 ->
warn_abstract_large_num (o.ty_name,o.to_ty);
glob_of_constr "numeral" ?loc env sigma (mkApp (to_ty,[|c|]))
| _ ->
@@ -922,7 +925,7 @@ let uninterp o n =
PrimTokenNotation.uninterp
begin function
| (Int _, c) -> rawnum_of_coqint c
- | (UInt _, c) -> (rawnum_of_coquint c, true)
+ | (UInt _, c) -> (SPlus, rawnum_of_coquint c)
| (Z _, c) -> big2raw (bigint_of_z c)
| (Int63, c) -> big2raw (bigint_of_int63 c)
end o n
@@ -1249,8 +1252,8 @@ let find_notation ntn sc =
(n.not_interp, n.not_location)
let notation_of_prim_token = function
- | Numeral (n,true) -> InConstrEntrySomeLevel, n
- | Numeral (n,false) -> InConstrEntrySomeLevel, "- "^n
+ | Numeral (SPlus,n) -> InConstrEntrySomeLevel, n
+ | Numeral (SMinus,n) -> InConstrEntrySomeLevel, "- "^n
| String _ -> raise Not_found
let find_prim_token check_allowed ?loc p sc =
diff --git a/interp/notation.mli b/interp/notation.mli
index 5dcc96dc29..4480f3ff75 100644
--- a/interp/notation.mli
+++ b/interp/notation.mli
@@ -77,7 +77,7 @@ val find_delimiters_scope : ?loc:Loc.t -> delimiters -> scope_name
type notation_location = (DirPath.t * DirPath.t) * string
type required_module = full_path * string list
-type rawnum = Constrexpr.raw_natural_number * Constrexpr.sign
+type rawnum = Constrexpr.sign * Constrexpr.raw_natural_number
(** The unique id string below will be used to refer to a particular
registered interpreter/uninterpreter of numeral or string notation.
diff --git a/parsing/g_constr.mlg b/parsing/g_constr.mlg
index 6f73a3e4ed..9679474e81 100644
--- a/parsing/g_constr.mlg
+++ b/parsing/g_constr.mlg
@@ -226,7 +226,7 @@ GRAMMAR EXTEND Gram
| c=match_constr -> { c }
| "("; c = operconstr LEVEL "200"; ")" ->
{ (match c.CAst.v with
- | CPrim (Numeral (n,true)) ->
+ | CPrim (Numeral (SPlus,n)) ->
CAst.make ~loc @@ CNotation((InConstrEntrySomeLevel,"( _ )"),([c],[],[],[]))
| _ -> c) }
| "{|"; c = record_declaration; "|}" -> { c }
@@ -305,7 +305,7 @@ GRAMMAR EXTEND Gram
atomic_constr:
[ [ g=global; i=instance -> { CAst.make ~loc @@ CRef (g,i) }
| s=sort -> { CAst.make ~loc @@ CSort s }
- | n=INT -> { CAst.make ~loc @@ CPrim (Numeral (n,true)) }
+ | n=INT -> { CAst.make ~loc @@ CPrim (Numeral (SPlus,n)) }
| s=string -> { CAst.make ~loc @@ CPrim (String s) }
| "_" -> { CAst.make ~loc @@ CHole (None, IntroAnonymous, None) }
| "?"; "["; id=ident; "]" -> { CAst.make ~loc @@ CHole (None, IntroIdentifier id, None) }
@@ -413,18 +413,18 @@ GRAMMAR EXTEND Gram
| "_" -> { CAst.make ~loc @@ CPatAtom None }
| "("; p = pattern LEVEL "200"; ")" ->
{ (match p.CAst.v with
- | CPatPrim (Numeral (n,true)) ->
+ | CPatPrim (Numeral (SPlus,n)) ->
CAst.make ~loc @@ CPatNotation((InConstrEntrySomeLevel,"( _ )"),([p],[]),[])
| _ -> p) }
| "("; p = pattern LEVEL "200"; ":"; ty = lconstr; ")" ->
{ let p =
match p with
- | { CAst.v = CPatPrim (Numeral (n,true)) } ->
+ | { CAst.v = CPatPrim (Numeral (SPlus,n)) } ->
CAst.make ~loc @@ CPatNotation((InConstrEntrySomeLevel,"( _ )"),([p],[]),[])
| _ -> p
in
CAst.make ~loc @@ CPatCast (p, ty) }
- | n = INT -> { CAst.make ~loc @@ CPatPrim (Numeral (n,true)) }
+ | n = INT -> { CAst.make ~loc @@ CPatPrim (Numeral (SPlus,n)) }
| s = string -> { CAst.make ~loc @@ CPatPrim (String s) } ] ]
;
impl_ident_tail:
diff --git a/plugins/ltac/g_tactic.mlg b/plugins/ltac/g_tactic.mlg
index 7bf705ffeb..574e22d50e 100644
--- a/plugins/ltac/g_tactic.mlg
+++ b/plugins/ltac/g_tactic.mlg
@@ -147,7 +147,8 @@ let destruction_arg_of_constr (c,lbind as clbind) = match lbind with
end
| _ -> ElimOnConstr clbind
-let mkNumeral n = Numeral (string_of_int (abs n), 0<=n)
+let mkNumeral n =
+ Numeral ((if 0<=n then SPlus else SMinus),string_of_int (abs n))
let mkTacCase with_evar = function
| [(clear,ElimOnConstr cl),(None,None),None],None ->
diff --git a/plugins/ssr/ssrparser.mlg b/plugins/ssr/ssrparser.mlg
index 0ec5f1673a..9931305832 100644
--- a/plugins/ssr/ssrparser.mlg
+++ b/plugins/ssr/ssrparser.mlg
@@ -360,8 +360,8 @@ let interp_index ist gl idx =
| Some c ->
let rc = Detyping.detype Detyping.Now false Id.Set.empty (pf_env gl) (project gl) c in
begin match Notation.uninterp_prim_token rc with
- | _, Constrexpr.Numeral (s,b) ->
- let n = int_of_string s in if b then n else -n
+ | _, Constrexpr.Numeral (b,s) ->
+ let n = int_of_string s in (match b with SPlus -> n | SMinus -> -n)
| _ -> raise Not_found
end
| None -> raise Not_found
diff --git a/printing/ppconstr.ml b/printing/ppconstr.ml
index 229930142e..1c496efb8f 100644
--- a/printing/ppconstr.ml
+++ b/printing/ppconstr.ml
@@ -84,7 +84,8 @@ let tag_var = tag Tag.variable
| Any -> true
let prec_of_prim_token = function
- | Numeral (_,b) -> if b then lposint else lnegint
+ | Numeral (SPlus,_) -> lposint
+ | Numeral (SMinus,_) -> lnegint
| String _ -> latom
let print_hunks n pr pr_patt pr_binders (terms, termlists, binders, binderlists) unps =
@@ -234,7 +235,8 @@ let tag_var = tag Tag.variable
| t -> str " :" ++ pr_sep_com (fun()->brk(1,2)) (pr ltop) t
let pr_prim_token = function
- | Numeral (n,s) -> str (if s then n else "-"^n)
+ | Numeral (SPlus,n) -> str n
+ | Numeral (SMinus,n) -> str ("-"^n)
| String s -> qs s
let pr_evar pr id l =
diff --git a/vernac/egramcoq.ml b/vernac/egramcoq.ml
index f1a08cc9b3..b913bccfa3 100644
--- a/vernac/egramcoq.ml
+++ b/vernac/egramcoq.ml
@@ -403,8 +403,8 @@ match e with
| TTClosedBinderList _ -> { subst with binderlists = List.flatten v :: subst.binderlists }
| TTBigint ->
begin match forpat with
- | ForConstr -> push_constr subst (CAst.make @@ CPrim (Numeral (v,true)))
- | ForPattern -> push_constr subst (CAst.make @@ CPatPrim (Numeral (v,true)))
+ | ForConstr -> push_constr subst (CAst.make @@ CPrim (Numeral (SPlus,v)))
+ | ForPattern -> push_constr subst (CAst.make @@ CPatPrim (Numeral (SPlus,v)))
end
| TTReference ->
begin match forpat with