summaryrefslogtreecommitdiff
path: root/src_plugins
diff options
context:
space:
mode:
authorStephane Glondu <steph@glondu.net>2021-11-19 13:12:04 +0100
committerStéphane Glondu <steph@glondu.net>2021-11-19 13:12:04 +0100
commit07d2c65d4f0867f0b41298175b5343fecf57bbad (patch)
treed3b6a60204864621a9f5532cf028b09212601ba3 /src_plugins
parenta4f13db147f12dbf7b7e985b338162f4fda29e9c (diff)
New upstream version 5.0
Diffstat (limited to 'src_plugins')
-rw-r--r--src_plugins/compat_macros.cppo11
-rw-r--r--src_plugins/create/dune5
-rw-r--r--src_plugins/create/ppx_deriving_create.cppo.ml11
-rw-r--r--src_plugins/enum/dune5
-rw-r--r--src_plugins/enum/ppx_deriving_enum.cppo.ml29
-rw-r--r--src_plugins/eq/dune5
-rw-r--r--src_plugins/eq/ppx_deriving_eq.cppo.ml22
-rw-r--r--src_plugins/fold/dune5
-rw-r--r--src_plugins/fold/ppx_deriving_fold.cppo.ml27
-rw-r--r--src_plugins/iter/dune5
-rw-r--r--src_plugins/iter/ppx_deriving_iter.cppo.ml22
-rw-r--r--src_plugins/make/dune5
-rw-r--r--src_plugins/make/ppx_deriving_make.cppo.ml11
-rw-r--r--src_plugins/map/dune4
-rw-r--r--src_plugins/map/ppx_deriving_map.cppo.ml26
-rw-r--r--src_plugins/ord/dune5
-rw-r--r--src_plugins/ord/ppx_deriving_ord.cppo.ml32
-rw-r--r--src_plugins/show/dune5
-rw-r--r--src_plugins/show/ppx_deriving_show.cppo.ml27
19 files changed, 93 insertions, 169 deletions
diff --git a/src_plugins/compat_macros.cppo b/src_plugins/compat_macros.cppo
deleted file mode 100644
index 7869e1c..0000000
--- a/src_plugins/compat_macros.cppo
+++ /dev/null
@@ -1,11 +0,0 @@
-#if OCAML_VERSION < (4, 03, 0)
-#define Pcstr_tuple(core_types) core_types
-#endif
-
-#if OCAML_VERSION < (4, 08, 0)
-#define Rtag_patt(label, constant, args) Rtag(label, _, constant, args)
-#define Rinherit_patt(typ) Rinherit(typ)
-#else
-#define Rtag_patt(label, constant, args) {prf_desc = Rtag(label, constant, args); _}
-#define Rinherit_patt(typ) {prf_desc = Rinherit(typ); _}
-#endif
diff --git a/src_plugins/create/dune b/src_plugins/create/dune
index fc5e81e..ab497af 100644
--- a/src_plugins/create/dune
+++ b/src_plugins/create/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_create.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version}
%{dep:ppx_deriving_create.cppo.ml} -o %{targets})))
@@ -9,6 +8,6 @@
(public_name ppx_deriving.create)
(synopsis "[@@deriving create]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/create/ppx_deriving_create.cppo.ml b/src_plugins/create/ppx_deriving_create.cppo.ml
index f9a3ff9..8d060d7 100644
--- a/src_plugins/create/ppx_deriving_create.cppo.ml
+++ b/src_plugins/create/ppx_deriving_create.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "create"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -79,12 +77,7 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(Ppx_deriving.sanitize ~quoter creator)]
let wrap_predef_option typ =
-#if OCAML_VERSION < (4, 03, 0)
- let predef_option = mknoloc (Ldot (Lident "*predef*", "option")) in
- Typ.constr predef_option [typ]
-#else
typ
-#endif
let sig_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
parse_options options;
diff --git a/src_plugins/enum/dune b/src_plugins/enum/dune
index 21ff948..32a9145 100644
--- a/src_plugins/enum/dune
+++ b/src_plugins/enum/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_enum.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version}
%{dep:ppx_deriving_enum.cppo.ml} -o %{targets})))
@@ -9,6 +8,6 @@
(public_name ppx_deriving.enum)
(synopsis "[@@deriving enum]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/enum/ppx_deriving_enum.cppo.ml b/src_plugins/enum/ppx_deriving_enum.cppo.ml
index ba71510..84aacdf 100644
--- a/src_plugins/enum/ppx_deriving_enum.cppo.ml
+++ b/src_plugins/enum/ppx_deriving_enum.cppo.ml
@@ -1,11 +1,13 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
+
+#if OCAML_VERSION < (4, 08, 0)
+module Stdlib = Pervasives
+#endif
let deriver = "enum"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -49,17 +51,6 @@ let mappings_of_type type_decl =
"%s can be derived only for argumentless constructors"
deriver
in
-#if OCAML_VERSION < (4, 08, 0)
- let loc = ptyp_loc in
- match row_field with
- | Rinherit _ -> error_inherit loc
- | Rtag (name, attrs, true, []) ->
- #if OCAML_VERSION < (4, 06, 0)
- let name = mkloc name loc in
- #endif
- map acc mappings attrs name
- | Rtag _ -> error_arguments loc
-#else
let loc = row_field.prf_loc in
let attrs = row_field.prf_attributes in
match row_field.prf_desc with
@@ -67,7 +58,6 @@ let mappings_of_type type_decl =
| Rtag (name, true, []) ->
map acc mappings attrs name
| Rtag _ -> error_arguments loc
-#endif
)
(0, []) constrs
| _ -> raise_errorf ~loc:type_decl.ptype_loc
@@ -77,13 +67,15 @@ let mappings_of_type type_decl =
match mappings with
| (a, { txt=atxt; loc=aloc }) :: (b, { txt=btxt; loc=bloc }) :: _ when a = b ->
let sigil = match kind with `Regular -> "" | `Polymorphic -> "`" in
- let sub = [Location.errorf ~loc:bloc "Same as for %s%s" sigil btxt] in
+ let sub =
+ [Ocaml_common.Location.errorf
+ ~loc:bloc "Same as for %s%s" sigil btxt] in
raise_errorf ~sub ~loc:aloc
"%s: duplicate value %d for constructor %s%s" deriver a sigil atxt
| _ :: rest -> check_dup rest
| [] -> ()
in
- mappings |> List.stable_sort (fun (a,_) (b,_) -> compare a b) |> check_dup;
+ mappings |> List.stable_sort (fun (a,_) (b,_) -> Stdlib.compare a b) |> check_dup;
kind, mappings
let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
@@ -116,6 +108,7 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(Exp.function_ from_enum_cases)]
let sig_of_type ~options ~path type_decl =
+ let loc = type_decl.ptype_loc in
parse_options options;
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
[Sig.value (Val.mk (mknoloc (Ppx_deriving.mangle_type_decl (`Prefix "min") type_decl))
diff --git a/src_plugins/eq/dune b/src_plugins/eq/dune
index 9bf478b..af843f6 100644
--- a/src_plugins/eq/dune
+++ b/src_plugins/eq/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_eq.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version}
%{dep:ppx_deriving_eq.cppo.ml} -o %{targets})))
@@ -9,6 +8,6 @@
(public_name ppx_deriving.eq)
(synopsis "[@@deriving eq]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/eq/ppx_deriving_eq.cppo.ml b/src_plugins/eq/ppx_deriving_eq.cppo.ml
index 3646c01..c2b5cec 100644
--- a/src_plugins/eq/ppx_deriving_eq.cppo.ml
+++ b/src_plugins/eq/ppx_deriving_eq.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "eq"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -37,6 +35,7 @@ let pconstrrec name fields =
pconstr name [precord ~closed:Closed fields]
let core_type_of_decl ~options ~path type_decl =
+ let loc = !Ast_helper.default_loc in
parse_options options;
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
Ppx_deriving.poly_arrow_of_type_decl
@@ -64,6 +63,7 @@ and expr_of_label_decl quoter { pld_type; pld_attributes } =
expr_of_typ quoter { pld_type with ptyp_attributes = attrs }
and expr_of_typ quoter typ =
+ let loc = !Ast_helper.default_loc in
let typ = Ppx_deriving.remove_pervasives ~deriver typ in
let expr_of_typ = expr_of_typ quoter in
match attr_equal typ.ptyp_attributes with
@@ -126,19 +126,15 @@ and expr_of_typ quoter typ =
(fields |> List.map (fun field ->
let pdup f = ptuple [f "lhs"; f "rhs"] in
let variant label popt =
-#if OCAML_VERSION < (4, 06, 0)
- Pat.variant label popt
-#else
Pat.variant label.txt popt
-#endif
in
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
Exp.case (pdup (fun _ -> variant label None)) [%expr true]
- | Rtag_patt(label, false, [typ]) ->
+ | Rtag(label, false, [typ]) ->
Exp.case (pdup (fun var -> variant label (Some (pvar var))))
(app (expr_of_typ typ) [evar "lhs"; evar "rhs"])
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
Exp.case (pdup (fun var -> Pat.alias (Pat.type_ tname) (mknoloc var)))
(app (expr_of_typ typ) [evar "lhs"; evar "rhs"])
| _ ->
@@ -169,13 +165,11 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
Ppx_deriving.(fold_exprs ~unit:[%expr true] (binop_reduce [%expr (&&)])) |>
Exp.case (ptuple [pconstr name (pattn `lhs typs);
pconstr name (pattn `rhs typs)])
-#if OCAML_VERSION >= (4, 03, 0)
| Pcstr_record(labels) ->
exprl quoter labels |>
Ppx_deriving.(fold_exprs ~unit:[%expr true] (binop_reduce [%expr (&&)])) |>
Exp.case (ptuple [pconstrrec name (pattl `lhs labels);
pconstrrec name (pattl `rhs labels)])
-#endif
)) @
[Exp.case (pvar "_") [%expr false]]
in
diff --git a/src_plugins/fold/dune b/src_plugins/fold/dune
index ee6912b..965cce7 100644
--- a/src_plugins/fold/dune
+++ b/src_plugins/fold/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_fold.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{dep:ppx_deriving_fold.cppo.ml} -o %{targets})))
@@ -8,6 +7,6 @@
(public_name ppx_deriving.fold)
(synopsis "[@@deriving fold]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/fold/ppx_deriving_fold.cppo.ml b/src_plugins/fold/ppx_deriving_fold.cppo.ml
index a20c51b..c6345cc 100644
--- a/src_plugins/fold/ppx_deriving_fold.cppo.ml
+++ b/src_plugins/fold/ppx_deriving_fold.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "fold"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -26,9 +24,12 @@ let pattl labels = List.map (fun { pld_name = { txt = n } } -> n, pvar (argl n))
let pconstrrec name fields = pconstr name [precord ~closed:Closed fields]
-let reduce_acc a b = [%expr let acc = [%e a] in [%e b]]
+let reduce_acc a b =
+ let loc = !Ast_helper.default_loc in
+ [%expr let acc = [%e a] in [%e b]]
let rec expr_of_typ typ =
+ let loc = typ.ptyp_loc in
let typ = Ppx_deriving.remove_pervasives ~deriver typ in
match typ with
| _ when Ppx_deriving.free_vars_in_core_type typ = [] -> [%expr fun acc _ -> acc]
@@ -62,19 +63,15 @@ let rec expr_of_typ typ =
let cases =
fields |> List.map (fun field ->
let variant label popt =
-#if OCAML_VERSION < (4, 06, 0)
- Pat.variant label popt
-#else
Pat.variant label.txt popt
-#endif
in
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
Exp.case (variant label None) [%expr acc]
- | Rtag_patt(label, false, [typ]) ->
+ | Rtag(label, false, [typ]) ->
Exp.case (variant label (Some [%pat? x]))
[%expr [%e expr_of_typ typ] acc x]
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
Exp.case [%pat? [%p Pat.type_ tname] as x]
[%expr [%e expr_of_typ typ] acc x]
| _ ->
@@ -106,14 +103,12 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
[%expr [%e expr_of_typ typ] acc [%e evar (argn i)]]) in
Exp.case (pconstr name' (pattn typs))
Ppx_deriving.(fold_exprs ~unit:[%expr acc] reduce_acc args)
-#if OCAML_VERSION >= (4, 03, 0)
| Pcstr_record(labels) ->
let args = labels |> List.map (fun ({ pld_name = { txt = n }; _ } as pld) ->
[%expr [%e expr_of_label_decl pld]
acc [%e evar (argl n)]]) in
Exp.case (pconstrrec name' (pattl labels))
Ppx_deriving.(fold_exprs ~unit:[%expr acc] reduce_acc args)
-#endif
)
in
[%expr fun acc -> [%e Exp.function_ cases]]
@@ -139,9 +134,7 @@ let sig_of_type ~options ~path type_decl =
let loc = type_decl.ptype_loc in
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
let vars =
-#if OCAML_VERSION >= (4, 05, 0)
(List.map (fun tyvar -> tyvar.txt))
-#endif
(Ppx_deriving.free_vars_in_core_type typ)
in
let acc = Typ.var ~loc Ppx_deriving.(fresh_var vars) in
diff --git a/src_plugins/iter/dune b/src_plugins/iter/dune
index 591b2b7..f64d67f 100644
--- a/src_plugins/iter/dune
+++ b/src_plugins/iter/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_iter.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{dep:ppx_deriving_iter.cppo.ml} -o %{targets})))
@@ -8,6 +7,6 @@
(public_name ppx_deriving.iter)
(synopsis "[@@deriving iter]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/iter/ppx_deriving_iter.cppo.ml b/src_plugins/iter/ppx_deriving_iter.cppo.ml
index a6ec273..a950323 100644
--- a/src_plugins/iter/ppx_deriving_iter.cppo.ml
+++ b/src_plugins/iter/ppx_deriving_iter.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "iter"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -27,6 +25,7 @@ let pattl labels = List.map (fun { pld_name = { txt = n } } -> n, pvar (argl n))
let pconstrrec name fields = pconstr name [precord ~closed:Closed fields]
let rec expr_of_typ typ =
+ let loc = !Ast_helper.default_loc in
let typ = Ppx_deriving.remove_pervasives ~deriver typ in
match typ with
| _ when Ppx_deriving.free_vars_in_core_type typ = [] -> [%expr fun _ -> ()]
@@ -59,19 +58,15 @@ let rec expr_of_typ typ =
let cases =
fields |> List.map (fun field ->
let variant label popt =
-#if OCAML_VERSION < (4, 06, 0)
- Pat.variant label popt
-#else
Pat.variant label.txt popt
-#endif
in
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
Exp.case (variant label None) [%expr ()]
- | Rtag_patt(label, false, [typ]) ->
+ | Rtag(label, false, [typ]) ->
Exp.case (variant label (Some [%pat? x]))
[%expr [%e expr_of_typ typ] x]
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
Exp.case [%pat? [%p Pat.type_ tname] as x]
[%expr [%e expr_of_typ typ] x]
| _ ->
@@ -107,13 +102,11 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
| args -> Ppx_deriving.(fold_exprs seq_reduce) args
in
Exp.case (pconstr name' (pattn typs)) result
-#if OCAML_VERSION >= (4, 03, 0)
| Pcstr_record(labels) ->
let args = labels |> List.map (fun ({ pld_name = { txt = n }; _ } as pld) ->
[%expr [%e expr_of_label_decl pld] [%e evar (argl n)]]) in
Exp.case (pconstrrec name' (pattl labels))
(Ppx_deriving.(fold_exprs seq_reduce) args)
-#endif
) |>
Exp.function_
| Ptype_record labels, _ ->
@@ -134,6 +127,7 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(polymorphize iterator)]
let sig_of_type ~options ~path type_decl =
+ let loc = !Ast_helper.default_loc in
parse_options options;
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
let polymorphize = Ppx_deriving.poly_arrow_of_type_decl
diff --git a/src_plugins/make/dune b/src_plugins/make/dune
index 3323a49..68a88e7 100644
--- a/src_plugins/make/dune
+++ b/src_plugins/make/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_make.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{dep:ppx_deriving_make.cppo.ml} -o %{targets})))
@@ -8,6 +7,6 @@
(public_name ppx_deriving.make)
(synopsis "[@@deriving make]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/make/ppx_deriving_make.cppo.ml b/src_plugins/make/ppx_deriving_make.cppo.ml
index 5e55ab1..ada9ce5 100644
--- a/src_plugins/make/ppx_deriving_make.cppo.ml
+++ b/src_plugins/make/ppx_deriving_make.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "make"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -94,12 +92,7 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(Ppx_deriving.sanitize ~quoter creator)]
let wrap_predef_option typ =
-#if OCAML_VERSION < (4, 03, 0)
- let predef_option = mknoloc (Ldot (Lident "*predef*", "option")) in
- Typ.constr predef_option [typ]
-#else
typ
-#endif
let sig_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
parse_options options;
diff --git a/src_plugins/map/dune b/src_plugins/map/dune
index 08ca955..44fb56b 100644
--- a/src_plugins/map/dune
+++ b/src_plugins/map/dune
@@ -8,6 +8,6 @@
(public_name ppx_deriving.map)
(synopsis "[@@deriving map]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/map/ppx_deriving_map.cppo.ml b/src_plugins/map/ppx_deriving_map.cppo.ml
index c35f5c5..d778c21 100644
--- a/src_plugins/map/ppx_deriving_map.cppo.ml
+++ b/src_plugins/map/ppx_deriving_map.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "map"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -28,6 +26,7 @@ let pconstrrec name fields = pconstr name [precord ~closed:Closed fields]
let constrrec name fields = constr name [ record fields]
let rec expr_of_typ ?decl typ =
+ let loc = typ.ptyp_loc in
let typ = Ppx_deriving.remove_pervasives ~deriver typ in
match typ with
| _ when Ppx_deriving.free_vars_in_core_type typ = [] -> [%expr fun x -> x]
@@ -58,26 +57,18 @@ let rec expr_of_typ ?decl typ =
let cases =
fields |> List.map (fun field ->
let pat_variant label popt =
-#if OCAML_VERSION < (4, 06, 0)
- Pat.variant label popt
-#else
Pat.variant label.txt popt
-#endif
in
let exp_variant label popt =
-#if OCAML_VERSION < (4, 06, 0)
- Exp.variant label popt
-#else
Exp.variant label.txt popt
-#endif
in
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
Exp.case (pat_variant label None) (exp_variant label None)
- | Rtag_patt(label, false, [typ]) ->
+ | Rtag(label, false, [typ]) ->
Exp.case (pat_variant label (Some [%pat? x]))
(exp_variant label (Some [%expr [%e expr_of_typ ?decl typ] x]))
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, _) } as typ) -> begin
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, _) } as typ) -> begin
match decl with
| None ->
raise_errorf "inheritance of polymorphic variants not supported"
@@ -114,14 +105,12 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
let args = List.mapi (fun i typ -> app (expr_of_typ ~decl:type_decl typ) [evar (argn i)]) typs in
Exp.case (pconstr name' (pattn typs))
(constr name' args)
-#if OCAML_VERSION >= (4, 03, 0)
| Pcstr_record(labels) ->
let args = labels |> List.map (fun ({ pld_name = { txt = n }; _ } as pld) ->
n, [%expr [%e expr_of_label_decl ~decl:type_decl pld]
[%e evar (argl n)]]) in
Exp.case (pconstrrec name' (pattl labels))
(constrrec name' args)
-#endif
) |>
Exp.function_
| Ptype_record labels, _ ->
@@ -143,6 +132,7 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
(polymorphize mapper)]
let sig_of_type ~options ~path type_decl =
+ let loc = type_decl.ptype_loc in
parse_options options;
let typ_arg, var_arg, bound = Ppx_deriving.instantiate [] type_decl in
let typ_ret, var_ret, _ = Ppx_deriving.instantiate bound type_decl in
diff --git a/src_plugins/ord/dune b/src_plugins/ord/dune
index 0139269..4641abe 100644
--- a/src_plugins/ord/dune
+++ b/src_plugins/ord/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_ord.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version}
%{dep:ppx_deriving_ord.cppo.ml} -o %{targets})))
@@ -9,6 +8,6 @@
(public_name ppx_deriving.ord)
(synopsis "[@@deriving ord]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/ord/ppx_deriving_ord.cppo.ml b/src_plugins/ord/ppx_deriving_ord.cppo.ml
index 89998ee..8e1643a 100644
--- a/src_plugins/ord/ppx_deriving_ord.cppo.ml
+++ b/src_plugins/ord/ppx_deriving_ord.cppo.ml
@@ -1,11 +1,10 @@
-#include "../compat_macros.cppo"
-
+open Ppxlib
open Longident
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "ord"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -28,14 +27,17 @@ let argl kind =
Printf.sprintf (match kind with `lhs -> "lhs%s" | `rhs -> "rhs%s")
let compare_reduce acc expr =
+ let loc = !Ast_helper.default_loc in
[%expr match [%e expr] with 0 -> [%e acc] | x -> x]
let reduce_compare l =
+ let loc = !Ast_helper.default_loc in
match List.rev l with
| [] -> [%expr 0]
| x :: xs -> List.fold_left compare_reduce x xs
let wildcard_case int_cases =
+ let loc = !Ast_helper.default_loc in
Exp.case [%pat? _] [%expr
let to_int = [%e Exp.function_ int_cases] in
Ppx_deriving_runtime.compare (to_int lhs) (to_int rhs)]
@@ -63,6 +65,7 @@ and expr_of_label_decl quoter { pld_type; pld_attributes } =
expr_of_typ quoter { pld_type with ptyp_attributes = attrs }
and expr_of_typ quoter typ =
+ let loc = typ.ptyp_loc in
let expr_of_typ = expr_of_typ quoter in
match attr_compare typ.ptyp_attributes with
| Some fn -> Ppx_deriving.quote quoter fn
@@ -133,22 +136,18 @@ and expr_of_typ quoter typ =
[%e exprn quoter typs |> reduce_compare]]
| { ptyp_desc = Ptyp_variant (fields, _, _); ptyp_loc } ->
let variant label popt =
-#if OCAML_VERSION < (4, 06, 0)
- Pat.variant label popt
-#else
Pat.variant label.txt popt
-#endif
in
let cases =
fields |> List.map (fun field ->
let pdup f = ptuple [f "lhs"; f "rhs"] in
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
Exp.case (pdup (fun _ -> variant label None)) [%expr 0]
- | Rtag_patt(label, false, [typ]) ->
+ | Rtag(label, false, [typ]) ->
Exp.case (pdup (fun var -> variant label (Some (pvar var))))
(app (expr_of_typ typ) [evar "lhs"; evar "rhs"])
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
Exp.case (pdup (fun var -> Pat.alias (Pat.type_ tname) (mknoloc var)))
(app (expr_of_typ typ) [evar "lhs"; evar "rhs"])
| _ ->
@@ -157,12 +156,12 @@ and expr_of_typ quoter typ =
in
let int_cases =
fields |> List.mapi (fun i field ->
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
Exp.case (variant label None) (int i)
- | Rtag_patt(label, false, [typ]) ->
+ | Rtag(label, false, [typ]) ->
Exp.case (variant label (Some [%pat? _])) (int i)
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, []) }) ->
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, []) }) ->
Exp.case (Pat.type_ tname) (int i)
| _ -> assert false)
in
@@ -176,6 +175,7 @@ and expr_of_typ quoter typ =
let core_type_of_decl ~options ~path type_decl =
parse_options options;
+ let loc = type_decl.ptype_loc in
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
let polymorphize = Ppx_deriving.poly_arrow_of_type_decl
(fun var -> [%type: [%t var] -> [%t var] -> Ppx_deriving_runtime.int]) type_decl in
@@ -204,12 +204,10 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
exprn quoter typs |> reduce_compare |>
Exp.case (ptuple [pconstr name (pattn `lhs typs);
pconstr name (pattn `rhs typs)])
-#if OCAML_VERSION >= (4, 03, 0)
| Pcstr_record(labels) ->
exprl quoter labels |> reduce_compare |>
Exp.case (ptuple [pconstrrec name (pattl `lhs labels);
pconstrrec name (pattl `rhs labels)])
-#endif
)
in
[%expr fun lhs rhs ->
diff --git a/src_plugins/show/dune b/src_plugins/show/dune
index 3bebba7..3377e13 100644
--- a/src_plugins/show/dune
+++ b/src_plugins/show/dune
@@ -1,5 +1,4 @@
(rule
- (deps ../compat_macros.cppo)
(targets ppx_deriving_show.ml)
(action (run %{bin:cppo} -V OCAML:%{ocaml_version}
%{dep:ppx_deriving_show.cppo.ml} -o %{targets})))
@@ -9,6 +8,6 @@
(public_name ppx_deriving.show)
(synopsis "[@@deriving show]")
(preprocess
- (action (run ppxfind -legacy ppx_tools.metaquot --as-pp %{input-file})))
- (libraries compiler-libs.common ppx_tools ppx_deriving.api)
+ (pps ppxlib.metaquot))
+ (libraries compiler-libs.common ppxlib ppx_deriving.api)
(kind ppx_deriver))
diff --git a/src_plugins/show/ppx_deriving_show.cppo.ml b/src_plugins/show/ppx_deriving_show.cppo.ml
index 9e76224..e2b95bc 100644
--- a/src_plugins/show/ppx_deriving_show.cppo.ml
+++ b/src_plugins/show/ppx_deriving_show.cppo.ml
@@ -1,11 +1,9 @@
-#include "../compat_macros.cppo"
-
-open Longident
+open Ppxlib
open Location
open Asttypes
open Parsetree
open Ast_helper
-open Ast_convenience
+open Ppx_deriving.Ast_convenience
let deriver = "show"
let raise_errorf = Ppx_deriving.raise_errorf
@@ -51,10 +49,12 @@ let pattl labels = List.map (fun { pld_name = { txt = n } } -> n, pvar (argl n))
let pconstrrec name fields = pconstr name [precord ~closed:Closed fields]
let wrap_printer quoter printer =
+ let loc = !Ast_helper.default_loc in
Ppx_deriving.quote quoter
[%expr (let fprintf = Ppx_deriving_runtime.Format.fprintf in [%e printer]) [@ocaml.warning "-26"]]
let pp_type_of_decl ~options ~path type_decl =
+ let loc = type_decl.ptype_loc in
let _ = parse_options options in
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
Ppx_deriving.poly_arrow_of_type_decl
@@ -63,6 +63,7 @@ let pp_type_of_decl ~options ~path type_decl =
[%type: Ppx_deriving_runtime.Format.formatter -> [%t typ] -> Ppx_deriving_runtime.unit]
let show_type_of_decl ~options ~path type_decl =
+ let loc = type_decl.ptype_loc in
let _ = parse_options options in
let typ = Ppx_deriving.core_type_of_type_decl type_decl in
Ppx_deriving.poly_arrow_of_type_decl
@@ -78,6 +79,7 @@ let sig_of_type ~options ~path type_decl =
(show_type_of_decl ~options ~path type_decl))]
let rec expr_of_typ quoter typ =
+ let loc = typ.ptyp_loc in
let expr_of_typ = expr_of_typ quoter in
match attr_printer typ.ptyp_attributes with
| Some printer -> [%expr [%e wrap_printer quoter printer] fmt]
@@ -172,22 +174,18 @@ let rec expr_of_typ quoter typ =
| { ptyp_desc = Ptyp_variant (fields, _, _); ptyp_loc } ->
let cases =
fields |> List.map (fun field ->
- match field with
- | Rtag_patt(label, true (*empty*), []) ->
-#if OCAML_VERSION >= (4, 06, 0)
+ match field.prf_desc with
+ | Rtag(label, true (*empty*), []) ->
let label = label.txt in
-#endif
Exp.case (Pat.variant label None)
[%expr Ppx_deriving_runtime.Format.pp_print_string fmt [%e str ("`" ^ label)]]
- | Rtag_patt(label, false, [typ]) ->
-#if OCAML_VERSION >= (4, 06, 0)
+ | Rtag(label, false, [typ]) ->
let label = label.txt in
-#endif
Exp.case (Pat.variant label (Some [%pat? x]))
[%expr Ppx_deriving_runtime.Format.fprintf fmt [%e str ("`" ^ label ^ " (@[<hov>")];
[%e expr_of_typ typ] x;
Ppx_deriving_runtime.Format.fprintf fmt "@])"]
- | Rinherit_patt({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
+ | Rinherit({ ptyp_desc = Ptyp_constr (tname, _) } as typ) ->
Exp.case [%pat? [%p Pat.type_ tname] as x]
[%expr [%e expr_of_typ typ] x]
| _ ->
@@ -237,12 +235,10 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
Exp.case (pconstr name' pattern_vars)
[%expr [%e wrap_printer quoter printer] fmt
[%e tuple expr_vars]]
-#if OCAML_VERSION >= (4, 03, 0)
| Some printer, Pcstr_record(labels) ->
let args = labels |> List.map (fun { pld_name = { txt = n } } -> evar (argl n)) in
Exp.case (pconstrrec name' (pattl labels))
(app (wrap_printer quoter printer) ([%expr fmt] :: args))
-#endif
| None, Pcstr_tuple(typs) ->
let args =
List.mapi (fun i typ -> app (expr_of_typ quoter typ) [evar (argn i)]) typs in
@@ -262,7 +258,6 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
Ppx_deriving_runtime.Format.fprintf fmt "@,))@]"]
in
Exp.case (pconstr name' (pattn typs)) printer
-#if OCAML_VERSION >= (4, 03, 0)
| None, Pcstr_record(labels) ->
let args =
labels |> List.map (fun ({ pld_name = { txt = n }; _ } as pld) ->
@@ -281,7 +276,6 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
Ppx_deriving_runtime.Format.fprintf fmt "@]}"]
in
Exp.case (pconstrrec name' (pattl labels)) printer
-#endif
)
in
[%expr fun fmt -> [%e Exp.function_ cases]]
@@ -325,6 +319,7 @@ let str_of_type ~options ~path ({ ptype_loc = loc } as type_decl) =
Vb.mk ~attrs:[no_warn_32] (Pat.constraint_ show_var show_type) (polymorphize stringprinter);]
let () =
+ let loc = !Ast_helper.default_loc in
Ppx_deriving.(register (create deriver
~core_type: (Ppx_deriving.with_quoter (fun quoter typ ->
[%expr fun x -> Ppx_deriving_runtime.Format.asprintf "%a" (fun fmt -> [%e expr_of_typ quoter typ]) x]))