1cerl_trees(3)              Erlang Module Definition              cerl_trees(3)
2
3
4

NAME

6       cerl_trees - Basic functions on Core Erlang abstract syntax trees.
7

DESCRIPTION

9       Basic functions on Core Erlang abstract syntax trees.
10
11       Syntax trees are defined in the module cerl.
12

DATA TYPES

14         cerl() = cerl:cerl():
15
16

EXPORTS

18       depth(T::cerl:cerl()) -> non_neg_integer()
19
20              Returns  the length of the longest path in the tree. A leaf node
21              has depth zero, the tree representing  "{foo,  bar}"  has  depth
22              one, etc.
23
24       fold(F::(cerl:cerl(),  term()) -> term(), S::term(), T::cerl:cerl()) ->
25       term()
26
27              Does a fold operation over the nodes of the tree. The result  is
28              the  value  of  Function(X1, Function(X2, ... Function(Xn, Unit)
29              ... )), where X1, ..., Xn are the nodes of Tree in a  post-order
30              traversal.
31
32              See also: mapfold/3.
33
34       free_variables(T::cerl:cerl()) -> [cerl:var_name()]
35
36              Like  variables/1,  but only includes variables that are free in
37              the tree.
38
39              See also: next_free_variable_name/1, variables/1.
40
41       get_label(T::cerl:cerl()) -> top | integer()
42
43       label(T::cerl:cerl()) -> {cerl:cerl(), integer()}
44
45              Equivalent to label(Tree, 0).
46
47       label(T::cerl:cerl(), N::integer()) -> {cerl:cerl(), integer()}
48
49              Labels each expression in the tree. A term {label,  L}  is  pre‐
50              fixed to the annotation list of each expression node, where L is
51              a unique number for every node, except for variables (and  func‐
52              tion  name variables) which get the same label if they represent
53              the same variable. Constant literal nodes are not labeled.
54
55              The returned value is a tuple {NewTree, Max}, where  NewTree  is
56              the labeled tree and Max is 1 plus the largest label value used.
57              All previous  annotation  terms  on  the  form  {label,  X}  are
58              deleted.
59
60              The  values of L used in the tree is a dense range from N to Max
61              - 1, where N =< Max =< N + size(Tree). Note that it is  possible
62              that no labels are used at all, i.e., N = Max.
63
64              Note: All instances of free variables will be given distinct la‐
65              bels.
66
67              See also: label/1, size/1.
68
69       map(F::(cerl:cerl()) -> cerl:cerl(), T::cerl:cerl()) -> cerl:cerl()
70
71              Maps a function onto the nodes of a  tree.  This  replaces  each
72              node in the tree by the result of applying the given function on
73              the original node, bottom-up.
74
75              See also: mapfold/3.
76
77       mapfold(F::(cerl:cerl(), term()) -> {cerl:cerl(), term()},  S0::term(),
78       T::cerl:cerl()) -> {cerl:cerl(), term()}
79
80              Does  a  combined  map/fold  operation on the nodes of the tree.
81              This is similar to map/2, but also propagates a value from  each
82              application  of  Function  to  the next, starting with the given
83              value Initial, while doing a post-order traversal of  the  tree,
84              much like fold/3.
85
86              This  is the same as mapfold/4, with an identity function as the
87              pre-operation.
88
89              See also: fold/3, map/2, mapfold/4.
90
91       mapfold(Pre::(cerl:cerl(), term()) ->  {cerl:cerl(),  term()}  |  skip,
92       Post::(cerl:cerl(),  term())  ->  {cerl:cerl(),  term()},  S00::term(),
93       T0::cerl:cerl()) -> {cerl:cerl(), term()}
94
95              Does a combined map/fold operation on the nodes of the tree.  It
96              begins  by calling Pre on the tree, using the Initial value. Pre
97              must either return a tree with an  updated  accumulator  or  the
98              atom skip.
99
100              If  a  tree is returned, this function deconstructs the top node
101              of the returned tree and recurses on the children, using the re‐
102              turned value as the new initial and carrying the returned values
103              from one call to the next. Finally it reassembles the  top  node
104              from the children, calls Post on it and returns the result.
105
106              If skip is returned, it returns the tree and accumulator as is.
107
108       next_free_variable_name(T::cerl:cerl()) -> integer()
109
110              Returns  a  integer  variable name higher than any other integer
111              variable name in the syntax tree. An exception is thrown if Tree
112              does not represent a well-formed Core Erlang syntax tree.
113
114              See also: free_variables/1, variables/1.
115
116       size(T::cerl:cerl()) -> non_neg_integer()
117
118              Returns the number of nodes in Tree.
119
120       variables(T::cerl:cerl()) -> [cerl:var_name()]
121
122              Returns an ordered-set list of the names of all variables in the
123              syntax tree. (This includes function name variables.) An  excep‐
124              tion is thrown if Tree does not represent a well-formed Core Er‐
125              lang syntax tree.
126
127              See also: free_variables/1, next_free_variable_name/1.
128

AUTHORS

130       Richard Carlsson <carlsson.richard@gmail.com>
131
132
133
134                                compiler 8.2.3                   cerl_trees(3)
Impressum