Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/ast.x
Shared helpers for x2c compiler AST nodes.
Functions
| Function | Summary |
|---|---|
Ast.addressed_identifier | Returns the name whose address an expression takes, or NULL. |
Ast.append_modifiers | Returns declarator with modifiers after its own, as a declaration whose base contributes modifiers declares each name. |
Ast.binding | Constructs a (binding identity spelling) node. |
Ast.binding_spelling | Returns a valid binding node’s source spelling, or NULL. |
Ast.collect_binding_references | Records in referenced the identity of every binding node names. |
Ast.contains_head | Returns whether any list under value has kind as its head. |
Ast.designated | Returns the innermost node value designates, past the forms that still name the same object: an expr wrapper, parentheses, a member, and an index into an array. |
Ast.direct_identifier | Returns the name an expression designates directly, following the forms that still name the same object - parentheses, a member, an array index, a dereference - or NULL when the expression designates no single name. |
Ast.entry_call | Returns the statement calling the void (void) function entry. |
Ast.indirect_identifier | Returns the name of the pointer an expression designates through, or NULL when it designates no object through a single name. |
Ast.initializer_cases | Returns initializer alternatives and their optional native macro input. |
Ast.initializer_functions | Returns function alternatives when every initializer arm calls one shared input, and stores that input expression in source. |
Ast.lvalue_binding | Returns the binding whose stored object the lvalue ast names, or NULL. |
Ast.never_returns | Returns whether control cannot flow out the bottom of ast. |
Ast.prototype_declarator | Returns declarator with the outermost volatile removed from each of its parameters. |
Ast.reference_guard_exits | Returns whether arm ends with a return or non-returning raise. |
Ast.replace_nodes | Returns root with each list beneath it that replaced maps, keyed by its address, swapped for its value, and adds each rebuilt ancestor to replaced. |
Ast.rewrap_origin | Returns replacement under the anchors of original, the statement it replaces, so a rewrite does not lose the node’s source position. |
Ast.rewrite_children | Applies per_child to each List child of ast and returns the node rebuilt from the results; non-list children pass through. |
Ast.try_binding | Extracts a valid (binding positive-integer string) node. |
Ast.without_origin | Returns ast without the (at ORIGIN ...) anchors it arrived wrapped in. |
Ast.written_definitions | Returns decl with each function definition marked kernel as written. |
Ast.written_operand | Returns the operand a write node changes: the left operand of an assignment or prefix update, or the operand of a postfix update; NULL when node writes no operand. |
Symbol.changes_left_operand | Returns whether op writes its left operand. |
Symbol.is_assignment_op | Returns whether op is plain or compound assignment. |
Ast
Ast.addressed_identifier
String Ast.addressed_identifier(Var value)
Returns the name whose address an expression takes, or NULL.
Source: src/ast.x:141
Ast.append_modifiers
List Ast.append_modifiers(List declarator, List modifiers)
Returns declarator with modifiers after its own, as a declaration
whose base contributes modifiers declares each name.
Source: src/ast.x:59
Ast.binding
List Ast.binding(int identity, String spelling)
Constructs a (binding identity spelling) node.
The caller must supply a positive compiler-issued identity.
Source: src/ast.x:30
Ast.binding_spelling
String Ast.binding_spelling(List binding)
Returns a valid binding node’s source spelling, or NULL.
Source: src/ast.x:50
Ast.collect_binding_references
void Ast.collect_binding_references(Var node, Map referenced)
Records in referenced the identity of every binding node names.
Source: src/ast.x:256
Ast.contains_head
int Ast.contains_head(Var value, Symbol kind)
Returns whether any list under value has kind as its head.
Source: src/ast.x:218
Ast.designated
List Ast.designated(Var value)
Returns the innermost node value designates, past the forms that still
name the same object: an expr wrapper, parentheses, a member, and an
index into an array. What remains is a name, a designation through a
pointer, or another expression; a non-list designates nothing.
Source: src/ast.x:114
Ast.direct_identifier
String Ast.direct_identifier(Var value)
Returns the name an expression designates directly, following the forms
that still name the same object - parentheses, a member, an array index,
a dereference - or NULL when the expression designates no single name.
A declaration qualifier that must reach one object, such as the volatile
an error transfer requires, applies to this name.
Source: src/ast.x:160
Ast.entry_call
List Ast.entry_call(String entry)
Returns the statement calling the void (void) function entry.
Source: src/ast.x:310
Ast.indirect_identifier
String Ast.indirect_identifier(Var value)
Returns the name of the pointer an expression designates through, or
NULL when it designates no object through a single name. *pointer,
pointer[index], and pointer->member all change the object the pointer
holds, which Ast.direct_identifier reports as no name at all.
Source: src/ast.x:178
Ast.initializer_cases
List Ast.initializer_cases(Ast ast, List &input)
Returns initializer alternatives and their optional native macro input.
Source: src/ast.x:388
Ast.initializer_functions
List Ast.initializer_functions(Ast ast, List &source)
Returns function alternatives when every initializer arm calls one shared
input, and stores that input expression in source. Other forms return
NULL.
Source: src/ast.x:402
Ast.lvalue_binding
List Ast.lvalue_binding(Ast ast)
Returns the binding whose stored object the lvalue ast names, or
NULL. Pointer dereferences and pointer indexes name another object; an
array field remains part of its containing aggregate.
Source: src/ast.x:133
Ast.never_returns
int Ast.never_returns(Ast ast)
Returns whether control cannot flow out the bottom of ast.
Recognized terminals are shared non-returning raises, native termination
calls, and blocks ending in either one when the block contains no
return. Generation uses this fact to mark the enclosing function
_Noreturn.
Source: src/ast.x:335
Ast.prototype_declarator
List Ast.prototype_declarator(List declarator)
Returns declarator with the outermost volatile removed from each of
its parameters. C ignores a parameter’s top-level qualifier when it
compares a prototype with its definition, and the qualifier the error
transfer requires belongs to the definition that writes the parameter,
not to the declaration its callers read.
Source: src/ast.x:77
Ast.reference_guard_exits
int Ast.reference_guard_exits(List arm)
Returns whether arm ends with a return or non-returning raise.
Source: src/ast.x:316
Ast.replace_nodes
Var Ast.replace_nodes(Var root, Map replaced)
Returns root with each list beneath it that replaced maps, keyed
by its address, swapped for its value, and adds each rebuilt ancestor
to replaced. Only the ancestors of a swapped list are new, so root
returns itself when nothing beneath it is swapped. The walk keeps deep
expression chains off the C stack.
Source: src/ast.x:229
Ast.rewrap_origin
Ast Ast.rewrap_origin(Ast original, Ast replacement)
Returns replacement under the anchors of original, the statement it
replaces, so a rewrite does not lose the node’s source position.
Source: src/ast.x:288
Ast.rewrite_children
Ast Ast.rewrite_children(Ast ast, Func per_child)
Applies per_child to each List child of ast and returns the node
rebuilt from the results; non-list children pass through. When no child
changed, no scratch storage is allocated and ast itself returns, so the
fixed-point transform driver can compare unchanged-node identity.
Source: src/ast.x:212
Ast.try_binding
int Ast.try_binding( List binding, int &?identity, String &?spelling)
Extracts a valid (binding positive-integer string) node.
Returns one on success and writes only non-NULL outputs; failure returns
zero without changing either output.
Source: src/ast.x:37
Ast.without_origin
Ast Ast.without_origin(Ast ast)
Returns ast without the (at ORIGIN ...) anchors it arrived wrapped
in. Every block statement carries one so that a transform-phase
diagnostic can name its line; a pass that dispatches on a statement tag
has to see the statement, not the anchor.
Source: src/ast.x:276
Ast.written_definitions
List Ast.written_definitions(List decl)
Returns decl with each function definition marked kernel as written.
The transform strips the marker before it offers the definition only to
shipped function rules.
Source: src/ast.x:300
Ast.written_operand
List Ast.written_operand(Ast node)
Returns the operand a write node changes: the left operand of an
assignment or prefix update, or the operand of a postfix update; NULL
when node writes no operand.
Source: src/ast.x:195
Symbol
Symbol.changes_left_operand
int Symbol.changes_left_operand(Symbol op)
Returns whether op writes its left operand.
Source: src/ast.x:382
Symbol.is_assignment_op
int Symbol.is_assignment_op(Symbol op)
Returns whether op is plain or compound assignment.
Source: src/ast.x:378
Public types
| Type | Kind | Summary |
|---|---|---|
Ast | alias | Represents one compiler AST node as a canonical immutable List. |
Ast
typedef List Ast
Represents one compiler AST node as a canonical immutable List.
NULL denotes no node, and nonempty nodes have the canonical List-pool
lifetime.
Source: src/ast.x:13
Design notes
Simple fixed-shape nodes remain direct immutable Lists. This module
holds the node operations that several compiler phases share.