-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtast_iterator.ml
702 lines (640 loc) · 24.3 KB
/
tast_iterator.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Isaac "Izzy" Avram *)
(* *)
(* Copyright 2019 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
open Asttypes
open Jane_asttypes
open Typedtree
type iterator =
{
attribute: iterator -> attribute -> unit;
attributes: iterator -> attributes -> unit;
binding_op: iterator -> binding_op -> unit;
case: 'k . iterator -> 'k case -> unit;
class_declaration: iterator -> class_declaration -> unit;
class_description: iterator -> class_description -> unit;
class_expr: iterator -> class_expr -> unit;
class_field: iterator -> class_field -> unit;
class_signature: iterator -> class_signature -> unit;
class_structure: iterator -> class_structure -> unit;
class_type: iterator -> class_type -> unit;
class_type_declaration: iterator -> class_type_declaration -> unit;
class_type_field: iterator -> class_type_field -> unit;
env: iterator -> Env.t -> unit;
expr: iterator -> expression -> unit;
extension_constructor: iterator -> extension_constructor -> unit;
jkind_annotation: iterator -> const_jkind -> unit;
location: iterator -> Location.t -> unit;
module_binding: iterator -> module_binding -> unit;
module_coercion: iterator -> module_coercion -> unit;
module_declaration: iterator -> module_declaration -> unit;
module_substitution: iterator -> module_substitution -> unit;
module_expr: iterator -> module_expr -> unit;
module_type: iterator -> module_type -> unit;
module_type_declaration: iterator -> module_type_declaration -> unit;
package_type: iterator -> package_type -> unit;
pat: 'k . iterator -> 'k general_pattern -> unit;
row_field: iterator -> row_field -> unit;
object_field: iterator -> object_field -> unit;
open_declaration: iterator -> open_declaration -> unit;
open_description: iterator -> open_description -> unit;
signature: iterator -> signature -> unit;
signature_item: iterator -> signature_item -> unit;
structure: iterator -> structure -> unit;
structure_item: iterator -> structure_item -> unit;
typ: iterator -> core_type -> unit;
type_declaration: iterator -> type_declaration -> unit;
type_declarations: iterator -> (rec_flag * type_declaration list) -> unit;
type_extension: iterator -> type_extension -> unit;
type_exception: iterator -> type_exception -> unit;
type_kind: iterator -> type_kind -> unit;
value_binding: iterator -> value_binding -> unit;
value_bindings: iterator -> (rec_flag * value_binding list) -> unit;
value_description: iterator -> value_description -> unit;
with_constraint: iterator -> with_constraint -> unit;
}
let iter_snd f (_, y) = f y
let iter_loc sub {loc; _} = sub.location sub loc
let location _sub _l = ()
let attribute sub x =
let iterator = {
Ast_iterator.default_iterator
with location = fun _this x -> sub.location sub x
} in
iter_loc sub x.Parsetree.attr_name;
iterator.payload iterator x.Parsetree.attr_payload;
sub.location sub x.Parsetree.attr_loc
let attributes sub l = List.iter (attribute sub) l
let structure sub {str_items; str_final_env; _} =
List.iter (sub.structure_item sub) str_items;
sub.env sub str_final_env
let class_infos sub f x =
sub.location sub x.ci_loc;
sub.attributes sub x.ci_attributes;
iter_loc sub x.ci_id_name;
List.iter (fun (ct, _) -> sub.typ sub ct) x.ci_params;
f x.ci_expr
let module_type_declaration sub x =
sub.location sub x.mtd_loc;
sub.attributes sub x.mtd_attributes;
iter_loc sub x.mtd_name;
Option.iter (sub.module_type sub) x.mtd_type
let module_declaration sub {md_loc; md_name; md_type; md_attributes; _} =
sub.location sub md_loc;
sub.attributes sub md_attributes;
iter_loc sub md_name;
sub.module_type sub md_type
let module_substitution sub {ms_loc; ms_name; ms_txt; ms_attributes; _} =
sub.location sub ms_loc;
sub.attributes sub ms_attributes;
iter_loc sub ms_name;
iter_loc sub ms_txt
let include_kind sub = function
| Tincl_structure -> ()
| Tincl_functor ccs ->
List.iter (fun (_, cc) -> sub.module_coercion sub cc) ccs
| Tincl_gen_functor ccs ->
List.iter (fun (_, cc) -> sub.module_coercion sub cc) ccs
let str_include_infos sub {incl_loc; incl_mod; incl_attributes; incl_kind; _} =
sub.location sub incl_loc;
sub.attributes sub incl_attributes;
sub.module_expr sub incl_mod;
include_kind sub incl_kind
let class_type_declaration sub x =
class_infos sub (sub.class_type sub) x
let class_declaration sub x =
class_infos sub (sub.class_expr sub) x
let structure_item sub {str_loc; str_desc; str_env; _} =
sub.location sub str_loc;
sub.env sub str_env;
match str_desc with
| Tstr_eval (exp, _, attrs) -> sub.expr sub exp; sub.attributes sub attrs
| Tstr_value (rec_flag, list) -> sub.value_bindings sub (rec_flag, list)
| Tstr_primitive v -> sub.value_description sub v
| Tstr_type (rec_flag, list) -> sub.type_declarations sub (rec_flag, list)
| Tstr_typext te -> sub.type_extension sub te
| Tstr_exception ext -> sub.type_exception sub ext
| Tstr_module mb -> sub.module_binding sub mb
| Tstr_recmodule list -> List.iter (sub.module_binding sub) list
| Tstr_modtype x -> sub.module_type_declaration sub x
| Tstr_class list ->
List.iter (fun (cls,_) -> sub.class_declaration sub cls) list
| Tstr_class_type list ->
List.iter (fun (_, s, cltd) ->
iter_loc sub s; sub.class_type_declaration sub cltd) list
| Tstr_include incl -> str_include_infos sub incl
| Tstr_open od -> sub.open_declaration sub od
| Tstr_attribute attr -> sub.attribute sub attr
let value_description sub x =
sub.location sub x.val_loc;
sub.attributes sub x.val_attributes;
iter_loc sub x.val_name;
sub.typ sub x.val_desc
let label_decl sub {ld_loc; ld_name; ld_type; ld_attributes; _} =
sub.location sub ld_loc;
sub.attributes sub ld_attributes;
iter_loc sub ld_name;
sub.typ sub ld_type
let field_decl sub (ty, _) = sub.typ sub ty
let constructor_args sub = function
| Cstr_tuple l -> List.iter (field_decl sub) l
| Cstr_record l -> List.iter (label_decl sub) l
let constructor_decl sub x =
sub.location sub x.cd_loc;
sub.attributes sub x.cd_attributes;
iter_loc sub x.cd_name;
constructor_args sub x.cd_args;
Option.iter (sub.typ sub) x.cd_res
let type_kind sub = function
| Ttype_abstract -> ()
| Ttype_variant list -> List.iter (constructor_decl sub) list
| Ttype_record list -> List.iter (label_decl sub) list
| Ttype_open -> ()
let type_declaration sub x =
sub.location sub x.typ_loc;
sub.attributes sub x.typ_attributes;
iter_loc sub x.typ_name;
List.iter
(fun (c1, c2, loc) ->
sub.typ sub c1;
sub.typ sub c2;
sub.location sub loc)
x.typ_cstrs;
sub.type_kind sub x.typ_kind;
Option.iter (sub.typ sub) x.typ_manifest;
List.iter (fun (c, _) -> sub.typ sub c) x.typ_params
let type_declarations sub (_, list) = List.iter (sub.type_declaration sub) list
let type_extension sub x =
sub.location sub x.tyext_loc;
sub.attributes sub x.tyext_attributes;
iter_loc sub x.tyext_txt;
List.iter (fun (c, _) -> sub.typ sub c) x.tyext_params;
List.iter (sub.extension_constructor sub) x.tyext_constructors
let type_exception sub {tyexn_loc; tyexn_constructor; tyexn_attributes; _} =
sub.location sub tyexn_loc;
sub.attributes sub tyexn_attributes;
sub.extension_constructor sub tyexn_constructor
let extension_constructor sub {ext_loc; ext_name; ext_kind; ext_attributes; _} =
sub.location sub ext_loc;
sub.attributes sub ext_attributes;
iter_loc sub ext_name;
match ext_kind with
| Text_decl (_, ctl, cto) ->
constructor_args sub ctl;
Option.iter (sub.typ sub) cto
| Text_rebind (_, lid) -> iter_loc sub lid
let pat_extra sub (e, loc, attrs) =
sub.location sub loc;
sub.attributes sub attrs;
match e with
| Tpat_type (_, lid) -> iter_loc sub lid
| Tpat_unpack -> ()
| Tpat_open (_, lid, env) -> iter_loc sub lid; sub.env sub env
| Tpat_constraint ct -> sub.typ sub ct
let pat
: type k . iterator -> k general_pattern -> unit
= fun sub {pat_loc; pat_extra=extra; pat_desc; pat_env; pat_attributes; _} ->
sub.location sub pat_loc;
sub.attributes sub pat_attributes;
sub.env sub pat_env;
List.iter (pat_extra sub) extra;
match pat_desc with
| Tpat_any -> ()
| Tpat_var (_, s, _, _) -> iter_loc sub s
| Tpat_constant _ -> ()
| Tpat_tuple l -> List.iter (sub.pat sub) l
| Tpat_construct (lid, _, l, vto) ->
iter_loc sub lid;
List.iter (sub.pat sub) l;
Option.iter (fun (ids, ct) ->
List.iter (iter_loc sub) ids; sub.typ sub ct) vto
| Tpat_variant (_, po, _) -> Option.iter (sub.pat sub) po
| Tpat_record (l, _) ->
List.iter (fun (lid, _, i) -> iter_loc sub lid; sub.pat sub i) l
| Tpat_array (_, l) -> List.iter (sub.pat sub) l
| Tpat_alias (p, _, s, _, _) -> sub.pat sub p; iter_loc sub s
| Tpat_lazy p -> sub.pat sub p
| Tpat_value p -> sub.pat sub (p :> pattern)
| Tpat_exception p -> sub.pat sub p
| Tpat_or (p1, p2, _) ->
sub.pat sub p1;
sub.pat sub p2
let expr sub {exp_loc; exp_extra; exp_desc; exp_env; exp_attributes; _} =
let extra = function
| Texp_constraint cty -> sub.typ sub cty
| Texp_coerce (cty1, cty2) ->
Option.iter (sub.typ sub) cty1;
sub.typ sub cty2
| Texp_newtype _ -> ()
| Texp_poly cto -> Option.iter (sub.typ sub) cto
in
sub.location sub exp_loc;
sub.attributes sub exp_attributes;
List.iter (fun (e, loc, _) -> extra e; sub.location sub loc) exp_extra;
sub.env sub exp_env;
match exp_desc with
| Texp_ident (_, lid, _, _, _) -> iter_loc sub lid
| Texp_constant _ -> ()
| Texp_let (rec_flag, list, exp) ->
sub.value_bindings sub (rec_flag, list);
sub.expr sub exp
| Texp_function {cases; _} ->
List.iter (sub.case sub) cases
| Texp_apply (exp, list, _, _) ->
sub.expr sub exp;
List.iter (function
| (_, Arg (exp, _)) -> sub.expr sub exp
| (_, Omitted _) -> ())
list
| Texp_match (exp, _, cases, _) ->
sub.expr sub exp;
List.iter (sub.case sub) cases
| Texp_try (exp, cases) ->
sub.expr sub exp;
List.iter (sub.case sub) cases
| Texp_tuple (list, _) -> List.iter (sub.expr sub) list
| Texp_construct (lid, _, args, _) ->
iter_loc sub lid;
List.iter (sub.expr sub) args
| Texp_variant (_, expo) ->
Option.iter (fun (expr, _) -> sub.expr sub expr) expo
| Texp_record { fields; extended_expression; _} ->
Array.iter (function
| _, Kept _ -> ()
| _, Overridden (lid, exp) -> iter_loc sub lid; sub.expr sub exp)
fields;
Option.iter (sub.expr sub) extended_expression;
| Texp_field (exp, lid, _, _, _) ->
iter_loc sub lid;
sub.expr sub exp
| Texp_setfield (exp1, _, lid, _, exp2) ->
iter_loc sub lid;
sub.expr sub exp1;
sub.expr sub exp2
| Texp_array (_, list, _) -> List.iter (sub.expr sub) list
| Texp_list_comprehension { comp_body; comp_clauses }
| Texp_array_comprehension (_, { comp_body; comp_clauses }) ->
sub.expr sub comp_body;
List.iter
(function
| Texp_comp_for bindings ->
List.iter
(fun { comp_cb_iterator; comp_cb_attributes } ->
sub.attributes sub comp_cb_attributes;
match comp_cb_iterator with
| Texp_comp_range { ident = _; start; stop; direction = _ } ->
sub.expr sub start;
sub.expr sub stop
| Texp_comp_in { pattern; sequence } ->
sub.pat sub pattern;
sub.expr sub sequence)
bindings
| Texp_comp_when exp ->
sub.expr sub exp)
comp_clauses
| Texp_ifthenelse (exp1, exp2, expo) ->
sub.expr sub exp1;
sub.expr sub exp2;
Option.iter (sub.expr sub) expo
| Texp_sequence (exp1, _, exp2) ->
sub.expr sub exp1;
sub.expr sub exp2
| Texp_while { wh_cond; wh_body } ->
sub.expr sub wh_cond;
sub.expr sub wh_body
| Texp_for {for_from; for_to; for_body} ->
sub.expr sub for_from;
sub.expr sub for_to;
sub.expr sub for_body
| Texp_send (exp, _, _) ->
sub.expr sub exp
| Texp_new (_, lid, _, _) -> iter_loc sub lid
| Texp_instvar (_, _, s) -> iter_loc sub s
| Texp_setinstvar (_, _, s, exp) ->
iter_loc sub s;
sub.expr sub exp
| Texp_override (_, list) ->
List.iter (fun (_, s, e) -> iter_loc sub s; sub.expr sub e) list
| Texp_letmodule (_, s, _, mexpr, exp) ->
iter_loc sub s;
sub.module_expr sub mexpr;
sub.expr sub exp
| Texp_letexception (cd, exp) ->
sub.extension_constructor sub cd;
sub.expr sub exp
| Texp_assert (exp, _) -> sub.expr sub exp
| Texp_lazy exp -> sub.expr sub exp
| Texp_object (cl, _) -> sub.class_structure sub cl
| Texp_pack mexpr -> sub.module_expr sub mexpr
| Texp_letop {let_ = l; ands; body; _} ->
sub.binding_op sub l;
List.iter (sub.binding_op sub) ands;
sub.case sub body
| Texp_unreachable -> ()
| Texp_extension_constructor (lid, _) -> iter_loc sub lid
| Texp_open (od, e) ->
sub.open_declaration sub od;
sub.expr sub e
| Texp_probe {handler;_} -> sub.expr sub handler
| Texp_probe_is_enabled _ -> ()
| Texp_exclave exp -> sub.expr sub exp
let package_type sub {pack_fields; pack_txt; _} =
List.iter (fun (lid, p) -> iter_loc sub lid; sub.typ sub p) pack_fields;
iter_loc sub pack_txt
let binding_op sub {bop_loc; bop_op_name; bop_exp; _} =
sub.location sub bop_loc;
iter_loc sub bop_op_name;
sub.expr sub bop_exp
let signature sub {sig_items; sig_final_env; _} =
sub.env sub sig_final_env;
List.iter (sub.signature_item sub) sig_items
let sig_include_infos sub {incl_loc; incl_mod; incl_attributes; incl_kind; _} =
sub.location sub incl_loc;
sub.attributes sub incl_attributes;
sub.module_type sub incl_mod;
include_kind sub incl_kind
let signature_item sub {sig_loc; sig_desc; sig_env; _} =
sub.location sub sig_loc;
sub.env sub sig_env;
match sig_desc with
| Tsig_value v -> sub.value_description sub v
| Tsig_type (rf, tdl) -> sub.type_declarations sub (rf, tdl)
| Tsig_typesubst list -> sub.type_declarations sub (Nonrecursive, list)
| Tsig_typext te -> sub.type_extension sub te
| Tsig_exception ext -> sub.type_exception sub ext
| Tsig_module x -> sub.module_declaration sub x
| Tsig_modsubst x -> sub.module_substitution sub x
| Tsig_recmodule list -> List.iter (sub.module_declaration sub) list
| Tsig_modtype x -> sub.module_type_declaration sub x
| Tsig_modtypesubst x -> sub.module_type_declaration sub x
| Tsig_include incl -> sig_include_infos sub incl
| Tsig_class list -> List.iter (sub.class_description sub) list
| Tsig_class_type list -> List.iter (sub.class_type_declaration sub) list
| Tsig_open od -> sub.open_description sub od
| Tsig_attribute _ -> ()
let class_description sub x =
class_infos sub (sub.class_type sub) x
let functor_parameter sub = function
| Unit -> ()
| Named (_, s, mtype) -> iter_loc sub s; sub.module_type sub mtype
let module_type sub {mty_loc; mty_desc; mty_env; mty_attributes; _} =
sub.location sub mty_loc;
sub.attributes sub mty_attributes;
sub.env sub mty_env;
match mty_desc with
| Tmty_ident (_, lid) -> iter_loc sub lid
| Tmty_alias (_, lid) -> iter_loc sub lid
| Tmty_signature sg -> sub.signature sub sg
| Tmty_functor (arg, mtype2) ->
functor_parameter sub arg;
sub.module_type sub mtype2
| Tmty_with (mtype, list) ->
sub.module_type sub mtype;
List.iter (fun (_, lid, e) ->
iter_loc sub lid; sub.with_constraint sub e) list
| Tmty_typeof mexpr -> sub.module_expr sub mexpr
| Tmty_strengthen (mtype, _, _) -> sub.module_type sub mtype
let with_constraint sub = function
| Twith_type decl -> sub.type_declaration sub decl
| Twith_typesubst decl -> sub.type_declaration sub decl
| Twith_module (_, lid) -> iter_loc sub lid
| Twith_modsubst (_, lid) -> iter_loc sub lid
| Twith_modtype mty -> sub.module_type sub mty
| Twith_modtypesubst mty -> sub.module_type sub mty
let open_description sub {open_loc; open_expr; open_env; open_attributes; _} =
sub.location sub open_loc;
sub.attributes sub open_attributes;
iter_snd (iter_loc sub) open_expr;
sub.env sub open_env
let open_declaration sub {open_loc; open_expr; open_env; open_attributes; _} =
sub.location sub open_loc;
sub.attributes sub open_attributes;
sub.module_expr sub open_expr;
sub.env sub open_env
let module_coercion sub = function
| Tcoerce_none -> ()
| Tcoerce_functor (c1,c2) ->
sub.module_coercion sub c1;
sub.module_coercion sub c2
| Tcoerce_alias (env, _, c1) ->
sub.env sub env;
sub.module_coercion sub c1
| Tcoerce_structure (l1, l2) ->
List.iter (fun (_, c) -> sub.module_coercion sub c) l1;
List.iter (fun (_, _ ,c) -> sub.module_coercion sub c) l2
| Tcoerce_primitive {pc_loc; pc_env; _} ->
sub.location sub pc_loc;
sub.env sub pc_env
let module_expr sub {mod_loc; mod_desc; mod_env; mod_attributes; _} =
sub.location sub mod_loc;
sub.attributes sub mod_attributes;
sub.env sub mod_env;
match mod_desc with
| Tmod_ident (_, lid) -> iter_loc sub lid
| Tmod_structure st -> sub.structure sub st
| Tmod_functor (arg, mexpr) ->
functor_parameter sub arg;
sub.module_expr sub mexpr
| Tmod_apply (mexp1, mexp2, c) ->
sub.module_expr sub mexp1;
sub.module_expr sub mexp2;
sub.module_coercion sub c
| Tmod_apply_unit mexp1 ->
sub.module_expr sub mexp1;
| Tmod_constraint (mexpr, _, Tmodtype_implicit, c) ->
sub.module_expr sub mexpr;
sub.module_coercion sub c
| Tmod_constraint (mexpr, _, Tmodtype_explicit mtype, c) ->
sub.module_expr sub mexpr;
sub.module_type sub mtype;
sub.module_coercion sub c
| Tmod_unpack (exp, _) -> sub.expr sub exp
let module_binding sub {mb_loc; mb_name; mb_expr; mb_attributes; _} =
sub.location sub mb_loc;
sub.attributes sub mb_attributes;
iter_loc sub mb_name;
sub.module_expr sub mb_expr
let class_expr sub {cl_loc; cl_desc; cl_env; cl_attributes; _} =
sub.location sub cl_loc;
sub.attributes sub cl_attributes;
sub.env sub cl_env;
match cl_desc with
| Tcl_constraint (cl, clty, _, _, _) ->
sub.class_expr sub cl;
Option.iter (sub.class_type sub) clty
| Tcl_structure clstr -> sub.class_structure sub clstr
| Tcl_fun (_, pat, priv, cl, _) ->
sub.pat sub pat;
List.iter (fun (_, e) -> sub.expr sub e) priv;
sub.class_expr sub cl
| Tcl_apply (cl, args) ->
sub.class_expr sub cl;
List.iter (function
| (_, Arg (exp, _)) -> sub.expr sub exp
| (_, Omitted _) -> ())
args
| Tcl_let (rec_flag, value_bindings, ivars, cl) ->
sub.value_bindings sub (rec_flag, value_bindings);
List.iter (fun (_, e) -> sub.expr sub e) ivars;
sub.class_expr sub cl
| Tcl_ident (_, lid, tyl) ->
iter_loc sub lid;
List.iter (sub.typ sub) tyl
| Tcl_open (od, e) ->
sub.open_description sub od;
sub.class_expr sub e
let class_type sub {cltyp_loc; cltyp_desc; cltyp_env; cltyp_attributes; _} =
sub.location sub cltyp_loc;
sub.attributes sub cltyp_attributes;
sub.env sub cltyp_env;
match cltyp_desc with
| Tcty_signature csg -> sub.class_signature sub csg
| Tcty_constr (_, lid, list) ->
iter_loc sub lid;
List.iter (sub.typ sub) list
| Tcty_arrow (_, ct, cl) ->
sub.typ sub ct;
sub.class_type sub cl
| Tcty_open (od, e) ->
sub.open_description sub od;
sub.class_type sub e
let class_signature sub {csig_self; csig_fields; _} =
sub.typ sub csig_self;
List.iter (sub.class_type_field sub) csig_fields
let class_type_field sub {ctf_loc; ctf_desc; ctf_attributes; _} =
sub.location sub ctf_loc;
sub.attributes sub ctf_attributes;
match ctf_desc with
| Tctf_inherit ct -> sub.class_type sub ct
| Tctf_val (_, _, _, ct) -> sub.typ sub ct
| Tctf_method (_, _, _, ct) -> sub.typ sub ct
| Tctf_constraint (ct1, ct2) ->
sub.typ sub ct1;
sub.typ sub ct2
| Tctf_attribute attr -> sub.attribute sub attr
let typ sub {ctyp_loc; ctyp_desc; ctyp_env; ctyp_attributes; _} =
sub.location sub ctyp_loc;
sub.attributes sub ctyp_attributes;
sub.env sub ctyp_env;
match ctyp_desc with
| Ttyp_var (_, jkind) ->
Option.iter (sub.jkind_annotation sub) jkind
| Ttyp_arrow (_, ct1, ct2) ->
sub.typ sub ct1;
sub.typ sub ct2
| Ttyp_tuple list -> List.iter (sub.typ sub) list
| Ttyp_constr (_, lid, list) ->
iter_loc sub lid;
List.iter (sub.typ sub) list
| Ttyp_object (list, _) -> List.iter (sub.object_field sub) list
| Ttyp_class (_, lid, list) ->
iter_loc sub lid;
List.iter (sub.typ sub) list
| Ttyp_alias (ct, _, jkind) ->
sub.typ sub ct;
Option.iter (sub.jkind_annotation sub) jkind
| Ttyp_variant (list, _, _) -> List.iter (sub.row_field sub) list
| Ttyp_poly (vars, ct) ->
List.iter (fun (_, l) -> Option.iter (sub.jkind_annotation sub) l) vars;
sub.typ sub ct
| Ttyp_package pack -> sub.package_type sub pack
let class_structure sub {cstr_self; cstr_fields; _} =
sub.pat sub cstr_self;
List.iter (sub.class_field sub) cstr_fields
let row_field sub {rf_loc; rf_desc; rf_attributes; _} =
sub.location sub rf_loc;
sub.attributes sub rf_attributes;
match rf_desc with
| Ttag (s, _, list) -> iter_loc sub s; List.iter (sub.typ sub) list
| Tinherit ct -> sub.typ sub ct
let object_field sub {of_loc; of_desc; of_attributes; _} =
sub.location sub of_loc;
sub.attributes sub of_attributes;
match of_desc with
| OTtag (s, ct) -> iter_loc sub s; sub.typ sub ct
| OTinherit ct -> sub.typ sub ct
let class_field_kind sub = function
| Tcfk_virtual ct -> sub.typ sub ct
| Tcfk_concrete (_, e) -> sub.expr sub e
let class_field sub {cf_loc; cf_desc; cf_attributes; _} =
sub.location sub cf_loc;
sub.attributes sub cf_attributes;
match cf_desc with
| Tcf_inherit (_, cl, _, _, _) -> sub.class_expr sub cl
| Tcf_constraint (cty1, cty2) ->
sub.typ sub cty1;
sub.typ sub cty2
| Tcf_val (s, _, _, k, _) -> iter_loc sub s; class_field_kind sub k
| Tcf_method (s, _, k) -> iter_loc sub s;class_field_kind sub k
| Tcf_initializer exp -> sub.expr sub exp
| Tcf_attribute attr -> sub.attribute sub attr
let value_bindings sub (_, list) = List.iter (sub.value_binding sub) list
let case sub {c_lhs; c_guard; c_rhs} =
sub.pat sub c_lhs;
Option.iter (sub.expr sub) c_guard;
sub.expr sub c_rhs
let value_binding sub {vb_loc; vb_pat; vb_expr; vb_attributes; _} =
sub.location sub vb_loc;
sub.attributes sub vb_attributes;
sub.pat sub vb_pat;
sub.expr sub vb_expr
let env _sub _ = ()
let jkind_annotation _sub _ = ()
let default_iterator =
{
attribute;
attributes;
binding_op;
case;
class_declaration;
class_description;
class_expr;
class_field;
class_signature;
class_structure;
class_type;
class_type_declaration;
class_type_field;
env;
expr;
extension_constructor;
jkind_annotation;
location;
module_binding;
module_coercion;
module_declaration;
module_substitution;
module_expr;
module_type;
module_type_declaration;
package_type;
pat;
row_field;
object_field;
open_declaration;
open_description;
signature;
signature_item;
structure;
structure_item;
typ;
type_declaration;
type_declarations;
type_extension;
type_exception;
type_kind;
value_binding;
value_bindings;
value_description;
with_constraint;
}