2012-05-30 08:25:49 -07:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Thomas Gazagnaire (OCamlPro), Fabrice Le Fessant (INRIA Saclay) *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2007 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
open Asttypes
|
|
|
|
open Typedtree
|
|
|
|
open Parsetree
|
2013-03-08 06:59:45 -08:00
|
|
|
open Ast_helper
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
(*
|
|
|
|
Some notes:
|
|
|
|
|
|
|
|
* For Pexp_function, we cannot go back to the exact original version
|
|
|
|
when there is a default argument, because the default argument is
|
|
|
|
translated in the typer. The code, if printed, will not be parsable because
|
|
|
|
new generated identifiers are not correct.
|
|
|
|
|
|
|
|
* For Pexp_apply, it is unclear whether arguments are reordered, especially
|
|
|
|
when there are optional arguments.
|
|
|
|
|
|
|
|
* TODO: check Ttype_variant -> Ptype_variant (stub None)
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
2013-03-25 07:56:56 -07:00
|
|
|
let option f = function None -> None | Some e -> Some (f e)
|
|
|
|
|
2012-05-30 08:25:49 -07:00
|
|
|
let rec lident_of_path path =
|
|
|
|
match path with
|
|
|
|
Path.Pident id -> Longident.Lident (Ident.name id)
|
|
|
|
| Path.Pdot (p, s, _) -> Longident.Ldot (lident_of_path p, s)
|
|
|
|
| Path.Papply (p1, p2) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
Longident.Lapply (lident_of_path p1, lident_of_path p2)
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
let rec untype_structure str =
|
|
|
|
List.map untype_structure_item str.str_items
|
|
|
|
|
|
|
|
and untype_structure_item item =
|
|
|
|
let desc =
|
|
|
|
match item.str_desc with
|
2013-04-11 07:07:32 -07:00
|
|
|
Tstr_eval (exp, attrs) -> Pstr_eval (untype_expression exp, attrs)
|
2013-06-03 08:14:19 -07:00
|
|
|
| Tstr_value (rec_flag, list) ->
|
|
|
|
Pstr_value (rec_flag, List.map untype_binding list)
|
2013-03-25 11:04:40 -07:00
|
|
|
| Tstr_primitive vd ->
|
|
|
|
Pstr_primitive (untype_value_description vd)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tstr_type list ->
|
2013-03-25 11:20:11 -07:00
|
|
|
Pstr_type (List.map untype_type_declaration list)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Tstr_typext tyext ->
|
|
|
|
Pstr_typext (untype_type_extension tyext)
|
|
|
|
| Tstr_exception ext ->
|
|
|
|
Pstr_exception (untype_extension_constructor ext)
|
2013-03-26 01:09:26 -07:00
|
|
|
| Tstr_module mb ->
|
|
|
|
Pstr_module (untype_module_binding mb)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tstr_recmodule list ->
|
2013-03-26 01:09:26 -07:00
|
|
|
Pstr_recmodule (List.map untype_module_binding list)
|
2013-04-18 06:14:53 -07:00
|
|
|
| Tstr_modtype mtd ->
|
2014-04-12 03:17:02 -07:00
|
|
|
Pstr_modtype {pmtd_name=mtd.mtd_name;
|
|
|
|
pmtd_type=option untype_module_type mtd.mtd_type;
|
2014-01-30 04:18:34 -08:00
|
|
|
pmtd_loc=mtd.mtd_loc;pmtd_attributes=mtd.mtd_attributes;}
|
2014-04-15 04:26:00 -07:00
|
|
|
| Tstr_open od ->
|
|
|
|
Pstr_open {popen_lid = od.open_txt; popen_override = od.open_override;
|
2014-04-22 08:28:20 -07:00
|
|
|
popen_attributes = od.open_attributes;
|
|
|
|
popen_loc = od.open_loc;
|
|
|
|
}
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tstr_class list ->
|
2014-05-04 16:08:45 -07:00
|
|
|
Pstr_class
|
|
|
|
(List.map
|
|
|
|
(fun (ci, _, _) -> untype_class_declaration ci)
|
|
|
|
list)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tstr_class_type list ->
|
2014-05-04 16:08:45 -07:00
|
|
|
Pstr_class_type
|
|
|
|
(List.map
|
|
|
|
(fun (_id, _name, ct) -> untype_class_type_declaration ct)
|
|
|
|
list)
|
2014-04-15 04:26:00 -07:00
|
|
|
| Tstr_include incl ->
|
|
|
|
Pstr_include {pincl_mod = untype_module_expr incl.incl_mod;
|
2014-04-22 08:28:20 -07:00
|
|
|
pincl_attributes = incl.incl_attributes;
|
|
|
|
pincl_loc = incl.incl_loc;
|
|
|
|
}
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_attribute x ->
|
|
|
|
Pstr_attribute x
|
2012-05-30 08:25:49 -07:00
|
|
|
in
|
|
|
|
{ pstr_desc = desc; pstr_loc = item.str_loc; }
|
|
|
|
|
2013-03-25 11:04:40 -07:00
|
|
|
and untype_value_description v =
|
2012-05-30 08:25:49 -07:00
|
|
|
{
|
2013-03-25 11:04:40 -07:00
|
|
|
pval_name = v.val_name;
|
2013-03-04 08:20:49 -08:00
|
|
|
pval_prim = v.val_prim;
|
|
|
|
pval_type = untype_core_type v.val_desc;
|
|
|
|
pval_loc = v.val_loc;
|
2013-03-25 07:16:07 -07:00
|
|
|
pval_attributes = v.val_attributes;
|
2013-03-04 08:20:49 -08:00
|
|
|
}
|
2012-05-30 08:25:49 -07:00
|
|
|
|
2013-03-26 01:09:26 -07:00
|
|
|
and untype_module_binding mb =
|
|
|
|
{
|
|
|
|
pmb_name = mb.mb_name;
|
|
|
|
pmb_expr = untype_module_expr mb.mb_expr;
|
|
|
|
pmb_attributes = mb.mb_attributes;
|
2014-01-30 04:18:34 -08:00
|
|
|
pmb_loc = mb.mb_loc;
|
2013-03-26 01:09:26 -07:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:20:11 -07:00
|
|
|
and untype_type_declaration decl =
|
2012-05-30 08:25:49 -07:00
|
|
|
{
|
2013-03-25 11:20:11 -07:00
|
|
|
ptype_name = decl.typ_name;
|
2014-05-04 16:08:45 -07:00
|
|
|
ptype_params = List.map untype_type_parameter decl.typ_params;
|
2012-05-30 08:25:49 -07:00
|
|
|
ptype_cstrs = List.map (fun (ct1, ct2, loc) ->
|
|
|
|
(untype_core_type ct1,
|
|
|
|
untype_core_type ct2, loc)
|
|
|
|
) decl.typ_cstrs;
|
|
|
|
ptype_kind = (match decl.typ_kind with
|
|
|
|
Ttype_abstract -> Ptype_abstract
|
|
|
|
| Ttype_variant list ->
|
2013-03-25 11:42:45 -07:00
|
|
|
Ptype_variant (List.map untype_constructor_declaration list)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Ttype_record list ->
|
2014-05-04 16:08:45 -07:00
|
|
|
Ptype_record (List.map untype_label_declaration list)
|
|
|
|
| Ttype_open -> Ptype_open
|
2012-05-30 08:25:49 -07:00
|
|
|
);
|
|
|
|
ptype_private = decl.typ_private;
|
2013-03-25 07:56:56 -07:00
|
|
|
ptype_manifest = option untype_core_type decl.typ_manifest;
|
2013-03-25 07:16:07 -07:00
|
|
|
ptype_attributes = decl.typ_attributes;
|
2012-05-30 08:25:49 -07:00
|
|
|
ptype_loc = decl.typ_loc;
|
|
|
|
}
|
|
|
|
|
2014-05-04 16:08:45 -07:00
|
|
|
and untype_type_parameter (ct, v) = (untype_core_type ct, v)
|
|
|
|
|
2013-09-04 08:12:37 -07:00
|
|
|
and untype_constructor_declaration cd =
|
2013-03-04 08:20:49 -08:00
|
|
|
{
|
2013-03-25 11:42:45 -07:00
|
|
|
pcd_name = cd.cd_name;
|
|
|
|
pcd_args = List.map untype_core_type cd.cd_args;
|
|
|
|
pcd_res = option untype_core_type cd.cd_res;
|
|
|
|
pcd_loc = cd.cd_loc;
|
|
|
|
pcd_attributes = cd.cd_attributes;
|
2013-03-04 08:20:49 -08:00
|
|
|
}
|
2012-05-30 08:25:49 -07:00
|
|
|
|
2014-05-04 16:08:45 -07:00
|
|
|
and untype_label_declaration ld =
|
2014-04-15 04:26:00 -07:00
|
|
|
{
|
2014-05-04 16:08:45 -07:00
|
|
|
pld_name=ld.ld_name;
|
|
|
|
pld_mutable=ld.ld_mutable;
|
|
|
|
pld_type=untype_core_type ld.ld_type;
|
|
|
|
pld_loc=ld.ld_loc;
|
|
|
|
pld_attributes=ld.ld_attributes
|
|
|
|
}
|
|
|
|
|
|
|
|
and untype_type_extension tyext =
|
|
|
|
{
|
|
|
|
ptyext_path = tyext.tyext_txt;
|
|
|
|
ptyext_params = List.map untype_type_parameter tyext.tyext_params;
|
|
|
|
ptyext_constructors =
|
|
|
|
List.map untype_extension_constructor tyext.tyext_constructors;
|
|
|
|
ptyext_private = tyext.tyext_private;
|
|
|
|
ptyext_attributes = tyext.tyext_attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
and untype_extension_constructor ext =
|
|
|
|
{
|
|
|
|
pext_name = ext.ext_name;
|
|
|
|
pext_kind = (match ext.ext_kind with
|
|
|
|
Text_decl (args, ret) ->
|
|
|
|
Pext_decl (List.map untype_core_type args,
|
|
|
|
option untype_core_type ret)
|
2014-05-12 03:41:21 -07:00
|
|
|
| Text_rebind (_p, lid) -> Pext_rebind lid
|
2014-05-04 16:08:45 -07:00
|
|
|
);
|
|
|
|
pext_loc = ext.ext_loc;
|
|
|
|
pext_attributes = ext.ext_attributes;
|
2014-04-15 04:26:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:25:49 -07:00
|
|
|
and untype_pattern pat =
|
|
|
|
let desc =
|
|
|
|
match pat with
|
2013-09-04 08:12:37 -07:00
|
|
|
{ pat_extra=[Tpat_unpack, _, _attrs]; pat_desc = Tpat_var (_,name); _ } ->
|
|
|
|
Ppat_unpack name
|
2013-03-25 07:16:07 -07:00
|
|
|
| { pat_extra=[Tpat_type (_path, lid), _, _attrs]; _ } -> Ppat_type lid
|
|
|
|
| { pat_extra= (Tpat_constraint ct, _, _attrs) :: rem; _ } ->
|
2013-09-04 08:12:37 -07:00
|
|
|
Ppat_constraint (untype_pattern { pat with pat_extra=rem },
|
|
|
|
untype_core_type ct)
|
2012-05-30 08:25:49 -07:00
|
|
|
| _ ->
|
|
|
|
match pat.pat_desc with
|
|
|
|
Tpat_any -> Ppat_any
|
|
|
|
| Tpat_var (id, name) ->
|
|
|
|
begin
|
|
|
|
match (Ident.name id).[0] with
|
|
|
|
'A'..'Z' ->
|
|
|
|
Ppat_unpack name
|
|
|
|
| _ ->
|
|
|
|
Ppat_var name
|
|
|
|
end
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tpat_alias (pat, _id, name) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Ppat_alias (untype_pattern pat, name)
|
2013-05-23 08:12:04 -07:00
|
|
|
| Tpat_constant cst -> Ppat_constant cst
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tpat_tuple list ->
|
|
|
|
Ppat_tuple (List.map untype_pattern list)
|
2013-04-17 02:46:52 -07:00
|
|
|
| Tpat_construct (lid, _, args) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Ppat_construct (lid,
|
|
|
|
(match args with
|
|
|
|
[] -> None
|
2013-06-17 01:53:03 -07:00
|
|
|
| [arg] -> Some (untype_pattern arg)
|
2013-03-08 06:59:45 -08:00
|
|
|
| args ->
|
|
|
|
Some
|
|
|
|
(Pat.tuple ~loc:pat.pat_loc
|
|
|
|
(List.map untype_pattern args)
|
|
|
|
)
|
2013-04-17 02:46:52 -07:00
|
|
|
))
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tpat_variant (label, pato, _) ->
|
2013-03-25 07:56:56 -07:00
|
|
|
Ppat_variant (label, option untype_pattern pato)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tpat_record (list, closed) ->
|
2012-10-24 05:03:00 -07:00
|
|
|
Ppat_record (List.map (fun (lid, _, pat) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
lid, untype_pattern pat) list, closed)
|
|
|
|
| Tpat_array list -> Ppat_array (List.map untype_pattern list)
|
|
|
|
| Tpat_or (p1, p2, _) -> Ppat_or (untype_pattern p1, untype_pattern p2)
|
|
|
|
| Tpat_lazy p -> Ppat_lazy (untype_pattern p)
|
|
|
|
in
|
2014-04-12 03:17:02 -07:00
|
|
|
Pat.mk ~loc:pat.pat_loc ~attrs:pat.pat_attributes desc
|
|
|
|
(* todo: fix attributes on extras *)
|
2012-05-30 08:25:49 -07:00
|
|
|
|
2013-03-25 07:16:07 -07:00
|
|
|
and untype_extra (extra, loc, attrs) sexp =
|
2012-07-10 01:25:58 -07:00
|
|
|
let desc =
|
|
|
|
match extra with
|
2013-04-17 05:23:44 -07:00
|
|
|
Texp_coerce (cty1, cty2) ->
|
|
|
|
Pexp_coerce (sexp,
|
|
|
|
option untype_core_type cty1,
|
|
|
|
untype_core_type cty2)
|
|
|
|
| Texp_constraint cty ->
|
|
|
|
Pexp_constraint (sexp, untype_core_type cty)
|
2013-05-16 06:34:53 -07:00
|
|
|
| Texp_open (ovf, _path, lid, _) -> Pexp_open (ovf, lid, sexp)
|
2012-07-10 01:25:58 -07:00
|
|
|
| Texp_poly cto -> Pexp_poly (sexp, option untype_core_type cto)
|
|
|
|
| Texp_newtype s -> Pexp_newtype (s, sexp)
|
|
|
|
in
|
2013-03-25 07:16:07 -07:00
|
|
|
Exp.mk ~loc ~attrs desc
|
2012-07-30 11:04:46 -07:00
|
|
|
|
2013-04-15 09:23:22 -07:00
|
|
|
and untype_cases l = List.map untype_case l
|
|
|
|
|
|
|
|
and untype_case {c_lhs; c_guard; c_rhs} =
|
|
|
|
{
|
|
|
|
pc_lhs = untype_pattern c_lhs;
|
|
|
|
pc_guard = option untype_expression c_guard;
|
|
|
|
pc_rhs = untype_expression c_rhs;
|
|
|
|
}
|
|
|
|
|
2014-04-22 08:28:20 -07:00
|
|
|
and untype_binding {vb_pat; vb_expr; vb_attributes; vb_loc} =
|
2013-06-03 08:14:19 -07:00
|
|
|
{
|
|
|
|
pvb_pat = untype_pattern vb_pat;
|
|
|
|
pvb_expr = untype_expression vb_expr;
|
|
|
|
pvb_attributes = vb_attributes;
|
2014-04-22 08:28:20 -07:00
|
|
|
pvb_loc = vb_loc;
|
2013-06-03 08:14:19 -07:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:25:49 -07:00
|
|
|
and untype_expression exp =
|
|
|
|
let desc =
|
|
|
|
match exp.exp_desc with
|
2012-12-19 01:25:21 -08:00
|
|
|
Texp_ident (_path, lid, _) -> Pexp_ident (lid)
|
2013-05-23 08:12:04 -07:00
|
|
|
| Texp_constant cst -> Pexp_constant cst
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_let (rec_flag, list, exp) ->
|
|
|
|
Pexp_let (rec_flag,
|
2013-06-03 08:14:19 -07:00
|
|
|
List.map untype_binding list,
|
2012-05-30 08:25:49 -07:00
|
|
|
untype_expression exp)
|
2013-04-17 04:43:29 -07:00
|
|
|
| Texp_function (label, [{c_lhs=p; c_guard=None; c_rhs=e}], _) ->
|
|
|
|
Pexp_fun (label, None, untype_pattern p, untype_expression e)
|
|
|
|
| Texp_function ("", cases, _) ->
|
|
|
|
Pexp_function (untype_cases cases)
|
|
|
|
| Texp_function _ ->
|
|
|
|
assert false
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_apply (exp, list) ->
|
|
|
|
Pexp_apply (untype_expression exp,
|
|
|
|
List.fold_right (fun (label, expo, _) list ->
|
|
|
|
match expo with
|
|
|
|
None -> list
|
|
|
|
| Some exp -> (label, untype_expression exp) :: list
|
|
|
|
) list [])
|
2014-05-05 04:49:37 -07:00
|
|
|
| Texp_match (exp, cases, exn_cases, _) ->
|
|
|
|
let merged_cases = untype_cases cases
|
|
|
|
@ List.map
|
|
|
|
(fun c ->
|
|
|
|
let uc = untype_case c in
|
|
|
|
let pat = { uc.pc_lhs
|
|
|
|
with ppat_desc = Ppat_exception uc.pc_lhs }
|
|
|
|
in
|
|
|
|
{ uc with pc_lhs = pat })
|
|
|
|
exn_cases
|
|
|
|
in
|
|
|
|
Pexp_match (untype_expression exp, merged_cases)
|
2013-04-15 09:23:22 -07:00
|
|
|
| Texp_try (exp, cases) ->
|
|
|
|
Pexp_try (untype_expression exp, untype_cases cases)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_tuple list ->
|
|
|
|
Pexp_tuple (List.map untype_expression list)
|
2013-04-17 02:46:52 -07:00
|
|
|
| Texp_construct (lid, _, args) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pexp_construct (lid,
|
|
|
|
(match args with
|
|
|
|
[] -> None
|
2012-09-27 09:50:13 -07:00
|
|
|
| [ arg ] -> Some (untype_expression arg)
|
2013-03-08 06:59:45 -08:00
|
|
|
| args ->
|
|
|
|
Some
|
|
|
|
(Exp.tuple ~loc:exp.exp_loc (List.map untype_expression args))
|
2013-04-17 02:46:52 -07:00
|
|
|
))
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_variant (label, expo) ->
|
2013-03-25 07:56:56 -07:00
|
|
|
Pexp_variant (label, option untype_expression expo)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_record (list, expo) ->
|
2012-10-24 05:03:00 -07:00
|
|
|
Pexp_record (List.map (fun (lid, _, exp) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
lid, untype_expression exp
|
|
|
|
) list,
|
2013-03-25 07:56:56 -07:00
|
|
|
option untype_expression expo)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Texp_field (exp, lid, _label) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pexp_field (untype_expression exp, lid)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Texp_setfield (exp1, lid, _label, exp2) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pexp_setfield (untype_expression exp1, lid,
|
|
|
|
untype_expression exp2)
|
|
|
|
| Texp_array list ->
|
|
|
|
Pexp_array (List.map untype_expression list)
|
|
|
|
| Texp_ifthenelse (exp1, exp2, expo) ->
|
|
|
|
Pexp_ifthenelse (untype_expression exp1,
|
|
|
|
untype_expression exp2,
|
2013-03-25 07:56:56 -07:00
|
|
|
option untype_expression expo)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_sequence (exp1, exp2) ->
|
|
|
|
Pexp_sequence (untype_expression exp1, untype_expression exp2)
|
|
|
|
| Texp_while (exp1, exp2) ->
|
|
|
|
Pexp_while (untype_expression exp1, untype_expression exp2)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Texp_for (_id, name, exp1, exp2, dir, exp3) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pexp_for (name,
|
|
|
|
untype_expression exp1, untype_expression exp2,
|
|
|
|
dir, untype_expression exp3)
|
|
|
|
| Texp_send (exp, meth, _) ->
|
|
|
|
Pexp_send (untype_expression exp, match meth with
|
|
|
|
Tmeth_name name -> name
|
|
|
|
| Tmeth_val id -> Ident.name id)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Texp_new (_path, lid, _) -> Pexp_new (lid)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Texp_instvar (_, path, name) ->
|
|
|
|
Pexp_ident ({name with txt = lident_of_path path})
|
2012-12-19 01:25:21 -08:00
|
|
|
| Texp_setinstvar (_, _path, lid, exp) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pexp_setinstvar (lid, untype_expression exp)
|
|
|
|
| Texp_override (_, list) ->
|
2012-12-19 01:25:21 -08:00
|
|
|
Pexp_override (List.map (fun (_path, lid, exp) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
lid, untype_expression exp
|
|
|
|
) list)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Texp_letmodule (_id, name, mexpr, exp) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pexp_letmodule (name, untype_module_expr mexpr,
|
|
|
|
untype_expression exp)
|
|
|
|
| Texp_assert exp -> Pexp_assert (untype_expression exp)
|
|
|
|
| Texp_lazy exp -> Pexp_lazy (untype_expression exp)
|
|
|
|
| Texp_object (cl, _) ->
|
|
|
|
Pexp_object (untype_class_structure cl)
|
|
|
|
| Texp_pack (mexpr) ->
|
|
|
|
Pexp_pack (untype_module_expr mexpr)
|
|
|
|
in
|
2012-07-10 01:25:58 -07:00
|
|
|
List.fold_right untype_extra exp.exp_extra
|
2013-03-25 07:16:07 -07:00
|
|
|
(Exp.mk ~loc:exp.exp_loc ~attrs:exp.exp_attributes desc)
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
and untype_package_type pack =
|
|
|
|
(pack.pack_txt,
|
|
|
|
List.map (fun (s, ct) ->
|
|
|
|
(s, untype_core_type ct)) pack.pack_fields)
|
|
|
|
|
|
|
|
and untype_signature sg =
|
|
|
|
List.map untype_signature_item sg.sig_items
|
|
|
|
|
|
|
|
and untype_signature_item item =
|
|
|
|
let desc =
|
|
|
|
match item.sig_desc with
|
2013-03-25 11:04:40 -07:00
|
|
|
Tsig_value v ->
|
|
|
|
Psig_value (untype_value_description v)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tsig_type list ->
|
2013-03-25 11:20:11 -07:00
|
|
|
Psig_type (List.map untype_type_declaration list)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Tsig_typext tyext ->
|
|
|
|
Psig_typext (untype_type_extension tyext)
|
|
|
|
| Tsig_exception ext ->
|
|
|
|
Psig_exception (untype_extension_constructor ext)
|
2013-03-25 10:47:28 -07:00
|
|
|
| Tsig_module md ->
|
2014-04-12 03:17:02 -07:00
|
|
|
Psig_module {pmd_name = md.md_name;
|
|
|
|
pmd_type = untype_module_type md.md_type;
|
2014-01-30 04:18:34 -08:00
|
|
|
pmd_attributes = md.md_attributes; pmd_loc = md.md_loc;
|
2013-09-27 10:05:39 -07:00
|
|
|
}
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tsig_recmodule list ->
|
2013-03-25 10:47:28 -07:00
|
|
|
Psig_recmodule (List.map (fun md ->
|
|
|
|
{pmd_name = md.md_name; pmd_type = untype_module_type md.md_type;
|
2014-01-30 04:18:34 -08:00
|
|
|
pmd_attributes = md.md_attributes; pmd_loc = md.md_loc}) list)
|
2013-03-25 10:47:28 -07:00
|
|
|
| Tsig_modtype mtd ->
|
2014-04-12 03:17:02 -07:00
|
|
|
Psig_modtype {pmtd_name=mtd.mtd_name;
|
|
|
|
pmtd_type=option untype_module_type mtd.mtd_type;
|
2014-01-30 04:18:34 -08:00
|
|
|
pmtd_attributes=mtd.mtd_attributes; pmtd_loc=mtd.mtd_loc}
|
2014-04-15 04:26:00 -07:00
|
|
|
| Tsig_open od ->
|
|
|
|
Psig_open {popen_lid = od.open_txt;
|
|
|
|
popen_override = od.open_override;
|
2014-04-22 08:28:20 -07:00
|
|
|
popen_attributes = od.open_attributes;
|
|
|
|
popen_loc = od.open_loc;
|
|
|
|
}
|
2014-04-15 04:26:00 -07:00
|
|
|
| Tsig_include incl ->
|
|
|
|
Psig_include {pincl_mod = untype_module_type incl.incl_mod;
|
2014-04-22 08:28:20 -07:00
|
|
|
pincl_attributes = incl.incl_attributes;
|
|
|
|
pincl_loc = incl.incl_loc;
|
|
|
|
}
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tsig_class list ->
|
|
|
|
Psig_class (List.map untype_class_description list)
|
|
|
|
| Tsig_class_type list ->
|
|
|
|
Psig_class_type (List.map untype_class_type_declaration list)
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tsig_attribute x ->
|
|
|
|
Psig_attribute x
|
2012-05-30 08:25:49 -07:00
|
|
|
in
|
|
|
|
{ psig_desc = desc;
|
|
|
|
psig_loc = item.sig_loc;
|
|
|
|
}
|
|
|
|
|
2014-05-04 16:08:45 -07:00
|
|
|
and untype_class_declaration cd =
|
|
|
|
{
|
|
|
|
pci_virt = cd.ci_virt;
|
|
|
|
pci_params = List.map untype_type_parameter cd.ci_params;
|
|
|
|
pci_name = cd.ci_id_name;
|
|
|
|
pci_expr = untype_class_expr cd.ci_expr;
|
|
|
|
pci_loc = cd.ci_loc;
|
|
|
|
pci_attributes = cd.ci_attributes;
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:25:49 -07:00
|
|
|
and untype_class_description cd =
|
|
|
|
{
|
|
|
|
pci_virt = cd.ci_virt;
|
2014-05-04 16:08:45 -07:00
|
|
|
pci_params = List.map untype_type_parameter cd.ci_params;
|
2012-05-30 08:25:49 -07:00
|
|
|
pci_name = cd.ci_id_name;
|
|
|
|
pci_expr = untype_class_type cd.ci_expr;
|
|
|
|
pci_loc = cd.ci_loc;
|
2013-03-25 07:16:07 -07:00
|
|
|
pci_attributes = cd.ci_attributes;
|
2012-05-30 08:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and untype_class_type_declaration cd =
|
|
|
|
{
|
|
|
|
pci_virt = cd.ci_virt;
|
2014-05-04 16:08:45 -07:00
|
|
|
pci_params = List.map untype_type_parameter cd.ci_params;
|
2012-05-30 08:25:49 -07:00
|
|
|
pci_name = cd.ci_id_name;
|
|
|
|
pci_expr = untype_class_type cd.ci_expr;
|
|
|
|
pci_loc = cd.ci_loc;
|
2013-03-25 07:16:07 -07:00
|
|
|
pci_attributes = cd.ci_attributes;
|
2012-05-30 08:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and untype_module_type mty =
|
|
|
|
let desc = match mty.mty_desc with
|
2012-12-19 01:25:21 -08:00
|
|
|
Tmty_ident (_path, lid) -> Pmty_ident (lid)
|
2013-09-29 00:22:34 -07:00
|
|
|
| Tmty_alias (_path, lid) -> Pmty_alias (lid)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tmty_signature sg -> Pmty_signature (untype_signature sg)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tmty_functor (_id, name, mtype1, mtype2) ->
|
2013-12-16 19:52:50 -08:00
|
|
|
Pmty_functor (name, Misc.may_map untype_module_type mtype1,
|
2012-05-30 08:25:49 -07:00
|
|
|
untype_module_type mtype2)
|
|
|
|
| Tmty_with (mtype, list) ->
|
|
|
|
Pmty_with (untype_module_type mtype,
|
2012-12-19 01:25:21 -08:00
|
|
|
List.map (fun (_path, lid, withc) ->
|
2013-04-16 03:47:45 -07:00
|
|
|
untype_with_constraint lid withc
|
2012-05-30 08:25:49 -07:00
|
|
|
) list)
|
|
|
|
| Tmty_typeof mexpr ->
|
|
|
|
Pmty_typeof (untype_module_expr mexpr)
|
|
|
|
in
|
2013-03-08 06:59:45 -08:00
|
|
|
Mty.mk ~loc:mty.mty_loc desc
|
2012-05-30 08:25:49 -07:00
|
|
|
|
2013-03-06 03:47:59 -08:00
|
|
|
and untype_with_constraint lid cstr =
|
2012-05-30 08:25:49 -07:00
|
|
|
match cstr with
|
2013-04-16 03:47:45 -07:00
|
|
|
Twith_type decl -> Pwith_type (lid, untype_type_declaration decl)
|
|
|
|
| Twith_module (_path, lid2) -> Pwith_module (lid, lid2)
|
2013-03-25 11:20:11 -07:00
|
|
|
| Twith_typesubst decl -> Pwith_typesubst (untype_type_declaration decl)
|
2013-04-16 03:47:45 -07:00
|
|
|
| Twith_modsubst (_path, lid2) ->
|
|
|
|
Pwith_modsubst ({loc = lid.loc; txt=Longident.last lid.txt}, lid2)
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
and untype_module_expr mexpr =
|
|
|
|
match mexpr.mod_desc with
|
|
|
|
Tmod_constraint (m, _, Tmodtype_implicit, _ ) ->
|
|
|
|
untype_module_expr m
|
|
|
|
| _ ->
|
|
|
|
let desc = match mexpr.mod_desc with
|
2012-12-19 01:25:21 -08:00
|
|
|
Tmod_ident (_p, lid) -> Pmod_ident (lid)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tmod_structure st -> Pmod_structure (untype_structure st)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tmod_functor (_id, name, mtype, mexpr) ->
|
2013-12-16 19:52:50 -08:00
|
|
|
Pmod_functor (name, Misc.may_map untype_module_type mtype,
|
2012-05-30 08:25:49 -07:00
|
|
|
untype_module_expr mexpr)
|
|
|
|
| Tmod_apply (mexp1, mexp2, _) ->
|
|
|
|
Pmod_apply (untype_module_expr mexp1, untype_module_expr mexp2)
|
|
|
|
| Tmod_constraint (mexpr, _, Tmodtype_explicit mtype, _) ->
|
|
|
|
Pmod_constraint (untype_module_expr mexpr,
|
|
|
|
untype_module_type mtype)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tmod_constraint (_mexpr, _, Tmodtype_implicit, _) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
assert false
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tmod_unpack (exp, _pack) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pmod_unpack (untype_expression exp)
|
|
|
|
(* TODO , untype_package_type pack) *)
|
|
|
|
|
|
|
|
in
|
2013-03-08 06:59:45 -08:00
|
|
|
Mod.mk ~loc:mexpr.mod_loc desc
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
and untype_class_expr cexpr =
|
|
|
|
let desc = match cexpr.cl_desc with
|
2013-09-04 08:12:37 -07:00
|
|
|
| Tcl_constraint ( { cl_desc = Tcl_ident (_path, lid, tyl); _ },
|
|
|
|
None, _, _, _ ) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pcl_constr (lid,
|
|
|
|
List.map untype_core_type tyl)
|
|
|
|
| Tcl_structure clstr -> Pcl_structure (untype_class_structure clstr)
|
|
|
|
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tcl_fun (label, pat, _pv, cl, _partial) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pcl_fun (label, None, untype_pattern pat, untype_class_expr cl)
|
|
|
|
|
|
|
|
| Tcl_apply (cl, args) ->
|
|
|
|
Pcl_apply (untype_class_expr cl,
|
|
|
|
List.fold_right (fun (label, expo, _) list ->
|
|
|
|
match expo with
|
|
|
|
None -> list
|
|
|
|
| Some exp -> (label, untype_expression exp) :: list
|
|
|
|
) args [])
|
|
|
|
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tcl_let (rec_flat, bindings, _ivars, cl) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pcl_let (rec_flat,
|
2013-06-03 08:14:19 -07:00
|
|
|
List.map untype_binding bindings,
|
2012-05-30 08:25:49 -07:00
|
|
|
untype_class_expr cl)
|
|
|
|
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tcl_constraint (cl, Some clty, _vals, _meths, _concrs) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pcl_constraint (untype_class_expr cl, untype_class_type clty)
|
|
|
|
|
|
|
|
| Tcl_ident _ -> assert false
|
|
|
|
| Tcl_constraint (_, None, _, _, _) -> assert false
|
|
|
|
in
|
|
|
|
{ pcl_desc = desc;
|
|
|
|
pcl_loc = cexpr.cl_loc;
|
2013-04-10 10:26:55 -07:00
|
|
|
pcl_attributes = cexpr.cl_attributes;
|
2012-05-30 08:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and untype_class_type ct =
|
|
|
|
let desc = match ct.cltyp_desc with
|
|
|
|
Tcty_signature csg -> Pcty_signature (untype_class_signature csg)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Tcty_constr (_path, lid, list) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Pcty_constr (lid, List.map untype_core_type list)
|
2013-04-16 01:59:09 -07:00
|
|
|
| Tcty_arrow (label, ct, cl) ->
|
|
|
|
Pcty_arrow (label, untype_core_type ct, untype_class_type cl)
|
2012-05-30 08:25:49 -07:00
|
|
|
in
|
|
|
|
{ pcty_desc = desc;
|
2013-04-10 10:44:15 -07:00
|
|
|
pcty_loc = ct.cltyp_loc;
|
|
|
|
pcty_attributes = ct.cltyp_attributes;
|
|
|
|
}
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
and untype_class_signature cs =
|
|
|
|
{
|
|
|
|
pcsig_self = untype_core_type cs.csig_self;
|
|
|
|
pcsig_fields = List.map untype_class_type_field cs.csig_fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
and untype_class_type_field ctf =
|
|
|
|
let desc = match ctf.ctf_desc with
|
2013-04-10 04:17:41 -07:00
|
|
|
Tctf_inherit ct -> Pctf_inherit (untype_class_type ct)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tctf_val (s, mut, virt, ct) ->
|
|
|
|
Pctf_val (s, mut, virt, untype_core_type ct)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Tctf_method (s, priv, virt, ct) ->
|
|
|
|
Pctf_method (s, priv, virt, untype_core_type ct)
|
|
|
|
| Tctf_constraint (ct1, ct2) ->
|
|
|
|
Pctf_constraint (untype_core_type ct1, untype_core_type ct2)
|
2014-05-04 13:42:34 -07:00
|
|
|
| Tctf_attribute x -> Pctf_attribute x
|
2012-05-30 08:25:49 -07:00
|
|
|
in
|
|
|
|
{
|
|
|
|
pctf_desc = desc;
|
|
|
|
pctf_loc = ctf.ctf_loc;
|
2013-04-10 02:17:22 -07:00
|
|
|
pctf_attributes = ctf.ctf_attributes;
|
2012-05-30 08:25:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and untype_core_type ct =
|
|
|
|
let desc = match ct.ctyp_desc with
|
|
|
|
Ttyp_any -> Ptyp_any
|
|
|
|
| Ttyp_var s -> Ptyp_var s
|
|
|
|
| Ttyp_arrow (label, ct1, ct2) ->
|
|
|
|
Ptyp_arrow (label, untype_core_type ct1, untype_core_type ct2)
|
|
|
|
| Ttyp_tuple list -> Ptyp_tuple (List.map untype_core_type list)
|
2012-12-19 01:25:21 -08:00
|
|
|
| Ttyp_constr (_path, lid, list) ->
|
2012-05-30 08:25:49 -07:00
|
|
|
Ptyp_constr (lid,
|
|
|
|
List.map untype_core_type list)
|
2013-04-09 06:29:00 -07:00
|
|
|
| Ttyp_object (list, o) ->
|
2014-05-05 04:21:45 -07:00
|
|
|
Ptyp_object
|
|
|
|
(List.map (fun (s, a, t) -> (s, a, untype_core_type t)) list, o)
|
2013-04-16 05:17:17 -07:00
|
|
|
| Ttyp_class (_path, lid, list) ->
|
|
|
|
Ptyp_class (lid, List.map untype_core_type list)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Ttyp_alias (ct, s) ->
|
|
|
|
Ptyp_alias (untype_core_type ct, s)
|
|
|
|
| Ttyp_variant (list, bool, labels) ->
|
|
|
|
Ptyp_variant (List.map untype_row_field list, bool, labels)
|
|
|
|
| Ttyp_poly (list, ct) -> Ptyp_poly (list, untype_core_type ct)
|
|
|
|
| Ttyp_package pack -> Ptyp_package (untype_package_type pack)
|
|
|
|
in
|
2013-03-08 06:59:45 -08:00
|
|
|
Typ.mk ~loc:ct.ctyp_loc desc
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
and untype_class_structure cs =
|
2013-04-10 02:35:09 -07:00
|
|
|
{ pcstr_self = untype_pattern cs.cstr_self;
|
2012-05-30 08:25:49 -07:00
|
|
|
pcstr_fields = List.map untype_class_field cs.cstr_fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
and untype_row_field rf =
|
|
|
|
match rf with
|
2014-04-30 01:19:55 -07:00
|
|
|
Ttag (label, attrs, bool, list) ->
|
|
|
|
Rtag (label, attrs, bool, List.map untype_core_type list)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Tinherit ct -> Rinherit (untype_core_type ct)
|
|
|
|
|
|
|
|
and untype_class_field cf =
|
|
|
|
let desc = match cf.cf_desc with
|
2013-04-10 04:17:41 -07:00
|
|
|
Tcf_inherit (ovf, cl, super, _vals, _meths) ->
|
|
|
|
Pcf_inherit (ovf, untype_class_expr cl, super)
|
|
|
|
| Tcf_constraint (cty, cty') ->
|
|
|
|
Pcf_constraint (untype_core_type cty, untype_core_type cty')
|
|
|
|
| Tcf_val (lab, mut, _, Tcfk_virtual cty, _) ->
|
|
|
|
Pcf_val (lab, mut, Cfk_virtual (untype_core_type cty))
|
|
|
|
| Tcf_val (lab, mut, _, Tcfk_concrete (o, exp), _) ->
|
|
|
|
Pcf_val (lab, mut, Cfk_concrete (o, untype_expression exp))
|
|
|
|
| Tcf_method (lab, priv, Tcfk_virtual cty) ->
|
|
|
|
Pcf_method (lab, priv, Cfk_virtual (untype_core_type cty))
|
|
|
|
| Tcf_method (lab, priv, Tcfk_concrete (o, exp)) ->
|
|
|
|
Pcf_method (lab, priv, Cfk_concrete (o, untype_expression exp))
|
|
|
|
| Tcf_initializer exp -> Pcf_initializer (untype_expression exp)
|
2014-05-04 13:42:34 -07:00
|
|
|
| Tcf_attribute x -> Pcf_attribute x
|
2012-05-30 08:25:49 -07:00
|
|
|
in
|
2013-04-09 08:54:41 -07:00
|
|
|
{ pcf_desc = desc; pcf_loc = cf.cf_loc; pcf_attributes = cf.cf_attributes }
|