1cerl(3) Erlang Module Definition cerl(3)
2
3
4
6 cerl - Core Erlang abstract syntax trees.
7
9 Core Erlang abstract syntax trees.
10
11 This module defines an abstract data type for representing Core Erlang
12 source code as syntax trees.
13
14 A recommended starting point for the first-time user is the documenta‐
15 tion of the function type/1.
16
17 NOTES:
18
19 This module deals with the composition and decomposition of syntactic
20 entities (as opposed to semantic ones); its purpose is to hide all
21 direct references to the data structures used to represent these enti‐
22 ties. With few exceptions, the functions in this module perform no
23 semantic interpretation of their inputs, and in general, the user is
24 assumed to pass type-correct arguments - if this is not done, the
25 effects are not defined.
26
27 Currently, the internal data structure used is the same as the record-
28 based data structures used traditionally in the Beam compiler.
29
30 The internal representations of abstract syntax trees are subject to
31 change without notice, and should not be documented outside this mod‐
32 ule. Furthermore, we do not give any guarantees on how an abstract syn‐
33 tax tree may or may not be represented, with the following exceptions:
34 no syntax tree is represented by a single atom, such as none, by a list
35 constructor [X | Y], or by the empty list []. This can be relied on
36 when writing functions that operate on syntax trees.
37
39 c_binary() = #c_binary{}:
40
41
42 c_bitstr() = #c_bitstr{}:
43
44
45 c_call() = #c_call{}:
46
47
48 c_clause() = #c_clause{}:
49
50
51 c_cons() = #c_cons{}:
52
53
54 c_fun() = #c_fun{}:
55
56
57 c_let() = #c_let{}:
58
59
60 c_literal() = #c_literal{}:
61
62
63 c_map() = #c_map{}:
64
65
66 c_map_pair() = #c_map_pair{}:
67
68
69 c_module() = #c_module{}:
70
71
72 c_tuple() = #c_tuple{}:
73
74
75 c_values() = #c_values{}:
76
77
78 c_var() = #c_var{}:
79
80
81 cerl():
82
83
84 An abstract Core Erlang syntax tree.
85
86 Every abstract syntax tree has a type, given by the function
87 type/1. In addition, each syntax tree has a list of user annota‐
88 tions (cf. get_ann/1), which are included in the Core Erlang syn‐
89 tax.
90
91 map_op() = #c_literal{val=assoc} | #c_literal{val=exact}:
92
93
94 var_name() = integer() | atom() | {atom(), integer()}:
95
96
98 abstract(Term::term()) -> cerl()
99
100 Creates a syntax tree corresponding to an Erlang term. Term must
101 be a literal term, i.e., one that can be represented as a source
102 code literal. Thus, it may not contain a process identifier,
103 port, reference, binary or function value as a subterm.
104
105 Note: This is a constant time operation.
106
107 See also: ann_abstract/2, concrete/1, is_literal/1, is_lit‐
108 eral_term/1.
109
110 add_ann(Annotations::[term()], Node::cerl()) -> cerl()
111
112 Appends Annotations to the list of user annotations of Node.
113
114 Note: this is equivalent to set_ann(Node, Annotations ++
115 get_ann(Node)), but potentially more efficient.
116
117 See also: get_ann/1, set_ann/2.
118
119 alias_pat(Node::cerl()) -> cerl()
120
121 Returns the pattern subtree of an abstract pattern alias.
122
123 See also: c_alias/2.
124
125 alias_var(Node::cerl()) -> cerl()
126
127 Returns the variable subtree of an abstract pattern alias.
128
129 See also: c_alias/2.
130
131 ann_abstract(Annotations::[term()], Term::term()) -> cerl()
132
133 See also: abstract/1.
134
135 ann_c_alias(As::[term()], Variable::cerl(), Pattern::cerl()) -> cerl()
136
137 See also: c_alias/2.
138
139 ann_c_apply(As::[term()], Operator::cerl(), Arguments::[cerl()]) ->
140 cerl()
141
142 See also: c_apply/2.
143
144 ann_c_atom(As::[term()], Name) -> cerl()
145
146 Types:
147
148 Name = atom() | string()
149
150 See also: c_atom/1.
151
152 ann_c_binary(As::[term()], Segments::[cerl()]) -> cerl()
153
154 See also: c_binary/1.
155
156 ann_c_bitstr(As::[term()], Value::cerl(), Size::cerl(), Type::cerl(),
157 Flags::cerl()) -> cerl()
158
159 Equivalent to ann_c_bitstr(As, Value, Size, abstract(1), Type,
160 Flags).
161
162 ann_c_bitstr(As::[term()], Value::cerl(), Size::cerl(), Unit::cerl(),
163 Type::cerl(), Flags::cerl()) -> cerl()
164
165 See also: ann_c_bitstr/5, c_bitstr/5.
166
167 ann_c_call(As::[term()], Module::cerl(), Name::cerl(), Argu‐
168 ments::[cerl()]) -> cerl()
169
170 See also: c_call/3.
171
172 ann_c_case(As::[term()], Argument::cerl(), Clauses::[cerl()]) -> cerl()
173
174 See also: c_case/2.
175
176 ann_c_catch(As::[term()], Body::cerl()) -> cerl()
177
178 See also: c_catch/1.
179
180 ann_c_char(As::[term()], Value::char()) -> cerl()
181
182 See also: c_char/1.
183
184 ann_c_clause(As::[term()], Patterns::[cerl()], Body::cerl()) -> cerl()
185
186 Equivalent to ann_c_clause(As, Patterns, c_atom(true), Body).
187
188 See also: c_clause/3.
189
190 ann_c_clause(As::[term()], Patterns::[cerl()], Guard::cerl(),
191 Body::cerl()) -> cerl()
192
193 See also: ann_c_clause/3, c_clause/3.
194
195 ann_c_cons(As::[term()], Head::cerl(), Tail::cerl()) -> cerl()
196
197 See also: c_cons/2.
198
199 ann_c_cons_skel(As::[term()], Head::cerl(), Tail::cerl()) -> cerl()
200
201 See also: c_cons_skel/2.
202
203 ann_c_float(As::[term()], Value::float()) -> cerl()
204
205 See also: c_float/1.
206
207 ann_c_fname(As::[term()], Name::atom(), Arity::arity()) -> cerl()
208
209 Equivalent to ann_c_var(As, {Atom, Arity}).
210
211 See also: c_fname/2.
212
213 ann_c_fun(As::[term()], Variables::[cerl()], Body::cerl()) -> cerl()
214
215 See also: c_fun/2.
216
217 ann_c_int(As::[term()], Value::integer()) -> cerl()
218
219 See also: c_int/1.
220
221 ann_c_let(As::[term()], Variables::[cerl()], Argument::cerl(),
222 Body::cerl()) -> c_let()
223
224 See also: c_let/3.
225
226 ann_c_letrec(As::[term()], Definitions::[{cerl(), cerl()}],
227 Body::cerl()) -> cerl()
228
229 See also: c_letrec/2.
230
231 ann_c_map(As::[term()], Es::[c_map_pair()]) -> c_map() | c_literal()
232
233 ann_c_map(As::[term()], C_literal::c_map() | c_literal(),
234 Es::[c_map_pair()]) -> c_map() | c_literal()
235
236 ann_c_map_pair(As::[term()], Op::cerl(), K::cerl(), V::cerl()) ->
237 c_map_pair()
238
239 ann_c_map_pattern(As::[term()], Pairs::[c_map_pair()]) -> c_map()
240
241 ann_c_module(As::[term()], Name::cerl(), Exports, Es::Definitions) ->
242 cerl()
243
244 Types:
245
246 Exports = [cerl()]
247 Definitions = [{cerl(), cerl()}]
248
249 See also: ann_c_module/5, c_module/3.
250
251 ann_c_module(As::[term()], Name::cerl(), Exports, Attrs::Attributes,
252 Es::Definitions) -> cerl()
253
254 Types:
255
256 Exports = [cerl()]
257 Attributes = [{cerl(), cerl()}]
258 Definitions = [{cerl(), cerl()}]
259
260 See also: ann_c_module/4, c_module/4.
261
262 ann_c_nil(As::[term()]) -> cerl()
263
264 See also: c_nil/0.
265
266 ann_c_primop(As::[term()], Name::cerl(), Arguments::[cerl()]) -> cerl()
267
268 See also: c_primop/2.
269
270 ann_c_receive(As::[term()], Clauses::[cerl()]) -> cerl()
271
272 Equivalent to ann_c_receive(As, Clauses, c_atom(infinity),
273 c_atom(true)).
274
275 See also: c_atom/1, c_receive/3.
276
277 ann_c_receive(As::[term()], Clauses::[cerl()], Timeout::cerl(),
278 Action::cerl()) -> cerl()
279
280 See also: ann_c_receive/2, c_receive/3.
281
282 ann_c_seq(As::[term()], Argument::cerl(), Body::cerl()) -> cerl()
283
284 See also: c_seq/2.
285
286 ann_c_string(As::[term()], Value::string()) -> cerl()
287
288 See also: c_string/1.
289
290 ann_c_try(As::[term()], Expression::cerl(), Variables::[cerl()],
291 Body::cerl(), EVars::[cerl()], Handler::cerl()) -> cerl()
292
293 See also: c_try/5.
294
295 ann_c_tuple(As::[term()], Elements::[cerl()]) -> cerl()
296
297 See also: c_tuple/1.
298
299 ann_c_tuple_skel(As::[term()], Elements::[cerl()]) -> cerl()
300
301 See also: c_tuple_skel/1.
302
303 ann_c_values(As::[term()], Elements::[cerl()]) -> cerl()
304
305 See also: c_values/1.
306
307 ann_c_var(As::[term()], Name::var_name()) -> cerl()
308
309 See also: c_var/1.
310
311 ann_make_data(As::[term()], Type::dtype(), Elements::[cerl()]) ->
312 cerl()
313
314 See also: make_data/2.
315
316 ann_make_data_skel(As::[term()], Type::dtype(), Elements::[cerl()]) ->
317 cerl()
318
319 See also: make_data_skel/2.
320
321 ann_make_list(As::[term()], List::[cerl()]) -> cerl()
322
323 Equivalent to ann_make_list(As, List, none).
324
325 ann_make_list(As::[term()], List::[cerl()], Tail) -> cerl()
326
327 Types:
328
329 Tail = cerl() | none
330
331 See also: ann_make_list/2, make_list/2.
332
333 ann_make_tree(As::[term()], Type::ctype(), Groups::[[cerl()]]) ->
334 cerl()
335
336 Creates a syntax tree with the given annotations, type and sub‐
337 trees. See make_tree/2 for details.
338
339 See also: make_tree/2.
340
341 apply_args(Node::cerl()) -> [cerl()]
342
343 Returns the list of argument subtrees of an abstract function
344 application.
345
346 See also: apply_arity/1, c_apply/2.
347
348 apply_arity(Node::cerl()) -> arity()
349
350 Returns the number of argument subtrees of an abstract function
351 application.
352
353 Note: this is equivalent to length(apply_args(Node)), but poten‐
354 tially more efficient.
355
356 See also: apply_args/1, c_apply/2.
357
358 apply_op(Node::cerl()) -> cerl()
359
360 Returns the operator subtree of an abstract function applica‐
361 tion.
362
363 See also: c_apply/2.
364
365 atom_lit(Node::cerl()) -> string()
366
367 Returns the literal string represented by an abstract atom. This
368 always includes surrounding single-quote characters.
369
370 Note that an abstract atom may have several literal representa‐
371 tions, and that the representation yielded by this function is
372 not fixed; e.g., atom_lit(c_atom("a\012b")) could yield the
373 string "\'a\\nb\'".
374
375 See also: c_atom/1.
376
377 atom_name(Node::cerl()) -> string()
378
379 Returns the printname of an abstract atom.
380
381 See also: c_atom/1.
382
383 atom_val(Node::cerl()) -> atom()
384
385 Returns the value represented by an abstract atom.
386
387 See also: c_atom/1.
388
389 binary_segments(Node::cerl()) -> [cerl()]
390
391 Returns the list of segment subtrees of an abstract binary-tem‐
392 plate.
393
394 See also: c_binary/1, c_bitstr/5.
395
396 bitstr_bitsize(Node::cerl()) -> any | all | utf | integer()
397
398 Returns the total size in bits of an abstract bit-string tem‐
399 plate. If the size field is an integer literal, the result is
400 the product of the size and unit values; if the size field is
401 the atom literal all, the atom all is returned. If the size is
402 not a literal, the atom any is returned.
403
404 See also: c_bitstr/5.
405
406 bitstr_flags(Node::cerl()) -> cerl()
407
408 Returns the flags subtree of an abstract bit-string template.
409
410 See also: c_bitstr/5.
411
412 bitstr_size(Node::cerl()) -> cerl()
413
414 Returns the size subtree of an abstract bit-string template.
415
416 See also: c_bitstr/5.
417
418 bitstr_type(Node::cerl()) -> cerl()
419
420 Returns the type subtree of an abstract bit-string template.
421
422 See also: c_bitstr/5.
423
424 bitstr_unit(Node::cerl()) -> cerl()
425
426 Returns the unit subtree of an abstract bit-string template.
427
428 See also: c_bitstr/5.
429
430 bitstr_val(Node::cerl()) -> cerl()
431
432 Returns the value subtree of an abstract bit-string template.
433
434 See also: c_bitstr/5.
435
436 c_alias(Variable::cerl(), Pattern::cerl()) -> cerl()
437
438 Creates an abstract pattern alias. The result represents "Vari‐
439 able = Pattern".
440
441 See also: alias_pat/1, alias_var/1, ann_c_alias/3, c_clause/3,
442 is_c_alias/1, update_c_alias/3.
443
444 c_apply(Operator::cerl(), Arguments::[cerl()]) -> cerl()
445
446 Creates an abstract function application. If Arguments is [A1,
447 ..., An], the result represents "apply Operator(A1, ..., An)".
448
449 See also: ann_c_apply/3, apply_args/1, apply_arity/1,
450 apply_op/1, c_call/3, c_primop/2, is_c_apply/1,
451 update_c_apply/3.
452
453 c_atom(Name) -> cerl()
454
455 Types:
456
457 Name = atom() | string()
458
459 Creates an abstract atom literal. The print name of the atom is
460 the character sequence represented by Name.
461
462 Note: passing a string as argument to this function causes a
463 corresponding atom to be created for the internal representa‐
464 tion.
465
466 See also: ann_c_atom/2, atom_lit/1, atom_name/1, atom_val/1,
467 is_c_atom/1.
468
469 c_binary(Segments::[cerl()]) -> cerl()
470
471 Creates an abstract binary-template. A binary object is in this
472 context a sequence of an arbitrary number of bits. (The number
473 of bits used to be evenly divisible by 8, but after the intro‐
474 duction of bit strings in the Erlang language, the choice was
475 made to use the binary template for all bit strings.) It is
476 specified by zero or more bit-string template segments of arbi‐
477 trary lengths (in number of bits). If Segments is [S1, ..., Sn],
478 the result represents "#{S1, ..., Sn}#". All the Si must have
479 type bitstr.
480
481 See also: ann_c_binary/2, binary_segments/1, c_bitstr/5,
482 is_c_binary/1, update_c_binary/2.
483
484 c_bitstr(Value::cerl(), Type::cerl(), Flags::cerl()) -> cerl()
485
486 Equivalent to c_bitstr(Value, abstract(all), abstract(1), Type,
487 Flags).
488
489 c_bitstr(Value::cerl(), Size::cerl(), Type::cerl(), Flags::cerl()) ->
490 cerl()
491
492 Equivalent to c_bitstr(Value, Size, abstract(1), Type, Flags).
493
494 c_bitstr(Value::cerl(), Size::cerl(), Unit::cerl(), Type::cerl(),
495 Flags::cerl()) -> cerl()
496
497 Creates an abstract bit-string template. These can only occur as
498 components of an abstract binary-template (see c_binary/1). The
499 result represents "#<Value>(Size, Unit, Type, Flags)", where
500 Unit must represent a positive integer constant, Type must rep‐
501 resent a constant atom (one of 'integer', 'float', or 'binary'),
502 and Flags must represent a constant list "[F1, ..., Fn]" where
503 all the Fi are atoms.
504
505 See also: ann_c_bitstr/6, bitstr_flags/1, bitstr_size/1, bit‐
506 str_type/1, bitstr_unit/1, bitstr_val/1, c_binary/1, is_c_bit‐
507 str/1, update_c_bitstr/6.
508
509 c_call(Module::cerl(), Name::cerl(), Arguments::[cerl()]) -> cerl()
510
511 Creates an abstract inter-module call. If Arguments is [A1, ...,
512 An], the result represents "call Module:Name(A1, ..., An)".
513
514 See also: ann_c_call/4, c_apply/2, c_primop/2, call_args/1,
515 call_arity/1, call_module/1, call_name/1, is_c_call/1,
516 update_c_call/4.
517
518 c_case(Argument::cerl(), Clauses::[cerl()]) -> cerl()
519
520 Creates an abstract case-expression. If Clauses is [C1, ...,
521 Cn], the result represents "case Argument of C1 ... Cn end".
522 Clauses must not be empty.
523
524 See also: ann_c_case/3, c_clause/3, case_arg/1, case_arity/1,
525 case_clauses/1, is_c_case/1, update_c_case/3.
526
527 c_catch(Body::cerl()) -> cerl()
528
529 Creates an abstract catch-expression. The result represents
530 "catch Body".
531
532 Note: catch-expressions can be rewritten as try-expressions, and
533 will eventually be removed from Core Erlang.
534
535 See also: ann_c_catch/2, c_try/5, catch_body/1, is_c_catch/1,
536 update_c_catch/2.
537
538 c_char(Value) -> cerl()
539
540 Types:
541
542 Value = char() | integer()
543
544 Creates an abstract character literal. If the local implementa‐
545 tion of Erlang defines char() as a subset of integer(), this
546 function is equivalent to c_int/1. Otherwise, if the given value
547 is an integer, it will be converted to the character with the
548 corresponding code. The lexical representation of a character is
549 "$Char", where Char is a single printing character or an escape
550 sequence.
551
552 See also: ann_c_char/2, c_int/1, c_string/1, char_lit/1,
553 char_val/1, is_c_char/1, is_print_char/1.
554
555 c_clause(Patterns::[cerl()], Body::cerl()) -> cerl()
556
557 Equivalent to c_clause(Patterns, c_atom(true), Body).
558
559 See also: c_atom/1.
560
561 c_clause(Patterns::[cerl()], Guard::cerl(), Body::cerl()) -> cerl()
562
563 Creates an an abstract clause. If Patterns is [P1, ..., Pn], the
564 result represents "<P1, ..., Pn> when Guard -> Body".
565
566 See also: ann_c_clause/4, c_case/2, c_clause/2, c_receive/3,
567 clause_arity/1, clause_body/1, clause_guard/1, clause_pats/1,
568 clause_vars/1, is_c_clause/1, update_c_clause/4.
569
570 c_cons(Head::cerl(), Tail::cerl()) -> cerl()
571
572 Creates an abstract list constructor. The result represents
573 "[Head | Tail]". Note that if both Head and Tail have type lit‐
574 eral, then the result will also have type literal, and annota‐
575 tions on Head and Tail are lost.
576
577 Recall that in Erlang, the tail element of a list constructor is
578 not necessarily a list.
579
580 See also: ann_c_cons/3, c_cons_skel/2, c_nil/0, cons_hd/1,
581 cons_tl/1, is_c_cons/1, is_c_list/1, list_elements/1,
582 list_length/1, make_list/2, update_c_cons/3.
583
584 c_cons_skel(Head::cerl(), Tail::cerl()) -> cerl()
585
586 Creates an abstract list constructor skeleton. Does not fold
587 constant literals, i.e., the result always has type cons, repre‐
588 senting "[Head | Tail]".
589
590 This function is occasionally useful when it is necessary to
591 have annotations on the subnodes of a list constructor node,
592 even when the subnodes are constant literals. Note however that
593 is_literal/1 will yield false and concrete/1 will fail if passed
594 the result from this function.
595
596 fold_literal/1 can be used to revert a node to the normal-form
597 representation.
598
599 See also: ann_c_cons_skel/3, c_cons/2, c_nil/0, concrete/1,
600 fold_literal/1, is_c_cons/1, is_c_list/1, is_literal/1,
601 update_c_cons_skel/3.
602
603 c_float(Value::float()) -> cerl()
604
605 Creates an abstract floating-point literal. The lexical repre‐
606 sentation is the decimal floating-point numeral of Value.
607
608 See also: ann_c_float/2, float_lit/1, float_val/1, is_c_float/1.
609
610 c_fname(Name::atom(), Arity::arity()) -> cerl()
611
612 Equivalent to c_var({Name, Arity}).
613
614 See also: ann_c_fname/3, fname_arity/1, fname_id/1,
615 is_c_fname/1, update_c_fname/3.
616
617 c_fun(Variables::[cerl()], Body::cerl()) -> cerl()
618
619 Creates an abstract fun-expression. If Variables is [V1, ...,
620 Vn], the result represents "fun (V1, ..., Vn) -> Body". All the
621 Vi must have type var.
622
623 See also: ann_c_fun/3, fun_arity/1, fun_body/1, fun_vars/1,
624 is_c_fun/1, update_c_fun/3.
625
626 c_int(Value::integer()) -> cerl()
627
628 Creates an abstract integer literal. The lexical representation
629 is the canonical decimal numeral of Value.
630
631 See also: ann_c_int/2, c_char/1, int_lit/1, int_val/1,
632 is_c_int/1.
633
634 c_let(Variables::[cerl()], Argument::cerl(), Body::cerl()) -> cerl()
635
636 Creates an abstract let-expression. If Variables is [V1, ...,
637 Vn], the result represents "let <V1, ..., Vn> = Argument in
638 Body". All the Vi must have type var.
639
640 See also: ann_c_let/4, is_c_let/1, let_arg/1, let_arity/1,
641 let_body/1, let_vars/1, update_c_let/4.
642
643 c_letrec(Definitions::[{cerl(), cerl()}], Body::cerl()) -> cerl()
644
645 Creates an abstract letrec-expression. If Definitions is [{V1,
646 F1}, ..., {Vn, Fn}], the result represents "letrec V1 = F1 ...
647 Vn = Fn in Body. All the Vi must have type var and represent
648 function names. All the Fi must have type 'fun'.
649
650 See also: ann_c_letrec/3, is_c_letrec/1, letrec_body/1,
651 letrec_defs/1, letrec_vars/1, update_c_letrec/3.
652
653 c_map(Pairs::[c_map_pair()]) -> c_map()
654
655 c_map_pair(Key::cerl(), Val::cerl()) -> c_map_pair()
656
657 c_map_pair_exact(Key::cerl(), Val::cerl()) -> c_map_pair()
658
659 c_map_pattern(Pairs::[c_map_pair()]) -> c_map()
660
661 c_module(Name::cerl(), Exports, Es::Definitions) -> cerl()
662
663 Types:
664
665 Exports = [cerl()]
666 Definitions = [{cerl(), cerl()}]
667
668 Equivalent to c_module(Name, Exports, [], Definitions).
669
670 c_module(Name::cerl(), Exports, Attrs::Attributes, Es::Definitions) ->
671 cerl()
672
673 Types:
674
675 Exports = [cerl()]
676 Attributes = [{cerl(), cerl()}]
677 Definitions = [{cerl(), cerl()}]
678
679 Creates an abstract module definition. The result represents
680
681 module Name [E1, ..., Ek]
682 attributes [K1 = T1, ...,
683 Km = Tm]
684 V1 = F1
685 ...
686 Vn = Fn
687 end
688
689 if Exports = [E1, ..., Ek], Attributes = [{K1, T1}, ..., {Km,
690 Tm}], and Definitions = [{V1, F1}, ..., {Vn, Fn}].
691
692 Name and all the Ki must be atom literals, and all the Ti must
693 be constant literals. All the Vi and Ei must have type var and
694 represent function names. All the Fi must have type 'fun'.
695
696 See also: ann_c_module/4, ann_c_module/5, c_atom/1, c_fun/2,
697 c_module/3, c_var/1, is_literal/1, module_attrs/1, mod‐
698 ule_defs/1, module_exports/1, module_name/1, module_vars/1,
699 update_c_module/5.
700
701 c_nil() -> cerl()
702
703 Creates an abstract empty list. The result represents "[]". The
704 empty list is traditionally called "nil".
705
706 See also: ann_c_nil/1, c_cons/2, is_c_list/1.
707
708 c_primop(Name::cerl(), Arguments::[cerl()]) -> cerl()
709
710 Creates an abstract primitive operation call. If Arguments is
711 [A1, ..., An], the result represents "primop Name(A1, ..., An)".
712 Name must be an atom literal.
713
714 See also: ann_c_primop/3, c_apply/2, c_call/3, is_c_primop/1,
715 primop_args/1, primop_arity/1, primop_name/1, update_c_primop/3.
716
717 c_receive(Clauses::[cerl()]) -> cerl()
718
719 Equivalent to c_receive(Clauses, c_atom(infinity),
720 c_atom(true)).
721
722 See also: c_atom/1.
723
724 c_receive(Clauses::[cerl()], Timeout::cerl(), Action::cerl()) -> cerl()
725
726 Creates an abstract receive-expression. If Clauses is [C1, ...,
727 Cn], the result represents "receive C1 ... Cn after Timeout ->
728 Action end".
729
730 See also: ann_c_receive/4, c_receive/1, is_c_receive/1,
731 receive_action/1, receive_clauses/1, receive_timeout/1,
732 update_c_receive/4.
733
734 c_seq(Argument::cerl(), Body::cerl()) -> cerl()
735
736 Creates an abstract sequencing expression. The result represents
737 "do Argument Body".
738
739 See also: ann_c_seq/3, is_c_seq/1, seq_arg/1, seq_body/1,
740 update_c_seq/3.
741
742 c_string(Value::string()) -> cerl()
743
744 Creates an abstract string literal. Equivalent to creating an
745 abstract list of the corresponding character literals (cf.
746 is_c_string/1), but is typically more efficient. The lexical
747 representation of a string is ""Chars"", where Chars is a
748 sequence of printing characters or spaces.
749
750 See also: ann_c_string/2, c_char/1, is_c_string/1,
751 is_print_string/1, string_lit/1, string_val/1.
752
753 c_try(Argument::cerl(), Variables::[cerl()], Body::cerl(), Exception‐
754 Vars::[cerl()], Handler::cerl()) -> cerl()
755
756 Creates an abstract try-expression. If Variables is [V1, ...,
757 Vn] and ExceptionVars is [X1, ..., Xm], the result represents
758 "try Argument of <V1, ..., Vn> -> Body catch <X1, ..., Xm> ->
759 Handler". All the Vi and Xi must have type var.
760
761 See also: ann_c_try/6, c_catch/1, is_c_try/1, try_arg/1,
762 try_body/1, try_vars/1, update_c_try/6.
763
764 c_tuple(Elements::[cerl()]) -> cerl()
765
766 Creates an abstract tuple. If Elements is [E1, ..., En], the
767 result represents "{E1, ..., En}". Note that if all nodes in
768 Elements have type literal, or if Elements is empty, then the
769 result will also have type literal and annotations on nodes in
770 Elements are lost.
771
772 Recall that Erlang has distinct 1-tuples, i.e., {X} is always
773 distinct from X itself.
774
775 See also: ann_c_tuple/2, c_tuple_skel/1, is_c_tuple/1,
776 tuple_arity/1, tuple_es/1, update_c_tuple/2.
777
778 c_tuple_skel(Elements::[cerl()]) -> cerl()
779
780 Creates an abstract tuple skeleton. Does not fold constant lit‐
781 erals, i.e., the result always has type tuple, representing
782 "{E1, ..., En}", if Elements is [E1, ..., En].
783
784 This function is occasionally useful when it is necessary to
785 have annotations on the subnodes of a tuple node, even when all
786 the subnodes are constant literals. Note however that is_lit‐
787 eral/1 will yield false and concrete/1 will fail if passed the
788 result from this function.
789
790 fold_literal/1 can be used to revert a node to the normal-form
791 representation.
792
793 See also: ann_c_tuple_skel/2, c_tuple/1, concrete/1, fold_lit‐
794 eral/1, is_c_tuple/1, is_literal/1, tuple_es/1,
795 update_c_tuple_skel/2.
796
797 c_values(Elements::[cerl()]) -> cerl()
798
799 Creates an abstract value list. If Elements is [E1, ..., En],
800 the result represents "<E1, ..., En>".
801
802 See also: ann_c_values/2, is_c_values/1, update_c_values/2, val‐
803 ues_arity/1, values_es/1.
804
805 c_var(Name::var_name()) -> cerl()
806
807 Types:
808
809 var_name() = integer() | atom() | {atom(), integer()}
810
811 Creates an abstract variable. A variable is identified by its
812 name, given by the Name parameter.
813
814 If a name is given by a single atom, it should either be a "sim‐
815 ple" atom which does not need to be single-quoted in Erlang, or
816 otherwise its print name should correspond to a proper Erlang
817 variable, i.e., begin with an uppercase character or an under‐
818 score. Names on the form {A, N} represent function name vari‐
819 ables "A/N"; these are special variables which may be bound only
820 in the function definitions of a module or a letrec. They may
821 not be bound in let expressions and cannot occur in clause pat‐
822 terns. The atom A in a function name may be any atom; the inte‐
823 ger N must be nonnegative. The functions c_fname/2 etc. are
824 utilities for handling function name variables.
825
826 When printing variable names, they must have the form of proper
827 Core Erlang variables and function names. E.g., a name repre‐
828 sented by an integer such as 42 could be formatted as "_42", an
829 atom 'Xxx' simply as "Xxx", and an atom foo as "_foo". However,
830 one must assure that any two valid distinct names are never
831 mapped to the same strings. Tuples such as {foo, 2} representing
832 function names can simply by formatted as "'foo'/2", with no
833 risk of conflicts.
834
835 See also: ann_c_var/2, c_fname/2, c_letrec/2, c_module/4,
836 is_c_var/1, update_c_var/2, var_name/1.
837
838 call_args(Node::cerl()) -> [cerl()]
839
840 Returns the list of argument subtrees of an abstract inter-mod‐
841 ule call.
842
843 See also: c_call/3, call_arity/1.
844
845 call_arity(Node::cerl()) -> arity()
846
847 Returns the number of argument subtrees of an abstract inter-
848 module call.
849
850 Note: this is equivalent to length(call_args(Node)), but poten‐
851 tially more efficient.
852
853 See also: c_call/3, call_args/1.
854
855 call_module(Node::cerl()) -> cerl()
856
857 Returns the module subtree of an abstract inter-module call.
858
859 See also: c_call/3.
860
861 call_name(Node::cerl()) -> cerl()
862
863 Returns the name subtree of an abstract inter-module call.
864
865 See also: c_call/3.
866
867 case_arg(Node::cerl()) -> cerl()
868
869 Returns the argument subtree of an abstract case-expression.
870
871 See also: c_case/2.
872
873 case_arity(Node::cerl()) -> integer()
874
875 Equivalent to clause_arity(hd(case_clauses(Node))), but poten‐
876 tially more efficient.
877
878 See also: c_case/2, case_clauses/1, clause_arity/1.
879
880 case_clauses(Node::cerl()) -> [cerl()]
881
882 Returns the list of clause subtrees of an abstract case-expres‐
883 sion.
884
885 See also: c_case/2, case_arity/1.
886
887 catch_body(Node::cerl()) -> cerl()
888
889 Returns the body subtree of an abstract catch-expression.
890
891 See also: c_catch/1.
892
893 char_lit(Node::cerl()) -> string()
894
895 Returns the literal string represented by an abstract character.
896 This includes a leading $ character. Currently, all characters
897 that are not in the set of ISO 8859-1 (Latin-1) "printing" char‐
898 acters will be escaped.
899
900 See also: c_char/1.
901
902 char_val(Node::cerl()) -> char()
903
904 Returns the value represented by an abstract character literal.
905
906 See also: c_char/1.
907
908 clause_arity(Node::cerl()) -> integer()
909
910 Returns the number of pattern subtrees of an abstract clause.
911
912 Note: this is equivalent to length(clause_pats(Node)), but
913 potentially more efficient.
914
915 See also: c_clause/3, clause_pats/1.
916
917 clause_body(Node::cerl()) -> cerl()
918
919 Returns the body subtree of an abstract clause.
920
921 See also: c_clause/3.
922
923 clause_guard(Node::cerl()) -> cerl()
924
925 Returns the guard subtree of an abstract clause.
926
927 See also: c_clause/3.
928
929 clause_pats(Node::cerl()) -> [cerl()]
930
931 Returns the list of pattern subtrees of an abstract clause.
932
933 See also: c_clause/3, clause_arity/1.
934
935 clause_vars(Clause::cerl()) -> [cerl()]
936
937 Returns the list of all abstract variables in the patterns of an
938 abstract clause. The order of listing is not defined.
939
940 See also: c_clause/3, pat_list_vars/1.
941
942 concrete(Node::cerl()) -> term()
943
944 Returns the Erlang term represented by a syntax tree. An excep‐
945 tion is thrown if Node does not represent a literal term.
946
947 Note: This is a constant time operation.
948
949 See also: abstract/1, is_literal/1.
950
951 cons_hd(C_cons::cerl()) -> cerl()
952
953 Returns the head subtree of an abstract list constructor.
954
955 See also: c_cons/2.
956
957 cons_tl(C_cons::cerl()) -> cerl()
958
959 Returns the tail subtree of an abstract list constructor.
960
961 Recall that the tail does not necessarily represent a proper
962 list.
963
964 See also: c_cons/2.
965
966 copy_ann(Source::cerl(), Target::cerl()) -> cerl()
967
968 Copies the list of user annotations from Source to Target.
969
970 Note: this is equivalent to set_ann(Target, get_ann(Source)),
971 but potentially more efficient.
972
973 See also: get_ann/1, set_ann/2.
974
975 data_arity(Node::cerl()) -> integer()
976
977 Returns the number of subtrees of a data constructor node. This
978 is equivalent to length(data_es(Node)), but potentially more
979 efficient.
980
981 See also: data_es/1, is_data/1.
982
983 data_es(Node::cerl()) -> [cerl()]
984
985 Returns the list of subtrees of a data constructor node. If the
986 arity of the constructor is zero, the result is the empty list.
987
988 Note: if data_type(Node) is cons, the number of subtrees is
989 exactly two. If data_type(Node) is {atomic, Value}, the number
990 of subtrees is zero.
991
992 See also: data_arity/1, data_type/1, is_data/1, make_data/2.
993
994 data_type(Node::cerl()) -> dtype()
995
996 Types:
997
998 dtype() = cons | tuple | {atomic, Value}
999 Value = integer() | float() | atom() | []
1000
1001 Returns a type descriptor for a data constructor node. (Cf.
1002 is_data/1.) This is mainly useful for comparing types and for
1003 constructing new nodes of the same type (cf. make_data/2). If
1004 Node represents an integer, floating-point number, atom or empty
1005 list, the result is {atomic, Value}, where Value is the value of
1006 concrete(Node), otherwise the result is either cons or tuple.
1007
1008 Type descriptors can be compared for equality or order (in the
1009 Erlang term order), but remember that floating-point values
1010 should in general never be tested for equality.
1011
1012 See also: concrete/1, is_data/1, make_data/2, type/1.
1013
1014 float_lit(Node::cerl()) -> string()
1015
1016 Returns the numeral string represented by a floating-point lit‐
1017 eral node.
1018
1019 See also: c_float/1.
1020
1021 float_val(Node::cerl()) -> float()
1022
1023 Returns the value represented by a floating-point literal node.
1024
1025 See also: c_float/1.
1026
1027 fname_arity(C_var::cerl()) -> arity()
1028
1029 Returns the arity part of an abstract function name variable.
1030
1031 See also: c_fname/2, fname_id/1.
1032
1033 fname_id(C_var::cerl()) -> atom()
1034
1035 Returns the identifier part of an abstract function name vari‐
1036 able.
1037
1038 See also: c_fname/2, fname_arity/1.
1039
1040 fold_literal(Node::cerl()) -> cerl()
1041
1042 Assures that literals have a compact representation. This is
1043 occasionally useful if c_cons_skel/2, c_tuple_skel/1 or
1044 unfold_literal/1 were used in the construction of Node, and you
1045 want to revert to the normal "folded" representation of liter‐
1046 als. If Node represents a tuple or list constructor, its ele‐
1047 ments are rewritten recursively, and the node is reconstructed
1048 using c_cons/2 or c_tuple/1, respectively; otherwise, Node is
1049 not changed.
1050
1051 See also: c_cons/2, c_cons_skel/2, c_tuple/1, c_tuple_skel/1,
1052 is_literal/1, unfold_literal/1.
1053
1054 from_records(Tree::record(record_types())) -> cerl()
1055
1056 Types:
1057
1058 record_types() = c_alias | c_apply | c_call | c_case |
1059 c_catch | c_clause | c_cons | c_fun | c_let | c_letrec |
1060 c_lit | c_module | c_primop | c_receive | c_seq | c_try |
1061 c_tuple | c_values | c_var
1062
1063 Translates an explicit record representation to a corresponding
1064 abstract syntax tree. The records are defined in the file
1065 "core_parse.hrl".
1066
1067 See also: to_records/1, type/1.
1068
1069 fun_arity(Node::cerl()) -> arity()
1070
1071 Returns the number of parameter subtrees of an abstract fun-
1072 expression.
1073
1074 Note: this is equivalent to length(fun_vars(Node)), but poten‐
1075 tially more efficient.
1076
1077 See also: c_fun/2, fun_vars/1.
1078
1079 fun_body(Node::cerl()) -> cerl()
1080
1081 Returns the body subtree of an abstract fun-expression.
1082
1083 See also: c_fun/2.
1084
1085 fun_vars(Node::cerl()) -> [cerl()]
1086
1087 Returns the list of parameter subtrees of an abstract fun-
1088 expression.
1089
1090 See also: c_fun/2, fun_arity/1.
1091
1092 get_ann(Node::cerl()) -> [term()]
1093
1094 Returns the list of user annotations associated with a syntax
1095 tree node. For a newly created node, this is the empty list. The
1096 annotations may be any terms.
1097
1098 See also: set_ann/2.
1099
1100 int_lit(Node::cerl()) -> string()
1101
1102 Returns the numeral string represented by an integer literal
1103 node.
1104
1105 See also: c_int/1.
1106
1107 int_val(Node::cerl()) -> integer()
1108
1109 Returns the value represented by an integer literal node.
1110
1111 See also: c_int/1.
1112
1113 is_c_alias(Node::cerl()) -> boolean()
1114
1115 Returns true if Node is an abstract pattern alias, otherwise
1116 false.
1117
1118 See also: c_alias/2.
1119
1120 is_c_apply(Node::cerl()) -> boolean()
1121
1122 Returns true if Node is an abstract function application, other‐
1123 wise false.
1124
1125 See also: c_apply/2.
1126
1127 is_c_atom(Node::cerl()) -> boolean()
1128
1129 Returns true if Node represents an atom literal, otherwise
1130 false.
1131
1132 See also: c_atom/1.
1133
1134 is_c_binary(Node::cerl()) -> boolean()
1135
1136 Returns true if Node is an abstract binary-template; otherwise
1137 false.
1138
1139 See also: c_binary/1.
1140
1141 is_c_bitstr(Node::cerl()) -> boolean()
1142
1143 Returns true if Node is an abstract bit-string template; other‐
1144 wise false.
1145
1146 See also: c_bitstr/5.
1147
1148 is_c_call(Node::cerl()) -> boolean()
1149
1150 Returns true if Node is an abstract inter-module call expres‐
1151 sion; otherwise false.
1152
1153 See also: c_call/3.
1154
1155 is_c_case(C_case::cerl()) -> boolean()
1156
1157 Returns true if Node is an abstract case-expression; otherwise
1158 false.
1159
1160 See also: c_case/2.
1161
1162 is_c_catch(Node::cerl()) -> boolean()
1163
1164 Returns true if Node is an abstract catch-expression, otherwise
1165 false.
1166
1167 See also: c_catch/1.
1168
1169 is_c_char(Node::cerl()) -> boolean()
1170
1171 Returns true if Node may represent a character literal, other‐
1172 wise false.
1173
1174 If the local implementation of Erlang defines char() as a subset
1175 of integer(), then is_c_int(Node) will also yield true.
1176
1177 See also: c_char/1, is_print_char/1.
1178
1179 is_c_clause(Node::cerl()) -> boolean()
1180
1181 Returns true if Node is an abstract clause, otherwise false.
1182
1183 See also: c_clause/3.
1184
1185 is_c_cons(Node::cerl()) -> boolean()
1186
1187 Returns true if Node is an abstract list constructor, otherwise
1188 false.
1189
1190 is_c_float(Node::cerl()) -> boolean()
1191
1192 Returns true if Node represents a floating-point literal, other‐
1193 wise false.
1194
1195 See also: c_float/1.
1196
1197 is_c_fname(Node::cerl()) -> boolean()
1198
1199 Returns true if Node is an abstract function name variable, oth‐
1200 erwise false.
1201
1202 See also: c_fname/2, c_var/1, var_name/1.
1203
1204 is_c_fun(Node::cerl()) -> boolean()
1205
1206 Returns true if Node is an abstract fun-expression, otherwise
1207 false.
1208
1209 See also: c_fun/2.
1210
1211 is_c_int(Node::cerl()) -> boolean()
1212
1213 Returns true if Node represents an integer literal, otherwise
1214 false.
1215
1216 See also: c_int/1.
1217
1218 is_c_let(Node::cerl()) -> boolean()
1219
1220 Returns true if Node is an abstract let-expression, otherwise
1221 false.
1222
1223 See also: c_let/3.
1224
1225 is_c_letrec(Node::cerl()) -> boolean()
1226
1227 Returns true if Node is an abstract letrec-expression, otherwise
1228 false.
1229
1230 See also: c_letrec/2.
1231
1232 is_c_list(Node::cerl()) -> boolean()
1233
1234 Returns true if Node represents a proper list, otherwise false.
1235 A proper list is either the empty list [], or a cons cell [Head
1236 | Tail], where recursively Tail is a proper list.
1237
1238 Note: Because Node is a syntax tree, the actual run-time values
1239 corresponding to its subtrees may often be partially or com‐
1240 pletely unknown. Thus, if Node represents e.g. "[... | Ns]"
1241 (where Ns is a variable), then the function will return false,
1242 because it is not known whether Ns will be bound to a list at
1243 run-time. If Node instead represents e.g. "[1, 2, 3]" or "[A |
1244 []]", then the function will return true.
1245
1246 See also: c_cons/2, c_nil/0, list_elements/1, list_length/1.
1247
1248 is_c_map(Node::cerl()) -> boolean()
1249
1250 Returns true if Node is an abstract map constructor, otherwise
1251 false.
1252
1253 is_c_map_empty(C_map::c_map() | c_literal()) -> boolean()
1254
1255 is_c_map_pattern(C_map::c_map()) -> boolean()
1256
1257 is_c_module(Node::cerl()) -> boolean()
1258
1259 Returns true if Node is an abstract module definition, otherwise
1260 false.
1261
1262 See also: type/1.
1263
1264 is_c_nil(Node::cerl()) -> boolean()
1265
1266 Returns true if Node is an abstract empty list, otherwise false.
1267
1268 is_c_primop(Node::cerl()) -> boolean()
1269
1270 Returns true if Node is an abstract primitive operation call,
1271 otherwise false.
1272
1273 See also: c_primop/2.
1274
1275 is_c_receive(Node::cerl()) -> boolean()
1276
1277 Returns true if Node is an abstract receive-expression, other‐
1278 wise false.
1279
1280 See also: c_receive/3.
1281
1282 is_c_seq(Node::cerl()) -> boolean()
1283
1284 Returns true if Node is an abstract sequencing expression, oth‐
1285 erwise false.
1286
1287 See also: c_seq/2.
1288
1289 is_c_string(Node::cerl()) -> boolean()
1290
1291 Returns true if Node may represent a string literal, otherwise
1292 false. Strings are defined as lists of characters; see
1293 is_c_char/1 for details.
1294
1295 See also: c_string/1, is_c_char/1, is_print_string/1.
1296
1297 is_c_try(Node::cerl()) -> boolean()
1298
1299 Returns true if Node is an abstract try-expression, otherwise
1300 false.
1301
1302 See also: c_try/5.
1303
1304 is_c_tuple(Node::cerl()) -> boolean()
1305
1306 Returns true if Node is an abstract tuple, otherwise false.
1307
1308 See also: c_tuple/1.
1309
1310 is_c_values(Node::cerl()) -> boolean()
1311
1312 Returns true if Node is an abstract value list; otherwise false.
1313
1314 See also: c_values/1.
1315
1316 is_c_var(Node::cerl()) -> boolean()
1317
1318 Returns true if Node is an abstract variable, otherwise false.
1319
1320 See also: c_var/1.
1321
1322 is_data(Node::cerl()) -> boolean()
1323
1324 Returns true if Node represents a data constructor, otherwise
1325 false. Data constructors are cons cells, tuples, and atomic lit‐
1326 erals.
1327
1328 See also: data_arity/1, data_es/1, data_type/1.
1329
1330 is_leaf(Node::cerl()) -> boolean()
1331
1332 Returns true if Node is a leaf node, otherwise false. The cur‐
1333 rent leaf node types are literal and var.
1334
1335 Note: all literals (cf. is_literal/1) are leaf nodes, even if
1336 they represent structured (constant) values such as {foo, [bar,
1337 baz]}. Also note that variables are leaf nodes but not literals.
1338
1339 See also: is_literal/1, type/1.
1340
1341 is_literal(Node::cerl()) -> boolean()
1342
1343 Returns true if Node represents a literal term, otherwise false.
1344 This function returns true if and only if the value of con‐
1345 crete(Node) is defined.
1346
1347 Note: This is a constant time operation.
1348
1349 See also: abstract/1, concrete/1, fold_literal/1.
1350
1351 is_literal_term(Term::term()) -> boolean()
1352
1353 Returns true if Term can be represented as a literal, otherwise
1354 false. This function takes time proportional to the size of
1355 Term.
1356
1357 See also: abstract/1.
1358
1359 is_print_char(Node::cerl()) -> boolean()
1360
1361 Returns true if Node may represent a "printing" character, oth‐
1362 erwise false. (Cf. is_c_char/1.) A "printing" character has
1363 either a given graphical representation, or a "named" escape
1364 sequence such as "\n". Currently, only ISO 8859-1 (Latin-1)
1365 character values are recognized.
1366
1367 See also: c_char/1, is_c_char/1.
1368
1369 is_print_string(Node::cerl()) -> boolean()
1370
1371 Returns true if Node may represent a string literal containing
1372 only "printing" characters, otherwise false. See is_c_string/1
1373 and is_print_char/1 for details. Currently, only ISO 8859-1
1374 (Latin-1) character values are recognized.
1375
1376 See also: c_string/1, is_c_string/1, is_print_char/1.
1377
1378 let_arg(Node::cerl()) -> cerl()
1379
1380 Returns the argument subtree of an abstract let-expression.
1381
1382 See also: c_let/3.
1383
1384 let_arity(Node::cerl()) -> integer()
1385
1386 Returns the number of left-hand side variables of an abstract
1387 let-expression.
1388
1389 Note: this is equivalent to length(let_vars(Node)), but poten‐
1390 tially more efficient.
1391
1392 See also: c_let/3, let_vars/1.
1393
1394 let_body(Node::cerl()) -> cerl()
1395
1396 Returns the body subtree of an abstract let-expression.
1397
1398 See also: c_let/3.
1399
1400 let_vars(Node::cerl()) -> [cerl()]
1401
1402 Returns the list of left-hand side variables of an abstract let-
1403 expression.
1404
1405 See also: c_let/3, let_arity/1.
1406
1407 letrec_body(Node::cerl()) -> cerl()
1408
1409 Returns the body subtree of an abstract letrec-expression.
1410
1411 See also: c_letrec/2.
1412
1413 letrec_defs(Node::cerl()) -> [{cerl(), cerl()}]
1414
1415 Returns the list of definitions of an abstract letrec-expres‐
1416 sion. If Node represents "letrec V1 = F1 ... Vn = Fn in Body",
1417 the returned value is [{V1, F1}, ..., {Vn, Fn}].
1418
1419 See also: c_letrec/2.
1420
1421 letrec_vars(Node::cerl()) -> [cerl()]
1422
1423 Returns the list of left-hand side function variable subtrees of
1424 a letrec-expression. If Node represents "letrec V1 = F1 ... Vn =
1425 Fn in Body", the returned value is [V1, ..., Vn].
1426
1427 See also: c_letrec/2.
1428
1429 list_elements(C_cons::cerl()) -> [cerl()]
1430
1431 Returns the list of element subtrees of an abstract list. Node
1432 must represent a proper list. E.g., if Node represents "[X1, X2
1433 | [X3, X4 | []]", then list_elements(Node) yields the list [X1,
1434 X2, X3, X4].
1435
1436 See also: c_cons/2, c_nil/0, is_c_list/1, list_length/1,
1437 make_list/2.
1438
1439 list_length(Node::cerl()) -> integer()
1440
1441 Returns the number of element subtrees of an abstract list. Node
1442 must represent a proper list. E.g., if Node represents "[X1 |
1443 [X2, X3 | [X4, X5, X6]]]", then list_length(Node) returns the
1444 integer 6.
1445
1446 Note: this is equivalent to length(list_elements(Node)), but
1447 potentially more efficient.
1448
1449 See also: c_cons/2, c_nil/0, is_c_list/1, list_elements/1.
1450
1451 make_data(Type::dtype(), Elements::[cerl()]) -> cerl()
1452
1453 Creates a data constructor node with the specified type and sub‐
1454 trees. (Cf. data_type/1.) An exception is thrown if the length
1455 of Elements is invalid for the given Type; see data_es/1 for
1456 arity constraints on constructor types.
1457
1458 See also: ann_make_data/3, data_es/1, data_type/1,
1459 make_data_skel/2, update_data/3.
1460
1461 make_data_skel(Type::dtype(), Elements::[cerl()]) -> cerl()
1462
1463 Like make_data/2, but analogous to c_tuple_skel/1 and
1464 c_cons_skel/2.
1465
1466 See also: ann_make_data_skel/3, c_cons_skel/2, c_tuple_skel/1,
1467 make_data/2, update_data_skel/3.
1468
1469 make_list(List) -> Node
1470
1471 Equivalent to make_list(List, none).
1472
1473 make_list(List::[cerl()], Tail) -> cerl()
1474
1475 Types:
1476
1477 Tail = cerl() | none
1478
1479 Creates an abstract list from the elements in List and the
1480 optional Tail. If Tail is none, the result will represent a nil-
1481 terminated list, otherwise it represents "[... | Tail]".
1482
1483 See also: ann_make_list/3, c_cons/2, c_nil/0, list_elements/1,
1484 update_list/3.
1485
1486 make_tree(Type::ctype(), Groups::[[cerl()]]) -> cerl()
1487
1488 Creates a syntax tree with the given type and subtrees. Type
1489 must be a node type name (cf. type/1) that does not denote a
1490 leaf node type (cf. is_leaf/1). Groups must be a nonempty list
1491 of groups of syntax trees, representing the subtrees of a node
1492 of the given type, in left-to-right order as they would occur in
1493 the printed program text, grouped by category as done by sub‐
1494 trees/1.
1495
1496 The result of ann_make_tree(get_ann(Node), type(Node), sub‐
1497 trees(Node)) (cf. update_tree/2) represents the same source code
1498 text as the original Node, assuming that subtrees(Node) yields a
1499 nonempty list. However, it does not necessarily have the exact
1500 same data representation as Node.
1501
1502 See also: ann_make_tree/3, is_leaf/1, subtrees/1, type/1,
1503 update_tree/2.
1504
1505 map_arg(C_literal::c_map() | c_literal()) -> c_map() | c_literal()
1506
1507 map_es(C_literal::c_map() | c_literal()) -> [c_map_pair()]
1508
1509 map_pair_key(C_map_pair::c_map_pair()) -> cerl()
1510
1511 map_pair_op(C_map_pair::c_map_pair()) -> map_op()
1512
1513 map_pair_val(C_map_pair::c_map_pair()) -> cerl()
1514
1515 meta(Tree::cerl()) -> cerl()
1516
1517 Creates a meta-representation of a syntax tree. The result rep‐
1518 resents an Erlang expression "MetaTree" which, if evaluated,
1519 will yield a new syntax tree representing the same source code
1520 text as Tree (although the actual data representation may be
1521 different). The expression represented by MetaTree is implemen‐
1522 tation independent with regard to the data structures used by
1523 the abstract syntax tree implementation.
1524
1525 Any node in Tree whose node type is var (cf. type/1), and whose
1526 list of annotations (cf. get_ann/1) contains the atom meta_var,
1527 will remain unchanged in the resulting tree, except that exactly
1528 one occurrence of meta_var is removed from its annotation list.
1529
1530 The main use of the function meta/1 is to transform a data
1531 structure Tree, which represents a piece of program code, into a
1532 form that is representation independent when printed. E.g., sup‐
1533 pose Tree represents a variable named "V". Then (assuming a
1534 function print/1 for printing syntax trees), evaluating
1535 print(abstract(Tree)) - simply using abstract/1 to map the
1536 actual data structure onto a syntax tree representation - would
1537 output a string that might look something like "{var, ...,
1538 'V'}", which is obviously dependent on the implementation of the
1539 abstract syntax trees. This could e.g. be useful for caching a
1540 syntax tree in a file. However, in some situations like in a
1541 program generator generator (with two "generator"), it may be
1542 unacceptable. Using print(meta(Tree)) instead would output a
1543 representation independent syntax tree generating expression; in
1544 the above case, something like "cerl:c_var('V')".
1545
1546 The implementation tries to generate compact code with respect
1547 to literals and lists.
1548
1549 See also: abstract/1, get_ann/1, type/1.
1550
1551 module_attrs(Node::cerl()) -> [{cerl(), cerl()}]
1552
1553 Returns the list of pairs of attribute key/value subtrees of an
1554 abstract module definition.
1555
1556 See also: c_module/4.
1557
1558 module_defs(Node::cerl()) -> [{cerl(), cerl()}]
1559
1560 Returns the list of function definitions of an abstract module
1561 definition.
1562
1563 See also: c_module/4.
1564
1565 module_exports(Node::cerl()) -> [cerl()]
1566
1567 Returns the list of exports subtrees of an abstract module defi‐
1568 nition.
1569
1570 See also: c_module/4.
1571
1572 module_name(Node::cerl()) -> cerl()
1573
1574 Returns the name subtree of an abstract module definition.
1575
1576 See also: c_module/4.
1577
1578 module_vars(Node::cerl()) -> [cerl()]
1579
1580 Returns the list of left-hand side function variable subtrees of
1581 an abstract module definition.
1582
1583 See also: c_module/4.
1584
1585 pat_list_vars(Patterns::[cerl()]) -> [cerl()]
1586
1587 Returns the list of all abstract variables in the given pat‐
1588 terns. An exception is thrown if some element in Patterns does
1589 not represent a well-formed Core Erlang clause pattern. The
1590 order of listing is not defined.
1591
1592 See also: clause_vars/1, pat_vars/1.
1593
1594 pat_vars(Pattern::cerl()) -> [cerl()]
1595
1596 Returns the list of all abstract variables in a pattern. An
1597 exception is thrown if Node does not represent a well-formed
1598 Core Erlang clause pattern. The order of listing is not defined.
1599
1600 See also: clause_vars/1, pat_list_vars/1.
1601
1602 primop_args(Node::cerl()) -> [cerl()]
1603
1604 Returns the list of argument subtrees of an abstract primitive
1605 operation call.
1606
1607 See also: c_primop/2, primop_arity/1.
1608
1609 primop_arity(Node::cerl()) -> arity()
1610
1611 Returns the number of argument subtrees of an abstract primitive
1612 operation call.
1613
1614 Note: this is equivalent to length(primop_args(Node)), but
1615 potentially more efficient.
1616
1617 See also: c_primop/2, primop_args/1.
1618
1619 primop_name(Node::cerl()) -> cerl()
1620
1621 Returns the name subtree of an abstract primitive operation
1622 call.
1623
1624 See also: c_primop/2.
1625
1626 receive_action(Node::cerl()) -> cerl()
1627
1628 Returns the action subtree of an abstract receive-expression.
1629
1630 See also: c_receive/3.
1631
1632 receive_clauses(Node::cerl()) -> [cerl()]
1633
1634 Returns the list of clause subtrees of an abstract receive-
1635 expression.
1636
1637 See also: c_receive/3.
1638
1639 receive_timeout(Node::cerl()) -> cerl()
1640
1641 Returns the timeout subtree of an abstract receive-expression.
1642
1643 See also: c_receive/3.
1644
1645 seq_arg(Node::cerl()) -> cerl()
1646
1647 Returns the argument subtree of an abstract sequencing expres‐
1648 sion.
1649
1650 See also: c_seq/2.
1651
1652 seq_body(Node::cerl()) -> cerl()
1653
1654 Returns the body subtree of an abstract sequencing expression.
1655
1656 See also: c_seq/2.
1657
1658 set_ann(Node::cerl(), Annotations::[term()]) -> cerl()
1659
1660 Sets the list of user annotations of Node to Annotations.
1661
1662 See also: add_ann/2, copy_ann/2, get_ann/1.
1663
1664 string_lit(Node::cerl()) -> string()
1665
1666 Returns the literal string represented by an abstract string.
1667 This includes surrounding double-quote characters "...". Cur‐
1668 rently, characters that are not in the set of ISO 8859-1
1669 (Latin-1) "printing" characters will be escaped, except for spa‐
1670 ces.
1671
1672 See also: c_string/1.
1673
1674 string_val(Node::cerl()) -> string()
1675
1676 Returns the value represented by an abstract string literal.
1677
1678 See also: c_string/1.
1679
1680 subtrees(Node::cerl()) -> [[cerl()]]
1681
1682 Returns the grouped list of all subtrees of a node. If Node is a
1683 leaf node (cf. is_leaf/1), this is the empty list, otherwise the
1684 result is always a nonempty list, containing the lists of sub‐
1685 trees of Node, in left-to-right order as they occur in the
1686 printed program text, and grouped by category. Often, each group
1687 contains only a single subtree.
1688
1689 Depending on the type of Node, the size of some groups may be
1690 variable (e.g., the group consisting of all the elements of a
1691 tuple), while others always contain the same number of elements
1692 - usually exactly one (e.g., the group containing the argument
1693 expression of a case-expression). Note, however, that the exact
1694 structure of the returned list (for a given node type) should in
1695 general not be depended upon, since it might be subject to
1696 change without notice.
1697
1698 The function subtrees/1 and the constructor functions
1699 make_tree/2 and update_tree/2 can be a great help if one wants
1700 to traverse a syntax tree, visiting all its subtrees, but treat
1701 nodes of the tree in a uniform way in most or all cases. Using
1702 these functions makes this simple, and also assures that your
1703 code is not overly sensitive to extensions of the syntax tree
1704 data type, because any node types not explicitly handled by your
1705 code can be left to a default case.
1706
1707 For example:
1708
1709 postorder(F, Tree) ->
1710 F(case subtrees(Tree) of
1711 [] -> Tree;
1712 List -> update_tree(Tree,
1713 [[postorder(F, Subtree)
1714 || Subtree <- Group]
1715 || Group <- List])
1716 end).
1717
1718
1719 maps the function F on Tree and all its subtrees, doing a post-
1720 order traversal of the syntax tree. (Note the use of
1721 update_tree/2 to preserve annotations.) For a simple function
1722 like:
1723
1724 f(Node) ->
1725 case type(Node) of
1726 atom -> atom("a_" ++ atom_name(Node));
1727 _ -> Node
1728 end.
1729
1730
1731 the call postorder(fun f/1, Tree) will yield a new representa‐
1732 tion of Tree in which all atom names have been extended with the
1733 prefix "a_", but nothing else (including annotations) has been
1734 changed.
1735
1736 See also: is_leaf/1, make_tree/2, update_tree/2.
1737
1738 to_records(Tree::cerl()) -> record(record_types())
1739
1740 Translates an abstract syntax tree to a corresponding explicit
1741 record representation. The records are defined in the file
1742 "cerl.hrl".
1743
1744 See also: from_records/1, type/1.
1745
1746 try_arg(Node::cerl()) -> cerl()
1747
1748 Returns the expression subtree of an abstract try-expression.
1749
1750 See also: c_try/5.
1751
1752 try_body(Node::cerl()) -> cerl()
1753
1754 Returns the success body subtree of an abstract try-expression.
1755
1756 See also: c_try/5.
1757
1758 try_evars(Node::cerl()) -> [cerl()]
1759
1760 Returns the list of exception variable subtrees of an abstract
1761 try-expression.
1762
1763 See also: c_try/5.
1764
1765 try_handler(Node::cerl()) -> cerl()
1766
1767 Returns the exception body subtree of an abstract try-expres‐
1768 sion.
1769
1770 See also: c_try/5.
1771
1772 try_vars(Node::cerl()) -> [cerl()]
1773
1774 Returns the list of success variable subtrees of an abstract
1775 try-expression.
1776
1777 See also: c_try/5.
1778
1779 tuple_arity(Node::cerl()) -> integer()
1780
1781 Returns the number of element subtrees of an abstract tuple.
1782
1783 Note: this is equivalent to length(tuple_es(Node)), but poten‐
1784 tially more efficient.
1785
1786 See also: c_tuple/1, tuple_es/1.
1787
1788 tuple_es(C_tuple::cerl()) -> [cerl()]
1789
1790 Returns the list of element subtrees of an abstract tuple.
1791
1792 See also: c_tuple/1.
1793
1794 type(Node::cerl()) -> atom()
1795
1796 Returns the type tag of Node. Current node types are:
1797
1798 alias apply binary bitstr call case catch clause
1799 cons fun let letrec literal map map_pair module
1800 primop receive seq try tuple values var
1801
1802
1803 Note: The name of the primary constructor function for a node
1804 type is always the name of the type itself, prefixed by "c_";
1805 recognizer predicates are correspondingly prefixed by "is_c_".
1806 Furthermore, to simplify preservation of annotations (cf.
1807 get_ann/1), there are analogous constructor functions prefixed
1808 by "ann_c_" and "update_c_", for setting the annotation list of
1809 the new node to either a specific value or to the annotations of
1810 an existing node, respectively.
1811
1812 See also: abstract/1, c_alias/2, c_apply/2, c_binary/1, c_bit‐
1813 str/5, c_call/3, c_case/2, c_catch/1, c_clause/3, c_cons/2,
1814 c_fun/2, c_let/3, c_letrec/2, c_module/3, c_primop/2,
1815 c_receive/1, c_seq/2, c_try/5, c_tuple/1, c_values/1, c_var/1,
1816 data_type/1, from_records/1, get_ann/1, meta/1, subtrees/1,
1817 to_records/1.
1818
1819 unfold_literal(Node::cerl()) -> cerl()
1820
1821 Assures that literals have a fully expanded representation. If
1822 Node represents a literal tuple or list constructor, its ele‐
1823 ments are rewritten recursively, and the node is reconstructed
1824 using c_cons_skel/2 or c_tuple_skel/1, respectively; otherwise,
1825 Node is not changed. The fold_literal/1 can be used to revert to
1826 the normal compact representation.
1827
1828 See also: c_cons/2, c_cons_skel/2, c_tuple/1, c_tuple_skel/1,
1829 fold_literal/1, is_literal/1.
1830
1831 update_c_alias(Old::cerl(), Variable::cerl(), Pattern::cerl()) ->
1832 cerl()
1833
1834 See also: c_alias/2.
1835
1836 update_c_apply(Old::cerl(), Operator::cerl(), Arguments::[cerl()]) ->
1837 cerl()
1838
1839 See also: c_apply/2.
1840
1841 update_c_binary(Old::cerl(), Segments::[cerl()]) -> cerl()
1842
1843 See also: c_binary/1.
1844
1845 update_c_bitstr(Old::cerl(), Value::cerl(), Size::cerl(), Type::cerl(),
1846 Flags::cerl()) -> cerl()
1847
1848 Equivalent to update_c_bitstr(Node, Value, Size, abstract(1),
1849 Type, Flags).
1850
1851 update_c_bitstr(Old::cerl(), Value::cerl(), Size::cerl(), Unit::cerl(),
1852 Type::cerl(), Flags::cerl()) -> cerl()
1853
1854 See also: c_bitstr/5, update_c_bitstr/5.
1855
1856 update_c_call(Old::cerl(), Module::cerl(), Name::cerl(), Argu‐
1857 ments::[cerl()]) -> cerl()
1858
1859 See also: c_call/3.
1860
1861 update_c_case(Old::cerl(), Argument::cerl(), Clauses::[cerl()]) ->
1862 cerl()
1863
1864 See also: c_case/2.
1865
1866 update_c_catch(Old::cerl(), Body::cerl()) -> cerl()
1867
1868 See also: c_catch/1.
1869
1870 update_c_clause(Old::cerl(), Patterns::[cerl()], Guard::cerl(),
1871 Body::cerl()) -> cerl()
1872
1873 See also: c_clause/3.
1874
1875 update_c_cons(Old::cerl(), Head::cerl(), Tail::cerl()) -> cerl()
1876
1877 See also: c_cons/2.
1878
1879 update_c_cons_skel(Old::cerl(), Head::cerl(), Tail::cerl()) -> cerl()
1880
1881 See also: c_cons_skel/2.
1882
1883 update_c_fname(Old::cerl(), Name::atom()) -> cerl()
1884
1885 Like update_c_fname/3, but takes the arity from Node.
1886
1887 See also: c_fname/2, update_c_fname/3.
1888
1889 update_c_fname(Old::cerl(), Name::atom(), Arity::arity()) -> cerl()
1890
1891 Equivalent to update_c_var(Old, {Atom, Arity}).
1892
1893 See also: c_fname/2, update_c_fname/2.
1894
1895 update_c_fun(Old::cerl(), Variables::[cerl()], Body::cerl()) -> cerl()
1896
1897 See also: c_fun/2.
1898
1899 update_c_let(Node::c_let(), Variables::[cerl()], Argument::cerl(),
1900 Body::cerl()) -> c_let()
1901
1902 See also: c_let/3.
1903
1904 update_c_letrec(Old::cerl(), Definitions::[{cerl(), cerl()}],
1905 Body::cerl()) -> cerl()
1906
1907 See also: c_letrec/2.
1908
1909 update_c_map(C_map::c_map(), M::cerl(), Es::[cerl()]) -> c_map() |
1910 c_literal()
1911
1912 update_c_map_pair(Old::c_map_pair(), Op::map_op(), K::cerl(),
1913 V::cerl()) -> c_map_pair()
1914
1915 update_c_module(Old::cerl(), Name::cerl(), Exports, Attrs::Attributes,
1916 Es::Definitions) -> cerl()
1917
1918 Types:
1919
1920 Exports = [cerl()]
1921 Attributes = [{cerl(), cerl()}]
1922 Definitions = [{cerl(), cerl()}]
1923
1924 See also: c_module/4.
1925
1926 update_c_primop(Old::cerl(), Name::cerl(), Arguments::[cerl()]) ->
1927 cerl()
1928
1929 See also: c_primop/2.
1930
1931 update_c_receive(Old::cerl(), Clauses::[cerl()], Timeout::cerl(),
1932 Action::cerl()) -> cerl()
1933
1934 See also: c_receive/3.
1935
1936 update_c_seq(Old::cerl(), Argument::cerl(), Body::cerl()) -> cerl()
1937
1938 See also: c_seq/2.
1939
1940 update_c_try(Old::cerl(), Expression::cerl(), Variables::[cerl()],
1941 Body::cerl(), EVars::[cerl()], Handler::cerl()) -> cerl()
1942
1943 See also: c_try/5.
1944
1945 update_c_tuple(Old::cerl(), Elements::[cerl()]) -> cerl()
1946
1947 See also: c_tuple/1.
1948
1949 update_c_tuple_skel(Old::cerl(), Elements::[cerl()]) -> cerl()
1950
1951 See also: c_tuple_skel/1.
1952
1953 update_c_values(Old::cerl(), Elements::[cerl()]) -> cerl()
1954
1955 See also: c_values/1.
1956
1957 update_c_var(Old::cerl(), Name::var_name()) -> cerl()
1958
1959 See also: c_var/1.
1960
1961 update_data(Old::cerl(), Type::dtype(), Elements::[cerl()]) -> cerl()
1962
1963 See also: make_data/2.
1964
1965 update_data_skel(Old::cerl(), Type::dtype(), Elements::[cerl()]) ->
1966 cerl()
1967
1968 See also: make_data_skel/2.
1969
1970 update_list(Old::cerl(), List::[cerl()]) -> cerl()
1971
1972 Equivalent to update_list(Old, List, none).
1973
1974 update_list(Old::cerl(), List::[cerl()], Tail) -> cerl()
1975
1976 Types:
1977
1978 Tail = cerl() | none
1979
1980 See also: make_list/2, update_list/2.
1981
1982 update_tree(Old::cerl(), Groups::[[cerl()]]) -> cerl()
1983
1984 Creates a syntax tree with the given subtrees, and the same type
1985 and annotations as the Old node. This is equivalent to
1986 ann_make_tree(get_ann(Node), type(Node), Groups), but poten‐
1987 tially more efficient.
1988
1989 See also: ann_make_tree/3, get_ann/1, type/1, update_tree/3.
1990
1991 update_tree(Old::cerl(), Type::ctype(), Groups::[[cerl()]]) -> cerl()
1992
1993 Creates a syntax tree with the given type and subtrees, and the
1994 same annotations as the Old node. This is equivalent to
1995 ann_make_tree(get_ann(Node), Type, Groups), but potentially more
1996 efficient.
1997
1998 See also: ann_make_tree/3, get_ann/1, update_tree/2.
1999
2000 values_arity(Node::cerl()) -> integer()
2001
2002 Returns the number of element subtrees of an abstract value
2003 list.
2004
2005 Note: This is equivalent to length(values_es(Node)), but poten‐
2006 tially more efficient.
2007
2008 See also: c_values/1, values_es/1.
2009
2010 values_es(Node::cerl()) -> [cerl()]
2011
2012 Returns the list of element subtrees of an abstract value list.
2013
2014 See also: c_values/1, values_arity/1.
2015
2016 var_name(Node::cerl()) -> var_name()
2017
2018 Returns the name of an abstract variable.
2019
2020 See also: c_var/1.
2021
2023 Richard Carlsson <carlsson.richard@gmail.com>
2024
2025
2026
2027 compiler 7.6.7 cerl(3)