Erlang -- cerl_trees

Compiler

Reference Manual

Version 7.5.3

- Reference Manual
- Internal Documentation
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- cerl
  - Top of manual page
  - abstract/1
  - add_ann/2
  - alias_pat/1
  - alias_var/1
  - ann_abstract/2
  - ann_c_alias/3
  - ann_c_apply/3
  - ann_c_atom/2
  - ann_c_binary/2
  - ann_c_bitstr/5
  - ann_c_bitstr/6
  - ann_c_call/4
  - ann_c_case/3
  - ann_c_catch/2
  - ann_c_char/2
  - ann_c_clause/3
  - ann_c_clause/4
  - ann_c_cons/3
  - ann_c_cons_skel/3
  - ann_c_float/2
  - ann_c_fname/3
  - ann_c_fun/3
  - ann_c_int/2
  - ann_c_let/4
  - ann_c_letrec/3
  - ann_c_map/2
  - ann_c_map/3
  - ann_c_map_pair/4
  - ann_c_map_pattern/2
  - ann_c_module/4
  - ann_c_module/5
  - ann_c_nil/1
  - ann_c_primop/3
  - ann_c_receive/2
  - ann_c_receive/4
  - ann_c_seq/3
  - ann_c_string/2
  - ann_c_try/6
  - ann_c_tuple/2
  - ann_c_tuple_skel/2
  - ann_c_values/2
  - ann_c_var/2
  - ann_make_data/3
  - ann_make_data_skel/3
  - ann_make_list/2
  - ann_make_list/3
  - ann_make_tree/3
  - apply_args/1
  - apply_arity/1
  - apply_op/1
  - atom_lit/1
  - atom_name/1
  - atom_val/1
  - binary_segments/1
  - bitstr_bitsize/1
  - bitstr_flags/1
  - bitstr_size/1
  - bitstr_type/1
  - bitstr_unit/1
  - bitstr_val/1
  - c_alias/2
  - c_apply/2
  - c_atom/1
  - c_binary/1
  - c_bitstr/3
  - c_bitstr/4
  - c_bitstr/5
  - c_call/3
  - c_case/2
  - c_catch/1
  - c_char/1
  - c_clause/2
  - c_clause/3
  - c_cons/2
  - c_cons_skel/2
  - c_float/1
  - c_fname/2
  - c_fun/2
  - c_int/1
  - c_let/3
  - c_letrec/2
  - c_map/1
  - c_map_pair/2
  - c_map_pair_exact/2
  - c_map_pattern/1
  - c_module/3
  - c_module/4
  - c_nil/0
  - c_primop/2
  - c_receive/1
  - c_receive/3
  - c_seq/2
  - c_string/1
  - c_try/5
  - c_tuple/1
  - c_tuple_skel/1
  - c_values/1
  - c_var/1
  - call_args/1
  - call_arity/1
  - call_module/1
  - call_name/1
  - case_arg/1
  - case_arity/1
  - case_clauses/1
  - catch_body/1
  - char_lit/1
  - char_val/1
  - clause_arity/1
  - clause_body/1
  - clause_guard/1
  - clause_pats/1
  - clause_vars/1
  - concrete/1
  - cons_hd/1
  - cons_tl/1
  - copy_ann/2
  - data_arity/1
  - data_es/1
  - data_type/1
  - float_lit/1
  - float_val/1
  - fname_arity/1
  - fname_id/1
  - fold_literal/1
  - from_records/1
  - fun_arity/1
  - fun_body/1
  - fun_vars/1
  - get_ann/1
  - int_lit/1
  - int_val/1
  - is_c_alias/1
  - is_c_apply/1
  - is_c_atom/1
  - is_c_binary/1
  - is_c_bitstr/1
  - is_c_call/1
  - is_c_case/1
  - is_c_catch/1
  - is_c_char/1
  - is_c_clause/1
  - is_c_cons/1
  - is_c_float/1
  - is_c_fname/1
  - is_c_fun/1
  - is_c_int/1
  - is_c_let/1
  - is_c_letrec/1
  - is_c_list/1
  - is_c_map/1
  - is_c_map_empty/1
  - is_c_map_pattern/1
  - is_c_module/1
  - is_c_nil/1
  - is_c_primop/1
  - is_c_receive/1
  - is_c_seq/1
  - is_c_string/1
  - is_c_try/1
  - is_c_tuple/1
  - is_c_values/1
  - is_c_var/1
  - is_data/1
  - is_leaf/1
  - is_literal/1
  - is_literal_term/1
  - is_print_char/1
  - is_print_string/1
  - let_arg/1
  - let_arity/1
  - let_body/1
  - let_vars/1
  - letrec_body/1
  - letrec_defs/1
  - letrec_vars/1
  - list_elements/1
  - list_length/1
  - make_data/2
  - make_data_skel/2
  - make_list/1
  - make_list/2
  - make_tree/2
  - map_arg/1
  - map_es/1
  - map_pair_key/1
  - map_pair_op/1
  - map_pair_val/1
  - meta/1
  - module_attrs/1
  - module_defs/1
  - module_exports/1
  - module_name/1
  - module_vars/1
  - pat_list_vars/1
  - pat_vars/1
  - primop_args/1
  - primop_arity/1
  - primop_name/1
  - receive_action/1
  - receive_clauses/1
  - receive_timeout/1
  - seq_arg/1
  - seq_body/1
  - set_ann/2
  - string_lit/1
  - string_val/1
  - subtrees/1
  - to_records/1
  - try_arg/1
  - try_body/1
  - try_evars/1
  - try_handler/1
  - try_vars/1
  - tuple_arity/1
  - tuple_es/1
  - type/1
  - unfold_literal/1
  - update_c_alias/3
  - update_c_apply/3
  - update_c_binary/2
  - update_c_bitstr/5
  - update_c_bitstr/6
  - update_c_call/4
  - update_c_case/3
  - update_c_catch/2
  - update_c_clause/4
  - update_c_cons/3
  - update_c_cons_skel/3
  - update_c_fname/2
  - update_c_fname/3
  - update_c_fun/3
  - update_c_let/4
  - update_c_letrec/3
  - update_c_map/3
  - update_c_map_pair/4
  - update_c_module/5
  - update_c_primop/3
  - update_c_receive/4
  - update_c_seq/3
  - update_c_try/6
  - update_c_tuple/2
  - update_c_tuple_skel/2
  - update_c_values/2
  - update_c_var/2
  - update_data/3
  - update_data_skel/3
  - update_list/2
  - update_list/3
  - update_tree/2
  - update_tree/3
  - values_arity/1
  - values_es/1
  - var_name/1
- cerl_trees
  - Top of manual page
  - depth/1
  - fold/3
  - free_variables/1
  - get_label/1
  - label/1
  - label/2
  - map/2
  - mapfold/3
  - mapfold/4
  - next_free_variable_name/1
  - size/1
  - variables/1
- cerl_clauses
  - Top of manual page
  - any_catchall/1
  - eval_guard/1
  - is_catchall/1
  - match/2
  - match_list/2
  - reduce/1
  - reduce/2

# cerl_trees

### Module

cerl_trees

### Module Summary

Basic functions on Core Erlang abstract syntax trees.

### Description

Basic functions on Core Erlang abstract syntax trees.

Syntax trees are defined in the module cerl.

### DATA TYPES

cerl() = cerl:cerl()

### Exports

depth(Tree::cerl()) -> integer() |

Returns the length of the longest path in the tree. A leaf node has depth zero, the tree representing "{foo, bar}" has depth one, etc.

fold(F::Function, Unit::term(), Tree::cerl()) -> term() |

### Types

Function = (cerl(), term()) -> term()

Does a fold operation over the nodes of the tree. The result is the value of Function(X1, Function(X2, ... Function(Xn, Unit) ... )), where X1, ..., Xn are the nodes of Tree in a post-order traversal.

See also: mapfold/3.

free_variables(Tree::cerl()) -> [var_name()] |

Like variables/1, but only includes variables that are free in the tree.

See also: next_free_variable_name/1, variables/1.

get_label(T::cerl:cerl()) -> top | integer() |

label(T::cerl:cerl()) -> {cerl:cerl(), integer()} |

Equivalent to label(Tree, 0).

label(Tree::cerl(), N::integer()) -> {cerl(), integer()} |

Labels each expression in the tree. A term {label, L} is prefixed to the annotation list of each expression node, where L is a unique number for every node, except for variables (and function name variables) which get the same label if they represent the same variable. Constant literal nodes are not labeled.

The returned value is a tuple {NewTree, Max}, where NewTree is the labeled tree and Max is 1 plus the largest label value used. All previous annotation terms on the form {label, X} are deleted.

The values of L used in the tree is a dense range from N to Max - 1, where N =< Max =< N + size(Tree). Note that it is possible that no labels are used at all, i.e., N = Max.

Note: All instances of free variables will be given distinct labels.

See also: label/1, size/1.

map(F::Function, Tree::cerl()) -> cerl() |

### Types

Function = (cerl()) -> cerl()

Maps a function onto the nodes of a tree. This replaces each node in the tree by the result of applying the given function on the original node, bottom-up.

See also: mapfold/3.

mapfold(F::Function, Initial::term(), Tree::cerl()) -> {cerl(), term()} |

### Types

Function = (cerl(), term()) -> {cerl(), term()}

Does a combined map/fold operation on the nodes of the tree. This is similar to map/2, but also propagates a value from each application of Function to the next, starting with the given value Initial, while doing a post-order traversal of the tree, much like fold/3.

This is the same as mapfold/4, with an identity function as the pre-operation.

See also: fold/3, map/2, mapfold/4.

mapfold(Pre, Post, Initial::term(), Tree::cerl()) -> {cerl(), term()} |

### Types

Pre = (cerl(), term()) -> {cerl(), term()}
Post = (cerl(), term()) -> {cerl(), term()}

Does a combined map/fold operation on the nodes of the tree. It begins by calling Pre on the tree, using the Initial value. It then deconstructs the top node of the returned tree and recurses on the children, using the returned value as the new initial and carrying the returned values from one call to the next. Finally it reassembles the top node from the children, calls Post on it and returns the result.

next_free_variable_name(Tree::cerl()) -> var_name() |

### Types

var_name() = integer()

Returns a integer variable name higher than any other integer variable name in the syntax tree. An exception is thrown if Tree does not represent a well-formed Core Erlang syntax tree.

See also: free_variables/1, variables/1.

size(Tree::cerl()) -> integer() |

Returns the number of nodes in Tree.

variables(Tree::cerl()) -> [var_name()] |

### Types

var_name() = integer() | atom() | {atom(), integer()}

Returns an ordered-set list of the names of all variables in the syntax tree. (This includes function name variables.) An exception is thrown if Tree does not represent a well-formed Core Erlang syntax tree.

See also: free_variables/1, next_free_variable_name/1.

Richard Carlsson carlsson.richard@gmail.com