Skip to content

Commit 246efbf

Browse files
author
Thomas Braibant
committed
Move the code for attr_warning in ppx_deriving
1 parent f4de2c5 commit 246efbf

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/ppx_deriving.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ let attr ~deriver name attrs =
161161
try Some (List.find (fun ({ txt }, _) -> txt = name) attrs)
162162
with Not_found -> None
163163

164+
let attr_warning expr =
165+
let loc = !default_loc in
166+
let structure = {pstr_desc = Pstr_eval (expr, []); pstr_loc = loc} in
167+
{txt = "ocaml.warning"; loc}, PStr [structure]
168+
164169
let fold_left_type_params fn accum params =
165170
List.fold_left (fun accum (param, _) ->
166171
match param with

src/ppx_deriving.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ val mangle_lid : ?fixpoint:string ->
159159
or [\[\@attr\]] otherwise. *)
160160
val attr : deriver:string -> string -> attributes -> attribute option
161161

162+
(** [attr_warning expr] builds the attribute [@ocaml.warning expr] *)
163+
val attr_warning: expression -> attribute
164+
162165
(** [free_vars_in_core_type typ] returns unique free variables in [typ] in
163166
lexical order. *)
164167
val free_vars_in_core_type : core_type -> string list
@@ -239,7 +242,7 @@ val seq_reduce : ?sep:expression -> expression -> expression -> expression
239242
(** [binop_reduce] ≡ [fun x a b -> [%expr [%e x] [%e a] [%e b]]]. *)
240243
val binop_reduce : expression -> expression -> expression -> expression
241244

242-
(** [strong_type_of_type ty] transform a type ty to
245+
(** [strong_type_of_type ty] transform a type ty to
243246
[freevars . ty], giving a strong polymorphic type *)
244247
val strong_type_of_type: core_type -> core_type
245248

src_plugins/ppx_deriving_ord.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ let wildcard_case int_cases =
4646
let to_int = [%e Exp.function_ int_cases] in
4747
Pervasives.compare (to_int lhs) (to_int rhs)]
4848

49-
let attr_warning expr =
50-
let loc = !default_loc in
51-
let structure = {pstr_desc = Pstr_eval (expr, []); pstr_loc = loc} in
52-
{txt = "ocaml.warning"; loc}, PStr [structure]
53-
5449
(* deactivate warning 4 in code that uses [wildcard_case] *)
5550
let warning_minus_4 =
56-
attr_warning [%expr "-4"]
51+
Ppx_deriving.attr_warning [%expr "-4"]
5752

5853
let pattn side typs =
5954
List.mapi (fun i _ -> pvar (argn side i)) typs

0 commit comments

Comments
 (0)