Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/ast.x

Shared helpers for x2c compiler AST nodes.

Functions

FunctionSummary
ast_changes_left_operandReturns whether op writes its left operand.
ast_contains_headReturns whether any list under value has kind as its head.
binding_identity_newConstructs a (binding identity spelling) node.
binding_identity_spellingReturns a valid binding node’s source spelling, or NULL.
binding_identity_try_partsExtracts a valid (binding positive-integer string) node.
preproc_conditional_kindClassifies the preprocessor line text as a conditional directive: <open> for #if, #ifdef, and #ifndef, <branch> for #elif and #else forms, <close> for #endif, or 0 for any other line.
preproc_directiveReturns the preprocessor line text without its # and the blanks around the directive.
preproc_include_targetReturns the file named by the #include line text, or NULL for any other line.
preproc_track_armsFollows the conditional groups open after the preprocessor line text.
preproc_within_armsReturns items inside the conditional arms arms tracked by preproc_track_arms: the directives that reopen each group, outermost first, then items, then one #endif per group.
Ast.initializer_casesReturns initializer alternatives and their optional native macro input.
Ast.initializer_functionsReturns function alternatives when every initializer arm calls one shared input, and stores that input expression in source.
Ast.never_returnsReturns whether control cannot flow out the bottom of ast.
Ast.rewrite_childrenApplies per_child to each List child of ast and returns the node rebuilt from the results; non-list children pass through.
Symbol.compound_assignmentReturns the compound assignment for a binary operator, or zero.
Symbol.compound_operatorReturns the binary operator computed by a compound assignment, or zero.
Symbol.is_assignment_opReturns whether op is plain or compound assignment.

Functions

ast_changes_left_operand

int ast_changes_left_operand(Symbol op)

Returns whether op writes its left operand.

Source: src/ast.x:146

ast_contains_head

int ast_contains_head(Var value, Symbol kind)

Returns whether any list under value has kind as its head. The worklist keeps deeply nested operator chains off the C stack.

Source: src/ast.x:151

binding_identity_new

List binding_identity_new(int identity, String spelling)

Constructs a (binding identity spelling) node. The caller must supply a positive compiler-issued identity.

Source: src/ast.x:39

binding_identity_spelling

String binding_identity_spelling(List binding)

Returns a valid binding node’s source spelling, or NULL.

Source: src/ast.x:58

binding_identity_try_parts

int binding_identity_try_parts(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:46

preproc_conditional_kind

Symbol preproc_conditional_kind(String text)

Classifies the preprocessor line text as a conditional directive: <open> for #if, #ifdef, and #ifndef, <branch> for #elif and #else forms, <close> for #endif, or 0 for any other line.

Source: src/ast.x:68

preproc_directive

String preproc_directive(String text)

Returns the preprocessor line text without its # and the blanks around the directive.

Source: src/ast.x:78

preproc_include_target

String preproc_include_target(String text, int *angle)

Returns the file named by the #include line text, or NULL for any other line. *angle is 1 for a <...> name and 0 otherwise. Text after the name, such as a comment, is ignored.

Source: src/ast.x:85

preproc_track_arms

List preproc_track_arms(List arms, String text)

Follows the conditional groups open after the preprocessor line text. arms holds one entry per open group, innermost first, listing the preproc nodes that select that group’s current arm.

Source: src/ast.x:100

preproc_within_arms

List preproc_within_arms(List arms, List items)

Returns items inside the conditional arms arms tracked by preproc_track_arms: the directives that reopen each group, outermost first, then items, then one #endif per group.

Source: src/ast.x:113

Ast

Ast.initializer_cases

List Ast.initializer_cases(Ast ast, List *input)

Returns initializer alternatives and their optional native macro input.

Source: src/ast.x:242

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:256

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:228

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:170

Symbol

Symbol.compound_assignment

Symbol Symbol.compound_assignment(Symbol op)

Returns the compound assignment for a binary operator, or zero.

Source: src/ast.x:136

Symbol.compound_operator

Symbol Symbol.compound_operator(Symbol op)

Returns the binary operator computed by a compound assignment, or zero.

Source: src/ast.x:130

Symbol.is_assignment_op

int Symbol.is_assignment_op(Symbol op)

Returns whether op is plain or compound assignment.

Source: src/ast.x:142

Public types

TypeKindSummary
AstaliasRepresents one compiler AST node as a canonical immutable List.
AstPosenumNames the syntactic position in which an AST is parsed or bound.

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

AstPos

typedef enum AstPos { AST_UNIT, AST_BLOCK, AST_FIELD, AST_ENUMERATOR, AST_MAP_ENTRY, AST_STATEMENT, AST_EXPRESSION } AstPos

Names the syntactic position in which an AST is parsed or bound.

Source: src/ast.x:16

Design notes

Keeps sequence placement in one place. Simple fixed-shape nodes remain direct immutable Lists.