1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Richard Carlsson.
13
%% Copyright (C) 1999-2002 Richard Carlsson.
14
%% Portions created by Ericsson are Copyright 2001, Ericsson Utvecklings
15
%% AB. All Rights Reserved.''
17
%% $Id: cerl_trees.erl,v 1.2 2010/06/07 06:32:39 kostis Exp $
19
%% @doc Basic functions on Core Erlang abstract syntax trees.
21
%% <p>Syntax trees are defined in the module <a
22
%% href=""><code>cerl</code></a>.</p>
24
%% @type cerl() = cerl:cerl()
28
-export([depth/1, fold/3, free_variables/1, label/1, label/2, map/2,
29
mapfold/3, size/1, variables/1]).
31
-import(cerl, [alias_pat/1, alias_var/1, ann_c_alias/3, ann_c_apply/3,
32
ann_c_binary/2, ann_c_bitstr/6, ann_c_call/4,
33
ann_c_case/3, ann_c_catch/2, ann_c_clause/4,
34
ann_c_cons_skel/3, ann_c_fun/3, ann_c_let/4,
35
ann_c_letrec/3, ann_c_module/5, ann_c_primop/3,
36
ann_c_receive/4, ann_c_seq/3, ann_c_try/6,
37
ann_c_tuple_skel/2, ann_c_values/2, apply_args/1,
38
apply_op/1, binary_segments/1, bitstr_val/1,
39
bitstr_size/1, bitstr_unit/1, bitstr_type/1,
40
bitstr_flags/1, call_args/1, call_module/1, call_name/1,
41
case_arg/1, case_clauses/1, catch_body/1, clause_body/1,
42
clause_guard/1, clause_pats/1, clause_vars/1, concrete/1,
43
cons_hd/1, cons_tl/1, fun_body/1, fun_vars/1, get_ann/1,
44
let_arg/1, let_body/1, let_vars/1, letrec_body/1,
45
letrec_defs/1, letrec_vars/1, module_attrs/1,
46
module_defs/1, module_exports/1, module_name/1,
47
module_vars/1, primop_args/1, primop_name/1,
48
receive_action/1, receive_clauses/1, receive_timeout/1,
49
seq_arg/1, seq_body/1, set_ann/2, subtrees/1, try_arg/1,
50
try_body/1, try_vars/1, try_evars/1, try_handler/1,
51
tuple_es/1, type/1, update_c_alias/3, update_c_apply/3,
52
update_c_binary/2, update_c_bitstr/6, update_c_call/4,
53
update_c_case/3, update_c_catch/2, update_c_clause/4,
54
update_c_cons/3, update_c_cons_skel/3, update_c_fun/3,
55
update_c_let/4, update_c_letrec/3, update_c_module/5,
56
update_c_primop/3, update_c_receive/4, update_c_seq/3,
57
update_c_try/6, update_c_tuple/2, update_c_tuple_skel/2,
58
update_c_values/2, values_es/1, var_name/1]).
61
%% ---------------------------------------------------------------------
63
%% @spec depth(Tree::cerl) -> integer()
65
%% @doc Returns the length of the longest path in the tree. A leaf
66
%% node has depth zero, the tree representing "<code>{foo,
67
%% bar}</code>" has depth one, etc.
74
1 + lists:foldl(fun (G, A) -> erlang:max(depth_1(G), A) end, 0, Gs)
78
lists:foldl(fun (T, A) -> erlang:max(depth(T), A) end, 0, Ts).
80
%% max(X, Y) when X > Y -> X;
84
%% @spec size(Tree::cerl()) -> integer()
86
%% @doc Returns the number of nodes in <code>Tree</code>.
89
fold(fun (_, S) -> S + 1 end, 0, T).
92
%% ---------------------------------------------------------------------
94
%% @spec map(Function, Tree::cerl()) -> cerl()
96
%% Function = (cerl()) -> cerl()
98
%% @doc Maps a function onto the nodes of a tree. This replaces each
99
%% node in the tree by the result of applying the given function on
100
%% the original node, bottom-up.
112
update_c_cons(T, map(F, cons_hd(T)),
114
V when tuple_size(V) > 0 ->
115
update_c_tuple(T, map_list(F, tuple_es(T)));
122
update_c_values(T, map_list(F, values_es(T)));
124
update_c_cons_skel(T, map(F, cons_hd(T)),
127
update_c_tuple_skel(T, map_list(F, tuple_es(T)));
129
update_c_let(T, map_list(F, let_vars(T)),
131
map(F, let_body(T)));
133
update_c_seq(T, map(F, seq_arg(T)),
134
map(F, seq_body(T)));
136
update_c_apply(T, map(F, apply_op(T)),
137
map_list(F, apply_args(T)));
139
update_c_call(T, map(F, call_module(T)),
140
map(F, call_name(T)),
141
map_list(F, call_args(T)));
143
update_c_primop(T, map(F, primop_name(T)),
144
map_list(F, primop_args(T)));
146
update_c_case(T, map(F, case_arg(T)),
147
map_list(F, case_clauses(T)));
149
update_c_clause(T, map_list(F, clause_pats(T)),
150
map(F, clause_guard(T)),
151
map(F, clause_body(T)));
153
update_c_alias(T, map(F, alias_var(T)),
154
map(F, alias_pat(T)));
156
update_c_fun(T, map_list(F, fun_vars(T)),
157
map(F, fun_body(T)));
159
update_c_receive(T, map_list(F, receive_clauses(T)),
160
map(F, receive_timeout(T)),
161
map(F, receive_action(T)));
163
update_c_try(T, map(F, try_arg(T)),
164
map_list(F, try_vars(T)),
166
map_list(F, try_evars(T)),
167
map(F, try_handler(T)));
169
update_c_catch(T, map(F, catch_body(T)));
171
update_c_binary(T, map_list(F, binary_segments(T)));
173
update_c_bitstr(T, map(F, bitstr_val(T)),
174
map(F, bitstr_size(T)),
175
map(F, bitstr_unit(T)),
176
map(F, bitstr_type(T)),
177
map(F, bitstr_flags(T)));
179
update_c_letrec(T, map_pairs(F, letrec_defs(T)),
180
map(F, letrec_body(T)));
182
update_c_module(T, map(F, module_name(T)),
183
map_list(F, module_exports(T)),
184
map_pairs(F, module_attrs(T)),
185
map_pairs(F, module_defs(T)))
188
map_list(F, [T | Ts]) ->
189
[map(F, T) | map_list(F, Ts)];
193
map_pairs(F, [{T1, T2} | Ps]) ->
194
[{map(F, T1), map(F, T2)} | map_pairs(F, Ps)];
199
%% @spec fold(Function, Unit::term(), Tree::cerl()) -> term()
201
%% Function = (cerl(), term()) -> term()
203
%% @doc Does a fold operation over the nodes of the tree. The result
204
%% is the value of <code>Function(X1, Function(X2, ... Function(Xn,
205
%% Unit) ... ))</code>, where <code>X1, ..., Xn</code> are the nodes
206
%% of <code>Tree</code> in a post-order traversal.
211
F(T, fold_1(F, S, T)).
218
fold(F, fold(F, S, cons_hd(T)), cons_tl(T));
219
V when tuple_size(V) > 0 ->
220
fold_list(F, S, tuple_es(T));
227
fold_list(F, S, values_es(T));
229
fold(F, fold(F, S, cons_hd(T)), cons_tl(T));
231
fold_list(F, S, tuple_es(T));
233
fold(F, fold(F, fold_list(F, S, let_vars(T)),
237
fold(F, fold(F, S, seq_arg(T)), seq_body(T));
239
fold_list(F, fold(F, S, apply_op(T)), apply_args(T));
241
fold_list(F, fold(F, fold(F, S, call_module(T)),
245
fold_list(F, fold(F, S, primop_name(T)), primop_args(T));
247
fold_list(F, fold(F, S, case_arg(T)), case_clauses(T));
249
fold(F, fold(F, fold_list(F, S, clause_pats(T)),
253
fold(F, fold(F, S, alias_var(T)), alias_pat(T));
255
fold(F, fold_list(F, S, fun_vars(T)), fun_body(T));
257
fold(F, fold(F, fold_list(F, S, receive_clauses(T)),
261
fold(F, fold_list(F, fold(F, fold_list(F, fold(F, S, try_arg(T)),
267
fold(F, S, catch_body(T));
269
fold_list(F, S, binary_segments(T));
275
fold(F, S, bitstr_val(T)),
281
fold(F, fold_pairs(F, S, letrec_defs(T)), letrec_body(T));
286
fold(F, S, module_name(T)),
292
fold_list(F, S, [T | Ts]) ->
293
fold_list(F, fold(F, S, T), Ts);
294
fold_list(_, S, []) ->
297
fold_pairs(F, S, [{T1, T2} | Ps]) ->
298
fold_pairs(F, fold(F, fold(F, S, T1), T2), Ps);
299
fold_pairs(_, S, []) ->
303
%% @spec mapfold(Function, Initial::term(), Tree::cerl()) ->
306
%% Function = (cerl(), term()) -> {cerl(), term()}
308
%% @doc Does a combined map/fold operation on the nodes of the
309
%% tree. This is similar to <code>map/2</code>, but also propagates a
310
%% value from each application of <code>Function</code> to the next,
311
%% starting with the given value <code>Initial</code>, while doing a
312
%% post-order traversal of the tree, much like <code>fold/3</code>.
322
{T1, S1} = mapfold(F, S0, cons_hd(T)),
323
{T2, S2} = mapfold(F, S1, cons_tl(T)),
324
F(update_c_cons(T, T1, T2), S2);
325
V when tuple_size(V) > 0 ->
326
{Ts, S1} = mapfold_list(F, S0, tuple_es(T)),
327
F(update_c_tuple(T, Ts), S1);
334
{Ts, S1} = mapfold_list(F, S0, values_es(T)),
335
F(update_c_values(T, Ts), S1);
337
{T1, S1} = mapfold(F, S0, cons_hd(T)),
338
{T2, S2} = mapfold(F, S1, cons_tl(T)),
339
F(update_c_cons_skel(T, T1, T2), S2);
341
{Ts, S1} = mapfold_list(F, S0, tuple_es(T)),
342
F(update_c_tuple_skel(T, Ts), S1);
344
{Vs, S1} = mapfold_list(F, S0, let_vars(T)),
345
{A, S2} = mapfold(F, S1, let_arg(T)),
346
{B, S3} = mapfold(F, S2, let_body(T)),
347
F(update_c_let(T, Vs, A, B), S3);
349
{A, S1} = mapfold(F, S0, seq_arg(T)),
350
{B, S2} = mapfold(F, S1, seq_body(T)),
351
F(update_c_seq(T, A, B), S2);
353
{E, S1} = mapfold(F, S0, apply_op(T)),
354
{As, S2} = mapfold_list(F, S1, apply_args(T)),
355
F(update_c_apply(T, E, As), S2);
357
{M, S1} = mapfold(F, S0, call_module(T)),
358
{N, S2} = mapfold(F, S1, call_name(T)),
359
{As, S3} = mapfold_list(F, S2, call_args(T)),
360
F(update_c_call(T, M, N, As), S3);
362
{N, S1} = mapfold(F, S0, primop_name(T)),
363
{As, S2} = mapfold_list(F, S1, primop_args(T)),
364
F(update_c_primop(T, N, As), S2);
366
{A, S1} = mapfold(F, S0, case_arg(T)),
367
{Cs, S2} = mapfold_list(F, S1, case_clauses(T)),
368
F(update_c_case(T, A, Cs), S2);
370
{Ps, S1} = mapfold_list(F, S0, clause_pats(T)),
371
{G, S2} = mapfold(F, S1, clause_guard(T)),
372
{B, S3} = mapfold(F, S2, clause_body(T)),
373
F(update_c_clause(T, Ps, G, B), S3);
375
{V, S1} = mapfold(F, S0, alias_var(T)),
376
{P, S2} = mapfold(F, S1, alias_pat(T)),
377
F(update_c_alias(T, V, P), S2);
379
{Vs, S1} = mapfold_list(F, S0, fun_vars(T)),
380
{B, S2} = mapfold(F, S1, fun_body(T)),
381
F(update_c_fun(T, Vs, B), S2);
383
{Cs, S1} = mapfold_list(F, S0, receive_clauses(T)),
384
{E, S2} = mapfold(F, S1, receive_timeout(T)),
385
{A, S3} = mapfold(F, S2, receive_action(T)),
386
F(update_c_receive(T, Cs, E, A), S3);
388
{E, S1} = mapfold(F, S0, try_arg(T)),
389
{Vs, S2} = mapfold_list(F, S1, try_vars(T)),
390
{B, S3} = mapfold(F, S2, try_body(T)),
391
{Evs, S4} = mapfold_list(F, S3, try_evars(T)),
392
{H, S5} = mapfold(F, S4, try_handler(T)),
393
F(update_c_try(T, E, Vs, B, Evs, H), S5);
395
{B, S1} = mapfold(F, S0, catch_body(T)),
396
F(update_c_catch(T, B), S1);
398
{Ds, S1} = mapfold_list(F, S0, binary_segments(T)),
399
F(update_c_binary(T, Ds), S1);
401
{Val, S1} = mapfold(F, S0, bitstr_val(T)),
402
{Size, S2} = mapfold(F, S1, bitstr_size(T)),
403
{Unit, S3} = mapfold(F, S2, bitstr_unit(T)),
404
{Type, S4} = mapfold(F, S3, bitstr_type(T)),
405
{Flags, S5} = mapfold(F, S4, bitstr_flags(T)),
406
F(update_c_bitstr(T, Val, Size, Unit, Type, Flags), S5);
408
{Ds, S1} = mapfold_pairs(F, S0, letrec_defs(T)),
409
{B, S2} = mapfold(F, S1, letrec_body(T)),
410
F(update_c_letrec(T, Ds, B), S2);
412
{N, S1} = mapfold(F, S0, module_name(T)),
413
{Es, S2} = mapfold_list(F, S1, module_exports(T)),
414
{As, S3} = mapfold_pairs(F, S2, module_attrs(T)),
415
{Ds, S4} = mapfold_pairs(F, S3, module_defs(T)),
416
F(update_c_module(T, N, Es, As, Ds), S4)
419
mapfold_list(F, S0, [T | Ts]) ->
420
{T1, S1} = mapfold(F, S0, T),
421
{Ts1, S2} = mapfold_list(F, S1, Ts),
423
mapfold_list(_, S, []) ->
426
mapfold_pairs(F, S0, [{T1, T2} | Ps]) ->
427
{T3, S1} = mapfold(F, S0, T1),
428
{T4, S2} = mapfold(F, S1, T2),
429
{Ps1, S3} = mapfold_pairs(F, S2, Ps),
430
{[{T3, T4} | Ps1], S3};
431
mapfold_pairs(_, S, []) ->
435
%% ---------------------------------------------------------------------
437
%% @spec variables(Tree::cerl()) -> [var_name()]
439
%% var_name() = integer() | atom() | {atom(), integer()}
441
%% @doc Returns an ordered-set list of the names of all variables in
442
%% the syntax tree. (This includes function name variables.) An
443
%% exception is thrown if <code>Tree</code> does not represent a
444
%% well-formed Core Erlang syntax tree.
446
%% @see free_variables/1
452
%% @spec free_variables(Tree::cerl()) -> [var_name()]
454
%% @doc Like <code>variables/1</code>, but only includes variables
455
%% that are free in the tree.
463
%% This is not exported
472
vars_in_list(values_es(T), S);
474
ordsets:union(variables(cons_hd(T), S),
475
variables(cons_tl(T), S));
477
vars_in_list(tuple_es(T), S);
479
Vs = variables(let_body(T), S),
480
Vs1 = var_list_names(let_vars(T)),
483
ordsets:subtract(Vs, Vs1);
485
ordsets:union(Vs, Vs1)
487
ordsets:union(variables(let_arg(T), S), Vs2);
489
ordsets:union(variables(seq_arg(T), S),
490
variables(seq_body(T), S));
493
variables(apply_op(T), S),
494
vars_in_list(apply_args(T), S));
496
ordsets:union(variables(call_module(T), S),
498
variables(call_name(T), S),
499
vars_in_list(call_args(T), S)));
501
vars_in_list(primop_args(T), S);
503
ordsets:union(variables(case_arg(T), S),
504
vars_in_list(case_clauses(T), S));
506
Vs = ordsets:union(variables(clause_guard(T), S),
507
variables(clause_body(T), S)),
508
Vs1 = vars_in_list(clause_pats(T), S),
511
ordsets:subtract(Vs, Vs1);
513
ordsets:union(Vs, Vs1)
516
ordsets:add_element(var_name(alias_var(T)),
517
variables(alias_pat(T)));
519
Vs = variables(fun_body(T), S),
520
Vs1 = var_list_names(fun_vars(T)),
523
ordsets:subtract(Vs, Vs1);
525
ordsets:union(Vs, Vs1)
529
vars_in_list(receive_clauses(T), S),
530
ordsets:union(variables(receive_timeout(T), S),
531
variables(receive_action(T), S)));
533
Vs = variables(try_body(T), S),
534
Vs1 = var_list_names(try_vars(T)),
537
ordsets:subtract(Vs, Vs1);
539
ordsets:union(Vs, Vs1)
541
Vs3 = variables(try_handler(T), S),
542
Vs4 = var_list_names(try_evars(T)),
545
ordsets:subtract(Vs3, Vs4);
547
ordsets:union(Vs3, Vs4)
549
ordsets:union(variables(try_arg(T), S),
550
ordsets:union(Vs2, Vs5));
552
variables(catch_body(T), S);
554
vars_in_list(binary_segments(T), S);
556
ordsets:union(variables(bitstr_val(T), S),
557
variables(bitstr_size(T), S));
559
Vs = vars_in_defs(letrec_defs(T), S),
560
Vs1 = ordsets:union(variables(letrec_body(T), S), Vs),
561
Vs2 = var_list_names(letrec_vars(T)),
564
ordsets:subtract(Vs1, Vs2);
566
ordsets:union(Vs1, Vs2)
569
Vs = vars_in_defs(module_defs(T), S),
570
Vs1 = ordsets:union(vars_in_list(module_exports(T), S), Vs),
571
Vs2 = var_list_names(module_vars(T)),
574
ordsets:subtract(Vs1, Vs2);
576
ordsets:union(Vs1, Vs2)
580
vars_in_list(Ts, S) ->
581
vars_in_list(Ts, S, []).
583
vars_in_list([T | Ts], S, A) ->
584
vars_in_list(Ts, S, ordsets:union(variables(T, S), A));
585
vars_in_list([], _, A) ->
588
%% Note that this function only visits the right-hand side of function
591
vars_in_defs(Ds, S) ->
592
vars_in_defs(Ds, S, []).
594
vars_in_defs([{_, F} | Ds], S, A) ->
595
vars_in_defs(Ds, S, ordsets:union(variables(F, S), A));
596
vars_in_defs([], _, A) ->
599
%% This amounts to insertion sort. Since the lists are generally short,
600
%% it is hardly worthwhile to use an asymptotically better sort.
602
var_list_names(Vs) ->
603
var_list_names(Vs, []).
605
var_list_names([V | Vs], A) ->
606
var_list_names(Vs, ordsets:add_element(var_name(V), A));
607
var_list_names([], A) ->
611
%% ---------------------------------------------------------------------
613
%% label(Tree::cerl()) -> {cerl(), integer()}
615
%% @equiv label(Tree, 0)
620
%% @spec label(Tree::cerl(), N::integer()) -> {cerl(), integer()}
622
%% @doc Labels each expression in the tree. A term <code>{label,
623
%% L}</code> is prefixed to the annotation list of each expression node,
624
%% where L is a unique number for every node, except for variables (and
625
%% function name variables) which get the same label if they represent
626
%% the same variable. Constant literal nodes are not labeled.
628
%% <p>The returned value is a tuple <code>{NewTree, Max}</code>, where
629
%% <code>NewTree</code> is the labeled tree and <code>Max</code> is 1
630
%% plus the largest label value used. All previous annotation terms on
631
%% the form <code>{label, X}</code> are deleted.</p>
633
%% <p>The values of L used in the tree is a dense range from
634
%% <code>N</code> to <code>Max - 1</code>, where <code>N =< Max
635
%% =< N + size(Tree)</code>. Note that it is possible that no
636
%% labels are used at all, i.e., <code>N = Max</code>.</p>
638
%% <p>Note: All instances of free variables will be given distinct
645
label(T, N, dict:new()).
650
%% Constant literals are not labeled.
653
case dict:find(var_name(T), Env) of
655
{As, _} = label_ann(T, L),
658
{As, N1} = label_ann(T, N)
660
{set_ann(T, As), N1};
662
{Ts, N1} = label_list(values_es(T), N, Env),
663
{As, N2} = label_ann(T, N1),
664
{ann_c_values(As, Ts), N2};
666
{T1, N1} = label(cons_hd(T), N, Env),
667
{T2, N2} = label(cons_tl(T), N1, Env),
668
{As, N3} = label_ann(T, N2),
669
{ann_c_cons_skel(As, T1, T2), N3};
671
{Ts, N1} = label_list(tuple_es(T), N, Env),
672
{As, N2} = label_ann(T, N1),
673
{ann_c_tuple_skel(As, Ts), N2};
675
{A, N1} = label(let_arg(T), N, Env),
676
{Vs, N2, Env1} = label_vars(let_vars(T), N1, Env),
677
{B, N3} = label(let_body(T), N2, Env1),
678
{As, N4} = label_ann(T, N3),
679
{ann_c_let(As, Vs, A, B), N4};
681
{A, N1} = label(seq_arg(T), N, Env),
682
{B, N2} = label(seq_body(T), N1, Env),
683
{As, N3} = label_ann(T, N2),
684
{ann_c_seq(As, A, B), N3};
686
{E, N1} = label(apply_op(T), N, Env),
687
{Es, N2} = label_list(apply_args(T), N1, Env),
688
{As, N3} = label_ann(T, N2),
689
{ann_c_apply(As, E, Es), N3};
691
{M, N1} = label(call_module(T), N, Env),
692
{F, N2} = label(call_name(T), N1, Env),
693
{Es, N3} = label_list(call_args(T), N2, Env),
694
{As, N4} = label_ann(T, N3),
695
{ann_c_call(As, M, F, Es), N4};
697
{F, N1} = label(primop_name(T), N, Env),
698
{Es, N2} = label_list(primop_args(T), N1, Env),
699
{As, N3} = label_ann(T, N2),
700
{ann_c_primop(As, F, Es), N3};
702
{A, N1} = label(case_arg(T), N, Env),
703
{Cs, N2} = label_list(case_clauses(T), N1, Env),
704
{As, N3} = label_ann(T, N2),
705
{ann_c_case(As, A, Cs), N3};
707
{_, N1, Env1} = label_vars(clause_vars(T), N, Env),
708
{Ps, N2} = label_list(clause_pats(T), N1, Env1),
709
{G, N3} = label(clause_guard(T), N2, Env1),
710
{B, N4} = label(clause_body(T), N3, Env1),
711
{As, N5} = label_ann(T, N4),
712
{ann_c_clause(As, Ps, G, B), N5};
714
{V, N1} = label(alias_var(T), N, Env),
715
{P, N2} = label(alias_pat(T), N1, Env),
716
{As, N3} = label_ann(T, N2),
717
{ann_c_alias(As, V, P), N3};
719
{Vs, N1, Env1} = label_vars(fun_vars(T), N, Env),
720
{B, N2} = label(fun_body(T), N1, Env1),
721
{As, N3} = label_ann(T, N2),
722
{ann_c_fun(As, Vs, B), N3};
724
{Cs, N1} = label_list(receive_clauses(T), N, Env),
725
{E, N2} = label(receive_timeout(T), N1, Env),
726
{A, N3} = label(receive_action(T), N2, Env),
727
{As, N4} = label_ann(T, N3),
728
{ann_c_receive(As, Cs, E, A), N4};
730
{E, N1} = label(try_arg(T), N, Env),
731
{Vs, N2, Env1} = label_vars(try_vars(T), N1, Env),
732
{B, N3} = label(try_body(T), N2, Env1),
733
{Evs, N4, Env2} = label_vars(try_evars(T), N3, Env),
734
{H, N5} = label(try_handler(T), N4, Env2),
735
{As, N6} = label_ann(T, N5),
736
{ann_c_try(As, E, Vs, B, Evs, H), N6};
738
{B, N1} = label(catch_body(T), N, Env),
739
{As, N2} = label_ann(T, N1),
740
{ann_c_catch(As, B), N2};
742
{Ds, N1} = label_list(binary_segments(T), N, Env),
743
{As, N2} = label_ann(T, N1),
744
{ann_c_binary(As, Ds), N2};
746
{Val, N1} = label(bitstr_val(T), N, Env),
747
{Size, N2} = label(bitstr_size(T), N1, Env),
748
{Unit, N3} = label(bitstr_unit(T), N2, Env),
749
{Type, N4} = label(bitstr_type(T), N3, Env),
750
{Flags, N5} = label(bitstr_flags(T), N4, Env),
751
{As, N6} = label_ann(T, N5),
752
{ann_c_bitstr(As, Val, Size, Unit, Type, Flags), N6};
754
{_, N1, Env1} = label_vars(letrec_vars(T), N, Env),
755
{Ds, N2} = label_defs(letrec_defs(T), N1, Env1),
756
{B, N3} = label(letrec_body(T), N2, Env1),
757
{As, N4} = label_ann(T, N3),
758
{ann_c_letrec(As, Ds, B), N4};
760
%% The module name is not labeled.
761
{_, N1, Env1} = label_vars(module_vars(T), N, Env),
762
{Ts, N2} = label_defs(module_attrs(T), N1, Env1),
763
{Ds, N3} = label_defs(module_defs(T), N2, Env1),
764
{Es, N4} = label_list(module_exports(T), N3, Env1),
765
{As, N5} = label_ann(T, N4),
766
{ann_c_module(As, module_name(T), Es, Ts, Ds), N5}
769
label_list([T | Ts], N, Env) ->
770
{T1, N1} = label(T, N, Env),
771
{Ts1, N2} = label_list(Ts, N1, Env),
773
label_list([], N, _Env) ->
776
label_vars([T | Ts], N, Env) ->
777
Env1 = dict:store(var_name(T), N, Env),
778
{As, N1} = label_ann(T, N),
780
{Ts1, N2, Env2} = label_vars(Ts, N1, Env1),
781
{[T1 | Ts1], N2, Env2};
782
label_vars([], N, Env) ->
785
label_defs([{F, T} | Ds], N, Env) ->
786
{F1, N1} = label(F, N, Env),
787
{T1, N2} = label(T, N1, Env),
788
{Ds1, N3} = label_defs(Ds, N2, Env),
789
{[{F1, T1} | Ds1], N3};
790
label_defs([], N, _Env) ->
794
{[{label, N} | filter_labels(get_ann(T))], N + 1}.
796
filter_labels([{label, _} | As]) ->
798
filter_labels([A | As]) ->
799
[A | filter_labels(As)];