2012-08-02 01:17:59 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Fabrice Le Fessant, INRIA Saclay *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2012 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. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
open Typedtree
|
|
|
|
|
|
|
|
module type MapArgument = sig
|
|
|
|
val enter_structure : structure -> structure
|
|
|
|
val enter_value_description : value_description -> value_description
|
|
|
|
val enter_type_declaration : type_declaration -> type_declaration
|
|
|
|
val enter_pattern : pattern -> pattern
|
|
|
|
val enter_expression : expression -> expression
|
|
|
|
val enter_package_type : package_type -> package_type
|
|
|
|
val enter_signature : signature -> signature
|
|
|
|
val enter_signature_item : signature_item -> signature_item
|
2013-03-25 10:47:28 -07:00
|
|
|
val enter_module_type_declaration : module_type_declaration -> module_type_declaration
|
2012-07-12 04:02:18 -07:00
|
|
|
val enter_module_type : module_type -> module_type
|
|
|
|
val enter_module_expr : module_expr -> module_expr
|
|
|
|
val enter_with_constraint : with_constraint -> with_constraint
|
|
|
|
val enter_class_expr : class_expr -> class_expr
|
|
|
|
val enter_class_signature : class_signature -> class_signature
|
|
|
|
val enter_class_description : class_description -> class_description
|
|
|
|
val enter_class_type_declaration :
|
|
|
|
class_type_declaration -> class_type_declaration
|
|
|
|
val enter_class_infos : 'a class_infos -> 'a class_infos
|
|
|
|
val enter_class_type : class_type -> class_type
|
|
|
|
val enter_class_type_field : class_type_field -> class_type_field
|
|
|
|
val enter_core_type : core_type -> core_type
|
|
|
|
val enter_class_structure : class_structure -> class_structure
|
|
|
|
val enter_class_field : class_field -> class_field
|
|
|
|
val enter_structure_item : structure_item -> structure_item
|
|
|
|
|
|
|
|
val leave_structure : structure -> structure
|
|
|
|
val leave_value_description : value_description -> value_description
|
|
|
|
val leave_type_declaration : type_declaration -> type_declaration
|
|
|
|
val leave_pattern : pattern -> pattern
|
|
|
|
val leave_expression : expression -> expression
|
|
|
|
val leave_package_type : package_type -> package_type
|
|
|
|
val leave_signature : signature -> signature
|
|
|
|
val leave_signature_item : signature_item -> signature_item
|
2013-03-25 10:47:28 -07:00
|
|
|
val leave_module_type_declaration : module_type_declaration -> module_type_declaration
|
2012-07-12 04:02:18 -07:00
|
|
|
val leave_module_type : module_type -> module_type
|
|
|
|
val leave_module_expr : module_expr -> module_expr
|
|
|
|
val leave_with_constraint : with_constraint -> with_constraint
|
|
|
|
val leave_class_expr : class_expr -> class_expr
|
|
|
|
val leave_class_signature : class_signature -> class_signature
|
|
|
|
val leave_class_description : class_description -> class_description
|
|
|
|
val leave_class_type_declaration :
|
|
|
|
class_type_declaration -> class_type_declaration
|
|
|
|
val leave_class_infos : 'a class_infos -> 'a class_infos
|
|
|
|
val leave_class_type : class_type -> class_type
|
|
|
|
val leave_class_type_field : class_type_field -> class_type_field
|
|
|
|
val leave_core_type : core_type -> core_type
|
|
|
|
val leave_class_structure : class_structure -> class_structure
|
|
|
|
val leave_class_field : class_field -> class_field
|
|
|
|
val leave_structure_item : structure_item -> structure_item
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
module MakeMap(Map : MapArgument) = struct
|
|
|
|
|
|
|
|
let may_map f v =
|
|
|
|
match v with
|
|
|
|
None -> v
|
|
|
|
| Some x -> Some (f x)
|
|
|
|
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
|
|
|
|
let rec map_structure str =
|
|
|
|
let str = Map.enter_structure str in
|
|
|
|
let str_items = List.map map_structure_item str.str_items in
|
|
|
|
Map.leave_structure { str with str_items = str_items }
|
|
|
|
|
|
|
|
and map_binding (pat, exp) = (map_pattern pat, map_expression exp)
|
|
|
|
|
|
|
|
and map_bindings rec_flag list =
|
|
|
|
List.map map_binding list
|
|
|
|
|
2013-04-15 09:23:22 -07:00
|
|
|
and map_case {c_lhs; c_guard; c_rhs} =
|
|
|
|
{
|
|
|
|
c_lhs = map_pattern c_lhs;
|
|
|
|
c_guard = may_map map_expression c_guard;
|
|
|
|
c_rhs = map_expression c_rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
and map_cases list =
|
|
|
|
List.map map_case list
|
|
|
|
|
2012-07-12 04:02:18 -07:00
|
|
|
and map_structure_item item =
|
|
|
|
let item = Map.enter_structure_item item in
|
|
|
|
let str_desc =
|
|
|
|
match item.str_desc with
|
2013-04-11 07:07:32 -07:00
|
|
|
Tstr_eval (exp, attrs) -> Tstr_eval (map_expression exp, attrs)
|
2013-04-11 06:52:06 -07:00
|
|
|
| Tstr_value (rec_flag, list, attrs) ->
|
|
|
|
Tstr_value (rec_flag, map_bindings rec_flag list, attrs)
|
2013-03-25 11:04:40 -07:00
|
|
|
| Tstr_primitive vd ->
|
|
|
|
Tstr_primitive (map_value_description vd)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tstr_type list ->
|
2013-03-25 11:20:11 -07:00
|
|
|
Tstr_type (List.map map_type_declaration list)
|
2013-03-25 11:42:45 -07:00
|
|
|
| Tstr_exception cd ->
|
|
|
|
Tstr_exception (map_constructor_declaration cd)
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_exn_rebind (id, name, path, lid, attrs) ->
|
|
|
|
Tstr_exn_rebind (id, name, path, lid, attrs)
|
2013-03-26 01:09:26 -07:00
|
|
|
| Tstr_module x ->
|
|
|
|
Tstr_module (map_module_binding x)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tstr_recmodule list ->
|
2013-03-26 01:09:26 -07:00
|
|
|
let list = List.map map_module_binding list in
|
2012-07-30 11:04:46 -07:00
|
|
|
Tstr_recmodule list
|
2013-03-26 01:21:29 -07:00
|
|
|
| Tstr_modtype x ->
|
|
|
|
Tstr_modtype (map_module_type_binding x)
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_open (path, lid, attrs) -> Tstr_open (path, lid, attrs)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tstr_class list ->
|
2012-07-30 11:04:46 -07:00
|
|
|
let list =
|
2012-07-12 04:02:18 -07:00
|
|
|
List.map (fun (ci, string_list, virtual_flag) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
let ci = Map.enter_class_infos ci in
|
|
|
|
let ci_expr = map_class_expr ci.ci_expr in
|
|
|
|
(Map.leave_class_infos { ci with ci_expr = ci_expr},
|
2012-07-12 04:02:18 -07:00
|
|
|
string_list, virtual_flag)
|
|
|
|
) list
|
2012-07-30 11:04:46 -07:00
|
|
|
in
|
|
|
|
Tstr_class list
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tstr_class_type list ->
|
|
|
|
let list = List.map (fun (id, name, ct) ->
|
|
|
|
let ct = Map.enter_class_infos ct in
|
|
|
|
let ci_expr = map_class_type ct.ci_expr in
|
2012-07-30 11:04:46 -07:00
|
|
|
(id, name, Map.leave_class_infos { ct with ci_expr = ci_expr})
|
2012-07-12 04:02:18 -07:00
|
|
|
) list in
|
2012-07-30 11:04:46 -07:00
|
|
|
Tstr_class_type list
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_include (mexpr, idents, attrs) ->
|
|
|
|
Tstr_include (map_module_expr mexpr, idents, attrs)
|
|
|
|
| Tstr_attribute x -> Tstr_attribute x
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
Map.leave_structure_item { item with str_desc = str_desc}
|
|
|
|
|
2013-03-26 01:09:26 -07:00
|
|
|
and map_module_binding x =
|
|
|
|
{x with mb_expr = map_module_expr x.mb_expr}
|
|
|
|
|
2013-03-26 01:21:29 -07:00
|
|
|
and map_module_type_binding x =
|
|
|
|
{x with mtb_type = map_module_type x.mtb_type}
|
|
|
|
|
2012-07-12 04:02:18 -07:00
|
|
|
and map_value_description v =
|
|
|
|
let v = Map.enter_value_description v in
|
|
|
|
let val_desc = map_core_type v.val_desc in
|
|
|
|
Map.leave_value_description { v with val_desc = val_desc }
|
|
|
|
|
|
|
|
and map_type_declaration decl =
|
|
|
|
let decl = Map.enter_type_declaration decl in
|
|
|
|
let typ_cstrs = List.map (fun (ct1, ct2, loc) ->
|
|
|
|
(map_core_type ct1,
|
|
|
|
map_core_type ct2,
|
|
|
|
loc)
|
|
|
|
) decl.typ_cstrs in
|
|
|
|
let typ_kind = match decl.typ_kind with
|
|
|
|
Ttype_abstract -> Ttype_abstract
|
|
|
|
| Ttype_variant list ->
|
2013-03-25 11:42:45 -07:00
|
|
|
let list = List.map map_constructor_declaration list in
|
2013-03-25 07:56:56 -07:00
|
|
|
Ttype_variant list
|
2012-07-12 04:02:18 -07:00
|
|
|
| Ttype_record list ->
|
2012-07-30 11:04:46 -07:00
|
|
|
let list =
|
2013-03-25 07:56:56 -07:00
|
|
|
List.map
|
|
|
|
(fun ld ->
|
|
|
|
{ld with ld_type = map_core_type ld.ld_type}
|
|
|
|
) list
|
|
|
|
in
|
2012-07-30 11:04:46 -07:00
|
|
|
Ttype_record list
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
let typ_manifest =
|
|
|
|
match decl.typ_manifest with
|
|
|
|
None -> None
|
|
|
|
| Some ct -> Some (map_core_type ct)
|
|
|
|
in
|
|
|
|
Map.leave_type_declaration { decl with typ_cstrs = typ_cstrs;
|
|
|
|
typ_kind = typ_kind; typ_manifest = typ_manifest }
|
|
|
|
|
2013-03-25 11:42:45 -07:00
|
|
|
and map_constructor_declaration cd =
|
|
|
|
{cd with cd_args = List.map map_core_type cd.cd_args;
|
|
|
|
cd_res = may_map map_core_type cd.cd_res
|
|
|
|
}
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
and map_pattern pat =
|
|
|
|
let pat = Map.enter_pattern pat in
|
|
|
|
let pat_desc =
|
|
|
|
match pat.pat_desc with
|
|
|
|
| Tpat_alias (pat1, p, text) ->
|
|
|
|
let pat1 = map_pattern pat1 in
|
2012-07-30 11:04:46 -07:00
|
|
|
Tpat_alias (pat1, p, text)
|
|
|
|
| Tpat_tuple list -> Tpat_tuple (List.map map_pattern list)
|
2012-10-24 05:03:00 -07:00
|
|
|
| Tpat_construct (lid, cstr_decl, args, arity) ->
|
|
|
|
Tpat_construct (lid, cstr_decl,
|
2012-07-12 04:02:18 -07:00
|
|
|
List.map map_pattern args, arity)
|
|
|
|
| Tpat_variant (label, pato, rowo) ->
|
|
|
|
let pato = match pato with
|
|
|
|
None -> pato
|
|
|
|
| Some pat -> Some (map_pattern pat)
|
|
|
|
in
|
2012-07-30 11:04:46 -07:00
|
|
|
Tpat_variant (label, pato, rowo)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tpat_record (list, closed) ->
|
2012-10-24 05:03:00 -07:00
|
|
|
Tpat_record (List.map (fun (lid, lab_desc, pat) ->
|
|
|
|
(lid, lab_desc, map_pattern pat) ) list, closed)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tpat_array list -> Tpat_array (List.map map_pattern list)
|
|
|
|
| Tpat_or (p1, p2, rowo) ->
|
|
|
|
Tpat_or (map_pattern p1, map_pattern p2, rowo)
|
|
|
|
| Tpat_lazy p -> Tpat_lazy (map_pattern p)
|
|
|
|
| Tpat_constant _
|
|
|
|
| Tpat_any
|
|
|
|
| Tpat_var _ -> pat.pat_desc
|
|
|
|
|
|
|
|
in
|
|
|
|
let pat_extra = List.map map_pat_extra pat.pat_extra in
|
|
|
|
Map.leave_pattern { pat with pat_desc = pat_desc; pat_extra = pat_extra }
|
|
|
|
|
|
|
|
and map_pat_extra pat_extra =
|
|
|
|
match pat_extra with
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tpat_constraint ct, loc, attrs -> (Tpat_constraint (map_core_type ct), loc, attrs)
|
|
|
|
| (Tpat_type _ | Tpat_unpack), _, _ -> pat_extra
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
and map_expression exp =
|
|
|
|
let exp = Map.enter_expression exp in
|
|
|
|
let exp_desc =
|
|
|
|
match exp.exp_desc with
|
|
|
|
Texp_ident (_, _, _)
|
|
|
|
| Texp_constant _ -> exp.exp_desc
|
|
|
|
| Texp_let (rec_flag, list, exp) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
Texp_let (rec_flag,
|
|
|
|
map_bindings rec_flag list,
|
|
|
|
map_expression exp)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_function (label, cases, partial) ->
|
2013-04-15 09:23:22 -07:00
|
|
|
Texp_function (label, map_cases cases, partial)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_apply (exp, list) ->
|
|
|
|
Texp_apply (map_expression exp,
|
2012-07-30 11:04:46 -07:00
|
|
|
List.map (fun (label, expo, optional) ->
|
|
|
|
let expo =
|
|
|
|
match expo with
|
|
|
|
None -> expo
|
|
|
|
| Some exp -> Some (map_expression exp)
|
|
|
|
in
|
|
|
|
(label, expo, optional)
|
|
|
|
) list )
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_match (exp, list, partial) ->
|
|
|
|
Texp_match (
|
2012-07-30 11:04:46 -07:00
|
|
|
map_expression exp,
|
2013-04-15 09:23:22 -07:00
|
|
|
map_cases list,
|
2012-07-30 11:04:46 -07:00
|
|
|
partial
|
|
|
|
)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_try (exp, list) ->
|
|
|
|
Texp_try (
|
2012-07-30 11:04:46 -07:00
|
|
|
map_expression exp,
|
2013-04-15 09:23:22 -07:00
|
|
|
map_cases list
|
2012-07-30 11:04:46 -07:00
|
|
|
)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_tuple list ->
|
|
|
|
Texp_tuple (List.map map_expression list)
|
2012-10-24 05:03:00 -07:00
|
|
|
| Texp_construct (lid, cstr_desc, args, arity) ->
|
|
|
|
Texp_construct (lid, cstr_desc,
|
2012-07-12 04:02:18 -07:00
|
|
|
List.map map_expression args, arity )
|
|
|
|
| Texp_variant (label, expo) ->
|
|
|
|
let expo =match expo with
|
|
|
|
None -> expo
|
|
|
|
| Some exp -> Some (map_expression exp)
|
2012-07-30 11:04:46 -07:00
|
|
|
in
|
|
|
|
Texp_variant (label, expo)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_record (list, expo) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
let list =
|
2012-10-24 05:03:00 -07:00
|
|
|
List.map (fun (lid, lab_desc, exp) ->
|
|
|
|
(lid, lab_desc, map_expression exp)
|
2012-07-12 04:02:18 -07:00
|
|
|
) list in
|
|
|
|
let expo = match expo with
|
|
|
|
None -> expo
|
|
|
|
| Some exp -> Some (map_expression exp)
|
2012-07-30 11:04:46 -07:00
|
|
|
in
|
|
|
|
Texp_record (list, expo)
|
2012-10-24 05:03:00 -07:00
|
|
|
| Texp_field (exp, lid, label) ->
|
|
|
|
Texp_field (map_expression exp, lid, label)
|
|
|
|
| Texp_setfield (exp1, lid, label, exp2) ->
|
2012-07-12 04:02:18 -07:00
|
|
|
Texp_setfield (
|
2012-07-30 11:04:46 -07:00
|
|
|
map_expression exp1,
|
2012-10-24 05:03:00 -07:00
|
|
|
lid,
|
2012-07-30 11:04:46 -07:00
|
|
|
label,
|
2012-07-12 04:02:18 -07:00
|
|
|
map_expression exp2)
|
|
|
|
| Texp_array list ->
|
|
|
|
Texp_array (List.map map_expression list)
|
|
|
|
| Texp_ifthenelse (exp1, exp2, expo) ->
|
|
|
|
Texp_ifthenelse (
|
2012-07-30 11:04:46 -07:00
|
|
|
map_expression exp1,
|
2012-07-12 04:02:18 -07:00
|
|
|
map_expression exp2,
|
|
|
|
match expo with
|
|
|
|
None -> expo
|
2012-07-30 11:04:46 -07:00
|
|
|
| Some exp -> Some (map_expression exp)
|
|
|
|
)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_sequence (exp1, exp2) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
Texp_sequence (
|
2012-07-12 04:02:18 -07:00
|
|
|
map_expression exp1,
|
|
|
|
map_expression exp2
|
2012-07-30 11:04:46 -07:00
|
|
|
)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_while (exp1, exp2) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
Texp_while (
|
2012-07-12 04:02:18 -07:00
|
|
|
map_expression exp1,
|
|
|
|
map_expression exp2
|
2012-07-30 11:04:46 -07:00
|
|
|
)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_for (id, name, exp1, exp2, dir, exp3) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
Texp_for (
|
|
|
|
id, name,
|
|
|
|
map_expression exp1,
|
|
|
|
map_expression exp2,
|
|
|
|
dir,
|
|
|
|
map_expression exp3
|
|
|
|
)
|
|
|
|
| Texp_send (exp, meth, expo) ->
|
|
|
|
Texp_send (map_expression exp, meth, may_map map_expression expo)
|
|
|
|
| Texp_new (path, lid, cl_decl) -> exp.exp_desc
|
|
|
|
| Texp_instvar (_, path, _) -> exp.exp_desc
|
|
|
|
| Texp_setinstvar (path, lid, path2, exp) ->
|
|
|
|
Texp_setinstvar (path, lid, path2, map_expression exp)
|
|
|
|
| Texp_override (path, list) ->
|
|
|
|
Texp_override (
|
|
|
|
path,
|
|
|
|
List.map (fun (path, lid, exp) ->
|
|
|
|
(path, lid, map_expression exp)
|
|
|
|
) list
|
|
|
|
)
|
|
|
|
| Texp_letmodule (id, name, mexpr, exp) ->
|
|
|
|
Texp_letmodule (
|
|
|
|
id, name,
|
|
|
|
map_module_expr mexpr,
|
|
|
|
map_expression exp
|
|
|
|
)
|
|
|
|
| Texp_assert exp -> Texp_assert (map_expression exp)
|
|
|
|
| Texp_lazy exp -> Texp_lazy (map_expression exp)
|
|
|
|
| Texp_object (cl, string_list) ->
|
|
|
|
Texp_object (map_class_structure cl, string_list)
|
|
|
|
| Texp_pack (mexpr) ->
|
|
|
|
Texp_pack (map_module_expr mexpr)
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
let exp_extra = List.map map_exp_extra exp.exp_extra in
|
|
|
|
Map.leave_expression {
|
|
|
|
exp with
|
|
|
|
exp_desc = exp_desc;
|
2013-03-25 07:16:07 -07:00
|
|
|
exp_extra = exp_extra; }
|
2012-07-12 04:02:18 -07:00
|
|
|
|
2013-03-25 07:16:07 -07:00
|
|
|
and map_exp_extra ((desc, loc, attrs) as exp_extra) =
|
|
|
|
match desc with
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_constraint (Some ct, None) ->
|
2013-03-25 07:16:07 -07:00
|
|
|
Texp_constraint (Some (map_core_type ct), None), loc, attrs
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_constraint (None, Some ct) ->
|
2013-03-25 07:16:07 -07:00
|
|
|
Texp_constraint (None, Some (map_core_type ct)), loc, attrs
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_constraint (Some ct1, Some ct2) ->
|
|
|
|
Texp_constraint (Some (map_core_type ct1),
|
2013-03-25 07:16:07 -07:00
|
|
|
Some (map_core_type ct2)), loc, attrs
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_poly (Some ct) ->
|
2013-03-25 07:16:07 -07:00
|
|
|
Texp_poly (Some ( map_core_type ct )), loc, attrs
|
2012-07-12 04:02:18 -07:00
|
|
|
| Texp_newtype _
|
|
|
|
| Texp_constraint (None, None)
|
|
|
|
| Texp_open _
|
|
|
|
| Texp_poly None -> exp_extra
|
|
|
|
|
|
|
|
|
|
|
|
and map_package_type pack =
|
|
|
|
let pack = Map.enter_package_type pack in
|
|
|
|
let pack_fields = List.map (
|
|
|
|
fun (s, ct) -> (s, map_core_type ct) ) pack.pack_fields in
|
|
|
|
Map.leave_package_type { pack with pack_fields = pack_fields }
|
|
|
|
|
|
|
|
and map_signature sg =
|
|
|
|
let sg = Map.enter_signature sg in
|
|
|
|
let sig_items = List.map map_signature_item sg.sig_items in
|
|
|
|
Map.leave_signature { sg with sig_items = sig_items }
|
|
|
|
|
|
|
|
and map_signature_item item =
|
|
|
|
let item = Map.enter_signature_item item in
|
|
|
|
let sig_desc =
|
|
|
|
match item.sig_desc with
|
2013-03-25 11:04:40 -07:00
|
|
|
Tsig_value vd ->
|
|
|
|
Tsig_value (map_value_description vd)
|
2013-03-25 11:20:11 -07:00
|
|
|
| Tsig_type list -> Tsig_type (List.map map_type_declaration list)
|
2013-03-25 11:42:45 -07:00
|
|
|
| Tsig_exception cd ->
|
|
|
|
Tsig_exception (map_constructor_declaration cd)
|
2013-03-25 10:47:28 -07:00
|
|
|
| Tsig_module md ->
|
|
|
|
Tsig_module {md with md_type = map_module_type md.md_type}
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tsig_recmodule list ->
|
2013-03-25 10:47:28 -07:00
|
|
|
Tsig_recmodule
|
|
|
|
(List.map
|
|
|
|
(fun md -> {md with md_type = map_module_type md.md_type})
|
|
|
|
list
|
|
|
|
)
|
|
|
|
| Tsig_modtype mtd ->
|
|
|
|
Tsig_modtype (map_module_type_declaration mtd)
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tsig_open (path, lid, _attrs) -> item.sig_desc
|
|
|
|
| Tsig_include (mty, lid, attrs) -> Tsig_include (map_module_type mty, lid, attrs)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tsig_class list -> Tsig_class (List.map map_class_description list)
|
|
|
|
| Tsig_class_type list ->
|
|
|
|
Tsig_class_type (List.map map_class_type_declaration list)
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tsig_attribute _ as x -> x
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
Map.leave_signature_item { item with sig_desc = sig_desc }
|
|
|
|
|
2013-03-25 10:47:28 -07:00
|
|
|
and map_module_type_declaration mtd =
|
|
|
|
let mtd = Map.enter_module_type_declaration mtd in
|
|
|
|
let mtd = {mtd with mtd_type = may_map map_module_type mtd.mtd_type} in
|
|
|
|
Map.leave_module_type_declaration mtd
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
and map_class_description cd =
|
|
|
|
let cd = Map.enter_class_description cd in
|
|
|
|
let ci_expr = map_class_type cd.ci_expr in
|
|
|
|
Map.leave_class_description { cd with ci_expr = ci_expr}
|
|
|
|
|
|
|
|
and map_class_type_declaration cd =
|
|
|
|
let cd = Map.enter_class_type_declaration cd in
|
|
|
|
let ci_expr = map_class_type cd.ci_expr in
|
|
|
|
Map.leave_class_type_declaration { cd with ci_expr = ci_expr }
|
|
|
|
|
|
|
|
and map_module_type mty =
|
|
|
|
let mty = Map.enter_module_type mty in
|
|
|
|
let mty_desc =
|
|
|
|
match mty.mty_desc with
|
|
|
|
Tmty_ident (path, lid) -> mty.mty_desc
|
|
|
|
| Tmty_signature sg -> Tmty_signature (map_signature sg)
|
|
|
|
| Tmty_functor (id, name, mtype1, mtype2) ->
|
2012-07-30 11:04:46 -07:00
|
|
|
Tmty_functor (id, name, map_module_type mtype1,
|
2012-07-12 04:02:18 -07:00
|
|
|
map_module_type mtype2)
|
|
|
|
| Tmty_with (mtype, list) ->
|
|
|
|
Tmty_with (map_module_type mtype,
|
2012-07-30 11:04:46 -07:00
|
|
|
List.map (fun (path, lid, withc) ->
|
|
|
|
(path, lid, map_with_constraint withc)
|
|
|
|
) list)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tmty_typeof mexpr ->
|
|
|
|
Tmty_typeof (map_module_expr mexpr)
|
|
|
|
in
|
|
|
|
Map.leave_module_type { mty with mty_desc = mty_desc}
|
|
|
|
|
|
|
|
and map_with_constraint cstr =
|
|
|
|
let cstr = Map.enter_with_constraint cstr in
|
|
|
|
let cstr =
|
|
|
|
match cstr with
|
|
|
|
Twith_type decl -> Twith_type (map_type_declaration decl)
|
|
|
|
| Twith_typesubst decl -> Twith_typesubst (map_type_declaration decl)
|
|
|
|
| Twith_module (path, lid) -> cstr
|
|
|
|
| Twith_modsubst (path, lid) -> cstr
|
|
|
|
in
|
|
|
|
Map.leave_with_constraint cstr
|
|
|
|
|
|
|
|
and map_module_expr mexpr =
|
|
|
|
let mexpr = Map.enter_module_expr mexpr in
|
|
|
|
let mod_desc =
|
|
|
|
match mexpr.mod_desc with
|
|
|
|
Tmod_ident (p, lid) -> mexpr.mod_desc
|
|
|
|
| Tmod_structure st -> Tmod_structure (map_structure st)
|
|
|
|
| Tmod_functor (id, name, mtype, mexpr) ->
|
|
|
|
Tmod_functor (id, name, map_module_type mtype,
|
|
|
|
map_module_expr mexpr)
|
|
|
|
| Tmod_apply (mexp1, mexp2, coercion) ->
|
|
|
|
Tmod_apply (map_module_expr mexp1, map_module_expr mexp2, coercion)
|
|
|
|
| Tmod_constraint (mexpr, mod_type, Tmodtype_implicit, coercion ) ->
|
|
|
|
Tmod_constraint (map_module_expr mexpr, mod_type,
|
|
|
|
Tmodtype_implicit, coercion)
|
|
|
|
| Tmod_constraint (mexpr, mod_type,
|
|
|
|
Tmodtype_explicit mtype, coercion) ->
|
|
|
|
Tmod_constraint (map_module_expr mexpr, mod_type,
|
|
|
|
Tmodtype_explicit (map_module_type mtype),
|
|
|
|
coercion)
|
|
|
|
| Tmod_unpack (exp, mod_type) ->
|
|
|
|
Tmod_unpack (map_expression exp, mod_type)
|
|
|
|
in
|
|
|
|
Map.leave_module_expr { mexpr with mod_desc = mod_desc }
|
|
|
|
|
|
|
|
and map_class_expr cexpr =
|
|
|
|
let cexpr = Map.enter_class_expr cexpr in
|
|
|
|
let cl_desc =
|
|
|
|
match cexpr.cl_desc with
|
|
|
|
| Tcl_constraint (cl, None, string_list1, string_list2, concr ) ->
|
|
|
|
Tcl_constraint (map_class_expr cl, None, string_list1,
|
|
|
|
string_list2, concr)
|
|
|
|
| Tcl_structure clstr -> Tcl_structure (map_class_structure clstr)
|
|
|
|
| Tcl_fun (label, pat, priv, cl, partial) ->
|
|
|
|
Tcl_fun (label, map_pattern pat,
|
2012-07-30 11:04:46 -07:00
|
|
|
List.map (fun (id, name, exp) ->
|
2012-07-12 04:02:18 -07:00
|
|
|
(id, name, map_expression exp)) priv,
|
2012-07-30 11:04:46 -07:00
|
|
|
map_class_expr cl, partial)
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
| Tcl_apply (cl, args) ->
|
|
|
|
Tcl_apply (map_class_expr cl,
|
2012-07-30 11:04:46 -07:00
|
|
|
List.map (fun (label, expo, optional) ->
|
2012-07-12 04:02:18 -07:00
|
|
|
(label, may_map map_expression expo,
|
|
|
|
optional)
|
2012-07-30 11:04:46 -07:00
|
|
|
) args)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tcl_let (rec_flat, bindings, ivars, cl) ->
|
|
|
|
Tcl_let (rec_flat, map_bindings rec_flat bindings,
|
2012-07-30 11:04:46 -07:00
|
|
|
List.map (fun (id, name, exp) ->
|
2012-07-12 04:02:18 -07:00
|
|
|
(id, name, map_expression exp)) ivars,
|
2012-07-30 11:04:46 -07:00
|
|
|
map_class_expr cl)
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
| Tcl_constraint (cl, Some clty, vals, meths, concrs) ->
|
|
|
|
Tcl_constraint ( map_class_expr cl,
|
|
|
|
Some (map_class_type clty), vals, meths, concrs)
|
|
|
|
|
|
|
|
| Tcl_ident (id, name, tyl) ->
|
|
|
|
Tcl_ident (id, name, List.map map_core_type tyl)
|
|
|
|
in
|
|
|
|
Map.leave_class_expr { cexpr with cl_desc = cl_desc }
|
|
|
|
|
|
|
|
and map_class_type ct =
|
|
|
|
let ct = Map.enter_class_type ct in
|
|
|
|
let cltyp_desc =
|
|
|
|
match ct.cltyp_desc with
|
|
|
|
Tcty_signature csg -> Tcty_signature (map_class_signature csg)
|
|
|
|
| Tcty_constr (path, lid, list) ->
|
|
|
|
Tcty_constr (path, lid, List.map map_core_type list)
|
2013-04-16 01:59:09 -07:00
|
|
|
| Tcty_arrow (label, ct, cl) ->
|
|
|
|
Tcty_arrow (label, map_core_type ct, map_class_type cl)
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
Map.leave_class_type { ct with cltyp_desc = cltyp_desc }
|
|
|
|
|
|
|
|
and map_class_signature cs =
|
|
|
|
let cs = Map.enter_class_signature cs in
|
|
|
|
let csig_self = map_core_type cs.csig_self in
|
|
|
|
let csig_fields = List.map map_class_type_field cs.csig_fields in
|
|
|
|
Map.leave_class_signature { cs with
|
|
|
|
csig_self = csig_self; csig_fields = csig_fields }
|
|
|
|
|
|
|
|
|
|
|
|
and map_class_type_field ctf =
|
|
|
|
let ctf = Map.enter_class_type_field ctf in
|
|
|
|
let ctf_desc =
|
|
|
|
match ctf.ctf_desc with
|
2013-04-10 04:17:41 -07:00
|
|
|
Tctf_inherit ct -> Tctf_inherit (map_class_type ct)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Tctf_val (s, mut, virt, ct) ->
|
|
|
|
Tctf_val (s, mut, virt, map_core_type ct)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Tctf_method (s, priv, virt, ct) ->
|
|
|
|
Tctf_method (s, priv, virt, map_core_type ct)
|
|
|
|
| Tctf_constraint (ct1, ct2) ->
|
|
|
|
Tctf_constraint (map_core_type ct1, map_core_type ct2)
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
Map.leave_class_type_field { ctf with ctf_desc = ctf_desc }
|
|
|
|
|
|
|
|
and map_core_type ct =
|
|
|
|
let ct = Map.enter_core_type ct in
|
|
|
|
let ctyp_desc =
|
|
|
|
match ct.ctyp_desc with
|
|
|
|
Ttyp_any
|
|
|
|
| Ttyp_var _ -> ct.ctyp_desc
|
|
|
|
| Ttyp_arrow (label, ct1, ct2) ->
|
|
|
|
Ttyp_arrow (label, map_core_type ct1, map_core_type ct2)
|
|
|
|
| Ttyp_tuple list -> Ttyp_tuple (List.map map_core_type list)
|
|
|
|
| Ttyp_constr (path, lid, list) ->
|
|
|
|
Ttyp_constr (path, lid, List.map map_core_type list)
|
2013-04-09 06:29:00 -07:00
|
|
|
| Ttyp_object (list, o) ->
|
|
|
|
Ttyp_object (List.map (fun (s, t) -> (s, map_core_type t)) list, o)
|
2013-04-16 05:17:17 -07:00
|
|
|
| Ttyp_class (path, lid, list) ->
|
|
|
|
Ttyp_class (path, lid, List.map map_core_type list)
|
2012-07-12 04:02:18 -07:00
|
|
|
| Ttyp_alias (ct, s) -> Ttyp_alias (map_core_type ct, s)
|
|
|
|
| Ttyp_variant (list, bool, labels) ->
|
|
|
|
Ttyp_variant (List.map map_row_field list, bool, labels)
|
|
|
|
| Ttyp_poly (list, ct) -> Ttyp_poly (list, map_core_type ct)
|
|
|
|
| Ttyp_package pack -> Ttyp_package (map_package_type pack)
|
|
|
|
in
|
|
|
|
Map.leave_core_type { ct with ctyp_desc = ctyp_desc }
|
|
|
|
|
|
|
|
and map_class_structure cs =
|
|
|
|
let cs = Map.enter_class_structure cs in
|
2013-04-10 02:35:09 -07:00
|
|
|
let cstr_self = map_pattern cs.cstr_self in
|
2012-07-12 04:02:18 -07:00
|
|
|
let cstr_fields = List.map map_class_field cs.cstr_fields in
|
2013-04-10 02:35:09 -07:00
|
|
|
Map.leave_class_structure { cs with cstr_self; cstr_fields }
|
2012-07-12 04:02:18 -07:00
|
|
|
|
|
|
|
and map_row_field rf =
|
|
|
|
match rf with
|
|
|
|
Ttag (label, bool, list) ->
|
|
|
|
Ttag (label, bool, List.map map_core_type list)
|
|
|
|
| Tinherit ct -> Tinherit (map_core_type ct)
|
|
|
|
|
|
|
|
and map_class_field cf =
|
|
|
|
let cf = Map.enter_class_field cf in
|
|
|
|
let cf_desc =
|
|
|
|
match cf.cf_desc with
|
2013-04-10 04:17:41 -07:00
|
|
|
Tcf_inherit (ovf, cl, super, vals, meths) ->
|
|
|
|
Tcf_inherit (ovf, map_class_expr cl, super, vals, meths)
|
|
|
|
| Tcf_constraint (cty, cty') ->
|
|
|
|
Tcf_constraint (map_core_type cty, map_core_type cty')
|
|
|
|
| Tcf_val (lab, mut, ident, Tcfk_virtual cty, b) ->
|
|
|
|
Tcf_val (lab, mut, ident, Tcfk_virtual (map_core_type cty), b)
|
|
|
|
| Tcf_val (lab, mut, ident, Tcfk_concrete (o, exp), b) ->
|
|
|
|
Tcf_val (lab, mut, ident, Tcfk_concrete (o, map_expression exp), b)
|
|
|
|
| Tcf_method (lab, priv, Tcfk_virtual cty) ->
|
|
|
|
Tcf_method (lab, priv, Tcfk_virtual (map_core_type cty))
|
|
|
|
| Tcf_method (lab, priv, Tcfk_concrete (o, exp)) ->
|
|
|
|
Tcf_method (lab, priv, Tcfk_concrete (o, map_expression exp))
|
|
|
|
| Tcf_initializer exp -> Tcf_initializer (map_expression exp)
|
2012-07-12 04:02:18 -07:00
|
|
|
in
|
|
|
|
Map.leave_class_field { cf with cf_desc = cf_desc }
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
module DefaultMapArgument = struct
|
|
|
|
|
|
|
|
let enter_structure t = t
|
|
|
|
let enter_value_description t = t
|
|
|
|
let enter_type_declaration t = t
|
|
|
|
let enter_exception_declaration t = t
|
|
|
|
let enter_pattern t = t
|
|
|
|
let enter_expression t = t
|
|
|
|
let enter_package_type t = t
|
|
|
|
let enter_signature t = t
|
|
|
|
let enter_signature_item t = t
|
2013-03-25 10:47:28 -07:00
|
|
|
let enter_module_type_declaration t = t
|
2012-07-12 04:02:18 -07:00
|
|
|
let enter_module_type t = t
|
|
|
|
let enter_module_expr t = t
|
|
|
|
let enter_with_constraint t = t
|
|
|
|
let enter_class_expr t = t
|
|
|
|
let enter_class_signature t = t
|
|
|
|
let enter_class_description t = t
|
|
|
|
let enter_class_type_declaration t = t
|
|
|
|
let enter_class_infos t = t
|
|
|
|
let enter_class_type t = t
|
|
|
|
let enter_class_type_field t = t
|
|
|
|
let enter_core_type t = t
|
|
|
|
let enter_class_structure t = t
|
|
|
|
let enter_class_field t = t
|
|
|
|
let enter_structure_item t = t
|
|
|
|
|
|
|
|
|
|
|
|
let leave_structure t = t
|
|
|
|
let leave_value_description t = t
|
|
|
|
let leave_type_declaration t = t
|
|
|
|
let leave_exception_declaration t = t
|
|
|
|
let leave_pattern t = t
|
|
|
|
let leave_expression t = t
|
|
|
|
let leave_package_type t = t
|
|
|
|
let leave_signature t = t
|
|
|
|
let leave_signature_item t = t
|
2013-03-25 10:47:28 -07:00
|
|
|
let leave_module_type_declaration t = t
|
2012-07-12 04:02:18 -07:00
|
|
|
let leave_module_type t = t
|
|
|
|
let leave_module_expr t = t
|
|
|
|
let leave_with_constraint t = t
|
|
|
|
let leave_class_expr t = t
|
|
|
|
let leave_class_signature t = t
|
|
|
|
let leave_class_description t = t
|
|
|
|
let leave_class_type_declaration t = t
|
|
|
|
let leave_class_infos t = t
|
|
|
|
let leave_class_type t = t
|
|
|
|
let leave_class_type_field t = t
|
|
|
|
let leave_core_type t = t
|
|
|
|
let leave_class_structure t = t
|
|
|
|
let leave_class_field t = t
|
|
|
|
let leave_structure_item t = t
|
|
|
|
|
|
|
|
end
|