cerl (compiler v8.0.2)

Core Erlang abstract syntax trees.

This module defines an abstract data type for representing Core Erlang source code as syntax trees.

A recommended starting point for the first-time user is the documentation of the function type/1.

NOTES:

This module deals with the composition and decomposition of syntactic entities (as opposed to semantic ones); its purpose is to hide all direct references to the data structures used to represent these entities. With few exceptions, the functions in this module perform no semantic interpretation of their inputs, and in general, the user is assumed to pass type-correct arguments - if this is not done, the effects are not defined.

Currently, the internal data structure used is the same as the record-based data structures used traditionally in the Beam compiler.

The internal representations of abstract syntax trees are subject to change without notice, and should not be documented outside this module. Furthermore, we do not give any guarantees on how an abstract syntax tree may or may not be represented, with the following exceptions: no syntax tree is represented by a single atom, such as none, by a list constructor [X | Y], or by the empty list []. This can be relied on when writing functions that operate on syntax trees.

DATA TYPES

c_alias() = #c_alias{}

c_apply() = #c_apply{}

c_binary() = #c_binary{}

c_bitstr() = #c_bitstr{}

c_call() = #c_call{}

c_case() = #c_case{}

c_catch() = #c_catch{}

c_clause() = #c_clause{}

c_cons() = #c_cons{}

c_fun() = #c_fun{}

c_lct() = c_literal() | c_cons() | c_tuple()

c_let() = #c_let{}

c_letrec() = #c_letrec{}

c_literal() = #c_literal{}

c_map() = #c_map{}

c_map_pair() = #c_map_pair{}

c_module() = #c_module{}

c_primop() = #c_primop{}

c_receive() = #c_receive{}

c_seq() = #c_seq{}

c_try() = #c_try{}

c_tuple() = #c_tuple{}

c_values() = #c_values{}

c_var() = #c_var{}

cerl() = c_alias() | c_apply() | c_binary() | c_bitstr() | c_call() | c_case() | c_catch() | c_clause() | c_cons() | c_fun() | c_let() | c_letrec() | c_literal() | c_map() | c_map_pair() | c_module() | c_primop() | c_receive() | c_seq() | c_try() | c_tuple() | c_values() | c_var()

ctype() = alias | apply | binary | bitstr | call | case | catch | clause | cons | fun | let | letrec | literal | map | map_pair | module | primop | receive | seq | try | tuple | values | var

dtype() = cons | tuple | {atomic, value()}

map_op() = #c_literal{val=assoc} | #c_literal{val=exact}

value() = integer() | float() | atom() | []

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

Link to this section Summary

Functions

Creates a syntax tree corresponding to an Erlang term. Term must be a literal term, i.e., one that can be represented as a source code literal. Thus, it may not contain a process identifier, port, reference, binary or function value as a subterm.

Appends Annotations to the list of user annotations of Node.

Returns the pattern subtree of an abstract pattern alias.

Returns the variable subtree of an abstract pattern alias.

Creates a syntax tree with the given annotations, type and subtrees. See make_tree/2 for details.

Returns the list of argument subtrees of an abstract function application.

Returns the number of argument subtrees of an abstract function application.

Returns the operator subtree of an abstract function application.

Returns the literal string represented by an abstract atom. This always includes surrounding single-quote characters.

Returns the printname of an abstract atom.

Returns the value represented by an abstract atom.

Returns the list of segment subtrees of an abstract binary-template.

Returns the total size in bits of an abstract bit-string template. If the size field is an integer literal, the result is the product of the size and unit values; if the size field is the atom literal all, the atom all is returned. If the size is not a literal, the atom any is returned.

Returns the flags subtree of an abstract bit-string template.

Returns the size subtree of an abstract bit-string template.

Returns the type subtree of an abstract bit-string template.

Returns the unit subtree of an abstract bit-string template.

Returns the value subtree of an abstract bit-string template.

Creates an abstract pattern alias. The result represents "Variable = Pattern".

Creates an abstract function application. If Arguments is [A1, ..., An], the result represents "apply Operator(A1, ..., An)".

Creates an abstract atom literal. The print name of the atom is the character sequence represented by Name.

Creates an abstract binary-template. A binary object is in this context a sequence of an arbitrary number of bits. (The number of bits used to be evenly divisible by 8, but after the introduction of bit strings in the Erlang language, the choice was made to use the binary template for all bit strings.) It is specified by zero or more bit-string template segments of arbitrary lengths (in number of bits). If Segments is [S1, ..., Sn], the result represents "#{S1, ..., Sn}#". All the Si must have type bitstr.

Creates an abstract bit-string template. These can only occur as components of an abstract binary-template (see c_binary/1). The result represents "#<Value>(Size, Unit, Type, Flags)", where Unit must represent a positive integer constant, Type must represent a constant atom (one of 'integer', 'float', or 'binary'), and Flags must represent a constant list "[F1, ..., Fn]" where all the Fi are atoms.

Creates an abstract inter-module call. If Arguments is [A1, ..., An], the result represents "call Module:Name(A1, ..., An)".

Creates an abstract case-expression. If Clauses is [C1, ..., Cn], the result represents "case Argument of C1 ... Cn end". Clauses must not be empty.

Creates an abstract catch-expression. The result represents "catch Body".

Creates an abstract character literal. If the local implementation of Erlang defines char() as a subset of integer(), this function is equivalent to c_int/1. Otherwise, if the given value is an integer, it will be converted to the character with the corresponding code. The lexical representation of a character is "$Char", where Char is a single printing character or an escape sequence.

Creates an an abstract clause. If Patterns is [P1, ..., Pn], the result represents "<P1, ..., Pn> when Guard -> Body".

Creates an abstract list constructor. The result represents "[Head | Tail]". Note that if both Head and Tail have type literal, then the result will also have type literal, and annotations on Head and Tail are lost.

Creates an abstract list constructor skeleton. Does not fold constant literals, i.e., the result always has type cons, representing "[Head | Tail]".

Creates an abstract floating-point literal. The lexical representation is the decimal floating-point numeral of Value.

Creates an abstract fun-expression. If Variables is [V1, ..., Vn], the result represents "fun (V1, ..., Vn) -> Body". All the Vi must have type var.

Creates an abstract integer literal. The lexical representation is the canonical decimal numeral of Value.

Creates an abstract let-expression. If Variables is [V1, ..., Vn], the result represents "let <V1, ..., Vn> = Argument in Body". All the Vi must have type var.

Creates an abstract letrec-expression. If Definitions is [{V1, F1}, ..., {Vn, Fn}], the result represents "letrec V1 = F1 ... Vn = Fn in Body. All the Vi must have type var and represent function names. All the Fi must have type 'fun'.

Creates an abstract empty list. The result represents "[]". The empty list is traditionally called "nil".

Creates an abstract primitive operation call. If Arguments is [A1, ..., An], the result represents "primop Name(A1, ..., An)". Name must be an atom literal.

Creates an abstract receive-expression. If Clauses is [C1, ..., Cn], the result represents "receive C1 ... Cn after Timeout -> Action end".

Creates an abstract sequencing expression. The result represents "do Argument Body".

Creates an abstract string literal. Equivalent to creating an abstract list of the corresponding character literals (cf. is_c_string/1), but is typically more efficient. The lexical representation of a string is ""Chars"", where Chars is a sequence of printing characters or spaces.

Creates an abstract try-expression. If Variables is [V1, ..., Vn] and ExceptionVars is [X1, ..., Xm], the result represents "try Argument of <V1, ..., Vn> -> Body catch <X1, ..., Xm> -> Handler". All the Vi and Xi must have type var.

Creates an abstract tuple. If Elements is [E1, ..., En], the result represents "{E1, ..., En}". Note that if all nodes in Elements have type literal, or if Elements is empty, then the result will also have type literal and annotations on nodes in Elements are lost.

Creates an abstract tuple skeleton. Does not fold constant literals, i.e., the result always has type tuple, representing "{E1, ..., En}", if Elements is [E1, ..., En].

Creates an abstract value list. If Elements is [E1, ..., En], the result represents "<E1, ..., En>".

Creates an abstract variable. A variable is identified by its name, given by the Name parameter.

Returns the list of argument subtrees of an abstract inter-module call.

Returns the number of argument subtrees of an abstract inter-module call.

Returns the module subtree of an abstract inter-module call.

Returns the name subtree of an abstract inter-module call.

Returns the argument subtree of an abstract case-expression.

Equivalent to clause_arity(hd(case_clauses(Node))), but potentially more efficient.

Returns the list of clause subtrees of an abstract case-expression.

Returns the body subtree of an abstract catch-expression.

Returns the literal string represented by an abstract character. This includes a leading $ character. Currently, all characters that are not in the set of ISO 8859-1 (Latin-1) "printing" characters will be escaped.

Returns the value represented by an abstract character literal.

Returns the number of pattern subtrees of an abstract clause.

Returns the body subtree of an abstract clause.

Returns the guard subtree of an abstract clause.

Returns the list of pattern subtrees of an abstract clause.

Returns the list of all abstract variables in the patterns of an abstract clause. The order of listing is not defined.

Returns the Erlang term represented by a syntax tree. An exception is thrown if Node does not represent a literal term.

Returns the head subtree of an abstract list constructor.

Returns the tail subtree of an abstract list constructor.

Copies the list of user annotations from Source to Target.

Returns the number of subtrees of a data constructor node. This is equivalent to length(data_es(Node)), but potentially more efficient.

Returns the list of subtrees of a data constructor node. If the arity of the constructor is zero, the result is the empty list.

Returns a type descriptor for a data constructor node. (Cf. is_data/1.) This is mainly useful for comparing types and for constructing new nodes of the same type (cf. make_data/2). If Node represents an integer, floating-point number, atom or empty list, the result is {atomic, Value}, where Value is the value of concrete(Node), otherwise the result is either cons or tuple.

Returns the numeral string represented by a floating-point literal node.

Returns the value represented by a floating-point literal node.

Returns the arity part of an abstract function name variable.

Returns the identifier part of an abstract function name variable.

Assures that literals have a compact representation. This is occasionally useful if c_cons_skel/2, c_tuple_skel/1 or unfold_literal/1 were used in the construction of Node, and you want to revert to the normal "folded" representation of literals. If Node represents a tuple or list constructor, its elements are rewritten recursively, and the node is reconstructed using c_cons/2 or c_tuple/1, respectively; otherwise, Node is not changed.

Translates an explicit record representation to a corresponding abstract syntax tree. The records are defined in the file "core_parse.hrl".

Returns the number of parameter subtrees of an abstract fun-expression.

Returns the body subtree of an abstract fun-expression.

Returns the list of parameter subtrees of an abstract fun-expression.

Returns the list of user annotations associated with a syntax tree node. For a newly created node, this is the empty list. The annotations may be any terms.

Returns the numeral string represented by an integer literal node.

Returns the value represented by an integer literal node.

Returns true if Node is an abstract pattern alias, otherwise false.

Returns true if Node is an abstract function application, otherwise false.

Returns true if Node represents an atom literal, otherwise false.

Returns true if Node is an abstract binary-template; otherwise false.

Returns true if Node is an abstract bit-string template; otherwise false.

Returns true if Node is an abstract inter-module call expression; otherwise false.

Returns true if Node is an abstract case-expression; otherwise false.

Returns true if Node is an abstract catch-expression, otherwise false.

Returns true if Node may represent a character literal, otherwise false.

Returns true if Node is an abstract clause, otherwise false.

Returns true if Node is an abstract list constructor, otherwise false.

Returns true if Node represents a floating-point literal, otherwise false.

Returns true if Node is an abstract function name variable, otherwise false.

Returns true if Node is an abstract fun-expression, otherwise false.

Returns true if Node represents an integer literal, otherwise false.

Returns true if Node is an abstract let-expression, otherwise false.

Returns true if Node is an abstract letrec-expression, otherwise false.

Returns true if Node represents a proper list, otherwise false. A proper list is either the empty list [], or a cons cell [Head | Tail], where recursively Tail is a proper list.

Returns true if Node is an abstract map constructor, otherwise false.

Returns true if Node is an abstract module definition, otherwise false.

Returns true if Node is an abstract empty list, otherwise false.

Returns true if Node is an abstract primitive operation call, otherwise false.

Returns true if Node is an abstract receive-expression, otherwise false.

Returns true if Node is an abstract sequencing expression, otherwise false.

Returns true if Node may represent a string literal, otherwise false. Strings are defined as lists of characters; see is_c_char/1 for details.

Returns true if Node is an abstract try-expression, otherwise false.

Returns true if Node is an abstract tuple, otherwise false.

Returns true if Node is an abstract value list; otherwise false.

Returns true if Node is an abstract variable, otherwise false.

Returns true if Node represents a data constructor, otherwise false. Data constructors are cons cells, tuples, and atomic literals.

Returns true if Node is a leaf node, otherwise false. The current leaf node types are literal and var.

Returns true if Node represents a literal term, otherwise false. This function returns true if and only if the value of concrete(Node) is defined.

Returns true if Term can be represented as a literal, otherwise false. This function takes time proportional to the size of Term.

Returns true if Node may represent a "printing" character, otherwise false. (Cf. is_c_char/1.) A "printing" character has either a given graphical representation, or a "named" escape sequence such as "\n". Currently, only ISO 8859-1 (Latin-1) character values are recognized.

Returns true if Node may represent a string literal containing only "printing" characters, otherwise false. See is_c_string/1 and is_print_char/1 for details. Currently, only ISO 8859-1 (Latin-1) character values are recognized.

Returns the argument subtree of an abstract let-expression.

Returns the number of left-hand side variables of an abstract let-expression.

Returns the body subtree of an abstract let-expression.

Returns the list of left-hand side variables of an abstract let-expression.

Returns the body subtree of an abstract letrec-expression.

Returns the list of definitions of an abstract letrec-expression. If Node represents "letrec V1 = F1 ... Vn = Fn in Body", the returned value is [{V1, F1}, ..., {Vn, Fn}].

Returns the list of left-hand side function variable subtrees of a letrec-expression. If Node represents "letrec V1 = F1 ... Vn = Fn in Body", the returned value is [V1, ..., Vn].

Returns the list of element subtrees of an abstract list. Node must represent a proper list. E.g., if Node represents "[X1, X2 | [X3, X4 | []]", then list_elements(Node) yields the list [X1, X2, X3, X4].

Returns the number of element subtrees of an abstract list. Node must represent a proper list. E.g., if Node represents "[X1 | [X2, X3 | [X4, X5, X6]]]", then list_length(Node) returns the integer 6.

Creates a data constructor node with the specified type and subtrees. (Cf. data_type/1.) An exception is thrown if the length of Elements is invalid for the given Type; see data_es/1 for arity constraints on constructor types.

Like make_data/2, but analogous to c_tuple_skel/1 and c_cons_skel/2.

Creates an abstract list from the elements in List and the optional Tail. If Tail is none, the result will represent a nil-terminated list, otherwise it represents "[... | Tail]".

Creates a syntax tree with the given type and subtrees. Type must be a node type name (cf. type/1) that does not denote a leaf node type (cf. is_leaf/1). Groups must be a nonempty list of groups of syntax trees, representing the subtrees of a node of the given type, in left-to-right order as they would occur in the printed program text, grouped by category as done by subtrees/1.

Creates a meta-representation of a syntax tree. The result represents an Erlang expression "MetaTree" which, if evaluated, will yield a new syntax tree representing the same source code text as Tree (although the actual data representation may be different). The expression represented by MetaTree is implementation independent with regard to the data structures used by the abstract syntax tree implementation.

Returns the list of pairs of attribute key/value subtrees of an abstract module definition.

Returns the list of function definitions of an abstract module definition.

Returns the list of exports subtrees of an abstract module definition.

Returns the name subtree of an abstract module definition.

Returns the list of left-hand side function variable subtrees of an abstract module definition.

Returns the list of all abstract variables in the given patterns. An exception is thrown if some element in Patterns does not represent a well-formed Core Erlang clause pattern. The order of listing is not defined.

Returns the list of all abstract variables in a pattern. An exception is thrown if Node does not represent a well-formed Core Erlang clause pattern. The order of listing is not defined.

Returns the list of argument subtrees of an abstract primitive operation call.

Returns the number of argument subtrees of an abstract primitive operation call.

Returns the name subtree of an abstract primitive operation call.

Returns the action subtree of an abstract receive-expression.

Returns the list of clause subtrees of an abstract receive-expression.

Returns the timeout subtree of an abstract receive-expression.

Returns the argument subtree of an abstract sequencing expression.

Returns the body subtree of an abstract sequencing expression.

Sets the list of user annotations of Node to Annotations.

Returns the literal string represented by an abstract string. This includes surrounding double-quote characters "...". Currently, characters that are not in the set of ISO 8859-1 (Latin-1) "printing" characters will be escaped, except for spaces.

Returns the value represented by an abstract string literal.

Returns the grouped list of all subtrees of a node. If Node is a leaf node (cf. is_leaf/1), this is the empty list, otherwise the result is always a nonempty list, containing the lists of subtrees of Node, in left-to-right order as they occur in the printed program text, and grouped by category. Often, each group contains only a single subtree.

Translates an abstract syntax tree to a corresponding explicit record representation. The records are defined in the file "cerl.hrl".

Returns the expression subtree of an abstract try-expression.

Returns the success body subtree of an abstract try-expression.

Returns the list of exception variable subtrees of an abstract try-expression.

Returns the exception body subtree of an abstract try-expression.

Returns the list of success variable subtrees of an abstract try-expression.

Returns the number of element subtrees of an abstract tuple.

Returns the list of element subtrees of an abstract tuple.

Returns the type tag of Node. Current node types are

Assures that literals have a fully expanded representation. If Node represents a literal tuple or list constructor, its elements are rewritten recursively, and the node is reconstructed using c_cons_skel/2 or c_tuple_skel/1, respectively; otherwise, Node is not changed. The fold_literal/1 can be used to revert to the normal compact representation.

Like update_c_fname/3, but takes the arity from Node.

Creates a syntax tree with the given subtrees, and the same type and annotations as the Old node. This is equivalent to ann_make_tree(get_ann(Node), type(Node), Groups), but potentially more efficient.

Creates a syntax tree with the given type and subtrees, and the same annotations as the Old node. This is equivalent to ann_make_tree(get_ann(Node), Type, Groups), but potentially more efficient.

Returns the number of element subtrees of an abstract value list.

Returns the list of element subtrees of an abstract value list.

Returns the name of an abstract variable.

Link to this section Functions

Link to this function

abstract(T::term()) -> c_literal()

Specs

abstract(term()) -> c_literal().

Creates a syntax tree corresponding to an Erlang term. Term must be a literal term, i.e., one that can be represented as a source code literal. Thus, it may not contain a process identifier, port, reference, binary or function value as a subterm.

Note: This is a constant time operation.

See also: ann_abstract/2, concrete/1, is_literal/1, is_literal_term/1.

Link to this function

add_ann(Terms::[term()], Node:: cerl() ) -> cerl()

Specs

add_ann([term()], cerl()) -> cerl().

Appends Annotations to the list of user annotations of Node.

Note: this is equivalent to set_ann(Node, Annotations ++ get_ann(Node)), but potentially more efficient.

See also: get_ann/1, set_ann/2.

Link to this function

alias_pat(Node:: c_alias() ) -> cerl()

Specs

alias_pat(c_alias()) -> cerl().

Returns the pattern subtree of an abstract pattern alias.

See also: c_alias/2.

Link to this function

alias_var(Node:: c_alias() ) -> c_var()

Specs

alias_var(c_alias()) -> c_var().

Returns the variable subtree of an abstract pattern alias.

See also: c_alias/2.

Link to this function

ann_abstract(As::[term()], T::term()) -> c_literal()

Specs

ann_abstract([term()], term()) -> c_literal().

See also: abstract/1.

Link to this function

ann_c_alias(As::[term()], Var:: c_var() , Pattern:: cerl() ) -> c_alias()

Specs

ann_c_alias([term()], c_var(), cerl()) -> c_alias().

See also: c_alias/2.

Link to this function

ann_c_apply(As::[term()], Operator:: cerl() , Arguments::[ cerl() ]) -> c_apply()

Specs

ann_c_apply([term()], cerl(), [cerl()]) -> c_apply().

See also: c_apply/2.

Link to this function

ann_c_atom(As::[term()], Name::atom() | string()) -> c_literal()

Specs

ann_c_atom([term()], atom() | string()) -> c_literal().

See also: c_atom/1.

Link to this function

ann_c_binary(As::[term()], Segments::[ cerl() ]) -> c_binary()

Specs

ann_c_binary([term()], [cerl()]) -> c_binary().

See also: c_binary/1.

Link to this function

ann_c_bitstr(As::[term()], Value:: cerl() , Size:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

ann_c_bitstr([term()], cerl(), cerl(), cerl(), cerl()) -> c_bitstr().

Equivalent to ann_c_bitstr(As, Value, Size, abstract(1), Type, Flags).

Link to this function

ann_c_bitstr(As::[term()], Val:: cerl() , Size:: cerl() , Unit:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

ann_c_bitstr([term()], cerl(), cerl(), cerl(), cerl(), cerl()) -> c_bitstr().

See also: ann_c_bitstr/5, c_bitstr/5.

Link to this function

ann_c_call(As::[term()], Module:: cerl() , Name:: cerl() , Arguments::[ cerl() ]) -> c_call()

Specs

ann_c_call([term()], cerl(), cerl(), [cerl()]) -> c_call().

See also: c_call/3.

Link to this function

ann_c_case(As::[term()], Expr:: cerl() , Clauses::[ cerl() ]) -> c_case()

Specs

ann_c_case([term()], cerl(), [cerl()]) -> c_case().

See also: c_case/2.

Link to this function

ann_c_catch(As::[term()], Body:: cerl() ) -> c_catch()

Specs

ann_c_catch([term()], cerl()) -> c_catch().

See also: c_catch/1.

Link to this function

ann_c_char(As::[term()], Value::char()) -> c_literal()

Specs

ann_c_char([term()], char()) -> c_literal().

See also: c_char/1.

Link to this function

ann_c_clause(As::[term()], Patterns::[ cerl() ], Body:: cerl() ) -> c_clause()

Specs

ann_c_clause([term()], [cerl()], cerl()) -> c_clause().

Equivalent to ann_c_clause(As, Patterns, c_atom(true), Body).

See also: c_clause/3.

Link to this function

ann_c_clause(As::[term()], Patterns::[ cerl() ], Guard:: cerl() , Body:: cerl() ) -> c_clause()

Specs

ann_c_clause([term()], [cerl()], cerl(), cerl()) -> c_clause().

See also: ann_c_clause/3, c_clause/3.

Link to this function

ann_c_cons(As::[term()], C_literal:: cerl() , Tail:: cerl() ) -> c_literal() | c_cons()

Specs

ann_c_cons([term()], cerl(), cerl()) -> c_literal() | c_cons().

See also: c_cons/2.

Link to this function

ann_c_cons_skel(As::[term()], Head:: cerl() , Tail:: cerl() ) -> c_cons()

Specs

ann_c_cons_skel([term()], cerl(), cerl()) -> c_cons().

See also: c_cons_skel/2.

Link to this function

ann_c_float(As::[term()], Value::float()) -> c_literal()

Specs

ann_c_float([term()], float()) -> c_literal().

See also: c_float/1.

Link to this function

ann_c_fname(As::[term()], Atom::atom(), Arity::arity()) -> c_var()

Specs

ann_c_fname([term()], atom(), arity()) -> c_var().

Equivalent to ann_c_var(As, {Atom, Arity}).

See also: c_fname/2.

Link to this function

ann_c_fun(As::[term()], Variables::[ cerl() ], Body:: cerl() ) -> c_fun()

Specs

ann_c_fun([term()], [cerl()], cerl()) -> c_fun().

See also: c_fun/2.

Link to this function

ann_c_int(As::[term()], Value::integer()) -> c_literal()

Specs

ann_c_int([term()], integer()) -> c_literal().

See also: c_int/1.

Link to this function

ann_c_let(As::[term()], Variables::[ cerl() ], Argument:: cerl() , Body:: cerl() ) -> c_let()

Specs

ann_c_let([term()], [cerl()], cerl(), cerl()) -> c_let().

See also: c_let/3.

Link to this function

ann_c_letrec(As::[term()], Defs::[{ cerl() , cerl() }], Body:: cerl() ) -> c_letrec()

Specs

ann_c_letrec([term()], [{cerl(), cerl()}], cerl()) -> c_letrec().

See also: c_letrec/2.

Link to this function

ann_c_map(As::[term()], Es::[ c_map_pair() ]) -> c_map() | c_literal()

Specs

ann_c_map([term()], [c_map_pair()]) -> c_map() | c_literal().
Link to this function

ann_c_map(As::[term()], C_literal:: c_map() | c_literal() , Es::[ c_map_pair() ]) -> c_map() | c_literal()

Specs

ann_c_map([term()], c_map() | c_literal(), [c_map_pair()]) -> c_map() | c_literal().
Link to this function

ann_c_map_pair(As::[term()], Op:: cerl() , K:: cerl() , V:: cerl() ) -> c_map_pair()

Specs

ann_c_map_pair([term()], cerl(), cerl(), cerl()) -> c_map_pair().
Link to this function

ann_c_map_pattern(As::[term()], Pairs::[ c_map_pair() ]) -> c_map()

Specs

ann_c_map_pattern([term()], [c_map_pair()]) -> c_map().
Link to this function

ann_c_module(As::[term()], Name:: cerl() , Exports::[ cerl() ], Es::[{ cerl() , cerl() }]) -> c_module()

Specs

ann_c_module([term()], cerl(), [cerl()], [{cerl(), cerl()}]) -> c_module().

See also: ann_c_module/5, c_module/3.

Link to this function

ann_c_module(As::[term()], Name:: cerl() , Exports::[ cerl() ], Attrs::[{ cerl() , cerl() }], Es::[{ cerl() , cerl() }]) -> c_module()

Specs

ann_c_module([term()], cerl(), [cerl()], [{cerl(), cerl()}], [{cerl(), cerl()}]) -> c_module().

See also: ann_c_module/4, c_module/4.

Link to this function

ann_c_nil(As::[term()]) -> c_literal()

Specs

ann_c_nil([term()]) -> c_literal().

See also: c_nil/0.

Link to this function

ann_c_primop(As::[term()], Name:: cerl() , Arguments::[ cerl() ]) -> c_primop()

Specs

ann_c_primop([term()], cerl(), [cerl()]) -> c_primop().

See also: c_primop/2.

Link to this function

ann_c_receive(As::[term()], Clauses::[ cerl() ]) -> c_receive()

Specs

ann_c_receive([term()], [cerl()]) -> c_receive().

Equivalent to ann_c_receive(As, Clauses, c_atom(infinity), c_atom(true)).

See also: c_atom/1, c_receive/3.

Link to this function

ann_c_receive(As::[term()], Clauses::[ cerl() ], Timeout:: cerl() , Action:: cerl() ) -> c_receive()

Specs

ann_c_receive([term()], [cerl()], cerl(), cerl()) -> c_receive().

See also: ann_c_receive/2, c_receive/3.

Link to this function

ann_c_seq(As::[term()], Argument:: cerl() , Body:: cerl() ) -> c_seq()

Specs

ann_c_seq([term()], cerl(), cerl()) -> c_seq().

See also: c_seq/2.

Link to this function

ann_c_string(As::[term()], Value::string()) -> c_literal()

Specs

ann_c_string([term()], string()) -> c_literal().

See also: c_string/1.

Link to this function

ann_c_try(As::[term()], Expr:: cerl() , Vs::[ cerl() ], Body:: cerl() , Evs::[ cerl() ], Handler:: cerl() ) -> c_try()

Specs

ann_c_try([term()], cerl(), [cerl()], cerl(), [cerl()], cerl()) -> c_try().

See also: c_try/5.

Link to this function

ann_c_tuple(As::[term()], Es::[ cerl() ]) -> c_tuple() | c_literal()

Specs

ann_c_tuple([term()], [cerl()]) -> c_tuple() | c_literal().

See also: c_tuple/1.

Link to this function

ann_c_tuple_skel(As::[term()], Es::[ cerl() ]) -> c_tuple()

Specs

ann_c_tuple_skel([term()], [cerl()]) -> c_tuple().

See also: c_tuple_skel/1.

Link to this function

ann_c_values(As::[term()], Es::[ cerl() ]) -> c_values()

Specs

ann_c_values([term()], [cerl()]) -> c_values().

See also: c_values/1.

Link to this function

ann_c_var(As::[term()], Name:: var_name() ) -> c_var()

Specs

ann_c_var([term()], var_name()) -> c_var().

See also: c_var/1.

Link to this function

ann_make_data(As::[term()], X2:: dtype() , Es::[ cerl() ]) -> c_lct()

Specs

ann_make_data([term()], dtype(), [cerl()]) -> c_lct().

See also: make_data/2.

Link to this function

ann_make_data_skel(As::[term()], X2:: dtype() , Es::[ cerl() ]) -> c_lct()

Specs

ann_make_data_skel([term()], dtype(), [cerl()]) -> c_lct().

See also: make_data_skel/2.

Link to this function

ann_make_list(As::[term()], List::[ cerl() ]) -> cerl()

Specs

ann_make_list([term()], [cerl()]) -> cerl().

Equivalent to ann_make_list(As, List, none).

Link to this function

ann_make_list(As::[term()], T::[ cerl() ], Tail:: cerl() | none) -> cerl()

Specs

ann_make_list([term()], [cerl()], cerl() | none) -> cerl().

See also: ann_make_list/2, make_list/2.

Link to this function

ann_make_tree(As::[term()], X2:: ctype() , X3::[[ cerl() ], ...]) -> cerl()

Specs

ann_make_tree([term()], ctype(), [[cerl()], ...]) -> cerl().

Creates a syntax tree with the given annotations, type and subtrees. See make_tree/2 for details.

See also: make_tree/2.

Link to this function

apply_args(Node:: c_apply() ) -> [ cerl() ]

Specs

apply_args(c_apply()) -> [cerl()].

Returns the list of argument subtrees of an abstract function application.

See also: apply_arity/1, c_apply/2.

Link to this function

apply_arity(Node:: c_apply() ) -> arity()

Specs

apply_arity(c_apply()) -> arity().

Returns the number of argument subtrees of an abstract function application.

Note: this is equivalent to length(apply_args(Node)), but potentially more efficient.

See also: apply_args/1, c_apply/2.

Link to this function

apply_op(Node:: c_apply() ) -> cerl()

Specs

apply_op(c_apply()) -> cerl().

Returns the operator subtree of an abstract function application.

See also: c_apply/2.

Link to this function

atom_lit(Node:: cerl() ) -> nonempty_string()

Specs

atom_lit(cerl()) -> nonempty_string().

Returns the literal string represented by an abstract atom. This always includes surrounding single-quote characters.

Note that an abstract atom may have several literal representations, and that the representation yielded by this function is not fixed; e.g., atom_lit(c_atom("a\012b")) could yield the string "\'a\\nb\'".

See also: c_atom/1.

Link to this function

atom_name(Node:: c_literal() ) -> string()

Specs

atom_name(c_literal()) -> string().

Returns the printname of an abstract atom.

See also: c_atom/1.

Link to this function

atom_val(Node:: c_literal() ) -> atom()

Specs

atom_val(c_literal()) -> atom().

Returns the value represented by an abstract atom.

See also: c_atom/1.

Link to this function

binary_segments(Node:: c_binary() ) -> [ cerl() ]

Specs

binary_segments(c_binary()) -> [cerl()].

Returns the list of segment subtrees of an abstract binary-template.

See also: c_binary/1, c_bitstr/5.

Link to this function

bitstr_bitsize(Node:: c_bitstr() ) -> all | any | utf | non_neg_integer()

Specs

bitstr_bitsize(c_bitstr()) -> all | any | utf | non_neg_integer().

Returns the total size in bits of an abstract bit-string template. If the size field is an integer literal, the result is the product of the size and unit values; if the size field is the atom literal all, the atom all is returned. If the size is not a literal, the atom any is returned.

See also: c_bitstr/5.

Link to this function

bitstr_flags(Node:: c_bitstr() ) -> cerl()

Specs

bitstr_flags(c_bitstr()) -> cerl().

Returns the flags subtree of an abstract bit-string template.

See also: c_bitstr/5.

Link to this function

bitstr_size(Node:: c_bitstr() ) -> cerl()

Specs

bitstr_size(c_bitstr()) -> cerl().

Returns the size subtree of an abstract bit-string template.

See also: c_bitstr/5.

Link to this function

bitstr_type(Node:: c_bitstr() ) -> cerl()

Specs

bitstr_type(c_bitstr()) -> cerl().

Returns the type subtree of an abstract bit-string template.

See also: c_bitstr/5.

Link to this function

bitstr_unit(Node:: c_bitstr() ) -> cerl()

Specs

bitstr_unit(c_bitstr()) -> cerl().

Returns the unit subtree of an abstract bit-string template.

See also: c_bitstr/5.

Link to this function

bitstr_val(Node:: c_bitstr() ) -> cerl()

Specs

bitstr_val(c_bitstr()) -> cerl().

Returns the value subtree of an abstract bit-string template.

See also: c_bitstr/5.

Link to this function

c_alias(Var:: c_var() , Pattern:: cerl() ) -> c_alias()

Specs

c_alias(c_var(), cerl()) -> c_alias().

Creates an abstract pattern alias. The result represents "Variable = Pattern".

See also: alias_pat/1, alias_var/1, ann_c_alias/3, c_clause/3, is_c_alias/1, update_c_alias/3.

Link to this function

c_apply(Operator:: cerl() , Arguments::[ cerl() ]) -> c_apply()

Specs

c_apply(cerl(), [cerl()]) -> c_apply().

Creates an abstract function application. If Arguments is [A1, ..., An], the result represents "apply Operator(A1, ..., An)".

See also: ann_c_apply/3, apply_args/1, apply_arity/1, apply_op/1, c_call/3, c_primop/2, is_c_apply/1, update_c_apply/3.

Link to this function

c_atom(Name::atom() | string()) -> c_literal()

Specs

c_atom(atom() | string()) -> c_literal().

Creates an abstract atom literal. The print name of the atom is the character sequence represented by Name.

Note: passing a string as argument to this function causes a corresponding atom to be created for the internal representation.

See also: ann_c_atom/2, atom_lit/1, atom_name/1, atom_val/1, is_c_atom/1.

Link to this function

c_binary(Segments::[ cerl() ]) -> c_binary()

Specs

c_binary([cerl()]) -> c_binary().

Creates an abstract binary-template. A binary object is in this context a sequence of an arbitrary number of bits. (The number of bits used to be evenly divisible by 8, but after the introduction of bit strings in the Erlang language, the choice was made to use the binary template for all bit strings.) It is specified by zero or more bit-string template segments of arbitrary lengths (in number of bits). If Segments is [S1, ..., Sn], the result represents "#{S1, ..., Sn}#". All the Si must have type bitstr.

See also: ann_c_binary/2, binary_segments/1, c_bitstr/5, is_c_binary/1, update_c_binary/2.

Link to this function

c_bitstr(Val:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

c_bitstr(cerl(), cerl(), cerl()) -> c_bitstr().

Equivalent to c_bitstr(Value, abstract(all), abstract(1), Type, Flags).

Link to this function

c_bitstr(Val:: cerl() , Size:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

c_bitstr(cerl(), cerl(), cerl(), cerl()) -> c_bitstr().

Equivalent to c_bitstr(Value, Size, abstract(1), Type, Flags).

Link to this function

c_bitstr(Val:: cerl() , Size:: cerl() , Unit:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

c_bitstr(cerl(), cerl(), cerl(), cerl(), cerl()) -> c_bitstr().

Creates an abstract bit-string template. These can only occur as components of an abstract binary-template (see c_binary/1). The result represents "#<Value>(Size, Unit, Type, Flags)", where Unit must represent a positive integer constant, Type must represent a constant atom (one of 'integer', 'float', or 'binary'), and Flags must represent a constant list "[F1, ..., Fn]" where all the Fi are atoms.

See also: ann_c_bitstr/6, bitstr_flags/1, bitstr_size/1, bitstr_type/1, bitstr_unit/1, bitstr_val/1, c_binary/1, is_c_bitstr/1, update_c_bitstr/6.

Link to this function

c_call(Module:: cerl() , Name:: cerl() , Arguments::[ cerl() ]) -> c_call()

Specs

c_call(cerl(), cerl(), [cerl()]) -> c_call().

Creates an abstract inter-module call. If Arguments is [A1, ..., An], the result represents "call Module:Name(A1, ..., An)".

See also: ann_c_call/4, c_apply/2, c_primop/2, call_args/1, call_arity/1, call_module/1, call_name/1, is_c_call/1, update_c_call/4.

Link to this function

c_case(Expr:: cerl() , Clauses::[ cerl() ]) -> c_case()

Specs

c_case(cerl(), [cerl()]) -> c_case().

Creates an abstract case-expression. If Clauses is [C1, ..., Cn], the result represents "case Argument of C1 ... Cn end". Clauses must not be empty.

See also: ann_c_case/3, c_clause/3, case_arg/1, case_arity/1, case_clauses/1, is_c_case/1, update_c_case/3.

Link to this function

c_catch(Body:: cerl() ) -> c_catch()

Specs

c_catch(cerl()) -> c_catch().

Creates an abstract catch-expression. The result represents "catch Body".

Note: catch-expressions can be rewritten as try-expressions, and will eventually be removed from Core Erlang.

See also: ann_c_catch/2, c_try/5, catch_body/1, is_c_catch/1, update_c_catch/2.

Link to this function

c_char(Value::non_neg_integer()) -> c_literal()

Specs

c_char(non_neg_integer()) -> c_literal().

Creates an abstract character literal. If the local implementation of Erlang defines char() as a subset of integer(), this function is equivalent to c_int/1. Otherwise, if the given value is an integer, it will be converted to the character with the corresponding code. The lexical representation of a character is "$Char", where Char is a single printing character or an escape sequence.

See also: ann_c_char/2, c_int/1, c_string/1, char_lit/1, char_val/1, is_c_char/1, is_print_char/1.

Link to this function

c_clause(Patterns::[ cerl() ], Body:: cerl() ) -> c_clause()

Specs

c_clause([cerl()], cerl()) -> c_clause().

Equivalent to c_clause(Patterns, c_atom(true), Body).

See also: c_atom/1.

Link to this function

c_clause(Patterns::[ cerl() ], Guard:: cerl() , Body:: cerl() ) -> c_clause()

Specs

c_clause([cerl()], cerl(), cerl()) -> c_clause().

Creates an an abstract clause. If Patterns is [P1, ..., Pn], the result represents "<P1, ..., Pn> when Guard -> Body".

See also: ann_c_clause/4, c_case/2, c_clause/2, c_receive/3, clause_arity/1, clause_body/1, clause_guard/1, clause_pats/1, clause_vars/1, is_c_clause/1, update_c_clause/4.

Link to this function

c_cons(C_literal:: cerl() , Tail:: cerl() ) -> c_literal() | c_cons()

Specs

c_cons(cerl(), cerl()) -> c_literal() | c_cons().

Creates an abstract list constructor. The result represents "[Head | Tail]". Note that if both Head and Tail have type literal, then the result will also have type literal, and annotations on Head and Tail are lost.

Recall that in Erlang, the tail element of a list constructor is not necessarily a list.

See also: ann_c_cons/3, c_cons_skel/2, c_nil/0, cons_hd/1, cons_tl/1, is_c_cons/1, is_c_list/1, list_elements/1, list_length/1, make_list/2, update_c_cons/3.

Link to this function

c_cons_skel(Head:: cerl() , Tail:: cerl() ) -> c_cons()

Specs

c_cons_skel(cerl(), cerl()) -> c_cons().

Creates an abstract list constructor skeleton. Does not fold constant literals, i.e., the result always has type cons, representing "[Head | Tail]".

This function is occasionally useful when it is necessary to have annotations on the subnodes of a list constructor node, even when the subnodes are constant literals. Note however that is_literal/1 will yield false and concrete/1 will fail if passed the result from this function.

fold_literal/1 can be used to revert a node to the normal-form representation.

See also: ann_c_cons_skel/3, c_cons/2, c_nil/0, concrete/1, fold_literal/1, is_c_cons/1, is_c_list/1, is_literal/1, update_c_cons_skel/3.

Link to this function

c_float(Value::float()) -> c_literal()

Specs

c_float(float()) -> c_literal().

Creates an abstract floating-point literal. The lexical representation is the decimal floating-point numeral of Value.

See also: ann_c_float/2, float_lit/1, float_val/1, is_c_float/1.

Link to this function

c_fname(Atom::atom(), Arity::arity()) -> c_var()

Specs

c_fname(atom(), arity()) -> c_var().

Equivalent to c_var({Name, Arity}).

See also: ann_c_fname/3, fname_arity/1, fname_id/1, is_c_fname/1, update_c_fname/3.

Link to this function

c_fun(Variables::[ cerl() ], Body:: cerl() ) -> c_fun()

Specs

c_fun([cerl()], cerl()) -> c_fun().

Creates an abstract fun-expression. If Variables is [V1, ..., Vn], the result represents "fun (V1, ..., Vn) -> Body". All the Vi must have type var.

See also: ann_c_fun/3, fun_arity/1, fun_body/1, fun_vars/1, is_c_fun/1, update_c_fun/3.

Link to this function

c_int(Value::integer()) -> c_literal()

Specs

c_int(integer()) -> c_literal().

Creates an abstract integer literal. The lexical representation is the canonical decimal numeral of Value.

See also: ann_c_int/2, c_char/1, int_lit/1, int_val/1, is_c_int/1.

Link to this function

c_let(Variables::[ cerl() ], Argument:: cerl() , Body:: cerl() ) -> c_let()

Specs

c_let([cerl()], cerl(), cerl()) -> c_let().

Creates an abstract let-expression. If Variables is [V1, ..., Vn], the result represents "let <V1, ..., Vn> = Argument in Body". All the Vi must have type var.

See also: ann_c_let/4, is_c_let/1, let_arg/1, let_arity/1, let_body/1, let_vars/1, update_c_let/4.

Link to this function

c_letrec(Defs::[{ cerl() , cerl() }], Body:: cerl() ) -> c_letrec()

Specs

c_letrec([{cerl(), cerl()}], cerl()) -> c_letrec().

Creates an abstract letrec-expression. If Definitions is [{V1, F1}, ..., {Vn, Fn}], the result represents "letrec V1 = F1 ... Vn = Fn in Body. All the Vi must have type var and represent function names. All the Fi must have type 'fun'.

See also: ann_c_letrec/3, is_c_letrec/1, letrec_body/1, letrec_defs/1, letrec_vars/1, update_c_letrec/3.

Link to this function

c_map(Pairs::[ c_map_pair() ]) -> c_map()

Specs

c_map([c_map_pair()]) -> c_map().
Link to this function

c_map_pair(Key:: cerl() , Val:: cerl() ) -> c_map_pair()

Specs

c_map_pair(cerl(), cerl()) -> c_map_pair().
Link to this function

c_map_pair_exact(Key:: cerl() , Val:: cerl() ) -> c_map_pair()

Specs

c_map_pair_exact(cerl(), cerl()) -> c_map_pair().
Link to this function

c_map_pattern(Pairs::[ c_map_pair() ]) -> c_map()

Specs

c_map_pattern([c_map_pair()]) -> c_map().
Link to this function

c_module(Name:: cerl() , Exports::[ cerl() ], Es::[{ cerl() , cerl() }]) -> c_module()

Specs

c_module(cerl(), [cerl()], [{cerl(), cerl()}]) -> c_module().

Equivalent to c_module(Name, Exports, [], Definitions).

Link to this function

c_module(Name:: cerl() , Exports::[ cerl() ], Attrs::[{ cerl() , cerl() }], Es::[{ cerl() , cerl() }]) -> c_module()

Specs

c_module(cerl(), [cerl()], [{cerl(), cerl()}], [{cerl(), cerl()}]) -> c_module().

Creates an abstract module definition. The result represents

    module Name [E1, ..., Ek]
      attributes [K1 = T1, ...,
                  Km = Tm]
      V1 = F1
      ...
      Vn = Fn
    end

if Exports = [E1, ..., Ek], Attributes = [{K1, T1}, ..., {Km, Tm}], and Definitions = [{V1, F1}, ..., {Vn, Fn}].

Name and all the Ki must be atom literals, and all the Ti must be constant literals. All the Vi and Ei must have type var and represent function names. All the Fi must have type 'fun'.

See also: ann_c_module/4, ann_c_module/5, c_atom/1, c_fun/2, c_module/3, c_var/1, is_literal/1, module_attrs/1, module_defs/1, module_exports/1, module_name/1, module_vars/1, update_c_module/5.

Link to this function

c_nil() -> c_literal()

Specs

c_nil() -> c_literal().

Creates an abstract empty list. The result represents "[]". The empty list is traditionally called "nil".

See also: ann_c_nil/1, c_cons/2, is_c_list/1.

Link to this function

c_primop(Name:: cerl() , Arguments::[ cerl() ]) -> c_primop()

Specs

c_primop(cerl(), [cerl()]) -> c_primop().

Creates an abstract primitive operation call. If Arguments is [A1, ..., An], the result represents "primop Name(A1, ..., An)". Name must be an atom literal.

See also: ann_c_primop/3, c_apply/2, c_call/3, is_c_primop/1, primop_args/1, primop_arity/1, primop_name/1, update_c_primop/3.

Link to this function

c_receive(Clauses::[ cerl() ]) -> c_receive()

Specs

c_receive([cerl()]) -> c_receive().

Equivalent to c_receive(Clauses, c_atom(infinity), c_atom(true)).

See also: c_atom/1.

Link to this function

c_receive(Clauses::[ cerl() ], Timeout:: cerl() , Action:: cerl() ) -> c_receive()

Specs

c_receive([cerl()], cerl(), cerl()) -> c_receive().

Creates an abstract receive-expression. If Clauses is [C1, ..., Cn], the result represents "receive C1 ... Cn after Timeout -> Action end".

See also: ann_c_receive/4, c_receive/1, is_c_receive/1, receive_action/1, receive_clauses/1, receive_timeout/1, update_c_receive/4.

Link to this function

c_seq(Argument:: cerl() , Body:: cerl() ) -> c_seq()

Specs

c_seq(cerl(), cerl()) -> c_seq().

Creates an abstract sequencing expression. The result represents "do Argument Body".

See also: ann_c_seq/3, is_c_seq/1, seq_arg/1, seq_body/1, update_c_seq/3.

Link to this function

c_string(Value::string()) -> c_literal()

Specs

c_string(string()) -> c_literal().

Creates an abstract string literal. Equivalent to creating an abstract list of the corresponding character literals (cf. is_c_string/1), but is typically more efficient. The lexical representation of a string is ""Chars"", where Chars is a sequence of printing characters or spaces.

See also: ann_c_string/2, c_char/1, is_c_string/1, is_print_string/1, string_lit/1, string_val/1.

Link to this function

c_try(Expr:: cerl() , Vs::[ cerl() ], Body:: cerl() , Evs::[ cerl() ], Handler:: cerl() ) -> c_try()

Specs

c_try(cerl(), [cerl()], cerl(), [cerl()], cerl()) -> c_try().

Creates an abstract try-expression. If Variables is [V1, ..., Vn] and ExceptionVars is [X1, ..., Xm], the result represents "try Argument of <V1, ..., Vn> -> Body catch <X1, ..., Xm> -> Handler". All the Vi and Xi must have type var.

See also: ann_c_try/6, c_catch/1, is_c_try/1, try_arg/1, try_body/1, try_vars/1, update_c_try/6.

Link to this function

c_tuple(Es::[ cerl() ]) -> c_tuple() | c_literal()

Specs

c_tuple([cerl()]) -> c_tuple() | c_literal().

Creates an abstract tuple. If Elements is [E1, ..., En], the result represents "{E1, ..., En}". Note that if all nodes in Elements have type literal, or if Elements is empty, then the result will also have type literal and annotations on nodes in Elements are lost.

Recall that Erlang has distinct 1-tuples, i.e., {X} is always distinct from X itself.

See also: ann_c_tuple/2, c_tuple_skel/1, is_c_tuple/1, tuple_arity/1, tuple_es/1, update_c_tuple/2.

Link to this function

c_tuple_skel(Es::[ cerl() ]) -> c_tuple()

Specs

c_tuple_skel([cerl()]) -> c_tuple().

Creates an abstract tuple skeleton. Does not fold constant literals, i.e., the result always has type tuple, representing "{E1, ..., En}", if Elements is [E1, ..., En].

This function is occasionally useful when it is necessary to have annotations on the subnodes of a tuple node, even when all the subnodes are constant literals. Note however that is_literal/1 will yield false and concrete/1 will fail if passed the result from this function.

fold_literal/1 can be used to revert a node to the normal-form representation.

See also: ann_c_tuple_skel/2, c_tuple/1, concrete/1, fold_literal/1, is_c_tuple/1, is_literal/1, tuple_es/1, update_c_tuple_skel/2.

Link to this function

c_values(Es::[ cerl() ]) -> c_values()

Specs

c_values([cerl()]) -> c_values().

Creates an abstract value list. If Elements is [E1, ..., En], the result represents "<E1, ..., En>".

See also: ann_c_values/2, is_c_values/1, update_c_values/2, values_arity/1, values_es/1.

Link to this function

c_var(Name:: var_name() ) -> c_var()

Specs

c_var(var_name()) -> c_var().

Creates an abstract variable. A variable is identified by its name, given by the Name parameter.

If a name is given by a single atom, it should either be a "simple" atom which does not need to be single-quoted in Erlang, or otherwise its print name should correspond to a proper Erlang variable, i.e., begin with an uppercase character or an underscore. Names on the form {A, N} represent function name variables "A/N"; these are special variables which may be bound only in the function definitions of a module or a letrec. They may not be bound in let expressions and cannot occur in clause patterns. The atom A in a function name may be any atom; the integer N must be nonnegative. The functions c_fname/2 etc. are utilities for handling function name variables.

When printing variable names, they must have the form of proper Core Erlang variables and function names. E.g., a name represented by an integer such as 42 could be formatted as "_42", an atom 'Xxx' simply as "Xxx", and an atom foo as "_foo". However, one must assure that any two valid distinct names are never mapped to the same strings. Tuples such as {foo, 2} representing function names can simply by formatted as "'foo'/2", with no risk of conflicts.

See also: ann_c_var/2, c_fname/2, c_letrec/2, c_module/4, is_c_var/1, update_c_var/2, var_name/1.

Link to this function

call_args(Node:: c_call() ) -> [ cerl() ]

Specs

call_args(c_call()) -> [cerl()].

Returns the list of argument subtrees of an abstract inter-module call.

See also: c_call/3, call_arity/1.

Link to this function

call_arity(Node:: c_call() ) -> arity()

Specs

call_arity(c_call()) -> arity().

Returns the number of argument subtrees of an abstract inter-module call.

Note: this is equivalent to length(call_args(Node)), but potentially more efficient.

See also: c_call/3, call_args/1.

Link to this function

call_module(Node:: c_call() ) -> cerl()

Specs

call_module(c_call()) -> cerl().

Returns the module subtree of an abstract inter-module call.

See also: c_call/3.

Link to this function

call_name(Node:: c_call() ) -> cerl()

Specs

call_name(c_call()) -> cerl().

Returns the name subtree of an abstract inter-module call.

See also: c_call/3.

Link to this function

case_arg(Node:: c_case() ) -> cerl()

Specs

case_arg(c_case()) -> cerl().

Returns the argument subtree of an abstract case-expression.

See also: c_case/2.

Link to this function

case_arity(Node:: c_case() ) -> non_neg_integer()

Specs

case_arity(c_case()) -> non_neg_integer().

Equivalent to clause_arity(hd(case_clauses(Node))), but potentially more efficient.

See also: c_case/2, case_clauses/1, clause_arity/1.

Link to this function

case_clauses(Node:: c_case() ) -> [ cerl() ]

Specs

case_clauses(c_case()) -> [cerl()].

Returns the list of clause subtrees of an abstract case-expression.

See also: c_case/2, case_arity/1.

Link to this function

catch_body(Node:: c_catch() ) -> cerl()

Specs

catch_body(c_catch()) -> cerl().

Returns the body subtree of an abstract catch-expression.

See also: c_catch/1.

Link to this function

char_lit(Node:: c_literal() ) -> nonempty_string()

Specs

char_lit(c_literal()) -> nonempty_string().

Returns the literal string represented by an abstract character. This includes a leading $ character. Currently, all characters that are not in the set of ISO 8859-1 (Latin-1) "printing" characters will be escaped.

See also: c_char/1.

Link to this function

char_val(Node:: c_literal() ) -> char()

Specs

char_val(c_literal()) -> char().

Returns the value represented by an abstract character literal.

See also: c_char/1.

Link to this function

clause_arity(Node:: c_clause() ) -> non_neg_integer()

Specs

clause_arity(c_clause()) -> non_neg_integer().

Returns the number of pattern subtrees of an abstract clause.

Note: this is equivalent to length(clause_pats(Node)), but potentially more efficient.

See also: c_clause/3, clause_pats/1.

Link to this function

clause_body(Node:: c_clause() ) -> cerl()

Specs

clause_body(c_clause()) -> cerl().

Returns the body subtree of an abstract clause.

See also: c_clause/3.

Link to this function

clause_guard(Node:: c_clause() ) -> cerl()

Specs

clause_guard(c_clause()) -> cerl().

Returns the guard subtree of an abstract clause.

See also: c_clause/3.

Link to this function

clause_pats(Node:: c_clause() ) -> [ cerl() ]

Specs

clause_pats(c_clause()) -> [cerl()].

Returns the list of pattern subtrees of an abstract clause.

See also: c_clause/3, clause_arity/1.

Link to this function

clause_vars(Clause:: c_clause() ) -> [ cerl() ]

Specs

clause_vars(c_clause()) -> [cerl()].

Returns the list of all abstract variables in the patterns of an abstract clause. The order of listing is not defined.

See also: c_clause/3, pat_list_vars/1.

Link to this function

concrete(C_literal:: c_literal() ) -> term()

Specs

concrete(c_literal()) -> term().

Returns the Erlang term represented by a syntax tree. An exception is thrown if Node does not represent a literal term.

Note: This is a constant time operation.

See also: abstract/1, is_literal/1.

Link to this function

cons_hd(C_cons:: c_cons() | c_literal() ) -> cerl()

Specs

cons_hd(c_cons() | c_literal()) -> cerl().

Returns the head subtree of an abstract list constructor.

See also: c_cons/2.

Link to this function

cons_tl(C_cons:: c_cons() | c_literal() ) -> cerl()

Specs

cons_tl(c_cons() | c_literal()) -> cerl().

Returns the tail subtree of an abstract list constructor.

Recall that the tail does not necessarily represent a proper list.

See also: c_cons/2.

Link to this function

copy_ann(Source:: cerl() , Target:: cerl() ) -> cerl()

Specs

copy_ann(cerl(), cerl()) -> cerl().

Copies the list of user annotations from Source to Target.

Note: this is equivalent to set_ann(Target, get_ann(Source)), but potentially more efficient.

See also: get_ann/1, set_ann/2.

Link to this function

data_arity(C_literal:: c_lct() ) -> non_neg_integer()

Specs

data_arity(c_lct()) -> non_neg_integer().

Returns the number of subtrees of a data constructor node. This is equivalent to length(data_es(Node)), but potentially more efficient.

See also: data_es/1, is_data/1.

Link to this function

data_es(C_literal:: c_lct() ) -> [ cerl() ]

Specs

data_es(c_lct()) -> [cerl()].

Returns the list of subtrees of a data constructor node. If the arity of the constructor is zero, the result is the empty list.

Note: if data_type(Node) is cons, the number of subtrees is exactly two. If data_type(Node) is {atomic, Value}, the number of subtrees is zero.

See also: data_arity/1, data_type/1, is_data/1, make_data/2.

Link to this function

data_type(C_literal:: c_lct() ) -> dtype()

Specs

data_type(c_lct()) -> dtype().

Returns a type descriptor for a data constructor node. (Cf. is_data/1.) This is mainly useful for comparing types and for constructing new nodes of the same type (cf. make_data/2). If Node represents an integer, floating-point number, atom or empty list, the result is {atomic, Value}, where Value is the value of concrete(Node), otherwise the result is either cons or tuple.

Type descriptors can be compared for equality or order (in the Erlang term order), but remember that floating-point values should in general never be tested for equality.

See also: concrete/1, is_data/1, make_data/2, type/1.

Link to this function

float_lit(Node:: c_literal() ) -> string()

Specs

float_lit(c_literal()) -> string().

Returns the numeral string represented by a floating-point literal node.

See also: c_float/1.

Link to this function

float_val(Node:: c_literal() ) -> float()

Specs

float_val(c_literal()) -> float().

Returns the value represented by a floating-point literal node.

See also: c_float/1.

Link to this function

fname_arity(C_var:: c_var() ) -> arity()

Specs

fname_arity(c_var()) -> arity().

Returns the arity part of an abstract function name variable.

See also: c_fname/2, fname_id/1.

Link to this function

fname_id(C_var:: c_var() ) -> atom()

Specs

fname_id(c_var()) -> atom().

Returns the identifier part of an abstract function name variable.

See also: c_fname/2, fname_arity/1.

Link to this function

fold_literal(Node:: cerl() ) -> cerl()

Specs

fold_literal(cerl()) -> cerl().

Assures that literals have a compact representation. This is occasionally useful if c_cons_skel/2, c_tuple_skel/1 or unfold_literal/1 were used in the construction of Node, and you want to revert to the normal "folded" representation of literals. If Node represents a tuple or list constructor, its elements are rewritten recursively, and the node is reconstructed using c_cons/2 or c_tuple/1, respectively; otherwise, Node is not changed.

See also: c_cons/2, c_cons_skel/2, c_tuple/1, c_tuple_skel/1, is_literal/1, unfold_literal/1.

Link to this function

from_records(Node:: cerl() ) -> cerl()

Specs

from_records(cerl()) -> cerl().

Translates an explicit record representation to a corresponding abstract syntax tree. The records are defined in the file "core_parse.hrl".

See also: to_records/1, type/1.

Link to this function

fun_arity(Node:: c_fun() ) -> arity()

Specs

fun_arity(c_fun()) -> arity().

Returns the number of parameter subtrees of an abstract fun-expression.

Note: this is equivalent to length(fun_vars(Node)), but potentially more efficient.

See also: c_fun/2, fun_vars/1.

Link to this function

fun_body(Node:: c_fun() ) -> cerl()

Specs

fun_body(c_fun()) -> cerl().

Returns the body subtree of an abstract fun-expression.

See also: c_fun/2.

Link to this function

fun_vars(Node:: c_fun() ) -> [ cerl() ]

Specs

fun_vars(c_fun()) -> [cerl()].

Returns the list of parameter subtrees of an abstract fun-expression.

See also: c_fun/2, fun_arity/1.

Link to this function

get_ann(Node:: cerl() ) -> [term()]

Specs

get_ann(cerl()) -> [term()].

Returns the list of user annotations associated with a syntax tree node. For a newly created node, this is the empty list. The annotations may be any terms.

See also: set_ann/2.

Link to this function

int_lit(Node:: c_literal() ) -> string()

Specs

int_lit(c_literal()) -> string().

Returns the numeral string represented by an integer literal node.

See also: c_int/1.

Link to this function

int_val(Node:: c_literal() ) -> integer()

Specs

int_val(c_literal()) -> integer().

Returns the value represented by an integer literal node.

See also: c_int/1.

Link to this function

is_c_alias(C_alias:: cerl() ) -> boolean()

Specs

is_c_alias(cerl()) -> boolean().

Returns true if Node is an abstract pattern alias, otherwise false.

See also: c_alias/2.

Link to this function

is_c_apply(C_apply:: cerl() ) -> boolean()

Specs

is_c_apply(cerl()) -> boolean().

Returns true if Node is an abstract function application, otherwise false.

See also: c_apply/2.

Link to this function

is_c_atom(C_literal:: cerl() ) -> boolean()

Specs

is_c_atom(cerl()) -> boolean().

Returns true if Node represents an atom literal, otherwise false.

See also: c_atom/1.

Link to this function

is_c_binary(C_binary:: cerl() ) -> boolean()

Specs

is_c_binary(cerl()) -> boolean().

Returns true if Node is an abstract binary-template; otherwise false.

See also: c_binary/1.

Link to this function

is_c_bitstr(C_bitstr:: cerl() ) -> boolean()

Specs

is_c_bitstr(cerl()) -> boolean().

Returns true if Node is an abstract bit-string template; otherwise false.

See also: c_bitstr/5.

Link to this function

is_c_call(C_call:: cerl() ) -> boolean()

Specs

is_c_call(cerl()) -> boolean().

Returns true if Node is an abstract inter-module call expression; otherwise false.

See also: c_call/3.

Link to this function

is_c_case(C_case:: cerl() ) -> boolean()

Specs

is_c_case(cerl()) -> boolean().

Returns true if Node is an abstract case-expression; otherwise false.

See also: c_case/2.

Link to this function

is_c_catch(C_catch:: cerl() ) -> boolean()

Specs

is_c_catch(cerl()) -> boolean().

Returns true if Node is an abstract catch-expression, otherwise false.

See also: c_catch/1.

Link to this function

is_c_char(C_literal:: c_literal() ) -> boolean()

Specs

is_c_char(c_literal()) -> boolean().

Returns true if Node may represent a character literal, otherwise false.

If the local implementation of Erlang defines char() as a subset of integer(), then is_c_int(Node) will also yield true.

See also: c_char/1, is_print_char/1.

Link to this function

is_c_clause(C_clause:: cerl() ) -> boolean()

Specs

is_c_clause(cerl()) -> boolean().

Returns true if Node is an abstract clause, otherwise false.

See also: c_clause/3.

Link to this function

is_c_cons(C_cons:: cerl() ) -> boolean()

Specs

is_c_cons(cerl()) -> boolean().

Returns true if Node is an abstract list constructor, otherwise false.

Link to this function

is_c_float(C_literal:: cerl() ) -> boolean()

Specs

is_c_float(cerl()) -> boolean().

Returns true if Node represents a floating-point literal, otherwise false.

See also: c_float/1.

Link to this function

is_c_fname(C_var:: cerl() ) -> boolean()

Specs

is_c_fname(cerl()) -> boolean().

Returns true if Node is an abstract function name variable, otherwise false.

See also: c_fname/2, c_var/1, var_name/1.

Link to this function

is_c_fun(C_fun:: cerl() ) -> boolean()

Specs

is_c_fun(cerl()) -> boolean().

Returns true if Node is an abstract fun-expression, otherwise false.

See also: c_fun/2.

Link to this function

is_c_int(C_literal:: cerl() ) -> boolean()

Specs

is_c_int(cerl()) -> boolean().

Returns true if Node represents an integer literal, otherwise false.

See also: c_int/1.

Link to this function

is_c_let(C_let:: cerl() ) -> boolean()

Specs

is_c_let(cerl()) -> boolean().

Returns true if Node is an abstract let-expression, otherwise false.

See also: c_let/3.

Link to this function

is_c_letrec(C_letrec:: cerl() ) -> boolean()

Specs

is_c_letrec(cerl()) -> boolean().

Returns true if Node is an abstract letrec-expression, otherwise false.

See also: c_letrec/2.

Link to this function

is_c_list(C_cons:: cerl() ) -> boolean()

Specs

is_c_list(cerl()) -> boolean().

Returns true if Node represents a proper list, otherwise false. A proper list is either the empty list [], or a cons cell [Head | Tail], where recursively Tail is a proper list.

Note: Because Node is a syntax tree, the actual run-time values corresponding to its subtrees may often be partially or completely unknown. Thus, if Node represents e.g. "[... | Ns]" (where Ns is a variable), then the function will return false, because it is not known whether Ns will be bound to a list at run-time. If Node instead represents e.g. "[1, 2, 3]" or "[A | []]", then the function will return true.

See also: c_cons/2, c_nil/0, list_elements/1, list_length/1.

Link to this function

is_c_map(C_map:: cerl() ) -> boolean()

Specs

is_c_map(cerl()) -> boolean().

Returns true if Node is an abstract map constructor, otherwise false.

Link to this function

is_c_map_empty(C_map:: c_map() | c_literal() ) -> boolean()

Specs

is_c_map_empty(c_map() | c_literal()) -> boolean().
Link to this function

is_c_map_pattern(C_map:: c_map() ) -> boolean()

Specs

is_c_map_pattern(c_map()) -> boolean().
Link to this function

is_c_module(C_module:: cerl() ) -> boolean()

Specs

is_c_module(cerl()) -> boolean().

Returns true if Node is an abstract module definition, otherwise false.

See also: type/1.

Link to this function

is_c_nil(C_literal:: cerl() ) -> boolean()

Specs

is_c_nil(cerl()) -> boolean().

Returns true if Node is an abstract empty list, otherwise false.

Link to this function

is_c_primop(C_primop:: cerl() ) -> boolean()

Specs

is_c_primop(cerl()) -> boolean().

Returns true if Node is an abstract primitive operation call, otherwise false.

See also: c_primop/2.

Link to this function

is_c_receive(C_receive:: cerl() ) -> boolean()

Specs

is_c_receive(cerl()) -> boolean().

Returns true if Node is an abstract receive-expression, otherwise false.

See also: c_receive/3.

Link to this function

is_c_seq(C_seq:: cerl() ) -> boolean()

Specs

is_c_seq(cerl()) -> boolean().

Returns true if Node is an abstract sequencing expression, otherwise false.

See also: c_seq/2.

Link to this function

is_c_string(C_literal:: cerl() ) -> boolean()

Specs

is_c_string(cerl()) -> boolean().

Returns true if Node may represent a string literal, otherwise false. Strings are defined as lists of characters; see is_c_char/1 for details.

See also: c_string/1, is_c_char/1, is_print_string/1.

Link to this function

is_c_try(C_try:: cerl() ) -> boolean()

Specs

is_c_try(cerl()) -> boolean().

Returns true if Node is an abstract try-expression, otherwise false.

See also: c_try/5.

Link to this function

is_c_tuple(C_tuple:: cerl() ) -> boolean()

Specs

is_c_tuple(cerl()) -> boolean().

Returns true if Node is an abstract tuple, otherwise false.

See also: c_tuple/1.

Link to this function

is_c_values(C_values:: cerl() ) -> boolean()

Specs

is_c_values(cerl()) -> boolean().

Returns true if Node is an abstract value list; otherwise false.

See also: c_values/1.

Link to this function

is_c_var(C_var:: cerl() ) -> boolean()

Specs

is_c_var(cerl()) -> boolean().

Returns true if Node is an abstract variable, otherwise false.

See also: c_var/1.

Link to this function

is_data(C_literal:: cerl() ) -> boolean()

Specs

is_data(cerl()) -> boolean().

Returns true if Node represents a data constructor, otherwise false. Data constructors are cons cells, tuples, and atomic literals.

See also: data_arity/1, data_es/1, data_type/1.

Link to this function

is_leaf(Node:: cerl() ) -> boolean()

Specs

is_leaf(cerl()) -> boolean().

Returns true if Node is a leaf node, otherwise false. The current leaf node types are literal and var.

Note: all literals (cf. is_literal/1) are leaf nodes, even if they represent structured (constant) values such as {foo, [bar, baz]}. Also note that variables are leaf nodes but not literals.

See also: is_literal/1, type/1.

Link to this function

is_literal(C_literal:: cerl() ) -> boolean()

Specs

is_literal(cerl()) -> boolean().

Returns true if Node represents a literal term, otherwise false. This function returns true if and only if the value of concrete(Node) is defined.

Note: This is a constant time operation.

See also: abstract/1, concrete/1, fold_literal/1.

Link to this function

is_literal_term(T::term()) -> boolean()

Specs

is_literal_term(term()) -> boolean().

Returns true if Term can be represented as a literal, otherwise false. This function takes time proportional to the size of Term.

See also: abstract/1.

Link to this function

is_print_char(C_literal:: cerl() ) -> boolean()

Specs

is_print_char(cerl()) -> boolean().

Returns true if Node may represent a "printing" character, otherwise false. (Cf. is_c_char/1.) A "printing" character has either a given graphical representation, or a "named" escape sequence such as "\n". Currently, only ISO 8859-1 (Latin-1) character values are recognized.

See also: c_char/1, is_c_char/1.

Link to this function

is_print_string(C_literal:: cerl() ) -> boolean()

Specs

is_print_string(cerl()) -> boolean().

Returns true if Node may represent a string literal containing only "printing" characters, otherwise false. See is_c_string/1 and is_print_char/1 for details. Currently, only ISO 8859-1 (Latin-1) character values are recognized.

See also: c_string/1, is_c_string/1, is_print_char/1.

Link to this function

let_arg(Node:: c_let() ) -> cerl()

Specs

let_arg(c_let()) -> cerl().

Returns the argument subtree of an abstract let-expression.

See also: c_let/3.

Link to this function

let_arity(Node:: c_let() ) -> non_neg_integer()

Specs

let_arity(c_let()) -> non_neg_integer().

Returns the number of left-hand side variables of an abstract let-expression.

Note: this is equivalent to length(let_vars(Node)), but potentially more efficient.

See also: c_let/3, let_vars/1.

Link to this function

let_body(Node:: c_let() ) -> cerl()

Specs

let_body(c_let()) -> cerl().

Returns the body subtree of an abstract let-expression.

See also: c_let/3.

Link to this function

let_vars(Node:: c_let() ) -> [ cerl() ]

Specs

let_vars(c_let()) -> [cerl()].

Returns the list of left-hand side variables of an abstract let-expression.

See also: c_let/3, let_arity/1.

Link to this function

letrec_body(Node:: c_letrec() ) -> cerl()

Specs

letrec_body(c_letrec()) -> cerl().

Returns the body subtree of an abstract letrec-expression.

See also: c_letrec/2.

Link to this function

letrec_defs(Node:: c_letrec() ) -> [{ cerl() , cerl() }]

Specs

letrec_defs(c_letrec()) -> [{cerl(), cerl()}].

Returns the list of definitions of an abstract letrec-expression. If Node represents "letrec V1 = F1 ... Vn = Fn in Body", the returned value is [{V1, F1}, ..., {Vn, Fn}].

See also: c_letrec/2.

Link to this function

letrec_vars(Node:: c_letrec() ) -> [ cerl() ]

Specs

letrec_vars(c_letrec()) -> [cerl()].

Returns the list of left-hand side function variable subtrees of a letrec-expression. If Node represents "letrec V1 = F1 ... Vn = Fn in Body", the returned value is [V1, ..., Vn].

See also: c_letrec/2.

Link to this function

list_elements(C_cons:: c_cons() | c_literal() ) -> [ cerl() ]

Specs

list_elements(c_cons() | c_literal()) -> [cerl()].

Returns the list of element subtrees of an abstract list. Node must represent a proper list. E.g., if Node represents "[X1, X2 | [X3, X4 | []]", then list_elements(Node) yields the list [X1, X2, X3, X4].

See also: c_cons/2, c_nil/0, is_c_list/1, list_length/1, make_list/2.

Link to this function

list_length(L:: c_cons() | c_literal() ) -> non_neg_integer()

Specs

list_length(c_cons() | c_literal()) -> non_neg_integer().

Returns the number of element subtrees of an abstract list. Node must represent a proper list. E.g., if Node represents "[X1 | [X2, X3 | [X4, X5, X6]]]", then list_length(Node) returns the integer 6.

Note: this is equivalent to length(list_elements(Node)), but potentially more efficient.

See also: c_cons/2, c_nil/0, is_c_list/1, list_elements/1.

Link to this function

make_data(CType:: dtype() , Es::[ cerl() ]) -> c_lct()

Specs

make_data(dtype(), [cerl()]) -> c_lct().

Creates a data constructor node with the specified type and subtrees. (Cf. data_type/1.) An exception is thrown if the length of Elements is invalid for the given Type; see data_es/1 for arity constraints on constructor types.

See also: ann_make_data/3, data_es/1, data_type/1, make_data_skel/2, update_data/3.

Link to this function

make_data_skel(CType:: dtype() , Es::[ cerl() ]) -> c_lct()

Specs

make_data_skel(dtype(), [cerl()]) -> c_lct().

Like make_data/2, but analogous to c_tuple_skel/1 and c_cons_skel/2.

See also: ann_make_data_skel/3, c_cons_skel/2, c_tuple_skel/1, make_data/2, update_data_skel/3.

Link to this function

make_list(List::[ cerl() ]) -> cerl()

Specs

make_list([cerl()]) -> cerl().

Equivalent to make_list(List, none).

Link to this function

make_list(List::[ cerl() ], Tail:: cerl() | none) -> cerl()

Specs

make_list([cerl()], cerl() | none) -> cerl().

Creates an abstract list from the elements in List and the optional Tail. If Tail is none, the result will represent a nil-terminated list, otherwise it represents "[... | Tail]".

See also: ann_make_list/3, c_cons/2, c_nil/0, list_elements/1, update_list/3.

Link to this function

make_tree(Type:: ctype() , Gs::[[ cerl() ], ...]) -> cerl()

Specs

make_tree(ctype(), [[cerl()], ...]) -> cerl().

Creates a syntax tree with the given type and subtrees. Type must be a node type name (cf. type/1) that does not denote a leaf node type (cf. is_leaf/1). Groups must be a nonempty list of groups of syntax trees, representing the subtrees of a node of the given type, in left-to-right order as they would occur in the printed program text, grouped by category as done by subtrees/1.

The result of ann_make_tree(get_ann(Node), type(Node), subtrees(Node)) (cf. update_tree/2) represents the same source code text as the original Node, assuming that subtrees(Node) yields a nonempty list. However, it does not necessarily have the exact same data representation as Node.

See also: ann_make_tree/3, is_leaf/1, subtrees/1, type/1, update_tree/2.

Link to this function

map_arg(C_literal:: c_map() | c_literal() ) -> c_map() | c_literal()

Specs

map_arg(c_map() | c_literal()) -> c_map() | c_literal().
Link to this function

map_es(C_literal:: c_map() | c_literal() ) -> [ c_map_pair() ]

Specs

map_es(c_map() | c_literal()) -> [c_map_pair()].
Link to this function

map_pair_key(C_map_pair:: c_map_pair() ) -> cerl()

Specs

map_pair_key(c_map_pair()) -> cerl().
Link to this function

map_pair_op(C_map_pair:: c_map_pair() ) -> map_op()

Specs

map_pair_op(c_map_pair()) -> map_op().
Link to this function

map_pair_val(C_map_pair:: c_map_pair() ) -> cerl()

Specs

map_pair_val(c_map_pair()) -> cerl().
Link to this function

meta(Node:: cerl() ) -> cerl()

Specs

meta(cerl()) -> cerl().

Creates a meta-representation of a syntax tree. The result represents an Erlang expression "MetaTree" which, if evaluated, will yield a new syntax tree representing the same source code text as Tree (although the actual data representation may be different). The expression represented by MetaTree is implementation independent with regard to the data structures used by the abstract syntax tree implementation.

Any node in Tree whose node type is var (cf. type/1), and whose list of annotations (cf. get_ann/1) contains the atom meta_var, will remain unchanged in the resulting tree, except that exactly one occurrence of meta_var is removed from its annotation list.

The main use of the function meta/1 is to transform a data structure Tree, which represents a piece of program code, into a form that is representation independent when printed. E.g., suppose Tree represents a variable named "V". Then (assuming a function print/1 for printing syntax trees), evaluating print(abstract(Tree)) - simply using abstract/1 to map the actual data structure onto a syntax tree representation - would output a string that might look something like "{var, ..., 'V'}", which is obviously dependent on the implementation of the abstract syntax trees. This could e.g. be useful for caching a syntax tree in a file. However, in some situations like in a program generator generator (with two "generator"), it may be unacceptable. Using print(meta(Tree)) instead would output a representation independent syntax tree generating expression; in the above case, something like "cerl:c_var('V')".

The implementation tries to generate compact code with respect to literals and lists.

See also: abstract/1, get_ann/1, type/1.

Link to this function

module_attrs(Node:: c_module() ) -> [{ cerl() , cerl() }]

Specs

module_attrs(c_module()) -> [{cerl(), cerl()}].

Returns the list of pairs of attribute key/value subtrees of an abstract module definition.

See also: c_module/4.

Link to this function

module_defs(Node:: c_module() ) -> [{ cerl() , cerl() }]

Specs

module_defs(c_module()) -> [{cerl(), cerl()}].

Returns the list of function definitions of an abstract module definition.

See also: c_module/4.

Link to this function

module_exports(Node:: c_module() ) -> [ cerl() ]

Specs

module_exports(c_module()) -> [cerl()].

Returns the list of exports subtrees of an abstract module definition.

See also: c_module/4.

Link to this function

module_name(Node:: c_module() ) -> cerl()

Specs

module_name(c_module()) -> cerl().

Returns the name subtree of an abstract module definition.

See also: c_module/4.

Link to this function

module_vars(Node:: c_module() ) -> [ cerl() ]

Specs

module_vars(c_module()) -> [cerl()].

Returns the list of left-hand side function variable subtrees of an abstract module definition.

See also: c_module/4.

Link to this function

pat_list_vars(Ps::[ cerl() ]) -> [ cerl() ]

Specs

pat_list_vars([cerl()]) -> [cerl()].

Returns the list of all abstract variables in the given patterns. An exception is thrown if some element in Patterns does not represent a well-formed Core Erlang clause pattern. The order of listing is not defined.

See also: clause_vars/1, pat_vars/1.

Link to this function

pat_vars(Node:: cerl() ) -> [ cerl() ]

Specs

pat_vars(cerl()) -> [cerl()].

Returns the list of all abstract variables in a pattern. An exception is thrown if Node does not represent a well-formed Core Erlang clause pattern. The order of listing is not defined.

See also: clause_vars/1, pat_list_vars/1.

Link to this function

primop_args(Node:: c_primop() ) -> [ cerl() ]

Specs

primop_args(c_primop()) -> [cerl()].

Returns the list of argument subtrees of an abstract primitive operation call.

See also: c_primop/2, primop_arity/1.

Link to this function

primop_arity(Node:: c_primop() ) -> arity()

Specs

primop_arity(c_primop()) -> arity().

Returns the number of argument subtrees of an abstract primitive operation call.

Note: this is equivalent to length(primop_args(Node)), but potentially more efficient.

See also: c_primop/2, primop_args/1.

Link to this function

primop_name(Node:: c_primop() ) -> cerl()

Specs

primop_name(c_primop()) -> cerl().

Returns the name subtree of an abstract primitive operation call.

See also: c_primop/2.

Link to this function

receive_action(Node:: c_receive() ) -> cerl()

Specs

receive_action(c_receive()) -> cerl().

Returns the action subtree of an abstract receive-expression.

See also: c_receive/3.

Link to this function

receive_clauses(Node:: c_receive() ) -> [ cerl() ]

Specs

receive_clauses(c_receive()) -> [cerl()].

Returns the list of clause subtrees of an abstract receive-expression.

See also: c_receive/3.

Link to this function

receive_timeout(Node:: c_receive() ) -> cerl()

Specs

receive_timeout(c_receive()) -> cerl().

Returns the timeout subtree of an abstract receive-expression.

See also: c_receive/3.

Link to this function

seq_arg(Node:: c_seq() ) -> cerl()

Specs

seq_arg(c_seq()) -> cerl().

Returns the argument subtree of an abstract sequencing expression.

See also: c_seq/2.

Link to this function

seq_body(Node:: c_seq() ) -> cerl()

Specs

seq_body(c_seq()) -> cerl().

Returns the body subtree of an abstract sequencing expression.

See also: c_seq/2.

Link to this function

set_ann(Node:: cerl() , List::[term()]) -> cerl()

Specs

set_ann(cerl(), [term()]) -> cerl().

Sets the list of user annotations of Node to Annotations.

See also: add_ann/2, copy_ann/2, get_ann/1.

Link to this function

string_lit(Node:: c_literal() ) -> nonempty_string()

Specs

string_lit(c_literal()) -> nonempty_string().

Returns the literal string represented by an abstract string. This includes surrounding double-quote characters "...". Currently, characters that are not in the set of ISO 8859-1 (Latin-1) "printing" characters will be escaped, except for spaces.

See also: c_string/1.

Link to this function

string_val(Node:: c_literal() ) -> string()

Specs

string_val(c_literal()) -> string().

Returns the value represented by an abstract string literal.

See also: c_string/1.

Link to this function

subtrees(T:: cerl() ) -> [[ cerl() ]]

Specs

subtrees(cerl()) -> [[cerl()]].

Returns the grouped list of all subtrees of a node. If Node is a leaf node (cf. is_leaf/1), this is the empty list, otherwise the result is always a nonempty list, containing the lists of subtrees of Node, in left-to-right order as they occur in the printed program text, and grouped by category. Often, each group contains only a single subtree.

Depending on the type of Node, the size of some groups may be variable (e.g., the group consisting of all the elements of a tuple), while others always contain the same number of elements - usually exactly one (e.g., the group containing the argument expression of a case-expression). Note, however, that the exact structure of the returned list (for a given node type) should in general not be depended upon, since it might be subject to change without notice.

The function subtrees/1 and the constructor functions make_tree/2 and update_tree/2 can be a great help if one wants to traverse a syntax tree, visiting all its subtrees, but treat nodes of the tree in a uniform way in most or all cases. Using these functions makes this simple, and also assures that your code is not overly sensitive to extensions of the syntax tree data type, because any node types not explicitly handled by your code can be left to a default case.

For example:

    postorder(F, Tree) ->
        F(case subtrees(Tree) of
            [] -> Tree;
            List -> update_tree(Tree,
                                [[postorder(F, Subtree)
                                  || Subtree <- Group]
                                 || Group <- List])
          end).
  

maps the function F on Tree and all its subtrees, doing a post-order traversal of the syntax tree. (Note the use of update_tree/2 to preserve annotations.) For a simple function like:

    f(Node) ->
        case type(Node) of
            atom -> atom("a_" ++ atom_name(Node));
            _ -> Node
        end.
  

the call postorder(fun f/1, Tree) will yield a new representation of Tree in which all atom names have been extended with the prefix "a_", but nothing else (including annotations) has been changed.

See also: is_leaf/1, make_tree/2, update_tree/2.

Link to this function

to_records(Node:: cerl() ) -> cerl()

Specs

to_records(cerl()) -> cerl().

Translates an abstract syntax tree to a corresponding explicit record representation. The records are defined in the file "cerl.hrl".

See also: from_records/1, type/1.

Link to this function

try_arg(Node:: c_try() ) -> cerl()

Specs

try_arg(c_try()) -> cerl().

Returns the expression subtree of an abstract try-expression.

See also: c_try/5.

Link to this function

try_body(Node:: c_try() ) -> cerl()

Specs

try_body(c_try()) -> cerl().

Returns the success body subtree of an abstract try-expression.

See also: c_try/5.

Link to this function

try_evars(Node:: c_try() ) -> [ cerl() ]

Specs

try_evars(c_try()) -> [cerl()].

Returns the list of exception variable subtrees of an abstract try-expression.

See also: c_try/5.

Link to this function

try_handler(Node:: c_try() ) -> cerl()

Specs

try_handler(c_try()) -> cerl().

Returns the exception body subtree of an abstract try-expression.

See also: c_try/5.

Link to this function

try_vars(Node:: c_try() ) -> [ cerl() ]

Specs

try_vars(c_try()) -> [cerl()].

Returns the list of success variable subtrees of an abstract try-expression.

See also: c_try/5.

Link to this function

tuple_arity(C_tuple:: c_tuple() | c_literal() ) -> non_neg_integer()

Specs

tuple_arity(c_tuple() | c_literal()) -> non_neg_integer().

Returns the number of element subtrees of an abstract tuple.

Note: this is equivalent to length(tuple_es(Node)), but potentially more efficient.

See also: c_tuple/1, tuple_es/1.

Link to this function

tuple_es(C_tuple:: c_tuple() | c_literal() ) -> [ cerl() ]

Specs

tuple_es(c_tuple() | c_literal()) -> [cerl()].

Returns the list of element subtrees of an abstract tuple.

See also: c_tuple/1.

Link to this function

type(C_alias:: cerl() ) -> ctype()

Specs

type(cerl()) -> ctype().

Returns the type tag of Node. Current node types are:

alias apply binary bitstr call case catch clause
cons fun let letrec literal map map_pair module
primop receive seq try tuple values var

Note: The name of the primary constructor function for a node type is always the name of the type itself, prefixed by "c_"; recognizer predicates are correspondingly prefixed by "is_c_". Furthermore, to simplify preservation of annotations (cf. get_ann/1), there are analogous constructor functions prefixed by "ann_c_" and "update_c_", for setting the annotation list of the new node to either a specific value or to the annotations of an existing node, respectively.

See also: abstract/1, c_alias/2, c_apply/2, c_binary/1, c_bitstr/5, c_call/3, c_case/2, c_catch/1, c_clause/3, c_cons/2, c_fun/2, c_let/3, c_letrec/2, c_module/3, c_primop/2, c_receive/1, c_seq/2, c_try/5, c_tuple/1, c_values/1, c_var/1, data_type/1, from_records/1, get_ann/1, meta/1, subtrees/1, to_records/1.

Link to this function

unfold_literal(Node:: cerl() ) -> cerl()

Specs

unfold_literal(cerl()) -> cerl().

Assures that literals have a fully expanded representation. If Node represents a literal tuple or list constructor, its elements are rewritten recursively, and the node is reconstructed using c_cons_skel/2 or c_tuple_skel/1, respectively; otherwise, Node is not changed. The fold_literal/1 can be used to revert to the normal compact representation.

See also: c_cons/2, c_cons_skel/2, c_tuple/1, c_tuple_skel/1, fold_literal/1, is_literal/1.

Link to this function

update_c_alias(Node:: c_alias() , Var:: cerl() , Pattern:: cerl() ) -> c_alias()

Specs

update_c_alias(c_alias(), cerl(), cerl()) -> c_alias().

See also: c_alias/2.

Link to this function

update_c_apply(Node:: c_apply() , Operator:: cerl() , Arguments::[ cerl() ]) -> c_apply()

Specs

update_c_apply(c_apply(), cerl(), [cerl()]) -> c_apply().

See also: c_apply/2.

Link to this function

update_c_binary(Node:: c_binary() , Segments::[ cerl() ]) -> c_binary()

Specs

update_c_binary(c_binary(), [cerl()]) -> c_binary().

See also: c_binary/1.

Link to this function

update_c_bitstr(Node:: c_bitstr() , Value:: cerl() , Size:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

update_c_bitstr(c_bitstr(), cerl(), cerl(), cerl(), cerl()) -> c_bitstr().

Equivalent to update_c_bitstr(Node, Value, Size, abstract(1), Type, Flags).

Link to this function

update_c_bitstr(Node:: c_bitstr() , Val:: cerl() , Size:: cerl() , Unit:: cerl() , Type:: cerl() , Flags:: cerl() ) -> c_bitstr()

Specs

update_c_bitstr(c_bitstr(), cerl(), cerl(), cerl(), cerl(), cerl()) -> c_bitstr().

See also: c_bitstr/5, update_c_bitstr/5.

Link to this function

update_c_call(Node:: cerl() , Module:: cerl() , Name:: cerl() , Arguments::[ cerl() ]) -> c_call()

Specs

update_c_call(cerl(), cerl(), cerl(), [cerl()]) -> c_call().

See also: c_call/3.

Link to this function

update_c_case(Node:: c_case() , Expr:: cerl() , Clauses::[ cerl() ]) -> c_case()

Specs

update_c_case(c_case(), cerl(), [cerl()]) -> c_case().

See also: c_case/2.

Link to this function

update_c_catch(Node:: c_catch() , Body:: cerl() ) -> c_catch()

Specs

update_c_catch(c_catch(), cerl()) -> c_catch().

See also: c_catch/1.

Link to this function

update_c_clause(Node:: c_clause() , Patterns::[ cerl() ], Guard:: cerl() , Body:: cerl() ) -> c_clause()

Specs

update_c_clause(c_clause(), [cerl()], cerl(), cerl()) -> c_clause().

See also: c_clause/3.

Link to this function

update_c_cons(Node:: c_literal() | c_cons() , C_literal:: cerl() , Tail:: cerl() ) -> c_literal() | c_cons()

Specs

update_c_cons(c_literal() | c_cons(), cerl(), cerl()) -> c_literal() | c_cons().

See also: c_cons/2.

Link to this function

update_c_cons_skel(Node:: c_cons() | c_literal() , Head:: cerl() , Tail:: cerl() ) -> c_cons()

Specs

update_c_cons_skel(c_cons() | c_literal(), cerl(), cerl()) -> c_cons().

See also: c_cons_skel/2.

Link to this function

update_c_fname(C_var:: c_var() , Atom::atom()) -> c_var()

Specs

update_c_fname(c_var(), atom()) -> c_var().

Like update_c_fname/3, but takes the arity from Node.

See also: c_fname/2, update_c_fname/3.

Link to this function

update_c_fname(Node:: c_var() , Atom::atom(), Arity::arity()) -> c_var()

Specs

update_c_fname(c_var(), atom(), arity()) -> c_var().

Equivalent to update_c_var(Old, {Atom, Arity}).

See also: c_fname/2, update_c_fname/2.

Link to this function

update_c_fun(Node:: c_fun() , Variables::[ cerl() ], Body:: cerl() ) -> c_fun()

Specs

update_c_fun(c_fun(), [cerl()], cerl()) -> c_fun().

See also: c_fun/2.

Link to this function

update_c_let(Node:: c_let() , Variables::[ cerl() ], Argument:: cerl() , Body:: cerl() ) -> c_let()

Specs

update_c_let(c_let(), [cerl()], cerl(), cerl()) -> c_let().

See also: c_let/3.

Link to this function

update_c_letrec(Node:: c_letrec() , Defs::[{ cerl() , cerl() }], Body:: cerl() ) -> c_letrec()

Specs

update_c_letrec(c_letrec(), [{cerl(), cerl()}], cerl()) -> c_letrec().

See also: c_letrec/2.

Link to this function

update_c_map(C_map:: c_map() , M:: cerl() , Es::[ cerl() ]) -> c_map() | c_literal()

Specs

update_c_map(c_map(), cerl(), [cerl()]) -> c_map() | c_literal().
Link to this function

update_c_map_pair(Old:: c_map_pair() , Op:: map_op() , K:: cerl() , V:: cerl() ) -> c_map_pair()

Specs

update_c_map_pair(c_map_pair(), map_op(), cerl(), cerl()) -> c_map_pair().
Link to this function

update_c_module(Node:: c_module() , Name:: cerl() , Exports::[ cerl() ], Attrs::[{ cerl() , cerl() }], Es::[{ cerl() , cerl() }]) -> c_module()

Specs

update_c_module(c_module(), cerl(), [cerl()], [{cerl(), cerl()}], [{cerl(), cerl()}]) ->
                   c_module().

See also: c_module/4.

Link to this function

update_c_primop(Node:: cerl() , Name:: cerl() , Arguments::[ cerl() ]) -> c_primop()

Specs

update_c_primop(cerl(), cerl(), [cerl()]) -> c_primop().

See also: c_primop/2.

Link to this function

update_c_receive(Node:: c_receive() , Clauses::[ cerl() ], Timeout:: cerl() , Action:: cerl() ) -> c_receive()

Specs

update_c_receive(c_receive(), [cerl()], cerl(), cerl()) -> c_receive().

See also: c_receive/3.

Link to this function

update_c_seq(Node:: c_seq() , Argument:: cerl() , Body:: cerl() ) -> c_seq()

Specs

update_c_seq(c_seq(), cerl(), cerl()) -> c_seq().

See also: c_seq/2.

Link to this function

update_c_try(Node:: c_try() , Expr:: cerl() , Vs::[ cerl() ], Body:: cerl() , Evs::[ cerl() ], Handler:: cerl() ) -> c_try()

Specs

update_c_try(c_try(), cerl(), [cerl()], cerl(), [cerl()], cerl()) -> c_try().

See also: c_try/5.

Link to this function

update_c_tuple(Node:: c_tuple() | c_literal() , Es::[ cerl() ]) -> c_tuple() | c_literal()

Specs

update_c_tuple(c_tuple() | c_literal(), [cerl()]) -> c_tuple() | c_literal().

See also: c_tuple/1.

Link to this function

update_c_tuple_skel(Old:: c_tuple() , Es::[ cerl() ]) -> c_tuple()

Specs

update_c_tuple_skel(c_tuple(), [cerl()]) -> c_tuple().

See also: c_tuple_skel/1.

Link to this function

update_c_values(Node:: c_values() , Es::[ cerl() ]) -> c_values()

Specs

update_c_values(c_values(), [cerl()]) -> c_values().

See also: c_values/1.

Link to this function

update_c_var(Node:: c_var() , Name:: var_name() ) -> c_var()

Specs

update_c_var(c_var(), var_name()) -> c_var().

See also: c_var/1.

Link to this function

update_data(Node:: cerl() , CType:: dtype() , Es::[ cerl() ]) -> c_lct()

Specs

update_data(cerl(), dtype(), [cerl()]) -> c_lct().

See also: make_data/2.

Link to this function

update_data_skel(Node:: cerl() , CType:: dtype() , Es::[ cerl() ]) -> c_lct()

Specs

update_data_skel(cerl(), dtype(), [cerl()]) -> c_lct().

See also: make_data_skel/2.

Link to this function

update_list(Node:: cerl() , List::[ cerl() ]) -> cerl()

Specs

update_list(cerl(), [cerl()]) -> cerl().

Equivalent to update_list(Old, List, none).

Link to this function

update_list(Node:: cerl() , List::[ cerl() ], Tail:: cerl() | none) -> cerl()

Specs

update_list(cerl(), [cerl()], cerl() | none) -> cerl().

See also: make_list/2, update_list/2.

Link to this function

update_tree(Node:: cerl() , Gs::[[ cerl() ], ...]) -> cerl()

Specs

update_tree(cerl(), [[cerl()], ...]) -> cerl().

Creates a syntax tree with the given subtrees, and the same type and annotations as the Old node. This is equivalent to ann_make_tree(get_ann(Node), type(Node), Groups), but potentially more efficient.

See also: ann_make_tree/3, get_ann/1, type/1, update_tree/3.

Link to this function

update_tree(Node:: cerl() , Type:: ctype() , Gs::[[ cerl() ], ...]) -> cerl()

Specs

update_tree(cerl(), ctype(), [[cerl()], ...]) -> cerl().

Creates a syntax tree with the given type and subtrees, and the same annotations as the Old node. This is equivalent to ann_make_tree(get_ann(Node), Type, Groups), but potentially more efficient.

See also: ann_make_tree/3, get_ann/1, update_tree/2.

Link to this function

values_arity(Node:: c_values() ) -> non_neg_integer()

Specs

values_arity(c_values()) -> non_neg_integer().

Returns the number of element subtrees of an abstract value list.

Note: This is equivalent to length(values_es(Node)), but potentially more efficient.

See also: c_values/1, values_es/1.

Link to this function

values_es(Node:: c_values() ) -> [ cerl() ]

Specs

values_es(c_values()) -> [cerl()].

Returns the list of element subtrees of an abstract value list.

See also: c_values/1, values_arity/1.

Link to this function

var_name(Node:: c_var() ) -> var_name()

Specs

var_name(c_var()) -> var_name().

Returns the name of an abstract variable.

See also: c_var/1.