@@ -84,12 +84,11 @@ let rewrite_structure (entries : map_entry list) (ast : structure) : structure =
8484 | _ -> None )
8585 | _ -> None
8686 in
87- let open Ast_helper in
88- let rec map_mod (m : module_expr ) : module_expr =
87+ let module_expr (self : Ast_mapper.mapper ) (m : module_expr ) : module_expr =
8988 match m.pmod_desc with
9089 | Pmod_extension (({txt = tag ; _} as name_loc ), payload ) -> (
9190 match string_lit_of_payload payload with
92- | None -> m
91+ | None -> Ast_mapper. default_mapper.module_expr self m
9392 | Some s -> (
9493 match Hashtbl. find_opt index tag with
9594 | None ->
@@ -108,18 +107,15 @@ let rewrite_structure (entries : map_entry list) (ast : structure) : structure =
108107 Location. raise_errorf ~loc: name_loc.loc
109108 " EMBED_MAP_MISMATCH: hash mismatch for tag %s occurrence %d" tag
110109 k;
111- Mod. ident ~loc: m.pmod_loc
112- {txt = Lident entry.target_module; loc = m.pmod_loc})))
113- | Pmod_structure s -> Mod. structure ~loc: m.pmod_loc (map_str s)
114- | Pmod_functor (n , mt , body ) ->
115- Mod. functor_ ~loc: m.pmod_loc n mt (map_mod body)
116- | Pmod_apply (m1 , m2 ) -> Mod. apply ~loc: m.pmod_loc (map_mod m1) (map_mod m2)
117- | _ -> m
118- and map_expr (e : expression ) : expression =
110+ Ast_helper.Mod. ident ~loc: m.pmod_loc
111+ {txt = Longident. Lident entry.target_module; loc = m.pmod_loc})))
112+ | _ -> Ast_mapper. default_mapper.module_expr self m
113+ in
114+ let expr (self : Ast_mapper.mapper ) (e : expression ) : expression =
119115 match e.pexp_desc with
120116 | Pexp_extension (({txt = tag ; _} as name_loc ), payload ) -> (
121117 match string_lit_of_payload payload with
122- | None -> e
118+ | None -> Ast_mapper. default_mapper.expr self e
123119 | Some s -> (
124120 match Hashtbl. find_opt index tag with
125121 | None ->
@@ -138,44 +134,19 @@ let rewrite_structure (entries : map_entry list) (ast : structure) : structure =
138134 Location. raise_errorf ~loc: name_loc.loc
139135 " EMBED_MAP_MISMATCH: hash mismatch for tag %s occurrence %d" tag
140136 k;
141- let id =
142- Exp. ident ~loc: e.pexp_loc
143- {
144- txt = Longident. Ldot (Lident entry.target_module, " default" );
145- loc = e.pexp_loc;
146- }
147- in
148- id)))
149- | _ -> e
150- and map_str (s : structure ) : structure =
151- List. map
152- (fun (si : structure_item ) ->
153- match si.pstr_desc with
154- | Pstr_include incl ->
155- let m' = map_mod incl.pincl_mod in
156- if m' == incl.pincl_mod then si
157- else Str. include_ ~loc: si.pstr_loc {incl with pincl_mod = m'}
158- | Pstr_module mb ->
159- let m' = map_mod mb.pmb_expr in
160- if m' == mb.pmb_expr then si
161- else Str. module_ ~loc: si.pstr_loc {mb with pmb_expr = m'}
162- | Pstr_recmodule mbs ->
163- let mbs' =
164- List. map (fun mb -> {mb with pmb_expr = map_mod mb.pmb_expr}) mbs
165- in
166- Str. rec_module ~loc: si.pstr_loc mbs'
167- | Pstr_value (recflag , vbs ) ->
168- let vbs' =
169- List. map (fun vb -> {vb with pvb_expr = map_expr vb.pvb_expr}) vbs
170- in
171- Str. value ~loc: si.pstr_loc recflag vbs'
172- | Pstr_eval (e , _attrs ) ->
173- let e' = map_expr e in
174- if e' == e then si else Str. eval ~loc: si.pstr_loc e'
175- | _ -> si)
176- s
137+ Ast_helper.Exp. ident ~loc: e.pexp_loc
138+ {
139+ txt =
140+ Longident. Ldot
141+ (Longident. Lident entry.target_module, " default" );
142+ loc = e.pexp_loc;
143+ })))
144+ | _ -> Ast_mapper. default_mapper.expr self e
145+ in
146+ let mapper : Ast_mapper.mapper =
147+ {Ast_mapper. default_mapper with expr; module_expr}
177148 in
178- map_str ast
149+ mapper. Ast_mapper. structure mapper ast
179150
180151let write_ast_impl ~output (ast : structure ) =
181152 let sourcefile = ! Location. input_name in
0 commit comments