package ppx_import

  1. Overview
  2. Docs

Source file ppx_types_migrate.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module At = Asttypes
module Pt = Parsetree
module Ot = Outcometree

open Migrate_parsetree
module Ab = Ast_407.Asttypes
module Pb = Ast_407.Parsetree
module Ob = Ast_407.Outcometree

module IMigrate = Convert(Versions.OCaml_current)(Versions.OCaml_407)

(* copy_mutable_flag / private_flag / arg_label are not exported by
   OMP so not worth the pain of the hack *)
let copy_mutable_flag (l : At.mutable_flag) : Ab.mutable_flag =
  match l with
  | At.Immutable -> Ab.Immutable
  | At.Mutable -> Ab.Mutable

let copy_private_flag (l : At.private_flag) : Ab.private_flag =
  match l with
  | At.Private -> Ab.Private
  | At.Public -> Ab.Public

let copy_arg_label (l : At.arg_label) : Ab.arg_label =
  match l with
  | At.Nolabel -> Ab.Nolabel
  | At.Labelled l -> Ab.Labelled l
  | At.Optional x -> Ab.Optional x

(* Here we want to do a hack due to the large type *)
let copy_attributes (attrs : Pt.attributes) : Pb.attributes =
  (* Hack *)
  let td = Ast_helper.Typ.any ~attrs () in
  let tb = IMigrate.copy_core_type td in
  tb.ptyp_attributes