Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/expressions.x
X2c expression parsing.
Functions
| Function | Summary |
|---|---|
Compiler.check_explicit_converter | Reports parsed when it is the explicit converter call resolved last and target converts its receiver on its own: either side is Var, the types share one C type, or the receiver declares a converter to the target. |
Compiler.complete_iter_chain | Completes an eligible resolved Iter call chain for immediate consumption. |
Compiler.convert_compound_literal | Keeps a compound literal’s native type definition at its original scope. |
Compiler.convert_expression | Adds operations to convert a resolved expression AST to target. |
Compiler.convert_initializer | Converts an initializer using its declared native object for array bounds. |
Compiler.convert_segment_to_string | Converts a resolved interpolation segment to String when available. |
Compiler.initializer_native_types | Returns native definition/reference types for a compound literal. |
Compiler.initializer_rows | Returns (original cases) rows; each case is (native-condition path destination value). |
Compiler.initializer_slot | Selects a native subobject without evaluating it when used by sizeof. |
Compiler.parse_assignment | Parses one right-associative assignment expression. |
Compiler.parse_conditional | Parses a binary expression and its optional conditional tail. |
Compiler.parse_expression | Parses an assignment expression and any following comma expressions. |
Compiler.parse_macro_expression_target | Parses one macro target through the cast-expression grammar. |
Compiler.parse_parenthesized_statement | Parses a statement beginning with (. |
Compiler.parse_primary | Parses one primary expression or expression-valued macro slot. |
Compiler.parse_variable | Parses and resolves one complex identifier expression. |
Compiler.printf_static_format | Returns the format a printf-family call consumes when it is known at translation time, or NULL. |
Compiler.promote_string_literal | Converts a C string literal to String where no C meaning applies: as a method receiver, a foreach collection, or a raise detail. |
Compiler.require_var_tag | Returns the exact Var tag for a type test, rejecting types without one. |
Compiler.resolve_expression | Resolves and type-annotates one expression AST in current compiler state. |
Compiler.resolve_map_entry | Resolves the key and value of one (map-entry key value) AST row. |
Compiler.resolve_postfix_member | Resolves one field or method selection without consuming parser tokens. |
Compiler.var_tag_expression | Builds an exact tag expression, deferring macro type slots until binding. |
List.printf_family | Returns the printf-family entry a callee names, or NULL. |
Compiler
Compiler.check_explicit_converter
void Compiler.check_explicit_converter( Compiler c, List parsed, Type target, int context)
Reports parsed when it is the explicit converter call resolved last
and target converts its receiver on its own: either side is Var, the
types share one C type, or the receiver declares a converter to the
target. The call then changes nothing but the spelling. context is 0
for a typed destination, 1 for an interpolation hole, which displays
every value through Var.str, and 2 for a printf-family value, which
the format converts when it is a Var.
Source: src/expressions.x:1562
Compiler.complete_iter_chain
List Compiler.complete_iter_chain(Compiler compiler, List expression)
Completes an eligible resolved Iter call chain for immediate consumption.
It accepts only a typed identifier call of the form
(expr R (call (expr ((func P) T) (ident B)) (args A))), where R and
the last formal in P canonicalize to Iter. Iter arguments are
completed recursively; a call missing only that last formal receives the
hidden destination. Variadic calls and Iter_unzip are returned unchanged.
Source: src/expressions.x:52
Compiler.convert_compound_literal
List Compiler.convert_compound_literal( Compiler c, List value, Type type, Type native_type)
Keeps a compound literal’s native type definition at its original scope.
Source: src/expressions.x:3756
Compiler.convert_expression
List Compiler.convert_expression(Compiler c, List expr, Type target)
Adds operations to convert a resolved expression AST to target.
The result may contain converter, boxing, unboxing, Func, reference, or
composite-literal operations. Returns the original expression when C
performs the conversion implicitly; an unsupported x2c conversion reports
a type error through c. Synthesized operations may add generated
bindings or immutable literal entries to compiler state.
Source: src/expressions.x:3800
Compiler.convert_initializer
List Compiler.convert_initializer( Compiler c, List value, Type type, List target)
Converts an initializer using its declared native object for array bounds.
Source: src/expressions.x:3751
Compiler.convert_segment_to_string
List Compiler.convert_segment_to_string(Compiler compiler, List expr)
Converts a resolved interpolation segment to String when available.
A missing String conversion is expected: the transform boxes that segment
to Var and renders it at runtime.
A declared numeric converter keeps its formatting; other numeric segments
use Var.str. A segment statically spelled Var also uses Var.str for
every
runtime tag. The ordinary Var-to-String conversion is
not equivalent: it
extracts only a String payload and yields empty String for every other
tag.
Source: src/expressions.x:4091
Compiler.initializer_native_types
List Compiler.initializer_native_types(Compiler c, Type type)
Returns native definition/reference types for a compound literal. Macro expansion stays in the original cast; named tags let later sizeof expressions reuse that exact layout without a new scope.
Source: src/expressions.x:2896
Compiler.initializer_rows
List Compiler.initializer_rows( Compiler c, Type root, List items, List target)
Returns (original cases) rows; each case is (native-condition path destination value). Explicit braces start a nested walk. Scalar runs map their ordinal through the native dimensions; other inputs retain possible cursor continuations. A NULL condition is unconditional, and a NULL destination is excess.
Source: src/expressions.x:3343
Compiler.initializer_slot
List Compiler.initializer_slot(Compiler c, List target, List path)
Selects a native subobject without evaluating it when used by sizeof.
Source: src/expressions.x:3023
Compiler.parse_assignment
List Compiler.parse_assignment(Compiler compiler)
Parses one right-associative assignment expression.
A parenthesized identifier list on the left becomes a destructuring
assignment only for =. compiler.token stops after the expression.
Source: src/expressions.x:2449
Compiler.parse_conditional
List Compiler.parse_conditional(Compiler compiler)
Parses a binary expression and its optional conditional tail.
The false arm recurses at conditional precedence, making ?:
right-associative, and compiler.token stops after the expression.
Source: src/expressions.x:2429
Compiler.parse_expression
List Compiler.parse_expression(Compiler compiler)
Parses an assignment expression and any following comma expressions.
A comma expression retains source order and takes the type of its final
value. compiler.token stops at the first token outside the expression.
Source: src/expressions.x:2534
Compiler.parse_macro_expression_target
List Compiler.parse_macro_expression_target(Compiler c)
Parses one macro target through the cast-expression grammar.
Parsing starts at c.token and leaves it at the first token after
the target.
Source: src/expressions.x:817
Compiler.parse_parenthesized_statement
List Compiler.parse_parenthesized_statement(Compiler c)
Parses a statement beginning with (.
The ordinary parameter parser consumes the contents once: one anonymous
parameter is a cast type, while named parameters are destructuring
declarations. Everything following an ordinary parenthesized expression
resumes at the postfix tail it had already reached. This entry consumes
the terminating ; and returns (stmnt expression) or an origin-anchored
(dstrdecl ...).
Source: src/expressions.x:2557
Compiler.parse_primary
List Compiler.parse_primary(Compiler compiler)
Parses one primary expression or expression-valued macro slot.
Dispatch starts at compiler.token to the selected literal, identifier,
grouping, or macro parser and leaves the token after that primary form.
Source: src/expressions.x:2485
Compiler.parse_variable
List Compiler.parse_variable(Compiler c)
Parses and resolves one complex identifier expression.
Parsing starts at compiler.token and leaves it after the identifier.
Source: src/expressions.x:2392
Compiler.printf_static_format
String Compiler.printf_static_format( Compiler compiler, Var format, int *raw)
Returns the format a printf-family call consumes when it is known at
translation time, or NULL. That is a quoted C string literal, the
canonical String one becomes, or the String_new of one; any other
format, such as a variable or an object macro, is not readable here.
raw reports C spelling, whose quotes and escape sequences the caller
steps over.
Source: src/expressions.x:222
Compiler.promote_string_literal
List Compiler.promote_string_literal(Compiler c, List expr)
Converts a C string literal to String where no C meaning applies: as a
method receiver, a foreach collection, or a raise detail. Parentheses
and a conditional whose arms are both literals count as the literal; any
other expression is returned unchanged.
Source: src/expressions.x:958
Compiler.require_var_tag
Symbol Compiler.require_var_tag( Compiler compiler, Type target, Token origin)
Returns the exact Var tag for a type test, rejecting types without one. Enums retain no identity after boxing and cannot be tested this way.
Source: src/expressions.x:1684
Compiler.resolve_expression
List Compiler.resolve_expression(Compiler c, List input, Token origin)
Resolves and type-annotates one expression AST in current compiler state.
Existing expr type annotations are resolved semantic types.
Already-resolved trees without unresolved descendants and non-expression
inputs are returned unchanged; abstract declarations use the declaration
binder. origin anchors diagnostics and generated operations that must
retain source position.
Source: src/expressions.x:2220
Compiler.resolve_map_entry
List Compiler.resolve_map_entry(Compiler compiler, List input, Token origin)
Resolves the key and value of one (map-entry key value) AST row.
Any other shape is reported at origin as a parse error.
Source: src/expressions.x:2204
Compiler.resolve_postfix_member
List Compiler.resolve_postfix_member( Compiler c, Type receiver_type, List field, Symbol access, int call_context)
Resolves one field or method selection without consuming parser tokens.
field is a single-name List and access is . or
->. The result is a
(field access type), (method binding signature), or (ambiguous ...)
row, or NULL when no member is visible. Method lookup is enabled only by
call_context and records the selected binding in compiler.sym.
Source: src/expressions.x:343
Compiler.var_tag_expression
List Compiler.var_tag_expression(Compiler c, Type target, Token origin)
Builds an exact tag expression, deferring macro type slots until binding.
Source: src/expressions.x:1712
List
List.printf_family
const PrintfFn *List.printf_family(List l)
Returns the printf-family entry a callee names, or NULL. A resolved
user function that happens to use a libc spelling is not one.
Source: src/expressions.x:200
Public types
| Type | Kind | Summary |
|---|---|---|
PrintfFn | struct | A printf-family function: its name, the indexes of its format and first value arguments, and whether only a spelling no declaration resolves names it. |
PrintfFn
typedef struct PrintfFn { const char *name, int fmt_arg, first_arg, unresolved; } PrintfFn
A printf-family function: its name, the indexes of its format and first value arguments, and whether only a spelling no declaration resolves names it.
Source: src/expressions.x:18
Design notes
Parses postfix operators and calls, unary operators and casts, binary operators with precedence/associativity, conditionals, assignment, primary/grouped forms, and comma folding. Precedence and associativity follow C; dotted method sugar and string-like addition use resolved type information from the compiler and type modules.