1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Nicolas Ojeda Bar, LexiFi *)
6 (* *)
7 (* Copyright 2012 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (* A generic Parsetree mapping class *)
17
18 (*
19 [@@@ocaml.warning "+9"]
20 (* Ensure that record patterns don't miss any field. *)
21 *)
22
23
24 open Parsetree
25 open Location
26
27 type iterator = {
28 attribute: iterator -> attribute -> unit;
29 attributes: iterator -> attribute list -> unit;
30 binding_op: iterator -> binding_op -> unit;
31 case: iterator -> case -> unit;
32 cases: iterator -> case list -> unit;
33 class_declaration: iterator -> class_declaration -> unit;
34 class_description: iterator -> class_description -> unit;
35 class_expr: iterator -> class_expr -> unit;
36 class_field: iterator -> class_field -> unit;
37 class_signature: iterator -> class_signature -> unit;
38 class_structure: iterator -> class_structure -> unit;
39 class_type: iterator -> class_type -> unit;
40 class_type_declaration: iterator -> class_type_declaration -> unit;
41 class_type_field: iterator -> class_type_field -> unit;
42 constructor_declaration: iterator -> constructor_declaration -> unit;
43 expr: iterator -> expression -> unit;
44 extension: iterator -> extension -> unit;
45 extension_constructor: iterator -> extension_constructor -> unit;
46 include_declaration: iterator -> include_declaration -> unit;
47 include_description: iterator -> include_description -> unit;
48 label_declaration: iterator -> label_declaration -> unit;
49 location: iterator -> Location.t -> unit;
50 module_binding: iterator -> module_binding -> unit;
51 module_declaration: iterator -> module_declaration -> unit;
52 module_substitution: iterator -> module_substitution -> unit;
53 module_expr: iterator -> module_expr -> unit;
54 module_type: iterator -> module_type -> unit;
55 module_type_declaration: iterator -> module_type_declaration -> unit;
56 open_declaration: iterator -> open_declaration -> unit;
57 open_description: iterator -> open_description -> unit;
58 pat: iterator -> pattern -> unit;
59 payload: iterator -> payload -> unit;
60 signature: iterator -> signature -> unit;
61 signature_item: iterator -> signature_item -> unit;
62 structure: iterator -> structure -> unit;
63 structure_item: iterator -> structure_item -> unit;
64 typ: iterator -> core_type -> unit;
65 row_field: iterator -> row_field -> unit;
66 object_field: iterator -> object_field -> unit;
67 type_declaration: iterator -> type_declaration -> unit;
68 type_extension: iterator -> type_extension -> unit;
69 type_exception: iterator -> type_exception -> unit;
70 type_kind: iterator -> type_kind -> unit;
71 value_binding: iterator -> value_binding -> unit;
72 value_description: iterator -> value_description -> unit;
73 with_constraint: iterator -> with_constraint -> unit;
74 }
75 (** A [iterator] record implements one "method" per syntactic category,
76 using an open recursion style: each method takes as its first
77 argument the iterator to be applied to children in the syntax
78 tree. *)
79
80 let iter_fst f (x, _) = f x
81 let iter_snd f (_, y) = f y
82 let iter_tuple f1 f2 (x, y) = f1 x; f2 y
83 let iter_tuple3 f1 f2 f3 (x, y, z) = f1 x; f2 y; f3 z
84 let iter_opt f = function None -> () | Some x -> f x
85
86 let iter_loc sub {loc; txt = _} = sub.location sub loc
87
88 module T = struct
89 (* Type expressions for the core language *)
90
91 let row_field sub {
92 prf_desc;
93 prf_loc;
94 prf_attributes;
95 } =
96 sub.location sub prf_loc;
97 sub.attributes sub prf_attributes;
98 match prf_desc with
99 | Rtag (_, _, tl) -> List.iter (sub.typ sub) tl
100 | Rinherit t -> sub.typ sub t
101
102 let object_field sub {
103 pof_desc;
104 pof_loc;
105 pof_attributes;
106 } =
107 sub.location sub pof_loc;
108 sub.attributes sub pof_attributes;
109 match pof_desc with
110 | Otag (_, t) -> sub.typ sub t
111 | Oinherit t -> sub.typ sub t
112
113 let iter sub {ptyp_desc = desc; ptyp_loc = loc; ptyp_attributes = attrs} =
114 sub.location sub loc;
115 sub.attributes sub attrs;
116 match desc with
117 | Ptyp_any
118 | Ptyp_var _ -> ()
119 | Ptyp_arrow (_lab, t1, t2) ->
120 sub.typ sub t1; sub.typ sub t2
121 | Ptyp_tuple tyl -> List.iter (sub.typ sub) tyl
122 | Ptyp_constr (lid, tl) ->
123 iter_loc sub lid; List.iter (sub.typ sub) tl
124 | Ptyp_object (ol, _o) ->
125 List.iter (object_field sub) ol
126 | Ptyp_class (lid, tl) ->
127 iter_loc sub lid; List.iter (sub.typ sub) tl
128 | Ptyp_alias (t, _) -> sub.typ sub t
129 | Ptyp_variant (rl, _b, _ll) ->
130 List.iter (row_field sub) rl
131 | Ptyp_poly (_, t) -> sub.typ sub t
132 | Ptyp_package (lid, l) ->
133 iter_loc sub lid;
134 List.iter (iter_tuple (iter_loc sub) (sub.typ sub)) l
135 | Ptyp_extension x -> sub.extension sub x
136
137 let iter_type_declaration sub
138 {ptype_name; ptype_params; ptype_cstrs;
139 ptype_kind;
140 ptype_private = _;
141 ptype_manifest;
142 ptype_attributes;
143 ptype_loc} =
144 iter_loc sub ptype_name;
145 List.iter (iter_fst (sub.typ sub)) ptype_params;
146 List.iter
147 (iter_tuple3 (sub.typ sub) (sub.typ sub) (sub.location sub))
148 ptype_cstrs;
149 sub.type_kind sub ptype_kind;
150 iter_opt (sub.typ sub) ptype_manifest;
151 sub.location sub ptype_loc;
152 sub.attributes sub ptype_attributes
153
154 let iter_type_kind sub = function
155 | Ptype_abstract -> ()
156 | Ptype_variant l ->
157 List.iter (sub.constructor_declaration sub) l
158 | Ptype_record l -> List.iter (sub.label_declaration sub) l
159 | Ptype_open -> ()
160
161 let iter_constructor_arguments sub = function
162 | Pcstr_tuple l -> List.iter (sub.typ sub) l
163 | Pcstr_record l ->
164 List.iter (sub.label_declaration sub) l
165
166 let iter_type_extension sub
167 {ptyext_path; ptyext_params;
168 ptyext_constructors;
169 ptyext_private = _;
170 ptyext_loc;
171 ptyext_attributes} =
172 iter_loc sub ptyext_path;
173 List.iter (sub.extension_constructor sub) ptyext_constructors;
174 List.iter (iter_fst (sub.typ sub)) ptyext_params;
175 sub.location sub ptyext_loc;
176 sub.attributes sub ptyext_attributes
177
178 let iter_type_exception sub
179 {ptyexn_constructor; ptyexn_loc; ptyexn_attributes} =
180 sub.extension_constructor sub ptyexn_constructor;
181 sub.location sub ptyexn_loc;
182 sub.attributes sub ptyexn_attributes
183
184 let iter_extension_constructor_kind sub = function
185 Pext_decl(ctl, cto) ->
186 iter_constructor_arguments sub ctl; iter_opt (sub.typ sub) cto
187 | Pext_rebind li ->
188 iter_loc sub li
189
190 let iter_extension_constructor sub
191 {pext_name;
192 pext_kind;
193 pext_loc;
194 pext_attributes} =
195 iter_loc sub pext_name;
196 iter_extension_constructor_kind sub pext_kind;
197 sub.location sub pext_loc;
198 sub.attributes sub pext_attributes
199
200 end
201
202 module CT = struct
203 (* Type expressions for the class language *)
204
205 let iter sub {pcty_loc = loc; pcty_desc = desc; pcty_attributes = attrs} =
206 sub.location sub loc;
207 sub.attributes sub attrs;
208 match desc with
209 | Pcty_constr (lid, tys) ->
210 iter_loc sub lid; List.iter (sub.typ sub) tys
211 | Pcty_signature x -> sub.class_signature sub x
212 | Pcty_arrow (_lab, t, ct) ->
213 sub.typ sub t; sub.class_type sub ct
214 | Pcty_extension x -> sub.extension sub x
215 | Pcty_open (o, e) ->
216 sub.open_description sub o; sub.class_type sub e
217
218 let iter_field sub {pctf_desc = desc; pctf_loc = loc; pctf_attributes = attrs}
219 =
220 sub.location sub loc;
221 sub.attributes sub attrs;
222 match desc with
223 | Pctf_inherit ct -> sub.class_type sub ct
224 | Pctf_val (_s, _m, _v, t) -> sub.typ sub t
225 | Pctf_method (_s, _p, _v, t) -> sub.typ sub t
226 | Pctf_constraint (t1, t2) ->
227 sub.typ sub t1; sub.typ sub t2
228 | Pctf_attribute x -> sub.attribute sub x
229 | Pctf_extension x -> sub.extension sub x
230
231 let iter_signature sub {pcsig_self; pcsig_fields} =
232 sub.typ sub pcsig_self;
233 List.iter (sub.class_type_field sub) pcsig_fields
234 end
235
236 let iter_functor_param sub = function
237 | Unit -> ()
238 | Named (name, mty) ->
239 iter_loc sub name;
240 sub.module_type sub mty
241
242 module MT = struct
243 (* Type expressions for the module language *)
244
245 let iter sub {pmty_desc = desc; pmty_loc = loc; pmty_attributes = attrs} =
246 sub.location sub loc;
247 sub.attributes sub attrs;
248 match desc with
249 | Pmty_ident s -> iter_loc sub s
250 | Pmty_alias s -> iter_loc sub s
251 | Pmty_signature sg -> sub.signature sub sg
252 | Pmty_functor (param, mt2) ->
253 iter_functor_param sub param;
254 sub.module_type sub mt2
255 | Pmty_with (mt, l) ->
256 sub.module_type sub mt;
257 List.iter (sub.with_constraint sub) l
258 | Pmty_typeof me -> sub.module_expr sub me
259 | Pmty_extension x -> sub.extension sub x
260
261 let iter_with_constraint sub = function
262 | Pwith_type (lid, d) ->
263 iter_loc sub lid; sub.type_declaration sub d
264 | Pwith_module (lid, lid2) ->
265 iter_loc sub lid; iter_loc sub lid2
266 | Pwith_typesubst (lid, d) ->
267 iter_loc sub lid; sub.type_declaration sub d
268 | Pwith_modsubst (s, lid) ->
269 iter_loc sub s; iter_loc sub lid
270
271 let iter_signature_item sub {psig_desc = desc; psig_loc = loc} =
272 sub.location sub loc;
273 match desc with
274 | Psig_value vd -> sub.value_description sub vd
275 | Psig_type (_, l)
276 | Psig_typesubst l ->
277 List.iter (sub.type_declaration sub) l
278 | Psig_typext te -> sub.type_extension sub te
279 | Psig_exception ed -> sub.type_exception sub ed
280 | Psig_module x -> sub.module_declaration sub x
281 | Psig_modsubst x -> sub.module_substitution sub x
282 | Psig_recmodule l ->
283 List.iter (sub.module_declaration sub) l
284 | Psig_modtype x -> sub.module_type_declaration sub x
285 | Psig_open x -> sub.open_description sub x
286 | Psig_include x -> sub.include_description sub x
287 | Psig_class l -> List.iter (sub.class_description sub) l
288 | Psig_class_type l ->
289 List.iter (sub.class_type_declaration sub) l
290 | Psig_extension (x, attrs) ->
291 sub.attributes sub attrs;
292 sub.extension sub x
293 | Psig_attribute x -> sub.attribute sub x
294 end
295
296
297 module M = struct
298 (* Value expressions for the module language *)
299
300 let iter sub {pmod_loc = loc; pmod_desc = desc; pmod_attributes = attrs} =
301 sub.location sub loc;
302 sub.attributes sub attrs;
303 match desc with
304 | Pmod_ident x -> iter_loc sub x
305 | Pmod_structure str -> sub.structure sub str
306 | Pmod_functor (param, body) ->
307 iter_functor_param sub param;
308 sub.module_expr sub body
309 | Pmod_apply (m1, m2) ->
310 sub.module_expr sub m1; sub.module_expr sub m2
311 | Pmod_constraint (m, mty) ->
312 sub.module_expr sub m; sub.module_type sub mty
313 | Pmod_unpack e -> sub.expr sub e
314 | Pmod_extension x -> sub.extension sub x
315
316 let iter_structure_item sub {pstr_loc = loc; pstr_desc = desc} =
317 sub.location sub loc;
318 match desc with
319 | Pstr_eval (x, attrs) ->
320 sub.attributes sub attrs; sub.expr sub x
321 | Pstr_value (_r, vbs) -> List.iter (sub.value_binding sub) vbs
322 | Pstr_primitive vd -> sub.value_description sub vd
323 | Pstr_type (_rf, l) -> List.iter (sub.type_declaration sub) l
324 | Pstr_typext te -> sub.type_extension sub te
325 | Pstr_exception ed -> sub.type_exception sub ed
326 | Pstr_module x -> sub.module_binding sub x
327 | Pstr_recmodule l -> List.iter (sub.module_binding sub) l
328 | Pstr_modtype x -> sub.module_type_declaration sub x
329 | Pstr_open x -> sub.open_declaration sub x
330 | Pstr_class l -> List.iter (sub.class_declaration sub) l
331 | Pstr_class_type l ->
332 List.iter (sub.class_type_declaration sub) l
333 | Pstr_include x -> sub.include_declaration sub x
334 | Pstr_extension (x, attrs) ->
335 sub.attributes sub attrs; sub.extension sub x
336 | Pstr_attribute x -> sub.attribute sub x
337 end
338
339 module E = struct
340 (* Value expressions for the core language *)
341
342 let iter sub {pexp_loc = loc; pexp_desc = desc; pexp_attributes = attrs} =
343 sub.location sub loc;
344 sub.attributes sub attrs;
345 match desc with
346 | Pexp_ident x -> iter_loc sub x
347 | Pexp_constant _ -> ()
348 | Pexp_let (_r, vbs, e) ->
349 List.iter (sub.value_binding sub) vbs;
350 sub.expr sub e
351 | Pexp_fun (_lab, def, p, e) ->
352 iter_opt (sub.expr sub) def;
353 sub.pat sub p;
354 sub.expr sub e
355 | Pexp_function pel -> sub.cases sub pel
356 | Pexp_apply (e, l) ->
357 sub.expr sub e; List.iter (iter_snd (sub.expr sub)) l
358 | Pexp_match (e, pel) ->
359 sub.expr sub e; sub.cases sub pel
360 | Pexp_try (e, pel) -> sub.expr sub e; sub.cases sub pel
361 | Pexp_tuple el -> List.iter (sub.expr sub) el
362 | Pexp_construct (lid, arg) ->
363 iter_loc sub lid; iter_opt (sub.expr sub) arg
364 | Pexp_variant (_lab, eo) ->
365 iter_opt (sub.expr sub) eo
366 | Pexp_record (l, eo) ->
367 List.iter (iter_tuple (iter_loc sub) (sub.expr sub)) l;
368 iter_opt (sub.expr sub) eo
369 | Pexp_field (e, lid) ->
370 sub.expr sub e; iter_loc sub lid
371 | Pexp_setfield (e1, lid, e2) ->
372 sub.expr sub e1; iter_loc sub lid;
373 sub.expr sub e2
374 | Pexp_array el -> List.iter (sub.expr sub) el
375 | Pexp_ifthenelse (e1, e2, e3) ->
376 sub.expr sub e1; sub.expr sub e2;
377 iter_opt (sub.expr sub) e3
378 | Pexp_sequence (e1, e2) ->
379 sub.expr sub e1; sub.expr sub e2
380 | Pexp_while (e1, e2) ->
381 sub.expr sub e1; sub.expr sub e2
382 | Pexp_for (p, e1, e2, _d, e3) ->
383 sub.pat sub p; sub.expr sub e1; sub.expr sub e2;
384 sub.expr sub e3
385 | Pexp_coerce (e, t1, t2) ->
386 sub.expr sub e; iter_opt (sub.typ sub) t1;
387 sub.typ sub t2
388 | Pexp_constraint (e, t) ->
389 sub.expr sub e; sub.typ sub t
390 | Pexp_send (e, _s) -> sub.expr sub e
391 | Pexp_new lid -> iter_loc sub lid
392 | Pexp_setinstvar (s, e) ->
393 iter_loc sub s; sub.expr sub e
394 | Pexp_override sel ->
395 List.iter (iter_tuple (iter_loc sub) (sub.expr sub)) sel
396 | Pexp_letmodule (s, me, e) ->
397 iter_loc sub s; sub.module_expr sub me;
398 sub.expr sub e
399 | Pexp_letexception (cd, e) ->
400 sub.extension_constructor sub cd;
401 sub.expr sub e
402 | Pexp_assert e -> sub.expr sub e
403 | Pexp_lazy e -> sub.expr sub e
404 | Pexp_poly (e, t) ->
405 sub.expr sub e; iter_opt (sub.typ sub) t
406 | Pexp_object cls -> sub.class_structure sub cls
407 | Pexp_newtype (_s, e) -> sub.expr sub e
408 | Pexp_pack me -> sub.module_expr sub me
409 | Pexp_open (o, e) ->
410 sub.open_declaration sub o; sub.expr sub e
411 | Pexp_letop {let_; ands; body} ->
412 sub.binding_op sub let_;
413 List.iter (sub.binding_op sub) ands;
414 sub.expr sub body
415 | Pexp_extension x -> sub.extension sub x
416 | Pexp_unreachable -> ()
417
418 let iter_binding_op sub {pbop_op; pbop_pat; pbop_exp; pbop_loc} =
419 iter_loc sub pbop_op;
420 sub.pat sub pbop_pat;
421 sub.expr sub pbop_exp;
422 sub.location sub pbop_loc
423
424 end
425
426 module P = struct
427 (* Patterns *)
428
429 let iter sub {ppat_desc = desc; ppat_loc = loc; ppat_attributes = attrs} =
430 sub.location sub loc;
431 sub.attributes sub attrs;
432 match desc with
433 | Ppat_any -> ()
434 | Ppat_var s -> iter_loc sub s
435 | Ppat_alias (p, s) -> sub.pat sub p; iter_loc sub s
436 | Ppat_constant _ -> ()
437 | Ppat_interval _ -> ()
438 | Ppat_tuple pl -> List.iter (sub.pat sub) pl
439 | Ppat_construct (l, p) ->
440 iter_loc sub l; iter_opt (sub.pat sub) p
441 | Ppat_variant (_l, p) -> iter_opt (sub.pat sub) p
442 | Ppat_record (lpl, _cf) ->
443 List.iter (iter_tuple (iter_loc sub) (sub.pat sub)) lpl
444 | Ppat_array pl -> List.iter (sub.pat sub) pl
445 | Ppat_or (p1, p2) -> sub.pat sub p1; sub.pat sub p2
446 | Ppat_constraint (p, t) ->
447 sub.pat sub p; sub.typ sub t
448 | Ppat_type s -> iter_loc sub s
449 | Ppat_lazy p -> sub.pat sub p
450 | Ppat_unpack s -> iter_loc sub s
451 | Ppat_exception p -> sub.pat sub p
452 | Ppat_extension x -> sub.extension sub x
453 | Ppat_open (lid, p) ->
454 iter_loc sub lid; sub.pat sub p
455
456 end
457
458 module CE = struct
459 (* Value expressions for the class language *)
460
461 let iter sub {pcl_loc = loc; pcl_desc = desc; pcl_attributes = attrs} =
462 sub.location sub loc;
463 sub.attributes sub attrs;
464 match desc with
465 | Pcl_constr (lid, tys) ->
466 iter_loc sub lid; List.iter (sub.typ sub) tys
467 | Pcl_structure s ->
468 sub.class_structure sub s
469 | Pcl_fun (_lab, e, p, ce) ->
470 iter_opt (sub.expr sub) e;
471 sub.pat sub p;
472 sub.class_expr sub ce
473 | Pcl_apply (ce, l) ->
474 sub.class_expr sub ce;
475 List.iter (iter_snd (sub.expr sub)) l
476 | Pcl_let (_r, vbs, ce) ->
477 List.iter (sub.value_binding sub) vbs;
478 sub.class_expr sub ce
479 | Pcl_constraint (ce, ct) ->
480 sub.class_expr sub ce; sub.class_type sub ct
481 | Pcl_extension x -> sub.extension sub x
482 | Pcl_open (o, e) ->
483 sub.open_description sub o; sub.class_expr sub e
484
485 let iter_kind sub = function
486 | Cfk_concrete (_o, e) -> sub.expr sub e
487 | Cfk_virtual t -> sub.typ sub t
488
489 let iter_field sub {pcf_desc = desc; pcf_loc = loc; pcf_attributes = attrs} =
490 sub.location sub loc;
491 sub.attributes sub attrs;
492 match desc with
493 | Pcf_inherit (_o, ce, _s) -> sub.class_expr sub ce
494 | Pcf_val (s, _m, k) -> iter_loc sub s; iter_kind sub k
495 | Pcf_method (s, _p, k) ->
496 iter_loc sub s; iter_kind sub k
497 | Pcf_constraint (t1, t2) ->
498 sub.typ sub t1; sub.typ sub t2
499 | Pcf_initializer e -> sub.expr sub e
500 | Pcf_attribute x -> sub.attribute sub x
501 | Pcf_extension x -> sub.extension sub x
502
503 let iter_structure sub {pcstr_self; pcstr_fields} =
504 sub.pat sub pcstr_self;
505 List.iter (sub.class_field sub) pcstr_fields
506
507 let class_infos sub f {pci_virt = _; pci_params = pl; pci_name; pci_expr;
508 pci_loc; pci_attributes} =
509 List.iter (iter_fst (sub.typ sub)) pl;
510 iter_loc sub pci_name;
511 f pci_expr;
512 sub.location sub pci_loc;
513 sub.attributes sub pci_attributes
514 end
515
516 (* Now, a generic AST mapper, to be extended to cover all kinds and
517 cases of the OCaml grammar. The default behavior of the mapper is
518 the identity. *)
519
520 let default_iterator =
521 {
522 structure = (fun this l -> List.iter (this.structure_item this) l);
523 structure_item = M.iter_structure_item;
524 module_expr = M.iter;
525 signature = (fun this l -> List.iter (this.signature_item this) l);
526 signature_item = MT.iter_signature_item;
527 module_type = MT.iter;
528 with_constraint = MT.iter_with_constraint;
529 class_declaration =
530 (fun this -> CE.class_infos this (this.class_expr this));
531 class_expr = CE.iter;
532 class_field = CE.iter_field;
533 class_structure = CE.iter_structure;
534 class_type = CT.iter;
535 class_type_field = CT.iter_field;
536 class_signature = CT.iter_signature;
537 class_type_declaration =
538 (fun this -> CE.class_infos this (this.class_type this));
539 class_description =
540 (fun this -> CE.class_infos this (this.class_type this));
541 type_declaration = T.iter_type_declaration;
542 type_kind = T.iter_type_kind;
543 typ = T.iter;
544 row_field = T.row_field;
545 object_field = T.object_field;
546 type_extension = T.iter_type_extension;
547 type_exception = T.iter_type_exception;
548 extension_constructor = T.iter_extension_constructor;
549 value_description =
550 (fun this {pval_name; pval_type; pval_prim = _; pval_loc;
551 pval_attributes} ->
552 iter_loc this pval_name;
553 this.typ this pval_type;
554 this.location this pval_loc;
555 this.attributes this pval_attributes;
556 );
557
558 pat = P.iter;
559 expr = E.iter;
560 binding_op = E.iter_binding_op;
561
562 module_declaration =
563 (fun this {pmd_name; pmd_type; pmd_attributes; pmd_loc} ->
564 iter_loc this pmd_name;
565 this.module_type this pmd_type;
566 this.location this pmd_loc;
567 this.attributes this pmd_attributes;
568 );
569
570 module_substitution =
571 (fun this {pms_name; pms_manifest; pms_attributes; pms_loc} ->
572 iter_loc this pms_name;
573 iter_loc this pms_manifest;
574 this.location this pms_loc;
575 this.attributes this pms_attributes;
576 );
577
578 module_type_declaration =
579 (fun this {pmtd_name; pmtd_type; pmtd_attributes; pmtd_loc} ->
580 iter_loc this pmtd_name;
581 iter_opt (this.module_type this) pmtd_type;
582 this.location this pmtd_loc;
583 this.attributes this pmtd_attributes;
584 );
585
586 module_binding =
587 (fun this {pmb_name; pmb_expr; pmb_attributes; pmb_loc} ->
588 iter_loc this pmb_name; this.module_expr this pmb_expr;
589 this.location this pmb_loc;
590 this.attributes this pmb_attributes;
591 );
592
593 open_declaration =
594 (fun this {popen_expr; popen_override = _; popen_attributes; popen_loc} ->
595 this.module_expr this popen_expr;
596 this.location this popen_loc;
597 this.attributes this popen_attributes
598 );
599
600 open_description =
601 (fun this {popen_expr; popen_override = _; popen_attributes; popen_loc} ->
602 iter_loc this popen_expr;
603 this.location this popen_loc;
604 this.attributes this popen_attributes
605 );
606
607
608 include_description =
609 (fun this {pincl_mod; pincl_attributes; pincl_loc} ->
610 this.module_type this pincl_mod;
611 this.location this pincl_loc;
612 this.attributes this pincl_attributes
613 );
614
615 include_declaration =
616 (fun this {pincl_mod; pincl_attributes; pincl_loc} ->
617 this.module_expr this pincl_mod;
618 this.location this pincl_loc;
619 this.attributes this pincl_attributes
620 );
621
622
623 value_binding =
624 (fun this {pvb_pat; pvb_expr; pvb_attributes; pvb_loc} ->
625 this.pat this pvb_pat;
626 this.expr this pvb_expr;
627 this.location this pvb_loc;
628 this.attributes this pvb_attributes
629 );
630
631
632 constructor_declaration =
633 (fun this {pcd_name; pcd_args; pcd_res; pcd_loc; pcd_attributes} ->
634 iter_loc this pcd_name;
635 T.iter_constructor_arguments this pcd_args;
636 iter_opt (this.typ this) pcd_res;
637 this.location this pcd_loc;
638 this.attributes this pcd_attributes
639 );
640
641 label_declaration =
642 (fun this {pld_name; pld_type; pld_loc; pld_mutable = _; pld_attributes}->
643 iter_loc this pld_name;
644 this.typ this pld_type;
645 this.location this pld_loc;
646 this.attributes this pld_attributes
647 );
648
649 cases = (fun this l -> List.iter (this.case this) l);
650 case =
651 (fun this {pc_lhs; pc_guard; pc_rhs} ->
652 this.pat this pc_lhs;
653 iter_opt (this.expr this) pc_guard;
654 this.expr this pc_rhs
655 );
656
657 location = (fun _this _l -> ());
658
659 extension = (fun this (s, e) -> iter_loc this s; this.payload this e);
660 attribute = (fun this a ->
661 iter_loc this a.attr_name;
662 this.payload this a.attr_payload;
663 this.location this a.attr_loc
664 );
665 attributes = (fun this l -> List.iter (this.attribute this) l);
666 payload =
667 (fun this -> function
668 | PStr x -> this.structure this x
669 | PSig x -> this.signature this x
670 | PTyp x -> this.typ this x
671 | PPat (x, g) -> this.pat this x; iter_opt (this.expr this) g
672 );
673 }
674