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

AUTHORS

146       Richard Carlsson <carlsson.richard@gmail.com>
147
148
149
150                               compiler 7.6.9.1                  cerl_trees(3)
Impressum